Skip to content

Commit 64d40ee

Browse files
committed
Add missing check for parent not editable for element to be unremovable
1 parent 7455c8f commit 64d40ee

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

addons/html_builder/static/src/core/remove_plugin.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { resizeGrid } from "@html_builder/utils/grid_layout_utils";
55
import { getVisibleSibling } from "./move_plugin";
66
import { unremovableNodePredicates as deletePluginPredicates } from "@html_editor/core/delete_plugin";
77
import { isUnremovableQWebElement as qwebPluginPredicate } from "@html_editor/others/qweb_plugin";
8+
import { isEditable } from "@html_builder/utils/utils";
89

910
// TODO (see forceNoDeleteButton) make a resource in the options plugins to not
1011
// duplicate some selectors.
@@ -18,12 +19,10 @@ const unremovableSelectors = [
1819
".s_table_of_content_navbar_wrap",
1920
".s_table_of_content_main",
2021
".nav-item",
21-
"header",
22-
"main",
23-
"footer",
2422
].join(", ");
2523

2624
const unremovableNodePredicates = [
25+
(node) => !isEditable(node.parentNode),
2726
...deletePluginPredicates,
2827
qwebPluginPredicate,
2928
(node) => node.parentNode.matches('[data-oe-type="image"]'),

addons/html_builder/static/src/utils/utils.js

+22
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,25 @@ export function getSelectorParams(builderOptions, optionClass) {
150150
}
151151
return selectorParams;
152152
}
153+
154+
/**
155+
* Checks if the given element is editable.
156+
*
157+
* @param {HTMLElement} node the element
158+
* @returns {Boolean}
159+
*/
160+
export function isEditable(node) {
161+
let currentNode = node;
162+
while (currentNode) {
163+
if (currentNode.className && typeof currentNode.className === "string") {
164+
if (currentNode.className.includes("o_not_editable")) {
165+
return false;
166+
}
167+
if (currentNode.className.includes("o_editable")) {
168+
return true;
169+
}
170+
}
171+
currentNode = currentNode.parentNode;
172+
}
173+
return false;
174+
}

0 commit comments

Comments
 (0)