@measured/puck 0.21.0-canary.cf074bc6 → 0.21.0-canary.dfecd012

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -153,9 +153,45 @@ var require_classnames = __commonJS({
153
153
  }
154
154
  });
155
155
 
156
+ // ../../node_modules/fast-deep-equal/index.js
157
+ var require_fast_deep_equal = __commonJS({
158
+ "../../node_modules/fast-deep-equal/index.js"(exports2, module2) {
159
+ "use strict";
160
+ init_react_import();
161
+ module2.exports = function equal(a, b) {
162
+ if (a === b) return true;
163
+ if (a && b && typeof a == "object" && typeof b == "object") {
164
+ if (a.constructor !== b.constructor) return false;
165
+ var length, i, keys;
166
+ if (Array.isArray(a)) {
167
+ length = a.length;
168
+ if (length != b.length) return false;
169
+ for (i = length; i-- !== 0; )
170
+ if (!equal(a[i], b[i])) return false;
171
+ return true;
172
+ }
173
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
174
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
175
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
176
+ keys = Object.keys(a);
177
+ length = keys.length;
178
+ if (length !== Object.keys(b).length) return false;
179
+ for (i = length; i-- !== 0; )
180
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
181
+ for (i = length; i-- !== 0; ) {
182
+ var key = keys[i];
183
+ if (!equal(a[key], b[key])) return false;
184
+ }
185
+ return true;
186
+ }
187
+ return a !== a && b !== b;
188
+ };
189
+ }
190
+ });
191
+
156
192
  // bundle/index.ts
157
- var bundle_exports = {};
158
- __export(bundle_exports, {
193
+ var index_exports = {};
194
+ __export(index_exports, {
159
195
  Action: () => Action,
160
196
  ActionBar: () => ActionBar,
161
197
  AutoField: () => AutoField,
@@ -180,7 +216,7 @@ __export(bundle_exports, {
180
216
  usePuck: () => usePuck,
181
217
  walkTree: () => walkTree
182
218
  });
183
- module.exports = __toCommonJS(bundle_exports);
219
+ module.exports = __toCommonJS(index_exports);
184
220
  init_react_import();
185
221
 
186
222
  // bundle/core.ts
@@ -1713,6 +1749,10 @@ var monitorHotkeys = (doc) => {
1713
1749
  useHotkeyStore.getState().reset();
1714
1750
  }
1715
1751
  };
1752
+ const onBlur = () => {
1753
+ useHotkeyStore.getState().reset();
1754
+ };
1755
+ window.addEventListener("blur", onBlur);
1716
1756
  doc.addEventListener("keydown", onKeyDown);
1717
1757
  doc.addEventListener("keyup", onKeyUp);
1718
1758
  doc.addEventListener("visibilitychange", onVisibilityChanged);
@@ -1720,6 +1760,7 @@ var monitorHotkeys = (doc) => {
1720
1760
  doc.removeEventListener("keydown", onKeyDown);
1721
1761
  doc.removeEventListener("keyup", onKeyUp);
1722
1762
  doc.removeEventListener("visibilitychange", onVisibilityChanged);
1763
+ window.removeEventListener("blur", onBlur);
1723
1764
  };
1724
1765
  };
1725
1766
  var useMonitorHotkeys = () => {
@@ -1922,23 +1963,23 @@ var flattenData = (state, config) => {
1922
1963
 
1923
1964
  // lib/get-changed.ts
1924
1965
  init_react_import();
1925
- var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
1966
+ var import_fast_equals = require("fast-equals");
1926
1967
  var getChanged = (newItem, oldItem) => {
1927
1968
  return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1928
1969
  const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1929
1970
  const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1930
1971
  return __spreadProps(__spreadValues({}, acc), {
1931
- [item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
1972
+ [item]: !(0, import_fast_equals.deepEqual)(oldItemProps[item], newItemProps[item])
1932
1973
  });
1933
1974
  }, {}) : {};
1934
1975
  };
1935
1976
 
1936
1977
  // store/slices/permissions.ts
1937
1978
  var createPermissionsSlice = (set, get) => {
1938
- const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1979
+ const resolvePermissions = (..._0) => __async(null, [..._0], function* (params = {}, force) {
1939
1980
  const { state, permissions, config } = get();
1940
1981
  const { cache: cache2, globalPermissions } = permissions;
1941
- const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1982
+ const resolveDataForItem = (item2, force2 = false) => __async(null, null, function* () {
1942
1983
  var _a, _b, _c;
1943
1984
  const { config: config2, state: appState, setComponentLoading } = get();
1944
1985
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
@@ -1993,13 +2034,13 @@ var createPermissionsSlice = (set, get) => {
1993
2034
  if (item) {
1994
2035
  yield resolveDataForItem(item, force);
1995
2036
  } else if (type) {
1996
- flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
2037
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(null, null, function* () {
1997
2038
  yield resolveDataForItem(item2, force);
1998
2039
  }));
1999
2040
  } else if (root) {
2000
2041
  resolveDataForRoot(force);
2001
2042
  } else {
2002
- flattenData(state, config).map((item2) => __async(void 0, null, function* () {
2043
+ flattenData(state, config).map((item2) => __async(null, null, function* () {
2003
2044
  yield resolveDataForItem(item2, force);
2004
2045
  }));
2005
2046
  }
@@ -2080,7 +2121,7 @@ var createFieldsSlice = (_set, _get) => {
2080
2121
  };
2081
2122
  var useRegisterFieldsSlice = (appStore, id) => {
2082
2123
  const resolveFields = (0, import_react7.useCallback)(
2083
- (reset) => __async(void 0, null, function* () {
2124
+ (reset) => __async(null, null, function* () {
2084
2125
  var _a, _b;
2085
2126
  const { fields, lastResolvedData } = appStore.getState().fields;
2086
2127
  const metadata = appStore.getState().metadata;
@@ -2149,16 +2190,16 @@ var useRegisterFieldsSlice = (appStore, id) => {
2149
2190
 
2150
2191
  // lib/resolve-component-data.ts
2151
2192
  init_react_import();
2152
- var import_fast_deep_equal2 = __toESM(require("fast-deep-equal"));
2193
+ var import_fast_equals2 = require("fast-equals");
2153
2194
  var cache = { lastChange: {} };
2154
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
2195
+ var resolveComponentData = (_0, _1, ..._2) => __async(null, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
2155
2196
  const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
2156
2197
  const resolvedItem = __spreadValues({}, item);
2157
2198
  const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
2158
2199
  const id = "id" in item.props ? item.props.id : "root";
2159
2200
  if (shouldRunResolver) {
2160
2201
  const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
2161
- if (trigger !== "force" && item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
2202
+ if (trigger !== "force" && item && (0, import_fast_equals2.deepEqual)(item, oldItem)) {
2162
2203
  return { node: resolved, didChange: false };
2163
2204
  }
2164
2205
  const changed = getChanged(item, oldItem);
@@ -2179,11 +2220,11 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
2179
2220
  let itemWithResolvedChildren = yield mapFields(
2180
2221
  resolvedItem,
2181
2222
  {
2182
- slot: (_02) => __async(void 0, [_02], function* ({ value }) {
2223
+ slot: (_02) => __async(null, [_02], function* ({ value }) {
2183
2224
  const content = value;
2184
2225
  return yield Promise.all(
2185
2226
  content.map(
2186
- (childItem) => __async(void 0, null, function* () {
2227
+ (childItem) => __async(null, null, function* () {
2187
2228
  return (yield resolveComponentData(
2188
2229
  childItem,
2189
2230
  config,
@@ -2208,7 +2249,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
2208
2249
  };
2209
2250
  return {
2210
2251
  node: itemWithResolvedChildren,
2211
- didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
2252
+ didChange: !(0, import_fast_equals2.deepEqual)(item, itemWithResolvedChildren)
2212
2253
  };
2213
2254
  });
2214
2255
 
@@ -2373,7 +2414,7 @@ var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
2373
2414
  const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
2374
2415
  return __spreadProps(__spreadValues({}, s), { state, selectedItem });
2375
2416
  }),
2376
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
2417
+ resolveComponentData: (componentData, trigger) => __async(null, null, function* () {
2377
2418
  const { config, metadata, setComponentLoading, permissions } = get();
2378
2419
  const timeouts = {};
2379
2420
  return yield resolveComponentData(
@@ -2384,7 +2425,7 @@ var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
2384
2425
  const id = "id" in item.props ? item.props.id : "root";
2385
2426
  timeouts[id] = setComponentLoading(id, true, 50);
2386
2427
  },
2387
- (item) => __async(void 0, null, function* () {
2428
+ (item) => __async(null, null, function* () {
2388
2429
  const id = "id" in item.props ? item.props.id : "root";
2389
2430
  if ("type" in item) {
2390
2431
  yield permissions.refreshPermissions({ item });
@@ -2396,7 +2437,7 @@ var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
2396
2437
  trigger
2397
2438
  );
2398
2439
  }),
2399
- resolveAndCommitData: () => __async(void 0, null, function* () {
2440
+ resolveAndCommitData: () => __async(null, null, function* () {
2400
2441
  const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
2401
2442
  walkAppState(
2402
2443
  state,
@@ -2968,7 +3009,7 @@ var collisionStore = (0, import_vanilla.createStore)(() => ({
2968
3009
 
2969
3010
  // lib/dnd/collision/dynamic/index.ts
2970
3011
  var flushNext = "";
2971
- var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input) => {
3012
+ var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => ((input) => {
2972
3013
  var _a, _b, _c, _d, _e;
2973
3014
  const { dragOperation, droppable } = input;
2974
3015
  const { position } = dragOperation;
@@ -3061,7 +3102,7 @@ var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input
3061
3102
  }
3062
3103
  collisionDebug(dragCenter, dropCenter, droppable.id.toString(), "hotpink");
3063
3104
  return null;
3064
- };
3105
+ });
3065
3106
 
3066
3107
  // components/Sortable/index.tsx
3067
3108
  var import_sortable = require("@dnd-kit/react/sortable");
@@ -3494,8 +3535,9 @@ var ArrayField = ({
3494
3535
  var _a;
3495
3536
  if (isDraggingAny) return;
3496
3537
  const existingValue = value || [];
3538
+ const defaultProps = typeof field.defaultItemProps === "function" ? field.defaultItemProps(existingValue.length) : (_a = field.defaultItemProps) != null ? _a : {};
3497
3539
  const newItem = defaultSlots(
3498
- uniqifyItem((_a = field.defaultItemProps) != null ? _a : {}),
3540
+ uniqifyItem(defaultProps),
3499
3541
  field.arrayFields
3500
3542
  );
3501
3543
  const newValue = [...existingValue, newItem];
@@ -3754,11 +3796,13 @@ var ExternalInput = ({
3754
3796
  id,
3755
3797
  readOnly
3756
3798
  }) => {
3799
+ var _a;
3757
3800
  const {
3758
3801
  mapProp = (val) => val,
3759
3802
  mapRow = (val) => val,
3760
3803
  filterFields
3761
3804
  } = field || {};
3805
+ const { enabled: shouldCacheData } = (_a = field.cache) != null ? _a : { enabled: true };
3762
3806
  const [data, setData] = (0, import_react17.useState)([]);
3763
3807
  const [isOpen, setOpen] = (0, import_react17.useState)(false);
3764
3808
  const [isLoading, setIsLoading] = (0, import_react17.useState)(true);
@@ -3781,14 +3825,21 @@ var ExternalInput = ({
3781
3825
  }, [mappedData]);
3782
3826
  const [searchQuery, setSearchQuery] = (0, import_react17.useState)(field.initialQuery || "");
3783
3827
  const search = (0, import_react17.useCallback)(
3784
- (query, filters2) => __async(void 0, null, function* () {
3828
+ (query, filters2) => __async(null, null, function* () {
3785
3829
  setIsLoading(true);
3786
3830
  const cacheKey = `${id}-${query}-${JSON.stringify(filters2)}`;
3787
- const listData = dataCache[cacheKey] || (yield field.fetchList({ query, filters: filters2 }));
3831
+ let listData;
3832
+ if (shouldCacheData && dataCache[cacheKey]) {
3833
+ listData = dataCache[cacheKey];
3834
+ } else {
3835
+ listData = yield field.fetchList({ query, filters: filters2 });
3836
+ }
3788
3837
  if (listData) {
3789
3838
  setData(listData);
3790
3839
  setIsLoading(false);
3791
- dataCache[cacheKey] = listData;
3840
+ if (shouldCacheData) {
3841
+ dataCache[cacheKey] = listData;
3842
+ }
3792
3843
  }
3793
3844
  }),
3794
3845
  [id, field]
@@ -3852,6 +3903,7 @@ var ExternalInput = ({
3852
3903
  }),
3853
3904
  onSubmit: (e) => {
3854
3905
  e.preventDefault();
3906
+ e.stopPropagation();
3855
3907
  search(searchQuery, filters);
3856
3908
  },
3857
3909
  children: [
@@ -3999,7 +4051,7 @@ var ExternalField = ({
3999
4051
  placeholder: ((_a = deprecatedField.adaptor) == null ? void 0 : _a.name) ? `Select from ${deprecatedField.adaptor.name}` : validField.placeholder || "Select data",
4000
4052
  mapProp: ((_b = deprecatedField.adaptor) == null ? void 0 : _b.mapProp) || validField.mapProp,
4001
4053
  mapRow: validField.mapRow,
4002
- fetchList: ((_c = deprecatedField.adaptor) == null ? void 0 : _c.fetchList) ? () => __async(void 0, null, function* () {
4054
+ fetchList: ((_c = deprecatedField.adaptor) == null ? void 0 : _c.fetchList) ? () => __async(null, null, function* () {
4003
4055
  return yield deprecatedField.adaptor.fetchList(
4004
4056
  deprecatedField.adaptorParams
4005
4057
  );
@@ -4375,6 +4427,7 @@ function AutoFieldInternal(props) {
4375
4427
  }
4376
4428
  return (_props) => null;
4377
4429
  }, [field.type]);
4430
+ const fieldKey = field.type === "custom" ? field.key : void 0;
4378
4431
  let FieldComponent = (0, import_react20.useMemo)(() => {
4379
4432
  if (field.type === "custom") {
4380
4433
  if (!field.render) {
@@ -4384,7 +4437,7 @@ function AutoFieldInternal(props) {
4384
4437
  } else if (field.type !== "slot") {
4385
4438
  return render[field.type];
4386
4439
  }
4387
- }, [field.type, render]);
4440
+ }, [field.type, fieldKey, render]);
4388
4441
  const { visible = true } = props.field;
4389
4442
  if (!visible) {
4390
4443
  return null;
@@ -4755,12 +4808,14 @@ var DraggableComponent = ({
4755
4808
  }
4756
4809
  return cleanup;
4757
4810
  }, [permissions.drag, zoneCompound]);
4811
+ const [, setRerender] = (0, import_react24.useState)(0);
4758
4812
  const ref = (0, import_react24.useRef)(null);
4759
4813
  const refSetter = (0, import_react24.useCallback)(
4760
4814
  (el) => {
4761
4815
  sortableRef(el);
4762
- if (el) {
4816
+ if (ref.current !== el) {
4763
4817
  ref.current = el;
4818
+ setRerender((update) => update + 1);
4764
4819
  }
4765
4820
  },
4766
4821
  [sortableRef]
@@ -5207,7 +5262,7 @@ var import_react27 = require("react");
5207
5262
  function useRenderedCallback(callback, deps) {
5208
5263
  const manager = (0, import_react26.useDragDropManager)();
5209
5264
  return (0, import_react27.useCallback)(
5210
- (...args) => __async(this, null, function* () {
5265
+ (...args) => __async(null, null, function* () {
5211
5266
  yield manager == null ? void 0 : manager.renderer.rendering;
5212
5267
  return callback(...args);
5213
5268
  }),
@@ -5412,8 +5467,9 @@ var Item = ({
5412
5467
  );
5413
5468
  };
5414
5469
  var SlotRender = (0, import_react31.forwardRef)(
5415
- function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
5416
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className, style, ref, children: content.map((item) => {
5470
+ function SlotRenderInternal({ className, style, content, config, metadata, as }, ref) {
5471
+ const El = as != null ? as : "div";
5472
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(El, { className, style, ref, children: content.map((item) => {
5417
5473
  if (!config.components[item.type]) {
5418
5474
  return null;
5419
5475
  }
@@ -5535,26 +5591,26 @@ var registerOverlayPortal = (el, opts = {}) => {
5535
5591
  capture: true
5536
5592
  });
5537
5593
  };
5538
- if (disableDragOnFocus) {
5539
- el.addEventListener("focus", onFocus, { capture: true });
5540
- el.addEventListener("blur", onBlur, { capture: true });
5541
- } else if (disableDrag) {
5594
+ if (disableDrag) {
5542
5595
  el.addEventListener("pointerdown", stopPropagation, {
5543
5596
  capture: true
5544
5597
  });
5598
+ } else if (disableDragOnFocus) {
5599
+ el.addEventListener("focus", onFocus, { capture: true });
5600
+ el.addEventListener("blur", onBlur, { capture: true });
5545
5601
  }
5546
5602
  el.setAttribute("data-puck-overlay-portal", "true");
5547
5603
  return () => {
5548
5604
  el.removeEventListener("mouseover", stopPropagation, {
5549
5605
  capture: true
5550
5606
  });
5551
- if (disableDragOnFocus) {
5552
- el.removeEventListener("focus", onFocus, { capture: true });
5553
- el.removeEventListener("blur", onFocus, { capture: true });
5554
- } else if (disableDrag) {
5607
+ if (disableDrag) {
5555
5608
  el.removeEventListener("pointerdown", stopPropagation, {
5556
5609
  capture: true
5557
5610
  });
5611
+ } else if (disableDragOnFocus) {
5612
+ el.removeEventListener("focus", onFocus, { capture: true });
5613
+ el.removeEventListener("blur", onBlur, { capture: true });
5558
5614
  }
5559
5615
  el.removeAttribute("data-puck-overlay-portal");
5560
5616
  };
@@ -5562,7 +5618,7 @@ var registerOverlayPortal = (el, opts = {}) => {
5562
5618
 
5563
5619
  // css-module:/home/runner/work/puck/puck/packages/core/components/InlineTextField/styles.module.css#css-module
5564
5620
  init_react_import();
5565
- var styles_module_default13 = { "InlineTextField": "_InlineTextField_1xph6_1" };
5621
+ var styles_module_default13 = { "InlineTextField": "_InlineTextField_104qp_1" };
5566
5622
 
5567
5623
  // lib/data/set-deep.ts
5568
5624
  init_react_import();
@@ -5636,7 +5692,7 @@ var InlineTextFieldInternal = ({
5636
5692
  ref.current.replaceChildren(value);
5637
5693
  }
5638
5694
  const cleanupPortal = registerOverlayPortal(ref.current);
5639
- const handleInput = (e) => __async(void 0, null, function* () {
5695
+ const handleInput = (e) => __async(null, null, function* () {
5640
5696
  var _a2;
5641
5697
  const appStore2 = appStoreApi.getState();
5642
5698
  const node = appStore2.state.indexes.nodes[componentId];
@@ -5928,7 +5984,8 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
5928
5984
  style,
5929
5985
  className,
5930
5986
  minEmptyHeight: userMinEmptyHeight = 128,
5931
- collisionAxis
5987
+ collisionAxis,
5988
+ as
5932
5989
  }, userRef) {
5933
5990
  const ctx = (0, import_react34.useContext)(dropZoneContext);
5934
5991
  const appStoreApi = useAppStoreApi();
@@ -6071,8 +6128,9 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
6071
6128
  userMinEmptyHeight,
6072
6129
  ref
6073
6130
  });
6131
+ const El = as != null ? as : "div";
6074
6132
  return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
6075
- "div",
6133
+ El,
6076
6134
  {
6077
6135
  className: `${getClassName18({
6078
6136
  isRootZone,
@@ -6135,7 +6193,7 @@ var DropZoneRenderItem = ({
6135
6193
  };
6136
6194
  var DropZoneRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(DropZoneRender, __spreadValues({}, props));
6137
6195
  var DropZoneRender = (0, import_react34.forwardRef)(
6138
- function DropZoneRenderInternal({ className, style, zone }, ref) {
6196
+ function DropZoneRenderInternal({ className, style, zone, as }, ref) {
6139
6197
  const ctx = (0, import_react34.useContext)(dropZoneContext);
6140
6198
  const { areaId = "root" } = ctx || {};
6141
6199
  const { config, data, metadata } = (0, import_react34.useContext)(renderContext);
@@ -6148,13 +6206,14 @@ var DropZoneRender = (0, import_react34.forwardRef)(
6148
6206
  }
6149
6207
  }
6150
6208
  }, [content]);
6209
+ const El = as != null ? as : "div";
6151
6210
  if (!data || !config) {
6152
6211
  return null;
6153
6212
  }
6154
6213
  if (zoneCompound !== rootDroppableId) {
6155
6214
  content = setupZone(data, zoneCompound).zones[zoneCompound];
6156
6215
  }
6157
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className, style, ref, children: content.map((item) => {
6216
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(El, { className, style, ref, children: content.map((item) => {
6158
6217
  const Component = config.components[item.type];
6159
6218
  if (Component) {
6160
6219
  return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
@@ -6460,7 +6519,8 @@ var createNestedDroppablePlugin = ({ onChange }, id) => class NestedDroppablePlu
6460
6519
 
6461
6520
  // lib/insert-component.ts
6462
6521
  init_react_import();
6463
- var insertComponent = (componentType, zone, index, appStore) => __async(void 0, null, function* () {
6522
+ var insertComponent = (componentType, zone, index, appStore) => __async(null, null, function* () {
6523
+ const { getState } = appStore;
6464
6524
  const id = generateId(componentType);
6465
6525
  const insertActionData = {
6466
6526
  type: "insert",
@@ -6469,8 +6529,9 @@ var insertComponent = (componentType, zone, index, appStore) => __async(void 0,
6469
6529
  destinationZone: zone,
6470
6530
  id
6471
6531
  };
6472
- const { state, dispatch, resolveComponentData: resolveComponentData2 } = appStore;
6473
- const insertedState = insertAction(state, insertActionData, appStore);
6532
+ const stateBefore = getState().state;
6533
+ const insertedState = insertAction(stateBefore, insertActionData, getState());
6534
+ const dispatch = getState().dispatch;
6474
6535
  dispatch(__spreadProps(__spreadValues({}, insertActionData), {
6475
6536
  // Dispatch insert rather set, as user's may rely on this via onAction
6476
6537
  // We must always record history here so the insert is added to user history
@@ -6478,23 +6539,21 @@ var insertComponent = (componentType, zone, index, appStore) => __async(void 0,
6478
6539
  // entries on insert - one for the initial insert, and one when the data resolves
6479
6540
  recordHistory: true
6480
6541
  }));
6481
- const itemSelector = {
6482
- index,
6483
- zone
6484
- };
6542
+ const itemSelector = { index, zone };
6485
6543
  dispatch({ type: "setUi", ui: { itemSelector } });
6486
6544
  const itemData = getItem(itemSelector, insertedState);
6487
- if (itemData) {
6488
- const resolved = yield resolveComponentData2(itemData, "insert");
6489
- if (resolved.didChange) {
6490
- dispatch({
6491
- type: "replace",
6492
- destinationZone: itemSelector.zone,
6493
- destinationIndex: itemSelector.index,
6494
- data: resolved.node
6495
- });
6496
- }
6497
- }
6545
+ if (!itemData) return;
6546
+ const resolveComponentData2 = getState().resolveComponentData;
6547
+ const resolved = yield resolveComponentData2(itemData, "insert");
6548
+ if (!resolved.didChange) return;
6549
+ const latestItemSelector = getSelectorForId(getState().state, id);
6550
+ if (!latestItemSelector) return;
6551
+ dispatch({
6552
+ type: "replace",
6553
+ destinationZone: latestItemSelector.zone,
6554
+ destinationIndex: latestItemSelector.index,
6555
+ data: resolved.node
6556
+ });
6498
6557
  });
6499
6558
 
6500
6559
  // components/DragDropContext/index.tsx
@@ -6731,7 +6790,7 @@ var DragDropContextClient = ({
6731
6790
  thisPreview.componentType,
6732
6791
  thisPreview.zone,
6733
6792
  thisPreview.index,
6734
- appStore.getState()
6793
+ appStore
6735
6794
  );
6736
6795
  } else if (initialSelector.current) {
6737
6796
  dispatch({
@@ -7168,7 +7227,7 @@ var DefaultFields = ({
7168
7227
  }) => {
7169
7228
  return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_jsx_runtime30.Fragment, { children });
7170
7229
  };
7171
- var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(void 0, null, function* () {
7230
+ var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(null, null, function* () {
7172
7231
  let currentProps;
7173
7232
  const { dispatch, state, selectedItem, resolveComponentData: resolveComponentData2 } = appStore.getState();
7174
7233
  const { data, ui } = state;
@@ -7537,7 +7596,7 @@ var CopyHostStyles = ({
7537
7596
  let elements = [];
7538
7597
  const hashes = {};
7539
7598
  const lookupEl = (el) => elements.findIndex((elementMap) => elementMap.original === el);
7540
- const mirrorEl = (el, inlineStyles = false) => __async(void 0, null, function* () {
7599
+ const mirrorEl = (el, inlineStyles = false) => __async(null, null, function* () {
7541
7600
  let mirror;
7542
7601
  if (el.nodeName === "LINK" && inlineStyles) {
7543
7602
  mirror = document.createElement("style");
@@ -7569,7 +7628,7 @@ var CopyHostStyles = ({
7569
7628
  }
7570
7629
  return mirror;
7571
7630
  });
7572
- const addEl = (el) => __async(void 0, null, function* () {
7631
+ const addEl = (el) => __async(null, null, function* () {
7573
7632
  const index = lookupEl(el);
7574
7633
  if (index > -1) {
7575
7634
  if (debug)
@@ -7642,7 +7701,7 @@ var CopyHostStyles = ({
7642
7701
  const parentBody = parentDocument.getElementsByTagName("body")[0];
7643
7702
  syncAttributes(parentBody, doc.body);
7644
7703
  Promise.all(
7645
- collectedStyles.map((styleNode, i) => __async(void 0, null, function* () {
7704
+ collectedStyles.map((styleNode, i) => __async(null, null, function* () {
7646
7705
  if (styleNode.nodeName === "LINK") {
7647
7706
  const linkHref = styleNode.href;
7648
7707
  if (hrefs.indexOf(linkHref) > -1) {
@@ -8717,7 +8776,7 @@ function createUsePuck() {
8717
8776
  }
8718
8777
  const result = (0, import_zustand6.useStore)(
8719
8778
  usePuckApi,
8720
- selector != null ? selector : (s) => s
8779
+ selector != null ? selector : ((s) => s)
8721
8780
  );
8722
8781
  return result;
8723
8782
  };
@@ -8739,7 +8798,7 @@ function useGetPuck() {
8739
8798
  }
8740
8799
 
8741
8800
  // components/Puck/index.tsx
8742
- var import_fast_deep_equal3 = __toESM(require("fast-deep-equal"));
8801
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
8743
8802
 
8744
8803
  // components/Puck/components/Header/index.tsx
8745
8804
  init_react_import();
@@ -9167,6 +9226,15 @@ function useSidebarResize(position, dispatch) {
9167
9226
  };
9168
9227
  }
9169
9228
 
9229
+ // lib/data/to-component.ts
9230
+ init_react_import();
9231
+ var toComponent = (item) => {
9232
+ return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
9233
+ props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
9234
+ type: "root"
9235
+ });
9236
+ };
9237
+
9170
9238
  // components/Puck/index.tsx
9171
9239
  var import_jsx_runtime46 = require("react/jsx-runtime");
9172
9240
  var getClassName31 = get_class_name_factory_default("Puck", styles_module_default15);
@@ -9243,9 +9311,13 @@ function PuckProvider({ children }) {
9243
9311
  }
9244
9312
  const rootProps = ((_h = initialData == null ? void 0 : initialData.root) == null ? void 0 : _h.props) || (initialData == null ? void 0 : initialData.root) || {};
9245
9313
  const defaultedRootProps = __spreadValues(__spreadValues({}, (_i = config.root) == null ? void 0 : _i.defaultProps), rootProps);
9314
+ const root = populateIds(
9315
+ toComponent(__spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: defaultedRootProps })),
9316
+ config
9317
+ );
9246
9318
  const newAppState = __spreadProps(__spreadValues({}, defaultAppState), {
9247
9319
  data: __spreadProps(__spreadValues({}, initialData), {
9248
- root: __spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: defaultedRootProps }),
9320
+ root: __spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: root.props }),
9249
9321
  content: initialData.content || []
9250
9322
  }),
9251
9323
  ui: __spreadProps(__spreadValues(__spreadValues({}, initial), clientUiState), {
@@ -9282,7 +9354,12 @@ function PuckProvider({ children }) {
9282
9354
  });
9283
9355
  })
9284
9356
  );
9285
- const initialHistoryIndex = (_initialHistory == null ? void 0 : _initialHistory.index) || blendedHistories.length - 1;
9357
+ const initialHistoryIndex = (0, import_react60.useMemo)(() => {
9358
+ if ((_initialHistory == null ? void 0 : _initialHistory.index) !== void 0 && (_initialHistory == null ? void 0 : _initialHistory.index) >= 0 && (_initialHistory == null ? void 0 : _initialHistory.index) < blendedHistories.length) {
9359
+ return _initialHistory == null ? void 0 : _initialHistory.index;
9360
+ }
9361
+ return blendedHistories.length - 1;
9362
+ }, []);
9286
9363
  const initialAppState = blendedHistories[initialHistoryIndex].state;
9287
9364
  const loadedOverrides = useLoadedOverrides({
9288
9365
  overrides,
@@ -9341,17 +9418,17 @@ function PuckProvider({ children }) {
9341
9418
  });
9342
9419
  const previousData = (0, import_react60.useRef)(null);
9343
9420
  (0, import_react60.useEffect)(() => {
9344
- appStore.subscribe(
9421
+ return appStore.subscribe(
9345
9422
  (s) => s.state.data,
9346
9423
  (data) => {
9347
9424
  if (onChange) {
9348
- if ((0, import_fast_deep_equal3.default)(data, previousData.current)) return;
9425
+ if ((0, import_fast_deep_equal.default)(data, previousData.current)) return;
9349
9426
  onChange(data);
9350
9427
  previousData.current = data;
9351
9428
  }
9352
9429
  }
9353
9430
  );
9354
- }, []);
9431
+ }, [onChange]);
9355
9432
  useRegisterPermissionsSlice(appStore, permissions);
9356
9433
  const uPuckStore = useRegisterUsePuckStore(appStore);
9357
9434
  (0, import_react60.useEffect)(() => {
@@ -9664,22 +9741,11 @@ function transformProps(data, propTransforms, config = { components: {} }) {
9664
9741
 
9665
9742
  // lib/resolve-all-data.ts
9666
9743
  init_react_import();
9667
-
9668
- // lib/data/to-component.ts
9669
- init_react_import();
9670
- var toComponent = (item) => {
9671
- return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
9672
- props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
9673
- type: "root"
9674
- });
9675
- };
9676
-
9677
- // lib/resolve-all-data.ts
9678
9744
  function resolveAllData(_0, _1) {
9679
9745
  return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
9680
9746
  var _a;
9681
9747
  const defaultedData = defaultData(data);
9682
- const resolveNode = (_node) => __async(this, null, function* () {
9748
+ const resolveNode = (_node) => __async(null, null, function* () {
9683
9749
  const node = toComponent(_node);
9684
9750
  onResolveStart == null ? void 0 : onResolveStart(node);
9685
9751
  const resolved = (yield resolveComponentData(
@@ -9700,13 +9766,13 @@ function resolveAllData(_0, _1) {
9700
9766
  onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
9701
9767
  return resolvedDeep;
9702
9768
  });
9703
- const processContent = (content) => __async(this, null, function* () {
9769
+ const processContent = (content) => __async(null, null, function* () {
9704
9770
  return Promise.all(content.map(resolveNode));
9705
9771
  });
9706
- const processZones = () => __async(this, null, function* () {
9772
+ const processZones = () => __async(null, null, function* () {
9707
9773
  var _a2;
9708
9774
  const zones = (_a2 = data.zones) != null ? _a2 : {};
9709
- Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
9775
+ Object.entries(zones).forEach((_02) => __async(null, [_02], function* ([zoneKey, content]) {
9710
9776
  zones[zoneKey] = yield Promise.all(content.map(resolveNode));
9711
9777
  }));
9712
9778
  return zones;
@@ -9716,7 +9782,7 @@ function resolveAllData(_0, _1) {
9716
9782
  content: yield processContent(defaultedData.content),
9717
9783
  zones: yield processZones()
9718
9784
  };
9719
- Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
9785
+ Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(null, null, function* () {
9720
9786
  const content = defaultedData.zones[zoneKey];
9721
9787
  dynamic.zones[zoneKey] = yield processContent(content);
9722
9788
  }), {});
@@ -9759,269 +9825,38 @@ classnames/index.js:
9759
9825
  *)
9760
9826
 
9761
9827
  lucide-react/dist/esm/shared/src/utils.js:
9762
- (**
9763
- * @license lucide-react v0.468.0 - ISC
9764
- *
9765
- * This source code is licensed under the ISC license.
9766
- * See the LICENSE file in the root directory of this source tree.
9767
- *)
9768
-
9769
9828
  lucide-react/dist/esm/defaultAttributes.js:
9770
- (**
9771
- * @license lucide-react v0.468.0 - ISC
9772
- *
9773
- * This source code is licensed under the ISC license.
9774
- * See the LICENSE file in the root directory of this source tree.
9775
- *)
9776
-
9777
9829
  lucide-react/dist/esm/Icon.js:
9778
- (**
9779
- * @license lucide-react v0.468.0 - ISC
9780
- *
9781
- * This source code is licensed under the ISC license.
9782
- * See the LICENSE file in the root directory of this source tree.
9783
- *)
9784
-
9785
9830
  lucide-react/dist/esm/createLucideIcon.js:
9786
- (**
9787
- * @license lucide-react v0.468.0 - ISC
9788
- *
9789
- * This source code is licensed under the ISC license.
9790
- * See the LICENSE file in the root directory of this source tree.
9791
- *)
9792
-
9793
9831
  lucide-react/dist/esm/icons/chevron-down.js:
9794
- (**
9795
- * @license lucide-react v0.468.0 - ISC
9796
- *
9797
- * This source code is licensed under the ISC license.
9798
- * See the LICENSE file in the root directory of this source tree.
9799
- *)
9800
-
9801
9832
  lucide-react/dist/esm/icons/chevron-right.js:
9802
- (**
9803
- * @license lucide-react v0.468.0 - ISC
9804
- *
9805
- * This source code is licensed under the ISC license.
9806
- * See the LICENSE file in the root directory of this source tree.
9807
- *)
9808
-
9809
9833
  lucide-react/dist/esm/icons/chevron-up.js:
9810
- (**
9811
- * @license lucide-react v0.468.0 - ISC
9812
- *
9813
- * This source code is licensed under the ISC license.
9814
- * See the LICENSE file in the root directory of this source tree.
9815
- *)
9816
-
9817
9834
  lucide-react/dist/esm/icons/circle-check-big.js:
9818
- (**
9819
- * @license lucide-react v0.468.0 - ISC
9820
- *
9821
- * This source code is licensed under the ISC license.
9822
- * See the LICENSE file in the root directory of this source tree.
9823
- *)
9824
-
9825
9835
  lucide-react/dist/esm/icons/copy.js:
9826
- (**
9827
- * @license lucide-react v0.468.0 - ISC
9828
- *
9829
- * This source code is licensed under the ISC license.
9830
- * See the LICENSE file in the root directory of this source tree.
9831
- *)
9832
-
9833
9836
  lucide-react/dist/esm/icons/corner-left-up.js:
9834
- (**
9835
- * @license lucide-react v0.468.0 - ISC
9836
- *
9837
- * This source code is licensed under the ISC license.
9838
- * See the LICENSE file in the root directory of this source tree.
9839
- *)
9840
-
9841
9837
  lucide-react/dist/esm/icons/ellipsis-vertical.js:
9842
- (**
9843
- * @license lucide-react v0.468.0 - ISC
9844
- *
9845
- * This source code is licensed under the ISC license.
9846
- * See the LICENSE file in the root directory of this source tree.
9847
- *)
9848
-
9849
9838
  lucide-react/dist/esm/icons/globe.js:
9850
- (**
9851
- * @license lucide-react v0.468.0 - ISC
9852
- *
9853
- * This source code is licensed under the ISC license.
9854
- * See the LICENSE file in the root directory of this source tree.
9855
- *)
9856
-
9857
9839
  lucide-react/dist/esm/icons/hash.js:
9858
- (**
9859
- * @license lucide-react v0.468.0 - ISC
9860
- *
9861
- * This source code is licensed under the ISC license.
9862
- * See the LICENSE file in the root directory of this source tree.
9863
- *)
9864
-
9865
9840
  lucide-react/dist/esm/icons/layers.js:
9866
- (**
9867
- * @license lucide-react v0.468.0 - ISC
9868
- *
9869
- * This source code is licensed under the ISC license.
9870
- * See the LICENSE file in the root directory of this source tree.
9871
- *)
9872
-
9873
9841
  lucide-react/dist/esm/icons/layout-grid.js:
9874
- (**
9875
- * @license lucide-react v0.468.0 - ISC
9876
- *
9877
- * This source code is licensed under the ISC license.
9878
- * See the LICENSE file in the root directory of this source tree.
9879
- *)
9880
-
9881
9842
  lucide-react/dist/esm/icons/link.js:
9882
- (**
9883
- * @license lucide-react v0.468.0 - ISC
9884
- *
9885
- * This source code is licensed under the ISC license.
9886
- * See the LICENSE file in the root directory of this source tree.
9887
- *)
9888
-
9889
9843
  lucide-react/dist/esm/icons/list.js:
9890
- (**
9891
- * @license lucide-react v0.468.0 - ISC
9892
- *
9893
- * This source code is licensed under the ISC license.
9894
- * See the LICENSE file in the root directory of this source tree.
9895
- *)
9896
-
9897
9844
  lucide-react/dist/esm/icons/lock-open.js:
9898
- (**
9899
- * @license lucide-react v0.468.0 - ISC
9900
- *
9901
- * This source code is licensed under the ISC license.
9902
- * See the LICENSE file in the root directory of this source tree.
9903
- *)
9904
-
9905
9845
  lucide-react/dist/esm/icons/lock.js:
9906
- (**
9907
- * @license lucide-react v0.468.0 - ISC
9908
- *
9909
- * This source code is licensed under the ISC license.
9910
- * See the LICENSE file in the root directory of this source tree.
9911
- *)
9912
-
9913
9846
  lucide-react/dist/esm/icons/monitor.js:
9914
- (**
9915
- * @license lucide-react v0.468.0 - ISC
9916
- *
9917
- * This source code is licensed under the ISC license.
9918
- * See the LICENSE file in the root directory of this source tree.
9919
- *)
9920
-
9921
9847
  lucide-react/dist/esm/icons/panel-left.js:
9922
- (**
9923
- * @license lucide-react v0.468.0 - ISC
9924
- *
9925
- * This source code is licensed under the ISC license.
9926
- * See the LICENSE file in the root directory of this source tree.
9927
- *)
9928
-
9929
9848
  lucide-react/dist/esm/icons/panel-right.js:
9930
- (**
9931
- * @license lucide-react v0.468.0 - ISC
9932
- *
9933
- * This source code is licensed under the ISC license.
9934
- * See the LICENSE file in the root directory of this source tree.
9935
- *)
9936
-
9937
9849
  lucide-react/dist/esm/icons/plus.js:
9938
- (**
9939
- * @license lucide-react v0.468.0 - ISC
9940
- *
9941
- * This source code is licensed under the ISC license.
9942
- * See the LICENSE file in the root directory of this source tree.
9943
- *)
9944
-
9945
9850
  lucide-react/dist/esm/icons/redo-2.js:
9946
- (**
9947
- * @license lucide-react v0.468.0 - ISC
9948
- *
9949
- * This source code is licensed under the ISC license.
9950
- * See the LICENSE file in the root directory of this source tree.
9951
- *)
9952
-
9953
9851
  lucide-react/dist/esm/icons/search.js:
9954
- (**
9955
- * @license lucide-react v0.468.0 - ISC
9956
- *
9957
- * This source code is licensed under the ISC license.
9958
- * See the LICENSE file in the root directory of this source tree.
9959
- *)
9960
-
9961
9852
  lucide-react/dist/esm/icons/sliders-horizontal.js:
9962
- (**
9963
- * @license lucide-react v0.468.0 - ISC
9964
- *
9965
- * This source code is licensed under the ISC license.
9966
- * See the LICENSE file in the root directory of this source tree.
9967
- *)
9968
-
9969
9853
  lucide-react/dist/esm/icons/smartphone.js:
9970
- (**
9971
- * @license lucide-react v0.468.0 - ISC
9972
- *
9973
- * This source code is licensed under the ISC license.
9974
- * See the LICENSE file in the root directory of this source tree.
9975
- *)
9976
-
9977
9854
  lucide-react/dist/esm/icons/tablet.js:
9978
- (**
9979
- * @license lucide-react v0.468.0 - ISC
9980
- *
9981
- * This source code is licensed under the ISC license.
9982
- * See the LICENSE file in the root directory of this source tree.
9983
- *)
9984
-
9985
9855
  lucide-react/dist/esm/icons/trash.js:
9986
- (**
9987
- * @license lucide-react v0.468.0 - ISC
9988
- *
9989
- * This source code is licensed under the ISC license.
9990
- * See the LICENSE file in the root directory of this source tree.
9991
- *)
9992
-
9993
9856
  lucide-react/dist/esm/icons/type.js:
9994
- (**
9995
- * @license lucide-react v0.468.0 - ISC
9996
- *
9997
- * This source code is licensed under the ISC license.
9998
- * See the LICENSE file in the root directory of this source tree.
9999
- *)
10000
-
10001
9857
  lucide-react/dist/esm/icons/undo-2.js:
10002
- (**
10003
- * @license lucide-react v0.468.0 - ISC
10004
- *
10005
- * This source code is licensed under the ISC license.
10006
- * See the LICENSE file in the root directory of this source tree.
10007
- *)
10008
-
10009
9858
  lucide-react/dist/esm/icons/zoom-in.js:
10010
- (**
10011
- * @license lucide-react v0.468.0 - ISC
10012
- *
10013
- * This source code is licensed under the ISC license.
10014
- * See the LICENSE file in the root directory of this source tree.
10015
- *)
10016
-
10017
9859
  lucide-react/dist/esm/icons/zoom-out.js:
10018
- (**
10019
- * @license lucide-react v0.468.0 - ISC
10020
- *
10021
- * This source code is licensed under the ISC license.
10022
- * See the LICENSE file in the root directory of this source tree.
10023
- *)
10024
-
10025
9860
  lucide-react/dist/esm/lucide-react.js:
10026
9861
  (**
10027
9862
  * @license lucide-react v0.468.0 - ISC