@measured/puck 0.18.0-canary.066aba9 → 0.18.0-canary.874ba1b

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.mjs CHANGED
@@ -1085,7 +1085,7 @@ init_react_import();
1085
1085
  import { DragDropProvider } from "@dnd-kit/react";
1086
1086
  import { useState as useState5 } from "react";
1087
1087
 
1088
- // lib/dnd-kit/safe.ts
1088
+ // lib/dnd/dnd-kit/safe.ts
1089
1089
  init_react_import();
1090
1090
  import {
1091
1091
  useDraggable,
@@ -1379,14 +1379,18 @@ var ArrayField = ({
1379
1379
  const subFieldName = `${name}[${i}].${fieldName}`;
1380
1380
  const wildcardFieldName = `${name}[*].${fieldName}`;
1381
1381
  const subReadOnly = forceReadOnly ? forceReadOnly : typeof readOnlyFields[subFieldName] !== "undefined" ? readOnlyFields[subFieldName] : readOnlyFields[wildcardFieldName];
1382
+ const label2 = subField.label || fieldName;
1382
1383
  return /* @__PURE__ */ jsx7(
1383
1384
  AutoFieldPrivate,
1384
1385
  {
1385
1386
  name: subFieldName,
1386
- label: subField.label || fieldName,
1387
+ label: label2,
1387
1388
  id: `${_arrayId}_${fieldName}`,
1388
1389
  readOnly: subReadOnly,
1389
- field: subField,
1390
+ field: __spreadProps(__spreadValues({}, subField), {
1391
+ label: label2
1392
+ // May be used by custom fields
1393
+ }),
1390
1394
  value: data[fieldName],
1391
1395
  onChange: (val, ui) => {
1392
1396
  onChange(
@@ -2115,14 +2119,18 @@ var ObjectField = ({
2115
2119
  const subFieldName = `${name}.${fieldName}`;
2116
2120
  const wildcardFieldName = `${name}.${fieldName}`;
2117
2121
  const subReadOnly = readOnly ? readOnly : typeof readOnlyFields[subFieldName] !== "undefined" ? readOnlyFields[subFieldName] : readOnlyFields[wildcardFieldName];
2122
+ const label2 = subField.label || fieldName;
2118
2123
  return /* @__PURE__ */ jsx17(
2119
2124
  AutoFieldPrivate,
2120
2125
  {
2121
2126
  name: subFieldName,
2122
- label: subField.label || fieldName,
2127
+ label: label2,
2123
2128
  id: `${id}_${fieldName}`,
2124
2129
  readOnly: subReadOnly,
2125
- field: subField,
2130
+ field: __spreadProps(__spreadValues({}, subField), {
2131
+ label: label2
2132
+ // May be used by custom fields
2133
+ }),
2126
2134
  value: data[fieldName],
2127
2135
  onChange: (val, ui) => {
2128
2136
  onChange(
@@ -2334,18 +2342,19 @@ init_react_import();
2334
2342
  var styles_module_default10 = { "Drawer": "_Drawer_fkqfo_1", "Drawer-draggable": "_Drawer-draggable_fkqfo_8", "Drawer-draggableBg": "_Drawer-draggableBg_fkqfo_12", "Drawer-draggableFg": "_Drawer-draggableFg_fkqfo_21", "DrawerItem-draggable": "_DrawerItem-draggable_fkqfo_25", "DrawerItem--disabled": "_DrawerItem--disabled_fkqfo_38", "DrawerItem": "_DrawerItem_fkqfo_25", "Drawer--isDraggingFrom": "_Drawer--isDraggingFrom_fkqfo_48", "DrawerItem-name": "_DrawerItem-name_fkqfo_66" };
2335
2343
 
2336
2344
  // components/Drawer/index.tsx
2337
- import { useMemo as useMemo8, useState as useState17 } from "react";
2345
+ import { useMemo as useMemo8, useState as useState18 } from "react";
2338
2346
 
2339
2347
  // components/DragDropContext/index.tsx
2340
2348
  init_react_import();
2341
2349
  import { DragDropProvider as DragDropProvider2 } from "@dnd-kit/react";
2342
2350
  import {
2343
2351
  createContext as createContext3,
2344
- useCallback as useCallback9,
2345
- useContext as useContext4,
2346
- useEffect as useEffect13,
2352
+ useCallback as useCallback11,
2353
+ useContext as useContext5,
2354
+ useEffect as useEffect15,
2355
+ useId,
2347
2356
  useRef as useRef5,
2348
- useState as useState16
2357
+ useState as useState17
2349
2358
  } from "react";
2350
2359
  import { AutoScroller, defaultPreset } from "@dnd-kit/dom";
2351
2360
 
@@ -2353,23 +2362,22 @@ import { AutoScroller, defaultPreset } from "@dnd-kit/dom";
2353
2362
  init_react_import();
2354
2363
  import {
2355
2364
  forwardRef as forwardRef3,
2356
- useCallback as useCallback8,
2357
- useContext as useContext3,
2358
- useEffect as useEffect12,
2365
+ useCallback as useCallback10,
2366
+ useContext as useContext4,
2367
+ useEffect as useEffect14,
2359
2368
  useMemo as useMemo7,
2360
- useRef as useRef4,
2361
- useState as useState15
2369
+ useRef as useRef4
2362
2370
  } from "react";
2363
2371
 
2364
2372
  // components/DraggableComponent/index.tsx
2365
2373
  init_react_import();
2366
2374
  import {
2367
- useCallback as useCallback6,
2368
- useContext as useContext2,
2375
+ useCallback as useCallback7,
2376
+ useContext as useContext3,
2369
2377
  useEffect as useEffect10,
2370
- useMemo as useMemo5,
2378
+ useMemo as useMemo6,
2371
2379
  useRef as useRef3,
2372
- useState as useState12
2380
+ useState as useState13
2373
2381
  } from "react";
2374
2382
 
2375
2383
  // css-module:/home/runner/work/puck/puck/packages/core/components/DraggableComponent/styles.module.css#css-module
@@ -2379,18 +2387,18 @@ var styles_module_default11 = { "DraggableComponent": "_DraggableComponent_1ukn8
2379
2387
  // components/DraggableComponent/index.tsx
2380
2388
  import { createPortal as createPortal2 } from "react-dom";
2381
2389
 
2382
- // components/DraggableComponent/collision/dynamic/index.ts
2390
+ // lib/dnd/collision/dynamic/index.ts
2383
2391
  init_react_import();
2384
2392
  import {
2385
2393
  CollisionPriority as CollisionPriority7,
2386
2394
  CollisionType as CollisionType7
2387
2395
  } from "@dnd-kit/abstract";
2388
2396
 
2389
- // components/DraggableComponent/collision/directional/index.ts
2397
+ // lib/dnd/collision/directional/index.ts
2390
2398
  init_react_import();
2391
2399
  import { CollisionType } from "@dnd-kit/abstract";
2392
2400
 
2393
- // components/DraggableComponent/collision/collision-debug.ts
2401
+ // lib/dnd/collision/collision-debug.ts
2394
2402
  init_react_import();
2395
2403
  var DEBUG = false;
2396
2404
  var debugElements = {};
@@ -2439,7 +2447,7 @@ var collisionDebug = (a, b, id, color, label) => {
2439
2447
  });
2440
2448
  };
2441
2449
 
2442
- // components/DraggableComponent/collision/directional/index.ts
2450
+ // lib/dnd/collision/directional/index.ts
2443
2451
  var distanceChange = "increasing";
2444
2452
  var directionalCollision = (input, previous) => {
2445
2453
  var _a;
@@ -2472,7 +2480,7 @@ var directionalCollision = (input, previous) => {
2472
2480
  return null;
2473
2481
  };
2474
2482
 
2475
- // components/DraggableComponent/collision/dynamic/get-direction.ts
2483
+ // lib/dnd/collision/dynamic/get-direction.ts
2476
2484
  init_react_import();
2477
2485
  var getDirection = (dragAxis, delta) => {
2478
2486
  if (dragAxis === "dynamic") {
@@ -2487,7 +2495,7 @@ var getDirection = (dragAxis, delta) => {
2487
2495
  return delta.y === 0 ? null : delta.y > 0 ? "down" : "up";
2488
2496
  };
2489
2497
 
2490
- // components/DraggableComponent/collision/dynamic/get-midpoint-impact.ts
2498
+ // lib/dnd/collision/dynamic/get-midpoint-impact.ts
2491
2499
  init_react_import();
2492
2500
  var getMidpointImpact = (dragShape, dropShape, direction, offsetMultiplier = 0) => {
2493
2501
  const dragRect = dragShape.boundingRectangle;
@@ -2506,7 +2514,7 @@ var getMidpointImpact = (dragShape, dropShape, direction, offsetMultiplier = 0)
2506
2514
  return dragRect.right - offset >= dropCenter.x;
2507
2515
  };
2508
2516
 
2509
- // components/DraggableComponent/collision/dynamic/track-movement-interval.ts
2517
+ // lib/dnd/collision/dynamic/track-movement-interval.ts
2510
2518
  init_react_import();
2511
2519
  import { Point } from "@dnd-kit/geometry";
2512
2520
  var INTERVAL_SENSITIVITY = 10;
@@ -2610,7 +2618,14 @@ var closestCorners = (input) => {
2610
2618
  };
2611
2619
  };
2612
2620
 
2613
- // components/DraggableComponent/collision/dynamic/index.ts
2621
+ // lib/dnd/collision/dynamic/store.ts
2622
+ init_react_import();
2623
+ import { createStore } from "zustand/vanilla";
2624
+ var collisionStore = createStore(() => ({
2625
+ fallbackEnabled: false
2626
+ }));
2627
+
2628
+ // lib/dnd/collision/dynamic/index.ts
2614
2629
  var flushNext = "";
2615
2630
  var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input) => {
2616
2631
  var _a, _b, _c, _d, _e;
@@ -2622,6 +2637,7 @@ var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input
2622
2637
  return null;
2623
2638
  }
2624
2639
  const { center: dragCenter } = dragShape;
2640
+ const { fallbackEnabled } = collisionStore.getState();
2625
2641
  const interval = trackMovementInterval(position.current, dragAxis);
2626
2642
  dragOperation.data = __spreadProps(__spreadValues({}, dragOperation.data), {
2627
2643
  direction: interval.direction
@@ -2667,7 +2683,7 @@ var createDynamicCollisionDetector = (dragAxis, midpointOffset = 0.05) => (input
2667
2683
  flushNext = "";
2668
2684
  return __spreadProps(__spreadValues({}, collision), { id: shouldFlushId ? "flush" : collision.id });
2669
2685
  }
2670
- if (((_c = dragOperation.source) == null ? void 0 : _c.id) !== droppable.id) {
2686
+ if (fallbackEnabled && ((_c = dragOperation.source) == null ? void 0 : _c.id) !== droppable.id) {
2671
2687
  const xAxisIntersection = dropShape.boundingRectangle.right > dragShape.boundingRectangle.left && dropShape.boundingRectangle.left < dragShape.boundingRectangle.right;
2672
2688
  const yAxisIntersection = dropShape.boundingRectangle.bottom > dragShape.boundingRectangle.top && dropShape.boundingRectangle.top < dragShape.boundingRectangle.bottom;
2673
2689
  if (dragAxis === "y" && xAxisIntersection || yAxisIntersection) {
@@ -2728,8 +2744,107 @@ function getDeepScrollPosition(element) {
2728
2744
  return totalScroll;
2729
2745
  }
2730
2746
 
2747
+ // components/DropZone/context.tsx
2748
+ init_react_import();
2749
+ import {
2750
+ createContext as createContext2,
2751
+ useCallback as useCallback6,
2752
+ useMemo as useMemo5,
2753
+ useState as useState12
2754
+ } from "react";
2755
+ import { createStore as createStore2 } from "zustand";
2756
+ import { Fragment as Fragment5, jsx as jsx19 } from "react/jsx-runtime";
2757
+ var dropZoneContext = createContext2(null);
2758
+ var ZoneStoreContext = createContext2(
2759
+ createStore2(() => ({
2760
+ zoneDepthIndex: {},
2761
+ nextZoneDepthIndex: {},
2762
+ areaDepthIndex: {},
2763
+ nextAreaDepthIndex: {},
2764
+ draggedItem: null,
2765
+ previewIndex: {}
2766
+ }))
2767
+ );
2768
+ var ZoneStoreProvider = ({
2769
+ children,
2770
+ store
2771
+ }) => {
2772
+ return /* @__PURE__ */ jsx19(ZoneStoreContext.Provider, { value: store, children });
2773
+ };
2774
+ var DropZoneProvider = ({
2775
+ children,
2776
+ value
2777
+ }) => {
2778
+ const [hoveringComponent, setHoveringComponent] = useState12();
2779
+ const [areasWithZones, setAreasWithZones] = useState12(
2780
+ {}
2781
+ );
2782
+ const [activeZones, setActiveZones] = useState12({});
2783
+ const { dispatch } = useAppContext();
2784
+ const registerZoneArea = useCallback6(
2785
+ (area) => {
2786
+ setAreasWithZones((latest) => __spreadProps(__spreadValues({}, latest), { [area]: true }));
2787
+ },
2788
+ [setAreasWithZones]
2789
+ );
2790
+ const registerZone = useCallback6(
2791
+ (zoneCompound) => {
2792
+ if (!dispatch) {
2793
+ return;
2794
+ }
2795
+ dispatch({
2796
+ type: "registerZone",
2797
+ zone: zoneCompound
2798
+ });
2799
+ setActiveZones((latest) => __spreadProps(__spreadValues({}, latest), { [zoneCompound]: true }));
2800
+ },
2801
+ [setActiveZones, dispatch]
2802
+ );
2803
+ const unregisterZone = useCallback6(
2804
+ (zoneCompound) => {
2805
+ if (!dispatch) {
2806
+ return;
2807
+ }
2808
+ dispatch({
2809
+ type: "unregisterZone",
2810
+ zone: zoneCompound
2811
+ });
2812
+ setActiveZones((latest) => __spreadProps(__spreadValues({}, latest), {
2813
+ [zoneCompound]: false
2814
+ }));
2815
+ },
2816
+ [setActiveZones, dispatch]
2817
+ );
2818
+ const memoValue = useMemo5(
2819
+ () => __spreadValues({
2820
+ hoveringComponent,
2821
+ setHoveringComponent,
2822
+ registerZoneArea,
2823
+ areasWithZones,
2824
+ registerZone,
2825
+ unregisterZone,
2826
+ activeZones
2827
+ }, value),
2828
+ [value, hoveringComponent, areasWithZones, activeZones]
2829
+ );
2830
+ return /* @__PURE__ */ jsx19(Fragment5, { children: memoValue && /* @__PURE__ */ jsx19(dropZoneContext.Provider, { value: memoValue, children }) });
2831
+ };
2832
+
2833
+ // lib/use-context-store.ts
2834
+ init_react_import();
2835
+ import { useContext as useContext2 } from "react";
2836
+ import { useStore } from "zustand";
2837
+ import { useShallow } from "zustand/react/shallow";
2838
+ function useContextStore(context, selector) {
2839
+ const store = useContext2(context);
2840
+ if (!store) {
2841
+ throw new Error("useContextStore must be used inside context");
2842
+ }
2843
+ return useStore(store, useShallow(selector));
2844
+ }
2845
+
2731
2846
  // components/DraggableComponent/index.tsx
2732
- import { jsx as jsx19, jsxs as jsxs9 } from "react/jsx-runtime";
2847
+ import { jsx as jsx20, jsxs as jsxs9 } from "react/jsx-runtime";
2733
2848
  var getClassName16 = get_class_name_factory_default("DraggableComponent", styles_module_default11);
2734
2849
  var DEBUG2 = false;
2735
2850
  var space = 8;
@@ -2743,9 +2858,9 @@ var DefaultActionBar = ({
2743
2858
  }) => /* @__PURE__ */ jsxs9(ActionBar, { children: [
2744
2859
  /* @__PURE__ */ jsxs9(ActionBar.Group, { children: [
2745
2860
  parentAction,
2746
- label && /* @__PURE__ */ jsx19(ActionBar.Label, { label })
2861
+ label && /* @__PURE__ */ jsx20(ActionBar.Label, { label })
2747
2862
  ] }),
2748
- /* @__PURE__ */ jsx19(ActionBar.Group, { children })
2863
+ /* @__PURE__ */ jsx20(ActionBar.Group, { children })
2749
2864
  ] });
2750
2865
  var convertIdToSelector = (id, zoneCompound, data) => {
2751
2866
  const content = zoneCompound && data.zones && zoneCompound !== "default-zone" ? data.zones[zoneCompound] : data.content;
@@ -2780,9 +2895,9 @@ var DraggableComponent = ({
2780
2895
  iframe,
2781
2896
  state
2782
2897
  } = useAppContext();
2783
- const ctx = useContext2(dropZoneContext);
2784
- const [localZones, setLocalZones] = useState12({});
2785
- const registerLocalZone = useCallback6(
2898
+ const ctx = useContext3(dropZoneContext);
2899
+ const [localZones, setLocalZones] = useState13({});
2900
+ const registerLocalZone = useCallback7(
2786
2901
  (zoneCompound2, active) => {
2787
2902
  var _a;
2788
2903
  (_a = ctx == null ? void 0 : ctx.registerLocalZone) == null ? void 0 : _a.call(ctx, zoneCompound2, active);
@@ -2792,7 +2907,7 @@ var DraggableComponent = ({
2792
2907
  },
2793
2908
  [setLocalZones]
2794
2909
  );
2795
- const unregisterLocalZone = useCallback6(
2910
+ const unregisterLocalZone = useCallback7(
2796
2911
  (zoneCompound2) => {
2797
2912
  var _a;
2798
2913
  (_a = ctx == null ? void 0 : ctx.unregisterLocalZone) == null ? void 0 : _a.call(ctx, zoneCompound2);
@@ -2806,7 +2921,7 @@ var DraggableComponent = ({
2806
2921
  );
2807
2922
  const containsActiveZone = Object.values(localZones).filter(Boolean).length > 0;
2808
2923
  const { path = [] } = ctx || {};
2809
- const [canDrag, setCanDrag] = useState12(false);
2924
+ const [canDrag, setCanDrag] = useState13(false);
2810
2925
  useEffect10(() => {
2811
2926
  var _a;
2812
2927
  const item = getItem({ index, zone: zoneCompound }, state.data);
@@ -2817,10 +2932,13 @@ var DraggableComponent = ({
2817
2932
  setCanDrag((_a = perms.drag) != null ? _a : true);
2818
2933
  }
2819
2934
  }, [state, index, zoneCompound, getPermissions]);
2820
- const userIsDragging = !!(ctx == null ? void 0 : ctx.draggedItem);
2935
+ const userIsDragging = useContextStore(
2936
+ ZoneStoreContext,
2937
+ (s) => !!s.draggedItem
2938
+ );
2821
2939
  const canCollide = canDrag || userIsDragging;
2822
2940
  const disabled = !isEnabled || !canCollide;
2823
- const [dragAxis, setDragAxis] = useState12(userDragAxis || autoDragAxis);
2941
+ const [dragAxis, setDragAxis] = useState13(userDragAxis || autoDragAxis);
2824
2942
  const { ref: sortableRef, status } = useSortableSafe({
2825
2943
  id,
2826
2944
  index,
@@ -2847,7 +2965,7 @@ var DraggableComponent = ({
2847
2965
  });
2848
2966
  const thisIsDragging = status === "dragging";
2849
2967
  const ref = useRef3(null);
2850
- const refSetter = useCallback6(
2968
+ const refSetter = useCallback7(
2851
2969
  (el) => {
2852
2970
  sortableRef(el);
2853
2971
  if (el) {
@@ -2856,14 +2974,14 @@ var DraggableComponent = ({
2856
2974
  },
2857
2975
  [sortableRef]
2858
2976
  );
2859
- const [portalEl, setPortalEl] = useState12();
2977
+ const [portalEl, setPortalEl] = useState13();
2860
2978
  useEffect10(() => {
2861
2979
  var _a, _b, _c;
2862
2980
  setPortalEl(
2863
2981
  iframe.enabled ? (_a = ref.current) == null ? void 0 : _a.ownerDocument.body : (_c = (_b = ref.current) == null ? void 0 : _b.closest("[data-puck-preview]")) != null ? _c : document.body
2864
2982
  );
2865
2983
  }, [iframe.enabled, ref.current]);
2866
- const getStyle = useCallback6(() => {
2984
+ const getStyle = useCallback7(() => {
2867
2985
  var _a, _b, _c;
2868
2986
  if (!ref.current) return;
2869
2987
  const rect = ref.current.getBoundingClientRect();
@@ -2883,8 +3001,8 @@ var DraggableComponent = ({
2883
3001
  };
2884
3002
  return style2;
2885
3003
  }, [ref.current]);
2886
- const [style, setStyle] = useState12();
2887
- const sync = useCallback6(() => {
3004
+ const [style, setStyle] = useState13();
3005
+ const sync = useCallback7(() => {
2888
3006
  setStyle(getStyle());
2889
3007
  }, [ref.current, iframe]);
2890
3008
  useEffect10(() => {
@@ -2897,19 +3015,21 @@ var DraggableComponent = ({
2897
3015
  }
2898
3016
  }, [ref.current]);
2899
3017
  useEffect10(() => {
2900
- ctx == null ? void 0 : ctx.registerPath({
2901
- index,
2902
- zone: zoneCompound
2903
- });
3018
+ if (isSelected) {
3019
+ ctx == null ? void 0 : ctx.registerPath({
3020
+ index,
3021
+ zone: zoneCompound
3022
+ });
3023
+ }
2904
3024
  }, [isSelected]);
2905
- const CustomActionBar = useMemo5(
3025
+ const CustomActionBar = useMemo6(
2906
3026
  () => overrides.actionBar || DefaultActionBar,
2907
3027
  [overrides.actionBar]
2908
3028
  );
2909
3029
  const permissions = getPermissions({
2910
3030
  item: selectedItem
2911
3031
  });
2912
- const onClick = useCallback6(
3032
+ const onClick = useCallback7(
2913
3033
  (e) => {
2914
3034
  e.stopPropagation();
2915
3035
  dispatch({
@@ -2921,7 +3041,7 @@ var DraggableComponent = ({
2921
3041
  },
2922
3042
  [index, zoneCompound, id]
2923
3043
  );
2924
- const onSelectParent = useCallback6(() => {
3044
+ const onSelectParent = useCallback7(() => {
2925
3045
  if (!(ctx == null ? void 0 : ctx.areaId)) {
2926
3046
  return;
2927
3047
  }
@@ -2939,21 +3059,21 @@ var DraggableComponent = ({
2939
3059
  }
2940
3060
  });
2941
3061
  }, [ctx, path]);
2942
- const onDuplicate = useCallback6(() => {
3062
+ const onDuplicate = useCallback7(() => {
2943
3063
  dispatch({
2944
3064
  type: "duplicate",
2945
3065
  sourceIndex: index,
2946
3066
  sourceZone: zoneCompound
2947
3067
  });
2948
3068
  }, [index, zoneCompound]);
2949
- const onDelete = useCallback6(() => {
3069
+ const onDelete = useCallback7(() => {
2950
3070
  dispatch({
2951
3071
  type: "remove",
2952
3072
  index,
2953
3073
  zone: zoneCompound
2954
3074
  });
2955
3075
  }, [index, zoneCompound]);
2956
- const [hover, setHover] = useState12(false);
3076
+ const [hover, setHover] = useState13(false);
2957
3077
  const indicativeHover = (ctx == null ? void 0 : ctx.hoveringComponent) === id;
2958
3078
  useEffect10(() => {
2959
3079
  if (!ref.current) {
@@ -3014,7 +3134,7 @@ var DraggableComponent = ({
3014
3134
  };
3015
3135
  }
3016
3136
  }, [disabled, ref]);
3017
- const [isVisible, setIsVisible] = useState12(false);
3137
+ const [isVisible, setIsVisible] = useState13(false);
3018
3138
  useEffect10(() => {
3019
3139
  sync();
3020
3140
  if ((isSelected || hover || indicativeHover) && !userIsDragging) {
@@ -3023,7 +3143,7 @@ var DraggableComponent = ({
3023
3143
  setIsVisible(false);
3024
3144
  }
3025
3145
  }, [isSelected, hover, indicativeHover, iframe, state.data, userIsDragging]);
3026
- const syncActionsPosition = useCallback6(
3146
+ const syncActionsPosition = useCallback7(
3027
3147
  (el) => {
3028
3148
  if (el) {
3029
3149
  const view = el.ownerDocument.defaultView;
@@ -3054,7 +3174,7 @@ var DraggableComponent = ({
3054
3174
  }
3055
3175
  setDragAxis(autoDragAxis);
3056
3176
  }, [ref, userDragAxis, autoDragAxis]);
3057
- const parentAction = (ctx == null ? void 0 : ctx.areaId) && (ctx == null ? void 0 : ctx.areaId) !== "root" && /* @__PURE__ */ jsx19(ActionBar.Action, { onClick: onSelectParent, label: "Select parent", children: /* @__PURE__ */ jsx19(CornerLeftUp, { size: 16 }) });
3177
+ const parentAction = (ctx == null ? void 0 : ctx.areaId) && (ctx == null ? void 0 : ctx.areaId) !== "root" && /* @__PURE__ */ jsx20(ActionBar.Action, { onClick: onSelectParent, label: "Select parent", children: /* @__PURE__ */ jsx20(CornerLeftUp, { size: 16 }) });
3058
3178
  return /* @__PURE__ */ jsxs9(
3059
3179
  DropZoneProvider,
3060
3180
  {
@@ -3081,15 +3201,15 @@ var DraggableComponent = ({
3081
3201
  "data-puck-overlay": true,
3082
3202
  children: [
3083
3203
  debug,
3084
- isLoading && /* @__PURE__ */ jsx19("div", { className: getClassName16("loadingOverlay"), children: /* @__PURE__ */ jsx19(Loader, {}) }),
3085
- /* @__PURE__ */ jsx19(
3204
+ isLoading && /* @__PURE__ */ jsx20("div", { className: getClassName16("loadingOverlay"), children: /* @__PURE__ */ jsx20(Loader, {}) }),
3205
+ /* @__PURE__ */ jsx20(
3086
3206
  "div",
3087
3207
  {
3088
3208
  className: getClassName16("actionsOverlay"),
3089
3209
  style: {
3090
3210
  top: actionsOverlayTop / zoomConfig.zoom
3091
3211
  },
3092
- children: /* @__PURE__ */ jsx19(
3212
+ children: /* @__PURE__ */ jsx20(
3093
3213
  "div",
3094
3214
  {
3095
3215
  className: getClassName16("actions"),
@@ -3107,8 +3227,8 @@ var DraggableComponent = ({
3107
3227
  parentAction,
3108
3228
  label: DEBUG2 ? id : label,
3109
3229
  children: [
3110
- permissions.duplicate && /* @__PURE__ */ jsx19(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ jsx19(Copy, { size: 16 }) }),
3111
- permissions.delete && /* @__PURE__ */ jsx19(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ jsx19(Trash, { size: 16 }) })
3230
+ permissions.duplicate && /* @__PURE__ */ jsx20(ActionBar.Action, { onClick: onDuplicate, label: "Duplicate", children: /* @__PURE__ */ jsx20(Copy, { size: 16 }) }),
3231
+ permissions.delete && /* @__PURE__ */ jsx20(ActionBar.Action, { onClick: onDelete, label: "Delete", children: /* @__PURE__ */ jsx20(Trash, { size: 16 }) })
3112
3232
  ]
3113
3233
  }
3114
3234
  )
@@ -3116,7 +3236,7 @@ var DraggableComponent = ({
3116
3236
  )
3117
3237
  }
3118
3238
  ),
3119
- /* @__PURE__ */ jsx19("div", { className: getClassName16("overlay") })
3239
+ /* @__PURE__ */ jsx20("div", { className: getClassName16("overlay") })
3120
3240
  ]
3121
3241
  }
3122
3242
  ),
@@ -3132,98 +3252,26 @@ var DraggableComponent = ({
3132
3252
  init_react_import();
3133
3253
  var styles_module_default12 = { "DropZone": "_DropZone_kmkdc_1", "DropZone--isActive": "_DropZone--isActive_kmkdc_10", "DropZone--hasChildren": "_DropZone--hasChildren_kmkdc_14", "DropZone--userIsDragging": "_DropZone--userIsDragging_kmkdc_22", "DropZone--isAreaSelected": "_DropZone--isAreaSelected_kmkdc_26", "DropZone--hoveringOverArea": "_DropZone--hoveringOverArea_kmkdc_27", "DropZone--isRootZone": "_DropZone--isRootZone_kmkdc_27", "DropZone--isDestination": "_DropZone--isDestination_kmkdc_37", "DropZone-item": "_DropZone-item_kmkdc_49", "DropZone-hitbox": "_DropZone-hitbox_kmkdc_53", "DropZone--isEnabled": "_DropZone--isEnabled_kmkdc_61", "DropZone--isAnimating": "_DropZone--isAnimating_kmkdc_70" };
3134
3254
 
3135
- // components/DropZone/context.tsx
3136
- init_react_import();
3137
- import {
3138
- createContext as createContext2,
3139
- useCallback as useCallback7,
3140
- useMemo as useMemo6,
3141
- useState as useState13
3142
- } from "react";
3143
- import { Fragment as Fragment5, jsx as jsx20 } from "react/jsx-runtime";
3144
- var dropZoneContext = createContext2(null);
3145
- var DropZoneProvider = ({
3146
- children,
3147
- value
3148
- }) => {
3149
- const [hoveringComponent, setHoveringComponent] = useState13();
3150
- const [areasWithZones, setAreasWithZones] = useState13(
3151
- {}
3152
- );
3153
- const [activeZones, setActiveZones] = useState13({});
3154
- const { dispatch } = useAppContext();
3155
- const registerZoneArea = useCallback7(
3156
- (area) => {
3157
- setAreasWithZones((latest) => __spreadProps(__spreadValues({}, latest), { [area]: true }));
3158
- },
3159
- [setAreasWithZones]
3160
- );
3161
- const registerZone = useCallback7(
3162
- (zoneCompound) => {
3163
- if (!dispatch) {
3164
- return;
3165
- }
3166
- dispatch({
3167
- type: "registerZone",
3168
- zone: zoneCompound
3169
- });
3170
- setActiveZones((latest) => __spreadProps(__spreadValues({}, latest), { [zoneCompound]: true }));
3171
- },
3172
- [setActiveZones, dispatch]
3173
- );
3174
- const unregisterZone = useCallback7(
3175
- (zoneCompound) => {
3176
- if (!dispatch) {
3177
- return;
3178
- }
3179
- dispatch({
3180
- type: "unregisterZone",
3181
- zone: zoneCompound
3182
- });
3183
- setActiveZones((latest) => __spreadProps(__spreadValues({}, latest), {
3184
- [zoneCompound]: false
3185
- }));
3186
- },
3187
- [setActiveZones, dispatch]
3188
- );
3189
- const memoValue = useMemo6(
3190
- () => __spreadValues({
3191
- hoveringComponent,
3192
- setHoveringComponent,
3193
- registerZoneArea,
3194
- areasWithZones,
3195
- registerZone,
3196
- unregisterZone,
3197
- activeZones
3198
- }, value),
3199
- [value, hoveringComponent, areasWithZones, activeZones]
3200
- );
3201
- return /* @__PURE__ */ jsx20(Fragment5, { children: memoValue && /* @__PURE__ */ jsx20(dropZoneContext.Provider, { value: memoValue, children }) });
3202
- };
3203
-
3204
- // lib/insert.ts
3205
- init_react_import();
3206
- var insert = (list, index, item) => {
3207
- const result = Array.from(list);
3208
- result.splice(index, 0, item);
3209
- return result;
3210
- };
3211
-
3212
- // components/DropZone/use-min-empty-height.ts
3255
+ // components/DropZone/lib/use-min-empty-height.ts
3213
3256
  init_react_import();
3214
3257
  import { useEffect as useEffect11, useState as useState14 } from "react";
3215
3258
  var useMinEmptyHeight = ({
3216
- draggedItem,
3217
3259
  zoneCompound,
3218
3260
  userMinEmptyHeight,
3219
3261
  ref
3220
3262
  }) => {
3221
3263
  const [prevHeight, setPrevHeight] = useState14(0);
3222
3264
  const [isAnimating, setIsAnimating] = useState14(false);
3265
+ const { draggedItem, isZone } = useContextStore(ZoneStoreContext, (s) => {
3266
+ var _a, _b;
3267
+ return {
3268
+ draggedItem: ((_a = s.draggedItem) == null ? void 0 : _a.data.zone) === zoneCompound ? s.draggedItem : null,
3269
+ isZone: ((_b = s.draggedItem) == null ? void 0 : _b.data.zone) === zoneCompound
3270
+ };
3271
+ });
3223
3272
  useEffect11(() => {
3224
3273
  if (draggedItem && ref.current) {
3225
- const componentData = draggedItem.data;
3226
- if (componentData.zone === zoneCompound) {
3274
+ if (isZone) {
3227
3275
  const rect = ref.current.getBoundingClientRect();
3228
3276
  setPrevHeight(rect.height);
3229
3277
  setIsAnimating(true);
@@ -3253,13 +3301,128 @@ function assignRefs(refs, node) {
3253
3301
  });
3254
3302
  }
3255
3303
 
3256
- // components/DropZone/index.tsx
3257
- import { Fragment as Fragment6, jsx as jsx21, jsxs as jsxs10 } from "react/jsx-runtime";
3258
- var getClassName17 = get_class_name_factory_default("DropZone", styles_module_default12);
3259
- var DEBUG3 = false;
3304
+ // components/DropZone/lib/use-content-with-preview.ts
3305
+ init_react_import();
3306
+ import { useEffect as useEffect12, useState as useState15 } from "react";
3307
+
3308
+ // lib/dnd/use-rendered-callback.ts
3309
+ init_react_import();
3310
+ import { useDragDropManager } from "@dnd-kit/react";
3311
+ import { useCallback as useCallback8 } from "react";
3312
+ function useRenderedCallback(callback, deps) {
3313
+ const manager = useDragDropManager();
3314
+ return useCallback8(
3315
+ (...args) => __async(this, null, function* () {
3316
+ yield manager == null ? void 0 : manager.renderer.rendering;
3317
+ return callback(...args);
3318
+ }),
3319
+ [...deps, manager]
3320
+ );
3321
+ }
3322
+
3323
+ // lib/insert.ts
3324
+ init_react_import();
3325
+ var insert = (list, index, item) => {
3326
+ const result = Array.from(list);
3327
+ result.splice(index, 0, item);
3328
+ return result;
3329
+ };
3330
+
3331
+ // components/DropZone/lib/use-content-with-preview.ts
3332
+ var useContentWithPreview = (content, zoneCompound) => {
3333
+ const { draggedItemId, preview, previewExists } = useContextStore(
3334
+ ZoneStoreContext,
3335
+ (s) => {
3336
+ var _a;
3337
+ return {
3338
+ draggedItemId: (_a = s.draggedItem) == null ? void 0 : _a.id,
3339
+ preview: s.previewIndex[zoneCompound],
3340
+ previewExists: Object.keys(s.previewIndex || {}).length > 0
3341
+ };
3342
+ }
3343
+ );
3344
+ const [contentWithPreview, setContentWithPreview] = useState15(content);
3345
+ const updateContent = useRenderedCallback(
3346
+ (content2, preview2) => {
3347
+ if (preview2) {
3348
+ if (preview2.type === "insert") {
3349
+ setContentWithPreview(
3350
+ insert(
3351
+ content2.filter((item) => item.props.id !== preview2.props.id),
3352
+ preview2.index,
3353
+ {
3354
+ type: "preview",
3355
+ props: { id: preview2.props.id }
3356
+ }
3357
+ )
3358
+ );
3359
+ } else {
3360
+ setContentWithPreview(
3361
+ insert(
3362
+ content2.filter((item) => item.props.id !== preview2.props.id),
3363
+ preview2.index,
3364
+ {
3365
+ type: preview2.componentType,
3366
+ props: preview2.props
3367
+ }
3368
+ )
3369
+ );
3370
+ }
3371
+ } else {
3372
+ setContentWithPreview(
3373
+ previewExists ? content2.filter((item) => item.props.id !== draggedItemId) : content2
3374
+ );
3375
+ }
3376
+ },
3377
+ [draggedItemId, previewExists]
3378
+ );
3379
+ useEffect12(() => {
3380
+ updateContent(content, preview);
3381
+ }, [content, preview]);
3382
+ return contentWithPreview;
3383
+ };
3384
+
3385
+ // components/DropZone/lib/use-drag-axis.ts
3386
+ init_react_import();
3387
+ import { useCallback as useCallback9, useEffect as useEffect13, useState as useState16 } from "react";
3260
3388
  var GRID_DRAG_AXIS = "dynamic";
3261
3389
  var FLEX_ROW_DRAG_AXIS = "x";
3262
3390
  var DEFAULT_DRAG_AXIS = "y";
3391
+ var useDragAxis = (ref, collisionAxis) => {
3392
+ const { status } = useAppContext();
3393
+ const [dragAxis, setDragAxis] = useState16(
3394
+ collisionAxis || DEFAULT_DRAG_AXIS
3395
+ );
3396
+ const calculateDragAxis = useCallback9(() => {
3397
+ if (ref.current) {
3398
+ const computedStyle = window.getComputedStyle(ref.current);
3399
+ if (computedStyle.display === "grid") {
3400
+ setDragAxis(GRID_DRAG_AXIS);
3401
+ } else if (computedStyle.display === "flex" && computedStyle.flexDirection === "row") {
3402
+ setDragAxis(FLEX_ROW_DRAG_AXIS);
3403
+ } else {
3404
+ setDragAxis(DEFAULT_DRAG_AXIS);
3405
+ }
3406
+ }
3407
+ }, [ref.current]);
3408
+ useEffect13(() => {
3409
+ const onViewportChange = () => {
3410
+ calculateDragAxis();
3411
+ };
3412
+ window.addEventListener("viewportchange", onViewportChange);
3413
+ return () => {
3414
+ window.removeEventListener("viewportchange", onViewportChange);
3415
+ };
3416
+ }, []);
3417
+ useEffect13(calculateDragAxis, [status, collisionAxis]);
3418
+ return [dragAxis, calculateDragAxis];
3419
+ };
3420
+
3421
+ // components/DropZone/index.tsx
3422
+ import { Fragment as Fragment6, jsx as jsx21, jsxs as jsxs10 } from "react/jsx-runtime";
3423
+ var getClassName17 = get_class_name_factory_default("DropZone", styles_module_default12);
3424
+ var getRandomColor = () => `#${Math.floor(Math.random() * 16777215).toString(16)}`;
3425
+ var RENDER_DEBUG = false;
3263
3426
  var DropZoneEdit = forwardRef3(
3264
3427
  function DropZoneEdit2({
3265
3428
  zone,
@@ -3271,31 +3434,50 @@ var DropZoneEdit = forwardRef3(
3271
3434
  collisionAxis
3272
3435
  }, userRef) {
3273
3436
  const appContext2 = useAppContext();
3274
- const ctx = useContext3(dropZoneContext);
3437
+ const ctx = useContext4(dropZoneContext);
3275
3438
  const {
3276
3439
  // These all need setting via context
3277
3440
  data,
3278
3441
  config,
3279
3442
  areaId,
3280
- draggedItem,
3281
3443
  registerZoneArea,
3282
3444
  depth,
3283
3445
  registerLocalZone,
3284
3446
  unregisterLocalZone,
3285
- deepestZone = rootDroppableId,
3286
- deepestArea,
3287
- nextDeepestArea,
3288
3447
  path = [],
3289
3448
  activeZones
3290
3449
  } = ctx;
3291
- const { itemSelector } = appContext2.state.ui;
3292
3450
  let zoneCompound = rootDroppableId;
3293
- useEffect12(() => {
3451
+ if (areaId) {
3452
+ if (zone !== rootDroppableId) {
3453
+ zoneCompound = `${areaId}:${zone}`;
3454
+ }
3455
+ }
3456
+ const isRootZone = zoneCompound === rootDroppableId || zone === rootDroppableId || areaId === "root";
3457
+ const {
3458
+ isDeepestZone,
3459
+ inNextDeepestArea,
3460
+ draggedComponentType,
3461
+ userIsDragging,
3462
+ preview
3463
+ } = useContextStore(ZoneStoreContext, (s) => {
3464
+ var _a, _b, _c;
3465
+ return {
3466
+ isDeepestZone: (_a = s.zoneDepthIndex[zoneCompound]) != null ? _a : false,
3467
+ inNextDeepestArea: s.nextAreaDepthIndex[areaId || ""],
3468
+ draggedItemId: (_b = s.draggedItem) == null ? void 0 : _b.id,
3469
+ draggedComponentType: (_c = s.draggedItem) == null ? void 0 : _c.data.componentType,
3470
+ userIsDragging: !!s.draggedItem,
3471
+ preview: s.previewIndex[zoneCompound]
3472
+ };
3473
+ });
3474
+ const { itemSelector } = appContext2.state.ui;
3475
+ useEffect14(() => {
3294
3476
  if (areaId && registerZoneArea) {
3295
3477
  registerZoneArea(areaId);
3296
3478
  }
3297
3479
  }, [areaId]);
3298
- useEffect12(() => {
3480
+ useEffect14(() => {
3299
3481
  if (ctx == null ? void 0 : ctx.registerZone) {
3300
3482
  ctx == null ? void 0 : ctx.registerZone(zoneCompound);
3301
3483
  }
@@ -3305,11 +3487,6 @@ var DropZoneEdit = forwardRef3(
3305
3487
  }
3306
3488
  };
3307
3489
  }, []);
3308
- if (areaId) {
3309
- if (zone !== rootDroppableId) {
3310
- zoneCompound = `${areaId}:${zone}`;
3311
- }
3312
- }
3313
3490
  const content = useMemo7(() => {
3314
3491
  if (areaId && zone !== rootDroppableId) {
3315
3492
  return setupZone(data, zoneCompound).zones[zoneCompound];
@@ -3317,13 +3494,11 @@ var DropZoneEdit = forwardRef3(
3317
3494
  return data.content || [];
3318
3495
  }, [data, zoneCompound]);
3319
3496
  const ref = useRef4(null);
3320
- const acceptsTarget = useCallback8(
3321
- (target) => {
3322
- if (!target) {
3497
+ const acceptsTarget = useCallback10(
3498
+ (componentType) => {
3499
+ if (!componentType) {
3323
3500
  return true;
3324
3501
  }
3325
- const data2 = target.data;
3326
- const { componentType } = data2;
3327
3502
  if (disallow) {
3328
3503
  const defaultedAllow = allow || [];
3329
3504
  const filteredDisallow = (disallow || []).filter(
@@ -3341,49 +3516,26 @@ var DropZoneEdit = forwardRef3(
3341
3516
  },
3342
3517
  [allow, disallow]
3343
3518
  );
3344
- useEffect12(() => {
3519
+ useEffect14(() => {
3345
3520
  if (registerLocalZone) {
3346
- registerLocalZone(zoneCompound, acceptsTarget(draggedItem));
3521
+ registerLocalZone(zoneCompound, acceptsTarget(draggedComponentType));
3347
3522
  }
3348
3523
  return () => {
3349
3524
  if (unregisterLocalZone) {
3350
3525
  unregisterLocalZone(zoneCompound);
3351
3526
  }
3352
3527
  };
3353
- }, [draggedItem, zoneCompound]);
3354
- const isRootZone = zoneCompound === rootDroppableId || zone === rootDroppableId || areaId === "root";
3355
- const hoveringOverArea = nextDeepestArea ? nextDeepestArea === areaId : isRootZone;
3356
- const userIsDragging = !!draggedItem;
3528
+ }, [draggedComponentType, zoneCompound]);
3529
+ const hoveringOverArea = inNextDeepestArea || isRootZone;
3357
3530
  let isEnabled = true;
3358
- if (draggedItem) {
3359
- isEnabled = deepestZone === zoneCompound;
3531
+ if (userIsDragging) {
3532
+ isEnabled = isDeepestZone;
3360
3533
  }
3361
3534
  if (isEnabled) {
3362
- isEnabled = acceptsTarget(draggedItem);
3363
- }
3364
- const preview = useContext3(previewContext);
3365
- const previewInZone = (preview == null ? void 0 : preview.zone) === zoneCompound;
3366
- const contentWithPreview = useMemo7(() => {
3367
- let contentWithPreview2 = preview ? content.filter((item) => item.props.id !== preview.props.id) : content;
3368
- if (previewInZone) {
3369
- contentWithPreview2 = content.filter(
3370
- (item) => item.props.id !== preview.props.id
3371
- );
3372
- if (preview.type === "insert") {
3373
- contentWithPreview2 = insert(contentWithPreview2, preview.index, {
3374
- type: "preview",
3375
- props: { id: preview.props.id }
3376
- });
3377
- } else {
3378
- contentWithPreview2 = insert(contentWithPreview2, preview.index, {
3379
- type: preview.componentType,
3380
- props: preview.props
3381
- });
3382
- }
3383
- }
3384
- return contentWithPreview2;
3385
- }, [preview, content]);
3386
- const isDropEnabled = isEnabled && (previewInZone ? contentWithPreview.length === 1 : contentWithPreview.length === 0);
3535
+ isEnabled = acceptsTarget(draggedComponentType);
3536
+ }
3537
+ const contentWithPreview = useContentWithPreview(content, zoneCompound);
3538
+ const isDropEnabled = isEnabled && (preview ? contentWithPreview.length === 1 : contentWithPreview.length === 0);
3387
3539
  const droppableConfig = {
3388
3540
  id: zoneCompound,
3389
3541
  collisionPriority: isEnabled ? depth : 0,
@@ -3393,45 +3545,20 @@ var DropZoneEdit = forwardRef3(
3393
3545
  data: {
3394
3546
  areaId,
3395
3547
  depth,
3396
- isDroppableTarget: acceptsTarget(draggedItem),
3548
+ isDroppableTarget: acceptsTarget(draggedComponentType),
3397
3549
  path
3398
3550
  }
3399
3551
  };
3400
3552
  const { ref: dropRef } = useDroppableSafe(droppableConfig);
3401
3553
  const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
3402
3554
  const isAreaSelected = selectedItem && areaId === selectedItem.props.id;
3403
- const [dragAxis, setDragAxis] = useState15(
3404
- collisionAxis || DEFAULT_DRAG_AXIS
3405
- );
3406
- const calculateDragAxis = useCallback8(() => {
3407
- if (ref.current) {
3408
- const computedStyle = window.getComputedStyle(ref.current);
3409
- if (computedStyle.display === "grid") {
3410
- setDragAxis(GRID_DRAG_AXIS);
3411
- } else if (computedStyle.display === "flex" && computedStyle.flexDirection === "row") {
3412
- setDragAxis(FLEX_ROW_DRAG_AXIS);
3413
- } else {
3414
- setDragAxis(DEFAULT_DRAG_AXIS);
3415
- }
3416
- }
3417
- }, [ref.current]);
3418
- useEffect12(calculateDragAxis, [appContext2.status, collisionAxis]);
3419
- useEffect12(() => {
3420
- const onViewportChange = () => {
3421
- calculateDragAxis();
3422
- };
3423
- window.addEventListener("viewportchange", onViewportChange);
3424
- return () => {
3425
- window.removeEventListener("viewportchange", onViewportChange);
3426
- };
3427
- }, []);
3555
+ const [dragAxis] = useDragAxis(ref, collisionAxis);
3428
3556
  const [minEmptyHeight, isAnimating] = useMinEmptyHeight({
3429
- draggedItem,
3430
3557
  zoneCompound,
3431
3558
  userMinEmptyHeight,
3432
3559
  ref
3433
3560
  });
3434
- return /* @__PURE__ */ jsxs10(
3561
+ return /* @__PURE__ */ jsx21(
3435
3562
  "div",
3436
3563
  {
3437
3564
  className: `${getClassName17({
@@ -3451,88 +3578,83 @@ var DropZoneEdit = forwardRef3(
3451
3578
  "data-puck-dropzone": zoneCompound,
3452
3579
  "data-puck-dnd": zoneCompound,
3453
3580
  style: __spreadProps(__spreadValues({}, style), {
3454
- "--min-empty-height": `${minEmptyHeight}px`
3581
+ "--min-empty-height": `${minEmptyHeight}px`,
3582
+ backgroundColor: RENDER_DEBUG ? getRandomColor() : void 0
3455
3583
  }),
3456
- children: [
3457
- isRootZone && DEBUG3 && /* @__PURE__ */ jsxs10("div", { "data-puck-component": true, children: [
3458
- /* @__PURE__ */ jsx21("p", { children: deepestZone || rootDroppableId }),
3459
- /* @__PURE__ */ jsx21("p", { children: deepestArea || "No area" })
3460
- ] }),
3461
- contentWithPreview.map((item, i) => {
3462
- var _a, _b, _c, _d, _e;
3463
- const componentId = item.props.id;
3464
- const puckProps = {
3465
- renderDropZone: DropZone,
3466
- isEditing: true,
3467
- dragRef: null
3584
+ children: contentWithPreview.map((item, i) => {
3585
+ var _a, _b, _c, _d, _e;
3586
+ const componentId = item.props.id;
3587
+ const puckProps = {
3588
+ renderDropZone: DropZone,
3589
+ isEditing: true,
3590
+ dragRef: null
3591
+ };
3592
+ const defaultedProps = __spreadProps(__spreadValues(__spreadValues({}, (_a = config.components[item.type]) == null ? void 0 : _a.defaultProps), item.props), {
3593
+ puck: puckProps,
3594
+ editMode: true
3595
+ // DEPRECATED
3596
+ });
3597
+ const isSelected = (selectedItem == null ? void 0 : selectedItem.props.id) === componentId || false;
3598
+ let Render2 = config.components[item.type] && item.type !== "preview" ? config.components[item.type].render : () => /* @__PURE__ */ jsxs10("div", { style: { padding: 48, textAlign: "center" }, children: [
3599
+ "No configuration for ",
3600
+ item.type
3601
+ ] });
3602
+ const componentConfig = config.components[item.type];
3603
+ let componentType = item.type;
3604
+ let label = (_b = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _b : item.type.toString();
3605
+ if (item.type === "preview" && preview) {
3606
+ let Preview4 = function() {
3607
+ return /* @__PURE__ */ jsx21(DrawerItemInner, { name: label, children: appContext2.overrides.componentItem });
3468
3608
  };
3469
- const defaultedProps = __spreadProps(__spreadValues(__spreadValues({}, (_a = config.components[item.type]) == null ? void 0 : _a.defaultProps), item.props), {
3470
- puck: puckProps,
3471
- editMode: true
3472
- // DEPRECATED
3473
- });
3474
- const isSelected = (selectedItem == null ? void 0 : selectedItem.props.id) === componentId || false;
3475
- let Render2 = config.components[item.type] ? config.components[item.type].render : () => /* @__PURE__ */ jsxs10("div", { style: { padding: 48, textAlign: "center" }, children: [
3476
- "No configuration for ",
3477
- item.type
3478
- ] });
3479
- const componentConfig = config.components[item.type];
3480
- let componentType = item.type;
3481
- let label = (_b = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _b : item.type.toString();
3482
- if (item.type === "preview") {
3483
- let Preview3 = function() {
3484
- return /* @__PURE__ */ jsx21(DrawerItemInner, { name: label });
3485
- };
3486
- var Preview2 = Preview3;
3487
- componentType = preview.componentType;
3488
- label = (_d = (_c = config.components[componentType]) == null ? void 0 : _c.label) != null ? _d : preview.componentType;
3489
- Render2 = Preview3;
3490
- }
3491
- return /* @__PURE__ */ jsx21(
3492
- DropZoneProvider,
3493
- {
3494
- value: __spreadProps(__spreadValues({}, ctx), { path: [...path, zoneCompound] }),
3495
- children: /* @__PURE__ */ jsx21(
3496
- DraggableComponent,
3497
- {
3498
- id: componentId,
3499
- componentType,
3500
- zoneCompound,
3501
- depth: depth + 1,
3502
- index: i,
3503
- isLoading: ((_e = appContext2.componentState[componentId]) == null ? void 0 : _e.loadingCount) > 0,
3504
- isSelected,
3505
- label,
3506
- isEnabled,
3507
- autoDragAxis: dragAxis,
3508
- userDragAxis: collisionAxis,
3509
- inDroppableZone: acceptsTarget(draggedItem),
3510
- children: (dragRef) => (componentConfig == null ? void 0 : componentConfig.inline) ? /* @__PURE__ */ jsx21(
3511
- Render2,
3512
- __spreadProps(__spreadValues({}, defaultedProps), {
3513
- puck: __spreadProps(__spreadValues({}, defaultedProps.puck), {
3514
- dragRef
3515
- })
3609
+ var Preview3 = Preview4;
3610
+ componentType = preview.componentType;
3611
+ label = (_d = (_c = config.components[componentType]) == null ? void 0 : _c.label) != null ? _d : preview.componentType;
3612
+ Render2 = Preview4;
3613
+ }
3614
+ return /* @__PURE__ */ jsx21(
3615
+ DropZoneProvider,
3616
+ {
3617
+ value: __spreadProps(__spreadValues({}, ctx), { path: [...path, zoneCompound] }),
3618
+ children: /* @__PURE__ */ jsx21(
3619
+ DraggableComponent,
3620
+ {
3621
+ id: componentId,
3622
+ componentType,
3623
+ zoneCompound,
3624
+ depth: depth + 1,
3625
+ index: i,
3626
+ isLoading: ((_e = appContext2.componentState[componentId]) == null ? void 0 : _e.loadingCount) > 0,
3627
+ isSelected,
3628
+ label,
3629
+ isEnabled,
3630
+ autoDragAxis: dragAxis,
3631
+ userDragAxis: collisionAxis,
3632
+ inDroppableZone: acceptsTarget(draggedComponentType),
3633
+ children: (dragRef) => (componentConfig == null ? void 0 : componentConfig.inline) ? /* @__PURE__ */ jsx21(
3634
+ Render2,
3635
+ __spreadProps(__spreadValues({}, defaultedProps), {
3636
+ puck: __spreadProps(__spreadValues({}, defaultedProps.puck), {
3637
+ dragRef
3516
3638
  })
3517
- ) : /* @__PURE__ */ jsx21("div", { ref: dragRef, children: /* @__PURE__ */ jsx21(Render2, __spreadValues({}, defaultedProps)) })
3518
- }
3519
- )
3520
- },
3521
- componentId
3522
- );
3523
- })
3524
- ]
3639
+ })
3640
+ ) : /* @__PURE__ */ jsx21("div", { ref: dragRef, children: /* @__PURE__ */ jsx21(Render2, __spreadValues({}, defaultedProps)) })
3641
+ }
3642
+ )
3643
+ },
3644
+ componentId
3645
+ );
3646
+ })
3525
3647
  }
3526
3648
  );
3527
3649
  }
3528
3650
  );
3529
3651
  var DropZoneRender = forwardRef3(
3530
3652
  function DropZoneRender2({ className, style, zone }, ref) {
3531
- const ctx = useContext3(dropZoneContext);
3653
+ const ctx = useContext4(dropZoneContext);
3532
3654
  const { data, areaId = "root", config } = ctx || {};
3533
3655
  let zoneCompound = rootDroppableId;
3534
3656
  let content = (data == null ? void 0 : data.content) || [];
3535
- useEffect12(() => {
3657
+ useEffect14(() => {
3536
3658
  if (ctx == null ? void 0 : ctx.registerZone) {
3537
3659
  ctx == null ? void 0 : ctx.registerZone(zoneCompound);
3538
3660
  }
@@ -3578,7 +3700,7 @@ var DropZoneRender = forwardRef3(
3578
3700
  );
3579
3701
  var DropZone = forwardRef3(
3580
3702
  function DropZone2(props, ref) {
3581
- const ctx = useContext3(dropZoneContext);
3703
+ const ctx = useContext4(dropZoneContext);
3582
3704
  if ((ctx == null ? void 0 : ctx.mode) === "edit") {
3583
3705
  return /* @__PURE__ */ jsx21(Fragment6, { children: /* @__PURE__ */ jsx21(DropZoneEdit, __spreadProps(__spreadValues({}, props), { ref })) });
3584
3706
  }
@@ -3598,7 +3720,7 @@ var getZoneId = (zoneCompound) => {
3598
3720
  return [rootDroppableId, zoneCompound];
3599
3721
  };
3600
3722
 
3601
- // components/DragDropContext/NestedDroppablePlugin.ts
3723
+ // lib/dnd/NestedDroppablePlugin.ts
3602
3724
  init_react_import();
3603
3725
  import { Plugin } from "@dnd-kit/abstract";
3604
3726
  import { effects } from "@dnd-kit/state";
@@ -3640,7 +3762,7 @@ var getFrame = () => {
3640
3762
  return (frameEl == null ? void 0 : frameEl.ownerDocument) || document;
3641
3763
  };
3642
3764
 
3643
- // components/DragDropContext/NestedDroppablePlugin.ts
3765
+ // lib/dnd/NestedDroppablePlugin.ts
3644
3766
  var depthSort = (candidates) => {
3645
3767
  return candidates.sort((a, b) => {
3646
3768
  const aData = a.data;
@@ -3755,9 +3877,7 @@ var findDeepestCandidate = (position, manager, ownerDocument) => {
3755
3877
  area: null
3756
3878
  };
3757
3879
  };
3758
- var createNestedDroppablePlugin = ({
3759
- onChange
3760
- }) => class NestedDroppablePlugin extends Plugin {
3880
+ var createNestedDroppablePlugin = ({ onChange }, id) => class NestedDroppablePlugin extends Plugin {
3761
3881
  constructor(manager, options) {
3762
3882
  super(manager);
3763
3883
  if (typeof window === "undefined") {
@@ -3771,10 +3891,17 @@ var createNestedDroppablePlugin = ({
3771
3891
  };
3772
3892
  const target = event.originalTarget || event.target;
3773
3893
  const ownerDocument = target == null ? void 0 : target.ownerDocument;
3774
- onChange(
3775
- findDeepestCandidate(position, manager, ownerDocument),
3776
- manager
3894
+ const elements = document.elementsFromPoint(
3895
+ event.clientX,
3896
+ event.clientY
3777
3897
  );
3898
+ const overEl = elements.some((el) => el.id === id);
3899
+ if (overEl) {
3900
+ onChange(
3901
+ findDeepestCandidate(position, manager, ownerDocument),
3902
+ manager
3903
+ );
3904
+ }
3778
3905
  };
3779
3906
  const handleMoveThrottled = throttle(handleMove, 50);
3780
3907
  const handlePointerMove = (event) => {
@@ -4191,7 +4318,7 @@ var insertComponent = (componentType, zone, index, {
4191
4318
  import { useDebouncedCallback as useDebouncedCallback2 } from "use-debounce";
4192
4319
  import { isElement as isElement2 } from "@dnd-kit/dom/utilities";
4193
4320
 
4194
- // components/DragDropContext/PointerSensor.ts
4321
+ // lib/dnd/PointerSensor.ts
4195
4322
  init_react_import();
4196
4323
  import { batch, effect } from "@dnd-kit/state";
4197
4324
  import { Sensor, configurator } from "@dnd-kit/abstract";
@@ -4462,13 +4589,15 @@ function patchWindow(window2) {
4462
4589
  }
4463
4590
 
4464
4591
  // components/DragDropContext/index.tsx
4592
+ import { createStore as createStore3 } from "zustand";
4465
4593
  import { jsx as jsx22 } from "react/jsx-runtime";
4594
+ var DEBUG3 = false;
4466
4595
  var dragListenerContext = createContext3({
4467
4596
  dragListeners: {}
4468
4597
  });
4469
4598
  function useDragListener(type, fn, deps = []) {
4470
- const { setDragListeners } = useContext4(dragListenerContext);
4471
- useEffect13(() => {
4599
+ const { setDragListeners } = useContext5(dragListenerContext);
4600
+ useEffect15(() => {
4472
4601
  if (setDragListeners) {
4473
4602
  setDragListeners((old) => __spreadProps(__spreadValues({}, old), {
4474
4603
  [type]: [...old[type] || [], fn]
@@ -4476,80 +4605,147 @@ function useDragListener(type, fn, deps = []) {
4476
4605
  }
4477
4606
  }, deps);
4478
4607
  }
4479
- var previewContext = createContext3(null);
4480
4608
  var AREA_CHANGE_DEBOUNCE_MS = 100;
4609
+ var useTempDisableFallback = (timeout3) => {
4610
+ const lastFallbackDisable = useRef5(null);
4611
+ return useCallback11((manager) => {
4612
+ collisionStore.setState({ fallbackEnabled: false });
4613
+ const fallbackId = generateId();
4614
+ lastFallbackDisable.current = fallbackId;
4615
+ setTimeout(() => {
4616
+ if (lastFallbackDisable.current === fallbackId) {
4617
+ collisionStore.setState({ fallbackEnabled: true });
4618
+ manager.collisionObserver.forceUpdate(true);
4619
+ }
4620
+ }, timeout3);
4621
+ }, []);
4622
+ };
4481
4623
  var DragDropContextClient = ({
4482
4624
  children,
4483
4625
  disableAutoScroll
4484
4626
  }) => {
4485
4627
  const { state, config, dispatch, resolveData } = useAppContext();
4486
- const [preview, setPreview] = useState16(null);
4487
- const previewRef = useRef5(null);
4628
+ const id = useId();
4488
4629
  const { data } = state;
4489
- const [deepest, setDeepest] = useState16(null);
4490
- const [nextDeepest, setNextDeepest] = useState16(null);
4491
- const deepestRef = useRef5(deepest);
4492
4630
  const debouncedParamsRef = useRef5(null);
4493
- const setDeepestAndCollide = useCallback9(
4631
+ const tempDisableFallback = useTempDisableFallback(100);
4632
+ const [zoneStore] = useState17(
4633
+ () => createStore3(() => ({
4634
+ zoneDepthIndex: {},
4635
+ nextZoneDepthIndex: {},
4636
+ areaDepthIndex: {},
4637
+ nextAreaDepthIndex: {},
4638
+ draggedItem: null,
4639
+ previewIndex: {}
4640
+ }))
4641
+ );
4642
+ const getChanged2 = useCallback11(
4643
+ (params, id2) => {
4644
+ const { zoneDepthIndex = {}, areaDepthIndex = {} } = zoneStore.getState() || {};
4645
+ const stateHasZone = Object.keys(zoneDepthIndex).length > 0;
4646
+ const stateHasArea = Object.keys(areaDepthIndex).length > 0;
4647
+ let zoneChanged = false;
4648
+ let areaChanged = false;
4649
+ if (params.zone && !zoneDepthIndex[params.zone]) {
4650
+ zoneChanged = true;
4651
+ } else if (!params.zone && stateHasZone) {
4652
+ zoneChanged = true;
4653
+ }
4654
+ if (params.area && !areaDepthIndex[params.area]) {
4655
+ areaChanged = true;
4656
+ } else if (!params.area && stateHasArea) {
4657
+ areaChanged = true;
4658
+ }
4659
+ return { zoneChanged, areaChanged };
4660
+ },
4661
+ [zoneStore]
4662
+ );
4663
+ const setDeepestAndCollide = useCallback11(
4494
4664
  (params, manager) => {
4495
- setDeepest(params);
4665
+ const { zoneChanged, areaChanged } = getChanged2(params, id);
4666
+ if (!zoneChanged && !areaChanged) return;
4667
+ zoneStore.setState({
4668
+ zoneDepthIndex: params.zone ? { [params.zone]: true } : {},
4669
+ areaDepthIndex: params.area ? { [params.area]: true } : {}
4670
+ });
4671
+ tempDisableFallback(manager);
4496
4672
  setTimeout(() => {
4497
4673
  manager.collisionObserver.forceUpdate(true);
4498
4674
  }, 50);
4499
4675
  debouncedParamsRef.current = null;
4500
4676
  },
4501
- []
4677
+ [zoneStore]
4502
4678
  );
4503
4679
  const setDeepestDb = useDebouncedCallback2(
4504
4680
  setDeepestAndCollide,
4505
4681
  AREA_CHANGE_DEBOUNCE_MS
4506
4682
  );
4507
- useEffect13(() => {
4508
- deepestRef.current = deepest;
4509
- }, [deepest]);
4510
4683
  const cancelDb = () => {
4511
4684
  setDeepestDb.cancel();
4512
4685
  debouncedParamsRef.current = null;
4513
4686
  };
4514
- const [plugins] = useState16(() => [
4515
- ...disableAutoScroll ? defaultPreset.plugins.filter((plugin) => plugin !== AutoScroller) : defaultPreset.plugins,
4516
- createNestedDroppablePlugin({
4517
- onChange: (params, manager) => {
4518
- const lastParams = deepestRef.current;
4519
- const areaChanged = params.area !== (lastParams == null ? void 0 : lastParams.area);
4520
- const zoneChanged = params.zone !== (lastParams == null ? void 0 : lastParams.zone);
4521
- const isDragging = manager.dragOperation.status.dragging;
4522
- if (areaChanged || zoneChanged) {
4523
- setNextDeepest(params);
4524
- }
4525
- if (params.zone !== "void" && (lastParams == null ? void 0 : lastParams.zone) === "void") {
4526
- setDeepest(params);
4527
- manager.collisionObserver.forceUpdate(true);
4528
- return;
4687
+ useEffect15(() => {
4688
+ if (DEBUG3) {
4689
+ zoneStore.subscribe(
4690
+ (s) => {
4691
+ var _a, _b;
4692
+ return console.log(
4693
+ s.previewIndex,
4694
+ (_a = Object.entries(s.zoneDepthIndex || {})[0]) == null ? void 0 : _a[0],
4695
+ (_b = Object.entries(s.areaDepthIndex || {})[0]) == null ? void 0 : _b[0]
4696
+ );
4529
4697
  }
4530
- if (areaChanged) {
4531
- if (isDragging) {
4532
- const debouncedParams = debouncedParamsRef.current;
4533
- const isSameParams = debouncedParams && debouncedParams.area === params.area && debouncedParams.zone === params.zone;
4534
- if (!isSameParams) {
4698
+ );
4699
+ }
4700
+ }, []);
4701
+ const [plugins] = useState17(() => [
4702
+ ...disableAutoScroll ? defaultPreset.plugins.filter((plugin) => plugin !== AutoScroller) : defaultPreset.plugins,
4703
+ createNestedDroppablePlugin(
4704
+ {
4705
+ onChange: (params, manager) => {
4706
+ const state2 = zoneStore.getState();
4707
+ const { zoneChanged, areaChanged } = getChanged2(params, id);
4708
+ const isDragging = manager.dragOperation.status.dragging;
4709
+ if (areaChanged || zoneChanged) {
4710
+ let nextZoneDepthIndex = {};
4711
+ let nextAreaDepthIndex = {};
4712
+ if (params.zone) {
4713
+ nextZoneDepthIndex = { [params.zone]: true };
4714
+ }
4715
+ if (params.area) {
4716
+ nextAreaDepthIndex = { [params.area]: true };
4717
+ }
4718
+ zoneStore.setState({ nextZoneDepthIndex, nextAreaDepthIndex });
4719
+ }
4720
+ if (params.zone !== "void" && (state2 == null ? void 0 : state2.zoneDepthIndex["void"])) {
4721
+ setDeepestAndCollide(params, manager);
4722
+ return;
4723
+ }
4724
+ if (areaChanged) {
4725
+ if (isDragging) {
4726
+ const debouncedParams = debouncedParamsRef.current;
4727
+ const isSameParams = debouncedParams && debouncedParams.area === params.area && debouncedParams.zone === params.zone;
4728
+ if (!isSameParams) {
4729
+ cancelDb();
4730
+ setDeepestDb(params, manager);
4731
+ debouncedParamsRef.current = params;
4732
+ }
4733
+ } else {
4535
4734
  cancelDb();
4536
- setDeepestDb(params, manager);
4537
- debouncedParamsRef.current = params;
4735
+ setDeepestAndCollide(params, manager);
4538
4736
  }
4539
- } else {
4540
- cancelDb();
4737
+ return;
4738
+ }
4739
+ if (zoneChanged) {
4541
4740
  setDeepestAndCollide(params, manager);
4542
4741
  }
4543
- return;
4544
- }
4545
- if (zoneChanged) {
4546
- setDeepestAndCollide(params, manager);
4742
+ cancelDb();
4547
4743
  }
4548
- cancelDb();
4549
- }
4550
- })
4744
+ },
4745
+ id
4746
+ )
4551
4747
  ]);
4552
- const [sensors] = useState16(() => [
4748
+ const [sensors] = useState17(() => [
4553
4749
  PointerSensor.configure({
4554
4750
  activationConstraints(event, source) {
4555
4751
  var _a;
@@ -4568,11 +4764,10 @@ var DragDropContextClient = ({
4568
4764
  }
4569
4765
  })
4570
4766
  ]);
4571
- const [draggedItem, setDraggedItem] = useState16();
4572
- const [dragListeners, setDragListeners] = useState16({});
4573
- const [pathData, setPathData] = useState16();
4767
+ const [dragListeners, setDragListeners] = useState17({});
4768
+ const [pathData, setPathData] = useState17();
4574
4769
  const dragMode = useRef5(null);
4575
- const registerPath = useCallback9(
4770
+ const registerPath = useCallback11(
4576
4771
  (selector) => {
4577
4772
  const item = getItem(selector, data);
4578
4773
  if (!item) {
@@ -4595,40 +4790,40 @@ var DragDropContextClient = ({
4595
4790
  [data, setPathData]
4596
4791
  );
4597
4792
  const initialSelector = useRef5(void 0);
4598
- return /* @__PURE__ */ jsx22(
4793
+ return /* @__PURE__ */ jsx22("div", { id, children: /* @__PURE__ */ jsx22(
4599
4794
  dragListenerContext.Provider,
4600
4795
  {
4601
4796
  value: {
4602
4797
  dragListeners,
4603
4798
  setDragListeners
4604
4799
  },
4605
- children: /* @__PURE__ */ jsx22(previewContext.Provider, { value: preview, children: /* @__PURE__ */ jsx22(
4800
+ children: /* @__PURE__ */ jsx22(
4606
4801
  DragDropProvider2,
4607
4802
  {
4608
4803
  plugins,
4609
4804
  sensors,
4610
4805
  onDragEnd: (event, manager) => {
4806
+ var _a;
4611
4807
  const { source, target } = event.operation;
4612
- deepestRef.current = null;
4613
4808
  if (!source) {
4614
- setDraggedItem(null);
4809
+ zoneStore.setState({ draggedItem: null });
4615
4810
  return;
4616
4811
  }
4617
4812
  const { zone, index } = source.data;
4618
- const thisPreview = previewRef.current ? __spreadValues({}, previewRef.current) : null;
4619
- previewRef.current = null;
4813
+ const { previewIndex = {} } = zoneStore.getState() || {};
4814
+ const thisPreview = ((_a = previewIndex[zone]) == null ? void 0 : _a.props.id) === source.id ? previewIndex[zone] : null;
4620
4815
  setTimeout(() => {
4621
- var _a, _b;
4622
- setDraggedItem(null);
4816
+ var _a2, _b;
4817
+ zoneStore.setState({ draggedItem: null });
4623
4818
  if (event.canceled || (target == null ? void 0 : target.type) === "void") {
4624
- setPreview(null);
4625
- (_a = dragListeners.dragend) == null ? void 0 : _a.forEach((fn) => {
4819
+ zoneStore.setState({ previewIndex: {} });
4820
+ (_a2 = dragListeners.dragend) == null ? void 0 : _a2.forEach((fn) => {
4626
4821
  fn(event, manager);
4627
4822
  });
4628
4823
  return;
4629
4824
  }
4630
4825
  if (thisPreview) {
4631
- setPreview(null);
4826
+ zoneStore.setState({ previewIndex: {} });
4632
4827
  if (thisPreview.type === "insert") {
4633
4828
  insertComponent(
4634
4829
  thisPreview.componentType,
@@ -4663,8 +4858,9 @@ var DragDropContextClient = ({
4663
4858
  }, 250);
4664
4859
  },
4665
4860
  onDragOver: (event, manager) => {
4666
- var _a, _b, _c, _d;
4861
+ var _a, _b, _c, _d, _e;
4667
4862
  event.preventDefault();
4863
+ const draggedItem = (_a = zoneStore.getState()) == null ? void 0 : _a.draggedItem;
4668
4864
  if (!draggedItem) return;
4669
4865
  cancelDb();
4670
4866
  const { source, target } = event.operation;
@@ -4680,7 +4876,7 @@ var DragDropContextClient = ({
4680
4876
  const targetData = target.data;
4681
4877
  targetZone = targetData.zone;
4682
4878
  targetIndex = targetData.index;
4683
- const collisionData = (_b = (_a = manager.dragOperation.data) == null ? void 0 : _a.collisionMap) == null ? void 0 : _b[targetId];
4879
+ const collisionData = (_c = (_b = manager.dragOperation.data) == null ? void 0 : _b.collisionMap) == null ? void 0 : _c[targetId];
4684
4880
  const collisionPosition = (collisionData == null ? void 0 : collisionData.direction) === "up" || (collisionData == null ? void 0 : collisionData.direction) === "left" ? "before" : "after";
4685
4881
  if (targetIndex >= sourceIndex && sourceZone === targetZone) {
4686
4882
  targetIndex = targetIndex - 1;
@@ -4692,23 +4888,26 @@ var DragDropContextClient = ({
4692
4888
  targetZone = target.id.toString();
4693
4889
  targetIndex = 0;
4694
4890
  }
4695
- if (targetId === sourceId || ((_c = pathData == null ? void 0 : pathData[target.id]) == null ? void 0 : _c.path.find((path) => {
4891
+ if (targetId === sourceId || ((_d = pathData == null ? void 0 : pathData[target.id]) == null ? void 0 : _d.path.find((path) => {
4696
4892
  const [pathId] = path.split(":");
4697
4893
  return pathId === sourceId;
4698
4894
  }))) {
4699
4895
  return;
4700
4896
  }
4701
4897
  if (dragMode.current === "new") {
4702
- previewRef.current = {
4703
- componentType: sourceData.componentType,
4704
- type: "insert",
4705
- index: targetIndex,
4706
- zone: targetZone,
4707
- props: {
4708
- id: source.id.toString()
4898
+ zoneStore.setState({
4899
+ previewIndex: {
4900
+ [targetZone]: {
4901
+ componentType: sourceData.componentType,
4902
+ type: "insert",
4903
+ index: targetIndex,
4904
+ zone: targetZone,
4905
+ props: {
4906
+ id: source.id.toString()
4907
+ }
4908
+ }
4709
4909
  }
4710
- };
4711
- setPreview(previewRef.current);
4910
+ });
4712
4911
  } else {
4713
4912
  if (!initialSelector.current) {
4714
4913
  initialSelector.current = {
@@ -4718,17 +4917,20 @@ var DragDropContextClient = ({
4718
4917
  }
4719
4918
  const item = getItem(initialSelector.current, data);
4720
4919
  if (item) {
4721
- previewRef.current = {
4722
- componentType: sourceData.componentType,
4723
- type: "move",
4724
- index: targetIndex,
4725
- zone: targetZone,
4726
- props: item.props
4727
- };
4728
- setPreview(previewRef.current);
4920
+ zoneStore.setState({
4921
+ previewIndex: {
4922
+ [targetZone]: {
4923
+ componentType: sourceData.componentType,
4924
+ type: "move",
4925
+ index: targetIndex,
4926
+ zone: targetZone,
4927
+ props: item.props
4928
+ }
4929
+ }
4930
+ });
4729
4931
  }
4730
4932
  }
4731
- (_d = dragListeners.dragover) == null ? void 0 : _d.forEach((fn) => {
4933
+ (_e = dragListeners.dragover) == null ? void 0 : _e.forEach((fn) => {
4732
4934
  fn(event, manager);
4733
4935
  });
4734
4936
  },
@@ -4738,45 +4940,61 @@ var DragDropContextClient = ({
4738
4940
  type: "setUi",
4739
4941
  ui: { itemSelector: null, isDragging: true }
4740
4942
  });
4943
+ const { source } = event.operation;
4944
+ if (source && source.type !== "void") {
4945
+ const sourceData = source.data;
4946
+ const item = getItem(
4947
+ {
4948
+ zone: sourceData.zone,
4949
+ index: sourceData.index
4950
+ },
4951
+ data
4952
+ );
4953
+ if (item) {
4954
+ zoneStore.setState({
4955
+ previewIndex: {
4956
+ [sourceData.zone]: {
4957
+ componentType: sourceData.componentType,
4958
+ type: "move",
4959
+ index: sourceData.index,
4960
+ zone: sourceData.zone,
4961
+ props: item.props
4962
+ }
4963
+ }
4964
+ });
4965
+ }
4966
+ }
4741
4967
  (_a = dragListeners.dragstart) == null ? void 0 : _a.forEach((fn) => {
4742
4968
  fn(event, manager);
4743
4969
  });
4744
4970
  },
4745
4971
  onBeforeDragStart: (event) => {
4746
4972
  var _a;
4747
- if (draggedItem) {
4748
- console.warn("New drag started before previous drag cleaned up");
4749
- }
4750
4973
  const isNewComponent = ((_a = event.operation.source) == null ? void 0 : _a.data.type) === "drawer";
4751
4974
  dragMode.current = isNewComponent ? "new" : "existing";
4752
4975
  initialSelector.current = void 0;
4753
- setDraggedItem(event.operation.source);
4976
+ zoneStore.setState({ draggedItem: event.operation.source });
4754
4977
  },
4755
- children: /* @__PURE__ */ jsx22(
4978
+ children: /* @__PURE__ */ jsx22(ZoneStoreProvider, { store: zoneStore, children: /* @__PURE__ */ jsx22(
4756
4979
  DropZoneProvider,
4757
4980
  {
4758
4981
  value: {
4759
4982
  data,
4760
4983
  config,
4761
- draggedItem,
4762
4984
  mode: "edit",
4763
4985
  areaId: "root",
4764
4986
  depth: 0,
4765
4987
  registerPath,
4766
4988
  pathData,
4767
- deepestZone: deepest == null ? void 0 : deepest.zone,
4768
- deepestArea: deepest == null ? void 0 : deepest.area,
4769
- nextDeepestZone: nextDeepest == null ? void 0 : nextDeepest.zone,
4770
- nextDeepestArea: nextDeepest == null ? void 0 : nextDeepest.area,
4771
4989
  path: []
4772
4990
  },
4773
4991
  children
4774
4992
  }
4775
- )
4993
+ ) })
4776
4994
  }
4777
- ) })
4995
+ )
4778
4996
  }
4779
- );
4997
+ ) });
4780
4998
  };
4781
4999
  var DragDropContext = ({
4782
5000
  children,
@@ -4854,7 +5072,7 @@ var DrawerItem = ({
4854
5072
  isDragDisabled
4855
5073
  }) => {
4856
5074
  const resolvedId = id || name;
4857
- const [dynamicId, setDynamicId] = useState17(generateId(resolvedId));
5075
+ const [dynamicId, setDynamicId] = useState18(generateId(resolvedId));
4858
5076
  if (typeof index !== "undefined") {
4859
5077
  console.error(
4860
5078
  "Warning: The `index` prop on Drawer.Item is deprecated and no longer required."
@@ -4893,7 +5111,7 @@ var Drawer = ({
4893
5111
  "Warning: The `direction` prop on Drawer is deprecated and no longer required to achieve multi-directional dragging."
4894
5112
  );
4895
5113
  }
4896
- const [id] = useState17(generateId());
5114
+ const [id] = useState18(generateId());
4897
5115
  const { ref } = useDroppableSafe({
4898
5116
  id,
4899
5117
  type: "void",
@@ -4916,11 +5134,11 @@ Drawer.Item = DrawerItem;
4916
5134
  // components/Puck/index.tsx
4917
5135
  init_react_import();
4918
5136
  import {
4919
- useCallback as useCallback15,
4920
- useEffect as useEffect21,
5137
+ useCallback as useCallback17,
5138
+ useEffect as useEffect23,
4921
5139
  useMemo as useMemo17,
4922
5140
  useReducer,
4923
- useState as useState25
5141
+ useState as useState26
4924
5142
  } from "react";
4925
5143
 
4926
5144
  // components/SidebarSection/index.tsx
@@ -4932,7 +5150,7 @@ var styles_module_default13 = { "SidebarSection": "_SidebarSection_125qe_1", "Si
4932
5150
 
4933
5151
  // lib/use-breadcrumbs.ts
4934
5152
  init_react_import();
4935
- import { useContext as useContext5, useMemo as useMemo9 } from "react";
5153
+ import { useContext as useContext6, useMemo as useMemo9 } from "react";
4936
5154
  var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
4937
5155
  const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
4938
5156
  const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
@@ -4982,7 +5200,7 @@ var useBreadcrumbs = (renderCount) => {
4982
5200
  state: { data },
4983
5201
  selectedItem
4984
5202
  } = useAppContext();
4985
- const dzContext = useContext5(dropZoneContext);
5203
+ const dzContext = useContext6(dropZoneContext);
4986
5204
  return useMemo9(() => {
4987
5205
  const breadcrumbs = convertPathDataToBreadcrumbs(
4988
5206
  selectedItem,
@@ -5107,7 +5325,7 @@ function MenuBar({
5107
5325
 
5108
5326
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/styles.module.css#css-module
5109
5327
  init_react_import();
5110
- var styles_module_default15 = { "Puck": "_Puck_1g88c_19", "Puck-portal": "_Puck-portal_1g88c_24", "PuckLayout": "_PuckLayout_1g88c_31", "PuckLayout-inner": "_PuckLayout-inner_1g88c_39", "PuckLayout--mounted": "_PuckLayout--mounted_1g88c_51", "PuckLayout--leftSideBarVisible": "_PuckLayout--leftSideBarVisible_1g88c_55", "PuckLayout--rightSideBarVisible": "_PuckLayout--rightSideBarVisible_1g88c_61", "PuckLayout-mounted": "_PuckLayout-mounted_1g88c_75", "PuckLayout-header": "_PuckLayout-header_1g88c_116", "PuckLayout-headerInner": "_PuckLayout-headerInner_1g88c_125", "PuckLayout-headerToggle": "_PuckLayout-headerToggle_1g88c_135", "PuckLayout-rightSideBarToggle": "_PuckLayout-rightSideBarToggle_1g88c_142", "PuckLayout-leftSideBarToggle": "_PuckLayout-leftSideBarToggle_1g88c_143", "PuckLayout-headerTitle": "_PuckLayout-headerTitle_1g88c_147", "PuckLayout-headerPath": "_PuckLayout-headerPath_1g88c_151", "PuckLayout-headerTools": "_PuckLayout-headerTools_1g88c_158", "PuckLayout-menuButton": "_PuckLayout-menuButton_1g88c_164", "PuckLayout--menuOpen": "_PuckLayout--menuOpen_1g88c_169", "PuckLayout-leftSideBar": "_PuckLayout-leftSideBar_1g88c_143", "PuckLayout-rightSideBar": "_PuckLayout-rightSideBar_1g88c_142" };
5328
+ var styles_module_default15 = { "Puck": "_Puck_12s9r_19", "Puck-portal": "_Puck-portal_12s9r_24", "PuckLayout-inner": "_PuckLayout-inner_12s9r_31", "PuckLayout--mounted": "_PuckLayout--mounted_12s9r_43", "PuckLayout--leftSideBarVisible": "_PuckLayout--leftSideBarVisible_12s9r_47", "PuckLayout--rightSideBarVisible": "_PuckLayout--rightSideBarVisible_12s9r_53", "PuckLayout-mounted": "_PuckLayout-mounted_12s9r_67", "PuckLayout": "_PuckLayout_12s9r_31", "PuckLayout-header": "_PuckLayout-header_12s9r_108", "PuckLayout-headerInner": "_PuckLayout-headerInner_12s9r_117", "PuckLayout-headerToggle": "_PuckLayout-headerToggle_12s9r_127", "PuckLayout-rightSideBarToggle": "_PuckLayout-rightSideBarToggle_12s9r_134", "PuckLayout-leftSideBarToggle": "_PuckLayout-leftSideBarToggle_12s9r_135", "PuckLayout-headerTitle": "_PuckLayout-headerTitle_12s9r_139", "PuckLayout-headerPath": "_PuckLayout-headerPath_12s9r_143", "PuckLayout-headerTools": "_PuckLayout-headerTools_12s9r_150", "PuckLayout-menuButton": "_PuckLayout-menuButton_12s9r_156", "PuckLayout--menuOpen": "_PuckLayout--menuOpen_12s9r_161", "PuckLayout-leftSideBar": "_PuckLayout-leftSideBar_12s9r_135", "PuckLayout-rightSideBar": "_PuckLayout-rightSideBar_12s9r_134" };
5111
5329
 
5112
5330
  // components/Puck/components/Fields/index.tsx
5113
5331
  init_react_import();
@@ -5117,15 +5335,15 @@ init_react_import();
5117
5335
  var styles_module_default16 = { "PuckFields": "_PuckFields_jp3lw_1", "PuckFields--isLoading": "_PuckFields--isLoading_jp3lw_6", "PuckFields-loadingOverlay": "_PuckFields-loadingOverlay_jp3lw_10", "PuckFields-loadingOverlayInner": "_PuckFields-loadingOverlayInner_jp3lw_25" };
5118
5336
 
5119
5337
  // components/Puck/components/Fields/index.tsx
5120
- import { useCallback as useCallback10, useEffect as useEffect14, useMemo as useMemo10, useState as useState18 } from "react";
5338
+ import { useCallback as useCallback12, useEffect as useEffect16, useMemo as useMemo10, useState as useState19 } from "react";
5121
5339
 
5122
5340
  // lib/use-parent.ts
5123
5341
  init_react_import();
5124
- import { useContext as useContext6 } from "react";
5342
+ import { useContext as useContext7 } from "react";
5125
5343
  var useParent = (itemSelector) => {
5126
5344
  var _a;
5127
5345
  const { selectedItem, state } = useAppContext();
5128
- const { pathData } = useContext6(dropZoneContext) || {};
5346
+ const { pathData } = useContext7(dropZoneContext) || {};
5129
5347
  const item = itemSelector ? getItem(itemSelector, state.data) : selectedItem;
5130
5348
  const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, state.data);
5131
5349
  const lastItem = breadcrumbs[breadcrumbs.length - 1];
@@ -5156,15 +5374,15 @@ var useResolvedFields = () => {
5156
5374
  [selectedItem, rootFields, componentConfig == null ? void 0 : componentConfig.fields]
5157
5375
  );
5158
5376
  const rootProps = data.root.props || data.root;
5159
- const [lastSelectedData, setLastSelectedData] = useState18({});
5160
- const [resolvedFields, setResolvedFields] = useState18(defaultFields);
5161
- const [fieldsLoading, setFieldsLoading] = useState18(false);
5377
+ const [lastSelectedData, setLastSelectedData] = useState19({});
5378
+ const [resolvedFields, setResolvedFields] = useState19(defaultFields);
5379
+ const [fieldsLoading, setFieldsLoading] = useState19(false);
5162
5380
  const defaultResolveFields = (_componentData, _params) => defaultFields;
5163
5381
  const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
5164
5382
  const hasComponentResolver = selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields);
5165
5383
  const hasRootResolver = !selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields);
5166
5384
  const hasResolver = hasComponentResolver || hasRootResolver;
5167
- const resolveFields = useCallback10(
5385
+ const resolveFields = useCallback12(
5168
5386
  (..._0) => __async(void 0, [..._0], function* (fields = {}) {
5169
5387
  var _a2;
5170
5388
  const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
@@ -5202,7 +5420,7 @@ var useResolvedFields = () => {
5202
5420
  }),
5203
5421
  [data, config, componentData, selectedItem, resolvedFields, state]
5204
5422
  );
5205
- useEffect14(() => {
5423
+ useEffect16(() => {
5206
5424
  if (hasResolver) {
5207
5425
  setFieldsLoading(true);
5208
5426
  resolveFields(defaultFields).then((fields) => {
@@ -5356,7 +5574,7 @@ init_react_import();
5356
5574
 
5357
5575
  // lib/use-component-list.tsx
5358
5576
  init_react_import();
5359
- import { useEffect as useEffect15, useState as useState19 } from "react";
5577
+ import { useEffect as useEffect17, useState as useState20 } from "react";
5360
5578
 
5361
5579
  // components/ComponentList/index.tsx
5362
5580
  init_react_import();
@@ -5423,8 +5641,8 @@ ComponentList.Item = ComponentListItem;
5423
5641
  // lib/use-component-list.tsx
5424
5642
  import { jsx as jsx28 } from "react/jsx-runtime";
5425
5643
  var useComponentList = (config, ui) => {
5426
- const [componentList, setComponentList] = useState19();
5427
- useEffect15(() => {
5644
+ const [componentList, setComponentList] = useState20();
5645
+ useEffect17(() => {
5428
5646
  var _a, _b, _c;
5429
5647
  if (Object.keys(ui.componentList).length > 0) {
5430
5648
  const matchedComponents = [];
@@ -5504,15 +5722,15 @@ var Components = () => {
5504
5722
 
5505
5723
  // components/Puck/components/Preview/index.tsx
5506
5724
  init_react_import();
5507
- import { useCallback as useCallback11, useEffect as useEffect17, useRef as useRef7, useMemo as useMemo12 } from "react";
5725
+ import { useCallback as useCallback13, useEffect as useEffect19, useRef as useRef7, useMemo as useMemo12 } from "react";
5508
5726
 
5509
5727
  // components/AutoFrame/index.tsx
5510
5728
  init_react_import();
5511
5729
  import {
5512
5730
  createContext as createContext4,
5513
- useContext as useContext7,
5514
- useEffect as useEffect16,
5515
- useState as useState20
5731
+ useContext as useContext8,
5732
+ useEffect as useEffect18,
5733
+ useState as useState21
5516
5734
  } from "react";
5517
5735
  import hash from "object-hash";
5518
5736
  import { createPortal as createPortal3 } from "react-dom";
@@ -5559,7 +5777,7 @@ var CopyHostStyles = ({
5559
5777
  onStylesLoaded = () => null
5560
5778
  }) => {
5561
5779
  const { document: doc, window: win } = useFrame();
5562
- useEffect16(() => {
5780
+ useEffect18(() => {
5563
5781
  if (!win || !doc) {
5564
5782
  return () => {
5565
5783
  };
@@ -5719,7 +5937,7 @@ var CopyHostStyles = ({
5719
5937
  return /* @__PURE__ */ jsx30(Fragment9, { children });
5720
5938
  };
5721
5939
  var autoFrameContext = createContext4({});
5722
- var useFrame = () => useContext7(autoFrameContext);
5940
+ var useFrame = () => useContext8(autoFrameContext);
5723
5941
  function AutoFrame(_a) {
5724
5942
  var _b = _a, {
5725
5943
  children,
@@ -5736,10 +5954,10 @@ function AutoFrame(_a) {
5736
5954
  "onStylesLoaded",
5737
5955
  "frameRef"
5738
5956
  ]);
5739
- const [loaded, setLoaded] = useState20(false);
5740
- const [ctx, setCtx] = useState20({});
5741
- const [mountTarget, setMountTarget] = useState20();
5742
- useEffect16(() => {
5957
+ const [loaded, setLoaded] = useState21(false);
5958
+ const [ctx, setCtx] = useState21({});
5959
+ const [mountTarget, setMountTarget] = useState21();
5960
+ useEffect18(() => {
5743
5961
  var _a2;
5744
5962
  if (frameRef.current) {
5745
5963
  setCtx({
@@ -5833,7 +6051,7 @@ import { Fragment as Fragment10, jsx as jsx32 } from "react/jsx-runtime";
5833
6051
  var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
5834
6052
  var useBubbleIframeEvents = (ref) => {
5835
6053
  const { status } = useAppContext();
5836
- useEffect17(() => {
6054
+ useEffect19(() => {
5837
6055
  var _a;
5838
6056
  if (ref.current && status === "READY") {
5839
6057
  const iframe = ref.current;
@@ -5870,9 +6088,9 @@ var useBubbleIframeEvents = (ref) => {
5870
6088
  }
5871
6089
  }, [status]);
5872
6090
  };
5873
- var Preview = ({ id = "puck-preview" }) => {
6091
+ var Preview2 = ({ id = "puck-preview" }) => {
5874
6092
  const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
5875
- const Page = useCallback11(
6093
+ const Page = useCallback13(
5876
6094
  (pageProps) => {
5877
6095
  var _a, _b;
5878
6096
  return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
@@ -5980,7 +6198,7 @@ var scrollIntoView = (el) => {
5980
6198
  };
5981
6199
 
5982
6200
  // components/LayerTree/index.tsx
5983
- import { useContext as useContext8 } from "react";
6201
+ import { useContext as useContext9 } from "react";
5984
6202
 
5985
6203
  // lib/is-child-of-zone.ts
5986
6204
  init_react_import();
@@ -6026,7 +6244,7 @@ var LayerTree = ({
6026
6244
  label
6027
6245
  }) => {
6028
6246
  const zones = data.zones || {};
6029
- const ctx = useContext8(dropZoneContext);
6247
+ const ctx = useContext9(dropZoneContext);
6030
6248
  return /* @__PURE__ */ jsxs16(Fragment11, { children: [
6031
6249
  label && /* @__PURE__ */ jsxs16("div", { className: getClassName24("zoneTitle"), children: [
6032
6250
  /* @__PURE__ */ jsx33("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ jsx33(Layers, { size: "16" }) }),
@@ -6133,13 +6351,13 @@ var LayerTree = ({
6133
6351
  };
6134
6352
 
6135
6353
  // components/Puck/components/Outline/index.tsx
6136
- import { useCallback as useCallback12, useMemo as useMemo13 } from "react";
6354
+ import { useCallback as useCallback14, useMemo as useMemo13 } from "react";
6137
6355
  import { Fragment as Fragment12, jsx as jsx34, jsxs as jsxs17 } from "react/jsx-runtime";
6138
6356
  var Outline = () => {
6139
6357
  const { dispatch, state, overrides, config } = useAppContext();
6140
6358
  const { data, ui } = state;
6141
6359
  const { itemSelector } = ui;
6142
- const setItemSelector = useCallback12(
6360
+ const setItemSelector = useCallback14(
6143
6361
  (newItemSelector) => {
6144
6362
  dispatch({
6145
6363
  type: "setUi",
@@ -6262,19 +6480,19 @@ function usePuckHistory({
6262
6480
 
6263
6481
  // lib/use-history-store.ts
6264
6482
  init_react_import();
6265
- import { useState as useState21 } from "react";
6483
+ import { useState as useState22 } from "react";
6266
6484
  import { useDebouncedCallback as useDebouncedCallback3 } from "use-debounce";
6267
6485
  var EMPTY_HISTORY_INDEX = 0;
6268
6486
  function useHistoryStore(initialHistory) {
6269
6487
  var _a, _b;
6270
- const [histories, setHistories] = useState21(
6488
+ const [histories, setHistories] = useState22(
6271
6489
  (_a = initialHistory == null ? void 0 : initialHistory.histories) != null ? _a : []
6272
6490
  );
6273
6491
  const updateHistories = (histories2) => {
6274
6492
  setHistories(histories2);
6275
6493
  setIndex(histories2.length - 1);
6276
6494
  };
6277
- const [index, setIndex] = useState21(
6495
+ const [index, setIndex] = useState22(
6278
6496
  (_b = initialHistory == null ? void 0 : initialHistory.index) != null ? _b : EMPTY_HISTORY_INDEX
6279
6497
  );
6280
6498
  const hasPast = index > EMPTY_HISTORY_INDEX;
@@ -6435,16 +6653,16 @@ var getBox = function getBox2(el) {
6435
6653
 
6436
6654
  // components/Puck/components/Canvas/index.tsx
6437
6655
  import {
6438
- useCallback as useCallback13,
6439
- useEffect as useEffect19,
6656
+ useCallback as useCallback15,
6657
+ useEffect as useEffect21,
6440
6658
  useMemo as useMemo15,
6441
6659
  useRef as useRef8,
6442
- useState as useState23
6660
+ useState as useState24
6443
6661
  } from "react";
6444
6662
 
6445
6663
  // components/ViewportControls/index.tsx
6446
6664
  init_react_import();
6447
- import { useEffect as useEffect18, useMemo as useMemo14, useState as useState22 } from "react";
6665
+ import { useEffect as useEffect20, useMemo as useMemo14, useState as useState23 } from "react";
6448
6666
 
6449
6667
  // css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
6450
6668
  init_react_import();
@@ -6467,8 +6685,8 @@ var ViewportButton = ({
6467
6685
  onClick
6468
6686
  }) => {
6469
6687
  const { state } = useAppContext();
6470
- const [isActive, setIsActive] = useState22(false);
6471
- useEffect18(() => {
6688
+ const [isActive, setIsActive] = useState23(false);
6689
+ useEffect20(() => {
6472
6690
  setIsActive(width === state.ui.viewports.current.width);
6473
6691
  }, [width, state.ui.viewports.current.width]);
6474
6692
  return /* @__PURE__ */ jsx35("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ jsx35(
@@ -6628,7 +6846,7 @@ var Canvas = () => {
6628
6846
  const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
6629
6847
  const { ui } = state;
6630
6848
  const frameRef = useRef8(null);
6631
- const [showTransition, setShowTransition] = useState23(false);
6849
+ const [showTransition, setShowTransition] = useState24(false);
6632
6850
  const defaultRender = useMemo15(() => {
6633
6851
  const PuckDefault = ({ children }) => /* @__PURE__ */ jsx36(Fragment13, { children });
6634
6852
  return PuckDefault;
@@ -6637,7 +6855,7 @@ var Canvas = () => {
6637
6855
  () => overrides.preview || defaultRender,
6638
6856
  [overrides]
6639
6857
  );
6640
- const getFrameDimensions = useCallback13(() => {
6858
+ const getFrameDimensions = useCallback15(() => {
6641
6859
  if (frameRef.current) {
6642
6860
  const frame = frameRef.current;
6643
6861
  const box = getBox(frame);
@@ -6645,7 +6863,7 @@ var Canvas = () => {
6645
6863
  }
6646
6864
  return { width: 0, height: 0 };
6647
6865
  }, [frameRef]);
6648
- const resetAutoZoom = useCallback13(
6866
+ const resetAutoZoom = useCallback15(
6649
6867
  (ui2 = state.ui) => {
6650
6868
  if (frameRef.current) {
6651
6869
  setZoomConfig(
@@ -6655,11 +6873,11 @@ var Canvas = () => {
6655
6873
  },
6656
6874
  [frameRef, zoomConfig, state.ui]
6657
6875
  );
6658
- useEffect19(() => {
6876
+ useEffect21(() => {
6659
6877
  setShowTransition(false);
6660
6878
  resetAutoZoom();
6661
6879
  }, [frameRef, ui.leftSideBarVisible, ui.rightSideBarVisible]);
6662
- useEffect19(() => {
6880
+ useEffect21(() => {
6663
6881
  const { height: frameHeight } = getFrameDimensions();
6664
6882
  if (ui.viewports.current.height === "auto") {
6665
6883
  setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
@@ -6667,13 +6885,13 @@ var Canvas = () => {
6667
6885
  }));
6668
6886
  }
6669
6887
  }, [zoomConfig.zoom]);
6670
- useEffect19(() => {
6888
+ useEffect21(() => {
6671
6889
  if (ZOOM_ON_CHANGE) {
6672
6890
  setShowTransition(true);
6673
6891
  resetAutoZoom(ui);
6674
6892
  }
6675
6893
  }, [ui.viewports.current.width]);
6676
- useEffect19(() => {
6894
+ useEffect21(() => {
6677
6895
  const cb = () => {
6678
6896
  setShowTransition(false);
6679
6897
  resetAutoZoom();
@@ -6683,8 +6901,8 @@ var Canvas = () => {
6683
6901
  window.removeEventListener("resize", cb);
6684
6902
  };
6685
6903
  }, []);
6686
- const [showLoader, setShowLoader] = useState23(false);
6687
- useEffect19(() => {
6904
+ const [showLoader, setShowLoader] = useState24(false);
6905
+ useEffect21(() => {
6688
6906
  setTimeout(() => {
6689
6907
  setShowLoader(true);
6690
6908
  }, 500);
@@ -6750,7 +6968,7 @@ var Canvas = () => {
6750
6968
  })
6751
6969
  );
6752
6970
  },
6753
- children: /* @__PURE__ */ jsx36(CustomPreview, { children: /* @__PURE__ */ jsx36(Preview, {}) })
6971
+ children: /* @__PURE__ */ jsx36(CustomPreview, { children: /* @__PURE__ */ jsx36(Preview2, {}) })
6754
6972
  }
6755
6973
  ),
6756
6974
  /* @__PURE__ */ jsx36("div", { className: getClassName26("loader"), children: /* @__PURE__ */ jsx36(Loader, { size: 24 }) })
@@ -6813,14 +7031,14 @@ var DefaultOverride = ({ children }) => /* @__PURE__ */ jsx37(Fragment14, { chil
6813
7031
 
6814
7032
  // lib/use-inject-css.ts
6815
7033
  init_react_import();
6816
- import { useEffect as useEffect20, useState as useState24 } from "react";
7034
+ import { useEffect as useEffect22, useState as useState25 } from "react";
6817
7035
  var styles = ``;
6818
7036
  var useInjectStyleSheet = (initialStyles, iframeEnabled) => {
6819
- const [el, setEl] = useState24();
6820
- useEffect20(() => {
7037
+ const [el, setEl] = useState25();
7038
+ useEffect22(() => {
6821
7039
  setEl(document.createElement("style"));
6822
7040
  }, []);
6823
- useEffect20(() => {
7041
+ useEffect22(() => {
6824
7042
  var _a;
6825
7043
  if (!el || typeof window === "undefined") {
6826
7044
  return;
@@ -6840,10 +7058,10 @@ var useInjectGlobalCss = (iframeEnabled) => {
6840
7058
 
6841
7059
  // lib/use-preview-mode-hotkeys.ts
6842
7060
  init_react_import();
6843
- import { useCallback as useCallback14 } from "react";
7061
+ import { useCallback as useCallback16 } from "react";
6844
7062
  import { useHotkeys as useHotkeys2 } from "react-hotkeys-hook";
6845
7063
  var usePreviewModeHotkeys = (dispatch, iframeEnabled) => {
6846
- const toggleInteractive = useCallback14(() => {
7064
+ const toggleInteractive = useCallback16(() => {
6847
7065
  dispatch({
6848
7066
  type: "setUi",
6849
7067
  ui: (ui) => ({
@@ -6895,7 +7113,7 @@ function Puck({
6895
7113
  waitForStyles: true
6896
7114
  }, _iframe);
6897
7115
  useInjectGlobalCss(iframe.enabled);
6898
- const [generatedAppState] = useState25(() => {
7116
+ const [generatedAppState] = useState26(() => {
6899
7117
  var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
6900
7118
  const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
6901
7119
  let clientUiState = {};
@@ -6967,7 +7185,7 @@ function Puck({
6967
7185
  histories,
6968
7186
  index: initialHistoryIndex
6969
7187
  });
6970
- const [reducer] = useState25(
7188
+ const [reducer] = useState26(
6971
7189
  () => createReducer({
6972
7190
  config,
6973
7191
  record: historyStore.record,
@@ -6985,14 +7203,14 @@ function Puck({
6985
7203
  historyStore,
6986
7204
  iframeEnabled: (_a = _iframe == null ? void 0 : _iframe.enabled) != null ? _a : true
6987
7205
  });
6988
- const [menuOpen, setMenuOpen] = useState25(false);
7206
+ const [menuOpen, setMenuOpen] = useState26(false);
6989
7207
  const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
6990
7208
  const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
6991
- useEffect21(() => {
7209
+ useEffect23(() => {
6992
7210
  if (onChange) onChange(data);
6993
7211
  }, [data]);
6994
7212
  const rootProps = data.root.props || data.root;
6995
- const toggleSidebars = useCallback15(
7213
+ const toggleSidebars = useCallback17(
6996
7214
  (sidebar) => {
6997
7215
  const widerViewport = window.matchMedia("(min-width: 638px)").matches;
6998
7216
  const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
@@ -7006,7 +7224,7 @@ function Puck({
7006
7224
  },
7007
7225
  [dispatch, leftSideBarVisible, rightSideBarVisible]
7008
7226
  );
7009
- useEffect21(() => {
7227
+ useEffect23(() => {
7010
7228
  if (!window.matchMedia("(min-width: 638px)").matches) {
7011
7229
  dispatch({
7012
7230
  type: "setUi",
@@ -7072,8 +7290,8 @@ function Puck({
7072
7290
  () => loadedOverrides.headerActions || defaultHeaderActionsRender,
7073
7291
  [loadedOverrides]
7074
7292
  );
7075
- const [mounted, setMounted] = useState25(false);
7076
- useEffect21(() => {
7293
+ const [mounted, setMounted] = useState26(false);
7294
+ useEffect23(() => {
7077
7295
  setMounted(true);
7078
7296
  }, []);
7079
7297
  const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
@@ -7234,7 +7452,7 @@ function Puck({
7234
7452
  Puck.Components = Components;
7235
7453
  Puck.Fields = Fields;
7236
7454
  Puck.Outline = Outline;
7237
- Puck.Preview = Preview;
7455
+ Puck.Preview = Preview2;
7238
7456
 
7239
7457
  // lib/migrate.ts
7240
7458
  init_react_import();