@measured/puck 0.20.3-canary.d855fa8c → 0.21.0-canary.16a3eee1

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") {
@@ -1017,7 +1057,7 @@ var flattenData = (state, config) => {
1017
1057
  (content) => content,
1018
1058
  (item) => {
1019
1059
  data.push(item);
1020
- return null;
1060
+ return item;
1021
1061
  }
1022
1062
  );
1023
1063
  return data;
@@ -1173,6 +1213,7 @@ var useRegisterFieldsSlice = (appStore, id) => {
1173
1213
  (reset) => __async(void 0, null, function* () {
1174
1214
  var _a, _b;
1175
1215
  const { fields, lastResolvedData } = appStore.getState().fields;
1216
+ const metadata = appStore.getState().metadata;
1176
1217
  const nodes = appStore.getState().state.indexes.nodes;
1177
1218
  const node = nodes[id || "root"];
1178
1219
  const componentData = node == null ? void 0 : node.data;
@@ -1202,6 +1243,7 @@ var useRegisterFieldsSlice = (appStore, id) => {
1202
1243
  changed,
1203
1244
  fields: defaultFields2,
1204
1245
  lastFields,
1246
+ metadata: __spreadValues(__spreadValues({}, metadata), componentConfig.metadata),
1205
1247
  lastData,
1206
1248
  appState: makeStatePublic(state),
1207
1249
  parent
@@ -6419,7 +6461,7 @@ function useGetPuck() {
6419
6461
  init_react_import();
6420
6462
  import {
6421
6463
  createContext as createContext8,
6422
- useCallback as useCallback20,
6464
+ useCallback as useCallback21,
6423
6465
  useContext as useContext13,
6424
6466
  useEffect as useEffect29,
6425
6467
  useMemo as useMemo20,
@@ -7979,12 +8021,73 @@ var usePreviewModeHotkeys = () => {
7979
8021
  useHotkey({ ctrl: true, i: true }, toggleInteractive);
7980
8022
  };
7981
8023
 
8024
+ // lib/use-delete-hotkeys.ts
8025
+ init_react_import();
8026
+ import { useCallback as useCallback17 } from "react";
8027
+ var isElementVisible = (element) => {
8028
+ let current = element;
8029
+ while (current && current !== document.body) {
8030
+ const style = window.getComputedStyle(current);
8031
+ if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" || current.getAttribute("aria-hidden") === "true" || current.hasAttribute("hidden")) {
8032
+ return false;
8033
+ }
8034
+ current = current.parentElement;
8035
+ }
8036
+ return true;
8037
+ };
8038
+ var shouldBlockDeleteHotkey = (e) => {
8039
+ var _a;
8040
+ if (e == null ? void 0 : e.defaultPrevented) return true;
8041
+ const origin = ((_a = e == null ? void 0 : e.composedPath) == null ? void 0 : _a.call(e)[0]) || (e == null ? void 0 : e.target) || document.activeElement;
8042
+ if (origin instanceof HTMLElement) {
8043
+ const tag = origin.tagName.toLowerCase();
8044
+ if (tag === "input" || tag === "textarea" || tag === "select") return true;
8045
+ if (origin.isContentEditable) return true;
8046
+ const role = origin.getAttribute("role");
8047
+ if (role === "textbox" || role === "combobox" || role === "searchbox" || role === "listbox" || role === "grid") {
8048
+ return true;
8049
+ }
8050
+ }
8051
+ const modal = document.querySelector(
8052
+ 'dialog[open], [aria-modal="true"], [role="dialog"], [role="alertdialog"]'
8053
+ );
8054
+ if (modal && isElementVisible(modal)) {
8055
+ return true;
8056
+ }
8057
+ return false;
8058
+ };
8059
+ var useDeleteHotkeys = () => {
8060
+ const appStore = useAppStoreApi();
8061
+ const deleteSelectedComponent = useCallback17(
8062
+ (e) => {
8063
+ var _a;
8064
+ if (shouldBlockDeleteHotkey(e)) {
8065
+ return false;
8066
+ }
8067
+ const { state, dispatch, permissions, selectedItem } = appStore.getState();
8068
+ const sel = (_a = state.ui) == null ? void 0 : _a.itemSelector;
8069
+ if (!(sel == null ? void 0 : sel.zone) || !selectedItem) return true;
8070
+ if (!permissions.getPermissions({ item: selectedItem }).delete)
8071
+ return true;
8072
+ dispatch({
8073
+ type: "remove",
8074
+ index: sel.index,
8075
+ zone: sel.zone
8076
+ });
8077
+ return true;
8078
+ },
8079
+ [appStore]
8080
+ );
8081
+ useHotkey({ delete: true }, deleteSelectedComponent);
8082
+ useHotkey({ backspace: true }, deleteSelectedComponent);
8083
+ };
8084
+
7982
8085
  // components/Puck/index.tsx
7983
- import fdeq from "fast-deep-equal";
8086
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
7984
8087
 
7985
8088
  // components/Puck/components/Header/index.tsx
7986
8089
  init_react_import();
7987
- import { memo as memo4, useCallback as useCallback17, useMemo as useMemo19, useState as useState23 } from "react";
8090
+ import { memo as memo4, useCallback as useCallback18, useMemo as useMemo19, useState as useState23 } from "react";
7988
8091
 
7989
8092
  // components/MenuBar/index.tsx
7990
8093
  init_react_import();
@@ -8111,7 +8214,7 @@ var HeaderInner = () => {
8111
8214
  const rightSideBarVisible = useAppStore(
8112
8215
  (s) => s.state.ui.rightSideBarVisible
8113
8216
  );
8114
- const toggleSidebars = useCallback17(
8217
+ const toggleSidebars = useCallback18(
8115
8218
  (sidebar) => {
8116
8219
  const widerViewport = window.matchMedia("(min-width: 638px)").matches;
8117
8220
  const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
@@ -8221,7 +8324,7 @@ init_react_import();
8221
8324
 
8222
8325
  // components/Puck/components/ResizeHandle/index.tsx
8223
8326
  init_react_import();
8224
- import { useCallback as useCallback18, useRef as useRef10 } from "react";
8327
+ import { useCallback as useCallback19, useRef as useRef10 } from "react";
8225
8328
 
8226
8329
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/ResizeHandle/styles.module.css#css-module
8227
8330
  init_react_import();
@@ -8242,7 +8345,7 @@ var ResizeHandle = ({
8242
8345
  const isDragging = useRef10(false);
8243
8346
  const startX = useRef10(0);
8244
8347
  const startWidth = useRef10(0);
8245
- const handleMouseMove = useCallback18(
8348
+ const handleMouseMove = useCallback19(
8246
8349
  (e) => {
8247
8350
  if (!isDragging.current) return;
8248
8351
  const delta = e.clientX - startX.current;
@@ -8253,7 +8356,7 @@ var ResizeHandle = ({
8253
8356
  },
8254
8357
  [onResize, position]
8255
8358
  );
8256
- const handleMouseUp = useCallback18(() => {
8359
+ const handleMouseUp = useCallback19(() => {
8257
8360
  var _a;
8258
8361
  if (!isDragging.current) return;
8259
8362
  isDragging.current = false;
@@ -8269,7 +8372,7 @@ var ResizeHandle = ({
8269
8372
  onResizeEnd(finalWidth);
8270
8373
  resetAutoZoom();
8271
8374
  }, [onResizeEnd]);
8272
- const handleMouseDown = useCallback18(
8375
+ const handleMouseDown = useCallback19(
8273
8376
  (e) => {
8274
8377
  var _a;
8275
8378
  isDragging.current = true;
@@ -8329,7 +8432,7 @@ var Sidebar = ({
8329
8432
 
8330
8433
  // lib/use-sidebar-resize.ts
8331
8434
  init_react_import();
8332
- import { useCallback as useCallback19, useEffect as useEffect28, useRef as useRef11, useState as useState24 } from "react";
8435
+ import { useCallback as useCallback20, useEffect as useEffect28, useRef as useRef11, useState as useState24 } from "react";
8333
8436
  function useSidebarResize(position, dispatch) {
8334
8437
  const [width, setWidth] = useState24(null);
8335
8438
  const sidebarRef = useRef11(null);
@@ -8366,7 +8469,7 @@ function useSidebarResize(position, dispatch) {
8366
8469
  setWidth(storeWidth);
8367
8470
  }
8368
8471
  }, [storeWidth]);
8369
- const handleResizeEnd = useCallback19(
8472
+ const handleResizeEnd = useCallback20(
8370
8473
  (width2) => {
8371
8474
  dispatch({
8372
8475
  type: "setUi",
@@ -8537,7 +8640,7 @@ function PuckProvider({ children }) {
8537
8640
  );
8538
8641
  return __spreadValues(__spreadValues({}, pluginFieldTransforms), fieldTransforms);
8539
8642
  }, [fieldTransforms, plugins]);
8540
- const generateAppStore = useCallback20(
8643
+ const generateAppStore = useCallback21(
8541
8644
  (state) => {
8542
8645
  return {
8543
8646
  state,
@@ -8586,7 +8689,7 @@ function PuckProvider({ children }) {
8586
8689
  (s) => s.state.data,
8587
8690
  (data) => {
8588
8691
  if (onChange) {
8589
- if (fdeq(data, previousData.current)) return;
8692
+ if ((0, import_fast_deep_equal.default)(data, previousData.current)) return;
8590
8693
  onChange(data);
8591
8694
  previousData.current = data;
8592
8695
  }
@@ -8666,6 +8769,7 @@ function PuckLayout({ children }) {
8666
8769
  }, []);
8667
8770
  const ready = useAppStore((s) => s.status === "READY");
8668
8771
  useMonitorHotkeys();
8772
+ useDeleteHotkeys();
8669
8773
  useEffect29(() => {
8670
8774
  if (ready && iframe.enabled) {
8671
8775
  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.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as History, P as Permissions, a as ComponentData, C as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as FieldTransforms, h as Field, i as FieldProps, D as DropZoneProps, j as Data, k as OnAction, l as InitialHistory, n as ItemSelector } from './walk-tree-JdJYB16L.mjs';
2
- export { a7 as Adaptor, a5 as ArrayField, B as ArrayState, ak as AsFieldProps, N as BaseData, $ as BaseField, Z as ComponentDataMap, X as ComponentDataOptionalId, _ as Content, ab as CustomField, aa as CustomFieldRender, ah as DefaultComponentProps, K as DefaultComponents, ae as DefaultRootFieldProps, ag as DefaultRootProps, af as DefaultRootRenderProps, o as Direction, p as DragAxis, a9 as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, am as ExtractField, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, Y as MappedItem, a1 as NumberField, a6 as ObjectField, x as OverrideKey, G as PuckComponent, ad as PuckContext, a4 as RadioField, J as RootConfig, T as RootData, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ac as SlotField, a0 as TextField, a2 as TextareaField, q as Viewport, al as WithChildren, ai as WithId, aj as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-JdJYB16L.mjs';
1
+ import { H as History, P as Permissions, a as ComponentData, C as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as FieldTransforms, h as Field, i as FieldProps, D as DropZoneProps, j as Data, k as OnAction, l as InitialHistory, n as ItemSelector } from './walk-tree-Ctf3FZQI.mjs';
2
+ export { a7 as Adaptor, a5 as ArrayField, B as ArrayState, ak as AsFieldProps, N as BaseData, $ as BaseField, Z as ComponentDataMap, X as ComponentDataOptionalId, _ as Content, ab as CustomField, aa as CustomFieldRender, ah as DefaultComponentProps, K as DefaultComponents, ae as DefaultRootFieldProps, ag as DefaultRootProps, af as DefaultRootRenderProps, o as Direction, p as DragAxis, a9 as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, am as ExtractField, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, Y as MappedItem, a1 as NumberField, a6 as ObjectField, x as OverrideKey, G as PuckComponent, ad as PuckContext, a4 as RadioField, J as RootConfig, T as RootData, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ac as SlotField, a0 as TextField, a2 as TextareaField, q as Viewport, al as WithChildren, ai as WithId, aj as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Ctf3FZQI.mjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
5
  import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { H as History, P as Permissions, a as ComponentData, C as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as FieldTransforms, h as Field, i as FieldProps, D as DropZoneProps, j as Data, k as OnAction, l as InitialHistory, n as ItemSelector } from './walk-tree-JdJYB16L.js';
2
- export { a7 as Adaptor, a5 as ArrayField, B as ArrayState, ak as AsFieldProps, N as BaseData, $ as BaseField, Z as ComponentDataMap, X as ComponentDataOptionalId, _ as Content, ab as CustomField, aa as CustomFieldRender, ah as DefaultComponentProps, K as DefaultComponents, ae as DefaultRootFieldProps, ag as DefaultRootProps, af as DefaultRootRenderProps, o as Direction, p as DragAxis, a9 as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, am as ExtractField, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, Y as MappedItem, a1 as NumberField, a6 as ObjectField, x as OverrideKey, G as PuckComponent, ad as PuckContext, a4 as RadioField, J as RootConfig, T as RootData, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ac as SlotField, a0 as TextField, a2 as TextareaField, q as Viewport, al as WithChildren, ai as WithId, aj as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-JdJYB16L.js';
1
+ import { H as History, P as Permissions, a as ComponentData, C as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as FieldTransforms, h as Field, i as FieldProps, D as DropZoneProps, j as Data, k as OnAction, l as InitialHistory, n as ItemSelector } from './walk-tree-Ctf3FZQI.js';
2
+ export { a7 as Adaptor, a5 as ArrayField, B as ArrayState, ak as AsFieldProps, N as BaseData, $ as BaseField, Z as ComponentDataMap, X as ComponentDataOptionalId, _ as Content, ab as CustomField, aa as CustomFieldRender, ah as DefaultComponentProps, K as DefaultComponents, ae as DefaultRootFieldProps, ag as DefaultRootProps, af as DefaultRootRenderProps, o as Direction, p as DragAxis, a9 as ExternalField, a8 as ExternalFieldWithAdaptor, L as ExtractConfigParams, am as ExtractField, y as FieldRenderFunctions, u as FieldTransformFn, s as FieldTransformFnParams, z as ItemWithId, Y as MappedItem, a1 as NumberField, a6 as ObjectField, x as OverrideKey, G as PuckComponent, ad as PuckContext, a4 as RadioField, J as RootConfig, T as RootData, Q as RootDataWithoutProps, a3 as SelectField, S as Slot, E as SlotComponent, ac as SlotField, a0 as TextField, a2 as TextareaField, q as Viewport, al as WithChildren, ai as WithId, aj as WithPuckProps, W as WithSlotProps, m as migrate, v as overrideKeys, r as resolveAllData, t as transformProps, w as walkTree } from './walk-tree-Ctf3FZQI.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
5
  import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';