From 7498d58edc8d54f8888f6e732b297cd4a0f967fe Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Fri, 11 Dec 2020 09:50:54 +0000 Subject: [PATCH] [IMP] web_editor: update Jabberwock library to commit b8d73691 Changelog: [IMP] Odoo: allow empty structure nodes [IMP] Odoo: expand parsing range of OdooStructureNode [FIX] DomHelpers: removeNodes only when they exist [FIX] withDomMutations : getParentModifiers [FIX] withDomMutations: don't get node loosely [FIX] withDomMutations: remove the proper observer [FIX] OdooField: do not apply empty class if placeholder [FIX] OdooWebsiteEditor: add expected Theme plugin X-original-commit: 537c3318a6f2751d83a011345602456125420590 --- .../static/lib/jabberwock/jabberwock.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/addons/web_editor/static/lib/jabberwock/jabberwock.js b/addons/web_editor/static/lib/jabberwock/jabberwock.js index 5b683e805f7..1e31b72f24b 100644 --- a/addons/web_editor/static/lib/jabberwock/jabberwock.js +++ b/addons/web_editor/static/lib/jabberwock/jabberwock.js @@ -20068,7 +20068,10 @@ odoo.define('web_editor.jabberwock', (function(require) { if (!node.fieldInfo.isValid.get()) { classList.add('jw-odoo-field-invalid'); } - if (!node.descendants(AtomicNode).length) { + if (!node.descendants(AtomicNode).length && + // A placeholder is visible, we don't want to collapse the field if + // it gives the impression of having content. + !node.modifiers.find(Attributes).has('placeholder')) { classList.add('jw-odoo-field-empty'); } container.attributes.class = classList; @@ -21809,6 +21812,7 @@ odoo.define('web_editor.jabberwock', (function(require) { super(params); this.breakable = false; this.dirty = false; + this.allowEmpty = true; this.xpath = params.xpath; this.viewId = params.viewId; } @@ -21818,9 +21822,12 @@ odoo.define('web_editor.jabberwock', (function(require) { constructor() { super(...arguments); this.predicate = (item) => { + var _a, _b; return (item instanceof Element && - item.classList.contains('oe_structure') && item.attributes && + (item.classList.contains('oe_structure') || + (((_a = item.attributes['data-oe-model']) === null || _a === void 0 ? void 0 : _a.value) === 'ir.ui.view' && + ((_b = item.attributes['data-oe-field']) === null || _b === void 0 ? void 0 : _b.value) === 'arch')) && item.attributes['data-oe-xpath'] && item.attributes['data-oe-id']); }; @@ -24075,6 +24082,7 @@ odoo.define('web_editor.jabberwock', (function(require) { [Iframe], [Button], [ReactiveEditorInfo], + [Theme], ...(options.plugins || []), ], }); @@ -24451,7 +24459,7 @@ odoo.define('web_editor.jabberwock', (function(require) { for (const mutation of mutations) { if (mutation.type === 'attributes') { const formats = getFormats(domEngine, mutation.target); - let vnodesOrFormats = ((formats === null || formats === void 0 ? void 0 : formats.length) && formats) || domEngine.getNodes(mutation.target); + let vnodesOrFormats = ((formats === null || formats === void 0 ? void 0 : formats.length) && formats) || domEngine.getNodes(mutation.target, false); const value = mutation.target.getAttribute(mutation.attributeName); if (vnodesOrFormats.length) { if (vnodesOrFormats[0] instanceof ContainerNode) { @@ -24521,7 +24529,7 @@ odoo.define('web_editor.jabberwock', (function(require) { for (const [observerNode, activeObservation] of activeObservers.entries()) { // The observation might have been already removed by another call // so we only delete and disconnect when it's still active. - if (activeObservation === activeObservation) { + if (activeObservation === observer) { activeObservers.delete(observerNode); observer.disconnect(); break; @@ -24555,6 +24563,8 @@ odoo.define('web_editor.jabberwock', (function(require) { break; ancestorsFormats.push(format); } + if (!ancestorsFormats.length) + return []; const greatestAncestorVNode = getVNodes(ancestors[0]); const allParentFormat = greatestAncestorVNode[0].modifiers.filter(m => m instanceof Format); // Now we can retrieve the format of `inlineNode`. @@ -24678,7 +24688,7 @@ odoo.define('web_editor.jabberwock', (function(require) { function removeNodes(originalParents, removedDomNodes, getVNode, getFirstFormat, replacementMap) { for (const removedDomNode of removedDomNodes) { const removedVNodes = getVNode(removedDomNode); - if (removedVNodes) { + if (removedVNodes === null || removedVNodes === void 0 ? void 0 : removedVNodes.length) { const firstVNode = removedVNodes[0]; // If we remove a text node that has a format, as no textnode will // represent the format after removing it, we need to insert an