@measured/puck-plugin-heading-analyzer 0.19.0-canary.61c8658 → 0.19.0-canary.765b5e2b

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/index.mjs CHANGED
@@ -21,12 +21,6 @@ var __spreadValues = (a, b) => {
21
21
  return a;
22
22
  };
23
23
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
25
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
26
- }) : x)(function(x) {
27
- if (typeof require !== "undefined") return require.apply(this, arguments);
28
- throw Error('Dynamic require of "' + x + '" is not supported');
29
- });
30
24
  var __objRest = (source, exclude) => {
31
25
  var target = {};
32
26
  for (var prop in source)
@@ -42,7 +36,7 @@ var __objRest = (source, exclude) => {
42
36
  var __esm = (fn, res) => function __init() {
43
37
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
44
38
  };
45
- var __commonJS = (cb, mod) => function __require2() {
39
+ var __commonJS = (cb, mod) => function __require() {
46
40
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
47
41
  };
48
42
  var __copyProps = (to, from, except, desc) => {
@@ -152,289 +146,6 @@ var require_classnames = __commonJS({
152
146
  }
153
147
  });
154
148
 
155
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js
156
- var require_use_sync_external_store_shim_production = __commonJS({
157
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js"(exports) {
158
- "use strict";
159
- init_react_import();
160
- var React2 = __require("react");
161
- function is(x, y) {
162
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
163
- }
164
- var objectIs = "function" === typeof Object.is ? Object.is : is;
165
- var useState2 = React2.useState;
166
- var useEffect7 = React2.useEffect;
167
- var useLayoutEffect = React2.useLayoutEffect;
168
- var useDebugValue2 = React2.useDebugValue;
169
- function useSyncExternalStore$2(subscribe, getSnapshot) {
170
- var value = getSnapshot(), _useState = useState2({ inst: { value, getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1];
171
- useLayoutEffect(
172
- function() {
173
- inst.value = value;
174
- inst.getSnapshot = getSnapshot;
175
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
176
- },
177
- [subscribe, value, getSnapshot]
178
- );
179
- useEffect7(
180
- function() {
181
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
182
- return subscribe(function() {
183
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
184
- });
185
- },
186
- [subscribe]
187
- );
188
- useDebugValue2(value);
189
- return value;
190
- }
191
- function checkIfSnapshotChanged(inst) {
192
- var latestGetSnapshot = inst.getSnapshot;
193
- inst = inst.value;
194
- try {
195
- var nextValue = latestGetSnapshot();
196
- return !objectIs(inst, nextValue);
197
- } catch (error) {
198
- return true;
199
- }
200
- }
201
- function useSyncExternalStore$1(subscribe, getSnapshot) {
202
- return getSnapshot();
203
- }
204
- var shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
205
- exports.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim;
206
- }
207
- });
208
-
209
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js
210
- var require_use_sync_external_store_shim_development = __commonJS({
211
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js"(exports) {
212
- "use strict";
213
- init_react_import();
214
- "production" !== process.env.NODE_ENV && function() {
215
- function is(x, y) {
216
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
217
- }
218
- function useSyncExternalStore$2(subscribe, getSnapshot) {
219
- didWarnOld18Alpha || void 0 === React2.startTransition || (didWarnOld18Alpha = true, console.error(
220
- "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
221
- ));
222
- var value = getSnapshot();
223
- if (!didWarnUncachedGetSnapshot) {
224
- var cachedValue = getSnapshot();
225
- objectIs(value, cachedValue) || (console.error(
226
- "The result of getSnapshot should be cached to avoid an infinite loop"
227
- ), didWarnUncachedGetSnapshot = true);
228
- }
229
- cachedValue = useState2({
230
- inst: { value, getSnapshot }
231
- });
232
- var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
233
- useLayoutEffect(
234
- function() {
235
- inst.value = value;
236
- inst.getSnapshot = getSnapshot;
237
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
238
- },
239
- [subscribe, value, getSnapshot]
240
- );
241
- useEffect7(
242
- function() {
243
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
244
- return subscribe(function() {
245
- checkIfSnapshotChanged(inst) && forceUpdate({ inst });
246
- });
247
- },
248
- [subscribe]
249
- );
250
- useDebugValue2(value);
251
- return value;
252
- }
253
- function checkIfSnapshotChanged(inst) {
254
- var latestGetSnapshot = inst.getSnapshot;
255
- inst = inst.value;
256
- try {
257
- var nextValue = latestGetSnapshot();
258
- return !objectIs(inst, nextValue);
259
- } catch (error) {
260
- return true;
261
- }
262
- }
263
- function useSyncExternalStore$1(subscribe, getSnapshot) {
264
- return getSnapshot();
265
- }
266
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
267
- var React2 = __require("react"), objectIs = "function" === typeof Object.is ? Object.is : is, useState2 = React2.useState, useEffect7 = React2.useEffect, useLayoutEffect = React2.useLayoutEffect, useDebugValue2 = React2.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
268
- exports.useSyncExternalStore = void 0 !== React2.useSyncExternalStore ? React2.useSyncExternalStore : shim;
269
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
270
- }();
271
- }
272
- });
273
-
274
- // ../../node_modules/use-sync-external-store/shim/index.js
275
- var require_shim = __commonJS({
276
- "../../node_modules/use-sync-external-store/shim/index.js"(exports, module) {
277
- "use strict";
278
- init_react_import();
279
- if (process.env.NODE_ENV === "production") {
280
- module.exports = require_use_sync_external_store_shim_production();
281
- } else {
282
- module.exports = require_use_sync_external_store_shim_development();
283
- }
284
- }
285
- });
286
-
287
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js
288
- var require_with_selector_production = __commonJS({
289
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js"(exports) {
290
- "use strict";
291
- init_react_import();
292
- var React2 = __require("react");
293
- var shim = require_shim();
294
- function is(x, y) {
295
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
296
- }
297
- var objectIs = "function" === typeof Object.is ? Object.is : is;
298
- var useSyncExternalStore = shim.useSyncExternalStore;
299
- var useRef = React2.useRef;
300
- var useEffect7 = React2.useEffect;
301
- var useMemo2 = React2.useMemo;
302
- var useDebugValue2 = React2.useDebugValue;
303
- exports.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
304
- var instRef = useRef(null);
305
- if (null === instRef.current) {
306
- var inst = { hasValue: false, value: null };
307
- instRef.current = inst;
308
- } else inst = instRef.current;
309
- instRef = useMemo2(
310
- function() {
311
- function memoizedSelector(nextSnapshot) {
312
- if (!hasMemo) {
313
- hasMemo = true;
314
- memoizedSnapshot = nextSnapshot;
315
- nextSnapshot = selector(nextSnapshot);
316
- if (void 0 !== isEqual && inst.hasValue) {
317
- var currentSelection = inst.value;
318
- if (isEqual(currentSelection, nextSnapshot))
319
- return memoizedSelection = currentSelection;
320
- }
321
- return memoizedSelection = nextSnapshot;
322
- }
323
- currentSelection = memoizedSelection;
324
- if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
325
- var nextSelection = selector(nextSnapshot);
326
- if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
327
- return memoizedSnapshot = nextSnapshot, currentSelection;
328
- memoizedSnapshot = nextSnapshot;
329
- return memoizedSelection = nextSelection;
330
- }
331
- var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
332
- return [
333
- function() {
334
- return memoizedSelector(getSnapshot());
335
- },
336
- null === maybeGetServerSnapshot ? void 0 : function() {
337
- return memoizedSelector(maybeGetServerSnapshot());
338
- }
339
- ];
340
- },
341
- [getSnapshot, getServerSnapshot, selector, isEqual]
342
- );
343
- var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
344
- useEffect7(
345
- function() {
346
- inst.hasValue = true;
347
- inst.value = value;
348
- },
349
- [value]
350
- );
351
- useDebugValue2(value);
352
- return value;
353
- };
354
- }
355
- });
356
-
357
- // ../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js
358
- var require_with_selector_development = __commonJS({
359
- "../../node_modules/use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js"(exports) {
360
- "use strict";
361
- init_react_import();
362
- "production" !== process.env.NODE_ENV && function() {
363
- function is(x, y) {
364
- return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
365
- }
366
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
367
- var React2 = __require("react"), shim = require_shim(), objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim.useSyncExternalStore, useRef = React2.useRef, useEffect7 = React2.useEffect, useMemo2 = React2.useMemo, useDebugValue2 = React2.useDebugValue;
368
- exports.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
369
- var instRef = useRef(null);
370
- if (null === instRef.current) {
371
- var inst = { hasValue: false, value: null };
372
- instRef.current = inst;
373
- } else inst = instRef.current;
374
- instRef = useMemo2(
375
- function() {
376
- function memoizedSelector(nextSnapshot) {
377
- if (!hasMemo) {
378
- hasMemo = true;
379
- memoizedSnapshot = nextSnapshot;
380
- nextSnapshot = selector(nextSnapshot);
381
- if (void 0 !== isEqual && inst.hasValue) {
382
- var currentSelection = inst.value;
383
- if (isEqual(currentSelection, nextSnapshot))
384
- return memoizedSelection = currentSelection;
385
- }
386
- return memoizedSelection = nextSnapshot;
387
- }
388
- currentSelection = memoizedSelection;
389
- if (objectIs(memoizedSnapshot, nextSnapshot))
390
- return currentSelection;
391
- var nextSelection = selector(nextSnapshot);
392
- if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
393
- return memoizedSnapshot = nextSnapshot, currentSelection;
394
- memoizedSnapshot = nextSnapshot;
395
- return memoizedSelection = nextSelection;
396
- }
397
- var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
398
- return [
399
- function() {
400
- return memoizedSelector(getSnapshot());
401
- },
402
- null === maybeGetServerSnapshot ? void 0 : function() {
403
- return memoizedSelector(maybeGetServerSnapshot());
404
- }
405
- ];
406
- },
407
- [getSnapshot, getServerSnapshot, selector, isEqual]
408
- );
409
- var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
410
- useEffect7(
411
- function() {
412
- inst.hasValue = true;
413
- inst.value = value;
414
- },
415
- [value]
416
- );
417
- useDebugValue2(value);
418
- return value;
419
- };
420
- "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
421
- }();
422
- }
423
- });
424
-
425
- // ../../node_modules/use-sync-external-store/shim/with-selector.js
426
- var require_with_selector = __commonJS({
427
- "../../node_modules/use-sync-external-store/shim/with-selector.js"(exports, module) {
428
- "use strict";
429
- init_react_import();
430
- if (process.env.NODE_ENV === "production") {
431
- module.exports = require_with_selector_production();
432
- } else {
433
- module.exports = require_with_selector_development();
434
- }
435
- }
436
- });
437
-
438
149
  // ../../node_modules/fast-deep-equal/index.js
439
150
  var require_fast_deep_equal = __commonJS({
440
151
  "../../node_modules/fast-deep-equal/index.js"(exports, module) {
@@ -476,7 +187,7 @@ init_react_import();
476
187
 
477
188
  // src/HeadingAnalyzer.tsx
478
189
  init_react_import();
479
- import { useEffect as useEffect6, useState } from "react";
190
+ import { useEffect as useEffect5, useState } from "react";
480
191
 
481
192
  // css-module:/home/runner/work/puck/puck/packages/plugin-heading-analyzer/src/HeadingAnalyzer.module.css#css-module
482
193
  init_react_import();
@@ -645,75 +356,247 @@ init_react_import();
645
356
  // ../core/reducer/index.ts
646
357
  init_react_import();
647
358
 
648
- // ../core/reducer/data.ts
359
+ // ../core/reducer/actions/set.ts
649
360
  init_react_import();
650
361
 
651
- // ../core/lib/reorder.ts
362
+ // ../core/lib/data/walk-tree.ts
652
363
  init_react_import();
653
- var reorder = (list, startIndex, endIndex) => {
654
- const result = Array.from(list);
655
- const [removed] = result.splice(startIndex, 1);
656
- result.splice(endIndex, 0, removed);
657
- return result;
364
+
365
+ // ../core/lib/data/for-each-slot.ts
366
+ init_react_import();
367
+
368
+ // ../core/lib/data/is-slot.ts
369
+ init_react_import();
370
+ var isSlot = (prop) => {
371
+ var _a, _b;
372
+ return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
373
+ };
374
+ var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
375
+ var _a, _b;
376
+ const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
377
+ if (!configForComponent) return isSlot(propValue);
378
+ return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
658
379
  };
659
380
 
381
+ // ../core/lib/data/for-each-slot.ts
382
+ var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
383
+ const props = item.props || {};
384
+ const propKeys = Object.keys(props);
385
+ for (let i = 0; i < propKeys.length; i++) {
386
+ const propKey = propKeys[i];
387
+ const itemType = "type" in item ? item.type : "root";
388
+ if (isSlot2(itemType, propKey, props[propKey])) {
389
+ const content = props[propKey];
390
+ cb(props.id, propKey, content);
391
+ if (recursive) {
392
+ content.forEach(
393
+ (childItem) => __async(void 0, null, function* () {
394
+ return forEachSlot(childItem, cb, true, isSlot2);
395
+ })
396
+ );
397
+ }
398
+ }
399
+ }
400
+ };
401
+
402
+ // ../core/lib/data/for-related-zones.ts
403
+ init_react_import();
404
+
405
+ // ../core/lib/get-zone-id.ts
406
+ init_react_import();
407
+
660
408
  // ../core/lib/root-droppable-id.ts
661
409
  init_react_import();
662
410
  var rootAreaId = "root";
663
411
  var rootZone = "default-zone";
664
412
  var rootDroppableId = `${rootAreaId}:${rootZone}`;
665
413
 
666
- // ../core/lib/insert.ts
667
- init_react_import();
668
- var insert = (list, index, item) => {
669
- const result = Array.from(list);
670
- result.splice(index, 0, item);
671
- return result;
414
+ // ../core/lib/get-zone-id.ts
415
+ var getZoneId = (zoneCompound) => {
416
+ if (!zoneCompound) {
417
+ return [];
418
+ }
419
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
420
+ return zoneCompound.split(":");
421
+ }
422
+ return [rootDroppableId, zoneCompound];
672
423
  };
673
424
 
674
- // ../core/lib/remove.ts
675
- init_react_import();
676
- var remove = (list, index) => {
677
- const result = Array.from(list);
678
- result.splice(index, 1);
679
- return result;
680
- };
425
+ // ../core/lib/data/for-related-zones.ts
426
+ function forRelatedZones(item, data, cb, path = []) {
427
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
428
+ const [parentId] = getZoneId(zoneCompound);
429
+ if (parentId === item.props.id) {
430
+ cb(path, zoneCompound, content);
431
+ }
432
+ });
433
+ }
681
434
 
682
- // ../core/lib/setup-zone.ts
435
+ // ../core/lib/data/strip-slots.ts
683
436
  init_react_import();
684
- var setupZone = (data, zoneKey) => {
685
- if (zoneKey === rootDroppableId) {
686
- return data;
687
- }
688
- const newData = __spreadProps(__spreadValues({}, data), {
689
- zones: data.zones ? __spreadValues({}, data.zones) : {}
437
+ var stripSlots = (data) => {
438
+ return __spreadProps(__spreadValues({}, data), {
439
+ props: Object.entries(data.props).reduce(
440
+ (acc, [propKey, propVal]) => {
441
+ if (isSlot(propVal)) {
442
+ return acc;
443
+ }
444
+ return __spreadProps(__spreadValues({}, acc), { [propKey]: propVal });
445
+ },
446
+ { id: data.props.id }
447
+ )
690
448
  });
691
- newData.zones[zoneKey] = newData.zones[zoneKey] || [];
692
- return newData;
693
449
  };
694
450
 
695
- // ../core/lib/replace.ts
696
- init_react_import();
697
- var replace = (list, index, newItem) => {
698
- const result = Array.from(list);
699
- result.splice(index, 1);
700
- result.splice(index, 0, newItem);
701
- return result;
451
+ // ../core/lib/data/walk-tree.ts
452
+ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
453
+ var _a;
454
+ let newZones = {};
455
+ const newZoneIndex = {};
456
+ const newNodeIndex = {};
457
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
458
+ var _a2;
459
+ const [parentId] = zoneCompound.split(":");
460
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
461
+ const [_2, zone] = zoneCompound.split(":");
462
+ const newZoneCompound = `${newId || parentId}:${zone}`;
463
+ const newContent2 = mappedContent.map(
464
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
465
+ );
466
+ newZoneIndex[newZoneCompound] = {
467
+ contentIds: newContent2.map((item) => item.props.id),
468
+ type: zoneType
469
+ };
470
+ return [newZoneCompound, newContent2];
471
+ };
472
+ const processRelatedZones = (item, newId, initialPath) => {
473
+ forRelatedZones(
474
+ item,
475
+ state.data,
476
+ (relatedPath, relatedZoneCompound, relatedContent) => {
477
+ const [zoneCompound, newContent2] = processContent(
478
+ relatedPath,
479
+ relatedZoneCompound,
480
+ relatedContent,
481
+ "dropzone",
482
+ newId
483
+ );
484
+ newZones[zoneCompound] = newContent2;
485
+ },
486
+ initialPath
487
+ );
488
+ };
489
+ const processItem = (item, path, index) => {
490
+ const mappedItem = mapNodeOrSkip(item, path, index);
491
+ if (!mappedItem) return item;
492
+ const id = mappedItem.props.id;
493
+ const newProps = __spreadValues({}, mappedItem.props);
494
+ forEachSlot(
495
+ mappedItem,
496
+ (parentId2, slotId, content) => {
497
+ const zoneCompound = `${parentId2}:${slotId}`;
498
+ const [_2, newContent2] = processContent(
499
+ path,
500
+ zoneCompound,
501
+ content,
502
+ "slot",
503
+ parentId2
504
+ );
505
+ newProps[slotId] = newContent2;
506
+ },
507
+ false,
508
+ createIsSlotConfig(config)
509
+ );
510
+ processRelatedZones(item, id, path);
511
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
512
+ const thisZoneCompound = path[path.length - 1];
513
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
514
+ newNodeIndex[id] = {
515
+ data: newItem,
516
+ flatData: stripSlots(newItem),
517
+ path,
518
+ parentId,
519
+ zone
520
+ };
521
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
522
+ if (newProps.id === "root") {
523
+ delete finalData["type"];
524
+ delete finalData.props["id"];
525
+ }
526
+ return finalData;
527
+ };
528
+ const zones = state.data.zones || {};
529
+ const [_, newContent] = processContent(
530
+ [],
531
+ rootDroppableId,
532
+ state.data.content,
533
+ "root"
534
+ );
535
+ const processedContent = newContent;
536
+ const zonesAlreadyProcessed = Object.keys(newZones);
537
+ Object.keys(zones || {}).forEach((zoneCompound) => {
538
+ const [parentId] = zoneCompound.split(":");
539
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
540
+ return;
541
+ }
542
+ const [_2, newContent2] = processContent(
543
+ [rootDroppableId],
544
+ zoneCompound,
545
+ zones[zoneCompound],
546
+ "dropzone",
547
+ parentId
548
+ );
549
+ newZones[zoneCompound] = newContent2;
550
+ }, newZones);
551
+ const processedRoot = processItem(
552
+ {
553
+ type: "root",
554
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
555
+ },
556
+ [],
557
+ -1
558
+ );
559
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
560
+ props: processedRoot.props
561
+ });
562
+ return __spreadProps(__spreadValues({}, state), {
563
+ data: {
564
+ root,
565
+ content: processedContent,
566
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
567
+ },
568
+ indexes: {
569
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
570
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
571
+ }
572
+ });
573
+ }
574
+
575
+ // ../core/reducer/actions/set.ts
576
+ var setAction = (state, action, appStore) => {
577
+ if (typeof action.state === "object") {
578
+ const newState = __spreadValues(__spreadValues({}, state), action.state);
579
+ if (action.state.indexes) {
580
+ return newState;
581
+ }
582
+ console.warn(
583
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
584
+ );
585
+ return walkTree(newState, appStore.config);
586
+ }
587
+ return __spreadValues(__spreadValues({}, state), action.state(state));
702
588
  };
703
589
 
704
- // ../core/lib/get-item.ts
590
+ // ../core/reducer/actions/insert.ts
705
591
  init_react_import();
706
- function getItem(selector, data, dynamicProps = {}) {
707
- if (!selector.zone || selector.zone === rootDroppableId) {
708
- const item2 = data.content[selector.index];
709
- return (item2 == null ? void 0 : item2.props) ? __spreadProps(__spreadValues({}, item2), { props: dynamicProps[item2.props.id] || item2.props }) : void 0;
710
- }
711
- const item = setupZone(data, selector.zone).zones[selector.zone][selector.index];
712
- return (item == null ? void 0 : item.props) ? __spreadProps(__spreadValues({}, item), { props: dynamicProps[item.props.id] || item.props }) : void 0;
713
- }
714
592
 
715
- // ../core/lib/reduce-related-zones.ts
593
+ // ../core/lib/data/insert.ts
716
594
  init_react_import();
595
+ var insert = (list, index, item) => {
596
+ const result = Array.from(list || []);
597
+ result.splice(index, 0, item);
598
+ return result;
599
+ };
717
600
 
718
601
  // ../core/lib/generate-id.ts
719
602
  init_react_import();
@@ -777,313 +660,378 @@ var v4_default = v4;
777
660
  // ../core/lib/generate-id.ts
778
661
  var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
779
662
 
780
- // ../core/lib/get-zone-id.ts
663
+ // ../core/lib/data/get-ids-for-parent.ts
781
664
  init_react_import();
782
- var getZoneId = (zoneCompound) => {
783
- if (!zoneCompound) {
784
- return [];
785
- }
786
- if (zoneCompound && zoneCompound.indexOf(":") > -1) {
787
- return zoneCompound.split(":");
788
- }
789
- return [rootDroppableId, zoneCompound];
665
+ var getIdsForParent = (zoneCompound, state) => {
666
+ const [parentId] = zoneCompound.split(":");
667
+ const node = state.indexes.nodes[parentId];
668
+ return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
790
669
  };
791
670
 
792
- // ../core/lib/reduce-related-zones.ts
793
- function reduceRelatedZones(item, data, fn) {
794
- return __spreadProps(__spreadValues({}, data), {
795
- zones: Object.keys(data.zones || {}).reduce(
796
- (acc, key) => {
797
- const [parentId] = getZoneId(key);
798
- if (parentId === item.props.id) {
799
- const zones = data.zones;
800
- return fn(acc, key, zones[key]);
801
- }
802
- return __spreadProps(__spreadValues({}, acc), { [key]: data.zones[key] });
803
- },
804
- {}
805
- )
806
- });
671
+ // ../core/reducer/actions/insert.ts
672
+ function insertAction(state, action, appStore) {
673
+ const id = action.id || generateId(action.componentType);
674
+ const emptyComponentData = {
675
+ type: action.componentType,
676
+ props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
677
+ id
678
+ })
679
+ };
680
+ const [parentId] = action.destinationZone.split(":");
681
+ const idsInPath = getIdsForParent(action.destinationZone, state);
682
+ return walkTree(
683
+ state,
684
+ appStore.config,
685
+ (content, zoneCompound) => {
686
+ if (zoneCompound === action.destinationZone) {
687
+ return insert(
688
+ content || [],
689
+ action.destinationIndex,
690
+ emptyComponentData
691
+ );
692
+ }
693
+ return content;
694
+ },
695
+ (childItem, path) => {
696
+ if (childItem.props.id === id || childItem.props.id === parentId) {
697
+ return childItem;
698
+ } else if (idsInPath.includes(childItem.props.id)) {
699
+ return childItem;
700
+ } else if (path.includes(action.destinationZone)) {
701
+ return childItem;
702
+ }
703
+ return null;
704
+ }
705
+ );
807
706
  }
808
- var findRelatedByZoneId = (zoneId, data) => {
809
- const [zoneParentId] = getZoneId(zoneId);
810
- return (data.zones[zoneId] || []).reduce(
811
- (acc, zoneItem) => {
812
- const related = findRelatedByItem(zoneItem, data);
813
- if (zoneItem.props.id === zoneParentId) {
814
- return __spreadProps(__spreadValues(__spreadValues({}, acc), related), { [zoneId]: zoneItem });
707
+
708
+ // ../core/reducer/actions/replace.ts
709
+ init_react_import();
710
+ var replaceAction = (state, action, appStore) => {
711
+ const [parentId] = action.destinationZone.split(":");
712
+ const idsInPath = getIdsForParent(action.destinationZone, state);
713
+ const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
714
+ const idChanged = originalId !== action.data.props.id;
715
+ if (idChanged) {
716
+ throw new Error(
717
+ `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
718
+ );
719
+ }
720
+ return walkTree(
721
+ state,
722
+ appStore.config,
723
+ (content, zoneCompound) => {
724
+ const newContent = [...content];
725
+ if (zoneCompound === action.destinationZone) {
726
+ newContent[action.destinationIndex] = action.data;
815
727
  }
816
- return __spreadValues(__spreadValues({}, acc), related);
728
+ return newContent;
817
729
  },
818
- {}
730
+ (childItem, path) => {
731
+ const pathIds = path.map((p) => p.split(":")[0]);
732
+ if (childItem.props.id === action.data.props.id) {
733
+ return action.data;
734
+ } else if (childItem.props.id === parentId) {
735
+ return childItem;
736
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
737
+ return childItem;
738
+ } else if (pathIds.indexOf(action.data.props.id) > -1) {
739
+ return childItem;
740
+ }
741
+ return null;
742
+ }
819
743
  );
820
744
  };
821
- var findRelatedByItem = (item, data) => {
822
- return Object.keys(data.zones || {}).reduce(
823
- (acc, zoneId) => {
824
- const [zoneParentId] = getZoneId(zoneId);
825
- if (item.props.id === zoneParentId) {
826
- const related = findRelatedByZoneId(zoneId, data);
827
- return __spreadProps(__spreadValues(__spreadValues({}, acc), related), {
828
- [zoneId]: data.zones[zoneId]
745
+
746
+ // ../core/reducer/actions/replace-root.ts
747
+ init_react_import();
748
+ var replaceRootAction = (state, action, appStore) => {
749
+ return walkTree(
750
+ state,
751
+ appStore.config,
752
+ (content) => content,
753
+ (childItem) => {
754
+ if (childItem.props.id === "root") {
755
+ return __spreadProps(__spreadValues({}, childItem), {
756
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
757
+ readOnly: action.root.readOnly
829
758
  });
830
759
  }
831
- return acc;
832
- },
833
- {}
760
+ return childItem;
761
+ }
834
762
  );
835
763
  };
836
- var removeRelatedZones = (item, data) => {
837
- const newData = __spreadValues({}, data);
838
- const related = findRelatedByItem(item, data);
839
- Object.keys(related).forEach((key) => {
840
- delete newData.zones[key];
841
- });
842
- return newData;
843
- };
844
- function duplicateRelatedZones(item, data, newId) {
845
- return reduceRelatedZones(item, data, (acc, key, zone) => {
846
- const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
847
- props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
848
- }));
849
- const dupeOfDupes = dupedZone.reduce(
850
- (dupeOfDupes2, item2, index) => __spreadValues(__spreadValues({}, dupeOfDupes2), duplicateRelatedZones(zone[index], data, item2.props.id).zones),
851
- acc
852
- );
853
- const [_, zoneId] = getZoneId(key);
854
- return __spreadProps(__spreadValues({}, dupeOfDupes), {
855
- [key]: zone,
856
- [`${newId}:${zoneId}`]: dupedZone
857
- });
858
- });
764
+
765
+ // ../core/reducer/actions/duplicate.ts
766
+ init_react_import();
767
+
768
+ // ../core/lib/data/get-item.ts
769
+ init_react_import();
770
+ function getItem(selector, state) {
771
+ var _a, _b;
772
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
773
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
859
774
  }
860
775
 
861
- // ../core/reducer/data.ts
862
- var zoneCache = {};
863
- var replaceAction = (data, action) => {
864
- if (action.destinationZone === rootDroppableId) {
865
- return __spreadProps(__spreadValues({}, data), {
866
- content: replace(data.content, action.destinationIndex, action.data)
867
- });
868
- }
869
- const newData = setupZone(data, action.destinationZone);
870
- return __spreadProps(__spreadValues({}, newData), {
871
- zones: __spreadProps(__spreadValues({}, newData.zones), {
872
- [action.destinationZone]: replace(
873
- newData.zones[action.destinationZone],
874
- action.destinationIndex,
875
- action.data
876
- )
776
+ // ../core/reducer/actions/duplicate.ts
777
+ function duplicateAction(state, action, appStore) {
778
+ const item = getItem(
779
+ { index: action.sourceIndex, zone: action.sourceZone },
780
+ state
781
+ );
782
+ const idsInPath = getIdsForParent(action.sourceZone, state);
783
+ const newItem = __spreadProps(__spreadValues({}, item), {
784
+ props: __spreadProps(__spreadValues({}, item.props), {
785
+ id: generateId(item.type)
877
786
  })
878
787
  });
879
- };
880
- function insertAction(data, action, config) {
881
- const emptyComponentData = {
882
- type: action.componentType,
883
- props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
884
- id: action.id || generateId(action.componentType)
885
- })
886
- };
887
- if (action.destinationZone === rootDroppableId) {
888
- return __spreadProps(__spreadValues({}, data), {
889
- content: insert(
890
- data.content,
891
- action.destinationIndex,
892
- emptyComponentData
893
- )
894
- });
895
- }
896
- const newData = setupZone(data, action.destinationZone);
897
- return __spreadProps(__spreadValues({}, data), {
898
- zones: __spreadProps(__spreadValues({}, newData.zones), {
899
- [action.destinationZone]: insert(
900
- newData.zones[action.destinationZone],
901
- action.destinationIndex,
902
- emptyComponentData
903
- )
788
+ const modified = walkTree(
789
+ state,
790
+ appStore.config,
791
+ (content, zoneCompound) => {
792
+ if (zoneCompound === action.sourceZone) {
793
+ return insert(content, action.sourceIndex + 1, item);
794
+ }
795
+ return content;
796
+ },
797
+ (childItem, path, index) => {
798
+ const zoneCompound = path[path.length - 1];
799
+ const parents = path.map((p) => p.split(":")[0]);
800
+ if (parents.indexOf(newItem.props.id) > -1) {
801
+ return __spreadProps(__spreadValues({}, childItem), {
802
+ props: __spreadProps(__spreadValues({}, childItem.props), {
803
+ id: generateId(childItem.type)
804
+ })
805
+ });
806
+ }
807
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
808
+ return newItem;
809
+ }
810
+ const [sourceZoneParent] = action.sourceZone.split(":");
811
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
812
+ return childItem;
813
+ }
814
+ return null;
815
+ }
816
+ );
817
+ return __spreadProps(__spreadValues({}, modified), {
818
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
819
+ itemSelector: {
820
+ index: action.sourceIndex + 1,
821
+ zone: action.sourceZone
822
+ }
904
823
  })
905
824
  });
906
825
  }
907
- var reorderAction = (data, action) => {
908
- if (action.destinationZone === rootDroppableId) {
909
- return __spreadProps(__spreadValues({}, data), {
910
- content: reorder(
911
- data.content,
912
- action.sourceIndex,
913
- action.destinationIndex
914
- )
915
- });
916
- }
917
- const newData = setupZone(data, action.destinationZone);
918
- return __spreadProps(__spreadValues({}, data), {
919
- zones: __spreadProps(__spreadValues({}, newData.zones), {
920
- [action.destinationZone]: reorder(
921
- newData.zones[action.destinationZone],
922
- action.sourceIndex,
923
- action.destinationIndex
924
- )
925
- })
926
- });
826
+
827
+ // ../core/reducer/actions/reorder.ts
828
+ init_react_import();
829
+
830
+ // ../core/reducer/actions/move.ts
831
+ init_react_import();
832
+
833
+ // ../core/lib/data/remove.ts
834
+ init_react_import();
835
+ var remove = (list, index) => {
836
+ const result = Array.from(list);
837
+ result.splice(index, 1);
838
+ return result;
927
839
  };
928
- function reduceData(data, action, config) {
929
- if (action.type === "insert") {
930
- return insertAction(data, action, config);
931
- }
932
- if (action.type === "duplicate") {
933
- const item = getItem(
934
- { index: action.sourceIndex, zone: action.sourceZone },
935
- data
936
- );
937
- const newItem = __spreadProps(__spreadValues({}, item), {
938
- props: __spreadProps(__spreadValues({}, item.props), {
939
- id: generateId(item.type)
940
- })
941
- });
942
- const dataWithRelatedDuplicated = duplicateRelatedZones(
943
- item,
944
- data,
945
- newItem.props.id
946
- );
947
- if (action.sourceZone === rootDroppableId) {
948
- return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
949
- content: insert(data.content, action.sourceIndex + 1, newItem)
950
- });
951
- }
952
- return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
953
- zones: __spreadProps(__spreadValues({}, dataWithRelatedDuplicated.zones), {
954
- [action.sourceZone]: insert(
955
- dataWithRelatedDuplicated.zones[action.sourceZone],
956
- action.sourceIndex + 1,
957
- newItem
958
- )
959
- })
960
- });
961
- }
962
- if (action.type === "reorder") {
963
- return reorderAction(data, action);
840
+
841
+ // ../core/reducer/actions/move.ts
842
+ var moveAction = (state, action, appStore) => {
843
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
844
+ return state;
964
845
  }
965
- if (action.type === "move") {
966
- if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
967
- return data;
968
- }
969
- const newData = setupZone(
970
- setupZone(data, action.sourceZone),
971
- action.destinationZone
972
- );
973
- const item = getItem(
974
- { zone: action.sourceZone, index: action.sourceIndex },
975
- newData
976
- );
977
- if (action.sourceZone === action.destinationZone) {
978
- return reorderAction(data, __spreadProps(__spreadValues({}, action), { type: "reorder" }));
846
+ const item = getItem(
847
+ { zone: action.sourceZone, index: action.sourceIndex },
848
+ state
849
+ );
850
+ if (!item) return state;
851
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
852
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
853
+ return walkTree(
854
+ state,
855
+ appStore.config,
856
+ (content, zoneCompound) => {
857
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
858
+ return insert(
859
+ remove(content, action.sourceIndex),
860
+ action.destinationIndex,
861
+ item
862
+ );
863
+ } else if (zoneCompound === action.sourceZone) {
864
+ return remove(content, action.sourceIndex);
865
+ } else if (zoneCompound === action.destinationZone) {
866
+ return insert(content, action.destinationIndex, item);
867
+ }
868
+ return content;
869
+ },
870
+ (childItem, path) => {
871
+ const [sourceZoneParent] = action.sourceZone.split(":");
872
+ const [destinationZoneParent] = action.destinationZone.split(":");
873
+ const childId = childItem.props.id;
874
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
875
+ return childItem;
876
+ }
877
+ return null;
979
878
  }
980
- if (action.sourceZone === rootDroppableId) {
981
- return __spreadProps(__spreadValues({}, newData), {
982
- content: remove(newData.content, action.sourceIndex),
983
- zones: __spreadProps(__spreadValues({}, newData.zones), {
984
- [action.destinationZone]: insert(
985
- newData.zones[action.destinationZone],
986
- action.destinationIndex,
987
- item
988
- )
989
- })
990
- });
879
+ );
880
+ };
881
+
882
+ // ../core/reducer/actions/reorder.ts
883
+ var reorderAction = (state, action, appStore) => {
884
+ return moveAction(
885
+ state,
886
+ {
887
+ type: "move",
888
+ sourceIndex: action.sourceIndex,
889
+ sourceZone: action.destinationZone,
890
+ destinationIndex: action.destinationIndex,
891
+ destinationZone: action.destinationZone
892
+ },
893
+ appStore
894
+ );
895
+ };
896
+
897
+ // ../core/reducer/actions/remove.ts
898
+ init_react_import();
899
+ var removeAction = (state, action, appStore) => {
900
+ const item = getItem({ index: action.index, zone: action.zone }, state);
901
+ const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
902
+ (acc, [nodeId, nodeData]) => {
903
+ const pathIds = nodeData.path.map((p) => p.split(":")[0]);
904
+ if (pathIds.includes(item.props.id)) {
905
+ return [...acc, nodeId];
906
+ }
907
+ return acc;
908
+ },
909
+ [item.props.id]
910
+ );
911
+ const newState = walkTree(
912
+ state,
913
+ appStore.config,
914
+ (content, zoneCompound) => {
915
+ if (zoneCompound === action.zone) {
916
+ return remove(content, action.index);
917
+ }
918
+ return content;
991
919
  }
992
- if (action.destinationZone === rootDroppableId) {
993
- return __spreadProps(__spreadValues({}, newData), {
994
- content: insert(newData.content, action.destinationIndex, item),
995
- zones: __spreadProps(__spreadValues({}, newData.zones), {
996
- [action.sourceZone]: remove(
997
- newData.zones[action.sourceZone],
998
- action.sourceIndex
999
- )
1000
- })
1001
- });
920
+ );
921
+ Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
922
+ const parentId = zoneCompound.split(":")[0];
923
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
924
+ delete newState.data.zones[zoneCompound];
1002
925
  }
1003
- return __spreadProps(__spreadValues({}, newData), {
1004
- zones: __spreadProps(__spreadValues({}, newData.zones), {
1005
- [action.sourceZone]: remove(
1006
- newData.zones[action.sourceZone],
1007
- action.sourceIndex
1008
- ),
1009
- [action.destinationZone]: insert(
1010
- newData.zones[action.destinationZone],
1011
- action.destinationIndex,
1012
- item
1013
- )
1014
- })
1015
- });
1016
- }
1017
- if (action.type === "replace") {
1018
- return replaceAction(data, action);
1019
- }
1020
- if (action.type === "remove") {
1021
- const item = getItem({ index: action.index, zone: action.zone }, data);
1022
- const dataWithRelatedRemoved = setupZone(
1023
- removeRelatedZones(item, data),
1024
- action.zone
1025
- );
1026
- if (action.zone === rootDroppableId) {
1027
- return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
1028
- content: remove(data.content, action.index)
1029
- });
926
+ });
927
+ Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
928
+ const parentId = zoneCompound.split(":")[0];
929
+ if (nodesToDelete.includes(parentId)) {
930
+ delete newState.indexes.zones[zoneCompound];
1030
931
  }
1031
- return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
1032
- zones: __spreadProps(__spreadValues({}, dataWithRelatedRemoved.zones), {
1033
- [action.zone]: remove(
1034
- dataWithRelatedRemoved.zones[action.zone],
1035
- action.index
1036
- )
1037
- })
1038
- });
932
+ });
933
+ nodesToDelete.forEach((id) => {
934
+ delete newState.indexes.nodes[id];
935
+ });
936
+ return newState;
937
+ };
938
+
939
+ // ../core/reducer/actions/register-zone.ts
940
+ init_react_import();
941
+
942
+ // ../core/lib/data/setup-zone.ts
943
+ init_react_import();
944
+ var setupZone = (data, zoneKey) => {
945
+ if (zoneKey === rootDroppableId) {
946
+ return data;
1039
947
  }
1040
- if (action.type === "registerZone") {
1041
- if (zoneCache[action.zone]) {
1042
- return __spreadProps(__spreadValues({}, data), {
1043
- zones: __spreadProps(__spreadValues({}, data.zones), {
948
+ const newData = __spreadProps(__spreadValues({}, data), {
949
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
950
+ });
951
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
952
+ return newData;
953
+ };
954
+
955
+ // ../core/reducer/actions/register-zone.ts
956
+ var zoneCache = {};
957
+ function registerZoneAction(state, action) {
958
+ if (zoneCache[action.zone]) {
959
+ return __spreadProps(__spreadValues({}, state), {
960
+ data: __spreadProps(__spreadValues({}, state.data), {
961
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
1044
962
  [action.zone]: zoneCache[action.zone]
1045
963
  })
1046
- });
1047
- }
1048
- return setupZone(data, action.zone);
1049
- }
1050
- if (action.type === "unregisterZone") {
1051
- const _zones = __spreadValues({}, data.zones || {});
1052
- if (_zones[action.zone]) {
1053
- zoneCache[action.zone] = _zones[action.zone];
1054
- delete _zones[action.zone];
1055
- }
1056
- return __spreadProps(__spreadValues({}, data), { zones: _zones });
964
+ }),
965
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
966
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
967
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
968
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
969
+ type: "dropzone"
970
+ })
971
+ })
972
+ })
973
+ });
1057
974
  }
1058
- if (action.type === "setData") {
1059
- if (typeof action.data === "object") {
1060
- return __spreadValues(__spreadValues({}, data), action.data);
1061
- }
1062
- return __spreadValues(__spreadValues({}, data), action.data(data));
975
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
976
+ }
977
+ function unregisterZoneAction(state, action) {
978
+ const _zones = __spreadValues({}, state.data.zones || {});
979
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
980
+ if (_zones[action.zone]) {
981
+ zoneCache[action.zone] = _zones[action.zone];
982
+ delete _zones[action.zone];
1063
983
  }
1064
- return data;
984
+ delete zoneIndex[action.zone];
985
+ return __spreadProps(__spreadValues({}, state), {
986
+ data: __spreadProps(__spreadValues({}, state.data), {
987
+ zones: _zones
988
+ }),
989
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
990
+ zones: zoneIndex
991
+ })
992
+ });
1065
993
  }
1066
994
 
1067
- // ../core/reducer/state.ts
995
+ // ../core/reducer/actions/set-data.ts
1068
996
  init_react_import();
1069
- var reduceUi = (ui, action) => {
1070
- if (action.type === "setUi") {
1071
- if (typeof action.ui === "object") {
1072
- return __spreadValues(__spreadValues({}, ui), action.ui);
1073
- }
1074
- return __spreadValues(__spreadValues({}, ui), action.ui(ui));
1075
- }
1076
- if (action.type === "duplicate") {
1077
- return __spreadProps(__spreadValues({}, ui), {
1078
- itemSelector: { index: action.sourceIndex + 1, zone: action.sourceZone }
1079
- });
997
+ var setDataAction = (state, action, appStore) => {
998
+ if (typeof action.data === "object") {
999
+ console.warn(
1000
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1001
+ );
1002
+ return walkTree(
1003
+ __spreadProps(__spreadValues({}, state), {
1004
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
1005
+ }),
1006
+ appStore.config
1007
+ );
1080
1008
  }
1081
- if (action.type === "remove") {
1082
- return __spreadProps(__spreadValues({}, ui), {
1083
- itemSelector: null
1009
+ return walkTree(
1010
+ __spreadProps(__spreadValues({}, state), {
1011
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1012
+ }),
1013
+ appStore.config
1014
+ );
1015
+ };
1016
+
1017
+ // ../core/reducer/actions/set-ui.ts
1018
+ init_react_import();
1019
+ var setUiAction = (state, action) => {
1020
+ if (typeof action.ui === "object") {
1021
+ return __spreadProps(__spreadValues({}, state), {
1022
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1084
1023
  });
1085
1024
  }
1086
- return ui;
1025
+ return __spreadProps(__spreadValues({}, state), {
1026
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1027
+ });
1028
+ };
1029
+
1030
+ // ../core/lib/data/make-state-public.ts
1031
+ init_react_import();
1032
+ var makeStatePublic = (state) => {
1033
+ const { data, ui } = state;
1034
+ return { data, ui };
1087
1035
  };
1088
1036
 
1089
1037
  // ../core/reducer/actions.tsx
@@ -1103,29 +1051,54 @@ function storeInterceptor(reducer, record, onAction) {
1103
1051
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1104
1052
  if (record) record(newAppState);
1105
1053
  }
1106
- onAction == null ? void 0 : onAction(action, newAppState, state);
1054
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1107
1055
  return newAppState;
1108
1056
  };
1109
1057
  }
1110
- var setAction = (state, action) => {
1111
- if (typeof action.state === "object") {
1112
- return __spreadValues(__spreadValues({}, state), action.state);
1113
- }
1114
- return __spreadValues(__spreadValues({}, state), action.state(state));
1115
- };
1116
1058
  function createReducer({
1117
- config,
1118
1059
  record,
1119
- onAction
1060
+ onAction,
1061
+ appStore
1120
1062
  }) {
1121
1063
  return storeInterceptor(
1122
1064
  (state, action) => {
1123
- const data = reduceData(state.data, action, config);
1124
- const ui = reduceUi(state.ui, action);
1125
1065
  if (action.type === "set") {
1126
- return setAction(state, action);
1066
+ return setAction(state, action, appStore);
1067
+ }
1068
+ if (action.type === "insert") {
1069
+ return insertAction(state, action, appStore);
1070
+ }
1071
+ if (action.type === "replace") {
1072
+ return replaceAction(state, action, appStore);
1073
+ }
1074
+ if (action.type === "replaceRoot") {
1075
+ return replaceRootAction(state, action, appStore);
1076
+ }
1077
+ if (action.type === "duplicate") {
1078
+ return duplicateAction(state, action, appStore);
1079
+ }
1080
+ if (action.type === "reorder") {
1081
+ return reorderAction(state, action, appStore);
1082
+ }
1083
+ if (action.type === "move") {
1084
+ return moveAction(state, action, appStore);
1127
1085
  }
1128
- return { data, ui };
1086
+ if (action.type === "remove") {
1087
+ return removeAction(state, action, appStore);
1088
+ }
1089
+ if (action.type === "registerZone") {
1090
+ return registerZoneAction(state, action);
1091
+ }
1092
+ if (action.type === "unregisterZone") {
1093
+ return unregisterZoneAction(state, action);
1094
+ }
1095
+ if (action.type === "setData") {
1096
+ return setDataAction(state, action, appStore);
1097
+ }
1098
+ if (action.type === "setUi") {
1099
+ return setUiAction(state, action);
1100
+ }
1101
+ return state;
1129
1102
  },
1130
1103
  record,
1131
1104
  onAction
@@ -1140,20 +1113,16 @@ var defaultViewports = [
1140
1113
  { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1141
1114
  ];
1142
1115
 
1143
- // ../../node_modules/zustand/esm/index.mjs
1144
- init_react_import();
1145
-
1146
1116
  // ../../node_modules/zustand/esm/vanilla.mjs
1147
1117
  init_react_import();
1148
- var import_meta = {};
1149
1118
  var createStoreImpl = (createState) => {
1150
1119
  let state;
1151
1120
  const listeners = /* @__PURE__ */ new Set();
1152
- const setState = (partial, replace2) => {
1121
+ const setState = (partial, replace) => {
1153
1122
  const nextState = typeof partial === "function" ? partial(state) : partial;
1154
1123
  if (!Object.is(nextState, state)) {
1155
1124
  const previousState = state;
1156
- state = (replace2 != null ? replace2 : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
1125
+ state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
1157
1126
  listeners.forEach((listener) => listener(state, previousState));
1158
1127
  }
1159
1128
  };
@@ -1163,53 +1132,28 @@ var createStoreImpl = (createState) => {
1163
1132
  listeners.add(listener);
1164
1133
  return () => listeners.delete(listener);
1165
1134
  };
1166
- const destroy = () => {
1167
- if ((import_meta.env ? import_meta.env.MODE : void 0) !== "production") {
1168
- console.warn(
1169
- "[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."
1170
- );
1171
- }
1172
- listeners.clear();
1173
- };
1174
- const api = { setState, getState, getInitialState, subscribe, destroy };
1135
+ const api = { setState, getState, getInitialState, subscribe };
1175
1136
  const initialState = state = createState(setState, getState, api);
1176
1137
  return api;
1177
1138
  };
1178
1139
  var createStore = (createState) => createState ? createStoreImpl(createState) : createStoreImpl;
1179
1140
 
1180
- // ../../node_modules/zustand/esm/index.mjs
1181
- var import_with_selector = __toESM(require_with_selector(), 1);
1182
- import ReactExports from "react";
1183
- var import_meta2 = {};
1184
- var { useDebugValue } = ReactExports;
1185
- var { useSyncExternalStoreWithSelector } = import_with_selector.default;
1186
- var didWarnAboutEqualityFn = false;
1141
+ // ../../node_modules/zustand/esm/react.mjs
1142
+ init_react_import();
1143
+ import React2 from "react";
1187
1144
  var identity = (arg) => arg;
1188
- function useStore(api, selector = identity, equalityFn) {
1189
- if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && equalityFn && !didWarnAboutEqualityFn) {
1190
- console.warn(
1191
- "[DEPRECATED] Use `createWithEqualityFn` instead of `create` or use `useStoreWithEqualityFn` instead of `useStore`. They can be imported from 'zustand/traditional'. https://github.com/pmndrs/zustand/discussions/1937"
1192
- );
1193
- didWarnAboutEqualityFn = true;
1194
- }
1195
- const slice = useSyncExternalStoreWithSelector(
1145
+ function useStore(api, selector = identity) {
1146
+ const slice = React2.useSyncExternalStore(
1196
1147
  api.subscribe,
1197
- api.getState,
1198
- api.getServerState || api.getInitialState,
1199
- selector,
1200
- equalityFn
1148
+ () => selector(api.getState()),
1149
+ () => selector(api.getInitialState())
1201
1150
  );
1202
- useDebugValue(slice);
1151
+ React2.useDebugValue(slice);
1203
1152
  return slice;
1204
1153
  }
1205
1154
  var createImpl = (createState) => {
1206
- if ((import_meta2.env ? import_meta2.env.MODE : void 0) !== "production" && typeof createState !== "function") {
1207
- console.warn(
1208
- "[DEPRECATED] Passing a vanilla store will be unsupported in a future version. Instead use `import { useStore } from 'zustand'`."
1209
- );
1210
- }
1211
- const api = typeof createState === "function" ? createStore(createState) : createState;
1212
- const useBoundStore = (selector, equalityFn) => useStore(api, selector, equalityFn);
1155
+ const api = createStore(createState);
1156
+ const useBoundStore = (selector) => useStore(api, selector);
1213
1157
  Object.assign(useBoundStore, api);
1214
1158
  return useBoundStore;
1215
1159
  };
@@ -1242,206 +1186,6 @@ var subscribeWithSelectorImpl = (fn) => (set, get, api) => {
1242
1186
  };
1243
1187
  var subscribeWithSelector = subscribeWithSelectorImpl;
1244
1188
 
1245
- // ../core/lib/resolve-data.ts
1246
- init_react_import();
1247
-
1248
- // ../core/lib/resolve-component-data.ts
1249
- init_react_import();
1250
-
1251
- // ../core/lib/get-changed.ts
1252
- init_react_import();
1253
- var getChanged = (newItem, oldItem) => {
1254
- return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1255
- const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1256
- const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1257
- return __spreadProps(__spreadValues({}, acc), {
1258
- [item]: oldItemProps[item] !== newItemProps[item]
1259
- });
1260
- }, {}) : {};
1261
- };
1262
-
1263
- // ../core/lib/resolve-component-data.ts
1264
- var cache = { lastChange: {} };
1265
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd) {
1266
- const configForItem = config.components[item.type];
1267
- if (configForItem.resolveData) {
1268
- const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
1269
- if (item && item === oldItem) {
1270
- return resolved;
1271
- }
1272
- const changed = getChanged(item, oldItem);
1273
- if (onResolveStart) {
1274
- onResolveStart(item);
1275
- }
1276
- const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1277
- changed,
1278
- lastData: oldItem,
1279
- metadata
1280
- });
1281
- const resolvedItem = __spreadProps(__spreadValues({}, item), {
1282
- props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1283
- });
1284
- if (Object.keys(readOnly).length) {
1285
- resolvedItem.readOnly = readOnly;
1286
- }
1287
- cache.lastChange[item.props.id] = {
1288
- item,
1289
- resolved: resolvedItem
1290
- };
1291
- if (onResolveEnd) {
1292
- onResolveEnd(resolvedItem);
1293
- }
1294
- return resolvedItem;
1295
- }
1296
- return item;
1297
- });
1298
-
1299
- // ../core/lib/apply-dynamic-props.ts
1300
- init_react_import();
1301
- var applyDynamicProps = (data, dynamicProps, rootData) => {
1302
- return __spreadProps(__spreadValues({}, data), {
1303
- root: rootData ? __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}) : data.root,
1304
- content: data.content.map((item) => {
1305
- return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1306
- }),
1307
- zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
1308
- return __spreadProps(__spreadValues({}, acc), {
1309
- [zoneKey]: data.zones[zoneKey].map((item) => {
1310
- return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1311
- })
1312
- });
1313
- }, {})
1314
- });
1315
- };
1316
-
1317
- // ../core/lib/resolve-root-data.ts
1318
- init_react_import();
1319
- var cache2 = {};
1320
- function resolveRootData(data, config, metadata) {
1321
- return __async(this, null, function* () {
1322
- var _a, _b, _c, _d, _e;
1323
- if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
1324
- if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
1325
- return cache2.lastChange.resolved;
1326
- }
1327
- const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
1328
- const rootWithProps = data.root;
1329
- const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
1330
- changed,
1331
- lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {},
1332
- metadata: metadata || {}
1333
- });
1334
- cache2.lastChange = {
1335
- original: data.root,
1336
- resolved: resolvedRoot
1337
- };
1338
- return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
1339
- props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
1340
- });
1341
- }
1342
- return data.root;
1343
- });
1344
- }
1345
-
1346
- // ../core/lib/flatten-data.ts
1347
- init_react_import();
1348
- var flattenData = (data) => {
1349
- return Object.keys(data.zones || {}).reduce(
1350
- (acc, zone) => [...acc, ...data.zones[zone]],
1351
- data.content
1352
- );
1353
- };
1354
-
1355
- // ../core/lib/resolve-data.ts
1356
- var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1357
- var resolveData = (newAppState, appStoreData) => {
1358
- const {
1359
- state: appState,
1360
- config,
1361
- dispatch,
1362
- resolveDataRuns,
1363
- setComponentLoading,
1364
- unsetComponentLoading,
1365
- metadata,
1366
- permissions
1367
- } = appStoreData;
1368
- const deferredSetStates = {};
1369
- const _setComponentLoading = (id, loading, defer = 0) => {
1370
- if (deferredSetStates[id]) {
1371
- clearTimeout(deferredSetStates[id]);
1372
- delete deferredSetStates[id];
1373
- }
1374
- deferredSetStates[id] = setTimeout(() => {
1375
- if (loading) {
1376
- setComponentLoading(id);
1377
- } else {
1378
- unsetComponentLoading(id);
1379
- }
1380
- delete deferredSetStates[id];
1381
- }, defer);
1382
- };
1383
- const runResolvers = () => __async(void 0, null, function* () {
1384
- const newData = newAppState.data;
1385
- const flatContent = flattenData(newData).filter(
1386
- (item) => {
1387
- var _a;
1388
- return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
1389
- }
1390
- );
1391
- const applyIfChange = (dynamicDataMap, dynamicRoot) => {
1392
- const processed = applyDynamicProps(
1393
- __spreadValues({}, appState.data),
1394
- dynamicDataMap,
1395
- dynamicRoot
1396
- );
1397
- const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
1398
- const containsChanges = !(0, import_fast_deep_equal.default)(appState, processedAppState);
1399
- if (containsChanges) {
1400
- dispatch({
1401
- type: "set",
1402
- state: (prev) => __spreadProps(__spreadValues({}, prev), {
1403
- data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
1404
- ui: resolveDataRuns > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
1405
- }),
1406
- recordHistory: resolveDataRuns > 0
1407
- });
1408
- }
1409
- };
1410
- const promises = [];
1411
- promises.push(
1412
- (() => __async(void 0, null, function* () {
1413
- _setComponentLoading("puck-root", true, 50);
1414
- const dynamicRoot = yield resolveRootData(newData, config, metadata);
1415
- applyIfChange({}, dynamicRoot);
1416
- _setComponentLoading("puck-root", false);
1417
- }))()
1418
- );
1419
- flatContent.forEach((item) => {
1420
- promises.push(
1421
- (() => __async(void 0, null, function* () {
1422
- permissions.resolvePermissions({ item }, true);
1423
- const dynamicData = yield resolveComponentData(
1424
- item,
1425
- config,
1426
- metadata,
1427
- (item2) => {
1428
- _setComponentLoading(item2.props.id, true, 50);
1429
- },
1430
- (item2) => {
1431
- deferredSetStates[item2.props.id];
1432
- _setComponentLoading(item2.props.id, false);
1433
- }
1434
- );
1435
- const dynamicDataMap = { [item.props.id]: dynamicData };
1436
- applyIfChange(dynamicDataMap);
1437
- }))()
1438
- );
1439
- });
1440
- yield Promise.all(promises);
1441
- });
1442
- return runResolvers();
1443
- };
1444
-
1445
1189
  // ../core/store/index.ts
1446
1190
  import { createContext, useContext } from "react";
1447
1191
 
@@ -1549,7 +1293,7 @@ var createHistorySlice = (set, get) => {
1549
1293
  const { dispatch, history } = get();
1550
1294
  dispatch({
1551
1295
  type: "set",
1552
- state: ((_a = history.histories[history.index]) == null ? void 0 : _a.state) || history.initialAppState
1296
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1553
1297
  });
1554
1298
  set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1555
1299
  },
@@ -1559,31 +1303,14 @@ var createHistorySlice = (set, get) => {
1559
1303
 
1560
1304
  // ../core/store/slices/nodes.ts
1561
1305
  init_react_import();
1562
- var import_fast_deep_equal2 = __toESM(require_fast_deep_equal());
1563
- import { useEffect as useEffect3 } from "react";
1564
- var partialDeepEqual = (newItem, existingItem) => {
1565
- const filteredExistingItem = Object.keys(newItem).reduce(
1566
- (acc, key) => __spreadProps(__spreadValues({}, acc), { [key]: existingItem[key] }),
1567
- {}
1568
- );
1569
- return (0, import_fast_deep_equal2.default)(newItem, filteredExistingItem);
1570
- };
1571
1306
  var createNodesSlice = (set, get) => ({
1572
1307
  nodes: {},
1573
1308
  registerNode: (id, node) => {
1574
1309
  const s = get().nodes;
1575
- if (s.nodes[id] && partialDeepEqual(node, s.nodes[id])) {
1576
- return;
1577
- }
1578
1310
  const emptyNode = {
1579
1311
  id,
1580
1312
  methods: { sync: () => null },
1581
- data: { props: { id }, type: "unknown" },
1582
- parentId: "",
1583
- zone: "",
1584
- path: [],
1585
- element: null,
1586
- index: -1
1313
+ element: null
1587
1314
  };
1588
1315
  const existingNode = s.nodes[id];
1589
1316
  set({
@@ -1613,36 +1340,61 @@ var createNodesSlice = (set, get) => ({
1613
1340
 
1614
1341
  // ../core/store/slices/permissions.ts
1615
1342
  init_react_import();
1616
- import { useEffect as useEffect4 } from "react";
1343
+ import { useEffect as useEffect3 } from "react";
1344
+
1345
+ // ../core/lib/data/flatten-data.ts
1346
+ init_react_import();
1347
+ var flattenData = (state, config) => {
1348
+ const data = [];
1349
+ walkTree(
1350
+ state,
1351
+ config,
1352
+ (content) => content,
1353
+ (item) => {
1354
+ data.push(item);
1355
+ return null;
1356
+ }
1357
+ );
1358
+ return data;
1359
+ };
1360
+
1361
+ // ../core/lib/get-changed.ts
1362
+ init_react_import();
1363
+ var getChanged = (newItem, oldItem) => {
1364
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1365
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1366
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1367
+ return __spreadProps(__spreadValues({}, acc), {
1368
+ [item]: oldItemProps[item] !== newItemProps[item]
1369
+ });
1370
+ }, {}) : {};
1371
+ };
1372
+
1373
+ // ../core/store/slices/permissions.ts
1617
1374
  var createPermissionsSlice = (set, get) => {
1618
1375
  const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1619
- const { state, permissions } = get();
1620
- const { cache: cache3, globalPermissions } = permissions;
1376
+ const { state, permissions, config } = get();
1377
+ const { cache: cache2, globalPermissions } = permissions;
1621
1378
  const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1622
1379
  var _a, _b, _c;
1623
- const {
1624
- config,
1625
- state: appState,
1626
- setComponentLoading,
1627
- unsetComponentLoading
1628
- } = get();
1629
- const componentConfig = item2.type === "root" ? config.root : config.components[item2.type];
1380
+ const { config: config2, state: appState, setComponentLoading } = get();
1381
+ const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1630
1382
  if (!componentConfig) {
1631
1383
  return;
1632
1384
  }
1633
1385
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1634
1386
  if (componentConfig.resolvePermissions) {
1635
- const changed = getChanged(item2, (_a = cache3[item2.props.id]) == null ? void 0 : _a.lastData);
1387
+ const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1636
1388
  if (Object.values(changed).some((el) => el === true) || force2) {
1637
- setComponentLoading(item2.props.id);
1389
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1638
1390
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1639
1391
  item2,
1640
1392
  {
1641
1393
  changed,
1642
- lastPermissions: ((_b = cache3[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1394
+ lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1643
1395
  permissions: initialPermissions,
1644
- appState,
1645
- lastData: ((_c = cache3[item2.props.id]) == null ? void 0 : _c.lastData) || null
1396
+ appState: makeStatePublic(appState),
1397
+ lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1646
1398
  }
1647
1399
  );
1648
1400
  const latest = get().permissions;
@@ -1659,7 +1411,7 @@ var createPermissionsSlice = (set, get) => {
1659
1411
  })
1660
1412
  })
1661
1413
  });
1662
- unsetComponentLoading(item2.props.id);
1414
+ clearTimeout2();
1663
1415
  }
1664
1416
  }
1665
1417
  });
@@ -1669,7 +1421,7 @@ var createPermissionsSlice = (set, get) => {
1669
1421
  // Shim the root data in by conforming to component data shape
1670
1422
  {
1671
1423
  type: "root",
1672
- props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
1424
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1673
1425
  },
1674
1426
  force2
1675
1427
  );
@@ -1678,14 +1430,13 @@ var createPermissionsSlice = (set, get) => {
1678
1430
  if (item) {
1679
1431
  yield resolveDataForItem(item, force);
1680
1432
  } else if (type) {
1681
- flattenData(state.data).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1433
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1682
1434
  yield resolveDataForItem(item2, force);
1683
1435
  }));
1684
1436
  } else if (root) {
1685
1437
  resolveDataForRoot(force);
1686
1438
  } else {
1687
- resolveDataForRoot(force);
1688
- flattenData(state.data).map((item2) => __async(void 0, null, function* () {
1439
+ flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1689
1440
  yield resolveDataForItem(item2, force);
1690
1441
  }));
1691
1442
  }
@@ -1715,7 +1466,7 @@ var createPermissionsSlice = (set, get) => {
1715
1466
  } else if (root) {
1716
1467
  const rootConfig = config.root;
1717
1468
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1718
- const resolvedForItem = resolvedPermissions["puck-root"];
1469
+ const resolvedForItem = resolvedPermissions["root"];
1719
1470
  return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1720
1471
  }
1721
1472
  return globalPermissions;
@@ -1727,8 +1478,8 @@ var createPermissionsSlice = (set, get) => {
1727
1478
 
1728
1479
  // ../core/store/slices/fields.ts
1729
1480
  init_react_import();
1730
- import { useCallback, useEffect as useEffect5 } from "react";
1731
- var createFieldsStore = (_set, _get) => {
1481
+ import { useCallback, useEffect as useEffect4 } from "react";
1482
+ var createFieldsSlice = (_set, _get) => {
1732
1483
  return {
1733
1484
  fields: {},
1734
1485
  loading: false,
@@ -1736,6 +1487,112 @@ var createFieldsStore = (_set, _get) => {
1736
1487
  };
1737
1488
  };
1738
1489
 
1490
+ // ../core/lib/resolve-component-data.ts
1491
+ init_react_import();
1492
+
1493
+ // ../core/lib/data/map-slots.ts
1494
+ init_react_import();
1495
+ function mapSlotsAsync(_0, _1) {
1496
+ return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
1497
+ const props = __spreadValues({}, item.props);
1498
+ const propKeys = Object.keys(props);
1499
+ for (let i = 0; i < propKeys.length; i++) {
1500
+ const propKey = propKeys[i];
1501
+ const itemType = "type" in item ? item.type : "root";
1502
+ if (isSlot2(itemType, propKey, props[propKey])) {
1503
+ const content = props[propKey];
1504
+ const mappedContent = recursive ? yield Promise.all(
1505
+ content.map((item2) => __async(this, null, function* () {
1506
+ return yield mapSlotsAsync(item2, map, recursive, isSlot2);
1507
+ }))
1508
+ ) : content;
1509
+ props[propKey] = yield map(mappedContent, propKey);
1510
+ }
1511
+ }
1512
+ return __spreadProps(__spreadValues({}, item), { props });
1513
+ });
1514
+ }
1515
+
1516
+ // ../core/lib/resolve-component-data.ts
1517
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1518
+ var cache = { lastChange: {} };
1519
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
1520
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
1521
+ if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
1522
+ const id = "id" in item.props ? item.props.id : "root";
1523
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1524
+ if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
1525
+ return { node: resolved, didChange: false };
1526
+ }
1527
+ const changed = getChanged(item, oldItem);
1528
+ if (onResolveStart) {
1529
+ onResolveStart(item);
1530
+ }
1531
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1532
+ changed,
1533
+ lastData: oldItem,
1534
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1535
+ trigger
1536
+ });
1537
+ let resolvedItem = __spreadProps(__spreadValues({}, item), {
1538
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1539
+ });
1540
+ if (recursive) {
1541
+ resolvedItem = yield mapSlotsAsync(
1542
+ resolvedItem,
1543
+ (content) => __async(void 0, null, function* () {
1544
+ return Promise.all(
1545
+ content.map(
1546
+ (childItem) => __async(void 0, null, function* () {
1547
+ return (yield resolveComponentData(
1548
+ childItem,
1549
+ config,
1550
+ metadata,
1551
+ onResolveStart,
1552
+ onResolveEnd,
1553
+ trigger,
1554
+ false
1555
+ )).node;
1556
+ })
1557
+ )
1558
+ );
1559
+ }),
1560
+ false,
1561
+ createIsSlotConfig(config)
1562
+ );
1563
+ }
1564
+ if (Object.keys(readOnly).length) {
1565
+ resolvedItem.readOnly = readOnly;
1566
+ }
1567
+ cache.lastChange[id] = {
1568
+ item,
1569
+ resolved: resolvedItem
1570
+ };
1571
+ if (onResolveEnd) {
1572
+ onResolveEnd(resolvedItem);
1573
+ }
1574
+ return { node: resolvedItem, didChange: !(0, import_fast_deep_equal.default)(item, resolvedItem) };
1575
+ }
1576
+ return { node: item, didChange: false };
1577
+ });
1578
+
1579
+ // ../core/lib/data/to-root.ts
1580
+ init_react_import();
1581
+ var toRoot = (item) => {
1582
+ if ("type" in item && item.type !== "root") {
1583
+ throw new Error("Converting non-root item to root.");
1584
+ }
1585
+ const { readOnly } = item;
1586
+ if (item.props) {
1587
+ if ("id" in item.props) {
1588
+ const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
1589
+ return { props, readOnly };
1590
+ }
1591
+ return { props: item.props, readOnly };
1592
+ }
1593
+ return { props: {}, readOnly };
1594
+ };
1595
+
1739
1596
  // ../core/store/index.ts
1740
1597
  var defaultAppState = {
1741
1598
  data: { content: [], root: {}, zones: {} },
@@ -1756,92 +1613,186 @@ var defaultAppState = {
1756
1613
  controlsVisible: true
1757
1614
  },
1758
1615
  field: { focus: null }
1616
+ },
1617
+ indexes: {
1618
+ nodes: {},
1619
+ zones: {}
1759
1620
  }
1760
1621
  };
1761
1622
  var defaultPageFields = {
1762
1623
  title: { type: "text" }
1763
1624
  };
1764
1625
  var createAppStore = (initialAppStore) => create()(
1765
- subscribeWithSelector((set, get) => __spreadProps(__spreadValues({
1766
- state: defaultAppState,
1767
- config: { components: {} },
1768
- componentState: {},
1769
- plugins: [],
1770
- overrides: {},
1771
- viewports: defaultViewports,
1772
- zoomConfig: {
1773
- autoZoom: 1,
1774
- rootHeight: 0,
1775
- zoom: 1
1776
- },
1777
- status: "LOADING",
1778
- iframe: {},
1779
- metadata: {}
1780
- }, initialAppStore), {
1781
- fields: createFieldsStore(set, get),
1782
- history: createHistorySlice(set, get),
1783
- nodes: createNodesSlice(set, get),
1784
- permissions: createPermissionsSlice(set, get),
1785
- getComponentConfig: (type) => {
1786
- var _a;
1787
- const { config, selectedItem } = get();
1788
- const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1789
- return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1790
- },
1791
- dispatch: (action) => set((s) => {
1792
- var _a, _b;
1793
- const { record } = get().history;
1794
- const dispatch = createReducer({ config: s.config, record });
1795
- const state = dispatch(s.state, action);
1796
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1797
- (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1798
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1799
- }),
1800
- setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1801
- setStatus: (status) => set({ status }),
1802
- setComponentState: (componentState) => set({ componentState }),
1803
- setComponentLoading: (id) => {
1804
- var _a;
1805
- const { setComponentState, componentState } = get();
1806
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1807
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1808
- loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1809
- })
1810
- }));
1811
- },
1812
- unsetComponentLoading: (id) => {
1813
- var _a;
1814
- const { setComponentState, componentState } = get();
1815
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1816
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1817
- loadingCount: Math.max(
1818
- (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1819
- 0
1820
- )
1821
- })
1822
- }));
1823
- },
1824
- // Helper
1825
- setUi: (ui, recordHistory) => set((s) => {
1826
- const dispatch = createReducer({
1827
- config: s.config,
1828
- record: () => {
1829
- }
1830
- });
1831
- const state = dispatch(s.state, {
1832
- type: "setUi",
1833
- ui,
1834
- recordHistory
1835
- });
1836
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1837
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1838
- }),
1839
- resolveDataRuns: 0,
1840
- resolveData: (newAppState) => set((s) => {
1841
- resolveData(newAppState, get());
1842
- return __spreadProps(__spreadValues({}, s), { resolveDataRuns: s.resolveDataRuns + 1 });
1843
- })
1844
- }))
1626
+ subscribeWithSelector((set, get) => {
1627
+ var _a, _b;
1628
+ return __spreadProps(__spreadValues({
1629
+ state: defaultAppState,
1630
+ config: { components: {} },
1631
+ componentState: {},
1632
+ plugins: [],
1633
+ overrides: {},
1634
+ viewports: defaultViewports,
1635
+ zoomConfig: {
1636
+ autoZoom: 1,
1637
+ rootHeight: 0,
1638
+ zoom: 1
1639
+ },
1640
+ status: "LOADING",
1641
+ iframe: {},
1642
+ metadata: {}
1643
+ }, initialAppStore), {
1644
+ fields: createFieldsSlice(set, get),
1645
+ history: createHistorySlice(set, get),
1646
+ nodes: createNodesSlice(set, get),
1647
+ permissions: createPermissionsSlice(set, get),
1648
+ getComponentConfig: (type) => {
1649
+ var _a2;
1650
+ const { config, selectedItem } = get();
1651
+ const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
1652
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1653
+ },
1654
+ selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
1655
+ (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
1656
+ initialAppStore.state
1657
+ ) : null,
1658
+ dispatch: (action) => set((s) => {
1659
+ var _a2, _b2;
1660
+ const { record } = get().history;
1661
+ const dispatch = createReducer({
1662
+ record,
1663
+ appStore: s
1664
+ });
1665
+ const state = dispatch(s.state, action);
1666
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1667
+ (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
1668
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1669
+ }),
1670
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1671
+ setStatus: (status) => set({ status }),
1672
+ setComponentState: (componentState) => set({ componentState }),
1673
+ pendingLoadTimeouts: {},
1674
+ setComponentLoading: (id, loading = true, defer = 0) => {
1675
+ const { setComponentState, pendingLoadTimeouts } = get();
1676
+ const loadId = generateId();
1677
+ const setLoading = () => {
1678
+ var _a2;
1679
+ const { componentState } = get();
1680
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1681
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1682
+ loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
1683
+ })
1684
+ }));
1685
+ };
1686
+ const unsetLoading = () => {
1687
+ var _a2;
1688
+ const { componentState } = get();
1689
+ clearTimeout(timeout);
1690
+ delete pendingLoadTimeouts[loadId];
1691
+ set({ pendingLoadTimeouts });
1692
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1693
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1694
+ loadingCount: Math.max(
1695
+ (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
1696
+ 0
1697
+ )
1698
+ })
1699
+ }));
1700
+ };
1701
+ const timeout = setTimeout(() => {
1702
+ if (loading) {
1703
+ setLoading();
1704
+ } else {
1705
+ unsetLoading();
1706
+ }
1707
+ delete pendingLoadTimeouts[loadId];
1708
+ set({ pendingLoadTimeouts });
1709
+ }, defer);
1710
+ set({
1711
+ pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
1712
+ [id]: timeout
1713
+ })
1714
+ });
1715
+ return unsetLoading;
1716
+ },
1717
+ unsetComponentLoading: (id) => {
1718
+ const { setComponentLoading } = get();
1719
+ setComponentLoading(id, false);
1720
+ },
1721
+ // Helper
1722
+ setUi: (ui, recordHistory) => set((s) => {
1723
+ const dispatch = createReducer({
1724
+ record: () => {
1725
+ },
1726
+ appStore: s
1727
+ });
1728
+ const state = dispatch(s.state, {
1729
+ type: "setUi",
1730
+ ui,
1731
+ recordHistory
1732
+ });
1733
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1734
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1735
+ }),
1736
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1737
+ const { config, metadata, setComponentLoading, permissions } = get();
1738
+ const timeouts = {};
1739
+ return yield resolveComponentData(
1740
+ componentData,
1741
+ config,
1742
+ metadata,
1743
+ (item) => {
1744
+ const id = "id" in item.props ? item.props.id : "root";
1745
+ timeouts[id] = setComponentLoading(id, true, 50);
1746
+ },
1747
+ (item) => __async(void 0, null, function* () {
1748
+ const id = "id" in item.props ? item.props.id : "root";
1749
+ if ("type" in item) {
1750
+ yield permissions.refreshPermissions({ item });
1751
+ } else {
1752
+ yield permissions.refreshPermissions({ root: true });
1753
+ }
1754
+ timeouts[id]();
1755
+ }),
1756
+ trigger
1757
+ );
1758
+ }),
1759
+ resolveAndCommitData: () => __async(void 0, null, function* () {
1760
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1761
+ walkTree(
1762
+ state,
1763
+ config,
1764
+ (content) => content,
1765
+ (childItem) => {
1766
+ resolveComponentData2(childItem, "load").then((resolved) => {
1767
+ const { state: state2 } = get();
1768
+ const node = state2.indexes.nodes[resolved.node.props.id];
1769
+ if (node && resolved.didChange) {
1770
+ if (resolved.node.props.id === "root") {
1771
+ dispatch({
1772
+ type: "replaceRoot",
1773
+ root: toRoot(resolved.node)
1774
+ });
1775
+ } else {
1776
+ const zoneCompound = `${node.parentId}:${node.zone}`;
1777
+ const parentZone = state2.indexes.zones[zoneCompound];
1778
+ const index = parentZone.contentIds.indexOf(
1779
+ resolved.node.props.id
1780
+ );
1781
+ dispatch({
1782
+ type: "replace",
1783
+ data: resolved.node,
1784
+ destinationIndex: index,
1785
+ destinationZone: zoneCompound
1786
+ });
1787
+ }
1788
+ }
1789
+ });
1790
+ return childItem;
1791
+ }
1792
+ );
1793
+ })
1794
+ });
1795
+ })
1845
1796
  );
1846
1797
  var appStoreContext = createContext(createAppStore());
1847
1798
  function useAppStore(selector) {
@@ -1861,12 +1812,12 @@ var useBreadcrumbs = (renderCount) => {
1861
1812
  const config = useAppStore((s) => s.config);
1862
1813
  const path = useAppStore((s) => {
1863
1814
  var _a;
1864
- return (_a = s.nodes.nodes[selectedId]) == null ? void 0 : _a.path;
1815
+ return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
1865
1816
  });
1866
1817
  const appStore = useAppStoreApi();
1867
1818
  return useMemo(() => {
1868
1819
  const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
1869
- var _a, _b;
1820
+ var _a, _b, _c;
1870
1821
  const [componentId] = zoneCompound.split(":");
1871
1822
  if (componentId === "root") {
1872
1823
  return {
@@ -1874,12 +1825,15 @@ var useBreadcrumbs = (renderCount) => {
1874
1825
  selector: null
1875
1826
  };
1876
1827
  }
1877
- const node = appStore.getState().nodes.nodes[componentId];
1878
- const label = node ? (_b = (_a = config.components[node.data.type]) == null ? void 0 : _a.label) != null ? _b : node.data.type : "Component";
1828
+ const node = appStore.getState().state.indexes.nodes[componentId];
1829
+ const parentId = node.path[node.path.length - 1];
1830
+ const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
1831
+ const index = contentIds.indexOf(componentId);
1832
+ const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
1879
1833
  return {
1880
1834
  label,
1881
1835
  selector: node ? {
1882
- index: node.index,
1836
+ index,
1883
1837
  zone: node.path[node.path.length - 1]
1884
1838
  } : null
1885
1839
  };
@@ -1900,6 +1854,12 @@ init_react_import();
1900
1854
  // ../core/lib/filter.ts
1901
1855
  init_react_import();
1902
1856
 
1857
+ // ../core/lib/data/reorder.ts
1858
+ init_react_import();
1859
+
1860
+ // ../core/lib/data/replace.ts
1861
+ init_react_import();
1862
+
1903
1863
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
1904
1864
  init_react_import();
1905
1865
  var styles_module_default3 = { "Loader": "_Loader_nacdm_13", "loader-animation": "_loader-animation_nacdm_1" };
@@ -2081,17 +2041,39 @@ var usePuck = createUsePuck();
2081
2041
  var HeadingAnalyzer = () => {
2082
2042
  const data = usePuck((s) => s.appState.data);
2083
2043
  const [hierarchy, setHierarchy] = useState([]);
2084
- useEffect6(() => {
2044
+ useEffect5(() => {
2085
2045
  const frame = getFrame();
2086
- const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2087
- if (!entry) return;
2088
- setHierarchy(buildHierarchy(entry));
2089
- const observer = new MutationObserver(() => {
2046
+ let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2047
+ const createHierarchy = () => {
2090
2048
  setHierarchy(buildHierarchy(entry));
2049
+ };
2050
+ const entryObserver = new MutationObserver(() => {
2051
+ createHierarchy();
2052
+ });
2053
+ const frameObserver = new MutationObserver(() => {
2054
+ entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2055
+ if (entry) {
2056
+ registerEntryObserver();
2057
+ frameObserver.disconnect();
2058
+ }
2091
2059
  });
2092
- observer.observe(entry, { subtree: true, childList: true });
2060
+ const registerEntryObserver = () => {
2061
+ if (!entry) return;
2062
+ entryObserver.observe(entry, { subtree: true, childList: true });
2063
+ };
2064
+ const registerFrameObserver = () => {
2065
+ if (!frame) return;
2066
+ frameObserver.observe(frame, { subtree: true, childList: true });
2067
+ };
2068
+ if (entry) {
2069
+ createHierarchy();
2070
+ registerEntryObserver();
2071
+ } else {
2072
+ registerFrameObserver();
2073
+ }
2093
2074
  return () => {
2094
- observer.disconnect();
2075
+ entryObserver.disconnect();
2076
+ frameObserver.disconnect();
2095
2077
  };
2096
2078
  }, [data]);
2097
2079
  return /* @__PURE__ */ jsxs2("div", { className: getClassName5(), children: [
@@ -2194,50 +2176,6 @@ classnames/index.js:
2194
2176
  http://jedwatson.github.io/classnames
2195
2177
  *)
2196
2178
 
2197
- use-sync-external-store/cjs/use-sync-external-store-shim.production.js:
2198
- (**
2199
- * @license React
2200
- * use-sync-external-store-shim.production.js
2201
- *
2202
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2203
- *
2204
- * This source code is licensed under the MIT license found in the
2205
- * LICENSE file in the root directory of this source tree.
2206
- *)
2207
-
2208
- use-sync-external-store/cjs/use-sync-external-store-shim.development.js:
2209
- (**
2210
- * @license React
2211
- * use-sync-external-store-shim.development.js
2212
- *
2213
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2214
- *
2215
- * This source code is licensed under the MIT license found in the
2216
- * LICENSE file in the root directory of this source tree.
2217
- *)
2218
-
2219
- use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.production.js:
2220
- (**
2221
- * @license React
2222
- * use-sync-external-store-shim/with-selector.production.js
2223
- *
2224
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2225
- *
2226
- * This source code is licensed under the MIT license found in the
2227
- * LICENSE file in the root directory of this source tree.
2228
- *)
2229
-
2230
- use-sync-external-store/cjs/use-sync-external-store-shim/with-selector.development.js:
2231
- (**
2232
- * @license React
2233
- * use-sync-external-store-shim/with-selector.development.js
2234
- *
2235
- * Copyright (c) Meta Platforms, Inc. and affiliates.
2236
- *
2237
- * This source code is licensed under the MIT license found in the
2238
- * LICENSE file in the root directory of this source tree.
2239
- *)
2240
-
2241
2179
  lucide-react/dist/esm/shared/src/utils.js:
2242
2180
  (**
2243
2181
  * @license lucide-react v0.468.0 - ISC