@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.mjs CHANGED
@@ -356,131 +356,30 @@ init_react_import();
356
356
  // ../core/reducer/index.ts
357
357
  init_react_import();
358
358
 
359
- // ../core/reducer/reduce.ts
359
+ // ../core/reducer/actions/set.ts
360
360
  init_react_import();
361
361
 
362
- // ../core/lib/insert.ts
363
- init_react_import();
364
- var insert = (list, index, item) => {
365
- const result = Array.from(list || []);
366
- result.splice(index, 0, item);
367
- return result;
368
- };
369
-
370
- // ../core/lib/remove.ts
371
- init_react_import();
372
- var remove = (list, index) => {
373
- const result = Array.from(list);
374
- result.splice(index, 1);
375
- return result;
376
- };
377
-
378
- // ../core/lib/setup-zone.ts
379
- init_react_import();
380
-
381
- // ../core/lib/root-droppable-id.ts
382
- init_react_import();
383
- var rootAreaId = "root";
384
- var rootZone = "default-zone";
385
- var rootDroppableId = `${rootAreaId}:${rootZone}`;
386
-
387
- // ../core/lib/setup-zone.ts
388
- var setupZone = (data, zoneKey) => {
389
- if (zoneKey === rootDroppableId) {
390
- return data;
391
- }
392
- const newData = __spreadProps(__spreadValues({}, data), {
393
- zones: data.zones ? __spreadValues({}, data.zones) : {}
394
- });
395
- newData.zones[zoneKey] = newData.zones[zoneKey] || [];
396
- return newData;
397
- };
398
-
399
- // ../core/lib/get-item.ts
400
- init_react_import();
401
- function getItem(selector, state) {
402
- var _a, _b;
403
- const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
404
- return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
405
- }
406
-
407
- // ../core/lib/generate-id.ts
408
- init_react_import();
409
-
410
- // ../../node_modules/uuid/dist/esm-node/index.js
411
- init_react_import();
412
-
413
- // ../../node_modules/uuid/dist/esm-node/rng.js
414
- init_react_import();
415
- import crypto from "crypto";
416
- var rnds8Pool = new Uint8Array(256);
417
- var poolPtr = rnds8Pool.length;
418
- function rng() {
419
- if (poolPtr > rnds8Pool.length - 16) {
420
- crypto.randomFillSync(rnds8Pool);
421
- poolPtr = 0;
422
- }
423
- return rnds8Pool.slice(poolPtr, poolPtr += 16);
424
- }
425
-
426
- // ../../node_modules/uuid/dist/esm-node/stringify.js
427
- init_react_import();
428
- var byteToHex = [];
429
- for (let i = 0; i < 256; ++i) {
430
- byteToHex.push((i + 256).toString(16).slice(1));
431
- }
432
- function unsafeStringify(arr, offset = 0) {
433
- 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]];
434
- }
435
-
436
- // ../../node_modules/uuid/dist/esm-node/v4.js
437
- init_react_import();
438
-
439
- // ../../node_modules/uuid/dist/esm-node/native.js
440
- init_react_import();
441
- import crypto2 from "crypto";
442
- var native_default = {
443
- randomUUID: crypto2.randomUUID
444
- };
445
-
446
- // ../../node_modules/uuid/dist/esm-node/v4.js
447
- function v4(options, buf, offset) {
448
- if (native_default.randomUUID && !buf && !options) {
449
- return native_default.randomUUID();
450
- }
451
- options = options || {};
452
- const rnds = options.random || (options.rng || rng)();
453
- rnds[6] = rnds[6] & 15 | 64;
454
- rnds[8] = rnds[8] & 63 | 128;
455
- if (buf) {
456
- offset = offset || 0;
457
- for (let i = 0; i < 16; ++i) {
458
- buf[offset + i] = rnds[i];
459
- }
460
- return buf;
461
- }
462
- return unsafeStringify(rnds);
463
- }
464
- var v4_default = v4;
465
-
466
- // ../core/lib/generate-id.ts
467
- var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
468
-
469
- // ../core/lib/walk-tree.ts
362
+ // ../core/lib/data/walk-app-state.ts
470
363
  init_react_import();
471
364
 
472
- // ../core/lib/for-each-slot.ts
365
+ // ../core/lib/data/for-each-slot.ts
473
366
  init_react_import();
474
367
 
475
- // ../core/lib/is-slot.ts
368
+ // ../core/lib/data/is-slot.ts
476
369
  init_react_import();
477
370
  var isSlot = (prop) => {
478
371
  var _a, _b;
479
372
  return Array.isArray(prop) && typeof ((_a = prop[0]) == null ? void 0 : _a.type) === "string" && typeof ((_b = prop[0]) == null ? void 0 : _b.props) === "object";
480
373
  };
374
+ var createIsSlotConfig = (config) => (itemType, propName, propValue) => {
375
+ var _a, _b;
376
+ const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
377
+ if (!configForComponent) return isSlot(propValue);
378
+ return ((_b = (_a = configForComponent.fields) == null ? void 0 : _a[propName]) == null ? void 0 : _b.type) === "slot";
379
+ };
481
380
 
482
- // ../core/lib/for-each-slot.ts
483
- var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, cb, recursive = false, isSlot2 = isSlot) {
381
+ // ../core/lib/data/for-each-slot.ts
382
+ var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
484
383
  const props = item.props || {};
485
384
  const propKeys = Object.keys(props);
486
385
  for (let i = 0; i < propKeys.length; i++) {
@@ -488,23 +387,31 @@ var forEachSlot = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function*
488
387
  const itemType = "type" in item ? item.type : "root";
489
388
  if (isSlot2(itemType, propKey, props[propKey])) {
490
389
  const content = props[propKey];
491
- yield cb(props.id, propKey, content);
390
+ cb(props.id, propKey, content);
492
391
  if (recursive) {
493
392
  content.forEach(
494
393
  (childItem) => __async(void 0, null, function* () {
495
- return yield forEachSlot(childItem, cb, true, isSlot2);
394
+ return forEachSlot(childItem, cb, true, isSlot2);
496
395
  })
497
396
  );
498
397
  }
499
398
  }
500
399
  }
501
- });
400
+ };
502
401
 
503
- // ../core/lib/for-related-zones.ts
402
+ // ../core/lib/data/for-related-zones.ts
504
403
  init_react_import();
505
404
 
506
405
  // ../core/lib/get-zone-id.ts
507
406
  init_react_import();
407
+
408
+ // ../core/lib/root-droppable-id.ts
409
+ init_react_import();
410
+ var rootAreaId = "root";
411
+ var rootZone = "default-zone";
412
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
413
+
414
+ // ../core/lib/get-zone-id.ts
508
415
  var getZoneId = (zoneCompound) => {
509
416
  if (!zoneCompound) {
510
417
  return [];
@@ -515,19 +422,17 @@ var getZoneId = (zoneCompound) => {
515
422
  return [rootDroppableId, zoneCompound];
516
423
  };
517
424
 
518
- // ../core/lib/for-related-zones.ts
425
+ // ../core/lib/data/for-related-zones.ts
519
426
  function forRelatedZones(item, data, cb, path = []) {
520
427
  Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
521
428
  const [parentId] = getZoneId(zoneCompound);
522
429
  if (parentId === item.props.id) {
523
- const newPath = [...path, zoneCompound];
524
- content.forEach((item2) => forRelatedZones(item2, data, cb, newPath));
525
430
  cb(path, zoneCompound, content);
526
431
  }
527
432
  });
528
433
  }
529
434
 
530
- // ../core/lib/strip-slots.ts
435
+ // ../core/lib/data/strip-slots.ts
531
436
  init_react_import();
532
437
  var stripSlots = (data) => {
533
438
  return __spreadProps(__spreadValues({}, data), {
@@ -543,8 +448,8 @@ var stripSlots = (data) => {
543
448
  });
544
449
  };
545
450
 
546
- // ../core/lib/walk-tree.ts
547
- function walkTree(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
451
+ // ../core/lib/data/walk-app-state.ts
452
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
548
453
  var _a;
549
454
  let newZones = {};
550
455
  const newZoneIndex = {};
@@ -585,7 +490,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
585
490
  const mappedItem = mapNodeOrSkip(item, path, index);
586
491
  if (!mappedItem) return item;
587
492
  const id = mappedItem.props.id;
588
- processRelatedZones(item, id, path);
589
493
  const newProps = __spreadValues({}, mappedItem.props);
590
494
  forEachSlot(
591
495
  mappedItem,
@@ -601,13 +505,9 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
601
505
  newProps[slotId] = newContent2;
602
506
  },
603
507
  false,
604
- (itemType, propName, propValue) => {
605
- var _a2, _b;
606
- const configForComponent = itemType === "root" ? config == null ? void 0 : config.root : config == null ? void 0 : config.components[itemType];
607
- if (!configForComponent) return isSlot(propValue);
608
- return ((_b = (_a2 = configForComponent.fields) == null ? void 0 : _a2[propName]) == null ? void 0 : _b.type) === "slot";
609
- }
508
+ createIsSlotConfig(config)
610
509
  );
510
+ processRelatedZones(item, id, path);
611
511
  const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
612
512
  const thisZoneCompound = path[path.length - 1];
613
513
  const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
@@ -618,7 +518,7 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
618
518
  parentId,
619
519
  zone
620
520
  };
621
- const finalData = newItem;
521
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
622
522
  if (newProps.id === "root") {
623
523
  delete finalData["type"];
624
524
  delete finalData.props["id"];
@@ -633,8 +533,12 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
633
533
  "root"
634
534
  );
635
535
  const processedContent = newContent;
536
+ const zonesAlreadyProcessed = Object.keys(newZones);
636
537
  Object.keys(zones || {}).forEach((zoneCompound) => {
637
538
  const [parentId] = zoneCompound.split(":");
539
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
540
+ return;
541
+ }
638
542
  const [_2, newContent2] = processContent(
639
543
  [rootDroppableId],
640
544
  zoneCompound,
@@ -658,7 +562,6 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
658
562
  return __spreadProps(__spreadValues({}, state), {
659
563
  data: {
660
564
  root,
661
- // 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.
662
565
  content: processedContent,
663
566
  zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
664
567
  },
@@ -669,60 +572,214 @@ function walkTree(state, config, mapContent = (content) => content, mapNodeOrSki
669
572
  });
670
573
  }
671
574
 
672
- // ../core/lib/deindex.ts
673
- init_react_import();
674
- var deindex = (state, componentData) => {
675
- let zones = __spreadValues({}, state.indexes.zones);
676
- let nodes = __spreadValues({}, state.indexes.nodes);
677
- const dindexRelatedZones = (item) => {
678
- forRelatedZones(item, state.data, (_path, zoneCompound, content) => {
679
- content.forEach((subItem) => {
680
- dindexChildren(subItem);
681
- delete nodes[subItem.props.id];
682
- });
683
- delete zones[zoneCompound];
684
- });
685
- };
686
- const dindexChildren = (item) => {
687
- forEachSlot(
688
- item,
689
- (parentId, slotId, content) => {
690
- const zoneCompound = `${parentId}:${slotId}`;
691
- delete zones[zoneCompound];
692
- content.forEach((item2) => {
693
- dindexRelatedZones(item2);
694
- delete nodes[item2.props.id];
695
- });
696
- },
697
- true
575
+ // ../core/reducer/actions/set.ts
576
+ var setAction = (state, action, appStore) => {
577
+ if (typeof action.state === "object") {
578
+ const newState = __spreadValues(__spreadValues({}, state), action.state);
579
+ if (action.state.indexes) {
580
+ return newState;
581
+ }
582
+ console.warn(
583
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
698
584
  );
699
- };
700
- dindexRelatedZones(componentData);
701
- dindexChildren(componentData);
702
- delete nodes[componentData.props.id];
703
- return { nodes, zones };
585
+ return walkAppState(newState, appStore.config);
586
+ }
587
+ return __spreadValues(__spreadValues({}, state), action.state(state));
704
588
  };
705
589
 
706
- // ../core/reducer/reduce.ts
707
- var zoneCache = {};
590
+ // ../core/reducer/actions/insert.ts
591
+ init_react_import();
592
+
593
+ // ../core/lib/data/insert.ts
594
+ init_react_import();
595
+ var insert = (list, index, item) => {
596
+ const result = Array.from(list || []);
597
+ result.splice(index, 0, item);
598
+ return result;
599
+ };
600
+
601
+ // ../core/lib/generate-id.ts
602
+ init_react_import();
603
+
604
+ // ../../node_modules/uuid/dist/esm-node/index.js
605
+ init_react_import();
606
+
607
+ // ../../node_modules/uuid/dist/esm-node/rng.js
608
+ init_react_import();
609
+ import crypto from "crypto";
610
+ var rnds8Pool = new Uint8Array(256);
611
+ var poolPtr = rnds8Pool.length;
612
+ function rng() {
613
+ if (poolPtr > rnds8Pool.length - 16) {
614
+ crypto.randomFillSync(rnds8Pool);
615
+ poolPtr = 0;
616
+ }
617
+ return rnds8Pool.slice(poolPtr, poolPtr += 16);
618
+ }
619
+
620
+ // ../../node_modules/uuid/dist/esm-node/stringify.js
621
+ init_react_import();
622
+ var byteToHex = [];
623
+ for (let i = 0; i < 256; ++i) {
624
+ byteToHex.push((i + 256).toString(16).slice(1));
625
+ }
626
+ function unsafeStringify(arr, offset = 0) {
627
+ 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]];
628
+ }
629
+
630
+ // ../../node_modules/uuid/dist/esm-node/v4.js
631
+ init_react_import();
632
+
633
+ // ../../node_modules/uuid/dist/esm-node/native.js
634
+ init_react_import();
635
+ import crypto2 from "crypto";
636
+ var native_default = {
637
+ randomUUID: crypto2.randomUUID
638
+ };
639
+
640
+ // ../../node_modules/uuid/dist/esm-node/v4.js
641
+ function v4(options, buf, offset) {
642
+ if (native_default.randomUUID && !buf && !options) {
643
+ return native_default.randomUUID();
644
+ }
645
+ options = options || {};
646
+ const rnds = options.random || (options.rng || rng)();
647
+ rnds[6] = rnds[6] & 15 | 64;
648
+ rnds[8] = rnds[8] & 63 | 128;
649
+ if (buf) {
650
+ offset = offset || 0;
651
+ for (let i = 0; i < 16; ++i) {
652
+ buf[offset + i] = rnds[i];
653
+ }
654
+ return buf;
655
+ }
656
+ return unsafeStringify(rnds);
657
+ }
658
+ var v4_default = v4;
659
+
660
+ // ../core/lib/generate-id.ts
661
+ var generateId = (type) => type ? `${type}-${v4_default()}` : v4_default();
662
+
663
+ // ../core/lib/data/get-ids-for-parent.ts
664
+ init_react_import();
708
665
  var getIdsForParent = (zoneCompound, state) => {
709
666
  const [parentId] = zoneCompound.split(":");
710
667
  const node = state.indexes.nodes[parentId];
711
668
  return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
712
669
  };
713
- function insertAction(state, action, config) {
714
- const id = action.id || generateId(action.componentType);
715
- const emptyComponentData = {
716
- type: action.componentType,
717
- props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
718
- id
719
- })
670
+
671
+ // ../core/lib/data/populate-ids.ts
672
+ init_react_import();
673
+
674
+ // ../core/lib/data/walk-tree.ts
675
+ init_react_import();
676
+
677
+ // ../core/lib/data/map-slots.ts
678
+ init_react_import();
679
+ function mapSlotsAsync(_0, _1) {
680
+ return __async(this, arguments, function* (item, map, recursive = true, isSlot2 = isSlot) {
681
+ const props = __spreadValues({}, item.props);
682
+ const propKeys = Object.keys(props);
683
+ for (let i = 0; i < propKeys.length; i++) {
684
+ const propKey = propKeys[i];
685
+ const itemType = "type" in item ? item.type : "root";
686
+ if (isSlot2(itemType, propKey, props[propKey])) {
687
+ const content = props[propKey];
688
+ const mappedContent = recursive ? yield Promise.all(
689
+ content.map((item2) => __async(this, null, function* () {
690
+ return yield mapSlotsAsync(item2, map, recursive, isSlot2);
691
+ }))
692
+ ) : content;
693
+ props[propKey] = yield map(mappedContent, propKey);
694
+ }
695
+ }
696
+ return __spreadProps(__spreadValues({}, item), { props });
697
+ });
698
+ }
699
+ function mapSlotsSync(item, map, isSlot2 = isSlot) {
700
+ var _a, _b;
701
+ const props = __spreadValues({}, item.props);
702
+ const propKeys = Object.keys(props);
703
+ for (let i = 0; i < propKeys.length; i++) {
704
+ const propKey = propKeys[i];
705
+ const itemType = "type" in item ? item.type : "root";
706
+ if (isSlot2(itemType, propKey, props[propKey])) {
707
+ const content = props[propKey];
708
+ const mappedContent = content.map((item2) => {
709
+ return mapSlotsSync(item2, map, isSlot2);
710
+ });
711
+ props[propKey] = (_b = map(mappedContent, (_a = props.id) != null ? _a : "root", propKey)) != null ? _b : mappedContent;
712
+ }
713
+ }
714
+ return __spreadProps(__spreadValues({}, item), { props });
715
+ }
716
+
717
+ // ../core/lib/data/walk-tree.ts
718
+ function walkTree(data, config, callbackFn) {
719
+ var _a, _b;
720
+ const isSlot2 = createIsSlotConfig(config);
721
+ const walkItem = (item) => {
722
+ return mapSlotsSync(
723
+ item,
724
+ (content, parentId, propName) => callbackFn(content, { parentId, propName }),
725
+ isSlot2
726
+ );
727
+ };
728
+ if ("props" in data) {
729
+ return walkItem(data);
730
+ }
731
+ const _data = data;
732
+ const zones = (_a = _data.zones) != null ? _a : {};
733
+ const mappedContent = _data.content.map(walkItem);
734
+ return {
735
+ root: walkItem(_data.root),
736
+ content: (_b = callbackFn(mappedContent, {
737
+ parentId: "root",
738
+ propName: "default-zone"
739
+ })) != null ? _b : mappedContent,
740
+ zones: Object.keys(zones).reduce(
741
+ (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
742
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
743
+ }),
744
+ {}
745
+ )
720
746
  };
747
+ }
748
+
749
+ // ../core/lib/data/populate-ids.ts
750
+ var populateIds = (data, config, override = false) => {
751
+ const id = generateId(data.type);
752
+ return walkTree(
753
+ __spreadProps(__spreadValues({}, data), {
754
+ props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({ id }, data.props)
755
+ }),
756
+ config,
757
+ (contents) => contents.map((item) => {
758
+ const id2 = generateId(item.type);
759
+ return __spreadProps(__spreadValues({}, item), {
760
+ props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
761
+ });
762
+ })
763
+ );
764
+ };
765
+
766
+ // ../core/reducer/actions/insert.ts
767
+ function insertAction(state, action, appStore) {
768
+ const id = action.id || generateId(action.componentType);
769
+ const emptyComponentData = populateIds(
770
+ {
771
+ type: action.componentType,
772
+ props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
773
+ id
774
+ })
775
+ },
776
+ appStore.config
777
+ );
721
778
  const [parentId] = action.destinationZone.split(":");
722
779
  const idsInPath = getIdsForParent(action.destinationZone, state);
723
- return walkTree(
780
+ return walkAppState(
724
781
  state,
725
- config,
782
+ appStore.config,
726
783
  (content, zoneCompound) => {
727
784
  if (zoneCompound === action.destinationZone) {
728
785
  return insert(
@@ -733,16 +790,154 @@ function insertAction(state, action, config) {
733
790
  }
734
791
  return content;
735
792
  },
736
- (childItem) => {
737
- if (childItem.props.id === id || childItem.props.id === parentId) {
738
- return childItem;
739
- } else if (idsInPath.indexOf(childItem.props.id) > -1) {
793
+ (childItem, path) => {
794
+ if (childItem.props.id === id || childItem.props.id === parentId) {
795
+ return childItem;
796
+ } else if (idsInPath.includes(childItem.props.id)) {
797
+ return childItem;
798
+ } else if (path.includes(action.destinationZone)) {
799
+ return childItem;
800
+ }
801
+ return null;
802
+ }
803
+ );
804
+ }
805
+
806
+ // ../core/reducer/actions/replace.ts
807
+ init_react_import();
808
+ var replaceAction = (state, action, appStore) => {
809
+ const [parentId] = action.destinationZone.split(":");
810
+ const idsInPath = getIdsForParent(action.destinationZone, state);
811
+ const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
812
+ const idChanged = originalId !== action.data.props.id;
813
+ if (idChanged) {
814
+ throw new Error(
815
+ `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
816
+ );
817
+ }
818
+ const data = populateIds(action.data, appStore.config);
819
+ return walkAppState(
820
+ state,
821
+ appStore.config,
822
+ (content, zoneCompound) => {
823
+ const newContent = [...content];
824
+ if (zoneCompound === action.destinationZone) {
825
+ newContent[action.destinationIndex] = data;
826
+ }
827
+ return newContent;
828
+ },
829
+ (childItem, path) => {
830
+ const pathIds = path.map((p) => p.split(":")[0]);
831
+ if (childItem.props.id === data.props.id) {
832
+ return data;
833
+ } else if (childItem.props.id === parentId) {
834
+ return childItem;
835
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
836
+ return childItem;
837
+ } else if (pathIds.indexOf(data.props.id) > -1) {
838
+ return childItem;
839
+ }
840
+ return null;
841
+ }
842
+ );
843
+ };
844
+
845
+ // ../core/reducer/actions/replace-root.ts
846
+ init_react_import();
847
+ var replaceRootAction = (state, action, appStore) => {
848
+ return walkAppState(
849
+ state,
850
+ appStore.config,
851
+ (content) => content,
852
+ (childItem) => {
853
+ if (childItem.props.id === "root") {
854
+ return __spreadProps(__spreadValues({}, childItem), {
855
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
856
+ readOnly: action.root.readOnly
857
+ });
858
+ }
859
+ return childItem;
860
+ }
861
+ );
862
+ };
863
+
864
+ // ../core/reducer/actions/duplicate.ts
865
+ init_react_import();
866
+
867
+ // ../core/lib/data/get-item.ts
868
+ init_react_import();
869
+ function getItem(selector, state) {
870
+ var _a, _b;
871
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
872
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
873
+ }
874
+
875
+ // ../core/reducer/actions/duplicate.ts
876
+ function duplicateAction(state, action, appStore) {
877
+ const item = getItem(
878
+ { index: action.sourceIndex, zone: action.sourceZone },
879
+ state
880
+ );
881
+ const idsInPath = getIdsForParent(action.sourceZone, state);
882
+ const newItem = __spreadProps(__spreadValues({}, item), {
883
+ props: __spreadProps(__spreadValues({}, item.props), {
884
+ id: generateId(item.type)
885
+ })
886
+ });
887
+ const modified = walkAppState(
888
+ state,
889
+ appStore.config,
890
+ (content, zoneCompound) => {
891
+ if (zoneCompound === action.sourceZone) {
892
+ return insert(content, action.sourceIndex + 1, item);
893
+ }
894
+ return content;
895
+ },
896
+ (childItem, path, index) => {
897
+ const zoneCompound = path[path.length - 1];
898
+ const parents = path.map((p) => p.split(":")[0]);
899
+ if (parents.indexOf(newItem.props.id) > -1) {
900
+ return __spreadProps(__spreadValues({}, childItem), {
901
+ props: __spreadProps(__spreadValues({}, childItem.props), {
902
+ id: generateId(childItem.type)
903
+ })
904
+ });
905
+ }
906
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
907
+ return newItem;
908
+ }
909
+ const [sourceZoneParent] = action.sourceZone.split(":");
910
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
740
911
  return childItem;
741
912
  }
742
913
  return null;
743
914
  }
744
915
  );
916
+ return __spreadProps(__spreadValues({}, modified), {
917
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
918
+ itemSelector: {
919
+ index: action.sourceIndex + 1,
920
+ zone: action.sourceZone
921
+ }
922
+ })
923
+ });
745
924
  }
925
+
926
+ // ../core/reducer/actions/reorder.ts
927
+ init_react_import();
928
+
929
+ // ../core/reducer/actions/move.ts
930
+ init_react_import();
931
+
932
+ // ../core/lib/data/remove.ts
933
+ init_react_import();
934
+ var remove = (list, index) => {
935
+ const result = Array.from(list);
936
+ result.splice(index, 1);
937
+ return result;
938
+ };
939
+
940
+ // ../core/reducer/actions/move.ts
746
941
  var moveAction = (state, action, appStore) => {
747
942
  if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
748
943
  return state;
@@ -754,7 +949,7 @@ var moveAction = (state, action, appStore) => {
754
949
  if (!item) return state;
755
950
  const idsInSourcePath = getIdsForParent(action.sourceZone, state);
756
951
  const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
757
- return walkTree(
952
+ return walkAppState(
758
953
  state,
759
954
  appStore.config,
760
955
  (content, zoneCompound) => {
@@ -771,233 +966,172 @@ var moveAction = (state, action, appStore) => {
771
966
  }
772
967
  return content;
773
968
  },
774
- (childItem) => {
969
+ (childItem, path) => {
775
970
  const [sourceZoneParent] = action.sourceZone.split(":");
776
971
  const [destinationZoneParent] = action.destinationZone.split(":");
777
972
  const childId = childItem.props.id;
778
- if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1) {
973
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
779
974
  return childItem;
780
975
  }
781
976
  return null;
782
977
  }
783
978
  );
784
979
  };
785
- var replaceAction = (state, action, appStore) => {
786
- const [parentId] = action.destinationZone.split(":");
787
- const idsInPath = getIdsForParent(action.destinationZone, state);
788
- return walkTree(
980
+
981
+ // ../core/reducer/actions/reorder.ts
982
+ var reorderAction = (state, action, appStore) => {
983
+ return moveAction(
984
+ state,
985
+ {
986
+ type: "move",
987
+ sourceIndex: action.sourceIndex,
988
+ sourceZone: action.destinationZone,
989
+ destinationIndex: action.destinationIndex,
990
+ destinationZone: action.destinationZone
991
+ },
992
+ appStore
993
+ );
994
+ };
995
+
996
+ // ../core/reducer/actions/remove.ts
997
+ init_react_import();
998
+ var removeAction = (state, action, appStore) => {
999
+ const item = getItem({ index: action.index, zone: action.zone }, state);
1000
+ const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
1001
+ (acc, [nodeId, nodeData]) => {
1002
+ const pathIds = nodeData.path.map((p) => p.split(":")[0]);
1003
+ if (pathIds.includes(item.props.id)) {
1004
+ return [...acc, nodeId];
1005
+ }
1006
+ return acc;
1007
+ },
1008
+ [item.props.id]
1009
+ );
1010
+ const newState = walkAppState(
789
1011
  state,
790
1012
  appStore.config,
791
- (content) => content,
792
- (childItem, path) => {
793
- const pathIds = path.map((p) => p.split(":")[0]);
794
- if (childItem.props.id === action.data.props.id) {
795
- return action.data;
796
- } else if (childItem.props.id === parentId) {
797
- return childItem;
798
- } else if (idsInPath.indexOf(childItem.props.id) > -1) {
799
- return childItem;
800
- } else if (pathIds.indexOf(action.data.props.id) > -1) {
801
- return childItem;
1013
+ (content, zoneCompound) => {
1014
+ if (zoneCompound === action.zone) {
1015
+ return remove(content, action.index);
802
1016
  }
803
- return null;
1017
+ return content;
804
1018
  }
805
1019
  );
806
- };
807
- var setAction = (state, action, appStore) => {
808
- if (typeof action.state === "object") {
809
- const newState = __spreadValues(__spreadValues({}, state), action.state);
810
- if (action.state.indexes) {
811
- console.warn(
812
- "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
813
- );
814
- return newState;
1020
+ Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
1021
+ const parentId = zoneCompound.split(":")[0];
1022
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
1023
+ delete newState.data.zones[zoneCompound];
815
1024
  }
816
- return walkTree(newState, appStore.config);
817
- }
818
- return __spreadValues(__spreadValues({}, state), action.state(state));
819
- };
820
- function reduce(state, action, appStore) {
821
- if (action.type === "set") {
822
- return setAction(state, action, appStore);
823
- }
824
- if (action.type === "insert") {
825
- return insertAction(state, action, appStore.config);
826
- }
827
- if (action.type === "replace") {
828
- return replaceAction(state, action, appStore);
829
- }
830
- if (action.type === "replaceRoot") {
831
- return walkTree(
832
- state,
833
- appStore.config,
834
- (content) => content,
835
- (childItem) => {
836
- if (childItem.props.id === "root") {
837
- return __spreadProps(__spreadValues({}, childItem), {
838
- props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
839
- readOnly: action.root.readOnly
840
- });
841
- }
842
- return childItem;
843
- }
844
- );
845
- }
846
- if (action.type === "duplicate") {
847
- const item = getItem(
848
- { index: action.sourceIndex, zone: action.sourceZone },
849
- state
850
- );
851
- const idsInPath = getIdsForParent(action.sourceZone, state);
852
- const newItem = __spreadProps(__spreadValues({}, item), {
853
- props: __spreadProps(__spreadValues({}, item.props), {
854
- id: generateId(item.type)
855
- })
856
- });
857
- const modified = walkTree(
858
- state,
859
- appStore.config,
860
- (content, zoneCompound) => {
861
- if (zoneCompound === action.sourceZone) {
862
- return insert(content, action.sourceIndex + 1, item);
863
- }
864
- return content;
865
- },
866
- (childItem, path, index) => {
867
- const zoneCompound = path[path.length - 1];
868
- const parents = path.map((p) => p.split(":")[0]);
869
- if (parents.indexOf(newItem.props.id) > -1) {
870
- return __spreadProps(__spreadValues({}, childItem), {
871
- props: __spreadProps(__spreadValues({}, childItem.props), {
872
- id: generateId(childItem.type)
873
- })
874
- });
875
- }
876
- if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
877
- return newItem;
878
- }
879
- const [sourceZoneParent] = action.sourceZone.split(":");
880
- if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
881
- return childItem;
882
- }
883
- return null;
884
- }
885
- );
886
- return __spreadProps(__spreadValues({}, modified), {
887
- ui: __spreadProps(__spreadValues({}, modified.ui), {
888
- itemSelector: {
889
- index: action.sourceIndex + 1,
890
- zone: action.sourceZone
891
- }
892
- })
893
- });
894
- }
895
- if (action.type === "reorder") {
896
- return moveAction(
897
- state,
898
- {
899
- type: "move",
900
- sourceIndex: action.sourceIndex,
901
- sourceZone: action.destinationZone,
902
- destinationIndex: action.destinationIndex,
903
- destinationZone: action.destinationZone
904
- },
905
- appStore
906
- );
907
- }
908
- if (action.type === "move") {
909
- return moveAction(state, action, appStore);
910
- }
911
- if (action.type === "remove") {
912
- const item = getItem({ index: action.index, zone: action.zone }, state);
913
- let deindexed = deindex(state, item);
914
- const [parentId] = action.zone.split(":");
915
- return walkTree(
916
- __spreadProps(__spreadValues({}, state), { indexes: deindexed }),
917
- appStore.config,
918
- (content, zoneCompound) => {
919
- if (zoneCompound === action.zone) {
920
- return remove(content, action.index);
921
- }
922
- return content;
923
- },
924
- (childItem, path) => {
925
- const parentIds = path.map((p) => p.split(":")[0]);
926
- if (childItem.props.id === parentId || childItem.props.id === item.props.id || parentIds.indexOf(item.props.id) > -1) {
927
- return childItem;
928
- }
929
- return null;
930
- }
931
- );
932
- }
933
- if (action.type === "registerZone") {
934
- if (zoneCache[action.zone]) {
935
- return __spreadProps(__spreadValues({}, state), {
936
- data: __spreadProps(__spreadValues({}, state.data), {
937
- zones: __spreadProps(__spreadValues({}, state.data.zones), {
938
- [action.zone]: zoneCache[action.zone]
939
- })
940
- }),
941
- indexes: __spreadProps(__spreadValues({}, state.indexes), {
942
- zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
943
- [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
944
- contentIds: zoneCache[action.zone].map((item) => item.props.id),
945
- type: "dropzone"
946
- })
947
- })
948
- })
949
- });
1025
+ });
1026
+ Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
1027
+ const parentId = zoneCompound.split(":")[0];
1028
+ if (nodesToDelete.includes(parentId)) {
1029
+ delete newState.indexes.zones[zoneCompound];
950
1030
  }
951
- return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1031
+ });
1032
+ nodesToDelete.forEach((id) => {
1033
+ delete newState.indexes.nodes[id];
1034
+ });
1035
+ return newState;
1036
+ };
1037
+
1038
+ // ../core/reducer/actions/register-zone.ts
1039
+ init_react_import();
1040
+
1041
+ // ../core/lib/data/setup-zone.ts
1042
+ init_react_import();
1043
+ var setupZone = (data, zoneKey) => {
1044
+ if (zoneKey === rootDroppableId) {
1045
+ return data;
952
1046
  }
953
- if (action.type === "unregisterZone") {
954
- const _zones = __spreadValues({}, state.data.zones || {});
955
- const zoneIndex = __spreadValues({}, state.indexes.zones || {});
956
- if (_zones[action.zone]) {
957
- zoneCache[action.zone] = _zones[action.zone];
958
- delete _zones[action.zone];
959
- }
960
- delete zoneIndex[action.zone];
1047
+ const newData = __spreadProps(__spreadValues({}, data), {
1048
+ zones: data.zones ? __spreadValues({}, data.zones) : {}
1049
+ });
1050
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
1051
+ return newData;
1052
+ };
1053
+
1054
+ // ../core/reducer/actions/register-zone.ts
1055
+ var zoneCache = {};
1056
+ function registerZoneAction(state, action) {
1057
+ if (zoneCache[action.zone]) {
961
1058
  return __spreadProps(__spreadValues({}, state), {
962
1059
  data: __spreadProps(__spreadValues({}, state.data), {
963
- zones: _zones
1060
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
1061
+ [action.zone]: zoneCache[action.zone]
1062
+ })
964
1063
  }),
965
1064
  indexes: __spreadProps(__spreadValues({}, state.indexes), {
966
- zones: zoneIndex
1065
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
1066
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
1067
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
1068
+ type: "dropzone"
1069
+ })
1070
+ })
967
1071
  })
968
1072
  });
969
1073
  }
970
- if (action.type === "setData") {
971
- if (typeof action.data === "object") {
972
- console.warn(
973
- "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
974
- );
975
- return walkTree(
976
- __spreadProps(__spreadValues({}, state), {
977
- data: __spreadValues(__spreadValues({}, state.data), action.data)
978
- }),
979
- appStore.config
980
- );
981
- }
982
- return walkTree(
1074
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1075
+ }
1076
+ function unregisterZoneAction(state, action) {
1077
+ const _zones = __spreadValues({}, state.data.zones || {});
1078
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
1079
+ if (_zones[action.zone]) {
1080
+ zoneCache[action.zone] = _zones[action.zone];
1081
+ delete _zones[action.zone];
1082
+ }
1083
+ delete zoneIndex[action.zone];
1084
+ return __spreadProps(__spreadValues({}, state), {
1085
+ data: __spreadProps(__spreadValues({}, state.data), {
1086
+ zones: _zones
1087
+ }),
1088
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1089
+ zones: zoneIndex
1090
+ })
1091
+ });
1092
+ }
1093
+
1094
+ // ../core/reducer/actions/set-data.ts
1095
+ init_react_import();
1096
+ var setDataAction = (state, action, appStore) => {
1097
+ if (typeof action.data === "object") {
1098
+ console.warn(
1099
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1100
+ );
1101
+ return walkAppState(
983
1102
  __spreadProps(__spreadValues({}, state), {
984
- data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1103
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
985
1104
  }),
986
1105
  appStore.config
987
1106
  );
988
1107
  }
989
- if (action.type === "setUi") {
990
- if (typeof action.ui === "object") {
991
- return __spreadProps(__spreadValues({}, state), {
992
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
993
- });
994
- }
1108
+ return walkAppState(
1109
+ __spreadProps(__spreadValues({}, state), {
1110
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1111
+ }),
1112
+ appStore.config
1113
+ );
1114
+ };
1115
+
1116
+ // ../core/reducer/actions/set-ui.ts
1117
+ init_react_import();
1118
+ var setUiAction = (state, action) => {
1119
+ if (typeof action.ui === "object") {
995
1120
  return __spreadProps(__spreadValues({}, state), {
996
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1121
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
997
1122
  });
998
1123
  }
999
- return state;
1000
- }
1124
+ return __spreadProps(__spreadValues({}, state), {
1125
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1126
+ });
1127
+ };
1128
+
1129
+ // ../core/lib/data/make-state-public.ts
1130
+ init_react_import();
1131
+ var makeStatePublic = (state) => {
1132
+ const { data, ui } = state;
1133
+ return { data, ui };
1134
+ };
1001
1135
 
1002
1136
  // ../core/reducer/actions.tsx
1003
1137
  init_react_import();
@@ -1016,7 +1150,7 @@ function storeInterceptor(reducer, record, onAction) {
1016
1150
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1017
1151
  if (record) record(newAppState);
1018
1152
  }
1019
- onAction == null ? void 0 : onAction(action, newAppState, state);
1153
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1020
1154
  return newAppState;
1021
1155
  };
1022
1156
  }
@@ -1027,8 +1161,43 @@ function createReducer({
1027
1161
  }) {
1028
1162
  return storeInterceptor(
1029
1163
  (state, action) => {
1030
- const result = reduce(state, action, appStore);
1031
- return result;
1164
+ if (action.type === "set") {
1165
+ return setAction(state, action, appStore);
1166
+ }
1167
+ if (action.type === "insert") {
1168
+ return insertAction(state, action, appStore);
1169
+ }
1170
+ if (action.type === "replace") {
1171
+ return replaceAction(state, action, appStore);
1172
+ }
1173
+ if (action.type === "replaceRoot") {
1174
+ return replaceRootAction(state, action, appStore);
1175
+ }
1176
+ if (action.type === "duplicate") {
1177
+ return duplicateAction(state, action, appStore);
1178
+ }
1179
+ if (action.type === "reorder") {
1180
+ return reorderAction(state, action, appStore);
1181
+ }
1182
+ if (action.type === "move") {
1183
+ return moveAction(state, action, appStore);
1184
+ }
1185
+ if (action.type === "remove") {
1186
+ return removeAction(state, action, appStore);
1187
+ }
1188
+ if (action.type === "registerZone") {
1189
+ return registerZoneAction(state, action);
1190
+ }
1191
+ if (action.type === "unregisterZone") {
1192
+ return unregisterZoneAction(state, action);
1193
+ }
1194
+ if (action.type === "setData") {
1195
+ return setDataAction(state, action, appStore);
1196
+ }
1197
+ if (action.type === "setUi") {
1198
+ return setUiAction(state, action);
1199
+ }
1200
+ return state;
1032
1201
  },
1033
1202
  record,
1034
1203
  onAction
@@ -1223,7 +1392,7 @@ var createHistorySlice = (set, get) => {
1223
1392
  const { dispatch, history } = get();
1224
1393
  dispatch({
1225
1394
  type: "set",
1226
- state: ((_a = history.histories[history.index]) == null ? void 0 : _a.state) || history.initialAppState
1395
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1227
1396
  });
1228
1397
  set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1229
1398
  },
@@ -1272,11 +1441,11 @@ var createNodesSlice = (set, get) => ({
1272
1441
  init_react_import();
1273
1442
  import { useEffect as useEffect3 } from "react";
1274
1443
 
1275
- // ../core/lib/flatten-data.ts
1444
+ // ../core/lib/data/flatten-data.ts
1276
1445
  init_react_import();
1277
1446
  var flattenData = (state, config) => {
1278
1447
  const data = [];
1279
- walkTree(
1448
+ walkAppState(
1280
1449
  state,
1281
1450
  config,
1282
1451
  (content) => content,
@@ -1307,12 +1476,7 @@ var createPermissionsSlice = (set, get) => {
1307
1476
  const { cache: cache2, globalPermissions } = permissions;
1308
1477
  const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1309
1478
  var _a, _b, _c;
1310
- const {
1311
- config: config2,
1312
- state: appState,
1313
- setComponentLoading,
1314
- unsetComponentLoading
1315
- } = get();
1479
+ const { config: config2, state: appState, setComponentLoading } = get();
1316
1480
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1317
1481
  if (!componentConfig) {
1318
1482
  return;
@@ -1321,14 +1485,14 @@ var createPermissionsSlice = (set, get) => {
1321
1485
  if (componentConfig.resolvePermissions) {
1322
1486
  const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1323
1487
  if (Object.values(changed).some((el) => el === true) || force2) {
1324
- setComponentLoading(item2.props.id);
1488
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1325
1489
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1326
1490
  item2,
1327
1491
  {
1328
1492
  changed,
1329
1493
  lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1330
1494
  permissions: initialPermissions,
1331
- appState,
1495
+ appState: makeStatePublic(appState),
1332
1496
  lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1333
1497
  }
1334
1498
  );
@@ -1346,7 +1510,7 @@ var createPermissionsSlice = (set, get) => {
1346
1510
  })
1347
1511
  })
1348
1512
  });
1349
- unsetComponentLoading(item2.props.id);
1513
+ clearTimeout2();
1350
1514
  }
1351
1515
  }
1352
1516
  });
@@ -1356,7 +1520,7 @@ var createPermissionsSlice = (set, get) => {
1356
1520
  // Shim the root data in by conforming to component data shape
1357
1521
  {
1358
1522
  type: "root",
1359
- props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
1523
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1360
1524
  },
1361
1525
  force2
1362
1526
  );
@@ -1371,7 +1535,6 @@ var createPermissionsSlice = (set, get) => {
1371
1535
  } else if (root) {
1372
1536
  resolveDataForRoot(force);
1373
1537
  } else {
1374
- resolveDataForRoot(force);
1375
1538
  flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1376
1539
  yield resolveDataForItem(item2, force);
1377
1540
  }));
@@ -1402,7 +1565,7 @@ var createPermissionsSlice = (set, get) => {
1402
1565
  } else if (root) {
1403
1566
  const rootConfig = config.root;
1404
1567
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1405
- const resolvedForItem = resolvedPermissions["puck-root"];
1568
+ const resolvedForItem = resolvedPermissions["root"];
1406
1569
  return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1407
1570
  }
1408
1571
  return globalPermissions;
@@ -1419,45 +1582,22 @@ var createFieldsSlice = (_set, _get) => {
1419
1582
  return {
1420
1583
  fields: {},
1421
1584
  loading: false,
1422
- lastResolvedData: {}
1585
+ lastResolvedData: {},
1586
+ id: void 0
1423
1587
  };
1424
1588
  };
1425
1589
 
1426
1590
  // ../core/lib/resolve-component-data.ts
1427
1591
  init_react_import();
1428
-
1429
- // ../core/lib/map-slots.ts
1430
- init_react_import();
1431
- function mapSlots(item, map, recursive = true, isSlot2) {
1432
- return __async(this, null, function* () {
1433
- const props = __spreadValues({}, item.props);
1434
- yield forEachSlot(
1435
- item,
1436
- (_parentId, propName, content) => __async(this, null, function* () {
1437
- const mappedContent = recursive ? yield Promise.all(
1438
- content.map((item2) => __async(this, null, function* () {
1439
- return yield mapSlots(item2, map, recursive, isSlot2);
1440
- }))
1441
- ) : content;
1442
- props[propName] = yield map(mappedContent, propName);
1443
- }),
1444
- false,
1445
- isSlot2
1446
- );
1447
- return __spreadProps(__spreadValues({}, item), { props });
1448
- });
1449
- }
1450
-
1451
- // ../core/lib/resolve-component-data.ts
1452
1592
  var import_fast_deep_equal = __toESM(require_fast_deep_equal());
1453
1593
  var cache = { lastChange: {} };
1454
1594
  var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace", recursive = true) {
1455
- const configForItem = "type" in item ? config.components[item.type] : config.root;
1595
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
1456
1596
  if ((configForItem == null ? void 0 : configForItem.resolveData) && item.props) {
1457
1597
  const id = "id" in item.props ? item.props.id : "root";
1458
1598
  const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1459
- if (item && item === oldItem) {
1460
- return resolved;
1599
+ if (item && (0, import_fast_deep_equal.default)(item, oldItem)) {
1600
+ return { node: resolved, didChange: false };
1461
1601
  }
1462
1602
  const changed = getChanged(item, oldItem);
1463
1603
  if (onResolveStart) {
@@ -1466,30 +1606,35 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1466
1606
  const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1467
1607
  changed,
1468
1608
  lastData: oldItem,
1469
- metadata,
1609
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1470
1610
  trigger
1471
1611
  });
1472
1612
  let resolvedItem = __spreadProps(__spreadValues({}, item), {
1473
1613
  props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
1474
1614
  });
1475
1615
  if (recursive) {
1476
- resolvedItem = yield mapSlots(resolvedItem, (content) => __async(void 0, null, function* () {
1477
- return Promise.all(
1478
- content.map(
1479
- (childItem) => __async(void 0, null, function* () {
1480
- return (yield resolveComponentData(
1481
- childItem,
1482
- config,
1483
- metadata,
1484
- onResolveStart,
1485
- onResolveEnd,
1486
- trigger,
1487
- false
1488
- )).node;
1489
- })
1490
- )
1491
- );
1492
- }));
1616
+ resolvedItem = yield mapSlotsAsync(
1617
+ resolvedItem,
1618
+ (content) => __async(void 0, null, function* () {
1619
+ return Promise.all(
1620
+ content.map(
1621
+ (childItem) => __async(void 0, null, function* () {
1622
+ return (yield resolveComponentData(
1623
+ childItem,
1624
+ config,
1625
+ metadata,
1626
+ onResolveStart,
1627
+ onResolveEnd,
1628
+ trigger,
1629
+ false
1630
+ )).node;
1631
+ })
1632
+ )
1633
+ );
1634
+ }),
1635
+ false,
1636
+ createIsSlotConfig(config)
1637
+ );
1493
1638
  }
1494
1639
  if (Object.keys(readOnly).length) {
1495
1640
  resolvedItem.readOnly = readOnly;
@@ -1506,7 +1651,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
1506
1651
  return { node: item, didChange: false };
1507
1652
  });
1508
1653
 
1509
- // ../core/lib/to-root.ts
1654
+ // ../core/lib/data/to-root.ts
1510
1655
  init_react_import();
1511
1656
  var toRoot = (item) => {
1512
1657
  if ("type" in item && item.type !== "root") {
@@ -1553,172 +1698,176 @@ var defaultPageFields = {
1553
1698
  title: { type: "text" }
1554
1699
  };
1555
1700
  var createAppStore = (initialAppStore) => create()(
1556
- subscribeWithSelector((set, get) => __spreadProps(__spreadValues({
1557
- state: defaultAppState,
1558
- config: { components: {} },
1559
- componentState: {},
1560
- plugins: [],
1561
- overrides: {},
1562
- viewports: defaultViewports,
1563
- zoomConfig: {
1564
- autoZoom: 1,
1565
- rootHeight: 0,
1566
- zoom: 1
1567
- },
1568
- status: "LOADING",
1569
- iframe: {},
1570
- metadata: {}
1571
- }, initialAppStore), {
1572
- fields: createFieldsSlice(set, get),
1573
- history: createHistorySlice(set, get),
1574
- nodes: createNodesSlice(set, get),
1575
- permissions: createPermissionsSlice(set, get),
1576
- getComponentConfig: (type) => {
1577
- var _a;
1578
- const { config, selectedItem } = get();
1579
- const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1580
- return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1581
- },
1582
- dispatch: (action) => set((s) => {
1583
- var _a, _b;
1584
- const { record } = get().history;
1585
- const dispatch = createReducer({
1586
- record,
1587
- appStore: s
1588
- });
1589
- const state = dispatch(s.state, action);
1590
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1591
- (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1592
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1593
- }),
1594
- setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1595
- setStatus: (status) => set({ status }),
1596
- setComponentState: (componentState) => set({ componentState }),
1597
- pendingComponentLoads: {},
1598
- setComponentLoading: (id, loading = true, defer = 0) => {
1599
- const { setComponentState, pendingComponentLoads } = get();
1600
- const thisPendingComponentLoads = __spreadValues({}, pendingComponentLoads);
1601
- const setLoading = () => {
1602
- var _a;
1603
- const { componentState } = get();
1604
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1605
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1606
- loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1607
- })
1608
- }));
1609
- };
1610
- const unsetLoading = () => {
1611
- var _a;
1612
- const { componentState } = get();
1613
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1614
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1615
- loadingCount: Math.max(
1616
- (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1617
- 0
1618
- )
1701
+ subscribeWithSelector((set, get) => {
1702
+ var _a, _b;
1703
+ return __spreadProps(__spreadValues({
1704
+ state: defaultAppState,
1705
+ config: { components: {} },
1706
+ componentState: {},
1707
+ plugins: [],
1708
+ overrides: {},
1709
+ viewports: defaultViewports,
1710
+ zoomConfig: {
1711
+ autoZoom: 1,
1712
+ rootHeight: 0,
1713
+ zoom: 1
1714
+ },
1715
+ status: "LOADING",
1716
+ iframe: {},
1717
+ metadata: {}
1718
+ }, initialAppStore), {
1719
+ fields: createFieldsSlice(set, get),
1720
+ history: createHistorySlice(set, get),
1721
+ nodes: createNodesSlice(set, get),
1722
+ permissions: createPermissionsSlice(set, get),
1723
+ getComponentConfig: (type) => {
1724
+ var _a2;
1725
+ const { config, selectedItem } = get();
1726
+ const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
1727
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1728
+ },
1729
+ selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
1730
+ (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
1731
+ initialAppStore.state
1732
+ ) : null,
1733
+ dispatch: (action) => set((s) => {
1734
+ var _a2, _b2;
1735
+ const { record } = get().history;
1736
+ const dispatch = createReducer({
1737
+ record,
1738
+ appStore: s
1739
+ });
1740
+ const state = dispatch(s.state, action);
1741
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1742
+ (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
1743
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1744
+ }),
1745
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1746
+ setStatus: (status) => set({ status }),
1747
+ setComponentState: (componentState) => set({ componentState }),
1748
+ pendingLoadTimeouts: {},
1749
+ setComponentLoading: (id, loading = true, defer = 0) => {
1750
+ const { setComponentState, pendingLoadTimeouts } = get();
1751
+ const loadId = generateId();
1752
+ const setLoading = () => {
1753
+ var _a2;
1754
+ const { componentState } = get();
1755
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1756
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1757
+ loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
1758
+ })
1759
+ }));
1760
+ };
1761
+ const unsetLoading = () => {
1762
+ var _a2;
1763
+ const { componentState } = get();
1764
+ clearTimeout(timeout);
1765
+ delete pendingLoadTimeouts[loadId];
1766
+ set({ pendingLoadTimeouts });
1767
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1768
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1769
+ loadingCount: Math.max(
1770
+ (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
1771
+ 0
1772
+ )
1773
+ })
1774
+ }));
1775
+ };
1776
+ const timeout = setTimeout(() => {
1777
+ if (loading) {
1778
+ setLoading();
1779
+ } else {
1780
+ unsetLoading();
1781
+ }
1782
+ delete pendingLoadTimeouts[loadId];
1783
+ set({ pendingLoadTimeouts });
1784
+ }, defer);
1785
+ set({
1786
+ pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
1787
+ [id]: timeout
1619
1788
  })
1620
- }));
1621
- };
1622
- if (thisPendingComponentLoads[id]) {
1623
- clearTimeout(thisPendingComponentLoads[id]);
1624
- delete thisPendingComponentLoads[id];
1625
- set({ pendingComponentLoads: thisPendingComponentLoads });
1626
- }
1627
- const timeout = setTimeout(() => {
1628
- if (loading) {
1629
- setLoading();
1630
- } else {
1631
- unsetLoading();
1632
- }
1633
- delete thisPendingComponentLoads[id];
1634
- set({ pendingComponentLoads: thisPendingComponentLoads });
1635
- }, defer);
1636
- set({
1637
- pendingComponentLoads: __spreadProps(__spreadValues({}, thisPendingComponentLoads), {
1638
- [id]: timeout
1639
- })
1640
- });
1641
- },
1642
- unsetComponentLoading: (id) => {
1643
- const { setComponentLoading } = get();
1644
- setComponentLoading(id, false);
1645
- },
1646
- // Helper
1647
- setUi: (ui, recordHistory) => set((s) => {
1648
- const dispatch = createReducer({
1649
- record: () => {
1650
- },
1651
- appStore: s
1652
- });
1653
- const state = dispatch(s.state, {
1654
- type: "setUi",
1655
- ui,
1656
- recordHistory
1657
- });
1658
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1659
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1660
- }),
1661
- // resolveDataRuns: 0,
1662
- // resolveData: (newAppState) =>
1663
- // set((s) => {
1664
- // resolveData(newAppState, get);
1665
- // return { ...s, resolveDataRuns: s.resolveDataRuns + 1 };
1666
- // }),
1667
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1668
- const { config, metadata, setComponentLoading } = get();
1669
- return yield resolveComponentData(
1670
- componentData,
1671
- config,
1672
- metadata,
1673
- (item) => setComponentLoading(
1674
- "id" in item.props ? item.props.id : "root",
1675
- true,
1676
- 50
1677
- ),
1678
- (item) => setComponentLoading(
1679
- "id" in item.props ? item.props.id : "root",
1680
- false,
1681
- 0
1682
- ),
1683
- trigger
1684
- );
1685
- }),
1686
- resolveAndCommitData: () => __async(void 0, null, function* () {
1687
- const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1688
- walkTree(
1689
- state,
1690
- config,
1691
- (content) => content,
1692
- (childItem) => {
1693
- resolveComponentData2(childItem, "load").then((resolved) => {
1694
- const { state: state2 } = get();
1695
- const node = state2.indexes.nodes[resolved.node.props.id];
1696
- if (node && resolved.didChange) {
1697
- if (resolved.node.props.id === "root") {
1698
- dispatch({
1699
- type: "replaceRoot",
1700
- root: toRoot(resolved.node)
1701
- });
1702
- } else {
1703
- const zoneCompound = `${node.parentId}:${node.zone}`;
1704
- const parentZone = state2.indexes.zones[zoneCompound];
1705
- const index = parentZone.contentIds.indexOf(
1706
- resolved.node.props.id
1707
- );
1708
- dispatch({
1709
- type: "replace",
1710
- data: resolved.node,
1711
- destinationIndex: index,
1712
- destinationZone: zoneCompound
1713
- });
1714
- }
1789
+ });
1790
+ return unsetLoading;
1791
+ },
1792
+ unsetComponentLoading: (id) => {
1793
+ const { setComponentLoading } = get();
1794
+ setComponentLoading(id, false);
1795
+ },
1796
+ // Helper
1797
+ setUi: (ui, recordHistory) => set((s) => {
1798
+ const dispatch = createReducer({
1799
+ record: () => {
1800
+ },
1801
+ appStore: s
1802
+ });
1803
+ const state = dispatch(s.state, {
1804
+ type: "setUi",
1805
+ ui,
1806
+ recordHistory
1807
+ });
1808
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1809
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1810
+ }),
1811
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1812
+ const { config, metadata, setComponentLoading, permissions } = get();
1813
+ const timeouts = {};
1814
+ return yield resolveComponentData(
1815
+ componentData,
1816
+ config,
1817
+ metadata,
1818
+ (item) => {
1819
+ const id = "id" in item.props ? item.props.id : "root";
1820
+ timeouts[id] = setComponentLoading(id, true, 50);
1821
+ },
1822
+ (item) => __async(void 0, null, function* () {
1823
+ const id = "id" in item.props ? item.props.id : "root";
1824
+ if ("type" in item) {
1825
+ yield permissions.refreshPermissions({ item });
1826
+ } else {
1827
+ yield permissions.refreshPermissions({ root: true });
1715
1828
  }
1716
- });
1717
- return childItem;
1718
- }
1719
- );
1720
- })
1721
- }))
1829
+ timeouts[id]();
1830
+ }),
1831
+ trigger
1832
+ );
1833
+ }),
1834
+ resolveAndCommitData: () => __async(void 0, null, function* () {
1835
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1836
+ walkAppState(
1837
+ state,
1838
+ config,
1839
+ (content) => content,
1840
+ (childItem) => {
1841
+ resolveComponentData2(childItem, "load").then((resolved) => {
1842
+ const { state: state2 } = get();
1843
+ const node = state2.indexes.nodes[resolved.node.props.id];
1844
+ if (node && resolved.didChange) {
1845
+ if (resolved.node.props.id === "root") {
1846
+ dispatch({
1847
+ type: "replaceRoot",
1848
+ root: toRoot(resolved.node)
1849
+ });
1850
+ } else {
1851
+ const zoneCompound = `${node.parentId}:${node.zone}`;
1852
+ const parentZone = state2.indexes.zones[zoneCompound];
1853
+ const index = parentZone.contentIds.indexOf(
1854
+ resolved.node.props.id
1855
+ );
1856
+ dispatch({
1857
+ type: "replace",
1858
+ data: resolved.node,
1859
+ destinationIndex: index,
1860
+ destinationZone: zoneCompound
1861
+ });
1862
+ }
1863
+ }
1864
+ });
1865
+ return childItem;
1866
+ }
1867
+ );
1868
+ })
1869
+ });
1870
+ })
1722
1871
  );
1723
1872
  var appStoreContext = createContext(createAppStore());
1724
1873
  function useAppStore(selector) {
@@ -1780,10 +1929,10 @@ init_react_import();
1780
1929
  // ../core/lib/filter.ts
1781
1930
  init_react_import();
1782
1931
 
1783
- // ../core/lib/reorder.ts
1932
+ // ../core/lib/data/reorder.ts
1784
1933
  init_react_import();
1785
1934
 
1786
- // ../core/lib/replace.ts
1935
+ // ../core/lib/data/replace.ts
1787
1936
  init_react_import();
1788
1937
 
1789
1938
  // css-module:/home/runner/work/puck/puck/packages/core/components/Loader/styles.module.css#css-module
@@ -1969,15 +2118,37 @@ var HeadingAnalyzer = () => {
1969
2118
  const [hierarchy, setHierarchy] = useState([]);
1970
2119
  useEffect5(() => {
1971
2120
  const frame = getFrame();
1972
- const entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
1973
- if (!entry) return;
1974
- setHierarchy(buildHierarchy(entry));
1975
- const observer = new MutationObserver(() => {
2121
+ let entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2122
+ const createHierarchy = () => {
1976
2123
  setHierarchy(buildHierarchy(entry));
2124
+ };
2125
+ const entryObserver = new MutationObserver(() => {
2126
+ createHierarchy();
2127
+ });
2128
+ const frameObserver = new MutationObserver(() => {
2129
+ entry = frame == null ? void 0 : frame.querySelector(`[data-puck-entry]`);
2130
+ if (entry) {
2131
+ registerEntryObserver();
2132
+ frameObserver.disconnect();
2133
+ }
1977
2134
  });
1978
- observer.observe(entry, { subtree: true, childList: true });
2135
+ const registerEntryObserver = () => {
2136
+ if (!entry) return;
2137
+ entryObserver.observe(entry, { subtree: true, childList: true });
2138
+ };
2139
+ const registerFrameObserver = () => {
2140
+ if (!frame) return;
2141
+ frameObserver.observe(frame, { subtree: true, childList: true });
2142
+ };
2143
+ if (entry) {
2144
+ createHierarchy();
2145
+ registerEntryObserver();
2146
+ } else {
2147
+ registerFrameObserver();
2148
+ }
1979
2149
  return () => {
1980
- observer.disconnect();
2150
+ entryObserver.disconnect();
2151
+ frameObserver.disconnect();
1981
2152
  };
1982
2153
  }, [data]);
1983
2154
  return /* @__PURE__ */ jsxs2("div", { className: getClassName5(), children: [