@gem-sdk/pages 1.36.6 → 2.0.0-dev.832

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 (110) hide show
  1. package/dist/cjs/components/ErrorBoundary.js +1 -40
  2. package/dist/cjs/components/ErrorFallback.js +1 -26
  3. package/dist/cjs/components/FacebookPixel.js +3 -36
  4. package/dist/cjs/components/Footer.js +1 -125
  5. package/dist/cjs/components/FooterForPostPurchase.js +1 -0
  6. package/dist/cjs/components/GoogleAnalytic.js +5 -67
  7. package/dist/cjs/components/Header.js +1 -96
  8. package/dist/cjs/components/TikTokPixel.js +3 -19
  9. package/dist/cjs/components/builder/PopupManager.js +1 -62
  10. package/dist/cjs/components/builder/Toolbar.js +1 -883
  11. package/dist/cjs/components/builder/Toolbox.js +1 -384
  12. package/dist/cjs/components/builder/toolbar/Onboarding.js +1 -110
  13. package/dist/cjs/components/image-to-layout/AddSectionImageToLayout.js +1 -263
  14. package/dist/cjs/components/image-to-layout/DropElement.js +1 -164
  15. package/dist/cjs/components/image-to-layout/ImageToLayout.js +1 -41
  16. package/dist/cjs/index.js +1 -75
  17. package/dist/cjs/layouts/main.js +1 -30
  18. package/dist/cjs/libs/api/get-builder-props.js +1 -41
  19. package/dist/cjs/libs/api/get-collection-props.js +1 -68
  20. package/dist/cjs/libs/api/get-home-page-props-v2.js +1 -145
  21. package/dist/cjs/libs/api/get-home-page-props.js +1 -151
  22. package/dist/cjs/libs/api/get-post-purchase-props-preview.js +1 -0
  23. package/dist/cjs/libs/api/get-preview-props.js +1 -18
  24. package/dist/cjs/libs/api/get-product-props.js +1 -73
  25. package/dist/cjs/libs/api/get-static-page-props-preview.js +1 -150
  26. package/dist/cjs/libs/api/get-static-page-props-v2.js +1 -148
  27. package/dist/cjs/libs/api/get-static-page-props.js +1 -148
  28. package/dist/cjs/libs/custom-fonts.js +8 -0
  29. package/dist/cjs/libs/fetcher.js +1 -67
  30. package/dist/cjs/libs/get-layout.js +1 -13
  31. package/dist/cjs/libs/get-storefront-api.js +1 -12
  32. package/dist/cjs/libs/getStaticPaths.js +1 -10
  33. package/dist/cjs/libs/google-fonts.js +1 -81
  34. package/dist/cjs/libs/helpers/common.js +1 -27
  35. package/dist/cjs/libs/helpers/gen-css.js +1 -111
  36. package/dist/cjs/libs/helpers/gen-fonts.js +1 -68
  37. package/dist/cjs/libs/helpers/generate-manifres.js +1 -5
  38. package/dist/cjs/libs/helpers/get-fallback.js +1 -35
  39. package/dist/cjs/libs/helpers/normalize.js +1 -90
  40. package/dist/cjs/libs/helpers/parse-json.js +1 -16
  41. package/dist/cjs/libs/helpers/user-agent.js +1 -7
  42. package/dist/cjs/libs/hooks/use-tracking-view.js +1 -45
  43. package/dist/cjs/libs/hooks/usePagePreview.js +1 -0
  44. package/dist/cjs/libs/parse-html.js +1 -42
  45. package/dist/cjs/libs/shopify-cdn-with-google-fonts.js +1 -1845
  46. package/dist/cjs/pages/404.js +1 -43
  47. package/dist/cjs/pages/500.js +1 -74
  48. package/dist/cjs/pages/CollectionGlobalProvider.js +1 -59
  49. package/dist/cjs/pages/builder.js +1 -103
  50. package/dist/cjs/pages/collection-detail.js +1 -64
  51. package/dist/cjs/pages/preview.js +1 -26
  52. package/dist/cjs/pages/product-detail.js +1 -69
  53. package/dist/cjs/pages/static-v2.js +1 -84
  54. package/dist/cjs/pages/static.js +1 -75
  55. package/dist/esm/components/ErrorBoundary.js +1 -38
  56. package/dist/esm/components/ErrorFallback.js +1 -24
  57. package/dist/esm/components/FacebookPixel.js +3 -34
  58. package/dist/esm/components/Footer.js +1 -121
  59. package/dist/esm/components/FooterForPostPurchase.js +1 -0
  60. package/dist/esm/components/GoogleAnalytic.js +5 -65
  61. package/dist/esm/components/Header.js +1 -92
  62. package/dist/esm/components/TikTokPixel.js +3 -17
  63. package/dist/esm/components/builder/PopupManager.js +1 -58
  64. package/dist/esm/components/builder/Toolbar.js +1 -879
  65. package/dist/esm/components/builder/Toolbox.js +1 -380
  66. package/dist/esm/components/builder/toolbar/Onboarding.js +1 -106
  67. package/dist/esm/components/image-to-layout/AddSectionImageToLayout.js +1 -259
  68. package/dist/esm/components/image-to-layout/DropElement.js +1 -162
  69. package/dist/esm/components/image-to-layout/ImageToLayout.js +1 -37
  70. package/dist/esm/index.js +1 -33
  71. package/dist/esm/layouts/main.js +1 -26
  72. package/dist/esm/libs/api/get-builder-props.js +1 -39
  73. package/dist/esm/libs/api/get-collection-props.js +1 -66
  74. package/dist/esm/libs/api/get-home-page-props-v2.js +1 -143
  75. package/dist/esm/libs/api/get-home-page-props.js +1 -149
  76. package/dist/esm/libs/api/get-post-purchase-props-preview.js +1 -0
  77. package/dist/esm/libs/api/get-preview-props.js +1 -16
  78. package/dist/esm/libs/api/get-product-props.js +1 -71
  79. package/dist/esm/libs/api/get-static-page-props-preview.js +1 -148
  80. package/dist/esm/libs/api/get-static-page-props-v2.js +1 -146
  81. package/dist/esm/libs/api/get-static-page-props.js +1 -146
  82. package/dist/esm/libs/custom-fonts.js +8 -0
  83. package/dist/esm/libs/fetcher.js +1 -64
  84. package/dist/esm/libs/get-layout.js +1 -11
  85. package/dist/esm/libs/get-storefront-api.js +1 -10
  86. package/dist/esm/libs/getStaticPaths.js +1 -8
  87. package/dist/esm/libs/google-fonts.js +1 -75
  88. package/dist/esm/libs/helpers/common.js +1 -24
  89. package/dist/esm/libs/helpers/gen-css.js +1 -109
  90. package/dist/esm/libs/helpers/gen-fonts.js +1 -65
  91. package/dist/esm/libs/helpers/generate-manifres.js +1 -3
  92. package/dist/esm/libs/helpers/get-fallback.js +1 -33
  93. package/dist/esm/libs/helpers/normalize.js +1 -85
  94. package/dist/esm/libs/helpers/parse-json.js +1 -13
  95. package/dist/esm/libs/helpers/user-agent.js +1 -5
  96. package/dist/esm/libs/hooks/use-tracking-view.js +1 -43
  97. package/dist/esm/libs/hooks/usePagePreview.js +1 -0
  98. package/dist/esm/libs/parse-html.js +1 -40
  99. package/dist/esm/libs/shopify-cdn-with-google-fonts.js +1 -1843
  100. package/dist/esm/pages/404.js +1 -41
  101. package/dist/esm/pages/500.js +1 -72
  102. package/dist/esm/pages/CollectionGlobalProvider.js +1 -55
  103. package/dist/esm/pages/builder.js +1 -101
  104. package/dist/esm/pages/collection-detail.js +1 -60
  105. package/dist/esm/pages/preview.js +1 -24
  106. package/dist/esm/pages/product-detail.js +1 -65
  107. package/dist/esm/pages/static-v2.js +1 -82
  108. package/dist/esm/pages/static.js +1 -71
  109. package/dist/types/index.d.ts +29 -6
  110. package/package.json +5 -5
@@ -1,879 +1 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { memo, useRef, useState, useCallback, useEffect } from 'react';
3
- import Onboarding from './toolbar/Onboarding.js';
4
-
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 Toolbar = ()=>{
16
- const currentComponentActive = useRef(null);
17
- const isDragging = useRef(false);
18
- const stopWatchReRenderComponent = useRef();
19
- const isResizeSpacing = useRef(false);
20
- const [isOnboarding, setIsOnboarding] = useState(false);
21
- const [countShowOnboarding, setCountShowOnboarding] = useState(0);
22
- const [onboardingPosition, setOnboardingPosition] = useState('bottom');
23
- const timeoutRef = useRef(null);
24
- const timeoutOnboarding = 5000;
25
- /* Functions */ const changePositionToolbar = ({ state, $toolbar, $component })=>{
26
- const $parentOverflow = findOverflowParent($component, $toolbar);
27
- const rect = $toolbar.getBoundingClientRect();
28
- const rectComponent = $component.getBoundingClientRect();
29
- const windowWidth = window.innerWidth;
30
- if ($parentOverflow) {
31
- if (rectComponent?.height <= 60) {
32
- $toolbar.setAttribute(`data-toolbar-${state}-revert`, 'true');
33
- } else {
34
- $toolbar.setAttribute(`data-toolbar-${state}-inside`, 'true');
35
- }
36
- // fix toolbar overflow right side
37
- if (rectComponent.left + rect.width > windowWidth) {
38
- $toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
39
- }
40
- } else {
41
- if (rect.top < TOOLBAR_ACTIVE_HEIGHT + 1) {
42
- if (rectComponent?.height <= 60) {
43
- $toolbar.setAttribute(`data-toolbar-${state}-revert`, 'true');
44
- } else {
45
- $toolbar.setAttribute(`data-toolbar-${state}-inside`, 'true');
46
- }
47
- }
48
- // fix toolbar overflow right side
49
- if (rectComponent.left + rect.width > windowWidth) {
50
- $toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
51
- }
52
- }
53
- // fix Popup overflow right position
54
- const popupEl = $component?.closest('[aria-label="Dialog body"]');
55
- if (popupEl) {
56
- const rectPopupEl = popupEl.getBoundingClientRect();
57
- const popupElRightPosition = rectPopupEl.left + rectPopupEl.width - 20;
58
- if (rectComponent.left + rect.width > popupElRightPosition) {
59
- $toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
60
- }
61
- }
62
- };
63
- const setHoverComponent = useCallback(({ $component, componentUid, focus, isThemeSection, isParent })=>{
64
- if (!$component && !componentUid) return;
65
- if (!$component) {
66
- const $c = document.querySelector(`[data-uid="${componentUid}"]`);
67
- if (!$c) return;
68
- $component = $c;
69
- }
70
- if (!componentUid) {
71
- const cUid = $component.getAttribute('data-uid');
72
- if (!cUid) return;
73
- componentUid = cUid;
74
- }
75
- const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
76
- const $outline = getChildrenByAttrSelector($component, 'data-outline');
77
- const $btnAddTop = getChildrenByAttrSelector($component, 'data-toolbar-add-top');
78
- const $btnAddBottom = getChildrenByAttrSelector($component, 'data-toolbar-add-bottom');
79
- const $themeSectionStatus = getChildrenByAttrSelector($component, 'data-theme-section-status');
80
- if (isThemeSection && $themeSectionStatus) {
81
- $themeSectionStatus.setAttribute('data-theme-section-status-active', 'true');
82
- }
83
- if ($toolbar) {
84
- $toolbar.removeAttribute('style');
85
- if (!isParent) {
86
- $toolbar.setAttribute('data-toolbar-hover', 'true');
87
- }
88
- if (focus) {
89
- $toolbar.setAttribute('data-toolbar-hover-focus', 'true');
90
- }
91
- changePositionToolbar({
92
- $toolbar,
93
- $component,
94
- state: 'hover'
95
- });
96
- }
97
- if ($outline) {
98
- $outline.setAttribute('data-outline-hover', 'true');
99
- if (isParent) {
100
- $outline.setAttribute('data-outline-parent-hover', 'true');
101
- }
102
- if (isThemeSection) {
103
- $outline.setAttribute('data-outline-overlay-theme-section', 'true');
104
- }
105
- if (focus) {
106
- $outline.setAttribute('data-outline-hover-focus', 'true');
107
- }
108
- }
109
- if ($btnAddTop) {
110
- if (!isParent) {
111
- $btnAddTop.setAttribute('data-toolbar-add-hover', 'true');
112
- }
113
- }
114
- if ($btnAddBottom) {
115
- if (!isParent) {
116
- $btnAddBottom.setAttribute('data-toolbar-add-hover', 'true');
117
- }
118
- }
119
- }, []);
120
- const setHoverComponentParents = useCallback(({ $component, componentUid })=>{
121
- if (!$component) {
122
- const $c = document.querySelector(`[data-uid="${componentUid}"]`);
123
- if (!$c) return;
124
- $component = $c;
125
- }
126
- const $parents = getDOMElementParents($component, '[data-uid][data-component-type="component"]:not([data-component-no-setting])', 1);
127
- if ($parents.length) {
128
- for (const $parent of $parents){
129
- if ($parent) {
130
- setHoverComponent({
131
- $component: $parent,
132
- isParent: true
133
- });
134
- }
135
- }
136
- changePositionToolbarParents({
137
- $component,
138
- $parents
139
- });
140
- }
141
- }, [
142
- setHoverComponent
143
- ]);
144
- const changePositionToolbarParents = ({ $component, $parents })=>{
145
- if (!$component) return;
146
- if (!$parents?.length) return;
147
- const $currentToolbar = getChildrenByAttrSelector($component, 'data-toolbar-hover-focus');
148
- if ($currentToolbar) {
149
- const currentRect = $currentToolbar.getBoundingClientRect();
150
- const isRevert = $currentToolbar.getAttribute('data-toolbar-hover-revert') ? true : false;
151
- const isInside = $currentToolbar.getAttribute('data-toolbar-hover-inside') ? true : false;
152
- let index = 1;
153
- for (const $parent of $parents){
154
- if ($parent) {
155
- const tag = $parent.getAttribute('data-component-tag');
156
- if (tag === 'Section') continue;
157
- const $toolbar = getChildrenByAttrSelector($parent, 'data-toolbar-hover');
158
- if ($toolbar) {
159
- // Ignore with toolbar active
160
- const isActive = $toolbar.getAttribute('data-toolbar-active');
161
- if (isActive) continue;
162
- // Start calc
163
- const parentRect = $toolbar.getBoundingClientRect();
164
- const checkRevert = isRevert || isInside;
165
- if (isOverParent({
166
- current: currentRect,
167
- parent: parentRect,
168
- index,
169
- revert: checkRevert
170
- })) {
171
- const parentStyle = getComputedStyle($toolbar);
172
- // parentStyle.top
173
- const diffTop = currentRect.top - parentRect.top;
174
- const diffLeft = currentRect.left - parentRect.left;
175
- let newTop = parseFloat(parentStyle.top) + diffTop - (TOOLBAR_HOVER_HEIGHT - 1) * index; // -1 border bottom
176
- if (checkRevert) {
177
- newTop = parseFloat(parentStyle.top) - diffTop + (TOOLBAR_HOVER_HEIGHT - 1) * index; // -1 border bottom
178
- }
179
- const newLeft = parseFloat(parentStyle.left) + diffLeft;
180
- $toolbar.setAttribute('style', `top: ${newTop}px;left: ${newLeft}px;`);
181
- index++;
182
- }
183
- }
184
- }
185
- }
186
- }
187
- };
188
- const removeHoverOverlayComponent = useCallback(()=>{
189
- const clearAttrs = [
190
- 'data-outline-overlay',
191
- 'data-outline-overlay-theme-section',
192
- 'data-theme-section-status-active'
193
- ];
194
- const $elms = document.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
195
- if ($elms) {
196
- clearAttrs.forEach((attr)=>{
197
- $elms.forEach(($el)=>$el.removeAttribute(attr));
198
- });
199
- }
200
- }, []);
201
- const removeHoverComponent = useCallback(()=>{
202
- const clearAttrs = [
203
- 'data-toolbar-hover-focus',
204
- 'data-toolbar-hover',
205
- 'data-outline-hover-focus',
206
- 'data-toolbar-hover-revert',
207
- 'data-toolbar-hover-inside',
208
- 'data-outline-hover',
209
- 'data-toolbar-add-hover',
210
- 'data-outline-parent-hover',
211
- 'data-toolbar-hover-overflow'
212
- ];
213
- const $elms = document.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
214
- if ($elms) {
215
- clearAttrs.forEach((attr)=>{
216
- $elms.forEach(($el)=>$el.removeAttribute(attr));
217
- });
218
- }
219
- removeHoverOverlayComponent();
220
- }, [
221
- removeHoverOverlayComponent
222
- ]);
223
- const onCloseOnboarding = useCallback(()=>{
224
- timeoutRef.current && clearTimeout(timeoutRef.current);
225
- if (countShowOnboarding > 0) {
226
- const eventCreate = new CustomEvent('editor:toolbar:close-onboarding', {
227
- bubbles: true,
228
- detail: {
229
- close: 'close Onboarding'
230
- }
231
- });
232
- window.dispatchEvent(eventCreate);
233
- setIsOnboarding(false);
234
- }
235
- }, [
236
- countShowOnboarding
237
- ]);
238
- const removeActiveComponent = useCallback(()=>{
239
- currentComponentActive.current = null;
240
- const clearAttrs = [
241
- 'data-toolbar-active',
242
- 'data-outline-active',
243
- 'data-toolbar-add-active',
244
- 'data-toolbar-active-revert',
245
- 'data-toolbar-active-inside',
246
- 'data-spacing-margin-bottom-active',
247
- 'data-toolbar-force-hover',
248
- 'data-outline-force-hover',
249
- 'data-toolbar-active-overflow'
250
- ];
251
- const $elms = document.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
252
- if ($elms) {
253
- clearAttrs.forEach((attr)=>{
254
- $elms.forEach(($el)=>$el.removeAttribute(attr));
255
- });
256
- }
257
- setFocusTextEditor(false);
258
- if (stopWatchReRenderComponent.current) stopWatchReRenderComponent.current();
259
- onCloseOnboarding();
260
- }, [
261
- onCloseOnboarding
262
- ]);
263
- const watchComponentReRender = ($el, callback)=>{
264
- // editor:component:render
265
- const onComponentReRender = (e)=>{
266
- const detail = e.detail;
267
- if (detail?.componentUid == currentComponentActive.current?.componentUid) {
268
- callback();
269
- }
270
- };
271
- window.removeEventListener('editor:component:render', onComponentReRender);
272
- window.addEventListener('editor:component:render', onComponentReRender);
273
- const $images = $el.querySelectorAll('img');
274
- if ($images?.length) {
275
- $images.forEach(($img)=>{
276
- $img.addEventListener('load', ()=>{
277
- callback();
278
- });
279
- });
280
- }
281
- stopWatchReRenderComponent.current = ()=>{
282
- window.removeEventListener('editor:component:render', onComponentReRender);
283
- };
284
- };
285
- const setActiveComponentSpacing = useCallback(({ $component })=>{
286
- if (!$component) return;
287
- const style = getComputedStyle($component);
288
- const $spacing = getChildrenByAttrSelector($component, 'data-spacing');
289
- const $marginBottom = ($spacing?.querySelector('[data-spacing-margin-bottom]')) || null;
290
- if ($marginBottom) {
291
- const $bg = $marginBottom.querySelector('[data-spacing-margin-bottom-bg]') || null;
292
- const $drag = $marginBottom.querySelector('[data-spacing-margin-bottom-drag]') || null;
293
- if ($bg && $drag) {
294
- const value = style.marginBottom;
295
- $bg.style.height = value;
296
- $drag.style.top = value;
297
- $marginBottom.setAttribute('data-spacing-margin-bottom-active', 'true');
298
- }
299
- }
300
- }, []);
301
- const calculateOnboardingPosition = ()=>{
302
- const toolbar = document.querySelector('[data-toolbar-active]');
303
- const toolbarOnboading = document.querySelector('[data-toolbar-onboarding]');
304
- if (toolbar && toolbarOnboading) {
305
- toolbarOnboading?.removeAttribute('data-onboarding-active');
306
- setTimeout(()=>{
307
- const rect = toolbar.getBoundingClientRect();
308
- const rectTop = rect.top || 0;
309
- const rectOnboading = toolbarOnboading?.getBoundingClientRect();
310
- const onboardingHeight = rectOnboading?.height || 0;
311
- const $iframe = parent.document.querySelector('.iframe');
312
- const $iframeWin = $iframe?.contentWindow;
313
- const iframeWinScrollY = $iframeWin?.scrollY || 0;
314
- const iframeHeight = $iframe?.clientHeight || 0;
315
- if (rectTop + onboardingHeight > iframeHeight) {
316
- const oboardingTop = rect.top + iframeWinScrollY - onboardingHeight - 8;
317
- toolbarOnboading?.setAttribute('style', `top: ${oboardingTop}px;left: ${rect.left}px;`);
318
- setOnboardingPosition('top');
319
- if ($iframeWin && oboardingTop < rect.top + iframeWinScrollY) {
320
- setTimeout(()=>{
321
- const toTop = oboardingTop - 20;
322
- $iframeWin.scrollTo({
323
- top: toTop,
324
- behavior: 'smooth'
325
- });
326
- }, 200);
327
- }
328
- } else {
329
- const oboardingTop = rect.top + iframeWinScrollY + rect.height + 8;
330
- toolbarOnboading?.setAttribute('style', `top: ${oboardingTop}px;left: ${rect.left}px;`);
331
- setOnboardingPosition('bottom');
332
- }
333
- setCountShowOnboarding((countShowOnboarding)=>countShowOnboarding + 1);
334
- toolbarOnboading?.setAttribute('data-onboarding-active', 'true');
335
- }, 100);
336
- }
337
- };
338
- const setToolbarOnboarding = useCallback(({ $component })=>{
339
- if (!$component) return;
340
- if (isSection($component) || isPopup($component) || isSticky($component)) return;
341
- const toolbarOnboading = document.querySelector('[data-toolbar-onboarding]');
342
- // only show one time
343
- if (countShowOnboarding == 0) {
344
- calculateOnboardingPosition();
345
- } else {
346
- onCloseOnboarding();
347
- toolbarOnboading?.removeAttribute('data-onboarding-active');
348
- }
349
- }, [
350
- countShowOnboarding,
351
- onCloseOnboarding
352
- ]);
353
- const setActiveComponent = useCallback(async ({ componentUid, productId, timeAwait = 500, forceReActive })=>{
354
- if (!componentUid) return;
355
- let $component = await waitForElementToExist(`${productId ? `[data-product-id="${productId}"] ` : ''}[data-uid="${componentUid}"]`, timeAwait);
356
- // check element fetch data: product, product list
357
- if (!$component) {
358
- const isLoading = document.querySelector(`.gp-loading-placeholder`);
359
- if (!isLoading) {
360
- return;
361
- }
362
- if (isLoading) {
363
- // await element onload
364
- $component = await waitForElementToExist(`${productId ? `[data-product-id="${productId}"] ` : ''}[data-uid="${componentUid}"]`, 15000);
365
- }
366
- }
367
- if (!$component) {
368
- return;
369
- }
370
- if (!forceReActive && componentUid == currentComponentActive.current?.componentUid && productId == currentComponentActive.current?.productId) return;
371
- if (componentUid !== currentComponentActive.current?.componentUid || productId !== currentComponentActive.current?.productId || forceReActive) removeActiveComponent();
372
- const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
373
- const $outline = getChildrenByAttrSelector($component, 'data-outline');
374
- const $btnAddTop = getChildrenByAttrSelector($component, 'data-toolbar-add-top');
375
- const $btnAddBottom = getChildrenByAttrSelector($component, 'data-toolbar-add-bottom');
376
- if ($toolbar) {
377
- currentComponentActive.current = {
378
- componentUid,
379
- productId
380
- };
381
- $toolbar.removeAttribute('style');
382
- $toolbar.setAttribute('data-toolbar-active', 'true');
383
- changePositionToolbar({
384
- $toolbar,
385
- $component,
386
- state: 'active'
387
- });
388
- }
389
- if ($outline) {
390
- $outline.setAttribute('data-outline-active', 'true');
391
- }
392
- if ($btnAddTop) {
393
- $btnAddTop.setAttribute('data-toolbar-add-active', 'true');
394
- }
395
- if ($btnAddBottom) {
396
- $btnAddBottom.setAttribute('data-toolbar-add-active', 'true');
397
- }
398
- // Active same element in product list
399
- if (productId) {
400
- const $relatedElements = document.querySelectorAll(`[data-uid="${componentUid}"]`);
401
- if ($relatedElements?.length) {
402
- $relatedElements.forEach(($relatedElement)=>{
403
- const $outline = getChildrenByAttrSelector($relatedElement, 'data-outline');
404
- if ($outline) {
405
- $outline.setAttribute('data-outline-active', 'true');
406
- }
407
- });
408
- }
409
- }
410
- setActiveComponentSpacing({
411
- $component
412
- });
413
- timeoutRef.current && clearTimeout(timeoutRef.current);
414
- timeoutRef.current = setTimeout(()=>{
415
- if ($component) {
416
- setToolbarOnboarding({
417
- $component
418
- });
419
- }
420
- }, timeoutOnboarding);
421
- removeHoverComponent();
422
- // Reactive when component re-render
423
- watchComponentReRender($component, ()=>{
424
- setActiveComponent({
425
- componentUid,
426
- productId,
427
- timeAwait: 2000,
428
- forceReActive: true
429
- });
430
- });
431
- }, [
432
- removeActiveComponent,
433
- removeHoverComponent,
434
- setActiveComponentSpacing,
435
- setToolbarOnboarding
436
- ]);
437
- const setFocusTextEditor = async (value)=>{
438
- if (!value) {
439
- const $components = document.querySelectorAll('[data-outline-editor-inline-focus],[data-toolbar-editor-inline-focus],[data-spacing-hidden]');
440
- if ($components.length) {
441
- $components.forEach(($component)=>{
442
- if ($component) {
443
- $component.removeAttribute('data-toolbar-editor-inline-focus');
444
- $component.removeAttribute('data-outline-editor-inline-focus');
445
- $component.removeAttribute('data-spacing-hidden');
446
- }
447
- });
448
- }
449
- } else {
450
- if (currentComponentActive.current?.componentUid) {
451
- const componentUid = currentComponentActive.current?.componentUid;
452
- const productId = currentComponentActive.current?.productId;
453
- const $component = await waitForElementToExist(`${productId ? `[data-product-id="${productId}"] ` : ''}[data-uid="${componentUid}"]`, 500);
454
- if ($component) {
455
- const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
456
- const $outline = getChildrenByAttrSelector($component, 'data-outline');
457
- const $spacing = getChildrenByAttrSelector($component, 'data-spacing');
458
- if ($toolbar) {
459
- if (value) {
460
- $toolbar.setAttribute('data-toolbar-editor-inline-focus', 'true');
461
- }
462
- }
463
- if ($outline) {
464
- if (value) {
465
- $outline.setAttribute('data-outline-editor-inline-focus', 'true');
466
- }
467
- }
468
- if ($spacing) {
469
- if (value) {
470
- $spacing.setAttribute('data-spacing-hidden', 'true');
471
- }
472
- }
473
- }
474
- }
475
- }
476
- };
477
- const hoverActiveThemeSection = useCallback(($target)=>{
478
- const $themeSection = $target.closest('[data-theme-section]');
479
- const $themeSectionUid = $themeSection?.getAttribute('data-uid');
480
- const isActiveThemeSection = $themeSection && $themeSectionUid === currentComponentActive.current?.componentUid;
481
- if (!isActiveThemeSection) return;
482
- const $themeSectionStatus = getChildrenByAttrSelector($themeSection, 'data-theme-section-status');
483
- if ($themeSectionStatus) {
484
- $themeSectionStatus.setAttribute('data-theme-section-status-active', 'true');
485
- }
486
- }, []);
487
- const setShowParents = async ({ value })=>{
488
- if (!value) {
489
- return;
490
- }
491
- const $component = await waitForElementToExist(`${currentComponentActive.current?.productId ? `[data-product-id="${currentComponentActive.current?.productId}"] ` : ''}[data-uid="${currentComponentActive.current?.componentUid}"]`, 500);
492
- if ($component) {
493
- const $parents = $component?.querySelectorAll('[data-toolbar-parent]');
494
- if ($parents.length) {
495
- const onHover = ($parent)=>{
496
- const uid = $parent.getAttribute('data-parent-uid');
497
- if (!uid) return;
498
- const $parentComponents = document.querySelectorAll(`[data-uid="${uid}"]`);
499
- if ($parentComponents.length) {
500
- $parentComponents.forEach(($parentComponent)=>{
501
- const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
502
- if ($outline) {
503
- $outline.setAttribute('data-outline-force-hover', 'true');
504
- $outline.setAttribute('data-outline-force-overlay', 'true');
505
- }
506
- });
507
- }
508
- };
509
- const outHover = ($parent)=>{
510
- const uid = $parent.getAttribute('data-parent-uid');
511
- if (!uid) return;
512
- const $parentComponents = document.querySelectorAll(`[data-uid="${uid}"]`);
513
- if ($parentComponents.length) {
514
- $parentComponents.forEach(($parentComponent)=>{
515
- const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
516
- if ($outline) {
517
- $outline.removeAttribute('data-outline-force-hover');
518
- $outline.removeAttribute('data-outline-force-overlay');
519
- }
520
- });
521
- }
522
- };
523
- const onClick = async ($parent)=>{
524
- const uid = $parent.getAttribute('data-parent-uid');
525
- if (!uid) return;
526
- const isElementInsideProduct = async ()=>{
527
- const $component = await waitForElementToExist(`[data-uid="${uid}"]`, 500);
528
- const $product = $component?.closest('[data-product-id]');
529
- const productId = $product?.getAttribute('data-product-id') || '';
530
- return productId ? true : false;
531
- };
532
- let productId = '';
533
- if (await isElementInsideProduct()) {
534
- productId = currentComponentActive.current?.productId || '';
535
- }
536
- const event = new CustomEvent('editor:toolbar:force-active-component', {
537
- bubbles: true,
538
- detail: {
539
- componentUid: uid,
540
- productId: productId
541
- }
542
- });
543
- outHover($parent);
544
- window.dispatchEvent(event);
545
- };
546
- $parents.forEach(($parent)=>{
547
- $parent.addEventListener('mouseover', ()=>onHover($parent));
548
- $parent.addEventListener('mouseout', ()=>outHover($parent));
549
- $parent.addEventListener('click', ()=>onClick($parent));
550
- });
551
- }
552
- }
553
- };
554
- /* Event listener */ const onMouseMove = useCallback((e)=>{
555
- if (isDragging.current) return;
556
- if (isResizeSpacing.current) return;
557
- const $target = e.target;
558
- if (!$target || typeof $target.closest !== 'function') {
559
- removeHoverOverlayComponent();
560
- return;
561
- }
562
- const $toolbarHover = $target.closest('[data-toolbar-hover]');
563
- if ($toolbarHover) {
564
- // Disable feature overlay when hover to toolbar parents
565
- return;
566
- // removeHoverOverlayComponent(); // remove overlay old
567
- // // Hover to toolbar is focus
568
- // if ($toolbarHover?.getAttribute('data-toolbar-hover-focus')) return;
569
- // const $component = $target.closest('[data-toolbar-wrap]');
570
- // if (!$component) return;
571
- // const $outline = getChildrenByAttrSelector($component, 'data-outline');
572
- // if (!$outline) return;
573
- // const isThemeSection = $component.getAttribute('data-theme-section');
574
- // const outlineOverlay = isThemeSection
575
- // ? 'data-outline-overlay-theme-section'
576
- // : 'data-outline-overlay';
577
- // $outline.setAttribute(outlineOverlay, 'true');
578
- }
579
- // Hover to other component
580
- const $component = $target.closest('[data-toolbar-wrap]');
581
- const componentUid = $component?.getAttribute('data-uid');
582
- if (!$component || !componentUid || componentUid == 'ROOT') {
583
- removeHoverComponent();
584
- return;
585
- }
586
- const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
587
- const $outline = getChildrenByAttrSelector($component, 'data-outline');
588
- if ($outline) $outline.removeAttribute('data-outline-overlay');
589
- if (!componentUid) return;
590
- if (componentUid == 'ROOT') return;
591
- if ($toolbar?.getAttribute('data-toolbar-hover-focus')) return;
592
- if (!$toolbar?.getAttribute('data-toolbar-hover-focus')) removeHoverComponent();
593
- hoverActiveThemeSection($target);
594
- // Disable event when hover active component
595
- if (componentUid == currentComponentActive.current?.componentUid) {
596
- if (currentComponentActive.current.productId) {
597
- const $product = $component.closest(`[data-product-id]`);
598
- if ($product) {
599
- const productId = $product.getAttribute('data-product-id');
600
- if (productId == currentComponentActive.current.productId) {
601
- removeHoverComponent();
602
- return;
603
- }
604
- }
605
- }
606
- const $themeSection = $target.closest('[data-theme-section]');
607
- if ($themeSection) {
608
- setHoverComponent({
609
- $component: $themeSection,
610
- focus: true,
611
- isThemeSection: true
612
- });
613
- } else {
614
- return;
615
- }
616
- }
617
- const $themeSection = $target.closest('[data-theme-section]');
618
- if ($themeSection) {
619
- setHoverComponent({
620
- $component: $themeSection,
621
- focus: true,
622
- isThemeSection: true
623
- });
624
- } else {
625
- setHoverComponent({
626
- $component,
627
- componentUid,
628
- focus: true
629
- });
630
- setHoverComponentParents({
631
- $component,
632
- componentUid
633
- });
634
- }
635
- }, [
636
- hoverActiveThemeSection,
637
- removeHoverComponent,
638
- setHoverComponent,
639
- setHoverComponentParents,
640
- removeHoverOverlayComponent,
641
- currentComponentActive
642
- ]);
643
- const onActiveComponent = useCallback((e)=>{
644
- if (isDragging.current) return;
645
- const detail = e.detail;
646
- if (detail?.componentUid) {
647
- setActiveComponent({
648
- componentUid: detail.componentUid,
649
- productId: detail.productId
650
- });
651
- } else {
652
- removeActiveComponent();
653
- }
654
- }, [
655
- setActiveComponent,
656
- removeActiveComponent,
657
- isDragging
658
- ]);
659
- const onFocusOutsidePreview = useCallback(()=>{
660
- removeHoverComponent();
661
- }, [
662
- removeHoverComponent
663
- ]);
664
- const onIsDragging = useCallback((e)=>{
665
- const detail = e.detail;
666
- if (detail.value) {
667
- removeHoverComponent();
668
- removeActiveComponent();
669
- }
670
- isDragging.current = detail.value;
671
- }, [
672
- removeHoverComponent,
673
- removeActiveComponent
674
- ]);
675
- const onIsEditingTextEditor = useCallback((e)=>{
676
- const detail = e.detail;
677
- if (detail.value) {
678
- setFocusTextEditor(true);
679
- } else {
680
- setFocusTextEditor(false);
681
- }
682
- }, []);
683
- const onShowParents = useCallback((e)=>{
684
- if (isDragging.current) return;
685
- const detail = e.detail;
686
- setShowParents({
687
- value: detail?.value || false
688
- });
689
- }, []);
690
- const onResizeSpacing = useCallback((e)=>{
691
- const detail = e.detail;
692
- if (detail?.value) {
693
- removeHoverComponent();
694
- isResizeSpacing.current = true;
695
- } else {
696
- isResizeSpacing.current = false;
697
- }
698
- }, [
699
- removeHoverComponent
700
- ]);
701
- const setHoverParentComponent = (uid, type)=>{
702
- if (!uid) return;
703
- const $parentComponents = document.querySelectorAll(`[data-uid="${uid}"]`);
704
- if ($parentComponents.length) {
705
- $parentComponents.forEach(($parentComponent)=>{
706
- const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
707
- if ($outline) {
708
- if (type === 'in') {
709
- $outline.setAttribute('data-outline-force-hover', 'true');
710
- $outline.setAttribute('data-outline-force-overlay', 'true');
711
- } else {
712
- $outline.removeAttribute('data-outline-force-hover');
713
- $outline.removeAttribute('data-outline-force-overlay');
714
- }
715
- }
716
- });
717
- }
718
- };
719
- const onHoverComponent = useCallback((e)=>{
720
- if (isDragging.current) return;
721
- const detail = e.detail;
722
- if (detail?.componentUid) {
723
- setHoverParentComponent(detail?.componentUid, detail?.type);
724
- }
725
- }, [
726
- isDragging
727
- ]);
728
- const onToolbarOnboarding = useCallback((e)=>{
729
- const detail = e.detail;
730
- if (detail?.isNewUser) {
731
- setIsOnboarding(true);
732
- }
733
- }, []);
734
- const onWindowResize = useCallback(()=>{
735
- if (isOnboarding) {
736
- calculateOnboardingPosition();
737
- }
738
- }, [
739
- isOnboarding
740
- ]);
741
- /* Register event */ useEffect(()=>{
742
- document.addEventListener('mousemove', onMouseMove);
743
- window.addEventListener('editor:active-component', onActiveComponent);
744
- window.addEventListener('editor:focus-outside-preview', onFocusOutsidePreview);
745
- window.addEventListener('editor:is-dragging', onIsDragging);
746
- window.addEventListener('editor:is-editing-text-editor', onIsEditingTextEditor);
747
- window.addEventListener('editor:toolbar:show-parents', onShowParents);
748
- window.addEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
749
- window.addEventListener('editor:hover-component', onHoverComponent);
750
- window.addEventListener('editor:toolbar-onboarding', onToolbarOnboarding);
751
- window.addEventListener('resize', onWindowResize);
752
- return ()=>{
753
- document.removeEventListener('mousemove', onMouseMove);
754
- window.removeEventListener('editor:active-component', onActiveComponent);
755
- window.removeEventListener('editor:is-dragging', onFocusOutsidePreview);
756
- window.removeEventListener('editor:is-dragging', onIsDragging);
757
- window.removeEventListener('editor:is-editing-text-editor', onIsEditingTextEditor);
758
- window.removeEventListener('editor:toolbar:show-parents', onShowParents);
759
- window.removeEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
760
- window.removeEventListener('editor:hover-component', onHoverComponent);
761
- window.removeEventListener('editor:toolbar-onboarding', onToolbarOnboarding);
762
- window.removeEventListener('resize', onWindowResize);
763
- };
764
- }, [
765
- onMouseMove,
766
- onActiveComponent,
767
- onFocusOutsidePreview,
768
- onIsDragging,
769
- onIsEditingTextEditor,
770
- onShowParents,
771
- onResizeSpacing,
772
- onHoverComponent,
773
- onToolbarOnboarding,
774
- onWindowResize
775
- ]);
776
- return isOnboarding && /*#__PURE__*/ jsx(Onboarding, {
777
- enable: true,
778
- position: onboardingPosition,
779
- onCloseOnboarding: onCloseOnboarding
780
- });
781
- };
782
- const getDOMElementParents = ($el, selector, limit)=>{
783
- // Set up a parent array
784
- const parents = [];
785
- // Push each parent $elms to the array
786
- while($el){
787
- $el = $el.parentElement ?? undefined;
788
- if ($el) {
789
- if ($el.tagName === 'BODY' || $el.getAttribute('data-uid') === 'ROOT') {
790
- break;
791
- }
792
- if (selector) {
793
- if ($el.matches(selector)) {
794
- parents.push($el);
795
- if (limit && parents.length == limit) {
796
- return parents;
797
- }
798
- }
799
- continue;
800
- }
801
- parents.push($el);
802
- if (limit && parents.length == limit) {
803
- return parents;
804
- }
805
- }
806
- }
807
- // Return our parent array
808
- return parents;
809
- };
810
- const getChildrenByAttrSelector = ($el, attrSelector)=>{
811
- const childLen = $el.children.length;
812
- if (childLen) {
813
- for(let i = 0; i < childLen; i++){
814
- const children = $el.children[i];
815
- if (children) {
816
- const is = children.getAttribute(attrSelector);
817
- if (is) {
818
- return children;
819
- }
820
- }
821
- }
822
- }
823
- };
824
- const isOverParent = ({ current, parent: parent1, index, revert })=>{
825
- for(let i = 0; i < index; i++){
826
- 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;
827
- if (revert) {
828
- 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;
829
- }
830
- if (is) return true;
831
- }
832
- return false;
833
- };
834
- const waitForElementToExist = (selector, timeout = 200)=>{
835
- return new Promise((resolve)=>{
836
- const intervalID = setInterval(()=>{
837
- const el = document.querySelector(selector);
838
- if (el) {
839
- clearInterval(intervalID);
840
- clearTimeout(timeoutID);
841
- resolve(el);
842
- }
843
- }, 50);
844
- const timeoutID = setTimeout(()=>{
845
- clearInterval(intervalID);
846
- clearTimeout(timeoutID);
847
- resolve(null);
848
- }, timeout);
849
- });
850
- };
851
- const notVisible = (el)=>{
852
- const overflow = getComputedStyle(el).overflow;
853
- return overflow !== 'visible';
854
- };
855
- const isSection = (el)=>{
856
- const tag = el.getAttribute('data-component-tag');
857
- return tag === 'Section';
858
- };
859
- const isOverToolbarPosition = (el, parent1)=>{
860
- const rect = el.getBoundingClientRect();
861
- const rectP = parent1.getBoundingClientRect();
862
- // 32px = toolbar active height
863
- return rect.top - rectP.top < TOOLBAR_ACTIVE_HEIGHT + 1;
864
- };
865
- const findOverflowParent = (element, initEl)=>{
866
- const thisEl = element;
867
- const origEl = initEl || thisEl;
868
- if (!thisEl) return;
869
- if (isSection(thisEl)) return;
870
- if (notVisible(thisEl) && isOverToolbarPosition(initEl, thisEl)) return thisEl;
871
- if (thisEl.parentElement) {
872
- return findOverflowParent(thisEl.parentElement, origEl);
873
- } else {
874
- return;
875
- }
876
- };
877
- var Toolbar$1 = /*#__PURE__*/ memo(Toolbar);
878
-
879
- export { Toolbar$1 as default };
1
+ import{jsx as t}from"react/jsx-runtime";import{memo as e,useRef as r,useState as o,useCallback as a,useEffect as i}from"react";import n from"./toolbar/Onboarding.js";import{usePageType as l}from"@gem-sdk/core";let TOOLBAR_HOVER_HEIGHT=24,TOOLBAR_ACTIVE_HEIGHT=32,getDOMElementParents=(t,e,r)=>{let o=[];for(;t;)if(t=t.parentElement??void 0){if("BODY"===t.tagName||"ROOT"===t.getAttribute("data-uid"))break;if(e){if(t.matches(e)&&(o.push(t),r&&o.length==r))return o;continue}if(o.push(t),r&&o.length==r)break}return o},getChildrenByAttrSelector=(t,e)=>{let r=t.children.length;if(r)for(let o=0;o<r;o++){let r=t.children[o];if(r){let t=r.getAttribute(e);if(t)return r}}},isOverParent=({current:t,parent:e,index:r,revert:o})=>{for(let a=0;a<r;a++){let r=t.top-23*a>=e.top&&t.top-23*a<=e.top+e.height||t.top-23*a>=e.top+e.height&&t.top-23*a<=e.top;if(o&&(r=t.bottom+23*a>=e.bottom&&t.bottom+23*a<=e.bottom-e.height||t.bottom+23*a>=e.bottom-e.height&&t.bottom+23*a<=e.bottom),r)return!0}return!1},waitForElementToExist=(t,e=200)=>new Promise(r=>{let o=setInterval(()=>{let e=document.querySelector(t);e&&(clearInterval(o),clearTimeout(a),r(e))},50),a=setTimeout(()=>{clearInterval(o),clearTimeout(a),r(null)},e)}),notVisible=t=>{let e=getComputedStyle(t).overflow;return"visible"!==e},isSection=t=>{let e=t.getAttribute("data-component-tag");return"Section"===e},isLayoutElement=t=>{let e=t.getAttribute("data-component-tag");return"Row"===e||"Product"===e},isPopup=t=>{let e=t.getAttribute("data-component-tag");return"Dialog"===e},isSticky=t=>{let e=t.getAttribute("data-component-tag");return"Sticky"===e},isOverToolbarPosition=(t,e)=>{let r=t.getBoundingClientRect(),o=e.getBoundingClientRect();return r.top-o.top<33},findOverflowParent=(t,e)=>{let r=e||t;if(t&&!isSection(t))return notVisible(t)&&isOverToolbarPosition(e,t)?t:t.parentElement?findOverflowParent(t.parentElement,r):void 0},COMPONENTS_TAG_NOT_LOAD_IMAGES=["PostPurchaseProductImages"],Toolbar=()=>{let e=r(null),d=r(!1),u=r(),c=r(!1),s=r(!1),[b,m]=o(!1),[v,g]=o(0),[f,p]=o("bottom"),h=r(null),A=l(),w=({state:t,$toolbar:e,$component:r})=>{let o=findOverflowParent(r,e),a=e.getBoundingClientRect(),i=r.getBoundingClientRect(),n=window.innerWidth;o?i?.height<=60?e.setAttribute(`data-toolbar-${t}-revert`,"true"):e.setAttribute(`data-toolbar-${t}-inside`,"true"):a.top<33&&(i?.height<=60?e.setAttribute(`data-toolbar-${t}-revert`,"true"):e.setAttribute(`data-toolbar-${t}-inside`,"true")),i.left+a.width>n&&e.setAttribute(`data-toolbar-${t}-overflow`,"true");let l=r?.closest('[aria-label="Dialog body"]');if(l){let r=l.getBoundingClientRect(),o=r.left+r.width-20;i.left+a.width>o&&e.setAttribute(`data-toolbar-${t}-overflow`,"true")}},y=a(({$component:t,componentUid:e,focus:r,isThemeSection:o,isParent:a})=>{if(!t&&!e)return;if(!t){let r=document.querySelector(`[data-uid="${e}"]`);if(!r)return;t=r}if(!e){let r=t.getAttribute("data-uid");if(!r)return;e=r}let i=getChildrenByAttrSelector(t,"data-toolbar"),n=getChildrenByAttrSelector(t,"data-outline"),l=getChildrenByAttrSelector(t,"data-toolbar-add-top"),d=getChildrenByAttrSelector(t,"data-toolbar-add-bottom"),u=getChildrenByAttrSelector(t,"data-column"),c=getChildrenByAttrSelector(t,"data-theme-section-status");o&&c&&c.setAttribute("data-theme-section-status-active","true"),i&&(i.removeAttribute("style"),a||i.setAttribute("data-toolbar-hover","true"),r&&i.setAttribute("data-toolbar-hover-focus","true"),w({$toolbar:i,$component:t,state:"hover"})),n&&(n.setAttribute("data-outline-hover","true"),a&&n.setAttribute("data-outline-parent-hover","true"),o&&n.setAttribute("data-outline-overlay-theme-section","true"),r&&n.setAttribute("data-outline-hover-focus","true")),l&&!a&&l.setAttribute("data-toolbar-add-hover","true"),d&&!a&&d.setAttribute("data-toolbar-add-hover","true"),u&&u.setAttribute("data-column-visible","true")},[]),E=a(({$component:t,componentUid:e})=>{if(!t){let r=document.querySelector(`[data-uid="${e}"]`);if(!r)return;t=r}let r=getDOMElementParents(t,'[data-uid][data-component-type="component"]:not([data-component-no-setting])',1);if(r.length){for(let t of r)t&&y({$component:t,isParent:!0});S({$component:t,$parents:r})}},[y]),S=({$component:t,$parents:e})=>{if(!t||!e?.length)return;let r=getChildrenByAttrSelector(t,"data-toolbar-hover-focus");if(r){let t=r.getBoundingClientRect(),o=!!r.getAttribute("data-toolbar-hover-revert"),a=!!r.getAttribute("data-toolbar-hover-inside"),i=1;for(let r of e)if(r){let e=r.getAttribute("data-component-tag");if("Section"===e)continue;let n=getChildrenByAttrSelector(r,"data-toolbar-hover");if(n){let e=n.getAttribute("data-toolbar-active");if(e)continue;let r=n.getBoundingClientRect(),l=o||a;if(isOverParent({current:t,parent:r,index:i,revert:l})){let e=getComputedStyle(n),o=t.top-r.top,a=t.left-r.left,d=parseFloat(e.top)+o-23*i;l&&(d=parseFloat(e.top)-o+23*i);let u=parseFloat(e.left)+a;n.setAttribute("style",`top: ${d}px;left: ${u}px;`),i++}}}}},C=a(()=>{let t=["data-outline-overlay","data-outline-overlay-theme-section","data-theme-section-status-active"],e=document.querySelectorAll(t.map(t=>`[${t}]`).join(","));e&&t.forEach(t=>{e.forEach(e=>e.removeAttribute(t))})},[]),$=a(()=>{let t=["data-toolbar-hover-focus","data-toolbar-hover","data-outline-hover-focus","data-toolbar-hover-revert","data-toolbar-hover-inside","data-outline-hover","data-toolbar-add-hover","data-column-visible","data-outline-parent-hover","data-toolbar-hover-overflow"],e=document.querySelectorAll(t.map(t=>`[${t}]`).join(","));e&&t.forEach(t=>{e.forEach(e=>e.removeAttribute(t))}),C()},[C]),B=a(()=>{if(h.current&&clearTimeout(h.current),v>0){let t=new CustomEvent("editor:toolbar:close-onboarding",{bubbles:!0,detail:{close:"close Onboarding"}});window.dispatchEvent(t),m(!1)}},[v]),T=a(()=>{e.current=null;let t=["data-toolbar-active","data-outline-active","data-toolbar-add-active","data-toolbar-active-revert","data-toolbar-active-inside","data-spacing-margin-bottom-active","data-toolbar-force-hover","data-outline-force-hover","data-column-force-visible","data-toolbar-active-overflow"],r=document.querySelectorAll(t.map(t=>`[${t}]`).join(","));r&&t.forEach(t=>{r.forEach(e=>e.removeAttribute(t))}),R(!1),u.current&&u.current(),B()},[B]),L=(t,r)=>{let o=t=>{let o=t.detail;o?.componentUid==e.current?.componentUid&&r()};window.removeEventListener("editor:component:render",o),window.addEventListener("editor:component:render",o);let a=t.getAttribute("data-component-tag");if(a&&!COMPONENTS_TAG_NOT_LOAD_IMAGES.includes(a)){let e=t.querySelectorAll("img");e?.length&&e.forEach(t=>{t.addEventListener("load",()=>{r()})})}u.current=()=>{window.removeEventListener("editor:component:render",o)}},O=a(({$component:t})=>{if(!t)return;let e=getComputedStyle(t),r=getChildrenByAttrSelector(t,"data-spacing"),o=r?.querySelector("[data-spacing-margin-bottom]")||null;if(o){let r=o.querySelector("[data-spacing-margin-bottom-bg]")||null,a=o.querySelector("[data-spacing-margin-bottom-drag]")||null;if(r&&a){let i=e.marginBottom;if(0>parseFloat(i)&&(i="0"),r.style.height=i,a.style.top=i,o.setAttribute("data-spacing-margin-bottom-active","true"),isLayoutElement(t))r.style.left="0";else{let t=e.paddingLeft,o=`-${t}`,i=`translate(${o}, -100%)`;r.style.left=o,a.style.transform=i}}}},[]),P=()=>{let t=document.querySelector("[data-toolbar-active]"),e=document.querySelector("[data-toolbar-onboarding]");t&&e&&(e?.removeAttribute("data-onboarding-active"),setTimeout(()=>{let r=t.getBoundingClientRect(),o=r.top||0,a=e?.getBoundingClientRect(),i=a?.height||0,n=parent.document.querySelector(".iframe"),l=n?.contentWindow,d=l?.scrollY||0,u=n?.clientHeight||0;if(o+i>u){let t=r.top+d-i-8;e?.setAttribute("style",`top: ${t}px;left: ${r.left}px;`),p("top"),l&&t<r.top+d&&setTimeout(()=>{let e=t-20;l.scrollTo({top:e,behavior:"smooth"})},200)}else{let t=r.top+d+r.height+8;e?.setAttribute("style",`top: ${t}px;left: ${r.left}px;`),p("bottom")}g(t=>t+1),e?.setAttribute("data-onboarding-active","true")},100))},q=a(({$component:t})=>{if(!t||isSection(t)||isPopup(t)||isSticky(t))return;let e=document.querySelector("[data-toolbar-onboarding]");0==v?P():(B(),e?.removeAttribute("data-onboarding-active"))},[v,B]),I=a(async({componentUid:t,productId:r,timeAwait:o=500,forceReActive:a})=>{if(!t)return;let i=`${r&&"POST_PURCHASE"!==A?`[data-product-id="${r}"][data-uid="${t}"], [data-product-id="${r}"] [data-uid="${t}"]`:`[data-uid="${t}"]`}`,n=await waitForElementToExist(i,o);if(!n||!a&&t==e.current?.componentUid&&r==e.current?.productId)return;(a||t===e.current?.componentUid)&&r===e.current?.productId||T();let l=getChildrenByAttrSelector(n,"data-toolbar"),d=getChildrenByAttrSelector(n,"data-outline"),u=getChildrenByAttrSelector(n,"data-toolbar-add-top"),c=getChildrenByAttrSelector(n,"data-toolbar-add-bottom"),s=getChildrenByAttrSelector(n,"data-column");if(l&&(e.current={componentUid:t,productId:r},l.removeAttribute("style"),l.setAttribute("data-toolbar-active","true"),w({$toolbar:l,$component:n,state:"active"})),d&&d.setAttribute("data-outline-active","true"),u&&u.setAttribute("data-toolbar-add-active","true"),c&&c.setAttribute("data-toolbar-add-active","true"),s&&s.setAttribute("data-column-force-visible","true"),r){let e=document.querySelectorAll(`[data-uid="${t}"]`);e?.length&&e.forEach(t=>{let e=getChildrenByAttrSelector(t,"data-outline");e&&e.setAttribute("data-outline-active","true")})}O({$component:n}),h.current&&clearTimeout(h.current),h.current=setTimeout(()=>{q({$component:n})},5e3),$(),L(n,()=>{I({componentUid:t,productId:r,timeAwait:2e3,forceReActive:!0})})},[T,$,O,q,A]),R=async t=>{if(t){if(e.current?.componentUid){let r=e.current?.componentUid,o=e.current?.productId,a=await waitForElementToExist(`${o?`[data-product-id="${o}"] `:""}[data-uid="${r}"]`,500);if(a){let e=getChildrenByAttrSelector(a,"data-toolbar"),r=getChildrenByAttrSelector(a,"data-outline"),o=getChildrenByAttrSelector(a,"data-spacing");e&&t&&e.setAttribute("data-toolbar-editor-inline-focus","true"),r&&t&&r.setAttribute("data-outline-editor-inline-focus","true"),o&&t&&o.setAttribute("data-spacing-hidden","true")}}}else{let t=document.querySelectorAll("[data-outline-editor-inline-focus],[data-toolbar-editor-inline-focus],[data-spacing-hidden]");t.length&&t.forEach(t=>{t&&(t.removeAttribute("data-toolbar-editor-inline-focus"),t.removeAttribute("data-outline-editor-inline-focus"),t.removeAttribute("data-spacing-hidden"))})}},U=a(t=>{let r=t.closest("[data-theme-section]"),o=r?.getAttribute("data-uid"),a=r&&o===e.current?.componentUid;if(!a)return;let i=getChildrenByAttrSelector(r,"data-theme-section-status");i&&i.setAttribute("data-theme-section-status-active","true")},[]),x=async({value:t})=>{if(!t)return;let r=await waitForElementToExist(`${e.current?.productId?`[data-product-id="${e.current?.productId}"] `:""}[data-uid="${e.current?.componentUid}"]`,500);if(r){let t=r?.querySelectorAll("[data-toolbar-parent]");if(t.length){let r=t=>{let e=t.getAttribute("data-parent-uid");if(!e)return;let r=document.querySelectorAll(`[data-uid="${e}"]`);r.length&&r.forEach(t=>{let e=getChildrenByAttrSelector(t,"data-outline");e&&(e.setAttribute("data-outline-force-hover","true"),e.setAttribute("data-outline-force-overlay","true"))})},o=t=>{let e=t.getAttribute("data-parent-uid");if(!e)return;let r=document.querySelectorAll(`[data-uid="${e}"]`);r.length&&r.forEach(t=>{let e=getChildrenByAttrSelector(t,"data-outline");e&&(e.removeAttribute("data-outline-force-hover"),e.removeAttribute("data-outline-force-overlay"))})},a=async t=>{let r=t.getAttribute("data-parent-uid");if(!r)return;let a=async()=>{let t=await waitForElementToExist(`[data-uid="${r}"]`,500),e=t?.closest("[data-product-id]"),o=e?.getAttribute("data-product-id")||"";return!!o},i="";await a()&&(i=e.current?.productId||"");let n=new CustomEvent("editor:toolbar:force-active-component",{bubbles:!0,detail:{componentUid:r,productId:i}});o(t),window.dispatchEvent(n)};t.forEach(t=>{t.addEventListener("mouseover",()=>r(t)),t.addEventListener("mouseout",()=>o(t)),t.addEventListener("click",()=>a(t))})}}},_=a(t=>{if(d.current||c.current||s.current)return;let r=t.target;if(!r||"function"!=typeof r.closest){C();return}let o=r.closest("[data-toolbar-hover]");if(o)return;let a=r.closest("[data-toolbar-wrap]"),i=a?.getAttribute("data-uid");if(!a||!i||"ROOT"==i){$();return}let n=getChildrenByAttrSelector(a,"data-toolbar"),l=getChildrenByAttrSelector(a,"data-outline");if(l&&l.removeAttribute("data-outline-overlay"),!i||"ROOT"==i||n?.getAttribute("data-toolbar-hover-focus"))return;if(n?.getAttribute("data-toolbar-hover-focus")||$(),U(r),i==e.current?.componentUid){if(e.current.productId){let t=a.closest("[data-product-id]");if(t){let r=t.getAttribute("data-product-id");if(r==e.current.productId)return}}let t=r.closest("[data-theme-section]");if(!t)return;y({$component:t,focus:!0,isThemeSection:!0})}let u=r.closest("[data-theme-section]");u?y({$component:u,focus:!0,isThemeSection:!0}):(y({$component:a,componentUid:i,focus:!0}),E({$component:a,componentUid:i}))},[U,$,y,E,C,e]),F=a(t=>{if(d.current)return;let e=t.detail;e?.componentUid?I({componentUid:e.componentUid,productId:e.productId}):T()},[I,T,d]),N=a(()=>{$()},[$]),k=a(t=>{let e=t.detail;e.value&&($(),T()),d.current=e.value},[$,T]),D=a(t=>{let e=t.detail;e.value?R(!0):R(!1)},[]),H=a(t=>{if(d.current)return;let e=t.detail;x({value:e?.value||!1})},[]),z=a(t=>{let e=t.detail;e?.value?($(),c.current=!0):c.current=!1},[$]),G=a(t=>{let e=t.detail;e?.value?($(),s.current=!0):s.current=!1},[$]),M=(t,e)=>{if(!t)return;let r=document.querySelectorAll(`[data-uid="${t}"]`);r.length&&r.forEach(t=>{let r=getChildrenByAttrSelector(t,"data-outline");r&&("in"===e?(r.setAttribute("data-outline-force-hover","true"),r.setAttribute("data-outline-force-overlay","true")):(r.removeAttribute("data-outline-force-hover"),r.removeAttribute("data-outline-force-overlay")))})},j=a(t=>{if(d.current)return;let e=t.detail;e?.componentUid&&M(e?.componentUid,e?.type)},[d]),V=a(t=>{let e=t.detail;e?.isNewUser&&m(!0)},[]),W=a(()=>{b&&P()},[b]);return i(()=>(document.addEventListener("mousemove",_),window.addEventListener("editor:active-component",F),window.addEventListener("editor:focus-outside-preview",N),window.addEventListener("editor:is-dragging",k),window.addEventListener("editor:is-editing-text-editor",D),window.addEventListener("editor:toolbar:show-parents",H),window.addEventListener("editor:toolbar:resize-spacing",z),window.addEventListener("editor:toolbar:resize-column",G),window.addEventListener("editor:hover-component",j),window.addEventListener("editor:toolbar-onboarding",V),window.addEventListener("resize",W),()=>{document.removeEventListener("mousemove",_),window.removeEventListener("editor:active-component",F),window.removeEventListener("editor:is-dragging",N),window.removeEventListener("editor:is-dragging",k),window.removeEventListener("editor:is-editing-text-editor",D),window.removeEventListener("editor:toolbar:show-parents",H),window.removeEventListener("editor:toolbar:resize-spacing",z),window.removeEventListener("editor:toolbar:resize-column",G),window.removeEventListener("editor:hover-component",j),window.removeEventListener("editor:toolbar-onboarding",V),window.removeEventListener("resize",W)}),[_,F,N,k,D,H,z,G,j,V,W]),b&&t(n,{enable:!0,position:f,onCloseOnboarding:B})};var Toolbar$1=e(Toolbar);export{Toolbar$1 as default};