Skip to content

Commit 8f7df18

Browse files
loco-odooFrancoisGe
authored andcommitted
Do not start all plugins in translate mode
1 parent 6c4ac95 commit 8f7df18

19 files changed

+227
-120
lines changed

addons/html_builder/static/src/builder.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { CustomizeTab } from "./sidebar/customize_tab";
2525
import { ThemeTab } from "@html_builder/website_builder/plugins/theme/theme_tab";
2626
import { CORE_PLUGINS } from "./core/core_plugins";
2727
import { EDITOR_COLOR_CSS_VARIABLES, getCSSVariableValue } from "./utils/utils_css";
28+
import { withSequence } from "@html_editor/utils/resource";
2829

2930
export class Builder extends Component {
3031
static template = "html_builder.Builder";
@@ -76,7 +77,8 @@ export class Builder extends Component {
7677
"BannerPlugin",
7778
]
7879
);
79-
const Plugins = [...mainPlugins, ...CORE_PLUGINS, ...(this.props.Plugins || [])];
80+
const corePlugins = this.props.isTranslation ? [] : CORE_PLUGINS;
81+
const Plugins = [...mainPlugins, ...corePlugins, ...(this.props.Plugins || [])];
8082
// TODO: maybe do a different config for the translate mode and the
8183
// "regular" mode.
8284
this.editor = new Editor(
@@ -103,9 +105,9 @@ export class Builder extends Component {
103105
trigger_dom_updated: () => {
104106
editorBus.trigger("DOM_UPDATED");
105107
},
106-
on_mobile_preview_clicked: () => {
108+
on_mobile_preview_clicked: withSequence(20, () => {
107109
editorBus.trigger("DOM_UPDATED");
108-
},
110+
}),
109111
change_current_options_containers_listeners: (currentOptionsContainers) => {
110112
this.state.currentOptionsContainers = currentOptionsContainers;
111113
if (!currentOptionsContainers.length) {

addons/html_builder/static/src/builder.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
<BlockTab />
3535
</t>
3636
<t t-if="state.activeTab === 'customize'">
37-
<CustomizeTab currentOptionsContainers="state.currentOptionsContainers" snippetModel="snippetModel"/>
37+
<t t-if="props.isTranslation" t-call="html_builder.CustomizeTranslationTab"/>
38+
<CustomizeTab t-else="" currentOptionsContainers="state.currentOptionsContainers" snippetModel="snippetModel"/>
3839
</t>
3940
<t t-if="state.activeTab === 'theme'">
4041
<ThemeTab/>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class BuilderOptionsPlugin extends Plugin {
2020
"getContainers",
2121
"updateContainers",
2222
"deactivateContainers",
23+
"getTarget",
2324
"getPageContainers",
2425
"getRemoveDisabledReason",
2526
"getCloneDisabledReason",
@@ -150,6 +151,10 @@ export class BuilderOptionsPlugin extends Plugin {
150151
this.dispatchTo("change_current_options_containers_listeners", this.lastContainers);
151152
}
152153

154+
getTarget() {
155+
return this.target;
156+
}
157+
153158
deactivateContainers() {
154159
this.target = null;
155160
this.lastContainers = [];
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Plugin } from "@html_editor/plugin";
2+
import { registry } from "@web/core/registry";
3+
4+
export class BuilderOptionsPlugin extends Plugin {
5+
static id = "builder-options";
6+
static shared = ["deactivateContainers", "getTarget"];
7+
8+
deactivateContainers() {}
9+
getTarget() {}
10+
}
11+
12+
registry.category("translation-plugins").add(BuilderOptionsPlugin.id, BuilderOptionsPlugin);

addons/html_builder/static/src/core/builder_overlay/builder_overlay_plugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { throttleForAnimation } from "@web/core/utils/timing";
33
import { getScrollingElement, getScrollingTarget } from "@web/core/utils/scrolling";
44
import { checkElement } from "../builder_options_plugin";
55
import { BuilderOverlay, sizingY, sizingX, sizingGrid } from "./builder_overlay";
6+
import { withSequence } from "@html_editor/utils/resource";
67

78
function isResizable(el) {
89
const isResizableY = el.matches(sizingY.selector) && !el.matches(sizingY.exclude);
@@ -18,7 +19,7 @@ export class BuilderOverlayPlugin extends Plugin {
1819
resources = {
1920
step_added_handlers: this.refreshOverlays.bind(this),
2021
change_current_options_containers_listeners: this.openBuilderOverlays.bind(this),
21-
on_mobile_preview_clicked: this.refreshOverlays.bind(this),
22+
on_mobile_preview_clicked: withSequence(20, this.refreshOverlays.bind(this)),
2223
has_overlay_options: { hasOption: (el) => isResizable(el) },
2324
};
2425

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { omit } from "@web/core/utils/objects";
22
import { Plugin } from "@html_editor/plugin";
3+
import { withSequence } from "@html_editor/utils/resource";
34

45
export class DisableSnippetsPlugin extends Plugin {
56
static id = "disableSnippets";
67
static dependencies = ["setup_editor_plugin", "dropzone", "dropzone_selector"];
78
static shared = ["disableUndroppableSnippets"];
89
resources = {
910
after_remove_handlers: this.disableUndroppableSnippets.bind(this),
10-
on_mobile_preview_clicked: this.disableUndroppableSnippets.bind(this),
1111
post_undo_handlers: this.disableUndroppableSnippets.bind(this),
1212
post_redo_handlers: this.disableUndroppableSnippets.bind(this),
13+
on_mobile_preview_clicked: withSequence(20, this.disableUndroppableSnippets.bind(this)),
1314
};
1415

1516
setup() {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Plugin } from "@html_editor/plugin";
2+
import { registry } from "@web/core/registry";
3+
4+
export class DisableSnippetsPlugin extends Plugin {
5+
static id = "disableSnippets";
6+
static shared = ["disableUndroppableSnippets"];
7+
8+
disableUndroppableSnippets() {}
9+
}
10+
11+
registry.category("translation-plugins").add(DisableSnippetsPlugin.id, DisableSnippetsPlugin);

addons/html_builder/static/src/core/overlay_buttons/overlay_buttons_plugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { throttleForAnimation } from "@web/core/utils/timing";
44
import { getScrollingElement, getScrollingTarget } from "@web/core/utils/scrolling";
55
import { checkElement } from "../builder_options_plugin";
66
import { OverlayButtons } from "./overlay_buttons";
7+
import { withSequence } from "@html_editor/utils/resource";
78

89
export class OverlayButtonsPlugin extends Plugin {
910
static id = "overlayButtons";
@@ -17,7 +18,7 @@ export class OverlayButtonsPlugin extends Plugin {
1718
resources = {
1819
step_added_handlers: this.refreshButtons.bind(this),
1920
change_current_options_containers_listeners: this.addOverlayButtons.bind(this),
20-
on_mobile_preview_clicked: this.refreshButtons.bind(this),
21+
on_mobile_preview_clicked: withSequence(20, this.refreshButtons.bind(this)),
2122
};
2223

2324
setup() {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Plugin } from "@html_editor/plugin";
22
import { rpc } from "@web/core/network/rpc";
3+
import { registry } from "@web/core/registry";
34

45
const oeStructureSelector = "#wrapwrap .oe_structure[data-oe-xpath][data-oe-id]";
56
const oeFieldSelector = "#wrapwrap [data-oe-field]:not([data-oe-sanitize-prevent-edition])";
@@ -222,3 +223,4 @@ export class SavePlugin extends Plugin {
222223
}
223224
}
224225
}
226+
registry.category("translation-plugins").add(SavePlugin.id, SavePlugin);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Plugin } from "@html_editor/plugin";
22
import { _t } from "@web/core/l10n/translation";
33
import { getTranslationEditableEls } from "@html_builder/website_builder/plugins/translation_plugin";
4+
import { registry } from "@web/core/registry";
45

56
export class SetupEditorPlugin extends Plugin {
67
static id = "setup_editor_plugin";
@@ -103,3 +104,4 @@ export class SetupEditorPlugin extends Plugin {
103104
return editablesAreaEls;
104105
}
105106
}
107+
registry.category("translation-plugins").add(SetupEditorPlugin.id, SetupEditorPlugin);

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

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { Plugin } from "@html_editor/plugin";
22
import { isMobileView } from "@html_builder/utils/utils";
3+
import { registry } from "@web/core/registry";
4+
import { withSequence } from "@html_editor/utils/resource";
35

46
export class VisibilityPlugin extends Plugin {
57
static id = "visibility";
@@ -10,7 +12,7 @@ export class VisibilityPlugin extends Plugin {
1012
"onOptionVisibilityUpdate",
1113
];
1214
resources = {
13-
on_mobile_preview_clicked: this.onMobilePreviewClicked.bind(this),
15+
on_mobile_preview_clicked: withSequence(10, this.onMobilePreviewClicked.bind(this)),
1416
system_attributes: ["data-invisible"],
1517
system_classes: ["o_snippet_override_invisible"],
1618
};
@@ -60,17 +62,21 @@ export class VisibilityPlugin extends Plugin {
6062
}
6163

6264
onMobilePreviewClicked() {
63-
const isMobilePreview = isMobileView(this.editable);
6465
const invisibleOverrideEls = this.editable.querySelectorAll(
6566
".o_snippet_mobile_invisible, .o_snippet_desktop_invisible"
6667
);
6768
for (const invisibleOverrideEl of [...invisibleOverrideEls]) {
68-
const isMobileHidden = invisibleOverrideEl.classList.contains(
69-
"o_snippet_mobile_invisible"
70-
);
7169
invisibleOverrideEl.classList.remove("o_snippet_override_invisible");
72-
const show = isMobilePreview !== isMobileHidden;
73-
this.toggleVisibilityStatus(invisibleOverrideEl, show);
70+
const show = this.toggleVisibilityStatus({
71+
editingEl: invisibleOverrideEl,
72+
considerDeviceVisibility: true,
73+
});
74+
if (
75+
!show &&
76+
invisibleOverrideEl.contains(this.dependencies["builder-options"].getTarget())
77+
) {
78+
this.dependencies["builder-options"].deactivateContainers();
79+
}
7480
}
7581
}
7682

@@ -83,7 +89,7 @@ export class VisibilityPlugin extends Plugin {
8389
* @returns {Boolean}
8490
*/
8591
toggleTargetVisibility(editingEl, show, considerDeviceVisibility) {
86-
show = this.toggleVisibilityStatus(editingEl, show, considerDeviceVisibility);
92+
show = this.toggleVisibilityStatus({ editingEl, show, considerDeviceVisibility });
8793
const dispatchName = show ? "target_show" : "target_hide";
8894
this.dispatchTo(dispatchName, editingEl);
8995
return show;
@@ -96,8 +102,7 @@ export class VisibilityPlugin extends Plugin {
96102
* @param {Boolean} show true/false if the element was shown/hidden
97103
*/
98104
onOptionVisibilityUpdate(editingEl, show) {
99-
const isShown = this.toggleVisibilityStatus(editingEl, show);
100-
105+
const isShown = this.toggleVisibilityStatus({ editingEl, show });
101106
if (!isShown) {
102107
this.dependencies["builder-options"].deactivateContainers();
103108
}
@@ -114,18 +119,14 @@ export class VisibilityPlugin extends Plugin {
114119
* @param {Boolean} considerDeviceVisibility
115120
* @returns {Boolean}
116121
*/
117-
toggleVisibilityStatus(editingEl, show, considerDeviceVisibility) {
122+
toggleVisibilityStatus({ editingEl, show, considerDeviceVisibility = false }) {
118123
if (
119124
considerDeviceVisibility &&
120125
editingEl.matches(".o_snippet_mobile_invisible, .o_snippet_desktop_invisible")
121126
) {
122127
const isMobilePreview = isMobileView(editingEl);
123128
const isMobileHidden = editingEl.classList.contains("o_snippet_mobile_invisible");
124-
if (isMobilePreview === isMobileHidden) {
125-
// If the preview mode and the hidden type are the same, the
126-
// element is considered as hidden.
127-
show = false;
128-
}
129+
show = isMobilePreview !== isMobileHidden;
129130
}
130131

131132
if (show === undefined) {
@@ -143,3 +144,5 @@ export class VisibilityPlugin extends Plugin {
143144
function isTargetVisible(editingEl) {
144145
return editingEl.dataset.invisible !== "1";
145146
}
147+
148+
registry.category("translation-plugins").add(VisibilityPlugin.id, VisibilityPlugin);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<templates xml:space="preserve">
3+
4+
<t t-name="html_builder.CustomizeTranslationTab">
5+
<div class="o_customize_tab h-100">
6+
<div class="text-center pt-5">
7+
Select content on your page to translate it.
8+
</div>
9+
</div>
10+
</t>
11+
12+
</templates>

addons/html_builder/static/src/website_builder/plugins/options/popup_option_plugin.js

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const COOKIES_BAR = SNIPPET_SPECIFIC_END;
99

1010
class PopupOptionPlugin extends Plugin {
1111
static id = "PopupOption";
12-
static dependencies = ["anchor", "visibility", "history"];
12+
static dependencies = ["anchor", "visibility", "history", "popupVisibilityPlugin"];
1313

1414
resources = {
1515
builder_options: [
@@ -34,24 +34,8 @@ class PopupOptionPlugin extends Plugin {
3434
on_cloned_handlers: this.onCloned.bind(this),
3535
on_remove_handlers: this.onRemove.bind(this),
3636
on_snippet_dropped_handlers: this.onSnippetDropped.bind(this),
37-
target_show: this.onTargetShow.bind(this),
38-
target_hide: this.onTargetHide.bind(this),
39-
clean_for_save_handlers: this.cleanForSave.bind(this),
4037
};
4138

42-
setup() {
43-
this.addDomListener(this.editable, "click", (ev) => {
44-
// Note: links are excluded here so that internal modal buttons do
45-
// not close the popup as we want to allow edition of those buttons.
46-
if (ev.target.matches(".s_popup .js_close_popup:not(a, .btn)")) {
47-
ev.stopPropagation();
48-
const popupEl = ev.target.closest(".s_popup");
49-
this.onTargetHide(popupEl);
50-
this.dependencies.visibility.onOptionVisibilityUpdate(popupEl, false);
51-
}
52-
});
53-
}
54-
5539
getActions() {
5640
return {
5741
// Moves the snippet in #o_shared_blocks to be common to all pages
@@ -115,11 +99,11 @@ class PopupOptionPlugin extends Plugin {
11599
}
116100

117101
onRemove(el) {
118-
this.onTargetHide(el);
102+
this.dependencies.popupVisibilityPlugin.onTargetHide(el);
119103
this.dependencies.history.addCustomMutation({
120104
apply: () => {},
121105
revert: () => {
122-
this.onTargetShow(el);
106+
this.dependencies.popupVisibilityPlugin.onTargetShow(el);
123107
},
124108
});
125109
}
@@ -129,10 +113,10 @@ class PopupOptionPlugin extends Plugin {
129113
this.assignUniqueID(snippetEl);
130114
this.dependencies.history.addCustomMutation({
131115
apply: () => {
132-
this.onTargetShow(snippetEl);
116+
this.dependencies.popupVisibilityPlugin.onTargetShow(snippetEl);
133117
},
134118
revert: () => {
135-
this.onTargetHide(snippetEl);
119+
this.dependencies.popupVisibilityPlugin.onTargetHide(snippetEl);
136120
},
137121
});
138122
}
@@ -142,32 +126,6 @@ class PopupOptionPlugin extends Plugin {
142126
);
143127
}
144128

145-
onTargetShow(target) {
146-
// Check if the popup is within the editable, because it is cloned on
147-
// save (see save plugin) and Bootstrap moves it if it is not within the
148-
// document (see Bootstrap Modal's _showElement).
149-
if (target.matches(".s_popup") && this.editable.contains(target)) {
150-
this.window.Modal.getOrCreateInstance(target.querySelector(".modal")).show();
151-
}
152-
}
153-
154-
onTargetHide(target) {
155-
if (target.matches(".s_popup")) {
156-
this.window.Modal.getOrCreateInstance(target.querySelector(".modal")).hide();
157-
}
158-
}
159-
160-
cleanForSave({ root }) {
161-
for (const modalEl of root.querySelectorAll(".s_popup .modal.show")) {
162-
modalEl.parentElement.dataset.invisible = "1";
163-
// Do not call .hide() directly, because it is queued whereas
164-
// .dispose() is not.
165-
modalEl.classList.remove("show");
166-
this.window.Modal.getOrCreateInstance(modalEl)._hideModal();
167-
this.window.Modal.getInstance(modalEl).dispose();
168-
}
169-
}
170-
171129
assignUniqueID(editingElement) {
172130
editingElement.closest(".s_popup").id = `sPopup${Date.now()}`;
173131
}

0 commit comments

Comments
 (0)