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