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

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
Diff view
Diff view
Prev Previous commit
Scroll to the clone and activate its option only if needed
  • Loading branch information
sobo-odoo committed May 20, 2025
commit 0d217dcea8e3c26e89b61160b0be1d8d0608c9fc
32 changes: 25 additions & 7 deletions addons/html_builder/static/src/core/clone_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,43 @@ export class ClonePlugin extends Plugin {
title: _t("Duplicate"),
disabledReason,
handler: () => {
this.cloneElement(this.overlayTarget, { scrollToClone: true });
this.cloneElement(this.overlayTarget, { activateClone: false });
this.dependencies.history.addStep();
},
});
return buttons;
}

cloneElement(el, { position = "afterend", scrollToClone = false } = {}) {
/**
* Duplicates the given element and returns the created clone.
*
* @param {HTMLElement} el the element to clone
* @param {Object}
* - `position`: specifies where to position the clone (first parameter of
* the `insertAdjacentElement` function)
* - `scrollToClone`: true if the we should scroll to the clone (if not in
* the viewport), false otherwise
* - `activateClone`: true if the option containers of the clone should be
* the active ones, false otherwise
* @returns {HTMLElement}
*/
cloneElement(el, { position = "afterend", scrollToClone = false, activateClone = true } = {}) {
this.dispatchTo("on_will_clone_handlers", { originalEl: el });
// TODO cleanUI resource for each option
const cloneEl = el.cloneNode(true);
this.cleanElement(cloneEl);
this.cleanElement(cloneEl); // TODO check that
el.insertAdjacentElement(position, cloneEl);
this.dependencies["builder-options"].updateContainers(cloneEl);
this.dispatchTo("on_cloned_handlers", { cloneEl: cloneEl, originalEl: el });

// Update the containers if required.
if (activateClone) {
this.dependencies["builder-options"].updateContainers(cloneEl);
}

// Scroll to the clone if required and if it is not visible.
if (scrollToClone && !isElementInViewport(cloneEl)) {
cloneEl.scrollIntoView({ behavior: "smooth", block: "center" });
}
// TODO snippet_cloned ?

this.dispatchTo("on_cloned_handlers", { cloneEl: cloneEl, originalEl: el });
return cloneEl;
}

Expand Down
2 changes: 1 addition & 1 deletion addons/html_builder/static/src/sidebar/option_container.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class OptionsContainer extends BaseOptionComponent {
cloneElement() {
this.callOperation(() => {
this.env.editor.shared.clone.cloneElement(this.props.editingElement, {
scrollToClone: true,
activateClone: false,
});
});
}
Expand Down
0