@measured/puck 0.21.0-canary.6dae6cb7 → 0.21.0-canary.74d9a160

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.
@@ -153,6 +153,42 @@ var require_classnames = __commonJS({
153
153
  }
154
154
  });
155
155
 
156
+ // ../../node_modules/fast-deep-equal/index.js
157
+ var require_fast_deep_equal = __commonJS({
158
+ "../../node_modules/fast-deep-equal/index.js"(exports2, module2) {
159
+ "use strict";
160
+ init_react_import();
161
+ module2.exports = function equal(a, b) {
162
+ if (a === b) return true;
163
+ if (a && b && typeof a == "object" && typeof b == "object") {
164
+ if (a.constructor !== b.constructor) return false;
165
+ var length, i, keys;
166
+ if (Array.isArray(a)) {
167
+ length = a.length;
168
+ if (length != b.length) return false;
169
+ for (i = length; i-- !== 0; )
170
+ if (!equal(a[i], b[i])) return false;
171
+ return true;
172
+ }
173
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
174
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
175
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
176
+ keys = Object.keys(a);
177
+ length = keys.length;
178
+ if (length !== Object.keys(b).length) return false;
179
+ for (i = length; i-- !== 0; )
180
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
181
+ for (i = length; i-- !== 0; ) {
182
+ var key = keys[i];
183
+ if (!equal(a[key], b[key])) return false;
184
+ }
185
+ return true;
186
+ }
187
+ return a !== a && b !== b;
188
+ };
189
+ }
190
+ });
191
+
156
192
  // bundle/no-external.ts
157
193
  var no_external_exports = {};
158
194
  __export(no_external_exports, {
@@ -1661,7 +1697,9 @@ var keyCodeMap = {
1661
1697
  KeyW: "w",
1662
1698
  KeyX: "x",
1663
1699
  KeyY: "y",
1664
- KeyZ: "z"
1700
+ KeyZ: "z",
1701
+ Delete: "delete",
1702
+ Backspace: "backspace"
1665
1703
  };
1666
1704
  var useHotkeyStore = (0, import_zustand.create)()(
1667
1705
  (0, import_middleware.subscribeWithSelector)((set) => ({
@@ -1685,8 +1723,10 @@ var monitorHotkeys = (doc) => {
1685
1723
  ([key2, value]) => value === !!combo[key2]
1686
1724
  );
1687
1725
  if (conditionMet) {
1688
- e.preventDefault();
1689
- cb();
1726
+ const handled = cb(e);
1727
+ if (handled !== false) {
1728
+ e.preventDefault();
1729
+ }
1690
1730
  }
1691
1731
  });
1692
1732
  if (key !== "meta" && key !== "ctrl" && key !== "shift") {
@@ -1709,6 +1749,10 @@ var monitorHotkeys = (doc) => {
1709
1749
  useHotkeyStore.getState().reset();
1710
1750
  }
1711
1751
  };
1752
+ const onBlur = () => {
1753
+ useHotkeyStore.getState().reset();
1754
+ };
1755
+ window.addEventListener("blur", onBlur);
1712
1756
  doc.addEventListener("keydown", onKeyDown);
1713
1757
  doc.addEventListener("keyup", onKeyUp);
1714
1758
  doc.addEventListener("visibilitychange", onVisibilityChanged);
@@ -1716,6 +1760,7 @@ var monitorHotkeys = (doc) => {
1716
1760
  doc.removeEventListener("keydown", onKeyDown);
1717
1761
  doc.removeEventListener("keyup", onKeyUp);
1718
1762
  doc.removeEventListener("visibilitychange", onVisibilityChanged);
1763
+ window.removeEventListener("blur", onBlur);
1719
1764
  };
1720
1765
  };
1721
1766
  var useMonitorHotkeys = () => {
@@ -1910,7 +1955,7 @@ var flattenData = (state, config) => {
1910
1955
  (content) => content,
1911
1956
  (item) => {
1912
1957
  data.push(item);
1913
- return null;
1958
+ return item;
1914
1959
  }
1915
1960
  );
1916
1961
  return data;
@@ -1918,13 +1963,13 @@ var flattenData = (state, config) => {
1918
1963
 
1919
1964
  // lib/get-changed.ts
1920
1965
  init_react_import();
1921
- var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
1966
+ var import_fast_equals = require("fast-equals");
1922
1967
  var getChanged = (newItem, oldItem) => {
1923
1968
  return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1924
1969
  const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1925
1970
  const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1926
1971
  return __spreadProps(__spreadValues({}, acc), {
1927
- [item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
1972
+ [item]: !(0, import_fast_equals.deepEqual)(oldItemProps[item], newItemProps[item])
1928
1973
  });
1929
1974
  }, {}) : {};
1930
1975
  };
@@ -2145,7 +2190,7 @@ var useRegisterFieldsSlice = (appStore, id) => {
2145
2190
 
2146
2191
  // lib/resolve-component-data.ts
2147
2192
  init_react_import();
2148
- var import_fast_deep_equal2 = __toESM(require("fast-deep-equal"));
2193
+ var import_fast_equals2 = require("fast-equals");
2149
2194
  var cache = { lastChange: {} };
2150
2195
  var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
2151
2196
  const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
@@ -2154,7 +2199,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
2154
2199
  const id = "id" in item.props ? item.props.id : "root";
2155
2200
  if (shouldRunResolver) {
2156
2201
  const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
2157
- if (trigger !== "force" && item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
2202
+ if (trigger !== "force" && item && (0, import_fast_equals2.deepEqual)(item, oldItem)) {
2158
2203
  return { node: resolved, didChange: false };
2159
2204
  }
2160
2205
  const changed = getChanged(item, oldItem);
@@ -2204,7 +2249,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
2204
2249
  };
2205
2250
  return {
2206
2251
  node: itemWithResolvedChildren,
2207
- didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
2252
+ didChange: !(0, import_fast_equals2.deepEqual)(item, itemWithResolvedChildren)
2208
2253
  };
2209
2254
  });
2210
2255
 
@@ -3750,11 +3795,13 @@ var ExternalInput = ({
3750
3795
  id,
3751
3796
  readOnly
3752
3797
  }) => {
3798
+ var _a;
3753
3799
  const {
3754
3800
  mapProp = (val) => val,
3755
3801
  mapRow = (val) => val,
3756
3802
  filterFields
3757
3803
  } = field || {};
3804
+ const { enabled: shouldCacheData } = (_a = field.cache) != null ? _a : { enabled: true };
3758
3805
  const [data, setData] = (0, import_react17.useState)([]);
3759
3806
  const [isOpen, setOpen] = (0, import_react17.useState)(false);
3760
3807
  const [isLoading, setIsLoading] = (0, import_react17.useState)(true);
@@ -3780,11 +3827,18 @@ var ExternalInput = ({
3780
3827
  (query, filters2) => __async(void 0, null, function* () {
3781
3828
  setIsLoading(true);
3782
3829
  const cacheKey = `${id}-${query}-${JSON.stringify(filters2)}`;
3783
- const listData = dataCache[cacheKey] || (yield field.fetchList({ query, filters: filters2 }));
3830
+ let listData;
3831
+ if (shouldCacheData && dataCache[cacheKey]) {
3832
+ listData = dataCache[cacheKey];
3833
+ } else {
3834
+ listData = yield field.fetchList({ query, filters: filters2 });
3835
+ }
3784
3836
  if (listData) {
3785
3837
  setData(listData);
3786
3838
  setIsLoading(false);
3787
- dataCache[cacheKey] = listData;
3839
+ if (shouldCacheData) {
3840
+ dataCache[cacheKey] = listData;
3841
+ }
3788
3842
  }
3789
3843
  }),
3790
3844
  [id, field]
@@ -3848,6 +3902,7 @@ var ExternalInput = ({
3848
3902
  }),
3849
3903
  onSubmit: (e) => {
3850
3904
  e.preventDefault();
3905
+ e.stopPropagation();
3851
3906
  search(searchQuery, filters);
3852
3907
  },
3853
3908
  children: [
@@ -4751,12 +4806,14 @@ var DraggableComponent = ({
4751
4806
  }
4752
4807
  return cleanup;
4753
4808
  }, [permissions.drag, zoneCompound]);
4809
+ const [, setRerender] = (0, import_react24.useState)(0);
4754
4810
  const ref = (0, import_react24.useRef)(null);
4755
4811
  const refSetter = (0, import_react24.useCallback)(
4756
4812
  (el) => {
4757
4813
  sortableRef(el);
4758
- if (el) {
4814
+ if (ref.current !== el) {
4759
4815
  ref.current = el;
4816
+ setRerender((update) => update + 1);
4760
4817
  }
4761
4818
  },
4762
4819
  [sortableRef]
@@ -5531,26 +5588,26 @@ var registerOverlayPortal = (el, opts = {}) => {
5531
5588
  capture: true
5532
5589
  });
5533
5590
  };
5534
- if (disableDragOnFocus) {
5535
- el.addEventListener("focus", onFocus, { capture: true });
5536
- el.addEventListener("blur", onBlur, { capture: true });
5537
- } else if (disableDrag) {
5591
+ if (disableDrag) {
5538
5592
  el.addEventListener("pointerdown", stopPropagation, {
5539
5593
  capture: true
5540
5594
  });
5595
+ } else if (disableDragOnFocus) {
5596
+ el.addEventListener("focus", onFocus, { capture: true });
5597
+ el.addEventListener("blur", onBlur, { capture: true });
5541
5598
  }
5542
5599
  el.setAttribute("data-puck-overlay-portal", "true");
5543
5600
  return () => {
5544
5601
  el.removeEventListener("mouseover", stopPropagation, {
5545
5602
  capture: true
5546
5603
  });
5547
- if (disableDragOnFocus) {
5548
- el.removeEventListener("focus", onFocus, { capture: true });
5549
- el.removeEventListener("blur", onFocus, { capture: true });
5550
- } else if (disableDrag) {
5604
+ if (disableDrag) {
5551
5605
  el.removeEventListener("pointerdown", stopPropagation, {
5552
5606
  capture: true
5553
5607
  });
5608
+ } else if (disableDragOnFocus) {
5609
+ el.removeEventListener("focus", onFocus, { capture: true });
5610
+ el.removeEventListener("blur", onBlur, { capture: true });
5554
5611
  }
5555
5612
  el.removeAttribute("data-puck-overlay-portal");
5556
5613
  };
@@ -5558,7 +5615,7 @@ var registerOverlayPortal = (el, opts = {}) => {
5558
5615
 
5559
5616
  // css-module:/home/runner/work/puck/puck/packages/core/components/InlineTextField/styles.module.css#css-module
5560
5617
  init_react_import();
5561
- var styles_module_default13 = { "InlineTextField": "_InlineTextField_1xph6_1" };
5618
+ var styles_module_default13 = { "InlineTextField": "_InlineTextField_104qp_1" };
5562
5619
 
5563
5620
  // lib/data/set-deep.ts
5564
5621
  init_react_import();
@@ -7048,7 +7105,7 @@ Drawer.Item = DrawerItem;
7048
7105
 
7049
7106
  // components/Puck/index.tsx
7050
7107
  init_react_import();
7051
- var import_react59 = require("react");
7108
+ var import_react60 = require("react");
7052
7109
 
7053
7110
  // components/SidebarSection/index.tsx
7054
7111
  init_react_import();
@@ -8586,9 +8643,70 @@ var usePreviewModeHotkeys = () => {
8586
8643
  useHotkey({ ctrl: true, i: true }, toggleInteractive);
8587
8644
  };
8588
8645
 
8589
- // lib/use-puck.ts
8646
+ // lib/use-delete-hotkeys.ts
8590
8647
  init_react_import();
8591
8648
  var import_react55 = require("react");
8649
+ var isElementVisible = (element) => {
8650
+ let current = element;
8651
+ while (current && current !== document.body) {
8652
+ const style = window.getComputedStyle(current);
8653
+ if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" || current.getAttribute("aria-hidden") === "true" || current.hasAttribute("hidden")) {
8654
+ return false;
8655
+ }
8656
+ current = current.parentElement;
8657
+ }
8658
+ return true;
8659
+ };
8660
+ var shouldBlockDeleteHotkey = (e) => {
8661
+ var _a;
8662
+ if (e == null ? void 0 : e.defaultPrevented) return true;
8663
+ const origin = ((_a = e == null ? void 0 : e.composedPath) == null ? void 0 : _a.call(e)[0]) || (e == null ? void 0 : e.target) || document.activeElement;
8664
+ if (origin instanceof HTMLElement) {
8665
+ const tag = origin.tagName.toLowerCase();
8666
+ if (tag === "input" || tag === "textarea" || tag === "select") return true;
8667
+ if (origin.isContentEditable) return true;
8668
+ const role = origin.getAttribute("role");
8669
+ if (role === "textbox" || role === "combobox" || role === "searchbox" || role === "listbox" || role === "grid") {
8670
+ return true;
8671
+ }
8672
+ }
8673
+ const modal = document.querySelector(
8674
+ 'dialog[open], [aria-modal="true"], [role="dialog"], [role="alertdialog"]'
8675
+ );
8676
+ if (modal && isElementVisible(modal)) {
8677
+ return true;
8678
+ }
8679
+ return false;
8680
+ };
8681
+ var useDeleteHotkeys = () => {
8682
+ const appStore = useAppStoreApi();
8683
+ const deleteSelectedComponent = (0, import_react55.useCallback)(
8684
+ (e) => {
8685
+ var _a;
8686
+ if (shouldBlockDeleteHotkey(e)) {
8687
+ return false;
8688
+ }
8689
+ const { state, dispatch, permissions, selectedItem } = appStore.getState();
8690
+ const sel = (_a = state.ui) == null ? void 0 : _a.itemSelector;
8691
+ if (!(sel == null ? void 0 : sel.zone) || !selectedItem) return true;
8692
+ if (!permissions.getPermissions({ item: selectedItem }).delete)
8693
+ return true;
8694
+ dispatch({
8695
+ type: "remove",
8696
+ index: sel.index,
8697
+ zone: sel.zone
8698
+ });
8699
+ return true;
8700
+ },
8701
+ [appStore]
8702
+ );
8703
+ useHotkey({ delete: true }, deleteSelectedComponent);
8704
+ useHotkey({ backspace: true }, deleteSelectedComponent);
8705
+ };
8706
+
8707
+ // lib/use-puck.ts
8708
+ init_react_import();
8709
+ var import_react56 = require("react");
8592
8710
  var import_zustand6 = require("zustand");
8593
8711
  var generateUsePuck = (store) => {
8594
8712
  const history = {
@@ -8615,7 +8733,7 @@ var generateUsePuck = (store) => {
8615
8733
  };
8616
8734
  return storeData;
8617
8735
  };
8618
- var UsePuckStoreContext = (0, import_react55.createContext)(
8736
+ var UsePuckStoreContext = (0, import_react56.createContext)(
8619
8737
  null
8620
8738
  );
8621
8739
  var convertToPickedStore = (store) => {
@@ -8629,12 +8747,12 @@ var convertToPickedStore = (store) => {
8629
8747
  };
8630
8748
  };
8631
8749
  var useRegisterUsePuckStore = (appStore) => {
8632
- const [usePuckStore] = (0, import_react55.useState)(
8750
+ const [usePuckStore] = (0, import_react56.useState)(
8633
8751
  () => (0, import_zustand6.createStore)(
8634
8752
  () => generateUsePuck(convertToPickedStore(appStore.getState()))
8635
8753
  )
8636
8754
  );
8637
- (0, import_react55.useEffect)(() => {
8755
+ (0, import_react56.useEffect)(() => {
8638
8756
  return appStore.subscribe(
8639
8757
  (store) => convertToPickedStore(store),
8640
8758
  (pickedStore) => {
@@ -8646,7 +8764,7 @@ var useRegisterUsePuckStore = (appStore) => {
8646
8764
  };
8647
8765
  function createUsePuck() {
8648
8766
  return function usePuck2(selector) {
8649
- const usePuckApi = (0, import_react55.useContext)(UsePuckStoreContext);
8767
+ const usePuckApi = (0, import_react56.useContext)(UsePuckStoreContext);
8650
8768
  if (!usePuckApi) {
8651
8769
  throw new Error("usePuck must be used inside <Puck>.");
8652
8770
  }
@@ -8658,7 +8776,7 @@ function createUsePuck() {
8658
8776
  };
8659
8777
  }
8660
8778
  function usePuck() {
8661
- (0, import_react55.useEffect)(() => {
8779
+ (0, import_react56.useEffect)(() => {
8662
8780
  console.warn(
8663
8781
  "You're using the `usePuck` method without a selector, which may cause unnecessary re-renders. Replace with `createUsePuck` and provide a selector for improved performance."
8664
8782
  );
@@ -8666,7 +8784,7 @@ function usePuck() {
8666
8784
  return createUsePuck()((s) => s);
8667
8785
  }
8668
8786
  function useGetPuck() {
8669
- const usePuckApi = (0, import_react55.useContext)(UsePuckStoreContext);
8787
+ const usePuckApi = (0, import_react56.useContext)(UsePuckStoreContext);
8670
8788
  if (!usePuckApi) {
8671
8789
  throw new Error("usePuckGet must be used inside <Puck>.");
8672
8790
  }
@@ -8674,11 +8792,11 @@ function useGetPuck() {
8674
8792
  }
8675
8793
 
8676
8794
  // components/Puck/index.tsx
8677
- var import_fast_deep_equal3 = __toESM(require("fast-deep-equal"));
8795
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
8678
8796
 
8679
8797
  // components/Puck/components/Header/index.tsx
8680
8798
  init_react_import();
8681
- var import_react56 = require("react");
8799
+ var import_react57 = require("react");
8682
8800
 
8683
8801
  // components/MenuBar/index.tsx
8684
8802
  init_react_import();
@@ -8760,7 +8878,7 @@ var HeaderInner = () => {
8760
8878
  } = usePropsContext();
8761
8879
  const dispatch = useAppStore((s) => s.dispatch);
8762
8880
  const appStore = useAppStoreApi();
8763
- const defaultHeaderRender = (0, import_react56.useMemo)(() => {
8881
+ const defaultHeaderRender = (0, import_react57.useMemo)(() => {
8764
8882
  if (renderHeader) {
8765
8883
  console.warn(
8766
8884
  "`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
@@ -8775,7 +8893,7 @@ var HeaderInner = () => {
8775
8893
  }
8776
8894
  return DefaultOverride;
8777
8895
  }, [renderHeader]);
8778
- const defaultHeaderActionsRender = (0, import_react56.useMemo)(() => {
8896
+ const defaultHeaderActionsRender = (0, import_react57.useMemo)(() => {
8779
8897
  if (renderHeaderActions) {
8780
8898
  console.warn(
8781
8899
  "`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
@@ -8795,7 +8913,7 @@ var HeaderInner = () => {
8795
8913
  const CustomHeaderActions = useAppStore(
8796
8914
  (s) => s.overrides.headerActions || defaultHeaderActionsRender
8797
8915
  );
8798
- const [menuOpen, setMenuOpen] = (0, import_react56.useState)(false);
8916
+ const [menuOpen, setMenuOpen] = (0, import_react57.useState)(false);
8799
8917
  const rootTitle = useAppStore((s) => {
8800
8918
  var _a, _b;
8801
8919
  const rootData = (_a = s.state.indexes.nodes["root"]) == null ? void 0 : _a.data;
@@ -8805,7 +8923,7 @@ var HeaderInner = () => {
8805
8923
  const rightSideBarVisible = useAppStore(
8806
8924
  (s) => s.state.ui.rightSideBarVisible
8807
8925
  );
8808
- const toggleSidebars = (0, import_react56.useCallback)(
8926
+ const toggleSidebars = (0, import_react57.useCallback)(
8809
8927
  (sidebar) => {
8810
8928
  const widerViewport = window.matchMedia("(min-width: 638px)").matches;
8811
8929
  const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
@@ -8908,14 +9026,14 @@ var HeaderInner = () => {
8908
9026
  }
8909
9027
  );
8910
9028
  };
8911
- var Header = (0, import_react56.memo)(HeaderInner);
9029
+ var Header = (0, import_react57.memo)(HeaderInner);
8912
9030
 
8913
9031
  // components/Puck/components/Sidebar/index.tsx
8914
9032
  init_react_import();
8915
9033
 
8916
9034
  // components/Puck/components/ResizeHandle/index.tsx
8917
9035
  init_react_import();
8918
- var import_react57 = require("react");
9036
+ var import_react58 = require("react");
8919
9037
 
8920
9038
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/ResizeHandle/styles.module.css#css-module
8921
9039
  init_react_import();
@@ -8932,11 +9050,11 @@ var ResizeHandle = ({
8932
9050
  }) => {
8933
9051
  const { frameRef } = useCanvasFrame();
8934
9052
  const resetAutoZoom = useResetAutoZoom(frameRef);
8935
- const handleRef = (0, import_react57.useRef)(null);
8936
- const isDragging = (0, import_react57.useRef)(false);
8937
- const startX = (0, import_react57.useRef)(0);
8938
- const startWidth = (0, import_react57.useRef)(0);
8939
- const handleMouseMove = (0, import_react57.useCallback)(
9053
+ const handleRef = (0, import_react58.useRef)(null);
9054
+ const isDragging = (0, import_react58.useRef)(false);
9055
+ const startX = (0, import_react58.useRef)(0);
9056
+ const startWidth = (0, import_react58.useRef)(0);
9057
+ const handleMouseMove = (0, import_react58.useCallback)(
8940
9058
  (e) => {
8941
9059
  if (!isDragging.current) return;
8942
9060
  const delta = e.clientX - startX.current;
@@ -8947,7 +9065,7 @@ var ResizeHandle = ({
8947
9065
  },
8948
9066
  [onResize, position]
8949
9067
  );
8950
- const handleMouseUp = (0, import_react57.useCallback)(() => {
9068
+ const handleMouseUp = (0, import_react58.useCallback)(() => {
8951
9069
  var _a;
8952
9070
  if (!isDragging.current) return;
8953
9071
  isDragging.current = false;
@@ -8963,7 +9081,7 @@ var ResizeHandle = ({
8963
9081
  onResizeEnd(finalWidth);
8964
9082
  resetAutoZoom();
8965
9083
  }, [onResizeEnd]);
8966
- const handleMouseDown = (0, import_react57.useCallback)(
9084
+ const handleMouseDown = (0, import_react58.useCallback)(
8967
9085
  (e) => {
8968
9086
  var _a;
8969
9087
  isDragging.current = true;
@@ -9023,14 +9141,14 @@ var Sidebar = ({
9023
9141
 
9024
9142
  // lib/use-sidebar-resize.ts
9025
9143
  init_react_import();
9026
- var import_react58 = require("react");
9144
+ var import_react59 = require("react");
9027
9145
  function useSidebarResize(position, dispatch) {
9028
- const [width, setWidth] = (0, import_react58.useState)(null);
9029
- const sidebarRef = (0, import_react58.useRef)(null);
9146
+ const [width, setWidth] = (0, import_react59.useState)(null);
9147
+ const sidebarRef = (0, import_react59.useRef)(null);
9030
9148
  const storeWidth = useAppStore(
9031
9149
  (s) => position === "left" ? s.state.ui.leftSideBarWidth : s.state.ui.rightSideBarWidth
9032
9150
  );
9033
- (0, import_react58.useEffect)(() => {
9151
+ (0, import_react59.useEffect)(() => {
9034
9152
  if (typeof window !== "undefined" && !storeWidth) {
9035
9153
  try {
9036
9154
  const savedWidths = localStorage.getItem("puck-sidebar-widths");
@@ -9055,12 +9173,12 @@ function useSidebarResize(position, dispatch) {
9055
9173
  }
9056
9174
  }
9057
9175
  }, [dispatch, position, storeWidth]);
9058
- (0, import_react58.useEffect)(() => {
9176
+ (0, import_react59.useEffect)(() => {
9059
9177
  if (storeWidth !== void 0) {
9060
9178
  setWidth(storeWidth);
9061
9179
  }
9062
9180
  }, [storeWidth]);
9063
- const handleResizeEnd = (0, import_react58.useCallback)(
9181
+ const handleResizeEnd = (0, import_react59.useCallback)(
9064
9182
  (width2) => {
9065
9183
  dispatch({
9066
9184
  type: "setUi",
@@ -9102,6 +9220,15 @@ function useSidebarResize(position, dispatch) {
9102
9220
  };
9103
9221
  }
9104
9222
 
9223
+ // lib/data/to-component.ts
9224
+ init_react_import();
9225
+ var toComponent = (item) => {
9226
+ return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
9227
+ props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
9228
+ type: "root"
9229
+ });
9230
+ };
9231
+
9105
9232
  // components/Puck/index.tsx
9106
9233
  var import_jsx_runtime46 = require("react/jsx-runtime");
9107
9234
  var getClassName31 = get_class_name_factory_default("Puck", styles_module_default15);
@@ -9115,11 +9242,11 @@ var FieldSideBar = () => {
9115
9242
  );
9116
9243
  return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(SidebarSection, { noPadding: true, noBorderTop: true, showBreadcrumbs: true, title, children: /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(Fields, {}) });
9117
9244
  };
9118
- var propsContext = (0, import_react59.createContext)({});
9245
+ var propsContext = (0, import_react60.createContext)({});
9119
9246
  function PropsProvider(props) {
9120
9247
  return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)(propsContext.Provider, { value: props, children: props.children });
9121
9248
  }
9122
- var usePropsContext = () => (0, import_react59.useContext)(propsContext);
9249
+ var usePropsContext = () => (0, import_react60.useContext)(propsContext);
9123
9250
  function PuckProvider({ children }) {
9124
9251
  const {
9125
9252
  config,
@@ -9136,14 +9263,14 @@ function PuckProvider({ children }) {
9136
9263
  onAction,
9137
9264
  fieldTransforms
9138
9265
  } = usePropsContext();
9139
- const iframe = (0, import_react59.useMemo)(
9266
+ const iframe = (0, import_react60.useMemo)(
9140
9267
  () => __spreadValues({
9141
9268
  enabled: true,
9142
9269
  waitForStyles: true
9143
9270
  }, _iframe),
9144
9271
  [_iframe]
9145
9272
  );
9146
- const [generatedAppState] = (0, import_react59.useState)(() => {
9273
+ const [generatedAppState] = (0, import_react60.useState)(() => {
9147
9274
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
9148
9275
  const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
9149
9276
  let clientUiState = {};
@@ -9178,9 +9305,13 @@ function PuckProvider({ children }) {
9178
9305
  }
9179
9306
  const rootProps = ((_h = initialData == null ? void 0 : initialData.root) == null ? void 0 : _h.props) || (initialData == null ? void 0 : initialData.root) || {};
9180
9307
  const defaultedRootProps = __spreadValues(__spreadValues({}, (_i = config.root) == null ? void 0 : _i.defaultProps), rootProps);
9308
+ const root = populateIds(
9309
+ toComponent(__spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: defaultedRootProps })),
9310
+ config
9311
+ );
9181
9312
  const newAppState = __spreadProps(__spreadValues({}, defaultAppState), {
9182
9313
  data: __spreadProps(__spreadValues({}, initialData), {
9183
- root: __spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: defaultedRootProps }),
9314
+ root: __spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: root.props }),
9184
9315
  content: initialData.content || []
9185
9316
  }),
9186
9317
  ui: __spreadProps(__spreadValues(__spreadValues({}, initial), clientUiState), {
@@ -9203,7 +9334,7 @@ function PuckProvider({ children }) {
9203
9334
  return walkAppState(newAppState, config);
9204
9335
  });
9205
9336
  const { appendData = true } = _initialHistory || {};
9206
- const [blendedHistories] = (0, import_react59.useState)(
9337
+ const [blendedHistories] = (0, import_react60.useState)(
9207
9338
  [
9208
9339
  ...(_initialHistory == null ? void 0 : _initialHistory.histories) || [],
9209
9340
  ...appendData ? [{ state: generatedAppState }] : []
@@ -9223,7 +9354,7 @@ function PuckProvider({ children }) {
9223
9354
  overrides,
9224
9355
  plugins
9225
9356
  });
9226
- const loadedFieldTransforms = (0, import_react59.useMemo)(() => {
9357
+ const loadedFieldTransforms = (0, import_react60.useMemo)(() => {
9227
9358
  const _plugins = plugins || [];
9228
9359
  const pluginFieldTransforms = _plugins.reduce(
9229
9360
  (acc, plugin) => __spreadValues(__spreadValues({}, acc), plugin.fieldTransforms),
@@ -9231,7 +9362,7 @@ function PuckProvider({ children }) {
9231
9362
  );
9232
9363
  return __spreadValues(__spreadValues({}, pluginFieldTransforms), fieldTransforms);
9233
9364
  }, [fieldTransforms, plugins]);
9234
- const generateAppStore = (0, import_react59.useCallback)(
9365
+ const generateAppStore = (0, import_react60.useCallback)(
9235
9366
  (state) => {
9236
9367
  return {
9237
9368
  state,
@@ -9257,15 +9388,15 @@ function PuckProvider({ children }) {
9257
9388
  loadedFieldTransforms
9258
9389
  ]
9259
9390
  );
9260
- const [appStore] = (0, import_react59.useState)(
9391
+ const [appStore] = (0, import_react60.useState)(
9261
9392
  () => createAppStore(generateAppStore(initialAppState))
9262
9393
  );
9263
- (0, import_react59.useEffect)(() => {
9394
+ (0, import_react60.useEffect)(() => {
9264
9395
  if (process.env.NODE_ENV !== "production") {
9265
9396
  window.__PUCK_INTERNAL_DO_NOT_USE = { appStore };
9266
9397
  }
9267
9398
  }, [appStore]);
9268
- (0, import_react59.useEffect)(() => {
9399
+ (0, import_react60.useEffect)(() => {
9269
9400
  const state = appStore.getState().state;
9270
9401
  appStore.setState(__spreadValues({}, generateAppStore(state)));
9271
9402
  }, [config, plugins, loadedOverrides, viewports, iframe, onAction, metadata]);
@@ -9274,13 +9405,13 @@ function PuckProvider({ children }) {
9274
9405
  index: initialHistoryIndex,
9275
9406
  initialAppState
9276
9407
  });
9277
- const previousData = (0, import_react59.useRef)(null);
9278
- (0, import_react59.useEffect)(() => {
9408
+ const previousData = (0, import_react60.useRef)(null);
9409
+ (0, import_react60.useEffect)(() => {
9279
9410
  appStore.subscribe(
9280
9411
  (s) => s.state.data,
9281
9412
  (data) => {
9282
9413
  if (onChange) {
9283
- if ((0, import_fast_deep_equal3.default)(data, previousData.current)) return;
9414
+ if ((0, import_fast_deep_equal.default)(data, previousData.current)) return;
9284
9415
  onChange(data);
9285
9416
  previousData.current = data;
9286
9417
  }
@@ -9289,7 +9420,7 @@ function PuckProvider({ children }) {
9289
9420
  }, []);
9290
9421
  useRegisterPermissionsSlice(appStore, permissions);
9291
9422
  const uPuckStore = useRegisterUsePuckStore(appStore);
9292
- (0, import_react59.useEffect)(() => {
9423
+ (0, import_react60.useEffect)(() => {
9293
9424
  const { resolveAndCommitData } = appStore.getState();
9294
9425
  resolveAndCommitData();
9295
9426
  }, []);
@@ -9301,7 +9432,7 @@ function PuckLayout({ children }) {
9301
9432
  dnd,
9302
9433
  initialHistory: _initialHistory
9303
9434
  } = usePropsContext();
9304
- const iframe = (0, import_react59.useMemo)(
9435
+ const iframe = (0, import_react60.useMemo)(
9305
9436
  () => __spreadValues({
9306
9437
  enabled: true,
9307
9438
  waitForStyles: true
@@ -9326,7 +9457,7 @@ function PuckLayout({ children }) {
9326
9457
  sidebarRef: rightSidebarRef,
9327
9458
  handleResizeEnd: handleRightSidebarResizeEnd
9328
9459
  } = useSidebarResize("right", dispatch);
9329
- (0, import_react59.useEffect)(() => {
9460
+ (0, import_react60.useEffect)(() => {
9330
9461
  if (!window.matchMedia("(min-width: 638px)").matches) {
9331
9462
  dispatch({
9332
9463
  type: "setUi",
@@ -9350,17 +9481,18 @@ function PuckLayout({ children }) {
9350
9481
  };
9351
9482
  }, []);
9352
9483
  const overrides = useAppStore((s) => s.overrides);
9353
- const CustomPuck = (0, import_react59.useMemo)(
9484
+ const CustomPuck = (0, import_react60.useMemo)(
9354
9485
  () => overrides.puck || DefaultOverride,
9355
9486
  [overrides]
9356
9487
  );
9357
- const [mounted, setMounted] = (0, import_react59.useState)(false);
9358
- (0, import_react59.useEffect)(() => {
9488
+ const [mounted, setMounted] = (0, import_react60.useState)(false);
9489
+ (0, import_react60.useEffect)(() => {
9359
9490
  setMounted(true);
9360
9491
  }, []);
9361
9492
  const ready = useAppStore((s) => s.status === "READY");
9362
9493
  useMonitorHotkeys();
9363
- (0, import_react59.useEffect)(() => {
9494
+ useDeleteHotkeys();
9495
+ (0, import_react60.useEffect)(() => {
9364
9496
  if (ready && iframe.enabled) {
9365
9497
  const frameDoc = getFrame();
9366
9498
  if (frameDoc) {
@@ -9598,17 +9730,6 @@ function transformProps(data, propTransforms, config = { components: {} }) {
9598
9730
 
9599
9731
  // lib/resolve-all-data.ts
9600
9732
  init_react_import();
9601
-
9602
- // lib/data/to-component.ts
9603
- init_react_import();
9604
- var toComponent = (item) => {
9605
- return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
9606
- props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
9607
- type: "root"
9608
- });
9609
- };
9610
-
9611
- // lib/resolve-all-data.ts
9612
9733
  function resolveAllData(_0, _1) {
9613
9734
  return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
9614
9735
  var _a;