8000 Remove "Replace Snippet" overlay button (rip) + Do not scroll to the dropped snippet if it is an inner content + Call prepare_drag resource for snippets too and properly cancel + Scroll to the clone and activate its option only if needed by sobo-odoo · Pull Request #4691 · odoo-dev/odoo · GitHub
[go: up one dir, main page]

Skip to content

Remove "Replace Snippet" overlay button (rip) + Do not scroll to the dropped snippet if it is an inner content + Call prepare_drag resource for snippets too and properly cancel + Scroll to the clone and activate its option only if needed #4691

8000 New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
8000
Diff view
Diff view
Prev Previous commit
Next Next commit
Call prepare_drag resource for snippets too and properly cancel
  • Loading branch information
sobo-odoo committed May 20, 2025
commit 170b3353200e4c7cf0cabcd31bc321d34701b22b
7 changes: 5 additions & 2 deletions addons/html_builder/static/src/core/drag_and_drop_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ export class DragAndDropPlugin extends Plugin {
},
{ withLoadingEffect: false }
);
this.restoreDragSavePoint = this.dependencies.history.makeSavePoint();
const restoreDragSavePoint = this.dependencies.history.makeSavePoint();
this.cancelDragAndDrop = () => {
this.restoreDragSavePoint();
// Undo the changes needed to ease the drag and drop.
this.dragState.restoreCallbacks?.forEach((restore) => restore());
restoreDragSavePoint();
dragAndDropResolve();
this.dependencies["builder-options"].updateContainers(this.overlayTarget);
};
Expand Down Expand Up @@ -326,6 +328,7 @@ export class DragAndDropPlugin extends Plugin {

// Undo the changes needed to ease the drag and drop.
this.dragState.restoreCallbacks.forEach((restore) => restore());
this.dragState.restoreCallbacks = null;

// Add a history step only if the element was not dropped where
// it was before, otherwise cancel everything.
Expand Down
32 changes: 25 additions & 7 deletions addons/html_builder/static/src/sidebar/block_tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class BlockTab extends Component {
onSnippetGroupClick(snippet) {
this.shared.operation.next(
async () => {
this.cancelDragAndDrop = this.shared.history.makeSavePoint();
let snippetEl;
const baseSectionEl = snippet.content.cloneNode(true);
this.state.ongoingInsertion = true;
Expand Down Expand Up @@ -101,6 +102,7 @@ export class BlockTab extends Component {
await this.processDroppedSnippet(snippetEl);
}
this.state.ongoingInsertion = false;
delete this.cancelDragAndDrop;
},
{ withLoadingEffect: false }
);
Expand Down Expand Up @@ -223,7 +225,12 @@ export class BlockTab extends Component {
},
{ withLoadingEffect: false }
);
this.cancelDragAndDrop = this.shared.history.makeSavePoint();
const restoreDragSavePoint = this.shared.history.makeSavePoint();
this.cancelDragAndDrop = () => {
// Undo the changes needed to ease the drag and drop.
this.dragState.restoreCallbacks?.forEach((restore) => restore());
restoreDragSavePoint();
};
this.hideSnippetToolTip?.();

this.document.body.classList.add("oe_dropzone_active");
Expand All @@ -232,6 +239,14 @@ export class BlockTab extends Component {
this.dragState = {};
dropzoneEls = [];

// Make some changes on the page to ease the drag and drop.
const restoreCallbacks = [];
for (const prepareDrag of this.env.editor.getResource("on_prepare_drag_handlers")) {
const restore = prepareDrag();
restoreCallbacks.push(restore);
}
this.dragState.restoreCallbacks = restoreCallbacks;

const category = element.closest(".o_snippets_container").id;
const id = element.dataset.id;
snippet = this.snippetModel.getSnippet(category, id);
Expand Down Expand Up @@ -338,17 +353,20 @@ export class BlockTab extends Component {
if (closestDropzoneEl) {
currentDropzoneEl = closestDropzoneEl;
}
} else {
this.cancelDragAndDrop();
}
}

AD26 if (currentDropzoneEl) {
currentDropzoneEl.after(snippetEl);
this.shared.dropzone.removeDropzones();

// Undo the changes needed to ease the drag and drop.
this.dragState.restoreCallbacks.forEach((restore) => restore());
this.dragState.restoreCallbacks = null;

if (!isSnippetGroup) {
await this.processDroppedSnippet(snippetEl);
delete this.cancelDragAndDrop;
} else {
this.shared.operation.next(
async () => {
Expand All @@ -357,13 +375,13 @@ export class BlockTab extends Component {
{ withLoadingEffect: false }
);
}
} else {
this.cancelDragAndDrop();
delete this.cancelDragAndDrop;
}

this.state.ongoingInsertion = false;
delete this.cancelSnippetPreview;
if (!isSnippetGroup) {
delete this.cancelDragAndDrop;
}
dragAndDropResolve();
},
};
Expand All @@ -382,7 +400,7 @@ export class BlockTab extends Component {
const cancel = await onSnippetDropped({ snippetEl, dragState: this.dragState });
// Cancel everything if the resource asked to.
if (cancel) {
this.cancelDragAndDrop?.();
this.cancelDragAndDrop();
return;
}
}
Expand Down
0