@measured/puck-plugin-heading-analyzer 0.19.0-canary.61c8658 → 0.19.0-canary.6dc5101e

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