@measured/puck-plugin-heading-analyzer 0.19.0-canary.1918ad70 → 0.19.0-canary.226c08da

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
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
-
448
- // ../../node_modules/uuid/dist/esm-node/v4.js
449
- init_react_import();
450
-
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
374
+ // ../core/lib/data/walk-app-state.ts
482
375
  init_react_import();
483
376
 
484
- // ../core/lib/for-each-slot.ts
377
+ // ../core/lib/data/for-each-slot.ts
485
378
  init_react_import();
486
379
 
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,16 +802,154 @@ function insertAction(state, action, config) {
745
802
  }
746
803
  return content;
747
804
  },
748
- (childItem) => {
749
- if (childItem.props.id === id || childItem.props.id === parentId) {
750
- return childItem;
751
- } else if (idsInPath.indexOf(childItem.props.id) > -1) {
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) {
752
923
  return childItem;
753
924
  }
754
925
  return null;
755
926
  }
756
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
+ });
757
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
758
953
  var moveAction = (state, action, appStore) => {
759
954
  if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
760
955
  return state;
@@ -766,7 +961,7 @@ var moveAction = (state, action, appStore) => {
766
961
  if (!item) return state;
767
962
  const idsInSourcePath = getIdsForParent(action.sourceZone, state);
768
963
  const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
769
- return walkTree(
964
+ return walkAppState(
770
965
  state,
771
966
  appStore.config,
772
967
  (content, zoneCompound) => {
@@ -783,233 +978,172 @@ var moveAction = (state, action, appStore) => {
783
978
  }
784
979
  return content;
785
980
  },
786
- (childItem) => {
981
+ (childItem, path) => {
787
982
  const [sourceZoneParent] = action.sourceZone.split(":");
788
983
  const [destinationZoneParent] = action.destinationZone.split(":");
789
984
  const childId = childItem.props.id;
790
- if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1) {
985
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
791
986
  return childItem;
792
987
  }
793
988
  return null;
794
989
  }
795
990
  );
796
991
  };
797
- var replaceAction = (state, action, appStore) => {
798
- const [parentId] = action.destinationZone.split(":");
799
- const idsInPath = getIdsForParent(action.destinationZone, state);
800
- 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(
801
1023
  state,
802
1024
  appStore.config,
803
- (content) => content,
804
- (childItem, path) => {
805
- const pathIds = path.map((p) => p.split(":")[0]);
806
- if (childItem.props.id === action.data.props.id) {
807
- return action.data;
808
- } else if (childItem.props.id === parentId) {
809
- return childItem;
810
- } else if (idsInPath.indexOf(childItem.props.id) > -1) {
811
- return childItem;
812
- } else if (pathIds.indexOf(action.data.props.id) > -1) {
813
- return childItem;
1025
+ (content, zoneCompound) => {
1026
+ if (zoneCompound === action.zone) {
1027
+ return remove(content, action.index);
814
1028
  }
815
- return null;
1029
+ return content;
816
1030
  }
817
1031
  );
818
- };
819
- var setAction = (state, action, appStore) => {
820
- if (typeof action.state === "object") {
821
- const newState = __spreadValues(__spreadValues({}, state), action.state);
822
- if (action.state.indexes) {
823
- console.warn(
824
- "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
825
- );
826
- 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];
827
1036
  }
828
- return walkTree(newState, appStore.config);
829
- }
830
- return __spreadValues(__spreadValues({}, state), action.state(state));
831
- };
832
- function reduce(state, action, appStore) {
833
- if (action.type === "set") {
834
- return setAction(state, action, appStore);
835
- }
836
- if (action.type === "insert") {
837
- return insertAction(state, action, appStore.config);
838
- }
839
- if (action.type === "replace") {
840
- return replaceAction(state, action, appStore);
841
- }
842
- if (action.type === "replaceRoot") {
843
- return walkTree(
844
- state,
845
- appStore.config,
846
- (content) => content,
847
- (childItem) => {
848
- if (childItem.props.id === "root") {
849
- return __spreadProps(__spreadValues({}, childItem), {
850
- props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
851
- readOnly: action.root.readOnly
852
- });
853
- }
854
- return childItem;
855
- }
856
- );
857
- }
858
- if (action.type === "duplicate") {
859
- const item = getItem(
860
- { index: action.sourceIndex, zone: action.sourceZone },
861
- state
862
- );
863
- const idsInPath = getIdsForParent(action.sourceZone, state);
864
- const newItem = __spreadProps(__spreadValues({}, item), {
865
- props: __spreadProps(__spreadValues({}, item.props), {
866
- id: generateId(item.type)
867
- })
868
- });
869
- const modified = walkTree(
870
- state,
871
- appStore.config,
872
- (content, zoneCompound) => {
873
- if (zoneCompound === action.sourceZone) {
874
- return insert(content, action.sourceIndex + 1, item);
875
- }
876
- return content;
877
- },
878
- (childItem, path, index) => {
879
- const zoneCompound = path[path.length - 1];
880
- const parents = path.map((p) => p.split(":")[0]);
881
- if (parents.indexOf(newItem.props.id) > -1) {
882
- return __spreadProps(__spreadValues({}, childItem), {
883
- props: __spreadProps(__spreadValues({}, childItem.props), {
884
- id: generateId(childItem.type)
885
- })
886
- });
887
- }
888
- if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
889
- return newItem;
890
- }
891
- const [sourceZoneParent] = action.sourceZone.split(":");
892
- if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
893
- return childItem;
894
- }
895
- return null;
896
- }
897
- );
898
- return __spreadProps(__spreadValues({}, modified), {
899
- ui: __spreadProps(__spreadValues({}, modified.ui), {
900
- itemSelector: {
901
- index: action.sourceIndex + 1,
902
- zone: action.sourceZone
903
- }
904
- })
905
- });
906
- }
907
- if (action.type === "reorder") {
908
- return moveAction(
909
- state,
910
- {
911
- type: "move",
912
- sourceIndex: action.sourceIndex,
913
- sourceZone: action.destinationZone,
914
- destinationIndex: action.destinationIndex,
915
- destinationZone: action.destinationZone
916
- },
917
- appStore
918
- );
919
- }
920
- if (action.type === "move") {
921
- return moveAction(state, action, appStore);
922
- }
923
- if (action.type === "remove") {
924
- const item = getItem({ index: action.index, zone: action.zone }, state);
925
- let deindexed = deindex(state, item);
926
- const [parentId] = action.zone.split(":");
927
- return walkTree(
928
- __spreadProps(__spreadValues({}, state), { indexes: deindexed }),
929
- appStore.config,
930
- (content, zoneCompound) => {
931
- if (zoneCompound === action.zone) {
932
- return remove(content, action.index);
933
- }
934
- return content;
935
- },
936
- (childItem, path) => {
937
- const parentIds = path.map((p) => p.split(":")[0]);
938
- if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
939
- return childItem;
940
- }
941
- return null;
942
- }
943
- );
944
- }
945
- if (action.type === "registerZone") {
946
- if (zoneCache[action.zone]) {
947
- return __spreadProps(__spreadValues({}, state), {
948
- data: __spreadProps(__spreadValues({}, state.data), {
949
- zones: __spreadProps(__spreadValues({}, state.data.zones), {
950
- [action.zone]: zoneCache[action.zone]
951
- })
952
- }),
953
- indexes: __spreadProps(__spreadValues({}, state.indexes), {
954
- zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
955
- [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
956
- contentIds: zoneCache[action.zone].map((item) => item.props.id),
957
- type: "dropzone"
958
- })
959
- })
960
- })
961
- });
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];
962
1042
  }
963
- 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;
964
1058
  }
965
- if (action.type === "unregisterZone") {
966
- const _zones = __spreadValues({}, state.data.zones || {});
967
- const zoneIndex = __spreadValues({}, state.indexes.zones || {});
968
- if (_zones[action.zone]) {
969
- zoneCache[action.zone] = _zones[action.zone];
970
- delete _zones[action.zone];
971
- }
972
- 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]) {
973
1070
  return __spreadProps(__spreadValues({}, state), {
974
1071
  data: __spreadProps(__spreadValues({}, state.data), {
975
- zones: _zones
1072
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
1073
+ [action.zone]: zoneCache[action.zone]
1074
+ })
976
1075
  }),
977
1076
  indexes: __spreadProps(__spreadValues({}, state.indexes), {
978
- 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
+ })
979
1083
  })
980
1084
  });
981
1085
  }
982
- if (action.type === "setData") {
983
- if (typeof action.data === "object") {
984
- console.warn(
985
- "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
986
- );
987
- return walkTree(
988
- __spreadProps(__spreadValues({}, state), {
989
- data: __spreadValues(__spreadValues({}, state.data), action.data)
990
- }),
991
- appStore.config
992
- );
993
- }
994
- 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(
995
1114
  __spreadProps(__spreadValues({}, state), {
996
- data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1115
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
997
1116
  }),
998
1117
  appStore.config
999
1118
  );
1000
1119
  }
1001
- if (action.type === "setUi") {
1002
- if (typeof action.ui === "object") {
1003
- return __spreadProps(__spreadValues({}, state), {
1004
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1005
- });
1006
- }
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") {
1007
1132
  return __spreadProps(__spreadValues({}, state), {
1008
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1133
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1009
1134
  });
1010
1135
  }
1011
- return state;
1012
- }
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
+ };
1013
1147
 
1014
1148
  // ../core/reducer/actions.tsx
1015
1149
  init_react_import();
@@ -1028,7 +1162,7 @@ function storeInterceptor(reducer, record, onAction) {
1028
1162
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1029
1163
  if (record) record(newAppState);
1030
1164
  }
1031
- onAction == null ? void 0 : onAction(action, newAppState, state);
1165
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1032
1166
  return newAppState;
1033
1167
  };
1034
1168
  }
@@ -1039,8 +1173,43 @@ function createReducer({
1039
1173
  }) {
1040
1174
  return storeInterceptor(
1041
1175
  (state, action) => {
1042
- const result = reduce(state, action, appStore);
1043
- 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;
1044
1213
  },
1045
1214
  record,
1046
1215
  onAction
@@ -1235,7 +1404,7 @@ var createHistorySlice = (set, get) => {
1235
1404
  const { dispatch, history } = get();
1236
1405
  dispatch({
1237
1406
  type: "set",
1238
- 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
1239
1408
  });
1240
1409
  set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1241
1410
  },
@@ -1284,11 +1453,11 @@ var createNodesSlice = (set, get) => ({
1284
1453
  init_react_import();
1285
1454
  var import_react7 = require("react");
1286
1455
 
1287
- // ../core/lib/flatten-data.ts
1456
+ // ../core/lib/data/flatten-data.ts
1288
1457
  init_react_import();
1289
1458
  var flattenData = (state, config) => {
1290
1459
  const data = [];
1291
- walkTree(
1460
+ walkAppState(
1292
1461
  state,
1293
1462
  config,
1294
1463
  (content) => content,
@@ -1319,12 +1488,7 @@ var createPermissionsSlice = (set, get) => {
1319
1488
  const { cache: cache2, globalPermissions } = permissions;
1320
1489
  const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1321
1490
  var _a, _b, _c;
1322
- const {
1323
- config: config2,
1324
- state: appState,
1325
- setComponentLoading,
1326
- unsetComponentLoading
1327
- } = get();
1491
+ const { config: config2, state: appState, setComponentLoading } = get();
1328
1492
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1329
1493
  if (!componentConfig) {
1330
1494
  return;
@@ -1333,14 +1497,14 @@ var createPermissionsSlice = (set, get) => {
1333
1497
  if (componentConfig.resolvePermissions) {
1334
1498
  const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1335
1499
  if (Object.values(changed).some((el) => el === true) || force2) {
1336
- setComponentLoading(item2.props.id);
1500
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1337
1501
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1338
1502
  item2,
1339
1503
  {
1340
1504
  changed,
1341
1505
  lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1342
1506
  permissions: initialPermissions,
1343
- appState,
1507
+ appState: makeStatePublic(appState),
1344
1508
  lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1345
1509
  }
1346
1510
  );
@@ -1358,7 +1522,7 @@ var createPermissionsSlice = (set, get) => {
1358
1522
  })
1359
1523
  })
1360
1524
  });
1361
- unsetComponentLoading(item2.props.id);
1525
+ clearTimeout2();
1362
1526
  }
1363
1527
  }
1364
1528
  });
@@ -1368,7 +1532,7 @@ var createPermissionsSlice = (set, get) => {
1368
1532
  // Shim the root data in by conforming to component data shape
1369
1533
  {
1370
1534
  type: "root",
1371
- props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
1535
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1372
1536
  },
1373
1537
  force2
1374
1538
  );
@@ -1383,7 +1547,6 @@ var createPermissionsSlice = (set, get) => {
1383
1547
  } else if (root) {
1384
1548
  resolveDataForRoot(force);
1385
1549
  } else {
1386
- resolveDataForRoot(force);
1387
1550
  flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1388
1551
  yield resolveDataForItem(item2, force);
1389
1552
  }));
@@ -1414,7 +1577,7 @@ var createPermissionsSlice = (set, get) => {
1414
1577
  } else if (root) {
1415
1578
  const rootConfig = config.root;
1416
1579
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1417
- const resolvedForItem = resolvedPermissions["puck-root"];
1580
+ const resolvedForItem = resolvedPermissions["root"];
1418
1581
  return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1419
1582
  }
1420
1583
  return globalPermissions;
@@ -1431,45 +1594,22 @@ var createFieldsSlice = (_set, _get) => {
1431
1594
  return {
1432
1595
  fields: {},
1433
1596
  loading: false,
1434
- lastResolvedData: {}
1597
+ lastResolvedData: {},
1598
+ id: void 0
1435
1599
  };
1436
1600
  };
1437
1601
 
1438
1602
  // ../core/lib/resolve-component-data.ts
1439
1603
  init_react_import();
1440
-
1441
- // ../core/lib/map-slots.ts
1442
- init_react_import();
1443
- function mapSlots(item, map, recursive = true, isSlot2) {
1444
- return __async(this, null, function* () {
1445
- const props = __spreadValues({}, item.props);
1446
- yield forEachSlot(
1447
- item,
1448
- (_parentId, propName, content) => __async(this, null, function* () {
1449
- const mappedContent = recursive ? yield Promise.all(
1450
- content.map((item2) => __async(this, null, function* () {
1451
- return yield mapSlots(item2, map, recursive, isSlot2);
1452
- }))
1453
- ) : content;
1454
- props[propName] = yield map(mappedContent, propName);
1455
- }),
1456
- false,
1457
- isSlot2
1458
- );
1459
- return __spreadProps(__spreadValues({}, item), { props });
1460
- });
1461
- }
1462
-
1463
- // ../core/lib/resolve-component-data.ts
1464
1604
  var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1465
1605
  var cache = { lastChange: {} };
1466
1606
  var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
1467
- 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;
1468
1608
  if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
1469
1609
  const id = "id" in item.props ? item.props.id : "root";
1470
1610
  const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1471
- if (item && item === oldItem) {
1472
- return resolved;
1611
+ if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
1612
+ return { node: resolved, didChange: false };
1473
1613
  }
1474
1614
  const changed = getChanged(item, oldItem);
1475
1615
  if (onResolveStart) {
@@ -1478,30 +1618,35 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1478
1618
  const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1479
1619
  changed,
1480
1620
  lastData: oldItem,
1481
- metadata,
1621
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1482
1622
  trigger
1483
1623
  });
1484
1624
  let resolvedItem = __spreadProps(__spreadValues({}, item), {
1485
1625
  props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1486
1626
  });
1487
1627
  if (recursive) {
1488
- resolvedItem = yield mapSlots(resolvedItem, (content) => __async(void 0, null, function* () {
1489
- return Promise.all(
1490
- content.map(
1491
- (childItem) => __async(void 0, null, function* () {
1492
- return (yield resolveComponentData(
1493
- childItem,
1494
- config,
1495
- metadata,
1496
- onResolveStart,
1497
- onResolveEnd,
1498
- trigger,
1499
- false
1500
- )).node;
1501
- })
1502
- )
1503
- );
1504
- }));
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
+ );
1505
1650
  }
1506
1651
  if (Object.keys(readOnly).length) {
1507
1652
  resolvedItem.readOnly = readOnly;
@@ -1518,7 +1663,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1518
1663
  return { node: item, didChange: false };
1519
1664
  });
1520
1665
 
1521
- // ../core/lib/to-root.ts
1666
+ // ../core/lib/data/to-root.ts
1522
1667
  init_react_import();
1523
1668
  var toRoot = (item) => {
1524
1669
  if ("type" in item && item.type !== "root") {
@@ -1565,172 +1710,176 @@ var defaultPageFields = {
1565
1710
  title: { type: "text" }
1566
1711
  };
1567
1712
  var createAppStore = (initialAppStore) => create()(
1568
- subscribeWithSelector((set, get) => __spreadProps(__spreadValues({
1569
- state: defaultAppState,
1570
- config: { components: {} },
1571
- componentState: {},
1572
- plugins: [],
1573
- overrides: {},
1574
- viewports: defaultViewports,
1575
- zoomConfig: {
1576
- autoZoom: 1,
1577
- rootHeight: 0,
1578
- zoom: 1
1579
- },
1580
- status: "LOADING",
1581
- iframe: {},
1582
- metadata: {}
1583
- }, initialAppStore), {
1584
- fields: createFieldsSlice(set, get),
1585
- history: createHistorySlice(set, get),
1586
- nodes: createNodesSlice(set, get),
1587
- permissions: createPermissionsSlice(set, get),
1588
- getComponentConfig: (type) => {
1589
- var _a;
1590
- const { config, selectedItem } = get();
1591
- const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1592
- return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1593
- },
1594
- dispatch: (action) => set((s) => {
1595
- var _a, _b;
1596
- const { record } = get().history;
1597
- const dispatch = createReducer({
1598
- record,
1599
- appStore: s
1600
- });
1601
- const state = dispatch(s.state, action);
1602
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1603
- (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1604
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1605
- }),
1606
- setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1607
- setStatus: (status) => set({ status }),
1608
- setComponentState: (componentState) => set({ componentState }),
1609
- pendingComponentLoads: {},
1610
- setComponentLoading: (id, loading = true, defer = 0) => {
1611
- const { setComponentState, pendingComponentLoads } = get();
1612
- const thisPendingComponentLoads = __spreadValues({}, pendingComponentLoads);
1613
- const setLoading = () => {
1614
- var _a;
1615
- const { componentState } = get();
1616
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1617
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1618
- loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1619
- })
1620
- }));
1621
- };
1622
- const unsetLoading = () => {
1623
- var _a;
1624
- const { componentState } = get();
1625
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1626
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1627
- loadingCount: Math.max(
1628
- (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1629
- 0
1630
- )
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
1631
1800
  })
1632
- }));
1633
- };
1634
- if (thisPendingComponentLoads[id]) {
1635
- clearTimeout(thisPendingComponentLoads[id]);
1636
- delete thisPendingComponentLoads[id];
1637
- set({ pendingComponentLoads: thisPendingComponentLoads });
1638
- }
1639
- const timeout = setTimeout(() => {
1640
- if (loading) {
1641
- setLoading();
1642
- } else {
1643
- unsetLoading();
1644
- }
1645
- delete thisPendingComponentLoads[id];
1646
- set({ pendingComponentLoads: thisPendingComponentLoads });
1647
- }, defer);
1648
- set({
1649
- pendingComponentLoads: __spreadProps(__spreadValues({}, thisPendingComponentLoads), {
1650
- [id]: timeout
1651
- })
1652
- });
1653
- },
1654
- unsetComponentLoading: (id) => {
1655
- const { setComponentLoading } = get();
1656
- setComponentLoading(id, false);
1657
- },
1658
- // Helper
1659
- setUi: (ui, recordHistory) => set((s) => {
1660
- const dispatch = createReducer({
1661
- record: () => {
1662
- },
1663
- appStore: s
1664
- });
1665
- const state = dispatch(s.state, {
1666
- type: "setUi",
1667
- ui,
1668
- recordHistory
1669
- });
1670
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1671
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1672
- }),
1673
- // resolveDataRuns: 0,
1674
- // resolveData: (newAppState) =>
1675
- // set((s) => {
1676
- // resolveData(newAppState, get);
1677
- // return { ...s, resolveDataRuns: s.resolveDataRuns + 1 };
1678
- // }),
1679
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1680
- const { config, metadata, setComponentLoading } = get();
1681
- return yield resolveComponentData(
1682
- componentData,
1683
- config,
1684
- metadata,
1685
- (item) => setComponentLoading(
1686
- "id" in item.props ? item.props.id : "root",
1687
- true,
1688
- 50
1689
- ),
1690
- (item) => setComponentLoading(
1691
- "id" in item.props ? item.props.id : "root",
1692
- false,
1693
- 0
1694
- ),
1695
- trigger
1696
- );
1697
- }),
1698
- resolveAndCommitData: () => __async(void 0, null, function* () {
1699
- const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1700
- walkTree(
1701
- state,
1702
- config,
1703
- (content) => content,
1704
- (childItem) => {
1705
- resolveComponentData2(childItem, "load").then((resolved) => {
1706
- const { state: state2 } = get();
1707
- const node = state2.indexes.nodes[resolved.node.props.id];
1708
- if (node && resolved.didChange) {
1709
- if (resolved.node.props.id === "root") {
1710
- dispatch({
1711
- type: "replaceRoot",
1712
- root: toRoot(resolved.node)
1713
- });
1714
- } else {
1715
- const zoneCompound = `${node.parentId}:${node.zone}`;
1716
- const parentZone = state2.indexes.zones[zoneCompound];
1717
- const index = parentZone.contentIds.indexOf(
1718
- resolved.node.props.id
1719
- );
1720
- dispatch({
1721
- type: "replace",
1722
- data: resolved.node,
1723
- destinationIndex: index,
1724
- destinationZone: zoneCompound
1725
- });
1726
- }
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 });
1727
1840
  }
1728
- });
1729
- return childItem;
1730
- }
1731
- );
1732
- })
1733
- }))
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
+ })
1734
1883
  );
1735
1884
  var appStoreContext = (0, import_react9.createContext)(createAppStore());
1736
1885
  function useAppStore(selector) {
@@ -1792,10 +1941,10 @@ init_react_import();
1792
1941
  // ../core/lib/filter.ts
1793
1942
  init_react_import();
1794
1943
 
1795
- // ../core/lib/reorder.ts
1944
+ // ../core/lib/data/reorder.ts
1796
1945
  init_react_import();
1797
1946
 
1798
- // ../core/lib/replace.ts
1947
+ // ../core/lib/data/replace.ts
1799
1948
  init_react_import();
1800
1949
 
1801
1950
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
@@ -1981,15 +2130,37 @@ var HeadingAnalyzer = () => {
1981
2130
  const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
1982
2131
  (0, import_react11.useEffect)(() => {
1983
2132
  const frame = getFrame();
1984
- const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
1985
- if (!entry) return;
1986
- setHierarchy(buildHierarchy(entry));
1987
- const observer = new MutationObserver(() => {
2133
+ let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2134
+ const createHierarchy = () => {
1988
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
+ }
1989
2146
  });
1990
- 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
+ }
1991
2161
  return () => {
1992
- observer.disconnect();
2162
+ entryObserver.disconnect();
2163
+ frameObserver.disconnect();
1993
2164
  };
1994
2165
  }, [data]);
1995
2166
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [