@gem-sdk/pages 1.23.0-staging.34 → 1.23.0-staging.349
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/builder/Toolbar.js +317 -149
- package/dist/cjs/components/builder/Toolbox.js +106 -53
- package/dist/cjs/components/builder/toolbar/Onboarding.js +110 -0
- package/dist/cjs/components/image-to-layout/AddSectionImageToLayout.js +1 -7
- package/dist/cjs/components/image-to-layout/DropElement.js +128 -87
- package/dist/cjs/components/image-to-layout/ImageToLayout.js +2 -8
- package/dist/cjs/libs/api/get-home-page-props-v2.js +3 -1
- package/dist/cjs/libs/api/get-static-page-props-preview.js +3 -1
- package/dist/cjs/libs/google-fonts.js +6 -1
- package/dist/cjs/libs/helpers/gen-fonts.js +15 -4
- package/dist/cjs/pages/builder.js +43 -41
- package/dist/cjs/pages/collection-detail.js +12 -10
- package/dist/cjs/pages/product-detail.js +18 -16
- package/dist/cjs/pages/static-v2.js +14 -12
- package/dist/cjs/pages/static.js +13 -11
- package/dist/esm/components/builder/Toolbar.js +318 -150
- package/dist/esm/components/builder/Toolbox.js +107 -54
- package/dist/esm/components/builder/toolbar/Onboarding.js +106 -0
- package/dist/esm/components/image-to-layout/AddSectionImageToLayout.js +1 -7
- package/dist/esm/components/image-to-layout/DropElement.js +128 -87
- package/dist/esm/components/image-to-layout/ImageToLayout.js +2 -8
- package/dist/esm/libs/api/get-home-page-props-v2.js +4 -2
- package/dist/esm/libs/api/get-static-page-props-preview.js +4 -2
- package/dist/esm/libs/google-fonts.js +6 -1
- package/dist/esm/libs/helpers/gen-fonts.js +15 -4
- package/dist/esm/pages/builder.js +44 -42
- package/dist/esm/pages/collection-detail.js +13 -11
- package/dist/esm/pages/product-detail.js +19 -17
- package/dist/esm/pages/static-v2.js +15 -13
- package/dist/esm/pages/static.js +14 -12
- package/dist/types/index.d.ts +1 -0
- package/package.json +3 -3
- package/dist/cjs/components/image-to-layout/ImageToLayoutInput.js +0 -193
- package/dist/cjs/components/image-to-layout/PagesSuggestion.js +0 -80
- package/dist/esm/components/image-to-layout/ImageToLayoutInput.js +0 -191
- package/dist/esm/components/image-to-layout/PagesSuggestion.js +0 -78
|
@@ -2,36 +2,150 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
5
6
|
var react = require('react');
|
|
7
|
+
var Onboarding = require('./toolbar/Onboarding.js');
|
|
6
8
|
|
|
7
9
|
const TOOLBAR_HOVER_HEIGHT = 24;
|
|
8
10
|
const TOOLBAR_ACTIVE_HEIGHT = 32;
|
|
11
|
+
const getDOMElementParents = ($el, selector, limit)=>{
|
|
12
|
+
// Set up a parent array
|
|
13
|
+
const parents = [];
|
|
14
|
+
// Push each parent $elms to the array
|
|
15
|
+
while($el){
|
|
16
|
+
$el = $el.parentElement ?? undefined;
|
|
17
|
+
if ($el) {
|
|
18
|
+
if ($el.tagName === 'BODY' || $el.getAttribute('data-uid') === 'ROOT') {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
if (selector) {
|
|
22
|
+
if ($el.matches(selector)) {
|
|
23
|
+
parents.push($el);
|
|
24
|
+
if (limit && parents.length == limit) {
|
|
25
|
+
return parents;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
parents.push($el);
|
|
31
|
+
if (limit && parents.length == limit) {
|
|
32
|
+
return parents;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// Return our parent array
|
|
37
|
+
return parents;
|
|
38
|
+
};
|
|
39
|
+
const getChildrenByAttrSelector = ($el, attrSelector)=>{
|
|
40
|
+
const childLen = $el.children.length;
|
|
41
|
+
if (childLen) {
|
|
42
|
+
for(let i = 0; i < childLen; i++){
|
|
43
|
+
const children = $el.children[i];
|
|
44
|
+
if (children) {
|
|
45
|
+
const is = children.getAttribute(attrSelector);
|
|
46
|
+
if (is) {
|
|
47
|
+
return children;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const isOverParent = ({ current, parent: parent1, index, revert })=>{
|
|
54
|
+
for(let i = 0; i < index; i++){
|
|
55
|
+
let is = current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent1.top && current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent1.top + parent1.height || current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent1.top + parent1.height && current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent1.top;
|
|
56
|
+
if (revert) {
|
|
57
|
+
is = current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent1.bottom && current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent1.bottom - parent1.height || current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent1.bottom - parent1.height && current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent1.bottom;
|
|
58
|
+
}
|
|
59
|
+
if (is) return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
};
|
|
63
|
+
const waitForElementToExist = (selector, timeout = 200)=>{
|
|
64
|
+
return new Promise((resolve)=>{
|
|
65
|
+
const intervalID = setInterval(()=>{
|
|
66
|
+
const el = document.querySelector(selector);
|
|
67
|
+
if (el) {
|
|
68
|
+
clearInterval(intervalID);
|
|
69
|
+
clearTimeout(timeoutID);
|
|
70
|
+
resolve(el);
|
|
71
|
+
}
|
|
72
|
+
}, 50);
|
|
73
|
+
const timeoutID = setTimeout(()=>{
|
|
74
|
+
clearInterval(intervalID);
|
|
75
|
+
clearTimeout(timeoutID);
|
|
76
|
+
resolve(null);
|
|
77
|
+
}, timeout);
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
const notVisible = (el)=>{
|
|
81
|
+
const overflow = getComputedStyle(el).overflow;
|
|
82
|
+
return overflow !== 'visible';
|
|
83
|
+
};
|
|
84
|
+
const isSection = (el)=>{
|
|
85
|
+
const tag = el.getAttribute('data-component-tag');
|
|
86
|
+
return tag === 'Section';
|
|
87
|
+
};
|
|
88
|
+
const isLayoutElement = (el)=>{
|
|
89
|
+
const tag = el.getAttribute('data-component-tag');
|
|
90
|
+
return tag === 'Row' || tag === 'Product';
|
|
91
|
+
};
|
|
92
|
+
const isPopup = (el)=>{
|
|
93
|
+
const tag = el.getAttribute('data-component-tag');
|
|
94
|
+
return tag === 'Dialog';
|
|
95
|
+
};
|
|
96
|
+
const isSticky = (el)=>{
|
|
97
|
+
const tag = el.getAttribute('data-component-tag');
|
|
98
|
+
return tag === 'Sticky';
|
|
99
|
+
};
|
|
9
100
|
const Toolbar = ()=>{
|
|
10
101
|
const currentComponentActive = react.useRef(null);
|
|
11
102
|
const isDragging = react.useRef(false);
|
|
12
|
-
const
|
|
103
|
+
const stopWatchReRenderComponent = react.useRef();
|
|
13
104
|
const isResizeSpacing = react.useRef(false);
|
|
105
|
+
const [isOnboarding, setIsOnboarding] = react.useState(false);
|
|
106
|
+
const [countShowOnboarding, setCountShowOnboarding] = react.useState(0);
|
|
107
|
+
const [onboardingPosition, setOnboardingPosition] = react.useState('bottom');
|
|
108
|
+
const timeoutRef = react.useRef(null);
|
|
109
|
+
const timeoutOnboarding = 5000;
|
|
14
110
|
/* Functions */ const changePositionToolbar = ({ state, $toolbar, $component })=>{
|
|
15
111
|
const $parentOverflow = findOverflowParent($component, $toolbar);
|
|
112
|
+
const rect = $toolbar.getBoundingClientRect();
|
|
113
|
+
const rectComponent = $component.getBoundingClientRect();
|
|
114
|
+
const windowWidth = window.innerWidth;
|
|
16
115
|
if ($parentOverflow) {
|
|
17
|
-
|
|
18
|
-
if (rect?.height <= 60) {
|
|
116
|
+
if (rectComponent?.height <= 60) {
|
|
19
117
|
$toolbar.setAttribute(`data-toolbar-${state}-revert`, 'true');
|
|
20
118
|
} else {
|
|
21
119
|
$toolbar.setAttribute(`data-toolbar-${state}-inside`, 'true');
|
|
22
120
|
}
|
|
121
|
+
// fix toolbar overflow right side
|
|
122
|
+
if (rectComponent.left + rect.width > windowWidth) {
|
|
123
|
+
$toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
|
|
124
|
+
}
|
|
23
125
|
} else {
|
|
24
|
-
|
|
25
|
-
if (rectComponent.top < TOOLBAR_ACTIVE_HEIGHT + 1) {
|
|
126
|
+
if (rect.top < TOOLBAR_ACTIVE_HEIGHT + 1) {
|
|
26
127
|
if (rectComponent?.height <= 60) {
|
|
27
128
|
$toolbar.setAttribute(`data-toolbar-${state}-revert`, 'true');
|
|
28
129
|
} else {
|
|
29
130
|
$toolbar.setAttribute(`data-toolbar-${state}-inside`, 'true');
|
|
30
131
|
}
|
|
31
132
|
}
|
|
133
|
+
// fix toolbar overflow right side
|
|
134
|
+
if (rectComponent.left + rect.width > windowWidth) {
|
|
135
|
+
$toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// fix Popup overflow right position
|
|
139
|
+
const popupEl = $component?.closest('[aria-label="Dialog body"]');
|
|
140
|
+
if (popupEl) {
|
|
141
|
+
const rectPopupEl = popupEl.getBoundingClientRect();
|
|
142
|
+
const popupElRightPosition = rectPopupEl.left + rectPopupEl.width - 20;
|
|
143
|
+
if (rectComponent.left + rect.width > popupElRightPosition) {
|
|
144
|
+
$toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
|
|
145
|
+
}
|
|
32
146
|
}
|
|
33
147
|
};
|
|
34
|
-
const setHoverComponent = react.useCallback(({ $component, componentUid, focus, isThemeSection })=>{
|
|
148
|
+
const setHoverComponent = react.useCallback(({ $component, componentUid, focus, isThemeSection, isParent })=>{
|
|
35
149
|
if (!$component && !componentUid) return;
|
|
36
150
|
if (!$component) {
|
|
37
151
|
const $c = document.querySelector(`[data-uid="${componentUid}"]`);
|
|
@@ -53,7 +167,9 @@ const Toolbar = ()=>{
|
|
|
53
167
|
}
|
|
54
168
|
if ($toolbar) {
|
|
55
169
|
$toolbar.removeAttribute('style');
|
|
56
|
-
|
|
170
|
+
if (!isParent) {
|
|
171
|
+
$toolbar.setAttribute('data-toolbar-hover', 'true');
|
|
172
|
+
}
|
|
57
173
|
if (focus) {
|
|
58
174
|
$toolbar.setAttribute('data-toolbar-hover-focus', 'true');
|
|
59
175
|
}
|
|
@@ -65,6 +181,9 @@ const Toolbar = ()=>{
|
|
|
65
181
|
}
|
|
66
182
|
if ($outline) {
|
|
67
183
|
$outline.setAttribute('data-outline-hover', 'true');
|
|
184
|
+
if (isParent) {
|
|
185
|
+
$outline.setAttribute('data-outline-parent-hover', 'true');
|
|
186
|
+
}
|
|
68
187
|
if (isThemeSection) {
|
|
69
188
|
$outline.setAttribute('data-outline-overlay-theme-section', 'true');
|
|
70
189
|
}
|
|
@@ -73,10 +192,14 @@ const Toolbar = ()=>{
|
|
|
73
192
|
}
|
|
74
193
|
}
|
|
75
194
|
if ($btnAddTop) {
|
|
76
|
-
|
|
195
|
+
if (!isParent) {
|
|
196
|
+
$btnAddTop.setAttribute('data-toolbar-add-hover', 'true');
|
|
197
|
+
}
|
|
77
198
|
}
|
|
78
199
|
if ($btnAddBottom) {
|
|
79
|
-
|
|
200
|
+
if (!isParent) {
|
|
201
|
+
$btnAddBottom.setAttribute('data-toolbar-add-hover', 'true');
|
|
202
|
+
}
|
|
80
203
|
}
|
|
81
204
|
}, []);
|
|
82
205
|
const setHoverComponentParents = react.useCallback(({ $component, componentUid })=>{
|
|
@@ -85,12 +208,13 @@ const Toolbar = ()=>{
|
|
|
85
208
|
if (!$c) return;
|
|
86
209
|
$component = $c;
|
|
87
210
|
}
|
|
88
|
-
const $parents = getDOMElementParents($component, '[data-uid][data-component-type="component"]:not([data-component-no-setting])');
|
|
211
|
+
const $parents = getDOMElementParents($component, '[data-uid][data-component-type="component"]:not([data-component-no-setting])', 1);
|
|
89
212
|
if ($parents.length) {
|
|
90
213
|
for (const $parent of $parents){
|
|
91
214
|
if ($parent) {
|
|
92
215
|
setHoverComponent({
|
|
93
|
-
$component: $parent
|
|
216
|
+
$component: $parent,
|
|
217
|
+
isParent: true
|
|
94
218
|
});
|
|
95
219
|
}
|
|
96
220
|
}
|
|
@@ -167,7 +291,9 @@ const Toolbar = ()=>{
|
|
|
167
291
|
'data-toolbar-hover-revert',
|
|
168
292
|
'data-toolbar-hover-inside',
|
|
169
293
|
'data-outline-hover',
|
|
170
|
-
'data-toolbar-add-hover'
|
|
294
|
+
'data-toolbar-add-hover',
|
|
295
|
+
'data-outline-parent-hover',
|
|
296
|
+
'data-toolbar-hover-overflow'
|
|
171
297
|
];
|
|
172
298
|
const $elms = document.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
|
|
173
299
|
if ($elms) {
|
|
@@ -179,6 +305,21 @@ const Toolbar = ()=>{
|
|
|
179
305
|
}, [
|
|
180
306
|
removeHoverOverlayComponent
|
|
181
307
|
]);
|
|
308
|
+
const onCloseOnboarding = react.useCallback(()=>{
|
|
309
|
+
timeoutRef.current && clearTimeout(timeoutRef.current);
|
|
310
|
+
if (countShowOnboarding > 0) {
|
|
311
|
+
const eventCreate = new CustomEvent('editor:toolbar:close-onboarding', {
|
|
312
|
+
bubbles: true,
|
|
313
|
+
detail: {
|
|
314
|
+
close: 'close Onboarding'
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
window.dispatchEvent(eventCreate);
|
|
318
|
+
setIsOnboarding(false);
|
|
319
|
+
}
|
|
320
|
+
}, [
|
|
321
|
+
countShowOnboarding
|
|
322
|
+
]);
|
|
182
323
|
const removeActiveComponent = react.useCallback(()=>{
|
|
183
324
|
currentComponentActive.current = null;
|
|
184
325
|
const clearAttrs = [
|
|
@@ -189,7 +330,8 @@ const Toolbar = ()=>{
|
|
|
189
330
|
'data-toolbar-active-inside',
|
|
190
331
|
'data-spacing-margin-bottom-active',
|
|
191
332
|
'data-toolbar-force-hover',
|
|
192
|
-
'data-outline-force-hover'
|
|
333
|
+
'data-outline-force-hover',
|
|
334
|
+
'data-toolbar-active-overflow'
|
|
193
335
|
];
|
|
194
336
|
const $elms = document.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
|
|
195
337
|
if ($elms) {
|
|
@@ -198,37 +340,32 @@ const Toolbar = ()=>{
|
|
|
198
340
|
});
|
|
199
341
|
}
|
|
200
342
|
setFocusTextEditor(false);
|
|
201
|
-
if (
|
|
202
|
-
|
|
343
|
+
if (stopWatchReRenderComponent.current) stopWatchReRenderComponent.current();
|
|
344
|
+
onCloseOnboarding();
|
|
345
|
+
}, [
|
|
346
|
+
onCloseOnboarding
|
|
347
|
+
]);
|
|
203
348
|
const watchComponentReRender = ($el, callback)=>{
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
mutation.removedNodes.forEach((el)=>{
|
|
210
|
-
if (el === $el) {
|
|
211
|
-
if (obsActiveComponent.current) obsActiveComponent.current.disconnect();
|
|
212
|
-
setTimeout(()=>{
|
|
213
|
-
callback();
|
|
214
|
-
}, 0);
|
|
215
|
-
}
|
|
216
|
-
});
|
|
349
|
+
// editor:component:render
|
|
350
|
+
const onComponentReRender = (e)=>{
|
|
351
|
+
const detail = e.detail;
|
|
352
|
+
if (detail?.componentUid == currentComponentActive.current?.componentUid) {
|
|
353
|
+
callback();
|
|
217
354
|
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
355
|
+
};
|
|
356
|
+
window.removeEventListener('editor:component:render', onComponentReRender);
|
|
357
|
+
window.addEventListener('editor:component:render', onComponentReRender);
|
|
222
358
|
const $images = $el.querySelectorAll('img');
|
|
223
359
|
if ($images?.length) {
|
|
224
360
|
$images.forEach(($img)=>{
|
|
225
361
|
$img.addEventListener('load', ()=>{
|
|
226
|
-
|
|
227
|
-
callback();
|
|
228
|
-
}, 0);
|
|
362
|
+
callback();
|
|
229
363
|
});
|
|
230
364
|
});
|
|
231
365
|
}
|
|
366
|
+
stopWatchReRenderComponent.current = ()=>{
|
|
367
|
+
window.removeEventListener('editor:component:render', onComponentReRender);
|
|
368
|
+
};
|
|
232
369
|
};
|
|
233
370
|
const setActiveComponentSpacing = react.useCallback(({ $component })=>{
|
|
234
371
|
if (!$component) return;
|
|
@@ -239,46 +376,94 @@ const Toolbar = ()=>{
|
|
|
239
376
|
const $bg = $marginBottom.querySelector('[data-spacing-margin-bottom-bg]') || null;
|
|
240
377
|
const $drag = $marginBottom.querySelector('[data-spacing-margin-bottom-drag]') || null;
|
|
241
378
|
if ($bg && $drag) {
|
|
242
|
-
|
|
379
|
+
let value = style.marginBottom;
|
|
380
|
+
if (parseFloat(value) < 0) {
|
|
381
|
+
value = '0';
|
|
382
|
+
}
|
|
243
383
|
$bg.style.height = value;
|
|
244
384
|
$drag.style.top = value;
|
|
245
385
|
$marginBottom.setAttribute('data-spacing-margin-bottom-active', 'true');
|
|
386
|
+
if (isLayoutElement($component)) {
|
|
387
|
+
$bg.style.left = '0';
|
|
388
|
+
} else {
|
|
389
|
+
const paddingLeft = style.paddingLeft;
|
|
390
|
+
const leftValue = `-${paddingLeft}`;
|
|
391
|
+
const translateCss = `translate(${leftValue}, -100%)`;
|
|
392
|
+
$bg.style.left = leftValue;
|
|
393
|
+
$drag.style.transform = translateCss;
|
|
394
|
+
}
|
|
246
395
|
}
|
|
247
396
|
}
|
|
248
397
|
}, []);
|
|
249
|
-
const
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
398
|
+
const calculateOnboardingPosition = ()=>{
|
|
399
|
+
const toolbar = document.querySelector('[data-toolbar-active]');
|
|
400
|
+
const toolbarOnboading = document.querySelector('[data-toolbar-onboarding]');
|
|
401
|
+
if (toolbar && toolbarOnboading) {
|
|
402
|
+
toolbarOnboading?.removeAttribute('data-onboarding-active');
|
|
403
|
+
setTimeout(()=>{
|
|
404
|
+
const rect = toolbar.getBoundingClientRect();
|
|
405
|
+
const rectTop = rect.top || 0;
|
|
406
|
+
const rectOnboading = toolbarOnboading?.getBoundingClientRect();
|
|
407
|
+
const onboardingHeight = rectOnboading?.height || 0;
|
|
408
|
+
const $iframe = parent.document.querySelector('.iframe');
|
|
409
|
+
const $iframeWin = $iframe?.contentWindow;
|
|
410
|
+
const iframeWinScrollY = $iframeWin?.scrollY || 0;
|
|
411
|
+
const iframeHeight = $iframe?.clientHeight || 0;
|
|
412
|
+
if (rectTop + onboardingHeight > iframeHeight) {
|
|
413
|
+
const oboardingTop = rect.top + iframeWinScrollY - onboardingHeight - 8;
|
|
414
|
+
toolbarOnboading?.setAttribute('style', `top: ${oboardingTop}px;left: ${rect.left}px;`);
|
|
415
|
+
setOnboardingPosition('top');
|
|
416
|
+
if ($iframeWin && oboardingTop < rect.top + iframeWinScrollY) {
|
|
417
|
+
setTimeout(()=>{
|
|
418
|
+
const toTop = oboardingTop - 20;
|
|
419
|
+
$iframeWin.scrollTo({
|
|
420
|
+
top: toTop,
|
|
421
|
+
behavior: 'smooth'
|
|
422
|
+
});
|
|
423
|
+
}, 200);
|
|
424
|
+
}
|
|
425
|
+
} else {
|
|
426
|
+
const oboardingTop = rect.top + iframeWinScrollY + rect.height + 8;
|
|
427
|
+
toolbarOnboading?.setAttribute('style', `top: ${oboardingTop}px;left: ${rect.left}px;`);
|
|
428
|
+
setOnboardingPosition('bottom');
|
|
274
429
|
}
|
|
275
|
-
|
|
430
|
+
setCountShowOnboarding((countShowOnboarding)=>countShowOnboarding + 1);
|
|
431
|
+
toolbarOnboading?.setAttribute('data-onboarding-active', 'true');
|
|
432
|
+
}, 100);
|
|
276
433
|
}
|
|
277
|
-
}
|
|
434
|
+
};
|
|
435
|
+
const setToolbarOnboarding = react.useCallback(({ $component })=>{
|
|
436
|
+
if (!$component) return;
|
|
437
|
+
if (isSection($component) || isPopup($component) || isSticky($component)) return;
|
|
438
|
+
const toolbarOnboading = document.querySelector('[data-toolbar-onboarding]');
|
|
439
|
+
// only show one time
|
|
440
|
+
if (countShowOnboarding == 0) {
|
|
441
|
+
calculateOnboardingPosition();
|
|
442
|
+
} else {
|
|
443
|
+
onCloseOnboarding();
|
|
444
|
+
toolbarOnboading?.removeAttribute('data-onboarding-active');
|
|
445
|
+
}
|
|
446
|
+
}, [
|
|
447
|
+
countShowOnboarding,
|
|
448
|
+
onCloseOnboarding
|
|
449
|
+
]);
|
|
278
450
|
const setActiveComponent = react.useCallback(async ({ componentUid, productId, timeAwait = 500, forceReActive })=>{
|
|
279
451
|
if (!componentUid) return;
|
|
280
|
-
|
|
281
|
-
|
|
452
|
+
let $component = await waitForElementToExist(`${productId ? `[data-product-id="${productId}"] ` : ''}[data-uid="${componentUid}"]`, timeAwait);
|
|
453
|
+
// check element fetch data: product, product list
|
|
454
|
+
if (!$component) {
|
|
455
|
+
const isLoading = document.querySelector(`.gp-loading-placeholder`);
|
|
456
|
+
if (!isLoading) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
if (isLoading) {
|
|
460
|
+
// await element onload
|
|
461
|
+
$component = await waitForElementToExist(`${productId ? `[data-product-id="${productId}"] ` : ''}[data-uid="${componentUid}"]`, 15000);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
if (!$component) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
282
467
|
if (!forceReActive && componentUid == currentComponentActive.current?.componentUid && productId == currentComponentActive.current?.productId) return;
|
|
283
468
|
if (componentUid !== currentComponentActive.current?.componentUid || productId !== currentComponentActive.current?.productId || forceReActive) removeActiveComponent();
|
|
284
469
|
const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
|
|
@@ -322,7 +507,14 @@ const Toolbar = ()=>{
|
|
|
322
507
|
setActiveComponentSpacing({
|
|
323
508
|
$component
|
|
324
509
|
});
|
|
325
|
-
|
|
510
|
+
timeoutRef.current && clearTimeout(timeoutRef.current);
|
|
511
|
+
timeoutRef.current = setTimeout(()=>{
|
|
512
|
+
if ($component) {
|
|
513
|
+
setToolbarOnboarding({
|
|
514
|
+
$component
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
}, timeoutOnboarding);
|
|
326
518
|
removeHoverComponent();
|
|
327
519
|
// Reactive when component re-render
|
|
328
520
|
watchComponentReRender($component, ()=>{
|
|
@@ -336,8 +528,8 @@ const Toolbar = ()=>{
|
|
|
336
528
|
}, [
|
|
337
529
|
removeActiveComponent,
|
|
338
530
|
removeHoverComponent,
|
|
339
|
-
|
|
340
|
-
|
|
531
|
+
setActiveComponentSpacing,
|
|
532
|
+
setToolbarOnboarding
|
|
341
533
|
]);
|
|
342
534
|
const setFocusTextEditor = async (value)=>{
|
|
343
535
|
if (!value) {
|
|
@@ -460,7 +652,7 @@ const Toolbar = ()=>{
|
|
|
460
652
|
if (isDragging.current) return;
|
|
461
653
|
if (isResizeSpacing.current) return;
|
|
462
654
|
const $target = e.target;
|
|
463
|
-
if (!$target) {
|
|
655
|
+
if (!$target || typeof $target.closest !== 'function') {
|
|
464
656
|
removeHoverOverlayComponent();
|
|
465
657
|
return;
|
|
466
658
|
}
|
|
@@ -603,6 +795,46 @@ const Toolbar = ()=>{
|
|
|
603
795
|
}, [
|
|
604
796
|
removeHoverComponent
|
|
605
797
|
]);
|
|
798
|
+
const setHoverParentComponent = (uid, type)=>{
|
|
799
|
+
if (!uid) return;
|
|
800
|
+
const $parentComponents = document.querySelectorAll(`[data-uid="${uid}"]`);
|
|
801
|
+
if ($parentComponents.length) {
|
|
802
|
+
$parentComponents.forEach(($parentComponent)=>{
|
|
803
|
+
const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
|
|
804
|
+
if ($outline) {
|
|
805
|
+
if (type === 'in') {
|
|
806
|
+
$outline.setAttribute('data-outline-force-hover', 'true');
|
|
807
|
+
$outline.setAttribute('data-outline-force-overlay', 'true');
|
|
808
|
+
} else {
|
|
809
|
+
$outline.removeAttribute('data-outline-force-hover');
|
|
810
|
+
$outline.removeAttribute('data-outline-force-overlay');
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
const onHoverComponent = react.useCallback((e)=>{
|
|
817
|
+
if (isDragging.current) return;
|
|
818
|
+
const detail = e.detail;
|
|
819
|
+
if (detail?.componentUid) {
|
|
820
|
+
setHoverParentComponent(detail?.componentUid, detail?.type);
|
|
821
|
+
}
|
|
822
|
+
}, [
|
|
823
|
+
isDragging
|
|
824
|
+
]);
|
|
825
|
+
const onToolbarOnboarding = react.useCallback((e)=>{
|
|
826
|
+
const detail = e.detail;
|
|
827
|
+
if (detail?.isNewUser) {
|
|
828
|
+
setIsOnboarding(true);
|
|
829
|
+
}
|
|
830
|
+
}, []);
|
|
831
|
+
const onWindowResize = react.useCallback(()=>{
|
|
832
|
+
if (isOnboarding) {
|
|
833
|
+
calculateOnboardingPosition();
|
|
834
|
+
}
|
|
835
|
+
}, [
|
|
836
|
+
isOnboarding
|
|
837
|
+
]);
|
|
606
838
|
/* Register event */ react.useEffect(()=>{
|
|
607
839
|
document.addEventListener('mousemove', onMouseMove);
|
|
608
840
|
window.addEventListener('editor:active-component', onActiveComponent);
|
|
@@ -611,6 +843,9 @@ const Toolbar = ()=>{
|
|
|
611
843
|
window.addEventListener('editor:is-editing-text-editor', onIsEditingTextEditor);
|
|
612
844
|
window.addEventListener('editor:toolbar:show-parents', onShowParents);
|
|
613
845
|
window.addEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
|
|
846
|
+
window.addEventListener('editor:hover-component', onHoverComponent);
|
|
847
|
+
window.addEventListener('editor:toolbar-onboarding', onToolbarOnboarding);
|
|
848
|
+
window.addEventListener('resize', onWindowResize);
|
|
614
849
|
return ()=>{
|
|
615
850
|
document.removeEventListener('mousemove', onMouseMove);
|
|
616
851
|
window.removeEventListener('editor:active-component', onActiveComponent);
|
|
@@ -619,6 +854,9 @@ const Toolbar = ()=>{
|
|
|
619
854
|
window.removeEventListener('editor:is-editing-text-editor', onIsEditingTextEditor);
|
|
620
855
|
window.removeEventListener('editor:toolbar:show-parents', onShowParents);
|
|
621
856
|
window.removeEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
|
|
857
|
+
window.removeEventListener('editor:hover-component', onHoverComponent);
|
|
858
|
+
window.removeEventListener('editor:toolbar-onboarding', onToolbarOnboarding);
|
|
859
|
+
window.removeEventListener('resize', onWindowResize);
|
|
622
860
|
};
|
|
623
861
|
}, [
|
|
624
862
|
onMouseMove,
|
|
@@ -627,90 +865,20 @@ const Toolbar = ()=>{
|
|
|
627
865
|
onIsDragging,
|
|
628
866
|
onIsEditingTextEditor,
|
|
629
867
|
onShowParents,
|
|
630
|
-
onResizeSpacing
|
|
868
|
+
onResizeSpacing,
|
|
869
|
+
onHoverComponent,
|
|
870
|
+
onToolbarOnboarding,
|
|
871
|
+
onWindowResize
|
|
631
872
|
]);
|
|
632
|
-
return
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
const parents = [];
|
|
637
|
-
// Push each parent $elms to the array
|
|
638
|
-
while($el){
|
|
639
|
-
$el = $el.parentElement ?? undefined;
|
|
640
|
-
if ($el) {
|
|
641
|
-
if ($el.tagName === 'BODY' || $el.getAttribute('data-uid') === 'ROOT') {
|
|
642
|
-
break;
|
|
643
|
-
}
|
|
644
|
-
if (selector) {
|
|
645
|
-
if ($el.matches(selector)) {
|
|
646
|
-
parents.push($el);
|
|
647
|
-
if (limit && parents.length == limit) {
|
|
648
|
-
return parents;
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
continue;
|
|
652
|
-
}
|
|
653
|
-
parents.push($el);
|
|
654
|
-
if (limit && parents.length == limit) {
|
|
655
|
-
return parents;
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
// Return our parent array
|
|
660
|
-
return parents;
|
|
661
|
-
};
|
|
662
|
-
const getChildrenByAttrSelector = ($el, attrSelector)=>{
|
|
663
|
-
const childLen = $el.children.length;
|
|
664
|
-
if (childLen) {
|
|
665
|
-
for(let i = 0; i < childLen; i++){
|
|
666
|
-
const children = $el.children[i];
|
|
667
|
-
if (children) {
|
|
668
|
-
const is = children.getAttribute(attrSelector);
|
|
669
|
-
if (is) {
|
|
670
|
-
return children;
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
};
|
|
676
|
-
const isOverParent = ({ current, parent, index, revert })=>{
|
|
677
|
-
for(let i = 0; i < index; i++){
|
|
678
|
-
let is = current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent.top && current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent.top + parent.height || current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent.top + parent.height && current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent.top;
|
|
679
|
-
if (revert) {
|
|
680
|
-
is = current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent.bottom && current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent.bottom - parent.height || current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent.bottom - parent.height && current.bottom + (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent.bottom;
|
|
681
|
-
}
|
|
682
|
-
if (is) return true;
|
|
683
|
-
}
|
|
684
|
-
return false;
|
|
685
|
-
};
|
|
686
|
-
const waitForElementToExist = (selector, timeout = 200)=>{
|
|
687
|
-
return new Promise((resolve)=>{
|
|
688
|
-
const intervalID = setInterval(()=>{
|
|
689
|
-
const el = document.querySelector(selector);
|
|
690
|
-
if (el) {
|
|
691
|
-
clearInterval(intervalID);
|
|
692
|
-
clearTimeout(timeoutID);
|
|
693
|
-
resolve(el);
|
|
694
|
-
}
|
|
695
|
-
}, 50);
|
|
696
|
-
const timeoutID = setTimeout(()=>{
|
|
697
|
-
clearInterval(intervalID);
|
|
698
|
-
clearTimeout(timeoutID);
|
|
699
|
-
resolve(null);
|
|
700
|
-
}, timeout);
|
|
873
|
+
return isOnboarding && /*#__PURE__*/ jsxRuntime.jsx(Onboarding.default, {
|
|
874
|
+
enable: true,
|
|
875
|
+
position: onboardingPosition,
|
|
876
|
+
onCloseOnboarding: onCloseOnboarding
|
|
701
877
|
});
|
|
702
878
|
};
|
|
703
|
-
const
|
|
704
|
-
const overflow = getComputedStyle(el).overflow;
|
|
705
|
-
return overflow !== 'visible';
|
|
706
|
-
};
|
|
707
|
-
const isSection = (el)=>{
|
|
708
|
-
const tag = el.getAttribute('data-component-tag');
|
|
709
|
-
return tag === 'Section';
|
|
710
|
-
};
|
|
711
|
-
const isOverToolbarPosition = (el, parent)=>{
|
|
879
|
+
const isOverToolbarPosition = (el, parent1)=>{
|
|
712
880
|
const rect = el.getBoundingClientRect();
|
|
713
|
-
const rectP =
|
|
881
|
+
const rectP = parent1.getBoundingClientRect();
|
|
714
882
|
// 32px = toolbar active height
|
|
715
883
|
return rect.top - rectP.top < TOOLBAR_ACTIVE_HEIGHT + 1;
|
|
716
884
|
};
|