@gem-sdk/pages 2.0.0-staging.709 → 2.0.0-staging.764

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 (145) 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 -33
  4. package/dist/cjs/components/FooterForPostPurchase.js +1 -34
  5. package/dist/cjs/components/GoogleAnalytic.js +5 -65
  6. package/dist/cjs/components/TikTokPixel.js +3 -19
  7. package/dist/cjs/components/builder/Body.js +1 -36
  8. package/dist/cjs/components/builder/Footer.js +1 -154
  9. package/dist/cjs/components/builder/Header.js +1 -186
  10. package/dist/cjs/components/builder/PopupManager.js +1 -63
  11. package/dist/cjs/components/builder/SwitchView.js +1 -184
  12. package/dist/cjs/components/builder/Toolbar.js +1 -706
  13. package/dist/cjs/components/builder/Toolbox.js +1 -508
  14. package/dist/cjs/components/builder/const.js +1 -56
  15. package/dist/cjs/components/builder/toolbar/const.js +1 -7
  16. package/dist/cjs/components/builder/toolbar/utils/findDOMClosest.js +1 -41
  17. package/dist/cjs/components/builder/toolbar/utils/findOverflowParent.js +1 -20
  18. package/dist/cjs/components/builder/toolbar/utils/getChildrenByAttrSelector.js +1 -18
  19. package/dist/cjs/components/builder/toolbar/utils/getDOMElementParents.js +1 -32
  20. package/dist/cjs/components/builder/toolbar/utils/isOverParent.js +1 -16
  21. package/dist/cjs/components/builder/toolbar/utils/isOverToolbarPosition.js +1 -12
  22. package/dist/cjs/components/builder/toolbar/utils/isSection.js +1 -8
  23. package/dist/cjs/components/builder/toolbar/utils/notVisible.js +1 -8
  24. package/dist/cjs/components/builder/toolbar/utils/waitForElementToExist.js +1 -27
  25. package/dist/cjs/components/composable/getListFontWeightTypos.js +1 -14
  26. package/dist/cjs/components/image-to-layout/AddSectionImageToLayout.js +1 -151
  27. package/dist/cjs/components/image-to-layout/DropElement.js +1 -191
  28. package/dist/cjs/components/image-to-layout/ImageToLayout.js +1 -41
  29. package/dist/cjs/constants/index.js +1 -15
  30. package/dist/cjs/index.js +1 -80
  31. package/dist/cjs/layouts/main.js +1 -30
  32. package/dist/cjs/libs/api/get-builder-props.js +1 -46
  33. package/dist/cjs/libs/api/get-collection-props.js +1 -68
  34. package/dist/cjs/libs/api/get-home-page-props-v2.js +1 -157
  35. package/dist/cjs/libs/api/get-home-page-props.js +1 -163
  36. package/dist/cjs/libs/api/get-post-purchase-props-preview.js +1 -301
  37. package/dist/cjs/libs/api/get-preview-props.js +1 -18
  38. package/dist/cjs/libs/api/get-product-props.js +1 -73
  39. package/dist/cjs/libs/api/get-static-page-props-preview.js +1 -160
  40. package/dist/cjs/libs/api/get-static-page-props-v2.js +1 -173
  41. package/dist/cjs/libs/api/get-static-page-props.js +1 -161
  42. package/dist/cjs/libs/custom-fonts.js +6 -60
  43. package/dist/cjs/libs/fetcher.js +1 -100
  44. package/dist/cjs/libs/get-layout.js +1 -13
  45. package/dist/cjs/libs/get-storefront-api.js +1 -12
  46. package/dist/cjs/libs/getStaticPaths.js +1 -10
  47. package/dist/cjs/libs/google-fonts.js +1 -138
  48. package/dist/cjs/libs/helpers/check-option-font.js +1 -65
  49. package/dist/cjs/libs/helpers/common.js +1 -27
  50. package/dist/cjs/libs/helpers/gen-css.js +1 -135
  51. package/dist/cjs/libs/helpers/gen-fonts.js +1 -96
  52. package/dist/cjs/libs/helpers/generate-manifres.js +1 -5
  53. package/dist/cjs/libs/helpers/get-fallback.js +1 -34
  54. package/dist/cjs/libs/helpers/get-metafield.js +1 -7
  55. package/dist/cjs/libs/helpers/normalize.js +1 -112
  56. package/dist/cjs/libs/helpers/parse-json.js +1 -16
  57. package/dist/cjs/libs/helpers/sentry.js +1 -17
  58. package/dist/cjs/libs/helpers/user-agent.js +1 -7
  59. package/dist/cjs/libs/hooks/use-tracking-view.js +1 -42
  60. package/dist/cjs/libs/hooks/usePagePreview.js +1 -92
  61. package/dist/cjs/libs/parse-html.js +1 -34
  62. package/dist/cjs/libs/shopify-cdn-with-google-fonts.js +1 -1845
  63. package/dist/cjs/pages/404.js +1 -43
  64. package/dist/cjs/pages/500.js +1 -74
  65. package/dist/cjs/pages/CollectionGlobalProvider.js +1 -59
  66. package/dist/cjs/pages/builder.js +1 -119
  67. package/dist/cjs/pages/collection-detail.js +1 -64
  68. package/dist/cjs/pages/preview.js +1 -26
  69. package/dist/cjs/pages/product-detail.js +1 -69
  70. package/dist/cjs/pages/static-v2.js +3 -142
  71. package/dist/cjs/pages/static.js +1 -75
  72. package/dist/cjs/store/libs-store.js +1 -14
  73. package/dist/esm/components/ErrorBoundary.js +1 -38
  74. package/dist/esm/components/ErrorFallback.js +1 -24
  75. package/dist/esm/components/FacebookPixel.js +3 -31
  76. package/dist/esm/components/FooterForPostPurchase.js +1 -30
  77. package/dist/esm/components/GoogleAnalytic.js +5 -63
  78. package/dist/esm/components/TikTokPixel.js +3 -17
  79. package/dist/esm/components/builder/Body.js +1 -32
  80. package/dist/esm/components/builder/Footer.js +1 -150
  81. package/dist/esm/components/builder/Header.js +1 -182
  82. package/dist/esm/components/builder/PopupManager.js +1 -59
  83. package/dist/esm/components/builder/SwitchView.js +1 -180
  84. package/dist/esm/components/builder/Toolbar.js +1 -702
  85. package/dist/esm/components/builder/Toolbox.js +1 -504
  86. package/dist/esm/components/builder/const.js +1 -54
  87. package/dist/esm/components/builder/toolbar/const.js +1 -4
  88. package/dist/esm/components/builder/toolbar/utils/findDOMClosest.js +1 -39
  89. package/dist/esm/components/builder/toolbar/utils/findOverflowParent.js +1 -18
  90. package/dist/esm/components/builder/toolbar/utils/getChildrenByAttrSelector.js +1 -16
  91. package/dist/esm/components/builder/toolbar/utils/getDOMElementParents.js +1 -30
  92. package/dist/esm/components/builder/toolbar/utils/isOverParent.js +1 -14
  93. package/dist/esm/components/builder/toolbar/utils/isOverToolbarPosition.js +1 -10
  94. package/dist/esm/components/builder/toolbar/utils/isSection.js +1 -6
  95. package/dist/esm/components/builder/toolbar/utils/notVisible.js +1 -6
  96. package/dist/esm/components/builder/toolbar/utils/waitForElementToExist.js +1 -25
  97. package/dist/esm/components/composable/getListFontWeightTypos.js +1 -12
  98. package/dist/esm/components/image-to-layout/AddSectionImageToLayout.js +1 -147
  99. package/dist/esm/components/image-to-layout/DropElement.js +1 -189
  100. package/dist/esm/components/image-to-layout/ImageToLayout.js +1 -37
  101. package/dist/esm/constants/index.js +1 -15
  102. package/dist/esm/index.js +1 -35
  103. package/dist/esm/layouts/main.js +1 -26
  104. package/dist/esm/libs/api/get-builder-props.js +1 -44
  105. package/dist/esm/libs/api/get-collection-props.js +1 -66
  106. package/dist/esm/libs/api/get-home-page-props-v2.js +1 -155
  107. package/dist/esm/libs/api/get-home-page-props.js +1 -161
  108. package/dist/esm/libs/api/get-post-purchase-props-preview.js +1 -293
  109. package/dist/esm/libs/api/get-preview-props.js +1 -16
  110. package/dist/esm/libs/api/get-product-props.js +1 -71
  111. package/dist/esm/libs/api/get-static-page-props-preview.js +1 -158
  112. package/dist/esm/libs/api/get-static-page-props-v2.js +1 -171
  113. package/dist/esm/libs/api/get-static-page-props.js +1 -159
  114. package/dist/esm/libs/custom-fonts.js +6 -55
  115. package/dist/esm/libs/fetcher.js +1 -96
  116. package/dist/esm/libs/get-layout.js +1 -11
  117. package/dist/esm/libs/get-storefront-api.js +1 -10
  118. package/dist/esm/libs/getStaticPaths.js +1 -8
  119. package/dist/esm/libs/google-fonts.js +1 -132
  120. package/dist/esm/libs/helpers/check-option-font.js +1 -63
  121. package/dist/esm/libs/helpers/common.js +1 -24
  122. package/dist/esm/libs/helpers/gen-css.js +1 -133
  123. package/dist/esm/libs/helpers/gen-fonts.js +1 -93
  124. package/dist/esm/libs/helpers/generate-manifres.js +1 -3
  125. package/dist/esm/libs/helpers/get-fallback.js +1 -32
  126. package/dist/esm/libs/helpers/get-metafield.js +1 -5
  127. package/dist/esm/libs/helpers/normalize.js +1 -104
  128. package/dist/esm/libs/helpers/parse-json.js +1 -13
  129. package/dist/esm/libs/helpers/sentry.js +1 -15
  130. package/dist/esm/libs/helpers/user-agent.js +1 -5
  131. package/dist/esm/libs/hooks/use-tracking-view.js +1 -40
  132. package/dist/esm/libs/hooks/usePagePreview.js +1 -90
  133. package/dist/esm/libs/parse-html.js +1 -32
  134. package/dist/esm/libs/shopify-cdn-with-google-fonts.js +1 -1843
  135. package/dist/esm/pages/404.js +1 -41
  136. package/dist/esm/pages/500.js +1 -72
  137. package/dist/esm/pages/CollectionGlobalProvider.js +1 -55
  138. package/dist/esm/pages/builder.js +1 -117
  139. package/dist/esm/pages/collection-detail.js +1 -60
  140. package/dist/esm/pages/preview.js +1 -24
  141. package/dist/esm/pages/product-detail.js +1 -65
  142. package/dist/esm/pages/static-v2.js +3 -140
  143. package/dist/esm/pages/static.js +1 -71
  144. package/dist/esm/store/libs-store.js +1 -12
  145. package/package.json +5 -5
@@ -1,707 +1,2 @@
1
1
  'use client';
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var jsxRuntime = require('react/jsx-runtime');
7
- var react = require('react');
8
- var getDOMElementParents = require('./toolbar/utils/getDOMElementParents.js');
9
- var _const = require('./toolbar/const.js');
10
- var getChildrenByAttrSelector = require('./toolbar/utils/getChildrenByAttrSelector.js');
11
- var findOverflowParent = require('./toolbar/utils/findOverflowParent.js');
12
- var waitForElementToExist = require('./toolbar/utils/waitForElementToExist.js');
13
- var isOverParent = require('./toolbar/utils/isOverParent.js');
14
- var findDOMClosest = require('./toolbar/utils/findDOMClosest.js');
15
-
16
- const Toolbar = ()=>{
17
- const currentComponentActive = react.useRef(null);
18
- const isDragging = react.useRef(false);
19
- const stopWatchReRenderComponent = react.useRef();
20
- const isResizeSpacing = react.useRef(false);
21
- const cacheHoverComponents = react.useRef([]);
22
- const cacheHoverThemeSectionComponents = react.useRef([]);
23
- const cacheActiveComponents = react.useRef([]);
24
- /* Functions */ const changePositionToolbar = ({ state, $toolbar, $component })=>{
25
- const $parentOverflow = findOverflowParent.findOverflowParent($component, $toolbar);
26
- const rect = $toolbar.getBoundingClientRect();
27
- const rectComponent = $component.getBoundingClientRect();
28
- const windowWidth = window.innerWidth;
29
- if ($parentOverflow) {
30
- if (rectComponent?.height <= 60) {
31
- $toolbar.setAttribute(`data-toolbar-${state}-revert`, 'true');
32
- } else {
33
- $toolbar.setAttribute(`data-toolbar-${state}-inside`, 'true');
34
- }
35
- // fix toolbar overflow right side
36
- if (rectComponent.left + rect.width > windowWidth) {
37
- $toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
38
- }
39
- } else {
40
- if (rect.top < _const.TOOLBAR_ACTIVE_HEIGHT + 1) {
41
- if (rectComponent?.height <= 60) {
42
- $toolbar.setAttribute(`data-toolbar-${state}-revert`, 'true');
43
- } else {
44
- $toolbar.setAttribute(`data-toolbar-${state}-inside`, 'true');
45
- }
46
- }
47
- // fix toolbar overflow right side
48
- if (rectComponent.left + rect.width > windowWidth) {
49
- $toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
50
- }
51
- }
52
- // fix Popup overflow right position
53
- const popupEl = $component?.closest('[aria-label="Dialog body"]');
54
- if (popupEl) {
55
- const rectPopupEl = popupEl.getBoundingClientRect();
56
- const popupElRightPosition = rectPopupEl.left + rectPopupEl.width - 20;
57
- if (rectComponent.left + rect.width > popupElRightPosition) {
58
- $toolbar.setAttribute(`data-toolbar-${state}-overflow`, 'true');
59
- }
60
- }
61
- };
62
- const setHoverComponent = react.useCallback(({ $component, componentUid, focus, isPreventSection, isParent })=>{
63
- if (!$component && !componentUid) return;
64
- if (!$component) {
65
- const $c = document.body.querySelector('#storefront')?.querySelector(`[data-uid="${componentUid}"]`);
66
- if (!$c) return;
67
- $component = $c;
68
- }
69
- if (!componentUid) {
70
- const cUid = $component.getAttribute('data-uid');
71
- if (!cUid) return;
72
- componentUid = cUid;
73
- }
74
- cacheHoverComponents.current.push($component);
75
- const $toolbar = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-toolbar');
76
- const $outline = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-outline');
77
- const $btnAddTop = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-toolbar-add-top');
78
- const $btnAddBottom = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-toolbar-add-bottom');
79
- const $themeSectionStatus = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-theme-section-status');
80
- if (isPreventSection && $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 (isPreventSection) {
103
- cacheHoverThemeSectionComponents.current.push($component);
104
- $outline.setAttribute('data-outline-overlay-theme-section', 'true');
105
- }
106
- if (focus) {
107
- $outline.setAttribute('data-outline-hover-focus', 'true');
108
- }
109
- }
110
- if ($btnAddTop) {
111
- if (!isParent) {
112
- $btnAddTop.setAttribute('data-toolbar-add-hover', 'true');
113
- }
114
- }
115
- if ($btnAddBottom) {
116
- if (!isParent) {
117
- $btnAddBottom.setAttribute('data-toolbar-add-hover', 'true');
118
- }
119
- }
120
- }, []);
121
- const setHoverComponentParents = react.useCallback(({ $component, componentUid })=>{
122
- if (!$component) {
123
- const $c = document.body.querySelector('#storefront')?.querySelector(`[data-uid="${componentUid}"]`);
124
- if (!$c) return;
125
- $component = $c;
126
- }
127
- const $parents = getDOMElementParents.getDOMElementParents($component, '[data-uid][data-component-type="component"]:not([data-component-no-setting])', 1);
128
- if ($parents.length) {
129
- for (const $parent of $parents){
130
- if ($parent) {
131
- setHoverComponent({
132
- $component: $parent,
133
- isParent: true
134
- });
135
- }
136
- }
137
- changePositionToolbarParents({
138
- $component,
139
- $parents
140
- });
141
- }
142
- }, [
143
- setHoverComponent
144
- ]);
145
- const changePositionToolbarParents = ({ $component, $parents })=>{
146
- if (!$component) return;
147
- if (!$parents?.length) return;
148
- const $currentToolbar = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-toolbar-hover-focus');
149
- if ($currentToolbar) {
150
- const currentRect = $currentToolbar.getBoundingClientRect();
151
- const isRevert = $currentToolbar.getAttribute('data-toolbar-hover-revert') ? true : false;
152
- const isInside = $currentToolbar.getAttribute('data-toolbar-hover-inside') ? true : false;
153
- let index = 1;
154
- for (const $parent of $parents){
155
- if ($parent) {
156
- const tag = $parent.getAttribute('data-component-tag');
157
- if (tag === 'Section') continue;
158
- const $toolbar = getChildrenByAttrSelector.getChildrenByAttrSelector($parent, 'data-toolbar-hover');
159
- if ($toolbar) {
160
- // Ignore with toolbar active
161
- const isActive = $toolbar.getAttribute('data-toolbar-active');
162
- if (isActive) continue;
163
- // Start calc
164
- const parentRect = $toolbar.getBoundingClientRect();
165
- const checkRevert = isRevert || isInside;
166
- if (isOverParent.isOverParent({
167
- current: currentRect,
168
- parent: parentRect,
169
- index,
170
- revert: checkRevert
171
- })) {
172
- const parentStyle = getComputedStyle($toolbar);
173
- // parentStyle.top
174
- const diffTop = currentRect.top - parentRect.top;
175
- const diffLeft = currentRect.left - parentRect.left;
176
- let newTop = parseFloat(parentStyle.top) + diffTop - (_const.TOOLBAR_HOVER_HEIGHT - 1) * index; // -1 border bottom
177
- if (checkRevert) {
178
- newTop = parseFloat(parentStyle.top) - diffTop + (_const.TOOLBAR_HOVER_HEIGHT - 1) * index; // -1 border bottom
179
- }
180
- const newLeft = parseFloat(parentStyle.left) + diffLeft;
181
- $toolbar.setAttribute('style', `top: ${newTop}px;left: ${newLeft}px;`);
182
- index++;
183
- }
184
- }
185
- }
186
- }
187
- }
188
- };
189
- const removeHoverThemeSectionComponent = react.useCallback(()=>{
190
- const clearAttrs = [
191
- 'data-outline-overlay-theme-section',
192
- 'data-theme-section-status-active'
193
- ];
194
- const $hoverThemeSectionComponents = cacheHoverThemeSectionComponents.current;
195
- if ($hoverThemeSectionComponents.length) {
196
- for (const $hoverThemeSectionComponent of $hoverThemeSectionComponents){
197
- const $elms = $hoverThemeSectionComponent.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
198
- if ($elms) {
199
- clearAttrs.forEach((attr)=>{
200
- $elms.forEach(($el)=>$el.removeAttribute(attr));
201
- });
202
- }
203
- }
204
- }
205
- cacheHoverThemeSectionComponents.current = []; // clear
206
- }, []);
207
- const removeHoverComponent = react.useCallback(()=>{
208
- const clearAttrs = [
209
- 'data-toolbar-hover-focus',
210
- 'data-toolbar-hover',
211
- 'data-outline-hover-focus',
212
- 'data-toolbar-hover-revert',
213
- 'data-toolbar-hover-inside',
214
- 'data-outline-hover',
215
- 'data-toolbar-add-hover',
216
- 'data-outline-parent-hover',
217
- 'data-toolbar-hover-overflow'
218
- ];
219
- const $hoverComponents = cacheHoverComponents.current;
220
- if ($hoverComponents.length) {
221
- for (const $hoverComponent of $hoverComponents){
222
- const $elms = $hoverComponent.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
223
- if ($elms) {
224
- clearAttrs.forEach((attr)=>{
225
- $elms.forEach(($el)=>$el.removeAttribute(attr));
226
- });
227
- }
228
- }
229
- }
230
- removeHoverThemeSectionComponent();
231
- cacheHoverComponents.current = []; // clear
232
- }, [
233
- removeHoverThemeSectionComponent
234
- ]);
235
- const removeActiveComponent = react.useCallback(()=>{
236
- currentComponentActive.current = null;
237
- const clearAttrs = [
238
- 'data-toolbar-active',
239
- 'data-outline-active',
240
- 'data-toolbar-add-active',
241
- 'data-toolbar-active-revert',
242
- 'data-toolbar-active-inside',
243
- 'data-spacing-margin-bottom-active',
244
- 'data-toolbar-force-hover',
245
- 'data-outline-force-hover',
246
- 'data-toolbar-active-overflow'
247
- ];
248
- const $activeComponents = cacheActiveComponents.current;
249
- if ($activeComponents.length) {
250
- for (const $activeComponent of $activeComponents){
251
- const $elms = $activeComponent.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
252
- if ($elms) {
253
- clearAttrs.forEach((attr)=>{
254
- $elms.forEach(($el)=>$el.removeAttribute(attr));
255
- });
256
- }
257
- }
258
- }
259
- cacheActiveComponents.current = []; // clear
260
- setFocusTextEditor(false);
261
- if (stopWatchReRenderComponent.current) stopWatchReRenderComponent.current();
262
- }, []);
263
- const setActiveComponentSpacing = react.useCallback(({ $component })=>{
264
- if (!$component) return;
265
- const style = getComputedStyle($component);
266
- const $spacing = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-spacing');
267
- const $marginBottom = ($spacing?.querySelector('[data-spacing-margin-bottom]')) || null;
268
- if ($marginBottom) {
269
- const $bg = $marginBottom.querySelector('[data-spacing-margin-bottom-bg]') || null;
270
- const $drag = $marginBottom.querySelector('[data-spacing-margin-bottom-drag]') || null;
271
- if ($bg && $drag) {
272
- const value = style.marginBottom;
273
- $bg.style.height = value;
274
- $drag.style.top = value;
275
- $marginBottom.setAttribute('data-spacing-margin-bottom-active', 'true');
276
- }
277
- }
278
- }, []);
279
- const getSelectorComponent = ({ componentUid, productId, articleId, marqueeKey })=>{
280
- if (articleId) {
281
- return `${articleId ? `[data-article-id="${articleId}"][data-uid="${componentUid}"], [data-article-id="${articleId}"] [data-uid="${componentUid}"]` : `[data-uid="${componentUid}"]`}`;
282
- }
283
- if (marqueeKey) {
284
- return `[marquee-item-key="${marqueeKey}"] [data-uid="${componentUid}"]`;
285
- }
286
- return `${productId ? `[data-product-id="${productId}"][data-uid="${componentUid}"], [data-product-id="${productId}"] [data-uid="${componentUid}"]` : `[data-uid="${componentUid}"]`}`;
287
- };
288
- const setActiveComponent = react.useCallback(async ({ componentUid, productId, timeAwait = 600, articleId, forceReActive, marqueeKey })=>{
289
- if (!componentUid) return;
290
- const selector = getSelectorComponent({
291
- componentUid,
292
- productId,
293
- articleId,
294
- marqueeKey
295
- });
296
- const $component = await waitForElementToExist.waitForElementToExist(selector, timeAwait);
297
- if (!$component) return;
298
- if (!forceReActive && componentUid == currentComponentActive.current?.componentUid && productId == currentComponentActive.current?.productId && articleId == currentComponentActive.current?.articleId && marqueeKey == currentComponentActive.current?.marqueeKey) return;
299
- if (componentUid !== currentComponentActive.current?.componentUid || productId !== currentComponentActive.current?.productId || articleId !== currentComponentActive.current?.articleId || forceReActive) removeActiveComponent();
300
- if (!forceReActive && componentUid !== currentComponentActive.current?.componentUid || productId !== currentComponentActive.current?.productId || marqueeKey !== currentComponentActive.current?.marqueeKey) {
301
- removeActiveComponent();
302
- }
303
- cacheActiveComponents.current.push($component);
304
- const $toolbar = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-toolbar');
305
- const $outline = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-outline');
306
- const $btnAddTop = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-toolbar-add-top');
307
- const $btnAddBottom = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-toolbar-add-bottom');
308
- if ($toolbar) {
309
- currentComponentActive.current = {
310
- componentUid,
311
- productId,
312
- articleId,
313
- marqueeKey
314
- };
315
- $toolbar.removeAttribute('style');
316
- $toolbar.setAttribute('data-toolbar-active', 'true');
317
- changePositionToolbar({
318
- $toolbar,
319
- $component,
320
- state: 'active'
321
- });
322
- }
323
- if ($outline) {
324
- $outline.setAttribute('data-outline-active', 'true');
325
- }
326
- if ($btnAddTop) {
327
- $btnAddTop.setAttribute('data-toolbar-add-active', 'true');
328
- }
329
- if ($btnAddBottom) {
330
- $btnAddBottom.setAttribute('data-toolbar-add-active', 'true');
331
- }
332
- const { $isChildOfMarquee, $section } = findDOMClosest.findDOMClosest($component, {
333
- $isChildOfMarquee: '[data-component-tag="Marquee"]',
334
- $section: '[data-component-tag="Section"]'
335
- });
336
- // Active same element in product list
337
- if ($section && (productId || articleId || $isChildOfMarquee)) {
338
- const $relatedElements = $section.querySelectorAll(`[data-uid="${componentUid}"]`);
339
- if ($relatedElements?.length) {
340
- $relatedElements.forEach(($relatedElement)=>{
341
- cacheActiveComponents.current.push($relatedElement);
342
- const $outline = getChildrenByAttrSelector.getChildrenByAttrSelector($relatedElement, 'data-outline');
343
- if ($outline) {
344
- $outline.setAttribute('data-outline-active', 'true');
345
- }
346
- });
347
- }
348
- }
349
- setActiveComponentSpacing({
350
- $component
351
- });
352
- removeHoverComponent();
353
- }, [
354
- removeActiveComponent,
355
- removeHoverComponent,
356
- setActiveComponentSpacing
357
- ]);
358
- const setFocusTextEditor = async (value)=>{
359
- if (!value) {
360
- const $components = document.body.querySelector('#storefront')?.querySelectorAll('[data-outline-editor-inline-focus],[data-toolbar-editor-inline-focus],[data-spacing-hidden]');
361
- if ($components?.length) {
362
- $components.forEach(($component)=>{
363
- if ($component) {
364
- $component.removeAttribute('data-toolbar-editor-inline-focus');
365
- $component.removeAttribute('data-outline-editor-inline-focus');
366
- $component.removeAttribute('data-spacing-hidden');
367
- }
368
- });
369
- }
370
- } else {
371
- if (currentComponentActive.current?.componentUid) {
372
- const selector = getSelectorComponent({
373
- ...currentComponentActive.current
374
- });
375
- const $component = await waitForElementToExist.waitForElementToExist(selector, 500);
376
- if ($component) {
377
- const $toolbar = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-toolbar');
378
- const $outline = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-outline');
379
- const $spacing = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-spacing');
380
- if ($toolbar) {
381
- if (value) {
382
- $toolbar.setAttribute('data-toolbar-editor-inline-focus', 'true');
383
- }
384
- }
385
- if ($outline) {
386
- if (value) {
387
- $outline.setAttribute('data-outline-editor-inline-focus', 'true');
388
- }
389
- }
390
- if ($spacing) {
391
- if (value) {
392
- $spacing.setAttribute('data-spacing-hidden', 'true');
393
- }
394
- }
395
- }
396
- }
397
- }
398
- };
399
- const hoverActiveThemeSection = react.useCallback(($target)=>{
400
- const $themeSection = $target.closest('[data-theme-section]');
401
- const $themeSectionUid = $themeSection?.getAttribute('data-uid');
402
- const isActiveThemeSection = $themeSection && $themeSectionUid === currentComponentActive.current?.componentUid;
403
- if (!isActiveThemeSection) return;
404
- cacheHoverThemeSectionComponents.current.push($themeSection);
405
- const $themeSectionStatus = getChildrenByAttrSelector.getChildrenByAttrSelector($themeSection, 'data-theme-section-status');
406
- if ($themeSectionStatus) {
407
- $themeSectionStatus.setAttribute('data-theme-section-status-active', 'true');
408
- }
409
- }, []);
410
- const setShowParents = async ({ value })=>{
411
- if (!value || !currentComponentActive.current) {
412
- return;
413
- }
414
- let isClickProcessing = false;
415
- const selector = getSelectorComponent({
416
- ...currentComponentActive.current
417
- });
418
- const $component = await waitForElementToExist.waitForElementToExist(selector, 500);
419
- if ($component) {
420
- const $parents = $component?.querySelectorAll('[data-toolbar-parent]');
421
- if ($parents.length) {
422
- const onHover = ($parent)=>{
423
- if (isClickProcessing) return;
424
- const uid = $parent.getAttribute('data-parent-uid');
425
- if (!uid) return;
426
- const $parentComponents = document.body.querySelector('#storefront')?.querySelectorAll(`[data-uid="${uid}"]`);
427
- if ($parentComponents?.length) {
428
- $parentComponents.forEach(($parentComponent)=>{
429
- const $outline = getChildrenByAttrSelector.getChildrenByAttrSelector($parentComponent, 'data-outline');
430
- if ($outline) {
431
- $outline.setAttribute('data-outline-force-hover', 'true');
432
- $outline.setAttribute('data-outline-force-overlay', 'true');
433
- }
434
- });
435
- }
436
- };
437
- const outHover = ($parent)=>{
438
- const uid = $parent.getAttribute('data-parent-uid');
439
- if (!uid) return;
440
- const $parentComponents = document.body.querySelector('#storefront')?.querySelectorAll(`[data-uid="${uid}"]`);
441
- if ($parentComponents?.length) {
442
- $parentComponents.forEach(($parentComponent)=>{
443
- const $outline = getChildrenByAttrSelector.getChildrenByAttrSelector($parentComponent, 'data-outline');
444
- if ($outline) {
445
- $outline.removeAttribute('data-outline-force-hover');
446
- $outline.removeAttribute('data-outline-force-overlay');
447
- }
448
- });
449
- }
450
- };
451
- const onClick = async ($parent)=>{
452
- isClickProcessing = true;
453
- const uid = $parent.getAttribute('data-parent-uid');
454
- if (!uid) return;
455
- const isElementInsideProduct = async ()=>{
456
- const $component = await waitForElementToExist.waitForElementToExist(`[data-uid="${uid}"]`, 500);
457
- const $product = $component?.closest('[data-product-id]');
458
- return !!($product?.getAttribute('data-product-id') || '');
459
- };
460
- const isElementInsideArticle = async ()=>{
461
- const $component = await waitForElementToExist.waitForElementToExist(`[data-uid="${uid}"]`, 500);
462
- const $article = $component?.closest('[data-article-id]');
463
- return !!($article?.getAttribute('data-article-id') || '');
464
- };
465
- let productId = '';
466
- let articleId = '';
467
- if (await isElementInsideProduct()) {
468
- productId = currentComponentActive.current?.productId || '';
469
- }
470
- if (await isElementInsideArticle()) {
471
- articleId = currentComponentActive.current?.articleId || '';
472
- }
473
- const event = new CustomEvent('editor:toolbar:force-active-component', {
474
- bubbles: true,
475
- detail: {
476
- componentUid: uid,
477
- productId,
478
- articleId,
479
- elementTag: $parent.getAttribute('data-component-tag') || ''
480
- }
481
- });
482
- outHover($parent);
483
- window.dispatchEvent(event);
484
- setTimeout(()=>{
485
- isClickProcessing = false;
486
- }, 0);
487
- };
488
- $parents.forEach(($parent)=>{
489
- $parent.addEventListener('mouseover', ()=>onHover($parent));
490
- $parent.addEventListener('mouseout', ()=>outHover($parent));
491
- $parent.addEventListener('click', ()=>onClick($parent));
492
- });
493
- }
494
- }
495
- };
496
- /* Event listener */ const onMouseMove = react.useCallback((e)=>{
497
- if (isDragging.current) return;
498
- if (isResizeSpacing.current) return;
499
- const $target = e.target;
500
- // check target
501
- if (!$target || typeof $target.closest !== 'function') {
502
- removeHoverThemeSectionComponent();
503
- removeHoverComponent();
504
- return;
505
- }
506
- const { $toolbarHover, $component, $themeSection, $shopifySection } = findDOMClosest.findDOMClosest($target, {
507
- $toolbarHover: '[data-toolbar-hover]',
508
- $component: '[data-toolbar-wrap]',
509
- $themeSection: '[data-theme-section]',
510
- $shopifySection: '[data-shopify-section]'
511
- });
512
- if ($toolbarHover) {
513
- // Disable feature overlay when hover to toolbar parents
514
- return;
515
- }
516
- // Hover to other component
517
- const componentUid = $component?.getAttribute('data-uid');
518
- if (!$component || !componentUid || componentUid == 'ROOT') {
519
- removeHoverComponent();
520
- return;
521
- }
522
- const $toolbar = getChildrenByAttrSelector.getChildrenByAttrSelector($component, 'data-toolbar');
523
- if (!componentUid) return;
524
- if (componentUid == 'ROOT') return;
525
- if ($toolbar?.getAttribute('data-toolbar-hover-focus')) return;
526
- if (!$toolbar?.getAttribute('data-toolbar-hover-focus')) removeHoverComponent();
527
- hoverActiveThemeSection($target);
528
- const $preventSection = $themeSection || $shopifySection;
529
- // Disable event when hover active component
530
- if (componentUid == currentComponentActive.current?.componentUid) {
531
- if (currentComponentActive.current.productId) {
532
- const $product = $component.closest(`[data-product-id]`);
533
- if ($product) {
534
- const productId = $product.getAttribute('data-product-id');
535
- if (productId == currentComponentActive.current.productId) {
536
- removeHoverComponent();
537
- return;
538
- }
539
- }
540
- }
541
- if ($preventSection) {
542
- setHoverComponent({
543
- $component: $preventSection,
544
- focus: true,
545
- isPreventSection: true
546
- });
547
- } else {
548
- return;
549
- }
550
- }
551
- if ($preventSection) {
552
- setHoverComponent({
553
- $component: $preventSection,
554
- focus: true,
555
- isPreventSection: true
556
- });
557
- } else {
558
- setHoverComponent({
559
- $component,
560
- componentUid,
561
- focus: true
562
- });
563
- setHoverComponentParents({
564
- $component,
565
- componentUid
566
- });
567
- }
568
- }, [
569
- hoverActiveThemeSection,
570
- removeHoverComponent,
571
- setHoverComponent,
572
- setHoverComponentParents,
573
- removeHoverThemeSectionComponent,
574
- currentComponentActive
575
- ]);
576
- const onActiveComponent = react.useCallback((e)=>{
577
- if (isDragging.current) return;
578
- const detail = e.detail;
579
- if (detail?.componentUid) {
580
- setActiveComponent({
581
- componentUid: detail.componentUid,
582
- productId: detail.productId,
583
- articleId: detail.articleId,
584
- marqueeKey: detail.marqueeKey
585
- });
586
- } else {
587
- removeActiveComponent();
588
- }
589
- }, [
590
- setActiveComponent,
591
- removeActiveComponent,
592
- isDragging
593
- ]);
594
- const onFocusOutsidePreview = react.useCallback(()=>{
595
- removeHoverComponent();
596
- }, [
597
- removeHoverComponent
598
- ]);
599
- const onIsDragging = react.useCallback((e)=>{
600
- const detail = e.detail;
601
- if (detail.value) {
602
- removeHoverComponent();
603
- removeActiveComponent();
604
- }
605
- isDragging.current = detail.value;
606
- }, [
607
- removeHoverComponent,
608
- removeActiveComponent
609
- ]);
610
- const onIsEditingTextEditor = react.useCallback((e)=>{
611
- const detail = e.detail;
612
- if (detail.value) {
613
- setFocusTextEditor(true);
614
- } else {
615
- setFocusTextEditor(false);
616
- }
617
- }, []);
618
- const onShowParents = react.useCallback((e)=>{
619
- if (isDragging.current) return;
620
- const detail = e.detail;
621
- setShowParents({
622
- value: detail?.value || false
623
- });
624
- }, []);
625
- const onResizeSpacing = react.useCallback((e)=>{
626
- const detail = e.detail;
627
- if (detail?.value) {
628
- removeHoverComponent();
629
- isResizeSpacing.current = true;
630
- } else {
631
- isResizeSpacing.current = false;
632
- }
633
- }, [
634
- removeHoverComponent
635
- ]);
636
- const setHoverParentComponent = (uid, type)=>{
637
- if (!uid) return;
638
- const $parentComponents = document.body.querySelector('#storefront')?.querySelectorAll(`[data-uid="${uid}"]`);
639
- if ($parentComponents?.length) {
640
- $parentComponents.forEach(($parentComponent)=>{
641
- const $outline = getChildrenByAttrSelector.getChildrenByAttrSelector($parentComponent, 'data-outline');
642
- if ($outline) {
643
- if (type === 'in') {
644
- $outline.setAttribute('data-outline-force-hover', 'true');
645
- $outline.setAttribute('data-outline-force-overlay', 'true');
646
- } else {
647
- $outline.removeAttribute('data-outline-force-hover');
648
- $outline.removeAttribute('data-outline-force-overlay');
649
- }
650
- }
651
- });
652
- }
653
- };
654
- const onHoverComponent = react.useCallback((e)=>{
655
- if (isDragging.current) return;
656
- const detail = e.detail;
657
- if (detail?.componentUid) {
658
- setHoverParentComponent(detail?.componentUid, detail?.type);
659
- }
660
- }, [
661
- isDragging
662
- ]);
663
- const onComponentReRender = (e)=>{
664
- const detail = e.detail;
665
- if (currentComponentActive.current?.componentUid && detail?.componentUid == currentComponentActive.current?.componentUid) {
666
- setActiveComponent({
667
- ...currentComponentActive.current
668
- });
669
- }
670
- };
671
- /* Register event */ react.useEffect(()=>{
672
- document.addEventListener('mousemove', onMouseMove);
673
- window.addEventListener('editor:active-component', onActiveComponent);
674
- window.addEventListener('editor:focus-outside-preview', onFocusOutsidePreview);
675
- window.addEventListener('editor:is-dragging', onIsDragging);
676
- window.addEventListener('editor:is-editing-text-editor', onIsEditingTextEditor);
677
- window.addEventListener('editor:toolbar:show-parents', onShowParents);
678
- window.addEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
679
- window.addEventListener('editor:hover-component', onHoverComponent);
680
- window.addEventListener('editor:component:render', onComponentReRender);
681
- return ()=>{
682
- document.removeEventListener('mousemove', onMouseMove);
683
- window.removeEventListener('editor:active-component', onActiveComponent);
684
- window.removeEventListener('editor:is-dragging', onFocusOutsidePreview);
685
- window.removeEventListener('editor:is-dragging', onIsDragging);
686
- window.removeEventListener('editor:is-editing-text-editor', onIsEditingTextEditor);
687
- window.removeEventListener('editor:toolbar:show-parents', onShowParents);
688
- window.removeEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
689
- window.removeEventListener('editor:hover-component', onHoverComponent);
690
- window.removeEventListener('editor:component:render', onComponentReRender);
691
- };
692
- }, [
693
- onMouseMove,
694
- onActiveComponent,
695
- onFocusOutsidePreview,
696
- onIsDragging,
697
- onIsEditingTextEditor,
698
- onShowParents,
699
- onResizeSpacing,
700
- onHoverComponent,
701
- onComponentReRender
702
- ]);
703
- return /*#__PURE__*/ jsxRuntime.jsx(jsxRuntime.Fragment, {});
704
- };
705
- var Toolbar$1 = /*#__PURE__*/ react.memo(Toolbar);
706
-
707
- exports.default = Toolbar$1;
2
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var jsxRuntime=require("react/jsx-runtime"),react=require("react"),getDOMElementParents=require("./toolbar/utils/getDOMElementParents.js"),_const=require("./toolbar/const.js"),getChildrenByAttrSelector=require("./toolbar/utils/getChildrenByAttrSelector.js"),findOverflowParent=require("./toolbar/utils/findOverflowParent.js"),waitForElementToExist=require("./toolbar/utils/waitForElementToExist.js"),isOverParent=require("./toolbar/utils/isOverParent.js"),findDOMClosest=require("./toolbar/utils/findDOMClosest.js");const Toolbar=()=>{let t=react.useRef(null),e=react.useRef(!1),r=react.useRef(),o=react.useRef(!1),a=react.useRef([]),i=react.useRef([]),n=react.useRef([]),l=({state:t,$toolbar:e,$component:r})=>{let o=findOverflowParent.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<_const.TOOLBAR_ACTIVE_HEIGHT+1&&(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")}},d=react.useCallback(({$component:t,componentUid:e,focus:r,isPreventSection:o,isParent:n})=>{if(!t&&!e)return;if(!t){let r=document.body.querySelector("#storefront")?.querySelector(`[data-uid="${e}"]`);if(!r)return;t=r}if(!e){let r=t.getAttribute("data-uid");if(!r)return;e=r}a.current.push(t);let d=getChildrenByAttrSelector.getChildrenByAttrSelector(t,"data-toolbar"),u=getChildrenByAttrSelector.getChildrenByAttrSelector(t,"data-outline"),c=getChildrenByAttrSelector.getChildrenByAttrSelector(t,"data-toolbar-add-top"),s=getChildrenByAttrSelector.getChildrenByAttrSelector(t,"data-toolbar-add-bottom"),b=getChildrenByAttrSelector.getChildrenByAttrSelector(t,"data-theme-section-status");o&&b&&b.setAttribute("data-theme-section-status-active","true"),d&&(d.removeAttribute("style"),n||d.setAttribute("data-toolbar-hover","true"),r&&d.setAttribute("data-toolbar-hover-focus","true"),l({$toolbar:d,$component:t,state:"hover"})),u&&(u.setAttribute("data-outline-hover","true"),n&&u.setAttribute("data-outline-parent-hover","true"),o&&(i.current.push(t),u.setAttribute("data-outline-overlay-theme-section","true")),r&&u.setAttribute("data-outline-hover-focus","true")),c&&!n&&c.setAttribute("data-toolbar-add-hover","true"),s&&!n&&s.setAttribute("data-toolbar-add-hover","true")},[]),u=react.useCallback(({$component:t,componentUid:e})=>{if(!t){let r=document.body.querySelector("#storefront")?.querySelector(`[data-uid="${e}"]`);if(!r)return;t=r}let r=getDOMElementParents.getDOMElementParents(t,'[data-uid][data-component-type="component"]:not([data-component-no-setting])',1);if(r.length){for(let t of r)t&&d({$component:t,isParent:!0});c({$component:t,$parents:r})}},[d]),c=({$component:t,$parents:e})=>{if(!t||!e?.length)return;let r=getChildrenByAttrSelector.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.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.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-(_const.TOOLBAR_HOVER_HEIGHT-1)*i;l&&(d=parseFloat(e.top)-o+(_const.TOOLBAR_HOVER_HEIGHT-1)*i);let u=parseFloat(e.left)+a;n.setAttribute("style",`top: ${d}px;left: ${u}px;`),i++}}}}},s=react.useCallback(()=>{let t=["data-outline-overlay-theme-section","data-theme-section-status-active"],e=i.current;if(e.length)for(let r of e){let e=r.querySelectorAll(t.map(t=>`[${t}]`).join(","));e&&t.forEach(t=>{e.forEach(e=>e.removeAttribute(t))})}i.current=[]},[]),b=react.useCallback(()=>{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-outline-parent-hover","data-toolbar-hover-overflow"],e=a.current;if(e.length)for(let r of e){let e=r.querySelectorAll(t.map(t=>`[${t}]`).join(","));e&&t.forEach(t=>{e.forEach(e=>e.removeAttribute(t))})}s(),a.current=[]},[s]),f=react.useCallback(()=>{t.current=null;let e=["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-toolbar-active-overflow"],o=n.current;if(o.length)for(let t of o){let r=t.querySelectorAll(e.map(t=>`[${t}]`).join(","));r&&e.forEach(t=>{r.forEach(e=>e.removeAttribute(t))})}n.current=[],m(!1),r.current&&r.current()},[]),v=react.useCallback(({$component:t})=>{if(!t)return;let e=getComputedStyle(t),r=getChildrenByAttrSelector.getChildrenByAttrSelector(t,"data-spacing"),o=r?.querySelector("[data-spacing-margin-bottom]")||null;if(o){let t=o.querySelector("[data-spacing-margin-bottom-bg]")||null,r=o.querySelector("[data-spacing-margin-bottom-drag]")||null;if(t&&r){let a=e.marginBottom;t.style.height=a,r.style.top=a,o.setAttribute("data-spacing-margin-bottom-active","true")}}},[]),h=({componentUid:t,productId:e,articleId:r,marqueeKey:o})=>r?`${r?`[data-article-id="${r}"][data-uid="${t}"], [data-article-id="${r}"] [data-uid="${t}"]`:`[data-uid="${t}"]`}`:o?`[marquee-item-key="${o}"] [data-uid="${t}"]`:`${e?`[data-product-id="${e}"][data-uid="${t}"], [data-product-id="${e}"] [data-uid="${t}"]`:`[data-uid="${t}"]`}`,g=react.useCallback(async({componentUid:e,productId:r,timeAwait:o=600,articleId:a,forceReActive:i,marqueeKey:d})=>{if(!e)return;let u=h({componentUid:e,productId:r,articleId:a,marqueeKey:d}),c=await waitForElementToExist.waitForElementToExist(u,o);if(!c||!i&&e==t.current?.componentUid&&r==t.current?.productId&&a==t.current?.articleId&&d==t.current?.marqueeKey)return;(e!==t.current?.componentUid||r!==t.current?.productId||a!==t.current?.articleId||i)&&f(),(i||e===t.current?.componentUid)&&r===t.current?.productId&&d===t.current?.marqueeKey||f(),n.current.push(c);let s=getChildrenByAttrSelector.getChildrenByAttrSelector(c,"data-toolbar"),g=getChildrenByAttrSelector.getChildrenByAttrSelector(c,"data-outline"),m=getChildrenByAttrSelector.getChildrenByAttrSelector(c,"data-toolbar-add-top"),A=getChildrenByAttrSelector.getChildrenByAttrSelector(c,"data-toolbar-add-bottom");s&&(t.current={componentUid:e,productId:r,articleId:a,marqueeKey:d},s.removeAttribute("style"),s.setAttribute("data-toolbar-active","true"),l({$toolbar:s,$component:c,state:"active"})),g&&g.setAttribute("data-outline-active","true"),m&&m.setAttribute("data-toolbar-add-active","true"),A&&A.setAttribute("data-toolbar-add-active","true");let{$isChildOfMarquee:p,$section:y}=findDOMClosest.findDOMClosest(c,{$isChildOfMarquee:'[data-component-tag="Marquee"]',$section:'[data-component-tag="Section"]'});if(y&&(r||a||p)){let t=y.querySelectorAll(`[data-uid="${e}"]`);t?.length&&t.forEach(t=>{n.current.push(t);let e=getChildrenByAttrSelector.getChildrenByAttrSelector(t,"data-outline");e&&e.setAttribute("data-outline-active","true")})}v({$component:c}),b()},[f,b,v]),m=async e=>{if(e){if(t.current?.componentUid){let r=h({...t.current}),o=await waitForElementToExist.waitForElementToExist(r,500);if(o){let t=getChildrenByAttrSelector.getChildrenByAttrSelector(o,"data-toolbar"),r=getChildrenByAttrSelector.getChildrenByAttrSelector(o,"data-outline"),a=getChildrenByAttrSelector.getChildrenByAttrSelector(o,"data-spacing");t&&e&&t.setAttribute("data-toolbar-editor-inline-focus","true"),r&&e&&r.setAttribute("data-outline-editor-inline-focus","true"),a&&e&&a.setAttribute("data-spacing-hidden","true")}}}else{let t=document.body.querySelector("#storefront")?.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"))})}},A=react.useCallback(e=>{let r=e.closest("[data-theme-section]"),o=r?.getAttribute("data-uid"),a=r&&o===t.current?.componentUid;if(!a)return;i.current.push(r);let n=getChildrenByAttrSelector.getChildrenByAttrSelector(r,"data-theme-section-status");n&&n.setAttribute("data-theme-section-status-active","true")},[]),p=async({value:e})=>{if(!e||!t.current)return;let r=!1,o=h({...t.current}),a=await waitForElementToExist.waitForElementToExist(o,500);if(a){let e=a?.querySelectorAll("[data-toolbar-parent]");if(e.length){let o=t=>{if(r)return;let e=t.getAttribute("data-parent-uid");if(!e)return;let o=document.body.querySelector("#storefront")?.querySelectorAll(`[data-uid="${e}"]`);o?.length&&o.forEach(t=>{let e=getChildrenByAttrSelector.getChildrenByAttrSelector(t,"data-outline");e&&(e.setAttribute("data-outline-force-hover","true"),e.setAttribute("data-outline-force-overlay","true"))})},a=t=>{let e=t.getAttribute("data-parent-uid");if(!e)return;let r=document.body.querySelector("#storefront")?.querySelectorAll(`[data-uid="${e}"]`);r?.length&&r.forEach(t=>{let e=getChildrenByAttrSelector.getChildrenByAttrSelector(t,"data-outline");e&&(e.removeAttribute("data-outline-force-hover"),e.removeAttribute("data-outline-force-overlay"))})},i=async e=>{r=!0;let o=e.getAttribute("data-parent-uid");if(!o)return;let i=async()=>{let t=await waitForElementToExist.waitForElementToExist(`[data-uid="${o}"]`,500),e=t?.closest("[data-product-id]");return!!e?.getAttribute("data-product-id")},n=async()=>{let t=await waitForElementToExist.waitForElementToExist(`[data-uid="${o}"]`,500),e=t?.closest("[data-article-id]");return!!e?.getAttribute("data-article-id")},l="",d="";await i()&&(l=t.current?.productId||""),await n()&&(d=t.current?.articleId||"");let u=new CustomEvent("editor:toolbar:force-active-component",{bubbles:!0,detail:{componentUid:o,productId:l,articleId:d,elementTag:e.getAttribute("data-component-tag")||""}});a(e),window.dispatchEvent(u),setTimeout(()=>{r=!1},0)};e.forEach(t=>{t.addEventListener("mouseover",()=>o(t)),t.addEventListener("mouseout",()=>a(t)),t.addEventListener("click",()=>i(t))})}}},y=react.useCallback(r=>{if(e.current||o.current)return;let a=r.target;if(!a||"function"!=typeof a.closest){s(),b();return}let{$toolbarHover:i,$component:n,$themeSection:l,$shopifySection:c}=findDOMClosest.findDOMClosest(a,{$toolbarHover:"[data-toolbar-hover]",$component:"[data-toolbar-wrap]",$themeSection:"[data-theme-section]",$shopifySection:"[data-shopify-section]"});if(i)return;let f=n?.getAttribute("data-uid");if(!n||!f||"ROOT"==f){b();return}let v=getChildrenByAttrSelector.getChildrenByAttrSelector(n,"data-toolbar");if(!f||"ROOT"==f||v?.getAttribute("data-toolbar-hover-focus"))return;v?.getAttribute("data-toolbar-hover-focus")||b(),A(a);let h=l||c;if(f==t.current?.componentUid){if(t.current.productId){let e=n.closest("[data-product-id]");if(e){let r=e.getAttribute("data-product-id");if(r==t.current.productId){b();return}}}if(!h)return;d({$component:h,focus:!0,isPreventSection:!0})}h?d({$component:h,focus:!0,isPreventSection:!0}):(d({$component:n,componentUid:f,focus:!0}),u({$component:n,componentUid:f}))},[A,b,d,u,s,t]),C=react.useCallback(t=>{if(e.current)return;let r=t.detail;r?.componentUid?g({componentUid:r.componentUid,productId:r.productId,articleId:r.articleId,marqueeKey:r.marqueeKey}):f()},[g,f,e]),S=react.useCallback(()=>{b()},[b]),w=react.useCallback(t=>{let r=t.detail;r.value&&(b(),f()),e.current=r.value},[b,f]),E=react.useCallback(t=>{let e=t.detail;e.value?m(!0):m(!1)},[]),B=react.useCallback(t=>{if(e.current)return;let r=t.detail;p({value:r?.value||!1})},[]),$=react.useCallback(t=>{let e=t.detail;e?.value?(b(),o.current=!0):o.current=!1},[b]),q=(t,e)=>{if(!t)return;let r=document.body.querySelector("#storefront")?.querySelectorAll(`[data-uid="${t}"]`);r?.length&&r.forEach(t=>{let r=getChildrenByAttrSelector.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")))})},O=react.useCallback(t=>{if(e.current)return;let r=t.detail;r?.componentUid&&q(r?.componentUid,r?.type)},[e]),T=e=>{let r=e.detail;t.current?.componentUid&&r?.componentUid==t.current?.componentUid&&g({...t.current})};return react.useEffect(()=>(document.addEventListener("mousemove",y),window.addEventListener("editor:active-component",C),window.addEventListener("editor:focus-outside-preview",S),window.addEventListener("editor:is-dragging",w),window.addEventListener("editor:is-editing-text-editor",E),window.addEventListener("editor:toolbar:show-parents",B),window.addEventListener("editor:toolbar:resize-spacing",$),window.addEventListener("editor:hover-component",O),window.addEventListener("editor:component:render",T),()=>{document.removeEventListener("mousemove",y),window.removeEventListener("editor:active-component",C),window.removeEventListener("editor:is-dragging",S),window.removeEventListener("editor:is-dragging",w),window.removeEventListener("editor:is-editing-text-editor",E),window.removeEventListener("editor:toolbar:show-parents",B),window.removeEventListener("editor:toolbar:resize-spacing",$),window.removeEventListener("editor:hover-component",O),window.removeEventListener("editor:component:render",T)}),[y,C,S,w,E,B,$,O,T]),jsxRuntime.jsx(jsxRuntime.Fragment,{})};var Toolbar$1=react.memo(Toolbar);exports.default=Toolbar$1;