@gem-sdk/pages 1.56.0 → 1.57.0-dev.45

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 (46) hide show
  1. package/dist/cjs/components/builder/Body.js +38 -0
  2. package/dist/cjs/components/builder/Footer.js +2 -2
  3. package/dist/cjs/components/builder/Header.js +4 -1
  4. package/dist/cjs/components/builder/InteractionSelectOnPageHeader.js +191 -0
  5. package/dist/cjs/components/builder/SwitchView.js +1 -0
  6. package/dist/cjs/components/builder/Toolbar.js +130 -340
  7. package/dist/cjs/components/builder/Toolbox.js +48 -1
  8. package/dist/cjs/components/builder/toolbar/const.js +7 -0
  9. package/dist/cjs/components/builder/toolbar/utils/findDOMClosest.js +41 -0
  10. package/dist/cjs/components/builder/toolbar/utils/findOverflowParent.js +20 -0
  11. package/dist/cjs/components/builder/toolbar/utils/getChildrenByAttrSelector.js +18 -0
  12. package/dist/cjs/components/builder/toolbar/utils/getDOMElementParents.js +32 -0
  13. package/dist/cjs/components/builder/toolbar/utils/isOverParent.js +16 -0
  14. package/dist/cjs/components/builder/toolbar/utils/isOverToolbarPosition.js +12 -0
  15. package/dist/cjs/components/builder/toolbar/utils/isSection.js +8 -0
  16. package/dist/cjs/components/builder/toolbar/utils/notVisible.js +8 -0
  17. package/dist/cjs/components/builder/toolbar/utils/waitForElementToExist.js +27 -0
  18. package/dist/cjs/components/image-to-layout/DropElement.js +2 -0
  19. package/dist/cjs/libs/api/get-static-page-props-v2.js +2 -1
  20. package/dist/cjs/pages/builder.js +4 -11
  21. package/dist/cjs/pages/static-v2.js +18 -5
  22. package/dist/esm/components/builder/Body.js +34 -0
  23. package/dist/esm/components/builder/Footer.js +2 -2
  24. package/dist/esm/components/builder/Header.js +5 -2
  25. package/dist/esm/components/builder/InteractionSelectOnPageHeader.js +187 -0
  26. package/dist/esm/components/builder/SwitchView.js +1 -0
  27. package/dist/esm/components/builder/Toolbar.js +102 -312
  28. package/dist/esm/components/builder/Toolbox.js +48 -1
  29. package/dist/esm/components/builder/toolbar/const.js +4 -0
  30. package/dist/esm/components/builder/toolbar/utils/findDOMClosest.js +39 -0
  31. package/dist/esm/components/builder/toolbar/utils/findOverflowParent.js +18 -0
  32. package/dist/esm/components/builder/toolbar/utils/getChildrenByAttrSelector.js +16 -0
  33. package/dist/esm/components/builder/toolbar/utils/getDOMElementParents.js +30 -0
  34. package/dist/esm/components/builder/toolbar/utils/isOverParent.js +14 -0
  35. package/dist/esm/components/builder/toolbar/utils/isOverToolbarPosition.js +10 -0
  36. package/dist/esm/components/builder/toolbar/utils/isSection.js +6 -0
  37. package/dist/esm/components/builder/toolbar/utils/notVisible.js +6 -0
  38. package/dist/esm/components/builder/toolbar/utils/waitForElementToExist.js +25 -0
  39. package/dist/esm/components/image-to-layout/DropElement.js +2 -0
  40. package/dist/esm/libs/api/get-static-page-props-v2.js +2 -1
  41. package/dist/esm/pages/builder.js +5 -12
  42. package/dist/esm/pages/static-v2.js +18 -5
  43. package/dist/types/index.d.ts +1 -0
  44. package/package.json +5 -5
  45. package/dist/cjs/components/builder/toolbar/Onboarding.js +0 -110
  46. package/dist/esm/components/builder/toolbar/Onboarding.js +0 -106
@@ -1,48 +1,21 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { memo, useRef, useState, useCallback, useEffect } from 'react';
3
- import Onboarding from './toolbar/Onboarding.js';
1
+ import { jsx, Fragment } from 'react/jsx-runtime';
2
+ import { memo, useRef, useCallback, useEffect } from 'react';
3
+ import { getDOMElementParents } from './toolbar/utils/getDOMElementParents.js';
4
+ import { TOOLBAR_ACTIVE_HEIGHT, TOOLBAR_HOVER_HEIGHT } from './toolbar/const.js';
5
+ import { getChildrenByAttrSelector } from './toolbar/utils/getChildrenByAttrSelector.js';
6
+ import { findOverflowParent } from './toolbar/utils/findOverflowParent.js';
7
+ import { waitForElementToExist } from './toolbar/utils/waitForElementToExist.js';
8
+ import { isOverParent } from './toolbar/utils/isOverParent.js';
9
+ import { findDOMClosest } from './toolbar/utils/findDOMClosest.js';
4
10
 
5
- const TOOLBAR_HOVER_HEIGHT = 24;
6
- const TOOLBAR_ACTIVE_HEIGHT = 32;
7
- const isPopup = (el)=>{
8
- const tag = el.getAttribute('data-component-tag');
9
- return tag === 'Dialog';
10
- };
11
- const isSticky = (el)=>{
12
- const tag = el.getAttribute('data-component-tag');
13
- return tag === 'Sticky';
14
- };
15
- const isOverToolbarPosition = (el, parent1)=>{
16
- const rect = el.getBoundingClientRect();
17
- const rectP = parent1.getBoundingClientRect();
18
- // 32px = toolbar active height
19
- return rect.top - rectP.top < TOOLBAR_ACTIVE_HEIGHT + 1;
20
- };
21
- const findOverflowParent = (element, initEl)=>{
22
- const thisEl = element;
23
- const origEl = initEl || thisEl;
24
- if (!thisEl) return;
25
- if (isSection(thisEl)) return;
26
- if (notVisible(thisEl) && isOverToolbarPosition(initEl, thisEl)) return thisEl;
27
- if (thisEl.parentElement) {
28
- return findOverflowParent(thisEl.parentElement, origEl);
29
- } else {
30
- return;
31
- }
32
- };
33
- const COMPONENTS_TAG_NOT_LOAD_IMAGES = [
34
- 'PostPurchaseProductImages'
35
- ];
36
11
  const Toolbar = ()=>{
37
12
  const currentComponentActive = useRef(null);
38
13
  const isDragging = useRef(false);
39
14
  const stopWatchReRenderComponent = useRef();
40
15
  const isResizeSpacing = useRef(false);
41
- const [isOnboarding, setIsOnboarding] = useState(false);
42
- const [countShowOnboarding, setCountShowOnboarding] = useState(0);
43
- const [onboardingPosition, setOnboardingPosition] = useState('bottom');
44
- const timeoutRef = useRef(null);
45
- const timeoutOnboarding = 5000;
16
+ const cacheHoverComponents = useRef([]);
17
+ const cacheHoverThemeSectionComponents = useRef([]);
18
+ const cacheActiveComponents = useRef([]);
46
19
  /* Functions */ const changePositionToolbar = ({ state, $toolbar, $component })=>{
47
20
  const $parentOverflow = findOverflowParent($component, $toolbar);
48
21
  const rect = $toolbar.getBoundingClientRect();
@@ -84,7 +57,7 @@ const Toolbar = ()=>{
84
57
  const setHoverComponent = useCallback(({ $component, componentUid, focus, isPreventSection, isParent })=>{
85
58
  if (!$component && !componentUid) return;
86
59
  if (!$component) {
87
- const $c = document.querySelector(`[data-uid="${componentUid}"]`);
60
+ const $c = document.body.querySelector('#storefront')?.querySelector(`[data-uid="${componentUid}"]`);
88
61
  if (!$c) return;
89
62
  $component = $c;
90
63
  }
@@ -93,6 +66,7 @@ const Toolbar = ()=>{
93
66
  if (!cUid) return;
94
67
  componentUid = cUid;
95
68
  }
69
+ cacheHoverComponents.current.push($component);
96
70
  const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
97
71
  const $outline = getChildrenByAttrSelector($component, 'data-outline');
98
72
  const $btnAddTop = getChildrenByAttrSelector($component, 'data-toolbar-add-top');
@@ -121,6 +95,7 @@ const Toolbar = ()=>{
121
95
  $outline.setAttribute('data-outline-parent-hover', 'true');
122
96
  }
123
97
  if (isPreventSection) {
98
+ cacheHoverThemeSectionComponents.current.push($component);
124
99
  $outline.setAttribute('data-outline-overlay-theme-section', 'true');
125
100
  }
126
101
  if (focus) {
@@ -140,7 +115,7 @@ const Toolbar = ()=>{
140
115
  }, []);
141
116
  const setHoverComponentParents = useCallback(({ $component, componentUid })=>{
142
117
  if (!$component) {
143
- const $c = document.querySelector(`[data-uid="${componentUid}"]`);
118
+ const $c = document.body.querySelector('#storefront')?.querySelector(`[data-uid="${componentUid}"]`);
144
119
  if (!$c) return;
145
120
  $component = $c;
146
121
  }
@@ -206,18 +181,23 @@ const Toolbar = ()=>{
206
181
  }
207
182
  }
208
183
  };
209
- const removeHoverOverlayComponent = useCallback(()=>{
184
+ const removeHoverThemeSectionComponent = useCallback(()=>{
210
185
  const clearAttrs = [
211
- 'data-outline-overlay',
212
186
  'data-outline-overlay-theme-section',
213
187
  'data-theme-section-status-active'
214
188
  ];
215
- const $elms = document.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
216
- if ($elms) {
217
- clearAttrs.forEach((attr)=>{
218
- $elms.forEach(($el)=>$el.removeAttribute(attr));
219
- });
189
+ const $hoverThemeSectionComponents = cacheHoverThemeSectionComponents.current;
190
+ if ($hoverThemeSectionComponents.length) {
191
+ for (const $hoverThemeSectionComponent of $hoverThemeSectionComponents){
192
+ const $elms = $hoverThemeSectionComponent.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
193
+ if ($elms) {
194
+ clearAttrs.forEach((attr)=>{
195
+ $elms.forEach(($el)=>$el.removeAttribute(attr));
196
+ });
197
+ }
198
+ }
220
199
  }
200
+ cacheHoverThemeSectionComponents.current = []; // clear
221
201
  }, []);
222
202
  const removeHoverComponent = useCallback(()=>{
223
203
  const clearAttrs = [
@@ -231,30 +211,21 @@ const Toolbar = ()=>{
231
211
  'data-outline-parent-hover',
232
212
  'data-toolbar-hover-overflow'
233
213
  ];
234
- const $elms = document.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
235
- if ($elms) {
236
- clearAttrs.forEach((attr)=>{
237
- $elms.forEach(($el)=>$el.removeAttribute(attr));
238
- });
239
- }
240
- removeHoverOverlayComponent();
241
- }, [
242
- removeHoverOverlayComponent
243
- ]);
244
- const onCloseOnboarding = useCallback(()=>{
245
- timeoutRef.current && clearTimeout(timeoutRef.current);
246
- if (countShowOnboarding > 0) {
247
- const eventCreate = new CustomEvent('editor:toolbar:close-onboarding', {
248
- bubbles: true,
249
- detail: {
250
- close: 'close Onboarding'
214
+ const $hoverComponents = cacheHoverComponents.current;
215
+ if ($hoverComponents.length) {
216
+ for (const $hoverComponent of $hoverComponents){
217
+ const $elms = $hoverComponent.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
218
+ if ($elms) {
219
+ clearAttrs.forEach((attr)=>{
220
+ $elms.forEach(($el)=>$el.removeAttribute(attr));
221
+ });
251
222
  }
252
- });
253
- window.dispatchEvent(eventCreate);
254
- setIsOnboarding(false);
223
+ }
255
224
  }
225
+ removeHoverThemeSectionComponent();
226
+ cacheHoverComponents.current = []; // clear
256
227
  }, [
257
- countShowOnboarding
228
+ removeHoverThemeSectionComponent
258
229
  ]);
259
230
  const removeActiveComponent = useCallback(()=>{
260
231
  currentComponentActive.current = null;
@@ -269,44 +240,21 @@ const Toolbar = ()=>{
269
240
  'data-outline-force-hover',
270
241
  'data-toolbar-active-overflow'
271
242
  ];
272
- const $elms = document.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
273
- if ($elms) {
274
- clearAttrs.forEach((attr)=>{
275
- $elms.forEach(($el)=>$el.removeAttribute(attr));
276
- });
277
- }
278
- setFocusTextEditor(false);
279
- if (stopWatchReRenderComponent.current) stopWatchReRenderComponent.current();
280
- onCloseOnboarding();
281
- }, [
282
- onCloseOnboarding
283
- ]);
284
- const watchComponentReRender = ($el, callback)=>{
285
- // editor:component:render
286
- const onComponentReRender = (e)=>{
287
- const detail = e.detail;
288
- if (detail?.componentUid == currentComponentActive.current?.componentUid) {
289
- callback();
290
- }
291
- };
292
- window.removeEventListener('editor:component:render', onComponentReRender);
293
- window.addEventListener('editor:component:render', onComponentReRender);
294
- const componentTag = $el.getAttribute('data-component-tag');
295
- // hotfix cho sale funnel release, nhưng cần tìm solution cho phần này
296
- if (componentTag && !COMPONENTS_TAG_NOT_LOAD_IMAGES.includes(componentTag)) {
297
- const $images = $el.querySelectorAll('img');
298
- if ($images?.length) {
299
- $images.forEach(($img)=>{
300
- $img.addEventListener('load', ()=>{
301
- callback();
243
+ const $activeComponents = cacheActiveComponents.current;
244
+ if ($activeComponents.length) {
245
+ for (const $activeComponent of $activeComponents){
246
+ const $elms = $activeComponent.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
247
+ if ($elms) {
248
+ clearAttrs.forEach((attr)=>{
249
+ $elms.forEach(($el)=>$el.removeAttribute(attr));
302
250
  });
303
- });
251
+ }
304
252
  }
305
253
  }
306
- stopWatchReRenderComponent.current = ()=>{
307
- window.removeEventListener('editor:component:render', onComponentReRender);
308
- };
309
- };
254
+ cacheActiveComponents.current = []; // clear
255
+ setFocusTextEditor(false);
256
+ if (stopWatchReRenderComponent.current) stopWatchReRenderComponent.current();
257
+ }, []);
310
258
  const setActiveComponentSpacing = useCallback(({ $component })=>{
311
259
  if (!$component) return;
312
260
  const style = getComputedStyle($component);
@@ -323,58 +271,6 @@ const Toolbar = ()=>{
323
271
  }
324
272
  }
325
273
  }, []);
326
- const calculateOnboardingPosition = ()=>{
327
- const toolbar = document.querySelector('[data-toolbar-active]');
328
- const toolbarOnboading = document.querySelector('[data-toolbar-onboarding]');
329
- if (toolbar && toolbarOnboading) {
330
- toolbarOnboading?.removeAttribute('data-onboarding-active');
331
- setTimeout(()=>{
332
- const rect = toolbar.getBoundingClientRect();
333
- const rectTop = rect.top || 0;
334
- const rectOnboading = toolbarOnboading?.getBoundingClientRect();
335
- const onboardingHeight = rectOnboading?.height || 0;
336
- const $iframe = parent.document.querySelector('.iframe');
337
- const $iframeWin = $iframe?.contentWindow;
338
- const iframeWinScrollY = $iframeWin?.scrollY || 0;
339
- const iframeHeight = $iframe?.clientHeight || 0;
340
- if (rectTop + onboardingHeight > iframeHeight) {
341
- const oboardingTop = rect.top + iframeWinScrollY - onboardingHeight - 8;
342
- toolbarOnboading?.setAttribute('style', `top: ${oboardingTop}px;left: ${rect.left}px;`);
343
- setOnboardingPosition('top');
344
- if ($iframeWin && oboardingTop < rect.top + iframeWinScrollY) {
345
- setTimeout(()=>{
346
- const toTop = oboardingTop - 20;
347
- $iframeWin.scrollTo({
348
- top: toTop,
349
- behavior: 'smooth'
350
- });
351
- }, 200);
352
- }
353
- } else {
354
- const oboardingTop = rect.top + iframeWinScrollY + rect.height + 8;
355
- toolbarOnboading?.setAttribute('style', `top: ${oboardingTop}px;left: ${rect.left}px;`);
356
- setOnboardingPosition('bottom');
357
- }
358
- setCountShowOnboarding((countShowOnboarding)=>countShowOnboarding + 1);
359
- toolbarOnboading?.setAttribute('data-onboarding-active', 'true');
360
- }, 100);
361
- }
362
- };
363
- const setToolbarOnboarding = useCallback(({ $component })=>{
364
- if (!$component) return;
365
- if (isSection($component) || isPopup($component) || isSticky($component)) return;
366
- const toolbarOnboading = document.querySelector('[data-toolbar-onboarding]');
367
- // only show one time
368
- if (countShowOnboarding == 0) {
369
- calculateOnboardingPosition();
370
- } else {
371
- onCloseOnboarding();
372
- toolbarOnboading?.removeAttribute('data-onboarding-active');
373
- }
374
- }, [
375
- countShowOnboarding,
376
- onCloseOnboarding
377
- ]);
378
274
  const getSelectorComponent = ({ componentUid, productId, articleId, marqueeKey })=>{
379
275
  if (articleId) {
380
276
  return `${articleId ? `[data-article-id="${articleId}"][data-uid="${componentUid}"], [data-article-id="${articleId}"] [data-uid="${componentUid}"]` : `[data-uid="${componentUid}"]`}`;
@@ -399,6 +295,7 @@ const Toolbar = ()=>{
399
295
  if (!forceReActive && componentUid !== currentComponentActive.current?.componentUid || productId !== currentComponentActive.current?.productId || marqueeKey !== currentComponentActive.current?.marqueeKey) {
400
296
  removeActiveComponent();
401
297
  }
298
+ cacheActiveComponents.current.push($component);
402
299
  const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
403
300
  const $outline = getChildrenByAttrSelector($component, 'data-outline');
404
301
  const $btnAddTop = getChildrenByAttrSelector($component, 'data-toolbar-add-top');
@@ -427,12 +324,16 @@ const Toolbar = ()=>{
427
324
  if ($btnAddBottom) {
428
325
  $btnAddBottom.setAttribute('data-toolbar-add-active', 'true');
429
326
  }
430
- const isChildOfMarquee = !!$component.closest('[data-component-tag="Marquee"]');
327
+ const { $isChildOfMarquee, $section } = findDOMClosest($component, {
328
+ $isChildOfMarquee: '[data-component-tag="Marquee"]',
329
+ $section: '[data-component-tag="Section"]'
330
+ });
431
331
  // Active same element in product list
432
- if (productId || articleId || isChildOfMarquee) {
433
- const $relatedElements = document.querySelectorAll(`[data-uid="${componentUid}"]`);
332
+ if ($section && (productId || articleId || $isChildOfMarquee)) {
333
+ const $relatedElements = $section.querySelectorAll(`[data-uid="${componentUid}"]`);
434
334
  if ($relatedElements?.length) {
435
335
  $relatedElements.forEach(($relatedElement)=>{
336
+ cacheActiveComponents.current.push($relatedElement);
436
337
  const $outline = getChildrenByAttrSelector($relatedElement, 'data-outline');
437
338
  if ($outline) {
438
339
  $outline.setAttribute('data-outline-active', 'true');
@@ -443,35 +344,16 @@ const Toolbar = ()=>{
443
344
  setActiveComponentSpacing({
444
345
  $component
445
346
  });
446
- timeoutRef.current && clearTimeout(timeoutRef.current);
447
- timeoutRef.current = setTimeout(()=>{
448
- if ($component) {
449
- setToolbarOnboarding({
450
- $component
451
- });
452
- }
453
- }, timeoutOnboarding);
454
347
  removeHoverComponent();
455
- // Reactive when component re-render
456
- watchComponentReRender($component, ()=>{
457
- setActiveComponent({
458
- componentUid,
459
- productId,
460
- articleId,
461
- timeAwait: 2000,
462
- forceReActive: true
463
- });
464
- });
465
348
  }, [
466
349
  removeActiveComponent,
467
350
  removeHoverComponent,
468
- setActiveComponentSpacing,
469
- setToolbarOnboarding
351
+ setActiveComponentSpacing
470
352
  ]);
471
353
  const setFocusTextEditor = async (value)=>{
472
354
  if (!value) {
473
- const $components = document.querySelectorAll('[data-outline-editor-inline-focus],[data-toolbar-editor-inline-focus],[data-spacing-hidden]');
474
- if ($components.length) {
355
+ const $components = document.body.querySelector('#storefront')?.querySelectorAll('[data-outline-editor-inline-focus],[data-toolbar-editor-inline-focus],[data-spacing-hidden]');
356
+ if ($components?.length) {
475
357
  $components.forEach(($component)=>{
476
358
  if ($component) {
477
359
  $component.removeAttribute('data-toolbar-editor-inline-focus');
@@ -482,9 +364,10 @@ const Toolbar = ()=>{
482
364
  }
483
365
  } else {
484
366
  if (currentComponentActive.current?.componentUid) {
485
- const componentUid = currentComponentActive.current?.componentUid;
486
- const productId = currentComponentActive.current?.productId;
487
- const $component = await waitForElementToExist(`${productId ? `[data-product-id="${productId}"] ` : ''}[data-uid="${componentUid}"]`, 500);
367
+ const selector = getSelectorComponent({
368
+ ...currentComponentActive.current
369
+ });
370
+ const $component = await waitForElementToExist(selector, 500);
488
371
  if ($component) {
489
372
  const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
490
373
  const $outline = getChildrenByAttrSelector($component, 'data-outline');
@@ -513,24 +396,28 @@ const Toolbar = ()=>{
513
396
  const $themeSectionUid = $themeSection?.getAttribute('data-uid');
514
397
  const isActiveThemeSection = $themeSection && $themeSectionUid === currentComponentActive.current?.componentUid;
515
398
  if (!isActiveThemeSection) return;
399
+ cacheHoverThemeSectionComponents.current.push($themeSection);
516
400
  const $themeSectionStatus = getChildrenByAttrSelector($themeSection, 'data-theme-section-status');
517
401
  if ($themeSectionStatus) {
518
402
  $themeSectionStatus.setAttribute('data-theme-section-status-active', 'true');
519
403
  }
520
404
  }, []);
521
405
  const setShowParents = async ({ value })=>{
522
- if (!value) {
406
+ if (!value || !currentComponentActive.current) {
523
407
  return;
524
408
  }
525
- const $component = await waitForElementToExist(`${currentComponentActive.current?.productId ? `[data-product-id="${currentComponentActive.current?.productId}"] ` : ''}[data-uid="${currentComponentActive.current?.componentUid}"]`, 500);
409
+ const selector = getSelectorComponent({
410
+ ...currentComponentActive.current
411
+ });
412
+ const $component = await waitForElementToExist(selector, 500);
526
413
  if ($component) {
527
414
  const $parents = $component?.querySelectorAll('[data-toolbar-parent]');
528
415
  if ($parents.length) {
529
416
  const onHover = ($parent)=>{
530
417
  const uid = $parent.getAttribute('data-parent-uid');
531
418
  if (!uid) return;
532
- const $parentComponents = document.querySelectorAll(`[data-uid="${uid}"]`);
533
- if ($parentComponents.length) {
419
+ const $parentComponents = document.body.querySelector('#storefront')?.querySelectorAll(`[data-uid="${uid}"]`);
420
+ if ($parentComponents?.length) {
534
421
  $parentComponents.forEach(($parentComponent)=>{
535
422
  const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
536
423
  if ($outline) {
@@ -543,8 +430,8 @@ const Toolbar = ()=>{
543
430
  const outHover = ($parent)=>{
544
431
  const uid = $parent.getAttribute('data-parent-uid');
545
432
  if (!uid) return;
546
- const $parentComponents = document.querySelectorAll(`[data-uid="${uid}"]`);
547
- if ($parentComponents.length) {
433
+ const $parentComponents = document.body.querySelector('#storefront')?.querySelectorAll(`[data-uid="${uid}"]`);
434
+ if ($parentComponents?.length) {
548
435
  $parentComponents.forEach(($parentComponent)=>{
549
436
  const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
550
437
  if ($outline) {
@@ -580,7 +467,8 @@ const Toolbar = ()=>{
580
467
  detail: {
581
468
  componentUid: uid,
582
469
  productId,
583
- articleId
470
+ articleId,
471
+ elementTag: $parent.getAttribute('data-component-tag') || ''
584
472
  }
585
473
  });
586
474
  outHover($parent);
@@ -598,42 +486,35 @@ const Toolbar = ()=>{
598
486
  if (isDragging.current) return;
599
487
  if (isResizeSpacing.current) return;
600
488
  const $target = e.target;
489
+ // check target
601
490
  if (!$target || typeof $target.closest !== 'function') {
602
- removeHoverOverlayComponent();
491
+ removeHoverThemeSectionComponent();
492
+ removeHoverComponent();
603
493
  return;
604
494
  }
605
- const $toolbarHover = $target.closest('[data-toolbar-hover]');
495
+ const { $toolbarHover, $component, $themeSection, $shopifySection } = findDOMClosest($target, {
496
+ $toolbarHover: '[data-toolbar-hover]',
497
+ $component: '[data-toolbar-wrap]',
498
+ $themeSection: '[data-theme-section]',
499
+ $shopifySection: '[data-shopify-section]'
500
+ });
606
501
  if ($toolbarHover) {
607
502
  // Disable feature overlay when hover to toolbar parents
608
503
  return;
609
- // removeHoverOverlayComponent(); // remove overlay old
610
- // // Hover to toolbar is focus
611
- // if ($toolbarHover?.getAttribute('data-toolbar-hover-focus')) return;
612
- // const $component = $target.closest('[data-toolbar-wrap]');
613
- // if (!$component) return;
614
- // const $outline = getChildrenByAttrSelector($component, 'data-outline');
615
- // if (!$outline) return;
616
- // const isThemeSection = $component.getAttribute('data-theme-section');
617
- // const outlineOverlay = isThemeSection
618
- // ? 'data-outline-overlay-theme-section'
619
- // : 'data-outline-overlay';
620
- // $outline.setAttribute(outlineOverlay, 'true');
621
504
  }
622
505
  // Hover to other component
623
- const $component = $target.closest('[data-toolbar-wrap]');
624
506
  const componentUid = $component?.getAttribute('data-uid');
625
507
  if (!$component || !componentUid || componentUid == 'ROOT') {
626
508
  removeHoverComponent();
627
509
  return;
628
510
  }
629
511
  const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
630
- const $outline = getChildrenByAttrSelector($component, 'data-outline');
631
- if ($outline) $outline.removeAttribute('data-outline-overlay');
632
512
  if (!componentUid) return;
633
513
  if (componentUid == 'ROOT') return;
634
514
  if ($toolbar?.getAttribute('data-toolbar-hover-focus')) return;
635
515
  if (!$toolbar?.getAttribute('data-toolbar-hover-focus')) removeHoverComponent();
636
516
  hoverActiveThemeSection($target);
517
+ const $preventSection = $themeSection || $shopifySection;
637
518
  // Disable event when hover active component
638
519
  if (componentUid == currentComponentActive.current?.componentUid) {
639
520
  if (currentComponentActive.current.productId) {
@@ -646,7 +527,6 @@ const Toolbar = ()=>{
646
527
  }
647
528
  }
648
529
  }
649
- const $preventSection = $target.closest('[data-theme-section]') || $target.closest('[data-shopify-section]');
650
530
  if ($preventSection) {
651
531
  setHoverComponent({
652
532
  $component: $preventSection,
@@ -657,7 +537,6 @@ const Toolbar = ()=>{
657
537
  return;
658
538
  }
659
539
  }
660
- const $preventSection = $target.closest('[data-theme-section]') || $target.closest('[data-shopify-section]');
661
540
  if ($preventSection) {
662
541
  setHoverComponent({
663
542
  $component: $preventSection,
@@ -680,7 +559,7 @@ const Toolbar = ()=>{
680
559
  removeHoverComponent,
681
560
  setHoverComponent,
682
561
  setHoverComponentParents,
683
- removeHoverOverlayComponent,
562
+ removeHoverThemeSectionComponent,
684
563
  currentComponentActive
685
564
  ]);
686
565
  const onActiveComponent = useCallback((e)=>{
@@ -745,8 +624,8 @@ const Toolbar = ()=>{
745
624
  ]);
746
625
  const setHoverParentComponent = (uid, type)=>{
747
626
  if (!uid) return;
748
- const $parentComponents = document.querySelectorAll(`[data-uid="${uid}"]`);
749
- if ($parentComponents.length) {
627
+ const $parentComponents = document.body.querySelector('#storefront')?.querySelectorAll(`[data-uid="${uid}"]`);
628
+ if ($parentComponents?.length) {
750
629
  $parentComponents.forEach(($parentComponent)=>{
751
630
  const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
752
631
  if ($outline) {
@@ -770,19 +649,14 @@ const Toolbar = ()=>{
770
649
  }, [
771
650
  isDragging
772
651
  ]);
773
- const onToolbarOnboarding = useCallback((e)=>{
652
+ const onComponentReRender = (e)=>{
774
653
  const detail = e.detail;
775
- if (detail?.isNewUser) {
776
- setIsOnboarding(true);
777
- }
778
- }, []);
779
- const onWindowResize = useCallback(()=>{
780
- if (isOnboarding) {
781
- calculateOnboardingPosition();
654
+ if (currentComponentActive.current?.componentUid && detail?.componentUid == currentComponentActive.current?.componentUid) {
655
+ setActiveComponent({
656
+ ...currentComponentActive.current
657
+ });
782
658
  }
783
- }, [
784
- isOnboarding
785
- ]);
659
+ };
786
660
  /* Register event */ useEffect(()=>{
787
661
  document.addEventListener('mousemove', onMouseMove);
788
662
  window.addEventListener('editor:active-component', onActiveComponent);
@@ -792,8 +666,7 @@ const Toolbar = ()=>{
792
666
  window.addEventListener('editor:toolbar:show-parents', onShowParents);
793
667
  window.addEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
794
668
  window.addEventListener('editor:hover-component', onHoverComponent);
795
- window.addEventListener('editor:toolbar-onboarding', onToolbarOnboarding);
796
- window.addEventListener('resize', onWindowResize);
669
+ window.addEventListener('editor:component:render', onComponentReRender);
797
670
  return ()=>{
798
671
  document.removeEventListener('mousemove', onMouseMove);
799
672
  window.removeEventListener('editor:active-component', onActiveComponent);
@@ -803,8 +676,7 @@ const Toolbar = ()=>{
803
676
  window.removeEventListener('editor:toolbar:show-parents', onShowParents);
804
677
  window.removeEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
805
678
  window.removeEventListener('editor:hover-component', onHoverComponent);
806
- window.removeEventListener('editor:toolbar-onboarding', onToolbarOnboarding);
807
- window.removeEventListener('resize', onWindowResize);
679
+ window.removeEventListener('editor:component:render', onComponentReRender);
808
680
  };
809
681
  }, [
810
682
  onMouseMove,
@@ -815,91 +687,9 @@ const Toolbar = ()=>{
815
687
  onShowParents,
816
688
  onResizeSpacing,
817
689
  onHoverComponent,
818
- onToolbarOnboarding,
819
- onWindowResize
690
+ onComponentReRender
820
691
  ]);
821
- return isOnboarding && /*#__PURE__*/ jsx(Onboarding, {
822
- enable: true,
823
- position: onboardingPosition,
824
- onCloseOnboarding: onCloseOnboarding
825
- });
826
- };
827
- const getDOMElementParents = ($el, selector, limit)=>{
828
- // Set up a parent array
829
- const parents = [];
830
- // Push each parent $elms to the array
831
- while($el){
832
- $el = $el.parentElement ?? undefined;
833
- if ($el) {
834
- if ($el.tagName === 'BODY' || $el.getAttribute('data-uid') === 'ROOT') {
835
- break;
836
- }
837
- if (selector) {
838
- if ($el.matches(selector)) {
839
- parents.push($el);
840
- if (limit && parents.length == limit) {
841
- return parents;
842
- }
843
- }
844
- continue;
845
- }
846
- parents.push($el);
847
- if (limit && parents.length == limit) {
848
- return parents;
849
- }
850
- }
851
- }
852
- // Return our parent array
853
- return parents;
854
- };
855
- const getChildrenByAttrSelector = ($el, attrSelector)=>{
856
- const childLen = $el.children.length;
857
- if (childLen) {
858
- for(let i = 0; i < childLen; i++){
859
- const children = $el.children[i];
860
- if (children) {
861
- const is = children.getAttribute(attrSelector);
862
- if (is) {
863
- return children;
864
- }
865
- }
866
- }
867
- }
868
- };
869
- const isOverParent = ({ current, parent: parent1, index, revert })=>{
870
- for(let i = 0; i < index; i++){
871
- 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;
872
- if (revert) {
873
- 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;
874
- }
875
- if (is) return true;
876
- }
877
- return false;
878
- };
879
- const waitForElementToExist = (selector, timeout = 200)=>{
880
- return new Promise((resolve)=>{
881
- const intervalID = setInterval(()=>{
882
- const el = document.querySelector(selector);
883
- if (el) {
884
- clearInterval(intervalID);
885
- clearTimeout(timeoutID);
886
- resolve(el);
887
- }
888
- }, 50);
889
- const timeoutID = setTimeout(()=>{
890
- clearInterval(intervalID);
891
- clearTimeout(timeoutID);
892
- resolve(null);
893
- }, timeout);
894
- });
895
- };
896
- const notVisible = (el)=>{
897
- const overflow = getComputedStyle(el).overflow;
898
- return overflow !== 'visible';
899
- };
900
- const isSection = (el)=>{
901
- const tag = el.getAttribute('data-component-tag');
902
- return tag === 'Section';
692
+ return /*#__PURE__*/ jsx(Fragment, {});
903
693
  };
904
694
  var Toolbar$1 = /*#__PURE__*/ memo(Toolbar);
905
695