Skip to content

Commit 94e99ab

Browse files
committed
Add missing check for parent not editable for element to be unremovable
1 parent 69a777b commit 94e99ab

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
@@ -149,3 +149,25 @@ export function getSelectorParams(builderOptions, optionClass) {
149149
}
150150
return selectorParams;
151151
}
152+
153+
/**
154+
* Checks if the given element is editable.
155+
*
156+
* @param {HTMLElement} node the element
157+
* @returns {Boolean}
158+
*/
159+
export function isEditable(node) {
160+
let currentNode = node;
161+
while (currentNode) {
162+
if (currentNode.className && typeof currentNode.className === "string") {
163+
if (currentNode.className.includes("o_not_editable")) {
164+
return false;
165+
}
166+
if (currentNode.className.includes("o_editable")) {
167+
return true;
168+
}
169+
}
170+
currentNode = currentNode.parentNode;
171+
}
172+
return false;
173+
}

0 commit comments

Comments
 (0)