@gem-sdk/pages 1.22.31-staging.1 → 1.23.0-staging.26

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.
@@ -0,0 +1,674 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+
7
+ const TOOLBAR_HOVER_HEIGHT = 24;
8
+ // const TOOLBAR_ACTIVE_HEIGHT = 32;
9
+ const getDOMElementParents = ($el, selector, limit)=>{
10
+ // Set up a parent array
11
+ const parents = [];
12
+ // Push each parent $elms to the array
13
+ while($el){
14
+ $el = $el.parentElement ?? undefined;
15
+ if ($el) {
16
+ if ($el.tagName === 'BODY' || $el.getAttribute('data-uid') === 'ROOT') {
17
+ break;
18
+ }
19
+ if (selector) {
20
+ if ($el.matches(selector)) {
21
+ parents.push($el);
22
+ if (limit && parents.length == limit) {
23
+ return parents;
24
+ }
25
+ }
26
+ continue;
27
+ }
28
+ parents.push($el);
29
+ if (limit && parents.length == limit) {
30
+ return parents;
31
+ }
32
+ }
33
+ }
34
+ // Return our parent array
35
+ return parents;
36
+ };
37
+ const getChildrenByAttrSelector = ($el, attrSelector)=>{
38
+ const childLen = $el.children.length;
39
+ if (childLen) {
40
+ for(let i = 0; i < childLen; i++){
41
+ const children = $el.children[i];
42
+ if (children) {
43
+ const is = children.getAttribute(attrSelector);
44
+ if (is) {
45
+ return children;
46
+ }
47
+ }
48
+ }
49
+ }
50
+ };
51
+ const isOverParent = (current, parent, index)=>{
52
+ for(let i = 0; i < index; i++){
53
+ const is = current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i >= parent.top && current.top - (TOOLBAR_HOVER_HEIGHT - 1) * i <= parent.top + parent.height && current.left >= parent.left && current.left <= parent.left + parent.width;
54
+ if (is) return true;
55
+ }
56
+ return false;
57
+ };
58
+ const waitForElementToExist = (selector, timeout = 200)=>{
59
+ return new Promise((resolve)=>{
60
+ const intervalID = setInterval(()=>{
61
+ const el = document.querySelector(selector);
62
+ if (el) {
63
+ clearInterval(intervalID);
64
+ clearTimeout(timeoutID);
65
+ resolve(el);
66
+ }
67
+ }, 50);
68
+ const timeoutID = setTimeout(()=>{
69
+ clearInterval(intervalID);
70
+ clearTimeout(timeoutID);
71
+ resolve(null);
72
+ }, timeout);
73
+ });
74
+ };
75
+ const notVisible = (el)=>{
76
+ const overflow = getComputedStyle(el).overflow;
77
+ return overflow !== 'visible';
78
+ };
79
+ const isSection = (el)=>{
80
+ const tag = el.getAttribute('data-component-tag');
81
+ return tag === 'Section';
82
+ };
83
+ const isOverToolbarPosition = (el, parent)=>{
84
+ const rect = el.getBoundingClientRect();
85
+ const rectP = parent.getBoundingClientRect();
86
+ // 32px = toolbar active height
87
+ return rect.top - rectP.top < 32 + 5;
88
+ };
89
+ const findOverflowParent = (element, initEl)=>{
90
+ const thisEl = element;
91
+ const origEl = initEl || thisEl;
92
+ if (!thisEl) return;
93
+ if (isSection(thisEl)) return;
94
+ if (notVisible(thisEl) && isOverToolbarPosition(initEl, thisEl)) return thisEl;
95
+ if (thisEl.parentElement) {
96
+ return findOverflowParent(thisEl.parentElement, origEl);
97
+ } else {
98
+ return;
99
+ }
100
+ };
101
+ const Toolbar = ()=>{
102
+ const currentComponentActive = react.useRef(null);
103
+ const isDragging = react.useRef(false);
104
+ const obsActiveComponent = react.useRef();
105
+ const isResizeSpacing = react.useRef(false);
106
+ /* Functions */ const setHoverComponent = react.useCallback(({ $component, componentUid, focus, isThemeSection })=>{
107
+ if (!$component && !componentUid) return;
108
+ if (!$component) {
109
+ const $c = document.querySelector(`[data-uid="${componentUid}"]`);
110
+ if (!$c) return;
111
+ $component = $c;
112
+ }
113
+ if (!componentUid) {
114
+ const cUid = $component.getAttribute('data-uid');
115
+ if (!cUid) return;
116
+ componentUid = cUid;
117
+ }
118
+ const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
119
+ const $outline = getChildrenByAttrSelector($component, 'data-outline');
120
+ const $btnAddTop = getChildrenByAttrSelector($component, 'data-toolbar-add-top');
121
+ const $btnAddBottom = getChildrenByAttrSelector($component, 'data-toolbar-add-bottom');
122
+ const $themeSectionStatus = getChildrenByAttrSelector($component, 'data-theme-section-status');
123
+ if (isThemeSection && $themeSectionStatus) {
124
+ $themeSectionStatus.setAttribute('data-theme-section-status-active', 'true');
125
+ }
126
+ if ($toolbar) {
127
+ $toolbar.removeAttribute('style');
128
+ $toolbar.setAttribute('data-toolbar-hover', 'true');
129
+ if (focus) {
130
+ $toolbar.setAttribute('data-toolbar-hover-focus', 'true');
131
+ }
132
+ const $parentOverflow = findOverflowParent($component, $toolbar);
133
+ if ($parentOverflow) {
134
+ $toolbar.setAttribute('data-toolbar-hover-revert', 'true');
135
+ }
136
+ }
137
+ if ($outline) {
138
+ $outline.setAttribute('data-outline-hover', 'true');
139
+ if (isThemeSection) {
140
+ $outline.setAttribute('data-outline-overlay-theme-section', 'true');
141
+ }
142
+ if (focus) {
143
+ $outline.setAttribute('data-outline-hover-focus', 'true');
144
+ }
145
+ }
146
+ if ($btnAddTop) {
147
+ $btnAddTop.setAttribute('data-toolbar-add-hover', 'true');
148
+ }
149
+ if ($btnAddBottom) {
150
+ $btnAddBottom.setAttribute('data-toolbar-add-hover', 'true');
151
+ }
152
+ }, []);
153
+ const setHoverComponentParents = react.useCallback(({ $component, componentUid })=>{
154
+ if (!$component) {
155
+ const $c = document.querySelector(`[data-uid="${componentUid}"]`);
156
+ if (!$c) return;
157
+ $component = $c;
158
+ }
159
+ const $parents = getDOMElementParents($component, '[data-uid][data-component-type="component"]:not([data-component-no-setting])');
160
+ if ($parents.length) {
161
+ for (const $parent of $parents){
162
+ if ($parent) {
163
+ setHoverComponent({
164
+ $component: $parent
165
+ });
166
+ }
167
+ }
168
+ changePositionToolbarParents({
169
+ $component,
170
+ $parents
171
+ });
172
+ }
173
+ }, [
174
+ setHoverComponent
175
+ ]);
176
+ const changePositionToolbarParents = ({ $component, $parents })=>{
177
+ if (!$component) return;
178
+ if (!$parents?.length) return;
179
+ const $currentToolbar = getChildrenByAttrSelector($component, 'data-toolbar-hover-focus');
180
+ if ($currentToolbar) {
181
+ const currentRect = $currentToolbar.getBoundingClientRect();
182
+ let index = 1;
183
+ for (const $parent of $parents){
184
+ if ($parent) {
185
+ const tag = $parent.getAttribute('data-component-tag');
186
+ if (tag === 'Section') continue;
187
+ const $toolbar = getChildrenByAttrSelector($parent, 'data-toolbar-hover');
188
+ if ($toolbar) {
189
+ // Ignore with toolbar active
190
+ const isActive = $toolbar.getAttribute('data-toolbar-active');
191
+ if (isActive) continue;
192
+ // Start calc
193
+ const parentRect = $toolbar.getBoundingClientRect();
194
+ if (isOverParent(currentRect, parentRect, index)) {
195
+ const parentStyle = getComputedStyle($toolbar);
196
+ const isRevert = $toolbar.getAttribute('data-toolbar-hover-revert') ? true : false;
197
+ // parentStyle.top
198
+ const diffTop = currentRect.top - parentRect.top;
199
+ const diffLeft = currentRect.left - parentRect.left;
200
+ let newTop = parseFloat(parentStyle.top) + diffTop - (TOOLBAR_HOVER_HEIGHT - 1) * index; // -1 border bottom
201
+ if (isRevert) {
202
+ newTop = parseFloat(parentStyle.top) - diffTop + (TOOLBAR_HOVER_HEIGHT - 1) * index; // -1 border bottom
203
+ }
204
+ const newLeft = parseFloat(parentStyle.left) + diffLeft;
205
+ $toolbar.setAttribute('style', `top: ${newTop}px;left: ${newLeft}px;`);
206
+ index++;
207
+ }
208
+ }
209
+ }
210
+ }
211
+ }
212
+ };
213
+ const removeHoverOverlayComponent = react.useCallback(()=>{
214
+ const clearAttrs = [
215
+ 'data-outline-overlay',
216
+ 'data-outline-overlay-theme-section',
217
+ 'data-theme-section-status-active'
218
+ ];
219
+ const $elms = document.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
220
+ if ($elms) {
221
+ clearAttrs.forEach((attr)=>{
222
+ $elms.forEach(($el)=>$el.removeAttribute(attr));
223
+ });
224
+ }
225
+ }, []);
226
+ const removeHoverComponent = react.useCallback(()=>{
227
+ const clearAttrs = [
228
+ 'data-toolbar-hover-focus',
229
+ 'data-toolbar-hover',
230
+ 'data-outline-hover-focus',
231
+ 'data-toolbar-hover-revert',
232
+ 'data-outline-hover',
233
+ 'data-toolbar-add-hover'
234
+ ];
235
+ const $elms = document.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
236
+ if ($elms) {
237
+ clearAttrs.forEach((attr)=>{
238
+ $elms.forEach(($el)=>$el.removeAttribute(attr));
239
+ });
240
+ }
241
+ removeHoverOverlayComponent();
242
+ }, [
243
+ removeHoverOverlayComponent
244
+ ]);
245
+ const removeActiveComponent = react.useCallback(()=>{
246
+ currentComponentActive.current = null;
247
+ const clearAttrs = [
248
+ 'data-toolbar-active',
249
+ 'data-outline-active',
250
+ 'data-toolbar-add-active',
251
+ 'data-toolbar-active-revert',
252
+ 'data-spacing-margin-bottom-active',
253
+ 'data-toolbar-force-hover',
254
+ 'data-outline-force-hover'
255
+ ];
256
+ const $elms = document.querySelectorAll(clearAttrs.map((attr)=>`[${attr}]`).join(','));
257
+ if ($elms) {
258
+ clearAttrs.forEach((attr)=>{
259
+ $elms.forEach(($el)=>$el.removeAttribute(attr));
260
+ });
261
+ }
262
+ setFocusTextEditor(false);
263
+ if (obsActiveComponent.current) obsActiveComponent.current.disconnect();
264
+ }, []);
265
+ const watchComponentReRender = ($el, callback)=>{
266
+ const parent = $el.parentNode;
267
+ if (!parent) return;
268
+ if (obsActiveComponent.current) obsActiveComponent.current.disconnect();
269
+ obsActiveComponent.current = new MutationObserver((mutations)=>{
270
+ for (const mutation of mutations){
271
+ mutation.removedNodes.forEach((el)=>{
272
+ if (el === $el) {
273
+ if (obsActiveComponent.current) obsActiveComponent.current.disconnect();
274
+ callback();
275
+ }
276
+ });
277
+ }
278
+ });
279
+ obsActiveComponent.current.observe(parent, {
280
+ childList: true
281
+ });
282
+ };
283
+ const setActiveComponentSpacing = react.useCallback(({ $component })=>{
284
+ if (!$component) return;
285
+ const style = getComputedStyle($component);
286
+ const $spacing = getChildrenByAttrSelector($component, 'data-spacing');
287
+ const $marginBottom = ($spacing?.querySelector('[data-spacing-margin-bottom]')) || null;
288
+ if ($marginBottom) {
289
+ const $bg = $marginBottom.querySelector('[data-spacing-margin-bottom-bg]') || null;
290
+ const $drag = $marginBottom.querySelector('[data-spacing-margin-bottom-drag]') || null;
291
+ if ($bg && $drag) {
292
+ const value = style.marginBottom;
293
+ $bg.style.height = value;
294
+ $drag.style.top = value;
295
+ $marginBottom.setAttribute('data-spacing-margin-bottom-active', 'true');
296
+ }
297
+ }
298
+ }, []);
299
+ const setActiveComponentForceHoverSection = ($component, value)=>{
300
+ const $section = $component.closest('[data-toolbar-wrap][data-component-tag="Section"]');
301
+ if ($section) {
302
+ if (value) {
303
+ const $toolbar = getChildrenByAttrSelector($section, 'data-toolbar');
304
+ const $outline = getChildrenByAttrSelector($section, 'data-outline');
305
+ if ($toolbar) {
306
+ $toolbar.setAttribute('data-toolbar-force-hover', 'true');
307
+ }
308
+ if ($outline) {
309
+ $outline.setAttribute('data-outline-force-hover', 'true');
310
+ }
311
+ } else {
312
+ const $toolbar = getChildrenByAttrSelector($section, 'data-toolbar');
313
+ const $outline = getChildrenByAttrSelector($section, 'data-outline');
314
+ if ($toolbar) {
315
+ $toolbar.removeAttribute('data-toolbar-force-hover');
316
+ }
317
+ if ($outline) {
318
+ $outline.removeAttribute('data-outline-force-hover');
319
+ }
320
+ }
321
+ }
322
+ };
323
+ const setActiveComponent = react.useCallback(async ({ componentUid, productId, timeAwait = 500, forceReActive })=>{
324
+ if (!componentUid) return;
325
+ const $component = await waitForElementToExist(`${productId ? `[data-product-id="${productId}"] ` : ''}[data-uid="${componentUid}"]`, timeAwait);
326
+ if (!$component) return;
327
+ if (!forceReActive && componentUid == currentComponentActive.current?.componentUid && productId == currentComponentActive.current?.productId) return;
328
+ if (!forceReActive && componentUid !== currentComponentActive.current?.componentUid || productId !== currentComponentActive.current?.productId) removeActiveComponent();
329
+ const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
330
+ const $outline = getChildrenByAttrSelector($component, 'data-outline');
331
+ const $btnAddTop = getChildrenByAttrSelector($component, 'data-toolbar-add-top');
332
+ const $btnAddBottom = getChildrenByAttrSelector($component, 'data-toolbar-add-bottom');
333
+ if ($toolbar) {
334
+ currentComponentActive.current = {
335
+ componentUid,
336
+ productId
337
+ };
338
+ $toolbar.removeAttribute('style');
339
+ $toolbar.setAttribute('data-toolbar-active', 'true');
340
+ const $parentOverflow = findOverflowParent($component, $toolbar);
341
+ if ($parentOverflow) {
342
+ $toolbar.setAttribute('data-toolbar-active-revert', 'true');
343
+ }
344
+ }
345
+ if ($outline) {
346
+ $outline.setAttribute('data-outline-active', 'true');
347
+ }
348
+ if ($btnAddTop) {
349
+ $btnAddTop.setAttribute('data-toolbar-add-active', 'true');
350
+ }
351
+ if ($btnAddBottom) {
352
+ $btnAddBottom.setAttribute('data-toolbar-add-active', 'true');
353
+ }
354
+ // Active same element in product list
355
+ if (productId) {
356
+ const $relatedElements = document.querySelectorAll(`[data-uid="${componentUid}"]`);
357
+ if ($relatedElements?.length) {
358
+ $relatedElements.forEach(($relatedElement)=>{
359
+ const $outline = getChildrenByAttrSelector($relatedElement, 'data-outline');
360
+ if ($outline) {
361
+ $outline.setAttribute('data-outline-active', 'true');
362
+ }
363
+ });
364
+ }
365
+ }
366
+ setActiveComponentSpacing({
367
+ $component
368
+ });
369
+ setActiveComponentForceHoverSection($component, true);
370
+ removeHoverComponent();
371
+ // Reactive when component re-render
372
+ watchComponentReRender($component, ()=>{
373
+ setActiveComponent({
374
+ componentUid,
375
+ productId,
376
+ timeAwait: 2000,
377
+ forceReActive: true
378
+ });
379
+ });
380
+ }, [
381
+ removeActiveComponent,
382
+ removeHoverComponent,
383
+ setActiveComponentSpacing
384
+ ]);
385
+ const setFocusTextEditor = async (value)=>{
386
+ if (!value) {
387
+ const $components = document.querySelectorAll('[data-outline-editor-inline-focus],[data-toolbar-editor-inline-focus],[data-spacing-hidden]');
388
+ if ($components.length) {
389
+ $components.forEach(($component)=>{
390
+ if ($component) {
391
+ $component.removeAttribute('data-toolbar-editor-inline-focus');
392
+ $component.removeAttribute('data-outline-editor-inline-focus');
393
+ $component.removeAttribute('data-spacing-hidden');
394
+ }
395
+ });
396
+ }
397
+ } else {
398
+ if (currentComponentActive.current?.componentUid) {
399
+ const componentUid = currentComponentActive.current?.componentUid;
400
+ const productId = currentComponentActive.current?.productId;
401
+ const $component = await waitForElementToExist(`${productId ? `[data-product-id="${productId}"] ` : ''}[data-uid="${componentUid}"]`, 500);
402
+ if ($component) {
403
+ const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
404
+ const $outline = getChildrenByAttrSelector($component, 'data-outline');
405
+ const $spacing = getChildrenByAttrSelector($component, 'data-spacing');
406
+ if ($toolbar) {
407
+ if (value) {
408
+ $toolbar.setAttribute('data-toolbar-editor-inline-focus', 'true');
409
+ }
410
+ }
411
+ if ($outline) {
412
+ if (value) {
413
+ $outline.setAttribute('data-outline-editor-inline-focus', 'true');
414
+ }
415
+ }
416
+ if ($spacing) {
417
+ if (value) {
418
+ $spacing.setAttribute('data-spacing-hidden', 'true');
419
+ }
420
+ }
421
+ }
422
+ }
423
+ }
424
+ };
425
+ const hoverActiveThemeSection = react.useCallback(($target)=>{
426
+ const $themeSection = $target.closest('[data-theme-section]');
427
+ const $themeSectionUid = $themeSection?.getAttribute('data-uid');
428
+ const isActiveThemeSection = $themeSection && $themeSectionUid === currentComponentActive.current?.componentUid;
429
+ if (!isActiveThemeSection) return;
430
+ const $themeSectionStatus = getChildrenByAttrSelector($themeSection, 'data-theme-section-status');
431
+ if ($themeSectionStatus) {
432
+ $themeSectionStatus.setAttribute('data-theme-section-status-active', 'true');
433
+ }
434
+ }, []);
435
+ const setShowParents = async ({ value })=>{
436
+ if (!value) {
437
+ return;
438
+ }
439
+ const $component = await waitForElementToExist(`${currentComponentActive.current?.productId ? `[data-product-id="${currentComponentActive.current?.productId}"] ` : ''}[data-uid="${currentComponentActive.current?.componentUid}"]`, 500);
440
+ if ($component) {
441
+ const $parents = $component?.querySelectorAll('[data-toolbar-parent]');
442
+ if ($parents.length) {
443
+ const onHover = ($parent)=>{
444
+ const uid = $parent.getAttribute('data-parent-uid');
445
+ if (!uid) return;
446
+ const $parentComponents = document.querySelectorAll(`[data-uid="${uid}"]`);
447
+ if ($parentComponents.length) {
448
+ $parentComponents.forEach(($parentComponent)=>{
449
+ const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
450
+ if ($outline) {
451
+ $outline.setAttribute('data-outline-force-hover', 'true');
452
+ $outline.setAttribute('data-outline-force-overlay', 'true');
453
+ }
454
+ });
455
+ }
456
+ };
457
+ const outHover = ($parent)=>{
458
+ const uid = $parent.getAttribute('data-parent-uid');
459
+ if (!uid) return;
460
+ const $parentComponents = document.querySelectorAll(`[data-uid="${uid}"]`);
461
+ if ($parentComponents.length) {
462
+ $parentComponents.forEach(($parentComponent)=>{
463
+ const $outline = getChildrenByAttrSelector($parentComponent, 'data-outline');
464
+ if ($outline) {
465
+ $outline.removeAttribute('data-outline-force-hover');
466
+ $outline.removeAttribute('data-outline-force-overlay');
467
+ }
468
+ });
469
+ }
470
+ };
471
+ const onClick = async ($parent)=>{
472
+ const uid = $parent.getAttribute('data-parent-uid');
473
+ if (!uid) return;
474
+ const isElementInsideProduct = async ()=>{
475
+ const $component = await waitForElementToExist(`[data-uid="${uid}"]`, 500);
476
+ const $product = $component?.closest('[data-product-id]');
477
+ const productId = $product?.getAttribute('data-product-id') || '';
478
+ return productId ? true : false;
479
+ };
480
+ let productId = '';
481
+ if (await isElementInsideProduct()) {
482
+ productId = currentComponentActive.current?.productId || '';
483
+ }
484
+ const event = new CustomEvent('editor:toolbar:force-active-component', {
485
+ bubbles: true,
486
+ detail: {
487
+ componentUid: uid,
488
+ productId: productId
489
+ }
490
+ });
491
+ outHover($parent);
492
+ window.dispatchEvent(event);
493
+ };
494
+ $parents.forEach(($parent)=>{
495
+ $parent.addEventListener('mouseover', ()=>onHover($parent));
496
+ $parent.addEventListener('mouseout', ()=>outHover($parent));
497
+ $parent.addEventListener('click', ()=>onClick($parent));
498
+ });
499
+ }
500
+ }
501
+ };
502
+ /* Event listener */ const onMouseMove = react.useCallback((e)=>{
503
+ if (isDragging.current) return;
504
+ if (isResizeSpacing.current) return;
505
+ const $target = e.target;
506
+ if (!$target) {
507
+ removeHoverOverlayComponent();
508
+ return;
509
+ }
510
+ const $toolbarHover = $target.closest('[data-toolbar-hover]');
511
+ if ($toolbarHover) {
512
+ removeHoverOverlayComponent(); // remove overlay old
513
+ // Hover to toolbar is showing
514
+ const $component = $target.closest('[data-toolbar-wrap]');
515
+ if (!$component) return;
516
+ const $outline = getChildrenByAttrSelector($component, 'data-outline');
517
+ if (!$outline) return;
518
+ const isThemeSection = $component.getAttribute('data-theme-section');
519
+ const outlineOverlay = isThemeSection ? 'data-outline-overlay-theme-section' : 'data-outline-overlay';
520
+ $outline.setAttribute(outlineOverlay, 'true');
521
+ } else {
522
+ // Hover to other component
523
+ const $component = $target.closest('[data-toolbar-wrap]');
524
+ const componentUid = $component?.getAttribute('data-uid');
525
+ if (!$component || !componentUid || componentUid == 'ROOT') {
526
+ removeHoverComponent();
527
+ return;
528
+ }
529
+ const $toolbar = getChildrenByAttrSelector($component, 'data-toolbar');
530
+ const $outline = getChildrenByAttrSelector($component, 'data-outline');
531
+ if ($outline) $outline.removeAttribute('data-outline-overlay');
532
+ if (!componentUid) return;
533
+ if (componentUid == 'ROOT') return;
534
+ if ($toolbar?.getAttribute('data-toolbar-hover-focus')) return;
535
+ if (!$toolbar?.getAttribute('data-toolbar-hover-focus')) removeHoverComponent();
536
+ hoverActiveThemeSection($target);
537
+ // Disable event when hover active component
538
+ if (componentUid == currentComponentActive.current?.componentUid) {
539
+ if (currentComponentActive.current.productId) {
540
+ const $product = $component.closest(`[data-product-id]`);
541
+ if ($product) {
542
+ const productId = $product.getAttribute('data-product-id');
543
+ if (productId == currentComponentActive.current.productId) {
544
+ return;
545
+ }
546
+ }
547
+ }
548
+ const $themeSection = $target.closest('[data-theme-section]');
549
+ if ($themeSection) {
550
+ setHoverComponent({
551
+ $component: $themeSection,
552
+ focus: true,
553
+ isThemeSection: true
554
+ });
555
+ } else {
556
+ return;
557
+ }
558
+ }
559
+ const $themeSection = $target.closest('[data-theme-section]');
560
+ if ($themeSection) {
561
+ setHoverComponent({
562
+ $component: $themeSection,
563
+ focus: true,
564
+ isThemeSection: true
565
+ });
566
+ } else {
567
+ setHoverComponent({
568
+ $component,
569
+ componentUid,
570
+ focus: true
571
+ });
572
+ setHoverComponentParents({
573
+ $component,
574
+ componentUid
575
+ });
576
+ }
577
+ }
578
+ }, [
579
+ hoverActiveThemeSection,
580
+ removeHoverComponent,
581
+ setHoverComponent,
582
+ setHoverComponentParents,
583
+ removeHoverOverlayComponent,
584
+ currentComponentActive
585
+ ]);
586
+ const onActiveComponent = react.useCallback((e)=>{
587
+ if (isDragging.current) return;
588
+ const detail = e.detail;
589
+ if (detail?.componentUid) {
590
+ setActiveComponent({
591
+ componentUid: detail.componentUid,
592
+ productId: detail.productId
593
+ });
594
+ } else {
595
+ removeActiveComponent();
596
+ }
597
+ }, [
598
+ setActiveComponent,
599
+ removeActiveComponent,
600
+ isDragging
601
+ ]);
602
+ const onFocusOutsidePreview = react.useCallback(()=>{
603
+ removeHoverComponent();
604
+ }, [
605
+ removeHoverComponent
606
+ ]);
607
+ const onIsDragging = react.useCallback((e)=>{
608
+ const detail = e.detail;
609
+ if (detail.value) {
610
+ removeHoverComponent();
611
+ removeActiveComponent();
612
+ }
613
+ isDragging.current = detail.value;
614
+ }, [
615
+ removeHoverComponent,
616
+ removeActiveComponent
617
+ ]);
618
+ const onIsEditingTextEditor = react.useCallback((e)=>{
619
+ const detail = e.detail;
620
+ if (detail.value) {
621
+ setFocusTextEditor(true);
622
+ } else {
623
+ setFocusTextEditor(false);
624
+ }
625
+ }, []);
626
+ const onShowParents = react.useCallback((e)=>{
627
+ if (isDragging.current) return;
628
+ const detail = e.detail;
629
+ setShowParents({
630
+ value: detail?.value || false
631
+ });
632
+ }, []);
633
+ const onResizeSpacing = react.useCallback((e)=>{
634
+ const detail = e.detail;
635
+ if (detail?.value) {
636
+ removeHoverComponent();
637
+ isResizeSpacing.current = true;
638
+ } else {
639
+ isResizeSpacing.current = false;
640
+ }
641
+ }, [
642
+ removeHoverComponent
643
+ ]);
644
+ /* Register event */ react.useEffect(()=>{
645
+ document.addEventListener('mousemove', onMouseMove);
646
+ window.addEventListener('editor:active-component', onActiveComponent);
647
+ window.addEventListener('editor:focus-outside-preview', onFocusOutsidePreview);
648
+ window.addEventListener('editor:is-dragging', onIsDragging);
649
+ window.addEventListener('editor:is-editing-text-editor', onIsEditingTextEditor);
650
+ window.addEventListener('editor:toolbar:show-parents', onShowParents);
651
+ window.addEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
652
+ return ()=>{
653
+ document.removeEventListener('mousemove', onMouseMove);
654
+ window.removeEventListener('editor:active-component', onActiveComponent);
655
+ window.removeEventListener('editor:is-dragging', onFocusOutsidePreview);
656
+ window.removeEventListener('editor:is-dragging', onIsDragging);
657
+ window.removeEventListener('editor:is-editing-text-editor', onIsEditingTextEditor);
658
+ window.removeEventListener('editor:toolbar:show-parents', onShowParents);
659
+ window.removeEventListener('editor:toolbar:resize-spacing', onResizeSpacing);
660
+ };
661
+ }, [
662
+ onMouseMove,
663
+ onActiveComponent,
664
+ onFocusOutsidePreview,
665
+ onIsDragging,
666
+ onIsEditingTextEditor,
667
+ onShowParents,
668
+ onResizeSpacing
669
+ ]);
670
+ return null;
671
+ };
672
+ var Toolbar$1 = /*#__PURE__*/ react.memo(Toolbar);
673
+
674
+ exports.default = Toolbar$1;