@measured/puck 0.21.0-canary.6dae6cb7 → 0.21.0-canary.9c2c8fe9

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.
@@ -24,7 +24,7 @@ import {
24
24
  walkAppState,
25
25
  walkField,
26
26
  walkTree
27
- } from "./chunk-OOLYDXKW.mjs";
27
+ } from "./chunk-X7YZ3YE7.mjs";
28
28
 
29
29
  // ../../node_modules/classnames/index.js
30
30
  var require_classnames = __commonJS({
@@ -88,6 +88,42 @@ var require_classnames = __commonJS({
88
88
  }
89
89
  });
90
90
 
91
+ // ../../node_modules/fast-deep-equal/index.js
92
+ var require_fast_deep_equal = __commonJS({
93
+ "../../node_modules/fast-deep-equal/index.js"(exports, module) {
94
+ "use strict";
95
+ init_react_import();
96
+ module.exports = function equal(a, b) {
97
+ if (a === b) return true;
98
+ if (a && b && typeof a == "object" && typeof b == "object") {
99
+ if (a.constructor !== b.constructor) return false;
100
+ var length, i, keys;
101
+ if (Array.isArray(a)) {
102
+ length = a.length;
103
+ if (length != b.length) return false;
104
+ for (i = length; i-- !== 0; )
105
+ if (!equal(a[i], b[i])) return false;
106
+ return true;
107
+ }
108
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
109
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
110
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
111
+ keys = Object.keys(a);
112
+ length = keys.length;
113
+ if (length !== Object.keys(b).length) return false;
114
+ for (i = length; i-- !== 0; )
115
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
116
+ for (i = length; i-- !== 0; ) {
117
+ var key = keys[i];
118
+ if (!equal(a[key], b[key])) return false;
119
+ }
120
+ return true;
121
+ }
122
+ return a !== a && b !== b;
123
+ };
124
+ }
125
+ });
126
+
91
127
  // types/API/Overrides.ts
92
128
  init_react_import();
93
129
  var overrideKeys = [
@@ -768,7 +804,9 @@ var keyCodeMap = {
768
804
  KeyW: "w",
769
805
  KeyX: "x",
770
806
  KeyY: "y",
771
- KeyZ: "z"
807
+ KeyZ: "z",
808
+ Delete: "delete",
809
+ Backspace: "backspace"
772
810
  };
773
811
  var useHotkeyStore = create()(
774
812
  subscribeWithSelector((set) => ({
@@ -792,8 +830,10 @@ var monitorHotkeys = (doc) => {
792
830
  ([key2, value]) => value === !!combo[key2]
793
831
  );
794
832
  if (conditionMet) {
795
- e.preventDefault();
796
- cb();
833
+ const handled = cb(e);
834
+ if (handled !== false) {
835
+ e.preventDefault();
836
+ }
797
837
  }
798
838
  });
799
839
  if (key !== "meta" && key !== "ctrl" && key !== "shift") {
@@ -816,6 +856,10 @@ var monitorHotkeys = (doc) => {
816
856
  useHotkeyStore.getState().reset();
817
857
  }
818
858
  };
859
+ const onBlur = () => {
860
+ useHotkeyStore.getState().reset();
861
+ };
862
+ window.addEventListener("blur", onBlur);
819
863
  doc.addEventListener("keydown", onKeyDown);
820
864
  doc.addEventListener("keyup", onKeyUp);
821
865
  doc.addEventListener("visibilitychange", onVisibilityChanged);
@@ -823,6 +867,7 @@ var monitorHotkeys = (doc) => {
823
867
  doc.removeEventListener("keydown", onKeyDown);
824
868
  doc.removeEventListener("keyup", onKeyUp);
825
869
  doc.removeEventListener("visibilitychange", onVisibilityChanged);
870
+ window.removeEventListener("blur", onBlur);
826
871
  };
827
872
  };
828
873
  var useMonitorHotkeys = () => {
@@ -1017,7 +1062,7 @@ var flattenData = (state, config) => {
1017
1062
  (content) => content,
1018
1063
  (item) => {
1019
1064
  data.push(item);
1020
- return null;
1065
+ return item;
1021
1066
  }
1022
1067
  );
1023
1068
  return data;
@@ -5661,7 +5706,7 @@ var registerOverlayPortal = (el, opts = {}) => {
5661
5706
 
5662
5707
  // css-module:/home/runner/work/puck/puck/packages/core/components/InlineTextField/styles.module.css#css-module
5663
5708
  init_react_import();
5664
- var styles_module_default13 = { "InlineTextField": "_InlineTextField_1xph6_1" };
5709
+ var styles_module_default13 = { "InlineTextField": "_InlineTextField_104qp_1" };
5665
5710
 
5666
5711
  // lib/data/set-deep.ts
5667
5712
  init_react_import();
@@ -6421,7 +6466,7 @@ function useGetPuck() {
6421
6466
  init_react_import();
6422
6467
  import {
6423
6468
  createContext as createContext8,
6424
- useCallback as useCallback20,
6469
+ useCallback as useCallback21,
6425
6470
  useContext as useContext13,
6426
6471
  useEffect as useEffect29,
6427
6472
  useMemo as useMemo20,
@@ -7981,12 +8026,73 @@ var usePreviewModeHotkeys = () => {
7981
8026
  useHotkey({ ctrl: true, i: true }, toggleInteractive);
7982
8027
  };
7983
8028
 
8029
+ // lib/use-delete-hotkeys.ts
8030
+ init_react_import();
8031
+ import { useCallback as useCallback17 } from "react";
8032
+ var isElementVisible = (element) => {
8033
+ let current = element;
8034
+ while (current && current !== document.body) {
8035
+ const style = window.getComputedStyle(current);
8036
+ if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" || current.getAttribute("aria-hidden") === "true" || current.hasAttribute("hidden")) {
8037
+ return false;
8038
+ }
8039
+ current = current.parentElement;
8040
+ }
8041
+ return true;
8042
+ };
8043
+ var shouldBlockDeleteHotkey = (e) => {
8044
+ var _a;
8045
+ if (e == null ? void 0 : e.defaultPrevented) return true;
8046
+ const origin = ((_a = e == null ? void 0 : e.composedPath) == null ? void 0 : _a.call(e)[0]) || (e == null ? void 0 : e.target) || document.activeElement;
8047
+ if (origin instanceof HTMLElement) {
8048
+ const tag = origin.tagName.toLowerCase();
8049
+ if (tag === "input" || tag === "textarea" || tag === "select") return true;
8050
+ if (origin.isContentEditable) return true;
8051
+ const role = origin.getAttribute("role");
8052
+ if (role === "textbox" || role === "combobox" || role === "searchbox" || role === "listbox" || role === "grid") {
8053
+ return true;
8054
+ }
8055
+ }
8056
+ const modal = document.querySelector(
8057
+ 'dialog[open], [aria-modal="true"], [role="dialog"], [role="alertdialog"]'
8058
+ );
8059
+ if (modal && isElementVisible(modal)) {
8060
+ return true;
8061
+ }
8062
+ return false;
8063
+ };
8064
+ var useDeleteHotkeys = () => {
8065
+ const appStore = useAppStoreApi();
8066
+ const deleteSelectedComponent = useCallback17(
8067
+ (e) => {
8068
+ var _a;
8069
+ if (shouldBlockDeleteHotkey(e)) {
8070
+ return false;
8071
+ }
8072
+ const { state, dispatch, permissions, selectedItem } = appStore.getState();
8073
+ const sel = (_a = state.ui) == null ? void 0 : _a.itemSelector;
8074
+ if (!(sel == null ? void 0 : sel.zone) || !selectedItem) return true;
8075
+ if (!permissions.getPermissions({ item: selectedItem }).delete)
8076
+ return true;
8077
+ dispatch({
8078
+ type: "remove",
8079
+ index: sel.index,
8080
+ zone: sel.zone
8081
+ });
8082
+ return true;
8083
+ },
8084
+ [appStore]
8085
+ );
8086
+ useHotkey({ delete: true }, deleteSelectedComponent);
8087
+ useHotkey({ backspace: true }, deleteSelectedComponent);
8088
+ };
8089
+
7984
8090
  // components/Puck/index.tsx
7985
- import fdeq from "fast-deep-equal";
8091
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
7986
8092
 
7987
8093
  // components/Puck/components/Header/index.tsx
7988
8094
  init_react_import();
7989
- import { memo as memo4, useCallback as useCallback17, useMemo as useMemo19, useState as useState23 } from "react";
8095
+ import { memo as memo4, useCallback as useCallback18, useMemo as useMemo19, useState as useState23 } from "react";
7990
8096
 
7991
8097
  // components/MenuBar/index.tsx
7992
8098
  init_react_import();
@@ -8113,7 +8219,7 @@ var HeaderInner = () => {
8113
8219
  const rightSideBarVisible = useAppStore(
8114
8220
  (s) => s.state.ui.rightSideBarVisible
8115
8221
  );
8116
- const toggleSidebars = useCallback17(
8222
+ const toggleSidebars = useCallback18(
8117
8223
  (sidebar) => {
8118
8224
  const widerViewport = window.matchMedia("(min-width: 638px)").matches;
8119
8225
  const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
@@ -8223,7 +8329,7 @@ init_react_import();
8223
8329
 
8224
8330
  // components/Puck/components/ResizeHandle/index.tsx
8225
8331
  init_react_import();
8226
- import { useCallback as useCallback18, useRef as useRef10 } from "react";
8332
+ import { useCallback as useCallback19, useRef as useRef10 } from "react";
8227
8333
 
8228
8334
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/ResizeHandle/styles.module.css#css-module
8229
8335
  init_react_import();
@@ -8244,7 +8350,7 @@ var ResizeHandle = ({
8244
8350
  const isDragging = useRef10(false);
8245
8351
  const startX = useRef10(0);
8246
8352
  const startWidth = useRef10(0);
8247
- const handleMouseMove = useCallback18(
8353
+ const handleMouseMove = useCallback19(
8248
8354
  (e) => {
8249
8355
  if (!isDragging.current) return;
8250
8356
  const delta = e.clientX - startX.current;
@@ -8255,7 +8361,7 @@ var ResizeHandle = ({
8255
8361
  },
8256
8362
  [onResize, position]
8257
8363
  );
8258
- const handleMouseUp = useCallback18(() => {
8364
+ const handleMouseUp = useCallback19(() => {
8259
8365
  var _a;
8260
8366
  if (!isDragging.current) return;
8261
8367
  isDragging.current = false;
@@ -8271,7 +8377,7 @@ var ResizeHandle = ({
8271
8377
  onResizeEnd(finalWidth);
8272
8378
  resetAutoZoom();
8273
8379
  }, [onResizeEnd]);
8274
- const handleMouseDown = useCallback18(
8380
+ const handleMouseDown = useCallback19(
8275
8381
  (e) => {
8276
8382
  var _a;
8277
8383
  isDragging.current = true;
@@ -8331,7 +8437,7 @@ var Sidebar = ({
8331
8437
 
8332
8438
  // lib/use-sidebar-resize.ts
8333
8439
  init_react_import();
8334
- import { useCallback as useCallback19, useEffect as useEffect28, useRef as useRef11, useState as useState24 } from "react";
8440
+ import { useCallback as useCallback20, useEffect as useEffect28, useRef as useRef11, useState as useState24 } from "react";
8335
8441
  function useSidebarResize(position, dispatch) {
8336
8442
  const [width, setWidth] = useState24(null);
8337
8443
  const sidebarRef = useRef11(null);
@@ -8368,7 +8474,7 @@ function useSidebarResize(position, dispatch) {
8368
8474
  setWidth(storeWidth);
8369
8475
  }
8370
8476
  }, [storeWidth]);
8371
- const handleResizeEnd = useCallback19(
8477
+ const handleResizeEnd = useCallback20(
8372
8478
  (width2) => {
8373
8479
  dispatch({
8374
8480
  type: "setUi",
@@ -8539,7 +8645,7 @@ function PuckProvider({ children }) {
8539
8645
  );
8540
8646
  return __spreadValues(__spreadValues({}, pluginFieldTransforms), fieldTransforms);
8541
8647
  }, [fieldTransforms, plugins]);
8542
- const generateAppStore = useCallback20(
8648
+ const generateAppStore = useCallback21(
8543
8649
  (state) => {
8544
8650
  return {
8545
8651
  state,
@@ -8588,7 +8694,7 @@ function PuckProvider({ children }) {
8588
8694
  (s) => s.state.data,
8589
8695
  (data) => {
8590
8696
  if (onChange) {
8591
- if (fdeq(data, previousData.current)) return;
8697
+ if ((0, import_fast_deep_equal.default)(data, previousData.current)) return;
8592
8698
  onChange(data);
8593
8699
  previousData.current = data;
8594
8700
  }
@@ -8668,6 +8774,7 @@ function PuckLayout({ children }) {
8668
8774
  }, []);
8669
8775
  const ready = useAppStore((s) => s.status === "READY");
8670
8776
  useMonitorHotkeys();
8777
+ useDeleteHotkeys();
8671
8778
  useEffect29(() => {
8672
8779
  if (ready && iframe.enabled) {
8673
8780
  const frameDoc = getFrame();
@@ -681,19 +681,19 @@ init_react_import();
681
681
 
682
682
  // lib/get-changed.ts
683
683
  init_react_import();
684
- import fdeq from "fast-deep-equal";
684
+ import { deepEqual } from "fast-equals";
685
685
  var getChanged = (newItem, oldItem) => {
686
686
  return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
687
687
  const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
688
688
  const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
689
689
  return __spreadProps(__spreadValues({}, acc), {
690
- [item]: !fdeq(oldItemProps[item], newItemProps[item])
690
+ [item]: !deepEqual(oldItemProps[item], newItemProps[item])
691
691
  });
692
692
  }, {}) : {};
693
693
  };
694
694
 
695
695
  // lib/resolve-component-data.ts
696
- import fdeq2 from "fast-deep-equal";
696
+ import { deepEqual as deepEqual2 } from "fast-equals";
697
697
  var cache = { lastChange: {} };
698
698
  var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
699
699
  const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
@@ -702,7 +702,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
702
702
  const id = "id" in item.props ? item.props.id : "root";
703
703
  if (shouldRunResolver) {
704
704
  const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
705
- if (trigger !== "force" && item && fdeq2(item, oldItem)) {
705
+ if (trigger !== "force" && item && deepEqual2(item, oldItem)) {
706
706
  return { node: resolved, didChange: false };
707
707
  }
708
708
  const changed = getChanged(item, oldItem);
@@ -752,7 +752,7 @@ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], f
752
752
  };
753
753
  return {
754
754
  node: itemWithResolvedChildren,
755
- didChange: !fdeq2(item, itemWithResolvedChildren)
755
+ didChange: !deepEqual2(item, itemWithResolvedChildren)
756
756
  };
757
757
  });
758
758
 
package/dist/index.css CHANGED
@@ -1331,16 +1331,17 @@ body:has(._DropZone--isAnimating_1i2sv_68:empty) [data-puck-overlay] {
1331
1331
  }
1332
1332
 
1333
1333
  /* css-module:/home/runner/work/puck/puck/packages/core/components/InlineTextField/styles.module.css/#css-module-data */
1334
- ._InlineTextField_1xph6_1 {
1334
+ ._InlineTextField_104qp_1 {
1335
1335
  cursor: text;
1336
1336
  display: inline-block;
1337
1337
  white-space: pre-wrap;
1338
+ text-decoration: inherit;
1338
1339
  }
1339
- [data-dnd-dragging] ._InlineTextField_1xph6_1 {
1340
+ [data-dnd-dragging] ._InlineTextField_104qp_1 {
1340
1341
  cursor: none;
1341
1342
  caret-color: transparent;
1342
1343
  }
1343
- [data-dnd-dragging] ._InlineTextField_1xph6_1::selection {
1344
+ [data-dnd-dragging] ._InlineTextField_104qp_1::selection {
1344
1345
  display: none;
1345
1346
  }
1346
1347