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