@measured/puck 0.21.0-canary.6dae6cb7 → 0.21.0-canary.7dca3a5a

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.
@@ -19,12 +19,13 @@ import {
19
19
  rootDroppableId,
20
20
  rootZone,
21
21
  setupZone,
22
+ toComponent,
22
23
  useFieldTransforms,
23
24
  useSlots,
24
25
  walkAppState,
25
26
  walkField,
26
27
  walkTree
27
- } from "./chunk-OOLYDXKW.mjs";
28
+ } from "./chunk-6SIKCDJJ.mjs";
28
29
 
29
30
  // ../../node_modules/classnames/index.js
30
31
  var require_classnames = __commonJS({
@@ -88,6 +89,42 @@ var require_classnames = __commonJS({
88
89
  }
89
90
  });
90
91
 
92
+ // ../../node_modules/fast-deep-equal/index.js
93
+ var require_fast_deep_equal = __commonJS({
94
+ "../../node_modules/fast-deep-equal/index.js"(exports, module) {
95
+ "use strict";
96
+ init_react_import();
97
+ module.exports = function equal(a, b) {
98
+ if (a === b) return true;
99
+ if (a && b && typeof a == "object" && typeof b == "object") {
100
+ if (a.constructor !== b.constructor) return false;
101
+ var length, i, keys;
102
+ if (Array.isArray(a)) {
103
+ length = a.length;
104
+ if (length != b.length) return false;
105
+ for (i = length; i-- !== 0; )
106
+ if (!equal(a[i], b[i])) return false;
107
+ return true;
108
+ }
109
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
110
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
111
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
112
+ keys = Object.keys(a);
113
+ length = keys.length;
114
+ if (length !== Object.keys(b).length) return false;
115
+ for (i = length; i-- !== 0; )
116
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
117
+ for (i = length; i-- !== 0; ) {
118
+ var key = keys[i];
119
+ if (!equal(a[key], b[key])) return false;
120
+ }
121
+ return true;
122
+ }
123
+ return a !== a && b !== b;
124
+ };
125
+ }
126
+ });
127
+
91
128
  // types/API/Overrides.ts
92
129
  init_react_import();
93
130
  var overrideKeys = [
@@ -768,7 +805,9 @@ var keyCodeMap = {
768
805
  KeyW: "w",
769
806
  KeyX: "x",
770
807
  KeyY: "y",
771
- KeyZ: "z"
808
+ KeyZ: "z",
809
+ Delete: "delete",
810
+ Backspace: "backspace"
772
811
  };
773
812
  var useHotkeyStore = create()(
774
813
  subscribeWithSelector((set) => ({
@@ -792,8 +831,10 @@ var monitorHotkeys = (doc) => {
792
831
  ([key2, value]) => value === !!combo[key2]
793
832
  );
794
833
  if (conditionMet) {
795
- e.preventDefault();
796
- cb();
834
+ const handled = cb(e);
835
+ if (handled !== false) {
836
+ e.preventDefault();
837
+ }
797
838
  }
798
839
  });
799
840
  if (key !== "meta" && key !== "ctrl" && key !== "shift") {
@@ -816,6 +857,10 @@ var monitorHotkeys = (doc) => {
816
857
  useHotkeyStore.getState().reset();
817
858
  }
818
859
  };
860
+ const onBlur = () => {
861
+ useHotkeyStore.getState().reset();
862
+ };
863
+ window.addEventListener("blur", onBlur);
819
864
  doc.addEventListener("keydown", onKeyDown);
820
865
  doc.addEventListener("keyup", onKeyUp);
821
866
  doc.addEventListener("visibilitychange", onVisibilityChanged);
@@ -823,6 +868,7 @@ var monitorHotkeys = (doc) => {
823
868
  doc.removeEventListener("keydown", onKeyDown);
824
869
  doc.removeEventListener("keyup", onKeyUp);
825
870
  doc.removeEventListener("visibilitychange", onVisibilityChanged);
871
+ window.removeEventListener("blur", onBlur);
826
872
  };
827
873
  };
828
874
  var useMonitorHotkeys = () => {
@@ -1017,7 +1063,7 @@ var flattenData = (state, config) => {
1017
1063
  (content) => content,
1018
1064
  (item) => {
1019
1065
  data.push(item);
1020
- return null;
1066
+ return item;
1021
1067
  }
1022
1068
  );
1023
1069
  return data;
@@ -1262,6 +1308,7 @@ var createAppStore = (initialAppStore) => create2()(
1262
1308
  subscribeWithSelector2((set, get) => {
1263
1309
  var _a, _b;
1264
1310
  return __spreadProps(__spreadValues({
1311
+ instanceId: generateId(),
1265
1312
  state: defaultAppState,
1266
1313
  config: { components: {} },
1267
1314
  componentState: {},
@@ -1570,7 +1617,7 @@ var getZoomConfig = (uiViewport, frame, zoom) => {
1570
1617
  const viewportHeight = uiViewport.height === "auto" ? frameHeight : uiViewport.height;
1571
1618
  let rootHeight = 0;
1572
1619
  let autoZoom = 1;
1573
- if (uiViewport.width > frameWidth || viewportHeight > frameHeight) {
1620
+ if (typeof uiViewport.width === "number" && (uiViewport.width > frameWidth || viewportHeight > frameHeight)) {
1574
1621
  const widthZoom = Math.min(frameWidth / uiViewport.width, 1);
1575
1622
  const heightZoom = Math.min(frameHeight / viewportHeight, 1);
1576
1623
  zoom = widthZoom;
@@ -1649,7 +1696,8 @@ var IconButton = ({
1649
1696
  tabIndex,
1650
1697
  newTab,
1651
1698
  fullWidth,
1652
- title
1699
+ title,
1700
+ suppressHydrationWarning
1653
1701
  }) => {
1654
1702
  const [loading, setLoading] = useState(false);
1655
1703
  const ElementType = href ? "a" : "button";
@@ -1676,6 +1724,7 @@ var IconButton = ({
1676
1724
  rel: newTab ? "noreferrer" : void 0,
1677
1725
  href,
1678
1726
  title,
1727
+ suppressHydrationWarning,
1679
1728
  children: [
1680
1729
  /* @__PURE__ */ jsx3("span", { className: getClassName3("title"), children: title }),
1681
1730
  children,
@@ -1937,6 +1986,15 @@ var EllipsisVertical = createLucideIcon("EllipsisVertical", [
1937
1986
  ["circle", { cx: "12", cy: "19", r: "1", key: "lyex9k" }]
1938
1987
  ]);
1939
1988
 
1989
+ // ../../node_modules/lucide-react/dist/esm/icons/expand.js
1990
+ init_react_import();
1991
+ var Expand = createLucideIcon("Expand", [
1992
+ ["path", { d: "m21 21-6-6m6 6v-4.8m0 4.8h-4.8", key: "1c15vz" }],
1993
+ ["path", { d: "M3 16.2V21m0 0h4.8M3 21l6-6", key: "1fsnz2" }],
1994
+ ["path", { d: "M21 7.8V3m0 0h-4.8M21 3l-6 6", key: "hawz9i" }],
1995
+ ["path", { d: "M3 7.8V3m0 0h4.8M3 3l6 6", key: "u9ee12" }]
1996
+ ]);
1997
+
1940
1998
  // ../../node_modules/lucide-react/dist/esm/icons/globe.js
1941
1999
  init_react_import();
1942
2000
  var Globe = createLucideIcon("Globe", [
@@ -1945,6 +2003,20 @@ var Globe = createLucideIcon("Globe", [
1945
2003
  ["path", { d: "M2 12h20", key: "9i4pu4" }]
1946
2004
  ]);
1947
2005
 
2006
+ // ../../node_modules/lucide-react/dist/esm/icons/hammer.js
2007
+ init_react_import();
2008
+ var Hammer = createLucideIcon("Hammer", [
2009
+ ["path", { d: "m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9", key: "eefl8a" }],
2010
+ ["path", { d: "m18 15 4-4", key: "16gjal" }],
2011
+ [
2012
+ "path",
2013
+ {
2014
+ d: "m21.5 11.5-1.914-1.914A2 2 0 0 1 19 8.172V7l-2.26-2.26a6 6 0 0 0-4.202-1.756L9 2.96l.92.82A6.18 6.18 0 0 1 12 8.4V10l2 2h1.172a2 2 0 0 1 1.414.586L18.5 14.5",
2015
+ key: "b7pghm"
2016
+ }
2017
+ ]
2018
+ ]);
2019
+
1948
2020
  // ../../node_modules/lucide-react/dist/esm/icons/hash.js
1949
2021
  init_react_import();
1950
2022
  var Hash = createLucideIcon("Hash", [
@@ -2021,6 +2093,24 @@ var Lock = createLucideIcon("Lock", [
2021
2093
  ["path", { d: "M7 11V7a5 5 0 0 1 10 0v4", key: "fwvmzm" }]
2022
2094
  ]);
2023
2095
 
2096
+ // ../../node_modules/lucide-react/dist/esm/icons/maximize-2.js
2097
+ init_react_import();
2098
+ var Maximize2 = createLucideIcon("Maximize2", [
2099
+ ["polyline", { points: "15 3 21 3 21 9", key: "mznyad" }],
2100
+ ["polyline", { points: "9 21 3 21 3 15", key: "1avn1i" }],
2101
+ ["line", { x1: "21", x2: "14", y1: "3", y2: "10", key: "ota7mn" }],
2102
+ ["line", { x1: "3", x2: "10", y1: "21", y2: "14", key: "1atl0r" }]
2103
+ ]);
2104
+
2105
+ // ../../node_modules/lucide-react/dist/esm/icons/minimize-2.js
2106
+ init_react_import();
2107
+ var Minimize2 = createLucideIcon("Minimize2", [
2108
+ ["polyline", { points: "4 14 10 14 10 20", key: "11kfnr" }],
2109
+ ["polyline", { points: "20 10 14 10 14 4", key: "rlmsce" }],
2110
+ ["line", { x1: "14", x2: "21", y1: "10", y2: "3", key: "o5lafz" }],
2111
+ ["line", { x1: "3", x2: "10", y1: "21", y2: "14", key: "1atl0r" }]
2112
+ ]);
2113
+
2024
2114
  // ../../node_modules/lucide-react/dist/esm/icons/monitor.js
2025
2115
  init_react_import();
2026
2116
  var Monitor = createLucideIcon("Monitor", [
@@ -2050,6 +2140,15 @@ var Plus = createLucideIcon("Plus", [
2050
2140
  ["path", { d: "M12 5v14", key: "s699le" }]
2051
2141
  ]);
2052
2142
 
2143
+ // ../../node_modules/lucide-react/dist/esm/icons/rectangle-ellipsis.js
2144
+ init_react_import();
2145
+ var RectangleEllipsis = createLucideIcon("RectangleEllipsis", [
2146
+ ["rect", { width: "20", height: "12", x: "2", y: "6", rx: "2", key: "9lu3g6" }],
2147
+ ["path", { d: "M12 12h.01", key: "1mp3jc" }],
2148
+ ["path", { d: "M17 12h.01", key: "1m0b6t" }],
2149
+ ["path", { d: "M7 12h.01", key: "eqddd0" }]
2150
+ ]);
2151
+
2053
2152
  // ../../node_modules/lucide-react/dist/esm/icons/redo-2.js
2054
2153
  init_react_import();
2055
2154
  var Redo2 = createLucideIcon("Redo2", [
@@ -2092,6 +2191,14 @@ var Tablet = createLucideIcon("Tablet", [
2092
2191
  ["line", { x1: "12", x2: "12.01", y1: "18", y2: "18", key: "1dp563" }]
2093
2192
  ]);
2094
2193
 
2194
+ // ../../node_modules/lucide-react/dist/esm/icons/toy-brick.js
2195
+ init_react_import();
2196
+ var ToyBrick = createLucideIcon("ToyBrick", [
2197
+ ["rect", { width: "18", height: "12", x: "3", y: "8", rx: "1", key: "158fvp" }],
2198
+ ["path", { d: "M10 8V5c0-.6-.4-1-1-1H6a1 1 0 0 0-1 1v3", key: "s0042v" }],
2199
+ ["path", { d: "M19 8V5c0-.6-.4-1-1-1h-3a1 1 0 0 0-1 1v3", key: "9wmeh2" }]
2200
+ ]);
2201
+
2095
2202
  // ../../node_modules/lucide-react/dist/esm/icons/trash.js
2096
2203
  init_react_import();
2097
2204
  var Trash = createLucideIcon("Trash", [
@@ -2115,6 +2222,13 @@ var Undo2 = createLucideIcon("Undo2", [
2115
2222
  ["path", { d: "M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11", key: "f3b9sd" }]
2116
2223
  ]);
2117
2224
 
2225
+ // ../../node_modules/lucide-react/dist/esm/icons/x.js
2226
+ init_react_import();
2227
+ var X = createLucideIcon("X", [
2228
+ ["path", { d: "M18 6 6 18", key: "1bl5f8" }],
2229
+ ["path", { d: "m6 6 12 12", key: "d8bk6v" }]
2230
+ ]);
2231
+
2118
2232
  // ../../node_modules/lucide-react/dist/esm/icons/zoom-in.js
2119
2233
  init_react_import();
2120
2234
  var ZoomIn = createLucideIcon("ZoomIn", [
@@ -2940,8 +3054,9 @@ var ArrayField = ({
2940
3054
  var _a;
2941
3055
  if (isDraggingAny) return;
2942
3056
  const existingValue = value || [];
3057
+ const defaultProps = typeof field.defaultItemProps === "function" ? field.defaultItemProps(existingValue.length) : (_a = field.defaultItemProps) != null ? _a : {};
2943
3058
  const newItem = defaultSlots(
2944
- uniqifyItem((_a = field.defaultItemProps) != null ? _a : {}),
3059
+ uniqifyItem(defaultProps),
2945
3060
  field.arrayFields
2946
3061
  );
2947
3062
  const newValue = [...existingValue, newItem];
@@ -3116,11 +3231,13 @@ var ExternalInput = ({
3116
3231
  id,
3117
3232
  readOnly
3118
3233
  }) => {
3234
+ var _a;
3119
3235
  const {
3120
3236
  mapProp = (val) => val,
3121
3237
  mapRow = (val) => val,
3122
3238
  filterFields
3123
3239
  } = field || {};
3240
+ const { enabled: shouldCacheData } = (_a = field.cache) != null ? _a : { enabled: true };
3124
3241
  const [data, setData] = useState6([]);
3125
3242
  const [isOpen, setOpen] = useState6(false);
3126
3243
  const [isLoading, setIsLoading] = useState6(true);
@@ -3146,11 +3263,18 @@ var ExternalInput = ({
3146
3263
  (query, filters2) => __async(void 0, null, function* () {
3147
3264
  setIsLoading(true);
3148
3265
  const cacheKey = `${id}-${query}-${JSON.stringify(filters2)}`;
3149
- const listData = dataCache[cacheKey] || (yield field.fetchList({ query, filters: filters2 }));
3266
+ let listData;
3267
+ if (shouldCacheData && dataCache[cacheKey]) {
3268
+ listData = dataCache[cacheKey];
3269
+ } else {
3270
+ listData = yield field.fetchList({ query, filters: filters2 });
3271
+ }
3150
3272
  if (listData) {
3151
3273
  setData(listData);
3152
3274
  setIsLoading(false);
3153
- dataCache[cacheKey] = listData;
3275
+ if (shouldCacheData) {
3276
+ dataCache[cacheKey] = listData;
3277
+ }
3154
3278
  }
3155
3279
  }),
3156
3280
  [id, field]
@@ -3214,6 +3338,7 @@ var ExternalInput = ({
3214
3338
  }),
3215
3339
  onSubmit: (e) => {
3216
3340
  e.preventDefault();
3341
+ e.stopPropagation();
3217
3342
  search(searchQuery, filters);
3218
3343
  },
3219
3344
  children: [
@@ -4124,12 +4249,14 @@ var DraggableComponent = ({
4124
4249
  }
4125
4250
  return cleanup;
4126
4251
  }, [permissions.drag, zoneCompound]);
4252
+ const [, setRerender] = useState10(0);
4127
4253
  const ref = useRef2(null);
4128
4254
  const refSetter = useCallback7(
4129
4255
  (el) => {
4130
4256
  sortableRef(el);
4131
- if (el) {
4257
+ if (ref.current !== el) {
4132
4258
  ref.current = el;
4259
+ setRerender((update) => update + 1);
4133
4260
  }
4134
4261
  },
4135
4262
  [sortableRef]
@@ -4217,14 +4344,23 @@ var DraggableComponent = ({
4217
4344
  if (!el.closest("[data-puck-overlay-portal]")) {
4218
4345
  e.stopPropagation();
4219
4346
  }
4220
- dispatch({
4221
- type: "setUi",
4222
- ui: {
4223
- itemSelector: { index, zone: zoneCompound }
4224
- }
4225
- });
4347
+ if (isSelected) {
4348
+ dispatch({
4349
+ type: "setUi",
4350
+ ui: {
4351
+ itemSelector: null
4352
+ }
4353
+ });
4354
+ } else {
4355
+ dispatch({
4356
+ type: "setUi",
4357
+ ui: {
4358
+ itemSelector: { index, zone: zoneCompound }
4359
+ }
4360
+ });
4361
+ }
4226
4362
  },
4227
- [index, zoneCompound, id]
4363
+ [index, zoneCompound, id, isSelected]
4228
4364
  );
4229
4365
  const appStore = useAppStoreApi();
4230
4366
  const onSelectParent = useCallback7(() => {
@@ -4873,8 +5009,8 @@ var DragDropContextClient = ({
4873
5009
  disableAutoScroll
4874
5010
  }) => {
4875
5011
  const dispatch = useAppStore((s) => s.dispatch);
5012
+ const instanceId = useAppStore((s) => s.instanceId);
4876
5013
  const appStore = useAppStoreApi();
4877
- const id = useSafeId();
4878
5014
  const debouncedParamsRef = useRef3(null);
4879
5015
  const tempDisableFallback = useTempDisableFallback(100);
4880
5016
  const [zoneStore] = useState11(
@@ -4890,7 +5026,7 @@ var DragDropContextClient = ({
4890
5026
  }))
4891
5027
  );
4892
5028
  const getChanged2 = useCallback8(
4893
- (params, id2) => {
5029
+ (params) => {
4894
5030
  const { zoneDepthIndex = {}, areaDepthIndex = {} } = zoneStore.getState() || {};
4895
5031
  const stateHasZone = Object.keys(zoneDepthIndex).length > 0;
4896
5032
  const stateHasArea = Object.keys(areaDepthIndex).length > 0;
@@ -4912,7 +5048,7 @@ var DragDropContextClient = ({
4912
5048
  );
4913
5049
  const setDeepestAndCollide = useCallback8(
4914
5050
  (params, manager) => {
4915
- const { zoneChanged, areaChanged } = getChanged2(params, id);
5051
+ const { zoneChanged, areaChanged } = getChanged2(params);
4916
5052
  if (!zoneChanged && !areaChanged) return;
4917
5053
  zoneStore.setState({
4918
5054
  zoneDepthIndex: params.zone ? { [params.zone]: true } : {},
@@ -4954,7 +5090,7 @@ var DragDropContextClient = ({
4954
5090
  {
4955
5091
  onChange: (params, manager) => {
4956
5092
  const state = zoneStore.getState();
4957
- const { zoneChanged, areaChanged } = getChanged2(params, id);
5093
+ const { zoneChanged, areaChanged } = getChanged2(params);
4958
5094
  const isDragging = manager.dragOperation.status.dragging;
4959
5095
  if (areaChanged || zoneChanged) {
4960
5096
  let nextZoneDepthIndex = {};
@@ -4992,7 +5128,7 @@ var DragDropContextClient = ({
4992
5128
  cancelDb();
4993
5129
  }
4994
5130
  },
4995
- id
5131
+ instanceId
4996
5132
  )
4997
5133
  ]);
4998
5134
  const sensors = useSensors();
@@ -5007,7 +5143,7 @@ var DragDropContextClient = ({
5007
5143
  }),
5008
5144
  []
5009
5145
  );
5010
- return /* @__PURE__ */ jsx21("div", { id, children: /* @__PURE__ */ jsx21(
5146
+ return /* @__PURE__ */ jsx21(
5011
5147
  dragListenerContext.Provider,
5012
5148
  {
5013
5149
  value: {
@@ -5234,7 +5370,7 @@ var DragDropContextClient = ({
5234
5370
  }
5235
5371
  )
5236
5372
  }
5237
- ) });
5373
+ );
5238
5374
  };
5239
5375
  var DragDropContext = ({
5240
5376
  children,
@@ -5634,26 +5770,26 @@ var registerOverlayPortal = (el, opts = {}) => {
5634
5770
  capture: true
5635
5771
  });
5636
5772
  };
5637
- if (disableDragOnFocus) {
5638
- el.addEventListener("focus", onFocus, { capture: true });
5639
- el.addEventListener("blur", onBlur, { capture: true });
5640
- } else if (disableDrag) {
5773
+ if (disableDrag) {
5641
5774
  el.addEventListener("pointerdown", stopPropagation, {
5642
5775
  capture: true
5643
5776
  });
5777
+ } else if (disableDragOnFocus) {
5778
+ el.addEventListener("focus", onFocus, { capture: true });
5779
+ el.addEventListener("blur", onBlur, { capture: true });
5644
5780
  }
5645
5781
  el.setAttribute("data-puck-overlay-portal", "true");
5646
5782
  return () => {
5647
5783
  el.removeEventListener("mouseover", stopPropagation, {
5648
5784
  capture: true
5649
5785
  });
5650
- if (disableDragOnFocus) {
5651
- el.removeEventListener("focus", onFocus, { capture: true });
5652
- el.removeEventListener("blur", onFocus, { capture: true });
5653
- } else if (disableDrag) {
5786
+ if (disableDrag) {
5654
5787
  el.removeEventListener("pointerdown", stopPropagation, {
5655
5788
  capture: true
5656
5789
  });
5790
+ } else if (disableDragOnFocus) {
5791
+ el.removeEventListener("focus", onFocus, { capture: true });
5792
+ el.removeEventListener("blur", onBlur, { capture: true });
5657
5793
  }
5658
5794
  el.removeAttribute("data-puck-overlay-portal");
5659
5795
  };
@@ -5661,7 +5797,7 @@ var registerOverlayPortal = (el, opts = {}) => {
5661
5797
 
5662
5798
  // css-module:/home/runner/work/puck/puck/packages/core/components/InlineTextField/styles.module.css#css-module
5663
5799
  init_react_import();
5664
- var styles_module_default13 = { "InlineTextField": "_InlineTextField_1xph6_1" };
5800
+ var styles_module_default13 = { "InlineTextField": "_InlineTextField_104qp_1" };
5665
5801
 
5666
5802
  // lib/data/set-deep.ts
5667
5803
  init_react_import();
@@ -6417,340 +6553,93 @@ function useGetPuck() {
6417
6553
  return usePuckApi.getState;
6418
6554
  }
6419
6555
 
6420
- // components/Puck/index.tsx
6556
+ // plugins/blocks/index.tsx
6421
6557
  init_react_import();
6422
- import {
6423
- createContext as createContext8,
6424
- useCallback as useCallback20,
6425
- useContext as useContext13,
6426
- useEffect as useEffect29,
6427
- useMemo as useMemo20,
6428
- useRef as useRef12,
6429
- useState as useState25
6430
- } from "react";
6431
6558
 
6432
- // components/SidebarSection/index.tsx
6559
+ // components/Puck/components/Components/index.tsx
6433
6560
  init_react_import();
6434
6561
 
6435
- // css-module:/home/runner/work/puck/puck/packages/core/components/SidebarSection/styles.module.css#css-module
6562
+ // lib/use-component-list.tsx
6436
6563
  init_react_import();
6437
- var styles_module_default14 = { "SidebarSection": "_SidebarSection_8boj8_1", "SidebarSection-title": "_SidebarSection-title_8boj8_12", "SidebarSection--noBorderTop": "_SidebarSection--noBorderTop_8boj8_20", "SidebarSection-content": "_SidebarSection-content_8boj8_24", "SidebarSection--noPadding": "_SidebarSection--noPadding_8boj8_28", "SidebarSection-breadcrumbLabel": "_SidebarSection-breadcrumbLabel_8boj8_41", "SidebarSection-breadcrumbs": "_SidebarSection-breadcrumbs_8boj8_70", "SidebarSection-breadcrumb": "_SidebarSection-breadcrumb_8boj8_41", "SidebarSection-heading": "_SidebarSection-heading_8boj8_82", "SidebarSection-loadingOverlay": "_SidebarSection-loadingOverlay_8boj8_86" };
6564
+ import { useEffect as useEffect21, useState as useState18 } from "react";
6438
6565
 
6439
- // lib/use-breadcrumbs.ts
6566
+ // components/ComponentList/index.tsx
6440
6567
  init_react_import();
6441
- import { useMemo as useMemo10 } from "react";
6442
- var useBreadcrumbs = (renderCount) => {
6443
- const selectedId = useAppStore((s) => {
6444
- var _a;
6445
- return (_a = s.selectedItem) == null ? void 0 : _a.props.id;
6446
- });
6447
- const config = useAppStore((s) => s.config);
6448
- const path = useAppStore((s) => {
6449
- var _a;
6450
- return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
6451
- });
6452
- const appStore = useAppStoreApi();
6453
- return useMemo10(() => {
6454
- const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
6455
- var _a, _b, _c;
6456
- const [componentId] = zoneCompound.split(":");
6457
- if (componentId === "root") {
6458
- return {
6459
- label: "Page",
6460
- selector: null
6461
- };
6462
- }
6463
- const node = appStore.getState().state.indexes.nodes[componentId];
6464
- const parentId = node.path[node.path.length - 1];
6465
- const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
6466
- const index = contentIds.indexOf(componentId);
6467
- const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
6468
- return {
6469
- label,
6470
- selector: node ? {
6471
- index,
6472
- zone: node.path[node.path.length - 1]
6473
- } : null
6474
- };
6475
- })) || [];
6476
- if (renderCount) {
6477
- return breadcrumbs.slice(breadcrumbs.length - renderCount);
6478
- }
6479
- return breadcrumbs;
6480
- }, [path, renderCount]);
6481
- };
6482
6568
 
6483
- // components/SidebarSection/index.tsx
6569
+ // css-module:/home/runner/work/puck/puck/packages/core/components/ComponentList/styles.module.css#css-module
6570
+ init_react_import();
6571
+ var styles_module_default14 = { "ComponentList": "_ComponentList_1rrlt_1", "ComponentList--isExpanded": "_ComponentList--isExpanded_1rrlt_5", "ComponentList-content": "_ComponentList-content_1rrlt_9", "ComponentList-title": "_ComponentList-title_1rrlt_17", "ComponentList-titleIcon": "_ComponentList-titleIcon_1rrlt_53" };
6572
+
6573
+ // components/ComponentList/index.tsx
6574
+ import { useEffect as useEffect20 } from "react";
6484
6575
  import { jsx as jsx28, jsxs as jsxs12 } from "react/jsx-runtime";
6485
- var getClassName20 = get_class_name_factory_default("SidebarSection", styles_module_default14);
6486
- var SidebarSection = ({
6576
+ var getClassName20 = get_class_name_factory_default("ComponentList", styles_module_default14);
6577
+ var ComponentListItem = ({
6578
+ name,
6579
+ label
6580
+ }) => {
6581
+ var _a;
6582
+ const overrides = useAppStore((s) => s.overrides);
6583
+ const canInsert = useAppStore(
6584
+ (s) => s.permissions.getPermissions({
6585
+ type: name
6586
+ }).insert
6587
+ );
6588
+ useEffect20(() => {
6589
+ if (overrides.componentItem) {
6590
+ console.warn(
6591
+ "The `componentItem` override has been deprecated and renamed to `drawerItem`"
6592
+ );
6593
+ }
6594
+ }, [overrides]);
6595
+ return /* @__PURE__ */ jsx28(Drawer.Item, { label, name, isDragDisabled: !canInsert, children: (_a = overrides.componentItem) != null ? _a : overrides.drawerItem });
6596
+ };
6597
+ var ComponentList = ({
6487
6598
  children,
6488
6599
  title,
6489
- background,
6490
- showBreadcrumbs,
6491
- noBorderTop,
6492
- noPadding,
6493
- isLoading
6600
+ id
6494
6601
  }) => {
6602
+ const config = useAppStore((s) => s.config);
6495
6603
  const setUi = useAppStore((s) => s.setUi);
6496
- const breadcrumbs = useBreadcrumbs(1);
6497
- return /* @__PURE__ */ jsxs12(
6498
- "div",
6499
- {
6500
- className: getClassName20({ noBorderTop, noPadding }),
6501
- style: { background },
6502
- children: [
6503
- /* @__PURE__ */ jsx28("div", { className: getClassName20("title"), children: /* @__PURE__ */ jsxs12("div", { className: getClassName20("breadcrumbs"), children: [
6504
- showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ jsxs12("div", { className: getClassName20("breadcrumb"), children: [
6505
- /* @__PURE__ */ jsx28(
6506
- "button",
6507
- {
6508
- type: "button",
6509
- className: getClassName20("breadcrumbLabel"),
6510
- onClick: () => setUi({ itemSelector: breadcrumb.selector }),
6511
- children: breadcrumb.label
6512
- }
6513
- ),
6514
- /* @__PURE__ */ jsx28(ChevronRight, { size: 16 })
6515
- ] }, i)) : null,
6516
- /* @__PURE__ */ jsx28("div", { className: getClassName20("heading"), children: /* @__PURE__ */ jsx28(Heading, { rank: "2", size: "xs", children: title }) })
6517
- ] }) }),
6518
- /* @__PURE__ */ jsx28("div", { className: getClassName20("content"), children }),
6519
- isLoading && /* @__PURE__ */ jsx28("div", { className: getClassName20("loadingOverlay"), children: /* @__PURE__ */ jsx28(Loader, { size: 32 }) })
6520
- ]
6521
- }
6522
- );
6604
+ const componentList = useAppStore((s) => s.state.ui.componentList);
6605
+ const { expanded = true } = componentList[id] || {};
6606
+ return /* @__PURE__ */ jsxs12("div", { className: getClassName20({ isExpanded: expanded }), children: [
6607
+ title && /* @__PURE__ */ jsxs12(
6608
+ "button",
6609
+ {
6610
+ type: "button",
6611
+ className: getClassName20("title"),
6612
+ onClick: () => setUi({
6613
+ componentList: __spreadProps(__spreadValues({}, componentList), {
6614
+ [id]: __spreadProps(__spreadValues({}, componentList[id]), {
6615
+ expanded: !expanded
6616
+ })
6617
+ })
6618
+ }),
6619
+ title: expanded ? `Collapse${title ? ` ${title}` : ""}` : `Expand${title ? ` ${title}` : ""}`,
6620
+ children: [
6621
+ /* @__PURE__ */ jsx28("div", { children: title }),
6622
+ /* @__PURE__ */ jsx28("div", { className: getClassName20("titleIcon"), children: expanded ? /* @__PURE__ */ jsx28(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx28(ChevronDown, { size: 12 }) })
6623
+ ]
6624
+ }
6625
+ ),
6626
+ /* @__PURE__ */ jsx28("div", { className: getClassName20("content"), children: /* @__PURE__ */ jsx28(Drawer, { children: children || Object.keys(config.components).map((componentKey) => {
6627
+ var _a;
6628
+ return /* @__PURE__ */ jsx28(
6629
+ ComponentListItem,
6630
+ {
6631
+ label: (_a = config.components[componentKey]["label"]) != null ? _a : componentKey,
6632
+ name: componentKey
6633
+ },
6634
+ componentKey
6635
+ );
6636
+ }) }) })
6637
+ ] });
6523
6638
  };
6524
-
6525
- // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/styles.module.css#css-module
6526
- init_react_import();
6527
- var styles_module_default15 = { "Puck": "_Puck_1yxlw_19", "Puck-portal": "_Puck-portal_1yxlw_31", "PuckLayout-inner": "_PuckLayout-inner_1yxlw_38", "PuckLayout--mounted": "_PuckLayout--mounted_1yxlw_59", "PuckLayout--leftSideBarVisible": "_PuckLayout--leftSideBarVisible_1yxlw_63", "PuckLayout--rightSideBarVisible": "_PuckLayout--rightSideBarVisible_1yxlw_69", "PuckLayout-mounted": "_PuckLayout-mounted_1yxlw_83", "PuckLayout": "_PuckLayout_1yxlw_38" };
6528
-
6529
- // components/Puck/components/Fields/index.tsx
6530
- init_react_import();
6531
-
6532
- // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Fields/styles.module.css#css-module
6533
- init_react_import();
6534
- var styles_module_default16 = { "PuckFields": "_PuckFields_10bh7_1", "PuckFields--isLoading": "_PuckFields--isLoading_10bh7_6", "PuckFields-loadingOverlay": "_PuckFields-loadingOverlay_10bh7_10", "PuckFields-loadingOverlayInner": "_PuckFields-loadingOverlayInner_10bh7_25", "PuckFields-field": "_PuckFields-field_10bh7_32", "PuckFields--wrapFields": "_PuckFields--wrapFields_10bh7_36" };
6535
-
6536
- // components/Puck/components/Fields/index.tsx
6537
- import { memo as memo3, useCallback as useCallback12, useMemo as useMemo11 } from "react";
6538
- import { useShallow as useShallow5 } from "zustand/react/shallow";
6539
- import { Fragment as Fragment8, jsx as jsx29, jsxs as jsxs13 } from "react/jsx-runtime";
6540
- var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
6541
- var DefaultFields = ({
6542
- children
6543
- }) => {
6544
- return /* @__PURE__ */ jsx29(Fragment8, { children });
6545
- };
6546
- var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(void 0, null, function* () {
6547
- let currentProps;
6548
- const { dispatch, state, selectedItem, resolveComponentData: resolveComponentData2 } = appStore.getState();
6549
- const { data, ui } = state;
6550
- const { itemSelector } = ui;
6551
- const rootProps = data.root.props || data.root;
6552
- if (selectedItem) {
6553
- currentProps = selectedItem.props;
6554
- } else {
6555
- currentProps = rootProps;
6556
- }
6557
- const newProps = __spreadProps(__spreadValues({}, currentProps), {
6558
- [fieldName]: value
6559
- });
6560
- if (selectedItem && itemSelector) {
6561
- dispatch({
6562
- type: "replace",
6563
- destinationIndex: itemSelector.index,
6564
- destinationZone: itemSelector.zone || rootDroppableId,
6565
- data: (yield resolveComponentData2(
6566
- __spreadProps(__spreadValues({}, selectedItem), { props: newProps }),
6567
- "replace"
6568
- )).node,
6569
- ui: updatedUi
6570
- });
6571
- } else {
6572
- if (data.root.props) {
6573
- dispatch({
6574
- type: "replaceRoot",
6575
- root: (yield resolveComponentData2(
6576
- __spreadProps(__spreadValues({}, data.root), { props: newProps }),
6577
- "replace"
6578
- )).node,
6579
- ui: __spreadValues(__spreadValues({}, ui), updatedUi),
6580
- recordHistory: true
6581
- });
6582
- } else {
6583
- dispatch({
6584
- type: "setData",
6585
- data: { root: newProps }
6586
- });
6587
- }
6588
- }
6589
- });
6590
- var FieldsChild = ({ fieldName }) => {
6591
- const field = useAppStore((s) => s.fields.fields[fieldName]);
6592
- const isReadOnly = useAppStore(
6593
- (s) => ((s.selectedItem ? s.selectedItem.readOnly : s.state.data.root.readOnly) || {})[fieldName]
6594
- );
6595
- const value = useAppStore((s) => {
6596
- const rootProps = s.state.data.root.props || s.state.data.root;
6597
- return s.selectedItem ? s.selectedItem.props[fieldName] : rootProps[fieldName];
6598
- });
6599
- const id = useAppStore((s) => {
6600
- if (!field) return null;
6601
- return s.selectedItem ? `${s.selectedItem.props.id}_${field.type}_${fieldName}` : `root_${field.type}_${fieldName}`;
6602
- });
6603
- const permissions = useAppStore(
6604
- useShallow5((s) => {
6605
- const { selectedItem, permissions: permissions2 } = s;
6606
- return selectedItem ? permissions2.getPermissions({ item: selectedItem }) : permissions2.getPermissions({ root: true });
6607
- })
6608
- );
6609
- const appStore = useAppStoreApi();
6610
- const onChange = useCallback12(createOnChange(fieldName, appStore), [
6611
- fieldName
6612
- ]);
6613
- const { visible = true } = field != null ? field : {};
6614
- if (!field || !id || !visible) return null;
6615
- if (field.type === "slot") return null;
6616
- return /* @__PURE__ */ jsx29("div", { className: getClassName21("field"), children: /* @__PURE__ */ jsx29(
6617
- AutoFieldPrivate,
6618
- {
6619
- field,
6620
- name: fieldName,
6621
- id,
6622
- readOnly: !permissions.edit || isReadOnly,
6623
- value,
6624
- onChange
6625
- }
6626
- ) }, id);
6627
- };
6628
- var FieldsChildMemo = memo3(FieldsChild);
6629
- var FieldsInternal = ({ wrapFields = true }) => {
6630
- const overrides = useAppStore((s) => s.overrides);
6631
- const componentResolving = useAppStore((s) => {
6632
- var _a, _b;
6633
- const loadingCount = s.selectedItem ? (_a = s.componentState[s.selectedItem.props.id]) == null ? void 0 : _a.loadingCount : (_b = s.componentState["root"]) == null ? void 0 : _b.loadingCount;
6634
- return (loadingCount != null ? loadingCount : 0) > 0;
6635
- });
6636
- const itemSelector = useAppStore(useShallow5((s) => s.state.ui.itemSelector));
6637
- const id = useAppStore((s) => {
6638
- var _a;
6639
- return (_a = s.selectedItem) == null ? void 0 : _a.props.id;
6640
- });
6641
- const appStore = useAppStoreApi();
6642
- useRegisterFieldsSlice(appStore, id);
6643
- const fieldsLoading = useAppStore((s) => s.fields.loading);
6644
- const fieldNames = useAppStore(
6645
- useShallow5((s) => {
6646
- if (s.fields.id === id) {
6647
- return Object.keys(s.fields.fields);
6648
- }
6649
- return [];
6650
- })
6651
- );
6652
- const isLoading = fieldsLoading || componentResolving;
6653
- const Wrapper = useMemo11(() => overrides.fields || DefaultFields, [overrides]);
6654
- return /* @__PURE__ */ jsxs13(
6655
- "form",
6656
- {
6657
- className: getClassName21({ wrapFields }),
6658
- onSubmit: (e) => {
6659
- e.preventDefault();
6660
- },
6661
- children: [
6662
- /* @__PURE__ */ jsx29(Wrapper, { isLoading, itemSelector, children: fieldNames.map((fieldName) => /* @__PURE__ */ jsx29(FieldsChildMemo, { fieldName }, fieldName)) }),
6663
- isLoading && /* @__PURE__ */ jsx29("div", { className: getClassName21("loadingOverlay"), children: /* @__PURE__ */ jsx29("div", { className: getClassName21("loadingOverlayInner"), children: /* @__PURE__ */ jsx29(Loader, { size: 16 }) }) })
6664
- ]
6665
- }
6666
- );
6667
- };
6668
- var Fields = memo3(FieldsInternal);
6669
-
6670
- // components/Puck/components/Components/index.tsx
6671
- init_react_import();
6672
-
6673
- // lib/use-component-list.tsx
6674
- init_react_import();
6675
- import { useEffect as useEffect21, useState as useState18 } from "react";
6676
-
6677
- // components/ComponentList/index.tsx
6678
- init_react_import();
6679
-
6680
- // css-module:/home/runner/work/puck/puck/packages/core/components/ComponentList/styles.module.css#css-module
6681
- init_react_import();
6682
- var styles_module_default17 = { "ComponentList": "_ComponentList_1rrlt_1", "ComponentList--isExpanded": "_ComponentList--isExpanded_1rrlt_5", "ComponentList-content": "_ComponentList-content_1rrlt_9", "ComponentList-title": "_ComponentList-title_1rrlt_17", "ComponentList-titleIcon": "_ComponentList-titleIcon_1rrlt_53" };
6683
-
6684
- // components/ComponentList/index.tsx
6685
- import { useEffect as useEffect20 } from "react";
6686
- import { jsx as jsx30, jsxs as jsxs14 } from "react/jsx-runtime";
6687
- var getClassName22 = get_class_name_factory_default("ComponentList", styles_module_default17);
6688
- var ComponentListItem = ({
6689
- name,
6690
- label
6691
- }) => {
6692
- var _a;
6693
- const overrides = useAppStore((s) => s.overrides);
6694
- const canInsert = useAppStore(
6695
- (s) => s.permissions.getPermissions({
6696
- type: name
6697
- }).insert
6698
- );
6699
- useEffect20(() => {
6700
- if (overrides.componentItem) {
6701
- console.warn(
6702
- "The `componentItem` override has been deprecated and renamed to `drawerItem`"
6703
- );
6704
- }
6705
- }, [overrides]);
6706
- return /* @__PURE__ */ jsx30(Drawer.Item, { label, name, isDragDisabled: !canInsert, children: (_a = overrides.componentItem) != null ? _a : overrides.drawerItem });
6707
- };
6708
- var ComponentList = ({
6709
- children,
6710
- title,
6711
- id
6712
- }) => {
6713
- const config = useAppStore((s) => s.config);
6714
- const setUi = useAppStore((s) => s.setUi);
6715
- const componentList = useAppStore((s) => s.state.ui.componentList);
6716
- const { expanded = true } = componentList[id] || {};
6717
- return /* @__PURE__ */ jsxs14("div", { className: getClassName22({ isExpanded: expanded }), children: [
6718
- title && /* @__PURE__ */ jsxs14(
6719
- "button",
6720
- {
6721
- type: "button",
6722
- className: getClassName22("title"),
6723
- onClick: () => setUi({
6724
- componentList: __spreadProps(__spreadValues({}, componentList), {
6725
- [id]: __spreadProps(__spreadValues({}, componentList[id]), {
6726
- expanded: !expanded
6727
- })
6728
- })
6729
- }),
6730
- title: expanded ? `Collapse${title ? ` ${title}` : ""}` : `Expand${title ? ` ${title}` : ""}`,
6731
- children: [
6732
- /* @__PURE__ */ jsx30("div", { children: title }),
6733
- /* @__PURE__ */ jsx30("div", { className: getClassName22("titleIcon"), children: expanded ? /* @__PURE__ */ jsx30(ChevronUp, { size: 12 }) : /* @__PURE__ */ jsx30(ChevronDown, { size: 12 }) })
6734
- ]
6735
- }
6736
- ),
6737
- /* @__PURE__ */ jsx30("div", { className: getClassName22("content"), children: /* @__PURE__ */ jsx30(Drawer, { children: children || Object.keys(config.components).map((componentKey) => {
6738
- var _a;
6739
- return /* @__PURE__ */ jsx30(
6740
- ComponentListItem,
6741
- {
6742
- label: (_a = config.components[componentKey]["label"]) != null ? _a : componentKey,
6743
- name: componentKey
6744
- },
6745
- componentKey
6746
- );
6747
- }) }) })
6748
- ] });
6749
- };
6750
- ComponentList.Item = ComponentListItem;
6639
+ ComponentList.Item = ComponentListItem;
6751
6640
 
6752
6641
  // lib/use-component-list.tsx
6753
- import { jsx as jsx31 } from "react/jsx-runtime";
6642
+ import { jsx as jsx29 } from "react/jsx-runtime";
6754
6643
  var useComponentList = () => {
6755
6644
  const [componentList, setComponentList] = useState18();
6756
6645
  const config = useAppStore((s) => s.config);
@@ -6771,7 +6660,7 @@ var useComponentList = () => {
6771
6660
  if (category.visible === false) {
6772
6661
  return null;
6773
6662
  }
6774
- return /* @__PURE__ */ jsx31(
6663
+ return /* @__PURE__ */ jsx29(
6775
6664
  ComponentList,
6776
6665
  {
6777
6666
  id: categoryKey,
@@ -6779,7 +6668,7 @@ var useComponentList = () => {
6779
6668
  children: category.components.map((componentName, i) => {
6780
6669
  var _a2;
6781
6670
  const componentConf = config.components[componentName] || {};
6782
- return /* @__PURE__ */ jsx31(
6671
+ return /* @__PURE__ */ jsx29(
6783
6672
  ComponentList.Item,
6784
6673
  {
6785
6674
  label: (_a2 = componentConf["label"]) != null ? _a2 : componentName,
@@ -6799,7 +6688,7 @@ var useComponentList = () => {
6799
6688
  );
6800
6689
  if (remainingComponents.length > 0 && !((_a = uiComponentList.other) == null ? void 0 : _a.components) && ((_b = uiComponentList.other) == null ? void 0 : _b.visible) !== false) {
6801
6690
  _componentList.push(
6802
- /* @__PURE__ */ jsx31(
6691
+ /* @__PURE__ */ jsx29(
6803
6692
  ComponentList,
6804
6693
  {
6805
6694
  id: "other",
@@ -6807,7 +6696,7 @@ var useComponentList = () => {
6807
6696
  children: remainingComponents.map((componentName, i) => {
6808
6697
  var _a2;
6809
6698
  const componentConf = config.components[componentName] || {};
6810
- return /* @__PURE__ */ jsx31(
6699
+ return /* @__PURE__ */ jsx29(
6811
6700
  ComponentList.Item,
6812
6701
  {
6813
6702
  name: componentName,
@@ -6829,12 +6718,19 @@ var useComponentList = () => {
6829
6718
  };
6830
6719
 
6831
6720
  // components/Puck/components/Components/index.tsx
6832
- import { useMemo as useMemo12 } from "react";
6833
- import { jsx as jsx32 } from "react/jsx-runtime";
6721
+ import { useMemo as useMemo10 } from "react";
6722
+
6723
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Components/styles.module.css#css-module
6724
+ init_react_import();
6725
+ var styles_module_default15 = { "Components": "_Components_3pbdy_1" };
6726
+
6727
+ // components/Puck/components/Components/index.tsx
6728
+ import { jsx as jsx30 } from "react/jsx-runtime";
6729
+ var getClassName21 = get_class_name_factory_default("Components", styles_module_default15);
6834
6730
  var Components = () => {
6835
6731
  const overrides = useAppStore((s) => s.overrides);
6836
6732
  const componentList = useComponentList();
6837
- const Wrapper = useMemo12(() => {
6733
+ const Wrapper = useMemo10(() => {
6838
6734
  if (overrides.components) {
6839
6735
  console.warn(
6840
6736
  "The `components` override has been deprecated and renamed to `drawer`"
@@ -6842,1049 +6738,964 @@ var Components = () => {
6842
6738
  }
6843
6739
  return overrides.components || overrides.drawer || "div";
6844
6740
  }, [overrides]);
6845
- return /* @__PURE__ */ jsx32(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ jsx32(ComponentList, { id: "all" }) });
6741
+ return /* @__PURE__ */ jsx30("div", { className: getClassName21(), children: /* @__PURE__ */ jsx30(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ jsx30(ComponentList, { id: "all" }) }) });
6846
6742
  };
6847
6743
 
6848
- // components/Puck/components/Preview/index.tsx
6744
+ // plugins/blocks/index.tsx
6745
+ import { jsx as jsx31 } from "react/jsx-runtime";
6746
+ var blocksPlugin = () => ({
6747
+ name: "blocks",
6748
+ label: "Blocks",
6749
+ render: Components,
6750
+ icon: /* @__PURE__ */ jsx31(Hammer, {})
6751
+ });
6752
+
6753
+ // plugins/outline/index.tsx
6849
6754
  init_react_import();
6850
- import { useCallback as useCallback13, useEffect as useEffect23, useRef as useRef7, useMemo as useMemo13 } from "react";
6851
6755
 
6852
- // components/AutoFrame/index.tsx
6756
+ // components/Puck/components/Outline/index.tsx
6853
6757
  init_react_import();
6854
- import {
6855
- createContext as createContext6,
6856
- useContext as useContext10,
6857
- useEffect as useEffect22,
6858
- useState as useState19
6859
- } from "react";
6860
- import hash from "object-hash";
6861
- import { createPortal as createPortal3 } from "react-dom";
6862
- import { Fragment as Fragment9, jsx as jsx33 } from "react/jsx-runtime";
6863
- var styleSelector = 'style, link[rel="stylesheet"]';
6864
- var collectStyles = (doc) => {
6865
- const collected = [];
6866
- doc.querySelectorAll(styleSelector).forEach((style) => {
6867
- if (style.tagName === "STYLE") {
6868
- const hasContent = !!style.innerHTML.trim();
6869
- if (hasContent) {
6870
- collected.push(style);
6871
- }
6872
- } else {
6873
- collected.push(style);
6874
- }
6875
- });
6876
- return collected;
6877
- };
6878
- var getStyleSheet = (el) => {
6879
- return Array.from(document.styleSheets).find((ss) => {
6880
- const ownerNode = ss.ownerNode;
6881
- return ownerNode.href === el.href;
6882
- });
6883
- };
6884
- var getStyles = (styleSheet) => {
6885
- if (styleSheet) {
6886
- try {
6887
- return [...Array.from(styleSheet.cssRules)].map((rule) => rule.cssText).join("");
6888
- } catch (e) {
6889
- console.warn(
6890
- "Access to stylesheet %s is denied. Ignoring\u2026",
6891
- styleSheet.href
6892
- );
6893
- }
6758
+
6759
+ // components/LayerTree/index.tsx
6760
+ init_react_import();
6761
+
6762
+ // css-module:/home/runner/work/puck/puck/packages/core/components/LayerTree/styles.module.css#css-module
6763
+ init_react_import();
6764
+ var styles_module_default16 = { "LayerTree": "_LayerTree_7rx04_1", "LayerTree-zoneTitle": "_LayerTree-zoneTitle_7rx04_11", "LayerTree-helper": "_LayerTree-helper_7rx04_17", "Layer": "_Layer_7rx04_1", "Layer-inner": "_Layer-inner_7rx04_29", "Layer--containsZone": "_Layer--containsZone_7rx04_35", "Layer-clickable": "_Layer-clickable_7rx04_39", "Layer--isSelected": "_Layer--isSelected_7rx04_61", "Layer-chevron": "_Layer-chevron_7rx04_77", "Layer--childIsSelected": "_Layer--childIsSelected_7rx04_78", "Layer-zones": "_Layer-zones_7rx04_82", "Layer-title": "_Layer-title_7rx04_96", "Layer-name": "_Layer-name_7rx04_105", "Layer-icon": "_Layer-icon_7rx04_111", "Layer-zoneIcon": "_Layer-zoneIcon_7rx04_116" };
6765
+
6766
+ // lib/scroll-into-view.ts
6767
+ init_react_import();
6768
+ var scrollIntoView = (el) => {
6769
+ const oldStyle = __spreadValues({}, el.style);
6770
+ el.style.scrollMargin = "256px";
6771
+ if (el) {
6772
+ el == null ? void 0 : el.scrollIntoView({ behavior: "smooth" });
6773
+ el.style.scrollMargin = oldStyle.scrollMargin || "";
6894
6774
  }
6895
- return "";
6896
6775
  };
6897
- var syncAttributes = (sourceElement, targetElement) => {
6898
- const attributes = sourceElement.attributes;
6899
- if ((attributes == null ? void 0 : attributes.length) > 0) {
6900
- Array.from(attributes).forEach((attribute) => {
6901
- targetElement.setAttribute(attribute.name, attribute.value);
6902
- });
6903
- }
6776
+
6777
+ // components/LayerTree/index.tsx
6778
+ import { useCallback as useCallback12, useContext as useContext10 } from "react";
6779
+
6780
+ // lib/on-scroll-end.ts
6781
+ init_react_import();
6782
+ var onScrollEnd = (frame, cb) => {
6783
+ let scrollTimeout;
6784
+ const callback = function() {
6785
+ clearTimeout(scrollTimeout);
6786
+ scrollTimeout = setTimeout(function() {
6787
+ cb();
6788
+ frame == null ? void 0 : frame.removeEventListener("scroll", callback);
6789
+ }, 50);
6790
+ };
6791
+ frame == null ? void 0 : frame.addEventListener("scroll", callback);
6792
+ setTimeout(() => {
6793
+ if (!scrollTimeout) {
6794
+ cb();
6795
+ }
6796
+ }, 50);
6904
6797
  };
6905
- var defer = (fn) => setTimeout(fn, 0);
6906
- var CopyHostStyles = ({
6907
- children,
6908
- debug = false,
6909
- onStylesLoaded = () => null
6798
+
6799
+ // components/LayerTree/index.tsx
6800
+ import { useShallow as useShallow5 } from "zustand/react/shallow";
6801
+ import { Fragment as Fragment8, jsx as jsx32, jsxs as jsxs13 } from "react/jsx-runtime";
6802
+ var getClassName22 = get_class_name_factory_default("LayerTree", styles_module_default16);
6803
+ var getClassNameLayer = get_class_name_factory_default("Layer", styles_module_default16);
6804
+ var Layer = ({
6805
+ index,
6806
+ itemId,
6807
+ zoneCompound
6910
6808
  }) => {
6911
- const { document: doc, window: win } = useFrame();
6912
- useEffect22(() => {
6913
- if (!win || !doc) {
6914
- return () => {
6915
- };
6916
- }
6917
- let elements = [];
6918
- const hashes = {};
6919
- const lookupEl = (el) => elements.findIndex((elementMap) => elementMap.original === el);
6920
- const mirrorEl = (el, inlineStyles = false) => __async(void 0, null, function* () {
6921
- let mirror;
6922
- if (el.nodeName === "LINK" && inlineStyles) {
6923
- mirror = document.createElement("style");
6924
- mirror.type = "text/css";
6925
- let styleSheet = getStyleSheet(el);
6926
- if (!styleSheet) {
6927
- yield new Promise((resolve) => {
6928
- const fn = () => {
6929
- resolve();
6930
- el.removeEventListener("load", fn);
6931
- };
6932
- el.addEventListener("load", fn);
6933
- });
6934
- styleSheet = getStyleSheet(el);
6935
- }
6936
- const styles2 = getStyles(styleSheet);
6937
- if (!styles2) {
6938
- if (debug) {
6939
- console.warn(
6940
- `Tried to load styles for link element, but couldn't find them. Skipping...`
6941
- );
6942
- }
6943
- return;
6944
- }
6945
- mirror.innerHTML = styles2;
6946
- mirror.setAttribute("data-href", el.getAttribute("href"));
6947
- } else {
6948
- mirror = el.cloneNode(true);
6949
- }
6950
- return mirror;
6951
- });
6952
- const addEl = (el) => __async(void 0, null, function* () {
6953
- const index = lookupEl(el);
6954
- if (index > -1) {
6955
- if (debug)
6956
- console.log(
6957
- `Tried to add an element that was already mirrored. Updating instead...`
6958
- );
6959
- elements[index].mirror.innerText = el.innerText;
6960
- return;
6961
- }
6962
- const mirror = yield mirrorEl(el);
6963
- if (!mirror) {
6964
- return;
6965
- }
6966
- const elHash = hash(mirror.outerHTML);
6967
- if (hashes[elHash]) {
6968
- if (debug)
6969
- console.log(
6970
- `iframe already contains element that is being mirrored. Skipping...`
6971
- );
6972
- return;
6973
- }
6974
- hashes[elHash] = true;
6975
- doc.head.append(mirror);
6976
- elements.push({ original: el, mirror });
6977
- if (debug) console.log(`Added style node ${el.outerHTML}`);
6978
- });
6979
- const removeEl = (el) => {
6980
- var _a, _b;
6981
- const index = lookupEl(el);
6982
- if (index === -1) {
6983
- if (debug)
6984
- console.log(
6985
- `Tried to remove an element that did not exist. Skipping...`
6986
- );
6987
- return;
6988
- }
6989
- const elHash = hash(el.outerHTML);
6990
- (_b = (_a = elements[index]) == null ? void 0 : _a.mirror) == null ? void 0 : _b.remove();
6991
- delete hashes[elHash];
6992
- if (debug) console.log(`Removed style node ${el.outerHTML}`);
6993
- };
6994
- const observer = new MutationObserver((mutations) => {
6995
- mutations.forEach((mutation) => {
6996
- if (mutation.type === "childList") {
6997
- mutation.addedNodes.forEach((node) => {
6998
- if (node.nodeType === Node.TEXT_NODE || node.nodeType === Node.ELEMENT_NODE) {
6999
- const el = node.nodeType === Node.TEXT_NODE ? node.parentElement : node;
7000
- if (el && el.matches(styleSelector)) {
7001
- defer(() => addEl(el));
7002
- }
7003
- }
7004
- });
7005
- mutation.removedNodes.forEach((node) => {
7006
- if (node.nodeType === Node.TEXT_NODE || node.nodeType === Node.ELEMENT_NODE) {
7007
- const el = node.nodeType === Node.TEXT_NODE ? node.parentElement : node;
7008
- if (el && el.matches(styleSelector)) {
7009
- defer(() => removeEl(el));
7010
- }
7011
- }
7012
- });
7013
- }
7014
- });
7015
- });
7016
- const parentDocument = win.parent.document;
7017
- const collectedStyles = collectStyles(parentDocument);
7018
- const hrefs = [];
7019
- let stylesLoaded = 0;
7020
- const parentHtml = parentDocument.getElementsByTagName("html")[0];
7021
- syncAttributes(parentHtml, doc.documentElement);
7022
- const parentBody = parentDocument.getElementsByTagName("body")[0];
7023
- syncAttributes(parentBody, doc.body);
7024
- Promise.all(
7025
- collectedStyles.map((styleNode, i) => __async(void 0, null, function* () {
7026
- if (styleNode.nodeName === "LINK") {
7027
- const linkHref = styleNode.href;
7028
- if (hrefs.indexOf(linkHref) > -1) {
7029
- return;
7030
- }
7031
- hrefs.push(linkHref);
7032
- }
7033
- const mirror = yield mirrorEl(styleNode);
7034
- if (!mirror) return;
7035
- elements.push({ original: styleNode, mirror });
7036
- return mirror;
7037
- }))
7038
- ).then((mirrorStyles) => {
7039
- const filtered = mirrorStyles.filter(
7040
- (el) => typeof el !== "undefined"
7041
- );
7042
- filtered.forEach((mirror) => {
7043
- mirror.onload = () => {
7044
- stylesLoaded = stylesLoaded + 1;
7045
- if (stylesLoaded >= elements.length) {
7046
- onStylesLoaded();
7047
- }
7048
- };
7049
- mirror.onerror = () => {
7050
- console.warn(`AutoFrame couldn't load a stylesheet`);
7051
- stylesLoaded = stylesLoaded + 1;
7052
- if (stylesLoaded >= elements.length) {
7053
- onStylesLoaded();
7054
- }
7055
- };
7056
- });
7057
- doc.head.innerHTML = "";
7058
- doc.head.append(...filtered);
7059
- observer.observe(parentDocument.head, { childList: true, subtree: true });
7060
- filtered.forEach((el) => {
7061
- const elHash = hash(el.outerHTML);
7062
- hashes[elHash] = true;
7063
- });
7064
- });
7065
- return () => {
7066
- observer.disconnect();
7067
- };
7068
- }, []);
7069
- return /* @__PURE__ */ jsx33(Fragment9, { children });
7070
- };
7071
- var autoFrameContext = createContext6({});
7072
- var useFrame = () => useContext10(autoFrameContext);
7073
- function AutoFrame(_a) {
7074
- var _b = _a, {
7075
- children,
7076
- className,
7077
- debug,
7078
- id,
7079
- onReady = () => {
7080
- },
7081
- onNotReady = () => {
6809
+ var _a;
6810
+ const config = useAppStore((s) => s.config);
6811
+ const itemSelector = useAppStore((s) => s.state.ui.itemSelector);
6812
+ const dispatch = useAppStore((s) => s.dispatch);
6813
+ const setItemSelector = useCallback12(
6814
+ (itemSelector2) => {
6815
+ dispatch({ type: "setUi", ui: { itemSelector: itemSelector2 } });
7082
6816
  },
7083
- frameRef
7084
- } = _b, props = __objRest(_b, [
7085
- "children",
7086
- "className",
7087
- "debug",
7088
- "id",
7089
- "onReady",
7090
- "onNotReady",
7091
- "frameRef"
7092
- ]);
7093
- const [loaded, setLoaded] = useState19(false);
7094
- const [ctx, setCtx] = useState19({});
7095
- const [mountTarget, setMountTarget] = useState19();
7096
- const [stylesLoaded, setStylesLoaded] = useState19(false);
7097
- useEffect22(() => {
7098
- var _a2;
7099
- if (frameRef.current) {
7100
- const doc = frameRef.current.contentDocument;
7101
- const win = frameRef.current.contentWindow;
7102
- setCtx({
7103
- document: doc || void 0,
7104
- window: win || void 0
7105
- });
7106
- setMountTarget(
7107
- (_a2 = frameRef.current.contentDocument) == null ? void 0 : _a2.getElementById("frame-root")
7108
- );
7109
- if (doc && win && stylesLoaded) {
7110
- onReady();
7111
- } else {
7112
- onNotReady();
7113
- }
7114
- }
7115
- }, [frameRef, loaded, stylesLoaded]);
7116
- return /* @__PURE__ */ jsx33(
7117
- "iframe",
7118
- __spreadProps(__spreadValues({}, props), {
7119
- className,
7120
- id,
7121
- srcDoc: '<!DOCTYPE html><html><head></head><body><div id="frame-root" data-puck-entry></div></body></html>',
7122
- ref: frameRef,
7123
- onLoad: () => {
7124
- setLoaded(true);
7125
- },
7126
- children: /* @__PURE__ */ jsx33(autoFrameContext.Provider, { value: ctx, children: loaded && mountTarget && /* @__PURE__ */ jsx33(
7127
- CopyHostStyles,
7128
- {
7129
- debug,
7130
- onStylesLoaded: () => setStylesLoaded(true),
7131
- children: createPortal3(children, mountTarget)
7132
- }
7133
- ) })
7134
- })
6817
+ [dispatch]
7135
6818
  );
7136
- }
7137
- AutoFrame.displayName = "AutoFrame";
7138
- var AutoFrame_default = AutoFrame;
7139
-
7140
- // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Preview/styles.module.css#css-module
7141
- init_react_import();
7142
- var styles_module_default18 = { "PuckPreview": "_PuckPreview_z2rgu_1", "PuckPreview-frame": "_PuckPreview-frame_z2rgu_6" };
7143
-
7144
- // components/Puck/components/Preview/index.tsx
7145
- import { Fragment as Fragment10, jsx as jsx34 } from "react/jsx-runtime";
7146
- var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
7147
- var useBubbleIframeEvents = (ref) => {
7148
- const status = useAppStore((s) => s.status);
7149
- useEffect23(() => {
7150
- if (ref.current && status === "READY") {
7151
- const iframe = ref.current;
7152
- const handlePointerMove = (event) => {
7153
- const evt = new BubbledPointerEvent("pointermove", __spreadProps(__spreadValues({}, event), {
7154
- bubbles: true,
7155
- cancelable: false,
7156
- clientX: event.clientX,
7157
- clientY: event.clientY,
7158
- originalTarget: event.target
7159
- }));
7160
- iframe.dispatchEvent(evt);
7161
- };
7162
- const register = () => {
7163
- var _a;
7164
- unregister();
7165
- (_a = iframe.contentDocument) == null ? void 0 : _a.addEventListener(
7166
- "pointermove",
7167
- handlePointerMove,
7168
- {
7169
- capture: true
7170
- }
7171
- );
7172
- };
7173
- const unregister = () => {
7174
- var _a;
7175
- (_a = iframe.contentDocument) == null ? void 0 : _a.removeEventListener(
7176
- "pointermove",
7177
- handlePointerMove
7178
- );
7179
- };
7180
- register();
7181
- return () => {
7182
- unregister();
7183
- };
7184
- }
7185
- }, [status]);
7186
- };
7187
- var Preview2 = ({ id = "puck-preview" }) => {
7188
- const dispatch = useAppStore((s) => s.dispatch);
7189
- const root = useAppStore((s) => s.state.data.root);
7190
- const config = useAppStore((s) => s.config);
7191
- const setStatus = useAppStore((s) => s.setStatus);
7192
- const iframe = useAppStore((s) => s.iframe);
7193
- const overrides = useAppStore((s) => s.overrides);
7194
- const metadata = useAppStore((s) => s.metadata);
7195
- const renderData = useAppStore(
7196
- (s) => s.state.ui.previewMode === "edit" ? null : s.state.data
6819
+ const selecedItemId = useAppStore((s) => {
6820
+ var _a2;
6821
+ return (_a2 = s.selectedItem) == null ? void 0 : _a2.props.id;
6822
+ });
6823
+ const isSelected = selecedItemId === itemId || itemSelector && itemSelector.zone === rootDroppableId && !zoneCompound;
6824
+ const nodeData = useAppStore((s) => s.state.indexes.nodes[itemId]);
6825
+ const zonesForItem = useAppStore(
6826
+ useShallow5(
6827
+ (s) => Object.keys(s.state.indexes.zones).filter(
6828
+ (z) => z.split(":")[0] === itemId
6829
+ )
6830
+ )
7197
6831
  );
7198
- const Page = useCallback13(
7199
- (pageProps) => {
7200
- var _a, _b;
7201
- const propsWithSlots = useSlots(
7202
- config,
7203
- { type: "root", props: pageProps },
7204
- DropZoneEditPure
7205
- );
7206
- return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
7207
- id: "puck-root"
7208
- }, propsWithSlots)) : /* @__PURE__ */ jsx34(Fragment10, { children: propsWithSlots.children });
7209
- },
7210
- [config]
6832
+ const containsZone = zonesForItem.length > 0;
6833
+ const zoneStore = useContext10(ZoneStoreContext);
6834
+ const isHovering = useContextStore(
6835
+ ZoneStoreContext,
6836
+ (s) => s.hoveringComponent === itemId
7211
6837
  );
7212
- const Frame = useMemo13(() => overrides.iframe, [overrides]);
7213
- const rootProps = root.props || root;
7214
- const ref = useRef7(null);
7215
- useBubbleIframeEvents(ref);
7216
- const inner = !renderData ? /* @__PURE__ */ jsx34(
7217
- Page,
7218
- __spreadProps(__spreadValues({}, rootProps), {
7219
- puck: {
7220
- renderDropZone: DropZonePure,
7221
- isEditing: true,
7222
- dragRef: null,
7223
- metadata
7224
- },
7225
- editMode: true,
7226
- children: /* @__PURE__ */ jsx34(DropZonePure, { zone: rootDroppableId })
7227
- })
7228
- ) : /* @__PURE__ */ jsx34(Render, { data: renderData, config, metadata });
7229
- useEffect23(() => {
7230
- if (!iframe.enabled) {
7231
- setStatus("READY");
7232
- }
7233
- }, [iframe.enabled]);
7234
- return /* @__PURE__ */ jsx34(
7235
- "div",
6838
+ const childIsSelected = useAppStore((s) => {
6839
+ var _a2, _b;
6840
+ const selectedData = s.state.indexes.nodes[(_a2 = s.selectedItem) == null ? void 0 : _a2.props.id];
6841
+ return (_b = selectedData == null ? void 0 : selectedData.path.some((candidate) => {
6842
+ const [candidateId] = candidate.split(":");
6843
+ return candidateId === itemId;
6844
+ })) != null ? _b : false;
6845
+ });
6846
+ const componentConfig = config.components[nodeData.data.type];
6847
+ const label = (_a = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _a : nodeData.data.type.toString();
6848
+ return /* @__PURE__ */ jsxs13(
6849
+ "li",
7236
6850
  {
7237
- className: getClassName23(),
7238
- id,
7239
- "data-puck-preview": true,
7240
- onClick: (e) => {
7241
- const el = e.target;
7242
- if (!el.hasAttribute("data-puck-component") && !el.hasAttribute("data-puck-dropzone")) {
7243
- dispatch({ type: "setUi", ui: { itemSelector: null } });
7244
- }
7245
- },
7246
- children: iframe.enabled ? /* @__PURE__ */ jsx34(
7247
- AutoFrame_default,
7248
- {
7249
- id: "preview-frame",
7250
- className: getClassName23("frame"),
7251
- "data-rfd-iframe": true,
7252
- onReady: () => {
7253
- setStatus("READY");
7254
- },
7255
- onNotReady: () => {
7256
- setStatus("MOUNTED");
7257
- },
7258
- frameRef: ref,
7259
- children: /* @__PURE__ */ jsx34(autoFrameContext.Consumer, { children: ({ document: document2 }) => {
7260
- if (Frame) {
7261
- return /* @__PURE__ */ jsx34(Frame, { document: document2, children: inner });
7262
- }
7263
- return inner;
7264
- } })
7265
- }
7266
- ) : /* @__PURE__ */ jsx34(
7267
- "div",
7268
- {
7269
- id: "preview-frame",
7270
- className: getClassName23("frame"),
7271
- ref,
7272
- "data-puck-entry": true,
7273
- children: inner
7274
- }
7275
- )
6851
+ className: getClassNameLayer({
6852
+ isSelected,
6853
+ isHovering,
6854
+ containsZone,
6855
+ childIsSelected
6856
+ }),
6857
+ children: [
6858
+ /* @__PURE__ */ jsx32("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ jsxs13(
6859
+ "button",
6860
+ {
6861
+ type: "button",
6862
+ className: getClassNameLayer("clickable"),
6863
+ onClick: () => {
6864
+ if (isSelected) {
6865
+ setItemSelector(null);
6866
+ return;
6867
+ }
6868
+ const frame = getFrame();
6869
+ const el = frame == null ? void 0 : frame.querySelector(
6870
+ `[data-puck-component="${itemId}"]`
6871
+ );
6872
+ if (!el) {
6873
+ setItemSelector({
6874
+ index,
6875
+ zone: zoneCompound
6876
+ });
6877
+ return;
6878
+ }
6879
+ scrollIntoView(el);
6880
+ onScrollEnd(frame, () => {
6881
+ setItemSelector({
6882
+ index,
6883
+ zone: zoneCompound
6884
+ });
6885
+ });
6886
+ },
6887
+ onMouseEnter: (e) => {
6888
+ e.stopPropagation();
6889
+ zoneStore.setState({ hoveringComponent: itemId });
6890
+ },
6891
+ onMouseLeave: (e) => {
6892
+ e.stopPropagation();
6893
+ zoneStore.setState({ hoveringComponent: null });
6894
+ },
6895
+ children: [
6896
+ containsZone && /* @__PURE__ */ jsx32(
6897
+ "div",
6898
+ {
6899
+ className: getClassNameLayer("chevron"),
6900
+ title: isSelected ? "Collapse" : "Expand",
6901
+ children: /* @__PURE__ */ jsx32(ChevronDown, { size: "12" })
6902
+ }
6903
+ ),
6904
+ /* @__PURE__ */ jsxs13("div", { className: getClassNameLayer("title"), children: [
6905
+ /* @__PURE__ */ jsx32("div", { className: getClassNameLayer("icon"), children: nodeData.data.type === "Text" || nodeData.data.type === "Heading" ? /* @__PURE__ */ jsx32(Type, { size: "16" }) : /* @__PURE__ */ jsx32(LayoutGrid, { size: "16" }) }),
6906
+ /* @__PURE__ */ jsx32("div", { className: getClassNameLayer("name"), children: label })
6907
+ ] })
6908
+ ]
6909
+ }
6910
+ ) }),
6911
+ containsZone && zonesForItem.map((subzone) => /* @__PURE__ */ jsx32("div", { className: getClassNameLayer("zones"), children: /* @__PURE__ */ jsx32(LayerTree, { zoneCompound: subzone }) }, subzone))
6912
+ ]
7276
6913
  }
7277
6914
  );
7278
6915
  };
6916
+ var LayerTree = ({
6917
+ label: _label,
6918
+ zoneCompound
6919
+ }) => {
6920
+ const label = useAppStore((s) => {
6921
+ var _a, _b, _c, _d;
6922
+ if (_label) return _label;
6923
+ if (zoneCompound === rootDroppableId) return;
6924
+ const [componentId, slotId] = zoneCompound.split(":");
6925
+ const componentType = (_a = s.state.indexes.nodes[componentId]) == null ? void 0 : _a.data.type;
6926
+ const configForComponent = componentType && componentType !== rootAreaId ? s.config.components[componentType] : s.config.root;
6927
+ return (_d = (_c = (_b = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _b[slotId]) == null ? void 0 : _c.label) != null ? _d : slotId;
6928
+ });
6929
+ const contentIds = useAppStore(
6930
+ useShallow5(
6931
+ (s) => {
6932
+ var _a, _b;
6933
+ return zoneCompound ? (_b = (_a = s.state.indexes.zones[zoneCompound]) == null ? void 0 : _a.contentIds) != null ? _b : [] : [];
6934
+ }
6935
+ )
6936
+ );
6937
+ return /* @__PURE__ */ jsxs13(Fragment8, { children: [
6938
+ label && /* @__PURE__ */ jsxs13("div", { className: getClassName22("zoneTitle"), children: [
6939
+ /* @__PURE__ */ jsx32("div", { className: getClassName22("zoneIcon"), children: /* @__PURE__ */ jsx32(Layers, { size: "16" }) }),
6940
+ label
6941
+ ] }),
6942
+ /* @__PURE__ */ jsxs13("ul", { className: getClassName22(), children: [
6943
+ contentIds.length === 0 && /* @__PURE__ */ jsx32("div", { className: getClassName22("helper"), children: "No items" }),
6944
+ contentIds.map((itemId, i) => {
6945
+ return /* @__PURE__ */ jsx32(
6946
+ Layer,
6947
+ {
6948
+ index: i,
6949
+ itemId,
6950
+ zoneCompound
6951
+ },
6952
+ itemId
6953
+ );
6954
+ })
6955
+ ] })
6956
+ ] });
6957
+ };
7279
6958
 
7280
6959
  // components/Puck/components/Outline/index.tsx
6960
+ import { useMemo as useMemo11 } from "react";
6961
+
6962
+ // lib/data/find-zones-for-area.ts
7281
6963
  init_react_import();
6964
+ var findZonesForArea = (state, area) => {
6965
+ return Object.keys(state.indexes.zones).filter(
6966
+ (zone) => zone.split(":")[0] === area
6967
+ );
6968
+ };
7282
6969
 
7283
- // components/LayerTree/index.tsx
6970
+ // components/Puck/components/Outline/index.tsx
6971
+ import { useShallow as useShallow6 } from "zustand/react/shallow";
6972
+
6973
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Outline/styles.module.css#css-module
7284
6974
  init_react_import();
6975
+ var styles_module_default17 = { "Outline": "_Outline_cvjlj_1" };
7285
6976
 
7286
- // css-module:/home/runner/work/puck/puck/packages/core/components/LayerTree/styles.module.css#css-module
6977
+ // components/Puck/components/Outline/index.tsx
6978
+ import { jsx as jsx33 } from "react/jsx-runtime";
6979
+ var getClassName23 = get_class_name_factory_default("Outline", styles_module_default17);
6980
+ var Outline = () => {
6981
+ const outlineOverride = useAppStore((s) => s.overrides.outline);
6982
+ const rootZones = useAppStore(
6983
+ useShallow6((s) => findZonesForArea(s.state, "root"))
6984
+ );
6985
+ const Wrapper = useMemo11(() => outlineOverride || "div", [outlineOverride]);
6986
+ return /* @__PURE__ */ jsx33("div", { className: getClassName23(), children: /* @__PURE__ */ jsx33(Wrapper, { children: rootZones.map((zoneCompound) => /* @__PURE__ */ jsx33(
6987
+ LayerTree,
6988
+ {
6989
+ label: rootZones.length === 1 ? "" : zoneCompound.split(":")[1],
6990
+ zoneCompound
6991
+ },
6992
+ zoneCompound
6993
+ )) }) });
6994
+ };
6995
+
6996
+ // plugins/outline/index.tsx
6997
+ import { jsx as jsx34 } from "react/jsx-runtime";
6998
+ var outlinePlugin = () => ({
6999
+ name: "outline",
7000
+ label: "Outline",
7001
+ render: Outline,
7002
+ icon: /* @__PURE__ */ jsx34(Layers, {})
7003
+ });
7004
+
7005
+ // plugins/fields/index.tsx
7287
7006
  init_react_import();
7288
- var styles_module_default19 = { "LayerTree": "_LayerTree_7rx04_1", "LayerTree-zoneTitle": "_LayerTree-zoneTitle_7rx04_11", "LayerTree-helper": "_LayerTree-helper_7rx04_17", "Layer": "_Layer_7rx04_1", "Layer-inner": "_Layer-inner_7rx04_29", "Layer--containsZone": "_Layer--containsZone_7rx04_35", "Layer-clickable": "_Layer-clickable_7rx04_39", "Layer--isSelected": "_Layer--isSelected_7rx04_61", "Layer-chevron": "_Layer-chevron_7rx04_77", "Layer--childIsSelected": "_Layer--childIsSelected_7rx04_78", "Layer-zones": "_Layer-zones_7rx04_82", "Layer-title": "_Layer-title_7rx04_96", "Layer-name": "_Layer-name_7rx04_105", "Layer-icon": "_Layer-icon_7rx04_111", "Layer-zoneIcon": "_Layer-zoneIcon_7rx04_116" };
7289
7007
 
7290
- // lib/scroll-into-view.ts
7008
+ // components/Breadcrumbs/index.tsx
7291
7009
  init_react_import();
7292
- var scrollIntoView = (el) => {
7293
- const oldStyle = __spreadValues({}, el.style);
7294
- el.style.scrollMargin = "256px";
7295
- if (el) {
7296
- el == null ? void 0 : el.scrollIntoView({ behavior: "smooth" });
7297
- el.style.scrollMargin = oldStyle.scrollMargin || "";
7298
- }
7299
- };
7300
7010
 
7301
- // components/LayerTree/index.tsx
7302
- import { useCallback as useCallback14, useContext as useContext11 } from "react";
7011
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Breadcrumbs/styles.module.css#css-module
7012
+ init_react_import();
7013
+ var styles_module_default18 = { "Breadcrumbs": "_Breadcrumbs_1c9yh_1", "Breadcrumbs-breadcrumbLabel": "_Breadcrumbs-breadcrumbLabel_1c9yh_7", "Breadcrumbs-breadcrumb": "_Breadcrumbs-breadcrumb_1c9yh_7" };
7303
7014
 
7304
- // lib/on-scroll-end.ts
7015
+ // lib/use-breadcrumbs.ts
7305
7016
  init_react_import();
7306
- var onScrollEnd = (frame, cb) => {
7307
- let scrollTimeout;
7308
- const callback = function() {
7309
- clearTimeout(scrollTimeout);
7310
- scrollTimeout = setTimeout(function() {
7311
- cb();
7312
- frame == null ? void 0 : frame.removeEventListener("scroll", callback);
7313
- }, 50);
7314
- };
7315
- frame == null ? void 0 : frame.addEventListener("scroll", callback);
7316
- setTimeout(() => {
7317
- if (!scrollTimeout) {
7318
- cb();
7017
+ import { useMemo as useMemo12 } from "react";
7018
+ var useBreadcrumbs = (renderCount) => {
7019
+ const selectedId = useAppStore((s) => {
7020
+ var _a;
7021
+ return (_a = s.selectedItem) == null ? void 0 : _a.props.id;
7022
+ });
7023
+ const config = useAppStore((s) => s.config);
7024
+ const path = useAppStore((s) => {
7025
+ var _a;
7026
+ return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
7027
+ });
7028
+ const appStore = useAppStoreApi();
7029
+ return useMemo12(() => {
7030
+ const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
7031
+ var _a, _b, _c;
7032
+ const [componentId] = zoneCompound.split(":");
7033
+ if (componentId === "root") {
7034
+ return {
7035
+ label: "Page",
7036
+ selector: null
7037
+ };
7038
+ }
7039
+ const node = appStore.getState().state.indexes.nodes[componentId];
7040
+ const parentId = node.path[node.path.length - 1];
7041
+ const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
7042
+ const index = contentIds.indexOf(componentId);
7043
+ const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
7044
+ return {
7045
+ label,
7046
+ selector: node ? {
7047
+ index,
7048
+ zone: node.path[node.path.length - 1]
7049
+ } : null
7050
+ };
7051
+ })) || [];
7052
+ if (renderCount) {
7053
+ return breadcrumbs.slice(breadcrumbs.length - renderCount);
7319
7054
  }
7320
- }, 50);
7055
+ return breadcrumbs;
7056
+ }, [path, renderCount]);
7321
7057
  };
7322
7058
 
7323
- // components/LayerTree/index.tsx
7324
- import { useShallow as useShallow6 } from "zustand/react/shallow";
7325
- import { Fragment as Fragment11, jsx as jsx35, jsxs as jsxs15 } from "react/jsx-runtime";
7326
- var getClassName24 = get_class_name_factory_default("LayerTree", styles_module_default19);
7327
- var getClassNameLayer = get_class_name_factory_default("Layer", styles_module_default19);
7328
- var Layer = ({
7329
- index,
7330
- itemId,
7331
- zoneCompound
7059
+ // components/Breadcrumbs/index.tsx
7060
+ import { jsx as jsx35, jsxs as jsxs14 } from "react/jsx-runtime";
7061
+ var getClassName24 = get_class_name_factory_default("Breadcrumbs", styles_module_default18);
7062
+ var Breadcrumbs = ({
7063
+ children,
7064
+ numParents = 1
7332
7065
  }) => {
7333
- var _a;
7334
- const config = useAppStore((s) => s.config);
7335
- const itemSelector = useAppStore((s) => s.state.ui.itemSelector);
7336
- const dispatch = useAppStore((s) => s.dispatch);
7337
- const setItemSelector = useCallback14(
7338
- (itemSelector2) => {
7339
- dispatch({ type: "setUi", ui: { itemSelector: itemSelector2 } });
7340
- },
7341
- [dispatch]
7342
- );
7343
- const selecedItemId = useAppStore((s) => {
7344
- var _a2;
7345
- return (_a2 = s.selectedItem) == null ? void 0 : _a2.props.id;
7066
+ const setUi = useAppStore((s) => s.setUi);
7067
+ const breadcrumbs = useBreadcrumbs(numParents);
7068
+ return /* @__PURE__ */ jsxs14("div", { className: getClassName24(), children: [
7069
+ breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ jsxs14("div", { className: getClassName24("breadcrumb"), children: [
7070
+ /* @__PURE__ */ jsx35(
7071
+ "button",
7072
+ {
7073
+ type: "button",
7074
+ className: getClassName24("breadcrumbLabel"),
7075
+ onClick: () => setUi({ itemSelector: breadcrumb.selector }),
7076
+ children: breadcrumb.label
7077
+ }
7078
+ ),
7079
+ /* @__PURE__ */ jsx35(ChevronRight, { size: 16 })
7080
+ ] }, i)),
7081
+ children
7082
+ ] });
7083
+ };
7084
+
7085
+ // components/Puck/components/Fields/index.tsx
7086
+ init_react_import();
7087
+
7088
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Fields/styles.module.css#css-module
7089
+ init_react_import();
7090
+ var styles_module_default19 = { "PuckFields": "_PuckFields_10bh7_1", "PuckFields--isLoading": "_PuckFields--isLoading_10bh7_6", "PuckFields-loadingOverlay": "_PuckFields-loadingOverlay_10bh7_10", "PuckFields-loadingOverlayInner": "_PuckFields-loadingOverlayInner_10bh7_25", "PuckFields-field": "_PuckFields-field_10bh7_32", "PuckFields--wrapFields": "_PuckFields--wrapFields_10bh7_36" };
7091
+
7092
+ // components/Puck/components/Fields/index.tsx
7093
+ import { memo as memo3, useCallback as useCallback13, useMemo as useMemo13 } from "react";
7094
+ import { useShallow as useShallow7 } from "zustand/react/shallow";
7095
+ import { Fragment as Fragment9, jsx as jsx36, jsxs as jsxs15 } from "react/jsx-runtime";
7096
+ var getClassName25 = get_class_name_factory_default("PuckFields", styles_module_default19);
7097
+ var DefaultFields = ({
7098
+ children
7099
+ }) => {
7100
+ return /* @__PURE__ */ jsx36(Fragment9, { children });
7101
+ };
7102
+ var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(void 0, null, function* () {
7103
+ let currentProps;
7104
+ const { dispatch, state, selectedItem, resolveComponentData: resolveComponentData2 } = appStore.getState();
7105
+ const { data, ui } = state;
7106
+ const { itemSelector } = ui;
7107
+ const rootProps = data.root.props || data.root;
7108
+ if (selectedItem) {
7109
+ currentProps = selectedItem.props;
7110
+ } else {
7111
+ currentProps = rootProps;
7112
+ }
7113
+ const newProps = __spreadProps(__spreadValues({}, currentProps), {
7114
+ [fieldName]: value
7346
7115
  });
7347
- const isSelected = selecedItemId === itemId || itemSelector && itemSelector.zone === rootDroppableId && !zoneCompound;
7348
- const nodeData = useAppStore((s) => s.state.indexes.nodes[itemId]);
7349
- const zonesForItem = useAppStore(
7350
- useShallow6(
7351
- (s) => Object.keys(s.state.indexes.zones).filter(
7352
- (z) => z.split(":")[0] === itemId
7353
- )
7354
- )
7116
+ if (selectedItem && itemSelector) {
7117
+ dispatch({
7118
+ type: "replace",
7119
+ destinationIndex: itemSelector.index,
7120
+ destinationZone: itemSelector.zone || rootDroppableId,
7121
+ data: (yield resolveComponentData2(
7122
+ __spreadProps(__spreadValues({}, selectedItem), { props: newProps }),
7123
+ "replace"
7124
+ )).node,
7125
+ ui: updatedUi
7126
+ });
7127
+ } else {
7128
+ if (data.root.props) {
7129
+ dispatch({
7130
+ type: "replaceRoot",
7131
+ root: (yield resolveComponentData2(
7132
+ __spreadProps(__spreadValues({}, data.root), { props: newProps }),
7133
+ "replace"
7134
+ )).node,
7135
+ ui: __spreadValues(__spreadValues({}, ui), updatedUi),
7136
+ recordHistory: true
7137
+ });
7138
+ } else {
7139
+ dispatch({
7140
+ type: "setData",
7141
+ data: { root: newProps }
7142
+ });
7143
+ }
7144
+ }
7145
+ });
7146
+ var FieldsChild = ({ fieldName }) => {
7147
+ const field = useAppStore((s) => s.fields.fields[fieldName]);
7148
+ const isReadOnly = useAppStore(
7149
+ (s) => ((s.selectedItem ? s.selectedItem.readOnly : s.state.data.root.readOnly) || {})[fieldName]
7355
7150
  );
7356
- const containsZone = zonesForItem.length > 0;
7357
- const zoneStore = useContext11(ZoneStoreContext);
7358
- const isHovering = useContextStore(
7359
- ZoneStoreContext,
7360
- (s) => s.hoveringComponent === itemId
7151
+ const value = useAppStore((s) => {
7152
+ const rootProps = s.state.data.root.props || s.state.data.root;
7153
+ return s.selectedItem ? s.selectedItem.props[fieldName] : rootProps[fieldName];
7154
+ });
7155
+ const id = useAppStore((s) => {
7156
+ if (!field) return null;
7157
+ return s.selectedItem ? `${s.selectedItem.props.id}_${field.type}_${fieldName}` : `root_${field.type}_${fieldName}`;
7158
+ });
7159
+ const permissions = useAppStore(
7160
+ useShallow7((s) => {
7161
+ const { selectedItem, permissions: permissions2 } = s;
7162
+ return selectedItem ? permissions2.getPermissions({ item: selectedItem }) : permissions2.getPermissions({ root: true });
7163
+ })
7361
7164
  );
7362
- const childIsSelected = useAppStore((s) => {
7363
- var _a2, _b;
7364
- const selectedData = s.state.indexes.nodes[(_a2 = s.selectedItem) == null ? void 0 : _a2.props.id];
7365
- return (_b = selectedData == null ? void 0 : selectedData.path.some((candidate) => {
7366
- const [candidateId] = candidate.split(":");
7367
- return candidateId === itemId;
7368
- })) != null ? _b : false;
7165
+ const appStore = useAppStoreApi();
7166
+ const onChange = useCallback13(createOnChange(fieldName, appStore), [
7167
+ fieldName
7168
+ ]);
7169
+ const { visible = true } = field != null ? field : {};
7170
+ if (!field || !id || !visible) return null;
7171
+ if (field.type === "slot") return null;
7172
+ return /* @__PURE__ */ jsx36("div", { className: getClassName25("field"), children: /* @__PURE__ */ jsx36(
7173
+ AutoFieldPrivate,
7174
+ {
7175
+ field,
7176
+ name: fieldName,
7177
+ id,
7178
+ readOnly: !permissions.edit || isReadOnly,
7179
+ value,
7180
+ onChange
7181
+ }
7182
+ ) }, id);
7183
+ };
7184
+ var FieldsChildMemo = memo3(FieldsChild);
7185
+ var FieldsInternal = ({ wrapFields = true }) => {
7186
+ const overrides = useAppStore((s) => s.overrides);
7187
+ const componentResolving = useAppStore((s) => {
7188
+ var _a, _b;
7189
+ const loadingCount = s.selectedItem ? (_a = s.componentState[s.selectedItem.props.id]) == null ? void 0 : _a.loadingCount : (_b = s.componentState["root"]) == null ? void 0 : _b.loadingCount;
7190
+ return (loadingCount != null ? loadingCount : 0) > 0;
7369
7191
  });
7370
- const componentConfig = config.components[nodeData.data.type];
7371
- const label = (_a = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _a : nodeData.data.type.toString();
7192
+ const itemSelector = useAppStore(useShallow7((s) => s.state.ui.itemSelector));
7193
+ const id = useAppStore((s) => {
7194
+ var _a;
7195
+ return (_a = s.selectedItem) == null ? void 0 : _a.props.id;
7196
+ });
7197
+ const appStore = useAppStoreApi();
7198
+ useRegisterFieldsSlice(appStore, id);
7199
+ const fieldsLoading = useAppStore((s) => s.fields.loading);
7200
+ const fieldNames = useAppStore(
7201
+ useShallow7((s) => {
7202
+ if (s.fields.id === id) {
7203
+ return Object.keys(s.fields.fields);
7204
+ }
7205
+ return [];
7206
+ })
7207
+ );
7208
+ const isLoading = fieldsLoading || componentResolving;
7209
+ const Wrapper = useMemo13(() => overrides.fields || DefaultFields, [overrides]);
7372
7210
  return /* @__PURE__ */ jsxs15(
7373
- "li",
7211
+ "form",
7374
7212
  {
7375
- className: getClassNameLayer({
7376
- isSelected,
7377
- isHovering,
7378
- containsZone,
7379
- childIsSelected
7380
- }),
7213
+ className: getClassName25({ wrapFields }),
7214
+ onSubmit: (e) => {
7215
+ e.preventDefault();
7216
+ },
7381
7217
  children: [
7382
- /* @__PURE__ */ jsx35("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ jsxs15(
7383
- "button",
7384
- {
7385
- type: "button",
7386
- className: getClassNameLayer("clickable"),
7387
- onClick: () => {
7388
- if (isSelected) {
7389
- setItemSelector(null);
7390
- return;
7391
- }
7392
- const frame = getFrame();
7393
- const el = frame == null ? void 0 : frame.querySelector(
7394
- `[data-puck-component="${itemId}"]`
7395
- );
7396
- if (!el) {
7397
- setItemSelector({
7398
- index,
7399
- zone: zoneCompound
7400
- });
7401
- return;
7402
- }
7403
- scrollIntoView(el);
7404
- onScrollEnd(frame, () => {
7405
- setItemSelector({
7406
- index,
7407
- zone: zoneCompound
7408
- });
7409
- });
7410
- },
7411
- onMouseEnter: (e) => {
7412
- e.stopPropagation();
7413
- zoneStore.setState({ hoveringComponent: itemId });
7414
- },
7415
- onMouseLeave: (e) => {
7416
- e.stopPropagation();
7417
- zoneStore.setState({ hoveringComponent: null });
7418
- },
7419
- children: [
7420
- containsZone && /* @__PURE__ */ jsx35(
7421
- "div",
7422
- {
7423
- className: getClassNameLayer("chevron"),
7424
- title: isSelected ? "Collapse" : "Expand",
7425
- children: /* @__PURE__ */ jsx35(ChevronDown, { size: "12" })
7426
- }
7427
- ),
7428
- /* @__PURE__ */ jsxs15("div", { className: getClassNameLayer("title"), children: [
7429
- /* @__PURE__ */ jsx35("div", { className: getClassNameLayer("icon"), children: nodeData.data.type === "Text" || nodeData.data.type === "Heading" ? /* @__PURE__ */ jsx35(Type, { size: "16" }) : /* @__PURE__ */ jsx35(LayoutGrid, { size: "16" }) }),
7430
- /* @__PURE__ */ jsx35("div", { className: getClassNameLayer("name"), children: label })
7431
- ] })
7432
- ]
7433
- }
7434
- ) }),
7435
- containsZone && zonesForItem.map((subzone) => /* @__PURE__ */ jsx35("div", { className: getClassNameLayer("zones"), children: /* @__PURE__ */ jsx35(LayerTree, { zoneCompound: subzone }) }, subzone))
7218
+ /* @__PURE__ */ jsx36(Wrapper, { isLoading, itemSelector, children: fieldNames.map((fieldName) => /* @__PURE__ */ jsx36(FieldsChildMemo, { fieldName }, fieldName)) }),
7219
+ isLoading && /* @__PURE__ */ jsx36("div", { className: getClassName25("loadingOverlay"), children: /* @__PURE__ */ jsx36("div", { className: getClassName25("loadingOverlayInner"), children: /* @__PURE__ */ jsx36(Loader, { size: 16 }) }) })
7436
7220
  ]
7437
7221
  }
7438
7222
  );
7439
7223
  };
7440
- var LayerTree = ({
7441
- label: _label,
7442
- zoneCompound
7443
- }) => {
7444
- const label = useAppStore((s) => {
7445
- var _a, _b, _c, _d;
7446
- if (_label) return _label;
7447
- if (zoneCompound === rootDroppableId) return;
7448
- const [componentId, slotId] = zoneCompound.split(":");
7449
- const componentType = (_a = s.state.indexes.nodes[componentId]) == null ? void 0 : _a.data.type;
7450
- const configForComponent = componentType && componentType !== rootAreaId ? s.config.components[componentType] : s.config.root;
7451
- return (_d = (_c = (_b = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _b[slotId]) == null ? void 0 : _c.label) != null ? _d : slotId;
7452
- });
7453
- const contentIds = useAppStore(
7454
- useShallow6(
7455
- (s) => {
7456
- var _a, _b;
7457
- return zoneCompound ? (_b = (_a = s.state.indexes.zones[zoneCompound]) == null ? void 0 : _a.contentIds) != null ? _b : [] : [];
7458
- }
7459
- )
7460
- );
7461
- return /* @__PURE__ */ jsxs15(Fragment11, { children: [
7462
- label && /* @__PURE__ */ jsxs15("div", { className: getClassName24("zoneTitle"), children: [
7463
- /* @__PURE__ */ jsx35("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ jsx35(Layers, { size: "16" }) }),
7464
- label
7465
- ] }),
7466
- /* @__PURE__ */ jsxs15("ul", { className: getClassName24(), children: [
7467
- contentIds.length === 0 && /* @__PURE__ */ jsx35("div", { className: getClassName24("helper"), children: "No items" }),
7468
- contentIds.map((itemId, i) => {
7469
- return /* @__PURE__ */ jsx35(
7470
- Layer,
7471
- {
7472
- index: i,
7473
- itemId,
7474
- zoneCompound
7475
- },
7476
- itemId
7477
- );
7478
- })
7479
- ] })
7480
- ] });
7481
- };
7482
-
7483
- // components/Puck/components/Outline/index.tsx
7484
- import { useMemo as useMemo14 } from "react";
7224
+ var Fields = memo3(FieldsInternal);
7485
7225
 
7486
- // lib/data/find-zones-for-area.ts
7226
+ // css-module:/home/runner/work/puck/puck/packages/core/plugins/fields/styles.module.css#css-module
7487
7227
  init_react_import();
7488
- var findZonesForArea = (state, area) => {
7489
- return Object.keys(state.indexes.zones).filter(
7490
- (zone) => zone.split(":")[0] === area
7491
- );
7492
- };
7228
+ var styles_module_default20 = { "FieldsPlugin": "_FieldsPlugin_nd930_1", "FieldsPlugin-header": "_FieldsPlugin-header_nd930_7" };
7493
7229
 
7494
- // components/Puck/components/Outline/index.tsx
7495
- import { useShallow as useShallow7 } from "zustand/react/shallow";
7496
- import { jsx as jsx36 } from "react/jsx-runtime";
7497
- var Outline = () => {
7498
- const outlineOverride = useAppStore((s) => s.overrides.outline);
7499
- const rootZones = useAppStore(
7500
- useShallow7((s) => findZonesForArea(s.state, "root"))
7501
- );
7502
- const Wrapper = useMemo14(() => outlineOverride || "div", [outlineOverride]);
7503
- return /* @__PURE__ */ jsx36(Wrapper, { children: rootZones.map((zoneCompound) => /* @__PURE__ */ jsx36(
7504
- LayerTree,
7505
- {
7506
- label: rootZones.length === 1 ? "" : zoneCompound.split(":")[1],
7507
- zoneCompound
7508
- },
7509
- zoneCompound
7510
- )) });
7511
- };
7230
+ // plugins/fields/index.tsx
7231
+ import { jsx as jsx37, jsxs as jsxs16 } from "react/jsx-runtime";
7232
+ var getClassName26 = get_class_name_factory_default("FieldsPlugin", styles_module_default20);
7233
+ var CurrentTitle = () => {
7234
+ const label = useAppStore((s) => {
7235
+ var _a, _b;
7236
+ const selectedItem = s.selectedItem;
7237
+ return selectedItem ? (_b = (_a = s.config.components[selectedItem.type]) == null ? void 0 : _a.label) != null ? _b : selectedItem.type : "Page";
7238
+ });
7239
+ return label;
7240
+ };
7241
+ var fieldsPlugin = ({ mobileOnly = true } = {}) => ({
7242
+ name: "fields",
7243
+ label: "Fields",
7244
+ render: () => /* @__PURE__ */ jsxs16("div", { className: getClassName26(), children: [
7245
+ /* @__PURE__ */ jsx37("div", { className: getClassName26("header"), children: /* @__PURE__ */ jsx37(Breadcrumbs, { numParents: 2, children: /* @__PURE__ */ jsx37(CurrentTitle, {}) }) }),
7246
+ /* @__PURE__ */ jsx37(Fields, {})
7247
+ ] }),
7248
+ icon: /* @__PURE__ */ jsx37(RectangleEllipsis, {}),
7249
+ mobileOnly
7250
+ });
7512
7251
 
7513
- // components/Puck/components/Canvas/index.tsx
7252
+ // components/Puck/index.tsx
7514
7253
  init_react_import();
7515
7254
  import {
7516
- useCallback as useCallback15,
7517
- useEffect as useEffect25,
7518
- useMemo as useMemo17,
7519
- useRef as useRef9,
7520
- useState as useState21
7255
+ createContext as createContext8,
7256
+ useCallback as useCallback21,
7257
+ useContext as useContext13,
7258
+ useEffect as useEffect30,
7259
+ useMemo as useMemo21,
7260
+ useRef as useRef12,
7261
+ useState as useState26
7521
7262
  } from "react";
7522
7263
 
7523
- // components/ViewportControls/index.tsx
7264
+ // components/Puck/components/Preview/index.tsx
7524
7265
  init_react_import();
7525
- import { useEffect as useEffect24, useMemo as useMemo15, useState as useState20 } from "react";
7266
+ import { useCallback as useCallback14, useEffect as useEffect23, useRef as useRef7, useMemo as useMemo14 } from "react";
7526
7267
 
7527
- // css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
7268
+ // components/AutoFrame/index.tsx
7528
7269
  init_react_import();
7529
- var styles_module_default20 = { "ViewportControls": "_ViewportControls_gejzr_1", "ViewportControls-divider": "_ViewportControls-divider_gejzr_15", "ViewportControls-zoomSelect": "_ViewportControls-zoomSelect_gejzr_21", "ViewportButton--isActive": "_ViewportButton--isActive_gejzr_38", "ViewportButton-inner": "_ViewportButton-inner_gejzr_38" };
7530
-
7531
- // components/ViewportControls/index.tsx
7532
- import { jsx as jsx37, jsxs as jsxs16 } from "react/jsx-runtime";
7533
- var icons = {
7534
- Smartphone: /* @__PURE__ */ jsx37(Smartphone, { size: 16 }),
7535
- Tablet: /* @__PURE__ */ jsx37(Tablet, { size: 16 }),
7536
- Monitor: /* @__PURE__ */ jsx37(Monitor, { size: 16 })
7270
+ import {
7271
+ createContext as createContext6,
7272
+ useContext as useContext11,
7273
+ useEffect as useEffect22,
7274
+ useState as useState19
7275
+ } from "react";
7276
+ import hash from "object-hash";
7277
+ import { createPortal as createPortal3 } from "react-dom";
7278
+ import { Fragment as Fragment10, jsx as jsx38 } from "react/jsx-runtime";
7279
+ var styleSelector = 'style, link[rel="stylesheet"]';
7280
+ var collectStyles = (doc) => {
7281
+ const collected = [];
7282
+ doc.querySelectorAll(styleSelector).forEach((style) => {
7283
+ if (style.tagName === "STYLE") {
7284
+ const hasContent = !!style.innerHTML.trim();
7285
+ if (hasContent) {
7286
+ collected.push(style);
7287
+ }
7288
+ } else {
7289
+ collected.push(style);
7290
+ }
7291
+ });
7292
+ return collected;
7537
7293
  };
7538
- var getClassName25 = get_class_name_factory_default("ViewportControls", styles_module_default20);
7539
- var getClassNameButton = get_class_name_factory_default("ViewportButton", styles_module_default20);
7540
- var ViewportButton = ({
7541
- children,
7542
- height = "auto",
7543
- title,
7544
- width,
7545
- onClick
7546
- }) => {
7547
- const viewports = useAppStore((s) => s.state.ui.viewports);
7548
- const [isActive, setIsActive] = useState20(false);
7549
- useEffect24(() => {
7550
- setIsActive(width === viewports.current.width);
7551
- }, [width, viewports.current.width]);
7552
- return /* @__PURE__ */ jsx37("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ jsx37(
7553
- IconButton,
7554
- {
7555
- type: "button",
7556
- title,
7557
- disabled: isActive,
7558
- onClick: (e) => {
7559
- e.stopPropagation();
7560
- onClick({ width, height });
7561
- },
7562
- children: /* @__PURE__ */ jsx37("span", { className: getClassNameButton("inner"), children })
7294
+ var getStyleSheet = (el) => {
7295
+ return Array.from(document.styleSheets).find((ss) => {
7296
+ const ownerNode = ss.ownerNode;
7297
+ return ownerNode.href === el.href;
7298
+ });
7299
+ };
7300
+ var getStyles = (styleSheet) => {
7301
+ if (styleSheet) {
7302
+ try {
7303
+ return [...Array.from(styleSheet.cssRules)].map((rule) => rule.cssText).join("");
7304
+ } catch (e) {
7305
+ console.warn(
7306
+ "Access to stylesheet %s is denied. Ignoring\u2026",
7307
+ styleSheet.href
7308
+ );
7563
7309
  }
7564
- ) });
7310
+ }
7311
+ return "";
7565
7312
  };
7566
- var defaultZoomOptions = [
7567
- { label: "25%", value: 0.25 },
7568
- { label: "50%", value: 0.5 },
7569
- { label: "75%", value: 0.75 },
7570
- { label: "100%", value: 1 },
7571
- { label: "125%", value: 1.25 },
7572
- { label: "150%", value: 1.5 },
7573
- { label: "200%", value: 2 }
7574
- ];
7575
- var ViewportControls = ({
7576
- autoZoom,
7577
- zoom,
7578
- onViewportChange,
7579
- onZoom
7313
+ var syncAttributes = (sourceElement, targetElement) => {
7314
+ const attributes = sourceElement.attributes;
7315
+ if ((attributes == null ? void 0 : attributes.length) > 0) {
7316
+ Array.from(attributes).forEach((attribute) => {
7317
+ targetElement.setAttribute(attribute.name, attribute.value);
7318
+ });
7319
+ }
7320
+ };
7321
+ var defer = (fn) => setTimeout(fn, 0);
7322
+ var CopyHostStyles = ({
7323
+ children,
7324
+ debug = false,
7325
+ onStylesLoaded = () => null
7580
7326
  }) => {
7581
- var _a, _b;
7582
- const viewports = useAppStore((s) => s.viewports);
7583
- const defaultsContainAutoZoom = defaultZoomOptions.find(
7584
- (option) => option.value === autoZoom
7585
- );
7586
- const zoomOptions = useMemo15(
7587
- () => [
7588
- ...defaultZoomOptions,
7589
- ...defaultsContainAutoZoom ? [] : [
7590
- {
7591
- value: autoZoom,
7592
- label: `${(autoZoom * 100).toFixed(0)}% (Auto)`
7327
+ const { document: doc, window: win } = useFrame();
7328
+ useEffect22(() => {
7329
+ if (!win || !doc) {
7330
+ return () => {
7331
+ };
7332
+ }
7333
+ let elements = [];
7334
+ const hashes = {};
7335
+ const lookupEl = (el) => elements.findIndex((elementMap) => elementMap.original === el);
7336
+ const mirrorEl = (el, inlineStyles = false) => __async(void 0, null, function* () {
7337
+ let mirror;
7338
+ if (el.nodeName === "LINK" && inlineStyles) {
7339
+ mirror = document.createElement("style");
7340
+ mirror.type = "text/css";
7341
+ let styleSheet = getStyleSheet(el);
7342
+ if (!styleSheet) {
7343
+ yield new Promise((resolve) => {
7344
+ const fn = () => {
7345
+ resolve();
7346
+ el.removeEventListener("load", fn);
7347
+ };
7348
+ el.addEventListener("load", fn);
7349
+ });
7350
+ styleSheet = getStyleSheet(el);
7593
7351
  }
7594
- ]
7595
- ].filter((a) => a.value <= autoZoom).sort((a, b) => a.value > b.value ? 1 : -1),
7596
- [autoZoom]
7597
- );
7598
- return /* @__PURE__ */ jsxs16("div", { className: getClassName25(), children: [
7599
- viewports.map((viewport, i) => /* @__PURE__ */ jsx37(
7600
- ViewportButton,
7601
- {
7602
- height: viewport.height,
7603
- width: viewport.width,
7604
- title: viewport.label ? `Switch to ${viewport.label} viewport` : "Switch viewport",
7605
- onClick: onViewportChange,
7606
- children: typeof viewport.icon === "string" ? icons[viewport.icon] || viewport.icon : viewport.icon || icons.Smartphone
7607
- },
7608
- i
7609
- )),
7610
- /* @__PURE__ */ jsx37("div", { className: getClassName25("divider") }),
7611
- /* @__PURE__ */ jsx37(
7612
- IconButton,
7613
- {
7614
- type: "button",
7615
- title: "Zoom viewport out",
7616
- disabled: zoom <= ((_a = zoomOptions[0]) == null ? void 0 : _a.value),
7617
- onClick: (e) => {
7618
- e.stopPropagation();
7619
- onZoom(
7620
- zoomOptions[Math.max(
7621
- zoomOptions.findIndex((option) => option.value === zoom) - 1,
7622
- 0
7623
- )].value
7352
+ const styles2 = getStyles(styleSheet);
7353
+ if (!styles2) {
7354
+ if (debug) {
7355
+ console.warn(
7356
+ `Tried to load styles for link element, but couldn't find them. Skipping...`
7357
+ );
7358
+ }
7359
+ return;
7360
+ }
7361
+ mirror.innerHTML = styles2;
7362
+ mirror.setAttribute("data-href", el.getAttribute("href"));
7363
+ } else {
7364
+ mirror = el.cloneNode(true);
7365
+ }
7366
+ return mirror;
7367
+ });
7368
+ const addEl = (el) => __async(void 0, null, function* () {
7369
+ const index = lookupEl(el);
7370
+ if (index > -1) {
7371
+ if (debug)
7372
+ console.log(
7373
+ `Tried to add an element that was already mirrored. Updating instead...`
7624
7374
  );
7625
- },
7626
- children: /* @__PURE__ */ jsx37(ZoomOut, { size: 16 })
7375
+ elements[index].mirror.innerText = el.innerText;
7376
+ return;
7627
7377
  }
7628
- ),
7629
- /* @__PURE__ */ jsx37(
7630
- IconButton,
7631
- {
7632
- type: "button",
7633
- title: "Zoom viewport in",
7634
- disabled: zoom >= ((_b = zoomOptions[zoomOptions.length - 1]) == null ? void 0 : _b.value),
7635
- onClick: (e) => {
7636
- e.stopPropagation();
7637
- onZoom(
7638
- zoomOptions[Math.min(
7639
- zoomOptions.findIndex((option) => option.value === zoom) + 1,
7640
- zoomOptions.length - 1
7641
- )].value
7378
+ const mirror = yield mirrorEl(el);
7379
+ if (!mirror) {
7380
+ return;
7381
+ }
7382
+ const elHash = hash(mirror.outerHTML);
7383
+ if (hashes[elHash]) {
7384
+ if (debug)
7385
+ console.log(
7386
+ `iframe already contains element that is being mirrored. Skipping...`
7642
7387
  );
7643
- },
7644
- children: /* @__PURE__ */ jsx37(ZoomIn, { size: 16 })
7388
+ return;
7645
7389
  }
7646
- ),
7647
- /* @__PURE__ */ jsx37("div", { className: getClassName25("divider") }),
7648
- /* @__PURE__ */ jsx37(
7649
- "select",
7650
- {
7651
- className: getClassName25("zoomSelect"),
7652
- value: zoom.toString(),
7653
- onClick: (e) => {
7654
- e.stopPropagation();
7655
- },
7656
- onChange: (e) => {
7657
- onZoom(parseFloat(e.currentTarget.value));
7658
- },
7659
- children: zoomOptions.map((option) => /* @__PURE__ */ jsx37(
7660
- "option",
7661
- {
7662
- value: option.value,
7663
- label: option.label
7664
- },
7665
- option.label
7666
- ))
7390
+ hashes[elHash] = true;
7391
+ doc.head.append(mirror);
7392
+ elements.push({ original: el, mirror });
7393
+ if (debug) console.log(`Added style node ${el.outerHTML}`);
7394
+ });
7395
+ const removeEl = (el) => {
7396
+ var _a, _b;
7397
+ const index = lookupEl(el);
7398
+ if (index === -1) {
7399
+ if (debug)
7400
+ console.log(
7401
+ `Tried to remove an element that did not exist. Skipping...`
7402
+ );
7403
+ return;
7667
7404
  }
7668
- )
7669
- ] });
7405
+ const elHash = hash(el.outerHTML);
7406
+ (_b = (_a = elements[index]) == null ? void 0 : _a.mirror) == null ? void 0 : _b.remove();
7407
+ delete hashes[elHash];
7408
+ if (debug) console.log(`Removed style node ${el.outerHTML}`);
7409
+ };
7410
+ const observer = new MutationObserver((mutations) => {
7411
+ mutations.forEach((mutation) => {
7412
+ if (mutation.type === "childList") {
7413
+ mutation.addedNodes.forEach((node) => {
7414
+ if (node.nodeType === Node.TEXT_NODE || node.nodeType === Node.ELEMENT_NODE) {
7415
+ const el = node.nodeType === Node.TEXT_NODE ? node.parentElement : node;
7416
+ if (el && el.matches(styleSelector)) {
7417
+ defer(() => addEl(el));
7418
+ }
7419
+ }
7420
+ });
7421
+ mutation.removedNodes.forEach((node) => {
7422
+ if (node.nodeType === Node.TEXT_NODE || node.nodeType === Node.ELEMENT_NODE) {
7423
+ const el = node.nodeType === Node.TEXT_NODE ? node.parentElement : node;
7424
+ if (el && el.matches(styleSelector)) {
7425
+ defer(() => removeEl(el));
7426
+ }
7427
+ }
7428
+ });
7429
+ }
7430
+ });
7431
+ });
7432
+ const parentDocument = win.parent.document;
7433
+ const collectedStyles = collectStyles(parentDocument);
7434
+ const hrefs = [];
7435
+ let stylesLoaded = 0;
7436
+ const parentHtml = parentDocument.getElementsByTagName("html")[0];
7437
+ syncAttributes(parentHtml, doc.documentElement);
7438
+ const parentBody = parentDocument.getElementsByTagName("body")[0];
7439
+ syncAttributes(parentBody, doc.body);
7440
+ Promise.all(
7441
+ collectedStyles.map((styleNode, i) => __async(void 0, null, function* () {
7442
+ if (styleNode.nodeName === "LINK") {
7443
+ const linkHref = styleNode.href;
7444
+ if (hrefs.indexOf(linkHref) > -1) {
7445
+ return;
7446
+ }
7447
+ hrefs.push(linkHref);
7448
+ }
7449
+ const mirror = yield mirrorEl(styleNode);
7450
+ if (!mirror) return;
7451
+ elements.push({ original: styleNode, mirror });
7452
+ return mirror;
7453
+ }))
7454
+ ).then((mirrorStyles) => {
7455
+ const filtered = mirrorStyles.filter(
7456
+ (el) => typeof el !== "undefined"
7457
+ );
7458
+ filtered.forEach((mirror) => {
7459
+ mirror.onload = () => {
7460
+ stylesLoaded = stylesLoaded + 1;
7461
+ if (stylesLoaded >= elements.length) {
7462
+ onStylesLoaded();
7463
+ }
7464
+ };
7465
+ mirror.onerror = () => {
7466
+ console.warn(`AutoFrame couldn't load a stylesheet`);
7467
+ stylesLoaded = stylesLoaded + 1;
7468
+ if (stylesLoaded >= elements.length) {
7469
+ onStylesLoaded();
7470
+ }
7471
+ };
7472
+ });
7473
+ doc.head.innerHTML = "";
7474
+ doc.head.append(...filtered);
7475
+ observer.observe(parentDocument.head, { childList: true, subtree: true });
7476
+ filtered.forEach((el) => {
7477
+ const elHash = hash(el.outerHTML);
7478
+ hashes[elHash] = true;
7479
+ });
7480
+ });
7481
+ return () => {
7482
+ observer.disconnect();
7483
+ };
7484
+ }, []);
7485
+ return /* @__PURE__ */ jsx38(Fragment10, { children });
7670
7486
  };
7487
+ var autoFrameContext = createContext6({});
7488
+ var useFrame = () => useContext11(autoFrameContext);
7489
+ function AutoFrame(_a) {
7490
+ var _b = _a, {
7491
+ children,
7492
+ className,
7493
+ debug,
7494
+ id,
7495
+ onReady = () => {
7496
+ },
7497
+ onNotReady = () => {
7498
+ },
7499
+ frameRef
7500
+ } = _b, props = __objRest(_b, [
7501
+ "children",
7502
+ "className",
7503
+ "debug",
7504
+ "id",
7505
+ "onReady",
7506
+ "onNotReady",
7507
+ "frameRef"
7508
+ ]);
7509
+ const [loaded, setLoaded] = useState19(false);
7510
+ const [ctx, setCtx] = useState19({});
7511
+ const [mountTarget, setMountTarget] = useState19();
7512
+ const [stylesLoaded, setStylesLoaded] = useState19(false);
7513
+ useEffect22(() => {
7514
+ var _a2;
7515
+ if (frameRef.current) {
7516
+ const doc = frameRef.current.contentDocument;
7517
+ const win = frameRef.current.contentWindow;
7518
+ setCtx({
7519
+ document: doc || void 0,
7520
+ window: win || void 0
7521
+ });
7522
+ setMountTarget(
7523
+ (_a2 = frameRef.current.contentDocument) == null ? void 0 : _a2.getElementById("frame-root")
7524
+ );
7525
+ if (doc && win && stylesLoaded) {
7526
+ onReady();
7527
+ } else {
7528
+ onNotReady();
7529
+ }
7530
+ }
7531
+ }, [frameRef, loaded, stylesLoaded]);
7532
+ return /* @__PURE__ */ jsx38(
7533
+ "iframe",
7534
+ __spreadProps(__spreadValues({}, props), {
7535
+ className,
7536
+ id,
7537
+ srcDoc: '<!DOCTYPE html><html><head></head><body><div id="frame-root" data-puck-entry></div></body></html>',
7538
+ ref: frameRef,
7539
+ onLoad: () => {
7540
+ setLoaded(true);
7541
+ },
7542
+ children: /* @__PURE__ */ jsx38(autoFrameContext.Provider, { value: ctx, children: loaded && mountTarget && /* @__PURE__ */ jsx38(
7543
+ CopyHostStyles,
7544
+ {
7545
+ debug,
7546
+ onStylesLoaded: () => setStylesLoaded(true),
7547
+ children: createPortal3(children, mountTarget)
7548
+ }
7549
+ ) })
7550
+ })
7551
+ );
7552
+ }
7553
+ AutoFrame.displayName = "AutoFrame";
7554
+ var AutoFrame_default = AutoFrame;
7671
7555
 
7672
- // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Canvas/styles.module.css#css-module
7556
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Preview/styles.module.css#css-module
7673
7557
  init_react_import();
7674
- var styles_module_default21 = { "PuckCanvas": "_PuckCanvas_18jay_1", "PuckCanvas-controls": "_PuckCanvas-controls_18jay_16", "PuckCanvas-inner": "_PuckCanvas-inner_18jay_21", "PuckCanvas-root": "_PuckCanvas-root_18jay_30", "PuckCanvas--ready": "_PuckCanvas--ready_18jay_55", "PuckCanvas-loader": "_PuckCanvas-loader_18jay_60", "PuckCanvas--showLoader": "_PuckCanvas--showLoader_18jay_70" };
7558
+ var styles_module_default21 = { "PuckPreview": "_PuckPreview_z2rgu_1", "PuckPreview-frame": "_PuckPreview-frame_z2rgu_6" };
7675
7559
 
7676
- // components/Puck/components/Canvas/index.tsx
7677
- import { useShallow as useShallow8 } from "zustand/react/shallow";
7678
-
7679
- // lib/frame-context.tsx
7680
- init_react_import();
7681
- import {
7682
- createContext as createContext7,
7683
- useContext as useContext12,
7684
- useRef as useRef8,
7685
- useMemo as useMemo16
7686
- } from "react";
7687
- import { jsx as jsx38 } from "react/jsx-runtime";
7688
- var FrameContext = createContext7(null);
7689
- var FrameProvider = ({
7690
- children
7691
- }) => {
7692
- const frameRef = useRef8(null);
7693
- const value = useMemo16(
7694
- () => ({
7695
- frameRef
7696
- }),
7697
- []
7698
- );
7699
- return /* @__PURE__ */ jsx38(FrameContext.Provider, { value, children });
7700
- };
7701
- var useCanvasFrame = () => {
7702
- const context = useContext12(FrameContext);
7703
- if (context === null) {
7704
- throw new Error("useCanvasFrame must be used within a FrameProvider");
7705
- }
7706
- return context;
7560
+ // components/Puck/components/Preview/index.tsx
7561
+ import { Fragment as Fragment11, jsx as jsx39 } from "react/jsx-runtime";
7562
+ var getClassName27 = get_class_name_factory_default("PuckPreview", styles_module_default21);
7563
+ var useBubbleIframeEvents = (ref) => {
7564
+ const status = useAppStore((s) => s.status);
7565
+ useEffect23(() => {
7566
+ if (ref.current && status === "READY") {
7567
+ const iframe = ref.current;
7568
+ const handlePointerMove = (event) => {
7569
+ const evt = new BubbledPointerEvent("pointermove", __spreadProps(__spreadValues({}, event), {
7570
+ bubbles: true,
7571
+ cancelable: false,
7572
+ clientX: event.clientX,
7573
+ clientY: event.clientY,
7574
+ originalTarget: event.target
7575
+ }));
7576
+ iframe.dispatchEvent(evt);
7577
+ };
7578
+ const register = () => {
7579
+ var _a;
7580
+ unregister();
7581
+ (_a = iframe.contentDocument) == null ? void 0 : _a.addEventListener(
7582
+ "pointermove",
7583
+ handlePointerMove,
7584
+ {
7585
+ capture: true
7586
+ }
7587
+ );
7588
+ };
7589
+ const unregister = () => {
7590
+ var _a;
7591
+ (_a = iframe.contentDocument) == null ? void 0 : _a.removeEventListener(
7592
+ "pointermove",
7593
+ handlePointerMove
7594
+ );
7595
+ };
7596
+ register();
7597
+ return () => {
7598
+ unregister();
7599
+ };
7600
+ }
7601
+ }, [status]);
7707
7602
  };
7708
-
7709
- // components/Puck/components/Canvas/index.tsx
7710
- import { Fragment as Fragment12, jsx as jsx39, jsxs as jsxs17 } from "react/jsx-runtime";
7711
- var getClassName26 = get_class_name_factory_default("PuckCanvas", styles_module_default21);
7712
- var ZOOM_ON_CHANGE = true;
7713
- var TRANSITION_DURATION = 150;
7714
- var Canvas = () => {
7715
- const { frameRef } = useCanvasFrame();
7716
- const resetAutoZoom = useResetAutoZoom(frameRef);
7717
- const {
7718
- dispatch,
7719
- overrides,
7720
- setUi,
7721
- zoomConfig,
7722
- setZoomConfig,
7723
- status,
7724
- iframe
7725
- } = useAppStore(
7726
- useShallow8((s) => ({
7727
- dispatch: s.dispatch,
7728
- overrides: s.overrides,
7729
- setUi: s.setUi,
7730
- zoomConfig: s.zoomConfig,
7731
- setZoomConfig: s.setZoomConfig,
7732
- status: s.status,
7733
- iframe: s.iframe
7734
- }))
7735
- );
7736
- const {
7737
- leftSideBarVisible,
7738
- rightSideBarVisible,
7739
- leftSideBarWidth,
7740
- rightSideBarWidth,
7741
- viewports
7742
- } = useAppStore(
7743
- useShallow8((s) => ({
7744
- leftSideBarVisible: s.state.ui.leftSideBarVisible,
7745
- rightSideBarVisible: s.state.ui.rightSideBarVisible,
7746
- leftSideBarWidth: s.state.ui.leftSideBarWidth,
7747
- rightSideBarWidth: s.state.ui.rightSideBarWidth,
7748
- viewports: s.state.ui.viewports
7749
- }))
7603
+ var Preview2 = ({ id = "puck-preview" }) => {
7604
+ const dispatch = useAppStore((s) => s.dispatch);
7605
+ const root = useAppStore((s) => s.state.data.root);
7606
+ const config = useAppStore((s) => s.config);
7607
+ const setStatus = useAppStore((s) => s.setStatus);
7608
+ const iframe = useAppStore((s) => s.iframe);
7609
+ const overrides = useAppStore((s) => s.overrides);
7610
+ const metadata = useAppStore((s) => s.metadata);
7611
+ const renderData = useAppStore(
7612
+ (s) => s.state.ui.previewMode === "edit" ? null : s.state.data
7750
7613
  );
7751
- const [showTransition, setShowTransition] = useState21(false);
7752
- const isResizingRef = useRef9(false);
7753
- const defaultRender = useMemo17(() => {
7754
- const PuckDefault = ({ children }) => /* @__PURE__ */ jsx39(Fragment12, { children });
7755
- return PuckDefault;
7756
- }, []);
7757
- const CustomPreview = useMemo17(
7758
- () => overrides.preview || defaultRender,
7759
- [overrides]
7614
+ const Page = useCallback14(
7615
+ (pageProps) => {
7616
+ var _a, _b;
7617
+ const propsWithSlots = useSlots(
7618
+ config,
7619
+ { type: "root", props: pageProps },
7620
+ DropZoneEditPure
7621
+ );
7622
+ return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
7623
+ id: "puck-root"
7624
+ }, propsWithSlots)) : /* @__PURE__ */ jsx39(Fragment11, { children: propsWithSlots.children });
7625
+ },
7626
+ [config]
7760
7627
  );
7761
- const getFrameDimensions = useCallback15(() => {
7762
- if (frameRef.current) {
7763
- const frame = frameRef.current;
7764
- const box = getBox(frame);
7765
- return { width: box.contentBox.width, height: box.contentBox.height };
7766
- }
7767
- return { width: 0, height: 0 };
7768
- }, [frameRef]);
7769
- useEffect25(() => {
7770
- resetAutoZoom();
7771
- }, [
7772
- frameRef,
7773
- leftSideBarVisible,
7774
- rightSideBarVisible,
7775
- leftSideBarWidth,
7776
- rightSideBarWidth,
7777
- viewports
7778
- ]);
7779
- useEffect25(() => {
7780
- const { height: frameHeight } = getFrameDimensions();
7781
- if (viewports.current.height === "auto") {
7782
- setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
7783
- rootHeight: frameHeight / zoomConfig.zoom
7784
- }));
7785
- }
7786
- }, [zoomConfig.zoom, getFrameDimensions, setZoomConfig]);
7787
- useEffect25(() => {
7788
- if (ZOOM_ON_CHANGE) {
7789
- resetAutoZoom();
7628
+ const Frame = useMemo14(() => overrides.iframe, [overrides]);
7629
+ const rootProps = root.props || root;
7630
+ const ref = useRef7(null);
7631
+ useBubbleIframeEvents(ref);
7632
+ const inner = !renderData ? /* @__PURE__ */ jsx39(
7633
+ Page,
7634
+ __spreadProps(__spreadValues({}, rootProps), {
7635
+ puck: {
7636
+ renderDropZone: DropZonePure,
7637
+ isEditing: true,
7638
+ dragRef: null,
7639
+ metadata
7640
+ },
7641
+ editMode: true,
7642
+ children: /* @__PURE__ */ jsx39(DropZonePure, { zone: rootDroppableId })
7643
+ })
7644
+ ) : /* @__PURE__ */ jsx39(Render, { data: renderData, config, metadata });
7645
+ useEffect23(() => {
7646
+ if (!iframe.enabled) {
7647
+ setStatus("READY");
7790
7648
  }
7791
- }, [viewports.current.width, viewports]);
7792
- useEffect25(() => {
7793
- if (!frameRef.current) return;
7794
- const resizeObserver = new ResizeObserver(() => {
7795
- if (!isResizingRef.current) {
7796
- resetAutoZoom();
7797
- }
7798
- });
7799
- resizeObserver.observe(frameRef.current);
7800
- return () => {
7801
- resizeObserver.disconnect();
7802
- };
7803
- }, [frameRef.current]);
7804
- const [showLoader, setShowLoader] = useState21(false);
7805
- useEffect25(() => {
7806
- setTimeout(() => {
7807
- setShowLoader(true);
7808
- }, 500);
7809
- }, []);
7810
- return /* @__PURE__ */ jsxs17(
7649
+ }, [iframe.enabled]);
7650
+ return /* @__PURE__ */ jsx39(
7811
7651
  "div",
7812
7652
  {
7813
- className: getClassName26({
7814
- ready: status === "READY" || !iframe.enabled || !iframe.waitForStyles,
7815
- showLoader
7816
- }),
7653
+ className: getClassName27(),
7654
+ id,
7655
+ "data-puck-preview": true,
7817
7656
  onClick: (e) => {
7818
7657
  const el = e.target;
7819
7658
  if (!el.hasAttribute("data-puck-component") && !el.hasAttribute("data-puck-dropzone")) {
7820
- dispatch({
7821
- type: "setUi",
7822
- ui: { itemSelector: null },
7823
- recordHistory: true
7824
- });
7659
+ dispatch({ type: "setUi", ui: { itemSelector: null } });
7825
7660
  }
7826
7661
  },
7827
- children: [
7828
- viewports.controlsVisible && iframe.enabled && /* @__PURE__ */ jsx39("div", { className: getClassName26("controls"), children: /* @__PURE__ */ jsx39(
7829
- ViewportControls,
7830
- {
7831
- autoZoom: zoomConfig.autoZoom,
7832
- zoom: zoomConfig.zoom,
7833
- onViewportChange: (viewport) => {
7834
- setShowTransition(true);
7835
- isResizingRef.current = true;
7836
- const uiViewport = __spreadProps(__spreadValues({}, viewport), {
7837
- height: viewport.height || "auto",
7838
- zoom: zoomConfig.zoom
7839
- });
7840
- const newUi = {
7841
- viewports: __spreadProps(__spreadValues({}, viewports), { current: uiViewport })
7842
- };
7843
- setUi(newUi);
7844
- if (ZOOM_ON_CHANGE) {
7845
- resetAutoZoom({
7846
- viewports: __spreadProps(__spreadValues({}, viewports), { current: uiViewport })
7847
- });
7848
- }
7849
- },
7850
- onZoom: (zoom) => {
7851
- setShowTransition(true);
7852
- isResizingRef.current = true;
7853
- setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), { zoom }));
7854
- }
7855
- }
7856
- ) }),
7857
- /* @__PURE__ */ jsxs17("div", { className: getClassName26("inner"), ref: frameRef, children: [
7858
- /* @__PURE__ */ jsx39(
7859
- "div",
7860
- {
7861
- className: getClassName26("root"),
7862
- style: {
7863
- width: iframe.enabled ? viewports.current.width : "100%",
7864
- height: zoomConfig.rootHeight,
7865
- transform: iframe.enabled ? `scale(${zoomConfig.zoom})` : void 0,
7866
- transition: showTransition ? `width ${TRANSITION_DURATION}ms ease-out, height ${TRANSITION_DURATION}ms ease-out, transform ${TRANSITION_DURATION}ms ease-out` : "",
7867
- overflow: iframe.enabled ? void 0 : "auto"
7868
- },
7869
- suppressHydrationWarning: true,
7870
- id: "puck-canvas-root",
7871
- onTransitionEnd: () => {
7872
- setShowTransition(false);
7873
- isResizingRef.current = false;
7874
- },
7875
- children: /* @__PURE__ */ jsx39(CustomPreview, { children: /* @__PURE__ */ jsx39(Preview2, {}) })
7662
+ children: iframe.enabled ? /* @__PURE__ */ jsx39(
7663
+ AutoFrame_default,
7664
+ {
7665
+ id: "preview-frame",
7666
+ className: getClassName27("frame"),
7667
+ "data-rfd-iframe": true,
7668
+ onReady: () => {
7669
+ setStatus("READY");
7670
+ },
7671
+ onNotReady: () => {
7672
+ setStatus("MOUNTED");
7673
+ },
7674
+ frameRef: ref,
7675
+ children: /* @__PURE__ */ jsx39(autoFrameContext.Consumer, { children: ({ document: document2 }) => {
7676
+ if (Frame) {
7677
+ return /* @__PURE__ */ jsx39(Frame, { document: document2, children: inner });
7876
7678
  }
7877
- ),
7878
- /* @__PURE__ */ jsx39("div", { className: getClassName26("loader"), children: /* @__PURE__ */ jsx39(Loader, { size: 24 }) })
7879
- ] })
7880
- ]
7679
+ return inner;
7680
+ } })
7681
+ }
7682
+ ) : /* @__PURE__ */ jsx39(
7683
+ "div",
7684
+ {
7685
+ id: "preview-frame",
7686
+ className: getClassName27("frame"),
7687
+ ref,
7688
+ "data-puck-entry": true,
7689
+ children: inner
7690
+ }
7691
+ )
7881
7692
  }
7882
7693
  );
7883
7694
  };
7884
7695
 
7885
7696
  // lib/use-loaded-overrides.ts
7886
7697
  init_react_import();
7887
- import { useMemo as useMemo18 } from "react";
7698
+ import { useMemo as useMemo15 } from "react";
7888
7699
 
7889
7700
  // lib/load-overrides.ts
7890
7701
  init_react_import();
@@ -7926,26 +7737,32 @@ var useLoadedOverrides = ({
7926
7737
  overrides,
7927
7738
  plugins
7928
7739
  }) => {
7929
- return useMemo18(() => {
7740
+ return useMemo15(() => {
7930
7741
  return loadOverrides({ overrides, plugins });
7931
7742
  }, [plugins, overrides]);
7932
7743
  };
7933
7744
 
7934
- // components/DefaultOverride/index.tsx
7745
+ // components/Puck/index.tsx
7746
+ var import_fast_deep_equal = __toESM(require_fast_deep_equal());
7747
+
7748
+ // components/Puck/components/Layout/index.tsx
7749
+ init_react_import();
7750
+ import { useEffect as useEffect29, useMemo as useMemo20, useState as useState25 } from "react";
7751
+
7752
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Layout/styles.module.css#css-module
7935
7753
  init_react_import();
7936
- import { Fragment as Fragment13, jsx as jsx40 } from "react/jsx-runtime";
7937
- var DefaultOverride = ({ children }) => /* @__PURE__ */ jsx40(Fragment13, { children });
7754
+ var styles_module_default22 = { "Puck": "_Puck_hv23j_19", "Puck-portal": "_Puck-portal_hv23j_31", "PuckLayout": "_PuckLayout_hv23j_36", "PuckLayout-inner": "_PuckLayout-inner_hv23j_40", "PuckLayout--mounted": "_PuckLayout--mounted_hv23j_73", "PuckLayout--mobilePanelHeightToggle": "_PuckLayout--mobilePanelHeightToggle_hv23j_77", "PuckLayout--leftSideBarVisible": "_PuckLayout--leftSideBarVisible_hv23j_77", "PuckLayout--isExpanded": "_PuckLayout--isExpanded_hv23j_83", "PuckLayout--mobilePanelHeightMinContent": "_PuckLayout--mobilePanelHeightMinContent_hv23j_101", "PuckLayout--rightSideBarVisible": "_PuckLayout--rightSideBarVisible_hv23j_128", "PuckLayout-mounted": "_PuckLayout-mounted_hv23j_147", "PuckLayout-nav": "_PuckLayout-nav_hv23j_188", "PuckLayout-header": "_PuckLayout-header_hv23j_204", "PuckPluginTab": "_PuckPluginTab_hv23j_218", "PuckPluginTab--visible": "_PuckPluginTab--visible_hv23j_224", "PuckPluginTab-body": "_PuckPluginTab-body_hv23j_229" };
7938
7755
 
7939
7756
  // lib/use-inject-css.ts
7940
7757
  init_react_import();
7941
- import { useEffect as useEffect26, useState as useState22 } from "react";
7758
+ import { useEffect as useEffect24, useState as useState20 } from "react";
7942
7759
  var styles = ``;
7943
7760
  var useInjectStyleSheet = (initialStyles, iframeEnabled) => {
7944
- const [el, setEl] = useState22();
7945
- useEffect26(() => {
7761
+ const [el, setEl] = useState20();
7762
+ useEffect24(() => {
7946
7763
  setEl(document.createElement("style"));
7947
7764
  }, []);
7948
- useEffect26(() => {
7765
+ useEffect24(() => {
7949
7766
  var _a;
7950
7767
  if (!el || typeof window === "undefined") {
7951
7768
  return;
@@ -7963,12 +7780,17 @@ var useInjectGlobalCss = (iframeEnabled) => {
7963
7780
  return useInjectStyleSheet(styles, iframeEnabled);
7964
7781
  };
7965
7782
 
7783
+ // components/DefaultOverride/index.tsx
7784
+ init_react_import();
7785
+ import { Fragment as Fragment12, jsx as jsx40 } from "react/jsx-runtime";
7786
+ var DefaultOverride = ({ children }) => /* @__PURE__ */ jsx40(Fragment12, { children });
7787
+
7966
7788
  // lib/use-preview-mode-hotkeys.ts
7967
7789
  init_react_import();
7968
- import { useCallback as useCallback16 } from "react";
7790
+ import { useCallback as useCallback15 } from "react";
7969
7791
  var usePreviewModeHotkeys = () => {
7970
7792
  const appStore = useAppStoreApi();
7971
- const toggleInteractive = useCallback16(() => {
7793
+ const toggleInteractive = useCallback15(() => {
7972
7794
  const dispatch = appStore.getState().dispatch;
7973
7795
  dispatch({
7974
7796
  type: "setUi",
@@ -7981,23 +7803,20 @@ var usePreviewModeHotkeys = () => {
7981
7803
  useHotkey({ ctrl: true, i: true }, toggleInteractive);
7982
7804
  };
7983
7805
 
7984
- // components/Puck/index.tsx
7985
- import fdeq from "fast-deep-equal";
7986
-
7987
7806
  // components/Puck/components/Header/index.tsx
7988
7807
  init_react_import();
7989
- import { memo as memo4, useCallback as useCallback17, useMemo as useMemo19, useState as useState23 } from "react";
7808
+ import { memo as memo4, useCallback as useCallback16, useMemo as useMemo16, useState as useState21 } from "react";
7990
7809
 
7991
7810
  // components/MenuBar/index.tsx
7992
7811
  init_react_import();
7993
7812
 
7994
7813
  // css-module:/home/runner/work/puck/puck/packages/core/components/MenuBar/styles.module.css#css-module
7995
7814
  init_react_import();
7996
- var styles_module_default22 = { "MenuBar": "_MenuBar_8pf8c_1", "MenuBar--menuOpen": "_MenuBar--menuOpen_8pf8c_14", "MenuBar-inner": "_MenuBar-inner_8pf8c_29", "MenuBar-history": "_MenuBar-history_8pf8c_45" };
7815
+ var styles_module_default23 = { "MenuBar": "_MenuBar_8pf8c_1", "MenuBar--menuOpen": "_MenuBar--menuOpen_8pf8c_14", "MenuBar-inner": "_MenuBar-inner_8pf8c_29", "MenuBar-history": "_MenuBar-history_8pf8c_45" };
7997
7816
 
7998
7817
  // components/MenuBar/index.tsx
7999
- import { Fragment as Fragment14, jsx as jsx41, jsxs as jsxs18 } from "react/jsx-runtime";
8000
- var getClassName27 = get_class_name_factory_default("MenuBar", styles_module_default22);
7818
+ import { Fragment as Fragment13, jsx as jsx41, jsxs as jsxs17 } from "react/jsx-runtime";
7819
+ var getClassName28 = get_class_name_factory_default("MenuBar", styles_module_default23);
8001
7820
  function MenuBar({
8002
7821
  menuOpen = false,
8003
7822
  renderHeaderActions,
@@ -8010,7 +7829,7 @@ function MenuBar({
8010
7829
  return /* @__PURE__ */ jsx41(
8011
7830
  "div",
8012
7831
  {
8013
- className: getClassName27({ menuOpen }),
7832
+ className: getClassName28({ menuOpen }),
8014
7833
  onClick: (event) => {
8015
7834
  var _a;
8016
7835
  const element = event.target;
@@ -8021,8 +7840,8 @@ function MenuBar({
8021
7840
  setMenuOpen(false);
8022
7841
  }
8023
7842
  },
8024
- children: /* @__PURE__ */ jsxs18("div", { className: getClassName27("inner"), children: [
8025
- /* @__PURE__ */ jsxs18("div", { className: getClassName27("history"), children: [
7843
+ children: /* @__PURE__ */ jsxs17("div", { className: getClassName28("inner"), children: [
7844
+ /* @__PURE__ */ jsxs17("div", { className: getClassName28("history"), children: [
8026
7845
  /* @__PURE__ */ jsx41(
8027
7846
  IconButton,
8028
7847
  {
@@ -8044,7 +7863,7 @@ function MenuBar({
8044
7863
  }
8045
7864
  )
8046
7865
  ] }),
8047
- /* @__PURE__ */ jsx41(Fragment14, { children: renderHeaderActions && renderHeaderActions() })
7866
+ /* @__PURE__ */ jsx41(Fragment13, { children: renderHeaderActions && renderHeaderActions() })
8048
7867
  ] })
8049
7868
  }
8050
7869
  );
@@ -8052,11 +7871,11 @@ function MenuBar({
8052
7871
 
8053
7872
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Header/styles.module.css#css-module
8054
7873
  init_react_import();
8055
- var styles_module_default23 = { "PuckHeader": "_PuckHeader_15xnq_1", "PuckHeader-inner": "_PuckHeader-inner_15xnq_10", "PuckHeader-toggle": "_PuckHeader-toggle_15xnq_20", "PuckHeader--rightSideBarVisible": "_PuckHeader--rightSideBarVisible_15xnq_27", "PuckHeader-rightSideBarToggle": "_PuckHeader-rightSideBarToggle_15xnq_27", "PuckHeader--leftSideBarVisible": "_PuckHeader--leftSideBarVisible_15xnq_28", "PuckHeader-leftSideBarToggle": "_PuckHeader-leftSideBarToggle_15xnq_28", "PuckHeader-title": "_PuckHeader-title_15xnq_32", "PuckHeader-path": "_PuckHeader-path_15xnq_36", "PuckHeader-tools": "_PuckHeader-tools_15xnq_43", "PuckHeader-menuButton": "_PuckHeader-menuButton_15xnq_49", "PuckHeader--menuOpen": "_PuckHeader--menuOpen_15xnq_54" };
7874
+ var styles_module_default24 = { "PuckHeader": "_PuckHeader_1bhmt_1", "PuckHeader-inner": "_PuckHeader-inner_1bhmt_16", "PuckHeader-toggle": "_PuckHeader-toggle_1bhmt_32", "PuckHeader--rightSideBarVisible": "_PuckHeader--rightSideBarVisible_1bhmt_39", "PuckHeader-rightSideBarToggle": "_PuckHeader-rightSideBarToggle_1bhmt_39", "PuckHeader--leftSideBarVisible": "_PuckHeader--leftSideBarVisible_1bhmt_40", "PuckHeader-leftSideBarToggle": "_PuckHeader-leftSideBarToggle_1bhmt_40", "PuckHeader-title": "_PuckHeader-title_1bhmt_56", "PuckHeader-path": "_PuckHeader-path_1bhmt_60", "PuckHeader-tools": "_PuckHeader-tools_1bhmt_67", "PuckHeader-menuButton": "_PuckHeader-menuButton_1bhmt_73", "PuckHeader--menuOpen": "_PuckHeader--menuOpen_1bhmt_78" };
8056
7875
 
8057
7876
  // components/Puck/components/Header/index.tsx
8058
- import { Fragment as Fragment15, jsx as jsx42, jsxs as jsxs19 } from "react/jsx-runtime";
8059
- var getClassName28 = get_class_name_factory_default("PuckHeader", styles_module_default23);
7877
+ import { Fragment as Fragment14, jsx as jsx42, jsxs as jsxs18 } from "react/jsx-runtime";
7878
+ var getClassName29 = get_class_name_factory_default("PuckHeader", styles_module_default24);
8060
7879
  var HeaderInner = () => {
8061
7880
  const {
8062
7881
  onPublish,
@@ -8068,7 +7887,7 @@ var HeaderInner = () => {
8068
7887
  } = usePropsContext();
8069
7888
  const dispatch = useAppStore((s) => s.dispatch);
8070
7889
  const appStore = useAppStoreApi();
8071
- const defaultHeaderRender = useMemo19(() => {
7890
+ const defaultHeaderRender = useMemo16(() => {
8072
7891
  if (renderHeader) {
8073
7892
  console.warn(
8074
7893
  "`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
@@ -8083,7 +7902,7 @@ var HeaderInner = () => {
8083
7902
  }
8084
7903
  return DefaultOverride;
8085
7904
  }, [renderHeader]);
8086
- const defaultHeaderActionsRender = useMemo19(() => {
7905
+ const defaultHeaderActionsRender = useMemo16(() => {
8087
7906
  if (renderHeaderActions) {
8088
7907
  console.warn(
8089
7908
  "`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
@@ -8100,138 +7919,653 @@ var HeaderInner = () => {
8100
7919
  const CustomHeader = useAppStore(
8101
7920
  (s) => s.overrides.header || defaultHeaderRender
8102
7921
  );
8103
- const CustomHeaderActions = useAppStore(
8104
- (s) => s.overrides.headerActions || defaultHeaderActionsRender
7922
+ const CustomHeaderActions = useAppStore(
7923
+ (s) => s.overrides.headerActions || defaultHeaderActionsRender
7924
+ );
7925
+ const [menuOpen, setMenuOpen] = useState21(false);
7926
+ const rootTitle = useAppStore((s) => {
7927
+ var _a, _b;
7928
+ const rootData = (_a = s.state.indexes.nodes["root"]) == null ? void 0 : _a.data;
7929
+ return (_b = rootData.props.title) != null ? _b : "";
7930
+ });
7931
+ const leftSideBarVisible = useAppStore((s) => s.state.ui.leftSideBarVisible);
7932
+ const rightSideBarVisible = useAppStore(
7933
+ (s) => s.state.ui.rightSideBarVisible
7934
+ );
7935
+ const toggleSidebars = useCallback16(
7936
+ (sidebar) => {
7937
+ const widerViewport = window.matchMedia("(min-width: 638px)").matches;
7938
+ const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
7939
+ const oppositeSideBar = sidebar === "left" ? "rightSideBarVisible" : "leftSideBarVisible";
7940
+ dispatch({
7941
+ type: "setUi",
7942
+ ui: __spreadValues({
7943
+ [`${sidebar}SideBarVisible`]: !sideBarVisible
7944
+ }, !widerViewport ? { [oppositeSideBar]: false } : {})
7945
+ });
7946
+ },
7947
+ [dispatch, leftSideBarVisible, rightSideBarVisible]
7948
+ );
7949
+ return /* @__PURE__ */ jsx42(
7950
+ CustomHeader,
7951
+ {
7952
+ actions: /* @__PURE__ */ jsx42(Fragment14, { children: /* @__PURE__ */ jsx42(CustomHeaderActions, { children: /* @__PURE__ */ jsx42(
7953
+ Button,
7954
+ {
7955
+ onClick: () => {
7956
+ const data = appStore.getState().state.data;
7957
+ onPublish && onPublish(data);
7958
+ },
7959
+ icon: /* @__PURE__ */ jsx42(Globe, { size: "14px" }),
7960
+ children: "Publish"
7961
+ }
7962
+ ) }) }),
7963
+ children: /* @__PURE__ */ jsx42(
7964
+ "header",
7965
+ {
7966
+ className: getClassName29({ leftSideBarVisible, rightSideBarVisible }),
7967
+ children: /* @__PURE__ */ jsxs18("div", { className: getClassName29("inner"), children: [
7968
+ /* @__PURE__ */ jsxs18("div", { className: getClassName29("toggle"), children: [
7969
+ /* @__PURE__ */ jsx42("div", { className: getClassName29("leftSideBarToggle"), children: /* @__PURE__ */ jsx42(
7970
+ IconButton,
7971
+ {
7972
+ type: "button",
7973
+ onClick: () => {
7974
+ toggleSidebars("left");
7975
+ },
7976
+ title: "Toggle left sidebar",
7977
+ children: /* @__PURE__ */ jsx42(PanelLeft, { focusable: "false" })
7978
+ }
7979
+ ) }),
7980
+ /* @__PURE__ */ jsx42("div", { className: getClassName29("rightSideBarToggle"), children: /* @__PURE__ */ jsx42(
7981
+ IconButton,
7982
+ {
7983
+ type: "button",
7984
+ onClick: () => {
7985
+ toggleSidebars("right");
7986
+ },
7987
+ title: "Toggle right sidebar",
7988
+ children: /* @__PURE__ */ jsx42(PanelRight, { focusable: "false" })
7989
+ }
7990
+ ) })
7991
+ ] }),
7992
+ /* @__PURE__ */ jsx42("div", { className: getClassName29("title"), children: /* @__PURE__ */ jsxs18(Heading, { rank: "2", size: "xs", children: [
7993
+ headerTitle || rootTitle || "Page",
7994
+ headerPath && /* @__PURE__ */ jsxs18(Fragment14, { children: [
7995
+ " ",
7996
+ /* @__PURE__ */ jsx42("code", { className: getClassName29("path"), children: headerPath })
7997
+ ] })
7998
+ ] }) }),
7999
+ /* @__PURE__ */ jsxs18("div", { className: getClassName29("tools"), children: [
8000
+ /* @__PURE__ */ jsx42("div", { className: getClassName29("menuButton"), children: /* @__PURE__ */ jsx42(
8001
+ IconButton,
8002
+ {
8003
+ type: "button",
8004
+ onClick: () => {
8005
+ return setMenuOpen(!menuOpen);
8006
+ },
8007
+ title: "Toggle menu bar",
8008
+ children: menuOpen ? /* @__PURE__ */ jsx42(ChevronUp, { focusable: "false" }) : /* @__PURE__ */ jsx42(ChevronDown, { focusable: "false" })
8009
+ }
8010
+ ) }),
8011
+ /* @__PURE__ */ jsx42(
8012
+ MenuBar,
8013
+ {
8014
+ dispatch,
8015
+ onPublish,
8016
+ menuOpen,
8017
+ renderHeaderActions: () => /* @__PURE__ */ jsx42(CustomHeaderActions, { children: /* @__PURE__ */ jsx42(
8018
+ Button,
8019
+ {
8020
+ onClick: () => {
8021
+ const data = appStore.getState().state.data;
8022
+ onPublish && onPublish(data);
8023
+ },
8024
+ icon: /* @__PURE__ */ jsx42(Globe, { size: "14px" }),
8025
+ children: "Publish"
8026
+ }
8027
+ ) }),
8028
+ setMenuOpen
8029
+ }
8030
+ )
8031
+ ] })
8032
+ ] })
8033
+ }
8034
+ )
8035
+ }
8036
+ );
8037
+ };
8038
+ var Header = memo4(HeaderInner);
8039
+
8040
+ // components/SidebarSection/index.tsx
8041
+ init_react_import();
8042
+
8043
+ // css-module:/home/runner/work/puck/puck/packages/core/components/SidebarSection/styles.module.css#css-module
8044
+ init_react_import();
8045
+ var styles_module_default25 = { "SidebarSection": "_SidebarSection_8boj8_1", "SidebarSection-title": "_SidebarSection-title_8boj8_12", "SidebarSection--noBorderTop": "_SidebarSection--noBorderTop_8boj8_20", "SidebarSection-content": "_SidebarSection-content_8boj8_24", "SidebarSection--noPadding": "_SidebarSection--noPadding_8boj8_28", "SidebarSection-breadcrumbLabel": "_SidebarSection-breadcrumbLabel_8boj8_41", "SidebarSection-breadcrumbs": "_SidebarSection-breadcrumbs_8boj8_70", "SidebarSection-breadcrumb": "_SidebarSection-breadcrumb_8boj8_41", "SidebarSection-heading": "_SidebarSection-heading_8boj8_82", "SidebarSection-loadingOverlay": "_SidebarSection-loadingOverlay_8boj8_86" };
8046
+
8047
+ // components/SidebarSection/index.tsx
8048
+ import { jsx as jsx43, jsxs as jsxs19 } from "react/jsx-runtime";
8049
+ var getClassName30 = get_class_name_factory_default("SidebarSection", styles_module_default25);
8050
+ var SidebarSection = ({
8051
+ children,
8052
+ title,
8053
+ background,
8054
+ showBreadcrumbs,
8055
+ noBorderTop,
8056
+ noPadding,
8057
+ isLoading
8058
+ }) => {
8059
+ return /* @__PURE__ */ jsxs19(
8060
+ "div",
8061
+ {
8062
+ className: getClassName30({ noBorderTop, noPadding }),
8063
+ style: { background },
8064
+ children: [
8065
+ /* @__PURE__ */ jsx43("div", { className: getClassName30("title"), children: /* @__PURE__ */ jsxs19("div", { className: getClassName30("breadcrumbs"), children: [
8066
+ showBreadcrumbs && /* @__PURE__ */ jsx43(Breadcrumbs, {}),
8067
+ /* @__PURE__ */ jsx43("div", { className: getClassName30("heading"), children: /* @__PURE__ */ jsx43(Heading, { rank: "2", size: "xs", children: title }) })
8068
+ ] }) }),
8069
+ /* @__PURE__ */ jsx43("div", { className: getClassName30("content"), children }),
8070
+ isLoading && /* @__PURE__ */ jsx43("div", { className: getClassName30("loadingOverlay"), children: /* @__PURE__ */ jsx43(Loader, { size: 32 }) })
8071
+ ]
8072
+ }
8073
+ );
8074
+ };
8075
+
8076
+ // components/Puck/components/Canvas/index.tsx
8077
+ init_react_import();
8078
+ import {
8079
+ useCallback as useCallback17,
8080
+ useEffect as useEffect26,
8081
+ useMemo as useMemo19,
8082
+ useRef as useRef9,
8083
+ useState as useState23
8084
+ } from "react";
8085
+
8086
+ // components/ViewportControls/index.tsx
8087
+ init_react_import();
8088
+ import { useEffect as useEffect25, useMemo as useMemo17, useState as useState22 } from "react";
8089
+
8090
+ // css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
8091
+ init_react_import();
8092
+ var styles_module_default26 = { "ViewportControls": "_ViewportControls_e3unb_1", "ViewportControls--fullScreen": "_ViewportControls--fullScreen_e3unb_5", "ViewportControls-toggleButton": "_ViewportControls-toggleButton_e3unb_14", "ViewportControls--isExpanded": "_ViewportControls--isExpanded_e3unb_38", "ViewportControls-actions": "_ViewportControls-actions_e3unb_42", "ViewportControls-actionsInner": "_ViewportControls-actionsInner_e3unb_46", "ViewportControls-divider": "_ViewportControls-divider_e3unb_75", "ViewportControls-zoomSelect": "_ViewportControls-zoomSelect_e3unb_81", "ViewportControls-zoom": "_ViewportControls-zoom_e3unb_81", "ViewportButton-inner": "_ViewportButton-inner_e3unb_111", "ViewportButton--isActive": "_ViewportButton--isActive_e3unb_119" };
8093
+
8094
+ // components/ViewportControls/index.tsx
8095
+ import { jsx as jsx44, jsxs as jsxs20 } from "react/jsx-runtime";
8096
+ var icons = {
8097
+ Smartphone: /* @__PURE__ */ jsx44(Smartphone, { size: 16 }),
8098
+ Tablet: /* @__PURE__ */ jsx44(Tablet, { size: 16 }),
8099
+ Monitor: /* @__PURE__ */ jsx44(Monitor, { size: 16 }),
8100
+ FullWidth: /* @__PURE__ */ jsx44(Expand, { size: 16 })
8101
+ };
8102
+ var getClassName31 = get_class_name_factory_default("ViewportControls", styles_module_default26);
8103
+ var getClassNameButton = get_class_name_factory_default("ViewportButton", styles_module_default26);
8104
+ var ActionButton = ({
8105
+ children,
8106
+ title,
8107
+ onClick,
8108
+ isActive,
8109
+ disabled
8110
+ }) => {
8111
+ return /* @__PURE__ */ jsx44("span", { className: getClassNameButton({ isActive }), suppressHydrationWarning: true, children: /* @__PURE__ */ jsx44(
8112
+ IconButton,
8113
+ {
8114
+ type: "button",
8115
+ title,
8116
+ disabled: disabled || isActive,
8117
+ onClick,
8118
+ suppressHydrationWarning: true,
8119
+ children: /* @__PURE__ */ jsx44("span", { className: getClassNameButton("inner"), children })
8120
+ }
8121
+ ) });
8122
+ };
8123
+ var defaultZoomOptions = [
8124
+ { label: "25%", value: 0.25 },
8125
+ { label: "50%", value: 0.5 },
8126
+ { label: "75%", value: 0.75 },
8127
+ { label: "100%", value: 1 },
8128
+ { label: "125%", value: 1.25 },
8129
+ { label: "150%", value: 1.5 },
8130
+ { label: "200%", value: 2 }
8131
+ ];
8132
+ var ViewportControls = ({
8133
+ autoZoom,
8134
+ zoom,
8135
+ onViewportChange,
8136
+ onZoom,
8137
+ fullScreen
8138
+ }) => {
8139
+ var _a, _b;
8140
+ const viewports = useAppStore((s) => s.viewports);
8141
+ const uiViewports = useAppStore((s) => s.state.ui.viewports);
8142
+ const defaultsContainAutoZoom = defaultZoomOptions.find(
8143
+ (option) => option.value === autoZoom
8144
+ );
8145
+ const zoomOptions = useMemo17(
8146
+ () => [
8147
+ ...defaultZoomOptions,
8148
+ ...defaultsContainAutoZoom ? [] : [
8149
+ {
8150
+ value: autoZoom,
8151
+ label: `${(autoZoom * 100).toFixed(0)}% (Auto)`
8152
+ }
8153
+ ]
8154
+ ].filter((a) => a.value <= autoZoom).sort((a, b) => a.value > b.value ? 1 : -1),
8155
+ [autoZoom]
8156
+ );
8157
+ const [activeViewport, setActiveViewport] = useState22(
8158
+ uiViewports.current.width
8159
+ );
8160
+ useEffect25(() => {
8161
+ setActiveViewport(uiViewports.current.width);
8162
+ }, [uiViewports.current]);
8163
+ const [isExpanded, setIsExpanded] = useState22(false);
8164
+ return /* @__PURE__ */ jsxs20(
8165
+ "div",
8166
+ {
8167
+ className: getClassName31({ isExpanded, fullScreen }),
8168
+ suppressHydrationWarning: true,
8169
+ children: [
8170
+ /* @__PURE__ */ jsx44("div", { className: getClassName31("actions"), children: /* @__PURE__ */ jsxs20("div", { className: getClassName31("actionsInner"), children: [
8171
+ viewports.map((viewport, i) => /* @__PURE__ */ jsx44(
8172
+ ActionButton,
8173
+ {
8174
+ title: viewport.label ? `Switch to ${viewport.label} viewport` : "Switch viewport",
8175
+ onClick: () => {
8176
+ setActiveViewport(viewport.width);
8177
+ onViewportChange(viewport);
8178
+ },
8179
+ isActive: activeViewport === viewport.width,
8180
+ children: typeof viewport.icon === "string" ? icons[viewport.icon] || viewport.icon : viewport.icon || icons.Smartphone
8181
+ },
8182
+ i
8183
+ )),
8184
+ /* @__PURE__ */ jsx44("div", { className: getClassName31("divider") }),
8185
+ /* @__PURE__ */ jsx44(
8186
+ ActionButton,
8187
+ {
8188
+ title: "Zoom viewport out",
8189
+ disabled: zoom <= ((_a = zoomOptions[0]) == null ? void 0 : _a.value),
8190
+ onClick: (e) => {
8191
+ e.stopPropagation();
8192
+ onZoom(
8193
+ zoomOptions[Math.max(
8194
+ zoomOptions.findIndex((option) => option.value === zoom) - 1,
8195
+ 0
8196
+ )].value
8197
+ );
8198
+ },
8199
+ children: /* @__PURE__ */ jsx44(ZoomOut, { size: 16 })
8200
+ }
8201
+ ),
8202
+ /* @__PURE__ */ jsx44(
8203
+ ActionButton,
8204
+ {
8205
+ title: "Zoom viewport in",
8206
+ disabled: zoom >= ((_b = zoomOptions[zoomOptions.length - 1]) == null ? void 0 : _b.value),
8207
+ onClick: (e) => {
8208
+ e.stopPropagation();
8209
+ onZoom(
8210
+ zoomOptions[Math.min(
8211
+ zoomOptions.findIndex((option) => option.value === zoom) + 1,
8212
+ zoomOptions.length - 1
8213
+ )].value
8214
+ );
8215
+ },
8216
+ children: /* @__PURE__ */ jsx44(ZoomIn, { size: 16 })
8217
+ }
8218
+ ),
8219
+ /* @__PURE__ */ jsxs20("div", { className: getClassName31("zoom"), children: [
8220
+ /* @__PURE__ */ jsx44("div", { className: getClassName31("divider") }),
8221
+ /* @__PURE__ */ jsx44(
8222
+ "select",
8223
+ {
8224
+ className: getClassName31("zoomSelect"),
8225
+ value: zoom.toString(),
8226
+ onClick: (e) => {
8227
+ e.stopPropagation();
8228
+ },
8229
+ onChange: (e) => {
8230
+ onZoom(parseFloat(e.currentTarget.value));
8231
+ },
8232
+ children: zoomOptions.map((option) => /* @__PURE__ */ jsx44(
8233
+ "option",
8234
+ {
8235
+ value: option.value,
8236
+ label: option.label
8237
+ },
8238
+ option.label
8239
+ ))
8240
+ }
8241
+ )
8242
+ ] })
8243
+ ] }) }),
8244
+ /* @__PURE__ */ jsx44(
8245
+ "button",
8246
+ {
8247
+ className: getClassName31("toggleButton"),
8248
+ title: "Toggle viewport menu",
8249
+ onClick: () => setIsExpanded((s) => !s),
8250
+ children: isExpanded ? /* @__PURE__ */ jsx44(X, { size: 16 }) : /* @__PURE__ */ jsx44(Monitor, { size: 16 })
8251
+ }
8252
+ )
8253
+ ]
8254
+ }
8255
+ );
8256
+ };
8257
+
8258
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Canvas/styles.module.css#css-module
8259
+ init_react_import();
8260
+ var styles_module_default27 = { "PuckCanvas": "_PuckCanvas_t6s9b_1", "PuckCanvas-controls": "_PuckCanvas-controls_t6s9b_17", "PuckCanvas--fullScreen": "_PuckCanvas--fullScreen_t6s9b_22", "PuckCanvas-inner": "_PuckCanvas-inner_t6s9b_33", "PuckCanvas-root": "_PuckCanvas-root_t6s9b_42", "PuckCanvas--ready": "_PuckCanvas--ready_t6s9b_67", "PuckCanvas-loader": "_PuckCanvas-loader_t6s9b_72", "PuckCanvas--showLoader": "_PuckCanvas--showLoader_t6s9b_82" };
8261
+
8262
+ // components/Puck/components/Canvas/index.tsx
8263
+ import { useShallow as useShallow8 } from "zustand/react/shallow";
8264
+
8265
+ // lib/frame-context.tsx
8266
+ init_react_import();
8267
+ import {
8268
+ createContext as createContext7,
8269
+ useContext as useContext12,
8270
+ useRef as useRef8,
8271
+ useMemo as useMemo18
8272
+ } from "react";
8273
+ import { jsx as jsx45 } from "react/jsx-runtime";
8274
+ var FrameContext = createContext7(null);
8275
+ var FrameProvider = ({
8276
+ children
8277
+ }) => {
8278
+ const frameRef = useRef8(null);
8279
+ const value = useMemo18(
8280
+ () => ({
8281
+ frameRef
8282
+ }),
8283
+ []
8105
8284
  );
8106
- const [menuOpen, setMenuOpen] = useState23(false);
8107
- const rootTitle = useAppStore((s) => {
8108
- var _a, _b;
8109
- const rootData = (_a = s.state.indexes.nodes["root"]) == null ? void 0 : _a.data;
8110
- return (_b = rootData.props.title) != null ? _b : "";
8111
- });
8112
- const leftSideBarVisible = useAppStore((s) => s.state.ui.leftSideBarVisible);
8113
- const rightSideBarVisible = useAppStore(
8114
- (s) => s.state.ui.rightSideBarVisible
8285
+ return /* @__PURE__ */ jsx45(FrameContext.Provider, { value, children });
8286
+ };
8287
+ var useCanvasFrame = () => {
8288
+ const context = useContext12(FrameContext);
8289
+ if (context === null) {
8290
+ throw new Error("useCanvasFrame must be used within a FrameProvider");
8291
+ }
8292
+ return context;
8293
+ };
8294
+
8295
+ // components/Puck/components/Canvas/index.tsx
8296
+ import { Fragment as Fragment15, jsx as jsx46, jsxs as jsxs21 } from "react/jsx-runtime";
8297
+ var getClassName32 = get_class_name_factory_default("PuckCanvas", styles_module_default27);
8298
+ var ZOOM_ON_CHANGE = true;
8299
+ var TRANSITION_DURATION = 150;
8300
+ var Canvas = () => {
8301
+ const { frameRef } = useCanvasFrame();
8302
+ const resetAutoZoom = useResetAutoZoom(frameRef);
8303
+ const { _experimentalFullScreenCanvas } = usePropsContext();
8304
+ const {
8305
+ dispatch,
8306
+ overrides,
8307
+ setUi,
8308
+ zoomConfig,
8309
+ setZoomConfig,
8310
+ status,
8311
+ iframe
8312
+ } = useAppStore(
8313
+ useShallow8((s) => ({
8314
+ dispatch: s.dispatch,
8315
+ overrides: s.overrides,
8316
+ setUi: s.setUi,
8317
+ zoomConfig: s.zoomConfig,
8318
+ setZoomConfig: s.setZoomConfig,
8319
+ status: s.status,
8320
+ iframe: s.iframe
8321
+ }))
8115
8322
  );
8116
- const toggleSidebars = useCallback17(
8117
- (sidebar) => {
8118
- const widerViewport = window.matchMedia("(min-width: 638px)").matches;
8119
- const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
8120
- const oppositeSideBar = sidebar === "left" ? "rightSideBarVisible" : "leftSideBarVisible";
8121
- dispatch({
8122
- type: "setUi",
8123
- ui: __spreadValues({
8124
- [`${sidebar}SideBarVisible`]: !sideBarVisible
8125
- }, !widerViewport ? { [oppositeSideBar]: false } : {})
8126
- });
8127
- },
8128
- [dispatch, leftSideBarVisible, rightSideBarVisible]
8323
+ const {
8324
+ leftSideBarVisible,
8325
+ rightSideBarVisible,
8326
+ leftSideBarWidth,
8327
+ rightSideBarWidth,
8328
+ viewports
8329
+ } = useAppStore(
8330
+ useShallow8((s) => ({
8331
+ leftSideBarVisible: s.state.ui.leftSideBarVisible,
8332
+ rightSideBarVisible: s.state.ui.rightSideBarVisible,
8333
+ leftSideBarWidth: s.state.ui.leftSideBarWidth,
8334
+ rightSideBarWidth: s.state.ui.rightSideBarWidth,
8335
+ viewports: s.state.ui.viewports
8336
+ }))
8129
8337
  );
8130
- return /* @__PURE__ */ jsx42(
8131
- CustomHeader,
8338
+ const [showTransition, setShowTransition] = useState23(false);
8339
+ const isResizingRef = useRef9(false);
8340
+ const defaultRender = useMemo19(() => {
8341
+ const PuckDefault = ({ children }) => /* @__PURE__ */ jsx46(Fragment15, { children });
8342
+ return PuckDefault;
8343
+ }, []);
8344
+ const CustomPreview = useMemo19(
8345
+ () => overrides.preview || defaultRender,
8346
+ [overrides]
8347
+ );
8348
+ const getFrameDimensions = useCallback17(() => {
8349
+ if (frameRef.current) {
8350
+ const frame = frameRef.current;
8351
+ const box = getBox(frame);
8352
+ return { width: box.contentBox.width, height: box.contentBox.height };
8353
+ }
8354
+ return { width: 0, height: 0 };
8355
+ }, [frameRef]);
8356
+ useEffect26(() => {
8357
+ resetAutoZoom();
8358
+ }, [
8359
+ frameRef,
8360
+ leftSideBarVisible,
8361
+ rightSideBarVisible,
8362
+ leftSideBarWidth,
8363
+ rightSideBarWidth,
8364
+ viewports
8365
+ ]);
8366
+ useEffect26(() => {
8367
+ const { height: frameHeight } = getFrameDimensions();
8368
+ if (viewports.current.height === "auto") {
8369
+ setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
8370
+ rootHeight: frameHeight / zoomConfig.zoom
8371
+ }));
8372
+ }
8373
+ }, [zoomConfig.zoom, getFrameDimensions, setZoomConfig]);
8374
+ useEffect26(() => {
8375
+ if (ZOOM_ON_CHANGE) {
8376
+ resetAutoZoom();
8377
+ }
8378
+ }, [viewports.current.width, viewports]);
8379
+ useEffect26(() => {
8380
+ if (!frameRef.current) return;
8381
+ const resizeObserver = new ResizeObserver(() => {
8382
+ if (!isResizingRef.current) {
8383
+ resetAutoZoom();
8384
+ }
8385
+ });
8386
+ resizeObserver.observe(frameRef.current);
8387
+ return () => {
8388
+ resizeObserver.disconnect();
8389
+ };
8390
+ }, [frameRef.current]);
8391
+ const [showLoader, setShowLoader] = useState23(false);
8392
+ useEffect26(() => {
8393
+ setTimeout(() => {
8394
+ setShowLoader(true);
8395
+ }, 500);
8396
+ }, []);
8397
+ return /* @__PURE__ */ jsxs21(
8398
+ "div",
8132
8399
  {
8133
- actions: /* @__PURE__ */ jsx42(Fragment15, { children: /* @__PURE__ */ jsx42(CustomHeaderActions, { children: /* @__PURE__ */ jsx42(
8134
- Button,
8135
- {
8136
- onClick: () => {
8137
- const data = appStore.getState().state.data;
8138
- onPublish && onPublish(data);
8139
- },
8140
- icon: /* @__PURE__ */ jsx42(Globe, { size: "14px" }),
8141
- children: "Publish"
8142
- }
8143
- ) }) }),
8144
- children: /* @__PURE__ */ jsx42(
8145
- "header",
8146
- {
8147
- className: getClassName28({ leftSideBarVisible, rightSideBarVisible }),
8148
- children: /* @__PURE__ */ jsxs19("div", { className: getClassName28("inner"), children: [
8149
- /* @__PURE__ */ jsxs19("div", { className: getClassName28("toggle"), children: [
8150
- /* @__PURE__ */ jsx42("div", { className: getClassName28("leftSideBarToggle"), children: /* @__PURE__ */ jsx42(
8151
- IconButton,
8152
- {
8153
- type: "button",
8154
- onClick: () => {
8155
- toggleSidebars("left");
8156
- },
8157
- title: "Toggle left sidebar",
8158
- children: /* @__PURE__ */ jsx42(PanelLeft, { focusable: "false" })
8159
- }
8160
- ) }),
8161
- /* @__PURE__ */ jsx42("div", { className: getClassName28("rightSideBarToggle"), children: /* @__PURE__ */ jsx42(
8162
- IconButton,
8163
- {
8164
- type: "button",
8165
- onClick: () => {
8166
- toggleSidebars("right");
8167
- },
8168
- title: "Toggle right sidebar",
8169
- children: /* @__PURE__ */ jsx42(PanelRight, { focusable: "false" })
8170
- }
8171
- ) })
8172
- ] }),
8173
- /* @__PURE__ */ jsx42("div", { className: getClassName28("title"), children: /* @__PURE__ */ jsxs19(Heading, { rank: "2", size: "xs", children: [
8174
- headerTitle || rootTitle || "Page",
8175
- headerPath && /* @__PURE__ */ jsxs19(Fragment15, { children: [
8176
- " ",
8177
- /* @__PURE__ */ jsx42("code", { className: getClassName28("path"), children: headerPath })
8178
- ] })
8179
- ] }) }),
8180
- /* @__PURE__ */ jsxs19("div", { className: getClassName28("tools"), children: [
8181
- /* @__PURE__ */ jsx42("div", { className: getClassName28("menuButton"), children: /* @__PURE__ */ jsx42(
8182
- IconButton,
8183
- {
8184
- type: "button",
8185
- onClick: () => {
8186
- return setMenuOpen(!menuOpen);
8187
- },
8188
- title: "Toggle menu bar",
8189
- children: menuOpen ? /* @__PURE__ */ jsx42(ChevronUp, { focusable: "false" }) : /* @__PURE__ */ jsx42(ChevronDown, { focusable: "false" })
8190
- }
8191
- ) }),
8192
- /* @__PURE__ */ jsx42(
8193
- MenuBar,
8194
- {
8195
- dispatch,
8196
- onPublish,
8197
- menuOpen,
8198
- renderHeaderActions: () => /* @__PURE__ */ jsx42(CustomHeaderActions, { children: /* @__PURE__ */ jsx42(
8199
- Button,
8200
- {
8201
- onClick: () => {
8202
- const data = appStore.getState().state.data;
8203
- onPublish && onPublish(data);
8204
- },
8205
- icon: /* @__PURE__ */ jsx42(Globe, { size: "14px" }),
8206
- children: "Publish"
8207
- }
8208
- ) }),
8209
- setMenuOpen
8210
- }
8211
- )
8212
- ] })
8213
- ] })
8400
+ className: getClassName32({
8401
+ ready: status === "READY" || !iframe.enabled || !iframe.waitForStyles,
8402
+ showLoader,
8403
+ fullScreen: _experimentalFullScreenCanvas
8404
+ }),
8405
+ onClick: (e) => {
8406
+ const el = e.target;
8407
+ if (!el.hasAttribute("data-puck-component") && !el.hasAttribute("data-puck-dropzone")) {
8408
+ dispatch({
8409
+ type: "setUi",
8410
+ ui: { itemSelector: null },
8411
+ recordHistory: true
8412
+ });
8214
8413
  }
8215
- )
8414
+ },
8415
+ children: [
8416
+ viewports.controlsVisible && iframe.enabled && /* @__PURE__ */ jsx46("div", { className: getClassName32("controls"), children: /* @__PURE__ */ jsx46(
8417
+ ViewportControls,
8418
+ {
8419
+ fullScreen: _experimentalFullScreenCanvas,
8420
+ autoZoom: zoomConfig.autoZoom,
8421
+ zoom: zoomConfig.zoom,
8422
+ onViewportChange: (viewport) => {
8423
+ setShowTransition(true);
8424
+ isResizingRef.current = true;
8425
+ const uiViewport = __spreadProps(__spreadValues({}, viewport), {
8426
+ height: viewport.height || "auto",
8427
+ zoom: zoomConfig.zoom
8428
+ });
8429
+ const newUi = {
8430
+ viewports: __spreadProps(__spreadValues({}, viewports), { current: uiViewport })
8431
+ };
8432
+ setUi(newUi);
8433
+ if (ZOOM_ON_CHANGE) {
8434
+ resetAutoZoom({
8435
+ viewports: __spreadProps(__spreadValues({}, viewports), { current: uiViewport })
8436
+ });
8437
+ }
8438
+ },
8439
+ onZoom: (zoom) => {
8440
+ setShowTransition(true);
8441
+ isResizingRef.current = true;
8442
+ setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), { zoom }));
8443
+ }
8444
+ }
8445
+ ) }),
8446
+ /* @__PURE__ */ jsxs21("div", { className: getClassName32("inner"), ref: frameRef, children: [
8447
+ /* @__PURE__ */ jsx46(
8448
+ "div",
8449
+ {
8450
+ className: getClassName32("root"),
8451
+ style: {
8452
+ width: iframe.enabled ? viewports.current.width : "100%",
8453
+ height: zoomConfig.rootHeight,
8454
+ transform: iframe.enabled ? `scale(${zoomConfig.zoom})` : void 0,
8455
+ transition: showTransition ? `width ${TRANSITION_DURATION}ms ease-out, height ${TRANSITION_DURATION}ms ease-out, transform ${TRANSITION_DURATION}ms ease-out` : "",
8456
+ overflow: iframe.enabled ? void 0 : "auto"
8457
+ },
8458
+ suppressHydrationWarning: true,
8459
+ id: "puck-canvas-root",
8460
+ onTransitionEnd: () => {
8461
+ setShowTransition(false);
8462
+ isResizingRef.current = false;
8463
+ },
8464
+ children: /* @__PURE__ */ jsx46(CustomPreview, { children: /* @__PURE__ */ jsx46(Preview2, {}) })
8465
+ }
8466
+ ),
8467
+ /* @__PURE__ */ jsx46("div", { className: getClassName32("loader"), children: /* @__PURE__ */ jsx46(Loader, { size: 24 }) })
8468
+ ] })
8469
+ ]
8216
8470
  }
8217
8471
  );
8218
8472
  };
8219
- var Header = memo4(HeaderInner);
8473
+
8474
+ // lib/use-sidebar-resize.ts
8475
+ init_react_import();
8476
+ import { useCallback as useCallback18, useEffect as useEffect27, useRef as useRef10, useState as useState24 } from "react";
8477
+ function useSidebarResize(position, dispatch) {
8478
+ const [width, setWidth] = useState24(null);
8479
+ const sidebarRef = useRef10(null);
8480
+ const storeWidth = useAppStore(
8481
+ (s) => position === "left" ? s.state.ui.leftSideBarWidth : s.state.ui.rightSideBarWidth
8482
+ );
8483
+ useEffect27(() => {
8484
+ if (typeof window !== "undefined" && !storeWidth) {
8485
+ try {
8486
+ const savedWidths = localStorage.getItem("puck-sidebar-widths");
8487
+ if (savedWidths) {
8488
+ const widths = JSON.parse(savedWidths);
8489
+ const savedWidth = widths[position];
8490
+ const key = position === "left" ? "leftSideBarWidth" : "rightSideBarWidth";
8491
+ if (savedWidth) {
8492
+ dispatch({
8493
+ type: "setUi",
8494
+ ui: {
8495
+ [key]: savedWidth
8496
+ }
8497
+ });
8498
+ }
8499
+ }
8500
+ } catch (error) {
8501
+ console.error(
8502
+ `Failed to load ${position} sidebar width from localStorage`,
8503
+ error
8504
+ );
8505
+ }
8506
+ }
8507
+ }, [dispatch, position, storeWidth]);
8508
+ useEffect27(() => {
8509
+ if (storeWidth !== void 0) {
8510
+ setWidth(storeWidth);
8511
+ }
8512
+ }, [storeWidth]);
8513
+ const handleResizeEnd = useCallback18(
8514
+ (width2) => {
8515
+ dispatch({
8516
+ type: "setUi",
8517
+ ui: {
8518
+ [position === "left" ? "leftSideBarWidth" : "rightSideBarWidth"]: width2
8519
+ }
8520
+ });
8521
+ let widths = {};
8522
+ try {
8523
+ const savedWidths = localStorage.getItem("puck-sidebar-widths");
8524
+ widths = savedWidths ? JSON.parse(savedWidths) : {};
8525
+ } catch (error) {
8526
+ console.error(
8527
+ `Failed to save ${position} sidebar width to localStorage`,
8528
+ error
8529
+ );
8530
+ } finally {
8531
+ localStorage.setItem(
8532
+ "puck-sidebar-widths",
8533
+ JSON.stringify(__spreadProps(__spreadValues({}, widths), {
8534
+ [position]: width2
8535
+ }))
8536
+ );
8537
+ }
8538
+ window.dispatchEvent(
8539
+ new CustomEvent("viewportchange", {
8540
+ bubbles: true,
8541
+ cancelable: false
8542
+ })
8543
+ );
8544
+ },
8545
+ [dispatch, position]
8546
+ );
8547
+ return {
8548
+ width,
8549
+ setWidth,
8550
+ sidebarRef,
8551
+ handleResizeEnd
8552
+ };
8553
+ }
8220
8554
 
8221
8555
  // components/Puck/components/Sidebar/index.tsx
8222
8556
  init_react_import();
8223
8557
 
8224
8558
  // components/Puck/components/ResizeHandle/index.tsx
8225
8559
  init_react_import();
8226
- import { useCallback as useCallback18, useRef as useRef10 } from "react";
8560
+ import { useCallback as useCallback19, useRef as useRef11 } from "react";
8227
8561
 
8228
8562
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/ResizeHandle/styles.module.css#css-module
8229
8563
  init_react_import();
8230
- var styles_module_default24 = { "ResizeHandle": "_ResizeHandle_144bf_2", "ResizeHandle--left": "_ResizeHandle--left_144bf_16", "ResizeHandle--right": "_ResizeHandle--right_144bf_20" };
8564
+ var styles_module_default28 = { "ResizeHandle": "_ResizeHandle_144bf_2", "ResizeHandle--left": "_ResizeHandle--left_144bf_16", "ResizeHandle--right": "_ResizeHandle--right_144bf_20" };
8231
8565
 
8232
8566
  // components/Puck/components/ResizeHandle/index.tsx
8233
- import { jsx as jsx43 } from "react/jsx-runtime";
8234
- var getClassName29 = get_class_name_factory_default("ResizeHandle", styles_module_default24);
8567
+ import { jsx as jsx47 } from "react/jsx-runtime";
8568
+ var getClassName33 = get_class_name_factory_default("ResizeHandle", styles_module_default28);
8235
8569
  var ResizeHandle = ({
8236
8570
  position,
8237
8571
  sidebarRef,
@@ -8240,11 +8574,11 @@ var ResizeHandle = ({
8240
8574
  }) => {
8241
8575
  const { frameRef } = useCanvasFrame();
8242
8576
  const resetAutoZoom = useResetAutoZoom(frameRef);
8243
- const handleRef = useRef10(null);
8244
- const isDragging = useRef10(false);
8245
- const startX = useRef10(0);
8246
- const startWidth = useRef10(0);
8247
- const handleMouseMove = useCallback18(
8577
+ const handleRef = useRef11(null);
8578
+ const isDragging = useRef11(false);
8579
+ const startX = useRef11(0);
8580
+ const startWidth = useRef11(0);
8581
+ const handleMouseMove = useCallback19(
8248
8582
  (e) => {
8249
8583
  if (!isDragging.current) return;
8250
8584
  const delta = e.clientX - startX.current;
@@ -8255,7 +8589,7 @@ var ResizeHandle = ({
8255
8589
  },
8256
8590
  [onResize, position]
8257
8591
  );
8258
- const handleMouseUp = useCallback18(() => {
8592
+ const handleMouseUp = useCallback19(() => {
8259
8593
  var _a;
8260
8594
  if (!isDragging.current) return;
8261
8595
  isDragging.current = false;
@@ -8271,7 +8605,7 @@ var ResizeHandle = ({
8271
8605
  onResizeEnd(finalWidth);
8272
8606
  resetAutoZoom();
8273
8607
  }, [onResizeEnd]);
8274
- const handleMouseDown = useCallback18(
8608
+ const handleMouseDown = useCallback19(
8275
8609
  (e) => {
8276
8610
  var _a;
8277
8611
  isDragging.current = true;
@@ -8289,11 +8623,11 @@ var ResizeHandle = ({
8289
8623
  },
8290
8624
  [position, handleMouseMove, handleMouseUp]
8291
8625
  );
8292
- return /* @__PURE__ */ jsx43(
8626
+ return /* @__PURE__ */ jsx47(
8293
8627
  "div",
8294
8628
  {
8295
8629
  ref: handleRef,
8296
- className: getClassName29({ [position]: true }),
8630
+ className: getClassName33({ [position]: true }),
8297
8631
  onMouseDown: handleMouseDown
8298
8632
  }
8299
8633
  );
@@ -8301,11 +8635,11 @@ var ResizeHandle = ({
8301
8635
 
8302
8636
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Sidebar/styles.module.css#css-module
8303
8637
  init_react_import();
8304
- var styles_module_default25 = { "Sidebar": "_Sidebar_1xksb_1", "Sidebar--left": "_Sidebar--left_1xksb_8", "Sidebar--right": "_Sidebar--right_1xksb_14", "Sidebar-resizeHandle": "_Sidebar-resizeHandle_1xksb_20" };
8638
+ var styles_module_default29 = { "Sidebar": "_Sidebar_o396p_1", "Sidebar--isVisible": "_Sidebar--isVisible_o396p_9", "Sidebar--left": "_Sidebar--left_o396p_13", "Sidebar--right": "_Sidebar--right_o396p_25", "Sidebar-resizeHandle": "_Sidebar-resizeHandle_o396p_37" };
8305
8639
 
8306
8640
  // components/Puck/components/Sidebar/index.tsx
8307
- import { Fragment as Fragment16, jsx as jsx44, jsxs as jsxs20 } from "react/jsx-runtime";
8308
- var getClassName30 = get_class_name_factory_default("Sidebar", styles_module_default25);
8641
+ import { Fragment as Fragment16, jsx as jsx48, jsxs as jsxs22 } from "react/jsx-runtime";
8642
+ var getClassName34 = get_class_name_factory_default("Sidebar", styles_module_default29);
8309
8643
  var Sidebar = ({
8310
8644
  position,
8311
8645
  sidebarRef,
@@ -8314,10 +8648,16 @@ var Sidebar = ({
8314
8648
  onResizeEnd,
8315
8649
  children
8316
8650
  }) => {
8317
- if (!isVisible) return null;
8318
- return /* @__PURE__ */ jsxs20(Fragment16, { children: [
8319
- /* @__PURE__ */ jsx44("div", { ref: sidebarRef, className: getClassName30({ [position]: true }), children }),
8320
- /* @__PURE__ */ jsx44("div", { className: `${getClassName30("resizeHandle")}`, children: /* @__PURE__ */ jsx44(
8651
+ return /* @__PURE__ */ jsxs22(Fragment16, { children: [
8652
+ /* @__PURE__ */ jsx48(
8653
+ "div",
8654
+ {
8655
+ ref: sidebarRef,
8656
+ className: getClassName34({ [position]: true, isVisible }),
8657
+ children
8658
+ }
8659
+ ),
8660
+ /* @__PURE__ */ jsx48("div", { className: `${getClassName34("resizeHandle")}`, children: /* @__PURE__ */ jsx48(
8321
8661
  ResizeHandle,
8322
8662
  {
8323
8663
  position,
@@ -8329,103 +8669,364 @@ var Sidebar = ({
8329
8669
  ] });
8330
8670
  };
8331
8671
 
8332
- // lib/use-sidebar-resize.ts
8672
+ // lib/use-delete-hotkeys.ts
8333
8673
  init_react_import();
8334
- import { useCallback as useCallback19, useEffect as useEffect28, useRef as useRef11, useState as useState24 } from "react";
8335
- function useSidebarResize(position, dispatch) {
8336
- const [width, setWidth] = useState24(null);
8337
- const sidebarRef = useRef11(null);
8338
- const storeWidth = useAppStore(
8339
- (s) => position === "left" ? s.state.ui.leftSideBarWidth : s.state.ui.rightSideBarWidth
8674
+ import { useCallback as useCallback20 } from "react";
8675
+ var isElementVisible = (element) => {
8676
+ let current = element;
8677
+ while (current && current !== document.body) {
8678
+ const style = window.getComputedStyle(current);
8679
+ if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0" || current.getAttribute("aria-hidden") === "true" || current.hasAttribute("hidden")) {
8680
+ return false;
8681
+ }
8682
+ current = current.parentElement;
8683
+ }
8684
+ return true;
8685
+ };
8686
+ var shouldBlockDeleteHotkey = (e) => {
8687
+ var _a;
8688
+ if (e == null ? void 0 : e.defaultPrevented) return true;
8689
+ const origin = ((_a = e == null ? void 0 : e.composedPath) == null ? void 0 : _a.call(e)[0]) || (e == null ? void 0 : e.target) || document.activeElement;
8690
+ if (origin instanceof HTMLElement) {
8691
+ const tag = origin.tagName.toLowerCase();
8692
+ if (tag === "input" || tag === "textarea" || tag === "select") return true;
8693
+ if (origin.isContentEditable) return true;
8694
+ const role = origin.getAttribute("role");
8695
+ if (role === "textbox" || role === "combobox" || role === "searchbox" || role === "listbox" || role === "grid") {
8696
+ return true;
8697
+ }
8698
+ }
8699
+ const modal = document.querySelector(
8700
+ 'dialog[open], [aria-modal="true"], [role="dialog"], [role="alertdialog"]'
8340
8701
  );
8341
- useEffect28(() => {
8342
- if (typeof window !== "undefined" && !storeWidth) {
8343
- try {
8344
- const savedWidths = localStorage.getItem("puck-sidebar-widths");
8345
- if (savedWidths) {
8346
- const widths = JSON.parse(savedWidths);
8347
- const savedWidth = widths[position];
8348
- const key = position === "left" ? "leftSideBarWidth" : "rightSideBarWidth";
8349
- if (savedWidth) {
8350
- dispatch({
8351
- type: "setUi",
8352
- ui: {
8353
- [key]: savedWidth
8354
- }
8355
- });
8356
- }
8702
+ if (modal && isElementVisible(modal)) {
8703
+ return true;
8704
+ }
8705
+ return false;
8706
+ };
8707
+ var useDeleteHotkeys = () => {
8708
+ const appStore = useAppStoreApi();
8709
+ const deleteSelectedComponent = useCallback20(
8710
+ (e) => {
8711
+ var _a;
8712
+ if (shouldBlockDeleteHotkey(e)) {
8713
+ return false;
8714
+ }
8715
+ const { state, dispatch, permissions, selectedItem } = appStore.getState();
8716
+ const sel = (_a = state.ui) == null ? void 0 : _a.itemSelector;
8717
+ if (!(sel == null ? void 0 : sel.zone) || !selectedItem) return true;
8718
+ if (!permissions.getPermissions({ item: selectedItem }).delete)
8719
+ return true;
8720
+ dispatch({
8721
+ type: "remove",
8722
+ index: sel.index,
8723
+ zone: sel.zone
8724
+ });
8725
+ return true;
8726
+ },
8727
+ [appStore]
8728
+ );
8729
+ useHotkey({ delete: true }, deleteSelectedComponent);
8730
+ useHotkey({ backspace: true }, deleteSelectedComponent);
8731
+ };
8732
+
8733
+ // components/Puck/components/Nav/index.tsx
8734
+ init_react_import();
8735
+
8736
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Nav/styles.module.css#css-module
8737
+ init_react_import();
8738
+ var styles_module_default30 = { "Nav": "_Nav_3nnxc_1", "Nav-list": "_Nav-list_3nnxc_5", "Nav-mobileActions": "_Nav-mobileActions_3nnxc_23", "NavItem-link": "_NavItem-link_3nnxc_38", "NavItem": "_NavItem_3nnxc_38", "NavItem-linkIcon": "_NavItem-linkIcon_3nnxc_88", "NavItem--active": "_NavItem--active_3nnxc_93", "NavItem--mobileOnly": "_NavItem--mobileOnly_3nnxc_120" };
8739
+
8740
+ // components/Puck/components/Nav/index.tsx
8741
+ import { jsx as jsx49, jsxs as jsxs23 } from "react/jsx-runtime";
8742
+ var getClassName35 = get_class_name_factory_default("Nav", styles_module_default30);
8743
+ var getClassNameItem3 = get_class_name_factory_default("NavItem", styles_module_default30);
8744
+ var MenuItem = ({
8745
+ label,
8746
+ icon,
8747
+ onClick,
8748
+ isActive,
8749
+ mobileOnly
8750
+ }) => {
8751
+ return /* @__PURE__ */ jsx49("li", { className: getClassNameItem3({ active: isActive, mobileOnly }), children: onClick && /* @__PURE__ */ jsxs23("div", { className: getClassNameItem3("link"), onClick, children: [
8752
+ icon && /* @__PURE__ */ jsx49("span", { className: getClassNameItem3("linkIcon"), children: icon }),
8753
+ /* @__PURE__ */ jsx49("span", { className: getClassNameItem3("linkLabel"), children: label })
8754
+ ] }) });
8755
+ };
8756
+ var Nav = ({
8757
+ items,
8758
+ mobileActions
8759
+ }) => {
8760
+ return /* @__PURE__ */ jsxs23("nav", { className: getClassName35(), children: [
8761
+ /* @__PURE__ */ jsx49("ul", { className: getClassName35("list"), children: Object.entries(items).map(([key, item]) => /* @__PURE__ */ jsx49(MenuItem, __spreadValues({}, item), key)) }),
8762
+ mobileActions && /* @__PURE__ */ jsx49("div", { className: getClassName35("mobileActions"), children: mobileActions })
8763
+ ] });
8764
+ };
8765
+
8766
+ // components/Puck/components/Layout/index.tsx
8767
+ import { jsx as jsx50, jsxs as jsxs24 } from "react/jsx-runtime";
8768
+ var getClassName36 = get_class_name_factory_default("Puck", styles_module_default22);
8769
+ var getLayoutClassName = get_class_name_factory_default("PuckLayout", styles_module_default22);
8770
+ var getPluginTabClassName = get_class_name_factory_default("PuckPluginTab", styles_module_default22);
8771
+ var FieldSideBar = () => {
8772
+ const title = useAppStore(
8773
+ (s) => {
8774
+ var _a, _b;
8775
+ return s.selectedItem ? (_b = (_a = s.config.components[s.selectedItem.type]) == null ? void 0 : _a["label"]) != null ? _b : s.selectedItem.type.toString() : "Page";
8776
+ }
8777
+ );
8778
+ return /* @__PURE__ */ jsx50(SidebarSection, { noPadding: true, noBorderTop: true, showBreadcrumbs: true, title, children: /* @__PURE__ */ jsx50(Fields, {}) });
8779
+ };
8780
+ var PluginTab = ({
8781
+ children,
8782
+ visible,
8783
+ mobileOnly
8784
+ }) => {
8785
+ return /* @__PURE__ */ jsx50("div", { className: getPluginTabClassName({ visible, mobileOnly }), children: /* @__PURE__ */ jsx50("div", { className: getPluginTabClassName("body"), children }) });
8786
+ };
8787
+ var Layout = ({ children }) => {
8788
+ const {
8789
+ iframe: _iframe,
8790
+ dnd,
8791
+ initialHistory: _initialHistory,
8792
+ plugins,
8793
+ height = "100dvh"
8794
+ } = usePropsContext();
8795
+ const iframe = useMemo20(
8796
+ () => __spreadValues({
8797
+ enabled: true,
8798
+ waitForStyles: true
8799
+ }, _iframe),
8800
+ [_iframe]
8801
+ );
8802
+ useInjectGlobalCss(iframe.enabled);
8803
+ const dispatch = useAppStore((s) => s.dispatch);
8804
+ const leftSideBarVisible = useAppStore((s) => s.state.ui.leftSideBarVisible);
8805
+ const rightSideBarVisible = useAppStore(
8806
+ (s) => s.state.ui.rightSideBarVisible
8807
+ );
8808
+ const instanceId = useAppStore((s) => s.instanceId);
8809
+ const {
8810
+ width: leftWidth,
8811
+ setWidth: setLeftWidth,
8812
+ sidebarRef: leftSidebarRef,
8813
+ handleResizeEnd: handleLeftSidebarResizeEnd
8814
+ } = useSidebarResize("left", dispatch);
8815
+ const {
8816
+ width: rightWidth,
8817
+ setWidth: setRightWidth,
8818
+ sidebarRef: rightSidebarRef,
8819
+ handleResizeEnd: handleRightSidebarResizeEnd
8820
+ } = useSidebarResize("right", dispatch);
8821
+ useEffect29(() => {
8822
+ if (!window.matchMedia("(min-width: 638px)").matches) {
8823
+ dispatch({
8824
+ type: "setUi",
8825
+ ui: {
8826
+ leftSideBarVisible: false,
8827
+ rightSideBarVisible: false
8828
+ }
8829
+ });
8830
+ }
8831
+ const handleResize = () => {
8832
+ if (!window.matchMedia("(min-width: 638px)").matches) {
8833
+ dispatch({
8834
+ type: "setUi",
8835
+ ui: (ui) => __spreadValues(__spreadValues({}, ui), ui.rightSideBarVisible ? { leftSideBarVisible: false } : {})
8836
+ });
8837
+ }
8838
+ };
8839
+ window.addEventListener("resize", handleResize);
8840
+ return () => {
8841
+ window.removeEventListener("resize", handleResize);
8842
+ };
8843
+ }, []);
8844
+ const overrides = useAppStore((s) => s.overrides);
8845
+ const CustomPuck = useMemo20(
8846
+ () => overrides.puck || DefaultOverride,
8847
+ [overrides]
8848
+ );
8849
+ const [mounted, setMounted] = useState25(false);
8850
+ useEffect29(() => {
8851
+ setMounted(true);
8852
+ }, []);
8853
+ const ready = useAppStore((s) => s.status === "READY");
8854
+ useMonitorHotkeys();
8855
+ useEffect29(() => {
8856
+ if (ready && iframe.enabled) {
8857
+ const frameDoc = getFrame();
8858
+ if (frameDoc) {
8859
+ return monitorHotkeys(frameDoc);
8860
+ }
8861
+ }
8862
+ }, [ready, iframe.enabled]);
8863
+ usePreviewModeHotkeys();
8864
+ useDeleteHotkeys();
8865
+ const layoutOptions = {};
8866
+ if (leftWidth) {
8867
+ layoutOptions["--puck-user-left-side-bar-width"] = `${leftWidth}px`;
8868
+ }
8869
+ if (rightWidth) {
8870
+ layoutOptions["--puck-user-right-side-bar-width"] = `${rightWidth}px`;
8871
+ }
8872
+ const setUi = useAppStore((s) => s.setUi);
8873
+ const currentPlugin = useAppStore((s) => {
8874
+ var _a;
8875
+ return (_a = s.state.ui.plugin) == null ? void 0 : _a.current;
8876
+ });
8877
+ const appStoreApi = useAppStoreApi();
8878
+ const [mobilePanelHeightMode, setMobilePanelHeightMode] = useState25("toggle");
8879
+ const pluginItems = useMemo20(() => {
8880
+ const details = {};
8881
+ const defaultPlugins = [blocksPlugin(), outlinePlugin()];
8882
+ const combinedPlugins = [
8883
+ ...defaultPlugins,
8884
+ ...plugins != null ? plugins : []
8885
+ ];
8886
+ if (!(plugins == null ? void 0 : plugins.some((p) => p.name === "fields"))) {
8887
+ combinedPlugins.push(fieldsPlugin());
8888
+ }
8889
+ combinedPlugins == null ? void 0 : combinedPlugins.forEach((plugin) => {
8890
+ var _a, _b;
8891
+ if (plugin.name && plugin.render) {
8892
+ if (details[plugin.name]) {
8893
+ delete details[plugin.name];
8357
8894
  }
8358
- } catch (error) {
8359
- console.error(
8360
- `Failed to load ${position} sidebar width from localStorage`,
8361
- error
8362
- );
8895
+ details[plugin.name] = {
8896
+ label: (_a = plugin.label) != null ? _a : plugin.name,
8897
+ icon: (_b = plugin.icon) != null ? _b : /* @__PURE__ */ jsx50(ToyBrick, {}),
8898
+ onClick: () => {
8899
+ var _a2;
8900
+ setMobilePanelHeightMode((_a2 = plugin.mobilePanelHeight) != null ? _a2 : "toggle");
8901
+ if (plugin.name === currentPlugin) {
8902
+ if (leftSideBarVisible) {
8903
+ setUi({ leftSideBarVisible: false });
8904
+ } else {
8905
+ setUi({ leftSideBarVisible: true });
8906
+ }
8907
+ } else {
8908
+ if (plugin.name) {
8909
+ setUi({
8910
+ plugin: { current: plugin.name },
8911
+ leftSideBarVisible: true
8912
+ });
8913
+ }
8914
+ }
8915
+ },
8916
+ isActive: leftSideBarVisible && currentPlugin === plugin.name,
8917
+ render: plugin.render,
8918
+ mobileOnly: plugin.mobileOnly
8919
+ };
8363
8920
  }
8921
+ });
8922
+ return details;
8923
+ }, [plugins, currentPlugin, appStoreApi, leftSideBarVisible]);
8924
+ useEffect29(() => {
8925
+ if (!currentPlugin) {
8926
+ const names = Object.keys(pluginItems);
8927
+ setUi({ plugin: { current: names[0] } });
8364
8928
  }
8365
- }, [dispatch, position, storeWidth]);
8366
- useEffect28(() => {
8367
- if (storeWidth !== void 0) {
8368
- setWidth(storeWidth);
8929
+ }, [pluginItems, currentPlugin]);
8930
+ const hasDesktopFieldsPlugin = pluginItems["fields"] && pluginItems["fields"].mobileOnly === false;
8931
+ const mobilePanelExpanded = useAppStore(
8932
+ (s) => {
8933
+ var _a;
8934
+ return (_a = s.state.ui.mobilePanelExpanded) != null ? _a : false;
8369
8935
  }
8370
- }, [storeWidth]);
8371
- const handleResizeEnd = useCallback19(
8372
- (width2) => {
8373
- dispatch({
8374
- type: "setUi",
8375
- ui: {
8376
- [position === "left" ? "leftSideBarWidth" : "rightSideBarWidth"]: width2
8377
- }
8378
- });
8379
- let widths = {};
8380
- try {
8381
- const savedWidths = localStorage.getItem("puck-sidebar-widths");
8382
- widths = savedWidths ? JSON.parse(savedWidths) : {};
8383
- } catch (error) {
8384
- console.error(
8385
- `Failed to save ${position} sidebar width to localStorage`,
8386
- error
8387
- );
8388
- } finally {
8389
- localStorage.setItem(
8390
- "puck-sidebar-widths",
8391
- JSON.stringify(__spreadProps(__spreadValues({}, widths), {
8392
- [position]: width2
8393
- }))
8394
- );
8395
- }
8396
- window.dispatchEvent(
8397
- new CustomEvent("viewportchange", {
8398
- bubbles: true,
8399
- cancelable: false
8400
- })
8401
- );
8402
- },
8403
- [dispatch, position]
8404
8936
  );
8405
- return {
8406
- width,
8407
- setWidth,
8408
- sidebarRef,
8409
- handleResizeEnd
8410
- };
8411
- }
8412
-
8413
- // components/Puck/index.tsx
8414
- import { jsx as jsx45, jsxs as jsxs21 } from "react/jsx-runtime";
8415
- var getClassName31 = get_class_name_factory_default("Puck", styles_module_default15);
8416
- var getLayoutClassName = get_class_name_factory_default("PuckLayout", styles_module_default15);
8417
- var FieldSideBar = () => {
8418
- const title = useAppStore(
8419
- (s) => {
8420
- var _a, _b;
8421
- return s.selectedItem ? (_b = (_a = s.config.components[s.selectedItem.type]) == null ? void 0 : _a["label"]) != null ? _b : s.selectedItem.type.toString() : "Page";
8937
+ return /* @__PURE__ */ jsxs24(
8938
+ "div",
8939
+ {
8940
+ className: `Puck ${getClassName36()}`,
8941
+ style: { height },
8942
+ id: instanceId,
8943
+ children: [
8944
+ /* @__PURE__ */ jsx50(DragDropContext, { disableAutoScroll: dnd == null ? void 0 : dnd.disableAutoScroll, children: /* @__PURE__ */ jsx50(CustomPuck, { children: children || /* @__PURE__ */ jsx50(FrameProvider, { children: /* @__PURE__ */ jsx50(
8945
+ "div",
8946
+ {
8947
+ className: getLayoutClassName({
8948
+ leftSideBarVisible,
8949
+ mounted,
8950
+ rightSideBarVisible: !hasDesktopFieldsPlugin && rightSideBarVisible,
8951
+ isExpanded: mobilePanelExpanded,
8952
+ mobilePanelHeightToggle: mobilePanelHeightMode === "toggle",
8953
+ mobilePanelHeightMinContent: mobilePanelHeightMode === "min-content"
8954
+ }),
8955
+ children: /* @__PURE__ */ jsxs24(
8956
+ "div",
8957
+ {
8958
+ className: getLayoutClassName("inner"),
8959
+ style: layoutOptions,
8960
+ children: [
8961
+ /* @__PURE__ */ jsx50("div", { className: getLayoutClassName("header"), children: /* @__PURE__ */ jsx50(Header, {}) }),
8962
+ /* @__PURE__ */ jsx50("div", { className: getLayoutClassName("nav"), children: /* @__PURE__ */ jsx50(
8963
+ Nav,
8964
+ {
8965
+ items: pluginItems,
8966
+ mobileActions: leftSideBarVisible && mobilePanelHeightMode === "toggle" && /* @__PURE__ */ jsx50(
8967
+ IconButton,
8968
+ {
8969
+ type: "button",
8970
+ title: "maximize",
8971
+ onClick: () => {
8972
+ setUi({
8973
+ mobilePanelExpanded: !mobilePanelExpanded
8974
+ });
8975
+ },
8976
+ children: mobilePanelExpanded ? /* @__PURE__ */ jsx50(Minimize2, { size: 21 }) : /* @__PURE__ */ jsx50(Maximize2, { size: 21 })
8977
+ }
8978
+ )
8979
+ }
8980
+ ) }),
8981
+ /* @__PURE__ */ jsx50(
8982
+ Sidebar,
8983
+ {
8984
+ position: "left",
8985
+ sidebarRef: leftSidebarRef,
8986
+ isVisible: leftSideBarVisible,
8987
+ onResize: setLeftWidth,
8988
+ onResizeEnd: handleLeftSidebarResizeEnd,
8989
+ children: Object.entries(pluginItems).map(
8990
+ ([id, { mobileOnly, render: Render2, label }]) => /* @__PURE__ */ jsx50(
8991
+ PluginTab,
8992
+ {
8993
+ visible: currentPlugin === id,
8994
+ mobileOnly,
8995
+ children: /* @__PURE__ */ jsx50(Render2, {})
8996
+ },
8997
+ id
8998
+ )
8999
+ )
9000
+ }
9001
+ ),
9002
+ /* @__PURE__ */ jsx50(Canvas, {}),
9003
+ !hasDesktopFieldsPlugin && /* @__PURE__ */ jsx50(
9004
+ Sidebar,
9005
+ {
9006
+ position: "right",
9007
+ sidebarRef: rightSidebarRef,
9008
+ isVisible: rightSideBarVisible,
9009
+ onResize: setRightWidth,
9010
+ onResizeEnd: handleRightSidebarResizeEnd,
9011
+ children: /* @__PURE__ */ jsx50(FieldSideBar, {})
9012
+ }
9013
+ )
9014
+ ]
9015
+ }
9016
+ )
9017
+ }
9018
+ ) }) }) }),
9019
+ /* @__PURE__ */ jsx50("div", { id: "puck-portal-root", className: getClassName36("portal") })
9020
+ ]
8422
9021
  }
8423
9022
  );
8424
- return /* @__PURE__ */ jsx45(SidebarSection, { noPadding: true, noBorderTop: true, showBreadcrumbs: true, title, children: /* @__PURE__ */ jsx45(Fields, {}) });
8425
9023
  };
9024
+
9025
+ // components/Puck/index.tsx
9026
+ import { jsx as jsx51 } from "react/jsx-runtime";
8426
9027
  var propsContext = createContext8({});
8427
9028
  function PropsProvider(props) {
8428
- return /* @__PURE__ */ jsx45(propsContext.Provider, { value: props, children: props.children });
9029
+ return /* @__PURE__ */ jsx51(propsContext.Provider, { value: props, children: props.children });
8429
9030
  }
8430
9031
  var usePropsContext = () => useContext13(propsContext);
8431
9032
  function PuckProvider({ children }) {
@@ -8444,15 +9045,15 @@ function PuckProvider({ children }) {
8444
9045
  onAction,
8445
9046
  fieldTransforms
8446
9047
  } = usePropsContext();
8447
- const iframe = useMemo20(
9048
+ const iframe = useMemo21(
8448
9049
  () => __spreadValues({
8449
9050
  enabled: true,
8450
9051
  waitForStyles: true
8451
9052
  }, _iframe),
8452
9053
  [_iframe]
8453
9054
  );
8454
- const [generatedAppState] = useState25(() => {
8455
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
9055
+ const [generatedAppState] = useState26(() => {
9056
+ var _a, _b, _c, _d, _e, _f, _g;
8456
9057
  const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
8457
9058
  let clientUiState = {};
8458
9059
  if (typeof window !== "undefined") {
@@ -8463,32 +9064,46 @@ function PuckProvider({ children }) {
8463
9064
  });
8464
9065
  }
8465
9066
  const viewportWidth = window.innerWidth;
8466
- const viewportDifferences = Object.entries(viewports).map(([key, value]) => ({
9067
+ const fullWidthViewport = Object.values(viewports).find(
9068
+ (v) => v.width === "100%"
9069
+ );
9070
+ const containsFullWidthViewport = !!fullWidthViewport;
9071
+ const viewportDifferences = Object.entries(viewports).filter(([_, value]) => value.width !== "100%").map(([key, value]) => ({
8467
9072
  key,
8468
- diff: Math.abs(viewportWidth - value.width)
9073
+ diff: Math.abs(
9074
+ viewportWidth - (typeof value.width === "string" ? viewportWidth : value.width)
9075
+ ),
9076
+ value
8469
9077
  })).sort((a, b) => a.diff > b.diff ? 1 : -1);
8470
- const closestViewport = viewportDifferences[0].key;
9078
+ let closestViewport = viewportDifferences[0].value;
9079
+ if (closestViewport.width < viewportWidth && containsFullWidthViewport) {
9080
+ closestViewport = fullWidthViewport;
9081
+ }
8471
9082
  if (iframe.enabled) {
8472
9083
  clientUiState = __spreadProps(__spreadValues({}, clientUiState), {
8473
9084
  viewports: __spreadProps(__spreadValues({}, initial.viewports), {
8474
9085
  current: __spreadProps(__spreadValues({}, initial.viewports.current), {
8475
- height: ((_b = (_a = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _a.current) == null ? void 0 : _b.height) || ((_c = viewports[closestViewport]) == null ? void 0 : _c.height) || "auto",
8476
- width: ((_e = (_d = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _d.current) == null ? void 0 : _e.width) || ((_f = viewports[closestViewport]) == null ? void 0 : _f.width)
9086
+ height: ((_b = (_a = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _a.current) == null ? void 0 : _b.height) || (closestViewport == null ? void 0 : closestViewport.height) || "auto",
9087
+ width: ((_d = (_c = initialUi == null ? void 0 : initialUi.viewports) == null ? void 0 : _c.current) == null ? void 0 : _d.width) || (closestViewport == null ? void 0 : closestViewport.width)
8477
9088
  })
8478
9089
  })
8479
9090
  });
8480
9091
  }
8481
9092
  }
8482
- if (Object.keys((initialData == null ? void 0 : initialData.root) || {}).length > 0 && !((_g = initialData == null ? void 0 : initialData.root) == null ? void 0 : _g.props)) {
9093
+ if (Object.keys((initialData == null ? void 0 : initialData.root) || {}).length > 0 && !((_e = initialData == null ? void 0 : initialData.root) == null ? void 0 : _e.props)) {
8483
9094
  console.warn(
8484
9095
  "Warning: Defining props on `root` is deprecated. Please use `root.props`, or republish this page to migrate automatically."
8485
9096
  );
8486
9097
  }
8487
- const rootProps = ((_h = initialData == null ? void 0 : initialData.root) == null ? void 0 : _h.props) || (initialData == null ? void 0 : initialData.root) || {};
8488
- const defaultedRootProps = __spreadValues(__spreadValues({}, (_i = config.root) == null ? void 0 : _i.defaultProps), rootProps);
9098
+ const rootProps = ((_f = initialData == null ? void 0 : initialData.root) == null ? void 0 : _f.props) || (initialData == null ? void 0 : initialData.root) || {};
9099
+ const defaultedRootProps = __spreadValues(__spreadValues({}, (_g = config.root) == null ? void 0 : _g.defaultProps), rootProps);
9100
+ const root = populateIds(
9101
+ toComponent(__spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: defaultedRootProps })),
9102
+ config
9103
+ );
8489
9104
  const newAppState = __spreadProps(__spreadValues({}, defaultAppState), {
8490
9105
  data: __spreadProps(__spreadValues({}, initialData), {
8491
- root: __spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: defaultedRootProps }),
9106
+ root: __spreadProps(__spreadValues({}, initialData == null ? void 0 : initialData.root), { props: root.props }),
8492
9107
  content: initialData.content || []
8493
9108
  }),
8494
9109
  ui: __spreadProps(__spreadValues(__spreadValues({}, initial), clientUiState), {
@@ -8511,7 +9126,7 @@ function PuckProvider({ children }) {
8511
9126
  return walkAppState(newAppState, config);
8512
9127
  });
8513
9128
  const { appendData = true } = _initialHistory || {};
8514
- const [blendedHistories] = useState25(
9129
+ const [blendedHistories] = useState26(
8515
9130
  [
8516
9131
  ...(_initialHistory == null ? void 0 : _initialHistory.histories) || [],
8517
9132
  ...appendData ? [{ state: generatedAppState }] : []
@@ -8531,7 +9146,7 @@ function PuckProvider({ children }) {
8531
9146
  overrides,
8532
9147
  plugins
8533
9148
  });
8534
- const loadedFieldTransforms = useMemo20(() => {
9149
+ const loadedFieldTransforms = useMemo21(() => {
8535
9150
  const _plugins = plugins || [];
8536
9151
  const pluginFieldTransforms = _plugins.reduce(
8537
9152
  (acc, plugin) => __spreadValues(__spreadValues({}, acc), plugin.fieldTransforms),
@@ -8539,9 +9154,11 @@ function PuckProvider({ children }) {
8539
9154
  );
8540
9155
  return __spreadValues(__spreadValues({}, pluginFieldTransforms), fieldTransforms);
8541
9156
  }, [fieldTransforms, plugins]);
8542
- const generateAppStore = useCallback20(
9157
+ const instanceId = useSafeId();
9158
+ const generateAppStore = useCallback21(
8543
9159
  (state) => {
8544
9160
  return {
9161
+ instanceId,
8545
9162
  state,
8546
9163
  config,
8547
9164
  plugins: plugins || [],
@@ -8554,6 +9171,7 @@ function PuckProvider({ children }) {
8554
9171
  };
8555
9172
  },
8556
9173
  [
9174
+ instanceId,
8557
9175
  initialAppState,
8558
9176
  config,
8559
9177
  plugins,
@@ -8565,15 +9183,15 @@ function PuckProvider({ children }) {
8565
9183
  loadedFieldTransforms
8566
9184
  ]
8567
9185
  );
8568
- const [appStore] = useState25(
9186
+ const [appStore] = useState26(
8569
9187
  () => createAppStore(generateAppStore(initialAppState))
8570
9188
  );
8571
- useEffect29(() => {
9189
+ useEffect30(() => {
8572
9190
  if (process.env.NODE_ENV !== "production") {
8573
9191
  window.__PUCK_INTERNAL_DO_NOT_USE = { appStore };
8574
9192
  }
8575
9193
  }, [appStore]);
8576
- useEffect29(() => {
9194
+ useEffect30(() => {
8577
9195
  const state = appStore.getState().state;
8578
9196
  appStore.setState(__spreadValues({}, generateAppStore(state)));
8579
9197
  }, [config, plugins, loadedOverrides, viewports, iframe, onAction, metadata]);
@@ -8583,159 +9201,28 @@ function PuckProvider({ children }) {
8583
9201
  initialAppState
8584
9202
  });
8585
9203
  const previousData = useRef12(null);
8586
- useEffect29(() => {
8587
- appStore.subscribe(
9204
+ useEffect30(() => {
9205
+ return appStore.subscribe(
8588
9206
  (s) => s.state.data,
8589
9207
  (data) => {
8590
9208
  if (onChange) {
8591
- if (fdeq(data, previousData.current)) return;
9209
+ if ((0, import_fast_deep_equal.default)(data, previousData.current)) return;
8592
9210
  onChange(data);
8593
9211
  previousData.current = data;
8594
9212
  }
8595
9213
  }
8596
9214
  );
8597
- }, []);
9215
+ }, [onChange]);
8598
9216
  useRegisterPermissionsSlice(appStore, permissions);
8599
9217
  const uPuckStore = useRegisterUsePuckStore(appStore);
8600
- useEffect29(() => {
9218
+ useEffect30(() => {
8601
9219
  const { resolveAndCommitData } = appStore.getState();
8602
9220
  resolveAndCommitData();
8603
9221
  }, []);
8604
- return /* @__PURE__ */ jsx45(appStoreContext.Provider, { value: appStore, children: /* @__PURE__ */ jsx45(UsePuckStoreContext.Provider, { value: uPuckStore, children }) });
8605
- }
8606
- function PuckLayout({ children }) {
8607
- const {
8608
- iframe: _iframe,
8609
- dnd,
8610
- initialHistory: _initialHistory
8611
- } = usePropsContext();
8612
- const iframe = useMemo20(
8613
- () => __spreadValues({
8614
- enabled: true,
8615
- waitForStyles: true
8616
- }, _iframe),
8617
- [_iframe]
8618
- );
8619
- useInjectGlobalCss(iframe.enabled);
8620
- const dispatch = useAppStore((s) => s.dispatch);
8621
- const leftSideBarVisible = useAppStore((s) => s.state.ui.leftSideBarVisible);
8622
- const rightSideBarVisible = useAppStore(
8623
- (s) => s.state.ui.rightSideBarVisible
8624
- );
8625
- const {
8626
- width: leftWidth,
8627
- setWidth: setLeftWidth,
8628
- sidebarRef: leftSidebarRef,
8629
- handleResizeEnd: handleLeftSidebarResizeEnd
8630
- } = useSidebarResize("left", dispatch);
8631
- const {
8632
- width: rightWidth,
8633
- setWidth: setRightWidth,
8634
- sidebarRef: rightSidebarRef,
8635
- handleResizeEnd: handleRightSidebarResizeEnd
8636
- } = useSidebarResize("right", dispatch);
8637
- useEffect29(() => {
8638
- if (!window.matchMedia("(min-width: 638px)").matches) {
8639
- dispatch({
8640
- type: "setUi",
8641
- ui: {
8642
- leftSideBarVisible: false,
8643
- rightSideBarVisible: false
8644
- }
8645
- });
8646
- }
8647
- const handleResize = () => {
8648
- if (!window.matchMedia("(min-width: 638px)").matches) {
8649
- dispatch({
8650
- type: "setUi",
8651
- ui: (ui) => __spreadValues(__spreadValues({}, ui), ui.rightSideBarVisible ? { leftSideBarVisible: false } : {})
8652
- });
8653
- }
8654
- };
8655
- window.addEventListener("resize", handleResize);
8656
- return () => {
8657
- window.removeEventListener("resize", handleResize);
8658
- };
8659
- }, []);
8660
- const overrides = useAppStore((s) => s.overrides);
8661
- const CustomPuck = useMemo20(
8662
- () => overrides.puck || DefaultOverride,
8663
- [overrides]
8664
- );
8665
- const [mounted, setMounted] = useState25(false);
8666
- useEffect29(() => {
8667
- setMounted(true);
8668
- }, []);
8669
- const ready = useAppStore((s) => s.status === "READY");
8670
- useMonitorHotkeys();
8671
- useEffect29(() => {
8672
- if (ready && iframe.enabled) {
8673
- const frameDoc = getFrame();
8674
- if (frameDoc) {
8675
- return monitorHotkeys(frameDoc);
8676
- }
8677
- }
8678
- }, [ready, iframe.enabled]);
8679
- usePreviewModeHotkeys();
8680
- const layoutOptions = {};
8681
- if (leftWidth) {
8682
- layoutOptions["--puck-user-left-side-bar-width"] = `${leftWidth}px`;
8683
- }
8684
- if (rightWidth) {
8685
- layoutOptions["--puck-user-right-side-bar-width"] = `${rightWidth}px`;
8686
- }
8687
- return /* @__PURE__ */ jsxs21("div", { className: `Puck ${getClassName31()}`, children: [
8688
- /* @__PURE__ */ jsx45(DragDropContext, { disableAutoScroll: dnd == null ? void 0 : dnd.disableAutoScroll, children: /* @__PURE__ */ jsx45(CustomPuck, { children: children || /* @__PURE__ */ jsx45(FrameProvider, { children: /* @__PURE__ */ jsx45(
8689
- "div",
8690
- {
8691
- className: getLayoutClassName({
8692
- leftSideBarVisible,
8693
- mounted,
8694
- rightSideBarVisible
8695
- }),
8696
- children: /* @__PURE__ */ jsxs21(
8697
- "div",
8698
- {
8699
- className: getLayoutClassName("inner"),
8700
- style: layoutOptions,
8701
- children: [
8702
- /* @__PURE__ */ jsx45(Header, {}),
8703
- /* @__PURE__ */ jsxs21(
8704
- Sidebar,
8705
- {
8706
- position: "left",
8707
- sidebarRef: leftSidebarRef,
8708
- isVisible: leftSideBarVisible,
8709
- onResize: setLeftWidth,
8710
- onResizeEnd: handleLeftSidebarResizeEnd,
8711
- children: [
8712
- /* @__PURE__ */ jsx45(SidebarSection, { title: "Components", noBorderTop: true, children: /* @__PURE__ */ jsx45(Components, {}) }),
8713
- /* @__PURE__ */ jsx45(SidebarSection, { title: "Outline", children: /* @__PURE__ */ jsx45(Outline, {}) })
8714
- ]
8715
- }
8716
- ),
8717
- /* @__PURE__ */ jsx45(Canvas, {}),
8718
- /* @__PURE__ */ jsx45(
8719
- Sidebar,
8720
- {
8721
- position: "right",
8722
- sidebarRef: rightSidebarRef,
8723
- isVisible: rightSideBarVisible,
8724
- onResize: setRightWidth,
8725
- onResizeEnd: handleRightSidebarResizeEnd,
8726
- children: /* @__PURE__ */ jsx45(FieldSideBar, {})
8727
- }
8728
- )
8729
- ]
8730
- }
8731
- )
8732
- }
8733
- ) }) }) }),
8734
- /* @__PURE__ */ jsx45("div", { id: "puck-portal-root", className: getClassName31("portal") })
8735
- ] });
9222
+ return /* @__PURE__ */ jsx51(appStoreContext.Provider, { value: appStore, children: /* @__PURE__ */ jsx51(UsePuckStoreContext.Provider, { value: uPuckStore, children }) });
8736
9223
  }
8737
9224
  function Puck(props) {
8738
- return /* @__PURE__ */ jsx45(PropsProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ jsx45(PuckProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ jsx45(PuckLayout, __spreadValues({}, props)) })) }));
9225
+ return /* @__PURE__ */ jsx51(PropsProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ jsx51(PuckProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ jsx51(Layout, { children: props.children }) })) }));
8739
9226
  }
8740
9227
  Puck.Components = Components;
8741
9228
  Puck.Fields = Fields;
@@ -8797,6 +9284,9 @@ export {
8797
9284
  createUsePuck,
8798
9285
  usePuck,
8799
9286
  useGetPuck,
9287
+ blocksPlugin,
9288
+ outlinePlugin,
9289
+ fieldsPlugin,
8800
9290
  Puck
8801
9291
  };
8802
9292
  /*! Bundled license information:
@@ -8896,6 +9386,14 @@ lucide-react/dist/esm/icons/ellipsis-vertical.js:
8896
9386
  * See the LICENSE file in the root directory of this source tree.
8897
9387
  *)
8898
9388
 
9389
+ lucide-react/dist/esm/icons/expand.js:
9390
+ (**
9391
+ * @license lucide-react v0.468.0 - ISC
9392
+ *
9393
+ * This source code is licensed under the ISC license.
9394
+ * See the LICENSE file in the root directory of this source tree.
9395
+ *)
9396
+
8899
9397
  lucide-react/dist/esm/icons/globe.js:
8900
9398
  (**
8901
9399
  * @license lucide-react v0.468.0 - ISC
@@ -8904,6 +9402,14 @@ lucide-react/dist/esm/icons/globe.js:
8904
9402
  * See the LICENSE file in the root directory of this source tree.
8905
9403
  *)
8906
9404
 
9405
+ lucide-react/dist/esm/icons/hammer.js:
9406
+ (**
9407
+ * @license lucide-react v0.468.0 - ISC
9408
+ *
9409
+ * This source code is licensed under the ISC license.
9410
+ * See the LICENSE file in the root directory of this source tree.
9411
+ *)
9412
+
8907
9413
  lucide-react/dist/esm/icons/hash.js:
8908
9414
  (**
8909
9415
  * @license lucide-react v0.468.0 - ISC
@@ -8960,6 +9466,22 @@ lucide-react/dist/esm/icons/lock.js:
8960
9466
  * See the LICENSE file in the root directory of this source tree.
8961
9467
  *)
8962
9468
 
9469
+ lucide-react/dist/esm/icons/maximize-2.js:
9470
+ (**
9471
+ * @license lucide-react v0.468.0 - ISC
9472
+ *
9473
+ * This source code is licensed under the ISC license.
9474
+ * See the LICENSE file in the root directory of this source tree.
9475
+ *)
9476
+
9477
+ lucide-react/dist/esm/icons/minimize-2.js:
9478
+ (**
9479
+ * @license lucide-react v0.468.0 - ISC
9480
+ *
9481
+ * This source code is licensed under the ISC license.
9482
+ * See the LICENSE file in the root directory of this source tree.
9483
+ *)
9484
+
8963
9485
  lucide-react/dist/esm/icons/monitor.js:
8964
9486
  (**
8965
9487
  * @license lucide-react v0.468.0 - ISC
@@ -8992,6 +9514,14 @@ lucide-react/dist/esm/icons/plus.js:
8992
9514
  * See the LICENSE file in the root directory of this source tree.
8993
9515
  *)
8994
9516
 
9517
+ lucide-react/dist/esm/icons/rectangle-ellipsis.js:
9518
+ (**
9519
+ * @license lucide-react v0.468.0 - ISC
9520
+ *
9521
+ * This source code is licensed under the ISC license.
9522
+ * See the LICENSE file in the root directory of this source tree.
9523
+ *)
9524
+
8995
9525
  lucide-react/dist/esm/icons/redo-2.js:
8996
9526
  (**
8997
9527
  * @license lucide-react v0.468.0 - ISC
@@ -9032,6 +9562,14 @@ lucide-react/dist/esm/icons/tablet.js:
9032
9562
  * See the LICENSE file in the root directory of this source tree.
9033
9563
  *)
9034
9564
 
9565
+ lucide-react/dist/esm/icons/toy-brick.js:
9566
+ (**
9567
+ * @license lucide-react v0.468.0 - ISC
9568
+ *
9569
+ * This source code is licensed under the ISC license.
9570
+ * See the LICENSE file in the root directory of this source tree.
9571
+ *)
9572
+
9035
9573
  lucide-react/dist/esm/icons/trash.js:
9036
9574
  (**
9037
9575
  * @license lucide-react v0.468.0 - ISC
@@ -9056,6 +9594,14 @@ lucide-react/dist/esm/icons/undo-2.js:
9056
9594
  * See the LICENSE file in the root directory of this source tree.
9057
9595
  *)
9058
9596
 
9597
+ lucide-react/dist/esm/icons/x.js:
9598
+ (**
9599
+ * @license lucide-react v0.468.0 - ISC
9600
+ *
9601
+ * This source code is licensed under the ISC license.
9602
+ * See the LICENSE file in the root directory of this source tree.
9603
+ *)
9604
+
9059
9605
  lucide-react/dist/esm/icons/zoom-in.js:
9060
9606
  (**
9061
9607
  * @license lucide-react v0.468.0 - ISC