@measured/puck 0.9.1-canary.f4e8d4a → 0.10.0-canary.18b3473

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -327,7 +327,7 @@ var require_react_is_development = __commonJS({
327
327
  var ContextProvider = REACT_PROVIDER_TYPE;
328
328
  var Element = REACT_ELEMENT_TYPE;
329
329
  var ForwardRef = REACT_FORWARD_REF_TYPE;
330
- var Fragment9 = REACT_FRAGMENT_TYPE;
330
+ var Fragment11 = REACT_FRAGMENT_TYPE;
331
331
  var Lazy = REACT_LAZY_TYPE;
332
332
  var Memo = REACT_MEMO_TYPE;
333
333
  var Portal = REACT_PORTAL_TYPE;
@@ -386,7 +386,7 @@ var require_react_is_development = __commonJS({
386
386
  exports.ContextProvider = ContextProvider;
387
387
  exports.Element = Element;
388
388
  exports.ForwardRef = ForwardRef;
389
- exports.Fragment = Fragment9;
389
+ exports.Fragment = Fragment11;
390
390
  exports.Lazy = Lazy;
391
391
  exports.Memo = Memo;
392
392
  exports.Portal = Portal;
@@ -760,7 +760,7 @@ var require_factoryWithTypeCheckers = __commonJS({
760
760
  function validate(props, propName, componentName, location, propFullName) {
761
761
  if (!(props[propName] instanceof expectedClass)) {
762
762
  var expectedClassName = expectedClass.name || ANONYMOUS;
763
- var actualClassName = getClassName11(props[propName]);
763
+ var actualClassName = getClassName18(props[propName]);
764
764
  return new PropTypeError("Invalid " + location + " `" + propFullName + "` of type " + ("`" + actualClassName + "` supplied to `" + componentName + "`, expected ") + ("instance of `" + expectedClassName + "`."));
765
765
  }
766
766
  return null;
@@ -1012,7 +1012,7 @@ var require_factoryWithTypeCheckers = __commonJS({
1012
1012
  return type;
1013
1013
  }
1014
1014
  }
1015
- function getClassName11(propValue) {
1015
+ function getClassName18(propValue) {
1016
1016
  if (!propValue.constructor || !propValue.constructor.name) {
1017
1017
  return ANONYMOUS;
1018
1018
  }
@@ -1214,11 +1214,11 @@ var Button = ({
1214
1214
 
1215
1215
  // components/DropZone/index.tsx
1216
1216
  init_react_import();
1217
- var import_react21 = require("react");
1217
+ var import_react22 = require("react");
1218
1218
 
1219
1219
  // components/DraggableComponent/index.tsx
1220
1220
  init_react_import();
1221
- var import_react18 = require("react");
1221
+ var import_react19 = require("react");
1222
1222
  var import_react_beautiful_dnd = require("react-beautiful-dnd");
1223
1223
 
1224
1224
  // css-module:/home/runner/work/puck/puck/packages/core/components/DraggableComponent/styles.module.css#css-module
@@ -2130,7 +2130,7 @@ List.propTypes = {
2130
2130
  List.displayName = "List";
2131
2131
  var list_default = List;
2132
2132
 
2133
- // ../../node_modules/react-feather/dist/icons/sidebar.js
2133
+ // ../../node_modules/react-feather/dist/icons/plus.js
2134
2134
  init_react_import();
2135
2135
  var import_react14 = __toESM(require("react"));
2136
2136
  var import_prop_types12 = __toESM(require_prop_types());
@@ -2180,7 +2180,7 @@ function _objectWithoutPropertiesLoose12(source, excluded) {
2180
2180
  }
2181
2181
  return target;
2182
2182
  }
2183
- var Sidebar = (0, import_react14.forwardRef)(function(_ref, ref) {
2183
+ var Plus = (0, import_react14.forwardRef)(function(_ref, ref) {
2184
2184
  var _ref$color = _ref.color, color = _ref$color === void 0 ? "currentColor" : _ref$color, _ref$size = _ref.size, size = _ref$size === void 0 ? 24 : _ref$size, rest = _objectWithoutProperties12(_ref, ["color", "size"]);
2185
2185
  return /* @__PURE__ */ import_react14.default.createElement("svg", _extends12({
2186
2186
  ref,
@@ -2193,28 +2193,26 @@ var Sidebar = (0, import_react14.forwardRef)(function(_ref, ref) {
2193
2193
  strokeWidth: "2",
2194
2194
  strokeLinecap: "round",
2195
2195
  strokeLinejoin: "round"
2196
- }, rest), /* @__PURE__ */ import_react14.default.createElement("rect", {
2197
- x: "3",
2198
- y: "3",
2199
- width: "18",
2200
- height: "18",
2201
- rx: "2",
2202
- ry: "2"
2196
+ }, rest), /* @__PURE__ */ import_react14.default.createElement("line", {
2197
+ x1: "12",
2198
+ y1: "5",
2199
+ x2: "12",
2200
+ y2: "19"
2203
2201
  }), /* @__PURE__ */ import_react14.default.createElement("line", {
2204
- x1: "9",
2205
- y1: "3",
2206
- x2: "9",
2207
- y2: "21"
2202
+ x1: "5",
2203
+ y1: "12",
2204
+ x2: "19",
2205
+ y2: "12"
2208
2206
  }));
2209
2207
  });
2210
- Sidebar.propTypes = {
2208
+ Plus.propTypes = {
2211
2209
  color: import_prop_types12.default.string,
2212
2210
  size: import_prop_types12.default.oneOfType([import_prop_types12.default.string, import_prop_types12.default.number])
2213
2211
  };
2214
- Sidebar.displayName = "Sidebar";
2215
- var sidebar_default = Sidebar;
2212
+ Plus.displayName = "Plus";
2213
+ var plus_default = Plus;
2216
2214
 
2217
- // ../../node_modules/react-feather/dist/icons/trash.js
2215
+ // ../../node_modules/react-feather/dist/icons/sidebar.js
2218
2216
  init_react_import();
2219
2217
  var import_react15 = __toESM(require("react"));
2220
2218
  var import_prop_types13 = __toESM(require_prop_types());
@@ -2264,7 +2262,7 @@ function _objectWithoutPropertiesLoose13(source, excluded) {
2264
2262
  }
2265
2263
  return target;
2266
2264
  }
2267
- var Trash = (0, import_react15.forwardRef)(function(_ref, ref) {
2265
+ var Sidebar = (0, import_react15.forwardRef)(function(_ref, ref) {
2268
2266
  var _ref$color = _ref.color, color = _ref$color === void 0 ? "currentColor" : _ref$color, _ref$size = _ref.size, size = _ref$size === void 0 ? 24 : _ref$size, rest = _objectWithoutProperties13(_ref, ["color", "size"]);
2269
2267
  return /* @__PURE__ */ import_react15.default.createElement("svg", _extends13({
2270
2268
  ref,
@@ -2277,20 +2275,28 @@ var Trash = (0, import_react15.forwardRef)(function(_ref, ref) {
2277
2275
  strokeWidth: "2",
2278
2276
  strokeLinecap: "round",
2279
2277
  strokeLinejoin: "round"
2280
- }, rest), /* @__PURE__ */ import_react15.default.createElement("polyline", {
2281
- points: "3 6 5 6 21 6"
2282
- }), /* @__PURE__ */ import_react15.default.createElement("path", {
2283
- d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"
2278
+ }, rest), /* @__PURE__ */ import_react15.default.createElement("rect", {
2279
+ x: "3",
2280
+ y: "3",
2281
+ width: "18",
2282
+ height: "18",
2283
+ rx: "2",
2284
+ ry: "2"
2285
+ }), /* @__PURE__ */ import_react15.default.createElement("line", {
2286
+ x1: "9",
2287
+ y1: "3",
2288
+ x2: "9",
2289
+ y2: "21"
2284
2290
  }));
2285
2291
  });
2286
- Trash.propTypes = {
2292
+ Sidebar.propTypes = {
2287
2293
  color: import_prop_types13.default.string,
2288
2294
  size: import_prop_types13.default.oneOfType([import_prop_types13.default.string, import_prop_types13.default.number])
2289
2295
  };
2290
- Trash.displayName = "Trash";
2291
- var trash_default = Trash;
2296
+ Sidebar.displayName = "Sidebar";
2297
+ var sidebar_default = Sidebar;
2292
2298
 
2293
- // ../../node_modules/react-feather/dist/icons/type.js
2299
+ // ../../node_modules/react-feather/dist/icons/trash.js
2294
2300
  init_react_import();
2295
2301
  var import_react16 = __toESM(require("react"));
2296
2302
  var import_prop_types14 = __toESM(require_prop_types());
@@ -2340,7 +2346,7 @@ function _objectWithoutPropertiesLoose14(source, excluded) {
2340
2346
  }
2341
2347
  return target;
2342
2348
  }
2343
- var Type = (0, import_react16.forwardRef)(function(_ref, ref) {
2349
+ var Trash = (0, import_react16.forwardRef)(function(_ref, ref) {
2344
2350
  var _ref$color = _ref.color, color = _ref$color === void 0 ? "currentColor" : _ref$color, _ref$size = _ref.size, size = _ref$size === void 0 ? 24 : _ref$size, rest = _objectWithoutProperties14(_ref, ["color", "size"]);
2345
2351
  return /* @__PURE__ */ import_react16.default.createElement("svg", _extends14({
2346
2352
  ref,
@@ -2354,13 +2360,89 @@ var Type = (0, import_react16.forwardRef)(function(_ref, ref) {
2354
2360
  strokeLinecap: "round",
2355
2361
  strokeLinejoin: "round"
2356
2362
  }, rest), /* @__PURE__ */ import_react16.default.createElement("polyline", {
2363
+ points: "3 6 5 6 21 6"
2364
+ }), /* @__PURE__ */ import_react16.default.createElement("path", {
2365
+ d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"
2366
+ }));
2367
+ });
2368
+ Trash.propTypes = {
2369
+ color: import_prop_types14.default.string,
2370
+ size: import_prop_types14.default.oneOfType([import_prop_types14.default.string, import_prop_types14.default.number])
2371
+ };
2372
+ Trash.displayName = "Trash";
2373
+ var trash_default = Trash;
2374
+
2375
+ // ../../node_modules/react-feather/dist/icons/type.js
2376
+ init_react_import();
2377
+ var import_react17 = __toESM(require("react"));
2378
+ var import_prop_types15 = __toESM(require_prop_types());
2379
+ function _extends15() {
2380
+ _extends15 = Object.assign || function(target) {
2381
+ for (var i = 1; i < arguments.length; i++) {
2382
+ var source = arguments[i];
2383
+ for (var key in source) {
2384
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
2385
+ target[key] = source[key];
2386
+ }
2387
+ }
2388
+ }
2389
+ return target;
2390
+ };
2391
+ return _extends15.apply(this, arguments);
2392
+ }
2393
+ function _objectWithoutProperties15(source, excluded) {
2394
+ if (source == null)
2395
+ return {};
2396
+ var target = _objectWithoutPropertiesLoose15(source, excluded);
2397
+ var key, i;
2398
+ if (Object.getOwnPropertySymbols) {
2399
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
2400
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
2401
+ key = sourceSymbolKeys[i];
2402
+ if (excluded.indexOf(key) >= 0)
2403
+ continue;
2404
+ if (!Object.prototype.propertyIsEnumerable.call(source, key))
2405
+ continue;
2406
+ target[key] = source[key];
2407
+ }
2408
+ }
2409
+ return target;
2410
+ }
2411
+ function _objectWithoutPropertiesLoose15(source, excluded) {
2412
+ if (source == null)
2413
+ return {};
2414
+ var target = {};
2415
+ var sourceKeys = Object.keys(source);
2416
+ var key, i;
2417
+ for (i = 0; i < sourceKeys.length; i++) {
2418
+ key = sourceKeys[i];
2419
+ if (excluded.indexOf(key) >= 0)
2420
+ continue;
2421
+ target[key] = source[key];
2422
+ }
2423
+ return target;
2424
+ }
2425
+ var Type = (0, import_react17.forwardRef)(function(_ref, ref) {
2426
+ var _ref$color = _ref.color, color = _ref$color === void 0 ? "currentColor" : _ref$color, _ref$size = _ref.size, size = _ref$size === void 0 ? 24 : _ref$size, rest = _objectWithoutProperties15(_ref, ["color", "size"]);
2427
+ return /* @__PURE__ */ import_react17.default.createElement("svg", _extends15({
2428
+ ref,
2429
+ xmlns: "http://www.w3.org/2000/svg",
2430
+ width: size,
2431
+ height: size,
2432
+ viewBox: "0 0 24 24",
2433
+ fill: "none",
2434
+ stroke: color,
2435
+ strokeWidth: "2",
2436
+ strokeLinecap: "round",
2437
+ strokeLinejoin: "round"
2438
+ }, rest), /* @__PURE__ */ import_react17.default.createElement("polyline", {
2357
2439
  points: "4 7 4 4 20 4 20 7"
2358
- }), /* @__PURE__ */ import_react16.default.createElement("line", {
2440
+ }), /* @__PURE__ */ import_react17.default.createElement("line", {
2359
2441
  x1: "9",
2360
2442
  y1: "20",
2361
2443
  x2: "15",
2362
2444
  y2: "20"
2363
- }), /* @__PURE__ */ import_react16.default.createElement("line", {
2445
+ }), /* @__PURE__ */ import_react17.default.createElement("line", {
2364
2446
  x1: "12",
2365
2447
  y1: "4",
2366
2448
  x2: "12",
@@ -2368,18 +2450,18 @@ var Type = (0, import_react16.forwardRef)(function(_ref, ref) {
2368
2450
  }));
2369
2451
  });
2370
2452
  Type.propTypes = {
2371
- color: import_prop_types14.default.string,
2372
- size: import_prop_types14.default.oneOfType([import_prop_types14.default.string, import_prop_types14.default.number])
2453
+ color: import_prop_types15.default.string,
2454
+ size: import_prop_types15.default.oneOfType([import_prop_types15.default.string, import_prop_types15.default.number])
2373
2455
  };
2374
2456
  Type.displayName = "Type";
2375
2457
  var type_default = Type;
2376
2458
 
2377
2459
  // lib/use-modifier-held.ts
2378
2460
  init_react_import();
2379
- var import_react17 = require("react");
2461
+ var import_react18 = require("react");
2380
2462
  var useModifierHeld = (modifier) => {
2381
- const [modifierHeld, setModifierHeld] = (0, import_react17.useState)(false);
2382
- (0, import_react17.useEffect)(() => {
2463
+ const [modifierHeld, setModifierHeld] = (0, import_react18.useState)(false);
2464
+ (0, import_react18.useEffect)(() => {
2383
2465
  function downHandler({ key }) {
2384
2466
  if (key === modifier) {
2385
2467
  setModifierHeld(true);
@@ -2423,7 +2505,7 @@ var DraggableComponent = ({
2423
2505
  style
2424
2506
  }) => {
2425
2507
  const isModifierHeld = useModifierHeld("Alt");
2426
- (0, import_react18.useEffect)(onMount, []);
2508
+ (0, import_react19.useEffect)(onMount, []);
2427
2509
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2428
2510
  import_react_beautiful_dnd.Draggable,
2429
2511
  {
@@ -2467,13 +2549,13 @@ var DraggableComponent = ({
2467
2549
 
2468
2550
  // components/DroppableStrictMode/index.tsx
2469
2551
  init_react_import();
2470
- var import_react19 = require("react");
2552
+ var import_react20 = require("react");
2471
2553
  var import_react_beautiful_dnd2 = require("react-beautiful-dnd");
2472
2554
  var import_jsx_runtime3 = require("react/jsx-runtime");
2473
2555
  var DroppableStrictMode = (_a) => {
2474
2556
  var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
2475
- const [enabled, setEnabled] = (0, import_react19.useState)(false);
2476
- (0, import_react19.useEffect)(() => {
2557
+ const [enabled, setEnabled] = (0, import_react20.useState)(false);
2558
+ (0, import_react20.useEffect)(() => {
2477
2559
  const animation = requestAnimationFrame(() => setEnabled(true));
2478
2560
  return () => {
2479
2561
  cancelAnimationFrame(animation);
@@ -2552,7 +2634,7 @@ var styles_module_default2 = { "DropZone": "_DropZone_ou0z5_1", "DropZone-conten
2552
2634
 
2553
2635
  // components/DropZone/context.tsx
2554
2636
  init_react_import();
2555
- var import_react20 = require("react");
2637
+ var import_react21 = require("react");
2556
2638
  var import_use_debounce = require("use-debounce");
2557
2639
 
2558
2640
  // lib/get-zone-id.ts
@@ -2564,34 +2646,34 @@ var getZoneId = (zoneCompound) => {
2564
2646
  if (zoneCompound && zoneCompound.indexOf(":") > -1) {
2565
2647
  return zoneCompound.split(":");
2566
2648
  }
2567
- return ["root", zoneCompound];
2649
+ return [rootDroppableId, zoneCompound];
2568
2650
  };
2569
2651
 
2570
2652
  // components/DropZone/context.tsx
2571
2653
  var import_jsx_runtime4 = require("react/jsx-runtime");
2572
- var dropZoneContext = (0, import_react20.createContext)(null);
2654
+ var dropZoneContext = (0, import_react21.createContext)(null);
2573
2655
  var DropZoneProvider = ({
2574
2656
  children,
2575
2657
  value
2576
2658
  }) => {
2577
- const [hoveringArea, setHoveringArea] = (0, import_react20.useState)(null);
2578
- const [hoveringZone, setHoveringZone] = (0, import_react20.useState)(
2659
+ const [hoveringArea, setHoveringArea] = (0, import_react21.useState)(null);
2660
+ const [hoveringZone, setHoveringZone] = (0, import_react21.useState)(
2579
2661
  rootDroppableId
2580
2662
  );
2581
- const [hoveringComponent, setHoveringComponent] = (0, import_react20.useState)();
2663
+ const [hoveringComponent, setHoveringComponent] = (0, import_react21.useState)();
2582
2664
  const [hoveringAreaDb] = (0, import_use_debounce.useDebounce)(hoveringArea, 75, { leading: false });
2583
- const [areasWithZones, setAreasWithZones] = (0, import_react20.useState)(
2665
+ const [areasWithZones, setAreasWithZones] = (0, import_react21.useState)(
2584
2666
  {}
2585
2667
  );
2586
- const [activeZones, setActiveZones] = (0, import_react20.useState)({});
2668
+ const [activeZones, setActiveZones] = (0, import_react21.useState)({});
2587
2669
  const { dispatch = null } = value ? value : {};
2588
- const registerZoneArea = (0, import_react20.useCallback)(
2670
+ const registerZoneArea = (0, import_react21.useCallback)(
2589
2671
  (area) => {
2590
2672
  setAreasWithZones((latest) => __spreadProps(__spreadValues({}, latest), { [area]: true }));
2591
2673
  },
2592
2674
  [setAreasWithZones]
2593
2675
  );
2594
- const registerZone = (0, import_react20.useCallback)(
2676
+ const registerZone = (0, import_react21.useCallback)(
2595
2677
  (zoneCompound) => {
2596
2678
  if (!dispatch) {
2597
2679
  return;
@@ -2604,7 +2686,7 @@ var DropZoneProvider = ({
2604
2686
  },
2605
2687
  [setActiveZones, dispatch]
2606
2688
  );
2607
- const unregisterZone = (0, import_react20.useCallback)(
2689
+ const unregisterZone = (0, import_react21.useCallback)(
2608
2690
  (zoneCompound) => {
2609
2691
  if (!dispatch) {
2610
2692
  return;
@@ -2619,8 +2701,8 @@ var DropZoneProvider = ({
2619
2701
  },
2620
2702
  [setActiveZones, dispatch]
2621
2703
  );
2622
- const [pathData, setPathData] = (0, import_react20.useState)();
2623
- const registerPath = (0, import_react20.useCallback)(
2704
+ const [pathData, setPathData] = (0, import_react21.useState)();
2705
+ const registerPath = (0, import_react21.useCallback)(
2624
2706
  (selector) => {
2625
2707
  if (!(value == null ? void 0 : value.data)) {
2626
2708
  return;
@@ -2631,15 +2713,15 @@ var DropZoneProvider = ({
2631
2713
  }
2632
2714
  const [area] = getZoneId(selector.zone);
2633
2715
  setPathData((latestPathData = {}) => {
2634
- const pathData2 = latestPathData[area] || [];
2716
+ const parentPathData = latestPathData[area] || { path: [] };
2635
2717
  return __spreadProps(__spreadValues({}, latestPathData), {
2636
- [item.props.id]: [
2637
- ...pathData2,
2638
- {
2639
- selector,
2640
- label: item.type
2641
- }
2642
- ]
2718
+ [item.props.id]: {
2719
+ path: [
2720
+ ...parentPathData.path,
2721
+ ...selector.zone ? [selector.zone] : []
2722
+ ],
2723
+ label: item.type
2724
+ }
2643
2725
  });
2644
2726
  });
2645
2727
  },
@@ -2673,7 +2755,7 @@ var import_jsx_runtime5 = require("react/jsx-runtime");
2673
2755
  var getClassName3 = get_class_name_factory_default("DropZone", styles_module_default2);
2674
2756
  function DropZoneEdit({ zone, style }) {
2675
2757
  var _a;
2676
- const ctx = (0, import_react21.useContext)(dropZoneContext);
2758
+ const ctx = (0, import_react22.useContext)(dropZoneContext);
2677
2759
  const {
2678
2760
  // These all need setting via context
2679
2761
  data,
@@ -2690,12 +2772,12 @@ function DropZoneEdit({ zone, style }) {
2690
2772
  } = ctx || {};
2691
2773
  let content = data.content || [];
2692
2774
  let zoneCompound = rootDroppableId;
2693
- (0, import_react21.useEffect)(() => {
2775
+ (0, import_react22.useEffect)(() => {
2694
2776
  if (areaId && registerZoneArea) {
2695
2777
  registerZoneArea(areaId);
2696
2778
  }
2697
2779
  }, [areaId]);
2698
- (0, import_react21.useEffect)(() => {
2780
+ (0, import_react22.useEffect)(() => {
2699
2781
  if (ctx == null ? void 0 : ctx.registerZone) {
2700
2782
  ctx == null ? void 0 : ctx.registerZone(zoneCompound);
2701
2783
  }
@@ -2907,7 +2989,7 @@ function DropZoneEdit({ zone, style }) {
2907
2989
  );
2908
2990
  }
2909
2991
  function DropZoneRender({ zone }) {
2910
- const ctx = (0, import_react21.useContext)(dropZoneContext);
2992
+ const ctx = (0, import_react22.useContext)(dropZoneContext);
2911
2993
  const { data, areaId = "root", config } = ctx || {};
2912
2994
  let zoneCompound = rootDroppableId;
2913
2995
  let content = (data == null ? void 0 : data.content) || [];
@@ -2934,7 +3016,7 @@ function DropZoneRender({ zone }) {
2934
3016
  }) });
2935
3017
  }
2936
3018
  function DropZone(props) {
2937
- const ctx = (0, import_react21.useContext)(dropZoneContext);
3019
+ const ctx = (0, import_react22.useContext)(dropZoneContext);
2938
3020
  if ((ctx == null ? void 0 : ctx.mode) === "edit") {
2939
3021
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DropZoneEdit, __spreadValues({}, props));
2940
3022
  }
@@ -2946,7 +3028,7 @@ init_react_import();
2946
3028
 
2947
3029
  // components/IconButton/IconButton.tsx
2948
3030
  init_react_import();
2949
- var import_react22 = require("react");
3031
+ var import_react23 = require("react");
2950
3032
 
2951
3033
  // css-module:/home/runner/work/puck/puck/packages/core/components/IconButton/IconButton.module.css#css-module
2952
3034
  init_react_import();
@@ -2968,7 +3050,7 @@ var IconButton = ({
2968
3050
  fullWidth,
2969
3051
  title
2970
3052
  }) => {
2971
- const [loading, setLoading] = (0, import_react22.useState)(false);
3053
+ const [loading, setLoading] = (0, import_react23.useState)(false);
2972
3054
  const ElementType = href ? "a" : "button";
2973
3055
  const el = /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2974
3056
  ElementType,
@@ -3008,329 +3090,327 @@ var IconButton = ({
3008
3090
 
3009
3091
  // components/Puck/index.tsx
3010
3092
  init_react_import();
3011
- var import_react28 = require("react");
3012
- var import_react_beautiful_dnd4 = require("react-beautiful-dnd");
3093
+ var import_react32 = require("react");
3094
+ var import_react_beautiful_dnd5 = require("react-beautiful-dnd");
3013
3095
 
3014
3096
  // components/InputOrGroup/index.tsx
3015
3097
  init_react_import();
3016
3098
 
3017
- // components/ExternalInput/index.tsx
3099
+ // css-module:/home/runner/work/puck/puck/packages/core/components/InputOrGroup/styles.module.css#css-module
3018
3100
  init_react_import();
3019
- var import_react23 = require("react");
3101
+ var styles_module_default3 = { "Input": "_Input_nkpu6_1", "Input-label": "_Input-label_nkpu6_27", "Input-labelIcon": "_Input-labelIcon_nkpu6_34", "Input-input": "_Input-input_nkpu6_39", "Input--readOnly": "_Input--readOnly_nkpu6_60", "Input-radioGroupItems": "_Input-radioGroupItems_nkpu6_69", "Input-radio": "_Input-radio_nkpu6_69", "Input-radioInner": "_Input-radioInner_nkpu6_86", "Input-radioInput": "_Input-radioInput_nkpu6_98" };
3020
3102
 
3021
- // css-module:/home/runner/work/puck/puck/packages/core/components/ExternalInput/styles.module.css#css-module
3103
+ // components/InputOrGroup/fields/index.tsx
3022
3104
  init_react_import();
3023
- var styles_module_default3 = { "ExternalInput": "_ExternalInput_l4bks_1", "ExternalInput-actions": "_ExternalInput-actions_l4bks_5", "ExternalInput-button": "_ExternalInput-button_l4bks_9", "ExternalInput-detachButton": "_ExternalInput-detachButton_l4bks_28", "ExternalInput--hasData": "_ExternalInput--hasData_l4bks_35", "ExternalInput-modal": "_ExternalInput-modal_l4bks_55", "ExternalInput--modalVisible": "_ExternalInput--modalVisible_l4bks_69", "ExternalInput-modalInner": "_ExternalInput-modalInner_l4bks_73", "ExternalInput-modalHeading": "_ExternalInput-modalHeading_l4bks_84", "ExternalInput-modalTableWrapper": "_ExternalInput-modalTableWrapper_l4bks_89" };
3024
3105
 
3025
- // components/ExternalInput/index.tsx
3106
+ // components/InputOrGroup/fields/ArrayField/index.tsx
3107
+ init_react_import();
3108
+
3109
+ // css-module:/home/runner/work/puck/puck/packages/core/components/InputOrGroup/fields/ArrayField/styles.module.css#css-module
3110
+ init_react_import();
3111
+ var styles_module_default4 = { "ArrayField": "_ArrayField_zp334_5", "ArrayField--isDraggingFrom": "_ArrayField--isDraggingFrom_zp334_13", "ArrayField-addButton": "_ArrayField-addButton_zp334_17", "ArrayField--hasItems": "_ArrayField--hasItems_zp334_31", "ArrayFieldItem": "_ArrayFieldItem_zp334_45", "ArrayFieldItem--isDragging": "_ArrayFieldItem--isDragging_zp334_53", "ArrayFieldItem--isExpanded": "_ArrayFieldItem--isExpanded_zp334_58", "ArrayFieldItem-summary": "_ArrayFieldItem-summary_zp334_72", "ArrayFieldItem-body": "_ArrayFieldItem-body_zp334_104", "ArrayFieldItem-fieldset": "_ArrayFieldItem-fieldset_zp334_112", "ArrayFieldItem-rhs": "_ArrayFieldItem-rhs_zp334_119", "ArrayFieldItem-actions": "_ArrayFieldItem-actions_zp334_125", "ArrayFieldItem-action": "_ArrayFieldItem-action_zp334_125" };
3112
+
3113
+ // components/InputOrGroup/fields/ArrayField/index.tsx
3114
+ var import_react_beautiful_dnd4 = require("react-beautiful-dnd");
3115
+
3116
+ // components/Draggable/index.tsx
3117
+ init_react_import();
3118
+ var import_react_beautiful_dnd3 = require("react-beautiful-dnd");
3026
3119
  var import_jsx_runtime7 = require("react/jsx-runtime");
3027
- var getClassName5 = get_class_name_factory_default("ExternalInput", styles_module_default3);
3028
- var ExternalInput = ({
3029
- field,
3030
- onChange,
3031
- value = null
3120
+ var Draggable2 = ({
3121
+ className,
3122
+ children,
3123
+ id,
3124
+ index,
3125
+ showShadow,
3126
+ disableAnimations = false
3032
3127
  }) => {
3033
- const [data, setData] = (0, import_react23.useState)([]);
3034
- const [isOpen, setOpen] = (0, import_react23.useState)(false);
3035
- const [selectedData, setSelectedData] = (0, import_react23.useState)(value);
3036
- (0, import_react23.useEffect)(() => {
3037
- (() => __async(void 0, null, function* () {
3038
- if (field.adaptor) {
3039
- const listData = yield field.adaptor.fetchList(field.adaptorParams);
3040
- if (listData) {
3041
- setData(listData);
3128
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_react_beautiful_dnd3.Draggable, { draggableId: id, index, children: (provided, snapshot) => {
3129
+ var _a;
3130
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
3131
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3132
+ "div",
3133
+ __spreadProps(__spreadValues(__spreadValues({
3134
+ className: className && className(provided, snapshot),
3135
+ ref: provided.innerRef
3136
+ }, provided.draggableProps), provided.dragHandleProps), {
3137
+ style: __spreadProps(__spreadValues({}, provided.draggableProps.style), {
3138
+ transform: snapshot.isDragging || !disableAnimations ? (_a = provided.draggableProps.style) == null ? void 0 : _a.transform : "translate(0px, 0px)"
3139
+ }),
3140
+ children: children(provided, snapshot)
3141
+ })
3142
+ ),
3143
+ showShadow && snapshot.isDragging && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3144
+ "div",
3145
+ {
3146
+ className: className && className(provided, snapshot),
3147
+ style: { transform: "none !important" },
3148
+ children: children(provided, snapshot)
3042
3149
  }
3043
- }
3044
- }))();
3045
- }, [field.adaptor, field.adaptorParams]);
3046
- if (!field.adaptor) {
3047
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children: "Incorrectly configured" });
3048
- }
3049
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
3050
- "div",
3051
- {
3052
- className: getClassName5({
3053
- hasData: !!selectedData,
3054
- modalVisible: isOpen
3055
- }),
3056
- children: [
3057
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: getClassName5("actions"), children: [
3058
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3059
- "button",
3060
- {
3061
- onClick: () => setOpen(true),
3062
- className: getClassName5("button"),
3063
- children: selectedData ? field.getItemSummary ? field.getItemSummary(selectedData) : `${field.adaptor.name} item` : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
3064
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(link_default, { size: "16" }),
3065
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { children: [
3066
- "Select from ",
3067
- field.adaptor.name
3068
- ] })
3069
- ] })
3070
- }
3071
- ),
3072
- selectedData && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3073
- "button",
3074
- {
3075
- className: getClassName5("detachButton"),
3076
- onClick: () => {
3077
- setSelectedData(null);
3078
- onChange(null);
3079
- },
3080
- children: "Detach"
3081
- }
3082
- )
3083
- ] }),
3084
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: getClassName5("modal"), onClick: () => setOpen(false), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
3085
- "div",
3086
- {
3087
- className: getClassName5("modalInner"),
3088
- onClick: (e) => e.stopPropagation(),
3089
- children: [
3090
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h2", { className: getClassName5("modalHeading"), children: "Select content" }),
3091
- data.length ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: getClassName5("modalTableWrapper"), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("table", { children: [
3092
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("tr", { children: Object.keys(data[0]).map((key) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("th", { style: { textAlign: "left" }, children: key }, key)) }) }),
3093
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("tbody", { children: data.map((item, i) => {
3094
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
3095
- "tr",
3096
- {
3097
- style: { whiteSpace: "nowrap" },
3098
- onClick: (e) => {
3099
- onChange(item);
3100
- setOpen(false);
3101
- setSelectedData(item);
3102
- },
3103
- children: Object.keys(item).map((key) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("td", { children: item[key] }, key))
3104
- },
3105
- i
3106
- );
3107
- }) })
3108
- ] }) }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: { padding: 24 }, children: "No content" })
3109
- ]
3110
- }
3111
- ) })
3112
- ]
3113
- }
3114
- );
3150
+ )
3151
+ ] });
3152
+ } });
3115
3153
  };
3116
3154
 
3117
- // css-module:/home/runner/work/puck/puck/packages/core/components/InputOrGroup/styles.module.css#css-module
3155
+ // lib/generate-id.ts
3118
3156
  init_react_import();
3119
- var styles_module_default4 = { "Input": "_Input_izwhv_1", "Input-label": "_Input-label_izwhv_27", "Input-labelIcon": "_Input-labelIcon_izwhv_34", "Input-input": "_Input-input_izwhv_39", "Input--readOnly": "_Input--readOnly_izwhv_60", "Input-arrayItem": "_Input-arrayItem_izwhv_69", "Input-fieldset": "_Input-fieldset_izwhv_95", "Input-arrayItemAction": "_Input-arrayItemAction_izwhv_116", "Input-addButton": "_Input-addButton_izwhv_135", "Input-array": "_Input-array_izwhv_69", "Input-radioGroupItems": "_Input-radioGroupItems_izwhv_156", "Input-radio": "_Input-radio_izwhv_156", "Input-radioInner": "_Input-radioInner_izwhv_173", "Input-radioInput": "_Input-radioInput_izwhv_185" };
3157
+ var import_crypto = require("crypto");
3158
+ var generateId = (type) => `${type}-${(0, import_crypto.randomBytes)(20).toString("hex")}`;
3120
3159
 
3121
- // components/InputOrGroup/index.tsx
3160
+ // components/InputOrGroup/fields/ArrayField/index.tsx
3161
+ var import_react25 = require("react");
3162
+
3163
+ // components/DragIcon/index.tsx
3164
+ init_react_import();
3165
+
3166
+ // css-module:/home/runner/work/puck/puck/packages/core/components/DragIcon/styles.module.css#css-module
3167
+ init_react_import();
3168
+ var styles_module_default5 = { "DragIcon": "_DragIcon_o29on_1" };
3169
+
3170
+ // components/DragIcon/index.tsx
3122
3171
  var import_jsx_runtime8 = require("react/jsx-runtime");
3123
- var getClassName6 = get_class_name_factory_default("Input", styles_module_default4);
3124
- var FieldLabel = ({
3125
- children,
3126
- icon,
3127
- label
3128
- }) => {
3129
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { children: [
3130
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName6("label"), children: [
3131
- icon ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName6("labelIcon"), children: icon }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_jsx_runtime8.Fragment, {}),
3132
- label
3133
- ] }),
3134
- children
3135
- ] });
3172
+ var getClassName5 = get_class_name_factory_default("DragIcon", styles_module_default5);
3173
+ var DragIcon = () => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName5(), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("svg", { viewBox: "0 0 20 20", width: "12", fill: "currentColor", children: /* @__PURE__ */ (0, import_jsx_runtime8.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" }) }) });
3174
+
3175
+ // components/Puck/context.tsx
3176
+ init_react_import();
3177
+ var import_react24 = require("react");
3178
+ var defaultAppState = {
3179
+ data: { content: [], root: { title: "" } },
3180
+ ui: {
3181
+ leftSideBarVisible: true,
3182
+ arrayState: {},
3183
+ itemSelector: null
3184
+ }
3136
3185
  };
3137
- var InputOrGroup = ({
3138
- name,
3186
+ var appContext = (0, import_react24.createContext)({
3187
+ state: defaultAppState,
3188
+ dispatch: () => null
3189
+ });
3190
+ var AppProvider = appContext.Provider;
3191
+ var useAppContext = () => {
3192
+ const mainContext = (0, import_react24.useContext)(appContext);
3193
+ const selectedItem = mainContext.state.ui.itemSelector ? getItem(mainContext.state.ui.itemSelector, mainContext.state.data) : void 0;
3194
+ return __spreadProps(__spreadValues({}, mainContext), {
3195
+ // Helpers
3196
+ selectedItem,
3197
+ setUi: (ui, recordHistory) => {
3198
+ return mainContext.dispatch({
3199
+ type: "setUi",
3200
+ ui,
3201
+ recordHistory
3202
+ });
3203
+ }
3204
+ });
3205
+ };
3206
+
3207
+ // components/InputOrGroup/fields/ArrayField/index.tsx
3208
+ var import_jsx_runtime9 = require("react/jsx-runtime");
3209
+ var getClassNameInput = get_class_name_factory_default("Input", styles_module_default3);
3210
+ var getClassName6 = get_class_name_factory_default("ArrayField", styles_module_default4);
3211
+ var getClassNameItem = get_class_name_factory_default("ArrayFieldItem", styles_module_default4);
3212
+ var ArrayField = ({
3139
3213
  field,
3140
- value,
3141
- label,
3142
3214
  onChange,
3143
- readOnly
3215
+ value,
3216
+ name,
3217
+ label
3144
3218
  }) => {
3145
- if (field.type === "array") {
3146
- if (!field.arrayFields) {
3147
- return null;
3148
- }
3149
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName6(), children: [
3150
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("b", { className: getClassName6("label"), children: [
3151
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName6("labelIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(list_default, { size: 16 }) }),
3152
- label || name
3153
- ] }),
3154
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName6("array"), children: [
3155
- Array.isArray(value) ? value.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
3156
- "details",
3157
- {
3158
- className: getClassName6("arrayItem"),
3159
- children: [
3160
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("summary", { children: [
3161
- field.getItemSummary ? field.getItemSummary(item, i) : `Item #${i}`,
3162
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName6("arrayItemAction"), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3163
- IconButton,
3164
- {
3165
- onClick: () => {
3166
- const existingValue = value || [];
3167
- existingValue.splice(i, 1);
3168
- onChange(existingValue);
3169
- },
3170
- title: "Delete",
3171
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(trash_default, { size: 21 })
3172
- }
3173
- ) })
3174
- ] }),
3175
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("fieldset", { className: getClassName6("fieldset"), children: Object.keys(field.arrayFields).map((fieldName) => {
3176
- const subField = field.arrayFields[fieldName];
3177
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3178
- InputOrGroup,
3179
- {
3180
- name: `${name}_${i}_${fieldName}`,
3181
- label: subField.label || fieldName,
3182
- field: subField,
3183
- value: item[fieldName],
3184
- onChange: (val) => onChange(
3185
- replace(value, i, __spreadProps(__spreadValues({}, item), { [fieldName]: val }))
3186
- )
3187
- },
3188
- `${name}_${i}_${fieldName}`
3189
- );
3190
- }) })
3191
- ]
3192
- },
3193
- `${name}_${i}`
3194
- )) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", {}),
3195
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3196
- "button",
3197
- {
3198
- className: getClassName6("addButton"),
3199
- onClick: () => {
3200
- const existingValue = value || [];
3201
- onChange([...existingValue, field.defaultItemProps || {}]);
3202
- },
3203
- children: "+ Add item"
3204
- }
3205
- )
3206
- ] })
3207
- ] });
3208
- }
3209
- if (field.type === "external") {
3210
- if (!field.adaptor) {
3211
- return null;
3212
- }
3213
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName6(""), children: [
3214
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName6("label"), children: name === "_data" ? "External content" : label || name }),
3215
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ExternalInput, { field, onChange, value })
3216
- ] });
3217
- }
3218
- if (field.type === "select") {
3219
- if (!field.options) {
3220
- return null;
3221
- }
3222
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { className: getClassName6(), children: [
3223
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName6("label"), children: [
3224
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName6("labelIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(chevron_down_default, { size: 16 }) }),
3225
- label || name
3226
- ] }),
3227
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3228
- "select",
3229
- {
3230
- className: getClassName6("input"),
3231
- onChange: (e) => {
3232
- if (e.currentTarget.value === "true" || e.currentTarget.value === "false") {
3233
- onChange(Boolean(e.currentTarget.value));
3234
- return;
3235
- }
3236
- onChange(e.currentTarget.value);
3237
- },
3238
- value,
3239
- children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3240
- "option",
3241
- {
3242
- label: option.label,
3243
- value: option.value
3244
- },
3245
- option.label + option.value
3246
- ))
3247
- }
3248
- )
3249
- ] });
3250
- }
3251
- if (field.type === "textarea") {
3252
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { className: getClassName6({ readOnly }), children: [
3253
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName6("label"), children: [
3254
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName6("labelIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(type_default, { size: 16 }) }),
3255
- label || name
3256
- ] }),
3257
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3258
- "textarea",
3259
- {
3260
- className: getClassName6("input"),
3261
- autoComplete: "off",
3262
- name,
3263
- value: typeof value === "undefined" ? "" : value,
3264
- onChange: (e) => onChange(e.currentTarget.value),
3265
- readOnly,
3266
- rows: 5
3267
- }
3268
- )
3269
- ] });
3270
- }
3271
- if (field.type === "radio") {
3272
- if (!field.options) {
3273
- return null;
3274
- }
3275
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName6(), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName6("radioGroup"), children: [
3276
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName6("label"), children: [
3277
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName6("labelIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(check_circle_default, { size: 16 }) }),
3278
- field.label || name
3279
- ] }),
3280
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName6("radioGroupItems"), children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
3281
- "label",
3219
+ const [arrayFieldId] = (0, import_react25.useState)(generateId("ArrayField"));
3220
+ const { state, setUi } = useAppContext();
3221
+ const arrayState = state.ui.arrayState[arrayFieldId] || {
3222
+ items: Array.from(value).map((v) => ({
3223
+ _arrayId: generateId("ArrayItem"),
3224
+ data: v
3225
+ })),
3226
+ openId: ""
3227
+ };
3228
+ const setArrayState = (0, import_react25.useCallback)(
3229
+ (newArrayState, recordHistory = false) => {
3230
+ setUi(
3282
3231
  {
3283
- className: getClassName6("radio"),
3284
- children: [
3285
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3286
- "input",
3287
- {
3288
- type: "radio",
3289
- className: getClassName6("radioInput"),
3290
- value: option.value,
3291
- name,
3292
- onChange: (e) => {
3293
- if (e.currentTarget.value === "true" || e.currentTarget.value === "false") {
3294
- onChange(JSON.parse(e.currentTarget.value));
3295
- return;
3296
- }
3297
- onChange(e.currentTarget.value);
3298
- },
3299
- readOnly,
3300
- defaultChecked: value === option.value
3301
- }
3302
- ),
3303
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName6("radioInner"), children: option.label || option.value })
3304
- ]
3232
+ arrayState: __spreadProps(__spreadValues({}, state.ui.arrayState), {
3233
+ [arrayFieldId]: __spreadValues(__spreadValues({}, arrayState), newArrayState)
3234
+ })
3305
3235
  },
3306
- option.label + option.value
3307
- )) })
3308
- ] }) });
3309
- }
3310
- if (field.type === "custom") {
3311
- if (!field.render) {
3312
- return null;
3313
- }
3314
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: getClassName6(), children: field.render({
3315
- field,
3316
- name,
3317
- value,
3318
- onChange,
3319
- readOnly
3320
- }) });
3236
+ recordHistory
3237
+ );
3238
+ },
3239
+ [arrayState]
3240
+ );
3241
+ (0, import_react25.useEffect)(() => {
3242
+ const newItems = Array.from(value).map((item, idx) => {
3243
+ var _a;
3244
+ return {
3245
+ _arrayId: ((_a = arrayState.items[idx]) == null ? void 0 : _a._arrayId) || generateId("ArrayItem"),
3246
+ data: item
3247
+ };
3248
+ });
3249
+ setArrayState({ items: newItems });
3250
+ }, [value]);
3251
+ if (!field.arrayFields) {
3252
+ return null;
3321
3253
  }
3322
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { className: getClassName6({ readOnly }), children: [
3323
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName6("label"), children: [
3324
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: getClassName6("labelIcon"), children: [
3325
- field.type === "text" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(type_default, { size: 16 }),
3326
- field.type === "number" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(hash_default, { size: 16 })
3254
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: getClassNameInput(), children: [
3255
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("b", { className: getClassNameInput("label"), children: [
3256
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: getClassNameInput("labelIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(list_default, { size: 16 }) }),
3257
+ label || name
3258
+ ] }),
3259
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3260
+ import_react_beautiful_dnd4.DragDropContext,
3261
+ {
3262
+ onDragEnd: (event) => {
3263
+ var _a;
3264
+ if (event.destination) {
3265
+ const newValue = reorder(
3266
+ arrayState.items,
3267
+ event.source.index,
3268
+ (_a = event.destination) == null ? void 0 : _a.index
3269
+ );
3270
+ setArrayState(__spreadProps(__spreadValues({}, arrayState), { items: newValue }), false);
3271
+ onChange(newValue.map(({ data }) => data));
3272
+ }
3273
+ },
3274
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DroppableStrictMode_default, { droppableId: "array", children: (provided, snapshot) => {
3275
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3276
+ "div",
3277
+ __spreadProps(__spreadValues({}, provided.droppableProps), {
3278
+ ref: provided.innerRef,
3279
+ className: getClassName6({
3280
+ isDraggingFrom: !!snapshot.draggingFromThisWith,
3281
+ hasItems: value.length > 0
3282
+ }),
3283
+ children: [
3284
+ Array.isArray(value) && value.length > 0 ? arrayState.items.map(({ _arrayId, data }, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3285
+ Draggable2,
3286
+ {
3287
+ id: _arrayId,
3288
+ index: i,
3289
+ className: (_, snapshot2) => getClassNameItem({
3290
+ isExpanded: arrayState.openId === _arrayId,
3291
+ isDragging: snapshot2.isDragging
3292
+ }),
3293
+ children: () => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
3294
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3295
+ "div",
3296
+ {
3297
+ onClick: () => {
3298
+ if (arrayState.openId === _arrayId) {
3299
+ setArrayState({
3300
+ openId: ""
3301
+ });
3302
+ } else {
3303
+ setArrayState({
3304
+ openId: _arrayId
3305
+ });
3306
+ }
3307
+ },
3308
+ className: getClassNameItem("summary"),
3309
+ children: [
3310
+ field.getItemSummary ? field.getItemSummary(data, i) : `Item #${i}`,
3311
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: getClassNameItem("rhs"), children: [
3312
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: getClassNameItem("actions"), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: getClassNameItem("action"), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3313
+ IconButton,
3314
+ {
3315
+ onClick: () => {
3316
+ const existingValue = [
3317
+ ...value || []
3318
+ ];
3319
+ const existingItems = [
3320
+ ...arrayState.items || []
3321
+ ];
3322
+ existingValue.splice(i, 1);
3323
+ existingItems.splice(i, 1);
3324
+ setArrayState(
3325
+ { items: existingItems },
3326
+ true
3327
+ );
3328
+ onChange(existingValue);
3329
+ },
3330
+ title: "Delete",
3331
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(trash_default, { size: 16 })
3332
+ }
3333
+ ) }) }),
3334
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DragIcon, {}) })
3335
+ ] })
3336
+ ]
3337
+ }
3338
+ ),
3339
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: getClassNameItem("body"), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3340
+ "fieldset",
3341
+ {
3342
+ className: getClassNameItem("fieldset"),
3343
+ children: Object.keys(field.arrayFields).map(
3344
+ (fieldName) => {
3345
+ const subField = field.arrayFields[fieldName];
3346
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3347
+ InputOrGroup,
3348
+ {
3349
+ name: `${name}_${i}_${fieldName}`,
3350
+ label: subField.label || fieldName,
3351
+ field: subField,
3352
+ value: data[fieldName],
3353
+ onChange: (val) => onChange(
3354
+ replace(value, i, __spreadProps(__spreadValues({}, data), {
3355
+ [fieldName]: val
3356
+ }))
3357
+ )
3358
+ },
3359
+ `${name}_${i}_${fieldName}`
3360
+ );
3361
+ }
3362
+ )
3363
+ }
3364
+ ) })
3365
+ ] })
3366
+ },
3367
+ _arrayId
3368
+ )) : null,
3369
+ provided.placeholder,
3370
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3371
+ "button",
3372
+ {
3373
+ className: getClassName6("addButton"),
3374
+ onClick: () => {
3375
+ const existingValue = value || [];
3376
+ onChange([...existingValue, field.defaultItemProps || {}]);
3377
+ },
3378
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(plus_default, { size: "21" })
3379
+ }
3380
+ )
3381
+ ]
3382
+ })
3383
+ );
3384
+ } })
3385
+ }
3386
+ )
3387
+ ] });
3388
+ };
3389
+
3390
+ // components/InputOrGroup/fields/DefaultField/index.tsx
3391
+ init_react_import();
3392
+ var import_jsx_runtime10 = require("react/jsx-runtime");
3393
+ var getClassName7 = get_class_name_factory_default("Input", styles_module_default3);
3394
+ var DefaultField = ({
3395
+ field,
3396
+ onChange,
3397
+ readOnly,
3398
+ value,
3399
+ name,
3400
+ label
3401
+ }) => {
3402
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { className: getClassName7({ readOnly }), children: [
3403
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: getClassName7("label"), children: [
3404
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: getClassName7("labelIcon"), children: [
3405
+ field.type === "text" && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(type_default, { size: 16 }),
3406
+ field.type === "number" && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(hash_default, { size: 16 })
3327
3407
  ] }),
3328
3408
  label || name
3329
3409
  ] }),
3330
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
3410
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3331
3411
  "input",
3332
3412
  {
3333
- className: getClassName6("input"),
3413
+ className: getClassName7("input"),
3334
3414
  autoComplete: "off",
3335
3415
  type: field.type,
3336
3416
  name,
@@ -3348,67 +3428,350 @@ var InputOrGroup = ({
3348
3428
  ] });
3349
3429
  };
3350
3430
 
3431
+ // components/InputOrGroup/fields/ExternalField/index.tsx
3432
+ init_react_import();
3433
+
3434
+ // components/ExternalInput/index.tsx
3435
+ init_react_import();
3436
+ var import_react26 = require("react");
3437
+
3438
+ // css-module:/home/runner/work/puck/puck/packages/core/components/ExternalInput/styles.module.css#css-module
3439
+ init_react_import();
3440
+ var styles_module_default6 = { "ExternalInput": "_ExternalInput_l4bks_1", "ExternalInput-actions": "_ExternalInput-actions_l4bks_5", "ExternalInput-button": "_ExternalInput-button_l4bks_9", "ExternalInput-detachButton": "_ExternalInput-detachButton_l4bks_28", "ExternalInput--hasData": "_ExternalInput--hasData_l4bks_35", "ExternalInput-modal": "_ExternalInput-modal_l4bks_55", "ExternalInput--modalVisible": "_ExternalInput--modalVisible_l4bks_69", "ExternalInput-modalInner": "_ExternalInput-modalInner_l4bks_73", "ExternalInput-modalHeading": "_ExternalInput-modalHeading_l4bks_84", "ExternalInput-modalTableWrapper": "_ExternalInput-modalTableWrapper_l4bks_89" };
3441
+
3442
+ // components/ExternalInput/index.tsx
3443
+ var import_jsx_runtime11 = require("react/jsx-runtime");
3444
+ var getClassName8 = get_class_name_factory_default("ExternalInput", styles_module_default6);
3445
+ var ExternalInput = ({
3446
+ field,
3447
+ onChange,
3448
+ value = null
3449
+ }) => {
3450
+ const [data, setData] = (0, import_react26.useState)([]);
3451
+ const [isOpen, setOpen] = (0, import_react26.useState)(false);
3452
+ const [selectedData, setSelectedData] = (0, import_react26.useState)(value);
3453
+ const keys = (0, import_react26.useMemo)(() => {
3454
+ const validKeys = /* @__PURE__ */ new Set();
3455
+ for (const item of data) {
3456
+ for (const key of Object.keys(item)) {
3457
+ if (typeof item[key] === "string" || typeof item[key] === "number") {
3458
+ validKeys.add(key);
3459
+ }
3460
+ }
3461
+ }
3462
+ return Array.from(validKeys);
3463
+ }, [data]);
3464
+ (0, import_react26.useEffect)(() => {
3465
+ (() => __async(void 0, null, function* () {
3466
+ if (field.adaptor) {
3467
+ const listData = yield field.adaptor.fetchList(field.adaptorParams);
3468
+ if (listData) {
3469
+ setData(listData);
3470
+ }
3471
+ }
3472
+ }))();
3473
+ }, [field.adaptor, field.adaptorParams]);
3474
+ if (!field.adaptor) {
3475
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { children: "Incorrectly configured" });
3476
+ }
3477
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3478
+ "div",
3479
+ {
3480
+ className: getClassName8({
3481
+ hasData: !!selectedData,
3482
+ modalVisible: isOpen
3483
+ }),
3484
+ children: [
3485
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName8("actions"), children: [
3486
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3487
+ "button",
3488
+ {
3489
+ onClick: () => setOpen(true),
3490
+ className: getClassName8("button"),
3491
+ children: selectedData ? field.getItemSummary ? field.getItemSummary(selectedData) : `${field.adaptor.name} item` : /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_jsx_runtime11.Fragment, { children: [
3492
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(link_default, { size: "16" }),
3493
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { children: [
3494
+ "Select from ",
3495
+ field.adaptor.name
3496
+ ] })
3497
+ ] })
3498
+ }
3499
+ ),
3500
+ selectedData && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3501
+ "button",
3502
+ {
3503
+ className: getClassName8("detachButton"),
3504
+ onClick: () => {
3505
+ setSelectedData(null);
3506
+ onChange(null);
3507
+ },
3508
+ children: "Detach"
3509
+ }
3510
+ )
3511
+ ] }),
3512
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName8("modal"), onClick: () => setOpen(false), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
3513
+ "div",
3514
+ {
3515
+ className: getClassName8("modalInner"),
3516
+ onClick: (e) => e.stopPropagation(),
3517
+ children: [
3518
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h2", { className: getClassName8("modalHeading"), children: "Select content" }),
3519
+ data.length ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName8("modalTableWrapper"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("table", { children: [
3520
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("tr", { children: keys.map((key) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("th", { style: { textAlign: "left" }, children: key }, key)) }) }),
3521
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("tbody", { children: data.map((item, i) => {
3522
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3523
+ "tr",
3524
+ {
3525
+ style: { whiteSpace: "nowrap" },
3526
+ onClick: (e) => {
3527
+ onChange(item);
3528
+ setOpen(false);
3529
+ setSelectedData(item);
3530
+ },
3531
+ children: keys.map((key) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("td", { children: item[key] }, key))
3532
+ },
3533
+ i
3534
+ );
3535
+ }) })
3536
+ ] }) }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { style: { padding: 24 }, children: "No content" })
3537
+ ]
3538
+ }
3539
+ ) })
3540
+ ]
3541
+ }
3542
+ );
3543
+ };
3544
+
3545
+ // components/InputOrGroup/fields/ExternalField/index.tsx
3546
+ var import_jsx_runtime12 = require("react/jsx-runtime");
3547
+ var getClassName9 = get_class_name_factory_default("Input", styles_module_default3);
3548
+ var ExternalField = ({
3549
+ field,
3550
+ onChange,
3551
+ readOnly,
3552
+ value,
3553
+ name,
3554
+ label
3555
+ }) => {
3556
+ if (!field.adaptor) {
3557
+ return null;
3558
+ }
3559
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: getClassName9(""), children: [
3560
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: getClassName9("label"), children: name === "_data" ? "External content" : label || name }),
3561
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ExternalInput, { field, onChange, value })
3562
+ ] });
3563
+ };
3564
+
3565
+ // components/InputOrGroup/fields/RadioField/index.tsx
3566
+ init_react_import();
3567
+ var import_jsx_runtime13 = require("react/jsx-runtime");
3568
+ var getClassName10 = get_class_name_factory_default("Input", styles_module_default3);
3569
+ var RadioField = ({
3570
+ field,
3571
+ onChange,
3572
+ readOnly,
3573
+ value,
3574
+ name
3575
+ }) => {
3576
+ if (!field.options) {
3577
+ return null;
3578
+ }
3579
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: getClassName10(), children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: getClassName10("radioGroup"), children: [
3580
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: getClassName10("label"), children: [
3581
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: getClassName10("labelIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(check_circle_default, { size: 16 }) }),
3582
+ field.label || name
3583
+ ] }),
3584
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: getClassName10("radioGroupItems"), children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
3585
+ "label",
3586
+ {
3587
+ className: getClassName10("radio"),
3588
+ children: [
3589
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
3590
+ "input",
3591
+ {
3592
+ type: "radio",
3593
+ className: getClassName10("radioInput"),
3594
+ value: option.value,
3595
+ name,
3596
+ onChange: (e) => {
3597
+ if (e.currentTarget.value === "true" || e.currentTarget.value === "false") {
3598
+ onChange(JSON.parse(e.currentTarget.value));
3599
+ return;
3600
+ }
3601
+ onChange(e.currentTarget.value);
3602
+ },
3603
+ readOnly,
3604
+ defaultChecked: value === option.value
3605
+ }
3606
+ ),
3607
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: getClassName10("radioInner"), children: option.label || option.value })
3608
+ ]
3609
+ },
3610
+ option.label + option.value
3611
+ )) })
3612
+ ] }) });
3613
+ };
3614
+
3615
+ // components/InputOrGroup/fields/SelectField/index.tsx
3616
+ init_react_import();
3617
+ var import_jsx_runtime14 = require("react/jsx-runtime");
3618
+ var getClassName11 = get_class_name_factory_default("Input", styles_module_default3);
3619
+ var SelectField = ({
3620
+ field,
3621
+ onChange,
3622
+ label,
3623
+ value,
3624
+ name
3625
+ }) => {
3626
+ if (!field.options) {
3627
+ return null;
3628
+ }
3629
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("label", { className: getClassName11(), children: [
3630
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: getClassName11("label"), children: [
3631
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: getClassName11("labelIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(chevron_down_default, { size: 16 }) }),
3632
+ label || name
3633
+ ] }),
3634
+ /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3635
+ "select",
3636
+ {
3637
+ className: getClassName11("input"),
3638
+ onChange: (e) => {
3639
+ if (e.currentTarget.value === "true" || e.currentTarget.value === "false") {
3640
+ onChange(Boolean(e.currentTarget.value));
3641
+ return;
3642
+ }
3643
+ onChange(e.currentTarget.value);
3644
+ },
3645
+ value,
3646
+ children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3647
+ "option",
3648
+ {
3649
+ label: option.label,
3650
+ value: option.value
3651
+ },
3652
+ option.label + option.value
3653
+ ))
3654
+ }
3655
+ )
3656
+ ] });
3657
+ };
3658
+
3659
+ // components/InputOrGroup/fields/TextareaField/index.tsx
3660
+ init_react_import();
3661
+ var import_jsx_runtime15 = require("react/jsx-runtime");
3662
+ var getClassName12 = get_class_name_factory_default("Input", styles_module_default3);
3663
+ var TextareaField = ({
3664
+ onChange,
3665
+ readOnly,
3666
+ value,
3667
+ name,
3668
+ label
3669
+ }) => {
3670
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("label", { className: getClassName12({ readOnly }), children: [
3671
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { className: getClassName12("label"), children: [
3672
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: getClassName12("labelIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(type_default, { size: 16 }) }),
3673
+ label || name
3674
+ ] }),
3675
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
3676
+ "textarea",
3677
+ {
3678
+ className: getClassName12("input"),
3679
+ autoComplete: "off",
3680
+ name,
3681
+ value: typeof value === "undefined" ? "" : value,
3682
+ onChange: (e) => onChange(e.currentTarget.value),
3683
+ readOnly,
3684
+ rows: 5
3685
+ }
3686
+ )
3687
+ ] });
3688
+ };
3689
+
3690
+ // components/InputOrGroup/index.tsx
3691
+ var import_jsx_runtime16 = require("react/jsx-runtime");
3692
+ var getClassName13 = get_class_name_factory_default("Input", styles_module_default3);
3693
+ var FieldLabel = ({
3694
+ children,
3695
+ icon,
3696
+ label
3697
+ }) => {
3698
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("label", { children: [
3699
+ /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: getClassName13("label"), children: [
3700
+ icon ? /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: getClassName13("labelIcon"), children: icon }) : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, {}),
3701
+ label
3702
+ ] }),
3703
+ children
3704
+ ] });
3705
+ };
3706
+ var InputOrGroup = (props) => {
3707
+ const { name, field, value, onChange, readOnly } = props;
3708
+ if (field.type === "array") {
3709
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ArrayField, __spreadValues({}, props));
3710
+ }
3711
+ if (field.type === "external") {
3712
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ExternalField, __spreadValues({}, props));
3713
+ }
3714
+ if (field.type === "select") {
3715
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(SelectField, __spreadValues({}, props));
3716
+ }
3717
+ if (field.type === "textarea") {
3718
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(TextareaField, __spreadValues({}, props));
3719
+ }
3720
+ if (field.type === "radio") {
3721
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(RadioField, __spreadValues({}, props));
3722
+ }
3723
+ if (field.type === "custom") {
3724
+ if (!field.render) {
3725
+ return null;
3726
+ }
3727
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: getClassName13(), children: field.render({
3728
+ field,
3729
+ name,
3730
+ value,
3731
+ onChange,
3732
+ readOnly
3733
+ }) });
3734
+ }
3735
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(DefaultField, __spreadValues({}, props));
3736
+ };
3737
+
3351
3738
  // components/ComponentList/index.tsx
3352
3739
  init_react_import();
3353
- var import_react_beautiful_dnd3 = require("react-beautiful-dnd");
3354
3740
 
3355
3741
  // css-module:/home/runner/work/puck/puck/packages/core/components/ComponentList/styles.module.css#css-module
3356
3742
  init_react_import();
3357
- var styles_module_default5 = { "ComponentList": "_ComponentList_1ybn0_1", "ComponentList-item": "_ComponentList-item_1ybn0_9", "ComponentList-itemShadow": "_ComponentList-itemShadow_1ybn0_10", "ComponentList-itemIcon": "_ComponentList-itemIcon_1ybn0_28" };
3743
+ var styles_module_default7 = { "ComponentList": "_ComponentList_bvy0z_1", "ComponentList-item": "_ComponentList-item_bvy0z_6", "ComponentList-itemIcon": "_ComponentList-itemIcon_bvy0z_24", "ComponentList--isDraggingFrom": "_ComponentList--isDraggingFrom_bvy0z_28" };
3358
3744
 
3359
3745
  // components/ComponentList/index.tsx
3360
- var import_jsx_runtime9 = require("react/jsx-runtime");
3361
- var getClassName7 = get_class_name_factory_default("ComponentList", styles_module_default5);
3746
+ var import_jsx_runtime17 = require("react/jsx-runtime");
3747
+ var getClassName14 = get_class_name_factory_default("ComponentList", styles_module_default7);
3362
3748
  var ComponentList = ({ config }) => {
3363
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(DroppableStrictMode_default, { droppableId: "component-list", isDropDisabled: true, children: (provided, snapshot) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3749
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(DroppableStrictMode_default, { droppableId: "component-list", isDropDisabled: true, children: (provided, snapshot) => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
3364
3750
  "div",
3365
3751
  __spreadProps(__spreadValues({}, provided.droppableProps), {
3366
3752
  ref: provided.innerRef,
3367
- className: getClassName7(),
3753
+ className: getClassName14({
3754
+ isDraggingFrom: !!snapshot.draggingFromThisWith
3755
+ }),
3368
3756
  children: [
3369
3757
  Object.keys(config.components).map((componentKey, i) => {
3370
- const componentConfig = config[componentKey];
3371
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
3372
- import_react_beautiful_dnd3.Draggable,
3758
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
3759
+ Draggable2,
3373
3760
  {
3374
- draggableId: componentKey,
3761
+ id: componentKey,
3375
3762
  index: i,
3376
- children: (provided2, snapshot2) => {
3377
- var _a;
3378
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
3379
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3380
- "div",
3381
- __spreadProps(__spreadValues(__spreadValues({
3382
- ref: provided2.innerRef
3383
- }, provided2.draggableProps), provided2.dragHandleProps), {
3384
- className: getClassName7("item"),
3385
- style: __spreadProps(__spreadValues({}, provided2.draggableProps.style), {
3386
- transform: snapshot2.isDragging ? (_a = provided2.draggableProps.style) == null ? void 0 : _a.transform : "translate(0px, 0px)"
3387
- }),
3388
- children: [
3389
- componentKey,
3390
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: getClassName7("itemIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(grid_default, { size: 18 }) })
3391
- ]
3392
- })
3393
- ),
3394
- snapshot2.isDragging && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
3395
- "div",
3396
- {
3397
- className: getClassName7("itemShadow"),
3398
- style: { transform: "none !important" },
3399
- children: [
3400
- componentKey,
3401
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: getClassName7("itemIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(grid_default, { size: 18 }) })
3402
- ]
3403
- }
3404
- )
3405
- ] });
3406
- }
3763
+ showShadow: true,
3764
+ disableAnimations: true,
3765
+ className: () => getClassName14("item"),
3766
+ children: () => /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
3767
+ componentKey,
3768
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: getClassName14("itemIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(DragIcon, {}) })
3769
+ ] })
3407
3770
  },
3408
3771
  componentKey
3409
3772
  );
3410
3773
  }),
3411
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { style: { display: "none" }, children: provided.placeholder })
3774
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { style: { display: "none" }, children: provided.placeholder })
3412
3775
  ]
3413
3776
  })
3414
3777
  ) });
@@ -3416,10 +3779,10 @@ var ComponentList = ({ config }) => {
3416
3779
 
3417
3780
  // lib/use-placeholder-style.ts
3418
3781
  init_react_import();
3419
- var import_react24 = require("react");
3782
+ var import_react27 = require("react");
3420
3783
  var usePlaceholderStyle = () => {
3421
3784
  const queryAttr = "data-rbd-drag-handle-draggable-id";
3422
- const [placeholderStyle, setPlaceholderStyle] = (0, import_react24.useState)();
3785
+ const [placeholderStyle, setPlaceholderStyle] = (0, import_react27.useState)();
3423
3786
  const onDragStartOrUpdate = (draggedItem) => {
3424
3787
  var _a;
3425
3788
  const draggableId = draggedItem.draggableId;
@@ -3467,24 +3830,24 @@ init_react_import();
3467
3830
 
3468
3831
  // css-module:/home/runner/work/puck/puck/packages/core/components/SidebarSection/styles.module.css#css-module
3469
3832
  init_react_import();
3470
- var styles_module_default6 = { "SidebarSection": "_SidebarSection_f1p35_1", "SidebarSection-title": "_SidebarSection-title_f1p35_12", "SidebarSection-content": "_SidebarSection-content_f1p35_19", "SidebarSection--noPadding": "_SidebarSection--noPadding_f1p35_24", "SidebarSection-breadcrumbLabel": "_SidebarSection-breadcrumbLabel_f1p35_33", "SidebarSection-breadcrumbs": "_SidebarSection-breadcrumbs_f1p35_44", "SidebarSection-breadcrumb": "_SidebarSection-breadcrumb_f1p35_33", "SidebarSection-heading": "_SidebarSection-heading_f1p35_56" };
3833
+ var styles_module_default8 = { "SidebarSection": "_SidebarSection_f1p35_1", "SidebarSection-title": "_SidebarSection-title_f1p35_12", "SidebarSection-content": "_SidebarSection-content_f1p35_19", "SidebarSection--noPadding": "_SidebarSection--noPadding_f1p35_24", "SidebarSection-breadcrumbLabel": "_SidebarSection-breadcrumbLabel_f1p35_33", "SidebarSection-breadcrumbs": "_SidebarSection-breadcrumbs_f1p35_44", "SidebarSection-breadcrumb": "_SidebarSection-breadcrumb_f1p35_33", "SidebarSection-heading": "_SidebarSection-heading_f1p35_56" };
3471
3834
 
3472
3835
  // components/Heading/index.tsx
3473
3836
  init_react_import();
3474
3837
 
3475
3838
  // css-module:/home/runner/work/puck/puck/packages/core/components/Heading/styles.module.css#css-module
3476
3839
  init_react_import();
3477
- var styles_module_default7 = { "Heading": "_Heading_1bvy5_1", "Heading--xxxxl": "_Heading--xxxxl_1bvy5_13", "Heading--xxxl": "_Heading--xxxl_1bvy5_19", "Heading--xxl": "_Heading--xxl_1bvy5_23", "Heading--xl": "_Heading--xl_1bvy5_27", "Heading--l": "_Heading--l_1bvy5_31", "Heading--m": "_Heading--m_1bvy5_35", "Heading--s": "_Heading--s_1bvy5_39", "Heading--xs": "_Heading--xs_1bvy5_43" };
3840
+ var styles_module_default9 = { "Heading": "_Heading_1bvy5_1", "Heading--xxxxl": "_Heading--xxxxl_1bvy5_13", "Heading--xxxl": "_Heading--xxxl_1bvy5_19", "Heading--xxl": "_Heading--xxl_1bvy5_23", "Heading--xl": "_Heading--xl_1bvy5_27", "Heading--l": "_Heading--l_1bvy5_31", "Heading--m": "_Heading--m_1bvy5_35", "Heading--s": "_Heading--s_1bvy5_39", "Heading--xs": "_Heading--xs_1bvy5_43" };
3478
3841
 
3479
3842
  // components/Heading/index.tsx
3480
- var import_jsx_runtime10 = require("react/jsx-runtime");
3481
- var getClassName8 = get_class_name_factory_default("Heading", styles_module_default7);
3843
+ var import_jsx_runtime18 = require("react/jsx-runtime");
3844
+ var getClassName15 = get_class_name_factory_default("Heading", styles_module_default9);
3482
3845
  var Heading = ({ children, rank, size = "m" }) => {
3483
3846
  const Tag = rank ? `h${rank}` : "span";
3484
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
3847
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3485
3848
  Tag,
3486
3849
  {
3487
- className: getClassName8({
3850
+ className: getClassName15({
3488
3851
  [size]: true
3489
3852
  }),
3490
3853
  children
@@ -3492,37 +3855,210 @@ var Heading = ({ children, rank, size = "m" }) => {
3492
3855
  );
3493
3856
  };
3494
3857
 
3858
+ // lib/use-breadcrumbs.ts
3859
+ init_react_import();
3860
+ var import_react28 = require("react");
3861
+ var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
3862
+ const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
3863
+ const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
3864
+ if (!id) {
3865
+ return [];
3866
+ }
3867
+ return currentPathData == null ? void 0 : currentPathData.path.reduce((acc, zoneCompound) => {
3868
+ const [area] = getZoneId(zoneCompound);
3869
+ if (area === rootDroppableId) {
3870
+ return [
3871
+ {
3872
+ label: "Page",
3873
+ selector: null
3874
+ }
3875
+ ];
3876
+ }
3877
+ const parentZoneCompound = acc.length > 0 ? acc[acc.length - 1].zoneCompound : rootDroppableId;
3878
+ let parentZone = data.content;
3879
+ if (parentZoneCompound && parentZoneCompound !== rootDroppableId) {
3880
+ parentZone = data.zones[parentZoneCompound];
3881
+ }
3882
+ if (!parentZone) {
3883
+ return acc;
3884
+ }
3885
+ const itemIndex = parentZone.findIndex(
3886
+ (queryItem) => queryItem.props.id === area
3887
+ );
3888
+ const item = parentZone[itemIndex];
3889
+ if (!item) {
3890
+ return acc;
3891
+ }
3892
+ return [
3893
+ ...acc,
3894
+ {
3895
+ label: item.type.toString(),
3896
+ selector: {
3897
+ index: itemIndex,
3898
+ zone: parentZoneCompound
3899
+ },
3900
+ zoneCompound
3901
+ }
3902
+ ];
3903
+ }, []);
3904
+ };
3905
+ var useBreadcrumbs = (renderCount) => {
3906
+ const {
3907
+ state: { data },
3908
+ selectedItem
3909
+ } = useAppContext();
3910
+ const dzContext = (0, import_react28.useContext)(dropZoneContext);
3911
+ return (0, import_react28.useMemo)(() => {
3912
+ const breadcrumbs = convertPathDataToBreadcrumbs(
3913
+ selectedItem,
3914
+ dzContext == null ? void 0 : dzContext.pathData,
3915
+ data
3916
+ );
3917
+ if (renderCount) {
3918
+ return breadcrumbs.slice(breadcrumbs.length - renderCount);
3919
+ }
3920
+ return breadcrumbs;
3921
+ }, [selectedItem, dzContext == null ? void 0 : dzContext.pathData, renderCount]);
3922
+ };
3923
+
3495
3924
  // components/SidebarSection/index.tsx
3496
- var import_jsx_runtime11 = require("react/jsx-runtime");
3497
- var getClassName9 = get_class_name_factory_default("SidebarSection", styles_module_default6);
3925
+ var import_jsx_runtime19 = require("react/jsx-runtime");
3926
+ var getClassName16 = get_class_name_factory_default("SidebarSection", styles_module_default8);
3498
3927
  var SidebarSection = ({
3499
3928
  children,
3500
3929
  title,
3501
3930
  background,
3502
- breadcrumbs = [],
3503
- breadcrumbClick,
3931
+ showBreadcrumbs,
3504
3932
  noPadding
3505
3933
  }) => {
3506
- return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName9({ noPadding }), style: { background }, children: [
3507
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName9("title"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName9("breadcrumbs"), children: [
3508
- breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: getClassName9("breadcrumb"), children: [
3509
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
3934
+ const { setUi } = useAppContext();
3935
+ const breadcrumbs = useBreadcrumbs(1);
3936
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: getClassName16({ noPadding }), style: { background }, children: [
3937
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: getClassName16("title"), children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: getClassName16("breadcrumbs"), children: [
3938
+ showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: getClassName16("breadcrumb"), children: [
3939
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
3510
3940
  "div",
3511
3941
  {
3512
- className: getClassName9("breadcrumbLabel"),
3513
- onClick: () => breadcrumbClick && breadcrumbClick(breadcrumb),
3942
+ className: getClassName16("breadcrumbLabel"),
3943
+ onClick: () => setUi({ itemSelector: breadcrumb.selector }),
3514
3944
  children: breadcrumb.label
3515
3945
  }
3516
3946
  ),
3517
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(chevron_right_default, { size: 16 })
3518
- ] }, i)),
3519
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName9("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(Heading, { rank: 2, size: "xs", children: title }) })
3947
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(chevron_right_default, { size: 16 })
3948
+ ] }, i)) : null,
3949
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: getClassName16("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Heading, { rank: 2, size: "xs", children: title }) })
3520
3950
  ] }) }),
3521
- /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: getClassName9("content"), children })
3951
+ /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: getClassName16("content"), children })
3522
3952
  ] });
3523
3953
  };
3524
3954
 
3525
- // lib/reducer.ts
3955
+ // reducer/index.ts
3956
+ init_react_import();
3957
+
3958
+ // lib/use-puck-history.ts
3959
+ init_react_import();
3960
+ var import_react30 = require("react");
3961
+
3962
+ // lib/use-action-history.ts
3963
+ init_react_import();
3964
+ var import_react29 = require("react");
3965
+ var EMPTY_HISTORY_INDEX = -1;
3966
+ function useActionHistory() {
3967
+ const [histories, setHistories] = (0, import_react29.useState)([]);
3968
+ const [currentHistoryIndex, setCurrentHistoryIndex] = (0, import_react29.useState)(EMPTY_HISTORY_INDEX);
3969
+ const currentHistory = histories[currentHistoryIndex];
3970
+ const canRewind = currentHistoryIndex > EMPTY_HISTORY_INDEX;
3971
+ const canForward = currentHistoryIndex < histories.length - 1;
3972
+ const record = (params) => {
3973
+ const history = __spreadValues({
3974
+ id: Math.random().toString()
3975
+ }, params);
3976
+ setHistories((prev) => [
3977
+ ...prev.slice(0, currentHistoryIndex + 1),
3978
+ history
3979
+ ]);
3980
+ setCurrentHistoryIndex((prev) => prev + 1);
3981
+ };
3982
+ const rewind = () => {
3983
+ if (canRewind) {
3984
+ currentHistory.rewind();
3985
+ setCurrentHistoryIndex((prev) => prev - 1);
3986
+ }
3987
+ };
3988
+ const forward = () => {
3989
+ const forwardHistory = histories[currentHistoryIndex + 1];
3990
+ if (canForward && forwardHistory) {
3991
+ forwardHistory.forward();
3992
+ setCurrentHistoryIndex((prev) => prev + 1);
3993
+ }
3994
+ };
3995
+ return {
3996
+ currentHistory,
3997
+ canRewind,
3998
+ canForward,
3999
+ record,
4000
+ rewind,
4001
+ forward
4002
+ };
4003
+ }
4004
+
4005
+ // lib/use-puck-history.ts
4006
+ var import_react_hotkeys_hook = require("react-hotkeys-hook");
4007
+ var import_event_emitter = __toESM(require("event-emitter"));
4008
+ var import_use_debounce2 = require("use-debounce");
4009
+ var DEBOUNCE_TIME = 250;
4010
+ var RECORD_DIFF = "RECORD_DIFF";
4011
+ var historyEmitter = (0, import_event_emitter.default)();
4012
+ var recordDiff = (newAppState) => historyEmitter.emit(RECORD_DIFF, newAppState);
4013
+ var _recordHistory = ({
4014
+ snapshot,
4015
+ newSnapshot,
4016
+ record,
4017
+ dispatch
4018
+ }) => {
4019
+ if (JSON.stringify(snapshot) === JSON.stringify(newSnapshot))
4020
+ return;
4021
+ record({
4022
+ forward: () => {
4023
+ dispatch({ type: "set", state: newSnapshot });
4024
+ },
4025
+ rewind: () => {
4026
+ dispatch({ type: "set", state: snapshot });
4027
+ }
4028
+ });
4029
+ };
4030
+ function usePuckHistory({
4031
+ appState,
4032
+ dispatch
4033
+ }) {
4034
+ const { canForward, canRewind, rewind, forward, record } = useActionHistory();
4035
+ (0, import_react_hotkeys_hook.useHotkeys)("meta+z", rewind, { preventDefault: true });
4036
+ (0, import_react_hotkeys_hook.useHotkeys)("meta+shift+z", forward, { preventDefault: true });
4037
+ (0, import_react_hotkeys_hook.useHotkeys)("meta+y", forward, { preventDefault: true });
4038
+ const [snapshot] = (0, import_use_debounce2.useDebounce)(appState, DEBOUNCE_TIME);
4039
+ const handleRecordDiff = (0, import_use_debounce2.useDebouncedCallback)((newAppState) => {
4040
+ return _recordHistory({
4041
+ snapshot,
4042
+ newSnapshot: newAppState,
4043
+ record,
4044
+ dispatch
4045
+ });
4046
+ }, DEBOUNCE_TIME);
4047
+ (0, import_react30.useEffect)(() => {
4048
+ historyEmitter.on(RECORD_DIFF, handleRecordDiff);
4049
+ return () => {
4050
+ historyEmitter.off(RECORD_DIFF, handleRecordDiff);
4051
+ };
4052
+ }, [handleRecordDiff]);
4053
+ return {
4054
+ canForward,
4055
+ canRewind,
4056
+ rewind,
4057
+ forward
4058
+ };
4059
+ }
4060
+
4061
+ // reducer/data.ts
3526
4062
  init_react_import();
3527
4063
 
3528
4064
  // lib/insert.ts
@@ -3543,13 +4079,6 @@ var remove = (list, index) => {
3543
4079
 
3544
4080
  // lib/reduce-related-zones.ts
3545
4081
  init_react_import();
3546
-
3547
- // lib/generate-id.ts
3548
- init_react_import();
3549
- var import_crypto = require("crypto");
3550
- var generateId = (type) => `${type}-${(0, import_crypto.randomBytes)(20).toString("hex")}`;
3551
-
3552
- // lib/reduce-related-zones.ts
3553
4082
  var reduceRelatedZones = (item, data, fn) => {
3554
4083
  return __spreadProps(__spreadValues({}, data), {
3555
4084
  zones: Object.keys(data.zones || {}).reduce(
@@ -3612,125 +4141,12 @@ var duplicateRelatedZones = (item, data, newId) => {
3612
4141
  });
3613
4142
  };
3614
4143
 
3615
- // lib/use-puck-history.ts
3616
- init_react_import();
3617
- var import_react26 = require("react");
3618
-
3619
- // lib/use-action-history.ts
3620
- init_react_import();
3621
- var import_react25 = require("react");
3622
- var EMPTY_HISTORY_INDEX = -1;
3623
- function useActionHistory() {
3624
- const [histories, setHistories] = (0, import_react25.useState)([]);
3625
- const [currentHistoryIndex, setCurrentHistoryIndex] = (0, import_react25.useState)(EMPTY_HISTORY_INDEX);
3626
- const currentHistory = histories[currentHistoryIndex];
3627
- const canRewind = currentHistoryIndex > EMPTY_HISTORY_INDEX;
3628
- const canForward = currentHistoryIndex < histories.length - 1;
3629
- const record = (params) => {
3630
- const history = __spreadValues({
3631
- id: Math.random().toString()
3632
- }, params);
3633
- setHistories((prev) => [
3634
- ...prev.slice(0, currentHistoryIndex + 1),
3635
- history
3636
- ]);
3637
- setCurrentHistoryIndex((prev) => prev + 1);
3638
- };
3639
- const rewind = () => {
3640
- if (canRewind) {
3641
- currentHistory.rewind();
3642
- setCurrentHistoryIndex((prev) => prev - 1);
3643
- }
3644
- };
3645
- const forward = () => {
3646
- const forwardHistory = histories[currentHistoryIndex + 1];
3647
- if (canForward && forwardHistory) {
3648
- forwardHistory.forward();
3649
- setCurrentHistoryIndex((prev) => prev + 1);
3650
- }
3651
- };
3652
- return {
3653
- currentHistory,
3654
- canRewind,
3655
- canForward,
3656
- record,
3657
- rewind,
3658
- forward
3659
- };
3660
- }
3661
-
3662
- // lib/use-puck-history.ts
3663
- var import_react_hotkeys_hook = require("react-hotkeys-hook");
3664
- var import_event_emitter = __toESM(require("event-emitter"));
3665
- var import_use_debounce2 = require("use-debounce");
3666
- var import_deep_diff = require("deep-diff");
3667
- var DEBOUNCE_TIME = 250;
3668
- var RECORD_DIFF = "RECORD_DIFF";
3669
- var historyEmitter = (0, import_event_emitter.default)();
3670
- var recordDiff = (newData) => historyEmitter.emit(RECORD_DIFF, newData);
3671
- function usePuckHistory({
3672
- data,
3673
- dispatch
3674
- }) {
3675
- const { canForward, canRewind, rewind, forward, record } = useActionHistory();
3676
- (0, import_react_hotkeys_hook.useHotkeys)("meta+z", rewind, { preventDefault: true });
3677
- (0, import_react_hotkeys_hook.useHotkeys)("meta+shift+z", forward, { preventDefault: true });
3678
- (0, import_react_hotkeys_hook.useHotkeys)("meta+y", forward, { preventDefault: true });
3679
- const [snapshot] = (0, import_use_debounce2.useDebounce)(data, DEBOUNCE_TIME);
3680
- const handleRecordDiff = (0, import_use_debounce2.useDebouncedCallback)((newData) => {
3681
- const _diff = (0, import_deep_diff.diff)(snapshot, newData);
3682
- if (!_diff) {
3683
- return;
3684
- }
3685
- record({
3686
- forward: () => {
3687
- const target = structuredClone(data);
3688
- _diff.reduce((target2, change) => {
3689
- (0, import_deep_diff.applyChange)(target2, true, change);
3690
- return target2;
3691
- }, target);
3692
- dispatch({ type: "set", data: target });
3693
- },
3694
- rewind: () => {
3695
- const target = structuredClone(data);
3696
- _diff.reduce((target2, change) => {
3697
- (0, import_deep_diff.revertChange)(target2, true, change);
3698
- return target2;
3699
- }, target);
3700
- dispatch({ type: "set", data: target });
3701
- }
3702
- });
3703
- }, DEBOUNCE_TIME);
3704
- (0, import_react26.useEffect)(() => {
3705
- historyEmitter.on(RECORD_DIFF, handleRecordDiff);
3706
- return () => {
3707
- historyEmitter.off(RECORD_DIFF, handleRecordDiff);
3708
- };
3709
- }, [handleRecordDiff]);
3710
- return {
3711
- canForward,
3712
- canRewind,
3713
- rewind,
3714
- forward,
3715
- record
3716
- };
3717
- }
3718
-
3719
- // lib/reducer.ts
4144
+ // reducer/data.ts
3720
4145
  var zoneCache = {};
3721
4146
  var addToZoneCache = (key, data) => {
3722
4147
  zoneCache[key] = data;
3723
4148
  };
3724
- var storeInterceptor = (reducer) => {
3725
- return (data, action) => {
3726
- const newData = reducer(data, action);
3727
- if (!["registerZone", "unregisterZone", "set"].includes(action.type)) {
3728
- recordDiff(newData);
3729
- }
3730
- return newData;
3731
- };
3732
- };
3733
- var createReducer = ({ config }) => storeInterceptor((data, action) => {
4149
+ var reduceData = (data, action, config) => {
3734
4150
  if (action.type === "insert") {
3735
4151
  const emptyComponentData = {
3736
4152
  type: action.componentType,
@@ -3910,10 +4326,48 @@ var createReducer = ({ config }) => storeInterceptor((data, action) => {
3910
4326
  }
3911
4327
  return __spreadProps(__spreadValues({}, data), { zones: _zones });
3912
4328
  }
3913
- if (action.type === "set") {
4329
+ if (action.type === "setData") {
3914
4330
  return __spreadValues(__spreadValues({}, data), action.data);
3915
4331
  }
3916
4332
  return data;
4333
+ };
4334
+
4335
+ // reducer/state.ts
4336
+ init_react_import();
4337
+ var reduceState = (ui, action) => {
4338
+ if (action.type === "setUi") {
4339
+ return __spreadValues(__spreadValues({}, ui), action.ui);
4340
+ }
4341
+ return ui;
4342
+ };
4343
+
4344
+ // reducer/actions.tsx
4345
+ init_react_import();
4346
+
4347
+ // reducer/index.ts
4348
+ var storeInterceptor = (reducer) => {
4349
+ return (state, action) => {
4350
+ const newAppState = reducer(state, action);
4351
+ const isValidType = ![
4352
+ "registerZone",
4353
+ "unregisterZone",
4354
+ "setData",
4355
+ "setState",
4356
+ "set"
4357
+ ].includes(action.type);
4358
+ if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
4359
+ recordDiff(newAppState);
4360
+ }
4361
+ return newAppState;
4362
+ };
4363
+ };
4364
+ var createReducer = ({ config }) => storeInterceptor((state, action) => {
4365
+ const data = reduceData(state.data, action, config);
4366
+ const ui = reduceState(state.ui, action);
4367
+ if (action.type === "set") {
4368
+ return __spreadValues(__spreadValues({}, state), action.state);
4369
+ }
4370
+ return { data, ui };
3917
4371
  });
3918
4372
 
3919
4373
  // components/LayerTree/index.tsx
@@ -3921,7 +4375,7 @@ init_react_import();
3921
4375
 
3922
4376
  // css-module:/home/runner/work/puck/puck/packages/core/components/LayerTree/styles.module.css#css-module
3923
4377
  init_react_import();
3924
- var styles_module_default8 = { "LayerTree": "_LayerTree_1dcmd_1", "LayerTree-zoneTitle": "_LayerTree-zoneTitle_1dcmd_11", "LayerTree-helper": "_LayerTree-helper_1dcmd_17", "Layer": "_Layer_1dcmd_1", "Layer-inner": "_Layer-inner_1dcmd_29", "Layer--containsZone": "_Layer--containsZone_1dcmd_35", "Layer-clickable": "_Layer-clickable_1dcmd_39", "Layer--isSelected": "_Layer--isSelected_1dcmd_48", "Layer--isHovering": "_Layer--isHovering_1dcmd_49", "Layer-chevron": "_Layer-chevron_1dcmd_65", "Layer--childIsSelected": "_Layer--childIsSelected_1dcmd_66", "Layer-zones": "_Layer-zones_1dcmd_70", "Layer-title": "_Layer-title_1dcmd_84", "Layer-icon": "_Layer-icon_1dcmd_92", "Layer-zoneIcon": "_Layer-zoneIcon_1dcmd_97" };
4378
+ var styles_module_default10 = { "LayerTree": "_LayerTree_1dcmd_1", "LayerTree-zoneTitle": "_LayerTree-zoneTitle_1dcmd_11", "LayerTree-helper": "_LayerTree-helper_1dcmd_17", "Layer": "_Layer_1dcmd_1", "Layer-inner": "_Layer-inner_1dcmd_29", "Layer--containsZone": "_Layer--containsZone_1dcmd_35", "Layer-clickable": "_Layer-clickable_1dcmd_39", "Layer--isSelected": "_Layer--isSelected_1dcmd_48", "Layer--isHovering": "_Layer--isHovering_1dcmd_49", "Layer-chevron": "_Layer-chevron_1dcmd_65", "Layer--childIsSelected": "_Layer--childIsSelected_1dcmd_66", "Layer-zones": "_Layer-zones_1dcmd_70", "Layer-title": "_Layer-title_1dcmd_84", "Layer-icon": "_Layer-icon_1dcmd_92", "Layer-zoneIcon": "_Layer-zoneIcon_1dcmd_97" };
3925
4379
 
3926
4380
  // lib/scroll-into-view.ts
3927
4381
  init_react_import();
@@ -3935,7 +4389,7 @@ var scrollIntoView = (el) => {
3935
4389
  };
3936
4390
 
3937
4391
  // components/LayerTree/index.tsx
3938
- var import_react27 = require("react");
4392
+ var import_react31 = require("react");
3939
4393
 
3940
4394
  // lib/find-zones-for-area.ts
3941
4395
  init_react_import();
@@ -3954,19 +4408,16 @@ init_react_import();
3954
4408
  var isChildOfZone = (item, maybeChild, ctx) => {
3955
4409
  var _a;
3956
4410
  const { data, pathData = {} } = ctx || {};
3957
- return maybeChild && data ? !!((_a = pathData[maybeChild.props.id]) == null ? void 0 : _a.find((path) => {
3958
- if (path.selector) {
3959
- const pathItem = getItem(path.selector, data);
3960
- return (pathItem == null ? void 0 : pathItem.props.id) === item.props.id;
3961
- }
3962
- return false;
4411
+ return maybeChild && data ? !!((_a = pathData[maybeChild.props.id]) == null ? void 0 : _a.path.find((zoneCompound) => {
4412
+ const [area] = getZoneId(zoneCompound);
4413
+ return area === item.props.id;
3963
4414
  })) : false;
3964
4415
  };
3965
4416
 
3966
4417
  // components/LayerTree/index.tsx
3967
- var import_jsx_runtime12 = require("react/jsx-runtime");
3968
- var getClassName10 = get_class_name_factory_default("LayerTree", styles_module_default8);
3969
- var getClassNameLayer = get_class_name_factory_default("Layer", styles_module_default8);
4418
+ var import_jsx_runtime20 = require("react/jsx-runtime");
4419
+ var getClassName17 = get_class_name_factory_default("LayerTree", styles_module_default10);
4420
+ var getClassNameLayer = get_class_name_factory_default("Layer", styles_module_default10);
3970
4421
  var LayerTree = ({
3971
4422
  data,
3972
4423
  zoneContent,
@@ -3976,15 +4427,15 @@ var LayerTree = ({
3976
4427
  label
3977
4428
  }) => {
3978
4429
  const zones = data.zones || {};
3979
- const ctx = (0, import_react27.useContext)(dropZoneContext);
3980
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_jsx_runtime12.Fragment, { children: [
3981
- label && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: getClassName10("zoneTitle"), children: [
3982
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: getClassName10("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(layers_default, { size: "16" }) }),
4430
+ const ctx = (0, import_react31.useContext)(dropZoneContext);
4431
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
4432
+ label && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: getClassName17("zoneTitle"), children: [
4433
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName17("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(layers_default, { size: "16" }) }),
3983
4434
  " ",
3984
4435
  label
3985
4436
  ] }),
3986
- /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("ul", { className: getClassName10(), children: [
3987
- zoneContent.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: getClassName10("helper"), children: "No items" }),
4437
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("ul", { className: getClassName17(), children: [
4438
+ zoneContent.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName17("helper"), children: "No items" }),
3988
4439
  zoneContent.map((item, i) => {
3989
4440
  const isSelected = (itemSelector == null ? void 0 : itemSelector.index) === i && (itemSelector.zone === zone || itemSelector.zone === rootDroppableId && !zone);
3990
4441
  const zonesForItem = findZonesForArea(data, item.props.id);
@@ -3999,7 +4450,7 @@ var LayerTree = ({
3999
4450
  const selectedItem = itemSelector && data ? getItem(itemSelector, data) : null;
4000
4451
  const isHovering = hoveringComponent === item.props.id;
4001
4452
  const childIsSelected = isChildOfZone(item, selectedItem, ctx);
4002
- return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
4453
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
4003
4454
  "li",
4004
4455
  {
4005
4456
  className: getClassNameLayer({
@@ -4009,7 +4460,7 @@ var LayerTree = ({
4009
4460
  childIsSelected
4010
4461
  }),
4011
4462
  children: [
4012
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
4463
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(
4013
4464
  "div",
4014
4465
  {
4015
4466
  className: getClassNameLayer("clickable"),
@@ -4040,22 +4491,22 @@ var LayerTree = ({
4040
4491
  setHoveringComponent(null);
4041
4492
  },
4042
4493
  children: [
4043
- containsZone && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
4494
+ containsZone && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4044
4495
  "div",
4045
4496
  {
4046
4497
  className: getClassNameLayer("chevron"),
4047
4498
  title: isSelected ? "Collapse" : "Expand",
4048
- children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(chevron_down_default, { size: "12" })
4499
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(chevron_down_default, { size: "12" })
4049
4500
  }
4050
4501
  ),
4051
- /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: getClassNameLayer("title"), children: [
4052
- /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: getClassNameLayer("icon"), children: item.type === "Text" || item.type === "Heading" ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(type_default, { size: "16" }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(grid_default, { size: "16" }) }),
4502
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: getClassNameLayer("title"), children: [
4503
+ /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassNameLayer("icon"), children: item.type === "Text" || item.type === "Heading" ? /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(type_default, { size: "16" }) : /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(grid_default, { size: "16" }) }),
4053
4504
  item.type
4054
4505
  ] })
4055
4506
  ]
4056
4507
  }
4057
4508
  ) }),
4058
- containsZone && Object.keys(zonesForItem).map((zoneKey, idx) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: getClassNameLayer("zones"), children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
4509
+ containsZone && Object.keys(zonesForItem).map((zoneKey, idx) => /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassNameLayer("zones"), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4059
4510
  LayerTree,
4060
4511
  {
4061
4512
  data,
@@ -4084,32 +4535,35 @@ var areaContainsZones = (data, area) => {
4084
4535
 
4085
4536
  // lib/flush-zones.ts
4086
4537
  init_react_import();
4087
- var flushZones = (data) => {
4088
- const containsZones = typeof data.zones !== "undefined";
4538
+ var flushZones = (appState) => {
4539
+ const containsZones = typeof appState.data.zones !== "undefined";
4089
4540
  if (containsZones) {
4090
- Object.keys(data.zones || {}).forEach((zone) => {
4091
- addToZoneCache(zone, data.zones[zone]);
4541
+ Object.keys(appState.data.zones || {}).forEach((zone) => {
4542
+ addToZoneCache(zone, appState.data.zones[zone]);
4092
4543
  });
4093
- return __spreadProps(__spreadValues({}, data), {
4094
- zones: {}
4544
+ return __spreadProps(__spreadValues({}, appState), {
4545
+ data: __spreadProps(__spreadValues({}, appState.data), {
4546
+ zones: {}
4547
+ })
4095
4548
  });
4096
4549
  }
4097
- return data;
4550
+ return appState;
4098
4551
  };
4099
4552
 
4100
4553
  // components/Puck/index.tsx
4101
- var import_jsx_runtime13 = require("react/jsx-runtime");
4554
+ var import_jsx_runtime21 = require("react/jsx-runtime");
4102
4555
  var defaultPageFields = {
4103
4556
  title: { type: "text" }
4104
4557
  };
4105
4558
  var PluginRenderer = ({
4106
4559
  children,
4107
- data,
4560
+ dispatch,
4561
+ state,
4108
4562
  plugins,
4109
4563
  renderMethod
4110
4564
  }) => {
4111
4565
  return plugins.filter((item) => item[renderMethod]).map((item) => item[renderMethod]).reduce(
4112
- (accChildren, Item) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Item, { data, children: accChildren }),
4566
+ (accChildren, Item) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(Item, { dispatch, state, children: accChildren }),
4113
4567
  children
4114
4568
  );
4115
4569
  };
@@ -4125,51 +4579,67 @@ function Puck({
4125
4579
  headerPath
4126
4580
  }) {
4127
4581
  var _a, _b;
4128
- const [reducer] = (0, import_react28.useState)(() => createReducer({ config }));
4129
- const [data, dispatch] = (0, import_react28.useReducer)(
4582
+ const [reducer] = (0, import_react32.useState)(() => createReducer({ config }));
4583
+ const initialAppState = __spreadProps(__spreadValues({}, defaultAppState), {
4584
+ data: initialData
4585
+ });
4586
+ const [appState, dispatch] = (0, import_react32.useReducer)(
4130
4587
  reducer,
4131
- flushZones(initialData)
4588
+ flushZones(initialAppState)
4132
4589
  );
4590
+ const { data, ui } = appState;
4133
4591
  const { canForward, canRewind, rewind, forward } = usePuckHistory({
4134
- data,
4592
+ appState,
4135
4593
  dispatch
4136
4594
  });
4137
- const [itemSelector, setItemSelector] = (0, import_react28.useState)(null);
4595
+ const { itemSelector, leftSideBarVisible } = ui;
4596
+ const setItemSelector = (0, import_react32.useCallback)(
4597
+ (newItemSelector) => {
4598
+ dispatch({
4599
+ type: "setUi",
4600
+ ui: { itemSelector: newItemSelector }
4601
+ });
4602
+ },
4603
+ []
4604
+ );
4138
4605
  const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
4139
- const Page = (0, import_react28.useCallback)(
4606
+ const Page = (0, import_react32.useCallback)(
4140
4607
  (pageProps) => {
4141
4608
  var _a2, _b2;
4142
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4609
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4143
4610
  PluginRenderer,
4144
4611
  {
4145
4612
  plugins,
4146
4613
  renderMethod: "renderRoot",
4147
- data: pageProps.data,
4614
+ dispatch: pageProps.dispatch,
4615
+ state: pageProps.state,
4148
4616
  children: ((_a2 = config.root) == null ? void 0 : _a2.render) ? (_b2 = config.root) == null ? void 0 : _b2.render(__spreadProps(__spreadValues({}, pageProps), { editMode: true })) : pageProps.children
4149
4617
  }
4150
4618
  );
4151
4619
  },
4152
4620
  [config.root]
4153
4621
  );
4154
- const PageFieldWrapper = (0, import_react28.useCallback)(
4155
- (props) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4622
+ const PageFieldWrapper = (0, import_react32.useCallback)(
4623
+ (props) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4156
4624
  PluginRenderer,
4157
4625
  {
4158
4626
  plugins,
4159
4627
  renderMethod: "renderRootFields",
4160
- data: props.data,
4628
+ dispatch: props.dispatch,
4629
+ state: props.state,
4161
4630
  children: props.children
4162
4631
  }
4163
4632
  ),
4164
4633
  []
4165
4634
  );
4166
- const ComponentFieldWrapper = (0, import_react28.useCallback)(
4167
- (props) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4635
+ const ComponentFieldWrapper = (0, import_react32.useCallback)(
4636
+ (props) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4168
4637
  PluginRenderer,
4169
4638
  {
4170
4639
  plugins,
4171
4640
  renderMethod: "renderFields",
4172
- data: props.data,
4641
+ dispatch: props.dispatch,
4642
+ state: props.state,
4173
4643
  children: props.children
4174
4644
  }
4175
4645
  ),
@@ -4178,15 +4648,14 @@ function Puck({
4178
4648
  const FieldWrapper = itemSelector ? ComponentFieldWrapper : PageFieldWrapper;
4179
4649
  const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
4180
4650
  let fields = selectedItem ? ((_b = config.components[selectedItem.type]) == null ? void 0 : _b.fields) || {} : rootFields;
4181
- (0, import_react28.useEffect)(() => {
4651
+ (0, import_react32.useEffect)(() => {
4182
4652
  if (onChange)
4183
4653
  onChange(data);
4184
4654
  }, [data]);
4185
4655
  const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
4186
- const [leftSidebarVisible, setLeftSidebarVisible] = (0, import_react28.useState)(true);
4187
- const [draggedItem, setDraggedItem] = (0, import_react28.useState)();
4188
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "puck", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4189
- import_react_beautiful_dnd4.DragDropContext,
4656
+ const [draggedItem, setDraggedItem] = (0, import_react32.useState)();
4657
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "puck", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(AppProvider, { value: { state: appState, dispatch }, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4658
+ import_react_beautiful_dnd5.DragDropContext,
4190
4659
  {
4191
4660
  onDragUpdate: (update) => {
4192
4661
  setDraggedItem(__spreadValues(__spreadValues({}, draggedItem), update));
@@ -4237,7 +4706,7 @@ function Puck({
4237
4706
  });
4238
4707
  }
4239
4708
  },
4240
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4709
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4241
4710
  DropZoneProvider,
4242
4711
  {
4243
4712
  value: {
@@ -4251,19 +4720,14 @@ function Puck({
4251
4720
  mode: "edit",
4252
4721
  areaId: "root"
4253
4722
  },
4254
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(dropZoneContext.Consumer, { children: (ctx) => {
4255
- let path = (ctx == null ? void 0 : ctx.pathData) && selectedItem ? ctx == null ? void 0 : ctx.pathData[selectedItem == null ? void 0 : selectedItem.props.id] : void 0;
4256
- if (path) {
4257
- path = [{ label: "Page", selector: null }, ...path];
4258
- path = path.slice(path.length - 2, path.length - 1);
4259
- }
4260
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
4723
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(dropZoneContext.Consumer, { children: (ctx) => {
4724
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
4261
4725
  "div",
4262
4726
  {
4263
4727
  style: {
4264
4728
  display: "grid",
4265
4729
  gridTemplateAreas: '"header header header" "left editor right"',
4266
- gridTemplateColumns: `${leftSidebarVisible ? "288px" : "0px"} auto 288px`,
4730
+ gridTemplateColumns: `${leftSideBarVisible ? "288px" : "0px"} auto 288px`,
4267
4731
  gridTemplateRows: "min-content auto",
4268
4732
  height: "100vh",
4269
4733
  position: "fixed",
@@ -4273,7 +4737,7 @@ function Puck({
4273
4737
  right: 0
4274
4738
  },
4275
4739
  children: [
4276
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4740
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4277
4741
  "header",
4278
4742
  {
4279
4743
  style: {
@@ -4283,19 +4747,19 @@ function Puck({
4283
4747
  borderBottom: "1px solid var(--puck-color-grey-8)"
4284
4748
  },
4285
4749
  children: renderHeader ? renderHeader({
4286
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4750
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4287
4751
  Button,
4288
4752
  {
4289
4753
  onClick: () => {
4290
4754
  onPublish(data);
4291
4755
  },
4292
- icon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(globe_default, { size: "14px" }),
4756
+ icon: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(globe_default, { size: "14px" }),
4293
4757
  children: "Publish"
4294
4758
  }
4295
4759
  ),
4296
- data,
4297
- dispatch
4298
- }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
4760
+ dispatch,
4761
+ state: appState
4762
+ }) : /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
4299
4763
  "div",
4300
4764
  {
4301
4765
  style: {
@@ -4306,24 +4770,29 @@ function Puck({
4306
4770
  gridTemplateRows: "auto"
4307
4771
  },
4308
4772
  children: [
4309
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4773
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4310
4774
  "div",
4311
4775
  {
4312
4776
  style: {
4313
4777
  display: "flex",
4314
4778
  gap: 16
4315
4779
  },
4316
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4780
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4317
4781
  IconButton,
4318
4782
  {
4319
- onClick: () => setLeftSidebarVisible(!leftSidebarVisible),
4783
+ onClick: () => dispatch({
4784
+ type: "setUi",
4785
+ ui: {
4786
+ leftSideBarVisible: !leftSideBarVisible
4787
+ }
4788
+ }),
4320
4789
  title: "Toggle left sidebar",
4321
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(sidebar_default, {})
4790
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(sidebar_default, {})
4322
4791
  }
4323
4792
  )
4324
4793
  }
4325
4794
  ),
4326
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4795
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4327
4796
  "div",
4328
4797
  {
4329
4798
  style: {
@@ -4331,13 +4800,19 @@ function Puck({
4331
4800
  justifyContent: "center",
4332
4801
  alignItems: "center"
4333
4802
  },
4334
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Heading, { rank: 2, size: "xs", children: [
4803
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(Heading, { rank: 2, size: "xs", children: [
4335
4804
  headerTitle || data.root.title || "Page",
4336
- headerPath && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("small", { style: { fontWeight: 400, marginLeft: 4 }, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("code", { children: headerPath }) })
4805
+ headerPath && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4806
+ "small",
4807
+ {
4808
+ style: { fontWeight: 400, marginLeft: 4 },
4809
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("code", { children: headerPath })
4810
+ }
4811
+ )
4337
4812
  ] })
4338
4813
  }
4339
4814
  ),
4340
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
4815
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
4341
4816
  "div",
4342
4817
  {
4343
4818
  style: {
@@ -4346,14 +4821,14 @@ function Puck({
4346
4821
  justifyContent: "flex-end"
4347
4822
  },
4348
4823
  children: [
4349
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { style: { display: "flex" }, children: [
4350
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4824
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { style: { display: "flex" }, children: [
4825
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4351
4826
  IconButton,
4352
4827
  {
4353
4828
  title: "undo",
4354
4829
  disabled: !canRewind,
4355
4830
  onClick: rewind,
4356
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4831
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4357
4832
  chevron_left_default,
4358
4833
  {
4359
4834
  size: 21,
@@ -4362,13 +4837,13 @@ function Puck({
4362
4837
  )
4363
4838
  }
4364
4839
  ),
4365
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4840
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4366
4841
  IconButton,
4367
4842
  {
4368
4843
  title: "redo",
4369
4844
  disabled: !canForward,
4370
4845
  onClick: forward,
4371
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4846
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4372
4847
  chevron_right_default,
4373
4848
  {
4374
4849
  size: 21,
@@ -4378,14 +4853,17 @@ function Puck({
4378
4853
  }
4379
4854
  )
4380
4855
  ] }),
4381
- renderHeaderActions && renderHeaderActions({ data, dispatch }),
4382
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4856
+ renderHeaderActions && renderHeaderActions({
4857
+ state: appState,
4858
+ dispatch
4859
+ }),
4860
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4383
4861
  Button,
4384
4862
  {
4385
4863
  onClick: () => {
4386
4864
  onPublish(data);
4387
4865
  },
4388
- icon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(globe_default, { size: "14px" }),
4866
+ icon: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(globe_default, { size: "14px" }),
4389
4867
  children: "Publish"
4390
4868
  }
4391
4869
  )
@@ -4397,7 +4875,7 @@ function Puck({
4397
4875
  )
4398
4876
  }
4399
4877
  ),
4400
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
4878
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
4401
4879
  "div",
4402
4880
  {
4403
4881
  style: {
@@ -4409,9 +4887,9 @@ function Puck({
4409
4887
  flexDirection: "column"
4410
4888
  },
4411
4889
  children: [
4412
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(SidebarSection, { title: "Components", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ComponentList, { config }) }),
4413
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(SidebarSection, { title: "Outline", children: [
4414
- (ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4890
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(SidebarSection, { title: "Components", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(ComponentList, { config }) }),
4891
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(SidebarSection, { title: "Outline", children: [
4892
+ (ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4415
4893
  LayerTree,
4416
4894
  {
4417
4895
  data,
@@ -4423,7 +4901,7 @@ function Puck({
4423
4901
  ),
4424
4902
  Object.entries(findZonesForArea(data, "root")).map(
4425
4903
  ([zoneKey, zone]) => {
4426
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4904
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4427
4905
  LayerTree,
4428
4906
  {
4429
4907
  data,
@@ -4441,7 +4919,7 @@ function Puck({
4441
4919
  ]
4442
4920
  }
4443
4921
  ),
4444
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
4922
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
4445
4923
  "div",
4446
4924
  {
4447
4925
  style: {
@@ -4454,7 +4932,7 @@ function Puck({
4454
4932
  onClick: () => setItemSelector(null),
4455
4933
  id: "puck-frame",
4456
4934
  children: [
4457
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4935
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4458
4936
  "div",
4459
4937
  {
4460
4938
  className: "puck-root",
@@ -4463,18 +4941,26 @@ function Puck({
4463
4941
  margin: 32,
4464
4942
  zoom: 0.75
4465
4943
  },
4466
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4944
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4467
4945
  "div",
4468
4946
  {
4469
4947
  style: {
4470
4948
  border: "1px solid var(--puck-color-grey-8)"
4471
4949
  },
4472
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Page, __spreadProps(__spreadValues({ data }, data.root), { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(DropZone, { zone: rootDroppableId }) }))
4950
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4951
+ Page,
4952
+ __spreadProps(__spreadValues({
4953
+ dispatch,
4954
+ state: appState
4955
+ }, data.root), {
4956
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(DropZone, { zone: rootDroppableId })
4957
+ })
4958
+ )
4473
4959
  }
4474
4960
  )
4475
4961
  }
4476
4962
  ),
4477
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4963
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4478
4964
  "div",
4479
4965
  {
4480
4966
  style: {
@@ -4487,7 +4973,7 @@ function Puck({
4487
4973
  ]
4488
4974
  }
4489
4975
  ),
4490
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4976
+ /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4491
4977
  "div",
4492
4978
  {
4493
4979
  style: {
@@ -4499,12 +4985,11 @@ function Puck({
4499
4985
  flexDirection: "column",
4500
4986
  background: "var(--puck-color-white)"
4501
4987
  },
4502
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(FieldWrapper, { data, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4988
+ children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(FieldWrapper, { dispatch, state: appState, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4503
4989
  SidebarSection,
4504
4990
  {
4505
4991
  noPadding: true,
4506
- breadcrumbs: path,
4507
- breadcrumbClick: (breadcrumb) => setItemSelector(breadcrumb.selector),
4992
+ showBreadcrumbs: true,
4508
4993
  title: selectedItem ? selectedItem.type : "Page",
4509
4994
  children: Object.keys(fields).map((fieldName) => {
4510
4995
  var _a2, _b2, _c, _d;
@@ -4552,13 +5037,13 @@ function Puck({
4552
5037
  });
4553
5038
  } else {
4554
5039
  dispatch({
4555
- type: "set",
5040
+ type: "setData",
4556
5041
  data: { root: newProps }
4557
5042
  });
4558
5043
  }
4559
5044
  };
4560
5045
  if (selectedItem && itemSelector) {
4561
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5046
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4562
5047
  InputOrGroup,
4563
5048
  {
4564
5049
  field,
@@ -4574,13 +5059,15 @@ function Puck({
4574
5059
  `${selectedItem.props.id}_${fieldName}`
4575
5060
  );
4576
5061
  } else {
4577
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
5062
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4578
5063
  InputOrGroup,
4579
5064
  {
4580
5065
  field,
4581
5066
  name: fieldName,
4582
5067
  label: field.label,
4583
- readOnly: ((_d = (_c = data.root._meta) == null ? void 0 : _c.locked) == null ? void 0 : _d.indexOf(fieldName)) > -1,
5068
+ readOnly: ((_d = (_c = data.root._meta) == null ? void 0 : _c.locked) == null ? void 0 : _d.indexOf(
5069
+ fieldName
5070
+ )) > -1,
4584
5071
  value: data.root[fieldName],
4585
5072
  onChange: onChange2
4586
5073
  },
@@ -4599,17 +5086,17 @@ function Puck({
4599
5086
  }
4600
5087
  )
4601
5088
  }
4602
- ) });
5089
+ ) }) });
4603
5090
  }
4604
5091
 
4605
5092
  // components/Render/index.tsx
4606
5093
  init_react_import();
4607
- var import_jsx_runtime14 = require("react/jsx-runtime");
5094
+ var import_jsx_runtime22 = require("react/jsx-runtime");
4608
5095
  function Render({ config, data }) {
4609
5096
  if (config.root) {
4610
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DropZoneProvider, { value: { data, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(config.root.render, __spreadProps(__spreadValues({}, data.root), { editMode: false, id: "puck-root", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DropZone, { zone: rootDroppableId }) })) });
5097
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZoneProvider, { value: { data, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(config.root.render, __spreadProps(__spreadValues({}, data.root), { editMode: false, id: "puck-root", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZone, { zone: rootDroppableId }) })) });
4611
5098
  }
4612
- return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DropZoneProvider, { value: { data, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DropZone, { zone: rootDroppableId }) });
5099
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZoneProvider, { value: { data, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZone, { zone: rootDroppableId }) });
4613
5100
  }
4614
5101
  // Annotate the CommonJS export names for ESM import in node:
4615
5102
  0 && (module.exports = {