@measured/puck 0.17.0-canary.6e568de → 0.17.0-canary.6e5864a

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -9,9 +9,6 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
9
  var __getProtoOf = Object.getPrototypeOf;
10
10
  var __hasOwnProp = Object.prototype.hasOwnProperty;
11
11
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __typeError = (msg) => {
13
- throw TypeError(msg);
14
- };
15
12
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
16
13
  var __spreadValues = (a, b) => {
17
14
  for (var prop in b || (b = {}))
@@ -64,10 +61,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
64
61
  mod
65
62
  ));
66
63
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
67
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
68
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
69
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
70
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
71
64
  var __async = (__this, __arguments, generator) => {
72
65
  return new Promise((resolve, reject) => {
73
66
  var fulfilled = (value) => {
@@ -178,9 +171,6 @@ init_react_import();
178
171
  // types/API/index.ts
179
172
  init_react_import();
180
173
 
181
- // types/API/DropZone.ts
182
- init_react_import();
183
-
184
174
  // types/API/Viewports.ts
185
175
  init_react_import();
186
176
 
@@ -225,26 +215,26 @@ init_react_import();
225
215
  // lib/get-class-name-factory.ts
226
216
  init_react_import();
227
217
  var import_classnames = __toESM(require_classnames());
228
- var getClassNameFactory = (rootClass, styles2, config = { baseClass: "" }) => (options = {}) => {
218
+ var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
229
219
  if (typeof options === "string") {
230
220
  const descendant = options;
231
- const style = styles2[`${rootClass}-${descendant}`];
221
+ const style = styles[`${rootClass}-${descendant}`];
232
222
  if (style) {
233
- return config.baseClass + styles2[`${rootClass}-${descendant}`] || "";
223
+ return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
234
224
  }
235
225
  return "";
236
226
  } else if (typeof options === "object") {
237
227
  const modifiers = options;
238
228
  const prefixedModifiers = {};
239
229
  for (let modifier in modifiers) {
240
- prefixedModifiers[styles2[`${rootClass}--${modifier}`]] = modifiers[modifier];
230
+ prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
241
231
  }
242
- const c = styles2[rootClass];
232
+ const c = styles[rootClass];
243
233
  return config.baseClass + (0, import_classnames.default)(__spreadValues({
244
234
  [c]: !!c
245
235
  }, prefixedModifiers));
246
236
  } else {
247
- return config.baseClass + styles2[rootClass] || "";
237
+ return config.baseClass + styles[rootClass] || "";
248
238
  }
249
239
  };
250
240
  var get_class_name_factory_default = getClassNameFactory;
@@ -289,7 +279,7 @@ init_react_import();
289
279
  var styles_module_default2 = { "InputWrapper": "_InputWrapper_1l5m8_1", "Input": "_Input_1l5m8_1", "Input-label": "_Input-label_1l5m8_26", "Input-labelIcon": "_Input-labelIcon_1l5m8_35", "Input-disabledIcon": "_Input-disabledIcon_1l5m8_42", "Input-input": "_Input-input_1l5m8_47", "Input--readOnly": "_Input--readOnly_1l5m8_91", "Input-radioGroupItems": "_Input-radioGroupItems_1l5m8_102", "Input-radio": "_Input-radio_1l5m8_102", "Input-radioInner": "_Input-radioInner_1l5m8_119", "Input-radioInput": "_Input-radioInput_1l5m8_164" };
290
280
 
291
281
  // components/AutoField/index.tsx
292
- var import_react13 = require("react");
282
+ var import_react15 = require("react");
293
283
 
294
284
  // components/AutoField/fields/index.tsx
295
285
  init_react_import();
@@ -691,7 +681,7 @@ var IconButton = ({
691
681
  return el;
692
682
  };
693
683
 
694
- // components/LegacyDnd/Droppable/index.tsx
684
+ // components/Droppable/index.tsx
695
685
  init_react_import();
696
686
  var import_dnd = require("@measured/dnd");
697
687
 
@@ -737,6 +727,9 @@ var defaultViewports = [
737
727
  { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
738
728
  ];
739
729
 
730
+ // components/Puck/context.tsx
731
+ var import_ua_parser_js = require("ua-parser-js");
732
+
740
733
  // lib/use-resolved-permissions.ts
741
734
  init_react_import();
742
735
  var import_react4 = require("react");
@@ -1104,6 +1097,7 @@ var defaultContext = {
1104
1097
  status: "LOADING",
1105
1098
  setStatus: () => null,
1106
1099
  iframe: {},
1100
+ safariFallbackMode: false,
1107
1101
  globalPermissions: {},
1108
1102
  getPermissions: () => ({}),
1109
1103
  refreshPermissions: () => null
@@ -1118,6 +1112,24 @@ var AppProvider = ({
1118
1112
  (0, import_react6.useEffect)(() => {
1119
1113
  setStatus("MOUNTED");
1120
1114
  }, []);
1115
+ const [safariFallbackMode, setSafariFallbackMode] = (0, import_react6.useState)(false);
1116
+ (0, import_react6.useEffect)(() => {
1117
+ var _a, _b, _c;
1118
+ const ua = new import_ua_parser_js.UAParser(navigator.userAgent);
1119
+ const { browser } = ua.getResult();
1120
+ if (browser.name === "Safari" && (((_a = browser.version) == null ? void 0 : _a.indexOf("17.2.")) || ((_b = browser.version) == null ? void 0 : _b.indexOf("17.3.")) || ((_c = browser.version) == null ? void 0 : _c.indexOf("17.4.")))) {
1121
+ if (process.env.NODE_ENV !== "production" && value.iframe.enabled) {
1122
+ console.warn(
1123
+ `Detected Safari ${browser.version}, which contains a bug that prevents Puck DropZones from detecting a mouseover event within an iframe. This affects Safari versions 17.2, 17.3 and 17.4.
1124
+
1125
+ Running in compatibility mode, which may have some DropZone side-effects. Alternatively, consider disabling iframes: https://puckeditor.com/docs/integrating-puck/viewports#opting-out-of-iframes.
1126
+
1127
+ See https://github.com/measuredco/puck/issues/411 for more information. This message will not show in production.`
1128
+ );
1129
+ }
1130
+ setSafariFallbackMode(true);
1131
+ }
1132
+ }, []);
1121
1133
  const selectedItem = value.state.ui.itemSelector ? getItem(value.state.ui.itemSelector, value.state.data) : void 0;
1122
1134
  const [componentState, setComponentState] = (0, import_react6.useState)({});
1123
1135
  const setComponentLoading = (id) => {
@@ -1164,6 +1176,7 @@ var AppProvider = ({
1164
1176
  setZoomConfig,
1165
1177
  status,
1166
1178
  setStatus,
1179
+ safariFallbackMode,
1167
1180
  getPermissions,
1168
1181
  refreshPermissions,
1169
1182
  componentState,
@@ -1188,7 +1201,7 @@ function useAppContext() {
1188
1201
  });
1189
1202
  }
1190
1203
 
1191
- // components/LegacyDnd/Droppable/index.tsx
1204
+ // components/Droppable/index.tsx
1192
1205
  var import_jsx_runtime5 = require("react/jsx-runtime");
1193
1206
  var defaultProvided = {
1194
1207
  droppableProps: {
@@ -1211,7 +1224,7 @@ var Droppable = (props) => {
1211
1224
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(El, __spreadValues({}, props));
1212
1225
  };
1213
1226
 
1214
- // components/LegacyDnd/Draggable/index.tsx
1227
+ // components/Draggable/index.tsx
1215
1228
  init_react_import();
1216
1229
  var import_dnd2 = require("@measured/dnd");
1217
1230
  var import_jsx_runtime6 = require("react/jsx-runtime");
@@ -1293,7 +1306,7 @@ var import_jsx_runtime7 = require("react/jsx-runtime");
1293
1306
  var getClassName4 = get_class_name_factory_default("DragIcon", styles_module_default5);
1294
1307
  var DragIcon = ({ isDragDisabled }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: getClassName4({ disabled: isDragDisabled }), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("svg", { viewBox: "0 0 20 20", width: "12", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: "M7 2a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 2zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 8zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 7 14zm6-8a2 2 0 1 0-.001-4.001A2 2 0 0 0 13 6zm0 2a2 2 0 1 0 .001 4.001A2 2 0 0 0 13 8zm0 6a2 2 0 1 0 .001 4.001A2 2 0 0 0 13 14z" }) }) });
1295
1308
 
1296
- // components/LegacyDnd/DragDropContext/index.tsx
1309
+ // components/DragDropContext/index.tsx
1297
1310
  init_react_import();
1298
1311
  var import_dnd3 = require("@measured/dnd");
1299
1312
  var import_jsx_runtime8 = require("react/jsx-runtime");
@@ -1624,6 +1637,7 @@ var DefaultField = ({
1624
1637
  className: getClassName6("input"),
1625
1638
  autoComplete: "off",
1626
1639
  type: field.type,
1640
+ title: label || name,
1627
1641
  name,
1628
1642
  value: typeof value === "undefined" ? "" : value.toString(),
1629
1643
  onChange: (e) => {
@@ -2038,6 +2052,20 @@ var ExternalField = ({
2038
2052
 
2039
2053
  // components/AutoField/fields/RadioField/index.tsx
2040
2054
  init_react_import();
2055
+ var import_react12 = require("react");
2056
+
2057
+ // lib/safe-json-parse.ts
2058
+ init_react_import();
2059
+ var safeJsonParse = (str) => {
2060
+ try {
2061
+ const jsonValue = JSON.parse(str);
2062
+ return jsonValue;
2063
+ } catch (e) {
2064
+ return str;
2065
+ }
2066
+ };
2067
+
2068
+ // components/AutoField/fields/RadioField/index.tsx
2041
2069
  var import_jsx_runtime16 = require("react/jsx-runtime");
2042
2070
  var getClassName11 = get_class_name_factory_default("Input", styles_module_default2);
2043
2071
  var RadioField = ({
@@ -2050,6 +2078,10 @@ var RadioField = ({
2050
2078
  label,
2051
2079
  Label
2052
2080
  }) => {
2081
+ const flatOptions = (0, import_react12.useMemo)(
2082
+ () => field.type === "radio" ? field.options.map(({ value: value2 }) => value2) : [],
2083
+ [field]
2084
+ );
2053
2085
  if (field.type !== "radio" || !field.options) {
2054
2086
  return null;
2055
2087
  }
@@ -2073,11 +2105,12 @@ var RadioField = ({
2073
2105
  value: option.value,
2074
2106
  name,
2075
2107
  onChange: (e) => {
2076
- if (e.currentTarget.value === "true" || e.currentTarget.value === "false") {
2077
- onChange(JSON.parse(e.currentTarget.value));
2078
- return;
2108
+ const jsonValue = safeJsonParse(e.target.value) || e.target.value;
2109
+ if (flatOptions.indexOf(jsonValue) > -1) {
2110
+ onChange(jsonValue);
2111
+ } else {
2112
+ onChange(e.target.value);
2079
2113
  }
2080
- onChange(e.currentTarget.value);
2081
2114
  },
2082
2115
  disabled: readOnly,
2083
2116
  checked: value === option.value
@@ -2094,6 +2127,7 @@ var RadioField = ({
2094
2127
 
2095
2128
  // components/AutoField/fields/SelectField/index.tsx
2096
2129
  init_react_import();
2130
+ var import_react13 = require("react");
2097
2131
  var import_jsx_runtime17 = require("react/jsx-runtime");
2098
2132
  var getClassName12 = get_class_name_factory_default("Input", styles_module_default2);
2099
2133
  var SelectField = ({
@@ -2106,6 +2140,10 @@ var SelectField = ({
2106
2140
  readOnly,
2107
2141
  id
2108
2142
  }) => {
2143
+ const flatOptions = (0, import_react13.useMemo)(
2144
+ () => field.type === "select" ? field.options.map(({ value: value2 }) => value2) : [],
2145
+ [field]
2146
+ );
2109
2147
  if (field.type !== "select" || !field.options) {
2110
2148
  return null;
2111
2149
  }
@@ -2119,14 +2157,16 @@ var SelectField = ({
2119
2157
  "select",
2120
2158
  {
2121
2159
  id,
2160
+ title: label || name,
2122
2161
  className: getClassName12("input"),
2123
2162
  disabled: readOnly,
2124
2163
  onChange: (e) => {
2125
- if (e.currentTarget.value === "true" || e.currentTarget.value === "false") {
2126
- onChange(JSON.parse(e.currentTarget.value));
2127
- return;
2164
+ const jsonValue = safeJsonParse(e.target.value) || e.target.value;
2165
+ if (flatOptions.indexOf(jsonValue) > -1) {
2166
+ onChange(jsonValue);
2167
+ } else {
2168
+ onChange(e.target.value);
2128
2169
  }
2129
- onChange(e.currentTarget.value);
2130
2170
  },
2131
2171
  value,
2132
2172
  children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
@@ -2240,7 +2280,7 @@ var ObjectField = ({
2240
2280
 
2241
2281
  // lib/use-safe-id.ts
2242
2282
  init_react_import();
2243
- var import_react12 = __toESM(require("react"));
2283
+ var import_react14 = __toESM(require("react"));
2244
2284
 
2245
2285
  // lib/generate-id.ts
2246
2286
  init_react_import();
@@ -2249,10 +2289,10 @@ var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, impor
2249
2289
 
2250
2290
  // lib/use-safe-id.ts
2251
2291
  var useSafeId = () => {
2252
- if (typeof import_react12.default.useId !== "undefined") {
2253
- return import_react12.default.useId();
2292
+ if (typeof import_react14.default.useId !== "undefined") {
2293
+ return import_react14.default.useId();
2254
2294
  }
2255
- const [id] = (0, import_react12.useState)(generateId());
2295
+ const [id] = (0, import_react14.useState)(generateId());
2256
2296
  return id;
2257
2297
  };
2258
2298
 
@@ -2286,7 +2326,7 @@ var FieldLabelInternal2 = ({
2286
2326
  readOnly
2287
2327
  }) => {
2288
2328
  const { overrides } = useAppContext();
2289
- const Wrapper = (0, import_react13.useMemo)(
2329
+ const Wrapper = (0, import_react15.useMemo)(
2290
2330
  () => overrides.fieldLabel || FieldLabel,
2291
2331
  [overrides]
2292
2332
  );
@@ -2339,7 +2379,7 @@ function AutoFieldInternal(props) {
2339
2379
  Label,
2340
2380
  id: resolvedId
2341
2381
  });
2342
- const onFocus = (0, import_react13.useCallback)(
2382
+ const onFocus = (0, import_react15.useCallback)(
2343
2383
  (e) => {
2344
2384
  if (mergedProps.name && e.target.nodeName === "INPUT") {
2345
2385
  e.stopPropagation();
@@ -2353,7 +2393,7 @@ function AutoFieldInternal(props) {
2353
2393
  },
2354
2394
  [mergedProps.name]
2355
2395
  );
2356
- const onBlur = (0, import_react13.useCallback)((e) => {
2396
+ const onBlur = (0, import_react15.useCallback)((e) => {
2357
2397
  if ("name" in e.target) {
2358
2398
  dispatch({
2359
2399
  type: "setUi",
@@ -2372,12 +2412,23 @@ function AutoFieldInternal(props) {
2372
2412
  }
2373
2413
  const children = defaultFields[field.type](mergedProps);
2374
2414
  const Render2 = render[field.type];
2375
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassNameWrapper(), onFocus, onBlur, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Render2, __spreadProps(__spreadValues({}, mergedProps), { children })) });
2415
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2416
+ "div",
2417
+ {
2418
+ className: getClassNameWrapper(),
2419
+ onFocus,
2420
+ onBlur,
2421
+ onClick: (e) => {
2422
+ e.stopPropagation();
2423
+ },
2424
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Render2, __spreadProps(__spreadValues({}, mergedProps), { children }))
2425
+ }
2426
+ );
2376
2427
  }
2377
2428
  function AutoFieldPrivate(props) {
2378
2429
  const { state } = useAppContext();
2379
2430
  const { value, onChange } = props;
2380
- const [localValue, setLocalValue] = (0, import_react13.useState)(value);
2431
+ const [localValue, setLocalValue] = (0, import_react15.useState)(value);
2381
2432
  const onChangeDb = (0, import_use_debounce.useDebouncedCallback)(
2382
2433
  (val, ui) => {
2383
2434
  onChange(val, ui);
@@ -2385,11 +2436,11 @@ function AutoFieldPrivate(props) {
2385
2436
  50,
2386
2437
  { leading: true }
2387
2438
  );
2388
- const onChangeLocal = (0, import_react13.useCallback)((val, ui) => {
2439
+ const onChangeLocal = (0, import_react15.useCallback)((val, ui) => {
2389
2440
  setLocalValue(val);
2390
2441
  onChangeDb(val, ui);
2391
2442
  }, []);
2392
- (0, import_react13.useEffect)(() => {
2443
+ (0, import_react15.useEffect)(() => {
2393
2444
  if (state.ui.field.focus !== props.name) {
2394
2445
  setLocalValue(value);
2395
2446
  }
@@ -2401,7 +2452,7 @@ function AutoFieldPrivate(props) {
2401
2452
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(AutoFieldInternal, __spreadValues(__spreadValues({}, props), localProps));
2402
2453
  }
2403
2454
  function AutoField(props) {
2404
- const DefaultLabel = (0, import_react13.useMemo)(() => {
2455
+ const DefaultLabel = (0, import_react15.useMemo)(() => {
2405
2456
  const DefaultLabel2 = (labelProps) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
2406
2457
  "div",
2407
2458
  __spreadProps(__spreadValues({}, labelProps), {
@@ -2418,35 +2469,104 @@ init_react_import();
2418
2469
 
2419
2470
  // css-module:/home/runner/work/puck/puck/packages/core/components/Drawer/styles.module.css#css-module
2420
2471
  init_react_import();
2421
- var styles_module_default10 = { "Drawer": "_Drawer_1ob9x_1", "DrawerItem-draggable": "_DrawerItem-draggable_1ob9x_8", "DrawerItem--disabled": "_DrawerItem--disabled_1ob9x_21", "DrawerItem": "_DrawerItem_1ob9x_8", "Drawer--isDraggingFrom": "_Drawer--isDraggingFrom_1ob9x_31", "DrawerItem-name": "_DrawerItem-name_1ob9x_49" };
2472
+ var styles_module_default10 = { "Drawer": "_Drawer_1oa7v_1", "DrawerItem--disabled": "_DrawerItem--disabled_1oa7v_5", "DrawerItem-draggable": "_DrawerItem-draggable_1oa7v_5", "DrawerItem-default": "_DrawerItem-default_1oa7v_11", "DrawerItem-draggableWrapper": "_DrawerItem-draggableWrapper_1oa7v_11", "DrawerItem": "_DrawerItem_1oa7v_5", "Drawer--isDraggingFrom": "_Drawer--isDraggingFrom_1oa7v_36", "DrawerItem-name": "_DrawerItem-name_1oa7v_54" };
2422
2473
 
2423
2474
  // components/Drawer/index.tsx
2424
- var import_react21 = require("react");
2425
-
2426
- // components/DragDropContext/index.tsx
2427
- init_react_import();
2428
- var import_react19 = require("@dnd-kit/react");
2429
- var import_react20 = require("react");
2430
- var import_dom = require("@dnd-kit/dom");
2475
+ var import_react16 = require("react");
2476
+ var import_jsx_runtime21 = require("react/jsx-runtime");
2477
+ var getClassName16 = get_class_name_factory_default("Drawer", styles_module_default10);
2478
+ var getClassNameItem2 = get_class_name_factory_default("DrawerItem", styles_module_default10);
2479
+ var drawerContext = (0, import_react16.createContext)({
2480
+ droppableId: ""
2481
+ });
2482
+ var DrawerDraggable = ({
2483
+ children,
2484
+ id,
2485
+ index,
2486
+ isDragDisabled
2487
+ }) => {
2488
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2489
+ Draggable,
2490
+ {
2491
+ id,
2492
+ index,
2493
+ isDragDisabled,
2494
+ showShadow: true,
2495
+ disableAnimations: true,
2496
+ className: () => getClassNameItem2({ disabled: isDragDisabled }),
2497
+ children: () => children
2498
+ },
2499
+ id
2500
+ );
2501
+ };
2502
+ var DrawerItem = ({
2503
+ name,
2504
+ children,
2505
+ id,
2506
+ label,
2507
+ index,
2508
+ isDragDisabled
2509
+ }) => {
2510
+ const ctx = (0, import_react16.useContext)(drawerContext);
2511
+ const resolvedId = `${ctx.droppableId}::${id || name}`;
2512
+ const CustomInner = (0, import_react16.useMemo)(
2513
+ () => children || (({ children: children2, name: name2 }) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: getClassNameItem2("default"), children: children2 })),
2514
+ [children]
2515
+ );
2516
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
2517
+ DrawerDraggable,
2518
+ {
2519
+ id: resolvedId,
2520
+ index,
2521
+ isDragDisabled,
2522
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(CustomInner, { name, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: getClassNameItem2("draggableWrapper"), children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: getClassNameItem2("draggable"), children: [
2523
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: getClassNameItem2("name"), children: label != null ? label : name }),
2524
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: getClassNameItem2("icon"), children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(DragIcon, { isDragDisabled }) })
2525
+ ] }) }) })
2526
+ }
2527
+ );
2528
+ };
2529
+ var Drawer = ({
2530
+ children,
2531
+ droppableId: _droppableId = "default",
2532
+ direction = "vertical"
2533
+ }) => {
2534
+ const droppableId = `component-list:${_droppableId}`;
2535
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(drawerContext.Provider, { value: { droppableId }, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Droppable, { droppableId, isDropDisabled: true, direction, children: (provided, snapshot) => /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
2536
+ "div",
2537
+ __spreadProps(__spreadValues({}, provided.droppableProps), {
2538
+ ref: provided.innerRef,
2539
+ className: getClassName16({
2540
+ isDraggingFrom: !!snapshot.draggingFromThisWith
2541
+ }),
2542
+ children: [
2543
+ children,
2544
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("span", { style: { display: "none" }, children: provided.placeholder })
2545
+ ]
2546
+ })
2547
+ ) }) });
2548
+ };
2549
+ Drawer.Item = DrawerItem;
2431
2550
 
2432
2551
  // components/DropZone/index.tsx
2433
2552
  init_react_import();
2434
- var import_react18 = require("react");
2553
+ var import_react20 = require("react");
2435
2554
 
2436
2555
  // components/DraggableComponent/index.tsx
2437
2556
  init_react_import();
2438
- var import_react16 = require("react");
2557
+ var import_react18 = require("react");
2558
+ var import_dnd4 = require("@measured/dnd");
2439
2559
 
2440
2560
  // css-module:/home/runner/work/puck/puck/packages/core/components/DraggableComponent/styles.module.css#css-module
2441
2561
  init_react_import();
2442
- var styles_module_default11 = { "DraggableComponent": "_DraggableComponent_1uqah_1", "DraggableComponent-overlay": "_DraggableComponent-overlay_1uqah_12", "DraggableComponent-loadingOverlay": "_DraggableComponent-loadingOverlay_1uqah_29", "DraggableComponent--hover": "_DraggableComponent--hover_1uqah_45", "DraggableComponent--isLocked": "_DraggableComponent--isLocked_1uqah_45", "DraggableComponent--isSelected": "_DraggableComponent--isSelected_1uqah_54", "DraggableComponent-actionsOverlay": "_DraggableComponent-actionsOverlay_1uqah_66", "DraggableComponent-actions": "_DraggableComponent-actions_1uqah_66" };
2562
+ var styles_module_default11 = { "DraggableComponent": "_DraggableComponent_1bhad_1", "DraggableComponent--isDragging": "_DraggableComponent--isDragging_1bhad_11", "DraggableComponent-contents": "_DraggableComponent-contents_1bhad_16", "DraggableComponent-overlay": "_DraggableComponent-overlay_1bhad_29", "DraggableComponent-loadingOverlay": "_DraggableComponent-loadingOverlay_1bhad_49", "DraggableComponent--isLocked": "_DraggableComponent--isLocked_1bhad_65", "DraggableComponent--forceHover": "_DraggableComponent--forceHover_1bhad_71", "DraggableComponent--isSelected": "_DraggableComponent--isSelected_1bhad_76", "DraggableComponent--indicativeHover": "_DraggableComponent--indicativeHover_1bhad_81", "DraggableComponent-actionsOverlay": "_DraggableComponent-actionsOverlay_1bhad_97", "DraggableComponent-actions": "_DraggableComponent-actions_1bhad_97" };
2443
2563
 
2444
2564
  // lib/use-modifier-held.ts
2445
2565
  init_react_import();
2446
- var import_react14 = require("react");
2566
+ var import_react17 = require("react");
2447
2567
  var useModifierHeld = (modifier) => {
2448
- const [modifierHeld, setModifierHeld] = (0, import_react14.useState)(false);
2449
- (0, import_react14.useEffect)(() => {
2568
+ const [modifierHeld, setModifierHeld] = (0, import_react17.useState)(false);
2569
+ (0, import_react17.useEffect)(() => {
2450
2570
  function downHandler({ key }) {
2451
2571
  if (key === modifier) {
2452
2572
  setModifierHeld(true);
@@ -2467,762 +2587,179 @@ var useModifierHeld = (modifier) => {
2467
2587
  return modifierHeld;
2468
2588
  };
2469
2589
 
2470
- // components/DraggableComponent/index.tsx
2471
- var import_react_dom2 = require("react-dom");
2472
-
2473
- // components/DraggableComponent/collision/dynamic/index.ts
2474
- init_react_import();
2475
- var import_abstract8 = require("@dnd-kit/abstract");
2476
-
2477
- // components/DraggableComponent/collision/directional/index.ts
2478
- init_react_import();
2479
- var import_abstract = require("@dnd-kit/abstract");
2480
-
2481
- // components/DraggableComponent/collision/collision-debug.ts
2482
- init_react_import();
2483
- var DEBUG = false;
2484
- var debugElements = {};
2485
- var timeout;
2486
- var collisionDebug = (a, b, id, color, label) => {
2487
- if (!DEBUG) return;
2488
- const debugId = `${id}-debug`;
2489
- clearTimeout(timeout);
2490
- timeout = setTimeout(() => {
2491
- Object.entries(debugElements).forEach(([id2, { svg }]) => {
2492
- svg.remove();
2493
- delete debugElements[id2];
2494
- });
2495
- }, 1e3);
2496
- requestAnimationFrame(() => {
2497
- var _a, _b;
2498
- const existingEl = debugElements[debugId];
2499
- let line = (_a = debugElements[debugId]) == null ? void 0 : _a.line;
2500
- let text = (_b = debugElements[debugId]) == null ? void 0 : _b.text;
2501
- if (!existingEl) {
2502
- const svgNs = "http://www.w3.org/2000/svg";
2503
- const svg = document.createElementNS(svgNs, "svg");
2504
- line = document.createElementNS(svgNs, "line");
2505
- text = document.createElementNS(svgNs, "text");
2506
- svg.setAttribute("id", debugId);
2507
- svg.setAttribute(
2508
- "style",
2509
- "position: fixed; height: 100%; width: 100%; pointer-events: none;"
2510
- );
2511
- svg.appendChild(line);
2512
- svg.appendChild(text);
2513
- text.setAttribute("fill", `black`);
2514
- document.body.appendChild(svg);
2515
- debugElements[debugId] = { svg, line, text };
2516
- }
2517
- line.setAttribute("x1", a.x.toString());
2518
- line.setAttribute("x2", b.x.toString());
2519
- line.setAttribute("y1", a.y.toString());
2520
- line.setAttribute("y2", b.y.toString());
2521
- line.setAttribute("style", `stroke:${color};stroke-width:2`);
2522
- text.setAttribute("x", (a.x - (a.x - b.x) / 2).toString());
2523
- text.setAttribute("y", (a.y - (a.y - b.y) / 2).toString());
2524
- if (label) {
2525
- text.innerHTML = label;
2526
- }
2527
- });
2528
- };
2529
-
2530
- // components/DraggableComponent/collision/directional/index.ts
2531
- var distanceChange = "increasing";
2532
- var directionalCollision = (input, previous) => {
2533
- var _a;
2534
- const { dragOperation, droppable } = input;
2535
- const { shape: dropShape } = droppable;
2536
- const { position } = dragOperation;
2537
- const dragShape = (_a = dragOperation.shape) == null ? void 0 : _a.current;
2538
- if (!dragShape || !dropShape) return null;
2539
- const dropCenter = dropShape.center;
2540
- const distanceToPrevious = Math.sqrt(
2541
- Math.pow(dropCenter.x - previous.x, 2) + Math.pow(dropCenter.y - previous.y, 2)
2542
- );
2543
- const distanceToCurrent = Math.sqrt(
2544
- Math.pow(dropCenter.x - position.current.x, 2) + Math.pow(dropCenter.y - position.current.y, 2)
2545
- );
2546
- distanceChange = distanceToCurrent === distanceToPrevious ? distanceChange : distanceToCurrent < distanceToPrevious ? "decreasing" : "increasing";
2547
- collisionDebug(
2548
- dragShape.center,
2549
- dropCenter,
2550
- droppable.id.toString(),
2551
- "rebeccapurple"
2552
- );
2553
- if (distanceChange === "decreasing") {
2554
- return {
2555
- id: droppable.id,
2556
- value: 1,
2557
- type: import_abstract.CollisionType.Collision
2558
- };
2559
- }
2560
- return null;
2561
- };
2562
-
2563
- // components/DraggableComponent/collision/dynamic/get-direction.ts
2564
- init_react_import();
2565
- var getDirection = (dragAxis, delta) => {
2566
- if (dragAxis === "dynamic") {
2567
- if (Math.abs(delta.y) > Math.abs(delta.x)) {
2568
- return delta.y === 0 ? null : delta.y > 0 ? "down" : "up";
2569
- } else {
2570
- return delta.x === 0 ? null : delta.x > 0 ? "right" : "left";
2571
- }
2572
- } else if (dragAxis === "x") {
2573
- return delta.x === 0 ? null : delta.x > 0 ? "right" : "left";
2574
- }
2575
- return delta.y === 0 ? null : delta.y > 0 ? "down" : "up";
2576
- };
2577
-
2578
- // components/DraggableComponent/collision/dynamic/get-midpoint-impact.ts
2579
- init_react_import();
2580
- var getMidpointImpact = (dragShape, dropShape, direction, offsetMultiplier = 0) => {
2581
- const dragRect = dragShape.boundingRectangle;
2582
- const dropCenter = dropShape.center;
2583
- if (direction === "down") {
2584
- const offset2 = offsetMultiplier * dropShape.boundingRectangle.height;
2585
- return dragRect.bottom >= dropCenter.y + offset2;
2586
- } else if (direction === "up") {
2587
- const offset2 = offsetMultiplier * dropShape.boundingRectangle.height;
2588
- return dragRect.top < dropCenter.y - offset2;
2589
- } else if (direction === "left") {
2590
- const offset2 = offsetMultiplier * dropShape.boundingRectangle.width;
2591
- return dropCenter.x - offset2 >= dragRect.left;
2592
- }
2593
- const offset = offsetMultiplier * dropShape.boundingRectangle.width;
2594
- return dragRect.right - offset >= dropCenter.x;
2595
- };
2596
-
2597
- // components/DraggableComponent/collision/dynamic/track-movement-interval.ts
2598
- init_react_import();
2599
- var import_geometry = require("@dnd-kit/geometry");
2600
- var INTERVAL_SENSITIVITY = 10;
2601
- var intervalCache = {
2602
- current: { x: 0, y: 0 },
2603
- delta: { x: 0, y: 0 },
2604
- previous: { x: 0, y: 0 },
2605
- direction: null
2606
- };
2607
- var trackMovementInterval = (point, dragAxis = "dynamic") => {
2608
- intervalCache.current = point;
2609
- intervalCache.delta = {
2610
- x: point.x - intervalCache.previous.x,
2611
- y: point.y - intervalCache.previous.y
2612
- };
2613
- intervalCache.direction = getDirection(dragAxis, intervalCache.delta) || intervalCache.direction;
2614
- if (Math.abs(intervalCache.delta.x) > INTERVAL_SENSITIVITY || Math.abs(intervalCache.delta.y) > INTERVAL_SENSITIVITY) {
2615
- intervalCache.previous = import_geometry.Point.from(point);
2616
- }
2617
- return intervalCache;
2618
- };
2619
-
2620
- // ../../node_modules/@dnd-kit/collision/dist/index.js
2621
- init_react_import();
2622
- var import_abstract2 = require("@dnd-kit/abstract");
2623
- var import_geometry2 = require("@dnd-kit/geometry");
2624
- var import_abstract3 = require("@dnd-kit/abstract");
2625
- var import_geometry3 = require("@dnd-kit/geometry");
2626
- var import_abstract4 = require("@dnd-kit/abstract");
2627
- var import_geometry4 = require("@dnd-kit/geometry");
2628
- var import_abstract5 = require("@dnd-kit/abstract");
2629
- var import_geometry5 = require("@dnd-kit/geometry");
2630
- var import_abstract6 = require("@dnd-kit/abstract");
2631
- var import_geometry6 = require("@dnd-kit/geometry");
2632
- var import_abstract7 = require("@dnd-kit/abstract");
2633
- var import_geometry7 = require("@dnd-kit/geometry");
2634
- var pointerIntersection = ({
2635
- dragOperation,
2636
- droppable
2637
- }) => {
2638
- const pointerCoordinates = dragOperation.position.current;
2639
- if (!pointerCoordinates) {
2640
- return null;
2641
- }
2642
- const { id } = droppable;
2643
- if (!droppable.shape) {
2644
- return null;
2645
- }
2646
- if (droppable.shape.containsPoint(pointerCoordinates)) {
2647
- const distance = import_geometry2.Point.distance(droppable.shape.center, pointerCoordinates);
2648
- return {
2649
- id,
2650
- value: 1 / distance,
2651
- type: import_abstract2.CollisionType.PointerIntersection,
2652
- priority: import_abstract2.CollisionPriority.High
2653
- };
2654
- }
2655
- return null;
2656
- };
2657
- var closestCorners = (input) => {
2658
- const { dragOperation, droppable } = input;
2659
- const { shape, position } = dragOperation;
2660
- if (!droppable.shape) {
2661
- return null;
2662
- }
2663
- const { left, top, right, bottom } = droppable.shape.boundingRectangle;
2664
- const corners = [
2665
- {
2666
- x: left,
2667
- y: top
2668
- },
2669
- {
2670
- x: right,
2671
- y: top
2672
- },
2673
- {
2674
- x: left,
2675
- y: bottom
2676
- },
2677
- {
2678
- x: right,
2679
- y: bottom
2680
- }
2681
- ];
2682
- const distance = corners.reduce(
2683
- (acc, corner) => {
2684
- var _a;
2685
- return acc + import_geometry4.Point.distance(
2686
- import_geometry4.Point.from(corner),
2687
- (_a = shape == null ? void 0 : shape.current.center) != null ? _a : position.current
2688
- );
2689
- },
2690
- 0
2691
- );
2692
- const value = distance / 4;
2693
- return {
2694
- id: droppable.id,
2695
- value: 1 / value,
2696
- type: import_abstract4.CollisionType.Collision,
2697
- priority: import_abstract4.CollisionPriority.Normal
2698
- };
2699
- };
2700
-
2701
- // components/DraggableComponent/collision/dynamic/index.ts
2702
- var flushNext = "";
2703
- var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input) => {
2704
- var _a, _b, _c, _d, _e;
2705
- const { dragOperation, droppable } = input;
2706
- const { position } = dragOperation;
2707
- const dragShape = (_a = dragOperation.shape) == null ? void 0 : _a.current;
2708
- const { shape: dropShape } = droppable;
2709
- if (!dragShape || !dropShape) {
2710
- return null;
2711
- }
2712
- const { center: dragCenter } = dragShape;
2713
- const interval = trackMovementInterval(position.current, dragAxis);
2714
- dragOperation.data = __spreadProps(__spreadValues({}, dragOperation.data), {
2715
- direction: interval.direction
2716
- });
2717
- const collisionMap = dragOperation.data.collisionMap || {};
2718
- dragOperation.data.collisionMap = collisionMap;
2719
- collisionMap[droppable.id] = {
2720
- direction: interval.direction
2721
- };
2722
- const { center: dropCenter } = dropShape;
2723
- const overMidpoint = getMidpointImpact(
2724
- dragShape,
2725
- dropShape,
2726
- interval.direction,
2727
- midpointOffset
2728
- );
2729
- if (((_b = dragOperation.source) == null ? void 0 : _b.id) === droppable.id) {
2730
- const collision = directionalCollision(input, interval.previous);
2731
- collisionDebug(dragCenter, dropCenter, droppable.id.toString(), "yellow");
2732
- if (collision) {
2733
- return __spreadProps(__spreadValues({}, collision), {
2734
- priority: import_abstract8.CollisionPriority.Highest
2735
- });
2736
- }
2737
- }
2738
- const intersectionArea = dragShape.intersectionArea(dropShape);
2739
- const intersectionRatio = intersectionArea / dropShape.area;
2740
- if (intersectionArea && overMidpoint) {
2741
- collisionDebug(
2742
- dragCenter,
2743
- dropCenter,
2744
- droppable.id.toString(),
2745
- "green",
2746
- interval.direction
2747
- );
2748
- const collision = {
2749
- id: droppable.id,
2750
- value: intersectionRatio,
2751
- priority: import_abstract8.CollisionPriority.High,
2752
- type: import_abstract8.CollisionType.Collision
2753
- };
2754
- const shouldFlushId = flushNext === droppable.id;
2755
- flushNext = "";
2756
- return __spreadProps(__spreadValues({}, collision), { id: shouldFlushId ? "flush" : collision.id });
2757
- }
2758
- if (((_c = dragOperation.source) == null ? void 0 : _c.id) !== droppable.id) {
2759
- const xAxisIntersection = dropShape.boundingRectangle.right > dragShape.boundingRectangle.left && dropShape.boundingRectangle.left < dragShape.boundingRectangle.right;
2760
- const yAxisIntersection = dropShape.boundingRectangle.bottom > dragShape.boundingRectangle.top && dropShape.boundingRectangle.top < dragShape.boundingRectangle.bottom;
2761
- if (dragAxis === "y" && xAxisIntersection || yAxisIntersection) {
2762
- const fallbackCollision = closestCorners(input);
2763
- if (fallbackCollision) {
2764
- const direction = getDirection(dragAxis, {
2765
- x: dragShape.center.x - (((_d = droppable.shape) == null ? void 0 : _d.center.x) || 0),
2766
- y: dragShape.center.y - (((_e = droppable.shape) == null ? void 0 : _e.center.y) || 0)
2767
- });
2768
- collisionMap[droppable.id] = {
2769
- direction
2770
- };
2771
- if (intersectionArea) {
2772
- collisionDebug(
2773
- dragCenter,
2774
- dropCenter,
2775
- droppable.id.toString(),
2776
- "red",
2777
- direction || ""
2778
- );
2779
- flushNext = droppable.id;
2780
- return __spreadProps(__spreadValues({}, fallbackCollision), {
2781
- priority: import_abstract8.CollisionPriority.Low
2782
- });
2783
- }
2784
- collisionDebug(
2785
- dragCenter,
2786
- dropCenter,
2787
- droppable.id.toString(),
2788
- "orange",
2789
- direction || ""
2790
- );
2791
- return __spreadProps(__spreadValues({}, fallbackCollision), { priority: import_abstract8.CollisionPriority.Lowest });
2792
- }
2793
- }
2794
- }
2795
- collisionDebug(dragCenter, dropCenter, droppable.id.toString(), "hotpink");
2796
- delete collisionMap[droppable.id];
2797
- return null;
2798
- };
2799
-
2800
- // lib/dnd-kit/safe.ts
2801
- init_react_import();
2802
- var import_react15 = require("@dnd-kit/react");
2803
- var import_sortable = require("@dnd-kit/react/sortable");
2804
- function useDroppableSafe(input) {
2805
- if (typeof window === "undefined") {
2806
- return { ref: () => {
2807
- } };
2808
- }
2809
- return (0, import_react15.useDroppable)(input);
2810
- }
2811
- function useDraggableSafe(input) {
2812
- if (typeof window === "undefined") {
2813
- return { ref: () => {
2814
- } };
2815
- }
2816
- return (0, import_react15.useDraggable)(input);
2817
- }
2818
- function useSortableSafe(input) {
2819
- if (typeof window === "undefined") {
2820
- return { ref: () => {
2821
- }, status: "idle" };
2822
- }
2823
- return (0, import_sortable.useSortable)(input);
2824
- }
2825
-
2826
- // lib/get-deep-scroll-position.ts
2590
+ // lib/is-ios.ts
2827
2591
  init_react_import();
2828
- function getDeepScrollPosition(element) {
2829
- let totalScroll = {
2830
- x: 0,
2831
- y: 0
2832
- };
2833
- let current = element;
2834
- while (current && current !== document.documentElement) {
2835
- const parent = current.parentElement;
2836
- if (parent) {
2837
- totalScroll.x += parent.scrollLeft;
2838
- totalScroll.y += parent.scrollTop;
2839
- }
2840
- current = parent;
2841
- }
2842
- return totalScroll;
2843
- }
2592
+ var isIos = () => [
2593
+ "iPad Simulator",
2594
+ "iPhone Simulator",
2595
+ "iPod Simulator",
2596
+ "iPad",
2597
+ "iPhone",
2598
+ "iPod"
2599
+ ].includes(navigator.platform) || // iPad on iOS 13 detection
2600
+ navigator.userAgent.includes("Mac") && "ontouchend" in document;
2844
2601
 
2845
2602
  // components/DraggableComponent/index.tsx
2846
- var import_jsx_runtime21 = require("react/jsx-runtime");
2847
- var getClassName16 = get_class_name_factory_default("DraggableComponent", styles_module_default11);
2848
- var DEBUG2 = false;
2603
+ var import_jsx_runtime22 = require("react/jsx-runtime");
2604
+ var getClassName17 = get_class_name_factory_default("DraggableComponent", styles_module_default11);
2849
2605
  var space = 8;
2850
2606
  var actionsOverlayTop = space * 6.5;
2851
2607
  var actionsTop = -(actionsOverlayTop - 8);
2852
- var actionsSide = space;
2608
+ var actionsRight = space;
2853
2609
  var DefaultActionBar = ({
2854
2610
  label,
2855
2611
  children
2856
- }) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ActionBar, { label, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ActionBar.Group, { children }) });
2612
+ }) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ActionBar, { label, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ActionBar.Group, { children }) });
2857
2613
  var DraggableComponent = ({
2858
2614
  children,
2859
- depth,
2860
- componentType,
2861
2615
  id,
2862
2616
  index,
2863
- zoneCompound,
2864
2617
  isLoading = false,
2865
2618
  isSelected = false,
2619
+ onClick = () => null,
2620
+ onMount = () => null,
2621
+ onMouseDown = () => null,
2622
+ onMouseUp = () => null,
2623
+ onMouseOver = () => null,
2624
+ onMouseOut = () => null,
2625
+ onDelete = () => null,
2626
+ onDuplicate = () => null,
2866
2627
  debug,
2867
2628
  label,
2868
- isEnabled,
2869
- autoDragAxis,
2870
- userDragAxis,
2871
- inDroppableZone = true
2629
+ isLocked = false,
2630
+ isDragDisabled,
2631
+ forceHover = false,
2632
+ indicativeHover = false,
2633
+ style
2872
2634
  }) => {
2873
- const {
2874
- zoomConfig,
2875
- overrides,
2876
- selectedItem,
2877
- getPermissions,
2878
- dispatch,
2879
- iframe,
2880
- state
2881
- } = useAppContext();
2635
+ const { zoomConfig, status, overrides, selectedItem, getPermissions } = useAppContext();
2882
2636
  const isModifierHeld = useModifierHeld("Alt");
2883
- const ctx = (0, import_react16.useContext)(dropZoneContext);
2884
- const [localZones, setLocalZones] = (0, import_react16.useState)({});
2885
- const registerLocalZone = (0, import_react16.useCallback)(
2886
- (zoneCompound2, active) => {
2887
- var _a;
2888
- (_a = ctx == null ? void 0 : ctx.registerLocalZone) == null ? void 0 : _a.call(ctx, zoneCompound2, active);
2889
- setLocalZones((obj) => __spreadProps(__spreadValues({}, obj), {
2890
- [zoneCompound2]: active
2891
- }));
2892
- },
2893
- [setLocalZones]
2894
- );
2895
- const containsActiveZone = Object.values(localZones).filter(Boolean).length > 0;
2896
- const { path = [] } = ctx || {};
2897
- const [canDrag, setCanDrag] = (0, import_react16.useState)(false);
2898
- (0, import_react16.useEffect)(() => {
2899
- var _a;
2900
- const item = getItem({ index, zone: zoneCompound }, state.data);
2901
- if (item) {
2902
- const perms = getPermissions({
2903
- item
2904
- });
2905
- setCanDrag((_a = perms.drag) != null ? _a : true);
2906
- }
2907
- }, [state, index, zoneCompound, getPermissions]);
2908
- const userIsDragging = !!(ctx == null ? void 0 : ctx.draggedItem);
2909
- const canCollide = canDrag || userIsDragging;
2910
- const disabled = !isEnabled || !canCollide;
2911
- const [dragAxis, setDragAxis] = (0, import_react16.useState)(userDragAxis || autoDragAxis);
2912
- const { ref: sortableRef, status } = useSortableSafe({
2913
- id,
2914
- index,
2915
- group: zoneCompound,
2916
- type: "component",
2917
- data: {
2918
- zone: zoneCompound,
2919
- index,
2920
- componentType,
2921
- containsActiveZone,
2922
- depth,
2923
- path,
2924
- inDroppableZone
2925
- },
2926
- collisionPriority: isEnabled ? depth : 0,
2927
- collisionDetector: createDynamicCollisionDetector(dragAxis),
2928
- disabled,
2929
- // "Out of the way" transition from react-beautiful-dnd
2930
- transition: {
2931
- duration: 200,
2932
- easing: "cubic-bezier(0.2, 0, 0, 1)"
2933
- }
2934
- });
2935
- const thisIsDragging = status === "dragging";
2936
- const ref = (0, import_react16.useRef)();
2937
- const refSetter = (0, import_react16.useCallback)(
2938
- (el) => {
2939
- sortableRef(el);
2940
- if (el) {
2941
- ref.current = el;
2942
- }
2943
- },
2944
- [sortableRef]
2945
- );
2946
- const [portalEl, setPortalEl] = (0, import_react16.useState)();
2947
- (0, import_react16.useEffect)(() => {
2948
- var _a, _b, _c;
2949
- setPortalEl(
2950
- iframe.enabled ? (_a = ref.current) == null ? void 0 : _a.ownerDocument.body : (_c = (_b = ref.current) == null ? void 0 : _b.closest("[data-puck-preview]")) != null ? _c : document.body
2951
- );
2952
- }, [iframe.enabled, ref.current]);
2953
- const getStyle = (0, import_react16.useCallback)(() => {
2954
- var _a, _b, _c;
2955
- if (!ref.current) return;
2956
- const rect = ref.current.getBoundingClientRect();
2957
- const deepScrollPosition = getDeepScrollPosition(ref.current);
2958
- const portalContainerEl = iframe.enabled ? null : (_a = ref.current) == null ? void 0 : _a.closest("[data-puck-preview]");
2959
- const portalContainerRect = portalContainerEl == null ? void 0 : portalContainerEl.getBoundingClientRect();
2960
- const portalScroll = portalContainerEl ? getDeepScrollPosition(portalContainerEl) : { x: 0, y: 0 };
2961
- const scroll = {
2962
- x: deepScrollPosition.x - portalScroll.x - ((_b = portalContainerRect == null ? void 0 : portalContainerRect.left) != null ? _b : 0),
2963
- y: deepScrollPosition.y - portalScroll.y - ((_c = portalContainerRect == null ? void 0 : portalContainerRect.top) != null ? _c : 0)
2964
- };
2965
- const style2 = {
2966
- left: `${rect.left + scroll.x}px`,
2967
- top: `${rect.top + scroll.y}px`,
2968
- height: `${rect.height}px`,
2969
- width: `${rect.width}px`
2970
- };
2971
- return style2;
2972
- }, [ref.current]);
2973
- const [style, setStyle] = (0, import_react16.useState)();
2974
- const sync = (0, import_react16.useCallback)(() => {
2975
- setStyle(getStyle());
2976
- }, [ref.current, iframe]);
2977
- (0, import_react16.useEffect)(() => {
2978
- if (ref.current) {
2979
- const observer = new ResizeObserver(sync);
2980
- observer.observe(ref.current);
2981
- return () => {
2982
- observer.disconnect();
2983
- };
2637
+ const El = status !== "LOADING" ? import_dnd4.Draggable : DefaultDraggable;
2638
+ (0, import_react18.useEffect)(onMount, []);
2639
+ const [disableSecondaryAnimation, setDisableSecondaryAnimation] = (0, import_react18.useState)(false);
2640
+ (0, import_react18.useEffect)(() => {
2641
+ if (isIos()) {
2642
+ setDisableSecondaryAnimation(true);
2984
2643
  }
2985
- }, [ref.current]);
2986
- (0, import_react16.useEffect)(() => {
2987
- ctx == null ? void 0 : ctx.registerPath({
2988
- index,
2989
- zone: zoneCompound
2990
- });
2991
- }, [isSelected]);
2992
- const CustomActionBar = (0, import_react16.useMemo)(
2644
+ }, []);
2645
+ const CustomActionBar = (0, import_react18.useMemo)(
2993
2646
  () => overrides.actionBar || DefaultActionBar,
2994
2647
  [overrides.actionBar]
2995
2648
  );
2996
2649
  const permissions = getPermissions({
2997
2650
  item: selectedItem
2998
2651
  });
2999
- const onClick = (0, import_react16.useCallback)(
3000
- (e) => {
3001
- e.stopPropagation();
3002
- dispatch({
3003
- type: "setUi",
3004
- ui: {
3005
- itemSelector: { index, zone: zoneCompound }
3006
- }
3007
- });
2652
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2653
+ El,
2654
+ {
2655
+ draggableId: id,
2656
+ index,
2657
+ isDragDisabled,
2658
+ disableSecondaryAnimation,
2659
+ children: (provided, snapshot) => /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
2660
+ "div",
2661
+ __spreadProps(__spreadValues(__spreadValues({
2662
+ ref: provided.innerRef
2663
+ }, provided.draggableProps), provided.dragHandleProps), {
2664
+ className: getClassName17({
2665
+ isSelected,
2666
+ isModifierHeld,
2667
+ isDragging: snapshot.isDragging,
2668
+ isLocked,
2669
+ forceHover,
2670
+ indicativeHover
2671
+ }),
2672
+ style: __spreadProps(__spreadValues(__spreadValues({}, style), provided.draggableProps.style), {
2673
+ cursor: isModifierHeld || isDragDisabled ? "pointer" : "grab"
2674
+ }),
2675
+ onMouseOver,
2676
+ onMouseOut,
2677
+ onMouseDown,
2678
+ onMouseUp,
2679
+ onClick,
2680
+ children: [
2681
+ debug,
2682
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: getClassName17("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Loader, {}) }),
2683
+ isSelected && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2684
+ "div",
2685
+ {
2686
+ className: getClassName17("actionsOverlay"),
2687
+ style: {
2688
+ top: actionsOverlayTop / zoomConfig.zoom
2689
+ },
2690
+ children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2691
+ "div",
2692
+ {
2693
+ className: getClassName17("actions"),
2694
+ style: {
2695
+ transform: `scale(${1 / zoomConfig.zoom}`,
2696
+ top: actionsTop / zoomConfig.zoom,
2697
+ right: actionsRight / zoomConfig.zoom
2698
+ },
2699
+ children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(CustomActionBar, { label, children: [
2700
+ permissions.duplicate && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Copy, { size: 16 }) }),
2701
+ permissions.delete && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Trash, { size: 16 }) })
2702
+ ] })
2703
+ }
2704
+ )
2705
+ }
2706
+ ),
2707
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: getClassName17("overlay") }),
2708
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: getClassName17("contents"), children })
2709
+ ]
2710
+ })
2711
+ )
3008
2712
  },
3009
- [index, zoneCompound, id]
3010
- );
3011
- const onDuplicate = (0, import_react16.useCallback)(
3012
- (e) => {
3013
- e.stopPropagation();
3014
- dispatch({
3015
- type: "duplicate",
3016
- sourceIndex: index,
3017
- sourceZone: zoneCompound
3018
- });
3019
- },
3020
- [index, zoneCompound]
3021
- );
3022
- const onDelete = (0, import_react16.useCallback)(
3023
- (e) => {
3024
- e.stopPropagation();
3025
- dispatch({
3026
- type: "remove",
3027
- index,
3028
- zone: zoneCompound
3029
- });
3030
- },
3031
- [index, zoneCompound]
3032
- );
3033
- const [hover, setHover] = (0, import_react16.useState)(false);
3034
- const indicativeHover = (ctx == null ? void 0 : ctx.hoveringComponent) === id;
3035
- (0, import_react16.useEffect)(() => {
3036
- if (!ref.current) {
3037
- return;
3038
- }
3039
- const el = ref.current;
3040
- const _onMouseOver = (e) => {
3041
- if (userIsDragging) {
3042
- if (thisIsDragging) {
3043
- setHover(true);
3044
- } else {
3045
- setHover(false);
3046
- }
3047
- } else {
3048
- setHover(true);
3049
- }
3050
- e.stopPropagation();
3051
- };
3052
- const _onMouseOut = (e) => {
3053
- e.stopPropagation();
3054
- setHover(false);
3055
- };
3056
- el.setAttribute("data-puck-component", id);
3057
- el.style.position = "relative";
3058
- el.addEventListener("click", onClick);
3059
- el.addEventListener("mouseover", _onMouseOver);
3060
- el.addEventListener("mouseout", _onMouseOut);
3061
- if (thisIsDragging) {
3062
- el.setAttribute("data-puck-dragging", "");
3063
- } else {
3064
- el.removeAttribute("data-puck-dragging");
3065
- }
3066
- return () => {
3067
- el.removeAttribute("data-puck-component");
3068
- el.removeEventListener("click", onClick);
3069
- el.removeEventListener("mouseover", _onMouseOver);
3070
- el.removeEventListener("mouseout", _onMouseOut);
3071
- el.removeAttribute("data-puck-dragging");
3072
- };
3073
- }, [
3074
- ref,
3075
- onClick,
3076
- containsActiveZone,
3077
- zoneCompound,
3078
- id,
3079
- userIsDragging,
3080
- thisIsDragging,
3081
- inDroppableZone
3082
- ]);
3083
- (0, import_react16.useEffect)(() => {
3084
- if (ref.current && disabled) {
3085
- ref.current.setAttribute("data-puck-disabled", "");
3086
- return () => {
3087
- var _a;
3088
- (_a = ref.current) == null ? void 0 : _a.removeAttribute("data-puck-disabled");
3089
- };
3090
- }
3091
- }, [disabled, ref]);
3092
- const [isVisible, setIsVisible] = (0, import_react16.useState)(false);
3093
- (0, import_react16.useEffect)(() => {
3094
- sync();
3095
- if ((isSelected || hover || indicativeHover) && !userIsDragging) {
3096
- setIsVisible(true);
3097
- } else {
3098
- setIsVisible(false);
3099
- }
3100
- }, [isSelected, hover, indicativeHover, iframe, state.data, userIsDragging]);
3101
- const syncActionsPosition = (0, import_react16.useCallback)(
3102
- (el) => {
3103
- if (el) {
3104
- const view = el.ownerDocument.defaultView;
3105
- if (view) {
3106
- const rect = el.getBoundingClientRect();
3107
- const diffLeft = rect.x;
3108
- const exceedsBoundsLeft = diffLeft < 0;
3109
- if (exceedsBoundsLeft) {
3110
- el.style.transformOrigin = "left top";
3111
- el.style.left = "0px";
3112
- } else {
3113
- el.style.transformOrigin = "right top";
3114
- el.style.left = "";
3115
- }
3116
- }
3117
- }
3118
- },
3119
- [zoomConfig]
3120
- );
3121
- (0, import_react16.useEffect)(() => {
3122
- if (userDragAxis) {
3123
- setDragAxis(userDragAxis);
3124
- return;
3125
- }
3126
- if (ref.current) {
3127
- const computedStyle = window.getComputedStyle(ref.current);
3128
- if (computedStyle.display === "inline" || computedStyle.display === "inline-block") {
3129
- setDragAxis("x");
3130
- return;
3131
- }
3132
- }
3133
- setDragAxis(autoDragAxis);
3134
- }, [ref, userDragAxis, autoDragAxis]);
3135
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
3136
- DropZoneProvider,
3137
- {
3138
- value: __spreadProps(__spreadValues({}, ctx), {
3139
- areaId: id,
3140
- zoneCompound,
3141
- index,
3142
- depth: depth + 1,
3143
- registerLocalZone,
3144
- path: [...path, id]
3145
- }),
3146
- children: [
3147
- isVisible && (0, import_react_dom2.createPortal)(
3148
- /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
3149
- "div",
3150
- {
3151
- className: getClassName16({
3152
- isSelected,
3153
- isDragging: thisIsDragging,
3154
- isModifierHeld,
3155
- hover: hover || indicativeHover
3156
- }),
3157
- style: __spreadValues({}, style),
3158
- children: [
3159
- debug,
3160
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: getClassName16("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Loader, {}) }),
3161
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
3162
- "div",
3163
- {
3164
- className: getClassName16("actionsOverlay"),
3165
- style: {
3166
- top: actionsOverlayTop / zoomConfig.zoom
3167
- },
3168
- children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
3169
- "div",
3170
- {
3171
- className: getClassName16("actions"),
3172
- style: {
3173
- transform: `scale(${1 / zoomConfig.zoom}`,
3174
- top: actionsTop / zoomConfig.zoom,
3175
- right: 0,
3176
- paddingLeft: actionsSide,
3177
- paddingRight: actionsSide
3178
- },
3179
- ref: syncActionsPosition,
3180
- children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(CustomActionBar, { label: DEBUG2 ? id : label, children: [
3181
- permissions.duplicate && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Copy, { size: 16 }) }),
3182
- permissions.delete && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Trash, { size: 16 }) })
3183
- ] })
3184
- }
3185
- )
3186
- }
3187
- ),
3188
- /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: getClassName16("overlay") })
3189
- ]
3190
- }
3191
- ),
3192
- portalEl || document.body
3193
- ),
3194
- children(refSetter)
3195
- ]
3196
- }
2713
+ id
3197
2714
  );
3198
2715
  };
3199
2716
 
3200
2717
  // css-module:/home/runner/work/puck/puck/packages/core/components/DropZone/styles.module.css#css-module
3201
2718
  init_react_import();
3202
- var styles_module_default12 = { "DropZone": "_DropZone_74ebh_1", "DropZone--hasChildren": "_DropZone--hasChildren_74ebh_12", "DropZone--userIsDragging": "_DropZone--userIsDragging_74ebh_20", "DropZone--isAreaSelected": "_DropZone--isAreaSelected_74ebh_29", "DropZone--hoveringOverArea": "_DropZone--hoveringOverArea_74ebh_30", "DropZone--isRootZone": "_DropZone--isRootZone_74ebh_30", "DropZone--isDestination": "_DropZone--isDestination_74ebh_40", "DropZone-item": "_DropZone-item_74ebh_52", "DropZone-hitbox": "_DropZone-hitbox_74ebh_56", "DropZone--isEnabled": "_DropZone--isEnabled_74ebh_64" };
2719
+ var styles_module_default12 = { "DropZone": "_DropZone_djoti_1", "DropZone-content": "_DropZone-content_djoti_10", "DropZone--userIsDragging": "_DropZone--userIsDragging_djoti_15", "DropZone--draggingOverArea": "_DropZone--draggingOverArea_djoti_19", "DropZone--draggingNewComponent": "_DropZone--draggingNewComponent_djoti_20", "DropZone--isAreaSelected": "_DropZone--isAreaSelected_djoti_26", "DropZone--hoveringOverArea": "_DropZone--hoveringOverArea_djoti_27", "DropZone--isDisabled": "_DropZone--isDisabled_djoti_28", "DropZone--isRootZone": "_DropZone--isRootZone_djoti_29", "DropZone--hasChildren": "_DropZone--hasChildren_djoti_30", "DropZone--isDestination": "_DropZone--isDestination_djoti_40", "DropZone-item": "_DropZone-item_djoti_52", "DropZone-hitbox": "_DropZone-hitbox_djoti_56" };
3203
2720
 
3204
2721
  // components/DropZone/context.tsx
3205
2722
  init_react_import();
3206
- var import_react17 = require("react");
3207
- var import_jsx_runtime22 = require("react/jsx-runtime");
3208
- var dropZoneContext = (0, import_react17.createContext)(null);
2723
+ var import_react19 = require("react");
2724
+ var import_use_debounce2 = require("use-debounce");
2725
+
2726
+ // lib/get-zone-id.ts
2727
+ init_react_import();
2728
+ var getZoneId = (zoneCompound) => {
2729
+ if (!zoneCompound) {
2730
+ return [];
2731
+ }
2732
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
2733
+ return zoneCompound.split(":");
2734
+ }
2735
+ return [rootDroppableId, zoneCompound];
2736
+ };
2737
+
2738
+ // components/DropZone/context.tsx
2739
+ var import_jsx_runtime23 = require("react/jsx-runtime");
2740
+ var dropZoneContext = (0, import_react19.createContext)(null);
3209
2741
  var DropZoneProvider = ({
3210
2742
  children,
3211
2743
  value
3212
2744
  }) => {
3213
- const [hoveringComponent, setHoveringComponent] = (0, import_react17.useState)();
3214
- const [areasWithZones, setAreasWithZones] = (0, import_react17.useState)(
2745
+ const [hoveringArea, setHoveringArea] = (0, import_react19.useState)(null);
2746
+ const [hoveringZone, setHoveringZone] = (0, import_react19.useState)(
2747
+ rootDroppableId
2748
+ );
2749
+ const [hoveringComponent, setHoveringComponent] = (0, import_react19.useState)();
2750
+ const [hoveringAreaDb] = (0, import_use_debounce2.useDebounce)(hoveringArea, 75, { leading: false });
2751
+ const [areasWithZones, setAreasWithZones] = (0, import_react19.useState)(
3215
2752
  {}
3216
2753
  );
3217
- const [activeZones, setActiveZones] = (0, import_react17.useState)({});
2754
+ const [activeZones, setActiveZones] = (0, import_react19.useState)({});
3218
2755
  const { dispatch = null } = value ? value : {};
3219
- const registerZoneArea = (0, import_react17.useCallback)(
2756
+ const registerZoneArea = (0, import_react19.useCallback)(
3220
2757
  (area) => {
3221
2758
  setAreasWithZones((latest) => __spreadProps(__spreadValues({}, latest), { [area]: true }));
3222
2759
  },
3223
2760
  [setAreasWithZones]
3224
2761
  );
3225
- const registerZone = (0, import_react17.useCallback)(
2762
+ const registerZone = (0, import_react19.useCallback)(
3226
2763
  (zoneCompound) => {
3227
2764
  if (!dispatch) {
3228
2765
  return;
@@ -3235,7 +2772,7 @@ var DropZoneProvider = ({
3235
2772
  },
3236
2773
  [setActiveZones, dispatch]
3237
2774
  );
3238
- const unregisterZone = (0, import_react17.useCallback)(
2775
+ const unregisterZone = (0, import_react19.useCallback)(
3239
2776
  (zoneCompound) => {
3240
2777
  if (!dispatch) {
3241
2778
  return;
@@ -3250,76 +2787,89 @@ var DropZoneProvider = ({
3250
2787
  },
3251
2788
  [setActiveZones, dispatch]
3252
2789
  );
3253
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_jsx_runtime22.Fragment, { children: value && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
2790
+ const [pathData, setPathData] = (0, import_react19.useState)();
2791
+ const registerPath = (0, import_react19.useCallback)(
2792
+ (selector) => {
2793
+ if (!(value == null ? void 0 : value.data)) {
2794
+ return;
2795
+ }
2796
+ const item = getItem(selector, value.data);
2797
+ if (!item) {
2798
+ return;
2799
+ }
2800
+ const [area] = getZoneId(selector.zone);
2801
+ setPathData((latestPathData = {}) => {
2802
+ const parentPathData = latestPathData[area] || { path: [] };
2803
+ return __spreadProps(__spreadValues({}, latestPathData), {
2804
+ [item.props.id]: {
2805
+ path: [
2806
+ ...parentPathData.path,
2807
+ ...selector.zone ? [selector.zone] : []
2808
+ ],
2809
+ label: item.type
2810
+ }
2811
+ });
2812
+ });
2813
+ },
2814
+ [value, setPathData]
2815
+ );
2816
+ const [zoneWillDrag, setZoneWillDrag] = (0, import_react19.useState)("");
2817
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_jsx_runtime23.Fragment, { children: value && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
3254
2818
  dropZoneContext.Provider,
3255
2819
  {
3256
2820
  value: __spreadValues({
2821
+ hoveringArea: value.draggedItem ? hoveringAreaDb : hoveringArea,
2822
+ setHoveringArea,
2823
+ hoveringZone,
2824
+ setHoveringZone,
3257
2825
  hoveringComponent,
3258
2826
  setHoveringComponent,
3259
2827
  registerZoneArea,
3260
2828
  areasWithZones,
3261
2829
  registerZone,
3262
2830
  unregisterZone,
3263
- activeZones
2831
+ activeZones,
2832
+ registerPath,
2833
+ pathData,
2834
+ zoneWillDrag,
2835
+ setZoneWillDrag
3264
2836
  }, value),
3265
2837
  children
3266
2838
  }
3267
2839
  ) });
3268
2840
  };
3269
2841
 
3270
- // lib/insert.ts
3271
- init_react_import();
3272
- var insert = (list, index, item) => {
3273
- const result = Array.from(list);
3274
- result.splice(index, 0, item);
3275
- return result;
3276
- };
3277
-
3278
2842
  // components/DropZone/index.tsx
3279
- var import_jsx_runtime23 = require("react/jsx-runtime");
3280
- var getClassName17 = get_class_name_factory_default("DropZone", styles_module_default12);
3281
- var DEBUG3 = false;
3282
- var GRID_DRAG_AXIS = "dynamic";
3283
- var FLEX_ROW_DRAG_AXIS = "x";
3284
- var DEFAULT_DRAG_AXIS = "y";
3285
- function DropZoneEdit({
3286
- zone,
3287
- allow,
3288
- disallow,
3289
- style,
3290
- className,
3291
- minEmptyHeight = 128,
3292
- dragRef,
3293
- collisionAxis
3294
- }) {
2843
+ var import_jsx_runtime24 = require("react/jsx-runtime");
2844
+ var getClassName18 = get_class_name_factory_default("DropZone", styles_module_default12);
2845
+ function DropZoneEdit({ zone, allow, disallow, style }) {
2846
+ var _a;
3295
2847
  const appContext2 = useAppContext();
3296
- const ctx = (0, import_react18.useContext)(dropZoneContext);
2848
+ const ctx = (0, import_react20.useContext)(dropZoneContext);
3297
2849
  const {
3298
2850
  // These all need setting via context
3299
2851
  data,
2852
+ dispatch = () => null,
3300
2853
  config,
2854
+ itemSelector,
2855
+ setItemSelector = () => null,
3301
2856
  areaId,
3302
2857
  draggedItem,
2858
+ placeholderStyle,
3303
2859
  registerZoneArea,
3304
- depth,
3305
- registerLocalZone,
3306
- deepestZone = rootDroppableId,
3307
- deepestArea,
3308
- nextDeepestArea,
3309
- path = []
3310
- } = ctx;
3311
- const { itemSelector } = appContext2.state.ui;
2860
+ areasWithZones,
2861
+ hoveringComponent,
2862
+ zoneWillDrag,
2863
+ setZoneWillDrag = () => null
2864
+ } = ctx || {};
3312
2865
  let content = data.content || [];
3313
2866
  let zoneCompound = rootDroppableId;
3314
- (0, import_react18.useEffect)(() => {
2867
+ (0, import_react20.useEffect)(() => {
3315
2868
  if (areaId && registerZoneArea) {
3316
2869
  registerZoneArea(areaId);
3317
2870
  }
3318
2871
  }, [areaId]);
3319
- (0, import_react18.useEffect)(() => {
3320
- if (registerLocalZone) {
3321
- registerLocalZone(zoneCompound, isDroppableTarget());
3322
- }
2872
+ (0, import_react20.useEffect)(() => {
3323
2873
  if (ctx == null ? void 0 : ctx.registerZone) {
3324
2874
  ctx == null ? void 0 : ctx.registerZone(zoneCompound);
3325
2875
  }
@@ -3335,199 +2885,247 @@ function DropZoneEdit({
3335
2885
  content = setupZone(data, zoneCompound).zones[zoneCompound];
3336
2886
  }
3337
2887
  }
3338
- const ref = (0, import_react18.useRef)();
3339
- const isDroppableTarget = (0, import_react18.useCallback)(() => {
3340
- if (!draggedItem) {
3341
- return true;
2888
+ const isRootZone = zoneCompound === rootDroppableId || zone === rootDroppableId || areaId === "root";
2889
+ const draggedSourceId = draggedItem && draggedItem.source.droppableId;
2890
+ const draggedDestinationId = draggedItem && ((_a = draggedItem.destination) == null ? void 0 : _a.droppableId);
2891
+ const [zoneArea] = getZoneId(zoneCompound);
2892
+ const [draggedSourceArea] = getZoneId(draggedSourceId);
2893
+ const userWillDrag = zoneWillDrag === zone;
2894
+ const userIsDragging = !!draggedItem;
2895
+ const draggingOverArea = userIsDragging && zoneArea === draggedSourceArea;
2896
+ const draggingNewComponent = draggedSourceId == null ? void 0 : draggedSourceId.startsWith("component-list");
2897
+ if (!(ctx == null ? void 0 : ctx.config) || !ctx.setHoveringArea || !ctx.setHoveringZone || !ctx.setHoveringComponent || !ctx.setItemSelector || !ctx.registerPath || !ctx.dispatch) {
2898
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { children: "DropZone requires context to work." });
2899
+ }
2900
+ const {
2901
+ hoveringArea = "root",
2902
+ setHoveringArea,
2903
+ hoveringZone,
2904
+ setHoveringZone,
2905
+ setHoveringComponent
2906
+ } = ctx;
2907
+ const hoveringOverArea = hoveringArea ? hoveringArea === zoneArea : isRootZone;
2908
+ const hoveringOverZone = hoveringZone === zoneCompound;
2909
+ let isEnabled = userWillDrag;
2910
+ if (userIsDragging) {
2911
+ if (draggingNewComponent) {
2912
+ if (appContext2.safariFallbackMode) {
2913
+ isEnabled = true;
2914
+ } else {
2915
+ isEnabled = hoveringOverArea;
2916
+ }
2917
+ } else {
2918
+ isEnabled = draggingOverArea && hoveringOverZone;
3342
2919
  }
3343
- const { componentType } = draggedItem.data;
2920
+ }
2921
+ if (isEnabled && userIsDragging && (allow || disallow)) {
2922
+ const [_, componentType] = draggedItem.draggableId.split("::");
3344
2923
  if (disallow) {
3345
2924
  const defaultedAllow = allow || [];
3346
2925
  const filteredDisallow = (disallow || []).filter(
3347
2926
  (item) => defaultedAllow.indexOf(item) === -1
3348
2927
  );
3349
2928
  if (filteredDisallow.indexOf(componentType) !== -1) {
3350
- return false;
2929
+ isEnabled = false;
3351
2930
  }
3352
2931
  } else if (allow) {
3353
2932
  if (allow.indexOf(componentType) === -1) {
3354
- return false;
2933
+ isEnabled = false;
3355
2934
  }
3356
2935
  }
3357
- return true;
3358
- }, [draggedItem]);
3359
- (0, import_react18.useEffect)(() => {
3360
- if (registerLocalZone) {
3361
- registerLocalZone(zoneCompound, isDroppableTarget());
3362
- }
3363
- }, [draggedItem, zoneCompound]);
3364
- const isRootZone = zoneCompound === rootDroppableId || zone === rootDroppableId || areaId === "root";
3365
- const hoveringOverArea = nextDeepestArea ? nextDeepestArea === areaId : isRootZone;
3366
- const userIsDragging = !!draggedItem;
3367
- let isEnabled = true;
3368
- if (draggedItem) {
3369
- isEnabled = deepestZone === zoneCompound;
3370
2936
  }
3371
- if (isEnabled) {
3372
- isEnabled = isDroppableTarget();
3373
- }
3374
- const preview = (0, import_react18.useContext)(previewContext);
3375
- const previewInZone = (preview == null ? void 0 : preview.zone) === zoneCompound;
3376
- const contentWithPreview = (0, import_react18.useMemo)(() => {
3377
- let contentWithPreview2 = preview ? content.filter((item) => item.props.id !== preview.props.id) : content;
3378
- if (previewInZone) {
3379
- contentWithPreview2 = content.filter(
3380
- (item) => item.props.id !== preview.props.id
3381
- );
3382
- if (preview.type === "insert") {
3383
- contentWithPreview2 = insert(contentWithPreview2, preview.index, {
3384
- type: "preview",
3385
- props: { id: preview.props.id }
3386
- });
3387
- } else {
3388
- contentWithPreview2 = insert(contentWithPreview2, preview.index, {
3389
- type: preview.componentType,
3390
- props: preview.props
3391
- });
3392
- }
3393
- }
3394
- return contentWithPreview2;
3395
- }, [preview, content]);
3396
- const isDropEnabled = isEnabled && (previewInZone ? contentWithPreview.length === 1 : contentWithPreview.length === 0);
3397
- const droppableConfig = {
3398
- id: zoneCompound,
3399
- collisionPriority: isEnabled ? depth : 0,
3400
- disabled: !isDropEnabled,
3401
- collisionDetector: pointerIntersection,
3402
- type: "dropzone",
3403
- data: {
3404
- areaId,
3405
- depth,
3406
- isDroppableTarget: isDroppableTarget(),
3407
- path
3408
- }
3409
- };
3410
- const { ref: dropRef } = useDroppableSafe(droppableConfig);
3411
2937
  const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
3412
- const isAreaSelected = selectedItem && areaId === selectedItem.props.id;
3413
- const [dragAxis, setDragAxis] = (0, import_react18.useState)(
3414
- collisionAxis || DEFAULT_DRAG_AXIS
3415
- );
3416
- const calculateDragAxis = (0, import_react18.useCallback)(() => {
3417
- if (ref.current) {
3418
- const computedStyle = window.getComputedStyle(ref.current);
3419
- if (computedStyle.display === "grid") {
3420
- setDragAxis(GRID_DRAG_AXIS);
3421
- } else if (computedStyle.display === "flex" && computedStyle.flexDirection === "row") {
3422
- setDragAxis(FLEX_ROW_DRAG_AXIS);
3423
- } else {
3424
- setDragAxis(DEFAULT_DRAG_AXIS);
3425
- }
3426
- }
3427
- }, [ref.current]);
3428
- (0, import_react18.useEffect)(calculateDragAxis, [appContext2.status, collisionAxis]);
3429
- (0, import_react18.useEffect)(() => {
3430
- const onViewportChange = () => {
3431
- calculateDragAxis();
3432
- };
3433
- window.addEventListener("viewportchange", onViewportChange);
3434
- return () => {
3435
- window.removeEventListener("viewportchange", onViewportChange);
3436
- };
3437
- }, []);
3438
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
2938
+ const isAreaSelected = selectedItem && zoneArea === selectedItem.props.id;
2939
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3439
2940
  "div",
3440
2941
  {
3441
- className: `${getClassName17({
2942
+ className: getClassName18({
3442
2943
  isRootZone,
3443
2944
  userIsDragging,
2945
+ draggingOverArea,
3444
2946
  hoveringOverArea,
3445
- isEnabled,
2947
+ draggingNewComponent,
2948
+ isDestination: draggedDestinationId === zoneCompound,
2949
+ isDisabled: !isEnabled,
3446
2950
  isAreaSelected,
3447
2951
  hasChildren: content.length > 0
3448
- })}${className ? ` ${className}` : ""}`,
3449
- ref: (node) => {
3450
- ref.current = node;
3451
- dropRef(node);
3452
- if (dragRef) dragRef(node);
3453
- },
3454
- style: __spreadProps(__spreadValues({}, style), {
3455
- "--min-empty-height": `${minEmptyHeight}px`
3456
2952
  }),
3457
- children: [
3458
- isRootZone && DEBUG3 && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
3459
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("p", { children: deepestZone || rootDroppableId }),
3460
- /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("p", { children: deepestArea || "No area" })
3461
- ] }),
3462
- contentWithPreview.map((item, i) => {
3463
- var _a, _b, _c, _d, _e;
3464
- const componentId = item.props.id;
3465
- const puckProps = {
3466
- renderDropZone: DropZone,
3467
- isEditing: true,
3468
- dragRef: null
3469
- };
3470
- const defaultedProps = __spreadProps(__spreadValues(__spreadValues({}, (_a = config.components[item.type]) == null ? void 0 : _a.defaultProps), item.props), {
3471
- puck: puckProps,
3472
- editMode: true
3473
- // DEPRECATED
3474
- });
3475
- const isSelected = (selectedItem == null ? void 0 : selectedItem.props.id) === componentId || false;
3476
- let Render2 = config.components[item.type] ? config.components[item.type].render : () => /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { style: { padding: 48, textAlign: "center" }, children: [
3477
- "No configuration for ",
3478
- item.type
3479
- ] });
3480
- const componentConfig = config.components[item.type];
3481
- let componentType = item.type;
3482
- let label = (_b = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _b : item.type.toString();
3483
- if (item.type === "preview") {
3484
- let Preview3 = function() {
3485
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DrawerItemInner, { name: label });
3486
- };
3487
- var Preview2 = Preview3;
3488
- componentType = preview.componentType;
3489
- label = (_d = (_c = config.components[componentType]) == null ? void 0 : _c.label) != null ? _d : preview.componentType;
3490
- Render2 = Preview3;
3491
- }
3492
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
3493
- DropZoneProvider,
3494
- {
3495
- value: __spreadProps(__spreadValues({}, ctx), { path: [...path, zoneCompound] }),
3496
- children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
3497
- DraggableComponent,
3498
- {
3499
- id: componentId,
3500
- componentType,
3501
- zoneCompound,
3502
- depth: depth + 1,
3503
- index: i,
3504
- isLoading: ((_e = appContext2.componentState[componentId]) == null ? void 0 : _e.loadingCount) > 0,
3505
- isSelected,
3506
- label,
3507
- isEnabled,
3508
- autoDragAxis: dragAxis,
3509
- userDragAxis: collisionAxis,
3510
- inDroppableZone: isDroppableTarget(),
3511
- children: (dragRef2) => (componentConfig == null ? void 0 : componentConfig.inline) ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
3512
- Render2,
3513
- __spreadProps(__spreadValues({}, defaultedProps), {
3514
- puck: __spreadProps(__spreadValues({}, defaultedProps.puck), {
3515
- dragRef: dragRef2
2953
+ onMouseUp: () => {
2954
+ setZoneWillDrag("");
2955
+ },
2956
+ children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
2957
+ Droppable,
2958
+ {
2959
+ droppableId: zoneCompound,
2960
+ direction: "vertical",
2961
+ isDropDisabled: !isEnabled,
2962
+ children: (provided, snapshot) => {
2963
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
2964
+ "div",
2965
+ __spreadProps(__spreadValues({}, (provided || { droppableProps: {} }).droppableProps), {
2966
+ className: getClassName18("content"),
2967
+ ref: provided == null ? void 0 : provided.innerRef,
2968
+ style,
2969
+ id: zoneCompound,
2970
+ onMouseOver: (e) => {
2971
+ e.stopPropagation();
2972
+ setHoveringArea(zoneArea);
2973
+ setHoveringZone(zoneCompound);
2974
+ },
2975
+ children: [
2976
+ content.map((item, i) => {
2977
+ var _a2, _b, _c;
2978
+ const componentId = item.props.id;
2979
+ const puckProps = {
2980
+ renderDropZone: DropZone,
2981
+ isEditing: true
2982
+ };
2983
+ const defaultedProps = __spreadProps(__spreadValues(__spreadValues({}, (_a2 = config.components[item.type]) == null ? void 0 : _a2.defaultProps), item.props), {
2984
+ puck: puckProps,
2985
+ editMode: true
2986
+ // DEPRECATED
2987
+ });
2988
+ const isSelected = (selectedItem == null ? void 0 : selectedItem.props.id) === componentId || false;
2989
+ const isDragging = ((draggedItem == null ? void 0 : draggedItem.draggableId) || "draggable-").split(
2990
+ "draggable-"
2991
+ )[1] === componentId;
2992
+ const containsZone = areasWithZones ? areasWithZones[componentId] : false;
2993
+ const Render2 = config.components[item.type] ? config.components[item.type].render : () => /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)("div", { style: { padding: 48, textAlign: "center" }, children: [
2994
+ "No configuration for ",
2995
+ item.type
2996
+ ] });
2997
+ const componentConfig = config.components[item.type];
2998
+ const label = (_b = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _b : item.type.toString();
2999
+ const canDrag = appContext2.getPermissions({
3000
+ item: getItem(
3001
+ { index: i, zone: zoneCompound },
3002
+ appContext2.state.data
3003
+ )
3004
+ }).drag;
3005
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(
3006
+ "div",
3007
+ {
3008
+ className: getClassName18("item"),
3009
+ style: { zIndex: isDragging ? 1 : void 0 },
3010
+ children: [
3011
+ /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3012
+ DropZoneProvider,
3013
+ {
3014
+ value: __spreadProps(__spreadValues({}, ctx), {
3015
+ areaId: componentId
3016
+ }),
3017
+ children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3018
+ DraggableComponent,
3019
+ {
3020
+ label,
3021
+ id: `draggable-${componentId}`,
3022
+ index: i,
3023
+ isSelected,
3024
+ isLocked: userIsDragging,
3025
+ forceHover: hoveringComponent === componentId && !userIsDragging,
3026
+ isDragDisabled: !canDrag,
3027
+ indicativeHover: userIsDragging && containsZone && hoveringArea === componentId,
3028
+ isLoading: ((_c = appContext2.componentState[componentId]) == null ? void 0 : _c.loadingCount) > 0,
3029
+ onMount: () => {
3030
+ ctx.registerPath({
3031
+ index: i,
3032
+ zone: zoneCompound
3033
+ });
3034
+ },
3035
+ onClick: (e) => {
3036
+ setItemSelector({
3037
+ index: i,
3038
+ zone: zoneCompound
3039
+ });
3040
+ e.stopPropagation();
3041
+ },
3042
+ onMouseDown: (e) => {
3043
+ e.stopPropagation();
3044
+ setZoneWillDrag(zone);
3045
+ },
3046
+ onMouseOver: (e) => {
3047
+ e.stopPropagation();
3048
+ if (containsZone) {
3049
+ setHoveringArea(componentId);
3050
+ } else {
3051
+ setHoveringArea(zoneArea);
3052
+ }
3053
+ setHoveringComponent(componentId);
3054
+ setHoveringZone(zoneCompound);
3055
+ },
3056
+ onMouseOut: () => {
3057
+ setHoveringArea(null);
3058
+ setHoveringZone(null);
3059
+ setHoveringComponent(null);
3060
+ },
3061
+ onDelete: (e) => {
3062
+ dispatch({
3063
+ type: "remove",
3064
+ index: i,
3065
+ zone: zoneCompound
3066
+ });
3067
+ setItemSelector(null);
3068
+ e.stopPropagation();
3069
+ },
3070
+ onDuplicate: (e) => {
3071
+ dispatch({
3072
+ type: "duplicate",
3073
+ sourceIndex: i,
3074
+ sourceZone: zoneCompound
3075
+ });
3076
+ setItemSelector({
3077
+ zone: zoneCompound,
3078
+ index: i + 1
3079
+ });
3080
+ e.stopPropagation();
3081
+ },
3082
+ style: {
3083
+ pointerEvents: userIsDragging && draggingNewComponent ? "all" : void 0
3084
+ },
3085
+ children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { className: getClassName18("renderWrapper"), children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(Render2, __spreadValues({}, defaultedProps)) })
3086
+ }
3087
+ )
3088
+ }
3089
+ ),
3090
+ userIsDragging && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3091
+ "div",
3092
+ {
3093
+ className: getClassName18("hitbox"),
3094
+ onMouseOver: (e) => {
3095
+ e.stopPropagation();
3096
+ setHoveringArea(zoneArea);
3097
+ setHoveringZone(zoneCompound);
3098
+ }
3099
+ }
3100
+ )
3101
+ ]
3102
+ },
3103
+ item.props.id
3104
+ );
3105
+ }),
3106
+ provided == null ? void 0 : provided.placeholder,
3107
+ (snapshot == null ? void 0 : snapshot.isDraggingOver) && /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3108
+ "div",
3109
+ {
3110
+ "data-puck-placeholder": true,
3111
+ style: __spreadProps(__spreadValues({}, placeholderStyle), {
3112
+ background: "var(--puck-color-azure-06)",
3113
+ opacity: 0.3,
3114
+ zIndex: 0
3516
3115
  })
3517
- })
3518
- ) : /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { ref: dragRef2, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Render2, __spreadValues({}, defaultedProps)) })
3519
- }
3520
- )
3521
- },
3522
- componentId
3523
- );
3524
- })
3525
- ]
3116
+ }
3117
+ )
3118
+ ]
3119
+ })
3120
+ );
3121
+ }
3122
+ }
3123
+ )
3526
3124
  }
3527
3125
  );
3528
3126
  }
3529
- function DropZoneRender({ className, style, zone }) {
3530
- const ctx = (0, import_react18.useContext)(dropZoneContext);
3127
+ function DropZoneRender({ zone }) {
3128
+ const ctx = (0, import_react20.useContext)(dropZoneContext);
3531
3129
  const { data, areaId = "root", config } = ctx || {};
3532
3130
  let zoneCompound = rootDroppableId;
3533
3131
  let content = (data == null ? void 0 : data.content) || [];
@@ -3538,23 +3136,17 @@ function DropZoneRender({ className, style, zone }) {
3538
3136
  zoneCompound = `${areaId}:${zone}`;
3539
3137
  content = setupZone(data, zoneCompound).zones[zoneCompound];
3540
3138
  }
3541
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className, style, children: content.map((item) => {
3139
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_jsx_runtime24.Fragment, { children: content.map((item) => {
3542
3140
  const Component = config.components[item.type];
3543
3141
  if (Component) {
3544
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
3142
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3545
3143
  DropZoneProvider,
3546
3144
  {
3547
- value: {
3548
- data,
3549
- config,
3550
- areaId: item.props.id,
3551
- depth: 1,
3552
- path: []
3553
- },
3554
- children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
3145
+ value: { data, config, areaId: item.props.id },
3146
+ children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
3555
3147
  Component.render,
3556
3148
  __spreadProps(__spreadValues({}, item.props), {
3557
- puck: { renderDropZone: DropZoneRender }
3149
+ puck: { renderDropZone: DropZone }
3558
3150
  })
3559
3151
  )
3560
3152
  },
@@ -3565,224 +3157,192 @@ function DropZoneRender({ className, style, zone }) {
3565
3157
  }) });
3566
3158
  }
3567
3159
  function DropZone(props) {
3568
- const ctx = (0, import_react18.useContext)(dropZoneContext);
3160
+ const ctx = (0, import_react20.useContext)(dropZoneContext);
3569
3161
  if ((ctx == null ? void 0 : ctx.mode) === "edit") {
3570
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_jsx_runtime23.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DropZoneEdit, __spreadValues({}, props)) });
3162
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(DropZoneEdit, __spreadValues({}, props));
3571
3163
  }
3572
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(import_jsx_runtime23.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DropZoneRender, __spreadValues({}, props)) });
3164
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(DropZoneRender, __spreadValues({}, props));
3573
3165
  }
3574
3166
 
3575
- // lib/get-zone-id.ts
3167
+ // components/Puck/index.tsx
3576
3168
  init_react_import();
3577
- var getZoneId = (zoneCompound) => {
3578
- if (!zoneCompound) {
3579
- return [];
3580
- }
3581
- if (zoneCompound && zoneCompound.indexOf(":") > -1) {
3582
- return zoneCompound.split(":");
3583
- }
3584
- return [rootDroppableId, zoneCompound];
3585
- };
3169
+ var import_react35 = require("react");
3586
3170
 
3587
- // components/DragDropContext/NestedDroppablePlugin.ts
3171
+ // lib/use-placeholder-style.ts
3588
3172
  init_react_import();
3589
- var import_abstract9 = require("@dnd-kit/abstract");
3590
- var import_state = require("@dnd-kit/state");
3173
+ var import_react21 = require("react");
3591
3174
 
3592
- // lib/throttle.ts
3175
+ // lib/get-frame.ts
3593
3176
  init_react_import();
3594
- function timeout2(callback, duration) {
3595
- const id = setTimeout(callback, duration);
3596
- return () => clearTimeout(id);
3597
- }
3598
- function throttle(func, limit) {
3599
- const time = () => performance.now();
3600
- let cancel;
3601
- let lastRan = 0;
3602
- return function(...args) {
3603
- const now = time();
3604
- const context = this;
3605
- if (now - lastRan >= limit) {
3606
- func.apply(context, args);
3607
- lastRan = now;
3608
- } else {
3609
- cancel == null ? void 0 : cancel();
3610
- cancel = timeout2(() => {
3611
- func.apply(context, args);
3612
- lastRan = time();
3613
- }, limit - (now - lastRan));
3614
- }
3615
- };
3616
- }
3177
+ var getFrame = () => {
3178
+ let frame = document.querySelector("#preview-frame");
3179
+ if ((frame == null ? void 0 : frame.tagName) === "IFRAME") {
3180
+ frame = frame.contentDocument;
3181
+ }
3182
+ return frame;
3183
+ };
3617
3184
 
3618
- // components/DragDropContext/NestedDroppablePlugin.ts
3619
- function isPositionInsideRect(position, rect) {
3620
- return position.x >= rect.left && position.x <= rect.right && position.y >= rect.top && position.y <= rect.bottom;
3621
- }
3622
- var BUFFER_ZONE = 8;
3623
- var REFRESH_ON_MOVE = true;
3624
- var depthSort = (candidates) => {
3625
- return candidates.sort((a, b) => {
3626
- const aData = a.data;
3627
- const bData = b.data;
3628
- if (aData.depth > bData.depth) {
3629
- return 1;
3630
- }
3631
- if (bData.depth > aData.depth) {
3632
- return -1;
3185
+ // lib/use-placeholder-style.ts
3186
+ var usePlaceholderStyle = () => {
3187
+ const queryAttr = "data-rfd-drag-handle-draggable-id";
3188
+ const [placeholderStyle, setPlaceholderStyle] = (0, import_react21.useState)();
3189
+ const onDragStartOrUpdate = (draggedItem) => {
3190
+ var _a;
3191
+ const draggableId = draggedItem.draggableId;
3192
+ const destinationIndex = (draggedItem.destination || draggedItem.source).index;
3193
+ const droppableId = (draggedItem.destination || draggedItem.source).droppableId;
3194
+ const domQuery = `[${queryAttr}='${draggableId}']`;
3195
+ const frame = getFrame();
3196
+ const draggedDOM = document.querySelector(domQuery) || (frame == null ? void 0 : frame.querySelector(domQuery));
3197
+ if (!draggedDOM) {
3198
+ return;
3633
3199
  }
3634
- return 0;
3635
- });
3636
- };
3637
- var getZoneId2 = (candidate) => {
3638
- let id = candidate == null ? void 0 : candidate.id;
3639
- if (!candidate) return null;
3640
- if (candidate.type === "component") {
3641
- const data = candidate.data;
3642
- if (data.containsActiveZone) {
3643
- id = null;
3644
- } else {
3645
- id = data.zone;
3200
+ const targetListElement = frame == null ? void 0 : frame.querySelector(
3201
+ `[data-rfd-droppable-id='${droppableId}']`
3202
+ );
3203
+ const { clientHeight } = draggedDOM;
3204
+ if (!targetListElement) {
3205
+ return;
3646
3206
  }
3647
- } else if (candidate.type === "void") {
3648
- return "void";
3649
- }
3650
- return id;
3651
- };
3652
- var getAreaId = (candidate) => {
3653
- if (candidate.type === "component") {
3654
- const data = candidate.data;
3655
- if (data.containsActiveZone) {
3656
- return candidate.id;
3207
+ let clientY = 0;
3208
+ const isSameDroppable = draggedItem.source.droppableId === ((_a = draggedItem.destination) == null ? void 0 : _a.droppableId);
3209
+ if (destinationIndex > 0) {
3210
+ const end = destinationIndex > draggedItem.source.index && isSameDroppable ? destinationIndex + 1 : destinationIndex;
3211
+ const children = Array.from(targetListElement.children).filter(
3212
+ (item) => item !== draggedDOM && item.getAttributeNames().indexOf("data-puck-placeholder") === -1 && item.getAttributeNames().indexOf("data-rfd-placeholder-context-id") === -1
3213
+ ).slice(0, end);
3214
+ clientY = children.reduce(
3215
+ (total, item) => total + item.clientHeight + parseInt(window.getComputedStyle(item).marginTop.replace("px", "")) + parseInt(
3216
+ window.getComputedStyle(item).marginBottom.replace("px", "")
3217
+ ),
3218
+ 0
3219
+ );
3657
3220
  }
3658
- }
3659
- return null;
3660
- };
3661
- var getDeepestId = (candidates, idFn) => {
3662
- let id = null;
3663
- for (let i = 0; i < candidates.length; i++) {
3664
- const candidate = candidates[i];
3665
- id = idFn(candidate);
3666
- if (id) break;
3667
- }
3668
- return id;
3669
- };
3670
- var expandHitBox = (rect) => {
3671
- return {
3672
- bottom: rect.bottom + BUFFER_ZONE,
3673
- top: rect.top - BUFFER_ZONE,
3674
- width: rect.width + BUFFER_ZONE * 2,
3675
- height: rect.height + BUFFER_ZONE * 2,
3676
- left: rect.left - BUFFER_ZONE,
3677
- right: rect.right + BUFFER_ZONE
3221
+ setPlaceholderStyle({
3222
+ position: "absolute",
3223
+ top: clientY,
3224
+ left: 0,
3225
+ height: clientHeight,
3226
+ width: "100%"
3227
+ });
3678
3228
  };
3229
+ return { onDragStartOrUpdate, placeholderStyle };
3679
3230
  };
3680
- var getPointerCollisions = (position, manager) => {
3681
- var _a;
3682
- const candidates = [];
3683
- const source = (_a = manager.dragOperation) == null ? void 0 : _a.source;
3684
- const sourceData = source ? source.data : void 0;
3685
- for (const droppable of manager.registry.droppables.value) {
3686
- if (droppable.shape) {
3687
- let rect = droppable.shape.boundingRectangle;
3688
- const isNotSourceZone = droppable.id !== ((sourceData == null ? void 0 : sourceData.zone) || (source == null ? void 0 : source.id));
3689
- const isNotTargetZone = droppable.id !== ((sourceData == null ? void 0 : sourceData.zone) || (source == null ? void 0 : source.id));
3690
- if (droppable.type === "dropzone" && isNotSourceZone && isNotTargetZone) {
3691
- rect = expandHitBox(rect);
3692
- }
3693
- if (isPositionInsideRect(position, rect)) {
3694
- candidates.push(droppable);
3695
- }
3696
- }
3697
- }
3698
- return candidates;
3699
- };
3700
- var findDeepestCandidate = (position, manager) => {
3701
- const candidates = getPointerCollisions(position, manager);
3702
- if (candidates.length > 0) {
3703
- const sortedCandidates = depthSort(candidates);
3704
- const draggable = manager.dragOperation.source;
3705
- const draggedCandidateIndex = sortedCandidates.findIndex(
3706
- (candidate) => candidate.id === (draggable == null ? void 0 : draggable.id)
3231
+
3232
+ // components/SidebarSection/index.tsx
3233
+ init_react_import();
3234
+
3235
+ // css-module:/home/runner/work/puck/puck/packages/core/components/SidebarSection/styles.module.css#css-module
3236
+ init_react_import();
3237
+ var styles_module_default13 = { "SidebarSection": "_SidebarSection_125qe_1", "SidebarSection-title": "_SidebarSection-title_125qe_12", "SidebarSection--noBorderTop": "_SidebarSection--noBorderTop_125qe_20", "SidebarSection-content": "_SidebarSection-content_125qe_24", "SidebarSection--noPadding": "_SidebarSection--noPadding_125qe_28", "SidebarSection-breadcrumbLabel": "_SidebarSection-breadcrumbLabel_125qe_41", "SidebarSection-breadcrumbs": "_SidebarSection-breadcrumbs_125qe_70", "SidebarSection-breadcrumb": "_SidebarSection-breadcrumb_125qe_41", "SidebarSection-heading": "_SidebarSection-heading_125qe_82", "SidebarSection-loadingOverlay": "_SidebarSection-loadingOverlay_125qe_86" };
3238
+
3239
+ // lib/use-breadcrumbs.ts
3240
+ init_react_import();
3241
+ var import_react22 = require("react");
3242
+ var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
3243
+ const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
3244
+ const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
3245
+ if (!id) {
3246
+ return [];
3247
+ }
3248
+ return currentPathData == null ? void 0 : currentPathData.path.reduce((acc, zoneCompound) => {
3249
+ const [area] = getZoneId(zoneCompound);
3250
+ if (area === rootDroppableId) {
3251
+ return [
3252
+ {
3253
+ label: "Page",
3254
+ selector: null
3255
+ }
3256
+ ];
3257
+ }
3258
+ const parentZoneCompound = acc.length > 0 ? acc[acc.length - 1].zoneCompound : rootDroppableId;
3259
+ let parentZone = data.content;
3260
+ if (parentZoneCompound && parentZoneCompound !== rootDroppableId) {
3261
+ parentZone = data.zones[parentZoneCompound];
3262
+ }
3263
+ if (!parentZone) {
3264
+ return acc;
3265
+ }
3266
+ const itemIndex = parentZone.findIndex(
3267
+ (queryItem) => queryItem.props.id === area
3707
3268
  );
3708
- const draggedCandidateId = draggable == null ? void 0 : draggable.id;
3709
- let filteredCandidates = [...sortedCandidates];
3710
- if (draggedCandidateId && draggedCandidateIndex > -1) {
3711
- filteredCandidates.splice(draggedCandidateIndex, 1);
3269
+ const item = parentZone[itemIndex];
3270
+ if (!item) {
3271
+ return acc;
3712
3272
  }
3713
- filteredCandidates = filteredCandidates.filter((candidate) => {
3714
- const candidateData = candidate.data;
3715
- if (draggedCandidateId && draggedCandidateIndex > -1) {
3716
- if (candidateData.path.indexOf(draggedCandidateId) > -1) {
3717
- return false;
3718
- }
3719
- }
3720
- if (candidate.type === "dropzone") {
3721
- const candidateData2 = candidate.data;
3722
- if (!candidateData2.isDroppableTarget) {
3723
- return false;
3724
- }
3725
- if (candidateData2.areaId === draggedCandidateId) {
3726
- return false;
3727
- }
3728
- } else if (candidate.type === "component") {
3729
- const candidateData2 = candidate.data;
3730
- if (!candidateData2.inDroppableZone) {
3731
- return false;
3732
- }
3273
+ return [
3274
+ ...acc,
3275
+ {
3276
+ label: item.type.toString(),
3277
+ selector: {
3278
+ index: itemIndex,
3279
+ zone: parentZoneCompound
3280
+ },
3281
+ zoneCompound
3733
3282
  }
3734
- return true;
3735
- });
3736
- filteredCandidates.reverse();
3737
- const zone = getZoneId2(filteredCandidates[0]);
3738
- const area = getDeepestId(filteredCandidates, getAreaId);
3739
- return { zone, area };
3740
- }
3741
- return {
3742
- zone: "default-zone",
3743
- area: null
3744
- };
3283
+ ];
3284
+ }, []);
3745
3285
  };
3746
- var createNestedDroppablePlugin = ({
3747
- onChange
3748
- }) => class NestedDroppablePlugin extends import_abstract9.Plugin {
3749
- constructor(manager, options) {
3750
- super(manager);
3751
- if (typeof window === "undefined") {
3752
- return;
3286
+ var useBreadcrumbs = (renderCount) => {
3287
+ const {
3288
+ state: { data },
3289
+ selectedItem
3290
+ } = useAppContext();
3291
+ const dzContext = (0, import_react22.useContext)(dropZoneContext);
3292
+ return (0, import_react22.useMemo)(() => {
3293
+ const breadcrumbs = convertPathDataToBreadcrumbs(
3294
+ selectedItem,
3295
+ dzContext == null ? void 0 : dzContext.pathData,
3296
+ data
3297
+ );
3298
+ if (renderCount) {
3299
+ return breadcrumbs.slice(breadcrumbs.length - renderCount);
3753
3300
  }
3754
- const cleanupEffect = (0, import_state.effects)(() => {
3755
- const handleMove = (position) => {
3756
- if (REFRESH_ON_MOVE) {
3757
- for (const droppable of manager.registry.droppables.value) {
3758
- droppable.refreshShape();
3759
- }
3760
- }
3761
- onChange(findDeepestCandidate(position, manager), manager);
3762
- };
3763
- const handleMoveThrottled = throttle(handleMove, 50);
3764
- const handlePointerMove = (event) => {
3765
- handleMoveThrottled({
3766
- x: event.clientX,
3767
- y: event.clientY
3768
- });
3769
- };
3770
- document.body.addEventListener("pointermove", handlePointerMove, {
3771
- capture: true
3772
- // dndkit's PointerSensor prevents propagation during drag
3773
- });
3774
- this.destroy = () => {
3775
- document.body.removeEventListener("pointermove", handlePointerMove, {
3776
- capture: true
3777
- });
3778
- cleanupEffect();
3779
- };
3780
- });
3781
- }
3301
+ return breadcrumbs;
3302
+ }, [selectedItem, dzContext == null ? void 0 : dzContext.pathData, renderCount]);
3782
3303
  };
3783
3304
 
3784
- // lib/insert-component.ts
3785
- init_react_import();
3305
+ // components/SidebarSection/index.tsx
3306
+ var import_jsx_runtime25 = require("react/jsx-runtime");
3307
+ var getClassName19 = get_class_name_factory_default("SidebarSection", styles_module_default13);
3308
+ var SidebarSection = ({
3309
+ children,
3310
+ title,
3311
+ background,
3312
+ showBreadcrumbs,
3313
+ noBorderTop,
3314
+ noPadding,
3315
+ isLoading
3316
+ }) => {
3317
+ const { setUi } = useAppContext();
3318
+ const breadcrumbs = useBreadcrumbs(1);
3319
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(
3320
+ "div",
3321
+ {
3322
+ className: getClassName19({ noBorderTop, noPadding }),
3323
+ style: { background },
3324
+ children: [
3325
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: getClassName19("title"), children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassName19("breadcrumbs"), children: [
3326
+ showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassName19("breadcrumb"), children: [
3327
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
3328
+ "button",
3329
+ {
3330
+ type: "button",
3331
+ className: getClassName19("breadcrumbLabel"),
3332
+ onClick: () => setUi({ itemSelector: breadcrumb.selector }),
3333
+ children: breadcrumb.label
3334
+ }
3335
+ ),
3336
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(ChevronRight, { size: 16 })
3337
+ ] }, i)) : null,
3338
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: getClassName19("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Heading, { rank: "2", size: "xs", children: title }) })
3339
+ ] }) }),
3340
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: getClassName19("content"), children }),
3341
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: getClassName19("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(Loader, { size: 32 }) })
3342
+ ]
3343
+ }
3344
+ );
3345
+ };
3786
3346
 
3787
3347
  // reducer/index.ts
3788
3348
  init_react_import();
@@ -3790,6 +3350,14 @@ init_react_import();
3790
3350
  // reducer/data.ts
3791
3351
  init_react_import();
3792
3352
 
3353
+ // lib/insert.ts
3354
+ init_react_import();
3355
+ var insert = (list, index, item) => {
3356
+ const result = Array.from(list);
3357
+ result.splice(index, 0, item);
3358
+ return result;
3359
+ };
3360
+
3793
3361
  // lib/remove.ts
3794
3362
  init_react_import();
3795
3363
  var remove = (list, index) => {
@@ -3917,27 +3485,6 @@ function insertAction(data, action, config) {
3917
3485
  })
3918
3486
  });
3919
3487
  }
3920
- var reorderAction = (data, action) => {
3921
- if (action.destinationZone === rootDroppableId) {
3922
- return __spreadProps(__spreadValues({}, data), {
3923
- content: reorder(
3924
- data.content,
3925
- action.sourceIndex,
3926
- action.destinationIndex
3927
- )
3928
- });
3929
- }
3930
- const newData = setupZone(data, action.destinationZone);
3931
- return __spreadProps(__spreadValues({}, data), {
3932
- zones: __spreadProps(__spreadValues({}, newData.zones), {
3933
- [action.destinationZone]: reorder(
3934
- newData.zones[action.destinationZone],
3935
- action.sourceIndex,
3936
- action.destinationIndex
3937
- )
3938
- })
3939
- });
3940
- };
3941
3488
  function reduceData(data, action, config) {
3942
3489
  if (action.type === "insert") {
3943
3490
  return insertAction(data, action, config);
@@ -3973,12 +3520,27 @@ function reduceData(data, action, config) {
3973
3520
  });
3974
3521
  }
3975
3522
  if (action.type === "reorder") {
3976
- return reorderAction(data, action);
3523
+ if (action.destinationZone === rootDroppableId) {
3524
+ return __spreadProps(__spreadValues({}, data), {
3525
+ content: reorder(
3526
+ data.content,
3527
+ action.sourceIndex,
3528
+ action.destinationIndex
3529
+ )
3530
+ });
3531
+ }
3532
+ const newData = setupZone(data, action.destinationZone);
3533
+ return __spreadProps(__spreadValues({}, data), {
3534
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
3535
+ [action.destinationZone]: reorder(
3536
+ newData.zones[action.destinationZone],
3537
+ action.sourceIndex,
3538
+ action.destinationIndex
3539
+ )
3540
+ })
3541
+ });
3977
3542
  }
3978
3543
  if (action.type === "move") {
3979
- if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
3980
- return data;
3981
- }
3982
3544
  const newData = setupZone(
3983
3545
  setupZone(data, action.sourceZone),
3984
3546
  action.destinationZone
@@ -3987,9 +3549,6 @@ function reduceData(data, action, config) {
3987
3549
  { zone: action.sourceZone, index: action.sourceIndex },
3988
3550
  newData
3989
3551
  );
3990
- if (action.sourceZone === action.destinationZone) {
3991
- return reorderAction(data, __spreadProps(__spreadValues({}, action), { type: "reorder" }));
3992
- }
3993
3552
  if (action.sourceZone === rootDroppableId) {
3994
3553
  return __spreadProps(__spreadValues({}, newData), {
3995
3554
  content: remove(newData.content, action.sourceIndex),
@@ -4086,11 +3645,6 @@ var reduceUi = (ui, action) => {
4086
3645
  }
4087
3646
  return __spreadValues(__spreadValues({}, ui), action.ui(ui));
4088
3647
  }
4089
- if (action.type === "duplicate") {
4090
- return __spreadProps(__spreadValues({}, ui), {
4091
- itemSelector: { index: action.sourceIndex + 1, zone: action.sourceZone }
4092
- });
4093
- }
4094
3648
  return ui;
4095
3649
  };
4096
3650
 
@@ -4127,851 +3681,18 @@ function createReducer({
4127
3681
  onAction
4128
3682
  }) {
4129
3683
  return storeInterceptor(
4130
- (state, action) => {
4131
- const data = reduceData(state.data, action, config);
4132
- const ui = reduceUi(state.ui, action);
4133
- if (action.type === "set") {
4134
- return setAction(state, action);
4135
- }
4136
- return { data, ui };
4137
- },
4138
- record,
4139
- onAction
4140
- );
4141
- }
4142
-
4143
- // lib/insert-component.ts
4144
- var insertComponent = (componentType, zone, index, {
4145
- config,
4146
- dispatch,
4147
- resolveData,
4148
- state
4149
- }) => {
4150
- const id = generateId(componentType);
4151
- const insertActionData = {
4152
- type: "insert",
4153
- componentType,
4154
- destinationIndex: index,
4155
- destinationZone: zone,
4156
- id
4157
- };
4158
- const insertedData = insertAction(state.data, insertActionData, config);
4159
- dispatch(__spreadProps(__spreadValues({}, insertActionData), {
4160
- // Dispatch insert rather set, as user's may rely on this via onAction
4161
- // We must always record history here so the insert is added to user history
4162
- // If the user has defined a resolveData method, they will end up with 2 history
4163
- // entries on insert - one for the initial insert, and one when the data resolves
4164
- recordHistory: true
4165
- }));
4166
- const itemSelector = {
4167
- index,
4168
- zone
4169
- };
4170
- dispatch({ type: "setUi", ui: { itemSelector } });
4171
- resolveData({
4172
- data: insertedData,
4173
- ui: __spreadProps(__spreadValues({}, state.ui), { itemSelector })
4174
- });
4175
- };
4176
-
4177
- // components/DragDropContext/index.tsx
4178
- var import_use_debounce2 = require("use-debounce");
4179
- var import_utilities2 = require("@dnd-kit/dom/utilities");
4180
-
4181
- // components/DragDropContext/PointerSensor.ts
4182
- init_react_import();
4183
- var import_state3 = require("@dnd-kit/state");
4184
- var import_abstract10 = require("@dnd-kit/abstract");
4185
- var import_geometry8 = require("@dnd-kit/geometry");
4186
- var import_utilities = require("@dnd-kit/dom/utilities");
4187
- var _clearTimeout;
4188
- var _PointerSensor = class _PointerSensor extends import_abstract10.Sensor {
4189
- constructor(manager, options) {
4190
- super(manager);
4191
- this.manager = manager;
4192
- this.options = options;
4193
- this.listeners = new import_utilities.Listeners();
4194
- this.cleanup = /* @__PURE__ */ new Set();
4195
- this.source = void 0;
4196
- __privateAdd(this, _clearTimeout);
4197
- this.handleCancel = this.handleCancel.bind(this);
4198
- this.handlePointerUp = this.handlePointerUp.bind(this);
4199
- this.handleKeyDown = this.handleKeyDown.bind(this);
4200
- (0, import_state3.effect)(() => {
4201
- const unbindGlobal = this.bindGlobal(options != null ? options : {});
4202
- return () => {
4203
- unbindGlobal();
4204
- };
4205
- });
4206
- }
4207
- bind(source, options = this.options) {
4208
- const unbind = (0, import_state3.effect)(() => {
4209
- var _a;
4210
- const target = (_a = source.handle) != null ? _a : source.element;
4211
- const listener = (event) => {
4212
- if ((0, import_utilities.isPointerEvent)(event)) {
4213
- this.handlePointerDown(event, source, options);
4214
- }
4215
- };
4216
- if (target) {
4217
- patchWindow(target.ownerDocument.defaultView);
4218
- target.addEventListener("pointerdown", listener);
4219
- return () => {
4220
- target.removeEventListener("pointerdown", listener);
4221
- };
4222
- }
4223
- });
4224
- return unbind;
4225
- }
4226
- bindGlobal(options) {
4227
- const documents = /* @__PURE__ */ new Set();
4228
- for (const draggable of this.manager.registry.draggables.value) {
4229
- if (draggable.element) {
4230
- documents.add((0, import_utilities.getDocument)(draggable.element));
4231
- }
4232
- }
4233
- for (const droppable of this.manager.registry.droppables.value) {
4234
- if (droppable.element) {
4235
- documents.add((0, import_utilities.getDocument)(droppable.element));
4236
- }
4237
- }
4238
- const unbindFns = Array.from(documents).map(
4239
- (doc) => this.listeners.bind(doc, [
4240
- {
4241
- type: "pointermove",
4242
- listener: (event) => this.handlePointerMove(event, doc, options)
4243
- },
4244
- {
4245
- type: "pointerup",
4246
- listener: this.handlePointerUp,
4247
- options: {
4248
- capture: true
4249
- }
4250
- },
4251
- {
4252
- // Cancel activation if there is a competing Drag and Drop interaction
4253
- type: "dragstart",
4254
- listener: this.handleDragStart
4255
- }
4256
- ])
4257
- );
4258
- return () => {
4259
- unbindFns.forEach((unbind) => unbind());
4260
- };
4261
- }
4262
- handlePointerDown(event, source, options = {}) {
4263
- if (this.disabled || !event.isPrimary || event.button !== 0 || !(0, import_utilities.isElement)(event.target) || source.disabled) {
4264
- return;
4265
- }
4266
- const offset = (0, import_utilities.getFrameTransform)(source.element);
4267
- this.initialCoordinates = {
4268
- x: event.clientX * offset.scaleX + offset.x,
4269
- y: event.clientY * offset.scaleY + offset.y
4270
- };
4271
- this.source = source;
4272
- const { activationConstraints } = options;
4273
- const constraints = typeof activationConstraints === "function" ? activationConstraints(event, source) : activationConstraints;
4274
- event.stopImmediatePropagation();
4275
- if (!(constraints == null ? void 0 : constraints.delay) && !(constraints == null ? void 0 : constraints.distance)) {
4276
- this.handleStart(source, event);
4277
- } else {
4278
- const { delay } = constraints;
4279
- if (delay) {
4280
- const timeout3 = setTimeout(
4281
- () => this.handleStart(source, event),
4282
- delay.value
4283
- );
4284
- __privateSet(this, _clearTimeout, () => {
4285
- clearTimeout(timeout3);
4286
- __privateSet(this, _clearTimeout, void 0);
4287
- });
4288
- }
4289
- }
4290
- const cleanup = () => {
4291
- var _a;
4292
- (_a = __privateGet(this, _clearTimeout)) == null ? void 0 : _a.call(this);
4293
- this.initialCoordinates = void 0;
4294
- this.source = void 0;
4295
- };
4296
- this.cleanup.add(cleanup);
4297
- }
4298
- handlePointerMove(event, doc, options) {
4299
- if (!this.source) {
4300
- return;
4301
- }
4302
- const ownerDocument = this.source.element && (0, import_utilities.getDocument)(this.source.element);
4303
- if (doc !== ownerDocument) {
4304
- return;
4305
- }
4306
- const coordinates = {
4307
- x: event.clientX,
4308
- y: event.clientY
4309
- };
4310
- const offset = (0, import_utilities.getFrameTransform)(this.source.element);
4311
- coordinates.x = coordinates.x * offset.scaleX + offset.x;
4312
- coordinates.y = coordinates.y * offset.scaleY + offset.y;
4313
- if (this.manager.dragOperation.status.dragging) {
4314
- event.preventDefault();
4315
- event.stopPropagation();
4316
- this.manager.actions.move({ to: coordinates });
4317
- return;
4318
- }
4319
- if (!this.initialCoordinates) {
4320
- return;
4321
- }
4322
- const delta = {
4323
- x: coordinates.x - this.initialCoordinates.x,
4324
- y: coordinates.y - this.initialCoordinates.y
4325
- };
4326
- const { activationConstraints } = options;
4327
- const constraints = typeof activationConstraints === "function" ? activationConstraints(event, this.source) : activationConstraints;
4328
- const { distance, delay } = constraints != null ? constraints : {};
4329
- if (distance) {
4330
- if (distance.tolerance != null && (0, import_geometry8.exceedsDistance)(delta, distance.tolerance)) {
4331
- return this.handleCancel();
4332
- }
4333
- if ((0, import_geometry8.exceedsDistance)(delta, distance.value)) {
4334
- return this.handleStart(this.source, event);
4335
- }
4336
- }
4337
- if (delay) {
4338
- if ((0, import_geometry8.exceedsDistance)(delta, delay.tolerance)) {
4339
- return this.handleCancel();
4340
- }
4341
- }
4342
- }
4343
- handlePointerUp(event) {
4344
- event.preventDefault();
4345
- event.stopPropagation();
4346
- const { status } = this.manager.dragOperation;
4347
- if (!status.idle) {
4348
- const canceled = !status.initialized;
4349
- this.manager.actions.stop({ canceled });
4350
- }
4351
- this.cleanup.forEach((cleanup) => cleanup());
4352
- this.cleanup.clear();
4353
- }
4354
- handleKeyDown(event) {
4355
- if (event.key === "Escape") {
4356
- event.preventDefault();
4357
- this.handleCancel();
4358
- }
4359
- }
4360
- handleStart(source, event) {
4361
- var _a;
4362
- const { manager, initialCoordinates } = this;
4363
- (_a = __privateGet(this, _clearTimeout)) == null ? void 0 : _a.call(this);
4364
- if (!initialCoordinates || manager.dragOperation.status.initialized) {
4365
- return;
4366
- }
4367
- if (event.defaultPrevented) {
4368
- return;
4369
- }
4370
- event.preventDefault();
4371
- (0, import_state3.batch)(() => {
4372
- manager.actions.setDragSource(source.id);
4373
- manager.actions.start({ coordinates: initialCoordinates, event });
4374
- });
4375
- const ownerDocument = (0, import_utilities.getDocument)(event.target);
4376
- const unbind = this.listeners.bind(ownerDocument, [
4377
- {
4378
- // Prevent scrolling on touch devices
4379
- type: "touchmove",
4380
- listener: preventDefault,
4381
- options: {
4382
- passive: false
4383
- }
4384
- },
4385
- {
4386
- // Prevent click events
4387
- type: "click",
4388
- listener: preventDefault
4389
- },
4390
- {
4391
- type: "keydown",
4392
- listener: this.handleKeyDown
4393
- }
4394
- ]);
4395
- ownerDocument.body.setPointerCapture(event.pointerId);
4396
- this.cleanup.add(unbind);
4397
- }
4398
- handleDragStart(event) {
4399
- const { target } = event;
4400
- if (!(0, import_utilities.isElement)(target)) {
4401
- return;
4402
- }
4403
- const isNativeDraggable = (0, import_utilities.isHTMLElement)(target) && target.draggable && target.getAttribute("draggable") === "true";
4404
- if (isNativeDraggable) {
4405
- this.handleCancel();
4406
- } else {
4407
- preventDefault(event);
4408
- }
4409
- }
4410
- handleCancel() {
4411
- const { dragOperation } = this.manager;
4412
- if (dragOperation.status.initialized) {
4413
- this.manager.actions.stop({ canceled: true });
4414
- }
4415
- this.cleanup.forEach((cleanup) => cleanup());
4416
- this.cleanup.clear();
4417
- }
4418
- destroy() {
4419
- this.listeners.clear();
4420
- }
4421
- };
4422
- _clearTimeout = new WeakMap();
4423
- _PointerSensor.configure = (0, import_abstract10.configurator)(_PointerSensor);
4424
- var PointerSensor = _PointerSensor;
4425
- function preventDefault(event) {
4426
- event.preventDefault();
4427
- }
4428
- function noop() {
4429
- }
4430
- var windows = /* @__PURE__ */ new WeakSet();
4431
- function patchWindow(window2) {
4432
- if (!window2 || windows.has(window2)) {
4433
- return;
4434
- }
4435
- window2.addEventListener("touchmove", noop, {
4436
- capture: false,
4437
- passive: false
4438
- });
4439
- windows.add(window2);
4440
- }
4441
-
4442
- // components/DragDropContext/index.tsx
4443
- var import_jsx_runtime24 = require("react/jsx-runtime");
4444
- var dragListenerContext = (0, import_react20.createContext)({
4445
- dragListeners: {}
4446
- });
4447
- function useDragListener(type, fn, deps = []) {
4448
- const { setDragListeners } = (0, import_react20.useContext)(dragListenerContext);
4449
- (0, import_react20.useEffect)(() => {
4450
- if (setDragListeners) {
4451
- setDragListeners((old) => __spreadProps(__spreadValues({}, old), {
4452
- [type]: [...old[type] || [], fn]
4453
- }));
4454
- }
4455
- }, deps);
4456
- }
4457
- var previewContext = (0, import_react20.createContext)(null);
4458
- var AREA_CHANGE_DEBOUNCE_MS = 100;
4459
- var DragDropContextClient = ({ children }) => {
4460
- const { state, config, dispatch, resolveData } = useAppContext();
4461
- const [preview, setPreview] = (0, import_react20.useState)(null);
4462
- const previewRef = (0, import_react20.useRef)(null);
4463
- const { data } = state;
4464
- const [deepest, setDeepest] = (0, import_react20.useState)(null);
4465
- const [nextDeepest, setNextDeepest] = (0, import_react20.useState)(null);
4466
- const deepestRef = (0, import_react20.useRef)(deepest);
4467
- const dbDeepestRef = (0, import_react20.useRef)(deepest);
4468
- const setDeepestDb = (0, import_use_debounce2.useDebouncedCallback)((params) => {
4469
- setDeepest(params);
4470
- dbDeepestRef.current = params;
4471
- }, AREA_CHANGE_DEBOUNCE_MS);
4472
- const setDeepestDbMaybe = (0, import_react20.useCallback)(
4473
- (params) => {
4474
- var _a, _b;
4475
- if (deepestRef.current === null || ((_a = deepestRef.current) == null ? void 0 : _a.zone) === "void" || params.zone && params.area && ((_b = dbDeepestRef.current) == null ? void 0 : _b.area) === params.area) {
4476
- setDeepest(params);
4477
- } else {
4478
- setDeepestDb(params);
4479
- }
4480
- if (!dbDeepestRef.current) {
4481
- dbDeepestRef.current = params;
4482
- }
4483
- },
4484
- [deepest]
4485
- );
4486
- const [plugins] = (0, import_react20.useState)(() => [
4487
- ...import_dom.defaultPreset.plugins,
4488
- createNestedDroppablePlugin({
4489
- onChange: (params, manager) => {
4490
- var _a, _b, _c;
4491
- const paramsChanged = !deepestRef.current || params.area !== ((_a = deepestRef.current) == null ? void 0 : _a.area) || params.zone !== ((_b = deepestRef.current) == null ? void 0 : _b.zone);
4492
- if (paramsChanged) {
4493
- if (manager.dragOperation.status.dragging) {
4494
- setDeepestDbMaybe(params);
4495
- } else {
4496
- setDeepest(params);
4497
- }
4498
- setNextDeepest(params);
4499
- }
4500
- if (params.area !== ((_c = deepestRef.current) == null ? void 0 : _c.area)) {
4501
- setTimeout(() => {
4502
- manager.collisionObserver.forceUpdate(true);
4503
- }, 50);
4504
- }
4505
- deepestRef.current = params;
4506
- }
4507
- })
4508
- ]);
4509
- const [sensors] = (0, import_react20.useState)(() => [
4510
- PointerSensor.configure({
4511
- activationConstraints(event, source) {
4512
- var _a;
4513
- const { pointerType, target } = event;
4514
- if (pointerType === "mouse" && (0, import_utilities2.isElement)(target) && (source.handle === target || ((_a = source.handle) == null ? void 0 : _a.contains(target)))) {
4515
- return void 0;
4516
- }
4517
- const delay = { value: 200, tolerance: 10 };
4518
- if (pointerType === "touch") {
4519
- return { delay };
4520
- }
4521
- return {
4522
- delay,
4523
- distance: { value: 5 }
4524
- };
4525
- }
4526
- })
4527
- ]);
4528
- const [draggedItem, setDraggedItem] = (0, import_react20.useState)();
4529
- const [dragListeners, setDragListeners] = (0, import_react20.useState)({});
4530
- const [pathData, setPathData] = (0, import_react20.useState)();
4531
- const dragMode = (0, import_react20.useRef)(null);
4532
- const registerPath = (0, import_react20.useCallback)(
4533
- (selector) => {
4534
- const item = getItem(selector, data);
4535
- if (!item) {
4536
- return;
4537
- }
4538
- const [area] = getZoneId(selector.zone);
4539
- setPathData((latestPathData = {}) => {
4540
- const parentPathData = latestPathData[area] || { path: [] };
4541
- return __spreadProps(__spreadValues({}, latestPathData), {
4542
- [item.props.id]: {
4543
- path: [
4544
- ...parentPathData.path,
4545
- ...selector.zone ? [selector.zone] : []
4546
- ],
4547
- label: item.type
4548
- }
4549
- });
4550
- });
4551
- },
4552
- [data, setPathData]
4553
- );
4554
- const initialSelector = (0, import_react20.useRef)();
4555
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
4556
- dragListenerContext.Provider,
4557
- {
4558
- value: {
4559
- dragListeners,
4560
- setDragListeners
4561
- },
4562
- children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(previewContext.Provider, { value: preview, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
4563
- import_react19.DragDropProvider,
4564
- {
4565
- plugins,
4566
- sensors,
4567
- onDragEnd: (event, manager) => {
4568
- const { source, target } = event.operation;
4569
- deepestRef.current = null;
4570
- if (!source) {
4571
- setDraggedItem(null);
4572
- return;
4573
- }
4574
- const { zone, index } = source.data;
4575
- const thisPreview = previewRef.current ? __spreadValues({}, previewRef.current) : null;
4576
- previewRef.current = null;
4577
- setTimeout(() => {
4578
- var _a, _b;
4579
- setDraggedItem(null);
4580
- if (event.canceled || (target == null ? void 0 : target.type) === "void") {
4581
- setPreview(null);
4582
- (_a = dragListeners.dragend) == null ? void 0 : _a.forEach((fn) => {
4583
- fn(event, manager);
4584
- });
4585
- return;
4586
- }
4587
- if (thisPreview) {
4588
- setPreview(null);
4589
- if (thisPreview.type === "insert") {
4590
- insertComponent(
4591
- thisPreview.componentType,
4592
- thisPreview.zone,
4593
- thisPreview.index,
4594
- { config, dispatch, resolveData, state }
4595
- );
4596
- } else if (initialSelector.current) {
4597
- dispatch({
4598
- type: "move",
4599
- sourceIndex: initialSelector.current.index,
4600
- sourceZone: initialSelector.current.zone,
4601
- destinationIndex: thisPreview.index,
4602
- destinationZone: thisPreview.zone,
4603
- recordHistory: false
4604
- });
4605
- }
4606
- }
4607
- dispatch({
4608
- type: "setUi",
4609
- ui: {
4610
- itemSelector: { index, zone },
4611
- isDragging: false
4612
- },
4613
- recordHistory: true
4614
- });
4615
- (_b = dragListeners.dragend) == null ? void 0 : _b.forEach((fn) => {
4616
- fn(event, manager);
4617
- });
4618
- }, 300);
4619
- },
4620
- onDragOver: (event, manager) => {
4621
- var _a, _b, _c, _d;
4622
- event.preventDefault();
4623
- if (!draggedItem) return;
4624
- const { source, target } = event.operation;
4625
- if (!target || !source || target.type === "void") return;
4626
- const [sourceId] = source.id.split(":");
4627
- const [targetId] = target.id.split(":");
4628
- const sourceData = source.data;
4629
- let sourceZone = sourceData.zone;
4630
- let sourceIndex = sourceData.index;
4631
- let targetZone = "";
4632
- let targetIndex = 0;
4633
- if (target.type === "component") {
4634
- const targetData = target.data;
4635
- targetZone = targetData.zone;
4636
- targetIndex = targetData.index;
4637
- const collisionData = (_b = (_a = manager.dragOperation.data) == null ? void 0 : _a.collisionMap) == null ? void 0 : _b[targetId];
4638
- const collisionPosition = (collisionData == null ? void 0 : collisionData.direction) === "up" || (collisionData == null ? void 0 : collisionData.direction) === "left" ? "before" : "after";
4639
- if (targetIndex >= sourceIndex && sourceZone === targetZone) {
4640
- targetIndex = targetIndex - 1;
4641
- }
4642
- if (collisionPosition === "after") {
4643
- targetIndex = targetIndex + 1;
4644
- }
4645
- } else {
4646
- targetZone = target.id.toString();
4647
- targetIndex = 0;
4648
- }
4649
- if (targetId === sourceId || ((_c = pathData == null ? void 0 : pathData[target.id]) == null ? void 0 : _c.path.find((path) => {
4650
- const [pathId] = path.split(":");
4651
- return pathId === sourceId;
4652
- }))) {
4653
- return;
4654
- }
4655
- if (dragMode.current === "new") {
4656
- previewRef.current = {
4657
- componentType: sourceData.componentType,
4658
- type: "insert",
4659
- index: targetIndex,
4660
- zone: targetZone,
4661
- props: {
4662
- id: source.id.toString()
4663
- }
4664
- };
4665
- setPreview(previewRef.current);
4666
- } else {
4667
- if (!initialSelector.current) {
4668
- initialSelector.current = {
4669
- zone: sourceData.zone,
4670
- index: sourceData.index
4671
- };
4672
- }
4673
- const item = getItem(initialSelector.current, data);
4674
- if (item) {
4675
- previewRef.current = {
4676
- componentType: sourceData.componentType,
4677
- type: "move",
4678
- index: targetIndex,
4679
- zone: targetZone,
4680
- props: item.props
4681
- };
4682
- setPreview(previewRef.current);
4683
- }
4684
- }
4685
- (_d = dragListeners.dragover) == null ? void 0 : _d.forEach((fn) => {
4686
- fn(event, manager);
4687
- });
4688
- },
4689
- onDragStart: (event, manager) => {
4690
- var _a;
4691
- setDeepest(
4692
- findDeepestCandidate(event.operation.position.current, manager)
4693
- );
4694
- dispatch({
4695
- type: "setUi",
4696
- ui: { itemSelector: null, isDragging: true }
4697
- });
4698
- (_a = dragListeners.dragstart) == null ? void 0 : _a.forEach((fn) => {
4699
- fn(event, manager);
4700
- });
4701
- },
4702
- onBeforeDragStart: (event) => {
4703
- var _a;
4704
- if (draggedItem) {
4705
- console.warn("New drag started before previous drag cleaned up");
4706
- }
4707
- const isNewComponent = ((_a = event.operation.source) == null ? void 0 : _a.data.type) === "drawer";
4708
- dragMode.current = isNewComponent ? "new" : "existing";
4709
- initialSelector.current = void 0;
4710
- setDraggedItem(event.operation.source);
4711
- },
4712
- children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
4713
- DropZoneProvider,
4714
- {
4715
- value: {
4716
- data,
4717
- config,
4718
- dispatch,
4719
- draggedItem,
4720
- mode: "edit",
4721
- areaId: "root",
4722
- depth: 0,
4723
- registerPath,
4724
- pathData,
4725
- deepestZone: deepest == null ? void 0 : deepest.zone,
4726
- deepestArea: deepest == null ? void 0 : deepest.area,
4727
- nextDeepestZone: nextDeepest == null ? void 0 : nextDeepest.zone,
4728
- nextDeepestArea: nextDeepest == null ? void 0 : nextDeepest.area,
4729
- path: []
4730
- },
4731
- children
4732
- }
4733
- )
4734
- }
4735
- ) })
4736
- }
4737
- );
4738
- };
4739
- var DragDropContext2 = ({ children }) => {
4740
- const { status } = useAppContext();
4741
- if (status === "LOADING") {
4742
- return children;
4743
- }
4744
- return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(DragDropContextClient, { children });
4745
- };
4746
-
4747
- // components/Drawer/index.tsx
4748
- var import_jsx_runtime25 = require("react/jsx-runtime");
4749
- var getClassName18 = get_class_name_factory_default("Drawer", styles_module_default10);
4750
- var getClassNameItem2 = get_class_name_factory_default("DrawerItem", styles_module_default10);
4751
- var DrawerItemInner = ({
4752
- children,
4753
- name,
4754
- label,
4755
- dragRef,
4756
- isDragDisabled
4757
- }) => {
4758
- const CustomInner = (0, import_react21.useMemo)(
4759
- () => children || (({ children: children2 }) => /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: getClassNameItem2("default"), children: children2 })),
4760
- [children]
4761
- );
4762
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
4763
- "div",
4764
- {
4765
- className: getClassNameItem2({ disabled: isDragDisabled }),
4766
- ref: dragRef,
4767
- onMouseDown: (e) => e.preventDefault(),
4768
- children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(CustomInner, { name, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: getClassNameItem2("draggableWrapper"), children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: getClassNameItem2("draggable"), children: [
4769
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: getClassNameItem2("name"), children: label != null ? label : name }),
4770
- /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: getClassNameItem2("icon"), children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(DragIcon, {}) })
4771
- ] }) }) })
4772
- }
4773
- );
4774
- };
4775
- var DrawerItemDraggable = ({
4776
- children,
4777
- name,
4778
- label,
4779
- id,
4780
- isDragDisabled
4781
- }) => {
4782
- const { ref } = useDraggableSafe({
4783
- id,
4784
- data: { type: "drawer", componentType: name },
4785
- disabled: isDragDisabled
4786
- });
4787
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
4788
- DrawerItemInner,
4789
- {
4790
- name,
4791
- label,
4792
- dragRef: ref,
4793
- isDragDisabled,
4794
- children
4795
- }
4796
- );
4797
- };
4798
- var DrawerItem = ({
4799
- name,
4800
- children,
4801
- id,
4802
- label,
4803
- index,
4804
- isDragDisabled
4805
- }) => {
4806
- const resolvedId = id || name;
4807
- const [dynamicId, setDynamicId] = (0, import_react21.useState)(generateId(resolvedId));
4808
- if (typeof index !== "undefined") {
4809
- console.error(
4810
- "Warning: The `index` prop on Drawer.Item is deprecated and no longer required."
4811
- );
4812
- }
4813
- useDragListener(
4814
- "dragend",
4815
- () => {
4816
- setDynamicId(generateId(resolvedId));
4817
- },
4818
- [resolvedId]
4819
- );
4820
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
4821
- DrawerItemDraggable,
4822
- {
4823
- name,
4824
- label,
4825
- id: dynamicId,
4826
- isDragDisabled,
4827
- children
4828
- }
4829
- ) }, dynamicId);
4830
- };
4831
- var Drawer = ({
4832
- children,
4833
- droppableId,
4834
- direction
4835
- }) => {
4836
- if (droppableId) {
4837
- console.error(
4838
- "Warning: The `droppableId` prop on Drawer is deprecated and no longer required."
4839
- );
4840
- }
4841
- if (direction) {
4842
- console.error(
4843
- "Warning: The `direction` prop on Drawer is deprecated and no longer required to achieve multi-directional dragging."
4844
- );
4845
- }
4846
- const [id] = (0, import_react21.useState)(generateId());
4847
- const { ref } = useDroppableSafe({
4848
- id,
4849
- type: "void",
4850
- collisionPriority: 0
4851
- // Never collide with this, but we use it so NestedDroppablePlugin respects the Drawer
4852
- });
4853
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className: getClassName18(), ref, children });
4854
- };
4855
- Drawer.Item = DrawerItem;
4856
-
4857
- // components/Puck/index.tsx
4858
- init_react_import();
4859
- var import_react36 = require("react");
4860
-
4861
- // components/SidebarSection/index.tsx
4862
- init_react_import();
4863
-
4864
- // css-module:/home/runner/work/puck/puck/packages/core/components/SidebarSection/styles.module.css#css-module
4865
- init_react_import();
4866
- var styles_module_default13 = { "SidebarSection": "_SidebarSection_125qe_1", "SidebarSection-title": "_SidebarSection-title_125qe_12", "SidebarSection--noBorderTop": "_SidebarSection--noBorderTop_125qe_20", "SidebarSection-content": "_SidebarSection-content_125qe_24", "SidebarSection--noPadding": "_SidebarSection--noPadding_125qe_28", "SidebarSection-breadcrumbLabel": "_SidebarSection-breadcrumbLabel_125qe_41", "SidebarSection-breadcrumbs": "_SidebarSection-breadcrumbs_125qe_70", "SidebarSection-breadcrumb": "_SidebarSection-breadcrumb_125qe_41", "SidebarSection-heading": "_SidebarSection-heading_125qe_82", "SidebarSection-loadingOverlay": "_SidebarSection-loadingOverlay_125qe_86" };
4867
-
4868
- // lib/use-breadcrumbs.ts
4869
- init_react_import();
4870
- var import_react22 = require("react");
4871
- var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
4872
- const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
4873
- const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
4874
- if (!id) {
4875
- return [];
4876
- }
4877
- return currentPathData == null ? void 0 : currentPathData.path.reduce((acc, zoneCompound) => {
4878
- const [area] = getZoneId(zoneCompound);
4879
- if (area === rootDroppableId) {
4880
- return [
4881
- {
4882
- label: "Page",
4883
- selector: null
4884
- }
4885
- ];
4886
- }
4887
- const parentZoneCompound = acc.length > 0 ? acc[acc.length - 1].zoneCompound : rootDroppableId;
4888
- let parentZone = data.content;
4889
- if (parentZoneCompound && parentZoneCompound !== rootDroppableId) {
4890
- parentZone = data.zones[parentZoneCompound];
4891
- }
4892
- if (!parentZone) {
4893
- return acc;
4894
- }
4895
- const itemIndex = parentZone.findIndex(
4896
- (queryItem) => queryItem.props.id === area
4897
- );
4898
- const item = parentZone[itemIndex];
4899
- if (!item) {
4900
- return acc;
4901
- }
4902
- return [
4903
- ...acc,
4904
- {
4905
- label: item.type.toString(),
4906
- selector: {
4907
- index: itemIndex,
4908
- zone: parentZoneCompound
4909
- },
4910
- zoneCompound
4911
- }
4912
- ];
4913
- }, []);
4914
- };
4915
- var useBreadcrumbs = (renderCount) => {
4916
- const {
4917
- state: { data },
4918
- selectedItem
4919
- } = useAppContext();
4920
- const dzContext = (0, import_react22.useContext)(dropZoneContext);
4921
- return (0, import_react22.useMemo)(() => {
4922
- const breadcrumbs = convertPathDataToBreadcrumbs(
4923
- selectedItem,
4924
- dzContext == null ? void 0 : dzContext.pathData,
4925
- data
4926
- );
4927
- if (renderCount) {
4928
- return breadcrumbs.slice(breadcrumbs.length - renderCount);
4929
- }
4930
- return breadcrumbs;
4931
- }, [selectedItem, dzContext == null ? void 0 : dzContext.pathData, renderCount]);
4932
- };
4933
-
4934
- // components/SidebarSection/index.tsx
4935
- var import_jsx_runtime26 = require("react/jsx-runtime");
4936
- var getClassName19 = get_class_name_factory_default("SidebarSection", styles_module_default13);
4937
- var SidebarSection = ({
4938
- children,
4939
- title,
4940
- background,
4941
- showBreadcrumbs,
4942
- noBorderTop,
4943
- noPadding,
4944
- isLoading
4945
- }) => {
4946
- const { setUi } = useAppContext();
4947
- const breadcrumbs = useBreadcrumbs(1);
4948
- return /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)(
4949
- "div",
4950
- {
4951
- className: getClassName19({ noBorderTop, noPadding }),
4952
- style: { background },
4953
- children: [
4954
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: getClassName19("title"), children: /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: getClassName19("breadcrumbs"), children: [
4955
- showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: getClassName19("breadcrumb"), children: [
4956
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
4957
- "button",
4958
- {
4959
- type: "button",
4960
- className: getClassName19("breadcrumbLabel"),
4961
- onClick: () => setUi({ itemSelector: breadcrumb.selector }),
4962
- children: breadcrumb.label
4963
- }
4964
- ),
4965
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ChevronRight, { size: 16 })
4966
- ] }, i)) : null,
4967
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: getClassName19("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Heading, { rank: "2", size: "xs", children: title }) })
4968
- ] }) }),
4969
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: getClassName19("content"), children }),
4970
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: getClassName19("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Loader, { size: 32 }) })
4971
- ]
4972
- }
3684
+ (state, action) => {
3685
+ const data = reduceData(state.data, action, config);
3686
+ const ui = reduceUi(state.ui, action);
3687
+ if (action.type === "set") {
3688
+ return setAction(state, action);
3689
+ }
3690
+ return { data, ui };
3691
+ },
3692
+ record,
3693
+ onAction
4973
3694
  );
4974
- };
3695
+ }
4975
3696
 
4976
3697
  // lib/flush-zones.ts
4977
3698
  init_react_import();
@@ -4998,7 +3719,7 @@ init_react_import();
4998
3719
  var styles_module_default14 = { "MenuBar": "_MenuBar_8pf8c_1", "MenuBar--menuOpen": "_MenuBar--menuOpen_8pf8c_14", "MenuBar-inner": "_MenuBar-inner_8pf8c_29", "MenuBar-history": "_MenuBar-history_8pf8c_45" };
4999
3720
 
5000
3721
  // components/MenuBar/index.tsx
5001
- var import_jsx_runtime27 = require("react/jsx-runtime");
3722
+ var import_jsx_runtime26 = require("react/jsx-runtime");
5002
3723
  var getClassName20 = get_class_name_factory_default("MenuBar", styles_module_default14);
5003
3724
  function MenuBar({
5004
3725
  appState,
@@ -5012,7 +3733,7 @@ function MenuBar({
5012
3733
  history: { back, forward, historyStore }
5013
3734
  } = useAppContext();
5014
3735
  const { hasFuture = false, hasPast = false } = historyStore || {};
5015
- return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
3736
+ return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
5016
3737
  "div",
5017
3738
  {
5018
3739
  className: getClassName20({ menuOpen }),
@@ -5026,12 +3747,12 @@ function MenuBar({
5026
3747
  setMenuOpen(false);
5027
3748
  }
5028
3749
  },
5029
- children: /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: getClassName20("inner"), children: [
5030
- /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: getClassName20("history"), children: [
5031
- /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(IconButton, { title: "undo", disabled: !hasPast, onClick: back, children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Undo2, { size: 21 }) }),
5032
- /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(IconButton, { title: "redo", disabled: !hasFuture, onClick: forward, children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Redo2, { size: 21 }) })
3750
+ children: /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: getClassName20("inner"), children: [
3751
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: getClassName20("history"), children: [
3752
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(IconButton, { title: "undo", disabled: !hasPast, onClick: back, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Undo2, { size: 21 }) }),
3753
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(IconButton, { title: "redo", disabled: !hasFuture, onClick: forward, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(Redo2, { size: 21 }) })
5033
3754
  ] }),
5034
- /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_jsx_runtime27.Fragment, { children: renderHeaderActions && renderHeaderActions({
3755
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_jsx_runtime26.Fragment, { children: renderHeaderActions && renderHeaderActions({
5035
3756
  state: appState,
5036
3757
  dispatch
5037
3758
  }) })
@@ -5069,7 +3790,7 @@ var useParent = (itemSelector) => {
5069
3790
  };
5070
3791
 
5071
3792
  // components/Puck/components/Fields/index.tsx
5072
- var import_jsx_runtime28 = require("react/jsx-runtime");
3793
+ var import_jsx_runtime27 = require("react/jsx-runtime");
5073
3794
  var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
5074
3795
  var defaultPageFields = {
5075
3796
  title: { type: "text" }
@@ -5077,7 +3798,7 @@ var defaultPageFields = {
5077
3798
  var DefaultFields = ({
5078
3799
  children
5079
3800
  }) => {
5080
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_jsx_runtime28.Fragment, { children });
3801
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_jsx_runtime27.Fragment, { children });
5081
3802
  };
5082
3803
  var useResolvedFields = () => {
5083
3804
  var _a, _b;
@@ -5169,7 +3890,7 @@ var Fields = () => {
5169
3890
  const isLoading = fieldsResolving || componentResolving;
5170
3891
  const rootProps = data.root.props || data.root;
5171
3892
  const Wrapper = (0, import_react24.useMemo)(() => overrides.fields || DefaultFields, [overrides]);
5172
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
3893
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
5173
3894
  "form",
5174
3895
  {
5175
3896
  className: getClassName21(),
@@ -5177,7 +3898,7 @@ var Fields = () => {
5177
3898
  e.preventDefault();
5178
3899
  },
5179
3900
  children: [
5180
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Wrapper, { isLoading, itemSelector, children: Object.keys(fields).map((fieldName) => {
3901
+ /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Wrapper, { isLoading, itemSelector, children: Object.keys(fields).map((fieldName) => {
5181
3902
  const field = fields[fieldName];
5182
3903
  if (!(field == null ? void 0 : field.type)) return null;
5183
3904
  const onChange = (value, updatedUi) => {
@@ -5247,38 +3968,40 @@ var Fields = () => {
5247
3968
  const { edit } = getPermissions({
5248
3969
  item: selectedItem
5249
3970
  });
5250
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
3971
+ const id = `${selectedItem.props.id}_${field.type}_${fieldName}`;
3972
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
5251
3973
  AutoFieldPrivate,
5252
3974
  {
5253
3975
  field,
5254
3976
  name: fieldName,
5255
- id: `${selectedItem.props.id}_${fieldName}`,
3977
+ id,
5256
3978
  readOnly: !edit || readOnly[fieldName],
5257
3979
  value: selectedItem.props[fieldName],
5258
3980
  onChange
5259
3981
  },
5260
- `${selectedItem.props.id}_${fieldName}`
3982
+ id
5261
3983
  );
5262
3984
  } else {
5263
3985
  const readOnly = data.root.readOnly || {};
5264
3986
  const { edit } = getPermissions({
5265
3987
  root: true
5266
3988
  });
5267
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
3989
+ const id = `root_${field.type}_${fieldName}`;
3990
+ return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
5268
3991
  AutoFieldPrivate,
5269
3992
  {
5270
3993
  field,
5271
3994
  name: fieldName,
5272
- id: `root_${fieldName}`,
3995
+ id,
5273
3996
  readOnly: !edit || readOnly[fieldName],
5274
3997
  value: rootProps[fieldName],
5275
3998
  onChange
5276
3999
  },
5277
- `page_${fieldName}`
4000
+ id
5278
4001
  );
5279
4002
  }
5280
4003
  }) }),
5281
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: getClassName21("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: getClassName21("loadingOverlayInner"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Loader, { size: 16 }) }) })
4004
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: getClassName21("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: getClassName21("loadingOverlayInner"), children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Loader, { size: 16 }) }) })
5282
4005
  ]
5283
4006
  }
5284
4007
  );
@@ -5299,17 +4022,27 @@ init_react_import();
5299
4022
  var styles_module_default17 = { "ComponentList": "_ComponentList_odh9d_1", "ComponentList--isExpanded": "_ComponentList--isExpanded_odh9d_5", "ComponentList-content": "_ComponentList-content_odh9d_9", "ComponentList-title": "_ComponentList-title_odh9d_17", "ComponentList-titleIcon": "_ComponentList-titleIcon_odh9d_53" };
5300
4023
 
5301
4024
  // components/ComponentList/index.tsx
5302
- var import_jsx_runtime29 = require("react/jsx-runtime");
4025
+ var import_jsx_runtime28 = require("react/jsx-runtime");
5303
4026
  var getClassName22 = get_class_name_factory_default("ComponentList", styles_module_default17);
5304
4027
  var ComponentListItem = ({
5305
4028
  name,
5306
- label
4029
+ label,
4030
+ index
5307
4031
  }) => {
5308
4032
  const { overrides, getPermissions } = useAppContext();
5309
4033
  const canInsert = getPermissions({
5310
4034
  type: name
5311
4035
  }).insert;
5312
- return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(Drawer.Item, { label, name, isDragDisabled: !canInsert, children: overrides.componentItem });
4036
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
4037
+ Drawer.Item,
4038
+ {
4039
+ label,
4040
+ name,
4041
+ index,
4042
+ isDragDisabled: !canInsert,
4043
+ children: overrides.componentItem
4044
+ }
4045
+ );
5313
4046
  };
5314
4047
  var ComponentList = ({
5315
4048
  children,
@@ -5318,8 +4051,8 @@ var ComponentList = ({
5318
4051
  }) => {
5319
4052
  const { config, state, setUi } = useAppContext();
5320
4053
  const { expanded = true } = state.ui.componentList[id] || {};
5321
- return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: getClassName22({ isExpanded: expanded }), children: [
5322
- title && /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
4054
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: getClassName22({ isExpanded: expanded }), children: [
4055
+ title && /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
5323
4056
  "button",
5324
4057
  {
5325
4058
  type: "button",
@@ -5333,18 +4066,19 @@ var ComponentList = ({
5333
4066
  }),
5334
4067
  title: expanded ? `Collapse${title ? ` ${title}` : ""}` : `Expand${title ? ` ${title}` : ""}`,
5335
4068
  children: [
5336
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { children: title }),
5337
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: getClassName22("titleIcon"), children: expanded ? /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(ChevronUp, { size: 12 }) : /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(ChevronDown, { size: 12 }) })
4069
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { children: title }),
4070
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: getClassName22("titleIcon"), children: expanded ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(ChevronUp, { size: 12 }) : /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(ChevronDown, { size: 12 }) })
5338
4071
  ]
5339
4072
  }
5340
4073
  ),
5341
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: getClassName22("content"), children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(Drawer, { children: children || Object.keys(config.components).map((componentKey) => {
4074
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: getClassName22("content"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Drawer, { droppableId: title, children: children || Object.keys(config.components).map((componentKey, i) => {
5342
4075
  var _a;
5343
- return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
4076
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
5344
4077
  ComponentListItem,
5345
4078
  {
5346
4079
  label: (_a = config.components[componentKey]["label"]) != null ? _a : componentKey,
5347
- name: componentKey
4080
+ name: componentKey,
4081
+ index: i
5348
4082
  },
5349
4083
  componentKey
5350
4084
  );
@@ -5354,7 +4088,7 @@ var ComponentList = ({
5354
4088
  ComponentList.Item = ComponentListItem;
5355
4089
 
5356
4090
  // lib/use-component-list.tsx
5357
- var import_jsx_runtime30 = require("react/jsx-runtime");
4091
+ var import_jsx_runtime29 = require("react/jsx-runtime");
5358
4092
  var useComponentList = (config, ui) => {
5359
4093
  const [componentList, setComponentList] = (0, import_react25.useState)();
5360
4094
  (0, import_react25.useEffect)(() => {
@@ -5367,7 +4101,7 @@ var useComponentList = (config, ui) => {
5367
4101
  if (category.visible === false || !category.components) {
5368
4102
  return null;
5369
4103
  }
5370
- return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
4104
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
5371
4105
  ComponentList,
5372
4106
  {
5373
4107
  id: categoryKey,
@@ -5376,7 +4110,7 @@ var useComponentList = (config, ui) => {
5376
4110
  var _a2;
5377
4111
  matchedComponents.push(componentName);
5378
4112
  const componentConf = config.components[componentName] || {};
5379
- return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
4113
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
5380
4114
  ComponentList.Item,
5381
4115
  {
5382
4116
  label: (_a2 = componentConf["label"]) != null ? _a2 : componentName,
@@ -5396,7 +4130,7 @@ var useComponentList = (config, ui) => {
5396
4130
  );
5397
4131
  if (remainingComponents.length > 0 && !((_a = ui.componentList.other) == null ? void 0 : _a.components) && ((_b = ui.componentList.other) == null ? void 0 : _b.visible) !== false) {
5398
4132
  _componentList.push(
5399
- /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
4133
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
5400
4134
  ComponentList,
5401
4135
  {
5402
4136
  id: "other",
@@ -5404,7 +4138,7 @@ var useComponentList = (config, ui) => {
5404
4138
  children: remainingComponents.map((componentName, i) => {
5405
4139
  var _a2;
5406
4140
  const componentConf = config.components[componentName] || {};
5407
- return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
4141
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
5408
4142
  ComponentList.Item,
5409
4143
  {
5410
4144
  name: componentName,
@@ -5427,12 +4161,12 @@ var useComponentList = (config, ui) => {
5427
4161
 
5428
4162
  // components/Puck/components/Components/index.tsx
5429
4163
  var import_react26 = require("react");
5430
- var import_jsx_runtime31 = require("react/jsx-runtime");
4164
+ var import_jsx_runtime30 = require("react/jsx-runtime");
5431
4165
  var Components = () => {
5432
4166
  const { config, state, overrides } = useAppContext();
5433
4167
  const componentList = useComponentList(config, state.ui);
5434
4168
  const Wrapper = (0, import_react26.useMemo)(() => overrides.components || "div", [overrides]);
5435
- return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(ComponentList, { id: "all" }) });
4169
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(ComponentList, { id: "all" }) });
5436
4170
  };
5437
4171
 
5438
4172
  // components/Puck/components/Preview/index.tsx
@@ -5443,8 +4177,8 @@ var import_react28 = require("react");
5443
4177
  init_react_import();
5444
4178
  var import_react27 = require("react");
5445
4179
  var import_object_hash = __toESM(require("object-hash"));
5446
- var import_react_dom3 = require("react-dom");
5447
- var import_jsx_runtime32 = require("react/jsx-runtime");
4180
+ var import_react_dom2 = require("react-dom");
4181
+ var import_jsx_runtime31 = require("react/jsx-runtime");
5448
4182
  var styleSelector = 'style, link[rel="stylesheet"]';
5449
4183
  var collectStyles = (doc) => {
5450
4184
  const collected = [];
@@ -5511,8 +4245,8 @@ var CopyHostStyles = ({
5511
4245
  });
5512
4246
  styleSheet = getStyleSheet(el);
5513
4247
  }
5514
- const styles2 = getStyles(styleSheet);
5515
- if (!styles2) {
4248
+ const styles = getStyles(styleSheet);
4249
+ if (!styles) {
5516
4250
  if (debug) {
5517
4251
  console.warn(
5518
4252
  `Tried to load styles for link element, but couldn't find them. Skipping...`
@@ -5520,7 +4254,7 @@ var CopyHostStyles = ({
5520
4254
  }
5521
4255
  return;
5522
4256
  }
5523
- mirror.innerHTML = styles2;
4257
+ mirror.innerHTML = styles;
5524
4258
  mirror.setAttribute("data-href", el.getAttribute("href"));
5525
4259
  } else {
5526
4260
  mirror = el.cloneNode(true);
@@ -5644,7 +4378,7 @@ var CopyHostStyles = ({
5644
4378
  observer.disconnect();
5645
4379
  };
5646
4380
  }, []);
5647
- return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(import_jsx_runtime32.Fragment, { children });
4381
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_jsx_runtime31.Fragment, { children });
5648
4382
  };
5649
4383
  var autoFrameContext = (0, import_react27.createContext)({});
5650
4384
  var useFrame = () => (0, import_react27.useContext)(autoFrameContext);
@@ -5654,42 +4388,39 @@ function AutoFrame(_a) {
5654
4388
  className,
5655
4389
  debug,
5656
4390
  id,
5657
- onStylesLoaded,
5658
- frameRef
4391
+ onStylesLoaded
5659
4392
  } = _b, props = __objRest(_b, [
5660
4393
  "children",
5661
4394
  "className",
5662
4395
  "debug",
5663
4396
  "id",
5664
- "onStylesLoaded",
5665
- "frameRef"
4397
+ "onStylesLoaded"
5666
4398
  ]);
5667
4399
  const [loaded, setLoaded] = (0, import_react27.useState)(false);
5668
4400
  const [ctx, setCtx] = (0, import_react27.useState)({});
4401
+ const ref = (0, import_react27.useRef)(null);
5669
4402
  const [mountTarget, setMountTarget] = (0, import_react27.useState)();
5670
4403
  (0, import_react27.useEffect)(() => {
5671
4404
  var _a2;
5672
- if (frameRef.current) {
4405
+ if (ref.current) {
5673
4406
  setCtx({
5674
- document: frameRef.current.contentDocument || void 0,
5675
- window: frameRef.current.contentWindow || void 0
4407
+ document: ref.current.contentDocument || void 0,
4408
+ window: ref.current.contentWindow || void 0
5676
4409
  });
5677
- setMountTarget(
5678
- (_a2 = frameRef.current.contentDocument) == null ? void 0 : _a2.getElementById("frame-root")
5679
- );
4410
+ setMountTarget((_a2 = ref.current.contentDocument) == null ? void 0 : _a2.getElementById("frame-root"));
5680
4411
  }
5681
- }, [frameRef, loaded]);
5682
- return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
4412
+ }, [ref, loaded]);
4413
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
5683
4414
  "iframe",
5684
4415
  __spreadProps(__spreadValues({}, props), {
5685
4416
  className,
5686
4417
  id,
5687
4418
  srcDoc: '<!DOCTYPE html><html><head></head><body><div id="frame-root"></div></body></html>',
5688
- ref: frameRef,
4419
+ ref,
5689
4420
  onLoad: () => {
5690
4421
  setLoaded(true);
5691
4422
  },
5692
- children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(autoFrameContext.Provider, { value: ctx, children: loaded && mountTarget && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(CopyHostStyles, { debug, onStylesLoaded, children: (0, import_react_dom3.createPortal)(children, mountTarget) }) })
4423
+ children: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(autoFrameContext.Provider, { value: ctx, children: loaded && mountTarget && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(CopyHostStyles, { debug, onStylesLoaded, children: (0, import_react_dom2.createPortal)(children, mountTarget) }) })
5693
4424
  })
5694
4425
  );
5695
4426
  }
@@ -5698,46 +4429,11 @@ var AutoFrame_default = AutoFrame;
5698
4429
 
5699
4430
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Preview/styles.module.css#css-module
5700
4431
  init_react_import();
5701
- var styles_module_default18 = { "PuckPreview": "_PuckPreview_z2rgu_1", "PuckPreview-frame": "_PuckPreview-frame_z2rgu_6" };
4432
+ var styles_module_default18 = { "PuckPreview": "_PuckPreview_rxwlr_1", "PuckPreview-frame": "_PuckPreview-frame_rxwlr_5" };
5702
4433
 
5703
4434
  // components/Puck/components/Preview/index.tsx
5704
- var import_jsx_runtime33 = require("react/jsx-runtime");
4435
+ var import_jsx_runtime32 = require("react/jsx-runtime");
5705
4436
  var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
5706
- var useBubbleIframeEvents = (ref) => {
5707
- const { status } = useAppContext();
5708
- (0, import_react28.useEffect)(() => {
5709
- var _a;
5710
- if (ref.current && status === "READY") {
5711
- const iframe = ref.current;
5712
- const handlePointerMove = (event) => {
5713
- var _a2;
5714
- const rect = iframe.getBoundingClientRect();
5715
- const evt = new CustomEvent("pointermove", {
5716
- bubbles: true,
5717
- cancelable: false
5718
- });
5719
- const scaleFactor = rect.width / (((_a2 = iframe.contentWindow) == null ? void 0 : _a2.innerWidth) || 1);
5720
- evt.clientX = event.clientX * scaleFactor + rect.left;
5721
- evt.clientY = event.clientY * scaleFactor + rect.top;
5722
- iframe.dispatchEvent(evt);
5723
- };
5724
- (_a = iframe.contentDocument) == null ? void 0 : _a.addEventListener(
5725
- "pointermove",
5726
- handlePointerMove,
5727
- {
5728
- capture: true
5729
- }
5730
- );
5731
- return () => {
5732
- var _a2;
5733
- (_a2 = iframe.contentDocument) == null ? void 0 : _a2.removeEventListener(
5734
- "pointermove",
5735
- handlePointerMove
5736
- );
5737
- };
5738
- }
5739
- }, [status]);
5740
- };
5741
4437
  var Preview = ({ id = "puck-preview" }) => {
5742
4438
  const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
5743
4439
  const Page = (0, import_react28.useCallback)(
@@ -5745,24 +4441,21 @@ var Preview = ({ id = "puck-preview" }) => {
5745
4441
  var _a, _b;
5746
4442
  return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
5747
4443
  id: "puck-root"
5748
- }, pageProps)) : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_jsx_runtime33.Fragment, { children: pageProps.children });
4444
+ }, pageProps)) : /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(import_jsx_runtime32.Fragment, { children: pageProps.children });
5749
4445
  },
5750
4446
  [config.root]
5751
4447
  );
5752
4448
  const Frame = (0, import_react28.useMemo)(() => overrides.iframe, [overrides]);
5753
4449
  const rootProps = state.data.root.props || state.data.root;
5754
- const ref = (0, import_react28.useRef)(null);
5755
- useBubbleIframeEvents(ref);
5756
- return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
4450
+ return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
5757
4451
  "div",
5758
4452
  {
5759
4453
  className: getClassName23(),
5760
4454
  id,
5761
- "data-puck-preview": true,
5762
4455
  onClick: () => {
5763
4456
  dispatch({ type: "setUi", ui: __spreadProps(__spreadValues({}, state.ui), { itemSelector: null }) });
5764
4457
  },
5765
- children: iframe.enabled ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
4458
+ children: iframe.enabled ? /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
5766
4459
  AutoFrame_default,
5767
4460
  {
5768
4461
  id: "preview-frame",
@@ -5771,32 +4464,27 @@ var Preview = ({ id = "puck-preview" }) => {
5771
4464
  onStylesLoaded: () => {
5772
4465
  setStatus("READY");
5773
4466
  },
5774
- frameRef: ref,
5775
- children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(autoFrameContext.Consumer, { children: ({ document: document2 }) => {
5776
- const inner = /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
4467
+ children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(autoFrameContext.Consumer, { children: ({ document: document2 }) => {
4468
+ const inner = /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
5777
4469
  Page,
5778
4470
  __spreadProps(__spreadValues({}, rootProps), {
5779
- puck: {
5780
- renderDropZone: DropZone,
5781
- isEditing: true,
5782
- dragRef: null
5783
- },
4471
+ puck: { renderDropZone: DropZone, isEditing: true },
5784
4472
  editMode: true,
5785
- children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(DropZone, { zone: rootDroppableId })
4473
+ children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(DropZone, { zone: rootDroppableId })
5786
4474
  })
5787
4475
  );
5788
4476
  if (Frame) {
5789
- return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Frame, { document: document2, children: inner });
4477
+ return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Frame, { document: document2, children: inner });
5790
4478
  }
5791
4479
  return inner;
5792
4480
  } })
5793
4481
  }
5794
- ) : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { id: "preview-frame", className: getClassName23("frame"), ref, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
4482
+ ) : /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { id: "preview-frame", className: getClassName23("frame"), children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
5795
4483
  Page,
5796
4484
  __spreadProps(__spreadValues({}, rootProps), {
5797
- puck: { renderDropZone: DropZone, isEditing: true, dragRef: null },
4485
+ puck: { renderDropZone: DropZone, isEditing: true },
5798
4486
  editMode: true,
5799
- children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(DropZone, { zone: rootDroppableId })
4487
+ children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(DropZone, { zone: rootDroppableId })
5800
4488
  })
5801
4489
  ) })
5802
4490
  }
@@ -5859,38 +4547,8 @@ var isChildOfZone = (item, maybeChild, ctx) => {
5859
4547
  })) : false;
5860
4548
  };
5861
4549
 
5862
- // lib/get-frame.ts
5863
- init_react_import();
5864
- var getFrame = () => {
5865
- if (typeof window === "undefined") return;
5866
- let frameEl = document.querySelector("#preview-frame");
5867
- if ((frameEl == null ? void 0 : frameEl.tagName) === "IFRAME") {
5868
- return frameEl.contentDocument || document;
5869
- }
5870
- return (frameEl == null ? void 0 : frameEl.ownerDocument) || document;
5871
- };
5872
-
5873
- // lib/on-scroll-end.ts
5874
- init_react_import();
5875
- var onScrollEnd = (frame, cb) => {
5876
- let scrollTimeout;
5877
- const callback = function() {
5878
- clearTimeout(scrollTimeout);
5879
- scrollTimeout = setTimeout(function() {
5880
- cb();
5881
- frame == null ? void 0 : frame.removeEventListener("scroll", callback);
5882
- }, 50);
5883
- };
5884
- frame == null ? void 0 : frame.addEventListener("scroll", callback);
5885
- setTimeout(() => {
5886
- if (!scrollTimeout) {
5887
- cb();
5888
- }
5889
- }, 50);
5890
- };
5891
-
5892
4550
  // components/LayerTree/index.tsx
5893
- var import_jsx_runtime34 = require("react/jsx-runtime");
4551
+ var import_jsx_runtime33 = require("react/jsx-runtime");
5894
4552
  var getClassName24 = get_class_name_factory_default("LayerTree", styles_module_default19);
5895
4553
  var getClassNameLayer = get_class_name_factory_default("Layer", styles_module_default19);
5896
4554
  var LayerTree = ({
@@ -5904,27 +4562,32 @@ var LayerTree = ({
5904
4562
  }) => {
5905
4563
  const zones = data.zones || {};
5906
4564
  const ctx = (0, import_react29.useContext)(dropZoneContext);
5907
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
5908
- label && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: getClassName24("zoneTitle"), children: [
5909
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Layers, { size: "16" }) }),
4565
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(import_jsx_runtime33.Fragment, { children: [
4566
+ label && /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: getClassName24("zoneTitle"), children: [
4567
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Layers, { size: "16" }) }),
5910
4568
  " ",
5911
4569
  label
5912
4570
  ] }),
5913
- /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("ul", { className: getClassName24(), children: [
5914
- zoneContent.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassName24("helper"), children: "No items" }),
4571
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("ul", { className: getClassName24(), children: [
4572
+ zoneContent.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: getClassName24("helper"), children: "No items" }),
5915
4573
  zoneContent.map((item, i) => {
5916
4574
  var _a;
5917
4575
  const isSelected = (itemSelector == null ? void 0 : itemSelector.index) === i && (itemSelector.zone === zone || itemSelector.zone === rootDroppableId && !zone);
5918
4576
  const zonesForItem = findZonesForArea(data, item.props.id);
5919
4577
  const containsZone = Object.keys(zonesForItem).length > 0;
5920
- const { setHoveringComponent = () => {
5921
- }, hoveringComponent } = ctx || {};
4578
+ const {
4579
+ setHoveringArea = () => {
4580
+ },
4581
+ setHoveringComponent = () => {
4582
+ },
4583
+ hoveringComponent
4584
+ } = ctx || {};
5922
4585
  const selectedItem = itemSelector && data ? getItem(itemSelector, data) : null;
5923
4586
  const isHovering = hoveringComponent === item.props.id;
5924
4587
  const childIsSelected = isChildOfZone(item, selectedItem, ctx);
5925
4588
  const componentConfig = config.components[item.type];
5926
4589
  const label2 = (_a = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _a : item.type.toString();
5927
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
4590
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(
5928
4591
  "li",
5929
4592
  {
5930
4593
  className: getClassNameLayer({
@@ -5934,7 +4597,7 @@ var LayerTree = ({
5934
4597
  childIsSelected
5935
4598
  }),
5936
4599
  children: [
5937
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
4600
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(
5938
4601
  "button",
5939
4602
  {
5940
4603
  type: "button",
@@ -5944,51 +4607,45 @@ var LayerTree = ({
5944
4607
  setItemSelector(null);
5945
4608
  return;
5946
4609
  }
4610
+ setItemSelector({
4611
+ index: i,
4612
+ zone
4613
+ });
5947
4614
  const id = zoneContent[i].props.id;
5948
4615
  const frame = getFrame();
5949
- const el = frame == null ? void 0 : frame.querySelector(
5950
- `[data-puck-component="${id}"]`
4616
+ scrollIntoView(
4617
+ frame == null ? void 0 : frame.querySelector(
4618
+ `[data-rfd-drag-handle-draggable-id="draggable-${id}"]`
4619
+ )
5951
4620
  );
5952
- if (!el) {
5953
- console.error(
5954
- "Scroll failed. No element was found for",
5955
- id
5956
- );
5957
- return;
5958
- }
5959
- scrollIntoView(el);
5960
- onScrollEnd(frame, () => {
5961
- setItemSelector({
5962
- index: i,
5963
- zone
5964
- });
5965
- });
5966
4621
  },
5967
4622
  onMouseOver: (e) => {
5968
4623
  e.stopPropagation();
4624
+ setHoveringArea(item.props.id);
5969
4625
  setHoveringComponent(item.props.id);
5970
4626
  },
5971
4627
  onMouseOut: (e) => {
5972
4628
  e.stopPropagation();
4629
+ setHoveringArea(null);
5973
4630
  setHoveringComponent(null);
5974
4631
  },
5975
4632
  children: [
5976
- containsZone && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
4633
+ containsZone && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5977
4634
  "div",
5978
4635
  {
5979
4636
  className: getClassNameLayer("chevron"),
5980
4637
  title: isSelected ? "Collapse" : "Expand",
5981
- children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ChevronDown, { size: "12" })
4638
+ children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(ChevronDown, { size: "12" })
5982
4639
  }
5983
4640
  ),
5984
- /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: getClassNameLayer("title"), children: [
5985
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassNameLayer("icon"), children: item.type === "Text" || item.type === "Heading" ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Type, { size: "16" }) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(LayoutGrid, { size: "16" }) }),
5986
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassNameLayer("name"), children: label2 })
4641
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: getClassNameLayer("title"), children: [
4642
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: getClassNameLayer("icon"), children: item.type === "Text" || item.type === "Heading" ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Type, { size: "16" }) : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(LayoutGrid, { size: "16" }) }),
4643
+ /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: getClassNameLayer("name"), children: label2 })
5987
4644
  ] })
5988
4645
  ]
5989
4646
  }
5990
4647
  ) }),
5991
- containsZone && Object.keys(zonesForItem).map((zoneKey, idx) => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassNameLayer("zones"), children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
4648
+ containsZone && Object.keys(zonesForItem).map((zoneKey, idx) => /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: getClassNameLayer("zones"), children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
5992
4649
  LayerTree,
5993
4650
  {
5994
4651
  config,
@@ -6011,7 +4668,7 @@ var LayerTree = ({
6011
4668
 
6012
4669
  // components/Puck/components/Outline/index.tsx
6013
4670
  var import_react30 = require("react");
6014
- var import_jsx_runtime35 = require("react/jsx-runtime");
4671
+ var import_jsx_runtime34 = require("react/jsx-runtime");
6015
4672
  var Outline = () => {
6016
4673
  const { dispatch, state, overrides, config } = useAppContext();
6017
4674
  const { data, ui } = state;
@@ -6026,8 +4683,8 @@ var Outline = () => {
6026
4683
  []
6027
4684
  );
6028
4685
  const Wrapper = (0, import_react30.useMemo)(() => overrides.outline || "div", [overrides]);
6029
- return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Wrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(dropZoneContext.Consumer, { children: (ctx) => /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_jsx_runtime35.Fragment, { children: [
6030
- (ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
4686
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Wrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(dropZoneContext.Consumer, { children: (ctx) => /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
4687
+ (ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
6031
4688
  LayerTree,
6032
4689
  {
6033
4690
  config,
@@ -6040,7 +4697,7 @@ var Outline = () => {
6040
4697
  ),
6041
4698
  Object.entries(findZonesForArea(data, "root")).map(
6042
4699
  ([zoneKey, zone]) => {
6043
- return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
4700
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
6044
4701
  LayerTree,
6045
4702
  {
6046
4703
  config,
@@ -6064,8 +4721,7 @@ var import_react_hotkeys_hook = require("react-hotkeys-hook");
6064
4721
  function usePuckHistory({
6065
4722
  dispatch,
6066
4723
  initialAppState,
6067
- historyStore,
6068
- iframeEnabled
4724
+ historyStore
6069
4725
  }) {
6070
4726
  const back = () => {
6071
4727
  var _a;
@@ -6083,16 +4739,6 @@ function usePuckHistory({
6083
4739
  historyStore.forward();
6084
4740
  }
6085
4741
  };
6086
- const backIframe = () => {
6087
- if (iframeEnabled) {
6088
- back();
6089
- }
6090
- };
6091
- const forwardIframe = () => {
6092
- if (iframeEnabled) {
6093
- forward();
6094
- }
6095
- };
6096
4742
  const setHistories = (histories) => {
6097
4743
  var _a;
6098
4744
  dispatch({
@@ -6111,23 +4757,9 @@ function usePuckHistory({
6111
4757
  historyStore.setHistoryIndex(index);
6112
4758
  }
6113
4759
  };
6114
- const frame = getFrame();
6115
- const resolvedFrame = typeof window !== "undefined" && frame !== document ? frame : void 0;
6116
4760
  (0, import_react_hotkeys_hook.useHotkeys)("meta+z", back, { preventDefault: true });
6117
4761
  (0, import_react_hotkeys_hook.useHotkeys)("meta+shift+z", forward, { preventDefault: true });
6118
4762
  (0, import_react_hotkeys_hook.useHotkeys)("meta+y", forward, { preventDefault: true });
6119
- (0, import_react_hotkeys_hook.useHotkeys)("meta+z", backIframe, {
6120
- preventDefault: true,
6121
- document: resolvedFrame
6122
- });
6123
- (0, import_react_hotkeys_hook.useHotkeys)("meta+shift+z", forwardIframe, {
6124
- preventDefault: true,
6125
- document: resolvedFrame
6126
- });
6127
- (0, import_react_hotkeys_hook.useHotkeys)("meta+y", forwardIframe, {
6128
- preventDefault: true,
6129
- document: resolvedFrame
6130
- });
6131
4763
  return {
6132
4764
  back,
6133
4765
  forward,
@@ -6278,24 +4910,24 @@ var parse = function parse2(raw) {
6278
4910
  !!isNaN(result) ? process.env.NODE_ENV !== "production" ? invariant(false, "Could not parse value [raw: " + raw + ", without suffix: " + value + "]") : invariant(false) : void 0;
6279
4911
  return result;
6280
4912
  };
6281
- var calculateBox = function calculateBox2(borderBox, styles2) {
4913
+ var calculateBox = function calculateBox2(borderBox, styles) {
6282
4914
  var margin = {
6283
- top: parse(styles2.marginTop),
6284
- right: parse(styles2.marginRight),
6285
- bottom: parse(styles2.marginBottom),
6286
- left: parse(styles2.marginLeft)
4915
+ top: parse(styles.marginTop),
4916
+ right: parse(styles.marginRight),
4917
+ bottom: parse(styles.marginBottom),
4918
+ left: parse(styles.marginLeft)
6287
4919
  };
6288
4920
  var padding = {
6289
- top: parse(styles2.paddingTop),
6290
- right: parse(styles2.paddingRight),
6291
- bottom: parse(styles2.paddingBottom),
6292
- left: parse(styles2.paddingLeft)
4921
+ top: parse(styles.paddingTop),
4922
+ right: parse(styles.paddingRight),
4923
+ bottom: parse(styles.paddingBottom),
4924
+ left: parse(styles.paddingLeft)
6293
4925
  };
6294
4926
  var border = {
6295
- top: parse(styles2.borderTopWidth),
6296
- right: parse(styles2.borderRightWidth),
6297
- bottom: parse(styles2.borderBottomWidth),
6298
- left: parse(styles2.borderLeftWidth)
4927
+ top: parse(styles.borderTopWidth),
4928
+ right: parse(styles.borderRightWidth),
4929
+ bottom: parse(styles.borderBottomWidth),
4930
+ left: parse(styles.borderLeftWidth)
6299
4931
  };
6300
4932
  return createBox({
6301
4933
  borderBox,
@@ -6306,8 +4938,8 @@ var calculateBox = function calculateBox2(borderBox, styles2) {
6306
4938
  };
6307
4939
  var getBox = function getBox2(el) {
6308
4940
  var borderBox = el.getBoundingClientRect();
6309
- var styles2 = window.getComputedStyle(el);
6310
- return calculateBox(borderBox, styles2);
4941
+ var styles = window.getComputedStyle(el);
4942
+ return calculateBox(borderBox, styles);
6311
4943
  };
6312
4944
 
6313
4945
  // components/Puck/components/Canvas/index.tsx
@@ -6322,11 +4954,11 @@ init_react_import();
6322
4954
  var styles_module_default20 = { "ViewportControls": "_ViewportControls_g1wgg_1", "ViewportControls-divider": "_ViewportControls-divider_g1wgg_15", "ViewportControls-zoomSelect": "_ViewportControls-zoomSelect_g1wgg_21", "ViewportButton--isActive": "_ViewportButton--isActive_g1wgg_34", "ViewportButton-inner": "_ViewportButton-inner_g1wgg_34" };
6323
4955
 
6324
4956
  // components/ViewportControls/index.tsx
6325
- var import_jsx_runtime36 = require("react/jsx-runtime");
4957
+ var import_jsx_runtime35 = require("react/jsx-runtime");
6326
4958
  var icons = {
6327
- Smartphone: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(Smartphone, { size: 16 }),
6328
- Tablet: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(Tablet, { size: 16 }),
6329
- Monitor: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(Monitor, { size: 16 })
4959
+ Smartphone: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Smartphone, { size: 16 }),
4960
+ Tablet: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Tablet, { size: 16 }),
4961
+ Monitor: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Monitor, { size: 16 })
6330
4962
  };
6331
4963
  var getClassName25 = get_class_name_factory_default("ViewportControls", styles_module_default20);
6332
4964
  var getClassNameButton = get_class_name_factory_default("ViewportButton", styles_module_default20);
@@ -6342,7 +4974,7 @@ var ViewportButton = ({
6342
4974
  (0, import_react32.useEffect)(() => {
6343
4975
  setIsActive(width === state.ui.viewports.current.width);
6344
4976
  }, [width, state.ui.viewports.current.width]);
6345
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
4977
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
6346
4978
  IconButton,
6347
4979
  {
6348
4980
  title,
@@ -6351,7 +4983,7 @@ var ViewportButton = ({
6351
4983
  e.stopPropagation();
6352
4984
  onClick({ width, height });
6353
4985
  },
6354
- children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: getClassNameButton("inner"), children })
4986
+ children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { className: getClassNameButton("inner"), children })
6355
4987
  }
6356
4988
  ) });
6357
4989
  };
@@ -6387,8 +5019,8 @@ var ViewportControls = ({
6387
5019
  ].filter((a) => a.value <= autoZoom).sort((a, b) => a.value > b.value ? 1 : -1),
6388
5020
  [autoZoom]
6389
5021
  );
6390
- return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: getClassName25(), children: [
6391
- viewports.map((viewport, i) => /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
5022
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: getClassName25(), children: [
5023
+ viewports.map((viewport, i) => /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
6392
5024
  ViewportButton,
6393
5025
  {
6394
5026
  height: viewport.height,
@@ -6399,8 +5031,8 @@ var ViewportControls = ({
6399
5031
  },
6400
5032
  i
6401
5033
  )),
6402
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: getClassName25("divider") }),
6403
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
5034
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: getClassName25("divider") }),
5035
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
6404
5036
  IconButton,
6405
5037
  {
6406
5038
  title: "Zoom viewport out",
@@ -6414,10 +5046,10 @@ var ViewportControls = ({
6414
5046
  )].value
6415
5047
  );
6416
5048
  },
6417
- children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ZoomOut, { size: 16 })
5049
+ children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(ZoomOut, { size: 16 })
6418
5050
  }
6419
5051
  ),
6420
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
5052
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
6421
5053
  IconButton,
6422
5054
  {
6423
5055
  title: "Zoom viewport in",
@@ -6431,11 +5063,11 @@ var ViewportControls = ({
6431
5063
  )].value
6432
5064
  );
6433
5065
  },
6434
- children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ZoomIn, { size: 16 })
5066
+ children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(ZoomIn, { size: 16 })
6435
5067
  }
6436
5068
  ),
6437
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: getClassName25("divider") }),
6438
- /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
5069
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: getClassName25("divider") }),
5070
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
6439
5071
  "select",
6440
5072
  {
6441
5073
  className: getClassName25("zoomSelect"),
@@ -6443,7 +5075,7 @@ var ViewportControls = ({
6443
5075
  onChange: (e) => {
6444
5076
  onZoom(parseFloat(e.currentTarget.value));
6445
5077
  },
6446
- children: zoomOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
5078
+ children: zoomOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
6447
5079
  "option",
6448
5080
  {
6449
5081
  value: option.value,
@@ -6458,7 +5090,7 @@ var ViewportControls = ({
6458
5090
 
6459
5091
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Canvas/styles.module.css#css-module
6460
5092
  init_react_import();
6461
- var styles_module_default21 = { "PuckCanvas": "_PuckCanvas_18jay_1", "PuckCanvas-controls": "_PuckCanvas-controls_18jay_16", "PuckCanvas-inner": "_PuckCanvas-inner_18jay_21", "PuckCanvas-root": "_PuckCanvas-root_18jay_30", "PuckCanvas--ready": "_PuckCanvas--ready_18jay_55", "PuckCanvas-loader": "_PuckCanvas-loader_18jay_60", "PuckCanvas--showLoader": "_PuckCanvas--showLoader_18jay_70" };
5093
+ var styles_module_default21 = { "PuckCanvas": "_PuckCanvas_avf1c_1", "PuckCanvas-controls": "_PuckCanvas-controls_avf1c_16", "PuckCanvas-inner": "_PuckCanvas-inner_avf1c_21", "PuckCanvas-root": "_PuckCanvas-root_avf1c_32", "PuckCanvas--ready": "_PuckCanvas--ready_avf1c_57", "PuckCanvas-loader": "_PuckCanvas-loader_avf1c_62", "PuckCanvas--showLoader": "_PuckCanvas--showLoader_avf1c_72" };
6462
5094
 
6463
5095
  // lib/get-zoom-config.ts
6464
5096
  init_react_import();
@@ -6491,7 +5123,7 @@ var getZoomConfig = (uiViewport, frame, zoom) => {
6491
5123
  };
6492
5124
 
6493
5125
  // components/Puck/components/Canvas/index.tsx
6494
- var import_jsx_runtime37 = require("react/jsx-runtime");
5126
+ var import_jsx_runtime36 = require("react/jsx-runtime");
6495
5127
  var getClassName26 = get_class_name_factory_default("PuckCanvas", styles_module_default21);
6496
5128
  var ZOOM_ON_CHANGE = true;
6497
5129
  var Canvas = () => {
@@ -6501,7 +5133,7 @@ var Canvas = () => {
6501
5133
  const frameRef = (0, import_react33.useRef)(null);
6502
5134
  const [showTransition, setShowTransition] = (0, import_react33.useState)(false);
6503
5135
  const defaultRender = (0, import_react33.useMemo)(() => {
6504
- const PuckDefault = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_jsx_runtime37.Fragment, { children });
5136
+ const PuckDefault = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_jsx_runtime36.Fragment, { children });
6505
5137
  return PuckDefault;
6506
5138
  }, []);
6507
5139
  const CustomPreview = (0, import_react33.useMemo)(
@@ -6545,13 +5177,15 @@ var Canvas = () => {
6545
5177
  }
6546
5178
  }, [ui.viewports.current.width]);
6547
5179
  (0, import_react33.useEffect)(() => {
6548
- const cb = () => {
5180
+ const observer = new ResizeObserver(() => {
6549
5181
  setShowTransition(false);
6550
5182
  resetAutoZoom();
6551
- };
6552
- window.addEventListener("resize", cb);
5183
+ });
5184
+ if (document.body) {
5185
+ observer.observe(document.body);
5186
+ }
6553
5187
  return () => {
6554
- window.removeEventListener("resize", cb);
5188
+ observer.disconnect();
6555
5189
  };
6556
5190
  }, []);
6557
5191
  const [showLoader, setShowLoader] = (0, import_react33.useState)(false);
@@ -6560,7 +5194,7 @@ var Canvas = () => {
6560
5194
  setShowLoader(true);
6561
5195
  }, 500);
6562
5196
  }, []);
6563
- return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)(
5197
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)(
6564
5198
  "div",
6565
5199
  {
6566
5200
  className: getClassName26({
@@ -6573,7 +5207,7 @@ var Canvas = () => {
6573
5207
  recordHistory: true
6574
5208
  }),
6575
5209
  children: [
6576
- ui.viewports.controlsVisible && iframe.enabled && /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: getClassName26("controls"), children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
5210
+ ui.viewports.controlsVisible && iframe.enabled && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: getClassName26("controls"), children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
6577
5211
  ViewportControls,
6578
5212
  {
6579
5213
  autoZoom: zoomConfig.autoZoom,
@@ -6585,8 +5219,7 @@ var Canvas = () => {
6585
5219
  zoom: zoomConfig.zoom
6586
5220
  });
6587
5221
  const newUi = __spreadProps(__spreadValues({}, ui), {
6588
- viewports: __spreadProps(__spreadValues({}, ui.viewports), { current: uiViewport }),
6589
- itemSelector: null
5222
+ viewports: __spreadProps(__spreadValues({}, ui.viewports), { current: uiViewport })
6590
5223
  });
6591
5224
  setUi(newUi);
6592
5225
  if (ZOOM_ON_CHANGE) {
@@ -6599,8 +5232,8 @@ var Canvas = () => {
6599
5232
  }
6600
5233
  }
6601
5234
  ) }),
6602
- /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("div", { className: getClassName26("inner"), ref: frameRef, children: [
6603
- /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
5235
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: getClassName26("inner"), ref: frameRef, children: [
5236
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
6604
5237
  "div",
6605
5238
  {
6606
5239
  className: getClassName26("root"),
@@ -6612,25 +5245,51 @@ var Canvas = () => {
6612
5245
  overflow: iframe.enabled ? void 0 : "auto"
6613
5246
  },
6614
5247
  suppressHydrationWarning: true,
6615
- id: "puck-canvas-root",
6616
- onTransitionEnd: () => {
6617
- window.dispatchEvent(
6618
- new CustomEvent("viewportchange", {
6619
- bubbles: true,
6620
- cancelable: false
6621
- })
6622
- );
6623
- },
6624
- children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(CustomPreview, { children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Preview, {}) })
5248
+ children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(CustomPreview, { children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(Preview, {}) })
6625
5249
  }
6626
5250
  ),
6627
- /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: getClassName26("loader"), children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Loader, { size: 24 }) })
5251
+ /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: getClassName26("loader"), children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(Loader, { size: 24 }) })
6628
5252
  ] })
6629
5253
  ]
6630
5254
  }
6631
5255
  );
6632
5256
  };
6633
5257
 
5258
+ // lib/insert-component.ts
5259
+ init_react_import();
5260
+ var insertComponent = (componentType, zone, index, {
5261
+ config,
5262
+ dispatch,
5263
+ resolveData,
5264
+ state
5265
+ }) => {
5266
+ const id = generateId(componentType);
5267
+ const insertActionData = {
5268
+ type: "insert",
5269
+ componentType,
5270
+ destinationIndex: index,
5271
+ destinationZone: zone,
5272
+ id
5273
+ };
5274
+ const insertedData = insertAction(state.data, insertActionData, config);
5275
+ dispatch(__spreadProps(__spreadValues({}, insertActionData), {
5276
+ // Dispatch insert rather set, as user's may rely on this via onAction
5277
+ // We must always record history here so the insert is added to user history
5278
+ // If the user has defined a resolveData method, they will end up with 2 history
5279
+ // entries on insert - one for the initial insert, and one when the data resolves
5280
+ recordHistory: true
5281
+ }));
5282
+ const itemSelector = {
5283
+ index,
5284
+ zone
5285
+ };
5286
+ dispatch({ type: "setUi", ui: { itemSelector } });
5287
+ resolveData({
5288
+ data: insertedData,
5289
+ ui: __spreadProps(__spreadValues({}, state.ui), { itemSelector })
5290
+ });
5291
+ };
5292
+
6634
5293
  // lib/use-loaded-overrides.ts
6635
5294
  init_react_import();
6636
5295
  var import_react34 = require("react");
@@ -6679,79 +5338,11 @@ var useLoadedOverrides = ({
6679
5338
 
6680
5339
  // components/DefaultOverride/index.tsx
6681
5340
  init_react_import();
6682
- var import_jsx_runtime38 = require("react/jsx-runtime");
6683
- var DefaultOverride = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_jsx_runtime38.Fragment, { children });
6684
-
6685
- // components/Puck/index.tsx
6686
- var import_dom2 = require("@dnd-kit/dom");
6687
-
6688
- // lib/use-inject-css.ts
6689
- init_react_import();
6690
- var import_react35 = require("react");
6691
- var styles = `
6692
- /* Prevent user from interacting with underlying component */
6693
- [data-puck-component] * {
6694
- pointer-events: none;
6695
- user-select: none;
6696
- -webkit-user-select: none;
6697
- }
6698
-
6699
- [data-puck-component] {
6700
- cursor: grab;
6701
- pointer-events: auto !important;
6702
- user-select: none;
6703
- -webkit-user-select: none;
6704
- }
6705
-
6706
- [data-puck-disabled] {
6707
- cursor: pointer;
6708
- }
6709
-
6710
- /* Placeholder */
6711
- [data-puck-dragging]:not([data-dnd-dragging]) {
6712
- background: var(--puck-color-azure-06) !important;
6713
- border: none !important;
6714
- color: #00000000 !important;
6715
- opacity: 0.3 !important;
6716
- outline: none !important;
6717
- transition: none !important;
6718
- }
6719
-
6720
- [data-puck-dragging]:not([data-dnd-dragging]) *, [data-puck-dragging]:not([data-dnd-dragging])::after, [data-puck-dragging]:not([data-dnd-dragging])::before {
6721
- opacity: 0 !important;
6722
- }
6723
-
6724
- [data-dnd-dragging] {
6725
- pointer-events: none !important;
6726
- outline: 2px var(--puck-color-azure-09) solid !important;
6727
- outline-offset: -2px !important;
6728
- }
6729
- `;
6730
- var useInjectStyleSheet = (initialStyles, iframeEnabled) => {
6731
- const [el, setEl] = (0, import_react35.useState)();
6732
- (0, import_react35.useEffect)(() => {
6733
- setEl(document.createElement("style"));
6734
- }, []);
6735
- (0, import_react35.useEffect)(() => {
6736
- var _a;
6737
- if (!el || typeof window === "undefined") {
6738
- return;
6739
- }
6740
- el.innerHTML = initialStyles;
6741
- if (iframeEnabled) {
6742
- const frame = getFrame();
6743
- (_a = frame == null ? void 0 : frame.head) == null ? void 0 : _a.appendChild(el);
6744
- }
6745
- document.head.appendChild(el);
6746
- }, [iframeEnabled, el]);
6747
- return el;
6748
- };
6749
- var useInjectGlobalCss = (iframeEnabled) => {
6750
- return useInjectStyleSheet(styles, iframeEnabled);
6751
- };
5341
+ var import_jsx_runtime37 = require("react/jsx-runtime");
5342
+ var DefaultOverride = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_jsx_runtime37.Fragment, { children });
6752
5343
 
6753
5344
  // components/Puck/index.tsx
6754
- var import_jsx_runtime39 = require("react/jsx-runtime");
5345
+ var import_jsx_runtime38 = require("react/jsx-runtime");
6755
5346
  var getClassName27 = get_class_name_factory_default("Puck", styles_module_default15);
6756
5347
  var getLayoutClassName = get_class_name_factory_default("PuckLayout", styles_module_default15);
6757
5348
  function Puck({
@@ -6774,14 +5365,13 @@ function Puck({
6774
5365
  dnd,
6775
5366
  initialHistory: _initialHistory
6776
5367
  }) {
6777
- var _a, _b;
5368
+ var _a;
6778
5369
  const iframe = __spreadValues({
6779
5370
  enabled: true,
6780
5371
  waitForStyles: true
6781
5372
  }, _iframe);
6782
- useInjectGlobalCss(iframe.enabled);
6783
- const [generatedAppState] = (0, import_react36.useState)(() => {
6784
- var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
5373
+ const [generatedAppState] = (0, import_react35.useState)(() => {
5374
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
6785
5375
  const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
6786
5376
  let clientUiState = {};
6787
5377
  if (typeof window !== "undefined") {
@@ -6801,7 +5391,7 @@ function Puck({
6801
5391
  clientUiState = __spreadProps(__spreadValues({}, clientUiState), {
6802
5392
  viewports: __spreadProps(__spreadValues({}, initial.viewports), {
6803
5393
  current: __spreadProps(__spreadValues({}, initial.viewports.current), {
6804
- height: ((_b2 = (_a2 = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _a2.current) == null ? void 0 : _b2.height) || ((_c = viewports[closestViewport]) == null ? void 0 : _c.height) || "auto",
5394
+ height: ((_b = (_a2 = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _a2.current) == null ? void 0 : _b.height) || ((_c = viewports[closestViewport]) == null ? void 0 : _c.height) || "auto",
6805
5395
  width: ((_e = (_d = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _d.current) == null ? void 0 : _e.width) || ((_f = viewports[closestViewport]) == null ? void 0 : _f.width)
6806
5396
  })
6807
5397
  })
@@ -6852,32 +5442,40 @@ function Puck({
6852
5442
  histories,
6853
5443
  index: initialHistoryIndex
6854
5444
  });
6855
- const [reducer] = (0, import_react36.useState)(
5445
+ const [reducer] = (0, import_react35.useState)(
6856
5446
  () => createReducer({
6857
5447
  config,
6858
5448
  record: historyStore.record,
6859
5449
  onAction
6860
5450
  })
6861
5451
  );
6862
- const [appState, dispatch] = (0, import_react36.useReducer)(
5452
+ const [appState, dispatch] = (0, import_react35.useReducer)(
6863
5453
  reducer,
6864
5454
  flushZones(initialAppState)
6865
5455
  );
6866
5456
  const { data, ui } = appState;
6867
- const history = usePuckHistory({
6868
- dispatch,
6869
- initialAppState,
6870
- historyStore,
6871
- iframeEnabled: (_a = _iframe == null ? void 0 : _iframe.enabled) != null ? _a : true
6872
- });
6873
- const [menuOpen, setMenuOpen] = (0, import_react36.useState)(false);
5457
+ const history = usePuckHistory({ dispatch, initialAppState, historyStore });
5458
+ const [menuOpen, setMenuOpen] = (0, import_react35.useState)(false);
6874
5459
  const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
5460
+ const setItemSelector = (0, import_react35.useCallback)(
5461
+ (newItemSelector) => {
5462
+ if (newItemSelector === itemSelector) return;
5463
+ dispatch({
5464
+ type: "setUi",
5465
+ ui: { itemSelector: newItemSelector },
5466
+ recordHistory: true
5467
+ });
5468
+ },
5469
+ [itemSelector]
5470
+ );
6875
5471
  const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
6876
- (0, import_react36.useEffect)(() => {
5472
+ (0, import_react35.useEffect)(() => {
6877
5473
  if (onChange) onChange(data);
6878
5474
  }, [data]);
5475
+ const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
5476
+ const [draggedItem, setDraggedItem] = (0, import_react35.useState)();
6879
5477
  const rootProps = data.root.props || data.root;
6880
- const toggleSidebars = (0, import_react36.useCallback)(
5478
+ const toggleSidebars = (0, import_react35.useCallback)(
6881
5479
  (sidebar) => {
6882
5480
  const widerViewport = window.matchMedia("(min-width: 638px)").matches;
6883
5481
  const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
@@ -6891,7 +5489,7 @@ function Puck({
6891
5489
  },
6892
5490
  [dispatch, leftSideBarVisible, rightSideBarVisible]
6893
5491
  );
6894
- (0, import_react36.useEffect)(() => {
5492
+ (0, import_react35.useEffect)(() => {
6895
5493
  if (!window.matchMedia("(min-width: 638px)").matches) {
6896
5494
  dispatch({
6897
5495
  type: "setUi",
@@ -6914,28 +5512,28 @@ function Puck({
6914
5512
  window.removeEventListener("resize", handleResize);
6915
5513
  };
6916
5514
  }, []);
6917
- const defaultHeaderRender = (0, import_react36.useMemo)(() => {
5515
+ const defaultHeaderRender = (0, import_react35.useMemo)(() => {
6918
5516
  if (renderHeader) {
6919
5517
  console.warn(
6920
5518
  "`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
6921
5519
  );
6922
5520
  const RenderHeader = (_a2) => {
6923
- var _b2 = _a2, { actions } = _b2, props = __objRest(_b2, ["actions"]);
5521
+ var _b = _a2, { actions } = _b, props = __objRest(_b, ["actions"]);
6924
5522
  const Comp = renderHeader;
6925
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState, children: actions }));
5523
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState, children: actions }));
6926
5524
  };
6927
5525
  return RenderHeader;
6928
5526
  }
6929
5527
  return DefaultOverride;
6930
5528
  }, [renderHeader]);
6931
- const defaultHeaderActionsRender = (0, import_react36.useMemo)(() => {
5529
+ const defaultHeaderActionsRender = (0, import_react35.useMemo)(() => {
6932
5530
  if (renderHeaderActions) {
6933
5531
  console.warn(
6934
5532
  "`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
6935
5533
  );
6936
5534
  const RenderHeader = (props) => {
6937
5535
  const Comp = renderHeaderActions;
6938
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState }));
5536
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState }));
6939
5537
  };
6940
5538
  return RenderHeader;
6941
5539
  }
@@ -6945,27 +5543,26 @@ function Puck({
6945
5543
  overrides,
6946
5544
  plugins
6947
5545
  });
6948
- const CustomPuck = (0, import_react36.useMemo)(
5546
+ const CustomPuck = (0, import_react35.useMemo)(
6949
5547
  () => loadedOverrides.puck || DefaultOverride,
6950
5548
  [loadedOverrides]
6951
5549
  );
6952
- const CustomHeader = (0, import_react36.useMemo)(
5550
+ const CustomHeader = (0, import_react35.useMemo)(
6953
5551
  () => loadedOverrides.header || defaultHeaderRender,
6954
5552
  [loadedOverrides]
6955
5553
  );
6956
- const CustomHeaderActions = (0, import_react36.useMemo)(
5554
+ const CustomHeaderActions = (0, import_react35.useMemo)(
6957
5555
  () => loadedOverrides.headerActions || defaultHeaderActionsRender,
6958
5556
  [loadedOverrides]
6959
5557
  );
6960
- const [mounted, setMounted] = (0, import_react36.useState)(false);
6961
- (0, import_react36.useEffect)(() => {
5558
+ const [mounted, setMounted] = (0, import_react35.useState)(false);
5559
+ (0, import_react35.useEffect)(() => {
6962
5560
  setMounted(true);
6963
5561
  }, []);
6964
5562
  const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
6965
- const selectedComponentLabel = selectedItem ? (_b = selectedComponentConfig == null ? void 0 : selectedComponentConfig["label"]) != null ? _b : selectedItem.type.toString() : "";
6966
- const [manager] = (0, import_react36.useState)(new import_dom2.DragDropManager({ plugins: [import_dom2.Feedback] }));
6967
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: `Puck ${getClassName27()}`, children: [
6968
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
5563
+ const selectedComponentLabel = selectedItem ? (_a = selectedComponentConfig == null ? void 0 : selectedComponentConfig["label"]) != null ? _a : selectedItem.type.toString() : "";
5564
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: `Puck ${getClassName27()}`, children: [
5565
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
6969
5566
  AppProvider,
6970
5567
  {
6971
5568
  value: {
@@ -6987,133 +5584,233 @@ function Puck({
6987
5584
  getPermissions: () => ({}),
6988
5585
  refreshPermissions: () => null
6989
5586
  },
6990
- children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(DragDropContext2, { children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(CustomPuck, { children: children || /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
6991
- "div",
5587
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(appContext.Consumer, { children: ({ resolveData }) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5588
+ DragDropContext,
6992
5589
  {
6993
- className: getLayoutClassName({
6994
- leftSideBarVisible,
6995
- menuOpen,
6996
- mounted,
6997
- rightSideBarVisible
6998
- }),
6999
- children: /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: getLayoutClassName("inner"), children: [
7000
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7001
- CustomHeader,
7002
- {
7003
- actions: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_jsx_runtime39.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(CustomHeaderActions, { children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7004
- Button,
7005
- {
7006
- onClick: () => {
7007
- onPublish && onPublish(data);
7008
- },
7009
- icon: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Globe, { size: "14px" }),
7010
- children: "Publish"
7011
- }
7012
- ) }) }),
7013
- children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("header", { className: getLayoutClassName("header"), children: /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: getLayoutClassName("headerInner"), children: [
7014
- /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: getLayoutClassName("headerToggle"), children: [
7015
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7016
- "div",
7017
- {
7018
- className: getLayoutClassName("leftSideBarToggle"),
7019
- children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7020
- IconButton,
7021
- {
7022
- onClick: () => {
7023
- toggleSidebars("left");
7024
- },
7025
- title: "Toggle left sidebar",
7026
- children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(PanelLeft, { focusable: "false" })
7027
- }
7028
- )
7029
- }
7030
- ),
7031
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7032
- "div",
7033
- {
7034
- className: getLayoutClassName("rightSideBarToggle"),
7035
- children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7036
- IconButton,
7037
- {
7038
- onClick: () => {
7039
- toggleSidebars("right");
7040
- },
7041
- title: "Toggle right sidebar",
7042
- children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(PanelRight, { focusable: "false" })
7043
- }
7044
- )
7045
- }
7046
- )
7047
- ] }),
7048
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: getLayoutClassName("headerTitle"), children: /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(Heading, { rank: "2", size: "xs", children: [
7049
- headerTitle || rootProps.title || "Page",
7050
- headerPath && /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(import_jsx_runtime39.Fragment, { children: [
7051
- " ",
7052
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7053
- "code",
7054
- {
7055
- className: getLayoutClassName("headerPath"),
7056
- children: headerPath
7057
- }
7058
- )
7059
- ] })
7060
- ] }) }),
7061
- /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: getLayoutClassName("headerTools"), children: [
7062
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: getLayoutClassName("menuButton"), children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7063
- IconButton,
7064
- {
7065
- onClick: () => {
7066
- return setMenuOpen(!menuOpen);
7067
- },
7068
- title: "Toggle menu bar",
7069
- children: menuOpen ? /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(ChevronUp, { focusable: "false" }) : /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(ChevronDown, { focusable: "false" })
7070
- }
7071
- ) }),
7072
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7073
- MenuBar,
5590
+ autoScrollerOptions: { disabled: dnd == null ? void 0 : dnd.disableAutoScroll },
5591
+ onDragUpdate: (update) => {
5592
+ setDraggedItem(__spreadValues(__spreadValues({}, draggedItem), update));
5593
+ onDragStartOrUpdate(update);
5594
+ },
5595
+ onBeforeDragStart: (start) => {
5596
+ onDragStartOrUpdate(start);
5597
+ setItemSelector(null);
5598
+ dispatch({ type: "setUi", ui: { isDragging: true } });
5599
+ },
5600
+ onDragEnd: (droppedItem) => {
5601
+ setDraggedItem(void 0);
5602
+ dispatch({ type: "setUi", ui: { isDragging: false } });
5603
+ if (!droppedItem.destination) {
5604
+ return;
5605
+ }
5606
+ if (droppedItem.source.droppableId.startsWith("component-list") && droppedItem.destination) {
5607
+ const [_, componentType] = droppedItem.draggableId.split("::");
5608
+ insertComponent(
5609
+ componentType || droppedItem.draggableId,
5610
+ droppedItem.destination.droppableId,
5611
+ droppedItem.destination.index,
5612
+ { config, dispatch, resolveData, state: appState }
5613
+ );
5614
+ return;
5615
+ } else {
5616
+ const { source, destination } = droppedItem;
5617
+ if (source.droppableId === destination.droppableId) {
5618
+ dispatch({
5619
+ type: "reorder",
5620
+ sourceIndex: source.index,
5621
+ destinationIndex: destination.index,
5622
+ destinationZone: destination.droppableId
5623
+ });
5624
+ } else {
5625
+ dispatch({
5626
+ type: "move",
5627
+ sourceZone: source.droppableId,
5628
+ sourceIndex: source.index,
5629
+ destinationIndex: destination.index,
5630
+ destinationZone: destination.droppableId
5631
+ });
5632
+ }
5633
+ setItemSelector({
5634
+ index: destination.index,
5635
+ zone: destination.droppableId
5636
+ });
5637
+ }
5638
+ },
5639
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5640
+ DropZoneProvider,
5641
+ {
5642
+ value: {
5643
+ data,
5644
+ itemSelector,
5645
+ setItemSelector,
5646
+ config,
5647
+ dispatch,
5648
+ draggedItem,
5649
+ placeholderStyle,
5650
+ mode: "edit",
5651
+ areaId: "root"
5652
+ },
5653
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CustomPuck, { children: children || /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5654
+ "div",
5655
+ {
5656
+ className: getLayoutClassName({
5657
+ leftSideBarVisible,
5658
+ menuOpen,
5659
+ mounted,
5660
+ rightSideBarVisible
5661
+ }),
5662
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: getLayoutClassName("inner"), children: [
5663
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5664
+ CustomHeader,
7074
5665
  {
7075
- appState,
7076
- dispatch,
7077
- onPublish,
7078
- menuOpen,
7079
- renderHeaderActions: () => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(CustomHeaderActions, { children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
5666
+ actions: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_jsx_runtime38.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CustomHeaderActions, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
7080
5667
  Button,
7081
5668
  {
7082
5669
  onClick: () => {
7083
5670
  onPublish && onPublish(data);
7084
5671
  },
7085
- icon: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Globe, { size: "14px" }),
5672
+ icon: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Globe, { size: "14px" }),
7086
5673
  children: "Publish"
7087
5674
  }
7088
- ) }),
7089
- setMenuOpen
5675
+ ) }) }),
5676
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("header", { className: getLayoutClassName("header"), children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: getLayoutClassName("headerInner"), children: [
5677
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
5678
+ "div",
5679
+ {
5680
+ className: getLayoutClassName("headerToggle"),
5681
+ children: [
5682
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5683
+ "div",
5684
+ {
5685
+ className: getLayoutClassName(
5686
+ "leftSideBarToggle"
5687
+ ),
5688
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5689
+ IconButton,
5690
+ {
5691
+ onClick: () => {
5692
+ toggleSidebars("left");
5693
+ },
5694
+ title: "Toggle left sidebar",
5695
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(PanelLeft, { focusable: "false" })
5696
+ }
5697
+ )
5698
+ }
5699
+ ),
5700
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5701
+ "div",
5702
+ {
5703
+ className: getLayoutClassName(
5704
+ "rightSideBarToggle"
5705
+ ),
5706
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5707
+ IconButton,
5708
+ {
5709
+ onClick: () => {
5710
+ toggleSidebars("right");
5711
+ },
5712
+ title: "Toggle right sidebar",
5713
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(PanelRight, { focusable: "false" })
5714
+ }
5715
+ )
5716
+ }
5717
+ )
5718
+ ]
5719
+ }
5720
+ ),
5721
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5722
+ "div",
5723
+ {
5724
+ className: getLayoutClassName("headerTitle"),
5725
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(Heading, { rank: "2", size: "xs", children: [
5726
+ headerTitle || rootProps.title || "Page",
5727
+ headerPath && /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(import_jsx_runtime38.Fragment, { children: [
5728
+ " ",
5729
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5730
+ "code",
5731
+ {
5732
+ className: getLayoutClassName(
5733
+ "headerPath"
5734
+ ),
5735
+ children: headerPath
5736
+ }
5737
+ )
5738
+ ] })
5739
+ ] })
5740
+ }
5741
+ ),
5742
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
5743
+ "div",
5744
+ {
5745
+ className: getLayoutClassName("headerTools"),
5746
+ children: [
5747
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5748
+ "div",
5749
+ {
5750
+ className: getLayoutClassName("menuButton"),
5751
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5752
+ IconButton,
5753
+ {
5754
+ onClick: () => {
5755
+ return setMenuOpen(!menuOpen);
5756
+ },
5757
+ title: "Toggle menu bar",
5758
+ children: menuOpen ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ChevronUp, { focusable: "false" }) : /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ChevronDown, { focusable: "false" })
5759
+ }
5760
+ )
5761
+ }
5762
+ ),
5763
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5764
+ MenuBar,
5765
+ {
5766
+ appState,
5767
+ dispatch,
5768
+ onPublish,
5769
+ menuOpen,
5770
+ renderHeaderActions: () => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CustomHeaderActions, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5771
+ Button,
5772
+ {
5773
+ onClick: () => {
5774
+ onPublish && onPublish(data);
5775
+ },
5776
+ icon: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Globe, { size: "14px" }),
5777
+ children: "Publish"
5778
+ }
5779
+ ) }),
5780
+ setMenuOpen
5781
+ }
5782
+ )
5783
+ ]
5784
+ }
5785
+ )
5786
+ ] }) })
7090
5787
  }
7091
- )
5788
+ ),
5789
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: getLayoutClassName("leftSideBar"), children: [
5790
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(SidebarSection, { title: "Components", noBorderTop: true, children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Components, {}) }),
5791
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(SidebarSection, { title: "Outline", children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Outline, {}) })
5792
+ ] }),
5793
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Canvas, {}),
5794
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: getLayoutClassName("rightSideBar"), children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
5795
+ SidebarSection,
5796
+ {
5797
+ noPadding: true,
5798
+ noBorderTop: true,
5799
+ showBreadcrumbs: true,
5800
+ title: selectedItem ? selectedComponentLabel : "Page",
5801
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Fields, {})
5802
+ }
5803
+ ) })
7092
5804
  ] })
7093
- ] }) })
7094
- }
7095
- ),
7096
- /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: getLayoutClassName("leftSideBar"), children: [
7097
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(SidebarSection, { title: "Components", noBorderTop: true, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Components, {}) }),
7098
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(SidebarSection, { title: "Outline", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Outline, {}) })
7099
- ] }),
7100
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Canvas, {}),
7101
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: getLayoutClassName("rightSideBar"), children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
7102
- SidebarSection,
7103
- {
7104
- noPadding: true,
7105
- noBorderTop: true,
7106
- showBreadcrumbs: true,
7107
- title: selectedItem ? selectedComponentLabel : "Page",
7108
- children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Fields, {})
7109
- }
7110
- ) })
7111
- ] })
5805
+ }
5806
+ ) })
5807
+ }
5808
+ )
7112
5809
  }
7113
- ) }) })
5810
+ ) })
7114
5811
  }
7115
5812
  ),
7116
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { id: "puck-portal-root", className: getClassName27("portal") })
5813
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { id: "puck-portal-root", className: getClassName27("portal") })
7117
5814
  ] });
7118
5815
  }
7119
5816
  Puck.Components = Components;
@@ -7123,7 +5820,7 @@ Puck.Preview = Preview;
7123
5820
 
7124
5821
  // components/Render/index.tsx
7125
5822
  init_react_import();
7126
- var import_jsx_runtime40 = require("react/jsx-runtime");
5823
+ var import_jsx_runtime39 = require("react/jsx-runtime");
7127
5824
  function Render({
7128
5825
  config,
7129
5826
  data
@@ -7136,45 +5833,21 @@ function Render({
7136
5833
  const rootProps = defaultedData.root.props || defaultedData.root;
7137
5834
  const title = (rootProps == null ? void 0 : rootProps.title) || "";
7138
5835
  if ((_a = config.root) == null ? void 0 : _a.render) {
7139
- return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
7140
- DropZoneProvider,
7141
- {
7142
- value: {
7143
- data: defaultedData,
7144
- config,
7145
- mode: "render",
7146
- depth: 0,
7147
- path: []
5836
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(DropZoneProvider, { value: { data: defaultedData, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
5837
+ config.root.render,
5838
+ __spreadProps(__spreadValues({}, rootProps), {
5839
+ puck: {
5840
+ renderDropZone: DropZone,
5841
+ isEditing: false
7148
5842
  },
7149
- children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
7150
- config.root.render,
7151
- __spreadProps(__spreadValues({}, rootProps), {
7152
- puck: {
7153
- renderDropZone: DropZone,
7154
- isEditing: false
7155
- },
7156
- title,
7157
- editMode: false,
7158
- id: "puck-root",
7159
- children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(DropZone, { zone: rootDroppableId })
7160
- })
7161
- )
7162
- }
7163
- );
5843
+ title,
5844
+ editMode: false,
5845
+ id: "puck-root",
5846
+ children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(DropZone, { zone: rootDroppableId })
5847
+ })
5848
+ ) });
7164
5849
  }
7165
- return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
7166
- DropZoneProvider,
7167
- {
7168
- value: {
7169
- data: defaultedData,
7170
- config,
7171
- mode: "render",
7172
- depth: 0,
7173
- path: []
7174
- },
7175
- children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(DropZone, { zone: rootDroppableId })
7176
- }
7177
- );
5850
+ return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(DropZoneProvider, { value: { data: defaultedData, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(DropZone, { zone: rootDroppableId }) });
7178
5851
  }
7179
5852
 
7180
5853
  // lib/migrate.ts
@@ -7286,6 +5959,11 @@ var usePuck = () => {
7286
5959
  getPermissions,
7287
5960
  refreshPermissions
7288
5961
  } = useAppContext();
5962
+ if (dispatch === defaultContext.dispatch) {
5963
+ throw new Error(
5964
+ "usePuck was used outside of the <Puck> component. The usePuck hook must be rendered within the <Puck> context as children, overrides or plugins as described in https://puckeditor.com/docs/api-reference/functions/use-puck."
5965
+ );
5966
+ }
7289
5967
  return {
7290
5968
  appState,
7291
5969
  config,