Skip to content

Commit 01df2cf

Browse files
sobo-odooFrancoisGe
authored andcommitted
Display the editor messages (dropzone) only when needed + fix them
1 parent 505c8cd commit 01df2cf

File tree

3 files changed

+69
-16
lines changed

3 files changed

+69
-16
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,27 @@ export class DropZonePlugin extends Plugin {
212212
* This allows to add data on the dropzone depending on the hook
213213
* environment.
214214
* TODO
215-
*
215+
* @param {HTMLElement} hookEl the dropzone parent
216216
* @param {boolean} [vertical=false]
217217
* @param {Object} [style]
218218
* @returns {HTMLElement}
219219
*/
220-
createDropzone(isVertical, style) {
220+
createDropzone(hookEl, isVertical, style) {
221221
const dropzoneEl = this.document.createElement("div");
222222
dropzoneEl.classList.add("oe_drop_zone", "oe_insert");
223-
dropzoneEl.dataset.editorMessage = _t("DRAG BUILDING BLOCKS HERE");
223+
224+
// Set the messages to display in the dropzone.
225+
const editorMessagesAttributes = [
226+
"data-editor-message-default",
227+
"data-editor-message",
228+
"data-editor-sub-message",
229+
];
230+
for (const messageAttribute of editorMessagesAttributes) {
231+
const message = hookEl.getAttribute(messageAttribute);
232+
if (message) {
233+
dropzoneEl.setAttribute(messageAttribute, message);
234+
}
235+
}
224236

225237
if (isVertical) {
226238
dropzoneEl.classList.add("oe_vertical");
@@ -305,17 +317,17 @@ export class DropZonePlugin extends Plugin {
305317
const targets = [];
306318
for (const el of selectorChildren) {
307319
targets.push(...el.children);
308-
el.prepend(this.createDropzone());
320+
el.prepend(this.createDropzone(el));
309321
}
310322
targets.push(...selectorSiblings);
311323

312324
for (const target of targets) {
313325
if (!target.nextElementSibling?.classList.contains("oe_drop_zone")) {
314-
target.after(this.createDropzone());
326+
target.after(this.createDropzone(target.parentElement));
315327
}
316328

317329
if (!target.previousElementSibling?.classList.contains("oe_drop_zone")) {
318-
target.before(this.createDropzone());
330+
target.before(this.createDropzone(target.parentElement));
319331
}
320332
}
321333

addons/html_builder/static/src/core/editor.inside.scss

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// This style block is about the "editor message" which highlights the areas
2-
// where the user can drag & drop snippets.
31
$-editor-messages-margin-x: 2%;
42

53
%o-editor-messages {
@@ -15,34 +13,77 @@ $-editor-messages-margin-x: 2%;
1513
font-size: 20px;
1614
}
1715

16+
// Show the default editor message only for "empty" elements
17+
&:not(:empty) {
18+
&[data-editor-message-default]:before {
19+
content: none;
20+
}
21+
}
22+
1823
&:after {
1924
content: attr(data-editor-sub-message);
2025
display: block;
2126
}
2227
}
2328

29+
// This style block is about the "editor message" which highlights the areas
30+
// where the user can drag & drop snippets.
2431
.o_editable {
2532
&.oe_structure.oe_empty, &[data-oe-type=html], .oe_structure.oe_empty {
26-
&:empty {
33+
34+
// Base case (website.page (#wrap), t-field (product description), ...)
35+
> .oe_drop_zone.oe_insert:not(.oe_vertical) {
36+
@extend %o-editor-messages;
37+
height: auto;
38+
39+
// Empty editable element during drag & drop
40+
&:only-child {
41+
width: 100% - 2 * $-editor-messages-margin-x;
42+
padding: 12px 0;
43+
margin: 20px $-editor-messages-margin-x;
44+
}
45+
46+
&:not(:only-child) {
47+
&::before {
48+
font-size: 16px;
49+
}
50+
51+
&[data-editor-message-default]::before {
52+
content: none;
53+
}
54+
}
55+
}
56+
57+
// Exception 1: empty wrap NOT during drag & drop
58+
&#wrap:empty {
2759
@extend %o-editor-messages;
2860
padding: 112px 0px;
2961
margin: 20px $-editor-messages-margin-x;
3062
border-radius: $border-radius-lg;
3163
}
3264

33-
.oe_drop_zone.oe_insert:only-child {
34-
@extend %o-editor-messages;
35-
height: auto;
36-
width: 100% - 2 * $-editor-messages-margin-x;
37-
padding: 112px 0;
38-
margin: 20px $-editor-messages-margin-x;
65+
// Exception 2: empty wrap during drag & drop (override of base case)
66+
&#wrap > .oe_drop_zone.oe_insert:not(.oe_vertical):only-child {
67+
padding: 112px 0px;
3968
text-shadow: none;
4069
}
4170

4271
> p:empty:only-child {
4372
color: #aaa;
4473
}
4574
}
75+
76+
&[data-oe-type=html].oe_empty:empty {
77+
@extend %o-editor-messages;
78+
}
79+
}
80+
81+
.oe_structure_solo > .oe_drop_zone {
82+
// TODO implement something more robust. This is currently for our only
83+
// use case of oe_structure_solo: the footer. The dropzone in there need to
84+
// be 1px lower that the end-of-page dropzone to distinguish them. The
85+
// usability has to be reviewed anyway.
86+
transform: translateY(10px); // For some reason "1px" is not enough...
4687
}
4788

4889
.o-we-hint {

addons/html_builder/static/tests/drop_zone.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ describe.current.tags("desktop");
77

88
const dropzone = (hovered = false) => {
99
const highlightClass = hovered ? " o_dropzone_highlighted" : "";
10-
return `<div class="oe_drop_zone oe_insert${highlightClass}" data-editor-message="DRAG BUILDING BLOCKS HERE"></div>`;
10+
return `<div class="oe_drop_zone oe_insert${highlightClass}" data-editor-message-default="true" data-editor-message="DRAG BUILDING BLOCKS HERE"></div>`;
1111
};
1212

1313
test("#wrap element has the 'DRAG BUILDING BLOCKS HERE' message", async () => {

0 commit comments

Comments
 (0)