@measured/puck 0.21.0-canary.74d9a160 → 0.21.0-canary.79a26849

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
@@ -190,8 +190,8 @@ var require_fast_deep_equal = __commonJS({
190
190
  });
191
191
 
192
192
  // bundle/index.ts
193
- var bundle_exports = {};
194
- __export(bundle_exports, {
193
+ var index_exports = {};
194
+ __export(index_exports, {
195
195
  Action: () => Action,
196
196
  ActionBar: () => ActionBar,
197
197
  AutoField: () => AutoField,
@@ -216,7 +216,7 @@ __export(bundle_exports, {
216
216
  usePuck: () => usePuck,
217
217
  walkTree: () => walkTree
218
218
  });
219
- module.exports = __toCommonJS(bundle_exports);
219
+ module.exports = __toCommonJS(index_exports);
220
220
  init_react_import();
221
221
 
222
222
  // bundle/core.ts
@@ -1976,29 +1976,37 @@ var getChanged = (newItem, oldItem) => {
1976
1976
 
1977
1977
  // store/slices/permissions.ts
1978
1978
  var createPermissionsSlice = (set, get) => {
1979
- const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1979
+ const resolvePermissions = (..._0) => __async(null, [..._0], function* (params = {}, force) {
1980
1980
  const { state, permissions, config } = get();
1981
1981
  const { cache: cache2, globalPermissions } = permissions;
1982
- const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1983
- var _a, _b, _c;
1982
+ const resolvePermissionsForItem = (item2, force2 = false) => __async(null, null, function* () {
1983
+ var _a, _b;
1984
1984
  const { config: config2, state: appState, setComponentLoading } = get();
1985
+ const itemCache = cache2[item2.props.id];
1986
+ const nodes = appState.indexes.nodes;
1987
+ const parentId = (_a = nodes[item2.props.id]) == null ? void 0 : _a.parentId;
1988
+ const parentNode = parentId ? nodes[parentId] : null;
1989
+ const parentData = (_b = parentNode == null ? void 0 : parentNode.data) != null ? _b : null;
1985
1990
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1986
1991
  if (!componentConfig) {
1987
1992
  return;
1988
1993
  }
1989
1994
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1990
1995
  if (componentConfig.resolvePermissions) {
1991
- const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1992
- if (Object.values(changed).some((el) => el === true) || force2) {
1996
+ const changed = getChanged(item2, itemCache == null ? void 0 : itemCache.lastData);
1997
+ const propsChanged = Object.values(changed).some((el) => el === true);
1998
+ const parentChanged = (itemCache == null ? void 0 : itemCache.lastParentId) !== parentId;
1999
+ if (propsChanged || parentChanged || force2) {
1993
2000
  const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1994
2001
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1995
2002
  item2,
1996
2003
  {
1997
2004
  changed,
1998
- lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
2005
+ lastPermissions: (itemCache == null ? void 0 : itemCache.lastPermissions) || null,
1999
2006
  permissions: initialPermissions,
2000
2007
  appState: makeStatePublic(appState),
2001
- lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
2008
+ lastData: (itemCache == null ? void 0 : itemCache.lastData) || null,
2009
+ parent: parentData
2002
2010
  }
2003
2011
  );
2004
2012
  const latest = get().permissions;
@@ -2006,6 +2014,7 @@ var createPermissionsSlice = (set, get) => {
2006
2014
  permissions: __spreadProps(__spreadValues({}, latest), {
2007
2015
  cache: __spreadProps(__spreadValues({}, latest.cache), {
2008
2016
  [item2.props.id]: {
2017
+ lastParentId: parentId,
2009
2018
  lastData: item2,
2010
2019
  lastPermissions: resolvedPermissions
2011
2020
  }
@@ -2019,9 +2028,9 @@ var createPermissionsSlice = (set, get) => {
2019
2028
  }
2020
2029
  }
2021
2030
  });
2022
- const resolveDataForRoot = (force2 = false) => {
2031
+ const resolvePermissionsForRoot = (force2 = false) => {
2023
2032
  const { state: appState } = get();
2024
- resolveDataForItem(
2033
+ resolvePermissionsForItem(
2025
2034
  // Shim the root data in by conforming to component data shape
2026
2035
  {
2027
2036
  type: "root",
@@ -2032,16 +2041,16 @@ var createPermissionsSlice = (set, get) => {
2032
2041
  };
2033
2042
  const { item, type, root } = params;
2034
2043
  if (item) {
2035
- yield resolveDataForItem(item, force);
2044
+ yield resolvePermissionsForItem(item, force);
2036
2045
  } else if (type) {
2037
- flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
2038
- yield resolveDataForItem(item2, force);
2046
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(null, null, function* () {
2047
+ yield resolvePermissionsForItem(item2, force);
2039
2048
  }));
2040
2049
  } else if (root) {
2041
- resolveDataForRoot(force);
2050
+ resolvePermissionsForRoot(force);
2042
2051
  } else {
2043
- flattenData(state, config).map((item2) => __async(void 0, null, function* () {
2044
- yield resolveDataForItem(item2, force);
2052
+ flattenData(state, config).map((item2) => __async(null, null, function* () {
2053
+ yield resolvePermissionsForItem(item2, force);
2045
2054
  }));
2046
2055
  }
2047
2056
  });
@@ -2121,7 +2130,7 @@ var createFieldsSlice = (_set, _get) => {
2121
2130
  };
2122
2131
  var useRegisterFieldsSlice = (appStore, id) => {
2123
2132
  const resolveFields = (0, import_react7.useCallback)(
2124
- (reset) => __async(void 0, null, function* () {
2133
+ (reset) => __async(null, null, function* () {
2125
2134
  var _a, _b;
2126
2135
  const { fields, lastResolvedData } = appStore.getState().fields;
2127
2136
  const metadata = appStore.getState().metadata;
@@ -2192,7 +2201,7 @@ var useRegisterFieldsSlice = (appStore, id) => {
2192
2201
  init_react_import();
2193
2202
  var import_fast_equals2 = require("fast-equals");
2194
2203
  var cache = { lastChange: {} };
2195
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
2204
+ var resolveComponentData = (_0, _1, ..._2) => __async(null, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
2196
2205
  const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
2197
2206
  const resolvedItem = __spreadValues({}, item);
2198
2207
  const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
@@ -2220,11 +2229,11 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
2220
2229
  let itemWithResolvedChildren = yield mapFields(
2221
2230
  resolvedItem,
2222
2231
  {
2223
- slot: (_02) => __async(void 0, [_02], function* ({ value }) {
2232
+ slot: (_02) => __async(null, [_02], function* ({ value }) {
2224
2233
  const content = value;
2225
2234
  return yield Promise.all(
2226
2235
  content.map(
2227
- (childItem) => __async(void 0, null, function* () {
2236
+ (childItem) => __async(null, null, function* () {
2228
2237
  return (yield resolveComponentData(
2229
2238
  childItem,
2230
2239
  config,
@@ -2414,7 +2423,7 @@ var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
2414
2423
  const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
2415
2424
  return __spreadProps(__spreadValues({}, s), { state, selectedItem });
2416
2425
  }),
2417
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
2426
+ resolveComponentData: (componentData, trigger) => __async(null, null, function* () {
2418
2427
  const { config, metadata, setComponentLoading, permissions } = get();
2419
2428
  const timeouts = {};
2420
2429
  return yield resolveComponentData(
@@ -2425,7 +2434,7 @@ var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
2425
2434
  const id = "id" in item.props ? item.props.id : "root";
2426
2435
  timeouts[id] = setComponentLoading(id, true, 50);
2427
2436
  },
2428
- (item) => __async(void 0, null, function* () {
2437
+ (item) => __async(null, null, function* () {
2429
2438
  const id = "id" in item.props ? item.props.id : "root";
2430
2439
  if ("type" in item) {
2431
2440
  yield permissions.refreshPermissions({ item });
@@ -2437,7 +2446,7 @@ var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
2437
2446
  trigger
2438
2447
  );
2439
2448
  }),
2440
- resolveAndCommitData: () => __async(void 0, null, function* () {
2449
+ resolveAndCommitData: () => __async(null, null, function* () {
2441
2450
  const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
2442
2451
  walkAppState(
2443
2452
  state,
@@ -3009,7 +3018,7 @@ var collisionStore = (0, import_vanilla.createStore)(() => ({
3009
3018
 
3010
3019
  // lib/dnd/collision/dynamic/index.ts
3011
3020
  var flushNext = "";
3012
- var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input) => {
3021
+ var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => ((input) => {
3013
3022
  var _a, _b, _c, _d, _e;
3014
3023
  const { dragOperation, droppable } = input;
3015
3024
  const { position } = dragOperation;
@@ -3102,7 +3111,7 @@ var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input
3102
3111
  }
3103
3112
  collisionDebug(dragCenter, dropCenter, droppable.id.toString(), "hotpink");
3104
3113
  return null;
3105
- };
3114
+ });
3106
3115
 
3107
3116
  // components/Sortable/index.tsx
3108
3117
  var import_sortable = require("@dnd-kit/react/sortable");
@@ -3535,8 +3544,9 @@ var ArrayField = ({
3535
3544
  var _a;
3536
3545
  if (isDraggingAny) return;
3537
3546
  const existingValue = value || [];
3547
+ const defaultProps = typeof field.defaultItemProps === "function" ? field.defaultItemProps(existingValue.length) : (_a = field.defaultItemProps) != null ? _a : {};
3538
3548
  const newItem = defaultSlots(
3539
- uniqifyItem((_a = field.defaultItemProps) != null ? _a : {}),
3549
+ uniqifyItem(defaultProps),
3540
3550
  field.arrayFields
3541
3551
  );
3542
3552
  const newValue = [...existingValue, newItem];
@@ -3824,7 +3834,7 @@ var ExternalInput = ({
3824
3834
  }, [mappedData]);
3825
3835
  const [searchQuery, setSearchQuery] = (0, import_react17.useState)(field.initialQuery || "");
3826
3836
  const search = (0, import_react17.useCallback)(
3827
- (query, filters2) => __async(void 0, null, function* () {
3837
+ (query, filters2) => __async(null, null, function* () {
3828
3838
  setIsLoading(true);
3829
3839
  const cacheKey = `${id}-${query}-${JSON.stringify(filters2)}`;
3830
3840
  let listData;
@@ -4050,7 +4060,7 @@ var ExternalField = ({
4050
4060
  placeholder: ((_a = deprecatedField.adaptor) == null ? void 0 : _a.name) ? `Select from ${deprecatedField.adaptor.name}` : validField.placeholder || "Select data",
4051
4061
  mapProp: ((_b = deprecatedField.adaptor) == null ? void 0 : _b.mapProp) || validField.mapProp,
4052
4062
  mapRow: validField.mapRow,
4053
- fetchList: ((_c = deprecatedField.adaptor) == null ? void 0 : _c.fetchList) ? () => __async(void 0, null, function* () {
4063
+ fetchList: ((_c = deprecatedField.adaptor) == null ? void 0 : _c.fetchList) ? () => __async(null, null, function* () {
4054
4064
  return yield deprecatedField.adaptor.fetchList(
4055
4065
  deprecatedField.adaptorParams
4056
4066
  );
@@ -4426,6 +4436,7 @@ function AutoFieldInternal(props) {
4426
4436
  }
4427
4437
  return (_props) => null;
4428
4438
  }, [field.type]);
4439
+ const fieldKey = field.type === "custom" ? field.key : void 0;
4429
4440
  let FieldComponent = (0, import_react20.useMemo)(() => {
4430
4441
  if (field.type === "custom") {
4431
4442
  if (!field.render) {
@@ -4435,7 +4446,7 @@ function AutoFieldInternal(props) {
4435
4446
  } else if (field.type !== "slot") {
4436
4447
  return render[field.type];
4437
4448
  }
4438
- }, [field.type, render]);
4449
+ }, [field.type, fieldKey, render]);
4439
4450
  const { visible = true } = props.field;
4440
4451
  if (!visible) {
4441
4452
  return null;
@@ -5231,7 +5242,8 @@ var useMinEmptyHeight = ({
5231
5242
  }
5232
5243
  }
5233
5244
  }, [ref.current, draggedItem, onDragFinished]);
5234
- return [prevHeight || userMinEmptyHeight, isAnimating];
5245
+ const returnedMinHeight = isNaN(Number(userMinEmptyHeight)) ? userMinEmptyHeight : `${userMinEmptyHeight}px`;
5246
+ return [prevHeight ? `${prevHeight}px` : returnedMinHeight, isAnimating];
5235
5247
  };
5236
5248
 
5237
5249
  // lib/assign-refs.ts
@@ -5260,7 +5272,7 @@ var import_react27 = require("react");
5260
5272
  function useRenderedCallback(callback, deps) {
5261
5273
  const manager = (0, import_react26.useDragDropManager)();
5262
5274
  return (0, import_react27.useCallback)(
5263
- (...args) => __async(this, null, function* () {
5275
+ (...args) => __async(null, null, function* () {
5264
5276
  yield manager == null ? void 0 : manager.renderer.rendering;
5265
5277
  return callback(...args);
5266
5278
  }),
@@ -5465,8 +5477,9 @@ var Item = ({
5465
5477
  );
5466
5478
  };
5467
5479
  var SlotRender = (0, import_react31.forwardRef)(
5468
- function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
5469
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className, style, ref, children: content.map((item) => {
5480
+ function SlotRenderInternal({ className, style, content, config, metadata, as }, ref) {
5481
+ const El = as != null ? as : "div";
5482
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(El, { className, style, ref, children: content.map((item) => {
5470
5483
  if (!config.components[item.type]) {
5471
5484
  return null;
5472
5485
  }
@@ -5689,7 +5702,7 @@ var InlineTextFieldInternal = ({
5689
5702
  ref.current.replaceChildren(value);
5690
5703
  }
5691
5704
  const cleanupPortal = registerOverlayPortal(ref.current);
5692
- const handleInput = (e) => __async(void 0, null, function* () {
5705
+ const handleInput = (e) => __async(null, null, function* () {
5693
5706
  var _a2;
5694
5707
  const appStore2 = appStoreApi.getState();
5695
5708
  const node = appStore2.state.indexes.nodes[componentId];
@@ -5980,8 +5993,9 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
5980
5993
  disallow,
5981
5994
  style,
5982
5995
  className,
5983
- minEmptyHeight: userMinEmptyHeight = 128,
5984
- collisionAxis
5996
+ minEmptyHeight: userMinEmptyHeight = "128px",
5997
+ collisionAxis,
5998
+ as
5985
5999
  }, userRef) {
5986
6000
  const ctx = (0, import_react34.useContext)(dropZoneContext);
5987
6001
  const appStoreApi = useAppStoreApi();
@@ -6124,8 +6138,9 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
6124
6138
  userMinEmptyHeight,
6125
6139
  ref
6126
6140
  });
6141
+ const El = as != null ? as : "div";
6127
6142
  return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
6128
- "div",
6143
+ El,
6129
6144
  {
6130
6145
  className: `${getClassName18({
6131
6146
  isRootZone,
@@ -6141,7 +6156,7 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
6141
6156
  "data-testid": `dropzone:${zoneCompound}`,
6142
6157
  "data-puck-dropzone": zoneCompound,
6143
6158
  style: __spreadProps(__spreadValues({}, style), {
6144
- "--min-empty-height": `${minEmptyHeight}px`,
6159
+ "--min-empty-height": minEmptyHeight,
6145
6160
  backgroundColor: RENDER_DEBUG ? getRandomColor() : style == null ? void 0 : style.backgroundColor
6146
6161
  }),
6147
6162
  children: contentIdsWithPreview.map((componentId, i) => {
@@ -6188,7 +6203,7 @@ var DropZoneRenderItem = ({
6188
6203
  };
6189
6204
  var DropZoneRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(DropZoneRender, __spreadValues({}, props));
6190
6205
  var DropZoneRender = (0, import_react34.forwardRef)(
6191
- function DropZoneRenderInternal({ className, style, zone }, ref) {
6206
+ function DropZoneRenderInternal({ className, style, zone, as }, ref) {
6192
6207
  const ctx = (0, import_react34.useContext)(dropZoneContext);
6193
6208
  const { areaId = "root" } = ctx || {};
6194
6209
  const { config, data, metadata } = (0, import_react34.useContext)(renderContext);
@@ -6201,13 +6216,14 @@ var DropZoneRender = (0, import_react34.forwardRef)(
6201
6216
  }
6202
6217
  }
6203
6218
  }, [content]);
6219
+ const El = as != null ? as : "div";
6204
6220
  if (!data || !config) {
6205
6221
  return null;
6206
6222
  }
6207
6223
  if (zoneCompound !== rootDroppableId) {
6208
6224
  content = setupZone(data, zoneCompound).zones[zoneCompound];
6209
6225
  }
6210
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className, style, ref, children: content.map((item) => {
6226
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(El, { className, style, ref, children: content.map((item) => {
6211
6227
  const Component = config.components[item.type];
6212
6228
  if (Component) {
6213
6229
  return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
@@ -6513,7 +6529,8 @@ var createNestedDroppablePlugin = ({ onChange }, id) => class NestedDroppablePlu
6513
6529
 
6514
6530
  // lib/insert-component.ts
6515
6531
  init_react_import();
6516
- var insertComponent = (componentType, zone, index, appStore) => __async(void 0, null, function* () {
6532
+ var insertComponent = (componentType, zone, index, appStore) => __async(null, null, function* () {
6533
+ const { getState } = appStore;
6517
6534
  const id = generateId(componentType);
6518
6535
  const insertActionData = {
6519
6536
  type: "insert",
@@ -6522,8 +6539,9 @@ var insertComponent = (componentType, zone, index, appStore) => __async(void 0,
6522
6539
  destinationZone: zone,
6523
6540
  id
6524
6541
  };
6525
- const { state, dispatch, resolveComponentData: resolveComponentData2 } = appStore;
6526
- const insertedState = insertAction(state, insertActionData, appStore);
6542
+ const stateBefore = getState().state;
6543
+ const insertedState = insertAction(stateBefore, insertActionData, getState());
6544
+ const dispatch = getState().dispatch;
6527
6545
  dispatch(__spreadProps(__spreadValues({}, insertActionData), {
6528
6546
  // Dispatch insert rather set, as user's may rely on this via onAction
6529
6547
  // We must always record history here so the insert is added to user history
@@ -6531,23 +6549,21 @@ var insertComponent = (componentType, zone, index, appStore) => __async(void 0,
6531
6549
  // entries on insert - one for the initial insert, and one when the data resolves
6532
6550
  recordHistory: true
6533
6551
  }));
6534
- const itemSelector = {
6535
- index,
6536
- zone
6537
- };
6552
+ const itemSelector = { index, zone };
6538
6553
  dispatch({ type: "setUi", ui: { itemSelector } });
6539
6554
  const itemData = getItem(itemSelector, insertedState);
6540
- if (itemData) {
6541
- const resolved = yield resolveComponentData2(itemData, "insert");
6542
- if (resolved.didChange) {
6543
- dispatch({
6544
- type: "replace",
6545
- destinationZone: itemSelector.zone,
6546
- destinationIndex: itemSelector.index,
6547
- data: resolved.node
6548
- });
6549
- }
6550
- }
6555
+ if (!itemData) return;
6556
+ const resolveComponentData2 = getState().resolveComponentData;
6557
+ const resolved = yield resolveComponentData2(itemData, "insert");
6558
+ if (!resolved.didChange) return;
6559
+ const latestItemSelector = getSelectorForId(getState().state, id);
6560
+ if (!latestItemSelector) return;
6561
+ dispatch({
6562
+ type: "replace",
6563
+ destinationZone: latestItemSelector.zone,
6564
+ destinationIndex: latestItemSelector.index,
6565
+ data: resolved.node
6566
+ });
6551
6567
  });
6552
6568
 
6553
6569
  // components/DragDropContext/index.tsx
@@ -6784,7 +6800,7 @@ var DragDropContextClient = ({
6784
6800
  thisPreview.componentType,
6785
6801
  thisPreview.zone,
6786
6802
  thisPreview.index,
6787
- appStore.getState()
6803
+ appStore
6788
6804
  );
6789
6805
  } else if (initialSelector.current) {
6790
6806
  dispatch({
@@ -7221,49 +7237,48 @@ var DefaultFields = ({
7221
7237
  }) => {
7222
7238
  return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_jsx_runtime30.Fragment, { children });
7223
7239
  };
7224
- var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(void 0, null, function* () {
7225
- let currentProps;
7240
+ var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(null, null, function* () {
7226
7241
  const { dispatch, state, selectedItem, resolveComponentData: resolveComponentData2 } = appStore.getState();
7227
7242
  const { data, ui } = state;
7228
7243
  const { itemSelector } = ui;
7229
7244
  const rootProps = data.root.props || data.root;
7230
- if (selectedItem) {
7231
- currentProps = selectedItem.props;
7232
- } else {
7233
- currentProps = rootProps;
7234
- }
7235
- const newProps = __spreadProps(__spreadValues({}, currentProps), {
7236
- [fieldName]: value
7237
- });
7245
+ const currentProps = selectedItem ? selectedItem.props : rootProps;
7246
+ const newProps = __spreadProps(__spreadValues({}, currentProps), { [fieldName]: value });
7238
7247
  if (selectedItem && itemSelector) {
7248
+ const resolved = yield resolveComponentData2(
7249
+ __spreadProps(__spreadValues({}, selectedItem), { props: newProps }),
7250
+ "replace"
7251
+ );
7252
+ const latestSelector = getSelectorForId(
7253
+ appStore.getState().state,
7254
+ selectedItem.props.id
7255
+ );
7256
+ if (!latestSelector) return;
7239
7257
  dispatch({
7240
7258
  type: "replace",
7241
- destinationIndex: itemSelector.index,
7242
- destinationZone: itemSelector.zone || rootDroppableId,
7243
- data: (yield resolveComponentData2(
7244
- __spreadProps(__spreadValues({}, selectedItem), { props: newProps }),
7259
+ destinationIndex: latestSelector.index,
7260
+ destinationZone: latestSelector.zone || rootDroppableId,
7261
+ data: resolved.node,
7262
+ ui: updatedUi
7263
+ });
7264
+ return;
7265
+ }
7266
+ if (data.root.props) {
7267
+ dispatch({
7268
+ type: "replaceRoot",
7269
+ root: (yield resolveComponentData2(
7270
+ __spreadProps(__spreadValues({}, data.root), { props: newProps }),
7245
7271
  "replace"
7246
7272
  )).node,
7247
- ui: updatedUi
7273
+ ui: __spreadValues(__spreadValues({}, ui), updatedUi),
7274
+ recordHistory: true
7248
7275
  });
7249
- } else {
7250
- if (data.root.props) {
7251
- dispatch({
7252
- type: "replaceRoot",
7253
- root: (yield resolveComponentData2(
7254
- __spreadProps(__spreadValues({}, data.root), { props: newProps }),
7255
- "replace"
7256
- )).node,
7257
- ui: __spreadValues(__spreadValues({}, ui), updatedUi),
7258
- recordHistory: true
7259
- });
7260
- } else {
7261
- dispatch({
7262
- type: "setData",
7263
- data: { root: newProps }
7264
- });
7265
- }
7276
+ return;
7266
7277
  }
7278
+ dispatch({
7279
+ type: "setData",
7280
+ data: { root: newProps }
7281
+ });
7267
7282
  });
7268
7283
  var FieldsChild = ({ fieldName }) => {
7269
7284
  const field = useAppStore((s) => s.fields.fields[fieldName]);
@@ -7590,7 +7605,7 @@ var CopyHostStyles = ({
7590
7605
  let elements = [];
7591
7606
  const hashes = {};
7592
7607
  const lookupEl = (el) => elements.findIndex((elementMap) => elementMap.original === el);
7593
- const mirrorEl = (el, inlineStyles = false) => __async(void 0, null, function* () {
7608
+ const mirrorEl = (el, inlineStyles = false) => __async(null, null, function* () {
7594
7609
  let mirror;
7595
7610
  if (el.nodeName === "LINK" && inlineStyles) {
7596
7611
  mirror = document.createElement("style");
@@ -7622,7 +7637,7 @@ var CopyHostStyles = ({
7622
7637
  }
7623
7638
  return mirror;
7624
7639
  });
7625
- const addEl = (el) => __async(void 0, null, function* () {
7640
+ const addEl = (el) => __async(null, null, function* () {
7626
7641
  const index = lookupEl(el);
7627
7642
  if (index > -1) {
7628
7643
  if (debug)
@@ -7695,7 +7710,7 @@ var CopyHostStyles = ({
7695
7710
  const parentBody = parentDocument.getElementsByTagName("body")[0];
7696
7711
  syncAttributes(parentBody, doc.body);
7697
7712
  Promise.all(
7698
- collectedStyles.map((styleNode, i) => __async(void 0, null, function* () {
7713
+ collectedStyles.map((styleNode, i) => __async(null, null, function* () {
7699
7714
  if (styleNode.nodeName === "LINK") {
7700
7715
  const linkHref = styleNode.href;
7701
7716
  if (hrefs.indexOf(linkHref) > -1) {
@@ -8729,7 +8744,15 @@ var generateUsePuck = (store) => {
8729
8744
  selectedItem: store.selectedItem || null,
8730
8745
  getItemBySelector: (selector) => getItem(selector, store.state),
8731
8746
  getItemById: (id) => store.state.indexes.nodes[id].data,
8732
- getSelectorForId: (id) => getSelectorForId(store.state, id)
8747
+ getSelectorForId: (id) => getSelectorForId(store.state, id),
8748
+ getParentById: (id) => {
8749
+ const node = store.state.indexes.nodes[id];
8750
+ const parentId = node.parentId;
8751
+ if (parentId === null) return;
8752
+ const parentNode = store.state.indexes.nodes[parentId];
8753
+ if (!parentNode) return;
8754
+ return parentNode.data;
8755
+ }
8733
8756
  };
8734
8757
  return storeData;
8735
8758
  };
@@ -8770,7 +8793,7 @@ function createUsePuck() {
8770
8793
  }
8771
8794
  const result = (0, import_zustand6.useStore)(
8772
8795
  usePuckApi,
8773
- selector != null ? selector : (s) => s
8796
+ selector != null ? selector : ((s) => s)
8774
8797
  );
8775
8798
  return result;
8776
8799
  };
@@ -9348,7 +9371,12 @@ function PuckProvider({ children }) {
9348
9371
  });
9349
9372
  })
9350
9373
  );
9351
- const initialHistoryIndex = (_initialHistory == null ? void 0 : _initialHistory.index) || blendedHistories.length - 1;
9374
+ const initialHistoryIndex = (0, import_react60.useMemo)(() => {
9375
+ if ((_initialHistory == null ? void 0 : _initialHistory.index) !== void 0 && (_initialHistory == null ? void 0 : _initialHistory.index) >= 0 && (_initialHistory == null ? void 0 : _initialHistory.index) < blendedHistories.length) {
9376
+ return _initialHistory == null ? void 0 : _initialHistory.index;
9377
+ }
9378
+ return blendedHistories.length - 1;
9379
+ }, []);
9352
9380
  const initialAppState = blendedHistories[initialHistoryIndex].state;
9353
9381
  const loadedOverrides = useLoadedOverrides({
9354
9382
  overrides,
@@ -9407,7 +9435,7 @@ function PuckProvider({ children }) {
9407
9435
  });
9408
9436
  const previousData = (0, import_react60.useRef)(null);
9409
9437
  (0, import_react60.useEffect)(() => {
9410
- appStore.subscribe(
9438
+ return appStore.subscribe(
9411
9439
  (s) => s.state.data,
9412
9440
  (data) => {
9413
9441
  if (onChange) {
@@ -9417,7 +9445,7 @@ function PuckProvider({ children }) {
9417
9445
  }
9418
9446
  }
9419
9447
  );
9420
- }, []);
9448
+ }, [onChange]);
9421
9449
  useRegisterPermissionsSlice(appStore, permissions);
9422
9450
  const uPuckStore = useRegisterUsePuckStore(appStore);
9423
9451
  (0, import_react60.useEffect)(() => {
@@ -9734,7 +9762,7 @@ function resolveAllData(_0, _1) {
9734
9762
  return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
9735
9763
  var _a;
9736
9764
  const defaultedData = defaultData(data);
9737
- const resolveNode = (_node) => __async(this, null, function* () {
9765
+ const resolveNode = (_node) => __async(null, null, function* () {
9738
9766
  const node = toComponent(_node);
9739
9767
  onResolveStart == null ? void 0 : onResolveStart(node);
9740
9768
  const resolved = (yield resolveComponentData(
@@ -9755,13 +9783,13 @@ function resolveAllData(_0, _1) {
9755
9783
  onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
9756
9784
  return resolvedDeep;
9757
9785
  });
9758
- const processContent = (content) => __async(this, null, function* () {
9786
+ const processContent = (content) => __async(null, null, function* () {
9759
9787
  return Promise.all(content.map(resolveNode));
9760
9788
  });
9761
- const processZones = () => __async(this, null, function* () {
9789
+ const processZones = () => __async(null, null, function* () {
9762
9790
  var _a2;
9763
9791
  const zones = (_a2 = data.zones) != null ? _a2 : {};
9764
- Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
9792
+ Object.entries(zones).forEach((_02) => __async(null, [_02], function* ([zoneKey, content]) {
9765
9793
  zones[zoneKey] = yield Promise.all(content.map(resolveNode));
9766
9794
  }));
9767
9795
  return zones;
@@ -9771,7 +9799,7 @@ function resolveAllData(_0, _1) {
9771
9799
  content: yield processContent(defaultedData.content),
9772
9800
  zones: yield processZones()
9773
9801
  };
9774
- Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(this, null, function* () {
9802
+ Object.keys((_a = defaultedData.zones) != null ? _a : {}).forEach((zoneKey) => __async(null, null, function* () {
9775
9803
  const content = defaultedData.zones[zoneKey];
9776
9804
  dynamic.zones[zoneKey] = yield processContent(content);
9777
9805
  }), {});
@@ -9814,269 +9842,38 @@ classnames/index.js:
9814
9842
  *)
9815
9843
 
9816
9844
  lucide-react/dist/esm/shared/src/utils.js:
9817
- (**
9818
- * @license lucide-react v0.468.0 - ISC
9819
- *
9820
- * This source code is licensed under the ISC license.
9821
- * See the LICENSE file in the root directory of this source tree.
9822
- *)
9823
-
9824
9845
  lucide-react/dist/esm/defaultAttributes.js:
9825
- (**
9826
- * @license lucide-react v0.468.0 - ISC
9827
- *
9828
- * This source code is licensed under the ISC license.
9829
- * See the LICENSE file in the root directory of this source tree.
9830
- *)
9831
-
9832
9846
  lucide-react/dist/esm/Icon.js:
9833
- (**
9834
- * @license lucide-react v0.468.0 - ISC
9835
- *
9836
- * This source code is licensed under the ISC license.
9837
- * See the LICENSE file in the root directory of this source tree.
9838
- *)
9839
-
9840
9847
  lucide-react/dist/esm/createLucideIcon.js:
9841
- (**
9842
- * @license lucide-react v0.468.0 - ISC
9843
- *
9844
- * This source code is licensed under the ISC license.
9845
- * See the LICENSE file in the root directory of this source tree.
9846
- *)
9847
-
9848
9848
  lucide-react/dist/esm/icons/chevron-down.js:
9849
- (**
9850
- * @license lucide-react v0.468.0 - ISC
9851
- *
9852
- * This source code is licensed under the ISC license.
9853
- * See the LICENSE file in the root directory of this source tree.
9854
- *)
9855
-
9856
9849
  lucide-react/dist/esm/icons/chevron-right.js:
9857
- (**
9858
- * @license lucide-react v0.468.0 - ISC
9859
- *
9860
- * This source code is licensed under the ISC license.
9861
- * See the LICENSE file in the root directory of this source tree.
9862
- *)
9863
-
9864
9850
  lucide-react/dist/esm/icons/chevron-up.js:
9865
- (**
9866
- * @license lucide-react v0.468.0 - ISC
9867
- *
9868
- * This source code is licensed under the ISC license.
9869
- * See the LICENSE file in the root directory of this source tree.
9870
- *)
9871
-
9872
9851
  lucide-react/dist/esm/icons/circle-check-big.js:
9873
- (**
9874
- * @license lucide-react v0.468.0 - ISC
9875
- *
9876
- * This source code is licensed under the ISC license.
9877
- * See the LICENSE file in the root directory of this source tree.
9878
- *)
9879
-
9880
9852
  lucide-react/dist/esm/icons/copy.js:
9881
- (**
9882
- * @license lucide-react v0.468.0 - ISC
9883
- *
9884
- * This source code is licensed under the ISC license.
9885
- * See the LICENSE file in the root directory of this source tree.
9886
- *)
9887
-
9888
9853
  lucide-react/dist/esm/icons/corner-left-up.js:
9889
- (**
9890
- * @license lucide-react v0.468.0 - ISC
9891
- *
9892
- * This source code is licensed under the ISC license.
9893
- * See the LICENSE file in the root directory of this source tree.
9894
- *)
9895
-
9896
9854
  lucide-react/dist/esm/icons/ellipsis-vertical.js:
9897
- (**
9898
- * @license lucide-react v0.468.0 - ISC
9899
- *
9900
- * This source code is licensed under the ISC license.
9901
- * See the LICENSE file in the root directory of this source tree.
9902
- *)
9903
-
9904
9855
  lucide-react/dist/esm/icons/globe.js:
9905
- (**
9906
- * @license lucide-react v0.468.0 - ISC
9907
- *
9908
- * This source code is licensed under the ISC license.
9909
- * See the LICENSE file in the root directory of this source tree.
9910
- *)
9911
-
9912
9856
  lucide-react/dist/esm/icons/hash.js:
9913
- (**
9914
- * @license lucide-react v0.468.0 - ISC
9915
- *
9916
- * This source code is licensed under the ISC license.
9917
- * See the LICENSE file in the root directory of this source tree.
9918
- *)
9919
-
9920
9857
  lucide-react/dist/esm/icons/layers.js:
9921
- (**
9922
- * @license lucide-react v0.468.0 - ISC
9923
- *
9924
- * This source code is licensed under the ISC license.
9925
- * See the LICENSE file in the root directory of this source tree.
9926
- *)
9927
-
9928
9858
  lucide-react/dist/esm/icons/layout-grid.js:
9929
- (**
9930
- * @license lucide-react v0.468.0 - ISC
9931
- *
9932
- * This source code is licensed under the ISC license.
9933
- * See the LICENSE file in the root directory of this source tree.
9934
- *)
9935
-
9936
9859
  lucide-react/dist/esm/icons/link.js:
9937
- (**
9938
- * @license lucide-react v0.468.0 - ISC
9939
- *
9940
- * This source code is licensed under the ISC license.
9941
- * See the LICENSE file in the root directory of this source tree.
9942
- *)
9943
-
9944
9860
  lucide-react/dist/esm/icons/list.js:
9945
- (**
9946
- * @license lucide-react v0.468.0 - ISC
9947
- *
9948
- * This source code is licensed under the ISC license.
9949
- * See the LICENSE file in the root directory of this source tree.
9950
- *)
9951
-
9952
9861
  lucide-react/dist/esm/icons/lock-open.js:
9953
- (**
9954
- * @license lucide-react v0.468.0 - ISC
9955
- *
9956
- * This source code is licensed under the ISC license.
9957
- * See the LICENSE file in the root directory of this source tree.
9958
- *)
9959
-
9960
9862
  lucide-react/dist/esm/icons/lock.js:
9961
- (**
9962
- * @license lucide-react v0.468.0 - ISC
9963
- *
9964
- * This source code is licensed under the ISC license.
9965
- * See the LICENSE file in the root directory of this source tree.
9966
- *)
9967
-
9968
9863
  lucide-react/dist/esm/icons/monitor.js:
9969
- (**
9970
- * @license lucide-react v0.468.0 - ISC
9971
- *
9972
- * This source code is licensed under the ISC license.
9973
- * See the LICENSE file in the root directory of this source tree.
9974
- *)
9975
-
9976
9864
  lucide-react/dist/esm/icons/panel-left.js:
9977
- (**
9978
- * @license lucide-react v0.468.0 - ISC
9979
- *
9980
- * This source code is licensed under the ISC license.
9981
- * See the LICENSE file in the root directory of this source tree.
9982
- *)
9983
-
9984
9865
  lucide-react/dist/esm/icons/panel-right.js:
9985
- (**
9986
- * @license lucide-react v0.468.0 - ISC
9987
- *
9988
- * This source code is licensed under the ISC license.
9989
- * See the LICENSE file in the root directory of this source tree.
9990
- *)
9991
-
9992
9866
  lucide-react/dist/esm/icons/plus.js:
9993
- (**
9994
- * @license lucide-react v0.468.0 - ISC
9995
- *
9996
- * This source code is licensed under the ISC license.
9997
- * See the LICENSE file in the root directory of this source tree.
9998
- *)
9999
-
10000
9867
  lucide-react/dist/esm/icons/redo-2.js:
10001
- (**
10002
- * @license lucide-react v0.468.0 - ISC
10003
- *
10004
- * This source code is licensed under the ISC license.
10005
- * See the LICENSE file in the root directory of this source tree.
10006
- *)
10007
-
10008
9868
  lucide-react/dist/esm/icons/search.js:
10009
- (**
10010
- * @license lucide-react v0.468.0 - ISC
10011
- *
10012
- * This source code is licensed under the ISC license.
10013
- * See the LICENSE file in the root directory of this source tree.
10014
- *)
10015
-
10016
9869
  lucide-react/dist/esm/icons/sliders-horizontal.js:
10017
- (**
10018
- * @license lucide-react v0.468.0 - ISC
10019
- *
10020
- * This source code is licensed under the ISC license.
10021
- * See the LICENSE file in the root directory of this source tree.
10022
- *)
10023
-
10024
9870
  lucide-react/dist/esm/icons/smartphone.js:
10025
- (**
10026
- * @license lucide-react v0.468.0 - ISC
10027
- *
10028
- * This source code is licensed under the ISC license.
10029
- * See the LICENSE file in the root directory of this source tree.
10030
- *)
10031
-
10032
9871
  lucide-react/dist/esm/icons/tablet.js:
10033
- (**
10034
- * @license lucide-react v0.468.0 - ISC
10035
- *
10036
- * This source code is licensed under the ISC license.
10037
- * See the LICENSE file in the root directory of this source tree.
10038
- *)
10039
-
10040
9872
  lucide-react/dist/esm/icons/trash.js:
10041
- (**
10042
- * @license lucide-react v0.468.0 - ISC
10043
- *
10044
- * This source code is licensed under the ISC license.
10045
- * See the LICENSE file in the root directory of this source tree.
10046
- *)
10047
-
10048
9873
  lucide-react/dist/esm/icons/type.js:
10049
- (**
10050
- * @license lucide-react v0.468.0 - ISC
10051
- *
10052
- * This source code is licensed under the ISC license.
10053
- * See the LICENSE file in the root directory of this source tree.
10054
- *)
10055
-
10056
9874
  lucide-react/dist/esm/icons/undo-2.js:
10057
- (**
10058
- * @license lucide-react v0.468.0 - ISC
10059
- *
10060
- * This source code is licensed under the ISC license.
10061
- * See the LICENSE file in the root directory of this source tree.
10062
- *)
10063
-
10064
9875
  lucide-react/dist/esm/icons/zoom-in.js:
10065
- (**
10066
- * @license lucide-react v0.468.0 - ISC
10067
- *
10068
- * This source code is licensed under the ISC license.
10069
- * See the LICENSE file in the root directory of this source tree.
10070
- *)
10071
-
10072
9876
  lucide-react/dist/esm/icons/zoom-out.js:
10073
- (**
10074
- * @license lucide-react v0.468.0 - ISC
10075
- *
10076
- * This source code is licensed under the ISC license.
10077
- * See the LICENSE file in the root directory of this source tree.
10078
- *)
10079
-
10080
9877
  lucide-react/dist/esm/lucide-react.js:
10081
9878
  (**
10082
9879
  * @license lucide-react v0.468.0 - ISC