@measured/puck 0.19.0-canary.f96dc87b → 0.19.0-canary.fb0e8e24

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
@@ -1,4 +1,6 @@
1
1
  import {
2
+ SlotRender,
3
+ SlotRenderPure,
2
4
  __async,
3
5
  __commonJS,
4
6
  __objRest,
@@ -8,17 +10,20 @@ import {
8
10
  __spreadProps,
9
11
  __spreadValues,
10
12
  __toESM,
13
+ createIsSlotConfig,
11
14
  getChanged,
12
15
  init_react_import,
16
+ isSlot,
13
17
  resolveAllData,
14
18
  resolveComponentData,
15
- resolveRootData,
16
19
  rootAreaId,
17
20
  rootDroppableId,
18
21
  rootZone,
19
22
  setupZone,
20
- transformProps
21
- } from "./chunk-7N5DRY4G.mjs";
23
+ transformProps,
24
+ useSlots,
25
+ walkTree
26
+ } from "./chunk-COT3ZFIM.mjs";
22
27
 
23
28
  // ../../node_modules/classnames/index.js
24
29
  var require_classnames = __commonJS({
@@ -207,13 +212,13 @@ init_react_import();
207
212
 
208
213
  // css-module:/home/runner/work/puck/puck/packages/core/components/AutoField/styles.module.css#css-module
209
214
  init_react_import();
210
- var styles_module_default2 = { "InputWrapper": "_InputWrapper_g5w3n_1", "Input-label": "_Input-label_g5w3n_5", "Input-labelIcon": "_Input-labelIcon_g5w3n_14", "Input-disabledIcon": "_Input-disabledIcon_g5w3n_21", "Input-input": "_Input-input_g5w3n_26", "Input": "_Input_g5w3n_1", "Input--readOnly": "_Input--readOnly_g5w3n_74", "Input-radioGroupItems": "_Input-radioGroupItems_g5w3n_85", "Input-radio": "_Input-radio_g5w3n_85", "Input-radioInner": "_Input-radioInner_g5w3n_102", "Input-radioInput": "_Input-radioInput_g5w3n_147" };
215
+ var styles_module_default2 = { "InputWrapper": "_InputWrapper_4xor1_1", "Input-label": "_Input-label_4xor1_5", "Input-labelIcon": "_Input-labelIcon_4xor1_14", "Input-disabledIcon": "_Input-disabledIcon_4xor1_21", "Input-input": "_Input-input_4xor1_26", "Input": "_Input_4xor1_1", "Input--readOnly": "_Input--readOnly_4xor1_75", "Input-radioGroupItems": "_Input-radioGroupItems_4xor1_86", "Input-radio": "_Input-radio_4xor1_86", "Input-radioInner": "_Input-radioInner_4xor1_103", "Input-radioInput": "_Input-radioInput_4xor1_148" };
211
216
 
212
217
  // components/AutoField/index.tsx
213
218
  import {
214
219
  useCallback as useCallback4,
215
220
  useContext as useContext3,
216
- useEffect as useEffect11,
221
+ useEffect as useEffect10,
217
222
  useMemo as useMemo5,
218
223
  useState as useState8
219
224
  } from "react";
@@ -575,7 +580,7 @@ init_react_import();
575
580
  // lib/filter.ts
576
581
  init_react_import();
577
582
 
578
- // lib/reorder.ts
583
+ // lib/data/reorder.ts
579
584
  init_react_import();
580
585
  var reorder = (list, startIndex, endIndex) => {
581
586
  const result = Array.from(list);
@@ -584,7 +589,7 @@ var reorder = (list, startIndex, endIndex) => {
584
589
  return result;
585
590
  };
586
591
 
587
- // lib/replace.ts
592
+ // lib/data/replace.ts
588
593
  init_react_import();
589
594
  var replace = (list, index, newItem) => {
590
595
  const result = Array.from(list);
@@ -676,7 +681,7 @@ var IconButton = ({
676
681
  };
677
682
 
678
683
  // components/AutoField/fields/ArrayField/index.tsx
679
- import { useCallback as useCallback2, useEffect as useEffect6, useRef, useState as useState3 } from "react";
684
+ import { useCallback as useCallback2, useEffect as useEffect5, useRef, useState as useState3 } from "react";
680
685
 
681
686
  // components/DragIcon/index.tsx
682
687
  init_react_import();
@@ -696,44 +701,37 @@ init_react_import();
696
701
  // reducer/index.ts
697
702
  init_react_import();
698
703
 
699
- // reducer/data.ts
700
- init_react_import();
701
-
702
- // lib/insert.ts
704
+ // reducer/actions/set.ts
703
705
  init_react_import();
704
- var insert = (list, index, item) => {
705
- const result = Array.from(list);
706
- result.splice(index, 0, item);
707
- return result;
708
- };
709
706
 
710
- // lib/remove.ts
707
+ // lib/data/walk-app-state.ts
711
708
  init_react_import();
712
- var remove = (list, index) => {
713
- const result = Array.from(list);
714
- result.splice(index, 1);
715
- return result;
716
- };
717
709
 
718
- // lib/get-item.ts
710
+ // lib/data/for-each-slot.ts
719
711
  init_react_import();
720
- function getItem(selector, data, dynamicProps = {}) {
721
- if (!selector.zone || selector.zone === rootDroppableId) {
722
- const item2 = data.content[selector.index];
723
- return (item2 == null ? void 0 : item2.props) ? __spreadProps(__spreadValues({}, item2), { props: dynamicProps[item2.props.id] || item2.props }) : void 0;
712
+ var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
713
+ const props = item.props || {};
714
+ const propKeys = Object.keys(props);
715
+ for (let i = 0; i < propKeys.length; i++) {
716
+ const propKey = propKeys[i];
717
+ const itemType = "type" in item ? item.type : "root";
718
+ if (isSlot2(itemType, propKey, props[propKey])) {
719
+ const content = props[propKey];
720
+ cb(props.id, propKey, content);
721
+ if (recursive) {
722
+ content.forEach(
723
+ (childItem) => __async(void 0, null, function* () {
724
+ return forEachSlot(childItem, cb, true, isSlot2);
725
+ })
726
+ );
727
+ }
728
+ }
724
729
  }
725
- const item = setupZone(data, selector.zone).zones[selector.zone][selector.index];
726
- return (item == null ? void 0 : item.props) ? __spreadProps(__spreadValues({}, item), { props: dynamicProps[item.props.id] || item.props }) : void 0;
727
- }
730
+ };
728
731
 
729
- // lib/reduce-related-zones.ts
732
+ // lib/data/for-related-zones.ts
730
733
  init_react_import();
731
734
 
732
- // lib/generate-id.ts
733
- init_react_import();
734
- import { v4 as uuidv4 } from "uuid";
735
- var generateId = (type) => type ? `${type}-${uuidv4()}` : uuidv4();
736
-
737
735
  // lib/get-zone-id.ts
738
736
  init_react_import();
739
737
  var getZoneId = (zoneCompound) => {
@@ -746,301 +744,566 @@ var getZoneId = (zoneCompound) => {
746
744
  return [rootDroppableId, zoneCompound];
747
745
  };
748
746
 
749
- // lib/reduce-related-zones.ts
750
- function reduceRelatedZones(item, data, fn) {
747
+ // lib/data/for-related-zones.ts
748
+ function forRelatedZones(item, data, cb, path = []) {
749
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
750
+ const [parentId] = getZoneId(zoneCompound);
751
+ if (parentId === item.props.id) {
752
+ cb(path, zoneCompound, content);
753
+ }
754
+ });
755
+ }
756
+
757
+ // lib/data/strip-slots.ts
758
+ init_react_import();
759
+ var stripSlots = (data) => {
751
760
  return __spreadProps(__spreadValues({}, data), {
752
- zones: Object.keys(data.zones || {}).reduce(
753
- (acc, key) => {
754
- const [parentId] = getZoneId(key);
755
- if (parentId === item.props.id) {
756
- const zones = data.zones;
757
- return fn(acc, key, zones[key]);
761
+ props: Object.entries(data.props).reduce(
762
+ (acc, [propKey, propVal]) => {
763
+ if (isSlot(propVal)) {
764
+ return acc;
758
765
  }
759
- return __spreadProps(__spreadValues({}, acc), { [key]: data.zones[key] });
766
+ return __spreadProps(__spreadValues({}, acc), { [propKey]: propVal });
760
767
  },
761
- {}
768
+ { id: data.props.id }
762
769
  )
763
770
  });
771
+ };
772
+
773
+ // lib/data/walk-app-state.ts
774
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
775
+ var _a;
776
+ let newZones = {};
777
+ const newZoneIndex = {};
778
+ const newNodeIndex = {};
779
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
780
+ var _a2;
781
+ const [parentId] = zoneCompound.split(":");
782
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
783
+ const [_2, zone] = zoneCompound.split(":");
784
+ const newZoneCompound = `${newId || parentId}:${zone}`;
785
+ const newContent2 = mappedContent.map(
786
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
787
+ );
788
+ newZoneIndex[newZoneCompound] = {
789
+ contentIds: newContent2.map((item) => item.props.id),
790
+ type: zoneType
791
+ };
792
+ return [newZoneCompound, newContent2];
793
+ };
794
+ const processRelatedZones = (item, newId, initialPath) => {
795
+ forRelatedZones(
796
+ item,
797
+ state.data,
798
+ (relatedPath, relatedZoneCompound, relatedContent) => {
799
+ const [zoneCompound, newContent2] = processContent(
800
+ relatedPath,
801
+ relatedZoneCompound,
802
+ relatedContent,
803
+ "dropzone",
804
+ newId
805
+ );
806
+ newZones[zoneCompound] = newContent2;
807
+ },
808
+ initialPath
809
+ );
810
+ };
811
+ const processItem = (item, path, index) => {
812
+ const mappedItem = mapNodeOrSkip(item, path, index);
813
+ if (!mappedItem) return item;
814
+ const id = mappedItem.props.id;
815
+ const newProps = __spreadValues({}, mappedItem.props);
816
+ forEachSlot(
817
+ mappedItem,
818
+ (parentId2, slotId, content) => {
819
+ const zoneCompound = `${parentId2}:${slotId}`;
820
+ const [_2, newContent2] = processContent(
821
+ path,
822
+ zoneCompound,
823
+ content,
824
+ "slot",
825
+ parentId2
826
+ );
827
+ newProps[slotId] = newContent2;
828
+ },
829
+ false,
830
+ createIsSlotConfig(config)
831
+ );
832
+ processRelatedZones(item, id, path);
833
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
834
+ const thisZoneCompound = path[path.length - 1];
835
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
836
+ newNodeIndex[id] = {
837
+ data: newItem,
838
+ flatData: stripSlots(newItem),
839
+ path,
840
+ parentId,
841
+ zone
842
+ };
843
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
844
+ if (newProps.id === "root") {
845
+ delete finalData["type"];
846
+ delete finalData.props["id"];
847
+ }
848
+ return finalData;
849
+ };
850
+ const zones = state.data.zones || {};
851
+ const [_, newContent] = processContent(
852
+ [],
853
+ rootDroppableId,
854
+ state.data.content,
855
+ "root"
856
+ );
857
+ const processedContent = newContent;
858
+ const zonesAlreadyProcessed = Object.keys(newZones);
859
+ Object.keys(zones || {}).forEach((zoneCompound) => {
860
+ const [parentId] = zoneCompound.split(":");
861
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
862
+ return;
863
+ }
864
+ const [_2, newContent2] = processContent(
865
+ [rootDroppableId],
866
+ zoneCompound,
867
+ zones[zoneCompound],
868
+ "dropzone",
869
+ parentId
870
+ );
871
+ newZones[zoneCompound] = newContent2;
872
+ }, newZones);
873
+ const processedRoot = processItem(
874
+ {
875
+ type: "root",
876
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
877
+ },
878
+ [],
879
+ -1
880
+ );
881
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
882
+ props: processedRoot.props
883
+ });
884
+ return __spreadProps(__spreadValues({}, state), {
885
+ data: {
886
+ root,
887
+ content: processedContent,
888
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
889
+ },
890
+ indexes: {
891
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
892
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
893
+ }
894
+ });
895
+ }
896
+
897
+ // reducer/actions/set.ts
898
+ var setAction = (state, action, appStore) => {
899
+ if (typeof action.state === "object") {
900
+ const newState = __spreadValues(__spreadValues({}, state), action.state);
901
+ if (action.state.indexes) {
902
+ return newState;
903
+ }
904
+ console.warn(
905
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
906
+ );
907
+ return walkAppState(newState, appStore.config);
908
+ }
909
+ return __spreadValues(__spreadValues({}, state), action.state(state));
910
+ };
911
+
912
+ // reducer/actions/insert.ts
913
+ init_react_import();
914
+
915
+ // lib/data/insert.ts
916
+ init_react_import();
917
+ var insert = (list, index, item) => {
918
+ const result = Array.from(list || []);
919
+ result.splice(index, 0, item);
920
+ return result;
921
+ };
922
+
923
+ // lib/generate-id.ts
924
+ init_react_import();
925
+ import { v4 as uuidv4 } from "uuid";
926
+ var generateId = (type) => type ? `${type}-${uuidv4()}` : uuidv4();
927
+
928
+ // lib/data/get-ids-for-parent.ts
929
+ init_react_import();
930
+ var getIdsForParent = (zoneCompound, state) => {
931
+ const [parentId] = zoneCompound.split(":");
932
+ const node = state.indexes.nodes[parentId];
933
+ return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
934
+ };
935
+
936
+ // lib/data/populate-ids.ts
937
+ init_react_import();
938
+ var populateIds = (data, config, override = false) => {
939
+ const id = generateId(data.type);
940
+ return walkTree(
941
+ __spreadProps(__spreadValues({}, data), {
942
+ props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({ id }, data.props)
943
+ }),
944
+ config,
945
+ (contents) => contents.map((item) => {
946
+ const id2 = generateId(item.type);
947
+ return __spreadProps(__spreadValues({}, item), {
948
+ props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
949
+ });
950
+ })
951
+ );
952
+ };
953
+
954
+ // reducer/actions/insert.ts
955
+ function insertAction(state, action, appStore) {
956
+ const id = action.id || generateId(action.componentType);
957
+ const emptyComponentData = populateIds(
958
+ {
959
+ type: action.componentType,
960
+ props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
961
+ id
962
+ })
963
+ },
964
+ appStore.config
965
+ );
966
+ const [parentId] = action.destinationZone.split(":");
967
+ const idsInPath = getIdsForParent(action.destinationZone, state);
968
+ return walkAppState(
969
+ state,
970
+ appStore.config,
971
+ (content, zoneCompound) => {
972
+ if (zoneCompound === action.destinationZone) {
973
+ return insert(
974
+ content || [],
975
+ action.destinationIndex,
976
+ emptyComponentData
977
+ );
978
+ }
979
+ return content;
980
+ },
981
+ (childItem, path) => {
982
+ if (childItem.props.id === id || childItem.props.id === parentId) {
983
+ return childItem;
984
+ } else if (idsInPath.includes(childItem.props.id)) {
985
+ return childItem;
986
+ } else if (path.includes(action.destinationZone)) {
987
+ return childItem;
988
+ }
989
+ return null;
990
+ }
991
+ );
764
992
  }
765
- var findRelatedByZoneId = (zoneId, data) => {
766
- const [zoneParentId] = getZoneId(zoneId);
767
- return (data.zones[zoneId] || []).reduce(
768
- (acc, zoneItem) => {
769
- const related = findRelatedByItem(zoneItem, data);
770
- if (zoneItem.props.id === zoneParentId) {
771
- return __spreadProps(__spreadValues(__spreadValues({}, acc), related), { [zoneId]: zoneItem });
993
+
994
+ // reducer/actions/replace.ts
995
+ init_react_import();
996
+ var replaceAction = (state, action, appStore) => {
997
+ const [parentId] = action.destinationZone.split(":");
998
+ const idsInPath = getIdsForParent(action.destinationZone, state);
999
+ const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
1000
+ const idChanged = originalId !== action.data.props.id;
1001
+ if (idChanged) {
1002
+ throw new Error(
1003
+ `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
1004
+ );
1005
+ }
1006
+ const data = populateIds(action.data, appStore.config);
1007
+ return walkAppState(
1008
+ state,
1009
+ appStore.config,
1010
+ (content, zoneCompound) => {
1011
+ const newContent = [...content];
1012
+ if (zoneCompound === action.destinationZone) {
1013
+ newContent[action.destinationIndex] = data;
772
1014
  }
773
- return __spreadValues(__spreadValues({}, acc), related);
1015
+ return newContent;
774
1016
  },
775
- {}
1017
+ (childItem, path) => {
1018
+ const pathIds = path.map((p) => p.split(":")[0]);
1019
+ if (childItem.props.id === data.props.id) {
1020
+ return data;
1021
+ } else if (childItem.props.id === parentId) {
1022
+ return childItem;
1023
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
1024
+ return childItem;
1025
+ } else if (pathIds.indexOf(data.props.id) > -1) {
1026
+ return childItem;
1027
+ }
1028
+ return null;
1029
+ }
776
1030
  );
777
1031
  };
778
- var findRelatedByItem = (item, data) => {
779
- return Object.keys(data.zones || {}).reduce(
780
- (acc, zoneId) => {
781
- const [zoneParentId] = getZoneId(zoneId);
782
- if (item.props.id === zoneParentId) {
783
- const related = findRelatedByZoneId(zoneId, data);
784
- return __spreadProps(__spreadValues(__spreadValues({}, acc), related), {
785
- [zoneId]: data.zones[zoneId]
1032
+
1033
+ // reducer/actions/replace-root.ts
1034
+ init_react_import();
1035
+ var replaceRootAction = (state, action, appStore) => {
1036
+ return walkAppState(
1037
+ state,
1038
+ appStore.config,
1039
+ (content) => content,
1040
+ (childItem) => {
1041
+ if (childItem.props.id === "root") {
1042
+ return __spreadProps(__spreadValues({}, childItem), {
1043
+ props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
1044
+ readOnly: action.root.readOnly
786
1045
  });
787
1046
  }
788
- return acc;
789
- },
790
- {}
1047
+ return childItem;
1048
+ }
791
1049
  );
792
1050
  };
793
- var removeRelatedZones = (item, data) => {
794
- const newData = __spreadValues({}, data);
795
- const related = findRelatedByItem(item, data);
796
- Object.keys(related).forEach((key) => {
797
- delete newData.zones[key];
798
- });
799
- return newData;
800
- };
801
- function duplicateRelatedZones(item, data, newId) {
802
- return reduceRelatedZones(item, data, (acc, key, zone) => {
803
- const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
804
- props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
805
- }));
806
- const dupeOfDupes = dupedZone.reduce(
807
- (dupeOfDupes2, item2, index) => __spreadValues(__spreadValues({}, dupeOfDupes2), duplicateRelatedZones(zone[index], data, item2.props.id).zones),
808
- acc
809
- );
810
- const [_, zoneId] = getZoneId(key);
811
- return __spreadProps(__spreadValues({}, dupeOfDupes), {
812
- [key]: zone,
813
- [`${newId}:${zoneId}`]: dupedZone
814
- });
815
- });
1051
+
1052
+ // reducer/actions/duplicate.ts
1053
+ init_react_import();
1054
+
1055
+ // lib/data/get-item.ts
1056
+ init_react_import();
1057
+ function getItem(selector, state) {
1058
+ var _a, _b;
1059
+ const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
1060
+ return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
816
1061
  }
817
1062
 
818
- // reducer/data.ts
819
- var zoneCache = {};
820
- var replaceAction = (data, action) => {
821
- if (action.destinationZone === rootDroppableId) {
822
- return __spreadProps(__spreadValues({}, data), {
823
- content: replace(data.content, action.destinationIndex, action.data)
824
- });
825
- }
826
- const newData = setupZone(data, action.destinationZone);
827
- return __spreadProps(__spreadValues({}, newData), {
828
- zones: __spreadProps(__spreadValues({}, newData.zones), {
829
- [action.destinationZone]: replace(
830
- newData.zones[action.destinationZone],
831
- action.destinationIndex,
832
- action.data
833
- )
1063
+ // reducer/actions/duplicate.ts
1064
+ function duplicateAction(state, action, appStore) {
1065
+ const item = getItem(
1066
+ { index: action.sourceIndex, zone: action.sourceZone },
1067
+ state
1068
+ );
1069
+ const idsInPath = getIdsForParent(action.sourceZone, state);
1070
+ const newItem = __spreadProps(__spreadValues({}, item), {
1071
+ props: __spreadProps(__spreadValues({}, item.props), {
1072
+ id: generateId(item.type)
834
1073
  })
835
1074
  });
836
- };
837
- function insertAction(data, action, config) {
838
- const emptyComponentData = {
839
- type: action.componentType,
840
- props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
841
- id: action.id || generateId(action.componentType)
842
- })
843
- };
844
- if (action.destinationZone === rootDroppableId) {
845
- return __spreadProps(__spreadValues({}, data), {
846
- content: insert(
847
- data.content,
848
- action.destinationIndex,
849
- emptyComponentData
850
- )
851
- });
852
- }
853
- const newData = setupZone(data, action.destinationZone);
854
- return __spreadProps(__spreadValues({}, data), {
855
- zones: __spreadProps(__spreadValues({}, newData.zones), {
856
- [action.destinationZone]: insert(
857
- newData.zones[action.destinationZone],
858
- action.destinationIndex,
859
- emptyComponentData
860
- )
1075
+ const modified = walkAppState(
1076
+ state,
1077
+ appStore.config,
1078
+ (content, zoneCompound) => {
1079
+ if (zoneCompound === action.sourceZone) {
1080
+ return insert(content, action.sourceIndex + 1, item);
1081
+ }
1082
+ return content;
1083
+ },
1084
+ (childItem, path, index) => {
1085
+ const zoneCompound = path[path.length - 1];
1086
+ const parents = path.map((p) => p.split(":")[0]);
1087
+ if (parents.indexOf(newItem.props.id) > -1) {
1088
+ return __spreadProps(__spreadValues({}, childItem), {
1089
+ props: __spreadProps(__spreadValues({}, childItem.props), {
1090
+ id: generateId(childItem.type)
1091
+ })
1092
+ });
1093
+ }
1094
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
1095
+ return newItem;
1096
+ }
1097
+ const [sourceZoneParent] = action.sourceZone.split(":");
1098
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
1099
+ return childItem;
1100
+ }
1101
+ return null;
1102
+ }
1103
+ );
1104
+ return __spreadProps(__spreadValues({}, modified), {
1105
+ ui: __spreadProps(__spreadValues({}, modified.ui), {
1106
+ itemSelector: {
1107
+ index: action.sourceIndex + 1,
1108
+ zone: action.sourceZone
1109
+ }
861
1110
  })
862
1111
  });
863
1112
  }
864
- var reorderAction = (data, action) => {
865
- if (action.destinationZone === rootDroppableId) {
866
- return __spreadProps(__spreadValues({}, data), {
867
- content: reorder(
868
- data.content,
869
- action.sourceIndex,
870
- action.destinationIndex
871
- )
872
- });
873
- }
874
- const newData = setupZone(data, action.destinationZone);
875
- return __spreadProps(__spreadValues({}, data), {
876
- zones: __spreadProps(__spreadValues({}, newData.zones), {
877
- [action.destinationZone]: reorder(
878
- newData.zones[action.destinationZone],
879
- action.sourceIndex,
880
- action.destinationIndex
881
- )
882
- })
883
- });
1113
+
1114
+ // reducer/actions/reorder.ts
1115
+ init_react_import();
1116
+
1117
+ // reducer/actions/move.ts
1118
+ init_react_import();
1119
+
1120
+ // lib/data/remove.ts
1121
+ init_react_import();
1122
+ var remove = (list, index) => {
1123
+ const result = Array.from(list);
1124
+ result.splice(index, 1);
1125
+ return result;
884
1126
  };
885
- function reduceData(data, action, config) {
886
- if (action.type === "insert") {
887
- return insertAction(data, action, config);
888
- }
889
- if (action.type === "duplicate") {
890
- const item = getItem(
891
- { index: action.sourceIndex, zone: action.sourceZone },
892
- data
893
- );
894
- const newItem = __spreadProps(__spreadValues({}, item), {
895
- props: __spreadProps(__spreadValues({}, item.props), {
896
- id: generateId(item.type)
897
- })
898
- });
899
- const dataWithRelatedDuplicated = duplicateRelatedZones(
900
- item,
901
- data,
902
- newItem.props.id
903
- );
904
- if (action.sourceZone === rootDroppableId) {
905
- return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
906
- content: insert(data.content, action.sourceIndex + 1, newItem)
907
- });
908
- }
909
- return __spreadProps(__spreadValues({}, dataWithRelatedDuplicated), {
910
- zones: __spreadProps(__spreadValues({}, dataWithRelatedDuplicated.zones), {
911
- [action.sourceZone]: insert(
912
- dataWithRelatedDuplicated.zones[action.sourceZone],
913
- action.sourceIndex + 1,
914
- newItem
915
- )
916
- })
917
- });
918
- }
919
- if (action.type === "reorder") {
920
- return reorderAction(data, action);
1127
+
1128
+ // reducer/actions/move.ts
1129
+ var moveAction = (state, action, appStore) => {
1130
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
1131
+ return state;
921
1132
  }
922
- if (action.type === "move") {
923
- if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
924
- return data;
1133
+ const item = getItem(
1134
+ { zone: action.sourceZone, index: action.sourceIndex },
1135
+ state
1136
+ );
1137
+ if (!item) return state;
1138
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
1139
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
1140
+ return walkAppState(
1141
+ state,
1142
+ appStore.config,
1143
+ (content, zoneCompound) => {
1144
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
1145
+ return insert(
1146
+ remove(content, action.sourceIndex),
1147
+ action.destinationIndex,
1148
+ item
1149
+ );
1150
+ } else if (zoneCompound === action.sourceZone) {
1151
+ return remove(content, action.sourceIndex);
1152
+ } else if (zoneCompound === action.destinationZone) {
1153
+ return insert(content, action.destinationIndex, item);
1154
+ }
1155
+ return content;
1156
+ },
1157
+ (childItem, path) => {
1158
+ const [sourceZoneParent] = action.sourceZone.split(":");
1159
+ const [destinationZoneParent] = action.destinationZone.split(":");
1160
+ const childId = childItem.props.id;
1161
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
1162
+ return childItem;
1163
+ }
1164
+ return null;
925
1165
  }
926
- const newData = setupZone(
927
- setupZone(data, action.sourceZone),
928
- action.destinationZone
929
- );
930
- const item = getItem(
931
- { zone: action.sourceZone, index: action.sourceIndex },
932
- newData
933
- );
934
- if (action.sourceZone === action.destinationZone) {
935
- return reorderAction(data, __spreadProps(__spreadValues({}, action), { type: "reorder" }));
936
- }
937
- if (action.sourceZone === rootDroppableId) {
938
- return __spreadProps(__spreadValues({}, newData), {
939
- content: remove(newData.content, action.sourceIndex),
940
- zones: __spreadProps(__spreadValues({}, newData.zones), {
941
- [action.destinationZone]: insert(
942
- newData.zones[action.destinationZone],
943
- action.destinationIndex,
944
- item
945
- )
946
- })
947
- });
1166
+ );
1167
+ };
1168
+
1169
+ // reducer/actions/reorder.ts
1170
+ var reorderAction = (state, action, appStore) => {
1171
+ return moveAction(
1172
+ state,
1173
+ {
1174
+ type: "move",
1175
+ sourceIndex: action.sourceIndex,
1176
+ sourceZone: action.destinationZone,
1177
+ destinationIndex: action.destinationIndex,
1178
+ destinationZone: action.destinationZone
1179
+ },
1180
+ appStore
1181
+ );
1182
+ };
1183
+
1184
+ // reducer/actions/remove.ts
1185
+ init_react_import();
1186
+ var removeAction = (state, action, appStore) => {
1187
+ const item = getItem({ index: action.index, zone: action.zone }, state);
1188
+ const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
1189
+ (acc, [nodeId, nodeData]) => {
1190
+ const pathIds = nodeData.path.map((p) => p.split(":")[0]);
1191
+ if (pathIds.includes(item.props.id)) {
1192
+ return [...acc, nodeId];
1193
+ }
1194
+ return acc;
1195
+ },
1196
+ [item.props.id]
1197
+ );
1198
+ const newState = walkAppState(
1199
+ state,
1200
+ appStore.config,
1201
+ (content, zoneCompound) => {
1202
+ if (zoneCompound === action.zone) {
1203
+ return remove(content, action.index);
1204
+ }
1205
+ return content;
948
1206
  }
949
- if (action.destinationZone === rootDroppableId) {
950
- return __spreadProps(__spreadValues({}, newData), {
951
- content: insert(newData.content, action.destinationIndex, item),
952
- zones: __spreadProps(__spreadValues({}, newData.zones), {
953
- [action.sourceZone]: remove(
954
- newData.zones[action.sourceZone],
955
- action.sourceIndex
956
- )
957
- })
958
- });
1207
+ );
1208
+ Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
1209
+ const parentId = zoneCompound.split(":")[0];
1210
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
1211
+ delete newState.data.zones[zoneCompound];
959
1212
  }
960
- return __spreadProps(__spreadValues({}, newData), {
961
- zones: __spreadProps(__spreadValues({}, newData.zones), {
962
- [action.sourceZone]: remove(
963
- newData.zones[action.sourceZone],
964
- action.sourceIndex
965
- ),
966
- [action.destinationZone]: insert(
967
- newData.zones[action.destinationZone],
968
- action.destinationIndex,
969
- item
970
- )
971
- })
972
- });
973
- }
974
- if (action.type === "replace") {
975
- return replaceAction(data, action);
976
- }
977
- if (action.type === "remove") {
978
- const item = getItem({ index: action.index, zone: action.zone }, data);
979
- const dataWithRelatedRemoved = setupZone(
980
- removeRelatedZones(item, data),
981
- action.zone
982
- );
983
- if (action.zone === rootDroppableId) {
984
- return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
985
- content: remove(data.content, action.index)
986
- });
1213
+ });
1214
+ Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
1215
+ const parentId = zoneCompound.split(":")[0];
1216
+ if (nodesToDelete.includes(parentId)) {
1217
+ delete newState.indexes.zones[zoneCompound];
987
1218
  }
988
- return __spreadProps(__spreadValues({}, dataWithRelatedRemoved), {
989
- zones: __spreadProps(__spreadValues({}, dataWithRelatedRemoved.zones), {
990
- [action.zone]: remove(
991
- dataWithRelatedRemoved.zones[action.zone],
992
- action.index
993
- )
994
- })
995
- });
996
- }
997
- if (action.type === "registerZone") {
998
- if (zoneCache[action.zone]) {
999
- return __spreadProps(__spreadValues({}, data), {
1000
- zones: __spreadProps(__spreadValues({}, data.zones), {
1219
+ });
1220
+ nodesToDelete.forEach((id) => {
1221
+ delete newState.indexes.nodes[id];
1222
+ });
1223
+ return newState;
1224
+ };
1225
+
1226
+ // reducer/actions/register-zone.ts
1227
+ init_react_import();
1228
+ var zoneCache = {};
1229
+ function registerZoneAction(state, action) {
1230
+ if (zoneCache[action.zone]) {
1231
+ return __spreadProps(__spreadValues({}, state), {
1232
+ data: __spreadProps(__spreadValues({}, state.data), {
1233
+ zones: __spreadProps(__spreadValues({}, state.data.zones), {
1001
1234
  [action.zone]: zoneCache[action.zone]
1002
1235
  })
1003
- });
1004
- }
1005
- return setupZone(data, action.zone);
1006
- }
1007
- if (action.type === "unregisterZone") {
1008
- const _zones = __spreadValues({}, data.zones || {});
1009
- if (_zones[action.zone]) {
1010
- zoneCache[action.zone] = _zones[action.zone];
1011
- delete _zones[action.zone];
1012
- }
1013
- return __spreadProps(__spreadValues({}, data), { zones: _zones });
1236
+ }),
1237
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1238
+ zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
1239
+ [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
1240
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
1241
+ type: "dropzone"
1242
+ })
1243
+ })
1244
+ })
1245
+ });
1014
1246
  }
1015
- if (action.type === "setData") {
1016
- if (typeof action.data === "object") {
1017
- return __spreadValues(__spreadValues({}, data), action.data);
1018
- }
1019
- return __spreadValues(__spreadValues({}, data), action.data(data));
1247
+ return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1248
+ }
1249
+ function unregisterZoneAction(state, action) {
1250
+ const _zones = __spreadValues({}, state.data.zones || {});
1251
+ const zoneIndex = __spreadValues({}, state.indexes.zones || {});
1252
+ if (_zones[action.zone]) {
1253
+ zoneCache[action.zone] = _zones[action.zone];
1254
+ delete _zones[action.zone];
1020
1255
  }
1021
- return data;
1256
+ delete zoneIndex[action.zone];
1257
+ return __spreadProps(__spreadValues({}, state), {
1258
+ data: __spreadProps(__spreadValues({}, state.data), {
1259
+ zones: _zones
1260
+ }),
1261
+ indexes: __spreadProps(__spreadValues({}, state.indexes), {
1262
+ zones: zoneIndex
1263
+ })
1264
+ });
1022
1265
  }
1023
1266
 
1024
- // reducer/state.ts
1267
+ // reducer/actions/set-data.ts
1025
1268
  init_react_import();
1026
- var reduceUi = (ui, action) => {
1027
- if (action.type === "setUi") {
1028
- if (typeof action.ui === "object") {
1029
- return __spreadValues(__spreadValues({}, ui), action.ui);
1030
- }
1031
- return __spreadValues(__spreadValues({}, ui), action.ui(ui));
1032
- }
1033
- if (action.type === "duplicate") {
1034
- return __spreadProps(__spreadValues({}, ui), {
1035
- itemSelector: { index: action.sourceIndex + 1, zone: action.sourceZone }
1036
- });
1269
+ var setDataAction = (state, action, appStore) => {
1270
+ if (typeof action.data === "object") {
1271
+ console.warn(
1272
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1273
+ );
1274
+ return walkAppState(
1275
+ __spreadProps(__spreadValues({}, state), {
1276
+ data: __spreadValues(__spreadValues({}, state.data), action.data)
1277
+ }),
1278
+ appStore.config
1279
+ );
1037
1280
  }
1038
- if (action.type === "remove") {
1039
- return __spreadProps(__spreadValues({}, ui), {
1040
- itemSelector: null
1281
+ return walkAppState(
1282
+ __spreadProps(__spreadValues({}, state), {
1283
+ data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1284
+ }),
1285
+ appStore.config
1286
+ );
1287
+ };
1288
+
1289
+ // reducer/actions/set-ui.ts
1290
+ init_react_import();
1291
+ var setUiAction = (state, action) => {
1292
+ if (typeof action.ui === "object") {
1293
+ return __spreadProps(__spreadValues({}, state), {
1294
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1041
1295
  });
1042
1296
  }
1043
- return ui;
1297
+ return __spreadProps(__spreadValues({}, state), {
1298
+ ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1299
+ });
1300
+ };
1301
+
1302
+ // lib/data/make-state-public.ts
1303
+ init_react_import();
1304
+ var makeStatePublic = (state) => {
1305
+ const { data, ui } = state;
1306
+ return { data, ui };
1044
1307
  };
1045
1308
 
1046
1309
  // reducer/actions.tsx
@@ -1060,29 +1323,54 @@ function storeInterceptor(reducer, record, onAction) {
1060
1323
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1061
1324
  if (record) record(newAppState);
1062
1325
  }
1063
- onAction == null ? void 0 : onAction(action, newAppState, state);
1326
+ onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1064
1327
  return newAppState;
1065
1328
  };
1066
1329
  }
1067
- var setAction = (state, action) => {
1068
- if (typeof action.state === "object") {
1069
- return __spreadValues(__spreadValues({}, state), action.state);
1070
- }
1071
- return __spreadValues(__spreadValues({}, state), action.state(state));
1072
- };
1073
1330
  function createReducer({
1074
- config,
1075
1331
  record,
1076
- onAction
1332
+ onAction,
1333
+ appStore
1077
1334
  }) {
1078
1335
  return storeInterceptor(
1079
1336
  (state, action) => {
1080
- const data = reduceData(state.data, action, config);
1081
- const ui = reduceUi(state.ui, action);
1082
1337
  if (action.type === "set") {
1083
- return setAction(state, action);
1338
+ return setAction(state, action, appStore);
1339
+ }
1340
+ if (action.type === "insert") {
1341
+ return insertAction(state, action, appStore);
1342
+ }
1343
+ if (action.type === "replace") {
1344
+ return replaceAction(state, action, appStore);
1345
+ }
1346
+ if (action.type === "replaceRoot") {
1347
+ return replaceRootAction(state, action, appStore);
1348
+ }
1349
+ if (action.type === "duplicate") {
1350
+ return duplicateAction(state, action, appStore);
1351
+ }
1352
+ if (action.type === "reorder") {
1353
+ return reorderAction(state, action, appStore);
1354
+ }
1355
+ if (action.type === "move") {
1356
+ return moveAction(state, action, appStore);
1357
+ }
1358
+ if (action.type === "remove") {
1359
+ return removeAction(state, action, appStore);
1360
+ }
1361
+ if (action.type === "registerZone") {
1362
+ return registerZoneAction(state, action);
1363
+ }
1364
+ if (action.type === "unregisterZone") {
1365
+ return unregisterZoneAction(state, action);
1366
+ }
1367
+ if (action.type === "setData") {
1368
+ return setDataAction(state, action, appStore);
1084
1369
  }
1085
- return { data, ui };
1370
+ if (action.type === "setUi") {
1371
+ return setUiAction(state, action);
1372
+ }
1373
+ return state;
1086
1374
  },
1087
1375
  record,
1088
1376
  onAction
@@ -1100,128 +1388,6 @@ var defaultViewports = [
1100
1388
  // store/index.ts
1101
1389
  import { create as create2, useStore } from "zustand";
1102
1390
  import { subscribeWithSelector as subscribeWithSelector2 } from "zustand/middleware";
1103
-
1104
- // lib/resolve-data.ts
1105
- init_react_import();
1106
-
1107
- // lib/apply-dynamic-props.ts
1108
- init_react_import();
1109
- var applyDynamicProps = (data, dynamicProps, rootData) => {
1110
- return __spreadProps(__spreadValues({}, data), {
1111
- root: rootData ? __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}) : data.root,
1112
- content: data.content.map((item) => {
1113
- return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1114
- }),
1115
- zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
1116
- return __spreadProps(__spreadValues({}, acc), {
1117
- [zoneKey]: data.zones[zoneKey].map((item) => {
1118
- return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
1119
- })
1120
- });
1121
- }, {})
1122
- });
1123
- };
1124
-
1125
- // lib/flatten-data.ts
1126
- init_react_import();
1127
- var flattenData = (data) => {
1128
- return Object.keys(data.zones || {}).reduce(
1129
- (acc, zone) => [...acc, ...data.zones[zone]],
1130
- data.content
1131
- );
1132
- };
1133
-
1134
- // lib/resolve-data.ts
1135
- import fdeq from "fast-deep-equal";
1136
- var resolveData = (newAppState, appStoreData) => {
1137
- const {
1138
- state: appState,
1139
- config,
1140
- dispatch,
1141
- resolveDataRuns,
1142
- setComponentLoading,
1143
- unsetComponentLoading,
1144
- metadata,
1145
- permissions
1146
- } = appStoreData;
1147
- const deferredSetStates = {};
1148
- const _setComponentLoading = (id, loading, defer2 = 0) => {
1149
- if (deferredSetStates[id]) {
1150
- clearTimeout(deferredSetStates[id]);
1151
- delete deferredSetStates[id];
1152
- }
1153
- deferredSetStates[id] = setTimeout(() => {
1154
- if (loading) {
1155
- setComponentLoading(id);
1156
- } else {
1157
- unsetComponentLoading(id);
1158
- }
1159
- delete deferredSetStates[id];
1160
- }, defer2);
1161
- };
1162
- const runResolvers = () => __async(void 0, null, function* () {
1163
- const newData = newAppState.data;
1164
- const flatContent = flattenData(newData).filter(
1165
- (item) => {
1166
- var _a;
1167
- return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
1168
- }
1169
- );
1170
- const applyIfChange = (dynamicDataMap, dynamicRoot) => {
1171
- const processed = applyDynamicProps(
1172
- __spreadValues({}, appState.data),
1173
- dynamicDataMap,
1174
- dynamicRoot
1175
- );
1176
- const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
1177
- const containsChanges = !fdeq(appState, processedAppState);
1178
- if (containsChanges) {
1179
- dispatch({
1180
- type: "set",
1181
- state: (prev) => __spreadProps(__spreadValues({}, prev), {
1182
- data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
1183
- ui: resolveDataRuns > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
1184
- }),
1185
- recordHistory: resolveDataRuns > 0
1186
- });
1187
- }
1188
- };
1189
- const promises = [];
1190
- promises.push(
1191
- (() => __async(void 0, null, function* () {
1192
- _setComponentLoading("puck-root", true, 50);
1193
- const dynamicRoot = yield resolveRootData(newData, config, metadata);
1194
- applyIfChange({}, dynamicRoot);
1195
- _setComponentLoading("puck-root", false);
1196
- }))()
1197
- );
1198
- flatContent.forEach((item) => {
1199
- promises.push(
1200
- (() => __async(void 0, null, function* () {
1201
- permissions.resolvePermissions({ item }, true);
1202
- const dynamicData = yield resolveComponentData(
1203
- item,
1204
- config,
1205
- metadata,
1206
- (item2) => {
1207
- _setComponentLoading(item2.props.id, true, 50);
1208
- },
1209
- (item2) => {
1210
- deferredSetStates[item2.props.id];
1211
- _setComponentLoading(item2.props.id, false);
1212
- }
1213
- );
1214
- const dynamicDataMap = { [item.props.id]: dynamicData };
1215
- applyIfChange(dynamicDataMap);
1216
- }))()
1217
- );
1218
- });
1219
- yield Promise.all(promises);
1220
- });
1221
- return runResolvers();
1222
- };
1223
-
1224
- // store/index.ts
1225
1391
  import { createContext, useContext } from "react";
1226
1392
 
1227
1393
  // store/slices/history.ts
@@ -1416,7 +1582,7 @@ var createHistorySlice = (set, get) => {
1416
1582
  const { dispatch, history } = get();
1417
1583
  dispatch({
1418
1584
  type: "set",
1419
- state: ((_a = history.histories[history.index]) == null ? void 0 : _a.state) || history.initialAppState
1585
+ state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1420
1586
  });
1421
1587
  set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1422
1588
  },
@@ -1454,71 +1620,14 @@ function useRegisterHistorySlice(appStore, {
1454
1620
 
1455
1621
  // store/slices/nodes.ts
1456
1622
  init_react_import();
1457
- import deepEqual from "fast-deep-equal";
1458
- import { useEffect as useEffect3 } from "react";
1459
- var partialDeepEqual = (newItem, existingItem) => {
1460
- const filteredExistingItem = Object.keys(newItem).reduce(
1461
- (acc, key) => __spreadProps(__spreadValues({}, acc), { [key]: existingItem[key] }),
1462
- {}
1463
- );
1464
- return deepEqual(newItem, filteredExistingItem);
1465
- };
1466
- var generateNodesSlice = (data, appStore) => {
1467
- const nodeIndex = {};
1468
- const forAllData = (cb) => {
1469
- data.content.forEach((data2, index) => {
1470
- cb(data2, rootAreaId, rootZone, index);
1471
- });
1472
- Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
1473
- const [parentId, zone] = zoneCompound.split(":");
1474
- content.forEach((data2, index) => {
1475
- cb(data2, parentId, zone, index);
1476
- });
1477
- });
1478
- };
1479
- forAllData((data2, parentId, zone, index) => {
1480
- nodeIndex[data2.props.id] = { data: data2, parentId, zone, path: [], index };
1481
- });
1482
- const nodes = appStore.getState().nodes;
1483
- const registerNode = nodes.registerNode;
1484
- Object.keys(nodeIndex).forEach((componentId) => {
1485
- const details = nodeIndex[componentId];
1486
- let currentDetails = details;
1487
- let path = [];
1488
- while ((currentDetails == null ? void 0 : currentDetails.parentId) !== rootAreaId) {
1489
- path.unshift(`${currentDetails.parentId}:${currentDetails.zone}`);
1490
- currentDetails = nodeIndex[currentDetails.parentId];
1491
- }
1492
- path.unshift(rootDroppableId);
1493
- nodeIndex[componentId].path = path;
1494
- registerNode(componentId, nodeIndex[componentId]);
1495
- });
1496
- const rootProps = data.root.props || data.root;
1497
- registerNode("root", {
1498
- data: { type: "root", props: __spreadValues({ id: "root" }, rootProps) }
1499
- });
1500
- Object.keys(nodes.nodes).forEach((key) => {
1501
- if (!nodeIndex[key] && key !== "root") {
1502
- nodes.unregisterNode(key);
1503
- }
1504
- });
1505
- };
1506
1623
  var createNodesSlice = (set, get) => ({
1507
1624
  nodes: {},
1508
1625
  registerNode: (id, node) => {
1509
1626
  const s = get().nodes;
1510
- if (s.nodes[id] && partialDeepEqual(node, s.nodes[id])) {
1511
- return;
1512
- }
1513
1627
  const emptyNode = {
1514
1628
  id,
1515
1629
  methods: { sync: () => null },
1516
- data: { props: { id }, type: "unknown" },
1517
- parentId: "",
1518
- zone: "",
1519
- path: [],
1520
- element: null,
1521
- index: -1
1630
+ element: null
1522
1631
  };
1523
1632
  const existingNode = s.nodes[id];
1524
1633
  set({
@@ -1545,31 +1654,36 @@ var createNodesSlice = (set, get) => ({
1545
1654
  }
1546
1655
  }
1547
1656
  });
1548
- var useRegisterNodesSlice = (appStore) => {
1549
- useEffect3(() => {
1550
- return appStore.subscribe(
1551
- (s) => s.state.data,
1552
- (data) => generateNodesSlice(data, appStore)
1553
- );
1554
- }, []);
1555
- };
1556
1657
 
1557
1658
  // store/slices/permissions.ts
1558
1659
  init_react_import();
1559
- import { useEffect as useEffect4 } from "react";
1660
+ import { useEffect as useEffect3 } from "react";
1661
+
1662
+ // lib/data/flatten-data.ts
1663
+ init_react_import();
1664
+ var flattenData = (state, config) => {
1665
+ const data = [];
1666
+ walkAppState(
1667
+ state,
1668
+ config,
1669
+ (content) => content,
1670
+ (item) => {
1671
+ data.push(item);
1672
+ return null;
1673
+ }
1674
+ );
1675
+ return data;
1676
+ };
1677
+
1678
+ // store/slices/permissions.ts
1560
1679
  var createPermissionsSlice = (set, get) => {
1561
1680
  const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1562
- const { state, permissions } = get();
1681
+ const { state, permissions, config } = get();
1563
1682
  const { cache, globalPermissions } = permissions;
1564
1683
  const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1565
1684
  var _a, _b, _c;
1566
- const {
1567
- config,
1568
- state: appState,
1569
- setComponentLoading,
1570
- unsetComponentLoading
1571
- } = get();
1572
- const componentConfig = item2.type === "root" ? config.root : config.components[item2.type];
1685
+ const { config: config2, state: appState, setComponentLoading } = get();
1686
+ const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1573
1687
  if (!componentConfig) {
1574
1688
  return;
1575
1689
  }
@@ -1577,14 +1691,14 @@ var createPermissionsSlice = (set, get) => {
1577
1691
  if (componentConfig.resolvePermissions) {
1578
1692
  const changed = getChanged(item2, (_a = cache[item2.props.id]) == null ? void 0 : _a.lastData);
1579
1693
  if (Object.values(changed).some((el) => el === true) || force2) {
1580
- setComponentLoading(item2.props.id);
1694
+ const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1581
1695
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1582
1696
  item2,
1583
1697
  {
1584
1698
  changed,
1585
1699
  lastPermissions: ((_b = cache[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1586
1700
  permissions: initialPermissions,
1587
- appState,
1701
+ appState: makeStatePublic(appState),
1588
1702
  lastData: ((_c = cache[item2.props.id]) == null ? void 0 : _c.lastData) || null
1589
1703
  }
1590
1704
  );
@@ -1602,7 +1716,7 @@ var createPermissionsSlice = (set, get) => {
1602
1716
  })
1603
1717
  })
1604
1718
  });
1605
- unsetComponentLoading(item2.props.id);
1719
+ clearTimeout2();
1606
1720
  }
1607
1721
  }
1608
1722
  });
@@ -1612,7 +1726,7 @@ var createPermissionsSlice = (set, get) => {
1612
1726
  // Shim the root data in by conforming to component data shape
1613
1727
  {
1614
1728
  type: "root",
1615
- props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
1729
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1616
1730
  },
1617
1731
  force2
1618
1732
  );
@@ -1621,14 +1735,13 @@ var createPermissionsSlice = (set, get) => {
1621
1735
  if (item) {
1622
1736
  yield resolveDataForItem(item, force);
1623
1737
  } else if (type) {
1624
- flattenData(state.data).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1738
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1625
1739
  yield resolveDataForItem(item2, force);
1626
1740
  }));
1627
1741
  } else if (root) {
1628
1742
  resolveDataForRoot(force);
1629
1743
  } else {
1630
- resolveDataForRoot(force);
1631
- flattenData(state.data).map((item2) => __async(void 0, null, function* () {
1744
+ flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1632
1745
  yield resolveDataForItem(item2, force);
1633
1746
  }));
1634
1747
  }
@@ -1658,7 +1771,7 @@ var createPermissionsSlice = (set, get) => {
1658
1771
  } else if (root) {
1659
1772
  const rootConfig = config.root;
1660
1773
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1661
- const resolvedForItem = resolvedPermissions["puck-root"];
1774
+ const resolvedForItem = resolvedPermissions["root"];
1662
1775
  return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1663
1776
  }
1664
1777
  return globalPermissions;
@@ -1668,7 +1781,7 @@ var createPermissionsSlice = (set, get) => {
1668
1781
  };
1669
1782
  };
1670
1783
  var useRegisterPermissionsSlice = (appStore, globalPermissions) => {
1671
- useEffect4(() => {
1784
+ useEffect3(() => {
1672
1785
  const { permissions } = appStore.getState();
1673
1786
  const { globalPermissions: existingGlobalPermissions } = permissions;
1674
1787
  appStore.setState({
@@ -1678,7 +1791,7 @@ var useRegisterPermissionsSlice = (appStore, globalPermissions) => {
1678
1791
  });
1679
1792
  permissions.resolvePermissions();
1680
1793
  }, [globalPermissions]);
1681
- useEffect4(() => {
1794
+ useEffect3(() => {
1682
1795
  return appStore.subscribe(
1683
1796
  (s) => s.state.data,
1684
1797
  () => {
@@ -1686,7 +1799,7 @@ var useRegisterPermissionsSlice = (appStore, globalPermissions) => {
1686
1799
  }
1687
1800
  );
1688
1801
  }, []);
1689
- useEffect4(() => {
1802
+ useEffect3(() => {
1690
1803
  return appStore.subscribe(
1691
1804
  (s) => s.config,
1692
1805
  () => {
@@ -1698,8 +1811,8 @@ var useRegisterPermissionsSlice = (appStore, globalPermissions) => {
1698
1811
 
1699
1812
  // store/slices/fields.ts
1700
1813
  init_react_import();
1701
- import { useCallback, useEffect as useEffect5 } from "react";
1702
- var createFieldsStore = (_set, _get) => {
1814
+ import { useCallback, useEffect as useEffect4 } from "react";
1815
+ var createFieldsSlice = (_set, _get) => {
1703
1816
  return {
1704
1817
  fields: {},
1705
1818
  loading: false,
@@ -1711,10 +1824,10 @@ var useRegisterFieldsSlice = (appStore, id) => {
1711
1824
  (reset) => __async(void 0, null, function* () {
1712
1825
  var _a, _b;
1713
1826
  const { fields, lastResolvedData } = appStore.getState().fields;
1714
- const nodeStore = appStore.getState().nodes;
1715
- const node = nodeStore.nodes[id || "root"];
1827
+ const nodes = appStore.getState().state.indexes.nodes;
1828
+ const node = nodes[id || "root"];
1716
1829
  const componentData = node == null ? void 0 : node.data;
1717
- const parentNode = (node == null ? void 0 : node.parentId) ? nodeStore.nodes[node.parentId] : null;
1830
+ const parentNode = (node == null ? void 0 : node.parentId) ? nodes[node.parentId] : null;
1718
1831
  const parent = (parentNode == null ? void 0 : parentNode.data) || null;
1719
1832
  const { getComponentConfig, state } = appStore.getState();
1720
1833
  const componentConfig = getComponentConfig(componentData == null ? void 0 : componentData.type);
@@ -1741,7 +1854,7 @@ var useRegisterFieldsSlice = (appStore, id) => {
1741
1854
  fields: defaultFields,
1742
1855
  lastFields,
1743
1856
  lastData,
1744
- appState: state,
1857
+ appState: makeStatePublic(state),
1745
1858
  parent
1746
1859
  });
1747
1860
  clearTimeout(timeout3);
@@ -1763,15 +1876,32 @@ var useRegisterFieldsSlice = (appStore, id) => {
1763
1876
  }),
1764
1877
  [id]
1765
1878
  );
1766
- useEffect5(() => {
1879
+ useEffect4(() => {
1767
1880
  resolveFields(true);
1768
1881
  return appStore.subscribe(
1769
- (s) => s.nodes.nodes[id || "root"],
1882
+ (s) => s.state.indexes.nodes[id || "root"],
1770
1883
  () => resolveFields()
1771
1884
  );
1772
1885
  }, [id]);
1773
1886
  };
1774
1887
 
1888
+ // lib/data/to-root.ts
1889
+ init_react_import();
1890
+ var toRoot = (item) => {
1891
+ if ("type" in item && item.type !== "root") {
1892
+ throw new Error("Converting non-root item to root.");
1893
+ }
1894
+ const { readOnly } = item;
1895
+ if (item.props) {
1896
+ if ("id" in item.props) {
1897
+ const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
1898
+ return { props, readOnly };
1899
+ }
1900
+ return { props: item.props, readOnly };
1901
+ }
1902
+ return { props: {}, readOnly };
1903
+ };
1904
+
1775
1905
  // store/index.ts
1776
1906
  var defaultAppState = {
1777
1907
  data: { content: [], root: {}, zones: {} },
@@ -1792,92 +1922,186 @@ var defaultAppState = {
1792
1922
  controlsVisible: true
1793
1923
  },
1794
1924
  field: { focus: null }
1925
+ },
1926
+ indexes: {
1927
+ nodes: {},
1928
+ zones: {}
1795
1929
  }
1796
1930
  };
1797
1931
  var defaultPageFields = {
1798
1932
  title: { type: "text" }
1799
1933
  };
1800
1934
  var createAppStore = (initialAppStore) => create2()(
1801
- subscribeWithSelector2((set, get) => __spreadProps(__spreadValues({
1802
- state: defaultAppState,
1803
- config: { components: {} },
1804
- componentState: {},
1805
- plugins: [],
1806
- overrides: {},
1807
- viewports: defaultViewports,
1808
- zoomConfig: {
1809
- autoZoom: 1,
1810
- rootHeight: 0,
1811
- zoom: 1
1812
- },
1813
- status: "LOADING",
1814
- iframe: {},
1815
- metadata: {}
1816
- }, initialAppStore), {
1817
- fields: createFieldsStore(set, get),
1818
- history: createHistorySlice(set, get),
1819
- nodes: createNodesSlice(set, get),
1820
- permissions: createPermissionsSlice(set, get),
1821
- getComponentConfig: (type) => {
1822
- var _a;
1823
- const { config, selectedItem } = get();
1824
- const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
1825
- return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1826
- },
1827
- dispatch: (action) => set((s) => {
1828
- var _a, _b;
1829
- const { record } = get().history;
1830
- const dispatch = createReducer({ config: s.config, record });
1831
- const state = dispatch(s.state, action);
1832
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1833
- (_b = (_a = get()).onAction) == null ? void 0 : _b.call(_a, action, state, get().state);
1834
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1835
- }),
1836
- setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1837
- setStatus: (status) => set({ status }),
1838
- setComponentState: (componentState) => set({ componentState }),
1839
- setComponentLoading: (id) => {
1840
- var _a;
1841
- const { setComponentState, componentState } = get();
1842
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1843
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1844
- loadingCount: (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1845
- })
1846
- }));
1847
- },
1848
- unsetComponentLoading: (id) => {
1849
- var _a;
1850
- const { setComponentState, componentState } = get();
1851
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1852
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1853
- loadingCount: Math.max(
1854
- (((_a = componentState[id]) == null ? void 0 : _a.loadingCount) || 0) - 1,
1855
- 0
1856
- )
1857
- })
1858
- }));
1859
- },
1860
- // Helper
1861
- setUi: (ui, recordHistory) => set((s) => {
1862
- const dispatch = createReducer({
1863
- config: s.config,
1864
- record: () => {
1865
- }
1866
- });
1867
- const state = dispatch(s.state, {
1868
- type: "setUi",
1869
- ui,
1870
- recordHistory
1871
- });
1872
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state.data) : null;
1873
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1874
- }),
1875
- resolveDataRuns: 0,
1876
- resolveData: (newAppState) => set((s) => {
1877
- resolveData(newAppState, get());
1878
- return __spreadProps(__spreadValues({}, s), { resolveDataRuns: s.resolveDataRuns + 1 });
1879
- })
1880
- }))
1935
+ subscribeWithSelector2((set, get) => {
1936
+ var _a, _b;
1937
+ return __spreadProps(__spreadValues({
1938
+ state: defaultAppState,
1939
+ config: { components: {} },
1940
+ componentState: {},
1941
+ plugins: [],
1942
+ overrides: {},
1943
+ viewports: defaultViewports,
1944
+ zoomConfig: {
1945
+ autoZoom: 1,
1946
+ rootHeight: 0,
1947
+ zoom: 1
1948
+ },
1949
+ status: "LOADING",
1950
+ iframe: {},
1951
+ metadata: {}
1952
+ }, initialAppStore), {
1953
+ fields: createFieldsSlice(set, get),
1954
+ history: createHistorySlice(set, get),
1955
+ nodes: createNodesSlice(set, get),
1956
+ permissions: createPermissionsSlice(set, get),
1957
+ getComponentConfig: (type) => {
1958
+ var _a2;
1959
+ const { config, selectedItem } = get();
1960
+ const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
1961
+ return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1962
+ },
1963
+ selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
1964
+ (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
1965
+ initialAppStore.state
1966
+ ) : null,
1967
+ dispatch: (action) => set((s) => {
1968
+ var _a2, _b2;
1969
+ const { record } = get().history;
1970
+ const dispatch = createReducer({
1971
+ record,
1972
+ appStore: s
1973
+ });
1974
+ const state = dispatch(s.state, action);
1975
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1976
+ (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
1977
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1978
+ }),
1979
+ setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1980
+ setStatus: (status) => set({ status }),
1981
+ setComponentState: (componentState) => set({ componentState }),
1982
+ pendingLoadTimeouts: {},
1983
+ setComponentLoading: (id, loading = true, defer2 = 0) => {
1984
+ const { setComponentState, pendingLoadTimeouts } = get();
1985
+ const loadId = generateId();
1986
+ const setLoading = () => {
1987
+ var _a2;
1988
+ const { componentState } = get();
1989
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
1990
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1991
+ loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
1992
+ })
1993
+ }));
1994
+ };
1995
+ const unsetLoading = () => {
1996
+ var _a2;
1997
+ const { componentState } = get();
1998
+ clearTimeout(timeout3);
1999
+ delete pendingLoadTimeouts[loadId];
2000
+ set({ pendingLoadTimeouts });
2001
+ setComponentState(__spreadProps(__spreadValues({}, componentState), {
2002
+ [id]: __spreadProps(__spreadValues({}, componentState[id]), {
2003
+ loadingCount: Math.max(
2004
+ (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
2005
+ 0
2006
+ )
2007
+ })
2008
+ }));
2009
+ };
2010
+ const timeout3 = setTimeout(() => {
2011
+ if (loading) {
2012
+ setLoading();
2013
+ } else {
2014
+ unsetLoading();
2015
+ }
2016
+ delete pendingLoadTimeouts[loadId];
2017
+ set({ pendingLoadTimeouts });
2018
+ }, defer2);
2019
+ set({
2020
+ pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
2021
+ [id]: timeout3
2022
+ })
2023
+ });
2024
+ return unsetLoading;
2025
+ },
2026
+ unsetComponentLoading: (id) => {
2027
+ const { setComponentLoading } = get();
2028
+ setComponentLoading(id, false);
2029
+ },
2030
+ // Helper
2031
+ setUi: (ui, recordHistory) => set((s) => {
2032
+ const dispatch = createReducer({
2033
+ record: () => {
2034
+ },
2035
+ appStore: s
2036
+ });
2037
+ const state = dispatch(s.state, {
2038
+ type: "setUi",
2039
+ ui,
2040
+ recordHistory
2041
+ });
2042
+ const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
2043
+ return __spreadProps(__spreadValues({}, s), { state, selectedItem });
2044
+ }),
2045
+ resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
2046
+ const { config, metadata, setComponentLoading, permissions } = get();
2047
+ const timeouts = {};
2048
+ return yield resolveComponentData(
2049
+ componentData,
2050
+ config,
2051
+ metadata,
2052
+ (item) => {
2053
+ const id = "id" in item.props ? item.props.id : "root";
2054
+ timeouts[id] = setComponentLoading(id, true, 50);
2055
+ },
2056
+ (item) => __async(void 0, null, function* () {
2057
+ const id = "id" in item.props ? item.props.id : "root";
2058
+ if ("type" in item) {
2059
+ yield permissions.refreshPermissions({ item });
2060
+ } else {
2061
+ yield permissions.refreshPermissions({ root: true });
2062
+ }
2063
+ timeouts[id]();
2064
+ }),
2065
+ trigger
2066
+ );
2067
+ }),
2068
+ resolveAndCommitData: () => __async(void 0, null, function* () {
2069
+ const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
2070
+ walkAppState(
2071
+ state,
2072
+ config,
2073
+ (content) => content,
2074
+ (childItem) => {
2075
+ resolveComponentData2(childItem, "load").then((resolved) => {
2076
+ const { state: state2 } = get();
2077
+ const node = state2.indexes.nodes[resolved.node.props.id];
2078
+ if (node && resolved.didChange) {
2079
+ if (resolved.node.props.id === "root") {
2080
+ dispatch({
2081
+ type: "replaceRoot",
2082
+ root: toRoot(resolved.node)
2083
+ });
2084
+ } else {
2085
+ const zoneCompound = `${node.parentId}:${node.zone}`;
2086
+ const parentZone = state2.indexes.zones[zoneCompound];
2087
+ const index = parentZone.contentIds.indexOf(
2088
+ resolved.node.props.id
2089
+ );
2090
+ dispatch({
2091
+ type: "replace",
2092
+ data: resolved.node,
2093
+ destinationIndex: index,
2094
+ destinationZone: zoneCompound
2095
+ });
2096
+ }
2097
+ }
2098
+ });
2099
+ return childItem;
2100
+ }
2101
+ );
2102
+ })
2103
+ });
2104
+ })
1881
2105
  );
1882
2106
  var appStoreContext = createContext(createAppStore());
1883
2107
  function useAppStore(selector) {
@@ -2723,7 +2947,7 @@ var ArrayField = ({
2723
2947
  openId: ""
2724
2948
  };
2725
2949
  const [localState, setLocalState] = useState3({ arrayState, value });
2726
- useEffect6(() => {
2950
+ useEffect5(() => {
2727
2951
  var _a;
2728
2952
  const _arrayState = (_a = appStore.getState().state.ui.arrayState[id]) != null ? _a : arrayState;
2729
2953
  setLocalState({ arrayState: _arrayState, value });
@@ -2765,7 +2989,7 @@ var ArrayField = ({
2765
2989
  },
2766
2990
  [arrayState]
2767
2991
  );
2768
- useEffect6(() => {
2992
+ useEffect5(() => {
2769
2993
  if (arrayState.items.length > 0) {
2770
2994
  setUi(mapArrayStateToUi(arrayState));
2771
2995
  }
@@ -3068,13 +3292,13 @@ var DefaultField = ({
3068
3292
 
3069
3293
  // components/AutoField/fields/ExternalField/index.tsx
3070
3294
  init_react_import();
3071
- import { useEffect as useEffect10 } from "react";
3295
+ import { useEffect as useEffect9 } from "react";
3072
3296
 
3073
3297
  // components/ExternalInput/index.tsx
3074
3298
  init_react_import();
3075
3299
  import {
3076
3300
  useMemo as useMemo2,
3077
- useEffect as useEffect9,
3301
+ useEffect as useEffect8,
3078
3302
  useState as useState6,
3079
3303
  useCallback as useCallback3,
3080
3304
  isValidElement
@@ -3086,7 +3310,7 @@ var styles_module_default6 = { "ExternalInput-actions": "_ExternalInput-actions_
3086
3310
 
3087
3311
  // components/Modal/index.tsx
3088
3312
  init_react_import();
3089
- import { useEffect as useEffect7, useState as useState4 } from "react";
3313
+ import { useEffect as useEffect6, useState as useState4 } from "react";
3090
3314
 
3091
3315
  // css-module:/home/runner/work/puck/puck/packages/core/components/Modal/styles.module.css#css-module
3092
3316
  init_react_import();
@@ -3102,7 +3326,7 @@ var Modal = ({
3102
3326
  isOpen
3103
3327
  }) => {
3104
3328
  const [rootEl, setRootEl] = useState4(null);
3105
- useEffect7(() => {
3329
+ useEffect6(() => {
3106
3330
  setRootEl(document.getElementById("puck-portal-root"));
3107
3331
  }, []);
3108
3332
  if (!rootEl) {
@@ -3149,7 +3373,7 @@ init_react_import();
3149
3373
 
3150
3374
  // components/Button/Button.tsx
3151
3375
  init_react_import();
3152
- import { useEffect as useEffect8, useState as useState5 } from "react";
3376
+ import { useEffect as useEffect7, useState as useState5 } from "react";
3153
3377
 
3154
3378
  // css-module:/home/runner/work/puck/puck/packages/core/components/Button/Button.module.css#css-module
3155
3379
  init_react_import();
@@ -3200,7 +3424,7 @@ var Button = (_a) => {
3200
3424
  "loading"
3201
3425
  ]);
3202
3426
  const [loading, setLoading] = useState5(loadingProp);
3203
- useEffect8(() => setLoading(loadingProp), [loadingProp]);
3427
+ useEffect7(() => setLoading(loadingProp), [loadingProp]);
3204
3428
  const ElementType = href ? "a" : type ? "button" : "span";
3205
3429
  const dataAttrs = filterDataAttrs(props);
3206
3430
  const el = /* @__PURE__ */ jsxs5(
@@ -3297,7 +3521,7 @@ var ExternalInput = ({
3297
3521
  ] }),
3298
3522
  [field.renderFooter]
3299
3523
  );
3300
- useEffect9(() => {
3524
+ useEffect8(() => {
3301
3525
  search(searchQuery, filters);
3302
3526
  }, []);
3303
3527
  return /* @__PURE__ */ jsxs6(
@@ -3469,7 +3693,7 @@ var ExternalField = ({
3469
3693
  var _a, _b, _c;
3470
3694
  const validField = field;
3471
3695
  const deprecatedField = field;
3472
- useEffect10(() => {
3696
+ useEffect9(() => {
3473
3697
  if (deprecatedField.adaptor) {
3474
3698
  console.error(
3475
3699
  "Warning: The `adaptor` API is deprecated. Please use updated APIs on the `external` field instead. This will be a breaking change in a future release."
@@ -3888,6 +4112,9 @@ function AutoFieldInternal(props) {
3888
4112
  });
3889
4113
  }
3890
4114
  }, []);
4115
+ if (field.type === "slot") {
4116
+ return null;
4117
+ }
3891
4118
  if (field.type === "custom") {
3892
4119
  if (!field.render) {
3893
4120
  return null;
@@ -3930,11 +4157,18 @@ function AutoFieldPrivate(props) {
3930
4157
  },
3931
4158
  [onChange]
3932
4159
  );
3933
- useEffect11(() => {
4160
+ useEffect10(() => {
3934
4161
  if (!isFocused) {
3935
4162
  setLocalValue(value);
3936
4163
  }
3937
4164
  }, [value]);
4165
+ useEffect10(() => {
4166
+ if (!isFocused) {
4167
+ if (value !== localValue) {
4168
+ setLocalValue(value);
4169
+ }
4170
+ }
4171
+ }, [isFocused, value, localValue]);
3938
4172
  const localProps = {
3939
4173
  value: localValue,
3940
4174
  onChange: onChangeLocal
@@ -3951,6 +4185,9 @@ function AutoField(props) {
3951
4185
  );
3952
4186
  return DefaultLabel2;
3953
4187
  }, [props.readOnly]);
4188
+ if (props.field.type === "slot") {
4189
+ return null;
4190
+ }
3954
4191
  return /* @__PURE__ */ jsx18(AutoFieldInternal, __spreadProps(__spreadValues({}, props), { Label: DefaultLabel }));
3955
4192
  }
3956
4193
 
@@ -3962,7 +4199,7 @@ init_react_import();
3962
4199
  var styles_module_default10 = { "Drawer": "_Drawer_fkqfo_1", "Drawer-draggable": "_Drawer-draggable_fkqfo_8", "Drawer-draggableBg": "_Drawer-draggableBg_fkqfo_12", "Drawer-draggableFg": "_Drawer-draggableFg_fkqfo_21", "DrawerItem-draggable": "_DrawerItem-draggable_fkqfo_25", "DrawerItem--disabled": "_DrawerItem--disabled_fkqfo_38", "DrawerItem": "_DrawerItem_fkqfo_25", "Drawer--isDraggingFrom": "_Drawer--isDraggingFrom_fkqfo_48", "DrawerItem-name": "_DrawerItem-name_fkqfo_66" };
3963
4200
 
3964
4201
  // components/Drawer/index.tsx
3965
- import { useMemo as useMemo9, useState as useState15 } from "react";
4202
+ import { useMemo as useMemo11, useState as useState15 } from "react";
3966
4203
 
3967
4204
  // components/DragDropContext/index.tsx
3968
4205
  init_react_import();
@@ -3971,7 +4208,8 @@ import {
3971
4208
  createContext as createContext4,
3972
4209
  useCallback as useCallback10,
3973
4210
  useContext as useContext7,
3974
- useEffect as useEffect17,
4211
+ useEffect as useEffect16,
4212
+ useMemo as useMemo10,
3975
4213
  useRef as useRef4,
3976
4214
  useState as useState14
3977
4215
  } from "react";
@@ -3981,10 +4219,11 @@ import { AutoScroller, defaultPreset } from "@dnd-kit/dom";
3981
4219
  init_react_import();
3982
4220
  import {
3983
4221
  forwardRef as forwardRef3,
4222
+ memo,
3984
4223
  useCallback as useCallback9,
3985
4224
  useContext as useContext6,
3986
- useEffect as useEffect16,
3987
- useMemo as useMemo8,
4225
+ useEffect as useEffect15,
4226
+ useMemo as useMemo9,
3988
4227
  useRef as useRef3
3989
4228
  } from "react";
3990
4229
 
@@ -3993,7 +4232,7 @@ init_react_import();
3993
4232
  import {
3994
4233
  useCallback as useCallback6,
3995
4234
  useContext as useContext5,
3996
- useEffect as useEffect12,
4235
+ useEffect as useEffect11,
3997
4236
  useMemo as useMemo7,
3998
4237
  useRef as useRef2,
3999
4238
  useState as useState10
@@ -4001,7 +4240,7 @@ import {
4001
4240
 
4002
4241
  // css-module:/home/runner/work/puck/puck/packages/core/components/DraggableComponent/styles.module.css#css-module
4003
4242
  init_react_import();
4004
- var styles_module_default11 = { "DraggableComponent": "_DraggableComponent_1ukn8_1", "DraggableComponent-overlay": "_DraggableComponent-overlay_1ukn8_12", "DraggableComponent-loadingOverlay": "_DraggableComponent-loadingOverlay_1ukn8_29", "DraggableComponent--hover": "_DraggableComponent--hover_1ukn8_45", "DraggableComponent--isLocked": "_DraggableComponent--isLocked_1ukn8_45", "DraggableComponent--isSelected": "_DraggableComponent--isSelected_1ukn8_54", "DraggableComponent-actionsOverlay": "_DraggableComponent-actionsOverlay_1ukn8_66", "DraggableComponent-actions": "_DraggableComponent-actions_1ukn8_66" };
4243
+ var styles_module_default11 = { "DraggableComponent": "_DraggableComponent_qzbgx_1", "DraggableComponent-overlay": "_DraggableComponent-overlay_qzbgx_12", "DraggableComponent-loadingOverlay": "_DraggableComponent-loadingOverlay_qzbgx_29", "DraggableComponent--hover": "_DraggableComponent--hover_qzbgx_45", "DraggableComponent--isLocked": "_DraggableComponent--isLocked_qzbgx_45", "DraggableComponent--isSelected": "_DraggableComponent--isSelected_qzbgx_54", "DraggableComponent-actionsOverlay": "_DraggableComponent-actionsOverlay_qzbgx_66", "DraggableComponent-actions": "_DraggableComponent-actions_qzbgx_66" };
4005
4244
 
4006
4245
  // components/DraggableComponent/index.tsx
4007
4246
  import { createPortal as createPortal2 } from "react-dom";
@@ -4057,45 +4296,33 @@ var DropZoneProvider = ({
4057
4296
  value
4058
4297
  }) => {
4059
4298
  const [hoveringComponent, setHoveringComponent] = useState9();
4060
- const [activeZones, setActiveZones] = useState9({});
4061
4299
  const dispatch = useAppStore((s) => s.dispatch);
4062
4300
  const registerZone = useCallback5(
4063
4301
  (zoneCompound) => {
4064
- if (!dispatch) {
4065
- return;
4066
- }
4067
4302
  dispatch({
4068
4303
  type: "registerZone",
4069
4304
  zone: zoneCompound
4070
4305
  });
4071
- setActiveZones((latest) => __spreadProps(__spreadValues({}, latest), { [zoneCompound]: true }));
4072
4306
  },
4073
- [setActiveZones, dispatch]
4307
+ [dispatch]
4074
4308
  );
4075
4309
  const unregisterZone = useCallback5(
4076
4310
  (zoneCompound) => {
4077
- if (!dispatch) {
4078
- return;
4079
- }
4080
4311
  dispatch({
4081
4312
  type: "unregisterZone",
4082
4313
  zone: zoneCompound
4083
4314
  });
4084
- setActiveZones((latest) => __spreadProps(__spreadValues({}, latest), {
4085
- [zoneCompound]: false
4086
- }));
4087
4315
  },
4088
- [setActiveZones, dispatch]
4316
+ [dispatch]
4089
4317
  );
4090
4318
  const memoValue = useMemo6(
4091
4319
  () => __spreadValues({
4092
4320
  hoveringComponent,
4093
4321
  setHoveringComponent,
4094
4322
  registerZone,
4095
- unregisterZone,
4096
- activeZones
4323
+ unregisterZone
4097
4324
  }, value),
4098
- [value, hoveringComponent, activeZones]
4325
+ [value, hoveringComponent]
4099
4326
  );
4100
4327
  return /* @__PURE__ */ jsx19(Fragment5, { children: memoValue && /* @__PURE__ */ jsx19(dropZoneContext.Provider, { value: memoValue, children }) });
4101
4328
  };
@@ -4156,12 +4383,6 @@ var DraggableComponent = ({
4156
4383
  }
4157
4384
  );
4158
4385
  const overrides = useAppStore((s) => s.overrides);
4159
- const selectedItem = useAppStore(
4160
- (s) => {
4161
- var _a;
4162
- return ((_a = s.selectedItem) == null ? void 0 : _a.props.id) === id ? s.selectedItem : null;
4163
- }
4164
- );
4165
4386
  const dispatch = useAppStore((s) => s.dispatch);
4166
4387
  const iframe = useAppStore((s) => s.iframe);
4167
4388
  const ctx = useContext5(dropZoneContext);
@@ -4189,16 +4410,15 @@ var DraggableComponent = ({
4189
4410
  [setLocalZones]
4190
4411
  );
4191
4412
  const containsActiveZone = Object.values(localZones).filter(Boolean).length > 0;
4192
- const path = useAppStore((s) => {
4193
- var _a;
4194
- return (_a = s.nodes.nodes[id]) == null ? void 0 : _a.path;
4195
- });
4196
- const item = useAppStore((s) => {
4413
+ const path = useAppStore(useShallow2((s) => {
4197
4414
  var _a;
4198
- return (_a = s.nodes.nodes[id]) == null ? void 0 : _a.data;
4199
- });
4415
+ return (_a = s.state.indexes.nodes[id]) == null ? void 0 : _a.path;
4416
+ }));
4200
4417
  const permissions = useAppStore(
4201
- useShallow2((s) => s.permissions.getPermissions({ item }))
4418
+ useShallow2((s) => {
4419
+ const item = getItem({ index, zone: zoneCompound }, s.state);
4420
+ return s.permissions.getPermissions({ item });
4421
+ })
4202
4422
  );
4203
4423
  const userIsDragging = useContextStore(
4204
4424
  ZoneStoreContext,
@@ -4243,7 +4463,7 @@ var DraggableComponent = ({
4243
4463
  [sortableRef]
4244
4464
  );
4245
4465
  const [portalEl, setPortalEl] = useState10();
4246
- useEffect12(() => {
4466
+ useEffect11(() => {
4247
4467
  var _a, _b, _c;
4248
4468
  setPortalEl(
4249
4469
  iframe.enabled ? (_a = ref.current) == null ? void 0 : _a.ownerDocument.body : (_c = (_b = ref.current) == null ? void 0 : _b.closest("[data-puck-preview]")) != null ? _c : document.body
@@ -4273,7 +4493,7 @@ var DraggableComponent = ({
4273
4493
  const sync = useCallback6(() => {
4274
4494
  setStyle(getStyle());
4275
4495
  }, [ref.current, iframe]);
4276
- useEffect12(() => {
4496
+ useEffect11(() => {
4277
4497
  if (ref.current && !userIsDragging) {
4278
4498
  const observer = new ResizeObserver(sync);
4279
4499
  observer.observe(ref.current);
@@ -4283,7 +4503,7 @@ var DraggableComponent = ({
4283
4503
  }
4284
4504
  }, [ref.current, userIsDragging]);
4285
4505
  const registerNode = useAppStore((s) => s.nodes.registerNode);
4286
- useEffect12(() => {
4506
+ useEffect11(() => {
4287
4507
  var _a;
4288
4508
  registerNode(id, { methods: { sync }, element: (_a = ref.current) != null ? _a : null });
4289
4509
  return () => {
@@ -4308,18 +4528,22 @@ var DraggableComponent = ({
4308
4528
  );
4309
4529
  const appStore = useAppStoreApi();
4310
4530
  const onSelectParent = useCallback6(() => {
4311
- const { nodes } = appStore.getState().nodes;
4531
+ const { nodes, zones } = appStore.getState().state.indexes;
4312
4532
  const node = nodes[id];
4313
4533
  const parentNode = (node == null ? void 0 : node.parentId) ? nodes[node == null ? void 0 : node.parentId] : null;
4314
- if (!parentNode) {
4534
+ if (!parentNode || !node.parentId) {
4315
4535
  return;
4316
4536
  }
4537
+ const parentZoneCompound = `${parentNode.parentId}:${parentNode.zone}`;
4538
+ const parentIndex = zones[parentZoneCompound].contentIds.indexOf(
4539
+ node.parentId
4540
+ );
4317
4541
  dispatch({
4318
4542
  type: "setUi",
4319
4543
  ui: {
4320
4544
  itemSelector: {
4321
- zone: `${parentNode.parentId}:${parentNode.zone}`,
4322
- index: parentNode.index
4545
+ zone: parentZoneCompound,
4546
+ index: parentIndex
4323
4547
  }
4324
4548
  }
4325
4549
  });
@@ -4340,7 +4564,7 @@ var DraggableComponent = ({
4340
4564
  }, [index, zoneCompound]);
4341
4565
  const [hover, setHover] = useState10(false);
4342
4566
  const indicativeHover = (ctx == null ? void 0 : ctx.hoveringComponent) === id;
4343
- useEffect12(() => {
4567
+ useEffect11(() => {
4344
4568
  if (!ref.current) {
4345
4569
  return;
4346
4570
  }
@@ -4390,7 +4614,7 @@ var DraggableComponent = ({
4390
4614
  thisIsDragging,
4391
4615
  inDroppableZone
4392
4616
  ]);
4393
- useEffect12(() => {
4617
+ useEffect11(() => {
4394
4618
  if (ref.current && disabled) {
4395
4619
  ref.current.setAttribute("data-puck-disabled", "");
4396
4620
  return () => {
@@ -4400,7 +4624,7 @@ var DraggableComponent = ({
4400
4624
  }
4401
4625
  }, [disabled, ref]);
4402
4626
  const [isVisible, setIsVisible] = useState10(false);
4403
- useEffect12(() => {
4627
+ useEffect11(() => {
4404
4628
  sync();
4405
4629
  if ((isSelected || hover || indicativeHover) && !userIsDragging) {
4406
4630
  setIsVisible(true);
@@ -4433,7 +4657,7 @@ var DraggableComponent = ({
4433
4657
  },
4434
4658
  [zoom]
4435
4659
  );
4436
- useEffect12(() => {
4660
+ useEffect11(() => {
4437
4661
  if (userDragAxis) {
4438
4662
  setDragAxis(userDragAxis);
4439
4663
  return;
@@ -4448,85 +4672,91 @@ var DraggableComponent = ({
4448
4672
  setDragAxis(autoDragAxis);
4449
4673
  }, [ref, userDragAxis, autoDragAxis]);
4450
4674
  const parentAction = (ctx == null ? void 0 : ctx.areaId) && (ctx == null ? void 0 : ctx.areaId) !== "root" && /* @__PURE__ */ jsx20(ActionBar.Action, { onClick: onSelectParent, label: "Select parent", children: /* @__PURE__ */ jsx20(CornerLeftUp, { size: 16 }) });
4451
- return /* @__PURE__ */ jsxs9(
4452
- DropZoneProvider,
4453
- {
4454
- value: __spreadProps(__spreadValues({}, ctx), {
4455
- areaId: id,
4456
- zoneCompound,
4457
- index,
4458
- depth: depth + 1,
4459
- registerLocalZone,
4460
- unregisterLocalZone
4461
- }),
4462
- children: [
4463
- isVisible && createPortal2(
4464
- /* @__PURE__ */ jsxs9(
4465
- "div",
4466
- {
4467
- className: getClassName16({
4468
- isSelected,
4469
- isDragging: thisIsDragging,
4470
- hover: hover || indicativeHover
4471
- }),
4472
- style: __spreadValues({}, style),
4473
- "data-puck-overlay": true,
4474
- children: [
4475
- debug,
4476
- isLoading && /* @__PURE__ */ jsx20("div", { className: getClassName16("loadingOverlay"), children: /* @__PURE__ */ jsx20(Loader, {}) }),
4477
- /* @__PURE__ */ jsx20(
4675
+ const nextContextValue = useMemo7(
4676
+ () => __spreadProps(__spreadValues({}, ctx), {
4677
+ areaId: id,
4678
+ zoneCompound,
4679
+ index,
4680
+ depth: depth + 1,
4681
+ registerLocalZone,
4682
+ unregisterLocalZone
4683
+ }),
4684
+ [
4685
+ ctx,
4686
+ id,
4687
+ zoneCompound,
4688
+ index,
4689
+ depth,
4690
+ registerLocalZone,
4691
+ unregisterLocalZone
4692
+ ]
4693
+ );
4694
+ return /* @__PURE__ */ jsxs9(DropZoneProvider, { value: nextContextValue, children: [
4695
+ isVisible && createPortal2(
4696
+ /* @__PURE__ */ jsxs9(
4697
+ "div",
4698
+ {
4699
+ className: getClassName16({
4700
+ isSelected,
4701
+ isDragging: thisIsDragging,
4702
+ hover: hover || indicativeHover
4703
+ }),
4704
+ style: __spreadValues({}, style),
4705
+ "data-puck-overlay": true,
4706
+ children: [
4707
+ debug,
4708
+ isLoading && /* @__PURE__ */ jsx20("div", { className: getClassName16("loadingOverlay"), children: /* @__PURE__ */ jsx20(Loader, {}) }),
4709
+ /* @__PURE__ */ jsx20(
4710
+ "div",
4711
+ {
4712
+ className: getClassName16("actionsOverlay"),
4713
+ style: {
4714
+ top: actionsOverlayTop / zoom
4715
+ },
4716
+ children: /* @__PURE__ */ jsx20(
4478
4717
  "div",
4479
4718
  {
4480
- className: getClassName16("actionsOverlay"),
4719
+ className: getClassName16("actions"),
4481
4720
  style: {
4482
- top: actionsOverlayTop / zoom
4721
+ transform: `scale(${1 / zoom}`,
4722
+ top: actionsTop / zoom,
4723
+ right: 0,
4724
+ paddingLeft: actionsSide,
4725
+ paddingRight: actionsSide
4483
4726
  },
4484
- children: /* @__PURE__ */ jsx20(
4485
- "div",
4727
+ ref: syncActionsPosition,
4728
+ children: /* @__PURE__ */ jsxs9(
4729
+ CustomActionBar,
4486
4730
  {
4487
- className: getClassName16("actions"),
4488
- style: {
4489
- transform: `scale(${1 / zoom}`,
4490
- top: actionsTop / zoom,
4491
- right: 0,
4492
- paddingLeft: actionsSide,
4493
- paddingRight: actionsSide
4494
- },
4495
- ref: syncActionsPosition,
4496
- children: /* @__PURE__ */ jsxs9(
4497
- CustomActionBar,
4498
- {
4499
- parentAction,
4500
- label: DEBUG2 ? id : label,
4501
- children: [
4502
- permissions.duplicate && /* @__PURE__ */ jsx20(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ jsx20(Copy, { size: 16 }) }),
4503
- permissions.delete && /* @__PURE__ */ jsx20(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ jsx20(Trash, { size: 16 }) })
4504
- ]
4505
- }
4506
- )
4731
+ parentAction,
4732
+ label: DEBUG2 ? id : label,
4733
+ children: [
4734
+ permissions.duplicate && /* @__PURE__ */ jsx20(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ jsx20(Copy, { size: 16 }) }),
4735
+ permissions.delete && /* @__PURE__ */ jsx20(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ jsx20(Trash, { size: 16 }) })
4736
+ ]
4507
4737
  }
4508
4738
  )
4509
4739
  }
4510
- ),
4511
- /* @__PURE__ */ jsx20("div", { className: getClassName16("overlay") })
4512
- ]
4513
- }
4514
- ),
4515
- portalEl || document.body
4516
- ),
4517
- children(refSetter)
4518
- ]
4519
- }
4520
- );
4740
+ )
4741
+ }
4742
+ ),
4743
+ /* @__PURE__ */ jsx20("div", { className: getClassName16("overlay") })
4744
+ ]
4745
+ }
4746
+ ),
4747
+ portalEl || document.body
4748
+ ),
4749
+ children(refSetter)
4750
+ ] });
4521
4751
  };
4522
4752
 
4523
4753
  // css-module:/home/runner/work/puck/puck/packages/core/components/DropZone/styles.module.css#css-module
4524
4754
  init_react_import();
4525
- var styles_module_default12 = { "DropZone": "_DropZone_kmkdc_1", "DropZone--isActive": "_DropZone--isActive_kmkdc_10", "DropZone--hasChildren": "_DropZone--hasChildren_kmkdc_14", "DropZone--userIsDragging": "_DropZone--userIsDragging_kmkdc_22", "DropZone--isAreaSelected": "_DropZone--isAreaSelected_kmkdc_26", "DropZone--hoveringOverArea": "_DropZone--hoveringOverArea_kmkdc_27", "DropZone--isRootZone": "_DropZone--isRootZone_kmkdc_27", "DropZone--isDestination": "_DropZone--isDestination_kmkdc_37", "DropZone-item": "_DropZone-item_kmkdc_49", "DropZone-hitbox": "_DropZone-hitbox_kmkdc_53", "DropZone--isEnabled": "_DropZone--isEnabled_kmkdc_61", "DropZone--isAnimating": "_DropZone--isAnimating_kmkdc_70" };
4755
+ var styles_module_default12 = { "DropZone": "_DropZone_3dmev_1", "DropZone--hasChildren": "_DropZone--hasChildren_3dmev_11", "DropZone--userIsDragging": "_DropZone--userIsDragging_3dmev_19", "DropZone--isAreaSelected": "_DropZone--isAreaSelected_3dmev_23", "DropZone--hoveringOverArea": "_DropZone--hoveringOverArea_3dmev_24", "DropZone--isRootZone": "_DropZone--isRootZone_3dmev_24", "DropZone--isDestination": "_DropZone--isDestination_3dmev_34", "DropZone-item": "_DropZone-item_3dmev_46", "DropZone-hitbox": "_DropZone-hitbox_3dmev_50", "DropZone--isEnabled": "_DropZone--isEnabled_3dmev_58", "DropZone--isAnimating": "_DropZone--isAnimating_3dmev_67" };
4526
4756
 
4527
4757
  // components/DropZone/lib/use-min-empty-height.ts
4528
4758
  init_react_import();
4529
- import { useEffect as useEffect13, useState as useState11 } from "react";
4759
+ import { useEffect as useEffect12, useState as useState11 } from "react";
4530
4760
  var useMinEmptyHeight = ({
4531
4761
  zoneCompound,
4532
4762
  userMinEmptyHeight,
@@ -4542,7 +4772,7 @@ var useMinEmptyHeight = ({
4542
4772
  isZone: ((_b = s.draggedItem) == null ? void 0 : _b.data.zone) === zoneCompound
4543
4773
  };
4544
4774
  });
4545
- useEffect13(() => {
4775
+ useEffect12(() => {
4546
4776
  if (draggedItem && ref.current) {
4547
4777
  if (isZone) {
4548
4778
  const rect = ref.current.getBoundingClientRect();
@@ -4553,10 +4783,18 @@ var useMinEmptyHeight = ({
4553
4783
  }
4554
4784
  setPrevHeight(0);
4555
4785
  setTimeout(() => {
4556
- const { nodes } = appStore.getState().nodes;
4557
- Object.entries(nodes).forEach(([_, node]) => {
4786
+ var _a, _b;
4787
+ const zones = appStore.getState().state.indexes.zones;
4788
+ const nodes = appStore.getState().nodes;
4789
+ const selectedItem = appStore.getState().selectedItem;
4790
+ const contentIds = ((_a = zones[zoneCompound]) == null ? void 0 : _a.contentIds) || [];
4791
+ contentIds.forEach((contentId) => {
4792
+ const node = nodes.nodes[contentId];
4558
4793
  node == null ? void 0 : node.methods.sync();
4559
4794
  });
4795
+ if (selectedItem) {
4796
+ (_b = nodes.nodes[selectedItem.props.id]) == null ? void 0 : _b.methods.sync();
4797
+ }
4560
4798
  setIsAnimating(false);
4561
4799
  }, 400);
4562
4800
  }, [ref.current, draggedItem, zoneCompound]);
@@ -4580,7 +4818,7 @@ function assignRefs(refs, node) {
4580
4818
 
4581
4819
  // components/DropZone/lib/use-content-with-preview.ts
4582
4820
  init_react_import();
4583
- import { useEffect as useEffect14, useState as useState12 } from "react";
4821
+ import { useEffect as useEffect13, useState as useState12 } from "react";
4584
4822
 
4585
4823
  // lib/dnd/use-rendered-callback.ts
4586
4824
  init_react_import();
@@ -4647,7 +4885,7 @@ var useContentIdsWithPreview = (contentIds, zoneCompound) => {
4647
4885
  },
4648
4886
  [draggedItemId, previewExists]
4649
4887
  );
4650
- useEffect14(() => {
4888
+ useEffect13(() => {
4651
4889
  updateContent(contentIds, preview, isDragging);
4652
4890
  }, [contentIds, preview, isDragging]);
4653
4891
  return [contentIdsWithPreview, localPreview];
@@ -4655,7 +4893,7 @@ var useContentIdsWithPreview = (contentIds, zoneCompound) => {
4655
4893
 
4656
4894
  // components/DropZone/lib/use-drag-axis.ts
4657
4895
  init_react_import();
4658
- import { useCallback as useCallback8, useEffect as useEffect15, useState as useState13 } from "react";
4896
+ import { useCallback as useCallback8, useEffect as useEffect14, useState as useState13 } from "react";
4659
4897
  var GRID_DRAG_AXIS = "dynamic";
4660
4898
  var FLEX_ROW_DRAG_AXIS = "x";
4661
4899
  var DEFAULT_DRAG_AXIS = "y";
@@ -4676,7 +4914,7 @@ var useDragAxis = (ref, collisionAxis) => {
4676
4914
  }
4677
4915
  }
4678
4916
  }, [ref.current]);
4679
- useEffect15(() => {
4917
+ useEffect14(() => {
4680
4918
  const onViewportChange = () => {
4681
4919
  calculateDragAxis();
4682
4920
  };
@@ -4685,7 +4923,7 @@ var useDragAxis = (ref, collisionAxis) => {
4685
4923
  window.removeEventListener("viewportchange", onViewportChange);
4686
4924
  };
4687
4925
  }, []);
4688
- useEffect15(calculateDragAxis, [status, collisionAxis]);
4926
+ useEffect14(calculateDragAxis, [status, collisionAxis]);
4689
4927
  return [dragAxis, calculateDragAxis];
4690
4928
  };
4691
4929
 
@@ -4694,8 +4932,36 @@ import { useShallow as useShallow3 } from "zustand/react/shallow";
4694
4932
 
4695
4933
  // components/Render/index.tsx
4696
4934
  init_react_import();
4697
- import React3 from "react";
4935
+ import React3, { useMemo as useMemo8 } from "react";
4936
+
4937
+ // components/SlotRender/index.tsx
4938
+ init_react_import();
4698
4939
  import { jsx as jsx21 } from "react/jsx-runtime";
4940
+ var ContextSlotRender = ({
4941
+ componentId,
4942
+ zone
4943
+ }) => {
4944
+ const config = useAppStore((s) => s.config);
4945
+ const metadata = useAppStore((s) => s.metadata);
4946
+ const slotContent = useAppStore(
4947
+ (s) => {
4948
+ var _a, _b;
4949
+ return (_b = (_a = s.state.indexes.nodes[componentId]) == null ? void 0 : _a.data.props[zone]) != null ? _b : null;
4950
+ }
4951
+ );
4952
+ return /* @__PURE__ */ jsx21(
4953
+ SlotRenderPure,
4954
+ {
4955
+ content: slotContent,
4956
+ zone,
4957
+ config,
4958
+ metadata
4959
+ }
4960
+ );
4961
+ };
4962
+
4963
+ // components/Render/index.tsx
4964
+ import { jsx as jsx22 } from "react/jsx-runtime";
4699
4965
  var renderContext = React3.createContext({
4700
4966
  config: { components: {} },
4701
4967
  data: { root: {}, content: [] },
@@ -4713,51 +4979,38 @@ function Render({
4713
4979
  });
4714
4980
  const rootProps = defaultedData.root.props || defaultedData.root;
4715
4981
  const title = (rootProps == null ? void 0 : rootProps.title) || "";
4982
+ const pageProps = __spreadProps(__spreadValues({}, rootProps), {
4983
+ puck: {
4984
+ renderDropZone: DropZonePure,
4985
+ isEditing: false,
4986
+ dragRef: null,
4987
+ metadata
4988
+ },
4989
+ title,
4990
+ editMode: false,
4991
+ id: "puck-root"
4992
+ });
4993
+ const propsWithSlots = useSlots(config.root, pageProps, (props) => /* @__PURE__ */ jsx22(SlotRender, __spreadProps(__spreadValues({}, props), { config, metadata })));
4994
+ const nextContextValue = useMemo8(
4995
+ () => ({
4996
+ mode: "render",
4997
+ depth: 0
4998
+ }),
4999
+ []
5000
+ );
4716
5001
  if ((_a = config.root) == null ? void 0 : _a.render) {
4717
- return /* @__PURE__ */ jsx21(renderContext.Provider, { value: { config, data: defaultedData, metadata }, children: /* @__PURE__ */ jsx21(
4718
- DropZoneProvider,
4719
- {
4720
- value: {
4721
- mode: "render",
4722
- depth: 0
4723
- },
4724
- children: /* @__PURE__ */ jsx21(
4725
- config.root.render,
4726
- __spreadProps(__spreadValues({}, rootProps), {
4727
- puck: {
4728
- renderDropZone: DropZonePure,
4729
- isEditing: false,
4730
- dragRef: null
4731
- },
4732
- title,
4733
- editMode: false,
4734
- id: "puck-root",
4735
- children: /* @__PURE__ */ jsx21(DropZoneRenderPure, { zone: rootZone })
4736
- })
4737
- )
4738
- }
4739
- ) });
5002
+ return /* @__PURE__ */ jsx22(renderContext.Provider, { value: { config, data: defaultedData, metadata }, children: /* @__PURE__ */ jsx22(DropZoneProvider, { value: nextContextValue, children: /* @__PURE__ */ jsx22(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ jsx22(DropZoneRenderPure, { zone: rootZone }) })) }) });
4740
5003
  }
4741
- return /* @__PURE__ */ jsx21(renderContext.Provider, { value: { config, data: defaultedData, metadata }, children: /* @__PURE__ */ jsx21(
4742
- DropZoneProvider,
4743
- {
4744
- value: {
4745
- mode: "render",
4746
- depth: 0
4747
- },
4748
- children: /* @__PURE__ */ jsx21(DropZoneRenderPure, { zone: rootZone })
4749
- }
4750
- ) });
5004
+ return /* @__PURE__ */ jsx22(renderContext.Provider, { value: { config, data: defaultedData, metadata }, children: /* @__PURE__ */ jsx22(DropZoneProvider, { value: nextContextValue, children: /* @__PURE__ */ jsx22(DropZoneRenderPure, { zone: rootZone }) }) });
4751
5005
  }
4752
5006
 
4753
5007
  // components/DropZone/index.tsx
4754
- import { Fragment as Fragment6, jsx as jsx22, jsxs as jsxs10 } from "react/jsx-runtime";
5008
+ import { Fragment as Fragment6, jsx as jsx23, jsxs as jsxs10 } from "react/jsx-runtime";
4755
5009
  var getClassName17 = get_class_name_factory_default("DropZone", styles_module_default12);
4756
5010
  var getRandomColor = () => `#${Math.floor(Math.random() * 16777215).toString(16)}`;
4757
5011
  var RENDER_DEBUG = false;
4758
- var DropZoneEditPure = (props) => /* @__PURE__ */ jsx22(DropZoneEdit, __spreadValues({}, props));
5012
+ var DropZoneEditPure = (props) => /* @__PURE__ */ jsx23(DropZoneEdit, __spreadValues({}, props));
4759
5013
  var DropZoneChild = ({
4760
- zone,
4761
5014
  zoneCompound,
4762
5015
  componentId,
4763
5016
  preview,
@@ -4769,27 +5022,37 @@ var DropZoneChild = ({
4769
5022
  }) => {
4770
5023
  var _a, _b;
4771
5024
  const metadata = useAppStore((s) => s.metadata);
4772
- const puckProps = {
4773
- renderDropZone: DropZoneEditPure,
4774
- isEditing: true,
4775
- dragRef: null,
4776
- metadata
4777
- };
4778
5025
  const ctx = useContext6(dropZoneContext);
4779
- const { depth } = ctx;
4780
- const contentItem = useAppStore(
5026
+ const { depth = 1 } = ctx != null ? ctx : {};
5027
+ const nodeProps = useAppStore(
4781
5028
  useShallow3((s) => {
4782
- let content = s.state.data.content || [];
4783
- if (zoneCompound !== rootDroppableId) {
4784
- content = setupZone(s.state.data, zoneCompound).zones[zoneCompound];
4785
- }
4786
- return content.find((item2) => item2.props.id === componentId);
5029
+ var _a2;
5030
+ return (_a2 = s.state.indexes.nodes[componentId]) == null ? void 0 : _a2.flatData.props;
5031
+ })
5032
+ );
5033
+ const nodeType = useAppStore(
5034
+ (s) => {
5035
+ var _a2;
5036
+ return (_a2 = s.state.indexes.nodes[componentId]) == null ? void 0 : _a2.data.type;
5037
+ }
5038
+ );
5039
+ const nodeReadOnly = useAppStore(
5040
+ useShallow3((s) => {
5041
+ var _a2;
5042
+ return (_a2 = s.state.indexes.nodes[componentId]) == null ? void 0 : _a2.data.readOnly;
4787
5043
  })
4788
5044
  );
4789
- const item = contentItem != null ? contentItem : (preview == null ? void 0 : preview.componentType) ? { type: preview.componentType, props: preview.props } : null;
5045
+ const node = { type: nodeType, props: nodeProps };
5046
+ const item = nodeProps ? node : (preview == null ? void 0 : preview.componentType) ? { type: preview.componentType, props: preview.props } : null;
4790
5047
  const componentConfig = useAppStore(
4791
5048
  (s) => (item == null ? void 0 : item.type) ? s.config.components[item.type] : null
4792
5049
  );
5050
+ const puckProps = {
5051
+ renderDropZone: DropZoneEditPure,
5052
+ isEditing: true,
5053
+ dragRef: null,
5054
+ metadata: __spreadValues(__spreadValues({}, metadata), componentConfig == null ? void 0 : componentConfig.metadata)
5055
+ };
4793
5056
  const overrides = useAppStore((s) => s.overrides);
4794
5057
  const isLoading = useAppStore(
4795
5058
  (s) => {
@@ -4804,18 +5067,29 @@ var DropZoneChild = ({
4804
5067
  }
4805
5068
  );
4806
5069
  let label = (_b = (_a = componentConfig == null ? void 0 : componentConfig.label) != null ? _a : item == null ? void 0 : item.type.toString()) != null ? _b : "Component";
4807
- const renderPreview = useMemo8(
5070
+ const renderPreview = useMemo9(
4808
5071
  () => function Preview4() {
4809
- return /* @__PURE__ */ jsx22(DrawerItemInner, { name: label, children: overrides.componentItem });
5072
+ return /* @__PURE__ */ jsx23(DrawerItemInner, { name: label, children: overrides.componentItem });
4810
5073
  },
4811
5074
  [componentId, label, overrides]
4812
5075
  );
5076
+ const defaultsProps = useMemo9(
5077
+ () => __spreadProps(__spreadValues(__spreadValues({}, componentConfig == null ? void 0 : componentConfig.defaultProps), item == null ? void 0 : item.props), {
5078
+ puck: puckProps,
5079
+ editMode: true
5080
+ // DEPRECATED
5081
+ }),
5082
+ [componentConfig == null ? void 0 : componentConfig.defaultProps, item == null ? void 0 : item.props, puckProps]
5083
+ );
5084
+ const defaultedPropsWithSlots = useSlots(
5085
+ componentConfig,
5086
+ defaultsProps,
5087
+ DropZoneEditPure,
5088
+ (slotProps) => /* @__PURE__ */ jsx23(ContextSlotRender, { componentId, zone: slotProps.zone }),
5089
+ nodeReadOnly,
5090
+ isLoading
5091
+ );
4813
5092
  if (!item) return;
4814
- const defaultedProps = __spreadProps(__spreadValues(__spreadValues({}, componentConfig == null ? void 0 : componentConfig.defaultProps), item.props), {
4815
- puck: puckProps,
4816
- editMode: true
4817
- // DEPRECATED
4818
- });
4819
5093
  let Render2 = componentConfig ? componentConfig.render : () => /* @__PURE__ */ jsxs10("div", { style: { padding: 48, textAlign: "center" }, children: [
4820
5094
  "No configuration for ",
4821
5095
  item.type
@@ -4825,7 +5099,7 @@ var DropZoneChild = ({
4825
5099
  if (isPreview) {
4826
5100
  Render2 = renderPreview;
4827
5101
  }
4828
- return /* @__PURE__ */ jsx22(
5102
+ return /* @__PURE__ */ jsx23(
4829
5103
  DraggableComponent,
4830
5104
  {
4831
5105
  id: componentId,
@@ -4840,17 +5114,18 @@ var DropZoneChild = ({
4840
5114
  autoDragAxis: dragAxis,
4841
5115
  userDragAxis: collisionAxis,
4842
5116
  inDroppableZone,
4843
- children: (dragRef) => (componentConfig == null ? void 0 : componentConfig.inline) && !isPreview ? /* @__PURE__ */ jsx22(Fragment6, { children: /* @__PURE__ */ jsx22(
5117
+ children: (dragRef) => (componentConfig == null ? void 0 : componentConfig.inline) && !isPreview ? /* @__PURE__ */ jsx23(Fragment6, { children: /* @__PURE__ */ jsx23(
4844
5118
  Render2,
4845
- __spreadProps(__spreadValues({}, defaultedProps), {
4846
- puck: __spreadProps(__spreadValues({}, defaultedProps.puck), {
5119
+ __spreadProps(__spreadValues({}, defaultedPropsWithSlots), {
5120
+ puck: __spreadProps(__spreadValues({}, defaultedPropsWithSlots.puck), {
4847
5121
  dragRef
4848
5122
  })
4849
5123
  })
4850
- ) }) : /* @__PURE__ */ jsx22("div", { ref: dragRef, children: /* @__PURE__ */ jsx22(Render2, __spreadValues({}, defaultedProps)) })
5124
+ ) }) : /* @__PURE__ */ jsx23("div", { ref: dragRef, children: /* @__PURE__ */ jsx23(Render2, __spreadValues({}, defaultedPropsWithSlots)) })
4851
5125
  }
4852
5126
  );
4853
5127
  };
5128
+ var DropZoneChildMemo = memo(DropZoneChild);
4854
5129
  var DropZoneEdit = forwardRef3(
4855
5130
  function DropZoneEditInternal({
4856
5131
  zone,
@@ -4865,16 +5140,15 @@ var DropZoneEdit = forwardRef3(
4865
5140
  const {
4866
5141
  // These all need setting via context
4867
5142
  areaId,
4868
- depth,
5143
+ depth = 0,
4869
5144
  registerLocalZone,
4870
- unregisterLocalZone,
4871
- activeZones
4872
- } = ctx;
5145
+ unregisterLocalZone
5146
+ } = ctx != null ? ctx : {};
4873
5147
  const path = useAppStore(
4874
- (s) => {
5148
+ useShallow3((s) => {
4875
5149
  var _a;
4876
- return areaId ? (_a = s.nodes.nodes[areaId]) == null ? void 0 : _a.path : null;
4877
- }
5150
+ return areaId ? (_a = s.state.indexes.nodes[areaId]) == null ? void 0 : _a.path : null;
5151
+ })
4878
5152
  );
4879
5153
  let zoneCompound = rootDroppableId;
4880
5154
  if (areaId) {
@@ -4889,34 +5163,46 @@ var DropZoneEdit = forwardRef3(
4889
5163
  draggedComponentType,
4890
5164
  userIsDragging
4891
5165
  } = useContextStore(ZoneStoreContext, (s) => {
4892
- var _a, _b, _c;
5166
+ var _a, _b;
4893
5167
  return {
4894
5168
  isDeepestZone: (_a = s.zoneDepthIndex[zoneCompound]) != null ? _a : false,
4895
5169
  inNextDeepestArea: s.nextAreaDepthIndex[areaId || ""],
4896
- draggedItemId: (_b = s.draggedItem) == null ? void 0 : _b.id,
4897
- draggedComponentType: (_c = s.draggedItem) == null ? void 0 : _c.data.componentType,
5170
+ draggedComponentType: (_b = s.draggedItem) == null ? void 0 : _b.data.componentType,
4898
5171
  userIsDragging: !!s.draggedItem
4899
5172
  };
4900
5173
  });
4901
- useEffect16(() => {
4902
- if (ctx == null ? void 0 : ctx.registerZone) {
4903
- ctx == null ? void 0 : ctx.registerZone(zoneCompound);
4904
- }
4905
- return () => {
4906
- if (ctx == null ? void 0 : ctx.unregisterZone) {
4907
- ctx == null ? void 0 : ctx.unregisterZone(zoneCompound);
4908
- }
4909
- };
4910
- }, []);
4911
- const contentIds = useAppStore(
5174
+ const zoneContentIds = useAppStore(
4912
5175
  useShallow3((s) => {
4913
- let content = s.state.data.content || [];
4914
- if (zoneCompound !== rootDroppableId) {
4915
- content = setupZone(s.state.data, zoneCompound).zones[zoneCompound];
4916
- }
4917
- return content.map(({ props }) => props.id);
5176
+ var _a;
5177
+ return (_a = s.state.indexes.zones[zoneCompound]) == null ? void 0 : _a.contentIds;
5178
+ })
5179
+ );
5180
+ const zoneType = useAppStore(
5181
+ useShallow3((s) => {
5182
+ var _a;
5183
+ return (_a = s.state.indexes.zones[zoneCompound]) == null ? void 0 : _a.type;
4918
5184
  })
4919
5185
  );
5186
+ useEffect15(() => {
5187
+ if (!zoneType || zoneType === "dropzone") {
5188
+ if (zoneCompound !== rootDroppableId) {
5189
+ console.warn(
5190
+ "DropZones have been deprecated in favor of slot fields and will be removed in a future version of Puck. Please see the migration guide: https://www.puckeditor.com/docs/guides/migrations/dropzones-to-slots"
5191
+ );
5192
+ }
5193
+ if (ctx == null ? void 0 : ctx.registerZone) {
5194
+ ctx == null ? void 0 : ctx.registerZone(zoneCompound);
5195
+ }
5196
+ return () => {
5197
+ if (ctx == null ? void 0 : ctx.unregisterZone) {
5198
+ ctx == null ? void 0 : ctx.unregisterZone(zoneCompound);
5199
+ }
5200
+ };
5201
+ }
5202
+ }, [zoneType]);
5203
+ const contentIds = useMemo9(() => {
5204
+ return zoneContentIds || [];
5205
+ }, [zoneContentIds]);
4920
5206
  const ref = useRef3(null);
4921
5207
  const acceptsTarget = useCallback9(
4922
5208
  (componentType) => {
@@ -4940,7 +5226,7 @@ var DropZoneEdit = forwardRef3(
4940
5226
  },
4941
5227
  [allow, disallow]
4942
5228
  );
4943
- useEffect16(() => {
5229
+ useEffect15(() => {
4944
5230
  if (registerLocalZone) {
4945
5231
  registerLocalZone(zoneCompound, acceptsTarget(draggedComponentType));
4946
5232
  }
@@ -4986,7 +5272,7 @@ var DropZoneEdit = forwardRef3(
4986
5272
  userMinEmptyHeight,
4987
5273
  ref
4988
5274
  });
4989
- return /* @__PURE__ */ jsx22(
5275
+ return /* @__PURE__ */ jsx23(
4990
5276
  "div",
4991
5277
  {
4992
5278
  className: `${getClassName17({
@@ -4996,7 +5282,6 @@ var DropZoneEdit = forwardRef3(
4996
5282
  isEnabled,
4997
5283
  isAreaSelected,
4998
5284
  hasChildren: contentIds.length > 0,
4999
- isActive: activeZones == null ? void 0 : activeZones[zoneCompound],
5000
5285
  isAnimating
5001
5286
  })}${className ? ` ${className}` : ""}`,
5002
5287
  ref: (node) => {
@@ -5009,10 +5294,9 @@ var DropZoneEdit = forwardRef3(
5009
5294
  backgroundColor: RENDER_DEBUG ? getRandomColor() : style == null ? void 0 : style.backgroundColor
5010
5295
  }),
5011
5296
  children: contentIdsWithPreview.map((componentId, i) => {
5012
- return /* @__PURE__ */ jsx22(
5013
- DropZoneChild,
5297
+ return /* @__PURE__ */ jsx23(
5298
+ DropZoneChildMemo,
5014
5299
  {
5015
- zone,
5016
5300
  zoneCompound,
5017
5301
  componentId,
5018
5302
  preview,
@@ -5029,7 +5313,31 @@ var DropZoneEdit = forwardRef3(
5029
5313
  );
5030
5314
  }
5031
5315
  );
5032
- var DropZoneRenderPure = (props) => /* @__PURE__ */ jsx22(DropZoneRender, __spreadValues({}, props));
5316
+ var DropZoneRenderItem = ({
5317
+ config,
5318
+ item,
5319
+ metadata
5320
+ }) => {
5321
+ const Component = config.components[item.type];
5322
+ const props = useSlots(Component, item.props, (slotProps) => /* @__PURE__ */ jsx23(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
5323
+ const nextContextValue = useMemo9(
5324
+ () => ({
5325
+ areaId: props.id,
5326
+ depth: 1
5327
+ }),
5328
+ [props]
5329
+ );
5330
+ return /* @__PURE__ */ jsx23(DropZoneProvider, { value: nextContextValue, children: /* @__PURE__ */ jsx23(
5331
+ Component.render,
5332
+ __spreadProps(__spreadValues({}, props), {
5333
+ puck: __spreadProps(__spreadValues({}, props.puck), {
5334
+ renderDropZone: DropZoneRenderPure,
5335
+ metadata: __spreadValues(__spreadValues({}, metadata), Component.metadata)
5336
+ })
5337
+ })
5338
+ ) }, props.id);
5339
+ };
5340
+ var DropZoneRenderPure = (props) => /* @__PURE__ */ jsx23(DropZoneRender, __spreadValues({}, props));
5033
5341
  var DropZoneRender = forwardRef3(
5034
5342
  function DropZoneRenderInternal({ className, style, zone }, ref) {
5035
5343
  const ctx = useContext6(dropZoneContext);
@@ -5037,16 +5345,18 @@ var DropZoneRender = forwardRef3(
5037
5345
  const { config, data, metadata } = useContext6(renderContext);
5038
5346
  let zoneCompound = rootDroppableId;
5039
5347
  let content = (data == null ? void 0 : data.content) || [];
5040
- useEffect16(() => {
5041
- if (ctx == null ? void 0 : ctx.registerZone) {
5042
- ctx == null ? void 0 : ctx.registerZone(zoneCompound);
5043
- }
5044
- return () => {
5045
- if (ctx == null ? void 0 : ctx.unregisterZone) {
5046
- ctx == null ? void 0 : ctx.unregisterZone(zoneCompound);
5348
+ useEffect15(() => {
5349
+ if (!content) {
5350
+ if (ctx == null ? void 0 : ctx.registerZone) {
5351
+ ctx == null ? void 0 : ctx.registerZone(zoneCompound);
5047
5352
  }
5048
- };
5049
- }, []);
5353
+ return () => {
5354
+ if (ctx == null ? void 0 : ctx.unregisterZone) {
5355
+ ctx == null ? void 0 : ctx.unregisterZone(zoneCompound);
5356
+ }
5357
+ };
5358
+ }
5359
+ }, [content]);
5050
5360
  if (!data || !config) {
5051
5361
  return null;
5052
5362
  }
@@ -5054,25 +5364,15 @@ var DropZoneRender = forwardRef3(
5054
5364
  zoneCompound = `${areaId}:${zone}`;
5055
5365
  content = setupZone(data, zoneCompound).zones[zoneCompound];
5056
5366
  }
5057
- return /* @__PURE__ */ jsx22("div", { className, style, ref, children: content.map((item) => {
5367
+ return /* @__PURE__ */ jsx23("div", { className, style, ref, children: content.map((item) => {
5058
5368
  const Component = config.components[item.type];
5059
5369
  if (Component) {
5060
- return /* @__PURE__ */ jsx22(
5061
- DropZoneProvider,
5370
+ return /* @__PURE__ */ jsx23(
5371
+ DropZoneRenderItem,
5062
5372
  {
5063
- value: {
5064
- areaId: item.props.id,
5065
- depth: 1
5066
- },
5067
- children: /* @__PURE__ */ jsx22(
5068
- Component.render,
5069
- __spreadProps(__spreadValues({}, item.props), {
5070
- puck: {
5071
- renderDropZone: DropZoneRenderPure,
5072
- metadata: metadata || {}
5073
- }
5074
- })
5075
- )
5373
+ config,
5374
+ item,
5375
+ metadata
5076
5376
  },
5077
5377
  item.props.id
5078
5378
  );
@@ -5081,14 +5381,14 @@ var DropZoneRender = forwardRef3(
5081
5381
  }) });
5082
5382
  }
5083
5383
  );
5084
- var DropZonePure = (props) => /* @__PURE__ */ jsx22(DropZone, __spreadValues({}, props));
5384
+ var DropZonePure = (props) => /* @__PURE__ */ jsx23(DropZone, __spreadValues({}, props));
5085
5385
  var DropZone = forwardRef3(
5086
5386
  function DropZone2(props, ref) {
5087
5387
  const ctx = useContext6(dropZoneContext);
5088
5388
  if ((ctx == null ? void 0 : ctx.mode) === "edit") {
5089
- return /* @__PURE__ */ jsx22(Fragment6, { children: /* @__PURE__ */ jsx22(DropZoneEdit, __spreadProps(__spreadValues({}, props), { ref })) });
5389
+ return /* @__PURE__ */ jsx23(Fragment6, { children: /* @__PURE__ */ jsx23(DropZoneEdit, __spreadProps(__spreadValues({}, props), { ref })) });
5090
5390
  }
5091
- return /* @__PURE__ */ jsx22(Fragment6, { children: /* @__PURE__ */ jsx22(DropZoneRender, __spreadProps(__spreadValues({}, props), { ref })) });
5391
+ return /* @__PURE__ */ jsx23(Fragment6, { children: /* @__PURE__ */ jsx23(DropZoneRender, __spreadProps(__spreadValues({}, props), { ref })) });
5092
5392
  }
5093
5393
  );
5094
5394
 
@@ -5144,7 +5444,7 @@ var GlobalPosition = class {
5144
5444
  var _a;
5145
5445
  this.target = target;
5146
5446
  this.original = original;
5147
- this.frameEl = document.querySelector("iframe");
5447
+ this.frameEl = document.querySelector("#preview-frame");
5148
5448
  if (this.frameEl) {
5149
5449
  this.frameRect = this.frameEl.getBoundingClientRect();
5150
5450
  this.scaleFactor = this.frameRect.width / (((_a = this.frameEl.contentWindow) == null ? void 0 : _a.innerWidth) || 1);
@@ -5353,12 +5653,7 @@ var createNestedDroppablePlugin = ({ onChange }, id) => class NestedDroppablePlu
5353
5653
 
5354
5654
  // lib/insert-component.ts
5355
5655
  init_react_import();
5356
- var insertComponent = (componentType, zone, index, {
5357
- config,
5358
- dispatch,
5359
- resolveData: resolveData2,
5360
- state
5361
- }) => {
5656
+ var insertComponent = (componentType, zone, index, appStore) => __async(void 0, null, function* () {
5362
5657
  const id = generateId(componentType);
5363
5658
  const insertActionData = {
5364
5659
  type: "insert",
@@ -5367,7 +5662,8 @@ var insertComponent = (componentType, zone, index, {
5367
5662
  destinationZone: zone,
5368
5663
  id
5369
5664
  };
5370
- const insertedData = insertAction(state.data, insertActionData, config);
5665
+ const { state, dispatch, resolveComponentData: resolveComponentData2 } = appStore;
5666
+ const insertedState = insertAction(state, insertActionData, appStore);
5371
5667
  dispatch(__spreadProps(__spreadValues({}, insertActionData), {
5372
5668
  // Dispatch insert rather set, as user's may rely on this via onAction
5373
5669
  // We must always record history here so the insert is added to user history
@@ -5380,11 +5676,19 @@ var insertComponent = (componentType, zone, index, {
5380
5676
  zone
5381
5677
  };
5382
5678
  dispatch({ type: "setUi", ui: { itemSelector } });
5383
- resolveData2({
5384
- data: insertedData,
5385
- ui: __spreadProps(__spreadValues({}, state.ui), { itemSelector })
5386
- });
5387
- };
5679
+ const itemData = getItem(itemSelector, insertedState);
5680
+ if (itemData) {
5681
+ const resolved = yield resolveComponentData2(itemData, "insert");
5682
+ if (resolved.didChange) {
5683
+ dispatch({
5684
+ type: "replace",
5685
+ destinationZone: itemSelector.zone,
5686
+ destinationIndex: itemSelector.index,
5687
+ data: resolved.node
5688
+ });
5689
+ }
5690
+ }
5691
+ });
5388
5692
 
5389
5693
  // components/DragDropContext/index.tsx
5390
5694
  import { useDebouncedCallback } from "use-debounce";
@@ -5402,14 +5706,14 @@ function getDeepDir(el) {
5402
5706
  }
5403
5707
 
5404
5708
  // components/DragDropContext/index.tsx
5405
- import { jsx as jsx23 } from "react/jsx-runtime";
5709
+ import { jsx as jsx24 } from "react/jsx-runtime";
5406
5710
  var DEBUG3 = false;
5407
5711
  var dragListenerContext = createContext4({
5408
5712
  dragListeners: {}
5409
5713
  });
5410
5714
  function useDragListener(type, fn, deps = []) {
5411
5715
  const { setDragListeners } = useContext7(dragListenerContext);
5412
- useEffect17(() => {
5716
+ useEffect16(() => {
5413
5717
  if (setDragListeners) {
5414
5718
  setDragListeners((old) => __spreadProps(__spreadValues({}, old), {
5415
5719
  [type]: [...old[type] || [], fn]
@@ -5436,10 +5740,7 @@ var DragDropContextClient = ({
5436
5740
  children,
5437
5741
  disableAutoScroll
5438
5742
  }) => {
5439
- const config = useAppStore((s) => s.config);
5440
5743
  const dispatch = useAppStore((s) => s.dispatch);
5441
- const resolveData2 = useAppStore((s) => s.resolveData);
5442
- const metadata = useAppStore((s) => s.metadata);
5443
5744
  const appStore = useAppStoreApi();
5444
5745
  const id = useSafeId();
5445
5746
  const debouncedParamsRef = useRef4(null);
@@ -5499,7 +5800,7 @@ var DragDropContextClient = ({
5499
5800
  setDeepestDb.cancel();
5500
5801
  debouncedParamsRef.current = null;
5501
5802
  };
5502
- useEffect17(() => {
5803
+ useEffect16(() => {
5503
5804
  if (DEBUG3) {
5504
5805
  zoneStore.subscribe(
5505
5806
  (s) => {
@@ -5564,14 +5865,22 @@ var DragDropContextClient = ({
5564
5865
  const [dragListeners, setDragListeners] = useState14({});
5565
5866
  const dragMode = useRef4(null);
5566
5867
  const initialSelector = useRef4(void 0);
5567
- return /* @__PURE__ */ jsx23("div", { id, children: /* @__PURE__ */ jsx23(
5868
+ const nextContextValue = useMemo10(
5869
+ () => ({
5870
+ mode: "edit",
5871
+ areaId: "root",
5872
+ depth: 0
5873
+ }),
5874
+ []
5875
+ );
5876
+ return /* @__PURE__ */ jsx24("div", { id, children: /* @__PURE__ */ jsx24(
5568
5877
  dragListenerContext.Provider,
5569
5878
  {
5570
5879
  value: {
5571
5880
  dragListeners,
5572
5881
  setDragListeners
5573
5882
  },
5574
- children: /* @__PURE__ */ jsx23(
5883
+ children: /* @__PURE__ */ jsx24(
5575
5884
  DragDropProvider2,
5576
5885
  {
5577
5886
  plugins,
@@ -5605,13 +5914,12 @@ var DragDropContextClient = ({
5605
5914
  }
5606
5915
  if (thisPreview) {
5607
5916
  zoneStore.setState({ previewIndex: {} });
5608
- const state = appStore.getState().state;
5609
5917
  if (thisPreview.type === "insert") {
5610
5918
  insertComponent(
5611
5919
  thisPreview.componentType,
5612
5920
  thisPreview.zone,
5613
5921
  thisPreview.index,
5614
- { config, dispatch, resolveData: resolveData2, state }
5922
+ appStore.getState()
5615
5923
  );
5616
5924
  } else if (initialSelector.current) {
5617
5925
  dispatch({
@@ -5671,7 +5979,7 @@ var DragDropContextClient = ({
5671
5979
  targetZone = target.id.toString();
5672
5980
  targetIndex = 0;
5673
5981
  }
5674
- const path = ((_d = appStore.getState().nodes.nodes[target.id]) == null ? void 0 : _d.path) || [];
5982
+ const path = ((_d = appStore.getState().state.indexes.nodes[target.id]) == null ? void 0 : _d.path) || [];
5675
5983
  if (targetId === sourceId || path.find((path2) => {
5676
5984
  const [pathId] = path2.split(":");
5677
5985
  return pathId === sourceId;
@@ -5701,8 +6009,7 @@ var DragDropContextClient = ({
5701
6009
  }
5702
6010
  const item = getItem(
5703
6011
  initialSelector.current,
5704
- appStore.getState().state.data,
5705
- {}
6012
+ appStore.getState().state
5706
6013
  );
5707
6014
  if (item) {
5708
6015
  zoneStore.setState({
@@ -5731,13 +6038,12 @@ var DragDropContextClient = ({
5731
6038
  const { source } = event.operation;
5732
6039
  if (source && source.type !== "void") {
5733
6040
  const sourceData = source.data;
5734
- const { data } = appStore.getState().state;
5735
6041
  const item = getItem(
5736
6042
  {
5737
6043
  zone: sourceData.zone,
5738
6044
  index: sourceData.index
5739
6045
  },
5740
- data
6046
+ appStore.getState().state
5741
6047
  );
5742
6048
  if (item) {
5743
6049
  zoneStore.setState({
@@ -5764,17 +6070,7 @@ var DragDropContextClient = ({
5764
6070
  initialSelector.current = void 0;
5765
6071
  zoneStore.setState({ draggedItem: event.operation.source });
5766
6072
  },
5767
- children: /* @__PURE__ */ jsx23(ZoneStoreProvider, { store: zoneStore, children: /* @__PURE__ */ jsx23(
5768
- DropZoneProvider,
5769
- {
5770
- value: {
5771
- mode: "edit",
5772
- areaId: "root",
5773
- depth: 0
5774
- },
5775
- children
5776
- }
5777
- ) })
6073
+ children: /* @__PURE__ */ jsx24(ZoneStoreProvider, { store: zoneStore, children: /* @__PURE__ */ jsx24(DropZoneProvider, { value: nextContextValue, children }) })
5778
6074
  }
5779
6075
  )
5780
6076
  }
@@ -5788,11 +6084,11 @@ var DragDropContext = ({
5788
6084
  if (status === "LOADING") {
5789
6085
  return children;
5790
6086
  }
5791
- return /* @__PURE__ */ jsx23(DragDropContextClient, { disableAutoScroll, children });
6087
+ return /* @__PURE__ */ jsx24(DragDropContextClient, { disableAutoScroll, children });
5792
6088
  };
5793
6089
 
5794
6090
  // components/Drawer/index.tsx
5795
- import { jsx as jsx24, jsxs as jsxs11 } from "react/jsx-runtime";
6091
+ import { jsx as jsx25, jsxs as jsxs11 } from "react/jsx-runtime";
5796
6092
  var getClassName18 = get_class_name_factory_default("Drawer", styles_module_default10);
5797
6093
  var getClassNameItem2 = get_class_name_factory_default("DrawerItem", styles_module_default10);
5798
6094
  var DrawerItemInner = ({
@@ -5802,11 +6098,11 @@ var DrawerItemInner = ({
5802
6098
  dragRef,
5803
6099
  isDragDisabled
5804
6100
  }) => {
5805
- const CustomInner = useMemo9(
5806
- () => children || (({ children: children2 }) => /* @__PURE__ */ jsx24("div", { className: getClassNameItem2("default"), children: children2 })),
6101
+ const CustomInner = useMemo11(
6102
+ () => children || (({ children: children2 }) => /* @__PURE__ */ jsx25("div", { className: getClassNameItem2("default"), children: children2 })),
5807
6103
  [children]
5808
6104
  );
5809
- return /* @__PURE__ */ jsx24(
6105
+ return /* @__PURE__ */ jsx25(
5810
6106
  "div",
5811
6107
  {
5812
6108
  className: getClassNameItem2({ disabled: isDragDisabled }),
@@ -5814,9 +6110,9 @@ var DrawerItemInner = ({
5814
6110
  onMouseDown: (e) => e.preventDefault(),
5815
6111
  "data-testid": dragRef ? `drawer-item:${name}` : "",
5816
6112
  "data-puck-drawer-item": true,
5817
- children: /* @__PURE__ */ jsx24(CustomInner, { name, children: /* @__PURE__ */ jsx24("div", { className: getClassNameItem2("draggableWrapper"), children: /* @__PURE__ */ jsxs11("div", { className: getClassNameItem2("draggable"), children: [
5818
- /* @__PURE__ */ jsx24("div", { className: getClassNameItem2("name"), children: label != null ? label : name }),
5819
- /* @__PURE__ */ jsx24("div", { className: getClassNameItem2("icon"), children: /* @__PURE__ */ jsx24(DragIcon, {}) })
6113
+ children: /* @__PURE__ */ jsx25(CustomInner, { name, children: /* @__PURE__ */ jsx25("div", { className: getClassNameItem2("draggableWrapper"), children: /* @__PURE__ */ jsxs11("div", { className: getClassNameItem2("draggable"), children: [
6114
+ /* @__PURE__ */ jsx25("div", { className: getClassNameItem2("name"), children: label != null ? label : name }),
6115
+ /* @__PURE__ */ jsx25("div", { className: getClassNameItem2("icon"), children: /* @__PURE__ */ jsx25(DragIcon, {}) })
5820
6116
  ] }) }) })
5821
6117
  }
5822
6118
  );
@@ -5834,8 +6130,8 @@ var DrawerItemDraggable = ({
5834
6130
  disabled: isDragDisabled
5835
6131
  });
5836
6132
  return /* @__PURE__ */ jsxs11("div", { className: getClassName18("draggable"), children: [
5837
- /* @__PURE__ */ jsx24("div", { className: getClassName18("draggableBg"), children: /* @__PURE__ */ jsx24(DrawerItemInner, { name, label, children }) }),
5838
- /* @__PURE__ */ jsx24("div", { className: getClassName18("draggableFg"), children: /* @__PURE__ */ jsx24(
6133
+ /* @__PURE__ */ jsx25("div", { className: getClassName18("draggableBg"), children: /* @__PURE__ */ jsx25(DrawerItemInner, { name, label, children }) }),
6134
+ /* @__PURE__ */ jsx25("div", { className: getClassName18("draggableFg"), children: /* @__PURE__ */ jsx25(
5839
6135
  DrawerItemInner,
5840
6136
  {
5841
6137
  name,
@@ -5869,7 +6165,7 @@ var DrawerItem = ({
5869
6165
  },
5870
6166
  [resolvedId]
5871
6167
  );
5872
- return /* @__PURE__ */ jsx24("div", { children: /* @__PURE__ */ jsx24(
6168
+ return /* @__PURE__ */ jsx25("div", { children: /* @__PURE__ */ jsx25(
5873
6169
  DrawerItemDraggable,
5874
6170
  {
5875
6171
  name,
@@ -5902,7 +6198,7 @@ var Drawer = ({
5902
6198
  collisionPriority: 0
5903
6199
  // Never collide with this, but we use it so NestedDroppablePlugin respects the Drawer
5904
6200
  });
5905
- return /* @__PURE__ */ jsx24(
6201
+ return /* @__PURE__ */ jsx25(
5906
6202
  "div",
5907
6203
  {
5908
6204
  className: getClassName18(),
@@ -5921,8 +6217,8 @@ import {
5921
6217
  createContext as createContext7,
5922
6218
  useCallback as useCallback16,
5923
6219
  useContext as useContext11,
5924
- useEffect as useEffect25,
5925
- useMemo as useMemo18,
6220
+ useEffect as useEffect24,
6221
+ useMemo as useMemo20,
5926
6222
  useState as useState22
5927
6223
  } from "react";
5928
6224
 
@@ -5935,7 +6231,7 @@ var styles_module_default13 = { "SidebarSection": "_SidebarSection_8boj8_1", "Si
5935
6231
 
5936
6232
  // lib/use-breadcrumbs.ts
5937
6233
  init_react_import();
5938
- import { useMemo as useMemo10 } from "react";
6234
+ import { useMemo as useMemo12 } from "react";
5939
6235
  var useBreadcrumbs = (renderCount) => {
5940
6236
  const selectedId = useAppStore((s) => {
5941
6237
  var _a;
@@ -5944,12 +6240,12 @@ var useBreadcrumbs = (renderCount) => {
5944
6240
  const config = useAppStore((s) => s.config);
5945
6241
  const path = useAppStore((s) => {
5946
6242
  var _a;
5947
- return (_a = s.nodes.nodes[selectedId]) == null ? void 0 : _a.path;
6243
+ return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
5948
6244
  });
5949
6245
  const appStore = useAppStoreApi();
5950
- return useMemo10(() => {
6246
+ return useMemo12(() => {
5951
6247
  const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
5952
- var _a, _b;
6248
+ var _a, _b, _c;
5953
6249
  const [componentId] = zoneCompound.split(":");
5954
6250
  if (componentId === "root") {
5955
6251
  return {
@@ -5957,12 +6253,15 @@ var useBreadcrumbs = (renderCount) => {
5957
6253
  selector: null
5958
6254
  };
5959
6255
  }
5960
- const node = appStore.getState().nodes.nodes[componentId];
5961
- const label = node ? (_b = (_a = config.components[node.data.type]) == null ? void 0 : _a.label) != null ? _b : node.data.type : "Component";
6256
+ const node = appStore.getState().state.indexes.nodes[componentId];
6257
+ const parentId = node.path[node.path.length - 1];
6258
+ const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
6259
+ const index = contentIds.indexOf(componentId);
6260
+ const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
5962
6261
  return {
5963
6262
  label,
5964
6263
  selector: node ? {
5965
- index: node.index,
6264
+ index,
5966
6265
  zone: node.path[node.path.length - 1]
5967
6266
  } : null
5968
6267
  };
@@ -5975,7 +6274,7 @@ var useBreadcrumbs = (renderCount) => {
5975
6274
  };
5976
6275
 
5977
6276
  // components/SidebarSection/index.tsx
5978
- import { jsx as jsx25, jsxs as jsxs12 } from "react/jsx-runtime";
6277
+ import { jsx as jsx26, jsxs as jsxs12 } from "react/jsx-runtime";
5979
6278
  var getClassName19 = get_class_name_factory_default("SidebarSection", styles_module_default13);
5980
6279
  var SidebarSection = ({
5981
6280
  children,
@@ -5994,9 +6293,9 @@ var SidebarSection = ({
5994
6293
  className: getClassName19({ noBorderTop, noPadding }),
5995
6294
  style: { background },
5996
6295
  children: [
5997
- /* @__PURE__ */ jsx25("div", { className: getClassName19("title"), children: /* @__PURE__ */ jsxs12("div", { className: getClassName19("breadcrumbs"), children: [
6296
+ /* @__PURE__ */ jsx26("div", { className: getClassName19("title"), children: /* @__PURE__ */ jsxs12("div", { className: getClassName19("breadcrumbs"), children: [
5998
6297
  showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ jsxs12("div", { className: getClassName19("breadcrumb"), children: [
5999
- /* @__PURE__ */ jsx25(
6298
+ /* @__PURE__ */ jsx26(
6000
6299
  "button",
6001
6300
  {
6002
6301
  type: "button",
@@ -6005,12 +6304,12 @@ var SidebarSection = ({
6005
6304
  children: breadcrumb.label
6006
6305
  }
6007
6306
  ),
6008
- /* @__PURE__ */ jsx25(ChevronRight, { size: 16 })
6307
+ /* @__PURE__ */ jsx26(ChevronRight, { size: 16 })
6009
6308
  ] }, i)) : null,
6010
- /* @__PURE__ */ jsx25("div", { className: getClassName19("heading"), children: /* @__PURE__ */ jsx25(Heading, { rank: "2", size: "xs", children: title }) })
6309
+ /* @__PURE__ */ jsx26("div", { className: getClassName19("heading"), children: /* @__PURE__ */ jsx26(Heading, { rank: "2", size: "xs", children: title }) })
6011
6310
  ] }) }),
6012
- /* @__PURE__ */ jsx25("div", { className: getClassName19("content"), children }),
6013
- isLoading && /* @__PURE__ */ jsx25("div", { className: getClassName19("loadingOverlay"), children: /* @__PURE__ */ jsx25(Loader, { size: 32 }) })
6311
+ /* @__PURE__ */ jsx26("div", { className: getClassName19("content"), children }),
6312
+ isLoading && /* @__PURE__ */ jsx26("div", { className: getClassName19("loadingOverlay"), children: /* @__PURE__ */ jsx26(Loader, { size: 32 }) })
6014
6313
  ]
6015
6314
  }
6016
6315
  );
@@ -6024,7 +6323,7 @@ init_react_import();
6024
6323
  var styles_module_default14 = { "MenuBar": "_MenuBar_8pf8c_1", "MenuBar--menuOpen": "_MenuBar--menuOpen_8pf8c_14", "MenuBar-inner": "_MenuBar-inner_8pf8c_29", "MenuBar-history": "_MenuBar-history_8pf8c_45" };
6025
6324
 
6026
6325
  // components/MenuBar/index.tsx
6027
- import { Fragment as Fragment7, jsx as jsx26, jsxs as jsxs13 } from "react/jsx-runtime";
6326
+ import { Fragment as Fragment7, jsx as jsx27, jsxs as jsxs13 } from "react/jsx-runtime";
6028
6327
  var getClassName20 = get_class_name_factory_default("MenuBar", styles_module_default14);
6029
6328
  function MenuBar({
6030
6329
  menuOpen = false,
@@ -6035,7 +6334,7 @@ function MenuBar({
6035
6334
  const forward = useAppStore((s) => s.history.forward);
6036
6335
  const hasFuture = useAppStore((s) => s.history.hasFuture());
6037
6336
  const hasPast = useAppStore((s) => s.history.hasPast());
6038
- return /* @__PURE__ */ jsx26(
6337
+ return /* @__PURE__ */ jsx27(
6039
6338
  "div",
6040
6339
  {
6041
6340
  className: getClassName20({ menuOpen }),
@@ -6051,10 +6350,10 @@ function MenuBar({
6051
6350
  },
6052
6351
  children: /* @__PURE__ */ jsxs13("div", { className: getClassName20("inner"), children: [
6053
6352
  /* @__PURE__ */ jsxs13("div", { className: getClassName20("history"), children: [
6054
- /* @__PURE__ */ jsx26(IconButton, { title: "undo", disabled: !hasPast, onClick: back, children: /* @__PURE__ */ jsx26(Undo2, { size: 21 }) }),
6055
- /* @__PURE__ */ jsx26(IconButton, { title: "redo", disabled: !hasFuture, onClick: forward, children: /* @__PURE__ */ jsx26(Redo2, { size: 21 }) })
6353
+ /* @__PURE__ */ jsx27(IconButton, { title: "undo", disabled: !hasPast, onClick: back, children: /* @__PURE__ */ jsx27(Undo2, { size: 21 }) }),
6354
+ /* @__PURE__ */ jsx27(IconButton, { title: "redo", disabled: !hasFuture, onClick: forward, children: /* @__PURE__ */ jsx27(Redo2, { size: 21 }) })
6056
6355
  ] }),
6057
- /* @__PURE__ */ jsx26(Fragment7, { children: renderHeaderActions && renderHeaderActions() })
6356
+ /* @__PURE__ */ jsx27(Fragment7, { children: renderHeaderActions && renderHeaderActions() })
6058
6357
  ] })
6059
6358
  }
6060
6359
  );
@@ -6072,19 +6371,18 @@ init_react_import();
6072
6371
  var styles_module_default16 = { "PuckFields": "_PuckFields_10bh7_1", "PuckFields--isLoading": "_PuckFields--isLoading_10bh7_6", "PuckFields-loadingOverlay": "_PuckFields-loadingOverlay_10bh7_10", "PuckFields-loadingOverlayInner": "_PuckFields-loadingOverlayInner_10bh7_25", "PuckFields-field": "_PuckFields-field_10bh7_32", "PuckFields--wrapFields": "_PuckFields--wrapFields_10bh7_36" };
6073
6372
 
6074
6373
  // components/Puck/components/Fields/index.tsx
6075
- import { useCallback as useCallback11, useMemo as useMemo11 } from "react";
6374
+ import { useCallback as useCallback11, useMemo as useMemo13 } from "react";
6076
6375
  import { useShallow as useShallow4 } from "zustand/react/shallow";
6077
- import { Fragment as Fragment8, jsx as jsx27, jsxs as jsxs14 } from "react/jsx-runtime";
6376
+ import { Fragment as Fragment8, jsx as jsx28, jsxs as jsxs14 } from "react/jsx-runtime";
6078
6377
  var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
6079
6378
  var DefaultFields = ({
6080
6379
  children
6081
6380
  }) => {
6082
- return /* @__PURE__ */ jsx27(Fragment8, { children });
6381
+ return /* @__PURE__ */ jsx28(Fragment8, { children });
6083
6382
  };
6084
- var createOnChange = (fieldName, appStore) => (value, updatedUi) => {
6085
- var _a, _b;
6383
+ var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(void 0, null, function* () {
6086
6384
  let currentProps;
6087
- const { dispatch, resolveData: resolveData2, config, state, selectedItem } = appStore.getState();
6385
+ const { dispatch, state, selectedItem, resolveComponentData: resolveComponentData2 } = appStore.getState();
6088
6386
  const { data, ui } = state;
6089
6387
  const { itemSelector } = ui;
6090
6388
  const rootProps = data.root.props || data.root;
@@ -6097,48 +6395,27 @@ var createOnChange = (fieldName, appStore) => (value, updatedUi) => {
6097
6395
  [fieldName]: value
6098
6396
  });
6099
6397
  if (selectedItem && itemSelector) {
6100
- const replaceActionData = {
6398
+ dispatch({
6101
6399
  type: "replace",
6102
6400
  destinationIndex: itemSelector.index,
6103
6401
  destinationZone: itemSelector.zone || rootDroppableId,
6104
- data: __spreadProps(__spreadValues({}, selectedItem), { props: newProps })
6105
- };
6106
- const replacedData = replaceAction(data, replaceActionData);
6107
- const setActionData = {
6108
- type: "set",
6109
- state: {
6110
- data: __spreadValues(__spreadValues({}, data), replacedData),
6111
- ui: __spreadValues(__spreadValues({}, ui), updatedUi)
6112
- }
6113
- };
6114
- if ((_a = config.components[selectedItem.type]) == null ? void 0 : _a.resolveData) {
6115
- resolveData2(setAction(state, setActionData));
6116
- } else {
6117
- dispatch(__spreadProps(__spreadValues({}, setActionData), {
6118
- recordHistory: true
6119
- }));
6120
- }
6402
+ data: (yield resolveComponentData2(
6403
+ __spreadProps(__spreadValues({}, selectedItem), { props: newProps }),
6404
+ "replace"
6405
+ )).node,
6406
+ ui: updatedUi
6407
+ });
6121
6408
  } else {
6122
6409
  if (data.root.props) {
6123
- if ((_b = config.root) == null ? void 0 : _b.resolveData) {
6124
- resolveData2({
6125
- ui: __spreadValues(__spreadValues({}, ui), updatedUi),
6126
- data: __spreadProps(__spreadValues({}, data), {
6127
- root: { props: newProps }
6128
- })
6129
- });
6130
- } else {
6131
- dispatch({
6132
- type: "set",
6133
- state: {
6134
- ui: __spreadValues(__spreadValues({}, ui), updatedUi),
6135
- data: __spreadProps(__spreadValues({}, data), {
6136
- root: { props: newProps }
6137
- })
6138
- },
6139
- recordHistory: true
6140
- });
6141
- }
6410
+ dispatch({
6411
+ type: "replaceRoot",
6412
+ root: (yield resolveComponentData2(
6413
+ __spreadProps(__spreadValues({}, data.root), { props: newProps }),
6414
+ "replace"
6415
+ )).node,
6416
+ ui: __spreadValues(__spreadValues({}, ui), updatedUi),
6417
+ recordHistory: true
6418
+ });
6142
6419
  } else {
6143
6420
  dispatch({
6144
6421
  type: "setData",
@@ -6146,7 +6423,7 @@ var createOnChange = (fieldName, appStore) => (value, updatedUi) => {
6146
6423
  });
6147
6424
  }
6148
6425
  }
6149
- };
6426
+ });
6150
6427
  var FieldsChild = ({ fieldName }) => {
6151
6428
  const field = useAppStore((s) => s.fields.fields[fieldName]);
6152
6429
  const isReadOnly = useAppStore(
@@ -6171,7 +6448,8 @@ var FieldsChild = ({ fieldName }) => {
6171
6448
  fieldName
6172
6449
  ]);
6173
6450
  if (!field || !id) return null;
6174
- return /* @__PURE__ */ jsx27("div", { className: getClassName21("field"), children: /* @__PURE__ */ jsx27(
6451
+ if (field.type === "slot") return null;
6452
+ return /* @__PURE__ */ jsx28("div", { className: getClassName21("field"), children: /* @__PURE__ */ jsx28(
6175
6453
  AutoFieldPrivate,
6176
6454
  {
6177
6455
  field,
@@ -6187,7 +6465,7 @@ var Fields = ({ wrapFields = true }) => {
6187
6465
  const overrides = useAppStore((s) => s.overrides);
6188
6466
  const componentResolving = useAppStore((s) => {
6189
6467
  var _a, _b;
6190
- const loadingCount = s.selectedItem ? (_a = s.componentState[s.selectedItem.props.id]) == null ? void 0 : _a.loadingCount : (_b = s.componentState["puck-root"]) == null ? void 0 : _b.loadingCount;
6468
+ const loadingCount = s.selectedItem ? (_a = s.componentState[s.selectedItem.props.id]) == null ? void 0 : _a.loadingCount : (_b = s.componentState["root"]) == null ? void 0 : _b.loadingCount;
6191
6469
  return (loadingCount != null ? loadingCount : 0) > 0;
6192
6470
  });
6193
6471
  const itemSelector = useAppStore(useShallow4((s) => s.state.ui.itemSelector));
@@ -6202,7 +6480,7 @@ var Fields = ({ wrapFields = true }) => {
6202
6480
  useShallow4((s) => Object.keys(s.fields.fields))
6203
6481
  );
6204
6482
  const isLoading = fieldsLoading || componentResolving;
6205
- const Wrapper = useMemo11(() => overrides.fields || DefaultFields, [overrides]);
6483
+ const Wrapper = useMemo13(() => overrides.fields || DefaultFields, [overrides]);
6206
6484
  return /* @__PURE__ */ jsxs14(
6207
6485
  "form",
6208
6486
  {
@@ -6211,8 +6489,8 @@ var Fields = ({ wrapFields = true }) => {
6211
6489
  e.preventDefault();
6212
6490
  },
6213
6491
  children: [
6214
- /* @__PURE__ */ jsx27(Wrapper, { isLoading, itemSelector, children: fieldNames.map((fieldName) => /* @__PURE__ */ jsx27(FieldsChild, { fieldName }, fieldName)) }),
6215
- isLoading && /* @__PURE__ */ jsx27("div", { className: getClassName21("loadingOverlay"), children: /* @__PURE__ */ jsx27("div", { className: getClassName21("loadingOverlayInner"), children: /* @__PURE__ */ jsx27(Loader, { size: 16 }) }) })
6492
+ /* @__PURE__ */ jsx28(Wrapper, { isLoading, itemSelector, children: fieldNames.map((fieldName) => /* @__PURE__ */ jsx28(FieldsChild, { fieldName }, fieldName)) }),
6493
+ isLoading && /* @__PURE__ */ jsx28("div", { className: getClassName21("loadingOverlay"), children: /* @__PURE__ */ jsx28("div", { className: getClassName21("loadingOverlayInner"), children: /* @__PURE__ */ jsx28(Loader, { size: 16 }) }) })
6216
6494
  ]
6217
6495
  }
6218
6496
  );
@@ -6223,7 +6501,7 @@ init_react_import();
6223
6501
 
6224
6502
  // lib/use-component-list.tsx
6225
6503
  init_react_import();
6226
- import { useEffect as useEffect18, useState as useState16 } from "react";
6504
+ import { useEffect as useEffect17, useState as useState16 } from "react";
6227
6505
 
6228
6506
  // components/ComponentList/index.tsx
6229
6507
  init_react_import();
@@ -6233,7 +6511,7 @@ init_react_import();
6233
6511
  var styles_module_default17 = { "ComponentList": "_ComponentList_1rrlt_1", "ComponentList--isExpanded": "_ComponentList--isExpanded_1rrlt_5", "ComponentList-content": "_ComponentList-content_1rrlt_9", "ComponentList-title": "_ComponentList-title_1rrlt_17", "ComponentList-titleIcon": "_ComponentList-titleIcon_1rrlt_53" };
6234
6512
 
6235
6513
  // components/ComponentList/index.tsx
6236
- import { jsx as jsx28, jsxs as jsxs15 } from "react/jsx-runtime";
6514
+ import { jsx as jsx29, jsxs as jsxs15 } from "react/jsx-runtime";
6237
6515
  var getClassName22 = get_class_name_factory_default("ComponentList", styles_module_default17);
6238
6516
  var ComponentListItem = ({
6239
6517
  name,
@@ -6245,7 +6523,7 @@ var ComponentListItem = ({
6245
6523
  type: name
6246
6524
  }).insert
6247
6525
  );
6248
- return /* @__PURE__ */ jsx28(Drawer.Item, { label, name, isDragDisabled: !canInsert, children: overrides.componentItem });
6526
+ return /* @__PURE__ */ jsx29(Drawer.Item, { label, name, isDragDisabled: !canInsert, children: overrides.componentItem });
6249
6527
  };
6250
6528
  var ComponentList = ({
6251
6529
  children,
@@ -6271,14 +6549,14 @@ var ComponentList = ({
6271
6549
  }),
6272
6550
  title: expanded ? `Collapse${title ? ` ${title}` : ""}` : `Expand${title ? ` ${title}` : ""}`,
6273
6551
  children: [
6274
- /* @__PURE__ */ jsx28("div", { children: title }),
6275
- /* @__PURE__ */ jsx28("div", { className: getClassName22("titleIcon"), children: expanded ? /* @__PURE__ */ jsx28(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx28(ChevronDown, { size: 12 }) })
6552
+ /* @__PURE__ */ jsx29("div", { children: title }),
6553
+ /* @__PURE__ */ jsx29("div", { className: getClassName22("titleIcon"), children: expanded ? /* @__PURE__ */ jsx29(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx29(ChevronDown, { size: 12 }) })
6276
6554
  ]
6277
6555
  }
6278
6556
  ),
6279
- /* @__PURE__ */ jsx28("div", { className: getClassName22("content"), children: /* @__PURE__ */ jsx28(Drawer, { children: children || Object.keys(config.components).map((componentKey) => {
6557
+ /* @__PURE__ */ jsx29("div", { className: getClassName22("content"), children: /* @__PURE__ */ jsx29(Drawer, { children: children || Object.keys(config.components).map((componentKey) => {
6280
6558
  var _a;
6281
- return /* @__PURE__ */ jsx28(
6559
+ return /* @__PURE__ */ jsx29(
6282
6560
  ComponentListItem,
6283
6561
  {
6284
6562
  label: (_a = config.components[componentKey]["label"]) != null ? _a : componentKey,
@@ -6292,12 +6570,12 @@ var ComponentList = ({
6292
6570
  ComponentList.Item = ComponentListItem;
6293
6571
 
6294
6572
  // lib/use-component-list.tsx
6295
- import { jsx as jsx29 } from "react/jsx-runtime";
6573
+ import { jsx as jsx30 } from "react/jsx-runtime";
6296
6574
  var useComponentList = () => {
6297
6575
  const [componentList, setComponentList] = useState16();
6298
6576
  const config = useAppStore((s) => s.config);
6299
6577
  const uiComponentList = useAppStore((s) => s.state.ui.componentList);
6300
- useEffect18(() => {
6578
+ useEffect17(() => {
6301
6579
  var _a, _b, _c;
6302
6580
  if (Object.keys(uiComponentList).length > 0) {
6303
6581
  const matchedComponents = [];
@@ -6307,7 +6585,7 @@ var useComponentList = () => {
6307
6585
  if (category.visible === false || !category.components) {
6308
6586
  return null;
6309
6587
  }
6310
- return /* @__PURE__ */ jsx29(
6588
+ return /* @__PURE__ */ jsx30(
6311
6589
  ComponentList,
6312
6590
  {
6313
6591
  id: categoryKey,
@@ -6316,7 +6594,7 @@ var useComponentList = () => {
6316
6594
  var _a2;
6317
6595
  matchedComponents.push(componentName);
6318
6596
  const componentConf = config.components[componentName] || {};
6319
- return /* @__PURE__ */ jsx29(
6597
+ return /* @__PURE__ */ jsx30(
6320
6598
  ComponentList.Item,
6321
6599
  {
6322
6600
  label: (_a2 = componentConf["label"]) != null ? _a2 : componentName,
@@ -6336,7 +6614,7 @@ var useComponentList = () => {
6336
6614
  );
6337
6615
  if (remainingComponents.length > 0 && !((_a = uiComponentList.other) == null ? void 0 : _a.components) && ((_b = uiComponentList.other) == null ? void 0 : _b.visible) !== false) {
6338
6616
  _componentList.push(
6339
- /* @__PURE__ */ jsx29(
6617
+ /* @__PURE__ */ jsx30(
6340
6618
  ComponentList,
6341
6619
  {
6342
6620
  id: "other",
@@ -6344,7 +6622,7 @@ var useComponentList = () => {
6344
6622
  children: remainingComponents.map((componentName, i) => {
6345
6623
  var _a2;
6346
6624
  const componentConf = config.components[componentName] || {};
6347
- return /* @__PURE__ */ jsx29(
6625
+ return /* @__PURE__ */ jsx30(
6348
6626
  ComponentList.Item,
6349
6627
  {
6350
6628
  name: componentName,
@@ -6366,30 +6644,30 @@ var useComponentList = () => {
6366
6644
  };
6367
6645
 
6368
6646
  // components/Puck/components/Components/index.tsx
6369
- import { useMemo as useMemo12 } from "react";
6370
- import { jsx as jsx30 } from "react/jsx-runtime";
6647
+ import { useMemo as useMemo14 } from "react";
6648
+ import { jsx as jsx31 } from "react/jsx-runtime";
6371
6649
  var Components = () => {
6372
6650
  const overrides = useAppStore((s) => s.overrides);
6373
6651
  const componentList = useComponentList();
6374
- const Wrapper = useMemo12(() => overrides.components || "div", [overrides]);
6375
- return /* @__PURE__ */ jsx30(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ jsx30(ComponentList, { id: "all" }) });
6652
+ const Wrapper = useMemo14(() => overrides.components || "div", [overrides]);
6653
+ return /* @__PURE__ */ jsx31(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ jsx31(ComponentList, { id: "all" }) });
6376
6654
  };
6377
6655
 
6378
6656
  // components/Puck/components/Preview/index.tsx
6379
6657
  init_react_import();
6380
- import { useCallback as useCallback12, useEffect as useEffect20, useRef as useRef5, useMemo as useMemo13 } from "react";
6658
+ import { useCallback as useCallback12, useEffect as useEffect19, useRef as useRef5, useMemo as useMemo15 } from "react";
6381
6659
 
6382
6660
  // components/AutoFrame/index.tsx
6383
6661
  init_react_import();
6384
6662
  import {
6385
6663
  createContext as createContext5,
6386
6664
  useContext as useContext8,
6387
- useEffect as useEffect19,
6665
+ useEffect as useEffect18,
6388
6666
  useState as useState17
6389
6667
  } from "react";
6390
6668
  import hash from "object-hash";
6391
6669
  import { createPortal as createPortal3 } from "react-dom";
6392
- import { Fragment as Fragment9, jsx as jsx31 } from "react/jsx-runtime";
6670
+ import { Fragment as Fragment9, jsx as jsx32 } from "react/jsx-runtime";
6393
6671
  var styleSelector = 'style, link[rel="stylesheet"]';
6394
6672
  var collectStyles = (doc) => {
6395
6673
  const collected = [];
@@ -6432,7 +6710,7 @@ var CopyHostStyles = ({
6432
6710
  onStylesLoaded = () => null
6433
6711
  }) => {
6434
6712
  const { document: doc, window: win } = useFrame();
6435
- useEffect19(() => {
6713
+ useEffect18(() => {
6436
6714
  if (!win || !doc) {
6437
6715
  return () => {
6438
6716
  };
@@ -6589,7 +6867,7 @@ var CopyHostStyles = ({
6589
6867
  observer.disconnect();
6590
6868
  };
6591
6869
  }, []);
6592
- return /* @__PURE__ */ jsx31(Fragment9, { children });
6870
+ return /* @__PURE__ */ jsx32(Fragment9, { children });
6593
6871
  };
6594
6872
  var autoFrameContext = createContext5({});
6595
6873
  var useFrame = () => useContext8(autoFrameContext);
@@ -6617,7 +6895,7 @@ function AutoFrame(_a) {
6617
6895
  const [ctx, setCtx] = useState17({});
6618
6896
  const [mountTarget, setMountTarget] = useState17();
6619
6897
  const [stylesLoaded, setStylesLoaded] = useState17(false);
6620
- useEffect19(() => {
6898
+ useEffect18(() => {
6621
6899
  var _a2;
6622
6900
  if (frameRef.current) {
6623
6901
  const doc = frameRef.current.contentDocument;
@@ -6636,7 +6914,7 @@ function AutoFrame(_a) {
6636
6914
  }
6637
6915
  }
6638
6916
  }, [frameRef, loaded, stylesLoaded]);
6639
- return /* @__PURE__ */ jsx31(
6917
+ return /* @__PURE__ */ jsx32(
6640
6918
  "iframe",
6641
6919
  __spreadProps(__spreadValues({}, props), {
6642
6920
  className,
@@ -6646,7 +6924,7 @@ function AutoFrame(_a) {
6646
6924
  onLoad: () => {
6647
6925
  setLoaded(true);
6648
6926
  },
6649
- children: /* @__PURE__ */ jsx31(autoFrameContext.Provider, { value: ctx, children: loaded && mountTarget && /* @__PURE__ */ jsx31(
6927
+ children: /* @__PURE__ */ jsx32(autoFrameContext.Provider, { value: ctx, children: loaded && mountTarget && /* @__PURE__ */ jsx32(
6650
6928
  CopyHostStyles,
6651
6929
  {
6652
6930
  debug,
@@ -6665,11 +6943,11 @@ init_react_import();
6665
6943
  var styles_module_default18 = { "PuckPreview": "_PuckPreview_z2rgu_1", "PuckPreview-frame": "_PuckPreview-frame_z2rgu_6" };
6666
6944
 
6667
6945
  // components/Puck/components/Preview/index.tsx
6668
- import { Fragment as Fragment10, jsx as jsx32 } from "react/jsx-runtime";
6946
+ import { Fragment as Fragment10, jsx as jsx33 } from "react/jsx-runtime";
6669
6947
  var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
6670
6948
  var useBubbleIframeEvents = (ref) => {
6671
6949
  const status = useAppStore((s) => s.status);
6672
- useEffect20(() => {
6950
+ useEffect19(() => {
6673
6951
  if (ref.current && status === "READY") {
6674
6952
  const iframe = ref.current;
6675
6953
  const handlePointerMove = (event) => {
@@ -6721,17 +6999,19 @@ var Preview3 = ({ id = "puck-preview" }) => {
6721
6999
  const Page = useCallback12(
6722
7000
  (pageProps) => {
6723
7001
  var _a, _b;
7002
+ const rootConfig = config.root;
7003
+ const propsWithSlots = useSlots(rootConfig, pageProps, DropZoneEditPure);
6724
7004
  return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
6725
7005
  id: "puck-root"
6726
- }, pageProps)) : /* @__PURE__ */ jsx32(Fragment10, { children: pageProps.children });
7006
+ }, propsWithSlots)) : /* @__PURE__ */ jsx33(Fragment10, { children: propsWithSlots.children });
6727
7007
  },
6728
7008
  [config.root]
6729
7009
  );
6730
- const Frame = useMemo13(() => overrides.iframe, [overrides]);
7010
+ const Frame = useMemo15(() => overrides.iframe, [overrides]);
6731
7011
  const rootProps = root.props || root;
6732
7012
  const ref = useRef5(null);
6733
7013
  useBubbleIframeEvents(ref);
6734
- const inner = !renderData ? /* @__PURE__ */ jsx32(
7014
+ const inner = !renderData ? /* @__PURE__ */ jsx33(
6735
7015
  Page,
6736
7016
  __spreadProps(__spreadValues({}, rootProps), {
6737
7017
  puck: {
@@ -6741,15 +7021,15 @@ var Preview3 = ({ id = "puck-preview" }) => {
6741
7021
  metadata
6742
7022
  },
6743
7023
  editMode: true,
6744
- children: /* @__PURE__ */ jsx32(DropZonePure, { zone: rootDroppableId })
7024
+ children: /* @__PURE__ */ jsx33(DropZonePure, { zone: rootDroppableId })
6745
7025
  })
6746
- ) : /* @__PURE__ */ jsx32(Render, { data: renderData, config });
6747
- useEffect20(() => {
7026
+ ) : /* @__PURE__ */ jsx33(Render, { data: renderData, config });
7027
+ useEffect19(() => {
6748
7028
  if (!iframe.enabled) {
6749
7029
  setStatus("READY");
6750
7030
  }
6751
7031
  }, [iframe.enabled]);
6752
- return /* @__PURE__ */ jsx32(
7032
+ return /* @__PURE__ */ jsx33(
6753
7033
  "div",
6754
7034
  {
6755
7035
  className: getClassName23(),
@@ -6758,7 +7038,7 @@ var Preview3 = ({ id = "puck-preview" }) => {
6758
7038
  onClick: () => {
6759
7039
  dispatch({ type: "setUi", ui: { itemSelector: null } });
6760
7040
  },
6761
- children: iframe.enabled ? /* @__PURE__ */ jsx32(
7041
+ children: iframe.enabled ? /* @__PURE__ */ jsx33(
6762
7042
  AutoFrame_default,
6763
7043
  {
6764
7044
  id: "preview-frame",
@@ -6771,14 +7051,14 @@ var Preview3 = ({ id = "puck-preview" }) => {
6771
7051
  setStatus("MOUNTED");
6772
7052
  },
6773
7053
  frameRef: ref,
6774
- children: /* @__PURE__ */ jsx32(autoFrameContext.Consumer, { children: ({ document: document2 }) => {
7054
+ children: /* @__PURE__ */ jsx33(autoFrameContext.Consumer, { children: ({ document: document2 }) => {
6775
7055
  if (Frame) {
6776
- return /* @__PURE__ */ jsx32(Frame, { document: document2, children: inner });
7056
+ return /* @__PURE__ */ jsx33(Frame, { document: document2, children: inner });
6777
7057
  }
6778
7058
  return inner;
6779
7059
  } })
6780
7060
  }
6781
- ) : /* @__PURE__ */ jsx32(
7061
+ ) : /* @__PURE__ */ jsx33(
6782
7062
  "div",
6783
7063
  {
6784
7064
  id: "preview-frame",
@@ -6795,27 +7075,6 @@ var Preview3 = ({ id = "puck-preview" }) => {
6795
7075
  // components/Puck/components/Outline/index.tsx
6796
7076
  init_react_import();
6797
7077
 
6798
- // lib/area-contains-zones.ts
6799
- init_react_import();
6800
-
6801
- // lib/find-zones-for-area.ts
6802
- init_react_import();
6803
- var findZonesForArea = (data, area) => {
6804
- const { zones = {} } = data;
6805
- const result = Object.keys(zones).filter(
6806
- (zoneId) => getZoneId(zoneId)[0] === area
6807
- );
6808
- return result.reduce((acc, key) => {
6809
- return __spreadProps(__spreadValues({}, acc), { [key]: zones[key] });
6810
- }, {});
6811
- };
6812
-
6813
- // lib/area-contains-zones.ts
6814
- var areaContainsZones = (data, area) => {
6815
- const zones = Object.keys(findZonesForArea(data, area));
6816
- return zones.length > 0;
6817
- };
6818
-
6819
7078
  // components/LayerTree/index.tsx
6820
7079
  init_react_import();
6821
7080
 
@@ -6835,7 +7094,7 @@ var scrollIntoView = (el) => {
6835
7094
  };
6836
7095
 
6837
7096
  // components/LayerTree/index.tsx
6838
- import { useContext as useContext9 } from "react";
7097
+ import { useCallback as useCallback13, useContext as useContext9 } from "react";
6839
7098
 
6840
7099
  // lib/on-scroll-end.ts
6841
7100
  init_react_import();
@@ -6857,124 +7116,147 @@ var onScrollEnd = (frame, cb) => {
6857
7116
  };
6858
7117
 
6859
7118
  // components/LayerTree/index.tsx
6860
- import { Fragment as Fragment11, jsx as jsx33, jsxs as jsxs16 } from "react/jsx-runtime";
7119
+ import { useShallow as useShallow5 } from "zustand/react/shallow";
7120
+ import { Fragment as Fragment11, jsx as jsx34, jsxs as jsxs16 } from "react/jsx-runtime";
6861
7121
  var getClassName24 = get_class_name_factory_default("LayerTree", styles_module_default19);
6862
7122
  var getClassNameLayer = get_class_name_factory_default("Layer", styles_module_default19);
6863
- var LayerTree = ({
6864
- data,
6865
- config,
6866
- zoneContent,
6867
- itemSelector,
6868
- setItemSelector,
6869
- zone,
6870
- label
7123
+ var Layer = ({
7124
+ index,
7125
+ itemId,
7126
+ zoneCompound
6871
7127
  }) => {
6872
- const zones = data.zones || {};
7128
+ var _a;
6873
7129
  const ctx = useContext9(dropZoneContext);
6874
- const nodes = useAppStore((s) => s.nodes.nodes);
7130
+ const config = useAppStore((s) => s.config);
7131
+ const itemSelector = useAppStore((s) => s.state.ui.itemSelector);
7132
+ const dispatch = useAppStore((s) => s.dispatch);
7133
+ const setItemSelector = useCallback13(
7134
+ (itemSelector2) => {
7135
+ dispatch({ type: "setUi", ui: { itemSelector: itemSelector2 } });
7136
+ },
7137
+ [dispatch]
7138
+ );
7139
+ const selecedItemId = useAppStore((s) => {
7140
+ var _a2;
7141
+ return (_a2 = s.selectedItem) == null ? void 0 : _a2.props.id;
7142
+ });
7143
+ const isSelected = selecedItemId === itemId || itemSelector && itemSelector.zone === rootDroppableId && !zoneCompound;
7144
+ const nodeData = useAppStore((s) => s.state.indexes.nodes[itemId]);
7145
+ const zonesForItem = useAppStore(
7146
+ useShallow5(
7147
+ (s) => Object.keys(s.state.indexes.zones).filter(
7148
+ (z) => z.split(":")[0] === itemId
7149
+ )
7150
+ )
7151
+ );
7152
+ const containsZone = zonesForItem.length > 0;
7153
+ const { setHoveringComponent = () => {
7154
+ }, hoveringComponent } = ctx || {};
7155
+ const isHovering = hoveringComponent === itemId;
7156
+ const childIsSelected = useAppStore((s) => {
7157
+ var _a2, _b;
7158
+ const selectedData = s.state.indexes.nodes[(_a2 = s.selectedItem) == null ? void 0 : _a2.props.id];
7159
+ return (_b = selectedData == null ? void 0 : selectedData.path.some((candidate) => {
7160
+ const [candidateId] = candidate.split(":");
7161
+ return candidateId === itemId;
7162
+ })) != null ? _b : false;
7163
+ });
7164
+ const componentConfig = config.components[nodeData.data.type];
7165
+ const label = (_a = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _a : nodeData.data.type.toString();
7166
+ return /* @__PURE__ */ jsxs16(
7167
+ "li",
7168
+ {
7169
+ className: getClassNameLayer({
7170
+ isSelected,
7171
+ isHovering,
7172
+ containsZone,
7173
+ childIsSelected
7174
+ }),
7175
+ children: [
7176
+ /* @__PURE__ */ jsx34("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ jsxs16(
7177
+ "button",
7178
+ {
7179
+ type: "button",
7180
+ className: getClassNameLayer("clickable"),
7181
+ onClick: () => {
7182
+ if (isSelected) {
7183
+ setItemSelector(null);
7184
+ return;
7185
+ }
7186
+ const frame = getFrame();
7187
+ const el = frame == null ? void 0 : frame.querySelector(
7188
+ `[data-puck-component="${itemId}"]`
7189
+ );
7190
+ if (!el) {
7191
+ console.error("Scroll failed. No element was found for", itemId);
7192
+ return;
7193
+ }
7194
+ scrollIntoView(el);
7195
+ onScrollEnd(frame, () => {
7196
+ setItemSelector({
7197
+ index,
7198
+ zone: zoneCompound
7199
+ });
7200
+ });
7201
+ },
7202
+ onMouseOver: (e) => {
7203
+ e.stopPropagation();
7204
+ setHoveringComponent(itemId);
7205
+ },
7206
+ onMouseOut: (e) => {
7207
+ e.stopPropagation();
7208
+ setHoveringComponent(null);
7209
+ },
7210
+ children: [
7211
+ containsZone && /* @__PURE__ */ jsx34(
7212
+ "div",
7213
+ {
7214
+ className: getClassNameLayer("chevron"),
7215
+ title: isSelected ? "Collapse" : "Expand",
7216
+ children: /* @__PURE__ */ jsx34(ChevronDown, { size: "12" })
7217
+ }
7218
+ ),
7219
+ /* @__PURE__ */ jsxs16("div", { className: getClassNameLayer("title"), children: [
7220
+ /* @__PURE__ */ jsx34("div", { className: getClassNameLayer("icon"), children: nodeData.data.type === "Text" || nodeData.data.type === "Heading" ? /* @__PURE__ */ jsx34(Type, { size: "16" }) : /* @__PURE__ */ jsx34(LayoutGrid, { size: "16" }) }),
7221
+ /* @__PURE__ */ jsx34("div", { className: getClassNameLayer("name"), children: label })
7222
+ ] })
7223
+ ]
7224
+ }
7225
+ ) }),
7226
+ containsZone && zonesForItem.map((subzone) => /* @__PURE__ */ jsx34("div", { className: getClassNameLayer("zones"), children: /* @__PURE__ */ jsx34(LayerTree, { zoneCompound: subzone }) }, subzone))
7227
+ ]
7228
+ }
7229
+ );
7230
+ };
7231
+ var LayerTree = ({
7232
+ label: _label,
7233
+ zoneCompound
7234
+ }) => {
7235
+ const label = _label != null ? _label : zoneCompound.split(":")[1];
7236
+ const contentIds = useAppStore(
7237
+ useShallow5(
7238
+ (s) => {
7239
+ var _a, _b;
7240
+ return zoneCompound ? (_b = (_a = s.state.indexes.zones[zoneCompound]) == null ? void 0 : _a.contentIds) != null ? _b : [] : [];
7241
+ }
7242
+ )
7243
+ );
6875
7244
  return /* @__PURE__ */ jsxs16(Fragment11, { children: [
6876
7245
  label && /* @__PURE__ */ jsxs16("div", { className: getClassName24("zoneTitle"), children: [
6877
- /* @__PURE__ */ jsx33("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ jsx33(Layers, { size: "16" }) }),
6878
- " ",
7246
+ /* @__PURE__ */ jsx34("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ jsx34(Layers, { size: "16" }) }),
6879
7247
  label
6880
7248
  ] }),
6881
7249
  /* @__PURE__ */ jsxs16("ul", { className: getClassName24(), children: [
6882
- zoneContent.length === 0 && /* @__PURE__ */ jsx33("div", { className: getClassName24("helper"), children: "No items" }),
6883
- zoneContent.map((item, i) => {
6884
- var _a, _b, _c, _d;
6885
- const isSelected = (itemSelector == null ? void 0 : itemSelector.index) === i && (itemSelector.zone === zone || itemSelector.zone === rootDroppableId && !zone);
6886
- const zonesForItem = findZonesForArea(data, item.props.id);
6887
- const containsZone = Object.keys(zonesForItem).length > 0;
6888
- const { setHoveringComponent = () => {
6889
- }, hoveringComponent } = ctx || {};
6890
- const selectedItem = itemSelector && data ? getItem(itemSelector, data) : null;
6891
- const isHovering = hoveringComponent === item.props.id;
6892
- const path = selectedItem ? (_b = (_a = nodes[selectedItem == null ? void 0 : selectedItem.props.id]) == null ? void 0 : _a.path) != null ? _b : [] : [];
6893
- const childIsSelected = (_c = path == null ? void 0 : path.some((candidate) => {
6894
- const [candidateId] = candidate.split(":");
6895
- return candidateId === item.props.id;
6896
- })) != null ? _c : false;
6897
- const componentConfig = config.components[item.type];
6898
- const label2 = (_d = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _d : item.type.toString();
6899
- return /* @__PURE__ */ jsxs16(
6900
- "li",
7250
+ contentIds.length === 0 && /* @__PURE__ */ jsx34("div", { className: getClassName24("helper"), children: "No items" }),
7251
+ contentIds.map((itemId, i) => {
7252
+ return /* @__PURE__ */ jsx34(
7253
+ Layer,
6901
7254
  {
6902
- className: getClassNameLayer({
6903
- isSelected,
6904
- isHovering,
6905
- containsZone,
6906
- childIsSelected
6907
- }),
6908
- children: [
6909
- /* @__PURE__ */ jsx33("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ jsxs16(
6910
- "button",
6911
- {
6912
- type: "button",
6913
- className: getClassNameLayer("clickable"),
6914
- onClick: () => {
6915
- if (isSelected) {
6916
- setItemSelector(null);
6917
- return;
6918
- }
6919
- const id = zoneContent[i].props.id;
6920
- const frame = getFrame();
6921
- const el = frame == null ? void 0 : frame.querySelector(
6922
- `[data-puck-component="${id}"]`
6923
- );
6924
- if (!el) {
6925
- console.error(
6926
- "Scroll failed. No element was found for",
6927
- id
6928
- );
6929
- return;
6930
- }
6931
- scrollIntoView(el);
6932
- onScrollEnd(frame, () => {
6933
- setItemSelector({
6934
- index: i,
6935
- zone
6936
- });
6937
- });
6938
- },
6939
- onMouseOver: (e) => {
6940
- e.stopPropagation();
6941
- setHoveringComponent(item.props.id);
6942
- },
6943
- onMouseOut: (e) => {
6944
- e.stopPropagation();
6945
- setHoveringComponent(null);
6946
- },
6947
- children: [
6948
- containsZone && /* @__PURE__ */ jsx33(
6949
- "div",
6950
- {
6951
- className: getClassNameLayer("chevron"),
6952
- title: isSelected ? "Collapse" : "Expand",
6953
- children: /* @__PURE__ */ jsx33(ChevronDown, { size: "12" })
6954
- }
6955
- ),
6956
- /* @__PURE__ */ jsxs16("div", { className: getClassNameLayer("title"), children: [
6957
- /* @__PURE__ */ jsx33("div", { className: getClassNameLayer("icon"), children: item.type === "Text" || item.type === "Heading" ? /* @__PURE__ */ jsx33(Type, { size: "16" }) : /* @__PURE__ */ jsx33(LayoutGrid, { size: "16" }) }),
6958
- /* @__PURE__ */ jsx33("div", { className: getClassNameLayer("name"), children: label2 })
6959
- ] })
6960
- ]
6961
- }
6962
- ) }),
6963
- containsZone && Object.keys(zonesForItem).map((zoneKey, idx) => /* @__PURE__ */ jsx33("div", { className: getClassNameLayer("zones"), children: /* @__PURE__ */ jsx33(
6964
- LayerTree,
6965
- {
6966
- config,
6967
- data,
6968
- zoneContent: zones[zoneKey],
6969
- setItemSelector,
6970
- itemSelector,
6971
- zone: zoneKey,
6972
- label: getZoneId(zoneKey)[1]
6973
- }
6974
- ) }, idx))
6975
- ]
7255
+ index: i,
7256
+ itemId,
7257
+ zoneCompound
6976
7258
  },
6977
- `${item.props.id}_${i}`
7259
+ itemId
6978
7260
  );
6979
7261
  })
6980
7262
  ] })
@@ -6982,56 +7264,33 @@ var LayerTree = ({
6982
7264
  };
6983
7265
 
6984
7266
  // components/Puck/components/Outline/index.tsx
6985
- import { useCallback as useCallback13, useMemo as useMemo14 } from "react";
6986
- import { Fragment as Fragment12, jsx as jsx34, jsxs as jsxs17 } from "react/jsx-runtime";
7267
+ import { useMemo as useMemo16 } from "react";
7268
+
7269
+ // lib/data/find-zones-for-area.ts
7270
+ init_react_import();
7271
+ var findZonesForArea = (state, area) => {
7272
+ return Object.keys(state.indexes.zones).filter(
7273
+ (zone) => zone.split(":")[0] === area
7274
+ );
7275
+ };
7276
+
7277
+ // components/Puck/components/Outline/index.tsx
7278
+ import { useShallow as useShallow6 } from "zustand/react/shallow";
7279
+ import { jsx as jsx35 } from "react/jsx-runtime";
6987
7280
  var Outline = () => {
6988
- const state = useAppStore((s) => s.state);
6989
- const config = useAppStore((s) => s.config);
6990
7281
  const outlineOverride = useAppStore((s) => s.overrides.outline);
6991
- const { data, ui } = state;
6992
- const { itemSelector } = ui;
6993
- const appStore = useAppStoreApi();
6994
- const setItemSelector = useCallback13(
6995
- (newItemSelector) => {
6996
- const { dispatch } = appStore.getState();
6997
- dispatch({
6998
- type: "setUi",
6999
- ui: { itemSelector: newItemSelector }
7000
- });
7001
- },
7002
- [appStore]
7282
+ const rootZones = useAppStore(
7283
+ useShallow6((s) => findZonesForArea(s.state, "root"))
7003
7284
  );
7004
- const Wrapper = useMemo14(() => outlineOverride || "div", [outlineOverride]);
7005
- return /* @__PURE__ */ jsx34(Wrapper, { children: /* @__PURE__ */ jsx34(dropZoneContext.Consumer, { children: (ctx) => /* @__PURE__ */ jsxs17(Fragment12, { children: [
7006
- (ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ jsx34(
7007
- LayerTree,
7008
- {
7009
- config,
7010
- data,
7011
- label: areaContainsZones(data, "root") ? rootDroppableId : "",
7012
- zoneContent: data.content,
7013
- setItemSelector,
7014
- itemSelector
7015
- }
7016
- ),
7017
- Object.entries(findZonesForArea(data, "root")).map(
7018
- ([zoneKey, zone]) => {
7019
- return /* @__PURE__ */ jsx34(
7020
- LayerTree,
7021
- {
7022
- config,
7023
- data,
7024
- label: zoneKey,
7025
- zone: zoneKey,
7026
- zoneContent: zone,
7027
- setItemSelector,
7028
- itemSelector
7029
- },
7030
- zoneKey
7031
- );
7032
- }
7033
- )
7034
- ] }) }) });
7285
+ const Wrapper = useMemo16(() => outlineOverride || "div", [outlineOverride]);
7286
+ return /* @__PURE__ */ jsx35(Wrapper, { children: rootZones.map((zoneCompound) => /* @__PURE__ */ jsx35(
7287
+ LayerTree,
7288
+ {
7289
+ label: rootZones.length === 1 ? "" : zoneCompound.split(":")[1],
7290
+ zoneCompound
7291
+ },
7292
+ zoneCompound
7293
+ )) });
7035
7294
  };
7036
7295
 
7037
7296
  // components/Puck/components/Canvas/index.tsx
@@ -7159,26 +7418,26 @@ var getBox = function getBox2(el) {
7159
7418
  // components/Puck/components/Canvas/index.tsx
7160
7419
  import {
7161
7420
  useCallback as useCallback14,
7162
- useEffect as useEffect22,
7163
- useMemo as useMemo16,
7421
+ useEffect as useEffect21,
7422
+ useMemo as useMemo18,
7164
7423
  useRef as useRef6,
7165
7424
  useState as useState19
7166
7425
  } from "react";
7167
7426
 
7168
7427
  // components/ViewportControls/index.tsx
7169
7428
  init_react_import();
7170
- import { useEffect as useEffect21, useMemo as useMemo15, useState as useState18 } from "react";
7429
+ import { useEffect as useEffect20, useMemo as useMemo17, useState as useState18 } from "react";
7171
7430
 
7172
7431
  // css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
7173
7432
  init_react_import();
7174
7433
  var styles_module_default20 = { "ViewportControls": "_ViewportControls_gejzr_1", "ViewportControls-divider": "_ViewportControls-divider_gejzr_15", "ViewportControls-zoomSelect": "_ViewportControls-zoomSelect_gejzr_21", "ViewportButton--isActive": "_ViewportButton--isActive_gejzr_38", "ViewportButton-inner": "_ViewportButton-inner_gejzr_38" };
7175
7434
 
7176
7435
  // components/ViewportControls/index.tsx
7177
- import { jsx as jsx35, jsxs as jsxs18 } from "react/jsx-runtime";
7436
+ import { jsx as jsx36, jsxs as jsxs17 } from "react/jsx-runtime";
7178
7437
  var icons = {
7179
- Smartphone: /* @__PURE__ */ jsx35(Smartphone, { size: 16 }),
7180
- Tablet: /* @__PURE__ */ jsx35(Tablet, { size: 16 }),
7181
- Monitor: /* @__PURE__ */ jsx35(Monitor, { size: 16 })
7438
+ Smartphone: /* @__PURE__ */ jsx36(Smartphone, { size: 16 }),
7439
+ Tablet: /* @__PURE__ */ jsx36(Tablet, { size: 16 }),
7440
+ Monitor: /* @__PURE__ */ jsx36(Monitor, { size: 16 })
7182
7441
  };
7183
7442
  var getClassName25 = get_class_name_factory_default("ViewportControls", styles_module_default20);
7184
7443
  var getClassNameButton = get_class_name_factory_default("ViewportButton", styles_module_default20);
@@ -7191,10 +7450,10 @@ var ViewportButton = ({
7191
7450
  }) => {
7192
7451
  const viewports = useAppStore((s) => s.state.ui.viewports);
7193
7452
  const [isActive, setIsActive] = useState18(false);
7194
- useEffect21(() => {
7453
+ useEffect20(() => {
7195
7454
  setIsActive(width === viewports.current.width);
7196
7455
  }, [width, viewports.current.width]);
7197
- return /* @__PURE__ */ jsx35("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ jsx35(
7456
+ return /* @__PURE__ */ jsx36("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ jsx36(
7198
7457
  IconButton,
7199
7458
  {
7200
7459
  title,
@@ -7203,7 +7462,7 @@ var ViewportButton = ({
7203
7462
  e.stopPropagation();
7204
7463
  onClick({ width, height });
7205
7464
  },
7206
- children: /* @__PURE__ */ jsx35("span", { className: getClassNameButton("inner"), children })
7465
+ children: /* @__PURE__ */ jsx36("span", { className: getClassNameButton("inner"), children })
7207
7466
  }
7208
7467
  ) });
7209
7468
  };
@@ -7227,7 +7486,7 @@ var ViewportControls = ({
7227
7486
  const defaultsContainAutoZoom = defaultZoomOptions.find(
7228
7487
  (option) => option.value === autoZoom
7229
7488
  );
7230
- const zoomOptions = useMemo15(
7489
+ const zoomOptions = useMemo17(
7231
7490
  () => [
7232
7491
  ...defaultZoomOptions,
7233
7492
  ...defaultsContainAutoZoom ? [] : [
@@ -7239,8 +7498,8 @@ var ViewportControls = ({
7239
7498
  ].filter((a) => a.value <= autoZoom).sort((a, b) => a.value > b.value ? 1 : -1),
7240
7499
  [autoZoom]
7241
7500
  );
7242
- return /* @__PURE__ */ jsxs18("div", { className: getClassName25(), children: [
7243
- viewports.map((viewport, i) => /* @__PURE__ */ jsx35(
7501
+ return /* @__PURE__ */ jsxs17("div", { className: getClassName25(), children: [
7502
+ viewports.map((viewport, i) => /* @__PURE__ */ jsx36(
7244
7503
  ViewportButton,
7245
7504
  {
7246
7505
  height: viewport.height,
@@ -7251,8 +7510,8 @@ var ViewportControls = ({
7251
7510
  },
7252
7511
  i
7253
7512
  )),
7254
- /* @__PURE__ */ jsx35("div", { className: getClassName25("divider") }),
7255
- /* @__PURE__ */ jsx35(
7513
+ /* @__PURE__ */ jsx36("div", { className: getClassName25("divider") }),
7514
+ /* @__PURE__ */ jsx36(
7256
7515
  IconButton,
7257
7516
  {
7258
7517
  title: "Zoom viewport out",
@@ -7266,10 +7525,10 @@ var ViewportControls = ({
7266
7525
  )].value
7267
7526
  );
7268
7527
  },
7269
- children: /* @__PURE__ */ jsx35(ZoomOut, { size: 16 })
7528
+ children: /* @__PURE__ */ jsx36(ZoomOut, { size: 16 })
7270
7529
  }
7271
7530
  ),
7272
- /* @__PURE__ */ jsx35(
7531
+ /* @__PURE__ */ jsx36(
7273
7532
  IconButton,
7274
7533
  {
7275
7534
  title: "Zoom viewport in",
@@ -7283,11 +7542,11 @@ var ViewportControls = ({
7283
7542
  )].value
7284
7543
  );
7285
7544
  },
7286
- children: /* @__PURE__ */ jsx35(ZoomIn, { size: 16 })
7545
+ children: /* @__PURE__ */ jsx36(ZoomIn, { size: 16 })
7287
7546
  }
7288
7547
  ),
7289
- /* @__PURE__ */ jsx35("div", { className: getClassName25("divider") }),
7290
- /* @__PURE__ */ jsx35(
7548
+ /* @__PURE__ */ jsx36("div", { className: getClassName25("divider") }),
7549
+ /* @__PURE__ */ jsx36(
7291
7550
  "select",
7292
7551
  {
7293
7552
  className: getClassName25("zoomSelect"),
@@ -7295,7 +7554,7 @@ var ViewportControls = ({
7295
7554
  onChange: (e) => {
7296
7555
  onZoom(parseFloat(e.currentTarget.value));
7297
7556
  },
7298
- children: zoomOptions.map((option) => /* @__PURE__ */ jsx35(
7557
+ children: zoomOptions.map((option) => /* @__PURE__ */ jsx36(
7299
7558
  "option",
7300
7559
  {
7301
7560
  value: option.value,
@@ -7343,8 +7602,8 @@ var getZoomConfig = (uiViewport, frame, zoom) => {
7343
7602
  };
7344
7603
 
7345
7604
  // components/Puck/components/Canvas/index.tsx
7346
- import { useShallow as useShallow5 } from "zustand/react/shallow";
7347
- import { Fragment as Fragment13, jsx as jsx36, jsxs as jsxs19 } from "react/jsx-runtime";
7605
+ import { useShallow as useShallow7 } from "zustand/react/shallow";
7606
+ import { Fragment as Fragment12, jsx as jsx37, jsxs as jsxs18 } from "react/jsx-runtime";
7348
7607
  var getClassName26 = get_class_name_factory_default("PuckCanvas", styles_module_default21);
7349
7608
  var ZOOM_ON_CHANGE = true;
7350
7609
  var Canvas = () => {
@@ -7357,7 +7616,7 @@ var Canvas = () => {
7357
7616
  status,
7358
7617
  iframe
7359
7618
  } = useAppStore(
7360
- useShallow5((s) => ({
7619
+ useShallow7((s) => ({
7361
7620
  dispatch: s.dispatch,
7362
7621
  overrides: s.overrides,
7363
7622
  setUi: s.setUi,
@@ -7368,7 +7627,7 @@ var Canvas = () => {
7368
7627
  }))
7369
7628
  );
7370
7629
  const { leftSideBarVisible, rightSideBarVisible, viewports } = useAppStore(
7371
- useShallow5((s) => ({
7630
+ useShallow7((s) => ({
7372
7631
  leftSideBarVisible: s.state.ui.leftSideBarVisible,
7373
7632
  rightSideBarVisible: s.state.ui.rightSideBarVisible,
7374
7633
  viewports: s.state.ui.viewports
@@ -7376,11 +7635,11 @@ var Canvas = () => {
7376
7635
  );
7377
7636
  const frameRef = useRef6(null);
7378
7637
  const [showTransition, setShowTransition] = useState19(false);
7379
- const defaultRender = useMemo16(() => {
7380
- const PuckDefault = ({ children }) => /* @__PURE__ */ jsx36(Fragment13, { children });
7638
+ const defaultRender = useMemo18(() => {
7639
+ const PuckDefault = ({ children }) => /* @__PURE__ */ jsx37(Fragment12, { children });
7381
7640
  return PuckDefault;
7382
7641
  }, []);
7383
- const CustomPreview = useMemo16(
7642
+ const CustomPreview = useMemo18(
7384
7643
  () => overrides.preview || defaultRender,
7385
7644
  [overrides]
7386
7645
  );
@@ -7406,11 +7665,11 @@ var Canvas = () => {
7406
7665
  },
7407
7666
  [frameRef, zoomConfig, viewports]
7408
7667
  );
7409
- useEffect22(() => {
7668
+ useEffect21(() => {
7410
7669
  setShowTransition(false);
7411
7670
  resetAutoZoom(viewports);
7412
7671
  }, [frameRef, leftSideBarVisible, rightSideBarVisible]);
7413
- useEffect22(() => {
7672
+ useEffect21(() => {
7414
7673
  const { height: frameHeight } = getFrameDimensions();
7415
7674
  if (viewports.current.height === "auto") {
7416
7675
  setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
@@ -7418,13 +7677,13 @@ var Canvas = () => {
7418
7677
  }));
7419
7678
  }
7420
7679
  }, [zoomConfig.zoom]);
7421
- useEffect22(() => {
7680
+ useEffect21(() => {
7422
7681
  if (ZOOM_ON_CHANGE) {
7423
7682
  setShowTransition(true);
7424
7683
  resetAutoZoom(viewports);
7425
7684
  }
7426
7685
  }, [viewports.current.width]);
7427
- useEffect22(() => {
7686
+ useEffect21(() => {
7428
7687
  const cb = () => {
7429
7688
  setShowTransition(false);
7430
7689
  resetAutoZoom();
@@ -7435,12 +7694,12 @@ var Canvas = () => {
7435
7694
  };
7436
7695
  }, []);
7437
7696
  const [showLoader, setShowLoader] = useState19(false);
7438
- useEffect22(() => {
7697
+ useEffect21(() => {
7439
7698
  setTimeout(() => {
7440
7699
  setShowLoader(true);
7441
7700
  }, 500);
7442
7701
  }, []);
7443
- return /* @__PURE__ */ jsxs19(
7702
+ return /* @__PURE__ */ jsxs18(
7444
7703
  "div",
7445
7704
  {
7446
7705
  className: getClassName26({
@@ -7453,7 +7712,7 @@ var Canvas = () => {
7453
7712
  recordHistory: true
7454
7713
  }),
7455
7714
  children: [
7456
- viewports.controlsVisible && iframe.enabled && /* @__PURE__ */ jsx36("div", { className: getClassName26("controls"), children: /* @__PURE__ */ jsx36(
7715
+ viewports.controlsVisible && iframe.enabled && /* @__PURE__ */ jsx37("div", { className: getClassName26("controls"), children: /* @__PURE__ */ jsx37(
7457
7716
  ViewportControls,
7458
7717
  {
7459
7718
  autoZoom: zoomConfig.autoZoom,
@@ -7479,8 +7738,8 @@ var Canvas = () => {
7479
7738
  }
7480
7739
  }
7481
7740
  ) }),
7482
- /* @__PURE__ */ jsxs19("div", { className: getClassName26("inner"), ref: frameRef, children: [
7483
- /* @__PURE__ */ jsx36(
7741
+ /* @__PURE__ */ jsxs18("div", { className: getClassName26("inner"), ref: frameRef, children: [
7742
+ /* @__PURE__ */ jsx37(
7484
7743
  "div",
7485
7744
  {
7486
7745
  className: getClassName26("root"),
@@ -7501,10 +7760,10 @@ var Canvas = () => {
7501
7760
  })
7502
7761
  );
7503
7762
  },
7504
- children: /* @__PURE__ */ jsx36(CustomPreview, { children: /* @__PURE__ */ jsx36(Preview3, {}) })
7763
+ children: /* @__PURE__ */ jsx37(CustomPreview, { children: /* @__PURE__ */ jsx37(Preview3, {}) })
7505
7764
  }
7506
7765
  ),
7507
- /* @__PURE__ */ jsx36("div", { className: getClassName26("loader"), children: /* @__PURE__ */ jsx36(Loader, { size: 24 }) })
7766
+ /* @__PURE__ */ jsx37("div", { className: getClassName26("loader"), children: /* @__PURE__ */ jsx37(Loader, { size: 24 }) })
7508
7767
  ] })
7509
7768
  ]
7510
7769
  }
@@ -7513,7 +7772,7 @@ var Canvas = () => {
7513
7772
 
7514
7773
  // lib/use-loaded-overrides.ts
7515
7774
  init_react_import();
7516
- import { useMemo as useMemo17 } from "react";
7775
+ import { useMemo as useMemo19 } from "react";
7517
7776
 
7518
7777
  // lib/load-overrides.ts
7519
7778
  init_react_import();
@@ -7552,26 +7811,26 @@ var useLoadedOverrides = ({
7552
7811
  overrides,
7553
7812
  plugins
7554
7813
  }) => {
7555
- return useMemo17(() => {
7814
+ return useMemo19(() => {
7556
7815
  return loadOverrides({ overrides, plugins });
7557
7816
  }, [plugins, overrides]);
7558
7817
  };
7559
7818
 
7560
7819
  // components/DefaultOverride/index.tsx
7561
7820
  init_react_import();
7562
- import { Fragment as Fragment14, jsx as jsx37 } from "react/jsx-runtime";
7563
- var DefaultOverride = ({ children }) => /* @__PURE__ */ jsx37(Fragment14, { children });
7821
+ import { Fragment as Fragment13, jsx as jsx38 } from "react/jsx-runtime";
7822
+ var DefaultOverride = ({ children }) => /* @__PURE__ */ jsx38(Fragment13, { children });
7564
7823
 
7565
7824
  // lib/use-inject-css.ts
7566
7825
  init_react_import();
7567
- import { useEffect as useEffect23, useState as useState20 } from "react";
7826
+ import { useEffect as useEffect22, useState as useState20 } from "react";
7568
7827
  var styles = ``;
7569
7828
  var useInjectStyleSheet = (initialStyles, iframeEnabled) => {
7570
7829
  const [el, setEl] = useState20();
7571
- useEffect23(() => {
7830
+ useEffect22(() => {
7572
7831
  setEl(document.createElement("style"));
7573
7832
  }, []);
7574
- useEffect23(() => {
7833
+ useEffect22(() => {
7575
7834
  var _a;
7576
7835
  if (!el || typeof window === "undefined") {
7577
7836
  return;
@@ -7609,7 +7868,7 @@ var usePreviewModeHotkeys = () => {
7609
7868
 
7610
7869
  // lib/use-puck.ts
7611
7870
  init_react_import();
7612
- import { createContext as createContext6, useContext as useContext10, useEffect as useEffect24, useState as useState21 } from "react";
7871
+ import { createContext as createContext6, useContext as useContext10, useEffect as useEffect23, useState as useState21 } from "react";
7613
7872
  import { createStore as createStore4, useStore as useStore3 } from "zustand";
7614
7873
  var generateUsePuck = (store) => {
7615
7874
  const history = {
@@ -7623,13 +7882,22 @@ var generateUsePuck = (store) => {
7623
7882
  index: store.history.index
7624
7883
  };
7625
7884
  const storeData = {
7626
- appState: store.state,
7885
+ appState: makeStatePublic(store.state),
7627
7886
  config: store.config,
7628
7887
  dispatch: store.dispatch,
7629
7888
  getPermissions: store.permissions.getPermissions,
7630
7889
  refreshPermissions: store.permissions.refreshPermissions,
7631
7890
  history,
7632
- selectedItem: store.selectedItem || null
7891
+ selectedItem: store.selectedItem || null,
7892
+ getItemBySelector: (selector) => getItem(selector, store.state),
7893
+ getItemById: (id) => store.state.indexes.nodes[id].data,
7894
+ getSelectorForId: (id) => {
7895
+ const node = store.state.indexes.nodes[id];
7896
+ if (!node) return;
7897
+ const zoneCompound = `${node.parentId}:${node.zone}`;
7898
+ const index = store.state.indexes.zones[zoneCompound].contentIds.indexOf(id);
7899
+ return { zone: zoneCompound, index };
7900
+ }
7633
7901
  };
7634
7902
  const get = () => storeData;
7635
7903
  return __spreadProps(__spreadValues({}, storeData), { get });
@@ -7637,23 +7905,25 @@ var generateUsePuck = (store) => {
7637
7905
  var UsePuckStoreContext = createContext6(
7638
7906
  null
7639
7907
  );
7908
+ var convertToPickedStore = (store) => {
7909
+ return {
7910
+ state: store.state,
7911
+ config: store.config,
7912
+ dispatch: store.dispatch,
7913
+ permissions: store.permissions,
7914
+ history: store.history,
7915
+ selectedItem: store.selectedItem
7916
+ };
7917
+ };
7640
7918
  var useRegisterUsePuckStore = (appStore) => {
7641
7919
  const [usePuckStore] = useState21(
7642
- () => createStore4(() => generateUsePuck(appStore.getState()))
7920
+ () => createStore4(
7921
+ () => generateUsePuck(convertToPickedStore(appStore.getState()))
7922
+ )
7643
7923
  );
7644
- useEffect24(() => {
7924
+ useEffect23(() => {
7645
7925
  return appStore.subscribe(
7646
- (store) => {
7647
- const pickedStore = {
7648
- state: store.state,
7649
- config: store.config,
7650
- dispatch: store.dispatch,
7651
- permissions: store.permissions,
7652
- history: store.history,
7653
- selectedItem: store.selectedItem
7654
- };
7655
- return pickedStore;
7656
- },
7926
+ (store) => convertToPickedStore(store),
7657
7927
  (pickedStore) => {
7658
7928
  usePuckStore.setState(generateUsePuck(pickedStore));
7659
7929
  }
@@ -7675,7 +7945,7 @@ function createUsePuck() {
7675
7945
  };
7676
7946
  }
7677
7947
  function usePuck() {
7678
- useEffect24(() => {
7948
+ useEffect23(() => {
7679
7949
  console.warn(
7680
7950
  "You're using the `usePuck` method without a selector, which may cause unnecessary re-renders. Replace with `createUsePuck` and provide a selector for improved performance."
7681
7951
  );
@@ -7684,7 +7954,7 @@ function usePuck() {
7684
7954
  }
7685
7955
 
7686
7956
  // components/Puck/index.tsx
7687
- import { Fragment as Fragment15, jsx as jsx38, jsxs as jsxs20 } from "react/jsx-runtime";
7957
+ import { Fragment as Fragment14, jsx as jsx39, jsxs as jsxs19 } from "react/jsx-runtime";
7688
7958
  var getClassName27 = get_class_name_factory_default("Puck", styles_module_default15);
7689
7959
  var getLayoutClassName = get_class_name_factory_default("PuckLayout", styles_module_default15);
7690
7960
  var FieldSideBar = () => {
@@ -7694,11 +7964,11 @@ var FieldSideBar = () => {
7694
7964
  return s.selectedItem ? (_b = (_a = s.config.components[s.selectedItem.type]) == null ? void 0 : _a["label"]) != null ? _b : s.selectedItem.type.toString() : "Page";
7695
7965
  }
7696
7966
  );
7697
- return /* @__PURE__ */ jsx38(SidebarSection, { noPadding: true, noBorderTop: true, showBreadcrumbs: true, title, children: /* @__PURE__ */ jsx38(Fields, {}) });
7967
+ return /* @__PURE__ */ jsx39(SidebarSection, { noPadding: true, noBorderTop: true, showBreadcrumbs: true, title, children: /* @__PURE__ */ jsx39(Fields, {}) });
7698
7968
  };
7699
7969
  var propsContext = createContext7({});
7700
7970
  function PropsProvider(props) {
7701
- return /* @__PURE__ */ jsx38(propsContext.Provider, { value: props, children: props.children });
7971
+ return /* @__PURE__ */ jsx39(propsContext.Provider, { value: props, children: props.children });
7702
7972
  }
7703
7973
  var usePropsContext = () => useContext11(propsContext);
7704
7974
  function PuckProvider({ children }) {
@@ -7755,7 +8025,7 @@ function PuckProvider({ children }) {
7755
8025
  }
7756
8026
  const rootProps = ((_h = initialData == null ? void 0 : initialData.root) == null ? void 0 : _h.props) || (initialData == null ? void 0 : initialData.root) || {};
7757
8027
  const defaultedRootProps = __spreadValues(__spreadValues({}, (_i = config.root) == null ? void 0 : _i.defaultProps), rootProps);
7758
- return __spreadProps(__spreadValues({}, defaultAppState), {
8028
+ const newAppState = __spreadProps(__spreadValues({}, defaultAppState), {
7759
8029
  data: __spreadProps(__spreadValues({}, initialData), {
7760
8030
  root: __spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: defaultedRootProps }),
7761
8031
  content: initialData.content || []
@@ -7777,73 +8047,77 @@ function PuckProvider({ children }) {
7777
8047
  ) : {}
7778
8048
  })
7779
8049
  });
8050
+ return walkAppState(newAppState, config);
7780
8051
  });
7781
8052
  const { appendData = true } = _initialHistory || {};
7782
- const blendedHistories = [
7783
- ...(_initialHistory == null ? void 0 : _initialHistory.histories) || [],
7784
- ...appendData ? [{ state: generatedAppState }] : []
7785
- ].map((history) => __spreadProps(__spreadValues({}, history), {
7786
- // Inject default data to enable partial history injections
7787
- state: __spreadValues(__spreadValues({}, generatedAppState), history.state)
7788
- }));
8053
+ const [blendedHistories] = useState22(
8054
+ [
8055
+ ...(_initialHistory == null ? void 0 : _initialHistory.histories) || [],
8056
+ ...appendData ? [{ state: generatedAppState }] : []
8057
+ ].map((history) => {
8058
+ let newState = __spreadValues(__spreadValues({}, generatedAppState), history.state);
8059
+ if (!history.state.indexes) {
8060
+ newState = walkAppState(newState, config);
8061
+ }
8062
+ return __spreadProps(__spreadValues({}, history), {
8063
+ state: newState
8064
+ });
8065
+ })
8066
+ );
7789
8067
  const initialHistoryIndex = (_initialHistory == null ? void 0 : _initialHistory.index) || blendedHistories.length - 1;
7790
8068
  const initialAppState = blendedHistories[initialHistoryIndex].state;
7791
8069
  const loadedOverrides = useLoadedOverrides({
7792
8070
  overrides,
7793
8071
  plugins
7794
8072
  });
7795
- const generateAppStore = useCallback16(() => {
7796
- return {
7797
- state: initialAppState,
8073
+ const generateAppStore = useCallback16(
8074
+ (state) => {
8075
+ return {
8076
+ state,
8077
+ config,
8078
+ plugins: plugins || [],
8079
+ overrides: loadedOverrides,
8080
+ viewports,
8081
+ iframe,
8082
+ onAction,
8083
+ metadata
8084
+ };
8085
+ },
8086
+ [
8087
+ initialAppState,
7798
8088
  config,
7799
- plugins: plugins || [],
7800
- overrides: loadedOverrides,
8089
+ plugins,
8090
+ loadedOverrides,
7801
8091
  viewports,
7802
8092
  iframe,
7803
8093
  onAction,
7804
8094
  metadata
7805
- };
7806
- }, [
7807
- initialAppState,
7808
- config,
7809
- plugins,
7810
- loadedOverrides,
7811
- viewports,
7812
- iframe,
7813
- onAction,
7814
- metadata
7815
- ]);
7816
- const [appStore] = useState22(() => createAppStore(generateAppStore()));
7817
- useEffect25(() => {
7818
- appStore.setState(__spreadValues({}, generateAppStore()));
7819
- }, [
7820
- initialAppState,
7821
- config,
7822
- plugins,
7823
- loadedOverrides,
7824
- viewports,
7825
- iframe,
7826
- onAction,
7827
- metadata
7828
- ]);
8095
+ ]
8096
+ );
8097
+ const [appStore] = useState22(
8098
+ () => createAppStore(generateAppStore(initialAppState))
8099
+ );
8100
+ useEffect24(() => {
8101
+ const state = appStore.getState().state;
8102
+ appStore.setState(__spreadValues({}, generateAppStore(state)));
8103
+ }, [config, plugins, loadedOverrides, viewports, iframe, onAction, metadata]);
7829
8104
  useRegisterHistorySlice(appStore, {
7830
8105
  histories: blendedHistories,
7831
8106
  index: initialHistoryIndex,
7832
8107
  initialAppState
7833
8108
  });
7834
- useEffect25(() => {
8109
+ useEffect24(() => {
7835
8110
  appStore.subscribe((s) => {
7836
8111
  if (onChange) onChange(s.state.data);
7837
8112
  });
7838
8113
  }, []);
7839
- useRegisterNodesSlice(appStore);
7840
8114
  useRegisterPermissionsSlice(appStore, permissions);
7841
8115
  const uPuckStore = useRegisterUsePuckStore(appStore);
7842
- useEffect25(() => {
7843
- const { state, resolveData: resolveData2 } = appStore.getState();
7844
- resolveData2(state);
8116
+ useEffect24(() => {
8117
+ const { resolveAndCommitData } = appStore.getState();
8118
+ resolveAndCommitData();
7845
8119
  }, []);
7846
- return /* @__PURE__ */ jsx38(appStoreContext.Provider, { value: appStore, children: /* @__PURE__ */ jsx38(UsePuckStoreContext.Provider, { value: uPuckStore, children }) });
8120
+ return /* @__PURE__ */ jsx39(appStoreContext.Provider, { value: appStore, children: /* @__PURE__ */ jsx39(UsePuckStoreContext.Provider, { value: uPuckStore, children }) });
7847
8121
  }
7848
8122
  function PuckLayout({ children }) {
7849
8123
  const {
@@ -7868,7 +8142,7 @@ function PuckLayout({ children }) {
7868
8142
  );
7869
8143
  const [menuOpen, setMenuOpen] = useState22(false);
7870
8144
  const appStore = useAppStoreApi();
7871
- useEffect25(() => {
8145
+ useEffect24(() => {
7872
8146
  return appStore.subscribe((s) => {
7873
8147
  if (onChange) onChange(s.state.data);
7874
8148
  });
@@ -7891,7 +8165,7 @@ function PuckLayout({ children }) {
7891
8165
  },
7892
8166
  [dispatch, leftSideBarVisible, rightSideBarVisible]
7893
8167
  );
7894
- useEffect25(() => {
8168
+ useEffect24(() => {
7895
8169
  if (!window.matchMedia("(min-width: 638px)").matches) {
7896
8170
  dispatch({
7897
8171
  type: "setUi",
@@ -7914,7 +8188,7 @@ function PuckLayout({ children }) {
7914
8188
  window.removeEventListener("resize", handleResize);
7915
8189
  };
7916
8190
  }, []);
7917
- const defaultHeaderRender = useMemo18(() => {
8191
+ const defaultHeaderRender = useMemo20(() => {
7918
8192
  if (renderHeader) {
7919
8193
  console.warn(
7920
8194
  "`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
@@ -7923,13 +8197,13 @@ function PuckLayout({ children }) {
7923
8197
  var _b = _a, { actions } = _b, props = __objRest(_b, ["actions"]);
7924
8198
  const Comp = renderHeader;
7925
8199
  const appState = useAppStore((s) => s.state);
7926
- return /* @__PURE__ */ jsx38(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState, children: actions }));
8200
+ return /* @__PURE__ */ jsx39(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState, children: actions }));
7927
8201
  };
7928
8202
  return RenderHeader;
7929
8203
  }
7930
8204
  return DefaultOverride;
7931
8205
  }, [renderHeader]);
7932
- const defaultHeaderActionsRender = useMemo18(() => {
8206
+ const defaultHeaderActionsRender = useMemo20(() => {
7933
8207
  if (renderHeaderActions) {
7934
8208
  console.warn(
7935
8209
  "`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
@@ -7937,32 +8211,32 @@ function PuckLayout({ children }) {
7937
8211
  const RenderHeader = (props) => {
7938
8212
  const Comp = renderHeaderActions;
7939
8213
  const appState = useAppStore((s) => s.state);
7940
- return /* @__PURE__ */ jsx38(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState }));
8214
+ return /* @__PURE__ */ jsx39(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState }));
7941
8215
  };
7942
8216
  return RenderHeader;
7943
8217
  }
7944
8218
  return DefaultOverride;
7945
8219
  }, [renderHeader]);
7946
8220
  const overrides = useAppStore((s) => s.overrides);
7947
- const CustomPuck = useMemo18(
8221
+ const CustomPuck = useMemo20(
7948
8222
  () => overrides.puck || DefaultOverride,
7949
8223
  [overrides]
7950
8224
  );
7951
- const CustomHeader = useMemo18(
8225
+ const CustomHeader = useMemo20(
7952
8226
  () => overrides.header || defaultHeaderRender,
7953
8227
  [overrides]
7954
8228
  );
7955
- const CustomHeaderActions = useMemo18(
8229
+ const CustomHeaderActions = useMemo20(
7956
8230
  () => overrides.headerActions || defaultHeaderActionsRender,
7957
8231
  [overrides]
7958
8232
  );
7959
8233
  const [mounted, setMounted] = useState22(false);
7960
- useEffect25(() => {
8234
+ useEffect24(() => {
7961
8235
  setMounted(true);
7962
8236
  }, []);
7963
8237
  const ready = useAppStore((s) => s.status === "READY");
7964
8238
  useMonitorHotkeys();
7965
- useEffect25(() => {
8239
+ useEffect24(() => {
7966
8240
  if (ready && iframe.enabled) {
7967
8241
  const frameDoc = getFrame();
7968
8242
  if (frameDoc) {
@@ -7971,8 +8245,8 @@ function PuckLayout({ children }) {
7971
8245
  }
7972
8246
  }, [ready, iframe.enabled]);
7973
8247
  usePreviewModeHotkeys();
7974
- return /* @__PURE__ */ jsxs20("div", { className: `Puck ${getClassName27()}`, children: [
7975
- /* @__PURE__ */ jsx38(DragDropContext, { disableAutoScroll: dnd == null ? void 0 : dnd.disableAutoScroll, children: /* @__PURE__ */ jsx38(CustomPuck, { children: children || /* @__PURE__ */ jsx38(
8248
+ return /* @__PURE__ */ jsxs19("div", { className: `Puck ${getClassName27()}`, children: [
8249
+ /* @__PURE__ */ jsx39(DragDropContext, { disableAutoScroll: dnd == null ? void 0 : dnd.disableAutoScroll, children: /* @__PURE__ */ jsx39(CustomPuck, { children: children || /* @__PURE__ */ jsx39(
7976
8250
  "div",
7977
8251
  {
7978
8252
  className: getLayoutClassName({
@@ -7981,61 +8255,61 @@ function PuckLayout({ children }) {
7981
8255
  mounted,
7982
8256
  rightSideBarVisible
7983
8257
  }),
7984
- children: /* @__PURE__ */ jsxs20("div", { className: getLayoutClassName("inner"), children: [
7985
- /* @__PURE__ */ jsx38(
8258
+ children: /* @__PURE__ */ jsxs19("div", { className: getLayoutClassName("inner"), children: [
8259
+ /* @__PURE__ */ jsx39(
7986
8260
  CustomHeader,
7987
8261
  {
7988
- actions: /* @__PURE__ */ jsx38(Fragment15, { children: /* @__PURE__ */ jsx38(CustomHeaderActions, { children: /* @__PURE__ */ jsx38(
8262
+ actions: /* @__PURE__ */ jsx39(Fragment14, { children: /* @__PURE__ */ jsx39(CustomHeaderActions, { children: /* @__PURE__ */ jsx39(
7989
8263
  Button,
7990
8264
  {
7991
8265
  onClick: () => {
7992
8266
  const data = appStore.getState().state.data;
7993
8267
  onPublish && onPublish(data);
7994
8268
  },
7995
- icon: /* @__PURE__ */ jsx38(Globe, { size: "14px" }),
8269
+ icon: /* @__PURE__ */ jsx39(Globe, { size: "14px" }),
7996
8270
  children: "Publish"
7997
8271
  }
7998
8272
  ) }) }),
7999
- children: /* @__PURE__ */ jsx38("header", { className: getLayoutClassName("header"), children: /* @__PURE__ */ jsxs20("div", { className: getLayoutClassName("headerInner"), children: [
8000
- /* @__PURE__ */ jsxs20("div", { className: getLayoutClassName("headerToggle"), children: [
8001
- /* @__PURE__ */ jsx38(
8273
+ children: /* @__PURE__ */ jsx39("header", { className: getLayoutClassName("header"), children: /* @__PURE__ */ jsxs19("div", { className: getLayoutClassName("headerInner"), children: [
8274
+ /* @__PURE__ */ jsxs19("div", { className: getLayoutClassName("headerToggle"), children: [
8275
+ /* @__PURE__ */ jsx39(
8002
8276
  "div",
8003
8277
  {
8004
8278
  className: getLayoutClassName("leftSideBarToggle"),
8005
- children: /* @__PURE__ */ jsx38(
8279
+ children: /* @__PURE__ */ jsx39(
8006
8280
  IconButton,
8007
8281
  {
8008
8282
  onClick: () => {
8009
8283
  toggleSidebars("left");
8010
8284
  },
8011
8285
  title: "Toggle left sidebar",
8012
- children: /* @__PURE__ */ jsx38(PanelLeft, { focusable: "false" })
8286
+ children: /* @__PURE__ */ jsx39(PanelLeft, { focusable: "false" })
8013
8287
  }
8014
8288
  )
8015
8289
  }
8016
8290
  ),
8017
- /* @__PURE__ */ jsx38(
8291
+ /* @__PURE__ */ jsx39(
8018
8292
  "div",
8019
8293
  {
8020
8294
  className: getLayoutClassName("rightSideBarToggle"),
8021
- children: /* @__PURE__ */ jsx38(
8295
+ children: /* @__PURE__ */ jsx39(
8022
8296
  IconButton,
8023
8297
  {
8024
8298
  onClick: () => {
8025
8299
  toggleSidebars("right");
8026
8300
  },
8027
8301
  title: "Toggle right sidebar",
8028
- children: /* @__PURE__ */ jsx38(PanelRight, { focusable: "false" })
8302
+ children: /* @__PURE__ */ jsx39(PanelRight, { focusable: "false" })
8029
8303
  }
8030
8304
  )
8031
8305
  }
8032
8306
  )
8033
8307
  ] }),
8034
- /* @__PURE__ */ jsx38("div", { className: getLayoutClassName("headerTitle"), children: /* @__PURE__ */ jsxs20(Heading, { rank: "2", size: "xs", children: [
8308
+ /* @__PURE__ */ jsx39("div", { className: getLayoutClassName("headerTitle"), children: /* @__PURE__ */ jsxs19(Heading, { rank: "2", size: "xs", children: [
8035
8309
  headerTitle || (rootProps == null ? void 0 : rootProps.title) || "Page",
8036
- headerPath && /* @__PURE__ */ jsxs20(Fragment15, { children: [
8310
+ headerPath && /* @__PURE__ */ jsxs19(Fragment14, { children: [
8037
8311
  " ",
8038
- /* @__PURE__ */ jsx38(
8312
+ /* @__PURE__ */ jsx39(
8039
8313
  "code",
8040
8314
  {
8041
8315
  className: getLayoutClassName("headerPath"),
@@ -8044,31 +8318,31 @@ function PuckLayout({ children }) {
8044
8318
  )
8045
8319
  ] })
8046
8320
  ] }) }),
8047
- /* @__PURE__ */ jsxs20("div", { className: getLayoutClassName("headerTools"), children: [
8048
- /* @__PURE__ */ jsx38("div", { className: getLayoutClassName("menuButton"), children: /* @__PURE__ */ jsx38(
8321
+ /* @__PURE__ */ jsxs19("div", { className: getLayoutClassName("headerTools"), children: [
8322
+ /* @__PURE__ */ jsx39("div", { className: getLayoutClassName("menuButton"), children: /* @__PURE__ */ jsx39(
8049
8323
  IconButton,
8050
8324
  {
8051
8325
  onClick: () => {
8052
8326
  return setMenuOpen(!menuOpen);
8053
8327
  },
8054
8328
  title: "Toggle menu bar",
8055
- children: menuOpen ? /* @__PURE__ */ jsx38(ChevronUp, { focusable: "false" }) : /* @__PURE__ */ jsx38(ChevronDown, { focusable: "false" })
8329
+ children: menuOpen ? /* @__PURE__ */ jsx39(ChevronUp, { focusable: "false" }) : /* @__PURE__ */ jsx39(ChevronDown, { focusable: "false" })
8056
8330
  }
8057
8331
  ) }),
8058
- /* @__PURE__ */ jsx38(
8332
+ /* @__PURE__ */ jsx39(
8059
8333
  MenuBar,
8060
8334
  {
8061
8335
  dispatch,
8062
8336
  onPublish,
8063
8337
  menuOpen,
8064
- renderHeaderActions: () => /* @__PURE__ */ jsx38(CustomHeaderActions, { children: /* @__PURE__ */ jsx38(
8338
+ renderHeaderActions: () => /* @__PURE__ */ jsx39(CustomHeaderActions, { children: /* @__PURE__ */ jsx39(
8065
8339
  Button,
8066
8340
  {
8067
8341
  onClick: () => {
8068
8342
  const data = appStore.getState().state.data;
8069
8343
  onPublish && onPublish(data);
8070
8344
  },
8071
- icon: /* @__PURE__ */ jsx38(Globe, { size: "14px" }),
8345
+ icon: /* @__PURE__ */ jsx39(Globe, { size: "14px" }),
8072
8346
  children: "Publish"
8073
8347
  }
8074
8348
  ) }),
@@ -8079,20 +8353,20 @@ function PuckLayout({ children }) {
8079
8353
  ] }) })
8080
8354
  }
8081
8355
  ),
8082
- /* @__PURE__ */ jsxs20("div", { className: getLayoutClassName("leftSideBar"), children: [
8083
- /* @__PURE__ */ jsx38(SidebarSection, { title: "Components", noBorderTop: true, children: /* @__PURE__ */ jsx38(Components, {}) }),
8084
- /* @__PURE__ */ jsx38(SidebarSection, { title: "Outline", children: /* @__PURE__ */ jsx38(Outline, {}) })
8356
+ /* @__PURE__ */ jsxs19("div", { className: getLayoutClassName("leftSideBar"), children: [
8357
+ /* @__PURE__ */ jsx39(SidebarSection, { title: "Components", noBorderTop: true, children: /* @__PURE__ */ jsx39(Components, {}) }),
8358
+ /* @__PURE__ */ jsx39(SidebarSection, { title: "Outline", children: /* @__PURE__ */ jsx39(Outline, {}) })
8085
8359
  ] }),
8086
- /* @__PURE__ */ jsx38(Canvas, {}),
8087
- /* @__PURE__ */ jsx38("div", { className: getLayoutClassName("rightSideBar"), children: /* @__PURE__ */ jsx38(FieldSideBar, {}) })
8360
+ /* @__PURE__ */ jsx39(Canvas, {}),
8361
+ /* @__PURE__ */ jsx39("div", { className: getLayoutClassName("rightSideBar"), children: /* @__PURE__ */ jsx39(FieldSideBar, {}) })
8088
8362
  ] })
8089
8363
  }
8090
8364
  ) }) }),
8091
- /* @__PURE__ */ jsx38("div", { id: "puck-portal-root", className: getClassName27("portal") })
8365
+ /* @__PURE__ */ jsx39("div", { id: "puck-portal-root", className: getClassName27("portal") })
8092
8366
  ] });
8093
8367
  }
8094
8368
  function Puck(props) {
8095
- return /* @__PURE__ */ jsx38(PropsProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ jsx38(PuckProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ jsx38(PuckLayout, __spreadValues({}, props)) })) }));
8369
+ return /* @__PURE__ */ jsx39(PropsProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ jsx39(PuckProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ jsx39(PuckLayout, __spreadValues({}, props)) })) }));
8096
8370
  }
8097
8371
  Puck.Components = Components;
8098
8372
  Puck.Fields = Fields;
@@ -8116,10 +8390,67 @@ var migrations = [
8116
8390
  });
8117
8391
  }
8118
8392
  return data;
8393
+ },
8394
+ // Migrate zones to slots
8395
+ (data, config) => {
8396
+ var _a;
8397
+ if (!config) return data;
8398
+ console.log("Migrating DropZones to slots...");
8399
+ const updatedItems = {};
8400
+ const appState = __spreadProps(__spreadValues({}, defaultAppState), { data });
8401
+ const { indexes } = walkAppState(appState, config);
8402
+ const deletedCompounds = [];
8403
+ walkAppState(appState, config, (content, zoneCompound, zoneType) => {
8404
+ var _a2, _b;
8405
+ if (zoneType === "dropzone") {
8406
+ const [id, slotName] = zoneCompound.split(":");
8407
+ const nodeData = indexes.nodes[id].data;
8408
+ const componentType = nodeData.type;
8409
+ const configForComponent = config.components[componentType];
8410
+ if (((_b = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b.type) === "slot") {
8411
+ updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
8412
+ props: __spreadProps(__spreadValues({}, nodeData.props), {
8413
+ [slotName]: content
8414
+ })
8415
+ });
8416
+ deletedCompounds.push(zoneCompound);
8417
+ }
8418
+ return content;
8419
+ }
8420
+ return content;
8421
+ });
8422
+ const updated = walkAppState(
8423
+ appState,
8424
+ config,
8425
+ (content) => content,
8426
+ (item) => {
8427
+ var _a2;
8428
+ return (_a2 = updatedItems[item.props.id]) != null ? _a2 : item;
8429
+ }
8430
+ );
8431
+ deletedCompounds.forEach((zoneCompound) => {
8432
+ var _a2;
8433
+ const [_, propName] = zoneCompound.split(":");
8434
+ console.log(
8435
+ `\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
8436
+ );
8437
+ (_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
8438
+ });
8439
+ Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
8440
+ const [_, propName] = zoneCompound.split(":");
8441
+ throw new Error(
8442
+ `Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
8443
+ );
8444
+ });
8445
+ delete updated.data.zones;
8446
+ return updated.data;
8119
8447
  }
8120
8448
  ];
8121
- function migrate(data) {
8122
- return migrations == null ? void 0 : migrations.reduce((acc, migration) => migration(acc), data);
8449
+ function migrate(data, config) {
8450
+ return migrations == null ? void 0 : migrations.reduce(
8451
+ (acc, migration) => migration(acc, config),
8452
+ data
8453
+ );
8123
8454
  }
8124
8455
  export {
8125
8456
  Action,
@@ -8140,7 +8471,8 @@ export {
8140
8471
  renderContext,
8141
8472
  resolveAllData,
8142
8473
  transformProps,
8143
- usePuck
8474
+ usePuck,
8475
+ walkTree
8144
8476
  };
8145
8477
  /*! Bundled license information:
8146
8478