@gem-sdk/pages 1.63.19 → 2.0.0-dev.1082

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