@measured/puck-plugin-heading-analyzer 0.19.0-canary.d9be813b → 0.19.0-canary.e52d3b85

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,140 +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/reorder.ts
374
+ // ../core/lib/data/walk-tree.ts
375
375
  init_react_import();
376
- var reorder = (list, startIndex, endIndex) => {
377
- const result = Array.from(list);
378
- const [removed] = result.splice(startIndex, 1);
379
- result.splice(endIndex, 0, removed);
380
- return result;
381
- };
382
-
383
- // ../core/lib/insert.ts
384
- init_react_import();
385
- var insert = (list, index, item) => {
386
- const result = Array.from(list || []);
387
- result.splice(index, 0, item);
388
- return result;
389
- };
390
-
391
- // ../core/lib/remove.ts
392
- init_react_import();
393
- var remove = (list, index) => {
394
- const result = Array.from(list);
395
- result.splice(index, 1);
396
- return result;
397
- };
398
-
399
- // ../core/lib/setup-zone.ts
400
- init_react_import();
401
-
402
- // ../core/lib/root-droppable-id.ts
403
- init_react_import();
404
- var rootAreaId = "root";
405
- var rootZone = "default-zone";
406
- var rootDroppableId = `${rootAreaId}:${rootZone}`;
407
-
408
- // ../core/lib/setup-zone.ts
409
- var setupZone = (data, zoneKey) => {
410
- if (zoneKey === rootDroppableId) {
411
- return data;
412
- }
413
- const newData = __spreadProps(__spreadValues({}, data), {
414
- zones: data.zones ? __spreadValues({}, data.zones) : {}
415
- });
416
- newData.zones[zoneKey] = newData.zones[zoneKey] || [];
417
- return newData;
418
- };
419
-
420
- // ../core/lib/get-item.ts
421
- init_react_import();
422
- function getItem(selector, state) {
423
- var _a, _b;
424
- const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
425
- return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
426
- }
427
-
428
- // ../core/lib/generate-id.ts
429
- init_react_import();
430
-
431
- // ../../node_modules/uuid/dist/esm-node/index.js
432
- init_react_import();
433
-
434
- // ../../node_modules/uuid/dist/esm-node/rng.js
435
- init_react_import();
436
- var import_crypto = __toESM(require("crypto"));
437
- var rnds8Pool = new Uint8Array(256);
438
- var poolPtr = rnds8Pool.length;
439
- function rng() {
440
- if (poolPtr > rnds8Pool.length - 16) {
441
- import_crypto.default.randomFillSync(rnds8Pool);
442
- poolPtr = 0;
443
- }
444
- return rnds8Pool.slice(poolPtr, poolPtr += 16);
445
- }
446
-
447
- // ../../node_modules/uuid/dist/esm-node/stringify.js
448
- init_react_import();
449
- var byteToHex = [];
450
- for (let i = 0; i < 256; ++i) {
451
- byteToHex.push((i + 256).toString(16).slice(1));
452
- }
453
- function unsafeStringify(arr, offset = 0) {
454
- 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]];
455
- }
456
-
457
- // ../../node_modules/uuid/dist/esm-node/v4.js
458
- init_react_import();
459
-
460
- // ../../node_modules/uuid/dist/esm-node/native.js
461
- init_react_import();
462
- var import_crypto2 = __toESM(require("crypto"));
463
- var native_default = {
464
- randomUUID: import_crypto2.default.randomUUID
465
- };
466
376
 
467
- // ../../node_modules/uuid/dist/esm-node/v4.js
468
- function v4(options, buf, offset) {
469
- if (native_default.randomUUID && !buf && !options) {
470
- return native_default.randomUUID();
471
- }
472
- options = options || {};
473
- const rnds = options.random || (options.rng || rng)();
474
- rnds[6] = rnds[6] & 15 | 64;
475
- rnds[8] = rnds[8] & 63 | 128;
476
- if (buf) {
477
- offset = offset || 0;
478
- for (let i = 0; i < 16; ++i) {
479
- buf[offset + i] = rnds[i];
480
- }
481
- return buf;
482
- }
483
- return unsafeStringify(rnds);
484
- }
485
- var v4_default = v4;
486
-
487
- // ../core/lib/generate-id.ts
488
- var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
489
-
490
- // ../core/lib/walk-tree.ts
377
+ // ../core/lib/data/for-each-slot.ts
491
378
  init_react_import();
492
379
 
493
- // ../core/lib/for-each-slot.ts
494
- init_react_import();
495
-
496
- // ../core/lib/is-slot.ts
380
+ // ../core/lib/data/is-slot.ts
497
381
  init_react_import();
498
382
  var isSlot = (prop) => {
499
383
  var _a, _b;
500
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";
501
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
+ };
502
392
 
503
- // ../core/lib/for-each-slot.ts
504
- 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) => {
505
395
  const props = item.props || {};
506
396
  const propKeys = Object.keys(props);
507
397
  for (let i = 0; i < propKeys.length; i++) {
@@ -509,23 +399,31 @@ var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function*
509
399
  const itemType = "type" in item ? item.type : "root";
510
400
  if (isSlot2(itemType, propKey, props[propKey])) {
511
401
  const content = props[propKey];
512
- yield cb(props.id, propKey, content);
402
+ cb(props.id, propKey, content);
513
403
  if (recursive) {
514
404
  content.forEach(
515
405
  (childItem) => __async(void 0, null, function* () {
516
- return yield forEachSlot(childItem, cb, true, isSlot2);
406
+ return forEachSlot(childItem, cb, true, isSlot2);
517
407
  })
518
408
  );
519
409
  }
520
410
  }
521
411
  }
522
- });
412
+ };
523
413
 
524
- // ../core/lib/for-related-zones.ts
414
+ // ../core/lib/data/for-related-zones.ts
525
415
  init_react_import();
526
416
 
527
417
  // ../core/lib/get-zone-id.ts
528
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
529
427
  var getZoneId = (zoneCompound) => {
530
428
  if (!zoneCompound) {
531
429
  return [];
@@ -536,19 +434,17 @@ var getZoneId = (zoneCompound) => {
536
434
  return [rootDroppableId, zoneCompound];
537
435
  };
538
436
 
539
- // ../core/lib/for-related-zones.ts
437
+ // ../core/lib/data/for-related-zones.ts
540
438
  function forRelatedZones(item, data, cb, path = []) {
541
439
  Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
542
440
  const [parentId] = getZoneId(zoneCompound);
543
441
  if (parentId === item.props.id) {
544
- const newPath = [...path, zoneCompound];
545
- content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
546
442
  cb(path, zoneCompound, content);
547
443
  }
548
444
  });
549
445
  }
550
446
 
551
- // ../core/lib/strip-slots.ts
447
+ // ../core/lib/data/strip-slots.ts
552
448
  init_react_import();
553
449
  var stripSlots = (data) => {
554
450
  return __spreadProps(__spreadValues({}, data), {
@@ -564,7 +460,7 @@ var stripSlots = (data) => {
564
460
  });
565
461
  };
566
462
 
567
- // ../core/lib/walk-tree.ts
463
+ // ../core/lib/data/walk-tree.ts
568
464
  function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
569
465
  var _a;
570
466
  let newZones = {};
@@ -606,7 +502,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
606
502
  const mappedItem = mapNodeOrSkip(item, path, index);
607
503
  if (!mappedItem) return item;
608
504
  const id = mappedItem.props.id;
609
- processRelatedZones(item, id, path);
610
505
  const newProps = __spreadValues({}, mappedItem.props);
611
506
  forEachSlot(
612
507
  mappedItem,
@@ -622,13 +517,9 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
622
517
  newProps[slotId] = newContent2;
623
518
  },
624
519
  false,
625
- (itemType, propName, propValue) => {
626
- var _a2, _b;
627
- const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
628
- if (!configForComponent) return isSlot(propValue);
629
- return ((_b = (_a2 = configForComponent.fields) == null ? void 0 : _a2[propName]) == null ? void 0 : _b.type) === "slot";
630
- }
520
+ createIsSlotConfig(config)
631
521
  );
522
+ processRelatedZones(item, id, path);
632
523
  const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
633
524
  const thisZoneCompound = path[path.length - 1];
634
525
  const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
@@ -639,7 +530,7 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
639
530
  parentId,
640
531
  zone
641
532
  };
642
- const finalData = newItem;
533
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
643
534
  if (newProps.id === "root") {
644
535
  delete finalData["type"];
645
536
  delete finalData.props["id"];
@@ -654,8 +545,12 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
654
545
  "root"
655
546
  );
656
547
  const processedContent = newContent;
548
+ const zonesAlreadyProcessed = Object.keys(newZones);
657
549
  Object.keys(zones || {}).forEach((zoneCompound) => {
658
550
  const [parentId] = zoneCompound.split(":");
551
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
552
+ return;
553
+ }
659
554
  const [_2, newContent2] = processContent(
660
555
  [rootDroppableId],
661
556
  zoneCompound,
@@ -679,7 +574,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
679
574
  return __spreadProps(__spreadValues({}, state), {
680
575
  data: {
681
576
  root,
682
- // 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.
683
577
  content: processedContent,
684
578
  zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
685
579
  },
@@ -690,342 +584,467 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
690
584
  });
691
585
  }
692
586
 
693
- // ../core/lib/deindex.ts
694
- init_react_import();
695
- var deindex = (state, componentData) => {
696
- let zones = __spreadValues({}, state.indexes.zones);
697
- let nodes = __spreadValues({}, state.indexes.nodes);
698
- const dindexRelatedZones = (item) => {
699
- forRelatedZones(item, state.data, (_path, zoneCompound, content) => {
700
- content.forEach((subItem) => {
701
- dindexChildren(subItem);
702
- delete nodes[subItem.props.id];
703
- });
704
- delete zones[zoneCompound];
705
- });
706
- };
707
- const dindexChildren = (item) => {
708
- forEachSlot(
709
- item,
710
- (parentId, slotId, content) => {
711
- const zoneCompound = `${parentId}:${slotId}`;
712
- delete zones[zoneCompound];
713
- content.forEach((item2) => {
714
- dindexRelatedZones(item2);
715
- delete nodes[item2.props.id];
716
- });
717
- },
718
- 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."
719
596
  );
720
- };
721
- dindexRelatedZones(componentData);
722
- dindexChildren(componentData);
723
- delete nodes[componentData.props.id];
724
- return { nodes, zones };
597
+ return walkTree(newState, appStore.config);
598
+ }
599
+ return __spreadValues(__spreadValues({}, state), action.state(state));
725
600
  };
726
601
 
727
- // ../core/reducer/reduce.ts
728
- 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();
729
677
  var getIdsForParent = (zoneCompound, state) => {
730
678
  const [parentId] = zoneCompound.split(":");
731
679
  const node = state.indexes.nodes[parentId];
732
680
  return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
733
681
  };
734
- function insertAction(state, action, config) {
682
+
683
+ // ../core/reducer/actions/insert.ts
684
+ function insertAction(state, action, appStore) {
735
685
  const id = action.id || generateId(action.componentType);
736
686
  const emptyComponentData = {
737
687
  type: action.componentType,
738
- props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
688
+ props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
739
689
  id
740
690
  })
741
691
  };
742
692
  const [parentId] = action.destinationZone.split(":");
693
+ const idsInPath = getIdsForParent(action.destinationZone, state);
694
+ return walkTree(
695
+ state,
696
+ appStore.config,
697
+ (content, zoneCompound) => {
698
+ if (zoneCompound === action.destinationZone) {
699
+ return insert(
700
+ content || [],
701
+ action.destinationIndex,
702
+ emptyComponentData
703
+ );
704
+ }
705
+ return content;
706
+ },
707
+ (childItem, path) => {
708
+ if (childItem.props.id === id || childItem.props.id === parentId) {
709
+ return childItem;
710
+ } else if (idsInPath.includes(childItem.props.id)) {
711
+ return childItem;
712
+ } else if (path.includes(action.destinationZone)) {
713
+ return childItem;
714
+ }
715
+ return null;
716
+ }
717
+ );
718
+ }
719
+
720
+ // ../core/reducer/actions/replace.ts
721
+ init_react_import();
722
+ var replaceAction = (state, action, appStore) => {
723
+ const [parentId] = action.destinationZone.split(":");
724
+ const idsInPath = getIdsForParent(action.destinationZone, state);
725
+ const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
726
+ const idChanged = originalId !== action.data.props.id;
727
+ if (idChanged) {
728
+ throw new Error(
729
+ `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
730
+ );
731
+ }
732
+ return walkTree(
733
+ state,
734
+ appStore.config,
735
+ (content, zoneCompound) => {
736
+ const newContent = [...content];
737
+ if (zoneCompound === action.destinationZone) {
738
+ newContent[action.destinationIndex] = action.data;
739
+ }
740
+ return newContent;
741
+ },
742
+ (childItem, path) => {
743
+ const pathIds = path.map((p) => p.split(":")[0]);
744
+ if (childItem.props.id === action.data.props.id) {
745
+ return action.data;
746
+ } else if (childItem.props.id === parentId) {
747
+ return childItem;
748
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
749
+ return childItem;
750
+ } else if (pathIds.indexOf(action.data.props.id) > -1) {
751
+ return childItem;
752
+ }
753
+ return null;
754
+ }
755
+ );
756
+ };
757
+
758
+ // ../core/reducer/actions/replace-root.ts
759
+ init_react_import();
760
+ var replaceRootAction = (state, action, appStore) => {
761
+ return walkTree(
762
+ state,
763
+ appStore.config,
764
+ (content) => content,
765
+ (childItem) => {
766
+ if (childItem.props.id === "root") {
767
+ return __spreadProps(__spreadValues({}, childItem), {
768
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
769
+ readOnly: action.root.readOnly
770
+ });
771
+ }
772
+ return childItem;
773
+ }
774
+ );
775
+ };
776
+
777
+ // ../core/reducer/actions/duplicate.ts
778
+ init_react_import();
779
+
780
+ // ../core/lib/data/get-item.ts
781
+ init_react_import();
782
+ function getItem(selector, state) {
783
+ var _a, _b;
784
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
785
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
786
+ }
787
+
788
+ // ../core/reducer/actions/duplicate.ts
789
+ function duplicateAction(state, action, appStore) {
790
+ const item = getItem(
791
+ { index: action.sourceIndex, zone: action.sourceZone },
792
+ state
793
+ );
794
+ const idsInPath = getIdsForParent(action.sourceZone, state);
795
+ const newItem = __spreadProps(__spreadValues({}, item), {
796
+ props: __spreadProps(__spreadValues({}, item.props), {
797
+ id: generateId(item.type)
798
+ })
799
+ });
800
+ const modified = walkTree(
801
+ state,
802
+ appStore.config,
803
+ (content, zoneCompound) => {
804
+ if (zoneCompound === action.sourceZone) {
805
+ return insert(content, action.sourceIndex + 1, item);
806
+ }
807
+ return content;
808
+ },
809
+ (childItem, path, index) => {
810
+ const zoneCompound = path[path.length - 1];
811
+ const parents = path.map((p) => p.split(":")[0]);
812
+ if (parents.indexOf(newItem.props.id) > -1) {
813
+ return __spreadProps(__spreadValues({}, childItem), {
814
+ props: __spreadProps(__spreadValues({}, childItem.props), {
815
+ id: generateId(childItem.type)
816
+ })
817
+ });
818
+ }
819
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
820
+ return newItem;
821
+ }
822
+ const [sourceZoneParent] = action.sourceZone.split(":");
823
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
824
+ return childItem;
825
+ }
826
+ return null;
827
+ }
828
+ );
829
+ return __spreadProps(__spreadValues({}, modified), {
830
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
831
+ itemSelector: {
832
+ index: action.sourceIndex + 1,
833
+ zone: action.sourceZone
834
+ }
835
+ })
836
+ });
837
+ }
838
+
839
+ // ../core/reducer/actions/reorder.ts
840
+ init_react_import();
841
+
842
+ // ../core/reducer/actions/move.ts
843
+ init_react_import();
844
+
845
+ // ../core/lib/data/remove.ts
846
+ init_react_import();
847
+ var remove = (list, index) => {
848
+ const result = Array.from(list);
849
+ result.splice(index, 1);
850
+ return result;
851
+ };
852
+
853
+ // ../core/reducer/actions/move.ts
854
+ var moveAction = (state, action, appStore) => {
855
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
856
+ return state;
857
+ }
858
+ const item = getItem(
859
+ { zone: action.sourceZone, index: action.sourceIndex },
860
+ state
861
+ );
862
+ if (!item) return state;
863
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
864
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
743
865
  return walkTree(
744
866
  state,
745
- config,
867
+ appStore.config,
746
868
  (content, zoneCompound) => {
747
- if (zoneCompound === action.destinationZone) {
869
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
748
870
  return insert(
749
- content || [],
871
+ remove(content, action.sourceIndex),
750
872
  action.destinationIndex,
751
- emptyComponentData
873
+ item
752
874
  );
875
+ } else if (zoneCompound === action.sourceZone) {
876
+ return remove(content, action.sourceIndex);
877
+ } else if (zoneCompound === action.destinationZone) {
878
+ return insert(content, action.destinationIndex, item);
753
879
  }
754
880
  return content;
755
881
  },
756
- (childItem) => {
757
- if (childItem.props.id === id || childItem.props.id === parentId) {
882
+ (childItem, path) => {
883
+ const [sourceZoneParent] = action.sourceZone.split(":");
884
+ const [destinationZoneParent] = action.destinationZone.split(":");
885
+ const childId = childItem.props.id;
886
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
758
887
  return childItem;
759
888
  }
760
889
  return null;
761
890
  }
762
891
  );
763
- }
892
+ };
893
+
894
+ // ../core/reducer/actions/reorder.ts
764
895
  var reorderAction = (state, action, appStore) => {
765
- return walkTree(
896
+ return moveAction(
766
897
  state,
767
- appStore.config,
768
- (content, zoneCompound) => {
769
- if (zoneCompound === action.destinationZone) {
770
- return reorder(
771
- content || [],
772
- action.sourceIndex,
773
- action.destinationIndex
774
- );
775
- }
776
- return content;
898
+ {
899
+ type: "move",
900
+ sourceIndex: action.sourceIndex,
901
+ sourceZone: action.destinationZone,
902
+ destinationIndex: action.destinationIndex,
903
+ destinationZone: action.destinationZone
777
904
  },
778
- (childItem, path, index) => {
779
- const zoneCompound = path[path.length - 1];
780
- if (index === action.sourceIndex && zoneCompound === action.destinationZone || index === action.destinationIndex && zoneCompound === action.destinationZone) {
781
- return childItem;
782
- }
783
- return null;
784
- }
905
+ appStore
785
906
  );
786
907
  };
787
- var replaceAction = (state, action, appStore) => {
788
- const [parentId] = action.destinationZone.split(":");
789
- const idsInPath = getIdsForParent(action.destinationZone, state);
790
- return walkTree(
908
+
909
+ // ../core/reducer/actions/remove.ts
910
+ init_react_import();
911
+ var removeAction = (state, action, appStore) => {
912
+ const item = getItem({ index: action.index, zone: action.zone }, state);
913
+ const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
914
+ (acc, [nodeId, nodeData]) => {
915
+ const pathIds = nodeData.path.map((p) => p.split(":")[0]);
916
+ if (pathIds.includes(item.props.id)) {
917
+ return [...acc, nodeId];
918
+ }
919
+ return acc;
920
+ },
921
+ [item.props.id]
922
+ );
923
+ const newState = walkTree(
791
924
  state,
792
925
  appStore.config,
793
- (content) => content,
794
- (childItem, path) => {
795
- const pathIds = path.map((p) => p.split(":")[0]);
796
- if (childItem.props.id === action.data.props.id) {
797
- return action.data;
798
- } else if (childItem.props.id === parentId) {
799
- return childItem;
800
- } else if (idsInPath.indexOf(childItem.props.id) > -1) {
801
- return childItem;
802
- } else if (pathIds.indexOf(action.data.props.id) > -1) {
803
- return childItem;
926
+ (content, zoneCompound) => {
927
+ if (zoneCompound === action.zone) {
928
+ return remove(content, action.index);
804
929
  }
805
- return null;
930
+ return content;
806
931
  }
807
932
  );
808
- };
809
- var setAction = (state, action, appStore) => {
810
- if (typeof action.state === "object") {
811
- const newState = __spreadValues(__spreadValues({}, state), action.state);
812
- if (action.state.indexes) {
813
- console.warn(
814
- "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
815
- );
816
- return newState;
817
- }
818
- return walkTree(newState, appStore.config);
819
- }
820
- return __spreadValues(__spreadValues({}, state), action.state(state));
821
- };
822
- function reduce(state, action, appStore) {
823
- if (action.type === "set") {
824
- return setAction(state, action, appStore);
825
- }
826
- if (action.type === "insert") {
827
- return insertAction(state, action, appStore.config);
828
- }
829
- if (action.type === "replace") {
830
- return replaceAction(state, action, appStore);
831
- }
832
- if (action.type === "replaceRoot") {
833
- return walkTree(
834
- state,
835
- appStore.config,
836
- (content) => content,
837
- (childItem) => {
838
- if (childItem.props.id === "root") {
839
- return __spreadProps(__spreadValues({}, childItem), {
840
- props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
841
- readOnly: action.root.readOnly
842
- });
843
- }
844
- return childItem;
845
- }
846
- );
847
- }
848
- if (action.type === "duplicate") {
849
- const item = getItem(
850
- { index: action.sourceIndex, zone: action.sourceZone },
851
- state
852
- );
853
- const idsInPath = getIdsForParent(action.sourceZone, state);
854
- const newItem = __spreadProps(__spreadValues({}, item), {
855
- props: __spreadProps(__spreadValues({}, item.props), {
856
- id: generateId(item.type)
857
- })
858
- });
859
- const modified = walkTree(
860
- state,
861
- appStore.config,
862
- (content, zoneCompound) => {
863
- if (zoneCompound === action.sourceZone) {
864
- return insert(content, action.sourceIndex + 1, item);
865
- }
866
- return content;
867
- },
868
- (childItem, path, index) => {
869
- const zoneCompound = path[path.length - 1];
870
- const parents = path.map((p) => p.split(":")[0]);
871
- if (parents.indexOf(newItem.props.id) > -1) {
872
- return __spreadProps(__spreadValues({}, childItem), {
873
- props: __spreadProps(__spreadValues({}, childItem.props), {
874
- id: generateId(childItem.type)
875
- })
876
- });
877
- }
878
- if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
879
- return newItem;
880
- }
881
- const [sourceZoneParent] = action.sourceZone.split(":");
882
- if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
883
- return childItem;
884
- }
885
- return null;
886
- }
887
- );
888
- return __spreadProps(__spreadValues({}, modified), {
889
- ui: __spreadProps(__spreadValues({}, modified.ui), {
890
- itemSelector: {
891
- index: action.sourceIndex + 1,
892
- zone: action.sourceZone
893
- }
894
- })
895
- });
896
- }
897
- if (action.type === "reorder") {
898
- return reorderAction(state, action, appStore);
899
- }
900
- if (action.type === "move") {
901
- if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
902
- return state;
933
+ Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
934
+ const parentId = zoneCompound.split(":")[0];
935
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
936
+ delete newState.data.zones[zoneCompound];
903
937
  }
904
- const item = getItem(
905
- { zone: action.sourceZone, index: action.sourceIndex },
906
- state
907
- );
908
- if (!item) return state;
909
- const idsInSourcePath = getIdsForParent(action.sourceZone, state);
910
- const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
911
- return walkTree(
912
- state,
913
- appStore.config,
914
- (content, zoneCompound) => {
915
- if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
916
- return insert(
917
- remove(content, action.sourceIndex),
918
- action.destinationIndex,
919
- item
920
- );
921
- } else if (zoneCompound === action.sourceZone) {
922
- return remove(content, action.sourceIndex);
923
- } else if (zoneCompound === action.destinationZone) {
924
- return insert(content, action.destinationIndex, item);
925
- }
926
- return content;
927
- },
928
- (childItem) => {
929
- const [sourceZoneParent] = action.sourceZone.split(":");
930
- const [destinationZoneParent] = action.destinationZone.split(":");
931
- const childId = childItem.props.id;
932
- if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1) {
933
- return childItem;
934
- }
935
- return null;
936
- }
937
- );
938
- }
939
- if (action.type === "remove") {
940
- const item = getItem({ index: action.index, zone: action.zone }, state);
941
- let deindexed = deindex(state, item);
942
- const [parentId] = action.zone.split(":");
943
- return walkTree(
944
- __spreadProps(__spreadValues({}, state), { indexes: deindexed }),
945
- appStore.config,
946
- (content, zoneCompound) => {
947
- if (zoneCompound === action.zone) {
948
- return remove(content, action.index);
949
- }
950
- return content;
951
- },
952
- (childItem, path) => {
953
- const parentIds = path.map((p) => p.split(":")[0]);
954
- if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
955
- return childItem;
956
- }
957
- return null;
958
- }
959
- );
960
- }
961
- if (action.type === "registerZone") {
962
- if (zoneCache[action.zone]) {
963
- return __spreadProps(__spreadValues({}, state), {
964
- data: __spreadProps(__spreadValues({}, state.data), {
965
- zones: __spreadProps(__spreadValues({}, state.data.zones), {
966
- [action.zone]: zoneCache[action.zone]
967
- })
968
- }),
969
- indexes: __spreadProps(__spreadValues({}, state.indexes), {
970
- zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
971
- [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
972
- contentIds: zoneCache[action.zone].map((item) => item.props.id),
973
- type: "dropzone"
974
- })
975
- })
976
- })
977
- });
938
+ });
939
+ Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
940
+ const parentId = zoneCompound.split(":")[0];
941
+ if (nodesToDelete.includes(parentId)) {
942
+ delete newState.indexes.zones[zoneCompound];
978
943
  }
979
- return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
944
+ });
945
+ nodesToDelete.forEach((id) => {
946
+ delete newState.indexes.nodes[id];
947
+ });
948
+ return newState;
949
+ };
950
+
951
+ // ../core/reducer/actions/register-zone.ts
952
+ init_react_import();
953
+
954
+ // ../core/lib/data/setup-zone.ts
955
+ init_react_import();
956
+ var setupZone = (data, zoneKey) => {
957
+ if (zoneKey === rootDroppableId) {
958
+ return data;
980
959
  }
981
- if (action.type === "unregisterZone") {
982
- const _zones = __spreadValues({}, state.data.zones || {});
983
- const zoneIndex = __spreadValues({}, state.indexes.zones || {});
984
- if (_zones[action.zone]) {
985
- zoneCache[action.zone] = _zones[action.zone];
986
- delete _zones[action.zone];
987
- }
988
- delete zoneIndex[action.zone];
960
+ const newData = __spreadProps(__spreadValues({}, data), {
961
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
962
+ });
963
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
964
+ return newData;
965
+ };
966
+
967
+ // ../core/reducer/actions/register-zone.ts
968
+ var zoneCache = {};
969
+ function registerZoneAction(state, action) {
970
+ if (zoneCache[action.zone]) {
989
971
  return __spreadProps(__spreadValues({}, state), {
990
972
  data: __spreadProps(__spreadValues({}, state.data), {
991
- zones: _zones
973
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
974
+ [action.zone]: zoneCache[action.zone]
975
+ })
992
976
  }),
993
977
  indexes: __spreadProps(__spreadValues({}, state.indexes), {
994
- zones: zoneIndex
978
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
979
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
980
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
981
+ type: "dropzone"
982
+ })
983
+ })
995
984
  })
996
985
  });
997
986
  }
998
- if (action.type === "setData") {
999
- if (typeof action.data === "object") {
1000
- console.warn(
1001
- "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1002
- );
1003
- return walkTree(
1004
- __spreadProps(__spreadValues({}, state), {
1005
- data: __spreadValues(__spreadValues({}, state.data), action.data)
1006
- }),
1007
- appStore.config
1008
- );
1009
- }
987
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
988
+ }
989
+ function unregisterZoneAction(state, action) {
990
+ const _zones = __spreadValues({}, state.data.zones || {});
991
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
992
+ if (_zones[action.zone]) {
993
+ zoneCache[action.zone] = _zones[action.zone];
994
+ delete _zones[action.zone];
995
+ }
996
+ delete zoneIndex[action.zone];
997
+ return __spreadProps(__spreadValues({}, state), {
998
+ data: __spreadProps(__spreadValues({}, state.data), {
999
+ zones: _zones
1000
+ }),
1001
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1002
+ zones: zoneIndex
1003
+ })
1004
+ });
1005
+ }
1006
+
1007
+ // ../core/reducer/actions/set-data.ts
1008
+ init_react_import();
1009
+ var setDataAction = (state, action, appStore) => {
1010
+ if (typeof action.data === "object") {
1011
+ console.warn(
1012
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1013
+ );
1010
1014
  return walkTree(
1011
1015
  __spreadProps(__spreadValues({}, state), {
1012
- data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1016
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
1013
1017
  }),
1014
1018
  appStore.config
1015
1019
  );
1016
1020
  }
1017
- if (action.type === "setUi") {
1018
- if (typeof action.ui === "object") {
1019
- return __spreadProps(__spreadValues({}, state), {
1020
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1021
- });
1022
- }
1021
+ return walkTree(
1022
+ __spreadProps(__spreadValues({}, state), {
1023
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1024
+ }),
1025
+ appStore.config
1026
+ );
1027
+ };
1028
+
1029
+ // ../core/reducer/actions/set-ui.ts
1030
+ init_react_import();
1031
+ var setUiAction = (state, action) => {
1032
+ if (typeof action.ui === "object") {
1023
1033
  return __spreadProps(__spreadValues({}, state), {
1024
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1034
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1025
1035
  });
1026
1036
  }
1027
- return state;
1028
- }
1037
+ return __spreadProps(__spreadValues({}, state), {
1038
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1039
+ });
1040
+ };
1041
+
1042
+ // ../core/lib/data/make-state-public.ts
1043
+ init_react_import();
1044
+ var makeStatePublic = (state) => {
1045
+ const { data, ui } = state;
1046
+ return { data, ui };
1047
+ };
1029
1048
 
1030
1049
  // ../core/reducer/actions.tsx
1031
1050
  init_react_import();
@@ -1044,21 +1063,54 @@ function storeInterceptor(reducer, record, onAction) {
1044
1063
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1045
1064
  if (record) record(newAppState);
1046
1065
  }
1047
- onAction == null ? void 0 : onAction(action, newAppState, state);
1066
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1048
1067
  return newAppState;
1049
1068
  };
1050
1069
  }
1051
1070
  function createReducer({
1052
- config,
1053
1071
  record,
1054
1072
  onAction,
1055
1073
  appStore
1056
1074
  }) {
1057
1075
  return storeInterceptor(
1058
1076
  (state, action) => {
1059
- const result = reduce(state, action, appStore);
1060
- console.log(action.type, state, result);
1061
- return result;
1077
+ if (action.type === "set") {
1078
+ return setAction(state, action, appStore);
1079
+ }
1080
+ if (action.type === "insert") {
1081
+ return insertAction(state, action, appStore);
1082
+ }
1083
+ if (action.type === "replace") {
1084
+ return replaceAction(state, action, appStore);
1085
+ }
1086
+ if (action.type === "replaceRoot") {
1087
+ return replaceRootAction(state, action, appStore);
1088
+ }
1089
+ if (action.type === "duplicate") {
1090
+ return duplicateAction(state, action, appStore);
1091
+ }
1092
+ if (action.type === "reorder") {
1093
+ return reorderAction(state, action, appStore);
1094
+ }
1095
+ if (action.type === "move") {
1096
+ return moveAction(state, action, appStore);
1097
+ }
1098
+ if (action.type === "remove") {
1099
+ return removeAction(state, action, appStore);
1100
+ }
1101
+ if (action.type === "registerZone") {
1102
+ return registerZoneAction(state, action);
1103
+ }
1104
+ if (action.type === "unregisterZone") {
1105
+ return unregisterZoneAction(state, action);
1106
+ }
1107
+ if (action.type === "setData") {
1108
+ return setDataAction(state, action, appStore);
1109
+ }
1110
+ if (action.type === "setUi") {
1111
+ return setUiAction(state, action);
1112
+ }
1113
+ return state;
1062
1114
  },
1063
1115
  record,
1064
1116
  onAction
@@ -1253,7 +1305,7 @@ var createHistorySlice = (set, get) => {
1253
1305
  const { dispatch, history } = get();
1254
1306
  dispatch({
1255
1307
  type: "set",
1256
- state: ((_a = history.histories[history.index]) == null ? void 0 : _a.state) || history.initialAppState
1308
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1257
1309
  });
1258
1310
  set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1259
1311
  },
@@ -1302,7 +1354,7 @@ var createNodesSlice = (set, get) => ({
1302
1354
  init_react_import();
1303
1355
  var import_react7 = require("react");
1304
1356
 
1305
- // ../core/lib/flatten-data.ts
1357
+ // ../core/lib/data/flatten-data.ts
1306
1358
  init_react_import();
1307
1359
  var flattenData = (state, config) => {
1308
1360
  const data = [];
@@ -1337,12 +1389,7 @@ var createPermissionsSlice = (set, get) => {
1337
1389
  const { cache: cache2, globalPermissions } = permissions;
1338
1390
  const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1339
1391
  var _a, _b, _c;
1340
- const {
1341
- config: config2,
1342
- state: appState,
1343
- setComponentLoading,
1344
- unsetComponentLoading
1345
- } = get();
1392
+ const { config: config2, state: appState, setComponentLoading } = get();
1346
1393
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1347
1394
  if (!componentConfig) {
1348
1395
  return;
@@ -1351,14 +1398,14 @@ var createPermissionsSlice = (set, get) => {
1351
1398
  if (componentConfig.resolvePermissions) {
1352
1399
  const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1353
1400
  if (Object.values(changed).some((el) => el === true) || force2) {
1354
- setComponentLoading(item2.props.id);
1401
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1355
1402
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1356
1403
  item2,
1357
1404
  {
1358
1405
  changed,
1359
1406
  lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1360
1407
  permissions: initialPermissions,
1361
- appState,
1408
+ appState: makeStatePublic(appState),
1362
1409
  lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1363
1410
  }
1364
1411
  );
@@ -1376,7 +1423,7 @@ var createPermissionsSlice = (set, get) => {
1376
1423
  })
1377
1424
  })
1378
1425
  });
1379
- unsetComponentLoading(item2.props.id);
1426
+ clearTimeout2();
1380
1427
  }
1381
1428
  }
1382
1429
  });
@@ -1386,7 +1433,7 @@ var createPermissionsSlice = (set, get) => {
1386
1433
  // Shim the root data in by conforming to component data shape
1387
1434
  {
1388
1435
  type: "root",
1389
- props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
1436
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1390
1437
  },
1391
1438
  force2
1392
1439
  );
@@ -1401,7 +1448,6 @@ var createPermissionsSlice = (set, get) => {
1401
1448
  } else if (root) {
1402
1449
  resolveDataForRoot(force);
1403
1450
  } else {
1404
- resolveDataForRoot(force);
1405
1451
  flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1406
1452
  yield resolveDataForItem(item2, force);
1407
1453
  }));
@@ -1432,7 +1478,7 @@ var createPermissionsSlice = (set, get) => {
1432
1478
  } else if (root) {
1433
1479
  const rootConfig = config.root;
1434
1480
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1435
- const resolvedForItem = resolvedPermissions["puck-root"];
1481
+ const resolvedForItem = resolvedPermissions["root"];
1436
1482
  return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1437
1483
  }
1438
1484
  return globalPermissions;
@@ -1456,24 +1502,25 @@ var createFieldsSlice = (_set, _get) => {
1456
1502
  // ../core/lib/resolve-component-data.ts
1457
1503
  init_react_import();
1458
1504
 
1459
- // ../core/lib/map-slots.ts
1505
+ // ../core/lib/data/map-slots.ts
1460
1506
  init_react_import();
1461
- function mapSlots(item, map, recursive = true, isSlot2) {
1462
- return __async(this, null, function* () {
1507
+ function mapSlotsAsync(_0, _1) {
1508
+ return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
1463
1509
  const props = __spreadValues({}, item.props);
1464
- yield forEachSlot(
1465
- item,
1466
- (_parentId, propName, content) => __async(this, null, function* () {
1510
+ const propKeys = Object.keys(props);
1511
+ for (let i = 0; i < propKeys.length; i++) {
1512
+ const propKey = propKeys[i];
1513
+ const itemType = "type" in item ? item.type : "root";
1514
+ if (isSlot2(itemType, propKey, props[propKey])) {
1515
+ const content = props[propKey];
1467
1516
  const mappedContent = recursive ? yield Promise.all(
1468
1517
  content.map((item2) => __async(this, null, function* () {
1469
- return yield mapSlots(item2, map, recursive, isSlot2);
1518
+ return yield mapSlotsAsync(item2, map, recursive, isSlot2);
1470
1519
  }))
1471
1520
  ) : content;
1472
- props[propName] = yield map(mappedContent, propName);
1473
- }),
1474
- false,
1475
- isSlot2
1476
- );
1521
+ props[propKey] = yield map(mappedContent, propKey);
1522
+ }
1523
+ }
1477
1524
  return __spreadProps(__spreadValues({}, item), { props });
1478
1525
  });
1479
1526
  }
@@ -1482,12 +1529,12 @@ function mapSlots(item, map, recursive = true, isSlot2) {
1482
1529
  var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1483
1530
  var cache = { lastChange: {} };
1484
1531
  var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
1485
- const configForItem = "type" in item ? config.components[item.type] : config.root;
1532
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
1486
1533
  if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
1487
1534
  const id = "id" in item.props ? item.props.id : "root";
1488
1535
  const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1489
- if (item && item === oldItem) {
1490
- return resolved;
1536
+ if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
1537
+ return { node: resolved, didChange: false };
1491
1538
  }
1492
1539
  const changed = getChanged(item, oldItem);
1493
1540
  if (onResolveStart) {
@@ -1496,30 +1543,35 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1496
1543
  const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1497
1544
  changed,
1498
1545
  lastData: oldItem,
1499
- metadata,
1546
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1500
1547
  trigger
1501
1548
  });
1502
1549
  let resolvedItem = __spreadProps(__spreadValues({}, item), {
1503
1550
  props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1504
1551
  });
1505
1552
  if (recursive) {
1506
- resolvedItem = yield mapSlots(resolvedItem, (content) => __async(void 0, null, function* () {
1507
- return Promise.all(
1508
- content.map(
1509
- (childItem) => __async(void 0, null, function* () {
1510
- return (yield resolveComponentData(
1511
- childItem,
1512
- config,
1513
- metadata,
1514
- onResolveStart,
1515
- onResolveEnd,
1516
- trigger,
1517
- false
1518
- )).node;
1519
- })
1520
- )
1521
- );
1522
- }));
1553
+ resolvedItem = yield mapSlotsAsync(
1554
+ resolvedItem,
1555
+ (content) => __async(void 0, null, function* () {
1556
+ return Promise.all(
1557
+ content.map(
1558
+ (childItem) => __async(void 0, null, function* () {
1559
+ return (yield resolveComponentData(
1560
+ childItem,
1561
+ config,
1562
+ metadata,
1563
+ onResolveStart,
1564
+ onResolveEnd,
1565
+ trigger,
1566
+ false
1567
+ )).node;
1568
+ })
1569
+ )
1570
+ );
1571
+ }),
1572
+ false,
1573
+ createIsSlotConfig(config)
1574
+ );
1523
1575
  }
1524
1576
  if (Object.keys(readOnly).length) {
1525
1577
  resolvedItem.readOnly = readOnly;
@@ -1536,7 +1588,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1536
1588
  return { node: item, didChange: false };
1537
1589
  });
1538
1590
 
1539
- // ../core/lib/to-root.ts
1591
+ // ../core/lib/data/to-root.ts
1540
1592
  init_react_import();
1541
1593
  var toRoot = (item) => {
1542
1594
  if ("type" in item && item.type !== "root") {
@@ -1583,174 +1635,176 @@ var defaultPageFields = {
1583
1635
  title: { type: "text" }
1584
1636
  };
1585
1637
  var createAppStore = (initialAppStore) => create()(
1586
- subscribeWithSelector((set, get) => __spreadProps(__spreadValues({
1587
- state: defaultAppState,
1588
- config: { components: {} },
1589
- componentState: {},
1590
- plugins: [],
1591
- overrides: {},
1592
- viewports: defaultViewports,
1593
- zoomConfig: {
1594
- autoZoom: 1,
1595
- rootHeight: 0,
1596
- zoom: 1
1597
- },
1598
- status: "LOADING",
1599
- iframe: {},
1600
- metadata: {}
1601
- }, initialAppStore), {
1602
- fields: createFieldsSlice(set, get),
1603
- history: createHistorySlice(set, get),
1604
- nodes: createNodesSlice(set, get),
1605
- permissions: createPermissionsSlice(set, get),
1606
- getComponentConfig: (type) => {
1607
- var _a;
1608
- const { config, selectedItem } = get();
1609
- const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1610
- return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1611
- },
1612
- dispatch: (action) => set((s) => {
1613
- var _a, _b;
1614
- const { record } = get().history;
1615
- const dispatch = createReducer({
1616
- config: s.config,
1617
- record,
1618
- appStore: s
1619
- });
1620
- const state = dispatch(s.state, action);
1621
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1622
- (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1623
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1624
- }),
1625
- setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1626
- setStatus: (status) => set({ status }),
1627
- setComponentState: (componentState) => set({ componentState }),
1628
- pendingComponentLoads: {},
1629
- setComponentLoading: (id, loading = true, defer = 0) => {
1630
- const { setComponentState, pendingComponentLoads } = get();
1631
- const thisPendingComponentLoads = __spreadValues({}, pendingComponentLoads);
1632
- const setLoading = () => {
1633
- var _a;
1634
- const { componentState } = get();
1635
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1636
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1637
- loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1638
- })
1639
- }));
1640
- };
1641
- const unsetLoading = () => {
1642
- var _a;
1643
- const { componentState } = get();
1644
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1645
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1646
- loadingCount: Math.max(
1647
- (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1648
- 0
1649
- )
1638
+ subscribeWithSelector((set, get) => {
1639
+ var _a, _b;
1640
+ return __spreadProps(__spreadValues({
1641
+ state: defaultAppState,
1642
+ config: { components: {} },
1643
+ componentState: {},
1644
+ plugins: [],
1645
+ overrides: {},
1646
+ viewports: defaultViewports,
1647
+ zoomConfig: {
1648
+ autoZoom: 1,
1649
+ rootHeight: 0,
1650
+ zoom: 1
1651
+ },
1652
+ status: "LOADING",
1653
+ iframe: {},
1654
+ metadata: {}
1655
+ }, initialAppStore), {
1656
+ fields: createFieldsSlice(set, get),
1657
+ history: createHistorySlice(set, get),
1658
+ nodes: createNodesSlice(set, get),
1659
+ permissions: createPermissionsSlice(set, get),
1660
+ getComponentConfig: (type) => {
1661
+ var _a2;
1662
+ const { config, selectedItem } = get();
1663
+ const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
1664
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1665
+ },
1666
+ selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
1667
+ (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
1668
+ initialAppStore.state
1669
+ ) : null,
1670
+ dispatch: (action) => set((s) => {
1671
+ var _a2, _b2;
1672
+ const { record } = get().history;
1673
+ const dispatch = createReducer({
1674
+ record,
1675
+ appStore: s
1676
+ });
1677
+ const state = dispatch(s.state, action);
1678
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1679
+ (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
1680
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1681
+ }),
1682
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1683
+ setStatus: (status) => set({ status }),
1684
+ setComponentState: (componentState) => set({ componentState }),
1685
+ pendingLoadTimeouts: {},
1686
+ setComponentLoading: (id, loading = true, defer = 0) => {
1687
+ const { setComponentState, pendingLoadTimeouts } = get();
1688
+ const loadId = generateId();
1689
+ const setLoading = () => {
1690
+ var _a2;
1691
+ const { componentState } = get();
1692
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1693
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1694
+ loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
1695
+ })
1696
+ }));
1697
+ };
1698
+ const unsetLoading = () => {
1699
+ var _a2;
1700
+ const { componentState } = get();
1701
+ clearTimeout(timeout);
1702
+ delete pendingLoadTimeouts[loadId];
1703
+ set({ pendingLoadTimeouts });
1704
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1705
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1706
+ loadingCount: Math.max(
1707
+ (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
1708
+ 0
1709
+ )
1710
+ })
1711
+ }));
1712
+ };
1713
+ const timeout = setTimeout(() => {
1714
+ if (loading) {
1715
+ setLoading();
1716
+ } else {
1717
+ unsetLoading();
1718
+ }
1719
+ delete pendingLoadTimeouts[loadId];
1720
+ set({ pendingLoadTimeouts });
1721
+ }, defer);
1722
+ set({
1723
+ pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
1724
+ [id]: timeout
1650
1725
  })
1651
- }));
1652
- };
1653
- if (thisPendingComponentLoads[id]) {
1654
- clearTimeout(thisPendingComponentLoads[id]);
1655
- delete thisPendingComponentLoads[id];
1656
- set({ pendingComponentLoads: thisPendingComponentLoads });
1657
- }
1658
- const timeout = setTimeout(() => {
1659
- if (loading) {
1660
- setLoading();
1661
- } else {
1662
- unsetLoading();
1663
- }
1664
- delete thisPendingComponentLoads[id];
1665
- set({ pendingComponentLoads: thisPendingComponentLoads });
1666
- }, defer);
1667
- set({
1668
- pendingComponentLoads: __spreadProps(__spreadValues({}, thisPendingComponentLoads), {
1669
- [id]: timeout
1670
- })
1671
- });
1672
- },
1673
- unsetComponentLoading: (id) => {
1674
- const { setComponentLoading } = get();
1675
- setComponentLoading(id, false);
1676
- },
1677
- // Helper
1678
- setUi: (ui, recordHistory) => set((s) => {
1679
- const dispatch = createReducer({
1680
- config: s.config,
1681
- record: () => {
1682
- },
1683
- appStore: s
1684
- });
1685
- const state = dispatch(s.state, {
1686
- type: "setUi",
1687
- ui,
1688
- recordHistory
1689
- });
1690
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1691
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1692
- }),
1693
- // resolveDataRuns: 0,
1694
- // resolveData: (newAppState) =>
1695
- // set((s) => {
1696
- // resolveData(newAppState, get);
1697
- // return { ...s, resolveDataRuns: s.resolveDataRuns + 1 };
1698
- // }),
1699
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1700
- const { config, metadata, setComponentLoading } = get();
1701
- return yield resolveComponentData(
1702
- componentData,
1703
- config,
1704
- metadata,
1705
- (item) => setComponentLoading(
1706
- "id" in item.props ? item.props.id : "root",
1707
- true,
1708
- 50
1709
- ),
1710
- (item) => setComponentLoading(
1711
- "id" in item.props ? item.props.id : "root",
1712
- false,
1713
- 0
1714
- ),
1715
- trigger
1716
- );
1717
- }),
1718
- resolveAndCommitData: () => __async(void 0, null, function* () {
1719
- const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1720
- walkTree(
1721
- state,
1722
- config,
1723
- (content) => content,
1724
- (childItem) => {
1725
- resolveComponentData2(childItem, "load").then((resolved) => {
1726
- const { state: state2 } = get();
1727
- const node = state2.indexes.nodes[resolved.node.props.id];
1728
- if (node && resolved.didChange) {
1729
- if (resolved.node.props.id === "root") {
1730
- dispatch({
1731
- type: "replaceRoot",
1732
- root: toRoot(resolved.node)
1733
- });
1734
- } else {
1735
- const zoneCompound = `${node.parentId}:${node.zone}`;
1736
- const parentZone = state2.indexes.zones[zoneCompound];
1737
- const index = parentZone.contentIds.indexOf(
1738
- resolved.node.props.id
1739
- );
1740
- dispatch({
1741
- type: "replace",
1742
- data: resolved.node,
1743
- destinationIndex: index,
1744
- destinationZone: zoneCompound
1745
- });
1746
- }
1726
+ });
1727
+ return unsetLoading;
1728
+ },
1729
+ unsetComponentLoading: (id) => {
1730
+ const { setComponentLoading } = get();
1731
+ setComponentLoading(id, false);
1732
+ },
1733
+ // Helper
1734
+ setUi: (ui, recordHistory) => set((s) => {
1735
+ const dispatch = createReducer({
1736
+ record: () => {
1737
+ },
1738
+ appStore: s
1739
+ });
1740
+ const state = dispatch(s.state, {
1741
+ type: "setUi",
1742
+ ui,
1743
+ recordHistory
1744
+ });
1745
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1746
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1747
+ }),
1748
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1749
+ const { config, metadata, setComponentLoading, permissions } = get();
1750
+ const timeouts = {};
1751
+ return yield resolveComponentData(
1752
+ componentData,
1753
+ config,
1754
+ metadata,
1755
+ (item) => {
1756
+ const id = "id" in item.props ? item.props.id : "root";
1757
+ timeouts[id] = setComponentLoading(id, true, 50);
1758
+ },
1759
+ (item) => __async(void 0, null, function* () {
1760
+ const id = "id" in item.props ? item.props.id : "root";
1761
+ if ("type" in item) {
1762
+ yield permissions.refreshPermissions({ item });
1763
+ } else {
1764
+ yield permissions.refreshPermissions({ root: true });
1747
1765
  }
1748
- });
1749
- return childItem;
1750
- }
1751
- );
1752
- })
1753
- }))
1766
+ timeouts[id]();
1767
+ }),
1768
+ trigger
1769
+ );
1770
+ }),
1771
+ resolveAndCommitData: () => __async(void 0, null, function* () {
1772
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1773
+ walkTree(
1774
+ state,
1775
+ config,
1776
+ (content) => content,
1777
+ (childItem) => {
1778
+ resolveComponentData2(childItem, "load").then((resolved) => {
1779
+ const { state: state2 } = get();
1780
+ const node = state2.indexes.nodes[resolved.node.props.id];
1781
+ if (node && resolved.didChange) {
1782
+ if (resolved.node.props.id === "root") {
1783
+ dispatch({
1784
+ type: "replaceRoot",
1785
+ root: toRoot(resolved.node)
1786
+ });
1787
+ } else {
1788
+ const zoneCompound = `${node.parentId}:${node.zone}`;
1789
+ const parentZone = state2.indexes.zones[zoneCompound];
1790
+ const index = parentZone.contentIds.indexOf(
1791
+ resolved.node.props.id
1792
+ );
1793
+ dispatch({
1794
+ type: "replace",
1795
+ data: resolved.node,
1796
+ destinationIndex: index,
1797
+ destinationZone: zoneCompound
1798
+ });
1799
+ }
1800
+ }
1801
+ });
1802
+ return childItem;
1803
+ }
1804
+ );
1805
+ })
1806
+ });
1807
+ })
1754
1808
  );
1755
1809
  var appStoreContext = (0, import_react9.createContext)(createAppStore());
1756
1810
  function useAppStore(selector) {
@@ -1812,7 +1866,10 @@ init_react_import();
1812
1866
  // ../core/lib/filter.ts
1813
1867
  init_react_import();
1814
1868
 
1815
- // ../core/lib/replace.ts
1869
+ // ../core/lib/data/reorder.ts
1870
+ init_react_import();
1871
+
1872
+ // ../core/lib/data/replace.ts
1816
1873
  init_react_import();
1817
1874
 
1818
1875
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
@@ -1998,15 +2055,37 @@ var HeadingAnalyzer = () => {
1998
2055
  const [hierarchy, setHierarchy] = (0, import_react11.useState)([]);
1999
2056
  (0, import_react11.useEffect)(() => {
2000
2057
  const frame = getFrame();
2001
- const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2002
- if (!entry) return;
2003
- setHierarchy(buildHierarchy(entry));
2004
- const observer = new MutationObserver(() => {
2058
+ let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2059
+ const createHierarchy = () => {
2005
2060
  setHierarchy(buildHierarchy(entry));
2061
+ };
2062
+ const entryObserver = new MutationObserver(() => {
2063
+ createHierarchy();
2064
+ });
2065
+ const frameObserver = new MutationObserver(() => {
2066
+ entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2067
+ if (entry) {
2068
+ registerEntryObserver();
2069
+ frameObserver.disconnect();
2070
+ }
2006
2071
  });
2007
- observer.observe(entry, { subtree: true, childList: true });
2072
+ const registerEntryObserver = () => {
2073
+ if (!entry) return;
2074
+ entryObserver.observe(entry, { subtree: true, childList: true });
2075
+ };
2076
+ const registerFrameObserver = () => {
2077
+ if (!frame) return;
2078
+ frameObserver.observe(frame, { subtree: true, childList: true });
2079
+ };
2080
+ if (entry) {
2081
+ createHierarchy();
2082
+ registerEntryObserver();
2083
+ } else {
2084
+ registerFrameObserver();
2085
+ }
2008
2086
  return () => {
2009
- observer.disconnect();
2087
+ entryObserver.disconnect();
2088
+ frameObserver.disconnect();
2010
2089
  };
2011
2090
  }, [data]);
2012
2091
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: getClassName5(), children: [