@measured/puck 0.16.0-canary.6d43ba0 → 0.16.0-canary.7a6a65c

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  init_react_import,
9
9
  rootDroppableId,
10
10
  setupZone
11
- } from "./chunk-TM7CT64S.mjs";
11
+ } from "./chunk-LM7YWFFF.mjs";
12
12
 
13
13
  // ../../node_modules/classnames/index.js
14
14
  var require_classnames = __commonJS({
@@ -65,15 +65,47 @@ var require_classnames = __commonJS({
65
65
  // index.ts
66
66
  init_react_import();
67
67
 
68
+ // types/API/index.ts
69
+ init_react_import();
70
+
71
+ // types/API/Viewports.ts
72
+ init_react_import();
73
+
74
+ // types/index.ts
75
+ init_react_import();
76
+
77
+ // types/API/Overrides.ts
78
+ init_react_import();
79
+ var overrideKeys = [
80
+ "header",
81
+ "headerActions",
82
+ "fields",
83
+ "fieldLabel",
84
+ "components",
85
+ "componentItem",
86
+ "outline",
87
+ "puck",
88
+ "preview"
89
+ ];
90
+
91
+ // types/AppState.tsx
92
+ init_react_import();
93
+
68
94
  // types/Config.tsx
69
95
  init_react_import();
70
96
 
71
- // types/Plugin.ts
97
+ // types/Data.tsx
72
98
  init_react_import();
73
99
 
74
100
  // types/Fields.ts
75
101
  init_react_import();
76
102
 
103
+ // types/Props.tsx
104
+ init_react_import();
105
+
106
+ // types/Utils.tsx
107
+ init_react_import();
108
+
77
109
  // components/ActionBar/index.tsx
78
110
  init_react_import();
79
111
 
@@ -106,11 +138,11 @@ var get_class_name_factory_default = getClassNameFactory;
106
138
 
107
139
  // css-module:/home/runner/work/puck/puck/packages/core/components/ActionBar/styles.module.css#css-module
108
140
  init_react_import();
109
- var styles_module_default = { "ActionBarComponent": "_ActionBarComponent_8nyey_1", "ActionBarComponent-actionsLabel": "_ActionBarComponent-actionsLabel_8nyey_15", "ActionBarComponent-action": "_ActionBarComponent-action_8nyey_15" };
141
+ var styles_module_default = { "ActionBar": "_ActionBar_fp58q_1", "ActionBar-actionsLabel": "_ActionBar-actionsLabel_fp58q_16", "ActionBar-group": "_ActionBar-group_fp58q_29", "ActionBar-action": "_ActionBar-action_fp58q_16" };
110
142
 
111
143
  // components/ActionBar/index.tsx
112
144
  import { jsx, jsxs } from "react/jsx-runtime";
113
- var getClassName = get_class_name_factory_default("ActionBarComponent", styles_module_default);
145
+ var getClassName = get_class_name_factory_default("ActionBar", styles_module_default);
114
146
  var ActionBar = ({
115
147
  label,
116
148
  children
@@ -122,8 +154,19 @@ var Action = ({
122
154
  children,
123
155
  label,
124
156
  onClick
125
- }) => /* @__PURE__ */ jsx("button", { className: getClassName("action"), onClick, title: label, children });
157
+ }) => /* @__PURE__ */ jsx(
158
+ "button",
159
+ {
160
+ type: "button",
161
+ className: getClassName("action"),
162
+ onClick,
163
+ title: label,
164
+ children
165
+ }
166
+ );
167
+ var Group = ({ children }) => /* @__PURE__ */ jsx("div", { className: getClassName("group"), children });
126
168
  ActionBar.Action = Action;
169
+ ActionBar.Group = Group;
127
170
 
128
171
  // components/AutoField/index.tsx
129
172
  init_react_import();
@@ -134,10 +177,10 @@ var styles_module_default2 = { "Input": "_Input_3pq3z_1", "Input-label": "_Input
134
177
 
135
178
  // components/AutoField/index.tsx
136
179
  import {
137
- useCallback as useCallback3,
138
- useEffect as useEffect7,
180
+ useCallback as useCallback5,
181
+ useEffect as useEffect9,
139
182
  useMemo as useMemo2,
140
- useState as useState8
183
+ useState as useState10
141
184
  } from "react";
142
185
 
143
186
  // components/AutoField/fields/index.tsx
@@ -551,20 +594,20 @@ init_react_import();
551
594
  import {
552
595
  createContext,
553
596
  useContext,
554
- useEffect,
555
- useState as useState2
597
+ useEffect as useEffect3,
598
+ useState as useState4
556
599
  } from "react";
557
600
 
558
601
  // lib/get-item.ts
559
602
  init_react_import();
560
- var getItem = (selector, data, dynamicProps = {}) => {
603
+ function getItem(selector, data, dynamicProps = {}) {
561
604
  if (!selector.zone || selector.zone === rootDroppableId) {
562
605
  const item2 = data.content[selector.index];
563
606
  return (item2 == null ? void 0 : item2.props) ? __spreadProps(__spreadValues({}, item2), { props: dynamicProps[item2.props.id] || item2.props }) : void 0;
564
607
  }
565
608
  const item = setupZone(data, selector.zone).zones[selector.zone][selector.index];
566
609
  return (item == null ? void 0 : item.props) ? __spreadProps(__spreadValues({}, item), { props: dynamicProps[item.props.id] || item.props }) : void 0;
567
- };
610
+ }
568
611
 
569
612
  // components/ViewportControls/default-viewports.ts
570
613
  init_react_import();
@@ -576,6 +619,332 @@ var defaultViewports = [
576
619
 
577
620
  // components/Puck/context.tsx
578
621
  import { UAParser } from "ua-parser-js";
622
+
623
+ // lib/use-resolved-permissions.ts
624
+ init_react_import();
625
+ import { useCallback, useEffect, useState as useState2 } from "react";
626
+
627
+ // lib/flatten-data.ts
628
+ init_react_import();
629
+ var flattenData = (data) => {
630
+ return Object.keys(data.zones || {}).reduce(
631
+ (acc, zone) => [...acc, ...data.zones[zone]],
632
+ data.content
633
+ );
634
+ };
635
+
636
+ // lib/get-changed.ts
637
+ init_react_import();
638
+ var getChanged = (newItem, oldItem) => {
639
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
640
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
641
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
642
+ return __spreadProps(__spreadValues({}, acc), {
643
+ [item]: oldItemProps[item] !== newItemProps[item]
644
+ });
645
+ }, {}) : {};
646
+ };
647
+
648
+ // lib/use-resolved-permissions.ts
649
+ var useResolvedPermissions = (config, appState, globalPermissions, setComponentLoading, unsetComponentLoading) => {
650
+ const [cache3, setCache] = useState2({});
651
+ const [resolvedPermissions, setResolvedPermissions] = useState2({});
652
+ const resolveDataForItem = useCallback(
653
+ (item, force = false) => __async(void 0, null, function* () {
654
+ var _a, _b, _c;
655
+ setComponentLoading == null ? void 0 : setComponentLoading(item.props.id);
656
+ const componentConfig = item.type === "root" ? config.root : config.components[item.type];
657
+ if (!componentConfig) {
658
+ unsetComponentLoading == null ? void 0 : unsetComponentLoading(item.props.id);
659
+ return;
660
+ }
661
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
662
+ if (componentConfig.resolvePermissions) {
663
+ const changed = getChanged(item, (_a = cache3[item.props.id]) == null ? void 0 : _a.lastData);
664
+ if (Object.values(changed).some((el) => el === true) || force) {
665
+ const resolvedPermissions2 = yield componentConfig.resolvePermissions(
666
+ item,
667
+ {
668
+ changed,
669
+ lastPermissions: ((_b = cache3[item.props.id]) == null ? void 0 : _b.lastPermissions) || null,
670
+ permissions: initialPermissions,
671
+ appState,
672
+ lastData: ((_c = cache3[item.props.id]) == null ? void 0 : _c.lastData) || null
673
+ }
674
+ );
675
+ setCache((_cache) => __spreadProps(__spreadValues({}, _cache), {
676
+ [item.props.id]: {
677
+ lastData: item,
678
+ lastPermissions: resolvedPermissions2
679
+ }
680
+ }));
681
+ setResolvedPermissions((p) => __spreadProps(__spreadValues({}, p), {
682
+ [item.props.id]: resolvedPermissions2
683
+ }));
684
+ }
685
+ }
686
+ unsetComponentLoading == null ? void 0 : unsetComponentLoading(item.props.id);
687
+ }),
688
+ [config, globalPermissions, appState, cache3]
689
+ );
690
+ const resolveDataForRoot = (force = false) => {
691
+ resolveDataForItem(
692
+ // Shim the root data in by conforming to component data shape
693
+ {
694
+ type: "root",
695
+ props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "puck-root" })
696
+ },
697
+ force
698
+ );
699
+ };
700
+ const resolvePermissions = useCallback(
701
+ (..._0) => __async(void 0, [..._0], function* ({ item, type, root } = {}, force = false) {
702
+ if (item) {
703
+ yield resolveDataForItem(item, force);
704
+ } else if (type) {
705
+ flattenData(appState.data).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
706
+ yield resolveDataForItem(item2, force);
707
+ }));
708
+ } else if (root) {
709
+ resolveDataForRoot(force);
710
+ } else {
711
+ resolveDataForRoot(force);
712
+ flattenData(appState.data).map((item2) => __async(void 0, null, function* () {
713
+ yield resolveDataForItem(item2, force);
714
+ }));
715
+ }
716
+ }),
717
+ [config, appState]
718
+ );
719
+ const refreshPermissions = useCallback(
720
+ (params) => __async(void 0, null, function* () {
721
+ resolvePermissions(params, true);
722
+ }),
723
+ [config, appState]
724
+ );
725
+ useEffect(() => {
726
+ resolvePermissions();
727
+ }, [config, appState.data]);
728
+ const getPermissions = useCallback(
729
+ ({ item, type, root } = {}) => {
730
+ if (item) {
731
+ const componentConfig = config.components[item.type];
732
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
733
+ const resolvedForItem = resolvedPermissions[item.props.id];
734
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
735
+ } else if (type) {
736
+ const componentConfig = config.components[type];
737
+ return __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
738
+ } else if (root) {
739
+ const rootConfig = config.root;
740
+ const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
741
+ const resolvedForItem = resolvedPermissions["puck-root"];
742
+ return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
743
+ }
744
+ return globalPermissions;
745
+ },
746
+ [config, resolvedPermissions]
747
+ );
748
+ return {
749
+ getPermissions,
750
+ refreshPermissions
751
+ };
752
+ };
753
+
754
+ // lib/use-resolved-data.ts
755
+ init_react_import();
756
+ import { useCallback as useCallback2, useEffect as useEffect2, useState as useState3 } from "react";
757
+
758
+ // lib/resolve-component-data.ts
759
+ init_react_import();
760
+ var cache = { lastChange: {} };
761
+ var resolveAllComponentData = (content, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
762
+ return yield Promise.all(
763
+ content.map((item) => __async(void 0, null, function* () {
764
+ return yield resolveComponentData(
765
+ item,
766
+ config,
767
+ onResolveStart,
768
+ onResolveEnd
769
+ );
770
+ }))
771
+ );
772
+ });
773
+ var resolveComponentData = (item, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
774
+ const configForItem = config.components[item.type];
775
+ if (configForItem.resolveData) {
776
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
777
+ if (item && item === oldItem) {
778
+ return resolved;
779
+ }
780
+ const changed = getChanged(item, oldItem);
781
+ if (onResolveStart) {
782
+ onResolveStart(item);
783
+ }
784
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, { changed, lastData: oldItem });
785
+ const { readOnly: existingReadOnly = {} } = item || {};
786
+ const newReadOnly = __spreadValues(__spreadValues({}, existingReadOnly), readOnly);
787
+ const resolvedItem = __spreadProps(__spreadValues({}, item), {
788
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
789
+ });
790
+ if (Object.keys(newReadOnly).length) {
791
+ resolvedItem.readOnly = newReadOnly;
792
+ }
793
+ cache.lastChange[item.props.id] = {
794
+ item,
795
+ resolved: resolvedItem
796
+ };
797
+ if (onResolveEnd) {
798
+ onResolveEnd(resolvedItem);
799
+ }
800
+ return resolvedItem;
801
+ }
802
+ return item;
803
+ });
804
+
805
+ // lib/apply-dynamic-props.ts
806
+ init_react_import();
807
+ var applyDynamicProps = (data, dynamicProps, rootData) => {
808
+ return __spreadProps(__spreadValues({}, data), {
809
+ root: __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}),
810
+ content: data.content.map((item) => {
811
+ return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
812
+ }),
813
+ zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
814
+ return __spreadProps(__spreadValues({}, acc), {
815
+ [zoneKey]: data.zones[zoneKey].map((item) => {
816
+ return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
817
+ })
818
+ });
819
+ }, {})
820
+ });
821
+ };
822
+
823
+ // lib/resolve-root-data.ts
824
+ init_react_import();
825
+ var cache2 = {};
826
+ function resolveRootData(data, config) {
827
+ return __async(this, null, function* () {
828
+ var _a, _b, _c, _d, _e;
829
+ if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
830
+ if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
831
+ return cache2.lastChange.resolved;
832
+ }
833
+ const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
834
+ const rootWithProps = data.root;
835
+ const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
836
+ changed,
837
+ lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {}
838
+ });
839
+ cache2.lastChange = {
840
+ original: data.root,
841
+ resolved: resolvedRoot
842
+ };
843
+ return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
844
+ props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
845
+ });
846
+ }
847
+ return data.root;
848
+ });
849
+ }
850
+
851
+ // lib/use-resolved-data.ts
852
+ var useResolvedData = (appState, config, dispatch, setComponentLoading, unsetComponentLoading, refreshPermissions) => {
853
+ const [{ resolverKey, newAppState }, setResolverState] = useState3({
854
+ resolverKey: 0,
855
+ newAppState: appState
856
+ });
857
+ const deferredSetStates = {};
858
+ const _setComponentLoading = useCallback2(
859
+ (id, loading, defer2 = 0) => {
860
+ if (deferredSetStates[id]) {
861
+ clearTimeout(deferredSetStates[id]);
862
+ delete deferredSetStates[id];
863
+ }
864
+ deferredSetStates[id] = setTimeout(() => {
865
+ if (loading) {
866
+ setComponentLoading(id);
867
+ } else {
868
+ unsetComponentLoading(id);
869
+ }
870
+ delete deferredSetStates[id];
871
+ }, defer2);
872
+ },
873
+ []
874
+ );
875
+ const runResolvers = () => __async(void 0, null, function* () {
876
+ const newData = newAppState.data;
877
+ const flatContent = flattenData(newData).filter(
878
+ (item) => {
879
+ var _a;
880
+ return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
881
+ }
882
+ );
883
+ const applyIfChange = (dynamicDataMap, dynamicRoot) => {
884
+ const processed = applyDynamicProps(
885
+ appState.data,
886
+ dynamicDataMap,
887
+ dynamicRoot
888
+ );
889
+ const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
890
+ const containsChanges = JSON.stringify(appState) !== JSON.stringify(processedAppState);
891
+ if (containsChanges) {
892
+ dispatch({
893
+ type: "set",
894
+ state: (prev) => __spreadProps(__spreadValues({}, prev), {
895
+ data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
896
+ ui: resolverKey > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
897
+ }),
898
+ recordHistory: resolverKey > 0
899
+ });
900
+ }
901
+ };
902
+ const promises = [];
903
+ promises.push(
904
+ (() => __async(void 0, null, function* () {
905
+ _setComponentLoading("puck-root", true, 50);
906
+ const dynamicRoot = yield resolveRootData(newData, config);
907
+ applyIfChange({}, dynamicRoot);
908
+ _setComponentLoading("puck-root", false);
909
+ }))()
910
+ );
911
+ flatContent.forEach((item) => {
912
+ promises.push(
913
+ (() => __async(void 0, null, function* () {
914
+ refreshPermissions({ item });
915
+ const dynamicData = yield resolveComponentData(
916
+ item,
917
+ config,
918
+ (item2) => {
919
+ _setComponentLoading(item2.props.id, true, 50);
920
+ },
921
+ (item2) => {
922
+ deferredSetStates[item2.props.id];
923
+ _setComponentLoading(item2.props.id, false);
924
+ }
925
+ );
926
+ const dynamicDataMap = { [item.props.id]: dynamicData };
927
+ applyIfChange(dynamicDataMap);
928
+ }))()
929
+ );
930
+ });
931
+ yield Promise.all(promises);
932
+ });
933
+ useEffect2(() => {
934
+ runResolvers();
935
+ }, [resolverKey]);
936
+ const resolveData = useCallback2((newAppState2 = appState) => {
937
+ setResolverState((curr) => ({
938
+ resolverKey: curr.resolverKey + 1,
939
+ newAppState: newAppState2
940
+ }));
941
+ }, []);
942
+ return {
943
+ resolveData
944
+ };
945
+ };
946
+
947
+ // components/Puck/context.tsx
579
948
  import { jsx as jsx4 } from "react/jsx-runtime";
580
949
  var defaultAppState = {
581
950
  data: { content: [], root: {} },
@@ -601,6 +970,8 @@ var defaultContext = {
601
970
  dispatch: () => null,
602
971
  config: { components: {} },
603
972
  componentState: {},
973
+ setComponentState: () => {
974
+ },
604
975
  resolveData: () => {
605
976
  },
606
977
  plugins: [],
@@ -617,20 +988,22 @@ var defaultContext = {
617
988
  setStatus: () => null,
618
989
  iframe: {},
619
990
  safariFallbackMode: false,
620
- globalPermissions: {}
991
+ globalPermissions: {},
992
+ getPermissions: () => ({}),
993
+ refreshPermissions: () => null
621
994
  };
622
995
  var appContext = createContext(defaultContext);
623
996
  var AppProvider = ({
624
997
  children,
625
998
  value
626
999
  }) => {
627
- const [zoomConfig, setZoomConfig] = useState2(defaultContext.zoomConfig);
628
- const [status, setStatus] = useState2("LOADING");
629
- useEffect(() => {
1000
+ const [zoomConfig, setZoomConfig] = useState4(defaultContext.zoomConfig);
1001
+ const [status, setStatus] = useState4("LOADING");
1002
+ useEffect3(() => {
630
1003
  setStatus("MOUNTED");
631
1004
  }, []);
632
- const [safariFallbackMode, setSafariFallbackMode] = useState2(false);
633
- useEffect(() => {
1005
+ const [safariFallbackMode, setSafariFallbackMode] = useState4(false);
1006
+ useEffect3(() => {
634
1007
  var _a, _b, _c;
635
1008
  const ua = new UAParser(navigator.userAgent);
636
1009
  const { browser } = ua.getResult();
@@ -647,15 +1020,58 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
647
1020
  setSafariFallbackMode(true);
648
1021
  }
649
1022
  }, []);
1023
+ const selectedItem = value.state.ui.itemSelector ? getItem(value.state.ui.itemSelector, value.state.data) : void 0;
1024
+ const [componentState, setComponentState] = useState4({});
1025
+ const setComponentLoading = (id) => {
1026
+ setComponentState((prev) => {
1027
+ var _a;
1028
+ return __spreadProps(__spreadValues({}, prev), {
1029
+ [id]: __spreadProps(__spreadValues({}, prev[id]), {
1030
+ loadingCount: (((_a = prev[id]) == null ? void 0 : _a.loadingCount) || 0) + 1
1031
+ })
1032
+ });
1033
+ });
1034
+ };
1035
+ const unsetComponentLoading = (id) => {
1036
+ setComponentState((prev) => {
1037
+ var _a;
1038
+ return __spreadProps(__spreadValues({}, prev), {
1039
+ [id]: __spreadProps(__spreadValues({}, prev[id]), {
1040
+ loadingCount: Math.max((((_a = prev[id]) == null ? void 0 : _a.loadingCount) || 0) - 1, 0)
1041
+ })
1042
+ });
1043
+ });
1044
+ };
1045
+ const { getPermissions, refreshPermissions } = useResolvedPermissions(
1046
+ value.config,
1047
+ value.state,
1048
+ value.globalPermissions || {},
1049
+ setComponentLoading,
1050
+ unsetComponentLoading
1051
+ );
1052
+ const { resolveData } = useResolvedData(
1053
+ value.state,
1054
+ value.config,
1055
+ value.dispatch,
1056
+ setComponentLoading,
1057
+ unsetComponentLoading,
1058
+ refreshPermissions
1059
+ );
650
1060
  return /* @__PURE__ */ jsx4(
651
1061
  appContext.Provider,
652
1062
  {
653
1063
  value: __spreadProps(__spreadValues({}, value), {
1064
+ selectedItem,
654
1065
  zoomConfig,
655
1066
  setZoomConfig,
656
1067
  status,
657
1068
  setStatus,
658
- safariFallbackMode
1069
+ safariFallbackMode,
1070
+ getPermissions,
1071
+ refreshPermissions,
1072
+ componentState,
1073
+ setComponentState,
1074
+ resolveData
659
1075
  }),
660
1076
  children
661
1077
  }
@@ -663,10 +1079,8 @@ See https://github.com/measuredco/puck/issues/411 for more information. This mes
663
1079
  };
664
1080
  function useAppContext() {
665
1081
  const mainContext = useContext(appContext);
666
- const selectedItem = mainContext.state.ui.itemSelector ? getItem(mainContext.state.ui.itemSelector, mainContext.state.data) : void 0;
667
1082
  return __spreadProps(__spreadValues({}, mainContext), {
668
1083
  // Helpers
669
- selectedItem,
670
1084
  setUi: (ui, recordHistory) => {
671
1085
  return mainContext.dispatch({
672
1086
  type: "setUi",
@@ -770,7 +1184,7 @@ var Draggable = ({
770
1184
  };
771
1185
 
772
1186
  // components/AutoField/fields/ArrayField/index.tsx
773
- import { useCallback, useEffect as useEffect2, useState as useState3 } from "react";
1187
+ import { useCallback as useCallback3, useEffect as useEffect4, useState as useState5 } from "react";
774
1188
 
775
1189
  // components/DragIcon/index.tsx
776
1190
  init_react_import();
@@ -811,7 +1225,7 @@ var ArrayField = ({
811
1225
  id,
812
1226
  Label = (props) => /* @__PURE__ */ jsx9("div", __spreadValues({}, props))
813
1227
  }) => {
814
- const { state, setUi, selectedItem } = useAppContext();
1228
+ const { state, setUi, selectedItem, getPermissions } = useAppContext();
815
1229
  const readOnlyFields = (selectedItem == null ? void 0 : selectedItem.readOnly) || {};
816
1230
  const value = _value;
817
1231
  const arrayState = state.ui.arrayState[id] || {
@@ -823,11 +1237,11 @@ var ArrayField = ({
823
1237
  }),
824
1238
  openId: ""
825
1239
  };
826
- const [localState, setLocalState] = useState3({ arrayState, value });
827
- useEffect2(() => {
1240
+ const [localState, setLocalState] = useState5({ arrayState, value });
1241
+ useEffect4(() => {
828
1242
  setLocalState({ arrayState, value });
829
1243
  }, [value, state.ui.arrayState[id]]);
830
- const mapArrayStateToUi = useCallback(
1244
+ const mapArrayStateToUi = useCallback3(
831
1245
  (partialArrayState) => {
832
1246
  return {
833
1247
  arrayState: __spreadProps(__spreadValues({}, state.ui.arrayState), {
@@ -837,13 +1251,13 @@ var ArrayField = ({
837
1251
  },
838
1252
  [arrayState]
839
1253
  );
840
- const getHighestIndex = useCallback(() => {
1254
+ const getHighestIndex = useCallback3(() => {
841
1255
  return arrayState.items.reduce(
842
1256
  (acc, item) => item._originalIndex > acc ? item._originalIndex : acc,
843
1257
  -1
844
1258
  );
845
1259
  }, [arrayState]);
846
- const regenerateArrayState = useCallback(
1260
+ const regenerateArrayState = useCallback3(
847
1261
  (value2) => {
848
1262
  let highestIndex = getHighestIndex();
849
1263
  const newItems = Array.from(value2 || []).map((item, idx) => {
@@ -862,12 +1276,13 @@ var ArrayField = ({
862
1276
  },
863
1277
  [arrayState]
864
1278
  );
865
- useEffect2(() => {
1279
+ useEffect4(() => {
866
1280
  if (arrayState.items.length > 0) {
867
1281
  setUi(mapArrayStateToUi(arrayState));
868
1282
  }
869
1283
  }, []);
870
- const [hovering, setHovering] = useState3(false);
1284
+ const [hovering, setHovering] = useState5(false);
1285
+ const forceReadOnly = getPermissions({ item: selectedItem }).edit === false;
871
1286
  if (field.type !== "array" || !field.arrayFields) {
872
1287
  return null;
873
1288
  }
@@ -998,13 +1413,14 @@ var ArrayField = ({
998
1413
  const subField = field.arrayFields[fieldName];
999
1414
  const subFieldName = `${name}[${i}].${fieldName}`;
1000
1415
  const wildcardFieldName = `${name}[*].${fieldName}`;
1416
+ const subReadOnly = forceReadOnly ? forceReadOnly : typeof readOnlyFields[subFieldName] !== "undefined" ? readOnlyFields[subFieldName] : readOnlyFields[wildcardFieldName];
1001
1417
  return /* @__PURE__ */ jsx9(
1002
1418
  AutoFieldPrivate,
1003
1419
  {
1004
1420
  name: subFieldName,
1005
1421
  label: subField.label || fieldName,
1006
1422
  id: `${_arrayId}_${fieldName}`,
1007
- readOnly: typeof readOnlyFields[subFieldName] !== "undefined" ? readOnlyFields[subFieldName] : readOnlyFields[wildcardFieldName],
1423
+ readOnly: subReadOnly,
1008
1424
  field: subField,
1009
1425
  value: data[fieldName],
1010
1426
  onChange: (val, ui) => {
@@ -1104,19 +1520,19 @@ var DefaultField = ({
1104
1520
 
1105
1521
  // components/AutoField/fields/ExternalField/index.tsx
1106
1522
  init_react_import();
1107
- import { useEffect as useEffect6 } from "react";
1523
+ import { useEffect as useEffect8 } from "react";
1108
1524
 
1109
1525
  // components/ExternalInput/index.tsx
1110
1526
  init_react_import();
1111
- import { useMemo, useEffect as useEffect5, useState as useState6, useCallback as useCallback2 } from "react";
1527
+ import { useMemo, useEffect as useEffect7, useState as useState8, useCallback as useCallback4 } from "react";
1112
1528
 
1113
1529
  // css-module:/home/runner/work/puck/puck/packages/core/components/ExternalInput/styles.module.css#css-module
1114
1530
  init_react_import();
1115
- var styles_module_default6 = { "ExternalInput-actions": "_ExternalInput-actions_19obq_1", "ExternalInput-button": "_ExternalInput-button_19obq_5", "ExternalInput--dataSelected": "_ExternalInput--dataSelected_19obq_25", "ExternalInput-detachButton": "_ExternalInput-detachButton_19obq_32", "ExternalInputModal": "_ExternalInputModal_19obq_74", "ExternalInputModal-grid": "_ExternalInputModal-grid_19obq_84", "ExternalInputModal--filtersToggled": "_ExternalInputModal--filtersToggled_19obq_95", "ExternalInputModal-filters": "_ExternalInputModal-filters_19obq_100", "ExternalInputModal-masthead": "_ExternalInputModal-masthead_19obq_119", "ExternalInputModal-tableWrapper": "_ExternalInputModal-tableWrapper_19obq_128", "ExternalInputModal-table": "_ExternalInputModal-table_19obq_128", "ExternalInputModal-thead": "_ExternalInputModal-thead_19obq_144", "ExternalInputModal-th": "_ExternalInputModal-th_19obq_144", "ExternalInputModal-td": "_ExternalInputModal-td_19obq_159", "ExternalInputModal-tr": "_ExternalInputModal-tr_19obq_164", "ExternalInputModal-tbody": "_ExternalInputModal-tbody_19obq_171", "ExternalInputModal--hasData": "_ExternalInputModal--hasData_19obq_197", "ExternalInputModal-loadingBanner": "_ExternalInputModal-loadingBanner_19obq_201", "ExternalInputModal--isLoading": "_ExternalInputModal--isLoading_19obq_218", "ExternalInputModal-searchForm": "_ExternalInputModal-searchForm_19obq_222", "ExternalInputModal-search": "_ExternalInputModal-search_19obq_222", "ExternalInputModal-searchIcon": "_ExternalInputModal-searchIcon_19obq_259", "ExternalInputModal-searchIconText": "_ExternalInputModal-searchIconText_19obq_284", "ExternalInputModal-searchInput": "_ExternalInputModal-searchInput_19obq_294", "ExternalInputModal-searchActions": "_ExternalInputModal-searchActions_19obq_308", "ExternalInputModal-searchActionIcon": "_ExternalInputModal-searchActionIcon_19obq_321", "ExternalInputModal-footer": "_ExternalInputModal-footer_19obq_325" };
1531
+ var styles_module_default6 = { "ExternalInput-actions": "_ExternalInput-actions_wprq3_1", "ExternalInput-button": "_ExternalInput-button_wprq3_5", "ExternalInput--dataSelected": "_ExternalInput--dataSelected_wprq3_24", "ExternalInput--readOnly": "_ExternalInput--readOnly_wprq3_31", "ExternalInput-detachButton": "_ExternalInput-detachButton_wprq3_35", "ExternalInput": "_ExternalInput_wprq3_1", "ExternalInputModal": "_ExternalInputModal_wprq3_79", "ExternalInputModal-grid": "_ExternalInputModal-grid_wprq3_89", "ExternalInputModal--filtersToggled": "_ExternalInputModal--filtersToggled_wprq3_100", "ExternalInputModal-filters": "_ExternalInputModal-filters_wprq3_105", "ExternalInputModal-masthead": "_ExternalInputModal-masthead_wprq3_124", "ExternalInputModal-tableWrapper": "_ExternalInputModal-tableWrapper_wprq3_133", "ExternalInputModal-table": "_ExternalInputModal-table_wprq3_133", "ExternalInputModal-thead": "_ExternalInputModal-thead_wprq3_149", "ExternalInputModal-th": "_ExternalInputModal-th_wprq3_149", "ExternalInputModal-td": "_ExternalInputModal-td_wprq3_164", "ExternalInputModal-tr": "_ExternalInputModal-tr_wprq3_169", "ExternalInputModal-tbody": "_ExternalInputModal-tbody_wprq3_176", "ExternalInputModal--hasData": "_ExternalInputModal--hasData_wprq3_202", "ExternalInputModal-loadingBanner": "_ExternalInputModal-loadingBanner_wprq3_206", "ExternalInputModal--isLoading": "_ExternalInputModal--isLoading_wprq3_223", "ExternalInputModal-searchForm": "_ExternalInputModal-searchForm_wprq3_227", "ExternalInputModal-search": "_ExternalInputModal-search_wprq3_227", "ExternalInputModal-searchIcon": "_ExternalInputModal-searchIcon_wprq3_264", "ExternalInputModal-searchIconText": "_ExternalInputModal-searchIconText_wprq3_289", "ExternalInputModal-searchInput": "_ExternalInputModal-searchInput_wprq3_299", "ExternalInputModal-searchActions": "_ExternalInputModal-searchActions_wprq3_313", "ExternalInputModal-searchActionIcon": "_ExternalInputModal-searchActionIcon_wprq3_326", "ExternalInputModal-footer": "_ExternalInputModal-footer_wprq3_330" };
1116
1532
 
1117
1533
  // components/Modal/index.tsx
1118
1534
  init_react_import();
1119
- import { useEffect as useEffect3, useState as useState4 } from "react";
1535
+ import { useEffect as useEffect5, useState as useState6 } from "react";
1120
1536
 
1121
1537
  // css-module:/home/runner/work/puck/puck/packages/core/components/Modal/styles.module.css#css-module
1122
1538
  init_react_import();
@@ -1131,8 +1547,8 @@ var Modal = ({
1131
1547
  onClose,
1132
1548
  isOpen
1133
1549
  }) => {
1134
- const [rootEl, setRootEl] = useState4(null);
1135
- useEffect3(() => {
1550
+ const [rootEl, setRootEl] = useState6(null);
1551
+ useEffect5(() => {
1136
1552
  setRootEl(document.getElementById("puck-portal-root"));
1137
1553
  }, []);
1138
1554
  if (!rootEl) {
@@ -1179,7 +1595,7 @@ init_react_import();
1179
1595
 
1180
1596
  // components/Button/Button.tsx
1181
1597
  init_react_import();
1182
- import { useEffect as useEffect4, useState as useState5 } from "react";
1598
+ import { useEffect as useEffect6, useState as useState7 } from "react";
1183
1599
 
1184
1600
  // css-module:/home/runner/work/puck/puck/packages/core/components/Button/Button.module.css#css-module
1185
1601
  init_react_import();
@@ -1202,8 +1618,8 @@ var Button = ({
1202
1618
  size = "medium",
1203
1619
  loading: loadingProp = false
1204
1620
  }) => {
1205
- const [loading, setLoading] = useState5(loadingProp);
1206
- useEffect4(() => setLoading(loadingProp), [loadingProp]);
1621
+ const [loading, setLoading] = useState7(loadingProp);
1622
+ useEffect6(() => setLoading(loadingProp), [loadingProp]);
1207
1623
  const ElementType = href ? "a" : type ? "button" : "span";
1208
1624
  const el = /* @__PURE__ */ jsxs6(
1209
1625
  ElementType,
@@ -1248,19 +1664,20 @@ var ExternalInput = ({
1248
1664
  onChange,
1249
1665
  value = null,
1250
1666
  name,
1251
- id
1667
+ id,
1668
+ readOnly
1252
1669
  }) => {
1253
1670
  const {
1254
1671
  mapProp = (val) => val,
1255
1672
  mapRow = (val) => val,
1256
1673
  filterFields
1257
1674
  } = field || {};
1258
- const [data, setData] = useState6([]);
1259
- const [isOpen, setOpen] = useState6(false);
1260
- const [isLoading, setIsLoading] = useState6(true);
1675
+ const [data, setData] = useState8([]);
1676
+ const [isOpen, setOpen] = useState8(false);
1677
+ const [isLoading, setIsLoading] = useState8(true);
1261
1678
  const hasFilterFields = !!filterFields;
1262
- const [filters, setFilters] = useState6(field.initialFilters || {});
1263
- const [filtersToggled, setFiltersToggled] = useState6(hasFilterFields);
1679
+ const [filters, setFilters] = useState8(field.initialFilters || {});
1680
+ const [filtersToggled, setFiltersToggled] = useState8(hasFilterFields);
1264
1681
  const mappedData = useMemo(() => {
1265
1682
  return data.map(mapRow);
1266
1683
  }, [data]);
@@ -1275,8 +1692,8 @@ var ExternalInput = ({
1275
1692
  }
1276
1693
  return Array.from(validKeys);
1277
1694
  }, [mappedData]);
1278
- const [searchQuery, setSearchQuery] = useState6(field.initialQuery || "");
1279
- const search = useCallback2(
1695
+ const [searchQuery, setSearchQuery] = useState8(field.initialQuery || "");
1696
+ const search = useCallback4(
1280
1697
  (query, filters2) => __async(void 0, null, function* () {
1281
1698
  setIsLoading(true);
1282
1699
  const cacheKey = `${id}-${query}-${JSON.stringify(filters2)}`;
@@ -1289,7 +1706,7 @@ var ExternalInput = ({
1289
1706
  }),
1290
1707
  [id, field]
1291
1708
  );
1292
- useEffect5(() => {
1709
+ useEffect7(() => {
1293
1710
  search(searchQuery, filters);
1294
1711
  }, []);
1295
1712
  return /* @__PURE__ */ jsxs7(
@@ -1297,7 +1714,8 @@ var ExternalInput = ({
1297
1714
  {
1298
1715
  className: getClassName10({
1299
1716
  dataSelected: !!value,
1300
- modalVisible: isOpen
1717
+ modalVisible: isOpen,
1718
+ readOnly
1301
1719
  }),
1302
1720
  id,
1303
1721
  children: [
@@ -1308,6 +1726,7 @@ var ExternalInput = ({
1308
1726
  type: "button",
1309
1727
  onClick: () => setOpen(true),
1310
1728
  className: getClassName10("button"),
1729
+ disabled: readOnly,
1311
1730
  children: value ? field.getItemSummary ? field.getItemSummary(value) : "External item" : /* @__PURE__ */ jsxs7(Fragment7, { children: [
1312
1731
  /* @__PURE__ */ jsx14(Link, { size: "16" }),
1313
1732
  /* @__PURE__ */ jsx14("span", { children: field.placeholder })
@@ -1317,10 +1736,12 @@ var ExternalInput = ({
1317
1736
  value && /* @__PURE__ */ jsx14(
1318
1737
  "button",
1319
1738
  {
1739
+ type: "button",
1320
1740
  className: getClassName10("detachButton"),
1321
1741
  onClick: () => {
1322
1742
  onChange(null);
1323
1743
  },
1744
+ disabled: readOnly,
1324
1745
  children: /* @__PURE__ */ jsx14(Unlock, { size: 16 })
1325
1746
  }
1326
1747
  )
@@ -1446,12 +1867,13 @@ var ExternalField = ({
1446
1867
  name,
1447
1868
  label,
1448
1869
  Label,
1449
- id
1870
+ id,
1871
+ readOnly
1450
1872
  }) => {
1451
1873
  var _a, _b, _c;
1452
1874
  const validField = field;
1453
1875
  const deprecatedField = field;
1454
- useEffect6(() => {
1876
+ useEffect8(() => {
1455
1877
  if (deprecatedField.adaptor) {
1456
1878
  console.error(
1457
1879
  "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."
@@ -1478,7 +1900,8 @@ var ExternalField = ({
1478
1900
  }),
1479
1901
  onChange,
1480
1902
  value,
1481
- id
1903
+ id,
1904
+ readOnly
1482
1905
  }
1483
1906
  ) });
1484
1907
  };
@@ -1659,13 +2082,14 @@ var ObjectField = ({
1659
2082
  const subField = field.objectFields[fieldName];
1660
2083
  const subFieldName = `${name}.${fieldName}`;
1661
2084
  const wildcardFieldName = `${name}.${fieldName}`;
2085
+ const subReadOnly = readOnly ? readOnly : typeof readOnlyFields[subFieldName] !== "undefined" ? readOnlyFields[subFieldName] : readOnlyFields[wildcardFieldName];
1662
2086
  return /* @__PURE__ */ jsx19(
1663
2087
  AutoFieldPrivate,
1664
2088
  {
1665
2089
  name: subFieldName,
1666
2090
  label: subField.label || fieldName,
1667
2091
  id: `${id}_${fieldName}`,
1668
- readOnly: typeof readOnlyFields[subFieldName] !== "undefined" ? readOnlyFields[subFieldName] : readOnlyFields[wildcardFieldName],
2092
+ readOnly: subReadOnly,
1669
2093
  field: subField,
1670
2094
  value: data[fieldName],
1671
2095
  onChange: (val, ui) => {
@@ -1686,7 +2110,7 @@ var ObjectField = ({
1686
2110
 
1687
2111
  // lib/use-safe-id.ts
1688
2112
  init_react_import();
1689
- import React2, { useState as useState7 } from "react";
2113
+ import React2, { useState as useState9 } from "react";
1690
2114
 
1691
2115
  // lib/generate-id.ts
1692
2116
  init_react_import();
@@ -1698,7 +2122,7 @@ var useSafeId = () => {
1698
2122
  if (typeof React2.useId !== "undefined") {
1699
2123
  return React2.useId();
1700
2124
  }
1701
- const [id] = useState7(generateId());
2125
+ const [id] = useState9(generateId());
1702
2126
  return id;
1703
2127
  };
1704
2128
 
@@ -1795,7 +2219,7 @@ function AutoFieldInternal(props) {
1795
2219
  }
1796
2220
  function AutoFieldPrivate(props) {
1797
2221
  const { value, onChange } = props;
1798
- const [localValue, setLocalValue] = useState8(value);
2222
+ const [localValue, setLocalValue] = useState10(value);
1799
2223
  const onChangeDb = useDebouncedCallback(
1800
2224
  (val, ui) => {
1801
2225
  onChange(val, ui);
@@ -1803,11 +2227,11 @@ function AutoFieldPrivate(props) {
1803
2227
  50,
1804
2228
  { leading: true }
1805
2229
  );
1806
- const onChangeLocal = useCallback3((val, ui) => {
2230
+ const onChangeLocal = useCallback5((val, ui) => {
1807
2231
  setLocalValue(val);
1808
2232
  onChangeDb(val, ui);
1809
2233
  }, []);
1810
- useEffect7(() => {
2234
+ useEffect9(() => {
1811
2235
  setLocalValue(value);
1812
2236
  }, [value]);
1813
2237
  const localProps = {
@@ -1826,7 +2250,7 @@ init_react_import();
1826
2250
 
1827
2251
  // css-module:/home/runner/work/puck/puck/packages/core/components/Drawer/styles.module.css#css-module
1828
2252
  init_react_import();
1829
- var styles_module_default10 = { "Drawer": "_Drawer_4yfqn_1", "DrawerItem--disabled": "_DrawerItem--disabled_4yfqn_5", "DrawerItem-default": "_DrawerItem-default_4yfqn_11", "DrawerItem-draggableWrapper": "_DrawerItem-draggableWrapper_4yfqn_11", "DrawerItem": "_DrawerItem_4yfqn_5", "DrawerItem-draggable": "_DrawerItem-draggable_4yfqn_11", "Drawer--isDraggingFrom": "_Drawer--isDraggingFrom_4yfqn_36", "DrawerItem-name": "_DrawerItem-name_4yfqn_54" };
2253
+ var styles_module_default10 = { "Drawer": "_Drawer_1oa7v_1", "DrawerItem--disabled": "_DrawerItem--disabled_1oa7v_5", "DrawerItem-draggable": "_DrawerItem-draggable_1oa7v_5", "DrawerItem-default": "_DrawerItem-default_1oa7v_11", "DrawerItem-draggableWrapper": "_DrawerItem-draggableWrapper_1oa7v_11", "DrawerItem": "_DrawerItem_1oa7v_5", "Drawer--isDraggingFrom": "_Drawer--isDraggingFrom_1oa7v_36", "DrawerItem-name": "_DrawerItem-name_1oa7v_54" };
1830
2254
 
1831
2255
  // components/Drawer/index.tsx
1832
2256
  import {
@@ -1911,14 +2335,14 @@ Drawer.Item = DrawerItem;
1911
2335
 
1912
2336
  // components/DropZone/index.tsx
1913
2337
  init_react_import();
1914
- import { useContext as useContext3, useEffect as useEffect10 } from "react";
2338
+ import { useContext as useContext3, useEffect as useEffect12 } from "react";
1915
2339
 
1916
2340
  // components/DraggableComponent/index.tsx
1917
2341
  init_react_import();
1918
2342
  import {
1919
- useEffect as useEffect9,
2343
+ useEffect as useEffect11,
1920
2344
  useMemo as useMemo4,
1921
- useState as useState10
2345
+ useState as useState12
1922
2346
  } from "react";
1923
2347
  import { Draggable as Draggable2 } from "@measured/dnd";
1924
2348
 
@@ -1928,10 +2352,10 @@ var styles_module_default11 = { "DraggableComponent": "_DraggableComponent_1bhad
1928
2352
 
1929
2353
  // lib/use-modifier-held.ts
1930
2354
  init_react_import();
1931
- import { useEffect as useEffect8, useState as useState9 } from "react";
2355
+ import { useEffect as useEffect10, useState as useState11 } from "react";
1932
2356
  var useModifierHeld = (modifier) => {
1933
- const [modifierHeld, setModifierHeld] = useState9(false);
1934
- useEffect8(() => {
2357
+ const [modifierHeld, setModifierHeld] = useState11(false);
2358
+ useEffect10(() => {
1935
2359
  function downHandler({ key }) {
1936
2360
  if (key === modifier) {
1937
2361
  setModifierHeld(true);
@@ -1969,90 +2393,6 @@ init_react_import();
1969
2393
  import { Fragment as Fragment9, jsx as jsx22 } from "react/jsx-runtime";
1970
2394
  var DefaultOverride = ({ children }) => /* @__PURE__ */ jsx22(Fragment9, { children });
1971
2395
 
1972
- // lib/get-permissions.ts
1973
- init_react_import();
1974
-
1975
- // lib/get-changed.ts
1976
- init_react_import();
1977
- var getChanged = (newItem, oldItem) => {
1978
- return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1979
- const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1980
- const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1981
- return __spreadProps(__spreadValues({}, acc), {
1982
- [item]: oldItemProps[item] !== newItemProps[item]
1983
- });
1984
- }, {}) : {};
1985
- };
1986
-
1987
- // lib/resolve-permissions.ts
1988
- init_react_import();
1989
- var resolvePermissions = ({
1990
- selectedItem,
1991
- config,
1992
- changed,
1993
- lastPermissions,
1994
- initialPermissions,
1995
- appState
1996
- }) => {
1997
- const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
1998
- if (selectedItem && (componentConfig == null ? void 0 : componentConfig.resolvePermissions)) {
1999
- return componentConfig.resolvePermissions(selectedItem, {
2000
- changed,
2001
- lastPermissions,
2002
- initialPermissions,
2003
- appState
2004
- });
2005
- }
2006
- return {};
2007
- };
2008
-
2009
- // lib/get-permissions.ts
2010
- var cache = { lastPermissions: {}, lastSelected: {} };
2011
- var getPermissions = ({
2012
- selectedItem,
2013
- type,
2014
- globalPermissions,
2015
- config,
2016
- appState
2017
- }) => {
2018
- const componentType = type || selectedItem && selectedItem.type || "";
2019
- const componentId = selectedItem && selectedItem.props.id || "";
2020
- let componentPermissions = getInitialPermissions({
2021
- componentType,
2022
- config,
2023
- globalPermissions
2024
- });
2025
- const changed = getChanged(selectedItem, cache.lastSelected);
2026
- if (Object.values(changed).some((el) => el === true)) {
2027
- const resolvedPermissions = resolvePermissions({
2028
- selectedItem,
2029
- config,
2030
- changed,
2031
- lastPermissions: cache.lastPermissions[componentId] || componentPermissions,
2032
- initialPermissions: componentPermissions,
2033
- appState
2034
- });
2035
- if (resolvedPermissions !== void 0) {
2036
- componentPermissions = __spreadValues(__spreadValues({}, componentPermissions), resolvedPermissions);
2037
- }
2038
- cache.lastSelected = selectedItem;
2039
- cache.lastPermissions[componentId] = componentPermissions;
2040
- return componentPermissions;
2041
- }
2042
- if (Object.keys(componentId && cache.lastPermissions[componentId]).length !== 0) {
2043
- componentPermissions = cache.lastPermissions[componentId];
2044
- }
2045
- return componentPermissions;
2046
- };
2047
- var getInitialPermissions = ({
2048
- componentType,
2049
- globalPermissions,
2050
- config
2051
- }) => {
2052
- var _a;
2053
- return __spreadValues(__spreadValues({}, globalPermissions), (_a = config.components[componentType]) == null ? void 0 : _a.permissions);
2054
- };
2055
-
2056
2396
  // components/DraggableComponent/index.tsx
2057
2397
  import { jsx as jsx23, jsxs as jsxs11 } from "react/jsx-runtime";
2058
2398
  var getClassName17 = get_class_name_factory_default("DraggableComponent", styles_module_default11);
@@ -2063,7 +2403,7 @@ var actionsRight = space;
2063
2403
  var DefaultActionBar = ({
2064
2404
  label,
2065
2405
  children
2066
- }) => /* @__PURE__ */ jsx23(ActionBar, { label, children: /* @__PURE__ */ jsx23(DefaultOverride, { children }) });
2406
+ }) => /* @__PURE__ */ jsx23(ActionBar, { label, children: /* @__PURE__ */ jsx23(ActionBar.Group, { children: /* @__PURE__ */ jsx23(DefaultOverride, { children }) }) });
2067
2407
  var DraggableComponent = ({
2068
2408
  children,
2069
2409
  id,
@@ -2086,21 +2426,12 @@ var DraggableComponent = ({
2086
2426
  indicativeHover = false,
2087
2427
  style
2088
2428
  }) => {
2089
- const {
2090
- zoomConfig,
2091
- status,
2092
- overrides,
2093
- plugins,
2094
- selectedItem,
2095
- config,
2096
- globalPermissions,
2097
- state
2098
- } = useAppContext();
2429
+ const { zoomConfig, status, overrides, selectedItem, getPermissions } = useAppContext();
2099
2430
  const isModifierHeld = useModifierHeld("Alt");
2100
2431
  const El = status !== "LOADING" ? Draggable2 : DefaultDraggable;
2101
- useEffect9(onMount, []);
2102
- const [disableSecondaryAnimation, setDisableSecondaryAnimation] = useState10(false);
2103
- useEffect9(() => {
2432
+ useEffect11(onMount, []);
2433
+ const [disableSecondaryAnimation, setDisableSecondaryAnimation] = useState12(false);
2434
+ useEffect11(() => {
2104
2435
  if (isIos()) {
2105
2436
  setDisableSecondaryAnimation(true);
2106
2437
  }
@@ -2109,11 +2440,8 @@ var DraggableComponent = ({
2109
2440
  () => overrides.actionBar || DefaultActionBar,
2110
2441
  [overrides.actionBar]
2111
2442
  );
2112
- const permissions = selectedItem && getPermissions({
2113
- selectedItem,
2114
- globalPermissions: globalPermissions || {},
2115
- config,
2116
- appState: state
2443
+ const permissions = getPermissions({
2444
+ item: selectedItem
2117
2445
  });
2118
2446
  return /* @__PURE__ */ jsx23(
2119
2447
  El,
@@ -2136,7 +2464,7 @@ var DraggableComponent = ({
2136
2464
  indicativeHover
2137
2465
  }),
2138
2466
  style: __spreadProps(__spreadValues(__spreadValues({}, style), provided.draggableProps.style), {
2139
- cursor: isModifierHeld || isDragDisabled ? "initial" : "grab"
2467
+ cursor: isModifierHeld || isDragDisabled ? "pointer" : "grab"
2140
2468
  }),
2141
2469
  onMouseOver,
2142
2470
  onMouseOut,
@@ -2163,8 +2491,8 @@ var DraggableComponent = ({
2163
2491
  right: actionsRight / zoomConfig.zoom
2164
2492
  },
2165
2493
  children: /* @__PURE__ */ jsxs11(CustomActionBar, { label, children: [
2166
- permissions && permissions.duplicate && /* @__PURE__ */ jsx23(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ jsx23(Copy, { size: 16 }) }),
2167
- permissions && permissions.delete && /* @__PURE__ */ jsx23(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ jsx23(Trash, { size: 16 }) })
2494
+ permissions.duplicate && /* @__PURE__ */ jsx23(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ jsx23(Copy, { size: 16 }) }),
2495
+ permissions.delete && /* @__PURE__ */ jsx23(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ jsx23(Trash, { size: 16 }) })
2168
2496
  ] })
2169
2497
  }
2170
2498
  )
@@ -2188,8 +2516,8 @@ var styles_module_default12 = { "DropZone": "_DropZone_djoti_1", "DropZone-conte
2188
2516
  init_react_import();
2189
2517
  import {
2190
2518
  createContext as createContext3,
2191
- useCallback as useCallback4,
2192
- useState as useState11
2519
+ useCallback as useCallback6,
2520
+ useState as useState13
2193
2521
  } from "react";
2194
2522
  import { useDebounce } from "use-debounce";
2195
2523
 
@@ -2212,24 +2540,24 @@ var DropZoneProvider = ({
2212
2540
  children,
2213
2541
  value
2214
2542
  }) => {
2215
- const [hoveringArea, setHoveringArea] = useState11(null);
2216
- const [hoveringZone, setHoveringZone] = useState11(
2543
+ const [hoveringArea, setHoveringArea] = useState13(null);
2544
+ const [hoveringZone, setHoveringZone] = useState13(
2217
2545
  rootDroppableId
2218
2546
  );
2219
- const [hoveringComponent, setHoveringComponent] = useState11();
2547
+ const [hoveringComponent, setHoveringComponent] = useState13();
2220
2548
  const [hoveringAreaDb] = useDebounce(hoveringArea, 75, { leading: false });
2221
- const [areasWithZones, setAreasWithZones] = useState11(
2549
+ const [areasWithZones, setAreasWithZones] = useState13(
2222
2550
  {}
2223
2551
  );
2224
- const [activeZones, setActiveZones] = useState11({});
2552
+ const [activeZones, setActiveZones] = useState13({});
2225
2553
  const { dispatch = null } = value ? value : {};
2226
- const registerZoneArea = useCallback4(
2554
+ const registerZoneArea = useCallback6(
2227
2555
  (area) => {
2228
2556
  setAreasWithZones((latest) => __spreadProps(__spreadValues({}, latest), { [area]: true }));
2229
2557
  },
2230
2558
  [setAreasWithZones]
2231
2559
  );
2232
- const registerZone = useCallback4(
2560
+ const registerZone = useCallback6(
2233
2561
  (zoneCompound) => {
2234
2562
  if (!dispatch) {
2235
2563
  return;
@@ -2242,7 +2570,7 @@ var DropZoneProvider = ({
2242
2570
  },
2243
2571
  [setActiveZones, dispatch]
2244
2572
  );
2245
- const unregisterZone = useCallback4(
2573
+ const unregisterZone = useCallback6(
2246
2574
  (zoneCompound) => {
2247
2575
  if (!dispatch) {
2248
2576
  return;
@@ -2257,8 +2585,8 @@ var DropZoneProvider = ({
2257
2585
  },
2258
2586
  [setActiveZones, dispatch]
2259
2587
  );
2260
- const [pathData, setPathData] = useState11();
2261
- const registerPath = useCallback4(
2588
+ const [pathData, setPathData] = useState13();
2589
+ const registerPath = useCallback6(
2262
2590
  (selector) => {
2263
2591
  if (!(value == null ? void 0 : value.data)) {
2264
2592
  return;
@@ -2283,7 +2611,7 @@ var DropZoneProvider = ({
2283
2611
  },
2284
2612
  [value, setPathData]
2285
2613
  );
2286
- const [zoneWillDrag, setZoneWillDrag] = useState11("");
2614
+ const [zoneWillDrag, setZoneWillDrag] = useState13("");
2287
2615
  return /* @__PURE__ */ jsx24(Fragment10, { children: value && /* @__PURE__ */ jsx24(
2288
2616
  dropZoneContext.Provider,
2289
2617
  {
@@ -2334,12 +2662,12 @@ function DropZoneEdit({ zone, allow, disallow, style }) {
2334
2662
  } = ctx || {};
2335
2663
  let content = data.content || [];
2336
2664
  let zoneCompound = rootDroppableId;
2337
- useEffect10(() => {
2665
+ useEffect12(() => {
2338
2666
  if (areaId && registerZoneArea) {
2339
2667
  registerZoneArea(areaId);
2340
2668
  }
2341
2669
  }, [areaId]);
2342
- useEffect10(() => {
2670
+ useEffect12(() => {
2343
2671
  if (ctx == null ? void 0 : ctx.registerZone) {
2344
2672
  ctx == null ? void 0 : ctx.registerZone(zoneCompound);
2345
2673
  }
@@ -2466,14 +2794,11 @@ function DropZoneEdit({ zone, allow, disallow, style }) {
2466
2794
  ] });
2467
2795
  const componentConfig = config.components[item.type];
2468
2796
  const label = (_b = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _b : item.type.toString();
2469
- const canDrag = getPermissions({
2470
- selectedItem: getItem(
2797
+ const canDrag = appContext2.getPermissions({
2798
+ item: getItem(
2471
2799
  { index: i, zone: zoneCompound },
2472
2800
  appContext2.state.data
2473
- ),
2474
- config: appContext2.config,
2475
- globalPermissions: appContext2.globalPermissions || {},
2476
- appState: appContext2.state
2801
+ )
2477
2802
  }).drag;
2478
2803
  return /* @__PURE__ */ jsxs12(
2479
2804
  "div",
@@ -2498,7 +2823,7 @@ function DropZoneEdit({ zone, allow, disallow, style }) {
2498
2823
  forceHover: hoveringComponent === componentId && !userIsDragging,
2499
2824
  isDragDisabled: !canDrag,
2500
2825
  indicativeHover: userIsDragging && containsZone && hoveringArea === componentId,
2501
- isLoading: (_c = appContext2.componentState[componentId]) == null ? void 0 : _c.loading,
2826
+ isLoading: ((_c = appContext2.componentState[componentId]) == null ? void 0 : _c.loadingCount) > 0,
2502
2827
  onMount: () => {
2503
2828
  ctx.registerPath({
2504
2829
  index: i,
@@ -2640,16 +2965,16 @@ function DropZone(props) {
2640
2965
  // components/Puck/index.tsx
2641
2966
  init_react_import();
2642
2967
  import {
2643
- useCallback as useCallback10,
2644
- useEffect as useEffect17,
2968
+ useCallback as useCallback11,
2969
+ useEffect as useEffect18,
2645
2970
  useMemo as useMemo13,
2646
2971
  useReducer,
2647
- useState as useState20
2972
+ useState as useState21
2648
2973
  } from "react";
2649
2974
 
2650
2975
  // lib/use-placeholder-style.ts
2651
2976
  init_react_import();
2652
- import { useState as useState12 } from "react";
2977
+ import { useState as useState14 } from "react";
2653
2978
 
2654
2979
  // lib/get-frame.ts
2655
2980
  init_react_import();
@@ -2664,7 +2989,7 @@ var getFrame = () => {
2664
2989
  // lib/use-placeholder-style.ts
2665
2990
  var usePlaceholderStyle = () => {
2666
2991
  const queryAttr = "data-rfd-drag-handle-draggable-id";
2667
- const [placeholderStyle, setPlaceholderStyle] = useState12();
2992
+ const [placeholderStyle, setPlaceholderStyle] = useState14();
2668
2993
  const onDragStartOrUpdate = (draggedItem) => {
2669
2994
  var _a;
2670
2995
  const draggableId = draggedItem.draggableId;
@@ -2806,6 +3131,7 @@ var SidebarSection = ({
2806
3131
  /* @__PURE__ */ jsx26(
2807
3132
  "button",
2808
3133
  {
3134
+ type: "button",
2809
3135
  className: getClassName19("breadcrumbLabel"),
2810
3136
  onClick: () => setUi({ itemSelector: breadcrumb.selector }),
2811
3137
  children: breadcrumb.label
@@ -2846,7 +3172,7 @@ var remove = (list, index) => {
2846
3172
 
2847
3173
  // lib/reduce-related-zones.ts
2848
3174
  init_react_import();
2849
- var reduceRelatedZones = (item, data, fn) => {
3175
+ function reduceRelatedZones(item, data, fn) {
2850
3176
  return __spreadProps(__spreadValues({}, data), {
2851
3177
  zones: Object.keys(data.zones || {}).reduce(
2852
3178
  (acc, key) => {
@@ -2860,7 +3186,7 @@ var reduceRelatedZones = (item, data, fn) => {
2860
3186
  {}
2861
3187
  )
2862
3188
  });
2863
- };
3189
+ }
2864
3190
  var findRelatedByZoneId = (zoneId, data) => {
2865
3191
  const [zoneParentId] = getZoneId(zoneId);
2866
3192
  return (data.zones[zoneId] || []).reduce(
@@ -2897,7 +3223,7 @@ var removeRelatedZones = (item, data) => {
2897
3223
  });
2898
3224
  return newData;
2899
3225
  };
2900
- var duplicateRelatedZones = (item, data, newId) => {
3226
+ function duplicateRelatedZones(item, data, newId) {
2901
3227
  return reduceRelatedZones(item, data, (acc, key, zone) => {
2902
3228
  const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
2903
3229
  props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
@@ -2912,7 +3238,7 @@ var duplicateRelatedZones = (item, data, newId) => {
2912
3238
  [`${newId}:${zoneId}`]: dupedZone
2913
3239
  });
2914
3240
  });
2915
- };
3241
+ }
2916
3242
 
2917
3243
  // reducer/data.ts
2918
3244
  var zoneCache = {};
@@ -2936,7 +3262,7 @@ var replaceAction = (data, action) => {
2936
3262
  })
2937
3263
  });
2938
3264
  };
2939
- var insertAction = (data, action, config) => {
3265
+ function insertAction(data, action, config) {
2940
3266
  const emptyComponentData = {
2941
3267
  type: action.componentType,
2942
3268
  props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
@@ -2962,8 +3288,8 @@ var insertAction = (data, action, config) => {
2962
3288
  )
2963
3289
  })
2964
3290
  });
2965
- };
2966
- var reduceData = (data, action, config) => {
3291
+ }
3292
+ function reduceData(data, action, config) {
2967
3293
  if (action.type === "insert") {
2968
3294
  return insertAction(data, action, config);
2969
3295
  }
@@ -3105,278 +3431,88 @@ var reduceData = (data, action, config) => {
3105
3431
  }
3106
3432
  return __spreadProps(__spreadValues({}, data), { zones: _zones });
3107
3433
  }
3108
- if (action.type === "setData") {
3109
- if (typeof action.data === "object") {
3110
- return __spreadValues(__spreadValues({}, data), action.data);
3111
- }
3112
- return __spreadValues(__spreadValues({}, data), action.data(data));
3113
- }
3114
- return data;
3115
- };
3116
-
3117
- // reducer/state.ts
3118
- init_react_import();
3119
- var reduceUi = (ui, action) => {
3120
- if (action.type === "setUi") {
3121
- if (typeof action.ui === "object") {
3122
- return __spreadValues(__spreadValues({}, ui), action.ui);
3123
- }
3124
- return __spreadValues(__spreadValues({}, ui), action.ui(ui));
3125
- }
3126
- return ui;
3127
- };
3128
-
3129
- // reducer/actions.tsx
3130
- init_react_import();
3131
-
3132
- // reducer/index.ts
3133
- var storeInterceptor = (reducer, record, onAction) => {
3134
- return (state, action) => {
3135
- const newAppState = reducer(state, action);
3136
- const isValidType = ![
3137
- "registerZone",
3138
- "unregisterZone",
3139
- "setData",
3140
- "setUi",
3141
- "set"
3142
- ].includes(action.type);
3143
- if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
3144
- if (record) record(newAppState);
3145
- }
3146
- onAction == null ? void 0 : onAction(action, newAppState, state);
3147
- return newAppState;
3148
- };
3149
- };
3150
- var setAction = (state, action) => {
3151
- if (typeof action.state === "object") {
3152
- return __spreadValues(__spreadValues({}, state), action.state);
3153
- }
3154
- return __spreadValues(__spreadValues({}, state), action.state(state));
3155
- };
3156
- function createReducer({
3157
- config,
3158
- record,
3159
- onAction
3160
- }) {
3161
- return storeInterceptor(
3162
- (state, action) => {
3163
- const data = reduceData(state.data, action, config);
3164
- const ui = reduceUi(state.ui, action);
3165
- if (action.type === "set") {
3166
- return setAction(state, action);
3167
- }
3168
- return { data, ui };
3169
- },
3170
- record,
3171
- onAction
3172
- );
3173
- }
3174
-
3175
- // lib/flush-zones.ts
3176
- init_react_import();
3177
- var flushZones = (appState) => {
3178
- const containsZones = typeof appState.data.zones !== "undefined";
3179
- if (containsZones) {
3180
- Object.keys(appState.data.zones || {}).forEach((zone) => {
3181
- addToZoneCache(zone, appState.data.zones[zone]);
3182
- });
3183
- return __spreadProps(__spreadValues({}, appState), {
3184
- data: __spreadProps(__spreadValues({}, appState.data), {
3185
- zones: {}
3186
- })
3187
- });
3188
- }
3189
- return appState;
3190
- };
3191
-
3192
- // lib/use-resolved-data.ts
3193
- init_react_import();
3194
- import { useCallback as useCallback5, useEffect as useEffect11, useState as useState13 } from "react";
3195
-
3196
- // lib/resolve-component-data.ts
3197
- init_react_import();
3198
- var cache2 = { lastChange: {} };
3199
- var resolveAllComponentData = (content, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
3200
- return yield Promise.all(
3201
- content.map((item) => __async(void 0, null, function* () {
3202
- return yield resolveComponentData(
3203
- item,
3204
- config,
3205
- onResolveStart,
3206
- onResolveEnd
3207
- );
3208
- }))
3209
- );
3210
- });
3211
- var resolveComponentData = (item, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
3212
- const configForItem = config.components[item.type];
3213
- if (configForItem.resolveData) {
3214
- const { item: oldItem = {}, resolved = {} } = cache2.lastChange[item.props.id] || {};
3215
- if (item && item === oldItem) {
3216
- return resolved;
3217
- }
3218
- const changed = getChanged(item, oldItem);
3219
- if (onResolveStart) {
3220
- onResolveStart(item);
3221
- }
3222
- const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, { changed, lastData: oldItem });
3223
- const { readOnly: existingReadOnly = {} } = item || {};
3224
- const newReadOnly = __spreadValues(__spreadValues({}, existingReadOnly), readOnly);
3225
- const resolvedItem = __spreadProps(__spreadValues({}, item), {
3226
- props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
3227
- });
3228
- if (Object.keys(newReadOnly).length) {
3229
- resolvedItem.readOnly = newReadOnly;
3230
- }
3231
- cache2.lastChange[item.props.id] = {
3232
- item,
3233
- resolved: resolvedItem
3234
- };
3235
- if (onResolveEnd) {
3236
- onResolveEnd(resolvedItem);
3237
- }
3238
- return resolvedItem;
3239
- }
3240
- return item;
3241
- });
3242
-
3243
- // lib/apply-dynamic-props.ts
3244
- init_react_import();
3245
- var applyDynamicProps = (data, dynamicProps, rootData) => {
3246
- return __spreadProps(__spreadValues({}, data), {
3247
- root: __spreadValues(__spreadValues({}, data.root), rootData ? rootData : {}),
3248
- content: data.content.map((item) => {
3249
- return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
3250
- }),
3251
- zones: Object.keys(data.zones || {}).reduce((acc, zoneKey) => {
3252
- return __spreadProps(__spreadValues({}, acc), {
3253
- [zoneKey]: data.zones[zoneKey].map((item) => {
3254
- return dynamicProps[item.props.id] ? __spreadValues(__spreadValues({}, item), dynamicProps[item.props.id]) : item;
3255
- })
3256
- });
3257
- }, {})
3258
- });
3434
+ if (action.type === "setData") {
3435
+ if (typeof action.data === "object") {
3436
+ return __spreadValues(__spreadValues({}, data), action.data);
3437
+ }
3438
+ return __spreadValues(__spreadValues({}, data), action.data(data));
3439
+ }
3440
+ return data;
3441
+ }
3442
+
3443
+ // reducer/state.ts
3444
+ init_react_import();
3445
+ var reduceUi = (ui, action) => {
3446
+ if (action.type === "setUi") {
3447
+ if (typeof action.ui === "object") {
3448
+ return __spreadValues(__spreadValues({}, ui), action.ui);
3449
+ }
3450
+ return __spreadValues(__spreadValues({}, ui), action.ui(ui));
3451
+ }
3452
+ return ui;
3259
3453
  };
3260
3454
 
3261
- // lib/resolve-root-data.ts
3455
+ // reducer/actions.tsx
3262
3456
  init_react_import();
3263
- var cache3 = {};
3264
- function resolveRootData(data, config) {
3265
- return __async(this, null, function* () {
3266
- var _a, _b, _c, _d, _e;
3267
- if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
3268
- if (((_b = cache3.lastChange) == null ? void 0 : _b.original) === data.root) {
3269
- return cache3.lastChange.resolved;
3270
- }
3271
- const changed = getChanged(data.root, (_c = cache3.lastChange) == null ? void 0 : _c.original);
3272
- const rootWithProps = data.root;
3273
- const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
3274
- changed,
3275
- lastData: ((_d = cache3.lastChange) == null ? void 0 : _d.original) || {}
3276
- });
3277
- cache3.lastChange = {
3278
- original: data.root,
3279
- resolved: resolvedRoot
3280
- };
3281
- return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
3282
- props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
3283
- });
3457
+
3458
+ // reducer/index.ts
3459
+ function storeInterceptor(reducer, record, onAction) {
3460
+ return (state, action) => {
3461
+ const newAppState = reducer(state, action);
3462
+ const isValidType = ![
3463
+ "registerZone",
3464
+ "unregisterZone",
3465
+ "setData",
3466
+ "setUi",
3467
+ "set"
3468
+ ].includes(action.type);
3469
+ if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
3470
+ if (record) record(newAppState);
3284
3471
  }
3285
- return data.root;
3286
- });
3472
+ onAction == null ? void 0 : onAction(action, newAppState, state);
3473
+ return newAppState;
3474
+ };
3287
3475
  }
3288
-
3289
- // lib/use-resolved-data.ts
3290
- var useResolvedData = (appState, config, dispatch) => {
3291
- const [{ resolverKey, newAppState }, setResolverState] = useState13({
3292
- resolverKey: 0,
3293
- newAppState: appState
3294
- });
3295
- const [componentState, setComponentState] = useState13({});
3296
- const deferredSetStates = {};
3297
- const setComponentLoading = useCallback5(
3298
- (id, loading, defer2 = 0) => {
3299
- if (deferredSetStates[id]) {
3300
- clearTimeout(deferredSetStates[id]);
3301
- delete deferredSetStates[id];
3476
+ var setAction = (state, action) => {
3477
+ if (typeof action.state === "object") {
3478
+ return __spreadValues(__spreadValues({}, state), action.state);
3479
+ }
3480
+ return __spreadValues(__spreadValues({}, state), action.state(state));
3481
+ };
3482
+ function createReducer({
3483
+ config,
3484
+ record,
3485
+ onAction
3486
+ }) {
3487
+ return storeInterceptor(
3488
+ (state, action) => {
3489
+ const data = reduceData(state.data, action, config);
3490
+ const ui = reduceUi(state.ui, action);
3491
+ if (action.type === "set") {
3492
+ return setAction(state, action);
3302
3493
  }
3303
- deferredSetStates[id] = setTimeout(() => {
3304
- setComponentState((prev) => __spreadProps(__spreadValues({}, prev), {
3305
- [id]: __spreadProps(__spreadValues({}, prev[id]), { loading })
3306
- }));
3307
- delete deferredSetStates[id];
3308
- }, defer2);
3494
+ return { data, ui };
3309
3495
  },
3310
- []
3496
+ record,
3497
+ onAction
3311
3498
  );
3312
- const runResolvers = () => __async(void 0, null, function* () {
3313
- const newData = newAppState.data;
3314
- const flatContent = Object.keys(newData.zones || {}).reduce((acc, zone) => [...acc, ...newData.zones[zone]], newData.content).filter((item) => {
3315
- var _a;
3316
- return !!((_a = config.components[item.type]) == null ? void 0 : _a.resolveData);
3499
+ }
3500
+
3501
+ // lib/flush-zones.ts
3502
+ init_react_import();
3503
+ var flushZones = (appState) => {
3504
+ const containsZones = typeof appState.data.zones !== "undefined";
3505
+ if (containsZones) {
3506
+ Object.keys(appState.data.zones || {}).forEach((zone) => {
3507
+ addToZoneCache(zone, appState.data.zones[zone]);
3317
3508
  });
3318
- const applyIfChange = (dynamicDataMap, dynamicRoot) => {
3319
- const processed = applyDynamicProps(
3320
- appState.data,
3321
- dynamicDataMap,
3322
- dynamicRoot
3323
- );
3324
- const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
3325
- const containsChanges = JSON.stringify(appState) !== JSON.stringify(processedAppState);
3326
- if (containsChanges) {
3327
- dispatch({
3328
- type: "set",
3329
- state: (prev) => __spreadProps(__spreadValues({}, prev), {
3330
- data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
3331
- ui: resolverKey > 0 ? __spreadValues(__spreadValues({}, prev.ui), newAppState.ui) : prev.ui
3332
- }),
3333
- recordHistory: resolverKey > 0
3334
- });
3335
- }
3336
- };
3337
- const promises = [];
3338
- promises.push(
3339
- (() => __async(void 0, null, function* () {
3340
- setComponentLoading("puck-root", true, 50);
3341
- const dynamicRoot = yield resolveRootData(newData, config);
3342
- applyIfChange({}, dynamicRoot);
3343
- setComponentLoading("puck-root", false);
3344
- }))()
3345
- );
3346
- flatContent.forEach((item) => {
3347
- promises.push(
3348
- (() => __async(void 0, null, function* () {
3349
- const dynamicData = yield resolveComponentData(
3350
- item,
3351
- config,
3352
- (item2) => {
3353
- setComponentLoading(item2.props.id, true, 50);
3354
- },
3355
- (item2) => {
3356
- deferredSetStates[item2.props.id];
3357
- setComponentLoading(item2.props.id, false);
3358
- }
3359
- );
3360
- const dynamicDataMap = { [item.props.id]: dynamicData };
3361
- applyIfChange(dynamicDataMap);
3362
- }))()
3363
- );
3509
+ return __spreadProps(__spreadValues({}, appState), {
3510
+ data: __spreadProps(__spreadValues({}, appState.data), {
3511
+ zones: {}
3512
+ })
3364
3513
  });
3365
- yield Promise.all(promises);
3366
- });
3367
- useEffect11(() => {
3368
- runResolvers();
3369
- }, [resolverKey]);
3370
- const resolveData = useCallback5((newAppState2 = appState) => {
3371
- setResolverState((curr) => ({
3372
- resolverKey: curr.resolverKey + 1,
3373
- newAppState: newAppState2
3374
- }));
3375
- }, []);
3376
- return {
3377
- resolveData,
3378
- componentState
3379
- };
3514
+ }
3515
+ return appState;
3380
3516
  };
3381
3517
 
3382
3518
  // components/MenuBar/index.tsx
@@ -3389,15 +3525,14 @@ var styles_module_default14 = { "MenuBar": "_MenuBar_8pf8c_1", "MenuBar--menuOpe
3389
3525
  // components/MenuBar/index.tsx
3390
3526
  import { Fragment as Fragment12, jsx as jsx27, jsxs as jsxs14 } from "react/jsx-runtime";
3391
3527
  var getClassName20 = get_class_name_factory_default("MenuBar", styles_module_default14);
3392
- var MenuBar = ({
3528
+ function MenuBar({
3393
3529
  appState,
3394
- data = { content: [], root: {} },
3395
3530
  dispatch,
3396
3531
  menuOpen = false,
3397
3532
  onPublish,
3398
3533
  renderHeaderActions,
3399
3534
  setMenuOpen
3400
- }) => {
3535
+ }) {
3401
3536
  const {
3402
3537
  history: { back, forward, historyStore }
3403
3538
  } = useAppContext();
@@ -3428,7 +3563,7 @@ var MenuBar = ({
3428
3563
  ] })
3429
3564
  }
3430
3565
  );
3431
- };
3566
+ }
3432
3567
 
3433
3568
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/styles.module.css#css-module
3434
3569
  init_react_import();
@@ -3442,7 +3577,7 @@ init_react_import();
3442
3577
  var styles_module_default16 = { "PuckFields": "_PuckFields_jp3lw_1", "PuckFields--isLoading": "_PuckFields--isLoading_jp3lw_6", "PuckFields-loadingOverlay": "_PuckFields-loadingOverlay_jp3lw_10", "PuckFields-loadingOverlayInner": "_PuckFields-loadingOverlayInner_jp3lw_25" };
3443
3578
 
3444
3579
  // components/Puck/components/Fields/index.tsx
3445
- import { useCallback as useCallback6, useEffect as useEffect12, useMemo as useMemo6, useState as useState14 } from "react";
3580
+ import { useCallback as useCallback7, useEffect as useEffect13, useMemo as useMemo6, useState as useState15 } from "react";
3446
3581
  import { Fragment as Fragment13, jsx as jsx28, jsxs as jsxs15 } from "react/jsx-runtime";
3447
3582
  var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
3448
3583
  var defaultPageFields = {
@@ -3461,15 +3596,15 @@ var useResolvedFields = () => {
3461
3596
  const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
3462
3597
  const defaultFields = selectedItem ? componentConfig == null ? void 0 : componentConfig.fields : rootFields;
3463
3598
  const rootProps = data.root.props || data.root;
3464
- const [lastSelectedData, setLastSelectedData] = useState14({});
3465
- const [resolvedFields, setResolvedFields] = useState14(defaultFields || {});
3466
- const [fieldsLoading, setFieldsLoading] = useState14(false);
3599
+ const [lastSelectedData, setLastSelectedData] = useState15({});
3600
+ const [resolvedFields, setResolvedFields] = useState15(defaultFields || {});
3601
+ const [fieldsLoading, setFieldsLoading] = useState15(false);
3467
3602
  const defaultResolveFields = (_componentData, _params) => defaultFields;
3468
3603
  const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
3469
- const resolveFields = useCallback6(
3604
+ const resolveFields = useCallback7(
3470
3605
  (..._0) => __async(void 0, [..._0], function* (fields = {}) {
3471
3606
  var _a2, _b, _c;
3472
- const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : {};
3607
+ const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
3473
3608
  const changed = getChanged(componentData, lastData);
3474
3609
  setLastSelectedData(componentData);
3475
3610
  if (selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields)) {
@@ -3502,13 +3637,13 @@ var useResolvedFields = () => {
3502
3637
  }),
3503
3638
  [data, config, componentData, selectedItem, resolvedFields, state]
3504
3639
  );
3505
- useEffect12(() => {
3640
+ useEffect13(() => {
3506
3641
  setFieldsLoading(true);
3507
3642
  resolveFields(defaultFields).then((fields) => {
3508
3643
  setResolvedFields(fields || {});
3509
3644
  setFieldsLoading(false);
3510
3645
  });
3511
- }, [data, defaultFields]);
3646
+ }, [data, defaultFields, state.ui.itemSelector]);
3512
3647
  return [resolvedFields, fieldsLoading];
3513
3648
  };
3514
3649
  var Fields = () => {
@@ -3520,13 +3655,13 @@ var Fields = () => {
3520
3655
  config,
3521
3656
  resolveData,
3522
3657
  componentState,
3523
- overrides,
3524
- globalPermissions
3658
+ overrides
3525
3659
  } = useAppContext();
3526
3660
  const { data, ui } = state;
3527
3661
  const { itemSelector } = ui;
3528
3662
  const [fields, fieldsResolving] = useResolvedFields();
3529
- const componentResolving = selectedItem ? (_a = componentState[selectedItem == null ? void 0 : selectedItem.props.id]) == null ? void 0 : _a.loading : (_b = componentState["puck-root"]) == null ? void 0 : _b.loading;
3663
+ const { getPermissions } = useAppContext();
3664
+ const componentResolving = selectedItem ? ((_a = componentState[selectedItem == null ? void 0 : selectedItem.props.id]) == null ? void 0 : _a.loadingCount) > 0 : ((_b = componentState["puck-root"]) == null ? void 0 : _b.loadingCount) > 0;
3530
3665
  const isLoading = fieldsResolving || componentResolving;
3531
3666
  const rootProps = data.root.props || data.root;
3532
3667
  const Wrapper = useMemo6(() => overrides.fields || DefaultFields, [overrides]);
@@ -3606,10 +3741,7 @@ var Fields = () => {
3606
3741
  if (selectedItem && itemSelector) {
3607
3742
  const { readOnly = {} } = selectedItem;
3608
3743
  const { edit } = getPermissions({
3609
- selectedItem,
3610
- config,
3611
- globalPermissions: globalPermissions || {},
3612
- appState: state
3744
+ item: selectedItem
3613
3745
  });
3614
3746
  return /* @__PURE__ */ jsx28(
3615
3747
  AutoFieldPrivate,
@@ -3625,13 +3757,16 @@ var Fields = () => {
3625
3757
  );
3626
3758
  } else {
3627
3759
  const readOnly = data.root.readOnly || {};
3760
+ const { edit } = getPermissions({
3761
+ root: true
3762
+ });
3628
3763
  return /* @__PURE__ */ jsx28(
3629
3764
  AutoFieldPrivate,
3630
3765
  {
3631
3766
  field,
3632
3767
  name: fieldName,
3633
3768
  id: `root_${fieldName}`,
3634
- readOnly: readOnly[fieldName],
3769
+ readOnly: !edit || readOnly[fieldName],
3635
3770
  value: rootProps[fieldName],
3636
3771
  onChange
3637
3772
  },
@@ -3650,7 +3785,7 @@ init_react_import();
3650
3785
 
3651
3786
  // lib/use-component-list.tsx
3652
3787
  init_react_import();
3653
- import { useEffect as useEffect13, useState as useState15 } from "react";
3788
+ import { useEffect as useEffect14, useState as useState16 } from "react";
3654
3789
 
3655
3790
  // components/ComponentList/index.tsx
3656
3791
  init_react_import();
@@ -3667,12 +3802,9 @@ var ComponentListItem = ({
3667
3802
  label,
3668
3803
  index
3669
3804
  }) => {
3670
- const { overrides, config, globalPermissions, state } = useAppContext();
3805
+ const { overrides, getPermissions } = useAppContext();
3671
3806
  const canInsert = getPermissions({
3672
- type: name,
3673
- config,
3674
- globalPermissions: globalPermissions || {},
3675
- appState: state
3807
+ type: name
3676
3808
  }).insert;
3677
3809
  return /* @__PURE__ */ jsx29(
3678
3810
  Drawer.Item,
@@ -3696,6 +3828,7 @@ var ComponentList = ({
3696
3828
  title && /* @__PURE__ */ jsxs16(
3697
3829
  "button",
3698
3830
  {
3831
+ type: "button",
3699
3832
  className: getClassName22("title"),
3700
3833
  onClick: () => setUi({
3701
3834
  componentList: __spreadProps(__spreadValues({}, state.ui.componentList), {
@@ -3730,8 +3863,8 @@ ComponentList.Item = ComponentListItem;
3730
3863
  // lib/use-component-list.tsx
3731
3864
  import { jsx as jsx30 } from "react/jsx-runtime";
3732
3865
  var useComponentList = (config, ui) => {
3733
- const [componentList, setComponentList] = useState15();
3734
- useEffect13(() => {
3866
+ const [componentList, setComponentList] = useState16();
3867
+ useEffect14(() => {
3735
3868
  var _a, _b, _c;
3736
3869
  if (Object.keys(ui.componentList).length > 0) {
3737
3870
  const matchedComponents = [];
@@ -3811,16 +3944,16 @@ var Components = () => {
3811
3944
 
3812
3945
  // components/Puck/components/Preview/index.tsx
3813
3946
  init_react_import();
3814
- import { useCallback as useCallback7, useMemo as useMemo8 } from "react";
3947
+ import { useCallback as useCallback8, useMemo as useMemo8 } from "react";
3815
3948
 
3816
3949
  // components/AutoFrame/index.tsx
3817
3950
  init_react_import();
3818
3951
  import {
3819
3952
  createContext as createContext4,
3820
3953
  useContext as useContext5,
3821
- useEffect as useEffect14,
3822
- useRef,
3823
- useState as useState16
3954
+ useEffect as useEffect15,
3955
+ useRef as useRef2,
3956
+ useState as useState17
3824
3957
  } from "react";
3825
3958
  import hash from "object-hash";
3826
3959
  import { createPortal as createPortal2 } from "react-dom";
@@ -3867,7 +4000,7 @@ var CopyHostStyles = ({
3867
4000
  onStylesLoaded = () => null
3868
4001
  }) => {
3869
4002
  const { document: doc, window: win } = useFrame();
3870
- useEffect14(() => {
4003
+ useEffect15(() => {
3871
4004
  if (!win || !doc) {
3872
4005
  return () => {
3873
4006
  };
@@ -4042,11 +4175,11 @@ function AutoFrame(_a) {
4042
4175
  "id",
4043
4176
  "onStylesLoaded"
4044
4177
  ]);
4045
- const [loaded, setLoaded] = useState16(false);
4046
- const [ctx, setCtx] = useState16({});
4047
- const ref = useRef(null);
4048
- const [mountTarget, setMountTarget] = useState16();
4049
- useEffect14(() => {
4178
+ const [loaded, setLoaded] = useState17(false);
4179
+ const [ctx, setCtx] = useState17({});
4180
+ const ref = useRef2(null);
4181
+ const [mountTarget, setMountTarget] = useState17();
4182
+ useEffect15(() => {
4050
4183
  var _a2;
4051
4184
  if (ref.current) {
4052
4185
  setCtx({
@@ -4082,7 +4215,7 @@ import { Fragment as Fragment15, jsx as jsx33 } from "react/jsx-runtime";
4082
4215
  var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
4083
4216
  var Preview = ({ id = "puck-preview" }) => {
4084
4217
  const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
4085
- const Page = useCallback7(
4218
+ const Page = useCallback8(
4086
4219
  (pageProps) => {
4087
4220
  var _a, _b;
4088
4221
  return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
@@ -4246,6 +4379,7 @@ var LayerTree = ({
4246
4379
  /* @__PURE__ */ jsx34("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ jsxs17(
4247
4380
  "button",
4248
4381
  {
4382
+ type: "button",
4249
4383
  className: getClassNameLayer("clickable"),
4250
4384
  onClick: () => {
4251
4385
  if (isSelected) {
@@ -4312,13 +4446,13 @@ var LayerTree = ({
4312
4446
  };
4313
4447
 
4314
4448
  // components/Puck/components/Outline/index.tsx
4315
- import { useCallback as useCallback8, useMemo as useMemo9 } from "react";
4449
+ import { useCallback as useCallback9, useMemo as useMemo9 } from "react";
4316
4450
  import { Fragment as Fragment17, jsx as jsx35, jsxs as jsxs18 } from "react/jsx-runtime";
4317
4451
  var Outline = () => {
4318
4452
  const { dispatch, state, overrides, config } = useAppContext();
4319
4453
  const { data, ui } = state;
4320
4454
  const { itemSelector } = ui;
4321
- const setItemSelector = useCallback8(
4455
+ const setItemSelector = useCallback9(
4322
4456
  (newItemSelector) => {
4323
4457
  dispatch({
4324
4458
  type: "setUi",
@@ -4373,14 +4507,14 @@ function usePuckHistory({
4373
4507
  if (historyStore.hasPast) {
4374
4508
  dispatch({
4375
4509
  type: "set",
4376
- state: ((_a = historyStore.prevHistory) == null ? void 0 : _a.data) || initialAppState
4510
+ state: ((_a = historyStore.prevHistory) == null ? void 0 : _a.state) || initialAppState
4377
4511
  });
4378
4512
  historyStore.back();
4379
4513
  }
4380
4514
  };
4381
4515
  const forward = () => {
4382
4516
  if (historyStore.nextHistory) {
4383
- dispatch({ type: "set", state: historyStore.nextHistory.data });
4517
+ dispatch({ type: "set", state: historyStore.nextHistory.state });
4384
4518
  historyStore.forward();
4385
4519
  }
4386
4520
  };
@@ -4388,7 +4522,7 @@ function usePuckHistory({
4388
4522
  var _a;
4389
4523
  dispatch({
4390
4524
  type: "set",
4391
- state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.data) || initialAppState
4525
+ state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.state) || initialAppState
4392
4526
  });
4393
4527
  historyStore.setHistories(histories);
4394
4528
  };
@@ -4397,7 +4531,7 @@ function usePuckHistory({
4397
4531
  if (historyStore.histories.length > index) {
4398
4532
  dispatch({
4399
4533
  type: "set",
4400
- state: ((_a = historyStore.histories[index]) == null ? void 0 : _a.data) || initialAppState
4534
+ state: ((_a = historyStore.histories[index]) == null ? void 0 : _a.state) || initialAppState
4401
4535
  });
4402
4536
  historyStore.setHistoryIndex(index);
4403
4537
  }
@@ -4416,19 +4550,19 @@ function usePuckHistory({
4416
4550
 
4417
4551
  // lib/use-history-store.ts
4418
4552
  init_react_import();
4419
- import { useState as useState17 } from "react";
4553
+ import { useState as useState18 } from "react";
4420
4554
  import { useDebouncedCallback as useDebouncedCallback2 } from "use-debounce";
4421
- var EMPTY_HISTORY_INDEX = -1;
4555
+ var EMPTY_HISTORY_INDEX = 0;
4422
4556
  function useHistoryStore(initialHistory) {
4423
4557
  var _a, _b;
4424
- const [histories, setHistories] = useState17(
4558
+ const [histories, setHistories] = useState18(
4425
4559
  (_a = initialHistory == null ? void 0 : initialHistory.histories) != null ? _a : []
4426
4560
  );
4427
4561
  const updateHistories = (histories2) => {
4428
4562
  setHistories(histories2);
4429
4563
  setIndex(histories2.length - 1);
4430
4564
  };
4431
- const [index, setIndex] = useState17(
4565
+ const [index, setIndex] = useState18(
4432
4566
  (_b = initialHistory == null ? void 0 : initialHistory.index) != null ? _b : EMPTY_HISTORY_INDEX
4433
4567
  );
4434
4568
  const hasPast = index > EMPTY_HISTORY_INDEX;
@@ -4436,9 +4570,9 @@ function useHistoryStore(initialHistory) {
4436
4570
  const currentHistory = histories[index];
4437
4571
  const nextHistory = hasFuture ? histories[index + 1] : null;
4438
4572
  const prevHistory = hasPast ? histories[index - 1] : null;
4439
- const record = useDebouncedCallback2((data) => {
4573
+ const record = useDebouncedCallback2((state) => {
4440
4574
  const history = {
4441
- data,
4575
+ state,
4442
4576
  id: generateId("history")
4443
4577
  };
4444
4578
  updateHistories([...histories.slice(0, index + 1), history]);
@@ -4589,16 +4723,16 @@ var getBox = function getBox2(el) {
4589
4723
 
4590
4724
  // components/Puck/components/Canvas/index.tsx
4591
4725
  import {
4592
- useCallback as useCallback9,
4593
- useEffect as useEffect16,
4726
+ useCallback as useCallback10,
4727
+ useEffect as useEffect17,
4594
4728
  useMemo as useMemo11,
4595
- useRef as useRef2,
4596
- useState as useState19
4729
+ useRef as useRef3,
4730
+ useState as useState20
4597
4731
  } from "react";
4598
4732
 
4599
4733
  // components/ViewportControls/index.tsx
4600
4734
  init_react_import();
4601
- import { useEffect as useEffect15, useMemo as useMemo10, useState as useState18 } from "react";
4735
+ import { useEffect as useEffect16, useMemo as useMemo10, useState as useState19 } from "react";
4602
4736
 
4603
4737
  // css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
4604
4738
  init_react_import();
@@ -4621,8 +4755,8 @@ var ViewportButton = ({
4621
4755
  onClick
4622
4756
  }) => {
4623
4757
  const { state } = useAppContext();
4624
- const [isActive, setIsActive] = useState18(false);
4625
- useEffect15(() => {
4758
+ const [isActive, setIsActive] = useState19(false);
4759
+ useEffect16(() => {
4626
4760
  setIsActive(width === state.ui.viewports.current.width);
4627
4761
  }, [width, state.ui.viewports.current.width]);
4628
4762
  return /* @__PURE__ */ jsx36("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ jsx36(
@@ -4741,7 +4875,7 @@ var ViewportControls = ({
4741
4875
 
4742
4876
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Canvas/styles.module.css#css-module
4743
4877
  init_react_import();
4744
- var styles_module_default21 = { "PuckCanvas": "_PuckCanvas_6zd4y_1", "PuckCanvas-controls": "_PuckCanvas-controls_6zd4y_16", "PuckCanvas-inner": "_PuckCanvas-inner_6zd4y_21", "PuckCanvas-root": "_PuckCanvas-root_6zd4y_32", "PuckCanvas--ready": "_PuckCanvas--ready_6zd4y_56" };
4878
+ var styles_module_default21 = { "PuckCanvas": "_PuckCanvas_esbg1_1", "PuckCanvas-controls": "_PuckCanvas-controls_esbg1_16", "PuckCanvas-inner": "_PuckCanvas-inner_esbg1_21", "PuckCanvas-root": "_PuckCanvas-root_esbg1_32", "PuckCanvas--ready": "_PuckCanvas--ready_esbg1_56", "PuckCanvas-loader": "_PuckCanvas-loader_esbg1_60", "PuckCanvas--showLoader": "_PuckCanvas--showLoader_esbg1_70" };
4745
4879
 
4746
4880
  // lib/get-zoom-config.ts
4747
4881
  init_react_import();
@@ -4781,8 +4915,8 @@ var Canvas = () => {
4781
4915
  const { status, iframe } = useAppContext();
4782
4916
  const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
4783
4917
  const { ui } = state;
4784
- const frameRef = useRef2(null);
4785
- const [showTransition, setShowTransition] = useState19(false);
4918
+ const frameRef = useRef3(null);
4919
+ const [showTransition, setShowTransition] = useState20(false);
4786
4920
  const defaultRender = useMemo11(() => {
4787
4921
  const PuckDefault = ({ children }) => /* @__PURE__ */ jsx37(Fragment18, { children });
4788
4922
  return PuckDefault;
@@ -4791,7 +4925,7 @@ var Canvas = () => {
4791
4925
  () => overrides.preview || defaultRender,
4792
4926
  [overrides]
4793
4927
  );
4794
- const getFrameDimensions = useCallback9(() => {
4928
+ const getFrameDimensions = useCallback10(() => {
4795
4929
  if (frameRef.current) {
4796
4930
  const frame = frameRef.current;
4797
4931
  const box = getBox(frame);
@@ -4799,7 +4933,7 @@ var Canvas = () => {
4799
4933
  }
4800
4934
  return { width: 0, height: 0 };
4801
4935
  }, [frameRef]);
4802
- const resetAutoZoom = useCallback9(
4936
+ const resetAutoZoom = useCallback10(
4803
4937
  (ui2 = state.ui) => {
4804
4938
  if (frameRef.current) {
4805
4939
  setZoomConfig(
@@ -4809,11 +4943,11 @@ var Canvas = () => {
4809
4943
  },
4810
4944
  [frameRef, zoomConfig, state.ui]
4811
4945
  );
4812
- useEffect16(() => {
4946
+ useEffect17(() => {
4813
4947
  setShowTransition(false);
4814
4948
  resetAutoZoom();
4815
4949
  }, [frameRef, ui.leftSideBarVisible, ui.rightSideBarVisible]);
4816
- useEffect16(() => {
4950
+ useEffect17(() => {
4817
4951
  const { height: frameHeight } = getFrameDimensions();
4818
4952
  if (ui.viewports.current.height === "auto") {
4819
4953
  setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
@@ -4821,7 +4955,13 @@ var Canvas = () => {
4821
4955
  }));
4822
4956
  }
4823
4957
  }, [zoomConfig.zoom]);
4824
- useEffect16(() => {
4958
+ useEffect17(() => {
4959
+ if (ZOOM_ON_CHANGE) {
4960
+ setShowTransition(true);
4961
+ resetAutoZoom(ui);
4962
+ }
4963
+ }, [ui.viewports.current.width]);
4964
+ useEffect17(() => {
4825
4965
  const observer = new ResizeObserver(() => {
4826
4966
  setShowTransition(false);
4827
4967
  resetAutoZoom();
@@ -4833,11 +4973,18 @@ var Canvas = () => {
4833
4973
  observer.disconnect();
4834
4974
  };
4835
4975
  }, []);
4976
+ const [showLoader, setShowLoader] = useState20(false);
4977
+ useEffect17(() => {
4978
+ setTimeout(() => {
4979
+ setShowLoader(true);
4980
+ }, 500);
4981
+ }, []);
4836
4982
  return /* @__PURE__ */ jsxs20(
4837
4983
  "div",
4838
4984
  {
4839
4985
  className: getClassName26({
4840
- ready: status === "READY" || !iframe.enabled
4986
+ ready: status === "READY" || !iframe.enabled || !iframe.waitForStyles,
4987
+ showLoader
4841
4988
  }),
4842
4989
  onClick: () => dispatch({
4843
4990
  type: "setUi",
@@ -4870,21 +5017,24 @@ var Canvas = () => {
4870
5017
  }
4871
5018
  }
4872
5019
  ) }),
4873
- /* @__PURE__ */ jsx37("div", { className: getClassName26("inner"), ref: frameRef, children: /* @__PURE__ */ jsx37(
4874
- "div",
4875
- {
4876
- className: getClassName26("root"),
4877
- style: {
4878
- width: iframe.enabled ? ui.viewports.current.width : "100%",
4879
- height: zoomConfig.rootHeight,
4880
- transform: iframe.enabled ? `scale(${zoomConfig.zoom})` : void 0,
4881
- transition: showTransition ? "width 150ms ease-out, height 150ms ease-out, transform 150ms ease-out" : "",
4882
- overflow: iframe.enabled ? void 0 : "auto"
4883
- },
4884
- suppressHydrationWarning: true,
4885
- children: /* @__PURE__ */ jsx37(CustomPreview, { children: /* @__PURE__ */ jsx37(Preview, {}) })
4886
- }
4887
- ) })
5020
+ /* @__PURE__ */ jsxs20("div", { className: getClassName26("inner"), ref: frameRef, children: [
5021
+ /* @__PURE__ */ jsx37(
5022
+ "div",
5023
+ {
5024
+ className: getClassName26("root"),
5025
+ style: {
5026
+ width: iframe.enabled ? ui.viewports.current.width : "100%",
5027
+ height: zoomConfig.rootHeight,
5028
+ transform: iframe.enabled ? `scale(${zoomConfig.zoom})` : void 0,
5029
+ transition: showTransition ? "width 150ms ease-out, height 150ms ease-out, transform 150ms ease-out" : "",
5030
+ overflow: iframe.enabled ? void 0 : "auto"
5031
+ },
5032
+ suppressHydrationWarning: true,
5033
+ children: /* @__PURE__ */ jsx37(CustomPreview, { children: /* @__PURE__ */ jsx37(Preview, {}) })
5034
+ }
5035
+ ),
5036
+ /* @__PURE__ */ jsx37("div", { className: getClassName26("loader"), children: /* @__PURE__ */ jsx37(Loader, { size: 24 }) })
5037
+ ] })
4888
5038
  ]
4889
5039
  }
4890
5040
  );
@@ -4909,7 +5059,10 @@ var insertComponent = (componentType, zone, index, {
4909
5059
  const insertedData = insertAction(state.data, insertActionData, config);
4910
5060
  dispatch(__spreadProps(__spreadValues({}, insertActionData), {
4911
5061
  // Dispatch insert rather set, as user's may rely on this via onAction
4912
- recordHistory: false
5062
+ // We must always record history here so the insert is added to user history
5063
+ // If the user has defined a resolveData method, they will end up with 2 history
5064
+ // entries on insert - one for the initial insert, and one when the data resolves
5065
+ recordHistory: true
4913
5066
  }));
4914
5067
  const itemSelector = {
4915
5068
  index,
@@ -4975,7 +5128,7 @@ var getLayoutClassName = get_class_name_factory_default("PuckLayout", styles_mod
4975
5128
  function Puck({
4976
5129
  children,
4977
5130
  config,
4978
- data: initialData = { content: [], root: {} },
5131
+ data: initialData,
4979
5132
  ui: initialUi,
4980
5133
  onChange,
4981
5134
  onPublish,
@@ -4988,18 +5141,16 @@ function Puck({
4988
5141
  headerTitle,
4989
5142
  headerPath,
4990
5143
  viewports = defaultViewports,
4991
- iframe = {
4992
- enabled: true
4993
- },
5144
+ iframe: _iframe,
4994
5145
  dnd,
4995
- initialHistory
5146
+ initialHistory: _initialHistory
4996
5147
  }) {
4997
5148
  var _a;
4998
- const historyStore = useHistoryStore(initialHistory);
4999
- const [reducer] = useState20(
5000
- () => createReducer({ config, record: historyStore.record, onAction })
5001
- );
5002
- const [initialAppState] = useState20(() => {
5149
+ const iframe = __spreadValues({
5150
+ enabled: true,
5151
+ waitForStyles: true
5152
+ }, _iframe);
5153
+ const [generatedAppState] = useState21(() => {
5003
5154
  var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
5004
5155
  const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
5005
5156
  let clientUiState = {};
@@ -5017,14 +5168,14 @@ function Puck({
5017
5168
  })).sort((a, b) => a.diff > b.diff ? 1 : -1);
5018
5169
  const closestViewport = viewportDifferences[0].key;
5019
5170
  if (iframe.enabled) {
5020
- clientUiState = {
5171
+ clientUiState = __spreadProps(__spreadValues({}, clientUiState), {
5021
5172
  viewports: __spreadProps(__spreadValues({}, initial.viewports), {
5022
5173
  current: __spreadProps(__spreadValues({}, initial.viewports.current), {
5023
5174
  height: ((_b = (_a2 = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _a2.current) == null ? void 0 : _b.height) || ((_c = viewports[closestViewport]) == null ? void 0 : _c.height) || "auto",
5024
5175
  width: ((_e = (_d = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _d.current) == null ? void 0 : _e.width) || ((_f = viewports[closestViewport]) == null ? void 0 : _f.width)
5025
5176
  })
5026
5177
  })
5027
- };
5178
+ });
5028
5179
  }
5029
5180
  }
5030
5181
  if (Object.keys((initialData == null ? void 0 : initialData.root) || {}).length > 0 && !((_g = initialData == null ? void 0 : initialData.root) == null ? void 0 : _g.props)) {
@@ -5057,20 +5208,36 @@ function Puck({
5057
5208
  })
5058
5209
  });
5059
5210
  });
5211
+ const { appendData = true } = _initialHistory || {};
5212
+ const histories = [
5213
+ ...(_initialHistory == null ? void 0 : _initialHistory.histories) || [],
5214
+ ...appendData ? [{ state: generatedAppState }] : []
5215
+ ].map((history2) => __spreadProps(__spreadValues({}, history2), {
5216
+ // Inject default data to enable partial history injections
5217
+ state: __spreadValues(__spreadValues({}, generatedAppState), history2.state)
5218
+ }));
5219
+ const initialHistoryIndex = (_initialHistory == null ? void 0 : _initialHistory.index) || histories.length - 1;
5220
+ const initialAppState = histories[initialHistoryIndex].state;
5221
+ const historyStore = useHistoryStore({
5222
+ histories,
5223
+ index: initialHistoryIndex
5224
+ });
5225
+ const [reducer] = useState21(
5226
+ () => createReducer({
5227
+ config,
5228
+ record: historyStore.record,
5229
+ onAction
5230
+ })
5231
+ );
5060
5232
  const [appState, dispatch] = useReducer(
5061
5233
  reducer,
5062
5234
  flushZones(initialAppState)
5063
5235
  );
5064
5236
  const { data, ui } = appState;
5065
5237
  const history = usePuckHistory({ dispatch, initialAppState, historyStore });
5066
- const { resolveData, componentState } = useResolvedData(
5067
- appState,
5068
- config,
5069
- dispatch
5070
- );
5071
- const [menuOpen, setMenuOpen] = useState20(false);
5238
+ const [menuOpen, setMenuOpen] = useState21(false);
5072
5239
  const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
5073
- const setItemSelector = useCallback10(
5240
+ const setItemSelector = useCallback11(
5074
5241
  (newItemSelector) => {
5075
5242
  if (newItemSelector === itemSelector) return;
5076
5243
  dispatch({
@@ -5082,13 +5249,13 @@ function Puck({
5082
5249
  [itemSelector]
5083
5250
  );
5084
5251
  const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
5085
- useEffect17(() => {
5252
+ useEffect18(() => {
5086
5253
  if (onChange) onChange(data);
5087
5254
  }, [data]);
5088
5255
  const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
5089
- const [draggedItem, setDraggedItem] = useState20();
5256
+ const [draggedItem, setDraggedItem] = useState21();
5090
5257
  const rootProps = data.root.props || data.root;
5091
- const toggleSidebars = useCallback10(
5258
+ const toggleSidebars = useCallback11(
5092
5259
  (sidebar) => {
5093
5260
  const widerViewport = window.matchMedia("(min-width: 638px)").matches;
5094
5261
  const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
@@ -5102,7 +5269,7 @@ function Puck({
5102
5269
  },
5103
5270
  [dispatch, leftSideBarVisible, rightSideBarVisible]
5104
5271
  );
5105
- useEffect17(() => {
5272
+ useEffect18(() => {
5106
5273
  if (!window.matchMedia("(min-width: 638px)").matches) {
5107
5274
  dispatch({
5108
5275
  type: "setUi",
@@ -5168,8 +5335,8 @@ function Puck({
5168
5335
  () => loadedOverrides.headerActions || defaultHeaderActionsRender,
5169
5336
  [loadedOverrides]
5170
5337
  );
5171
- const [mounted, setMounted] = useState20(false);
5172
- useEffect17(() => {
5338
+ const [mounted, setMounted] = useState21(false);
5339
+ useEffect18(() => {
5173
5340
  setMounted(true);
5174
5341
  }, []);
5175
5342
  const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
@@ -5182,8 +5349,6 @@ function Puck({
5182
5349
  state: appState,
5183
5350
  dispatch,
5184
5351
  config,
5185
- componentState,
5186
- resolveData,
5187
5352
  plugins: plugins || [],
5188
5353
  overrides: loadedOverrides,
5189
5354
  history,
@@ -5195,9 +5360,11 @@ function Puck({
5195
5360
  duplicate: true,
5196
5361
  insert: true,
5197
5362
  edit: true
5198
- }, permissions)
5363
+ }, permissions),
5364
+ getPermissions: () => ({}),
5365
+ refreshPermissions: () => null
5199
5366
  },
5200
- children: /* @__PURE__ */ jsx38(
5367
+ children: /* @__PURE__ */ jsx38(appContext.Consumer, { children: ({ resolveData }) => /* @__PURE__ */ jsx38(
5201
5368
  DragDropContext,
5202
5369
  {
5203
5370
  autoScrollerOptions: { disabled: dnd == null ? void 0 : dnd.disableAutoScroll },
@@ -5287,90 +5454,115 @@ function Puck({
5287
5454
  }
5288
5455
  ) }) }),
5289
5456
  children: /* @__PURE__ */ jsx38("header", { className: getLayoutClassName("header"), children: /* @__PURE__ */ jsxs21("div", { className: getLayoutClassName("headerInner"), children: [
5290
- /* @__PURE__ */ jsxs21("div", { className: getLayoutClassName("headerToggle"), children: [
5291
- /* @__PURE__ */ jsx38(
5292
- "div",
5293
- {
5294
- className: getLayoutClassName(
5295
- "leftSideBarToggle"
5296
- ),
5297
- children: /* @__PURE__ */ jsx38(
5298
- IconButton,
5457
+ /* @__PURE__ */ jsxs21(
5458
+ "div",
5459
+ {
5460
+ className: getLayoutClassName("headerToggle"),
5461
+ children: [
5462
+ /* @__PURE__ */ jsx38(
5463
+ "div",
5299
5464
  {
5300
- onClick: () => {
5301
- toggleSidebars("left");
5302
- },
5303
- title: "Toggle left sidebar",
5304
- children: /* @__PURE__ */ jsx38(PanelLeft, { focusable: "false" })
5465
+ className: getLayoutClassName(
5466
+ "leftSideBarToggle"
5467
+ ),
5468
+ children: /* @__PURE__ */ jsx38(
5469
+ IconButton,
5470
+ {
5471
+ onClick: () => {
5472
+ toggleSidebars("left");
5473
+ },
5474
+ title: "Toggle left sidebar",
5475
+ children: /* @__PURE__ */ jsx38(PanelLeft, { focusable: "false" })
5476
+ }
5477
+ )
5305
5478
  }
5306
- )
5307
- }
5308
- ),
5309
- /* @__PURE__ */ jsx38(
5310
- "div",
5311
- {
5312
- className: getLayoutClassName(
5313
- "rightSideBarToggle"
5314
5479
  ),
5315
- children: /* @__PURE__ */ jsx38(
5316
- IconButton,
5480
+ /* @__PURE__ */ jsx38(
5481
+ "div",
5317
5482
  {
5318
- onClick: () => {
5319
- toggleSidebars("right");
5320
- },
5321
- title: "Toggle right sidebar",
5322
- children: /* @__PURE__ */ jsx38(PanelRight, { focusable: "false" })
5483
+ className: getLayoutClassName(
5484
+ "rightSideBarToggle"
5485
+ ),
5486
+ children: /* @__PURE__ */ jsx38(
5487
+ IconButton,
5488
+ {
5489
+ onClick: () => {
5490
+ toggleSidebars("right");
5491
+ },
5492
+ title: "Toggle right sidebar",
5493
+ children: /* @__PURE__ */ jsx38(PanelRight, { focusable: "false" })
5494
+ }
5495
+ )
5323
5496
  }
5324
5497
  )
5325
- }
5326
- )
5327
- ] }),
5328
- /* @__PURE__ */ jsx38("div", { className: getLayoutClassName("headerTitle"), children: /* @__PURE__ */ jsxs21(Heading, { rank: "2", size: "xs", children: [
5329
- headerTitle || rootProps.title || "Page",
5330
- headerPath && /* @__PURE__ */ jsxs21(Fragment19, { children: [
5331
- " ",
5332
- /* @__PURE__ */ jsx38(
5333
- "code",
5334
- {
5335
- className: getLayoutClassName("headerPath"),
5336
- children: headerPath
5337
- }
5338
- )
5339
- ] })
5340
- ] }) }),
5341
- /* @__PURE__ */ jsxs21("div", { className: getLayoutClassName("headerTools"), children: [
5342
- /* @__PURE__ */ jsx38("div", { className: getLayoutClassName("menuButton"), children: /* @__PURE__ */ jsx38(
5343
- IconButton,
5344
- {
5345
- onClick: () => {
5346
- return setMenuOpen(!menuOpen);
5347
- },
5348
- title: "Toggle menu bar",
5349
- children: menuOpen ? /* @__PURE__ */ jsx38(ChevronUp, { focusable: "false" }) : /* @__PURE__ */ jsx38(ChevronDown, { focusable: "false" })
5350
- }
5351
- ) }),
5352
- /* @__PURE__ */ jsx38(
5353
- MenuBar,
5354
- {
5355
- appState,
5356
- data,
5357
- dispatch,
5358
- onPublish,
5359
- menuOpen,
5360
- renderHeaderActions: () => /* @__PURE__ */ jsx38(CustomHeaderActions, { children: /* @__PURE__ */ jsx38(
5361
- Button,
5498
+ ]
5499
+ }
5500
+ ),
5501
+ /* @__PURE__ */ jsx38(
5502
+ "div",
5503
+ {
5504
+ className: getLayoutClassName("headerTitle"),
5505
+ children: /* @__PURE__ */ jsxs21(Heading, { rank: "2", size: "xs", children: [
5506
+ headerTitle || rootProps.title || "Page",
5507
+ headerPath && /* @__PURE__ */ jsxs21(Fragment19, { children: [
5508
+ " ",
5509
+ /* @__PURE__ */ jsx38(
5510
+ "code",
5511
+ {
5512
+ className: getLayoutClassName(
5513
+ "headerPath"
5514
+ ),
5515
+ children: headerPath
5516
+ }
5517
+ )
5518
+ ] })
5519
+ ] })
5520
+ }
5521
+ ),
5522
+ /* @__PURE__ */ jsxs21(
5523
+ "div",
5524
+ {
5525
+ className: getLayoutClassName("headerTools"),
5526
+ children: [
5527
+ /* @__PURE__ */ jsx38(
5528
+ "div",
5362
5529
  {
5363
- onClick: () => {
5364
- onPublish && onPublish(data);
5365
- },
5366
- icon: /* @__PURE__ */ jsx38(Globe, { size: "14px" }),
5367
- children: "Publish"
5530
+ className: getLayoutClassName("menuButton"),
5531
+ children: /* @__PURE__ */ jsx38(
5532
+ IconButton,
5533
+ {
5534
+ onClick: () => {
5535
+ return setMenuOpen(!menuOpen);
5536
+ },
5537
+ title: "Toggle menu bar",
5538
+ children: menuOpen ? /* @__PURE__ */ jsx38(ChevronUp, { focusable: "false" }) : /* @__PURE__ */ jsx38(ChevronDown, { focusable: "false" })
5539
+ }
5540
+ )
5368
5541
  }
5369
- ) }),
5370
- setMenuOpen
5371
- }
5372
- )
5373
- ] })
5542
+ ),
5543
+ /* @__PURE__ */ jsx38(
5544
+ MenuBar,
5545
+ {
5546
+ appState,
5547
+ dispatch,
5548
+ onPublish,
5549
+ menuOpen,
5550
+ renderHeaderActions: () => /* @__PURE__ */ jsx38(CustomHeaderActions, { children: /* @__PURE__ */ jsx38(
5551
+ Button,
5552
+ {
5553
+ onClick: () => {
5554
+ onPublish && onPublish(data);
5555
+ },
5556
+ icon: /* @__PURE__ */ jsx38(Globe, { size: "14px" }),
5557
+ children: "Publish"
5558
+ }
5559
+ ) }),
5560
+ setMenuOpen
5561
+ }
5562
+ )
5563
+ ]
5564
+ }
5565
+ )
5374
5566
  ] }) })
5375
5567
  }
5376
5568
  ),
@@ -5395,7 +5587,7 @@ function Puck({
5395
5587
  }
5396
5588
  )
5397
5589
  }
5398
- )
5590
+ ) })
5399
5591
  }
5400
5592
  ),
5401
5593
  /* @__PURE__ */ jsx38("div", { id: "puck-portal-root", className: getClassName27("portal") })
@@ -5544,24 +5736,15 @@ var usePuck = () => {
5544
5736
  history,
5545
5737
  dispatch,
5546
5738
  selectedItem: currentItem,
5547
- globalPermissions
5739
+ getPermissions,
5740
+ refreshPermissions
5548
5741
  } = useAppContext();
5549
5742
  return {
5550
5743
  appState,
5551
5744
  config,
5552
5745
  dispatch,
5553
- getPermissions: ({
5554
- item,
5555
- type
5556
- } = {}) => {
5557
- return getPermissions({
5558
- selectedItem: item || currentItem,
5559
- type,
5560
- globalPermissions: globalPermissions || {},
5561
- config,
5562
- appState
5563
- });
5564
- },
5746
+ getPermissions,
5747
+ refreshPermissions,
5565
5748
  history: {
5566
5749
  back: history.back,
5567
5750
  forward: history.forward,
@@ -5587,11 +5770,13 @@ export {
5587
5770
  DropZoneProvider,
5588
5771
  FieldLabel,
5589
5772
  FieldLabelInternal2 as FieldLabelInternal,
5773
+ Group,
5590
5774
  IconButton,
5591
5775
  Puck,
5592
5776
  Render,
5593
5777
  dropZoneContext,
5594
5778
  migrate,
5779
+ overrideKeys,
5595
5780
  resolveAllData,
5596
5781
  transformProps,
5597
5782
  usePuck