@measured/puck-plugin-heading-analyzer 0.19.0-canary.036267f6 → 0.19.0-canary.046cb9ed

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
@@ -368,131 +368,30 @@ init_react_import();
368
368
  // ../core/reducer/index.ts
369
369
  init_react_import();
370
370
 
371
- // ../core/reducer/reduce.ts
371
+ // ../core/reducer/actions/set.ts
372
372
  init_react_import();
373
373
 
374
- // ../core/lib/insert.ts
374
+ // ../core/lib/data/walk-app-state.ts
375
375
  init_react_import();
376
- var insert = (list, index, item) => {
377
- const result = Array.from(list || []);
378
- result.splice(index, 0, item);
379
- return result;
380
- };
381
-
382
- // ../core/lib/remove.ts
383
- init_react_import();
384
- var remove = (list, index) => {
385
- const result = Array.from(list);
386
- result.splice(index, 1);
387
- return result;
388
- };
389
-
390
- // ../core/lib/setup-zone.ts
391
- init_react_import();
392
-
393
- // ../core/lib/root-droppable-id.ts
394
- init_react_import();
395
- var rootAreaId = "root";
396
- var rootZone = "default-zone";
397
- var rootDroppableId = `${rootAreaId}:${rootZone}`;
398
-
399
- // ../core/lib/setup-zone.ts
400
- var setupZone = (data, zoneKey) => {
401
- if (zoneKey === rootDroppableId) {
402
- return data;
403
- }
404
- const newData = __spreadProps(__spreadValues({}, data), {
405
- zones: data.zones ? __spreadValues({}, data.zones) : {}
406
- });
407
- newData.zones[zoneKey] = newData.zones[zoneKey] || [];
408
- return newData;
409
- };
410
-
411
- // ../core/lib/get-item.ts
412
- init_react_import();
413
- function getItem(selector, state) {
414
- var _a, _b;
415
- const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
416
- return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
417
- }
418
-
419
- // ../core/lib/generate-id.ts
420
- init_react_import();
421
-
422
- // ../../node_modules/uuid/dist/esm-node/index.js
423
- init_react_import();
424
-
425
- // ../../node_modules/uuid/dist/esm-node/rng.js
426
- init_react_import();
427
- var import_crypto = __toESM(require("crypto"));
428
- var rnds8Pool = new Uint8Array(256);
429
- var poolPtr = rnds8Pool.length;
430
- function rng() {
431
- if (poolPtr > rnds8Pool.length - 16) {
432
- import_crypto.default.randomFillSync(rnds8Pool);
433
- poolPtr = 0;
434
- }
435
- return rnds8Pool.slice(poolPtr, poolPtr += 16);
436
- }
437
-
438
- // ../../node_modules/uuid/dist/esm-node/stringify.js
439
- init_react_import();
440
- var byteToHex = [];
441
- for (let i = 0; i < 256; ++i) {
442
- byteToHex.push((i + 256).toString(16).slice(1));
443
- }
444
- function unsafeStringify(arr, offset = 0) {
445
- return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
446
- }
447
376
 
448
- // ../../node_modules/uuid/dist/esm-node/v4.js
377
+ // ../core/lib/data/for-each-slot.ts
449
378
  init_react_import();
450
379
 
451
- // ../../node_modules/uuid/dist/esm-node/native.js
452
- init_react_import();
453
- var import_crypto2 = __toESM(require("crypto"));
454
- var native_default = {
455
- randomUUID: import_crypto2.default.randomUUID
456
- };
457
-
458
- // ../../node_modules/uuid/dist/esm-node/v4.js
459
- function v4(options, buf, offset) {
460
- if (native_default.randomUUID && !buf && !options) {
461
- return native_default.randomUUID();
462
- }
463
- options = options || {};
464
- const rnds = options.random || (options.rng || rng)();
465
- rnds[6] = rnds[6] & 15 | 64;
466
- rnds[8] = rnds[8] & 63 | 128;
467
- if (buf) {
468
- offset = offset || 0;
469
- for (let i = 0; i < 16; ++i) {
470
- buf[offset + i] = rnds[i];
471
- }
472
- return buf;
473
- }
474
- return unsafeStringify(rnds);
475
- }
476
- var v4_default = v4;
477
-
478
- // ../core/lib/generate-id.ts
479
- var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
480
-
481
- // ../core/lib/walk-tree.ts
482
- init_react_import();
483
-
484
- // ../core/lib/for-each-slot.ts
485
- init_react_import();
486
-
487
- // ../core/lib/is-slot.ts
380
+ // ../core/lib/data/is-slot.ts
488
381
  init_react_import();
489
382
  var isSlot = (prop) => {
490
383
  var _a, _b;
491
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";
492
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";
391
+ };
493
392
 
494
- // ../core/lib/for-each-slot.ts
495
- var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, cb, recursive = false, isSlot2 = isSlot) {
393
+ // ../core/lib/data/for-each-slot.ts
394
+ var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
496
395
  const props = item.props || {};
497
396
  const propKeys = Object.keys(props);
498
397
  for (let i = 0; i < propKeys.length; i++) {
@@ -500,23 +399,31 @@ var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function*
500
399
  const itemType = "type" in item ? item.type : "root";
501
400
  if (isSlot2(itemType, propKey, props[propKey])) {
502
401
  const content = props[propKey];
503
- yield cb(props.id, propKey, content);
402
+ cb(props.id, propKey, content);
504
403
  if (recursive) {
505
404
  content.forEach(
506
405
  (childItem) => __async(void 0, null, function* () {
507
- return yield forEachSlot(childItem, cb, true, isSlot2);
406
+ return forEachSlot(childItem, cb, true, isSlot2);
508
407
  })
509
408
  );
510
409
  }
511
410
  }
512
411
  }
513
- });
412
+ };
514
413
 
515
- // ../core/lib/for-related-zones.ts
414
+ // ../core/lib/data/for-related-zones.ts
516
415
  init_react_import();
517
416
 
518
417
  // ../core/lib/get-zone-id.ts
519
418
  init_react_import();
419
+
420
+ // ../core/lib/root-droppable-id.ts
421
+ init_react_import();
422
+ var rootAreaId = "root";
423
+ var rootZone = "default-zone";
424
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
425
+
426
+ // ../core/lib/get-zone-id.ts
520
427
  var getZoneId = (zoneCompound) => {
521
428
  if (!zoneCompound) {
522
429
  return [];
@@ -527,19 +434,17 @@ var getZoneId = (zoneCompound) => {
527
434
  return [rootDroppableId, zoneCompound];
528
435
  };
529
436
 
530
- // ../core/lib/for-related-zones.ts
437
+ // ../core/lib/data/for-related-zones.ts
531
438
  function forRelatedZones(item, data, cb, path = []) {
532
439
  Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
533
440
  const [parentId] = getZoneId(zoneCompound);
534
441
  if (parentId === item.props.id) {
535
- const newPath = [...path, zoneCompound];
536
- content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
537
442
  cb(path, zoneCompound, content);
538
443
  }
539
444
  });
540
445
  }
541
446
 
542
- // ../core/lib/strip-slots.ts
447
+ // ../core/lib/data/strip-slots.ts
543
448
  init_react_import();
544
449
  var stripSlots = (data) => {
545
450
  return __spreadProps(__spreadValues({}, data), {
@@ -555,8 +460,8 @@ var stripSlots = (data) => {
555
460
  });
556
461
  };
557
462
 
558
- // ../core/lib/walk-tree.ts
559
- function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
463
+ // ../core/lib/data/walk-app-state.ts
464
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
560
465
  var _a;
561
466
  let newZones = {};
562
467
  const newZoneIndex = {};
@@ -597,7 +502,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
597
502
  const mappedItem = mapNodeOrSkip(item, path, index);
598
503
  if (!mappedItem) return item;
599
504
  const id = mappedItem.props.id;
600
- processRelatedZones(item, id, path);
601
505
  const newProps = __spreadValues({}, mappedItem.props);
602
506
  forEachSlot(
603
507
  mappedItem,
@@ -613,13 +517,9 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
613
517
  newProps[slotId] = newContent2;
614
518
  },
615
519
  false,
616
- (itemType, propName, propValue) => {
617
- var _a2, _b;
618
- const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
619
- if (!configForComponent) return isSlot(propValue);
620
- return ((_b = (_a2 = configForComponent.fields) == null ? void 0 : _a2[propName]) == null ? void 0 : _b.type) === "slot";
621
- }
520
+ createIsSlotConfig(config)
622
521
  );
522
+ processRelatedZones(item, id, path);
623
523
  const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
624
524
  const thisZoneCompound = path[path.length - 1];
625
525
  const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
@@ -630,7 +530,7 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
630
530
  parentId,
631
531
  zone
632
532
  };
633
- const finalData = newItem;
533
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
634
534
  if (newProps.id === "root") {
635
535
  delete finalData["type"];
636
536
  delete finalData.props["id"];
@@ -645,8 +545,12 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
645
545
  "root"
646
546
  );
647
547
  const processedContent = newContent;
548
+ const zonesAlreadyProcessed = Object.keys(newZones);
648
549
  Object.keys(zones || {}).forEach((zoneCompound) => {
649
550
  const [parentId] = zoneCompound.split(":");
551
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
552
+ return;
553
+ }
650
554
  const [_2, newContent2] = processContent(
651
555
  [rootDroppableId],
652
556
  zoneCompound,
@@ -670,7 +574,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
670
574
  return __spreadProps(__spreadValues({}, state), {
671
575
  data: {
672
576
  root,
673
- // root: state.data.root, // TODO changing root causes it's entire subtree to re-render. Let's keep this disabled until the performance issues are resolved in #644.
674
577
  content: processedContent,
675
578
  zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
676
579
  },
@@ -681,60 +584,214 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
681
584
  });
682
585
  }
683
586
 
684
- // ../core/lib/deindex.ts
685
- init_react_import();
686
- var deindex = (state, componentData) => {
687
- let zones = __spreadValues({}, state.indexes.zones);
688
- let nodes = __spreadValues({}, state.indexes.nodes);
689
- const dindexRelatedZones = (item) => {
690
- forRelatedZones(item, state.data, (_path, zoneCompound, content) => {
691
- content.forEach((subItem) => {
692
- dindexChildren(subItem);
693
- delete nodes[subItem.props.id];
694
- });
695
- delete zones[zoneCompound];
696
- });
697
- };
698
- const dindexChildren = (item) => {
699
- forEachSlot(
700
- item,
701
- (parentId, slotId, content) => {
702
- const zoneCompound = `${parentId}:${slotId}`;
703
- delete zones[zoneCompound];
704
- content.forEach((item2) => {
705
- dindexRelatedZones(item2);
706
- delete nodes[item2.props.id];
707
- });
708
- },
709
- true
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."
710
596
  );
711
- };
712
- dindexRelatedZones(componentData);
713
- dindexChildren(componentData);
714
- delete nodes[componentData.props.id];
715
- return { nodes, zones };
597
+ return walkAppState(newState, appStore.config);
598
+ }
599
+ return __spreadValues(__spreadValues({}, state), action.state(state));
716
600
  };
717
601
 
718
- // ../core/reducer/reduce.ts
719
- var zoneCache = {};
602
+ // ../core/reducer/actions/insert.ts
603
+ init_react_import();
604
+
605
+ // ../core/lib/data/insert.ts
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
+ };
612
+
613
+ // ../core/lib/generate-id.ts
614
+ init_react_import();
615
+
616
+ // ../../node_modules/uuid/dist/esm-node/index.js
617
+ init_react_import();
618
+
619
+ // ../../node_modules/uuid/dist/esm-node/rng.js
620
+ init_react_import();
621
+ var import_crypto = __toESM(require("crypto"));
622
+ var rnds8Pool = new Uint8Array(256);
623
+ var poolPtr = rnds8Pool.length;
624
+ function rng() {
625
+ if (poolPtr > rnds8Pool.length - 16) {
626
+ import_crypto.default.randomFillSync(rnds8Pool);
627
+ poolPtr = 0;
628
+ }
629
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
630
+ }
631
+
632
+ // ../../node_modules/uuid/dist/esm-node/stringify.js
633
+ init_react_import();
634
+ var byteToHex = [];
635
+ for (let i = 0; i < 256; ++i) {
636
+ byteToHex.push((i + 256).toString(16).slice(1));
637
+ }
638
+ function unsafeStringify(arr, offset = 0) {
639
+ return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
640
+ }
641
+
642
+ // ../../node_modules/uuid/dist/esm-node/v4.js
643
+ init_react_import();
644
+
645
+ // ../../node_modules/uuid/dist/esm-node/native.js
646
+ init_react_import();
647
+ var import_crypto2 = __toESM(require("crypto"));
648
+ var native_default = {
649
+ randomUUID: import_crypto2.default.randomUUID
650
+ };
651
+
652
+ // ../../node_modules/uuid/dist/esm-node/v4.js
653
+ function v4(options, buf, offset) {
654
+ if (native_default.randomUUID && !buf && !options) {
655
+ return native_default.randomUUID();
656
+ }
657
+ options = options || {};
658
+ const rnds = options.random || (options.rng || rng)();
659
+ rnds[6] = rnds[6] & 15 | 64;
660
+ rnds[8] = rnds[8] & 63 | 128;
661
+ if (buf) {
662
+ offset = offset || 0;
663
+ for (let i = 0; i < 16; ++i) {
664
+ buf[offset + i] = rnds[i];
665
+ }
666
+ return buf;
667
+ }
668
+ return unsafeStringify(rnds);
669
+ }
670
+ var v4_default = v4;
671
+
672
+ // ../core/lib/generate-id.ts
673
+ var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
674
+
675
+ // ../core/lib/data/get-ids-for-parent.ts
676
+ init_react_import();
720
677
  var getIdsForParent = (zoneCompound, state) => {
721
678
  const [parentId] = zoneCompound.split(":");
722
679
  const node = state.indexes.nodes[parentId];
723
680
  return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
724
681
  };
725
- function insertAction(state, action, config) {
726
- const id = action.id || generateId(action.componentType);
727
- const emptyComponentData = {
728
- type: action.componentType,
729
- props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
730
- id
731
- })
682
+
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
+ }),
756
+ {}
757
+ )
732
758
  };
759
+ }
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
+ );
733
790
  const [parentId] = action.destinationZone.split(":");
734
791
  const idsInPath = getIdsForParent(action.destinationZone, state);
735
- return walkTree(
792
+ return walkAppState(
736
793
  state,
737
- config,
794
+ appStore.config,
738
795
  (content, zoneCompound) => {
739
796
  if (zoneCompound === action.destinationZone) {
740
797
  return insert(
@@ -745,18 +802,154 @@ function insertAction(state, action, config) {
745
802
  }
746
803
  return content;
747
804
  },
748
- (childItem, path) => {
749
- if (childItem.props.id === id || childItem.props.id === parentId) {
750
- return childItem;
751
- } else if (idsInPath.includes(childItem.props.id)) {
752
- return childItem;
753
- } else if (path.includes(action.destinationZone)) {
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
+ }
815
+ );
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;
838
+ }
839
+ return newContent;
840
+ },
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
+ }
854
+ );
855
+ };
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
+ );
874
+ };
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;
885
+ }
886
+
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)
897
+ })
898
+ });
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) {
754
923
  return childItem;
755
924
  }
756
925
  return null;
757
926
  }
758
927
  );
928
+ return __spreadProps(__spreadValues({}, modified), {
929
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
930
+ itemSelector: {
931
+ index: action.sourceIndex + 1,
932
+ zone: action.sourceZone
933
+ }
934
+ })
935
+ });
759
936
  }
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;
950
+ };
951
+
952
+ // ../core/reducer/actions/move.ts
760
953
  var moveAction = (state, action, appStore) => {
761
954
  if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
762
955
  return state;
@@ -768,7 +961,7 @@ var moveAction = (state, action, appStore) => {
768
961
  if (!item) return state;
769
962
  const idsInSourcePath = getIdsForParent(action.sourceZone, state);
770
963
  const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
771
- return walkTree(
964
+ return walkAppState(
772
965
  state,
773
966
  appStore.config,
774
967
  (content, zoneCompound) => {
@@ -796,222 +989,161 @@ var moveAction = (state, action, appStore) => {
796
989
  }
797
990
  );
798
991
  };
799
- var replaceAction = (state, action, appStore) => {
800
- const [parentId] = action.destinationZone.split(":");
801
- const idsInPath = getIdsForParent(action.destinationZone, state);
802
- return walkTree(
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(
803
1023
  state,
804
1024
  appStore.config,
805
- (content) => content,
806
- (childItem, path) => {
807
- const pathIds = path.map((p) => p.split(":")[0]);
808
- if (childItem.props.id === action.data.props.id) {
809
- return action.data;
810
- } else if (childItem.props.id === parentId) {
811
- return childItem;
812
- } else if (idsInPath.indexOf(childItem.props.id) > -1) {
813
- return childItem;
814
- } else if (pathIds.indexOf(action.data.props.id) > -1) {
815
- return childItem;
1025
+ (content, zoneCompound) => {
1026
+ if (zoneCompound === action.zone) {
1027
+ return remove(content, action.index);
816
1028
  }
817
- return null;
1029
+ return content;
818
1030
  }
819
1031
  );
820
- };
821
- var setAction = (state, action, appStore) => {
822
- if (typeof action.state === "object") {
823
- const newState = __spreadValues(__spreadValues({}, state), action.state);
824
- if (action.state.indexes) {
825
- console.warn(
826
- "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
827
- );
828
- return newState;
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];
829
1036
  }
830
- return walkTree(newState, appStore.config);
831
- }
832
- return __spreadValues(__spreadValues({}, state), action.state(state));
833
- };
834
- function reduce(state, action, appStore) {
835
- if (action.type === "set") {
836
- return setAction(state, action, appStore);
837
- }
838
- if (action.type === "insert") {
839
- return insertAction(state, action, appStore.config);
840
- }
841
- if (action.type === "replace") {
842
- return replaceAction(state, action, appStore);
843
- }
844
- if (action.type === "replaceRoot") {
845
- return walkTree(
846
- state,
847
- appStore.config,
848
- (content) => content,
849
- (childItem) => {
850
- if (childItem.props.id === "root") {
851
- return __spreadProps(__spreadValues({}, childItem), {
852
- props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
853
- readOnly: action.root.readOnly
854
- });
855
- }
856
- return childItem;
857
- }
858
- );
859
- }
860
- if (action.type === "duplicate") {
861
- const item = getItem(
862
- { index: action.sourceIndex, zone: action.sourceZone },
863
- state
864
- );
865
- const idsInPath = getIdsForParent(action.sourceZone, state);
866
- const newItem = __spreadProps(__spreadValues({}, item), {
867
- props: __spreadProps(__spreadValues({}, item.props), {
868
- id: generateId(item.type)
869
- })
870
- });
871
- const modified = walkTree(
872
- state,
873
- appStore.config,
874
- (content, zoneCompound) => {
875
- if (zoneCompound === action.sourceZone) {
876
- return insert(content, action.sourceIndex + 1, item);
877
- }
878
- return content;
879
- },
880
- (childItem, path, index) => {
881
- const zoneCompound = path[path.length - 1];
882
- const parents = path.map((p) => p.split(":")[0]);
883
- if (parents.indexOf(newItem.props.id) > -1) {
884
- return __spreadProps(__spreadValues({}, childItem), {
885
- props: __spreadProps(__spreadValues({}, childItem.props), {
886
- id: generateId(childItem.type)
887
- })
888
- });
889
- }
890
- if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
891
- return newItem;
892
- }
893
- const [sourceZoneParent] = action.sourceZone.split(":");
894
- if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
895
- return childItem;
896
- }
897
- return null;
898
- }
899
- );
900
- return __spreadProps(__spreadValues({}, modified), {
901
- ui: __spreadProps(__spreadValues({}, modified.ui), {
902
- itemSelector: {
903
- index: action.sourceIndex + 1,
904
- zone: action.sourceZone
905
- }
906
- })
907
- });
908
- }
909
- if (action.type === "reorder") {
910
- return moveAction(
911
- state,
912
- {
913
- type: "move",
914
- sourceIndex: action.sourceIndex,
915
- sourceZone: action.destinationZone,
916
- destinationIndex: action.destinationIndex,
917
- destinationZone: action.destinationZone
918
- },
919
- appStore
920
- );
921
- }
922
- if (action.type === "move") {
923
- return moveAction(state, action, appStore);
924
- }
925
- if (action.type === "remove") {
926
- const item = getItem({ index: action.index, zone: action.zone }, state);
927
- let deindexed = deindex(state, item);
928
- const [parentId] = action.zone.split(":");
929
- return walkTree(
930
- __spreadProps(__spreadValues({}, state), { indexes: deindexed }),
931
- appStore.config,
932
- (content, zoneCompound) => {
933
- if (zoneCompound === action.zone) {
934
- return remove(content, action.index);
935
- }
936
- return content;
937
- },
938
- (childItem, path) => {
939
- const parentIds = path.map((p) => p.split(":")[0]);
940
- if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
941
- return childItem;
942
- }
943
- return null;
944
- }
945
- );
946
- }
947
- if (action.type === "registerZone") {
948
- if (zoneCache[action.zone]) {
949
- return __spreadProps(__spreadValues({}, state), {
950
- data: __spreadProps(__spreadValues({}, state.data), {
951
- zones: __spreadProps(__spreadValues({}, state.data.zones), {
952
- [action.zone]: zoneCache[action.zone]
953
- })
954
- }),
955
- indexes: __spreadProps(__spreadValues({}, state.indexes), {
956
- zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
957
- [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
958
- contentIds: zoneCache[action.zone].map((item) => item.props.id),
959
- type: "dropzone"
960
- })
961
- })
962
- })
963
- });
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];
964
1042
  }
965
- return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
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;
966
1058
  }
967
- if (action.type === "unregisterZone") {
968
- const _zones = __spreadValues({}, state.data.zones || {});
969
- const zoneIndex = __spreadValues({}, state.indexes.zones || {});
970
- if (_zones[action.zone]) {
971
- zoneCache[action.zone] = _zones[action.zone];
972
- delete _zones[action.zone];
973
- }
974
- delete zoneIndex[action.zone];
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]) {
975
1070
  return __spreadProps(__spreadValues({}, state), {
976
1071
  data: __spreadProps(__spreadValues({}, state.data), {
977
- zones: _zones
1072
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
1073
+ [action.zone]: zoneCache[action.zone]
1074
+ })
978
1075
  }),
979
1076
  indexes: __spreadProps(__spreadValues({}, state.indexes), {
980
- zones: zoneIndex
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
+ })
981
1083
  })
982
1084
  });
983
1085
  }
984
- if (action.type === "setData") {
985
- if (typeof action.data === "object") {
986
- console.warn(
987
- "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
988
- );
989
- return walkTree(
990
- __spreadProps(__spreadValues({}, state), {
991
- data: __spreadValues(__spreadValues({}, state.data), action.data)
992
- }),
993
- appStore.config
994
- );
995
- }
996
- return walkTree(
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];
1094
+ }
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
+ });
1104
+ }
1105
+
1106
+ // ../core/reducer/actions/set-data.ts
1107
+ init_react_import();
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(
997
1114
  __spreadProps(__spreadValues({}, state), {
998
- data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1115
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
999
1116
  }),
1000
1117
  appStore.config
1001
1118
  );
1002
1119
  }
1003
- if (action.type === "setUi") {
1004
- if (typeof action.ui === "object") {
1005
- return __spreadProps(__spreadValues({}, state), {
1006
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1007
- });
1008
- }
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") {
1009
1132
  return __spreadProps(__spreadValues({}, state), {
1010
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1133
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1011
1134
  });
1012
1135
  }
1013
- return state;
1014
- }
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 };
1146
+ };
1015
1147
 
1016
1148
  // ../core/reducer/actions.tsx
1017
1149
  init_react_import();
@@ -1030,7 +1162,7 @@ function storeInterceptor(reducer, record, onAction) {
1030
1162
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1031
1163
  if (record) record(newAppState);
1032
1164
  }
1033
- onAction == null ? void 0 : onAction(action, newAppState, state);
1165
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1034
1166
  return newAppState;
1035
1167
  };
1036
1168
  }
@@ -1041,8 +1173,43 @@ function createReducer({
1041
1173
  }) {
1042
1174
  return storeInterceptor(
1043
1175
  (state, action) => {
1044
- const result = reduce(state, action, appStore);
1045
- return result;
1176
+ if (action.type === "set") {
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);
1199
+ }
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;
1046
1213
  },
1047
1214
  record,
1048
1215
  onAction
@@ -1237,7 +1404,7 @@ var createHistorySlice = (set, get) => {
1237
1404
  const { dispatch, history } = get();
1238
1405
  dispatch({
1239
1406
  type: "set",
1240
- 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
1241
1408
  });
1242
1409
  set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1243
1410
  },
@@ -1286,11 +1453,11 @@ var createNodesSlice = (set, get) => ({
1286
1453
  init_react_import();
1287
1454
  var import_react7 = require("react");
1288
1455
 
1289
- // ../core/lib/flatten-data.ts
1456
+ // ../core/lib/data/flatten-data.ts
1290
1457
  init_react_import();
1291
1458
  var flattenData = (state, config) => {
1292
1459
  const data = [];
1293
- walkTree(
1460
+ walkAppState(
1294
1461
  state,
1295
1462
  config,
1296
1463
  (content) => content,
@@ -1321,12 +1488,7 @@ var createPermissionsSlice = (set, get) => {
1321
1488
  const { cache: cache2, globalPermissions } = permissions;
1322
1489
  const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1323
1490
  var _a, _b, _c;
1324
- const {
1325
- config: config2,
1326
- state: appState,
1327
- setComponentLoading,
1328
- unsetComponentLoading
1329
- } = get();
1491
+ const { config: config2, state: appState, setComponentLoading } = get();
1330
1492
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1331
1493
  if (!componentConfig) {
1332
1494
  return;
@@ -1335,14 +1497,14 @@ var createPermissionsSlice = (set, get) => {
1335
1497
  if (componentConfig.resolvePermissions) {
1336
1498
  const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1337
1499
  if (Object.values(changed).some((el) => el === true) || force2) {
1338
- setComponentLoading(item2.props.id);
1500
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1339
1501
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1340
1502
  item2,
1341
1503
  {
1342
1504
  changed,
1343
1505
  lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1344
1506
  permissions: initialPermissions,
1345
- appState,
1507
+ appState: makeStatePublic(appState),
1346
1508
  lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1347
1509
  }
1348
1510
  );
@@ -1360,7 +1522,7 @@ var createPermissionsSlice = (set, get) => {
1360
1522
  })
1361
1523
  })
1362
1524
  });
1363
- unsetComponentLoading(item2.props.id);
1525
+ clearTimeout2();
1364
1526
  }
1365
1527
  }
1366
1528
  });
@@ -1370,7 +1532,7 @@ var createPermissionsSlice = (set, get) => {
1370
1532
  // Shim the root data in by conforming to component data shape
1371
1533
  {
1372
1534
  type: "root",
1373
- props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
1535
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1374
1536
  },
1375
1537
  force2
1376
1538
  );
@@ -1385,7 +1547,6 @@ var createPermissionsSlice = (set, get) => {
1385
1547
  } else if (root) {
1386
1548
  resolveDataForRoot(force);
1387
1549
  } else {
1388
- resolveDataForRoot(force);
1389
1550
  flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1390
1551
  yield resolveDataForItem(item2, force);
1391
1552
  }));
@@ -1416,7 +1577,7 @@ var createPermissionsSlice = (set, get) => {
1416
1577
  } else if (root) {
1417
1578
  const rootConfig = config.root;
1418
1579
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1419
- const resolvedForItem = resolvedPermissions["puck-root"];
1580
+ const resolvedForItem = resolvedPermissions["root"];
1420
1581
  return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1421
1582
  }
1422
1583
  return globalPermissions;
@@ -1433,45 +1594,22 @@ var createFieldsSlice = (_set, _get) => {
1433
1594
  return {
1434
1595
  fields: {},
1435
1596
  loading: false,
1436
- lastResolvedData: {}
1597
+ lastResolvedData: {},
1598
+ id: void 0
1437
1599
  };
1438
1600
  };
1439
1601
 
1440
1602
  // ../core/lib/resolve-component-data.ts
1441
1603
  init_react_import();
1442
-
1443
- // ../core/lib/map-slots.ts
1444
- init_react_import();
1445
- function mapSlots(item, map, recursive = true, isSlot2) {
1446
- return __async(this, null, function* () {
1447
- const props = __spreadValues({}, item.props);
1448
- yield forEachSlot(
1449
- item,
1450
- (_parentId, propName, content) => __async(this, null, function* () {
1451
- const mappedContent = recursive ? yield Promise.all(
1452
- content.map((item2) => __async(this, null, function* () {
1453
- return yield mapSlots(item2, map, recursive, isSlot2);
1454
- }))
1455
- ) : content;
1456
- props[propName] = yield map(mappedContent, propName);
1457
- }),
1458
- false,
1459
- isSlot2
1460
- );
1461
- return __spreadProps(__spreadValues({}, item), { props });
1462
- });
1463
- }
1464
-
1465
- // ../core/lib/resolve-component-data.ts
1466
1604
  var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1467
1605
  var cache = { lastChange: {} };
1468
1606
  var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
1469
- const configForItem = "type" in item ? config.components[item.type] : config.root;
1607
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
1470
1608
  if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
1471
1609
  const id = "id" in item.props ? item.props.id : "root";
1472
1610
  const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1473
- if (item && item === oldItem) {
1474
- return resolved;
1611
+ if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
1612
+ return { node: resolved, didChange: false };
1475
1613
  }
1476
1614
  const changed = getChanged(item, oldItem);
1477
1615
  if (onResolveStart) {
@@ -1480,30 +1618,35 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1480
1618
  const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1481
1619
  changed,
1482
1620
  lastData: oldItem,
1483
- metadata,
1621
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1484
1622
  trigger
1485
1623
  });
1486
1624
  let resolvedItem = __spreadProps(__spreadValues({}, item), {
1487
1625
  props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1488
1626
  });
1489
1627
  if (recursive) {
1490
- resolvedItem = yield mapSlots(resolvedItem, (content) => __async(void 0, null, function* () {
1491
- return Promise.all(
1492
- content.map(
1493
- (childItem) => __async(void 0, null, function* () {
1494
- return (yield resolveComponentData(
1495
- childItem,
1496
- config,
1497
- metadata,
1498
- onResolveStart,
1499
- onResolveEnd,
1500
- trigger,
1501
- false
1502
- )).node;
1503
- })
1504
- )
1505
- );
1506
- }));
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
+ );
1507
1650
  }
1508
1651
  if (Object.keys(readOnly).length) {
1509
1652
  resolvedItem.readOnly = readOnly;
@@ -1520,7 +1663,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1520
1663
  return { node: item, didChange: false };
1521
1664
  });
1522
1665
 
1523
- // ../core/lib/to-root.ts
1666
+ // ../core/lib/data/to-root.ts
1524
1667
  init_react_import();
1525
1668
  var toRoot = (item) => {
1526
1669
  if ("type" in item && item.type !== "root") {
@@ -1567,172 +1710,176 @@ var defaultPageFields = {
1567
1710
  title: { type: "text" }
1568
1711
  };
1569
1712
  var createAppStore = (initialAppStore) => create()(
1570
- subscribeWithSelector((set, get) => __spreadProps(__spreadValues({
1571
- state: defaultAppState,
1572
- config: { components: {} },
1573
- componentState: {},
1574
- plugins: [],
1575
- overrides: {},
1576
- viewports: defaultViewports,
1577
- zoomConfig: {
1578
- autoZoom: 1,
1579
- rootHeight: 0,
1580
- zoom: 1
1581
- },
1582
- status: "LOADING",
1583
- iframe: {},
1584
- metadata: {}
1585
- }, initialAppStore), {
1586
- fields: createFieldsSlice(set, get),
1587
- history: createHistorySlice(set, get),
1588
- nodes: createNodesSlice(set, get),
1589
- permissions: createPermissionsSlice(set, get),
1590
- getComponentConfig: (type) => {
1591
- var _a;
1592
- const { config, selectedItem } = get();
1593
- const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1594
- return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1595
- },
1596
- dispatch: (action) => set((s) => {
1597
- var _a, _b;
1598
- const { record } = get().history;
1599
- const dispatch = createReducer({
1600
- record,
1601
- appStore: s
1602
- });
1603
- const state = dispatch(s.state, action);
1604
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1605
- (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1606
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1607
- }),
1608
- setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1609
- setStatus: (status) => set({ status }),
1610
- setComponentState: (componentState) => set({ componentState }),
1611
- pendingComponentLoads: {},
1612
- setComponentLoading: (id, loading = true, defer = 0) => {
1613
- const { setComponentState, pendingComponentLoads } = get();
1614
- const thisPendingComponentLoads = __spreadValues({}, pendingComponentLoads);
1615
- const setLoading = () => {
1616
- var _a;
1617
- const { componentState } = get();
1618
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1619
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1620
- loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1621
- })
1622
- }));
1623
- };
1624
- const unsetLoading = () => {
1625
- var _a;
1626
- const { componentState } = get();
1627
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1628
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1629
- loadingCount: Math.max(
1630
- (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1631
- 0
1632
- )
1713
+ subscribeWithSelector((set, get) => {
1714
+ var _a, _b;
1715
+ return __spreadProps(__spreadValues({
1716
+ state: defaultAppState,
1717
+ config: { components: {} },
1718
+ componentState: {},
1719
+ plugins: [],
1720
+ overrides: {},
1721
+ viewports: defaultViewports,
1722
+ zoomConfig: {
1723
+ autoZoom: 1,
1724
+ rootHeight: 0,
1725
+ zoom: 1
1726
+ },
1727
+ status: "LOADING",
1728
+ iframe: {},
1729
+ metadata: {}
1730
+ }, initialAppStore), {
1731
+ fields: createFieldsSlice(set, get),
1732
+ history: createHistorySlice(set, get),
1733
+ nodes: createNodesSlice(set, get),
1734
+ permissions: createPermissionsSlice(set, get),
1735
+ getComponentConfig: (type) => {
1736
+ var _a2;
1737
+ const { config, selectedItem } = get();
1738
+ const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
1739
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1740
+ },
1741
+ selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
1742
+ (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
1743
+ initialAppStore.state
1744
+ ) : null,
1745
+ dispatch: (action) => set((s) => {
1746
+ var _a2, _b2;
1747
+ const { record } = get().history;
1748
+ const dispatch = createReducer({
1749
+ record,
1750
+ appStore: s
1751
+ });
1752
+ const state = dispatch(s.state, action);
1753
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1754
+ (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
1755
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1756
+ }),
1757
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1758
+ setStatus: (status) => set({ status }),
1759
+ setComponentState: (componentState) => set({ componentState }),
1760
+ pendingLoadTimeouts: {},
1761
+ setComponentLoading: (id, loading = true, defer = 0) => {
1762
+ const { setComponentState, pendingLoadTimeouts } = get();
1763
+ const loadId = generateId();
1764
+ const setLoading = () => {
1765
+ var _a2;
1766
+ const { componentState } = get();
1767
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1768
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1769
+ loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
1770
+ })
1771
+ }));
1772
+ };
1773
+ const unsetLoading = () => {
1774
+ var _a2;
1775
+ const { componentState } = get();
1776
+ clearTimeout(timeout);
1777
+ delete pendingLoadTimeouts[loadId];
1778
+ set({ pendingLoadTimeouts });
1779
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1780
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1781
+ loadingCount: Math.max(
1782
+ (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
1783
+ 0
1784
+ )
1785
+ })
1786
+ }));
1787
+ };
1788
+ const timeout = setTimeout(() => {
1789
+ if (loading) {
1790
+ setLoading();
1791
+ } else {
1792
+ unsetLoading();
1793
+ }
1794
+ delete pendingLoadTimeouts[loadId];
1795
+ set({ pendingLoadTimeouts });
1796
+ }, defer);
1797
+ set({
1798
+ pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
1799
+ [id]: timeout
1633
1800
  })
1634
- }));
1635
- };
1636
- if (thisPendingComponentLoads[id]) {
1637
- clearTimeout(thisPendingComponentLoads[id]);
1638
- delete thisPendingComponentLoads[id];
1639
- set({ pendingComponentLoads: thisPendingComponentLoads });
1640
- }
1641
- const timeout = setTimeout(() => {
1642
- if (loading) {
1643
- setLoading();
1644
- } else {
1645
- unsetLoading();
1646
- }
1647
- delete thisPendingComponentLoads[id];
1648
- set({ pendingComponentLoads: thisPendingComponentLoads });
1649
- }, defer);
1650
- set({
1651
- pendingComponentLoads: __spreadProps(__spreadValues({}, thisPendingComponentLoads), {
1652
- [id]: timeout
1653
- })
1654
- });
1655
- },
1656
- unsetComponentLoading: (id) => {
1657
- const { setComponentLoading } = get();
1658
- setComponentLoading(id, false);
1659
- },
1660
- // Helper
1661
- setUi: (ui, recordHistory) => set((s) => {
1662
- const dispatch = createReducer({
1663
- record: () => {
1664
- },
1665
- appStore: s
1666
- });
1667
- const state = dispatch(s.state, {
1668
- type: "setUi",
1669
- ui,
1670
- recordHistory
1671
- });
1672
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1673
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1674
- }),
1675
- // resolveDataRuns: 0,
1676
- // resolveData: (newAppState) =>
1677
- // set((s) => {
1678
- // resolveData(newAppState, get);
1679
- // return { ...s, resolveDataRuns: s.resolveDataRuns + 1 };
1680
- // }),
1681
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1682
- const { config, metadata, setComponentLoading } = get();
1683
- return yield resolveComponentData(
1684
- componentData,
1685
- config,
1686
- metadata,
1687
- (item) => setComponentLoading(
1688
- "id" in item.props ? item.props.id : "root",
1689
- true,
1690
- 50
1691
- ),
1692
- (item) => setComponentLoading(
1693
- "id" in item.props ? item.props.id : "root",
1694
- false,
1695
- 0
1696
- ),
1697
- trigger
1698
- );
1699
- }),
1700
- resolveAndCommitData: () => __async(void 0, null, function* () {
1701
- const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1702
- walkTree(
1703
- state,
1704
- config,
1705
- (content) => content,
1706
- (childItem) => {
1707
- resolveComponentData2(childItem, "load").then((resolved) => {
1708
- const { state: state2 } = get();
1709
- const node = state2.indexes.nodes[resolved.node.props.id];
1710
- if (node && resolved.didChange) {
1711
- if (resolved.node.props.id === "root") {
1712
- dispatch({
1713
- type: "replaceRoot",
1714
- root: toRoot(resolved.node)
1715
- });
1716
- } else {
1717
- const zoneCompound = `${node.parentId}:${node.zone}`;
1718
- const parentZone = state2.indexes.zones[zoneCompound];
1719
- const index = parentZone.contentIds.indexOf(
1720
- resolved.node.props.id
1721
- );
1722
- dispatch({
1723
- type: "replace",
1724
- data: resolved.node,
1725
- destinationIndex: index,
1726
- destinationZone: zoneCompound
1727
- });
1728
- }
1801
+ });
1802
+ return unsetLoading;
1803
+ },
1804
+ unsetComponentLoading: (id) => {
1805
+ const { setComponentLoading } = get();
1806
+ setComponentLoading(id, false);
1807
+ },
1808
+ // Helper
1809
+ setUi: (ui, recordHistory) => set((s) => {
1810
+ const dispatch = createReducer({
1811
+ record: () => {
1812
+ },
1813
+ appStore: s
1814
+ });
1815
+ const state = dispatch(s.state, {
1816
+ type: "setUi",
1817
+ ui,
1818
+ recordHistory
1819
+ });
1820
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1821
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1822
+ }),
1823
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1824
+ const { config, metadata, setComponentLoading, permissions } = get();
1825
+ const timeouts = {};
1826
+ return yield resolveComponentData(
1827
+ componentData,
1828
+ config,
1829
+ metadata,
1830
+ (item) => {
1831
+ const id = "id" in item.props ? item.props.id : "root";
1832
+ timeouts[id] = setComponentLoading(id, true, 50);
1833
+ },
1834
+ (item) => __async(void 0, null, function* () {
1835
+ const id = "id" in item.props ? item.props.id : "root";
1836
+ if ("type" in item) {
1837
+ yield permissions.refreshPermissions({ item });
1838
+ } else {
1839
+ yield permissions.refreshPermissions({ root: true });
1729
1840
  }
1730
- });
1731
- return childItem;
1732
- }
1733
- );
1734
- })
1735
- }))
1841
+ timeouts[id]();
1842
+ }),
1843
+ trigger
1844
+ );
1845
+ }),
1846
+ resolveAndCommitData: () => __async(void 0, null, function* () {
1847
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1848
+ walkAppState(
1849
+ state,
1850
+ config,
1851
+ (content) => content,
1852
+ (childItem) => {
1853
+ resolveComponentData2(childItem, "load").then((resolved) => {
1854
+ const { state: state2 } = get();
1855
+ const node = state2.indexes.nodes[resolved.node.props.id];
1856
+ if (node && resolved.didChange) {
1857
+ if (resolved.node.props.id === "root") {
1858
+ dispatch({
1859
+ type: "replaceRoot",
1860
+ root: toRoot(resolved.node)
1861
+ });
1862
+ } else {
1863
+ const zoneCompound = `${node.parentId}:${node.zone}`;
1864
+ const parentZone = state2.indexes.zones[zoneCompound];
1865
+ const index = parentZone.contentIds.indexOf(
1866
+ resolved.node.props.id
1867
+ );
1868
+ dispatch({
1869
+ type: "replace",
1870
+ data: resolved.node,
1871
+ destinationIndex: index,
1872
+ destinationZone: zoneCompound
1873
+ });
1874
+ }
1875
+ }
1876
+ });
1877
+ return childItem;
1878
+ }
1879
+ );
1880
+ })
1881
+ });
1882
+ })
1736
1883
  );
1737
1884
  var appStoreContext = (0, import_react9.createContext)(createAppStore());
1738
1885
  function useAppStore(selector) {
@@ -1794,10 +1941,10 @@ init_react_import();
1794
1941
  // ../core/lib/filter.ts
1795
1942
  init_react_import();
1796
1943
 
1797
- // ../core/lib/reorder.ts
1944
+ // ../core/lib/data/reorder.ts
1798
1945
  init_react_import();
1799
1946
 
1800
- // ../core/lib/replace.ts
1947
+ // ../core/lib/data/replace.ts
1801
1948
  init_react_import();
1802
1949
 
1803
1950
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
@@ -1983,15 +2130,37 @@ var HeadingAnalyzer = () => {
1983
2130
  const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
1984
2131
  (0, import_react11.useEffect)(() => {
1985
2132
  const frame = getFrame();
1986
- const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
1987
- if (!entry) return;
1988
- setHierarchy(buildHierarchy(entry));
1989
- const observer = new MutationObserver(() => {
2133
+ let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2134
+ const createHierarchy = () => {
1990
2135
  setHierarchy(buildHierarchy(entry));
2136
+ };
2137
+ const entryObserver = new MutationObserver(() => {
2138
+ createHierarchy();
2139
+ });
2140
+ const frameObserver = new MutationObserver(() => {
2141
+ entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2142
+ if (entry) {
2143
+ registerEntryObserver();
2144
+ frameObserver.disconnect();
2145
+ }
1991
2146
  });
1992
- observer.observe(entry, { subtree: true, childList: true });
2147
+ const registerEntryObserver = () => {
2148
+ if (!entry) return;
2149
+ entryObserver.observe(entry, { subtree: true, childList: true });
2150
+ };
2151
+ const registerFrameObserver = () => {
2152
+ if (!frame) return;
2153
+ frameObserver.observe(frame, { subtree: true, childList: true });
2154
+ };
2155
+ if (entry) {
2156
+ createHierarchy();
2157
+ registerEntryObserver();
2158
+ } else {
2159
+ registerFrameObserver();
2160
+ }
1993
2161
  return () => {
1994
- observer.disconnect();
2162
+ entryObserver.disconnect();
2163
+ frameObserver.disconnect();
1995
2164
  };
1996
2165
  }, [data]);
1997
2166
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [