@measured/puck 0.21.0-canary.16a3eee1 → 0.21.0-canary.1b69a8f3

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.
@@ -19,12 +19,13 @@ import {
19
19
  rootDroppableId,
20
20
  rootZone,
21
21
  setupZone,
22
+ toComponent,
22
23
  useFieldTransforms,
23
24
  useSlots,
24
25
  walkAppState,
25
26
  walkField,
26
27
  walkTree
27
- } from "./chunk-X7YZ3YE7.mjs";
28
+ } from "./chunk-JA7SEUEH.mjs";
28
29
 
29
30
  // ../../node_modules/classnames/index.js
30
31
  var require_classnames = __commonJS({
@@ -856,6 +857,10 @@ var monitorHotkeys = (doc) => {
856
857
  useHotkeyStore.getState().reset();
857
858
  }
858
859
  };
860
+ const onBlur = () => {
861
+ useHotkeyStore.getState().reset();
862
+ };
863
+ window.addEventListener("blur", onBlur);
859
864
  doc.addEventListener("keydown", onKeyDown);
860
865
  doc.addEventListener("keyup", onKeyUp);
861
866
  doc.addEventListener("visibilitychange", onVisibilityChanged);
@@ -863,6 +868,7 @@ var monitorHotkeys = (doc) => {
863
868
  doc.removeEventListener("keydown", onKeyDown);
864
869
  doc.removeEventListener("keyup", onKeyUp);
865
870
  doc.removeEventListener("visibilitychange", onVisibilityChanged);
871
+ window.removeEventListener("blur", onBlur);
866
872
  };
867
873
  };
868
874
  var useMonitorHotkeys = () => {
@@ -1065,29 +1071,37 @@ var flattenData = (state, config) => {
1065
1071
 
1066
1072
  // store/slices/permissions.ts
1067
1073
  var createPermissionsSlice = (set, get) => {
1068
- const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1074
+ const resolvePermissions = (..._0) => __async(null, [..._0], function* (params = {}, force) {
1069
1075
  const { state, permissions, config } = get();
1070
1076
  const { cache, globalPermissions } = permissions;
1071
- const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1072
- var _a, _b, _c;
1077
+ const resolvePermissionsForItem = (item2, force2 = false) => __async(null, null, function* () {
1078
+ var _a, _b;
1073
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;
1074
1085
  const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1075
1086
  if (!componentConfig) {
1076
1087
  return;
1077
1088
  }
1078
1089
  const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1079
1090
  if (componentConfig.resolvePermissions) {
1080
- const changed = getChanged(item2, (_a = cache[item2.props.id]) == null ? void 0 : _a.lastData);
1081
- 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) {
1082
1095
  const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1083
1096
  const resolvedPermissions = yield componentConfig.resolvePermissions(
1084
1097
  item2,
1085
1098
  {
1086
1099
  changed,
1087
- lastPermissions: ((_b = cache[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1100
+ lastPermissions: (itemCache == null ? void 0 : itemCache.lastPermissions) || null,
1088
1101
  permissions: initialPermissions,
1089
1102
  appState: makeStatePublic(appState),
1090
- lastData: ((_c = cache[item2.props.id]) == null ? void 0 : _c.lastData) || null
1103
+ lastData: (itemCache == null ? void 0 : itemCache.lastData) || null,
1104
+ parent: parentData
1091
1105
  }
1092
1106
  );
1093
1107
  const latest = get().permissions;
@@ -1095,6 +1109,7 @@ var createPermissionsSlice = (set, get) => {
1095
1109
  permissions: __spreadProps(__spreadValues({}, latest), {
1096
1110
  cache: __spreadProps(__spreadValues({}, latest.cache), {
1097
1111
  [item2.props.id]: {
1112
+ lastParentId: parentId,
1098
1113
  lastData: item2,
1099
1114
  lastPermissions: resolvedPermissions
1100
1115
  }
@@ -1108,9 +1123,9 @@ var createPermissionsSlice = (set, get) => {
1108
1123
  }
1109
1124
  }
1110
1125
  });
1111
- const resolveDataForRoot = (force2 = false) => {
1126
+ const resolvePermissionsForRoot = (force2 = false) => {
1112
1127
  const { state: appState } = get();
1113
- resolveDataForItem(
1128
+ resolvePermissionsForItem(
1114
1129
  // Shim the root data in by conforming to component data shape
1115
1130
  {
1116
1131
  type: "root",
@@ -1121,16 +1136,16 @@ var createPermissionsSlice = (set, get) => {
1121
1136
  };
1122
1137
  const { item, type, root } = params;
1123
1138
  if (item) {
1124
- yield resolveDataForItem(item, force);
1139
+ yield resolvePermissionsForItem(item, force);
1125
1140
  } else if (type) {
1126
- flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1127
- yield resolveDataForItem(item2, force);
1141
+ flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(null, null, function* () {
1142
+ yield resolvePermissionsForItem(item2, force);
1128
1143
  }));
1129
1144
  } else if (root) {
1130
- resolveDataForRoot(force);
1145
+ resolvePermissionsForRoot(force);
1131
1146
  } else {
1132
- flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1133
- yield resolveDataForItem(item2, force);
1147
+ flattenData(state, config).map((item2) => __async(null, null, function* () {
1148
+ yield resolvePermissionsForItem(item2, force);
1134
1149
  }));
1135
1150
  }
1136
1151
  });
@@ -1210,7 +1225,7 @@ var createFieldsSlice = (_set, _get) => {
1210
1225
  };
1211
1226
  var useRegisterFieldsSlice = (appStore, id) => {
1212
1227
  const resolveFields = useCallback(
1213
- (reset) => __async(void 0, null, function* () {
1228
+ (reset) => __async(null, null, function* () {
1214
1229
  var _a, _b;
1215
1230
  const { fields, lastResolvedData } = appStore.getState().fields;
1216
1231
  const metadata = appStore.getState().metadata;
@@ -1410,7 +1425,7 @@ var createAppStore = (initialAppStore) => create2()(
1410
1425
  const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1411
1426
  return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1412
1427
  }),
1413
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1428
+ resolveComponentData: (componentData, trigger) => __async(null, null, function* () {
1414
1429
  const { config, metadata, setComponentLoading, permissions } = get();
1415
1430
  const timeouts = {};
1416
1431
  return yield resolveComponentData(
@@ -1421,7 +1436,7 @@ var createAppStore = (initialAppStore) => create2()(
1421
1436
  const id = "id" in item.props ? item.props.id : "root";
1422
1437
  timeouts[id] = setComponentLoading(id, true, 50);
1423
1438
  },
1424
- (item) => __async(void 0, null, function* () {
1439
+ (item) => __async(null, null, function* () {
1425
1440
  const id = "id" in item.props ? item.props.id : "root";
1426
1441
  if ("type" in item) {
1427
1442
  yield permissions.refreshPermissions({ item });
@@ -1433,7 +1448,7 @@ var createAppStore = (initialAppStore) => create2()(
1433
1448
  trigger
1434
1449
  );
1435
1450
  }),
1436
- resolveAndCommitData: () => __async(void 0, null, function* () {
1451
+ resolveAndCommitData: () => __async(null, null, function* () {
1437
1452
  const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1438
1453
  walkAppState(
1439
1454
  state,
@@ -2454,7 +2469,7 @@ var collisionStore = createStore(() => ({
2454
2469
 
2455
2470
  // lib/dnd/collision/dynamic/index.ts
2456
2471
  var flushNext = "";
2457
- var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input) => {
2472
+ var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => ((input) => {
2458
2473
  var _a, _b, _c, _d, _e;
2459
2474
  const { dragOperation, droppable } = input;
2460
2475
  const { position } = dragOperation;
@@ -2547,7 +2562,7 @@ var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input
2547
2562
  }
2548
2563
  collisionDebug(dragCenter, dropCenter, droppable.id.toString(), "hotpink");
2549
2564
  return null;
2550
- };
2565
+ });
2551
2566
 
2552
2567
  // components/Sortable/index.tsx
2553
2568
  import { useSortable } from "@dnd-kit/react/sortable";
@@ -2980,8 +2995,9 @@ var ArrayField = ({
2980
2995
  var _a;
2981
2996
  if (isDraggingAny) return;
2982
2997
  const existingValue = value || [];
2998
+ const defaultProps = typeof field.defaultItemProps === "function" ? field.defaultItemProps(existingValue.length) : (_a = field.defaultItemProps) != null ? _a : {};
2983
2999
  const newItem = defaultSlots(
2984
- uniqifyItem((_a = field.defaultItemProps) != null ? _a : {}),
3000
+ uniqifyItem(defaultProps),
2985
3001
  field.arrayFields
2986
3002
  );
2987
3003
  const newValue = [...existingValue, newItem];
@@ -3156,11 +3172,13 @@ var ExternalInput = ({
3156
3172
  id,
3157
3173
  readOnly
3158
3174
  }) => {
3175
+ var _a;
3159
3176
  const {
3160
3177
  mapProp = (val) => val,
3161
3178
  mapRow = (val) => val,
3162
3179
  filterFields
3163
3180
  } = field || {};
3181
+ const { enabled: shouldCacheData } = (_a = field.cache) != null ? _a : { enabled: true };
3164
3182
  const [data, setData] = useState6([]);
3165
3183
  const [isOpen, setOpen] = useState6(false);
3166
3184
  const [isLoading, setIsLoading] = useState6(true);
@@ -3183,14 +3201,21 @@ var ExternalInput = ({
3183
3201
  }, [mappedData]);
3184
3202
  const [searchQuery, setSearchQuery] = useState6(field.initialQuery || "");
3185
3203
  const search = useCallback3(
3186
- (query, filters2) => __async(void 0, null, function* () {
3204
+ (query, filters2) => __async(null, null, function* () {
3187
3205
  setIsLoading(true);
3188
3206
  const cacheKey = `${id}-${query}-${JSON.stringify(filters2)}`;
3189
- const listData = dataCache[cacheKey] || (yield field.fetchList({ query, filters: filters2 }));
3207
+ let listData;
3208
+ if (shouldCacheData && dataCache[cacheKey]) {
3209
+ listData = dataCache[cacheKey];
3210
+ } else {
3211
+ listData = yield field.fetchList({ query, filters: filters2 });
3212
+ }
3190
3213
  if (listData) {
3191
3214
  setData(listData);
3192
3215
  setIsLoading(false);
3193
- dataCache[cacheKey] = listData;
3216
+ if (shouldCacheData) {
3217
+ dataCache[cacheKey] = listData;
3218
+ }
3194
3219
  }
3195
3220
  }),
3196
3221
  [id, field]
@@ -3254,6 +3279,7 @@ var ExternalInput = ({
3254
3279
  }),
3255
3280
  onSubmit: (e) => {
3256
3281
  e.preventDefault();
3282
+ e.stopPropagation();
3257
3283
  search(searchQuery, filters);
3258
3284
  },
3259
3285
  children: [
@@ -3401,7 +3427,7 @@ var ExternalField = ({
3401
3427
  placeholder: ((_a = deprecatedField.adaptor) == null ? void 0 : _a.name) ? `Select from ${deprecatedField.adaptor.name}` : validField.placeholder || "Select data",
3402
3428
  mapProp: ((_b = deprecatedField.adaptor) == null ? void 0 : _b.mapProp) || validField.mapProp,
3403
3429
  mapRow: validField.mapRow,
3404
- 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* () {
3405
3431
  return yield deprecatedField.adaptor.fetchList(
3406
3432
  deprecatedField.adaptorParams
3407
3433
  );
@@ -3777,6 +3803,7 @@ function AutoFieldInternal(props) {
3777
3803
  }
3778
3804
  return (_props) => null;
3779
3805
  }, [field.type]);
3806
+ const fieldKey = field.type === "custom" ? field.key : void 0;
3780
3807
  let FieldComponent = useMemo3(() => {
3781
3808
  if (field.type === "custom") {
3782
3809
  if (!field.render) {
@@ -3786,7 +3813,7 @@ function AutoFieldInternal(props) {
3786
3813
  } else if (field.type !== "slot") {
3787
3814
  return render[field.type];
3788
3815
  }
3789
- }, [field.type, render]);
3816
+ }, [field.type, fieldKey, render]);
3790
3817
  const { visible = true } = props.field;
3791
3818
  if (!visible) {
3792
3819
  return null;
@@ -4164,12 +4191,14 @@ var DraggableComponent = ({
4164
4191
  }
4165
4192
  return cleanup;
4166
4193
  }, [permissions.drag, zoneCompound]);
4194
+ const [, setRerender] = useState10(0);
4167
4195
  const ref = useRef2(null);
4168
4196
  const refSetter = useCallback7(
4169
4197
  (el) => {
4170
4198
  sortableRef(el);
4171
- if (el) {
4199
+ if (ref.current !== el) {
4172
4200
  ref.current = el;
4201
+ setRerender((update) => update + 1);
4173
4202
  }
4174
4203
  },
4175
4204
  [sortableRef]
@@ -4824,7 +4853,20 @@ var createNestedDroppablePlugin = ({ onChange }, id) => class NestedDroppablePlu
4824
4853
 
4825
4854
  // lib/insert-component.ts
4826
4855
  init_react_import();
4827
- 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;
4828
4870
  const id = generateId(componentType);
4829
4871
  const insertActionData = {
4830
4872
  type: "insert",
@@ -4833,8 +4875,9 @@ var insertComponent = (componentType, zone, index, appStore) => __async(void 0,
4833
4875
  destinationZone: zone,
4834
4876
  id
4835
4877
  };
4836
- const { state, dispatch, resolveComponentData: resolveComponentData2 } = appStore;
4837
- const insertedState = insertAction(state, insertActionData, appStore);
4878
+ const stateBefore = getState().state;
4879
+ const insertedState = insertAction(stateBefore, insertActionData, getState());
4880
+ const dispatch = getState().dispatch;
4838
4881
  dispatch(__spreadProps(__spreadValues({}, insertActionData), {
4839
4882
  // Dispatch insert rather set, as user's may rely on this via onAction
4840
4883
  // We must always record history here so the insert is added to user history
@@ -4842,23 +4885,21 @@ var insertComponent = (componentType, zone, index, appStore) => __async(void 0,
4842
4885
  // entries on insert - one for the initial insert, and one when the data resolves
4843
4886
  recordHistory: true
4844
4887
  }));
4845
- const itemSelector = {
4846
- index,
4847
- zone
4848
- };
4888
+ const itemSelector = { index, zone };
4849
4889
  dispatch({ type: "setUi", ui: { itemSelector } });
4850
4890
  const itemData = getItem(itemSelector, insertedState);
4851
- if (itemData) {
4852
- const resolved = yield resolveComponentData2(itemData, "insert");
4853
- if (resolved.didChange) {
4854
- dispatch({
4855
- type: "replace",
4856
- destinationZone: itemSelector.zone,
4857
- destinationIndex: itemSelector.index,
4858
- data: resolved.node
4859
- });
4860
- }
4861
- }
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
+ });
4862
4903
  });
4863
4904
 
4864
4905
  // components/DragDropContext/index.tsx
@@ -5095,7 +5136,7 @@ var DragDropContextClient = ({
5095
5136
  thisPreview.componentType,
5096
5137
  thisPreview.zone,
5097
5138
  thisPreview.index,
5098
- appStore.getState()
5139
+ appStore
5099
5140
  );
5100
5141
  } else if (initialSelector.current) {
5101
5142
  dispatch({
@@ -5508,7 +5549,7 @@ import { useCallback as useCallback9 } from "react";
5508
5549
  function useRenderedCallback(callback, deps) {
5509
5550
  const manager = useDragDropManager();
5510
5551
  return useCallback9(
5511
- (...args) => __async(this, null, function* () {
5552
+ (...args) => __async(null, null, function* () {
5512
5553
  yield manager == null ? void 0 : manager.renderer.rendering;
5513
5554
  return callback(...args);
5514
5555
  }),
@@ -5674,26 +5715,26 @@ var registerOverlayPortal = (el, opts = {}) => {
5674
5715
  capture: true
5675
5716
  });
5676
5717
  };
5677
- if (disableDragOnFocus) {
5678
- el.addEventListener("focus", onFocus, { capture: true });
5679
- el.addEventListener("blur", onBlur, { capture: true });
5680
- } else if (disableDrag) {
5718
+ if (disableDrag) {
5681
5719
  el.addEventListener("pointerdown", stopPropagation, {
5682
5720
  capture: true
5683
5721
  });
5722
+ } else if (disableDragOnFocus) {
5723
+ el.addEventListener("focus", onFocus, { capture: true });
5724
+ el.addEventListener("blur", onBlur, { capture: true });
5684
5725
  }
5685
5726
  el.setAttribute("data-puck-overlay-portal", "true");
5686
5727
  return () => {
5687
5728
  el.removeEventListener("mouseover", stopPropagation, {
5688
5729
  capture: true
5689
5730
  });
5690
- if (disableDragOnFocus) {
5691
- el.removeEventListener("focus", onFocus, { capture: true });
5692
- el.removeEventListener("blur", onFocus, { capture: true });
5693
- } else if (disableDrag) {
5731
+ if (disableDrag) {
5694
5732
  el.removeEventListener("pointerdown", stopPropagation, {
5695
5733
  capture: true
5696
5734
  });
5735
+ } else if (disableDragOnFocus) {
5736
+ el.removeEventListener("focus", onFocus, { capture: true });
5737
+ el.removeEventListener("blur", onBlur, { capture: true });
5697
5738
  }
5698
5739
  el.removeAttribute("data-puck-overlay-portal");
5699
5740
  };
@@ -5701,7 +5742,7 @@ var registerOverlayPortal = (el, opts = {}) => {
5701
5742
 
5702
5743
  // css-module:/home/runner/work/puck/puck/packages/core/components/InlineTextField/styles.module.css#css-module
5703
5744
  init_react_import();
5704
- var styles_module_default13 = { "InlineTextField": "_InlineTextField_1xph6_1" };
5745
+ var styles_module_default13 = { "InlineTextField": "_InlineTextField_104qp_1" };
5705
5746
 
5706
5747
  // lib/data/set-deep.ts
5707
5748
  init_react_import();
@@ -5737,16 +5778,6 @@ function setDeep(node, path, newVal) {
5737
5778
  return __spreadValues(__spreadValues({}, node), newNode);
5738
5779
  }
5739
5780
 
5740
- // lib/get-selector-for-id.ts
5741
- init_react_import();
5742
- var getSelectorForId = (state, id) => {
5743
- const node = state.indexes.nodes[id];
5744
- if (!node) return;
5745
- const zoneCompound = `${node.parentId}:${node.zone}`;
5746
- const index = state.indexes.zones[zoneCompound].contentIds.indexOf(id);
5747
- return { zone: zoneCompound, index };
5748
- };
5749
-
5750
5781
  // components/InlineTextField/index.tsx
5751
5782
  import { jsx as jsx24 } from "react/jsx-runtime";
5752
5783
  var getClassName18 = get_class_name_factory_default("InlineTextField", styles_module_default13);
@@ -5775,7 +5806,7 @@ var InlineTextFieldInternal = ({
5775
5806
  ref.current.replaceChildren(value);
5776
5807
  }
5777
5808
  const cleanupPortal = registerOverlayPortal(ref.current);
5778
- const handleInput = (e) => __async(void 0, null, function* () {
5809
+ const handleInput = (e) => __async(null, null, function* () {
5779
5810
  var _a2;
5780
5811
  const appStore2 = appStoreApi.getState();
5781
5812
  const node = appStore2.state.indexes.nodes[componentId];
@@ -6067,7 +6098,8 @@ var DropZoneEdit = forwardRef3(
6067
6098
  style,
6068
6099
  className,
6069
6100
  minEmptyHeight: userMinEmptyHeight = 128,
6070
- collisionAxis
6101
+ collisionAxis,
6102
+ as
6071
6103
  }, userRef) {
6072
6104
  const ctx = useContext8(dropZoneContext);
6073
6105
  const appStoreApi = useAppStoreApi();
@@ -6210,8 +6242,9 @@ var DropZoneEdit = forwardRef3(
6210
6242
  userMinEmptyHeight,
6211
6243
  ref
6212
6244
  });
6245
+ const El = as != null ? as : "div";
6213
6246
  return /* @__PURE__ */ jsx26(
6214
- "div",
6247
+ El,
6215
6248
  {
6216
6249
  className: `${getClassName19({
6217
6250
  isRootZone,
@@ -6274,7 +6307,7 @@ var DropZoneRenderItem = ({
6274
6307
  };
6275
6308
  var DropZoneRenderPure = (props) => /* @__PURE__ */ jsx26(DropZoneRender, __spreadValues({}, props));
6276
6309
  var DropZoneRender = forwardRef3(
6277
- function DropZoneRenderInternal({ className, style, zone }, ref) {
6310
+ function DropZoneRenderInternal({ className, style, zone, as }, ref) {
6278
6311
  const ctx = useContext8(dropZoneContext);
6279
6312
  const { areaId = "root" } = ctx || {};
6280
6313
  const { config, data, metadata } = useContext8(renderContext);
@@ -6287,13 +6320,14 @@ var DropZoneRender = forwardRef3(
6287
6320
  }
6288
6321
  }
6289
6322
  }, [content]);
6323
+ const El = as != null ? as : "div";
6290
6324
  if (!data || !config) {
6291
6325
  return null;
6292
6326
  }
6293
6327
  if (zoneCompound !== rootDroppableId) {
6294
6328
  content = setupZone(data, zoneCompound).zones[zoneCompound];
6295
6329
  }
6296
- return /* @__PURE__ */ jsx26("div", { className, style, ref, children: content.map((item) => {
6330
+ return /* @__PURE__ */ jsx26(El, { className, style, ref, children: content.map((item) => {
6297
6331
  const Component = config.components[item.type];
6298
6332
  if (Component) {
6299
6333
  return /* @__PURE__ */ jsx26(
@@ -6436,7 +6470,7 @@ function createUsePuck() {
6436
6470
  }
6437
6471
  const result = useStore3(
6438
6472
  usePuckApi,
6439
- selector != null ? selector : (s) => s
6473
+ selector != null ? selector : ((s) => s)
6440
6474
  );
6441
6475
  return result;
6442
6476
  };
@@ -6583,49 +6617,48 @@ var DefaultFields = ({
6583
6617
  }) => {
6584
6618
  return /* @__PURE__ */ jsx29(Fragment8, { children });
6585
6619
  };
6586
- var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(void 0, null, function* () {
6587
- let currentProps;
6620
+ var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(null, null, function* () {
6588
6621
  const { dispatch, state, selectedItem, resolveComponentData: resolveComponentData2 } = appStore.getState();
6589
6622
  const { data, ui } = state;
6590
6623
  const { itemSelector } = ui;
6591
6624
  const rootProps = data.root.props || data.root;
6592
- if (selectedItem) {
6593
- currentProps = selectedItem.props;
6594
- } else {
6595
- currentProps = rootProps;
6596
- }
6597
- const newProps = __spreadProps(__spreadValues({}, currentProps), {
6598
- [fieldName]: value
6599
- });
6625
+ const currentProps = selectedItem ? selectedItem.props : rootProps;
6626
+ const newProps = __spreadProps(__spreadValues({}, currentProps), { [fieldName]: value });
6600
6627
  if (selectedItem && itemSelector) {
6628
+ const resolved = yield resolveComponentData2(
6629
+ __spreadProps(__spreadValues({}, selectedItem), { props: newProps }),
6630
+ "replace"
6631
+ );
6632
+ const latestSelector = getSelectorForId(
6633
+ appStore.getState().state,
6634
+ selectedItem.props.id
6635
+ );
6636
+ if (!latestSelector) return;
6601
6637
  dispatch({
6602
6638
  type: "replace",
6603
- destinationIndex: itemSelector.index,
6604
- destinationZone: itemSelector.zone || rootDroppableId,
6605
- data: (yield resolveComponentData2(
6606
- __spreadProps(__spreadValues({}, selectedItem), { props: newProps }),
6639
+ destinationIndex: latestSelector.index,
6640
+ destinationZone: latestSelector.zone || rootDroppableId,
6641
+ data: resolved.node,
6642
+ ui: updatedUi
6643
+ });
6644
+ return;
6645
+ }
6646
+ if (data.root.props) {
6647
+ dispatch({
6648
+ type: "replaceRoot",
6649
+ root: (yield resolveComponentData2(
6650
+ __spreadProps(__spreadValues({}, data.root), { props: newProps }),
6607
6651
  "replace"
6608
6652
  )).node,
6609
- ui: updatedUi
6653
+ ui: __spreadValues(__spreadValues({}, ui), updatedUi),
6654
+ recordHistory: true
6610
6655
  });
6611
- } else {
6612
- if (data.root.props) {
6613
- dispatch({
6614
- type: "replaceRoot",
6615
- root: (yield resolveComponentData2(
6616
- __spreadProps(__spreadValues({}, data.root), { props: newProps }),
6617
- "replace"
6618
- )).node,
6619
- ui: __spreadValues(__spreadValues({}, ui), updatedUi),
6620
- recordHistory: true
6621
- });
6622
- } else {
6623
- dispatch({
6624
- type: "setData",
6625
- data: { root: newProps }
6626
- });
6627
- }
6656
+ return;
6628
6657
  }
6658
+ dispatch({
6659
+ type: "setData",
6660
+ data: { root: newProps }
6661
+ });
6629
6662
  });
6630
6663
  var FieldsChild = ({ fieldName }) => {
6631
6664
  const field = useAppStore((s) => s.fields.fields[fieldName]);
@@ -6957,7 +6990,7 @@ var CopyHostStyles = ({
6957
6990
  let elements = [];
6958
6991
  const hashes = {};
6959
6992
  const lookupEl = (el) => elements.findIndex((elementMap) => elementMap.original === el);
6960
- const mirrorEl = (el, inlineStyles = false) => __async(void 0, null, function* () {
6993
+ const mirrorEl = (el, inlineStyles = false) => __async(null, null, function* () {
6961
6994
  let mirror;
6962
6995
  if (el.nodeName === "LINK" && inlineStyles) {
6963
6996
  mirror = document.createElement("style");
@@ -6989,7 +7022,7 @@ var CopyHostStyles = ({
6989
7022
  }
6990
7023
  return mirror;
6991
7024
  });
6992
- const addEl = (el) => __async(void 0, null, function* () {
7025
+ const addEl = (el) => __async(null, null, function* () {
6993
7026
  const index = lookupEl(el);
6994
7027
  if (index > -1) {
6995
7028
  if (debug)
@@ -7062,7 +7095,7 @@ var CopyHostStyles = ({
7062
7095
  const parentBody = parentDocument.getElementsByTagName("body")[0];
7063
7096
  syncAttributes(parentBody, doc.body);
7064
7097
  Promise.all(
7065
- collectedStyles.map((styleNode, i) => __async(void 0, null, function* () {
7098
+ collectedStyles.map((styleNode, i) => __async(null, null, function* () {
7066
7099
  if (styleNode.nodeName === "LINK") {
7067
7100
  const linkHref = styleNode.href;
7068
7101
  if (hrefs.indexOf(linkHref) > -1) {
@@ -8587,9 +8620,13 @@ function PuckProvider({ children }) {
8587
8620
  }
8588
8621
  const rootProps = ((_h = initialData == null ? void 0 : initialData.root) == null ? void 0 : _h.props) || (initialData == null ? void 0 : initialData.root) || {};
8589
8622
  const defaultedRootProps = __spreadValues(__spreadValues({}, (_i = config.root) == null ? void 0 : _i.defaultProps), rootProps);
8623
+ const root = populateIds(
8624
+ toComponent(__spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: defaultedRootProps })),
8625
+ config
8626
+ );
8590
8627
  const newAppState = __spreadProps(__spreadValues({}, defaultAppState), {
8591
8628
  data: __spreadProps(__spreadValues({}, initialData), {
8592
- root: __spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: defaultedRootProps }),
8629
+ root: __spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: root.props }),
8593
8630
  content: initialData.content || []
8594
8631
  }),
8595
8632
  ui: __spreadProps(__spreadValues(__spreadValues({}, initial), clientUiState), {
@@ -8626,7 +8663,12 @@ function PuckProvider({ children }) {
8626
8663
  });
8627
8664
  })
8628
8665
  );
8629
- const initialHistoryIndex = (_initialHistory == null ? void 0 : _initialHistory.index) || blendedHistories.length - 1;
8666
+ const initialHistoryIndex = useMemo20(() => {
8667
+ if ((_initialHistory == null ? void 0 : _initialHistory.index) !== void 0 && (_initialHistory == null ? void 0 : _initialHistory.index) >= 0 && (_initialHistory == null ? void 0 : _initialHistory.index) < blendedHistories.length) {
8668
+ return _initialHistory == null ? void 0 : _initialHistory.index;
8669
+ }
8670
+ return blendedHistories.length - 1;
8671
+ }, []);
8630
8672
  const initialAppState = blendedHistories[initialHistoryIndex].state;
8631
8673
  const loadedOverrides = useLoadedOverrides({
8632
8674
  overrides,
@@ -8685,7 +8727,7 @@ function PuckProvider({ children }) {
8685
8727
  });
8686
8728
  const previousData = useRef12(null);
8687
8729
  useEffect29(() => {
8688
- appStore.subscribe(
8730
+ return appStore.subscribe(
8689
8731
  (s) => s.state.data,
8690
8732
  (data) => {
8691
8733
  if (onChange) {
@@ -8695,7 +8737,7 @@ function PuckProvider({ children }) {
8695
8737
  }
8696
8738
  }
8697
8739
  );
8698
- }, []);
8740
+ }, [onChange]);
8699
8741
  useRegisterPermissionsSlice(appStore, permissions);
8700
8742
  const uPuckStore = useRegisterUsePuckStore(appStore);
8701
8743
  useEffect29(() => {
@@ -8911,269 +8953,38 @@ classnames/index.js:
8911
8953
  *)
8912
8954
 
8913
8955
  lucide-react/dist/esm/shared/src/utils.js:
8914
- (**
8915
- * @license lucide-react v0.468.0 - ISC
8916
- *
8917
- * This source code is licensed under the ISC license.
8918
- * See the LICENSE file in the root directory of this source tree.
8919
- *)
8920
-
8921
8956
  lucide-react/dist/esm/defaultAttributes.js:
8922
- (**
8923
- * @license lucide-react v0.468.0 - ISC
8924
- *
8925
- * This source code is licensed under the ISC license.
8926
- * See the LICENSE file in the root directory of this source tree.
8927
- *)
8928
-
8929
8957
  lucide-react/dist/esm/Icon.js:
8930
- (**
8931
- * @license lucide-react v0.468.0 - ISC
8932
- *
8933
- * This source code is licensed under the ISC license.
8934
- * See the LICENSE file in the root directory of this source tree.
8935
- *)
8936
-
8937
8958
  lucide-react/dist/esm/createLucideIcon.js:
8938
- (**
8939
- * @license lucide-react v0.468.0 - ISC
8940
- *
8941
- * This source code is licensed under the ISC license.
8942
- * See the LICENSE file in the root directory of this source tree.
8943
- *)
8944
-
8945
8959
  lucide-react/dist/esm/icons/chevron-down.js:
8946
- (**
8947
- * @license lucide-react v0.468.0 - ISC
8948
- *
8949
- * This source code is licensed under the ISC license.
8950
- * See the LICENSE file in the root directory of this source tree.
8951
- *)
8952
-
8953
8960
  lucide-react/dist/esm/icons/chevron-right.js:
8954
- (**
8955
- * @license lucide-react v0.468.0 - ISC
8956
- *
8957
- * This source code is licensed under the ISC license.
8958
- * See the LICENSE file in the root directory of this source tree.
8959
- *)
8960
-
8961
8961
  lucide-react/dist/esm/icons/chevron-up.js:
8962
- (**
8963
- * @license lucide-react v0.468.0 - ISC
8964
- *
8965
- * This source code is licensed under the ISC license.
8966
- * See the LICENSE file in the root directory of this source tree.
8967
- *)
8968
-
8969
8962
  lucide-react/dist/esm/icons/circle-check-big.js:
8970
- (**
8971
- * @license lucide-react v0.468.0 - ISC
8972
- *
8973
- * This source code is licensed under the ISC license.
8974
- * See the LICENSE file in the root directory of this source tree.
8975
- *)
8976
-
8977
8963
  lucide-react/dist/esm/icons/copy.js:
8978
- (**
8979
- * @license lucide-react v0.468.0 - ISC
8980
- *
8981
- * This source code is licensed under the ISC license.
8982
- * See the LICENSE file in the root directory of this source tree.
8983
- *)
8984
-
8985
8964
  lucide-react/dist/esm/icons/corner-left-up.js:
8986
- (**
8987
- * @license lucide-react v0.468.0 - ISC
8988
- *
8989
- * This source code is licensed under the ISC license.
8990
- * See the LICENSE file in the root directory of this source tree.
8991
- *)
8992
-
8993
8965
  lucide-react/dist/esm/icons/ellipsis-vertical.js:
8994
- (**
8995
- * @license lucide-react v0.468.0 - ISC
8996
- *
8997
- * This source code is licensed under the ISC license.
8998
- * See the LICENSE file in the root directory of this source tree.
8999
- *)
9000
-
9001
8966
  lucide-react/dist/esm/icons/globe.js:
9002
- (**
9003
- * @license lucide-react v0.468.0 - ISC
9004
- *
9005
- * This source code is licensed under the ISC license.
9006
- * See the LICENSE file in the root directory of this source tree.
9007
- *)
9008
-
9009
8967
  lucide-react/dist/esm/icons/hash.js:
9010
- (**
9011
- * @license lucide-react v0.468.0 - ISC
9012
- *
9013
- * This source code is licensed under the ISC license.
9014
- * See the LICENSE file in the root directory of this source tree.
9015
- *)
9016
-
9017
8968
  lucide-react/dist/esm/icons/layers.js:
9018
- (**
9019
- * @license lucide-react v0.468.0 - ISC
9020
- *
9021
- * This source code is licensed under the ISC license.
9022
- * See the LICENSE file in the root directory of this source tree.
9023
- *)
9024
-
9025
8969
  lucide-react/dist/esm/icons/layout-grid.js:
9026
- (**
9027
- * @license lucide-react v0.468.0 - ISC
9028
- *
9029
- * This source code is licensed under the ISC license.
9030
- * See the LICENSE file in the root directory of this source tree.
9031
- *)
9032
-
9033
8970
  lucide-react/dist/esm/icons/link.js:
9034
- (**
9035
- * @license lucide-react v0.468.0 - ISC
9036
- *
9037
- * This source code is licensed under the ISC license.
9038
- * See the LICENSE file in the root directory of this source tree.
9039
- *)
9040
-
9041
8971
  lucide-react/dist/esm/icons/list.js:
9042
- (**
9043
- * @license lucide-react v0.468.0 - ISC
9044
- *
9045
- * This source code is licensed under the ISC license.
9046
- * See the LICENSE file in the root directory of this source tree.
9047
- *)
9048
-
9049
8972
  lucide-react/dist/esm/icons/lock-open.js:
9050
- (**
9051
- * @license lucide-react v0.468.0 - ISC
9052
- *
9053
- * This source code is licensed under the ISC license.
9054
- * See the LICENSE file in the root directory of this source tree.
9055
- *)
9056
-
9057
8973
  lucide-react/dist/esm/icons/lock.js:
9058
- (**
9059
- * @license lucide-react v0.468.0 - ISC
9060
- *
9061
- * This source code is licensed under the ISC license.
9062
- * See the LICENSE file in the root directory of this source tree.
9063
- *)
9064
-
9065
8974
  lucide-react/dist/esm/icons/monitor.js:
9066
- (**
9067
- * @license lucide-react v0.468.0 - ISC
9068
- *
9069
- * This source code is licensed under the ISC license.
9070
- * See the LICENSE file in the root directory of this source tree.
9071
- *)
9072
-
9073
8975
  lucide-react/dist/esm/icons/panel-left.js:
9074
- (**
9075
- * @license lucide-react v0.468.0 - ISC
9076
- *
9077
- * This source code is licensed under the ISC license.
9078
- * See the LICENSE file in the root directory of this source tree.
9079
- *)
9080
-
9081
8976
  lucide-react/dist/esm/icons/panel-right.js:
9082
- (**
9083
- * @license lucide-react v0.468.0 - ISC
9084
- *
9085
- * This source code is licensed under the ISC license.
9086
- * See the LICENSE file in the root directory of this source tree.
9087
- *)
9088
-
9089
8977
  lucide-react/dist/esm/icons/plus.js:
9090
- (**
9091
- * @license lucide-react v0.468.0 - ISC
9092
- *
9093
- * This source code is licensed under the ISC license.
9094
- * See the LICENSE file in the root directory of this source tree.
9095
- *)
9096
-
9097
8978
  lucide-react/dist/esm/icons/redo-2.js:
9098
- (**
9099
- * @license lucide-react v0.468.0 - ISC
9100
- *
9101
- * This source code is licensed under the ISC license.
9102
- * See the LICENSE file in the root directory of this source tree.
9103
- *)
9104
-
9105
8979
  lucide-react/dist/esm/icons/search.js:
9106
- (**
9107
- * @license lucide-react v0.468.0 - ISC
9108
- *
9109
- * This source code is licensed under the ISC license.
9110
- * See the LICENSE file in the root directory of this source tree.
9111
- *)
9112
-
9113
8980
  lucide-react/dist/esm/icons/sliders-horizontal.js:
9114
- (**
9115
- * @license lucide-react v0.468.0 - ISC
9116
- *
9117
- * This source code is licensed under the ISC license.
9118
- * See the LICENSE file in the root directory of this source tree.
9119
- *)
9120
-
9121
8981
  lucide-react/dist/esm/icons/smartphone.js:
9122
- (**
9123
- * @license lucide-react v0.468.0 - ISC
9124
- *
9125
- * This source code is licensed under the ISC license.
9126
- * See the LICENSE file in the root directory of this source tree.
9127
- *)
9128
-
9129
8982
  lucide-react/dist/esm/icons/tablet.js:
9130
- (**
9131
- * @license lucide-react v0.468.0 - ISC
9132
- *
9133
- * This source code is licensed under the ISC license.
9134
- * See the LICENSE file in the root directory of this source tree.
9135
- *)
9136
-
9137
8983
  lucide-react/dist/esm/icons/trash.js:
9138
- (**
9139
- * @license lucide-react v0.468.0 - ISC
9140
- *
9141
- * This source code is licensed under the ISC license.
9142
- * See the LICENSE file in the root directory of this source tree.
9143
- *)
9144
-
9145
8984
  lucide-react/dist/esm/icons/type.js:
9146
- (**
9147
- * @license lucide-react v0.468.0 - ISC
9148
- *
9149
- * This source code is licensed under the ISC license.
9150
- * See the LICENSE file in the root directory of this source tree.
9151
- *)
9152
-
9153
8985
  lucide-react/dist/esm/icons/undo-2.js:
9154
- (**
9155
- * @license lucide-react v0.468.0 - ISC
9156
- *
9157
- * This source code is licensed under the ISC license.
9158
- * See the LICENSE file in the root directory of this source tree.
9159
- *)
9160
-
9161
8986
  lucide-react/dist/esm/icons/zoom-in.js:
9162
- (**
9163
- * @license lucide-react v0.468.0 - ISC
9164
- *
9165
- * This source code is licensed under the ISC license.
9166
- * See the LICENSE file in the root directory of this source tree.
9167
- *)
9168
-
9169
8987
  lucide-react/dist/esm/icons/zoom-out.js:
9170
- (**
9171
- * @license lucide-react v0.468.0 - ISC
9172
- *
9173
- * This source code is licensed under the ISC license.
9174
- * See the LICENSE file in the root directory of this source tree.
9175
- *)
9176
-
9177
8988
  lucide-react/dist/esm/lucide-react.js:
9178
8989
  (**
9179
8990
  * @license lucide-react v0.468.0 - ISC