@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.
@@ -25,7 +25,7 @@ import {
25
25
  walkAppState,
26
26
  walkField,
27
27
  walkTree
28
- } from "./chunk-VBJEDLUM.mjs";
28
+ } from "./chunk-JA7SEUEH.mjs";
29
29
 
30
30
  // ../../node_modules/classnames/index.js
31
31
  var require_classnames = __commonJS({
@@ -1071,29 +1071,37 @@ var flattenData = (state, config) => {
1071
1071
 
1072
1072
  // store/slices/permissions.ts
1073
1073
  var createPermissionsSlice = (set, get) => {
1074
- const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1074
+ const resolvePermissions = (..._0) => __async(null, [..._0], function* (params = {}, force) {
1075
1075
  const { state, permissions, config } = get();
1076
1076
  const { cache, globalPermissions } = permissions;
1077
- const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1078
- var _a, _b, _c;
1077
+ const resolvePermissionsForItem = (item2, force2 = false) => __async(null, null, function* () {
1078
+ var _a, _b;
1079
1079
  const { config: config2, state: appState, setComponentLoading } = get();
1080
+ const itemCache = cache[item2.props.id];
1081
+ const nodes = appState.indexes.nodes;
1082
+ const parentId = (_a = nodes[item2.props.id]) == null ? void 0 : _a.parentId;
1083
+ const parentNode = parentId ? nodes[parentId] : null;
1084
+ const parentData = (_b = parentNode == null ? void 0 : parentNode.data) != null ? _b : null;
1080
1085
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1081
1086
  if (!componentConfig) {
1082
1087
  return;
1083
1088
  }
1084
1089
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1085
1090
  if (componentConfig.resolvePermissions) {
1086
- const changed = getChanged(item2, (_a = cache[item2.props.id]) == null ? void 0 : _a.lastData);
1087
- if (Object.values(changed).some((el) => el === true) || force2) {
1091
+ const changed = getChanged(item2, itemCache == null ? void 0 : itemCache.lastData);
1092
+ const propsChanged = Object.values(changed).some((el) => el === true);
1093
+ const parentChanged = (itemCache == null ? void 0 : itemCache.lastParentId) !== parentId;
1094
+ if (propsChanged || parentChanged || force2) {
1088
1095
  const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1089
1096
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1090
1097
  item2,
1091
1098
  {
1092
1099
  changed,
1093
- lastPermissions: ((_b = cache[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1100
+ lastPermissions: (itemCache == null ? void 0 : itemCache.lastPermissions) || null,
1094
1101
  permissions: initialPermissions,
1095
1102
  appState: makeStatePublic(appState),
1096
- lastData: ((_c = cache[item2.props.id]) == null ? void 0 : _c.lastData) || null
1103
+ lastData: (itemCache == null ? void 0 : itemCache.lastData) || null,
1104
+ parent: parentData
1097
1105
  }
1098
1106
  );
1099
1107
  const latest = get().permissions;
@@ -1101,6 +1109,7 @@ var createPermissionsSlice = (set, get) => {
1101
1109
  permissions: __spreadProps(__spreadValues({}, latest), {
1102
1110
  cache: __spreadProps(__spreadValues({}, latest.cache), {
1103
1111
  [item2.props.id]: {
1112
+ lastParentId: parentId,
1104
1113
  lastData: item2,
1105
1114
  lastPermissions: resolvedPermissions
1106
1115
  }
@@ -1114,9 +1123,9 @@ var createPermissionsSlice = (set, get) => {
1114
1123
  }
1115
1124
  }
1116
1125
  });
1117
- const resolveDataForRoot = (force2 = false) => {
1126
+ const resolvePermissionsForRoot = (force2 = false) => {
1118
1127
  const { state: appState } = get();
1119
- resolveDataForItem(
1128
+ resolvePermissionsForItem(
1120
1129
  // Shim the root data in by conforming to component data shape
1121
1130
  {
1122
1131
  type: "root",
@@ -1127,16 +1136,16 @@ var createPermissionsSlice = (set, get) => {
1127
1136
  };
1128
1137
  const { item, type, root } = params;
1129
1138
  if (item) {
1130
- yield resolveDataForItem(item, force);
1139
+ yield resolvePermissionsForItem(item, force);
1131
1140
  } else if (type) {
1132
- flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1133
- yield resolveDataForItem(item2, force);
1141
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(null, null, function* () {
1142
+ yield resolvePermissionsForItem(item2, force);
1134
1143
  }));
1135
1144
  } else if (root) {
1136
- resolveDataForRoot(force);
1145
+ resolvePermissionsForRoot(force);
1137
1146
  } else {
1138
- flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1139
- yield resolveDataForItem(item2, force);
1147
+ flattenData(state, config).map((item2) => __async(null, null, function* () {
1148
+ yield resolvePermissionsForItem(item2, force);
1140
1149
  }));
1141
1150
  }
1142
1151
  });
@@ -1216,7 +1225,7 @@ var createFieldsSlice = (_set, _get) => {
1216
1225
  };
1217
1226
  var useRegisterFieldsSlice = (appStore, id) => {
1218
1227
  const resolveFields = useCallback(
1219
- (reset) => __async(void 0, null, function* () {
1228
+ (reset) => __async(null, null, function* () {
1220
1229
  var _a, _b;
1221
1230
  const { fields, lastResolvedData } = appStore.getState().fields;
1222
1231
  const metadata = appStore.getState().metadata;
@@ -1416,7 +1425,7 @@ var createAppStore = (initialAppStore) => create2()(
1416
1425
  const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1417
1426
  return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1418
1427
  }),
1419
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1428
+ resolveComponentData: (componentData, trigger) => __async(null, null, function* () {
1420
1429
  const { config, metadata, setComponentLoading, permissions } = get();
1421
1430
  const timeouts = {};
1422
1431
  return yield resolveComponentData(
@@ -1427,7 +1436,7 @@ var createAppStore = (initialAppStore) => create2()(
1427
1436
  const id = "id" in item.props ? item.props.id : "root";
1428
1437
  timeouts[id] = setComponentLoading(id, true, 50);
1429
1438
  },
1430
- (item) => __async(void 0, null, function* () {
1439
+ (item) => __async(null, null, function* () {
1431
1440
  const id = "id" in item.props ? item.props.id : "root";
1432
1441
  if ("type" in item) {
1433
1442
  yield permissions.refreshPermissions({ item });
@@ -1439,7 +1448,7 @@ var createAppStore = (initialAppStore) => create2()(
1439
1448
  trigger
1440
1449
  );
1441
1450
  }),
1442
- resolveAndCommitData: () => __async(void 0, null, function* () {
1451
+ resolveAndCommitData: () => __async(null, null, function* () {
1443
1452
  const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1444
1453
  walkAppState(
1445
1454
  state,
@@ -2460,7 +2469,7 @@ var collisionStore = createStore(() => ({
2460
2469
 
2461
2470
  // lib/dnd/collision/dynamic/index.ts
2462
2471
  var flushNext = "";
2463
- var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input) => {
2472
+ var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => ((input) => {
2464
2473
  var _a, _b, _c, _d, _e;
2465
2474
  const { dragOperation, droppable } = input;
2466
2475
  const { position } = dragOperation;
@@ -2553,7 +2562,7 @@ var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input
2553
2562
  }
2554
2563
  collisionDebug(dragCenter, dropCenter, droppable.id.toString(), "hotpink");
2555
2564
  return null;
2556
- };
2565
+ });
2557
2566
 
2558
2567
  // components/Sortable/index.tsx
2559
2568
  import { useSortable } from "@dnd-kit/react/sortable";
@@ -2986,8 +2995,9 @@ var ArrayField = ({
2986
2995
  var _a;
2987
2996
  if (isDraggingAny) return;
2988
2997
  const existingValue = value || [];
2998
+ const defaultProps = typeof field.defaultItemProps === "function" ? field.defaultItemProps(existingValue.length) : (_a = field.defaultItemProps) != null ? _a : {};
2989
2999
  const newItem = defaultSlots(
2990
- uniqifyItem((_a = field.defaultItemProps) != null ? _a : {}),
3000
+ uniqifyItem(defaultProps),
2991
3001
  field.arrayFields
2992
3002
  );
2993
3003
  const newValue = [...existingValue, newItem];
@@ -3191,7 +3201,7 @@ var ExternalInput = ({
3191
3201
  }, [mappedData]);
3192
3202
  const [searchQuery, setSearchQuery] = useState6(field.initialQuery || "");
3193
3203
  const search = useCallback3(
3194
- (query, filters2) => __async(void 0, null, function* () {
3204
+ (query, filters2) => __async(null, null, function* () {
3195
3205
  setIsLoading(true);
3196
3206
  const cacheKey = `${id}-${query}-${JSON.stringify(filters2)}`;
3197
3207
  let listData;
@@ -3417,7 +3427,7 @@ var ExternalField = ({
3417
3427
  placeholder: ((_a = deprecatedField.adaptor) == null ? void 0 : _a.name) ? `Select from ${deprecatedField.adaptor.name}` : validField.placeholder || "Select data",
3418
3428
  mapProp: ((_b = deprecatedField.adaptor) == null ? void 0 : _b.mapProp) || validField.mapProp,
3419
3429
  mapRow: validField.mapRow,
3420
- fetchList: ((_c = deprecatedField.adaptor) == null ? void 0 : _c.fetchList) ? () => __async(void 0, null, function* () {
3430
+ fetchList: ((_c = deprecatedField.adaptor) == null ? void 0 : _c.fetchList) ? () => __async(null, null, function* () {
3421
3431
  return yield deprecatedField.adaptor.fetchList(
3422
3432
  deprecatedField.adaptorParams
3423
3433
  );
@@ -3793,6 +3803,7 @@ function AutoFieldInternal(props) {
3793
3803
  }
3794
3804
  return (_props) => null;
3795
3805
  }, [field.type]);
3806
+ const fieldKey = field.type === "custom" ? field.key : void 0;
3796
3807
  let FieldComponent = useMemo3(() => {
3797
3808
  if (field.type === "custom") {
3798
3809
  if (!field.render) {
@@ -3802,7 +3813,7 @@ function AutoFieldInternal(props) {
3802
3813
  } else if (field.type !== "slot") {
3803
3814
  return render[field.type];
3804
3815
  }
3805
- }, [field.type, render]);
3816
+ }, [field.type, fieldKey, render]);
3806
3817
  const { visible = true } = props.field;
3807
3818
  if (!visible) {
3808
3819
  return null;
@@ -4180,12 +4191,14 @@ var DraggableComponent = ({
4180
4191
  }
4181
4192
  return cleanup;
4182
4193
  }, [permissions.drag, zoneCompound]);
4194
+ const [, setRerender] = useState10(0);
4183
4195
  const ref = useRef2(null);
4184
4196
  const refSetter = useCallback7(
4185
4197
  (el) => {
4186
4198
  sortableRef(el);
4187
- if (el) {
4199
+ if (ref.current !== el) {
4188
4200
  ref.current = el;
4201
+ setRerender((update) => update + 1);
4189
4202
  }
4190
4203
  },
4191
4204
  [sortableRef]
@@ -4840,7 +4853,20 @@ var createNestedDroppablePlugin = ({ onChange }, id) => class NestedDroppablePlu
4840
4853
 
4841
4854
  // lib/insert-component.ts
4842
4855
  init_react_import();
4843
- var insertComponent = (componentType, zone, index, appStore) => __async(void 0, null, function* () {
4856
+
4857
+ // lib/get-selector-for-id.ts
4858
+ init_react_import();
4859
+ var getSelectorForId = (state, id) => {
4860
+ const node = state.indexes.nodes[id];
4861
+ if (!node) return;
4862
+ const zoneCompound = `${node.parentId}:${node.zone}`;
4863
+ const index = state.indexes.zones[zoneCompound].contentIds.indexOf(id);
4864
+ return { zone: zoneCompound, index };
4865
+ };
4866
+
4867
+ // lib/insert-component.ts
4868
+ var insertComponent = (componentType, zone, index, appStore) => __async(null, null, function* () {
4869
+ const { getState } = appStore;
4844
4870
  const id = generateId(componentType);
4845
4871
  const insertActionData = {
4846
4872
  type: "insert",
@@ -4849,8 +4875,9 @@ var insertComponent = (componentType, zone, index, appStore) => __async(void 0,
4849
4875
  destinationZone: zone,
4850
4876
  id
4851
4877
  };
4852
- const { state, dispatch, resolveComponentData: resolveComponentData2 } = appStore;
4853
- const insertedState = insertAction(state, insertActionData, appStore);
4878
+ const stateBefore = getState().state;
4879
+ const insertedState = insertAction(stateBefore, insertActionData, getState());
4880
+ const dispatch = getState().dispatch;
4854
4881
  dispatch(__spreadProps(__spreadValues({}, insertActionData), {
4855
4882
  // Dispatch insert rather set, as user's may rely on this via onAction
4856
4883
  // We must always record history here so the insert is added to user history
@@ -4858,23 +4885,21 @@ var insertComponent = (componentType, zone, index, appStore) => __async(void 0,
4858
4885
  // entries on insert - one for the initial insert, and one when the data resolves
4859
4886
  recordHistory: true
4860
4887
  }));
4861
- const itemSelector = {
4862
- index,
4863
- zone
4864
- };
4888
+ const itemSelector = { index, zone };
4865
4889
  dispatch({ type: "setUi", ui: { itemSelector } });
4866
4890
  const itemData = getItem(itemSelector, insertedState);
4867
- if (itemData) {
4868
- const resolved = yield resolveComponentData2(itemData, "insert");
4869
- if (resolved.didChange) {
4870
- dispatch({
4871
- type: "replace",
4872
- destinationZone: itemSelector.zone,
4873
- destinationIndex: itemSelector.index,
4874
- data: resolved.node
4875
- });
4876
- }
4877
- }
4891
+ if (!itemData) return;
4892
+ const resolveComponentData2 = getState().resolveComponentData;
4893
+ const resolved = yield resolveComponentData2(itemData, "insert");
4894
+ if (!resolved.didChange) return;
4895
+ const latestItemSelector = getSelectorForId(getState().state, id);
4896
+ if (!latestItemSelector) return;
4897
+ dispatch({
4898
+ type: "replace",
4899
+ destinationZone: latestItemSelector.zone,
4900
+ destinationIndex: latestItemSelector.index,
4901
+ data: resolved.node
4902
+ });
4878
4903
  });
4879
4904
 
4880
4905
  // components/DragDropContext/index.tsx
@@ -5111,7 +5136,7 @@ var DragDropContextClient = ({
5111
5136
  thisPreview.componentType,
5112
5137
  thisPreview.zone,
5113
5138
  thisPreview.index,
5114
- appStore.getState()
5139
+ appStore
5115
5140
  );
5116
5141
  } else if (initialSelector.current) {
5117
5142
  dispatch({
@@ -5495,7 +5520,8 @@ var useMinEmptyHeight = ({
5495
5520
  }
5496
5521
  }
5497
5522
  }, [ref.current, draggedItem, onDragFinished]);
5498
- return [prevHeight || userMinEmptyHeight, isAnimating];
5523
+ const returnedMinHeight = isNaN(Number(userMinEmptyHeight)) ? userMinEmptyHeight : `${userMinEmptyHeight}px`;
5524
+ return [prevHeight ? `${prevHeight}px` : returnedMinHeight, isAnimating];
5499
5525
  };
5500
5526
 
5501
5527
  // lib/assign-refs.ts
@@ -5524,7 +5550,7 @@ import { useCallback as useCallback9 } from "react";
5524
5550
  function useRenderedCallback(callback, deps) {
5525
5551
  const manager = useDragDropManager();
5526
5552
  return useCallback9(
5527
- (...args) => __async(this, null, function* () {
5553
+ (...args) => __async(null, null, function* () {
5528
5554
  yield manager == null ? void 0 : manager.renderer.rendering;
5529
5555
  return callback(...args);
5530
5556
  }),
@@ -5753,16 +5779,6 @@ function setDeep(node, path, newVal) {
5753
5779
  return __spreadValues(__spreadValues({}, node), newNode);
5754
5780
  }
5755
5781
 
5756
- // lib/get-selector-for-id.ts
5757
- init_react_import();
5758
- var getSelectorForId = (state, id) => {
5759
- const node = state.indexes.nodes[id];
5760
- if (!node) return;
5761
- const zoneCompound = `${node.parentId}:${node.zone}`;
5762
- const index = state.indexes.zones[zoneCompound].contentIds.indexOf(id);
5763
- return { zone: zoneCompound, index };
5764
- };
5765
-
5766
5782
  // components/InlineTextField/index.tsx
5767
5783
  import { jsx as jsx24 } from "react/jsx-runtime";
5768
5784
  var getClassName18 = get_class_name_factory_default("InlineTextField", styles_module_default13);
@@ -5791,7 +5807,7 @@ var InlineTextFieldInternal = ({
5791
5807
  ref.current.replaceChildren(value);
5792
5808
  }
5793
5809
  const cleanupPortal = registerOverlayPortal(ref.current);
5794
- const handleInput = (e) => __async(void 0, null, function* () {
5810
+ const handleInput = (e) => __async(null, null, function* () {
5795
5811
  var _a2;
5796
5812
  const appStore2 = appStoreApi.getState();
5797
5813
  const node = appStore2.state.indexes.nodes[componentId];
@@ -6082,8 +6098,9 @@ var DropZoneEdit = forwardRef3(
6082
6098
  disallow,
6083
6099
  style,
6084
6100
  className,
6085
- minEmptyHeight: userMinEmptyHeight = 128,
6086
- collisionAxis
6101
+ minEmptyHeight: userMinEmptyHeight = "128px",
6102
+ collisionAxis,
6103
+ as
6087
6104
  }, userRef) {
6088
6105
  const ctx = useContext8(dropZoneContext);
6089
6106
  const appStoreApi = useAppStoreApi();
@@ -6226,8 +6243,9 @@ var DropZoneEdit = forwardRef3(
6226
6243
  userMinEmptyHeight,
6227
6244
  ref
6228
6245
  });
6246
+ const El = as != null ? as : "div";
6229
6247
  return /* @__PURE__ */ jsx26(
6230
- "div",
6248
+ El,
6231
6249
  {
6232
6250
  className: `${getClassName19({
6233
6251
  isRootZone,
@@ -6243,7 +6261,7 @@ var DropZoneEdit = forwardRef3(
6243
6261
  "data-testid": `dropzone:${zoneCompound}`,
6244
6262
  "data-puck-dropzone": zoneCompound,
6245
6263
  style: __spreadProps(__spreadValues({}, style), {
6246
- "--min-empty-height": `${minEmptyHeight}px`,
6264
+ "--min-empty-height": minEmptyHeight,
6247
6265
  backgroundColor: RENDER_DEBUG ? getRandomColor() : style == null ? void 0 : style.backgroundColor
6248
6266
  }),
6249
6267
  children: contentIdsWithPreview.map((componentId, i) => {
@@ -6290,7 +6308,7 @@ var DropZoneRenderItem = ({
6290
6308
  };
6291
6309
  var DropZoneRenderPure = (props) => /* @__PURE__ */ jsx26(DropZoneRender, __spreadValues({}, props));
6292
6310
  var DropZoneRender = forwardRef3(
6293
- function DropZoneRenderInternal({ className, style, zone }, ref) {
6311
+ function DropZoneRenderInternal({ className, style, zone, as }, ref) {
6294
6312
  const ctx = useContext8(dropZoneContext);
6295
6313
  const { areaId = "root" } = ctx || {};
6296
6314
  const { config, data, metadata } = useContext8(renderContext);
@@ -6303,13 +6321,14 @@ var DropZoneRender = forwardRef3(
6303
6321
  }
6304
6322
  }
6305
6323
  }, [content]);
6324
+ const El = as != null ? as : "div";
6306
6325
  if (!data || !config) {
6307
6326
  return null;
6308
6327
  }
6309
6328
  if (zoneCompound !== rootDroppableId) {
6310
6329
  content = setupZone(data, zoneCompound).zones[zoneCompound];
6311
6330
  }
6312
- return /* @__PURE__ */ jsx26("div", { className, style, ref, children: content.map((item) => {
6331
+ return /* @__PURE__ */ jsx26(El, { className, style, ref, children: content.map((item) => {
6313
6332
  const Component = config.components[item.type];
6314
6333
  if (Component) {
6315
6334
  return /* @__PURE__ */ jsx26(
@@ -6411,7 +6430,15 @@ var generateUsePuck = (store) => {
6411
6430
  selectedItem: store.selectedItem || null,
6412
6431
  getItemBySelector: (selector) => getItem(selector, store.state),
6413
6432
  getItemById: (id) => store.state.indexes.nodes[id].data,
6414
- getSelectorForId: (id) => getSelectorForId(store.state, id)
6433
+ getSelectorForId: (id) => getSelectorForId(store.state, id),
6434
+ getParentById: (id) => {
6435
+ const node = store.state.indexes.nodes[id];
6436
+ const parentId = node.parentId;
6437
+ if (parentId === null) return;
6438
+ const parentNode = store.state.indexes.nodes[parentId];
6439
+ if (!parentNode) return;
6440
+ return parentNode.data;
6441
+ }
6415
6442
  };
6416
6443
  return storeData;
6417
6444
  };
@@ -6452,7 +6479,7 @@ function createUsePuck() {
6452
6479
  }
6453
6480
  const result = useStore3(
6454
6481
  usePuckApi,
6455
- selector != null ? selector : (s) => s
6482
+ selector != null ? selector : ((s) => s)
6456
6483
  );
6457
6484
  return result;
6458
6485
  };
@@ -6599,49 +6626,48 @@ var DefaultFields = ({
6599
6626
  }) => {
6600
6627
  return /* @__PURE__ */ jsx29(Fragment8, { children });
6601
6628
  };
6602
- var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(void 0, null, function* () {
6603
- let currentProps;
6629
+ var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(null, null, function* () {
6604
6630
  const { dispatch, state, selectedItem, resolveComponentData: resolveComponentData2 } = appStore.getState();
6605
6631
  const { data, ui } = state;
6606
6632
  const { itemSelector } = ui;
6607
6633
  const rootProps = data.root.props || data.root;
6608
- if (selectedItem) {
6609
- currentProps = selectedItem.props;
6610
- } else {
6611
- currentProps = rootProps;
6612
- }
6613
- const newProps = __spreadProps(__spreadValues({}, currentProps), {
6614
- [fieldName]: value
6615
- });
6634
+ const currentProps = selectedItem ? selectedItem.props : rootProps;
6635
+ const newProps = __spreadProps(__spreadValues({}, currentProps), { [fieldName]: value });
6616
6636
  if (selectedItem && itemSelector) {
6637
+ const resolved = yield resolveComponentData2(
6638
+ __spreadProps(__spreadValues({}, selectedItem), { props: newProps }),
6639
+ "replace"
6640
+ );
6641
+ const latestSelector = getSelectorForId(
6642
+ appStore.getState().state,
6643
+ selectedItem.props.id
6644
+ );
6645
+ if (!latestSelector) return;
6617
6646
  dispatch({
6618
6647
  type: "replace",
6619
- destinationIndex: itemSelector.index,
6620
- destinationZone: itemSelector.zone || rootDroppableId,
6621
- data: (yield resolveComponentData2(
6622
- __spreadProps(__spreadValues({}, selectedItem), { props: newProps }),
6648
+ destinationIndex: latestSelector.index,
6649
+ destinationZone: latestSelector.zone || rootDroppableId,
6650
+ data: resolved.node,
6651
+ ui: updatedUi
6652
+ });
6653
+ return;
6654
+ }
6655
+ if (data.root.props) {
6656
+ dispatch({
6657
+ type: "replaceRoot",
6658
+ root: (yield resolveComponentData2(
6659
+ __spreadProps(__spreadValues({}, data.root), { props: newProps }),
6623
6660
  "replace"
6624
6661
  )).node,
6625
- ui: updatedUi
6662
+ ui: __spreadValues(__spreadValues({}, ui), updatedUi),
6663
+ recordHistory: true
6626
6664
  });
6627
- } else {
6628
- if (data.root.props) {
6629
- dispatch({
6630
- type: "replaceRoot",
6631
- root: (yield resolveComponentData2(
6632
- __spreadProps(__spreadValues({}, data.root), { props: newProps }),
6633
- "replace"
6634
- )).node,
6635
- ui: __spreadValues(__spreadValues({}, ui), updatedUi),
6636
- recordHistory: true
6637
- });
6638
- } else {
6639
- dispatch({
6640
- type: "setData",
6641
- data: { root: newProps }
6642
- });
6643
- }
6665
+ return;
6644
6666
  }
6667
+ dispatch({
6668
+ type: "setData",
6669
+ data: { root: newProps }
6670
+ });
6645
6671
  });
6646
6672
  var FieldsChild = ({ fieldName }) => {
6647
6673
  const field = useAppStore((s) => s.fields.fields[fieldName]);
@@ -6973,7 +6999,7 @@ var CopyHostStyles = ({
6973
6999
  let elements = [];
6974
7000
  const hashes = {};
6975
7001
  const lookupEl = (el) => elements.findIndex((elementMap) => elementMap.original === el);
6976
- const mirrorEl = (el, inlineStyles = false) => __async(void 0, null, function* () {
7002
+ const mirrorEl = (el, inlineStyles = false) => __async(null, null, function* () {
6977
7003
  let mirror;
6978
7004
  if (el.nodeName === "LINK" && inlineStyles) {
6979
7005
  mirror = document.createElement("style");
@@ -7005,7 +7031,7 @@ var CopyHostStyles = ({
7005
7031
  }
7006
7032
  return mirror;
7007
7033
  });
7008
- const addEl = (el) => __async(void 0, null, function* () {
7034
+ const addEl = (el) => __async(null, null, function* () {
7009
7035
  const index = lookupEl(el);
7010
7036
  if (index > -1) {
7011
7037
  if (debug)
@@ -7078,7 +7104,7 @@ var CopyHostStyles = ({
7078
7104
  const parentBody = parentDocument.getElementsByTagName("body")[0];
7079
7105
  syncAttributes(parentBody, doc.body);
7080
7106
  Promise.all(
7081
- collectedStyles.map((styleNode, i) => __async(void 0, null, function* () {
7107
+ collectedStyles.map((styleNode, i) => __async(null, null, function* () {
7082
7108
  if (styleNode.nodeName === "LINK") {
7083
7109
  const linkHref = styleNode.href;
7084
7110
  if (hrefs.indexOf(linkHref) > -1) {
@@ -8646,7 +8672,12 @@ function PuckProvider({ children }) {
8646
8672
  });
8647
8673
  })
8648
8674
  );
8649
- const initialHistoryIndex = (_initialHistory == null ? void 0 : _initialHistory.index) || blendedHistories.length - 1;
8675
+ const initialHistoryIndex = useMemo20(() => {
8676
+ if ((_initialHistory == null ? void 0 : _initialHistory.index) !== void 0 && (_initialHistory == null ? void 0 : _initialHistory.index) >= 0 && (_initialHistory == null ? void 0 : _initialHistory.index) < blendedHistories.length) {
8677
+ return _initialHistory == null ? void 0 : _initialHistory.index;
8678
+ }
8679
+ return blendedHistories.length - 1;
8680
+ }, []);
8650
8681
  const initialAppState = blendedHistories[initialHistoryIndex].state;
8651
8682
  const loadedOverrides = useLoadedOverrides({
8652
8683
  overrides,
@@ -8705,7 +8736,7 @@ function PuckProvider({ children }) {
8705
8736
  });
8706
8737
  const previousData = useRef12(null);
8707
8738
  useEffect29(() => {
8708
- appStore.subscribe(
8739
+ return appStore.subscribe(
8709
8740
  (s) => s.state.data,
8710
8741
  (data) => {
8711
8742
  if (onChange) {
@@ -8715,7 +8746,7 @@ function PuckProvider({ children }) {
8715
8746
  }
8716
8747
  }
8717
8748
  );
8718
- }, []);
8749
+ }, [onChange]);
8719
8750
  useRegisterPermissionsSlice(appStore, permissions);
8720
8751
  const uPuckStore = useRegisterUsePuckStore(appStore);
8721
8752
  useEffect29(() => {
@@ -8931,269 +8962,38 @@ classnames/index.js:
8931
8962
  *)
8932
8963
 
8933
8964
  lucide-react/dist/esm/shared/src/utils.js:
8934
- (**
8935
- * @license lucide-react v0.468.0 - ISC
8936
- *
8937
- * This source code is licensed under the ISC license.
8938
- * See the LICENSE file in the root directory of this source tree.
8939
- *)
8940
-
8941
8965
  lucide-react/dist/esm/defaultAttributes.js:
8942
- (**
8943
- * @license lucide-react v0.468.0 - ISC
8944
- *
8945
- * This source code is licensed under the ISC license.
8946
- * See the LICENSE file in the root directory of this source tree.
8947
- *)
8948
-
8949
8966
  lucide-react/dist/esm/Icon.js:
8950
- (**
8951
- * @license lucide-react v0.468.0 - ISC
8952
- *
8953
- * This source code is licensed under the ISC license.
8954
- * See the LICENSE file in the root directory of this source tree.
8955
- *)
8956
-
8957
8967
  lucide-react/dist/esm/createLucideIcon.js:
8958
- (**
8959
- * @license lucide-react v0.468.0 - ISC
8960
- *
8961
- * This source code is licensed under the ISC license.
8962
- * See the LICENSE file in the root directory of this source tree.
8963
- *)
8964
-
8965
8968
  lucide-react/dist/esm/icons/chevron-down.js:
8966
- (**
8967
- * @license lucide-react v0.468.0 - ISC
8968
- *
8969
- * This source code is licensed under the ISC license.
8970
- * See the LICENSE file in the root directory of this source tree.
8971
- *)
8972
-
8973
8969
  lucide-react/dist/esm/icons/chevron-right.js:
8974
- (**
8975
- * @license lucide-react v0.468.0 - ISC
8976
- *
8977
- * This source code is licensed under the ISC license.
8978
- * See the LICENSE file in the root directory of this source tree.
8979
- *)
8980
-
8981
8970
  lucide-react/dist/esm/icons/chevron-up.js:
8982
- (**
8983
- * @license lucide-react v0.468.0 - ISC
8984
- *
8985
- * This source code is licensed under the ISC license.
8986
- * See the LICENSE file in the root directory of this source tree.
8987
- *)
8988
-
8989
8971
  lucide-react/dist/esm/icons/circle-check-big.js:
8990
- (**
8991
- * @license lucide-react v0.468.0 - ISC
8992
- *
8993
- * This source code is licensed under the ISC license.
8994
- * See the LICENSE file in the root directory of this source tree.
8995
- *)
8996
-
8997
8972
  lucide-react/dist/esm/icons/copy.js:
8998
- (**
8999
- * @license lucide-react v0.468.0 - ISC
9000
- *
9001
- * This source code is licensed under the ISC license.
9002
- * See the LICENSE file in the root directory of this source tree.
9003
- *)
9004
-
9005
8973
  lucide-react/dist/esm/icons/corner-left-up.js:
9006
- (**
9007
- * @license lucide-react v0.468.0 - ISC
9008
- *
9009
- * This source code is licensed under the ISC license.
9010
- * See the LICENSE file in the root directory of this source tree.
9011
- *)
9012
-
9013
8974
  lucide-react/dist/esm/icons/ellipsis-vertical.js:
9014
- (**
9015
- * @license lucide-react v0.468.0 - ISC
9016
- *
9017
- * This source code is licensed under the ISC license.
9018
- * See the LICENSE file in the root directory of this source tree.
9019
- *)
9020
-
9021
8975
  lucide-react/dist/esm/icons/globe.js:
9022
- (**
9023
- * @license lucide-react v0.468.0 - ISC
9024
- *
9025
- * This source code is licensed under the ISC license.
9026
- * See the LICENSE file in the root directory of this source tree.
9027
- *)
9028
-
9029
8976
  lucide-react/dist/esm/icons/hash.js:
9030
- (**
9031
- * @license lucide-react v0.468.0 - ISC
9032
- *
9033
- * This source code is licensed under the ISC license.
9034
- * See the LICENSE file in the root directory of this source tree.
9035
- *)
9036
-
9037
8977
  lucide-react/dist/esm/icons/layers.js:
9038
- (**
9039
- * @license lucide-react v0.468.0 - ISC
9040
- *
9041
- * This source code is licensed under the ISC license.
9042
- * See the LICENSE file in the root directory of this source tree.
9043
- *)
9044
-
9045
8978
  lucide-react/dist/esm/icons/layout-grid.js:
9046
- (**
9047
- * @license lucide-react v0.468.0 - ISC
9048
- *
9049
- * This source code is licensed under the ISC license.
9050
- * See the LICENSE file in the root directory of this source tree.
9051
- *)
9052
-
9053
8979
  lucide-react/dist/esm/icons/link.js:
9054
- (**
9055
- * @license lucide-react v0.468.0 - ISC
9056
- *
9057
- * This source code is licensed under the ISC license.
9058
- * See the LICENSE file in the root directory of this source tree.
9059
- *)
9060
-
9061
8980
  lucide-react/dist/esm/icons/list.js:
9062
- (**
9063
- * @license lucide-react v0.468.0 - ISC
9064
- *
9065
- * This source code is licensed under the ISC license.
9066
- * See the LICENSE file in the root directory of this source tree.
9067
- *)
9068
-
9069
8981
  lucide-react/dist/esm/icons/lock-open.js:
9070
- (**
9071
- * @license lucide-react v0.468.0 - ISC
9072
- *
9073
- * This source code is licensed under the ISC license.
9074
- * See the LICENSE file in the root directory of this source tree.
9075
- *)
9076
-
9077
8982
  lucide-react/dist/esm/icons/lock.js:
9078
- (**
9079
- * @license lucide-react v0.468.0 - ISC
9080
- *
9081
- * This source code is licensed under the ISC license.
9082
- * See the LICENSE file in the root directory of this source tree.
9083
- *)
9084
-
9085
8983
  lucide-react/dist/esm/icons/monitor.js:
9086
- (**
9087
- * @license lucide-react v0.468.0 - ISC
9088
- *
9089
- * This source code is licensed under the ISC license.
9090
- * See the LICENSE file in the root directory of this source tree.
9091
- *)
9092
-
9093
8984
  lucide-react/dist/esm/icons/panel-left.js:
9094
- (**
9095
- * @license lucide-react v0.468.0 - ISC
9096
- *
9097
- * This source code is licensed under the ISC license.
9098
- * See the LICENSE file in the root directory of this source tree.
9099
- *)
9100
-
9101
8985
  lucide-react/dist/esm/icons/panel-right.js:
9102
- (**
9103
- * @license lucide-react v0.468.0 - ISC
9104
- *
9105
- * This source code is licensed under the ISC license.
9106
- * See the LICENSE file in the root directory of this source tree.
9107
- *)
9108
-
9109
8986
  lucide-react/dist/esm/icons/plus.js:
9110
- (**
9111
- * @license lucide-react v0.468.0 - ISC
9112
- *
9113
- * This source code is licensed under the ISC license.
9114
- * See the LICENSE file in the root directory of this source tree.
9115
- *)
9116
-
9117
8987
  lucide-react/dist/esm/icons/redo-2.js:
9118
- (**
9119
- * @license lucide-react v0.468.0 - ISC
9120
- *
9121
- * This source code is licensed under the ISC license.
9122
- * See the LICENSE file in the root directory of this source tree.
9123
- *)
9124
-
9125
8988
  lucide-react/dist/esm/icons/search.js:
9126
- (**
9127
- * @license lucide-react v0.468.0 - ISC
9128
- *
9129
- * This source code is licensed under the ISC license.
9130
- * See the LICENSE file in the root directory of this source tree.
9131
- *)
9132
-
9133
8989
  lucide-react/dist/esm/icons/sliders-horizontal.js:
9134
- (**
9135
- * @license lucide-react v0.468.0 - ISC
9136
- *
9137
- * This source code is licensed under the ISC license.
9138
- * See the LICENSE file in the root directory of this source tree.
9139
- *)
9140
-
9141
8990
  lucide-react/dist/esm/icons/smartphone.js:
9142
- (**
9143
- * @license lucide-react v0.468.0 - ISC
9144
- *
9145
- * This source code is licensed under the ISC license.
9146
- * See the LICENSE file in the root directory of this source tree.
9147
- *)
9148
-
9149
8991
  lucide-react/dist/esm/icons/tablet.js:
9150
- (**
9151
- * @license lucide-react v0.468.0 - ISC
9152
- *
9153
- * This source code is licensed under the ISC license.
9154
- * See the LICENSE file in the root directory of this source tree.
9155
- *)
9156
-
9157
8992
  lucide-react/dist/esm/icons/trash.js:
9158
- (**
9159
- * @license lucide-react v0.468.0 - ISC
9160
- *
9161
- * This source code is licensed under the ISC license.
9162
- * See the LICENSE file in the root directory of this source tree.
9163
- *)
9164
-
9165
8993
  lucide-react/dist/esm/icons/type.js:
9166
- (**
9167
- * @license lucide-react v0.468.0 - ISC
9168
- *
9169
- * This source code is licensed under the ISC license.
9170
- * See the LICENSE file in the root directory of this source tree.
9171
- *)
9172
-
9173
8994
  lucide-react/dist/esm/icons/undo-2.js:
9174
- (**
9175
- * @license lucide-react v0.468.0 - ISC
9176
- *
9177
- * This source code is licensed under the ISC license.
9178
- * See the LICENSE file in the root directory of this source tree.
9179
- *)
9180
-
9181
8995
  lucide-react/dist/esm/icons/zoom-in.js:
9182
- (**
9183
- * @license lucide-react v0.468.0 - ISC
9184
- *
9185
- * This source code is licensed under the ISC license.
9186
- * See the LICENSE file in the root directory of this source tree.
9187
- *)
9188
-
9189
8996
  lucide-react/dist/esm/icons/zoom-out.js:
9190
- (**
9191
- * @license lucide-react v0.468.0 - ISC
9192
- *
9193
- * This source code is licensed under the ISC license.
9194
- * See the LICENSE file in the root directory of this source tree.
9195
- *)
9196
-
9197
8997
  lucide-react/dist/esm/lucide-react.js:
9198
8998
  (**
9199
8999
  * @license lucide-react v0.468.0 - ISC