@measured/puck 0.16.0-canary.a1d52cb → 0.16.0-canary.a3518ca

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,46 +65,73 @@ 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
 
80
112
  // lib/get-class-name-factory.ts
81
113
  init_react_import();
82
114
  var import_classnames = __toESM(require_classnames());
83
- var getClassNameFactory = (rootClass, styles, { baseClass = "" } = {}) => (options = {}) => {
84
- let descendant = false;
85
- let modifiers = false;
115
+ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
86
116
  if (typeof options === "string") {
87
- descendant = options;
88
- } else if (typeof options === "object") {
89
- modifiers = options;
90
- }
91
- if (descendant) {
117
+ const descendant = options;
92
118
  const style = styles[`${rootClass}-${descendant}`];
93
119
  if (style) {
94
- return baseClass + styles[`${rootClass}-${descendant}`] || "";
120
+ return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
95
121
  }
96
122
  return "";
97
- } else if (modifiers) {
123
+ } else if (typeof options === "object") {
124
+ const modifiers = options;
98
125
  const prefixedModifiers = {};
99
126
  for (let modifier in modifiers) {
100
127
  prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
101
128
  }
102
129
  const c = styles[rootClass];
103
- return baseClass + (0, import_classnames.default)(__spreadValues({
130
+ return config.baseClass + (0, import_classnames.default)(__spreadValues({
104
131
  [c]: !!c
105
132
  }, prefixedModifiers));
106
133
  } else {
107
- return baseClass + styles[rootClass] || "";
134
+ return config.baseClass + styles[rootClass] || "";
108
135
  }
109
136
  };
110
137
  var get_class_name_factory_default = getClassNameFactory;
@@ -127,7 +154,16 @@ var Action = ({
127
154
  children,
128
155
  label,
129
156
  onClick
130
- }) => /* @__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
+ );
131
167
  ActionBar.Action = Action;
132
168
 
133
169
  // components/AutoField/index.tsx
@@ -562,14 +598,14 @@ import {
562
598
 
563
599
  // lib/get-item.ts
564
600
  init_react_import();
565
- var getItem = (selector, data, dynamicProps = {}) => {
601
+ function getItem(selector, data, dynamicProps = {}) {
566
602
  if (!selector.zone || selector.zone === rootDroppableId) {
567
603
  const item2 = data.content[selector.index];
568
604
  return (item2 == null ? void 0 : item2.props) ? __spreadProps(__spreadValues({}, item2), { props: dynamicProps[item2.props.id] || item2.props }) : void 0;
569
605
  }
570
606
  const item = setupZone(data, selector.zone).zones[selector.zone][selector.index];
571
607
  return (item == null ? void 0 : item.props) ? __spreadProps(__spreadValues({}, item), { props: dynamicProps[item.props.id] || item.props }) : void 0;
572
- };
608
+ }
573
609
 
574
610
  // components/ViewportControls/default-viewports.ts
575
611
  init_react_import();
@@ -583,7 +619,7 @@ var defaultViewports = [
583
619
  import { UAParser } from "ua-parser-js";
584
620
  import { jsx as jsx4 } from "react/jsx-runtime";
585
621
  var defaultAppState = {
586
- data: { content: [], root: { props: {} } },
622
+ data: { content: [], root: {} },
587
623
  ui: {
588
624
  leftSideBarVisible: true,
589
625
  rightSideBarVisible: true,
@@ -1322,6 +1358,7 @@ var ExternalInput = ({
1322
1358
  value && /* @__PURE__ */ jsx14(
1323
1359
  "button",
1324
1360
  {
1361
+ type: "button",
1325
1362
  className: getClassName10("detachButton"),
1326
1363
  onClick: () => {
1327
1364
  onChange(null);
@@ -1378,7 +1415,7 @@ var ExternalInput = ({
1378
1415
  }
1379
1416
  ) })
1380
1417
  ] })
1381
- ] }) : /* @__PURE__ */ jsx14(Heading, { rank: 2, size: "xs", children: field.placeholder || "Select data" }) }),
1418
+ ] }) : /* @__PURE__ */ jsx14(Heading, { rank: "2", size: "xs", children: field.placeholder || "Select data" }) }),
1382
1419
  /* @__PURE__ */ jsxs7("div", { className: getClassNameModal("grid"), children: [
1383
1420
  hasFilterFields && /* @__PURE__ */ jsx14("div", { className: getClassNameModal("filters"), children: hasFilterFields && Object.keys(filterFields).map((fieldName) => {
1384
1421
  const filterField = filterFields[fieldName];
@@ -2811,6 +2848,7 @@ var SidebarSection = ({
2811
2848
  /* @__PURE__ */ jsx26(
2812
2849
  "button",
2813
2850
  {
2851
+ type: "button",
2814
2852
  className: getClassName19("breadcrumbLabel"),
2815
2853
  onClick: () => setUi({ itemSelector: breadcrumb.selector }),
2816
2854
  children: breadcrumb.label
@@ -2818,7 +2856,7 @@ var SidebarSection = ({
2818
2856
  ),
2819
2857
  /* @__PURE__ */ jsx26(ChevronRight, { size: 16 })
2820
2858
  ] }, i)) : null,
2821
- /* @__PURE__ */ jsx26("div", { className: getClassName19("heading"), children: /* @__PURE__ */ jsx26(Heading, { rank: 2, size: "xs", children: title }) })
2859
+ /* @__PURE__ */ jsx26("div", { className: getClassName19("heading"), children: /* @__PURE__ */ jsx26(Heading, { rank: "2", size: "xs", children: title }) })
2822
2860
  ] }) }),
2823
2861
  /* @__PURE__ */ jsx26("div", { className: getClassName19("content"), children }),
2824
2862
  isLoading && /* @__PURE__ */ jsx26("div", { className: getClassName19("loadingOverlay"), children: /* @__PURE__ */ jsx26(Loader, { size: 32 }) })
@@ -2851,7 +2889,7 @@ var remove = (list, index) => {
2851
2889
 
2852
2890
  // lib/reduce-related-zones.ts
2853
2891
  init_react_import();
2854
- var reduceRelatedZones = (item, data, fn) => {
2892
+ function reduceRelatedZones(item, data, fn) {
2855
2893
  return __spreadProps(__spreadValues({}, data), {
2856
2894
  zones: Object.keys(data.zones || {}).reduce(
2857
2895
  (acc, key) => {
@@ -2865,28 +2903,34 @@ var reduceRelatedZones = (item, data, fn) => {
2865
2903
  {}
2866
2904
  )
2867
2905
  });
2868
- };
2906
+ }
2869
2907
  var findRelatedByZoneId = (zoneId, data) => {
2870
2908
  const [zoneParentId] = getZoneId(zoneId);
2871
- return (data.zones[zoneId] || []).reduce((acc, zoneItem) => {
2872
- const related = findRelatedByItem(zoneItem, data);
2873
- if (zoneItem.props.id === zoneParentId) {
2874
- return __spreadProps(__spreadValues(__spreadValues({}, acc), related), { [zoneId]: zoneItem });
2875
- }
2876
- return __spreadValues(__spreadValues({}, acc), related);
2877
- }, {});
2909
+ return (data.zones[zoneId] || []).reduce(
2910
+ (acc, zoneItem) => {
2911
+ const related = findRelatedByItem(zoneItem, data);
2912
+ if (zoneItem.props.id === zoneParentId) {
2913
+ return __spreadProps(__spreadValues(__spreadValues({}, acc), related), { [zoneId]: zoneItem });
2914
+ }
2915
+ return __spreadValues(__spreadValues({}, acc), related);
2916
+ },
2917
+ {}
2918
+ );
2878
2919
  };
2879
2920
  var findRelatedByItem = (item, data) => {
2880
- return Object.keys(data.zones || {}).reduce((acc, zoneId) => {
2881
- const [zoneParentId] = getZoneId(zoneId);
2882
- if (item.props.id === zoneParentId) {
2883
- const related = findRelatedByZoneId(zoneId, data);
2884
- return __spreadProps(__spreadValues(__spreadValues({}, acc), related), {
2885
- [zoneId]: data.zones[zoneId]
2886
- });
2887
- }
2888
- return acc;
2889
- }, {});
2921
+ return Object.keys(data.zones || {}).reduce(
2922
+ (acc, zoneId) => {
2923
+ const [zoneParentId] = getZoneId(zoneId);
2924
+ if (item.props.id === zoneParentId) {
2925
+ const related = findRelatedByZoneId(zoneId, data);
2926
+ return __spreadProps(__spreadValues(__spreadValues({}, acc), related), {
2927
+ [zoneId]: data.zones[zoneId]
2928
+ });
2929
+ }
2930
+ return acc;
2931
+ },
2932
+ {}
2933
+ );
2890
2934
  };
2891
2935
  var removeRelatedZones = (item, data) => {
2892
2936
  const newData = __spreadValues({}, data);
@@ -2896,7 +2940,7 @@ var removeRelatedZones = (item, data) => {
2896
2940
  });
2897
2941
  return newData;
2898
2942
  };
2899
- var duplicateRelatedZones = (item, data, newId) => {
2943
+ function duplicateRelatedZones(item, data, newId) {
2900
2944
  return reduceRelatedZones(item, data, (acc, key, zone) => {
2901
2945
  const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
2902
2946
  props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
@@ -2911,7 +2955,7 @@ var duplicateRelatedZones = (item, data, newId) => {
2911
2955
  [`${newId}:${zoneId}`]: dupedZone
2912
2956
  });
2913
2957
  });
2914
- };
2958
+ }
2915
2959
 
2916
2960
  // reducer/data.ts
2917
2961
  var zoneCache = {};
@@ -2935,7 +2979,7 @@ var replaceAction = (data, action) => {
2935
2979
  })
2936
2980
  });
2937
2981
  };
2938
- var insertAction = (data, action, config) => {
2982
+ function insertAction(data, action, config) {
2939
2983
  const emptyComponentData = {
2940
2984
  type: action.componentType,
2941
2985
  props: __spreadProps(__spreadValues({}, config.components[action.componentType].defaultProps || {}), {
@@ -2961,8 +3005,8 @@ var insertAction = (data, action, config) => {
2961
3005
  )
2962
3006
  })
2963
3007
  });
2964
- };
2965
- var reduceData = (data, action, config) => {
3008
+ }
3009
+ function reduceData(data, action, config) {
2966
3010
  if (action.type === "insert") {
2967
3011
  return insertAction(data, action, config);
2968
3012
  }
@@ -3111,7 +3155,7 @@ var reduceData = (data, action, config) => {
3111
3155
  return __spreadValues(__spreadValues({}, data), action.data(data));
3112
3156
  }
3113
3157
  return data;
3114
- };
3158
+ }
3115
3159
 
3116
3160
  // reducer/state.ts
3117
3161
  init_react_import();
@@ -3129,7 +3173,7 @@ var reduceUi = (ui, action) => {
3129
3173
  init_react_import();
3130
3174
 
3131
3175
  // reducer/index.ts
3132
- var storeInterceptor = (reducer, record, onAction) => {
3176
+ function storeInterceptor(reducer, record, onAction) {
3133
3177
  return (state, action) => {
3134
3178
  const newAppState = reducer(state, action);
3135
3179
  const isValidType = ![
@@ -3145,7 +3189,7 @@ var storeInterceptor = (reducer, record, onAction) => {
3145
3189
  onAction == null ? void 0 : onAction(action, newAppState, state);
3146
3190
  return newAppState;
3147
3191
  };
3148
- };
3192
+ }
3149
3193
  var setAction = (state, action) => {
3150
3194
  if (typeof action.state === "object") {
3151
3195
  return __spreadValues(__spreadValues({}, state), action.state);
@@ -3260,28 +3304,30 @@ var applyDynamicProps = (data, dynamicProps, rootData) => {
3260
3304
  // lib/resolve-root-data.ts
3261
3305
  init_react_import();
3262
3306
  var cache3 = {};
3263
- var resolveRootData = (data, config) => __async(void 0, null, function* () {
3264
- var _a, _b, _c, _d, _e;
3265
- if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
3266
- if (((_b = cache3.lastChange) == null ? void 0 : _b.original) === data.root) {
3267
- return cache3.lastChange.resolved;
3307
+ function resolveRootData(data, config) {
3308
+ return __async(this, null, function* () {
3309
+ var _a, _b, _c, _d, _e;
3310
+ if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
3311
+ if (((_b = cache3.lastChange) == null ? void 0 : _b.original) === data.root) {
3312
+ return cache3.lastChange.resolved;
3313
+ }
3314
+ const changed = getChanged(data.root, (_c = cache3.lastChange) == null ? void 0 : _c.original);
3315
+ const rootWithProps = data.root;
3316
+ const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
3317
+ changed,
3318
+ lastData: ((_d = cache3.lastChange) == null ? void 0 : _d.original) || {}
3319
+ });
3320
+ cache3.lastChange = {
3321
+ original: data.root,
3322
+ resolved: resolvedRoot
3323
+ };
3324
+ return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
3325
+ props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
3326
+ });
3268
3327
  }
3269
- const changed = getChanged(data.root, (_c = cache3.lastChange) == null ? void 0 : _c.original);
3270
- const rootWithProps = data.root;
3271
- const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
3272
- changed,
3273
- lastData: ((_d = cache3.lastChange) == null ? void 0 : _d.original) || {}
3274
- });
3275
- cache3.lastChange = {
3276
- original: data.root,
3277
- resolved: resolvedRoot
3278
- };
3279
- return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
3280
- props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
3281
- });
3282
- }
3283
- return data.root;
3284
- });
3328
+ return data.root;
3329
+ });
3330
+ }
3285
3331
 
3286
3332
  // lib/use-resolved-data.ts
3287
3333
  var useResolvedData = (appState, config, dispatch) => {
@@ -3386,15 +3432,14 @@ var styles_module_default14 = { "MenuBar": "_MenuBar_8pf8c_1", "MenuBar--menuOpe
3386
3432
  // components/MenuBar/index.tsx
3387
3433
  import { Fragment as Fragment12, jsx as jsx27, jsxs as jsxs14 } from "react/jsx-runtime";
3388
3434
  var getClassName20 = get_class_name_factory_default("MenuBar", styles_module_default14);
3389
- var MenuBar = ({
3435
+ function MenuBar({
3390
3436
  appState,
3391
- data = { content: [], root: {} },
3392
3437
  dispatch,
3393
3438
  menuOpen = false,
3394
3439
  onPublish,
3395
3440
  renderHeaderActions,
3396
3441
  setMenuOpen
3397
- }) => {
3442
+ }) {
3398
3443
  const {
3399
3444
  history: { back, forward, historyStore }
3400
3445
  } = useAppContext();
@@ -3425,7 +3470,7 @@ var MenuBar = ({
3425
3470
  ] })
3426
3471
  }
3427
3472
  );
3428
- };
3473
+ }
3429
3474
 
3430
3475
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/styles.module.css#css-module
3431
3476
  init_react_import();
@@ -3458,9 +3503,7 @@ var useResolvedFields = () => {
3458
3503
  const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
3459
3504
  const defaultFields = selectedItem ? componentConfig == null ? void 0 : componentConfig.fields : rootFields;
3460
3505
  const rootProps = data.root.props || data.root;
3461
- const [lastSelectedData, setLastSelectedData] = useState14(
3462
- {}
3463
- );
3506
+ const [lastSelectedData, setLastSelectedData] = useState14({});
3464
3507
  const [resolvedFields, setResolvedFields] = useState14(defaultFields || {});
3465
3508
  const [fieldsLoading, setFieldsLoading] = useState14(false);
3466
3509
  const defaultResolveFields = (_componentData, _params) => defaultFields;
@@ -3507,7 +3550,7 @@ var useResolvedFields = () => {
3507
3550
  setResolvedFields(fields || {});
3508
3551
  setFieldsLoading(false);
3509
3552
  });
3510
- }, [data, defaultFields]);
3553
+ }, [data, defaultFields, state.ui.itemSelector]);
3511
3554
  return [resolvedFields, fieldsLoading];
3512
3555
  };
3513
3556
  var Fields = () => {
@@ -3623,7 +3666,7 @@ var Fields = () => {
3623
3666
  `${selectedItem.props.id}_${fieldName}`
3624
3667
  );
3625
3668
  } else {
3626
- const { readOnly = {} } = data.root;
3669
+ const readOnly = data.root.readOnly || {};
3627
3670
  return /* @__PURE__ */ jsx28(
3628
3671
  AutoFieldPrivate,
3629
3672
  {
@@ -3695,6 +3738,7 @@ var ComponentList = ({
3695
3738
  title && /* @__PURE__ */ jsxs16(
3696
3739
  "button",
3697
3740
  {
3741
+ type: "button",
3698
3742
  className: getClassName22("title"),
3699
3743
  onClick: () => setUi({
3700
3744
  componentList: __spreadProps(__spreadValues({}, state.ui.componentList), {
@@ -4084,13 +4128,9 @@ var Preview = ({ id = "puck-preview" }) => {
4084
4128
  const Page = useCallback7(
4085
4129
  (pageProps) => {
4086
4130
  var _a, _b;
4087
- return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadProps(__spreadValues({
4131
+ return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
4088
4132
  id: "puck-root"
4089
- }, pageProps), {
4090
- editMode: true,
4091
- // DEPRECATED
4092
- puck: { renderDropZone: DropZone, isEditing: true }
4093
- })) : /* @__PURE__ */ jsx33(Fragment15, { children: pageProps.children });
4133
+ }, pageProps)) : /* @__PURE__ */ jsx33(Fragment15, { children: pageProps.children });
4094
4134
  },
4095
4135
  [config.root]
4096
4136
  );
@@ -4114,14 +4154,28 @@ var Preview = ({ id = "puck-preview" }) => {
4114
4154
  setStatus("READY");
4115
4155
  },
4116
4156
  children: /* @__PURE__ */ jsx33(autoFrameContext.Consumer, { children: ({ document: document2 }) => {
4117
- const inner = /* @__PURE__ */ jsx33(Page, __spreadProps(__spreadValues({ dispatch, state }, rootProps), { children: /* @__PURE__ */ jsx33(DropZone, { zone: rootDroppableId }) }));
4157
+ const inner = /* @__PURE__ */ jsx33(
4158
+ Page,
4159
+ __spreadProps(__spreadValues({}, rootProps), {
4160
+ puck: { renderDropZone: DropZone, isEditing: true },
4161
+ editMode: true,
4162
+ children: /* @__PURE__ */ jsx33(DropZone, { zone: rootDroppableId })
4163
+ })
4164
+ );
4118
4165
  if (Frame) {
4119
4166
  return /* @__PURE__ */ jsx33(Frame, { document: document2, children: inner });
4120
4167
  }
4121
4168
  return inner;
4122
4169
  } })
4123
4170
  }
4124
- ) : /* @__PURE__ */ jsx33("div", { id: "preview-frame", className: getClassName23("frame"), children: /* @__PURE__ */ jsx33(Page, __spreadProps(__spreadValues({ dispatch, state }, rootProps), { children: /* @__PURE__ */ jsx33(DropZone, { zone: rootDroppableId }) })) })
4171
+ ) : /* @__PURE__ */ jsx33("div", { id: "preview-frame", className: getClassName23("frame"), children: /* @__PURE__ */ jsx33(
4172
+ Page,
4173
+ __spreadProps(__spreadValues({}, rootProps), {
4174
+ puck: { renderDropZone: DropZone, isEditing: true },
4175
+ editMode: true,
4176
+ children: /* @__PURE__ */ jsx33(DropZone, { zone: rootDroppableId })
4177
+ })
4178
+ ) })
4125
4179
  }
4126
4180
  );
4127
4181
  };
@@ -4235,6 +4289,7 @@ var LayerTree = ({
4235
4289
  /* @__PURE__ */ jsx34("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ jsxs17(
4236
4290
  "button",
4237
4291
  {
4292
+ type: "button",
4238
4293
  className: getClassNameLayer("clickable"),
4239
4294
  onClick: () => {
4240
4295
  if (isSelected) {
@@ -4362,14 +4417,14 @@ function usePuckHistory({
4362
4417
  if (historyStore.hasPast) {
4363
4418
  dispatch({
4364
4419
  type: "set",
4365
- state: ((_a = historyStore.prevHistory) == null ? void 0 : _a.data) || initialAppState
4420
+ state: ((_a = historyStore.prevHistory) == null ? void 0 : _a.state) || initialAppState
4366
4421
  });
4367
4422
  historyStore.back();
4368
4423
  }
4369
4424
  };
4370
4425
  const forward = () => {
4371
4426
  if (historyStore.nextHistory) {
4372
- dispatch({ type: "set", state: historyStore.nextHistory.data });
4427
+ dispatch({ type: "set", state: historyStore.nextHistory.state });
4373
4428
  historyStore.forward();
4374
4429
  }
4375
4430
  };
@@ -4377,7 +4432,7 @@ function usePuckHistory({
4377
4432
  var _a;
4378
4433
  dispatch({
4379
4434
  type: "set",
4380
- state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.data) || initialAppState
4435
+ state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.state) || initialAppState
4381
4436
  });
4382
4437
  historyStore.setHistories(histories);
4383
4438
  };
@@ -4386,7 +4441,7 @@ function usePuckHistory({
4386
4441
  if (historyStore.histories.length > index) {
4387
4442
  dispatch({
4388
4443
  type: "set",
4389
- state: ((_a = historyStore.histories[index]) == null ? void 0 : _a.data) || initialAppState
4444
+ state: ((_a = historyStore.histories[index]) == null ? void 0 : _a.state) || initialAppState
4390
4445
  });
4391
4446
  historyStore.setHistoryIndex(index);
4392
4447
  }
@@ -4407,7 +4462,7 @@ function usePuckHistory({
4407
4462
  init_react_import();
4408
4463
  import { useState as useState17 } from "react";
4409
4464
  import { useDebouncedCallback as useDebouncedCallback2 } from "use-debounce";
4410
- var EMPTY_HISTORY_INDEX = -1;
4465
+ var EMPTY_HISTORY_INDEX = 0;
4411
4466
  function useHistoryStore(initialHistory) {
4412
4467
  var _a, _b;
4413
4468
  const [histories, setHistories] = useState17(
@@ -4425,9 +4480,9 @@ function useHistoryStore(initialHistory) {
4425
4480
  const currentHistory = histories[index];
4426
4481
  const nextHistory = hasFuture ? histories[index + 1] : null;
4427
4482
  const prevHistory = hasPast ? histories[index - 1] : null;
4428
- const record = useDebouncedCallback2((data) => {
4483
+ const record = useDebouncedCallback2((state) => {
4429
4484
  const history = {
4430
- data,
4485
+ state,
4431
4486
  id: generateId("history")
4432
4487
  };
4433
4488
  updateHistories([...histories.slice(0, index + 1), history]);
@@ -4730,7 +4785,7 @@ var ViewportControls = ({
4730
4785
 
4731
4786
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Canvas/styles.module.css#css-module
4732
4787
  init_react_import();
4733
- 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" };
4788
+ 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" };
4734
4789
 
4735
4790
  // lib/get-zoom-config.ts
4736
4791
  init_react_import();
@@ -4810,6 +4865,12 @@ var Canvas = () => {
4810
4865
  }));
4811
4866
  }
4812
4867
  }, [zoomConfig.zoom]);
4868
+ useEffect16(() => {
4869
+ if (ZOOM_ON_CHANGE) {
4870
+ setShowTransition(true);
4871
+ resetAutoZoom(ui);
4872
+ }
4873
+ }, [ui.viewports.current.width]);
4813
4874
  useEffect16(() => {
4814
4875
  const observer = new ResizeObserver(() => {
4815
4876
  setShowTransition(false);
@@ -4822,11 +4883,18 @@ var Canvas = () => {
4822
4883
  observer.disconnect();
4823
4884
  };
4824
4885
  }, []);
4886
+ const [showLoader, setShowLoader] = useState19(false);
4887
+ useEffect16(() => {
4888
+ setTimeout(() => {
4889
+ setShowLoader(true);
4890
+ }, 500);
4891
+ }, []);
4825
4892
  return /* @__PURE__ */ jsxs20(
4826
4893
  "div",
4827
4894
  {
4828
4895
  className: getClassName26({
4829
- ready: status === "READY" || !iframe.enabled
4896
+ ready: status === "READY" || !iframe.enabled || !iframe.waitForStyles,
4897
+ showLoader
4830
4898
  }),
4831
4899
  onClick: () => dispatch({
4832
4900
  type: "setUi",
@@ -4859,21 +4927,24 @@ var Canvas = () => {
4859
4927
  }
4860
4928
  }
4861
4929
  ) }),
4862
- /* @__PURE__ */ jsx37("div", { className: getClassName26("inner"), ref: frameRef, children: /* @__PURE__ */ jsx37(
4863
- "div",
4864
- {
4865
- className: getClassName26("root"),
4866
- style: {
4867
- width: iframe.enabled ? ui.viewports.current.width : "100%",
4868
- height: zoomConfig.rootHeight,
4869
- transform: iframe.enabled ? `scale(${zoomConfig.zoom})` : void 0,
4870
- transition: showTransition ? "width 150ms ease-out, height 150ms ease-out, transform 150ms ease-out" : "",
4871
- overflow: iframe.enabled ? void 0 : "auto"
4872
- },
4873
- suppressHydrationWarning: true,
4874
- children: /* @__PURE__ */ jsx37(CustomPreview, { children: /* @__PURE__ */ jsx37(Preview, {}) })
4875
- }
4876
- ) })
4930
+ /* @__PURE__ */ jsxs20("div", { className: getClassName26("inner"), ref: frameRef, children: [
4931
+ /* @__PURE__ */ jsx37(
4932
+ "div",
4933
+ {
4934
+ className: getClassName26("root"),
4935
+ style: {
4936
+ width: iframe.enabled ? ui.viewports.current.width : "100%",
4937
+ height: zoomConfig.rootHeight,
4938
+ transform: iframe.enabled ? `scale(${zoomConfig.zoom})` : void 0,
4939
+ transition: showTransition ? "width 150ms ease-out, height 150ms ease-out, transform 150ms ease-out" : "",
4940
+ overflow: iframe.enabled ? void 0 : "auto"
4941
+ },
4942
+ suppressHydrationWarning: true,
4943
+ children: /* @__PURE__ */ jsx37(CustomPreview, { children: /* @__PURE__ */ jsx37(Preview, {}) })
4944
+ }
4945
+ ),
4946
+ /* @__PURE__ */ jsx37("div", { className: getClassName26("loader"), children: /* @__PURE__ */ jsx37(Loader, { size: 24 }) })
4947
+ ] })
4877
4948
  ]
4878
4949
  }
4879
4950
  );
@@ -4898,7 +4969,10 @@ var insertComponent = (componentType, zone, index, {
4898
4969
  const insertedData = insertAction(state.data, insertActionData, config);
4899
4970
  dispatch(__spreadProps(__spreadValues({}, insertActionData), {
4900
4971
  // Dispatch insert rather set, as user's may rely on this via onAction
4901
- recordHistory: false
4972
+ // We must always record history here so the insert is added to user history
4973
+ // If the user has defined a resolveData method, they will end up with 2 history
4974
+ // entries on insert - one for the initial insert, and one when the data resolves
4975
+ recordHistory: true
4902
4976
  }));
4903
4977
  const itemSelector = {
4904
4978
  index,
@@ -4923,7 +4997,8 @@ var loadOverrides = ({
4923
4997
  }) => {
4924
4998
  const collected = __spreadValues({}, overrides);
4925
4999
  plugins == null ? void 0 : plugins.forEach((plugin) => {
4926
- Object.keys(plugin.overrides).forEach((overridesType) => {
5000
+ Object.keys(plugin.overrides).forEach((_overridesType) => {
5001
+ const overridesType = _overridesType;
4927
5002
  if (overridesType === "fieldTypes") {
4928
5003
  const fieldTypes = plugin.overrides.fieldTypes;
4929
5004
  Object.keys(fieldTypes).forEach((fieldType) => {
@@ -4963,7 +5038,7 @@ var getLayoutClassName = get_class_name_factory_default("PuckLayout", styles_mod
4963
5038
  function Puck({
4964
5039
  children,
4965
5040
  config,
4966
- data: initialData = { content: [], root: {} },
5041
+ data: initialData,
4967
5042
  ui: initialUi,
4968
5043
  onChange,
4969
5044
  onPublish,
@@ -4976,19 +5051,17 @@ function Puck({
4976
5051
  headerTitle,
4977
5052
  headerPath,
4978
5053
  viewports = defaultViewports,
4979
- iframe = {
4980
- enabled: true
4981
- },
5054
+ iframe: _iframe,
4982
5055
  dnd,
4983
- initialHistory
5056
+ initialHistory: _initialHistory
4984
5057
  }) {
4985
5058
  var _a;
4986
- const historyStore = useHistoryStore(initialHistory);
4987
- const [reducer] = useState20(
4988
- () => createReducer({ config, record: historyStore.record, onAction })
4989
- );
4990
- const [initialAppState] = useState20(() => {
4991
- var _a2, _b, _c, _d, _e, _f, _g;
5059
+ const iframe = __spreadValues({
5060
+ enabled: true,
5061
+ waitForStyles: true
5062
+ }, _iframe);
5063
+ const [generatedAppState] = useState20(() => {
5064
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
4992
5065
  const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
4993
5066
  let clientUiState = {};
4994
5067
  if (typeof window !== "undefined") {
@@ -5008,20 +5081,20 @@ function Puck({
5008
5081
  clientUiState = {
5009
5082
  viewports: __spreadProps(__spreadValues({}, initial.viewports), {
5010
5083
  current: __spreadProps(__spreadValues({}, initial.viewports.current), {
5011
- height: ((_b = (_a2 = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _a2.current) == null ? void 0 : _b.height) || viewports[closestViewport].height || "auto",
5012
- width: ((_d = (_c = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _c.current) == null ? void 0 : _d.width) || viewports[closestViewport].width
5084
+ 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",
5085
+ 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)
5013
5086
  })
5014
5087
  })
5015
5088
  };
5016
5089
  }
5017
5090
  }
5018
- if (Object.keys((initialData == null ? void 0 : initialData.root) || {}).length > 0 && !((_e = initialData == null ? void 0 : initialData.root) == null ? void 0 : _e.props)) {
5091
+ if (Object.keys((initialData == null ? void 0 : initialData.root) || {}).length > 0 && !((_g = initialData == null ? void 0 : initialData.root) == null ? void 0 : _g.props)) {
5019
5092
  console.error(
5020
5093
  "Warning: Defining props on `root` is deprecated. Please use `root.props`, or republish this page to migrate automatically."
5021
5094
  );
5022
5095
  }
5023
- const rootProps2 = ((_f = initialData == null ? void 0 : initialData.root) == null ? void 0 : _f.props) || (initialData == null ? void 0 : initialData.root) || {};
5024
- const defaultedRootProps = __spreadValues(__spreadValues({}, (_g = config.root) == null ? void 0 : _g.defaultProps), rootProps2);
5096
+ const rootProps2 = ((_h = initialData == null ? void 0 : initialData.root) == null ? void 0 : _h.props) || (initialData == null ? void 0 : initialData.root) || {};
5097
+ const defaultedRootProps = __spreadValues(__spreadValues({}, (_i = config.root) == null ? void 0 : _i.defaultProps), rootProps2);
5025
5098
  return __spreadProps(__spreadValues({}, defaultAppState), {
5026
5099
  data: __spreadProps(__spreadValues({}, initialData), {
5027
5100
  root: __spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: defaultedRootProps }),
@@ -5045,6 +5118,27 @@ function Puck({
5045
5118
  })
5046
5119
  });
5047
5120
  });
5121
+ const { appendData = true } = _initialHistory || {};
5122
+ const histories = [
5123
+ ...(_initialHistory == null ? void 0 : _initialHistory.histories) || [],
5124
+ ...appendData ? [{ state: generatedAppState }] : []
5125
+ ].map((history2) => __spreadProps(__spreadValues({}, history2), {
5126
+ // Inject default data to enable partial history injections
5127
+ state: __spreadValues(__spreadValues({}, generatedAppState), history2.state)
5128
+ }));
5129
+ const initialHistoryIndex = (_initialHistory == null ? void 0 : _initialHistory.index) || histories.length - 1;
5130
+ const initialAppState = histories[initialHistoryIndex].state;
5131
+ const historyStore = useHistoryStore({
5132
+ histories,
5133
+ index: initialHistoryIndex
5134
+ });
5135
+ const [reducer] = useState20(
5136
+ () => createReducer({
5137
+ config,
5138
+ record: historyStore.record,
5139
+ onAction
5140
+ })
5141
+ );
5048
5142
  const [appState, dispatch] = useReducer(
5049
5143
  reducer,
5050
5144
  flushZones(initialAppState)
@@ -5313,7 +5407,7 @@ function Puck({
5313
5407
  }
5314
5408
  )
5315
5409
  ] }),
5316
- /* @__PURE__ */ jsx38("div", { className: getLayoutClassName("headerTitle"), children: /* @__PURE__ */ jsxs21(Heading, { rank: 2, size: "xs", children: [
5410
+ /* @__PURE__ */ jsx38("div", { className: getLayoutClassName("headerTitle"), children: /* @__PURE__ */ jsxs21(Heading, { rank: "2", size: "xs", children: [
5317
5411
  headerTitle || rootProps.title || "Page",
5318
5412
  headerPath && /* @__PURE__ */ jsxs21(Fragment19, { children: [
5319
5413
  " ",
@@ -5341,7 +5435,6 @@ function Puck({
5341
5435
  MenuBar,
5342
5436
  {
5343
5437
  appState,
5344
- data,
5345
5438
  dispatch,
5346
5439
  onPublish,
5347
5440
  menuOpen,
@@ -5397,10 +5490,7 @@ Puck.Preview = Preview;
5397
5490
  // components/Render/index.tsx
5398
5491
  init_react_import();
5399
5492
  import { jsx as jsx39 } from "react/jsx-runtime";
5400
- function Render({
5401
- config,
5402
- data
5403
- }) {
5493
+ function Render({ config, data }) {
5404
5494
  var _a;
5405
5495
  const defaultedData = __spreadProps(__spreadValues({}, data), {
5406
5496
  root: data.root || {},
@@ -5580,6 +5670,7 @@ export {
5580
5670
  Render,
5581
5671
  dropZoneContext,
5582
5672
  migrate,
5673
+ overrideKeys,
5583
5674
  resolveAllData,
5584
5675
  transformProps,
5585
5676
  usePuck