@measured/puck 0.21.0-canary.a5160e5d → 0.21.0-canary.af48a401

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.
@@ -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;
@@ -4806,12 +4817,14 @@ var DraggableComponent = ({
4806
4817
  }
4807
4818
  return cleanup;
4808
4819
  }, [permissions.drag, zoneCompound]);
4820
+ const [, setRerender] = (0, import_react24.useState)(0);
4809
4821
  const ref = (0, import_react24.useRef)(null);
4810
4822
  const refSetter = (0, import_react24.useCallback)(
4811
4823
  (el) => {
4812
4824
  sortableRef(el);
4813
- if (el) {
4825
+ if (ref.current !== el) {
4814
4826
  ref.current = el;
4827
+ setRerender((update) => update + 1);
4815
4828
  }
4816
4829
  },
4817
4830
  [sortableRef]
@@ -5229,7 +5242,8 @@ var useMinEmptyHeight = ({
5229
5242
  }
5230
5243
  }
5231
5244
  }, [ref.current, draggedItem, onDragFinished]);
5232
- return [prevHeight || userMinEmptyHeight, isAnimating];
5245
+ const returnedMinHeight = isNaN(Number(userMinEmptyHeight)) ? userMinEmptyHeight : `${userMinEmptyHeight}px`;
5246
+ return [prevHeight ? `${prevHeight}px` : returnedMinHeight, isAnimating];
5233
5247
  };
5234
5248
 
5235
5249
  // lib/assign-refs.ts
@@ -5258,7 +5272,7 @@ var import_react27 = require("react");
5258
5272
  function useRenderedCallback(callback, deps) {
5259
5273
  const manager = (0, import_react26.useDragDropManager)();
5260
5274
  return (0, import_react27.useCallback)(
5261
- (...args) => __async(this, null, function* () {
5275
+ (...args) => __async(null, null, function* () {
5262
5276
  yield manager == null ? void 0 : manager.renderer.rendering;
5263
5277
  return callback(...args);
5264
5278
  }),
@@ -5463,8 +5477,9 @@ var Item = ({
5463
5477
  );
5464
5478
  };
5465
5479
  var SlotRender = (0, import_react31.forwardRef)(
5466
- function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
5467
- 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) => {
5468
5483
  if (!config.components[item.type]) {
5469
5484
  return null;
5470
5485
  }
@@ -5687,7 +5702,7 @@ var InlineTextFieldInternal = ({
5687
5702
  ref.current.replaceChildren(value);
5688
5703
  }
5689
5704
  const cleanupPortal = registerOverlayPortal(ref.current);
5690
- const handleInput = (e) => __async(void 0, null, function* () {
5705
+ const handleInput = (e) => __async(null, null, function* () {
5691
5706
  var _a2;
5692
5707
  const appStore2 = appStoreApi.getState();
5693
5708
  const node = appStore2.state.indexes.nodes[componentId];
@@ -5978,8 +5993,9 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
5978
5993
  disallow,
5979
5994
  style,
5980
5995
  className,
5981
- minEmptyHeight: userMinEmptyHeight = 128,
5982
- collisionAxis
5996
+ minEmptyHeight: userMinEmptyHeight = "128px",
5997
+ collisionAxis,
5998
+ as
5983
5999
  }, userRef) {
5984
6000
  const ctx = (0, import_react34.useContext)(dropZoneContext);
5985
6001
  const appStoreApi = useAppStoreApi();
@@ -6122,8 +6138,9 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
6122
6138
  userMinEmptyHeight,
6123
6139
  ref
6124
6140
  });
6141
+ const El = as != null ? as : "div";
6125
6142
  return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
6126
- "div",
6143
+ El,
6127
6144
  {
6128
6145
  className: `${getClassName18({
6129
6146
  isRootZone,
@@ -6139,7 +6156,7 @@ var DropZoneEdit = (0, import_react34.forwardRef)(
6139
6156
  "data-testid": `dropzone:${zoneCompound}`,
6140
6157
  "data-puck-dropzone": zoneCompound,
6141
6158
  style: __spreadProps(__spreadValues({}, style), {
6142
- "--min-empty-height": `${minEmptyHeight}px`,
6159
+ "--min-empty-height": minEmptyHeight,
6143
6160
  backgroundColor: RENDER_DEBUG ? getRandomColor() : style == null ? void 0 : style.backgroundColor
6144
6161
  }),
6145
6162
  children: contentIdsWithPreview.map((componentId, i) => {
@@ -6186,7 +6203,7 @@ var DropZoneRenderItem = ({
6186
6203
  };
6187
6204
  var DropZoneRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(DropZoneRender, __spreadValues({}, props));
6188
6205
  var DropZoneRender = (0, import_react34.forwardRef)(
6189
- function DropZoneRenderInternal({ className, style, zone }, ref) {
6206
+ function DropZoneRenderInternal({ className, style, zone, as }, ref) {
6190
6207
  const ctx = (0, import_react34.useContext)(dropZoneContext);
6191
6208
  const { areaId = "root" } = ctx || {};
6192
6209
  const { config, data, metadata } = (0, import_react34.useContext)(renderContext);
@@ -6199,13 +6216,14 @@ var DropZoneRender = (0, import_react34.forwardRef)(
6199
6216
  }
6200
6217
  }
6201
6218
  }, [content]);
6219
+ const El = as != null ? as : "div";
6202
6220
  if (!data || !config) {
6203
6221
  return null;
6204
6222
  }
6205
6223
  if (zoneCompound !== rootDroppableId) {
6206
6224
  content = setupZone(data, zoneCompound).zones[zoneCompound];
6207
6225
  }
6208
- 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) => {
6209
6227
  const Component = config.components[item.type];
6210
6228
  if (Component) {
6211
6229
  return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
@@ -6511,7 +6529,8 @@ var createNestedDroppablePlugin = ({ onChange }, id) => class NestedDroppablePlu
6511
6529
 
6512
6530
  // lib/insert-component.ts
6513
6531
  init_react_import();
6514
- 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;
6515
6534
  const id = generateId(componentType);
6516
6535
  const insertActionData = {
6517
6536
  type: "insert",
@@ -6520,8 +6539,9 @@ var insertComponent = (componentType, zone, index, appStore) => __async(void 0,
6520
6539
  destinationZone: zone,
6521
6540
  id
6522
6541
  };
6523
- const { state, dispatch, resolveComponentData: resolveComponentData2 } = appStore;
6524
- const insertedState = insertAction(state, insertActionData, appStore);
6542
+ const stateBefore = getState().state;
6543
+ const insertedState = insertAction(stateBefore, insertActionData, getState());
6544
+ const dispatch = getState().dispatch;
6525
6545
  dispatch(__spreadProps(__spreadValues({}, insertActionData), {
6526
6546
  // Dispatch insert rather set, as user's may rely on this via onAction
6527
6547
  // We must always record history here so the insert is added to user history
@@ -6529,23 +6549,21 @@ var insertComponent = (componentType, zone, index, appStore) => __async(void 0,
6529
6549
  // entries on insert - one for the initial insert, and one when the data resolves
6530
6550
  recordHistory: true
6531
6551
  }));
6532
- const itemSelector = {
6533
- index,
6534
- zone
6535
- };
6552
+ const itemSelector = { index, zone };
6536
6553
  dispatch({ type: "setUi", ui: { itemSelector } });
6537
6554
  const itemData = getItem(itemSelector, insertedState);
6538
- if (itemData) {
6539
- const resolved = yield resolveComponentData2(itemData, "insert");
6540
- if (resolved.didChange) {
6541
- dispatch({
6542
- type: "replace",
6543
- destinationZone: itemSelector.zone,
6544
- destinationIndex: itemSelector.index,
6545
- data: resolved.node
6546
- });
6547
- }
6548
- }
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
+ });
6549
6567
  });
6550
6568
 
6551
6569
  // components/DragDropContext/index.tsx
@@ -6782,7 +6800,7 @@ var DragDropContextClient = ({
6782
6800
  thisPreview.componentType,
6783
6801
  thisPreview.zone,
6784
6802
  thisPreview.index,
6785
- appStore.getState()
6803
+ appStore
6786
6804
  );
6787
6805
  } else if (initialSelector.current) {
6788
6806
  dispatch({
@@ -7219,49 +7237,48 @@ var DefaultFields = ({
7219
7237
  }) => {
7220
7238
  return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(import_jsx_runtime30.Fragment, { children });
7221
7239
  };
7222
- var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(void 0, null, function* () {
7223
- let currentProps;
7240
+ var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(null, null, function* () {
7224
7241
  const { dispatch, state, selectedItem, resolveComponentData: resolveComponentData2 } = appStore.getState();
7225
7242
  const { data, ui } = state;
7226
7243
  const { itemSelector } = ui;
7227
7244
  const rootProps = data.root.props || data.root;
7228
- if (selectedItem) {
7229
- currentProps = selectedItem.props;
7230
- } else {
7231
- currentProps = rootProps;
7232
- }
7233
- const newProps = __spreadProps(__spreadValues({}, currentProps), {
7234
- [fieldName]: value
7235
- });
7245
+ const currentProps = selectedItem ? selectedItem.props : rootProps;
7246
+ const newProps = __spreadProps(__spreadValues({}, currentProps), { [fieldName]: value });
7236
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;
7237
7257
  dispatch({
7238
7258
  type: "replace",
7239
- destinationIndex: itemSelector.index,
7240
- destinationZone: itemSelector.zone || rootDroppableId,
7241
- data: (yield resolveComponentData2(
7242
- __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 }),
7243
7271
  "replace"
7244
7272
  )).node,
7245
- ui: updatedUi
7273
+ ui: __spreadValues(__spreadValues({}, ui), updatedUi),
7274
+ recordHistory: true
7246
7275
  });
7247
- } else {
7248
- if (data.root.props) {
7249
- dispatch({
7250
- type: "replaceRoot",
7251
- root: (yield resolveComponentData2(
7252
- __spreadProps(__spreadValues({}, data.root), { props: newProps }),
7253
- "replace"
7254
- )).node,
7255
- ui: __spreadValues(__spreadValues({}, ui), updatedUi),
7256
- recordHistory: true
7257
- });
7258
- } else {
7259
- dispatch({
7260
- type: "setData",
7261
- data: { root: newProps }
7262
- });
7263
- }
7276
+ return;
7264
7277
  }
7278
+ dispatch({
7279
+ type: "setData",
7280
+ data: { root: newProps }
7281
+ });
7265
7282
  });
7266
7283
  var FieldsChild = ({ fieldName }) => {
7267
7284
  const field = useAppStore((s) => s.fields.fields[fieldName]);
@@ -7588,7 +7605,7 @@ var CopyHostStyles = ({
7588
7605
  let elements = [];
7589
7606
  const hashes = {};
7590
7607
  const lookupEl = (el) => elements.findIndex((elementMap) => elementMap.original === el);
7591
- const mirrorEl = (el, inlineStyles = false) => __async(void 0, null, function* () {
7608
+ const mirrorEl = (el, inlineStyles = false) => __async(null, null, function* () {
7592
7609
  let mirror;
7593
7610
  if (el.nodeName === "LINK" && inlineStyles) {
7594
7611
  mirror = document.createElement("style");
@@ -7620,7 +7637,7 @@ var CopyHostStyles = ({
7620
7637
  }
7621
7638
  return mirror;
7622
7639
  });
7623
- const addEl = (el) => __async(void 0, null, function* () {
7640
+ const addEl = (el) => __async(null, null, function* () {
7624
7641
  const index = lookupEl(el);
7625
7642
  if (index > -1) {
7626
7643
  if (debug)
@@ -7693,7 +7710,7 @@ var CopyHostStyles = ({
7693
7710
  const parentBody = parentDocument.getElementsByTagName("body")[0];
7694
7711
  syncAttributes(parentBody, doc.body);
7695
7712
  Promise.all(
7696
- collectedStyles.map((styleNode, i) => __async(void 0, null, function* () {
7713
+ collectedStyles.map((styleNode, i) => __async(null, null, function* () {
7697
7714
  if (styleNode.nodeName === "LINK") {
7698
7715
  const linkHref = styleNode.href;
7699
7716
  if (hrefs.indexOf(linkHref) > -1) {
@@ -8727,7 +8744,15 @@ var generateUsePuck = (store) => {
8727
8744
  selectedItem: store.selectedItem || null,
8728
8745
  getItemBySelector: (selector) => getItem(selector, store.state),
8729
8746
  getItemById: (id) => store.state.indexes.nodes[id].data,
8730
- 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
+ }
8731
8756
  };
8732
8757
  return storeData;
8733
8758
  };
@@ -8768,7 +8793,7 @@ function createUsePuck() {
8768
8793
  }
8769
8794
  const result = (0, import_zustand6.useStore)(
8770
8795
  usePuckApi,
8771
- selector != null ? selector : (s) => s
8796
+ selector != null ? selector : ((s) => s)
8772
8797
  );
8773
8798
  return result;
8774
8799
  };
@@ -9346,7 +9371,12 @@ function PuckProvider({ children }) {
9346
9371
  });
9347
9372
  })
9348
9373
  );
9349
- 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
+ }, []);
9350
9380
  const initialAppState = blendedHistories[initialHistoryIndex].state;
9351
9381
  const loadedOverrides = useLoadedOverrides({
9352
9382
  overrides,
@@ -9405,7 +9435,7 @@ function PuckProvider({ children }) {
9405
9435
  });
9406
9436
  const previousData = (0, import_react60.useRef)(null);
9407
9437
  (0, import_react60.useEffect)(() => {
9408
- appStore.subscribe(
9438
+ return appStore.subscribe(
9409
9439
  (s) => s.state.data,
9410
9440
  (data) => {
9411
9441
  if (onChange) {
@@ -9415,7 +9445,7 @@ function PuckProvider({ children }) {
9415
9445
  }
9416
9446
  }
9417
9447
  );
9418
- }, []);
9448
+ }, [onChange]);
9419
9449
  useRegisterPermissionsSlice(appStore, permissions);
9420
9450
  const uPuckStore = useRegisterUsePuckStore(appStore);
9421
9451
  (0, import_react60.useEffect)(() => {
@@ -9732,7 +9762,7 @@ function resolveAllData(_0, _1) {
9732
9762
  return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
9733
9763
  var _a;
9734
9764
  const defaultedData = defaultData(data);
9735
- const resolveNode = (_node) => __async(this, null, function* () {
9765
+ const resolveNode = (_node) => __async(null, null, function* () {
9736
9766
  const node = toComponent(_node);
9737
9767
  onResolveStart == null ? void 0 : onResolveStart(node);
9738
9768
  const resolved = (yield resolveComponentData(
@@ -9753,13 +9783,13 @@ function resolveAllData(_0, _1) {
9753
9783
  onResolveEnd == null ? void 0 : onResolveEnd(toComponent(resolvedDeep));
9754
9784
  return resolvedDeep;
9755
9785
  });
9756
- const processContent = (content) => __async(this, null, function* () {
9786
+ const processContent = (content) => __async(null, null, function* () {
9757
9787
  return Promise.all(content.map(resolveNode));
9758
9788
  });
9759
- const processZones = () => __async(this, null, function* () {
9789
+ const processZones = () => __async(null, null, function* () {
9760
9790
  var _a2;
9761
9791
  const zones = (_a2 = data.zones) != null ? _a2 : {};
9762
- Object.entries(zones).forEach((_02) => __async(this, [_02], function* ([zoneKey, content]) {
9792
+ Object.entries(zones).forEach((_02) => __async(null, [_02], function* ([zoneKey, content]) {
9763
9793
  zones[zoneKey] = yield Promise.all(content.map(resolveNode));
9764
9794
  }));
9765
9795
  return zones;
@@ -9769,7 +9799,7 @@ function resolveAllData(_0, _1) {
9769
9799
  content: yield processContent(defaultedData.content),
9770
9800
  zones: yield processZones()
9771
9801
  };
9772
- 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* () {
9773
9803
  const content = defaultedData.zones[zoneKey];
9774
9804
  dynamic.zones[zoneKey] = yield processContent(content);
9775
9805
  }), {});
@@ -9812,269 +9842,38 @@ classnames/index.js:
9812
9842
  *)
9813
9843
 
9814
9844
  lucide-react/dist/esm/shared/src/utils.js:
9815
- (**
9816
- * @license lucide-react v0.468.0 - ISC
9817
- *
9818
- * This source code is licensed under the ISC license.
9819
- * See the LICENSE file in the root directory of this source tree.
9820
- *)
9821
-
9822
9845
  lucide-react/dist/esm/defaultAttributes.js:
9823
- (**
9824
- * @license lucide-react v0.468.0 - ISC
9825
- *
9826
- * This source code is licensed under the ISC license.
9827
- * See the LICENSE file in the root directory of this source tree.
9828
- *)
9829
-
9830
9846
  lucide-react/dist/esm/Icon.js:
9831
- (**
9832
- * @license lucide-react v0.468.0 - ISC
9833
- *
9834
- * This source code is licensed under the ISC license.
9835
- * See the LICENSE file in the root directory of this source tree.
9836
- *)
9837
-
9838
9847
  lucide-react/dist/esm/createLucideIcon.js:
9839
- (**
9840
- * @license lucide-react v0.468.0 - ISC
9841
- *
9842
- * This source code is licensed under the ISC license.
9843
- * See the LICENSE file in the root directory of this source tree.
9844
- *)
9845
-
9846
9848
  lucide-react/dist/esm/icons/chevron-down.js:
9847
- (**
9848
- * @license lucide-react v0.468.0 - ISC
9849
- *
9850
- * This source code is licensed under the ISC license.
9851
- * See the LICENSE file in the root directory of this source tree.
9852
- *)
9853
-
9854
9849
  lucide-react/dist/esm/icons/chevron-right.js:
9855
- (**
9856
- * @license lucide-react v0.468.0 - ISC
9857
- *
9858
- * This source code is licensed under the ISC license.
9859
- * See the LICENSE file in the root directory of this source tree.
9860
- *)
9861
-
9862
9850
  lucide-react/dist/esm/icons/chevron-up.js:
9863
- (**
9864
- * @license lucide-react v0.468.0 - ISC
9865
- *
9866
- * This source code is licensed under the ISC license.
9867
- * See the LICENSE file in the root directory of this source tree.
9868
- *)
9869
-
9870
9851
  lucide-react/dist/esm/icons/circle-check-big.js:
9871
- (**
9872
- * @license lucide-react v0.468.0 - ISC
9873
- *
9874
- * This source code is licensed under the ISC license.
9875
- * See the LICENSE file in the root directory of this source tree.
9876
- *)
9877
-
9878
9852
  lucide-react/dist/esm/icons/copy.js:
9879
- (**
9880
- * @license lucide-react v0.468.0 - ISC
9881
- *
9882
- * This source code is licensed under the ISC license.
9883
- * See the LICENSE file in the root directory of this source tree.
9884
- *)
9885
-
9886
9853
  lucide-react/dist/esm/icons/corner-left-up.js:
9887
- (**
9888
- * @license lucide-react v0.468.0 - ISC
9889
- *
9890
- * This source code is licensed under the ISC license.
9891
- * See the LICENSE file in the root directory of this source tree.
9892
- *)
9893
-
9894
9854
  lucide-react/dist/esm/icons/ellipsis-vertical.js:
9895
- (**
9896
- * @license lucide-react v0.468.0 - ISC
9897
- *
9898
- * This source code is licensed under the ISC license.
9899
- * See the LICENSE file in the root directory of this source tree.
9900
- *)
9901
-
9902
9855
  lucide-react/dist/esm/icons/globe.js:
9903
- (**
9904
- * @license lucide-react v0.468.0 - ISC
9905
- *
9906
- * This source code is licensed under the ISC license.
9907
- * See the LICENSE file in the root directory of this source tree.
9908
- *)
9909
-
9910
9856
  lucide-react/dist/esm/icons/hash.js:
9911
- (**
9912
- * @license lucide-react v0.468.0 - ISC
9913
- *
9914
- * This source code is licensed under the ISC license.
9915
- * See the LICENSE file in the root directory of this source tree.
9916
- *)
9917
-
9918
9857
  lucide-react/dist/esm/icons/layers.js:
9919
- (**
9920
- * @license lucide-react v0.468.0 - ISC
9921
- *
9922
- * This source code is licensed under the ISC license.
9923
- * See the LICENSE file in the root directory of this source tree.
9924
- *)
9925
-
9926
9858
  lucide-react/dist/esm/icons/layout-grid.js:
9927
- (**
9928
- * @license lucide-react v0.468.0 - ISC
9929
- *
9930
- * This source code is licensed under the ISC license.
9931
- * See the LICENSE file in the root directory of this source tree.
9932
- *)
9933
-
9934
9859
  lucide-react/dist/esm/icons/link.js:
9935
- (**
9936
- * @license lucide-react v0.468.0 - ISC
9937
- *
9938
- * This source code is licensed under the ISC license.
9939
- * See the LICENSE file in the root directory of this source tree.
9940
- *)
9941
-
9942
9860
  lucide-react/dist/esm/icons/list.js:
9943
- (**
9944
- * @license lucide-react v0.468.0 - ISC
9945
- *
9946
- * This source code is licensed under the ISC license.
9947
- * See the LICENSE file in the root directory of this source tree.
9948
- *)
9949
-
9950
9861
  lucide-react/dist/esm/icons/lock-open.js:
9951
- (**
9952
- * @license lucide-react v0.468.0 - ISC
9953
- *
9954
- * This source code is licensed under the ISC license.
9955
- * See the LICENSE file in the root directory of this source tree.
9956
- *)
9957
-
9958
9862
  lucide-react/dist/esm/icons/lock.js:
9959
- (**
9960
- * @license lucide-react v0.468.0 - ISC
9961
- *
9962
- * This source code is licensed under the ISC license.
9963
- * See the LICENSE file in the root directory of this source tree.
9964
- *)
9965
-
9966
9863
  lucide-react/dist/esm/icons/monitor.js:
9967
- (**
9968
- * @license lucide-react v0.468.0 - ISC
9969
- *
9970
- * This source code is licensed under the ISC license.
9971
- * See the LICENSE file in the root directory of this source tree.
9972
- *)
9973
-
9974
9864
  lucide-react/dist/esm/icons/panel-left.js:
9975
- (**
9976
- * @license lucide-react v0.468.0 - ISC
9977
- *
9978
- * This source code is licensed under the ISC license.
9979
- * See the LICENSE file in the root directory of this source tree.
9980
- *)
9981
-
9982
9865
  lucide-react/dist/esm/icons/panel-right.js:
9983
- (**
9984
- * @license lucide-react v0.468.0 - ISC
9985
- *
9986
- * This source code is licensed under the ISC license.
9987
- * See the LICENSE file in the root directory of this source tree.
9988
- *)
9989
-
9990
9866
  lucide-react/dist/esm/icons/plus.js:
9991
- (**
9992
- * @license lucide-react v0.468.0 - ISC
9993
- *
9994
- * This source code is licensed under the ISC license.
9995
- * See the LICENSE file in the root directory of this source tree.
9996
- *)
9997
-
9998
9867
  lucide-react/dist/esm/icons/redo-2.js:
9999
- (**
10000
- * @license lucide-react v0.468.0 - ISC
10001
- *
10002
- * This source code is licensed under the ISC license.
10003
- * See the LICENSE file in the root directory of this source tree.
10004
- *)
10005
-
10006
9868
  lucide-react/dist/esm/icons/search.js:
10007
- (**
10008
- * @license lucide-react v0.468.0 - ISC
10009
- *
10010
- * This source code is licensed under the ISC license.
10011
- * See the LICENSE file in the root directory of this source tree.
10012
- *)
10013
-
10014
9869
  lucide-react/dist/esm/icons/sliders-horizontal.js:
10015
- (**
10016
- * @license lucide-react v0.468.0 - ISC
10017
- *
10018
- * This source code is licensed under the ISC license.
10019
- * See the LICENSE file in the root directory of this source tree.
10020
- *)
10021
-
10022
9870
  lucide-react/dist/esm/icons/smartphone.js:
10023
- (**
10024
- * @license lucide-react v0.468.0 - ISC
10025
- *
10026
- * This source code is licensed under the ISC license.
10027
- * See the LICENSE file in the root directory of this source tree.
10028
- *)
10029
-
10030
9871
  lucide-react/dist/esm/icons/tablet.js:
10031
- (**
10032
- * @license lucide-react v0.468.0 - ISC
10033
- *
10034
- * This source code is licensed under the ISC license.
10035
- * See the LICENSE file in the root directory of this source tree.
10036
- *)
10037
-
10038
9872
  lucide-react/dist/esm/icons/trash.js:
10039
- (**
10040
- * @license lucide-react v0.468.0 - ISC
10041
- *
10042
- * This source code is licensed under the ISC license.
10043
- * See the LICENSE file in the root directory of this source tree.
10044
- *)
10045
-
10046
9873
  lucide-react/dist/esm/icons/type.js:
10047
- (**
10048
- * @license lucide-react v0.468.0 - ISC
10049
- *
10050
- * This source code is licensed under the ISC license.
10051
- * See the LICENSE file in the root directory of this source tree.
10052
- *)
10053
-
10054
9874
  lucide-react/dist/esm/icons/undo-2.js:
10055
- (**
10056
- * @license lucide-react v0.468.0 - ISC
10057
- *
10058
- * This source code is licensed under the ISC license.
10059
- * See the LICENSE file in the root directory of this source tree.
10060
- *)
10061
-
10062
9875
  lucide-react/dist/esm/icons/zoom-in.js:
10063
- (**
10064
- * @license lucide-react v0.468.0 - ISC
10065
- *
10066
- * This source code is licensed under the ISC license.
10067
- * See the LICENSE file in the root directory of this source tree.
10068
- *)
10069
-
10070
9876
  lucide-react/dist/esm/icons/zoom-out.js:
10071
- (**
10072
- * @license lucide-react v0.468.0 - ISC
10073
- *
10074
- * This source code is licensed under the ISC license.
10075
- * See the LICENSE file in the root directory of this source tree.
10076
- *)
10077
-
10078
9877
  lucide-react/dist/esm/lucide-react.js:
10079
9878
  (**
10080
9879
  * @license lucide-react v0.468.0 - ISC