@measured/puck 0.20.0-canary.755737e8 → 0.20.0-canary.ba585f93

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -458,20 +458,6 @@ var Globe = createLucideIcon("Globe", [
458
458
  ["path", { d: "M2 12h20", key: "9i4pu4" }]
459
459
  ]);
460
460
 
461
- // ../../node_modules/lucide-react/dist/esm/icons/hammer.js
462
- init_react_import();
463
- var Hammer = createLucideIcon("Hammer", [
464
- ["path", { d: "m15 12-8.373 8.373a1 1 0 1 1-3-3L12 9", key: "eefl8a" }],
465
- ["path", { d: "m18 15 4-4", key: "16gjal" }],
466
- [
467
- "path",
468
- {
469
- 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",
470
- key: "b7pghm"
471
- }
472
- ]
473
- ]);
474
-
475
461
  // ../../node_modules/lucide-react/dist/esm/icons/hash.js
476
462
  init_react_import();
477
463
  var Hash = createLucideIcon("Hash", [
@@ -619,14 +605,6 @@ var Tablet = createLucideIcon("Tablet", [
619
605
  ["line", { x1: "12", x2: "12.01", y1: "18", y2: "18", key: "1dp563" }]
620
606
  ]);
621
607
 
622
- // ../../node_modules/lucide-react/dist/esm/icons/toy-brick.js
623
- init_react_import();
624
- var ToyBrick = createLucideIcon("ToyBrick", [
625
- ["rect", { width: "18", height: "12", x: "3", y: "8", rx: "1", key: "158fvp" }],
626
- ["path", { d: "M10 8V5c0-.6-.4-1-1-1H6a1 1 0 0 0-1 1v3", key: "s0042v" }],
627
- ["path", { d: "M19 8V5c0-.6-.4-1-1-1h-3a1 1 0 0 0-1 1v3", key: "9wmeh2" }]
628
- ]);
629
-
630
608
  // ../../node_modules/lucide-react/dist/esm/icons/trash.js
631
609
  init_react_import();
632
610
  var Trash = createLucideIcon("Trash", [
@@ -1649,8 +1627,8 @@ var migrations = [
1649
1627
  return data;
1650
1628
  },
1651
1629
  // Migrate zones to slots
1652
- (data, config) => {
1653
- var _a;
1630
+ (data, config, migrationOptions) => {
1631
+ var _a, _b;
1654
1632
  if (!config) return data;
1655
1633
  console.log("Migrating DropZones to slots...");
1656
1634
  const updatedItems = {};
@@ -1658,13 +1636,13 @@ var migrations = [
1658
1636
  const { indexes } = walkAppState(appState, config);
1659
1637
  const deletedCompounds = [];
1660
1638
  walkAppState(appState, config, (content, zoneCompound, zoneType) => {
1661
- var _a2, _b, _c;
1639
+ var _a2, _b2, _c;
1662
1640
  if (zoneType === "dropzone") {
1663
1641
  const [id, slotName] = zoneCompound.split(":");
1664
1642
  const nodeData = indexes.nodes[id].data;
1665
1643
  const componentType = nodeData.type;
1666
1644
  const configForComponent = id === "root" ? config.root : config.components[componentType];
1667
- if (((_b = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b.type) === "slot") {
1645
+ if (((_b2 = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b2.type) === "slot") {
1668
1646
  updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
1669
1647
  props: __spreadProps(__spreadValues(__spreadValues({}, nodeData.props), (_c = updatedItems[id]) == null ? void 0 : _c.props), {
1670
1648
  [slotName]: content
@@ -1693,7 +1671,49 @@ var migrations = [
1693
1671
  );
1694
1672
  (_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
1695
1673
  });
1696
- Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
1674
+ if (migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) {
1675
+ const unmigratedZonesGrouped = {};
1676
+ Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
1677
+ var _a2;
1678
+ const [componentId, propName] = zoneCompound.split(":");
1679
+ const content = (_a2 = updated.data.zones) == null ? void 0 : _a2[zoneCompound];
1680
+ if (!content) {
1681
+ return;
1682
+ }
1683
+ if (!unmigratedZonesGrouped[componentId]) {
1684
+ unmigratedZonesGrouped[componentId] = {};
1685
+ }
1686
+ if (!unmigratedZonesGrouped[componentId][propName]) {
1687
+ unmigratedZonesGrouped[componentId][propName] = content;
1688
+ }
1689
+ });
1690
+ Object.keys(unmigratedZonesGrouped).forEach((componentId) => {
1691
+ updated.data = walkTree(updated.data, config, (content) => {
1692
+ return content.map((child) => {
1693
+ var _a2;
1694
+ if (child.props.id !== componentId) {
1695
+ return child;
1696
+ }
1697
+ const migrateFn = (_a2 = migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) == null ? void 0 : _a2[child.type];
1698
+ if (!migrateFn) {
1699
+ return child;
1700
+ }
1701
+ const zones = unmigratedZonesGrouped[componentId];
1702
+ const migratedProps = migrateFn(child.props, zones);
1703
+ Object.keys(zones).forEach((propName) => {
1704
+ var _a3;
1705
+ const zoneCompound = `${componentId}:${propName}`;
1706
+ console.log(`\u2713 Success: Migrated "${zoneCompound}" DropZone`);
1707
+ (_a3 = updated.data.zones) == null ? true : delete _a3[zoneCompound];
1708
+ });
1709
+ return __spreadProps(__spreadValues({}, child), {
1710
+ props: migratedProps
1711
+ });
1712
+ });
1713
+ });
1714
+ });
1715
+ }
1716
+ Object.keys((_b = updated.data.zones) != null ? _b : {}).forEach((zoneCompound) => {
1697
1717
  const [_, propName] = zoneCompound.split(":");
1698
1718
  throw new Error(
1699
1719
  `Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
@@ -1703,9 +1723,9 @@ var migrations = [
1703
1723
  return updated.data;
1704
1724
  }
1705
1725
  ];
1706
- function migrate(data, config) {
1726
+ function migrate(data, config, migrationOptions) {
1707
1727
  return migrations == null ? void 0 : migrations.reduce(
1708
- (acc, migration) => migration(acc, config),
1728
+ (acc, migration) => migration(acc, config, migrationOptions),
1709
1729
  data
1710
1730
  );
1711
1731
  }
@@ -2202,11 +2222,18 @@ var monitorHotkeys = (doc) => {
2202
2222
  }
2203
2223
  }
2204
2224
  };
2225
+ const onVisibilityChanged = (e) => {
2226
+ if (document.visibilityState === "hidden") {
2227
+ useHotkeyStore.getState().reset();
2228
+ }
2229
+ };
2205
2230
  doc.addEventListener("keydown", onKeyDown);
2206
2231
  doc.addEventListener("keyup", onKeyUp);
2232
+ doc.addEventListener("visibilitychange", onVisibilityChanged);
2207
2233
  return () => {
2208
2234
  doc.removeEventListener("keydown", onKeyDown);
2209
2235
  doc.removeEventListener("keyup", onKeyUp);
2236
+ doc.removeEventListener("visibilitychange", onVisibilityChanged);
2210
2237
  };
2211
2238
  };
2212
2239
  var useMonitorHotkeys = () => {
@@ -2301,7 +2328,7 @@ var createHistorySlice = (set, get) => {
2301
2328
  const { dispatch, history } = get();
2302
2329
  dispatch({
2303
2330
  type: "set",
2304
- state: ((_a = history.histories[history.histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
2331
+ state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
2305
2332
  });
2306
2333
  set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
2307
2334
  },
@@ -3986,6 +4013,7 @@ var ExternalInput = ({
3986
4013
  hasFilterFields && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: getClassNameModal("searchActionIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3987
4014
  IconButton,
3988
4015
  {
4016
+ type: "button",
3989
4017
  title: "Toggle filters",
3990
4018
  onClick: (e) => {
3991
4019
  e.preventDefault();
@@ -4333,9 +4361,8 @@ var ObjectField = ({
4333
4361
  readOnly,
4334
4362
  children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: getClassName14(), children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("fieldset", { className: getClassName14("fieldset"), children: Object.keys(field.objectFields).map((subName) => {
4335
4363
  const subField = field.objectFields[subName];
4336
- const subPath = `${name}.${subName}`;
4337
- const localSubPath = `${localName || name}.${subName}`;
4338
- const subReadOnly = readOnly ? readOnly : readOnlyFields[localSubPath];
4364
+ const subPath = `${localName}.${subName}`;
4365
+ const subReadOnly = readOnly ? readOnly : readOnlyFields[subPath];
4339
4366
  const label2 = subField.label || subName;
4340
4367
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
4341
4368
  NestedFieldProvider,
@@ -4434,7 +4461,7 @@ var FieldLabelInternal = ({
4434
4461
  );
4435
4462
  };
4436
4463
  function AutoFieldInternal(props) {
4437
- var _a, _b, _c, _d, _e, _f, _g, _h;
4464
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
4438
4465
  const dispatch = useAppStore((s) => s.dispatch);
4439
4466
  const overrides = useAppStore((s) => s.overrides);
4440
4467
  const readOnly = useAppStore((s) => {
@@ -4506,21 +4533,23 @@ function AutoFieldInternal(props) {
4506
4533
  if (field.type === "slot") {
4507
4534
  return null;
4508
4535
  }
4536
+ let children = null;
4537
+ let FieldComponent;
4509
4538
  if (field.type === "custom") {
4510
4539
  if (!field.render) {
4511
4540
  return null;
4512
4541
  }
4513
- const CustomField = field.render;
4514
- return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassNameWrapper(), onFocus, onBlur, children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName15(), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(CustomField, __spreadValues({}, mergedProps)) }) });
4542
+ FieldComponent = field.render;
4543
+ } else {
4544
+ children = defaultFields[field.type](mergedProps);
4545
+ FieldComponent = render[field.type];
4515
4546
  }
4516
- const children = defaultFields[field.type](mergedProps);
4517
- const Render3 = render[field.type];
4518
4547
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4519
4548
  NestedFieldContext.Provider,
4520
4549
  {
4521
4550
  value: {
4522
4551
  readOnlyFields: nestedFieldContext.readOnlyFields || readOnly || {},
4523
- localName: nestedFieldContext.localName
4552
+ localName: (_i = nestedFieldContext.localName) != null ? _i : mergedProps.name
4524
4553
  },
4525
4554
  children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
4526
4555
  "div",
@@ -4531,7 +4560,7 @@ function AutoFieldInternal(props) {
4531
4560
  onClick: (e) => {
4532
4561
  e.stopPropagation();
4533
4562
  },
4534
- children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Render3, __spreadProps(__spreadValues({}, mergedProps), { children }))
4563
+ children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(FieldComponent, __spreadProps(__spreadValues({}, mergedProps), { children }))
4535
4564
  }
4536
4565
  )
4537
4566
  }
@@ -4670,19 +4699,9 @@ var DropZoneProvider = ({
4670
4699
  },
4671
4700
  [dispatch]
4672
4701
  );
4673
- const unregisterZone = (0, import_react25.useCallback)(
4674
- (zoneCompound) => {
4675
- dispatch({
4676
- type: "unregisterZone",
4677
- zone: zoneCompound
4678
- });
4679
- },
4680
- [dispatch]
4681
- );
4682
4702
  const memoValue = (0, import_react25.useMemo)(
4683
4703
  () => __spreadValues({
4684
- registerZone,
4685
- unregisterZone
4704
+ registerZone
4686
4705
  }, value),
4687
4706
  [value]
4688
4707
  );
@@ -5054,7 +5073,8 @@ var DraggableComponent = ({
5054
5073
  el.removeEventListener("mouseout", _onMouseOut);
5055
5074
  };
5056
5075
  }, [
5057
- ref,
5076
+ ref.current,
5077
+ // Remount attributes if the element changes
5058
5078
  onClick,
5059
5079
  containsActiveZone,
5060
5080
  zoneCompound,
@@ -5556,7 +5576,8 @@ var DropZoneChild = ({
5556
5576
  return {
5557
5577
  type: preview.componentType,
5558
5578
  props: preview.props,
5559
- previewType: preview.type
5579
+ previewType: preview.type,
5580
+ element: preview.element
5560
5581
  };
5561
5582
  }
5562
5583
  return null;
@@ -5589,6 +5610,12 @@ var DropZoneChild = ({
5589
5610
  let label = (_b = (_a = componentConfig == null ? void 0 : componentConfig.label) != null ? _a : item == null ? void 0 : item.type.toString()) != null ? _b : "Component";
5590
5611
  const renderPreview = (0, import_react35.useMemo)(
5591
5612
  () => function Preview3() {
5613
+ if (item && "element" in item && item.element) {
5614
+ return (
5615
+ // Safe to use this since the HTML is set by the user
5616
+ /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { dangerouslySetInnerHTML: { __html: item.element.outerHTML } })
5617
+ );
5618
+ }
5592
5619
  return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(DrawerItemInner, { name: label, children: overrides.componentItem });
5593
5620
  },
5594
5621
  [componentId, label, overrides]
@@ -5664,6 +5691,7 @@ var DropZoneEdit = (0, import_react35.forwardRef)(
5664
5691
  collisionAxis
5665
5692
  }, userRef) {
5666
5693
  const ctx = (0, import_react35.useContext)(dropZoneContext);
5694
+ const appStoreApi = useAppStoreApi();
5667
5695
  const {
5668
5696
  // These all need setting via context
5669
5697
  areaId,
@@ -5705,13 +5733,8 @@ var DropZoneEdit = (0, import_react35.forwardRef)(
5705
5733
  if (ctx == null ? void 0 : ctx.registerZone) {
5706
5734
  ctx == null ? void 0 : ctx.registerZone(zoneCompound);
5707
5735
  }
5708
- return () => {
5709
- if (ctx == null ? void 0 : ctx.unregisterZone) {
5710
- ctx == null ? void 0 : ctx.unregisterZone(zoneCompound);
5711
- }
5712
- };
5713
5736
  }
5714
- }, [zoneType]);
5737
+ }, [zoneType, appStoreApi]);
5715
5738
  (0, import_react35.useEffect)(() => {
5716
5739
  if (zoneType === "dropzone") {
5717
5740
  if (zoneCompound !== rootDroppableId) {
@@ -5876,25 +5899,19 @@ var DropZoneRender2 = (0, import_react35.forwardRef)(
5876
5899
  const ctx = (0, import_react35.useContext)(dropZoneContext);
5877
5900
  const { areaId = "root" } = ctx || {};
5878
5901
  const { config, data, metadata } = (0, import_react35.useContext)(renderContext);
5879
- let zoneCompound = rootDroppableId;
5902
+ let zoneCompound = `${areaId}:${zone}`;
5880
5903
  let content = (data == null ? void 0 : data.content) || [];
5881
5904
  (0, import_react35.useEffect)(() => {
5882
5905
  if (!content) {
5883
5906
  if (ctx == null ? void 0 : ctx.registerZone) {
5884
5907
  ctx == null ? void 0 : ctx.registerZone(zoneCompound);
5885
5908
  }
5886
- return () => {
5887
- if (ctx == null ? void 0 : ctx.unregisterZone) {
5888
- ctx == null ? void 0 : ctx.unregisterZone(zoneCompound);
5889
- }
5890
- };
5891
5909
  }
5892
5910
  }, [content]);
5893
5911
  if (!data || !config) {
5894
5912
  return null;
5895
5913
  }
5896
- if (areaId !== rootAreaId && zone !== rootZone) {
5897
- zoneCompound = `${areaId}:${zone}`;
5914
+ if (zoneCompound !== rootDroppableId) {
5898
5915
  content = setupZone(data, zoneCompound).zones[zoneCompound];
5899
5916
  }
5900
5917
  return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("div", { className, style, ref, children: content.map((item) => {
@@ -6149,6 +6166,7 @@ var findDeepestCandidate = (position, manager) => {
6149
6166
  });
6150
6167
  filteredCandidates.reverse();
6151
6168
  const primaryCandidate = filteredCandidates[0];
6169
+ if (!primaryCandidate) return { zone: null, area: null };
6152
6170
  const primaryCandidateData = primaryCandidate.data;
6153
6171
  const primaryCandidateIsComponent = "containsActiveZone" in primaryCandidateData;
6154
6172
  const zone = getZoneId2(primaryCandidate);
@@ -6553,6 +6571,7 @@ var DragDropContextClient = ({
6553
6571
  type: "insert",
6554
6572
  index: targetIndex,
6555
6573
  zone: targetZone,
6574
+ element: source.element,
6556
6575
  props: {
6557
6576
  id: source.id.toString()
6558
6577
  }
@@ -6578,7 +6597,8 @@ var DragDropContextClient = ({
6578
6597
  type: "move",
6579
6598
  index: targetIndex,
6580
6599
  zone: targetZone,
6581
- props: item.props
6600
+ props: item.props,
6601
+ element: source.element
6582
6602
  }
6583
6603
  }
6584
6604
  });
@@ -6608,7 +6628,8 @@ var DragDropContextClient = ({
6608
6628
  type: "move",
6609
6629
  index: sourceData.index,
6610
6630
  zone: sourceData.zone,
6611
- props: item.props
6631
+ props: item.props,
6632
+ element: source.element
6612
6633
  }
6613
6634
  }
6614
6635
  });
@@ -6791,24 +6812,121 @@ Drawer.Item = DrawerItem;
6791
6812
 
6792
6813
  // components/Puck/index.tsx
6793
6814
  init_react_import();
6794
- var import_react57 = require("react");
6815
+ var import_react56 = require("react");
6816
+
6817
+ // components/SidebarSection/index.tsx
6818
+ init_react_import();
6819
+
6820
+ // css-module:/home/runner/work/puck/puck/packages/core/components/SidebarSection/styles.module.css#css-module
6821
+ init_react_import();
6822
+ var styles_module_default13 = { "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" };
6823
+
6824
+ // lib/use-breadcrumbs.ts
6825
+ init_react_import();
6826
+ var import_react41 = require("react");
6827
+ var useBreadcrumbs = (renderCount) => {
6828
+ const selectedId = useAppStore((s) => {
6829
+ var _a;
6830
+ return (_a = s.selectedItem) == null ? void 0 : _a.props.id;
6831
+ });
6832
+ const config = useAppStore((s) => s.config);
6833
+ const path = useAppStore((s) => {
6834
+ var _a;
6835
+ return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
6836
+ });
6837
+ const appStore = useAppStoreApi();
6838
+ return (0, import_react41.useMemo)(() => {
6839
+ const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
6840
+ var _a, _b, _c;
6841
+ const [componentId] = zoneCompound.split(":");
6842
+ if (componentId === "root") {
6843
+ return {
6844
+ label: "Page",
6845
+ selector: null
6846
+ };
6847
+ }
6848
+ const node = appStore.getState().state.indexes.nodes[componentId];
6849
+ const parentId = node.path[node.path.length - 1];
6850
+ const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
6851
+ const index = contentIds.indexOf(componentId);
6852
+ const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
6853
+ return {
6854
+ label,
6855
+ selector: node ? {
6856
+ index,
6857
+ zone: node.path[node.path.length - 1]
6858
+ } : null
6859
+ };
6860
+ })) || [];
6861
+ if (renderCount) {
6862
+ return breadcrumbs.slice(breadcrumbs.length - renderCount);
6863
+ }
6864
+ return breadcrumbs;
6865
+ }, [path, renderCount]);
6866
+ };
6867
+
6868
+ // components/SidebarSection/index.tsx
6869
+ var import_jsx_runtime28 = require("react/jsx-runtime");
6870
+ var getClassName19 = get_class_name_factory_default("SidebarSection", styles_module_default13);
6871
+ var SidebarSection = ({
6872
+ children,
6873
+ title,
6874
+ background,
6875
+ showBreadcrumbs,
6876
+ noBorderTop,
6877
+ noPadding,
6878
+ isLoading
6879
+ }) => {
6880
+ const setUi = useAppStore((s) => s.setUi);
6881
+ const breadcrumbs = useBreadcrumbs(1);
6882
+ return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
6883
+ "div",
6884
+ {
6885
+ className: getClassName19({ noBorderTop, noPadding }),
6886
+ style: { background },
6887
+ children: [
6888
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: getClassName19("title"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: getClassName19("breadcrumbs"), children: [
6889
+ showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: getClassName19("breadcrumb"), children: [
6890
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
6891
+ "button",
6892
+ {
6893
+ type: "button",
6894
+ className: getClassName19("breadcrumbLabel"),
6895
+ onClick: () => setUi({ itemSelector: breadcrumb.selector }),
6896
+ children: breadcrumb.label
6897
+ }
6898
+ ),
6899
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(ChevronRight, { size: 16 })
6900
+ ] }, i)) : null,
6901
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: getClassName19("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Heading, { rank: "2", size: "xs", children: title }) })
6902
+ ] }) }),
6903
+ /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: getClassName19("content"), children }),
6904
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: getClassName19("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Loader, { size: 32 }) })
6905
+ ]
6906
+ }
6907
+ );
6908
+ };
6909
+
6910
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/styles.module.css#css-module
6911
+ init_react_import();
6912
+ var styles_module_default14 = { "Puck": "_Puck_dnlfp_19", "Puck-portal": "_Puck-portal_dnlfp_31", "PuckLayout-inner": "_PuckLayout-inner_dnlfp_38", "PuckLayout--mounted": "_PuckLayout--mounted_dnlfp_50", "PuckLayout--leftSideBarVisible": "_PuckLayout--leftSideBarVisible_dnlfp_54", "PuckLayout--rightSideBarVisible": "_PuckLayout--rightSideBarVisible_dnlfp_60", "PuckLayout-mounted": "_PuckLayout-mounted_dnlfp_74", "PuckLayout": "_PuckLayout_dnlfp_38", "PuckLayout-leftSideBar": "_PuckLayout-leftSideBar_dnlfp_115", "PuckLayout-rightSideBar": "_PuckLayout-rightSideBar_dnlfp_124" };
6795
6913
 
6796
6914
  // components/Puck/components/Fields/index.tsx
6797
6915
  init_react_import();
6798
6916
 
6799
6917
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Fields/styles.module.css#css-module
6800
6918
  init_react_import();
6801
- var styles_module_default13 = { "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" };
6919
+ var styles_module_default15 = { "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" };
6802
6920
 
6803
6921
  // components/Puck/components/Fields/index.tsx
6804
- var import_react41 = require("react");
6922
+ var import_react42 = require("react");
6805
6923
  var import_shallow5 = require("zustand/react/shallow");
6806
- var import_jsx_runtime28 = require("react/jsx-runtime");
6807
- var getClassName19 = get_class_name_factory_default("PuckFields", styles_module_default13);
6924
+ var import_jsx_runtime29 = require("react/jsx-runtime");
6925
+ var getClassName20 = get_class_name_factory_default("PuckFields", styles_module_default15);
6808
6926
  var DefaultFields = ({
6809
6927
  children
6810
6928
  }) => {
6811
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_jsx_runtime28.Fragment, { children });
6929
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(import_jsx_runtime29.Fragment, { children });
6812
6930
  };
6813
6931
  var createOnChange = (fieldName, appStore) => (value, updatedUi) => __async(void 0, null, function* () {
6814
6932
  let currentProps;
@@ -6874,13 +6992,13 @@ var FieldsChild = ({ fieldName }) => {
6874
6992
  })
6875
6993
  );
6876
6994
  const appStore = useAppStoreApi();
6877
- const onChange = (0, import_react41.useCallback)(createOnChange(fieldName, appStore), [
6995
+ const onChange = (0, import_react42.useCallback)(createOnChange(fieldName, appStore), [
6878
6996
  fieldName
6879
6997
  ]);
6880
6998
  const { visible = true } = field != null ? field : {};
6881
6999
  if (!field || !id || !visible) return null;
6882
7000
  if (field.type === "slot") return null;
6883
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: getClassName19("field"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
7001
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: getClassName20("field"), children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
6884
7002
  AutoFieldPrivate,
6885
7003
  {
6886
7004
  field,
@@ -6892,7 +7010,7 @@ var FieldsChild = ({ fieldName }) => {
6892
7010
  }
6893
7011
  ) }, id);
6894
7012
  };
6895
- var FieldsChildMemo = (0, import_react41.memo)(FieldsChild);
7013
+ var FieldsChildMemo = (0, import_react42.memo)(FieldsChild);
6896
7014
  var FieldsInternal = ({ wrapFields = true }) => {
6897
7015
  const overrides = useAppStore((s) => s.overrides);
6898
7016
  const componentResolving = useAppStore((s) => {
@@ -6917,40 +7035,40 @@ var FieldsInternal = ({ wrapFields = true }) => {
6917
7035
  })
6918
7036
  );
6919
7037
  const isLoading = fieldsLoading || componentResolving;
6920
- const Wrapper = (0, import_react41.useMemo)(() => overrides.fields || DefaultFields, [overrides]);
6921
- return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
7038
+ const Wrapper = (0, import_react42.useMemo)(() => overrides.fields || DefaultFields, [overrides]);
7039
+ return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
6922
7040
  "form",
6923
7041
  {
6924
- className: getClassName19({ wrapFields }),
7042
+ className: getClassName20({ wrapFields }),
6925
7043
  onSubmit: (e) => {
6926
7044
  e.preventDefault();
6927
7045
  },
6928
7046
  children: [
6929
- /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Wrapper, { isLoading, itemSelector, children: fieldNames.map((fieldName) => /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(FieldsChildMemo, { fieldName }, fieldName)) }),
6930
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: getClassName19("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: getClassName19("loadingOverlayInner"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Loader, { size: 16 }) }) })
7047
+ /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(Wrapper, { isLoading, itemSelector, children: fieldNames.map((fieldName) => /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(FieldsChildMemo, { fieldName }, fieldName)) }),
7048
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: getClassName20("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: getClassName20("loadingOverlayInner"), children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(Loader, { size: 16 }) }) })
6931
7049
  ]
6932
7050
  }
6933
7051
  );
6934
7052
  };
6935
- var Fields = (0, import_react41.memo)(FieldsInternal);
7053
+ var Fields = (0, import_react42.memo)(FieldsInternal);
6936
7054
 
6937
7055
  // components/Puck/components/Components/index.tsx
6938
7056
  init_react_import();
6939
7057
 
6940
7058
  // lib/use-component-list.tsx
6941
7059
  init_react_import();
6942
- var import_react42 = require("react");
7060
+ var import_react43 = require("react");
6943
7061
 
6944
7062
  // components/ComponentList/index.tsx
6945
7063
  init_react_import();
6946
7064
 
6947
7065
  // css-module:/home/runner/work/puck/puck/packages/core/components/ComponentList/styles.module.css#css-module
6948
7066
  init_react_import();
6949
- 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" };
7067
+ var styles_module_default16 = { "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" };
6950
7068
 
6951
7069
  // components/ComponentList/index.tsx
6952
- var import_jsx_runtime29 = require("react/jsx-runtime");
6953
- var getClassName20 = get_class_name_factory_default("ComponentList", styles_module_default14);
7070
+ var import_jsx_runtime30 = require("react/jsx-runtime");
7071
+ var getClassName21 = get_class_name_factory_default("ComponentList", styles_module_default16);
6954
7072
  var ComponentListItem = ({
6955
7073
  name,
6956
7074
  label
@@ -6961,7 +7079,7 @@ var ComponentListItem = ({
6961
7079
  type: name
6962
7080
  }).insert
6963
7081
  );
6964
- return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(Drawer.Item, { label, name, isDragDisabled: !canInsert, children: overrides.componentItem });
7082
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Drawer.Item, { label, name, isDragDisabled: !canInsert, children: overrides.componentItem });
6965
7083
  };
6966
7084
  var ComponentList = ({
6967
7085
  children,
@@ -6972,12 +7090,12 @@ var ComponentList = ({
6972
7090
  const setUi = useAppStore((s) => s.setUi);
6973
7091
  const componentList = useAppStore((s) => s.state.ui.componentList);
6974
7092
  const { expanded = true } = componentList[id] || {};
6975
- return /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)("div", { className: getClassName20({ isExpanded: expanded }), children: [
6976
- title && /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
7093
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)("div", { className: getClassName21({ isExpanded: expanded }), children: [
7094
+ title && /* @__PURE__ */ (0, import_jsx_runtime30.jsxs)(
6977
7095
  "button",
6978
7096
  {
6979
7097
  type: "button",
6980
- className: getClassName20("title"),
7098
+ className: getClassName21("title"),
6981
7099
  onClick: () => setUi({
6982
7100
  componentList: __spreadProps(__spreadValues({}, componentList), {
6983
7101
  [id]: __spreadProps(__spreadValues({}, componentList[id]), {
@@ -6987,14 +7105,14 @@ var ComponentList = ({
6987
7105
  }),
6988
7106
  title: expanded ? `Collapse${title ? ` ${title}` : ""}` : `Expand${title ? ` ${title}` : ""}`,
6989
7107
  children: [
6990
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { children: title }),
6991
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: getClassName20("titleIcon"), children: expanded ? /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(ChevronUp, { size: 12 }) : /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(ChevronDown, { size: 12 }) })
7108
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { children: title }),
7109
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: getClassName21("titleIcon"), children: expanded ? /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(ChevronUp, { size: 12 }) : /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(ChevronDown, { size: 12 }) })
6992
7110
  ]
6993
7111
  }
6994
7112
  ),
6995
- /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: getClassName20("content"), children: /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(Drawer, { children: children || Object.keys(config.components).map((componentKey) => {
7113
+ /* @__PURE__ */ (0, import_jsx_runtime30.jsx)("div", { className: getClassName21("content"), children: /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Drawer, { children: children || Object.keys(config.components).map((componentKey) => {
6996
7114
  var _a;
6997
- return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)(
7115
+ return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
6998
7116
  ComponentListItem,
6999
7117
  {
7000
7118
  label: (_a = config.components[componentKey]["label"]) != null ? _a : componentKey,
@@ -7008,12 +7126,12 @@ var ComponentList = ({
7008
7126
  ComponentList.Item = ComponentListItem;
7009
7127
 
7010
7128
  // lib/use-component-list.tsx
7011
- var import_jsx_runtime30 = require("react/jsx-runtime");
7129
+ var import_jsx_runtime31 = require("react/jsx-runtime");
7012
7130
  var useComponentList = () => {
7013
- const [componentList, setComponentList] = (0, import_react42.useState)();
7131
+ const [componentList, setComponentList] = (0, import_react43.useState)();
7014
7132
  const config = useAppStore((s) => s.config);
7015
7133
  const uiComponentList = useAppStore((s) => s.state.ui.componentList);
7016
- (0, import_react42.useEffect)(() => {
7134
+ (0, import_react43.useEffect)(() => {
7017
7135
  var _a, _b, _c;
7018
7136
  if (Object.keys(uiComponentList).length > 0) {
7019
7137
  const matchedComponents = [];
@@ -7023,7 +7141,7 @@ var useComponentList = () => {
7023
7141
  if (category.visible === false || !category.components) {
7024
7142
  return null;
7025
7143
  }
7026
- return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
7144
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
7027
7145
  ComponentList,
7028
7146
  {
7029
7147
  id: categoryKey,
@@ -7032,7 +7150,7 @@ var useComponentList = () => {
7032
7150
  var _a2;
7033
7151
  matchedComponents.push(componentName);
7034
7152
  const componentConf = config.components[componentName] || {};
7035
- return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
7153
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
7036
7154
  ComponentList.Item,
7037
7155
  {
7038
7156
  label: (_a2 = componentConf["label"]) != null ? _a2 : componentName,
@@ -7052,7 +7170,7 @@ var useComponentList = () => {
7052
7170
  );
7053
7171
  if (remainingComponents.length > 0 && !((_a = uiComponentList.other) == null ? void 0 : _a.components) && ((_b = uiComponentList.other) == null ? void 0 : _b.visible) !== false) {
7054
7172
  _componentList.push(
7055
- /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
7173
+ /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
7056
7174
  ComponentList,
7057
7175
  {
7058
7176
  id: "other",
@@ -7060,7 +7178,7 @@ var useComponentList = () => {
7060
7178
  children: remainingComponents.map((componentName, i) => {
7061
7179
  var _a2;
7062
7180
  const componentConf = config.components[componentName] || {};
7063
- return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(
7181
+ return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
7064
7182
  ComponentList.Item,
7065
7183
  {
7066
7184
  name: componentName,
@@ -7082,30 +7200,37 @@ var useComponentList = () => {
7082
7200
  };
7083
7201
 
7084
7202
  // components/Puck/components/Components/index.tsx
7085
- var import_react43 = require("react");
7086
- var import_jsx_runtime31 = require("react/jsx-runtime");
7203
+ var import_react44 = require("react");
7204
+ var import_jsx_runtime32 = require("react/jsx-runtime");
7087
7205
  var Components = () => {
7088
7206
  const overrides = useAppStore((s) => s.overrides);
7089
7207
  const componentList = useComponentList();
7090
- const Wrapper = (0, import_react43.useMemo)(() => overrides.components || "div", [overrides]);
7091
- return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(ComponentList, { id: "all" }) });
7208
+ const Wrapper = (0, import_react44.useMemo)(() => overrides.components || "div", [overrides]);
7209
+ return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(ComponentList, { id: "all" }) });
7092
7210
  };
7093
7211
 
7094
7212
  // components/Puck/components/Preview/index.tsx
7095
7213
  init_react_import();
7096
- var import_react45 = require("react");
7214
+ var import_react46 = require("react");
7097
7215
 
7098
7216
  // components/AutoFrame/index.tsx
7099
7217
  init_react_import();
7100
- var import_react44 = require("react");
7218
+ var import_react45 = require("react");
7101
7219
  var import_object_hash = __toESM(require("object-hash"));
7102
7220
  var import_react_dom3 = require("react-dom");
7103
- var import_jsx_runtime32 = require("react/jsx-runtime");
7221
+ var import_jsx_runtime33 = require("react/jsx-runtime");
7104
7222
  var styleSelector = 'style, link[rel="stylesheet"]';
7105
7223
  var collectStyles = (doc) => {
7106
7224
  const collected = [];
7107
7225
  doc.querySelectorAll(styleSelector).forEach((style) => {
7108
- collected.push(style);
7226
+ if (style.tagName === "STYLE") {
7227
+ const hasContent = !!style.innerHTML.trim();
7228
+ if (hasContent) {
7229
+ collected.push(style);
7230
+ }
7231
+ } else {
7232
+ collected.push(style);
7233
+ }
7109
7234
  });
7110
7235
  return collected;
7111
7236
  };
@@ -7118,7 +7243,7 @@ var getStyleSheet = (el) => {
7118
7243
  var getStyles = (styleSheet) => {
7119
7244
  if (styleSheet) {
7120
7245
  try {
7121
- return [...styleSheet.cssRules].map((rule) => rule.cssText).join("");
7246
+ return [...Array.from(styleSheet.cssRules)].map((rule) => rule.cssText).join("");
7122
7247
  } catch (e) {
7123
7248
  console.warn(
7124
7249
  "Access to stylesheet %s is denied. Ignoring\u2026",
@@ -7143,7 +7268,7 @@ var CopyHostStyles = ({
7143
7268
  onStylesLoaded = () => null
7144
7269
  }) => {
7145
7270
  const { document: doc, window: win } = useFrame();
7146
- (0, import_react44.useEffect)(() => {
7271
+ (0, import_react45.useEffect)(() => {
7147
7272
  if (!win || !doc) {
7148
7273
  return () => {
7149
7274
  };
@@ -7300,10 +7425,10 @@ var CopyHostStyles = ({
7300
7425
  observer.disconnect();
7301
7426
  };
7302
7427
  }, []);
7303
- return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(import_jsx_runtime32.Fragment, { children });
7428
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_jsx_runtime33.Fragment, { children });
7304
7429
  };
7305
- var autoFrameContext = (0, import_react44.createContext)({});
7306
- var useFrame = () => (0, import_react44.useContext)(autoFrameContext);
7430
+ var autoFrameContext = (0, import_react45.createContext)({});
7431
+ var useFrame = () => (0, import_react45.useContext)(autoFrameContext);
7307
7432
  function AutoFrame(_a) {
7308
7433
  var _b = _a, {
7309
7434
  children,
@@ -7324,11 +7449,11 @@ function AutoFrame(_a) {
7324
7449
  "onNotReady",
7325
7450
  "frameRef"
7326
7451
  ]);
7327
- const [loaded, setLoaded] = (0, import_react44.useState)(false);
7328
- const [ctx, setCtx] = (0, import_react44.useState)({});
7329
- const [mountTarget, setMountTarget] = (0, import_react44.useState)();
7330
- const [stylesLoaded, setStylesLoaded] = (0, import_react44.useState)(false);
7331
- (0, import_react44.useEffect)(() => {
7452
+ const [loaded, setLoaded] = (0, import_react45.useState)(false);
7453
+ const [ctx, setCtx] = (0, import_react45.useState)({});
7454
+ const [mountTarget, setMountTarget] = (0, import_react45.useState)();
7455
+ const [stylesLoaded, setStylesLoaded] = (0, import_react45.useState)(false);
7456
+ (0, import_react45.useEffect)(() => {
7332
7457
  var _a2;
7333
7458
  if (frameRef.current) {
7334
7459
  const doc = frameRef.current.contentDocument;
@@ -7347,7 +7472,7 @@ function AutoFrame(_a) {
7347
7472
  }
7348
7473
  }
7349
7474
  }, [frameRef, loaded, stylesLoaded]);
7350
- return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
7475
+ return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
7351
7476
  "iframe",
7352
7477
  __spreadProps(__spreadValues({}, props), {
7353
7478
  className,
@@ -7357,7 +7482,7 @@ function AutoFrame(_a) {
7357
7482
  onLoad: () => {
7358
7483
  setLoaded(true);
7359
7484
  },
7360
- children: /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(autoFrameContext.Provider, { value: ctx, children: loaded && mountTarget && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
7485
+ children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(autoFrameContext.Provider, { value: ctx, children: loaded && mountTarget && /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
7361
7486
  CopyHostStyles,
7362
7487
  {
7363
7488
  debug,
@@ -7373,14 +7498,14 @@ var AutoFrame_default = AutoFrame;
7373
7498
 
7374
7499
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Preview/styles.module.css#css-module
7375
7500
  init_react_import();
7376
- var styles_module_default15 = { "PuckPreview": "_PuckPreview_z2rgu_1", "PuckPreview-frame": "_PuckPreview-frame_z2rgu_6" };
7501
+ var styles_module_default17 = { "PuckPreview": "_PuckPreview_z2rgu_1", "PuckPreview-frame": "_PuckPreview-frame_z2rgu_6" };
7377
7502
 
7378
7503
  // components/Puck/components/Preview/index.tsx
7379
- var import_jsx_runtime33 = require("react/jsx-runtime");
7380
- var getClassName21 = get_class_name_factory_default("PuckPreview", styles_module_default15);
7504
+ var import_jsx_runtime34 = require("react/jsx-runtime");
7505
+ var getClassName22 = get_class_name_factory_default("PuckPreview", styles_module_default17);
7381
7506
  var useBubbleIframeEvents = (ref) => {
7382
7507
  const status = useAppStore((s) => s.status);
7383
- (0, import_react45.useEffect)(() => {
7508
+ (0, import_react46.useEffect)(() => {
7384
7509
  if (ref.current && status === "READY") {
7385
7510
  const iframe = ref.current;
7386
7511
  const handlePointerMove = (event) => {
@@ -7429,7 +7554,7 @@ var Preview2 = ({ id = "puck-preview" }) => {
7429
7554
  const renderData = useAppStore(
7430
7555
  (s) => s.state.ui.previewMode === "edit" ? null : s.state.data
7431
7556
  );
7432
- const Page = (0, import_react45.useCallback)(
7557
+ const Page = (0, import_react46.useCallback)(
7433
7558
  (pageProps) => {
7434
7559
  var _a, _b;
7435
7560
  const propsWithSlots = useSlots(
@@ -7439,15 +7564,15 @@ var Preview2 = ({ id = "puck-preview" }) => {
7439
7564
  );
7440
7565
  return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
7441
7566
  id: "puck-root"
7442
- }, propsWithSlots)) : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_jsx_runtime33.Fragment, { children: propsWithSlots.children });
7567
+ }, propsWithSlots)) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(import_jsx_runtime34.Fragment, { children: propsWithSlots.children });
7443
7568
  },
7444
7569
  [config]
7445
7570
  );
7446
- const Frame = (0, import_react45.useMemo)(() => overrides.iframe, [overrides]);
7571
+ const Frame = (0, import_react46.useMemo)(() => overrides.iframe, [overrides]);
7447
7572
  const rootProps = root.props || root;
7448
- const ref = (0, import_react45.useRef)(null);
7573
+ const ref = (0, import_react46.useRef)(null);
7449
7574
  useBubbleIframeEvents(ref);
7450
- const inner = !renderData ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
7575
+ const inner = !renderData ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7451
7576
  Page,
7452
7577
  __spreadProps(__spreadValues({}, rootProps), {
7453
7578
  puck: {
@@ -7457,28 +7582,28 @@ var Preview2 = ({ id = "puck-preview" }) => {
7457
7582
  metadata
7458
7583
  },
7459
7584
  editMode: true,
7460
- children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(DropZonePure, { zone: rootDroppableId })
7585
+ children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(DropZonePure, { zone: rootDroppableId })
7461
7586
  })
7462
- ) : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Render2, { data: renderData, config });
7463
- (0, import_react45.useEffect)(() => {
7587
+ ) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Render2, { data: renderData, config, metadata });
7588
+ (0, import_react46.useEffect)(() => {
7464
7589
  if (!iframe.enabled) {
7465
7590
  setStatus("READY");
7466
7591
  }
7467
7592
  }, [iframe.enabled]);
7468
- return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
7593
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7469
7594
  "div",
7470
7595
  {
7471
- className: getClassName21(),
7596
+ className: getClassName22(),
7472
7597
  id,
7473
7598
  "data-puck-preview": true,
7474
7599
  onClick: () => {
7475
7600
  dispatch({ type: "setUi", ui: { itemSelector: null } });
7476
7601
  },
7477
- children: iframe.enabled ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
7602
+ children: iframe.enabled ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7478
7603
  AutoFrame_default,
7479
7604
  {
7480
7605
  id: "preview-frame",
7481
- className: getClassName21("frame"),
7606
+ className: getClassName22("frame"),
7482
7607
  "data-rfd-iframe": true,
7483
7608
  onReady: () => {
7484
7609
  setStatus("READY");
@@ -7487,18 +7612,18 @@ var Preview2 = ({ id = "puck-preview" }) => {
7487
7612
  setStatus("MOUNTED");
7488
7613
  },
7489
7614
  frameRef: ref,
7490
- children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(autoFrameContext.Consumer, { children: ({ document: document2 }) => {
7615
+ children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(autoFrameContext.Consumer, { children: ({ document: document2 }) => {
7491
7616
  if (Frame) {
7492
- return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Frame, { document: document2, children: inner });
7617
+ return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Frame, { document: document2, children: inner });
7493
7618
  }
7494
7619
  return inner;
7495
7620
  } })
7496
7621
  }
7497
- ) : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
7622
+ ) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7498
7623
  "div",
7499
7624
  {
7500
7625
  id: "preview-frame",
7501
- className: getClassName21("frame"),
7626
+ className: getClassName22("frame"),
7502
7627
  ref,
7503
7628
  "data-puck-entry": true,
7504
7629
  children: inner
@@ -7516,7 +7641,7 @@ init_react_import();
7516
7641
 
7517
7642
  // css-module:/home/runner/work/puck/puck/packages/core/components/LayerTree/styles.module.css#css-module
7518
7643
  init_react_import();
7519
- 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" };
7644
+ var styles_module_default18 = { "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" };
7520
7645
 
7521
7646
  // lib/scroll-into-view.ts
7522
7647
  init_react_import();
@@ -7530,7 +7655,7 @@ var scrollIntoView = (el) => {
7530
7655
  };
7531
7656
 
7532
7657
  // components/LayerTree/index.tsx
7533
- var import_react46 = require("react");
7658
+ var import_react47 = require("react");
7534
7659
 
7535
7660
  // lib/on-scroll-end.ts
7536
7661
  init_react_import();
@@ -7553,20 +7678,19 @@ var onScrollEnd = (frame, cb) => {
7553
7678
 
7554
7679
  // components/LayerTree/index.tsx
7555
7680
  var import_shallow6 = require("zustand/react/shallow");
7556
- var import_jsx_runtime34 = require("react/jsx-runtime");
7557
- var getClassName22 = get_class_name_factory_default("LayerTree", styles_module_default16);
7558
- var getClassNameLayer = get_class_name_factory_default("Layer", styles_module_default16);
7681
+ var import_jsx_runtime35 = require("react/jsx-runtime");
7682
+ var getClassName23 = get_class_name_factory_default("LayerTree", styles_module_default18);
7683
+ var getClassNameLayer = get_class_name_factory_default("Layer", styles_module_default18);
7559
7684
  var Layer = ({
7560
7685
  index,
7561
7686
  itemId,
7562
7687
  zoneCompound
7563
7688
  }) => {
7564
7689
  var _a;
7565
- const ctx = (0, import_react46.useContext)(dropZoneContext);
7566
7690
  const config = useAppStore((s) => s.config);
7567
7691
  const itemSelector = useAppStore((s) => s.state.ui.itemSelector);
7568
7692
  const dispatch = useAppStore((s) => s.dispatch);
7569
- const setItemSelector = (0, import_react46.useCallback)(
7693
+ const setItemSelector = (0, import_react47.useCallback)(
7570
7694
  (itemSelector2) => {
7571
7695
  dispatch({ type: "setUi", ui: { itemSelector: itemSelector2 } });
7572
7696
  },
@@ -7586,7 +7710,7 @@ var Layer = ({
7586
7710
  )
7587
7711
  );
7588
7712
  const containsZone = zonesForItem.length > 0;
7589
- const zoneStore = (0, import_react46.useContext)(ZoneStoreContext);
7713
+ const zoneStore = (0, import_react47.useContext)(ZoneStoreContext);
7590
7714
  const isHovering = useContextStore(
7591
7715
  ZoneStoreContext,
7592
7716
  (s) => s.hoveringComponent === itemId
@@ -7601,7 +7725,7 @@ var Layer = ({
7601
7725
  });
7602
7726
  const componentConfig = config.components[nodeData.data.type];
7603
7727
  const label = (_a = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _a : nodeData.data.type.toString();
7604
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
7728
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
7605
7729
  "li",
7606
7730
  {
7607
7731
  className: getClassNameLayer({
@@ -7611,7 +7735,7 @@ var Layer = ({
7611
7735
  childIsSelected
7612
7736
  }),
7613
7737
  children: [
7614
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(
7738
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: getClassNameLayer("inner"), children: /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
7615
7739
  "button",
7616
7740
  {
7617
7741
  type: "button",
@@ -7649,22 +7773,22 @@ var Layer = ({
7649
7773
  zoneStore.setState({ hoveringComponent: null });
7650
7774
  },
7651
7775
  children: [
7652
- containsZone && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7776
+ containsZone && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
7653
7777
  "div",
7654
7778
  {
7655
7779
  className: getClassNameLayer("chevron"),
7656
7780
  title: isSelected ? "Collapse" : "Expand",
7657
- children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ChevronDown, { size: "12" })
7781
+ children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(ChevronDown, { size: "12" })
7658
7782
  }
7659
7783
  ),
7660
- /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: getClassNameLayer("title"), children: [
7661
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassNameLayer("icon"), children: nodeData.data.type === "Text" || nodeData.data.type === "Heading" ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Type, { size: "16" }) : /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(LayoutGrid, { size: "16" }) }),
7662
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassNameLayer("name"), children: label })
7784
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: getClassNameLayer("title"), children: [
7785
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: getClassNameLayer("icon"), children: nodeData.data.type === "Text" || nodeData.data.type === "Heading" ? /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Type, { size: "16" }) : /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(LayoutGrid, { size: "16" }) }),
7786
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: getClassNameLayer("name"), children: label })
7663
7787
  ] })
7664
7788
  ]
7665
7789
  }
7666
7790
  ) }),
7667
- containsZone && zonesForItem.map((subzone) => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassNameLayer("zones"), children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(LayerTree, { zoneCompound: subzone }) }, subzone))
7791
+ containsZone && zonesForItem.map((subzone) => /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: getClassNameLayer("zones"), children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(LayerTree, { zoneCompound: subzone }) }, subzone))
7668
7792
  ]
7669
7793
  }
7670
7794
  );
@@ -7673,7 +7797,15 @@ var LayerTree = ({
7673
7797
  label: _label,
7674
7798
  zoneCompound
7675
7799
  }) => {
7676
- const label = _label != null ? _label : zoneCompound.split(":")[1];
7800
+ const label = useAppStore((s) => {
7801
+ var _a, _b, _c, _d;
7802
+ if (_label) return _label;
7803
+ if (zoneCompound === rootDroppableId) return;
7804
+ const [componentId, slotId] = zoneCompound.split(":");
7805
+ const componentType = (_a = s.state.indexes.nodes[componentId]) == null ? void 0 : _a.data.type;
7806
+ const configForComponent = componentType && componentType !== rootAreaId ? s.config.components[componentType] : s.config.root;
7807
+ return (_d = (_c = (_b = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _b[slotId]) == null ? void 0 : _c.label) != null ? _d : slotId;
7808
+ });
7677
7809
  const contentIds = useAppStore(
7678
7810
  (0, import_shallow6.useShallow)(
7679
7811
  (s) => {
@@ -7682,15 +7814,15 @@ var LayerTree = ({
7682
7814
  }
7683
7815
  )
7684
7816
  );
7685
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
7686
- label && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: getClassName22("zoneTitle"), children: [
7687
- /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassName22("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Layers, { size: "16" }) }),
7817
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_jsx_runtime35.Fragment, { children: [
7818
+ label && /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: getClassName23("zoneTitle"), children: [
7819
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: getClassName23("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Layers, { size: "16" }) }),
7688
7820
  label
7689
7821
  ] }),
7690
- /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("ul", { className: getClassName22(), children: [
7691
- contentIds.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassName22("helper"), children: "No items" }),
7822
+ /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("ul", { className: getClassName23(), children: [
7823
+ contentIds.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: getClassName23("helper"), children: "No items" }),
7692
7824
  contentIds.map((itemId, i) => {
7693
- return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
7825
+ return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
7694
7826
  Layer,
7695
7827
  {
7696
7828
  index: i,
@@ -7705,7 +7837,7 @@ var LayerTree = ({
7705
7837
  };
7706
7838
 
7707
7839
  // components/Puck/components/Outline/index.tsx
7708
- var import_react47 = require("react");
7840
+ var import_react48 = require("react");
7709
7841
 
7710
7842
  // lib/data/find-zones-for-area.ts
7711
7843
  init_react_import();
@@ -7717,14 +7849,14 @@ var findZonesForArea = (state, area) => {
7717
7849
 
7718
7850
  // components/Puck/components/Outline/index.tsx
7719
7851
  var import_shallow7 = require("zustand/react/shallow");
7720
- var import_jsx_runtime35 = require("react/jsx-runtime");
7852
+ var import_jsx_runtime36 = require("react/jsx-runtime");
7721
7853
  var Outline = () => {
7722
7854
  const outlineOverride = useAppStore((s) => s.overrides.outline);
7723
7855
  const rootZones = useAppStore(
7724
7856
  (0, import_shallow7.useShallow)((s) => findZonesForArea(s.state, "root"))
7725
7857
  );
7726
- const Wrapper = (0, import_react47.useMemo)(() => outlineOverride || "div", [outlineOverride]);
7727
- return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Wrapper, { children: rootZones.map((zoneCompound) => /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
7858
+ const Wrapper = (0, import_react48.useMemo)(() => outlineOverride || "div", [outlineOverride]);
7859
+ return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(Wrapper, { children: rootZones.map((zoneCompound) => /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
7728
7860
  LayerTree,
7729
7861
  {
7730
7862
  label: rootZones.length === 1 ? "" : zoneCompound.split(":")[1],
@@ -7734,1189 +7866,924 @@ var Outline = () => {
7734
7866
  )) });
7735
7867
  };
7736
7868
 
7737
- // lib/use-loaded-overrides.ts
7869
+ // components/Puck/components/Canvas/index.tsx
7738
7870
  init_react_import();
7739
- var import_react48 = require("react");
7740
7871
 
7741
- // lib/load-overrides.ts
7872
+ // ../../node_modules/css-box-model/dist/css-box-model.esm.js
7742
7873
  init_react_import();
7743
- var loadOverrides = ({
7744
- overrides,
7745
- plugins
7746
- }) => {
7747
- const collected = __spreadValues({}, overrides);
7748
- plugins == null ? void 0 : plugins.forEach((plugin) => {
7749
- if (!plugin.overrides) return;
7750
- Object.keys(plugin.overrides).forEach((_overridesType) => {
7751
- const overridesType = _overridesType;
7752
- if (overridesType === "fieldTypes") {
7753
- const fieldTypes = plugin.overrides.fieldTypes;
7754
- Object.keys(fieldTypes).forEach((fieldType) => {
7755
- collected.fieldTypes = collected.fieldTypes || {};
7756
- const childNode2 = collected.fieldTypes[fieldType];
7757
- const Comp2 = (props) => fieldTypes[fieldType](__spreadProps(__spreadValues({}, props), {
7758
- children: childNode2 ? childNode2(props) : props.children
7759
- }));
7760
- collected.fieldTypes[fieldType] = Comp2;
7761
- });
7762
- return;
7763
- }
7764
- const childNode = collected[overridesType];
7765
- const Comp = (props) => plugin.overrides[overridesType](__spreadProps(__spreadValues({}, props), {
7766
- children: childNode ? childNode(props) : props.children
7767
- }));
7768
- collected[overridesType] = Comp;
7769
- });
7770
- });
7771
- return collected;
7772
- };
7773
-
7774
- // lib/use-loaded-overrides.ts
7775
- var useLoadedOverrides = ({
7776
- overrides,
7777
- plugins
7778
- }) => {
7779
- return (0, import_react48.useMemo)(() => {
7780
- return loadOverrides({ overrides, plugins });
7781
- }, [plugins, overrides]);
7782
- };
7783
7874
 
7784
- // lib/use-puck.ts
7875
+ // ../../node_modules/tiny-invariant/dist/esm/tiny-invariant.js
7785
7876
  init_react_import();
7786
- var import_react49 = require("react");
7787
- var import_zustand6 = require("zustand");
7788
- var generateUsePuck = (store) => {
7789
- const history = {
7790
- back: store.history.back,
7791
- forward: store.history.forward,
7792
- setHistories: store.history.setHistories,
7793
- setHistoryIndex: store.history.setHistoryIndex,
7794
- hasPast: store.history.hasPast(),
7795
- hasFuture: store.history.hasFuture(),
7796
- histories: store.history.histories,
7797
- index: store.history.index
7798
- };
7799
- const storeData = {
7800
- appState: makeStatePublic(store.state),
7801
- config: store.config,
7802
- dispatch: store.dispatch,
7803
- getPermissions: store.permissions.getPermissions,
7804
- refreshPermissions: store.permissions.refreshPermissions,
7805
- history,
7806
- selectedItem: store.selectedItem || null,
7807
- getItemBySelector: (selector) => getItem(selector, store.state),
7808
- getItemById: (id) => store.state.indexes.nodes[id].data,
7809
- getSelectorForId: (id) => {
7810
- const node = store.state.indexes.nodes[id];
7811
- if (!node) return;
7812
- const zoneCompound = `${node.parentId}:${node.zone}`;
7813
- const index = store.state.indexes.zones[zoneCompound].contentIds.indexOf(id);
7814
- return { zone: zoneCompound, index };
7815
- }
7816
- };
7817
- const get = () => storeData;
7818
- return __spreadProps(__spreadValues({}, storeData), { get });
7819
- };
7820
- var UsePuckStoreContext = (0, import_react49.createContext)(
7821
- null
7822
- );
7823
- var convertToPickedStore = (store) => {
7824
- return {
7825
- state: store.state,
7826
- config: store.config,
7827
- dispatch: store.dispatch,
7828
- permissions: store.permissions,
7829
- history: store.history,
7830
- selectedItem: store.selectedItem
7877
+ var isProduction = process.env.NODE_ENV === "production";
7878
+ var prefix = "Invariant failed";
7879
+ function invariant(condition, message) {
7880
+ if (condition) {
7881
+ return;
7882
+ }
7883
+ if (isProduction) {
7884
+ throw new Error(prefix);
7885
+ }
7886
+ var provided = typeof message === "function" ? message() : message;
7887
+ var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
7888
+ throw new Error(value);
7889
+ }
7890
+
7891
+ // ../../node_modules/css-box-model/dist/css-box-model.esm.js
7892
+ var getRect = function getRect2(_ref) {
7893
+ var top = _ref.top, right = _ref.right, bottom = _ref.bottom, left = _ref.left;
7894
+ var width = right - left;
7895
+ var height = bottom - top;
7896
+ var rect = {
7897
+ top,
7898
+ right,
7899
+ bottom,
7900
+ left,
7901
+ width,
7902
+ height,
7903
+ x: left,
7904
+ y: top,
7905
+ center: {
7906
+ x: (right + left) / 2,
7907
+ y: (bottom + top) / 2
7908
+ }
7831
7909
  };
7910
+ return rect;
7832
7911
  };
7833
- var useRegisterUsePuckStore = (appStore) => {
7834
- const [usePuckStore] = (0, import_react49.useState)(
7835
- () => (0, import_zustand6.createStore)(
7836
- () => generateUsePuck(convertToPickedStore(appStore.getState()))
7837
- )
7838
- );
7839
- (0, import_react49.useEffect)(() => {
7840
- return appStore.subscribe(
7841
- (store) => convertToPickedStore(store),
7842
- (pickedStore) => {
7843
- usePuckStore.setState(generateUsePuck(pickedStore));
7844
- }
7845
- );
7846
- }, []);
7847
- return usePuckStore;
7912
+ var expand = function expand2(target, expandBy) {
7913
+ return {
7914
+ top: target.top - expandBy.top,
7915
+ left: target.left - expandBy.left,
7916
+ bottom: target.bottom + expandBy.bottom,
7917
+ right: target.right + expandBy.right
7918
+ };
7848
7919
  };
7849
- function createUsePuck() {
7850
- return function usePuck2(selector) {
7851
- const usePuckApi = (0, import_react49.useContext)(UsePuckStoreContext);
7852
- if (!usePuckApi) {
7853
- throw new Error("usePuck must be used inside <Puck>.");
7854
- }
7855
- const result = (0, import_zustand6.useStore)(
7856
- usePuckApi,
7857
- selector != null ? selector : (s) => s
7858
- );
7859
- return result;
7920
+ var shrink = function shrink2(target, shrinkBy) {
7921
+ return {
7922
+ top: target.top + shrinkBy.top,
7923
+ left: target.left + shrinkBy.left,
7924
+ bottom: target.bottom - shrinkBy.bottom,
7925
+ right: target.right - shrinkBy.right
7860
7926
  };
7861
- }
7862
- function usePuck() {
7863
- (0, import_react49.useEffect)(() => {
7864
- console.warn(
7865
- "You're using the `usePuck` method without a selector, which may cause unnecessary re-renders. Replace with `createUsePuck` and provide a selector for improved performance."
7866
- );
7867
- }, []);
7868
- return createUsePuck()((s) => s);
7869
- }
7870
- function useGetPuck() {
7871
- const usePuckApi = (0, import_react49.useContext)(UsePuckStoreContext);
7872
- if (!usePuckApi) {
7873
- throw new Error("usePuckGet must be used inside <Puck>.");
7927
+ };
7928
+ var noSpacing = {
7929
+ top: 0,
7930
+ right: 0,
7931
+ bottom: 0,
7932
+ left: 0
7933
+ };
7934
+ var createBox = function createBox2(_ref2) {
7935
+ var borderBox = _ref2.borderBox, _ref2$margin = _ref2.margin, margin = _ref2$margin === void 0 ? noSpacing : _ref2$margin, _ref2$border = _ref2.border, border = _ref2$border === void 0 ? noSpacing : _ref2$border, _ref2$padding = _ref2.padding, padding = _ref2$padding === void 0 ? noSpacing : _ref2$padding;
7936
+ var marginBox = getRect(expand(borderBox, margin));
7937
+ var paddingBox = getRect(shrink(borderBox, border));
7938
+ var contentBox = getRect(shrink(paddingBox, padding));
7939
+ return {
7940
+ marginBox,
7941
+ borderBox: getRect(borderBox),
7942
+ paddingBox,
7943
+ contentBox,
7944
+ margin,
7945
+ border,
7946
+ padding
7947
+ };
7948
+ };
7949
+ var parse = function parse2(raw) {
7950
+ var value = raw.slice(0, -2);
7951
+ var suffix = raw.slice(-2);
7952
+ if (suffix !== "px") {
7953
+ return 0;
7874
7954
  }
7875
- return usePuckApi.getState;
7876
- }
7877
-
7878
- // components/Puck/index.tsx
7879
- var import_fast_deep_equal3 = __toESM(require("fast-deep-equal"));
7880
-
7881
- // components/Puck/components/Layout/index.tsx
7882
- init_react_import();
7883
- var import_react56 = require("react");
7884
-
7885
- // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Layout/styles.module.css#css-module
7886
- init_react_import();
7887
- var styles_module_default17 = { "Puck": "_Puck_n6ob8_19", "Puck-portal": "_Puck-portal_n6ob8_31", "PuckLayout-inner": "_PuckLayout-inner_n6ob8_36", "PuckLayout--mounted": "_PuckLayout--mounted_n6ob8_48", "PuckLayout--leftSideBarVisible": "_PuckLayout--leftSideBarVisible_n6ob8_53", "PuckLayout--rightSideBarVisible": "_PuckLayout--rightSideBarVisible_n6ob8_61", "PuckLayout-mounted": "_PuckLayout-mounted_n6ob8_77", "PuckLayout": "_PuckLayout_n6ob8_36", "PuckLayout-leftSideBar": "_PuckLayout-leftSideBar_n6ob8_118", "PuckLayout-rightSideBar": "_PuckLayout-rightSideBar_n6ob8_128", "PuckLayout-nav": "_PuckLayout-nav_n6ob8_137" };
7888
-
7889
- // lib/use-inject-css.ts
7890
- init_react_import();
7891
- var import_react50 = require("react");
7892
- var styles = ``;
7893
- var useInjectStyleSheet = (initialStyles, iframeEnabled) => {
7894
- const [el, setEl] = (0, import_react50.useState)();
7895
- (0, import_react50.useEffect)(() => {
7896
- setEl(document.createElement("style"));
7897
- }, []);
7898
- (0, import_react50.useEffect)(() => {
7899
- var _a;
7900
- if (!el || typeof window === "undefined") {
7901
- return;
7902
- }
7903
- el.innerHTML = initialStyles;
7904
- if (iframeEnabled) {
7905
- const frame = getFrame();
7906
- (_a = frame == null ? void 0 : frame.head) == null ? void 0 : _a.appendChild(el);
7907
- }
7908
- document.head.appendChild(el);
7909
- }, [iframeEnabled, el]);
7910
- return el;
7955
+ var result = Number(value);
7956
+ !!isNaN(result) ? process.env.NODE_ENV !== "production" ? invariant(false, "Could not parse value [raw: " + raw + ", without suffix: " + value + "]") : invariant(false) : void 0;
7957
+ return result;
7911
7958
  };
7912
- var useInjectGlobalCss = (iframeEnabled) => {
7913
- return useInjectStyleSheet(styles, iframeEnabled);
7959
+ var calculateBox = function calculateBox2(borderBox, styles2) {
7960
+ var margin = {
7961
+ top: parse(styles2.marginTop),
7962
+ right: parse(styles2.marginRight),
7963
+ bottom: parse(styles2.marginBottom),
7964
+ left: parse(styles2.marginLeft)
7965
+ };
7966
+ var padding = {
7967
+ top: parse(styles2.paddingTop),
7968
+ right: parse(styles2.paddingRight),
7969
+ bottom: parse(styles2.paddingBottom),
7970
+ left: parse(styles2.paddingLeft)
7971
+ };
7972
+ var border = {
7973
+ top: parse(styles2.borderTopWidth),
7974
+ right: parse(styles2.borderRightWidth),
7975
+ bottom: parse(styles2.borderBottomWidth),
7976
+ left: parse(styles2.borderLeftWidth)
7977
+ };
7978
+ return createBox({
7979
+ borderBox,
7980
+ margin,
7981
+ padding,
7982
+ border
7983
+ });
7914
7984
  };
7915
-
7916
- // components/DefaultOverride/index.tsx
7917
- init_react_import();
7918
- var import_jsx_runtime36 = require("react/jsx-runtime");
7919
- var DefaultOverride = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_jsx_runtime36.Fragment, { children });
7920
-
7921
- // lib/use-preview-mode-hotkeys.ts
7922
- init_react_import();
7923
- var import_react51 = require("react");
7924
- var usePreviewModeHotkeys = () => {
7925
- const appStore = useAppStoreApi();
7926
- const toggleInteractive = (0, import_react51.useCallback)(() => {
7927
- const dispatch = appStore.getState().dispatch;
7928
- dispatch({
7929
- type: "setUi",
7930
- ui: (ui) => ({
7931
- previewMode: ui.previewMode === "edit" ? "interactive" : "edit"
7932
- })
7933
- });
7934
- }, [appStore]);
7935
- useHotkey({ meta: true, i: true }, toggleInteractive);
7936
- useHotkey({ ctrl: true, i: true }, toggleInteractive);
7985
+ var getBox = function getBox2(el) {
7986
+ var borderBox = el.getBoundingClientRect();
7987
+ var styles2 = window.getComputedStyle(el);
7988
+ return calculateBox(borderBox, styles2);
7937
7989
  };
7938
7990
 
7939
- // components/Puck/components/Header/index.tsx
7940
- init_react_import();
7941
- var import_react52 = require("react");
7991
+ // components/Puck/components/Canvas/index.tsx
7992
+ var import_react50 = require("react");
7942
7993
 
7943
- // components/MenuBar/index.tsx
7994
+ // components/ViewportControls/index.tsx
7944
7995
  init_react_import();
7996
+ var import_react49 = require("react");
7945
7997
 
7946
- // css-module:/home/runner/work/puck/puck/packages/core/components/MenuBar/styles.module.css#css-module
7998
+ // css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
7947
7999
  init_react_import();
7948
- var styles_module_default18 = { "MenuBar": "_MenuBar_8pf8c_1", "MenuBar--menuOpen": "_MenuBar--menuOpen_8pf8c_14", "MenuBar-inner": "_MenuBar-inner_8pf8c_29", "MenuBar-history": "_MenuBar-history_8pf8c_45" };
8000
+ var styles_module_default19 = { "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" };
7949
8001
 
7950
- // components/MenuBar/index.tsx
8002
+ // components/ViewportControls/index.tsx
7951
8003
  var import_jsx_runtime37 = require("react/jsx-runtime");
7952
- var getClassName23 = get_class_name_factory_default("MenuBar", styles_module_default18);
7953
- function MenuBar({
7954
- menuOpen = false,
7955
- renderHeaderActions,
7956
- setMenuOpen
7957
- }) {
7958
- const back = useAppStore((s) => s.history.back);
7959
- const forward = useAppStore((s) => s.history.forward);
7960
- const hasFuture = useAppStore((s) => s.history.hasFuture());
7961
- const hasPast = useAppStore((s) => s.history.hasPast());
7962
- return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
7963
- "div",
8004
+ var icons = {
8005
+ Smartphone: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Smartphone, { size: 16 }),
8006
+ Tablet: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Tablet, { size: 16 }),
8007
+ Monitor: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Monitor, { size: 16 })
8008
+ };
8009
+ var getClassName24 = get_class_name_factory_default("ViewportControls", styles_module_default19);
8010
+ var getClassNameButton = get_class_name_factory_default("ViewportButton", styles_module_default19);
8011
+ var ViewportButton = ({
8012
+ children,
8013
+ height = "auto",
8014
+ title,
8015
+ width,
8016
+ onClick
8017
+ }) => {
8018
+ const viewports = useAppStore((s) => s.state.ui.viewports);
8019
+ const [isActive, setIsActive] = (0, import_react49.useState)(false);
8020
+ (0, import_react49.useEffect)(() => {
8021
+ setIsActive(width === viewports.current.width);
8022
+ }, [width, viewports.current.width]);
8023
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
8024
+ IconButton,
7964
8025
  {
7965
- className: getClassName23({ menuOpen }),
7966
- onClick: (event) => {
7967
- var _a;
7968
- const element = event.target;
7969
- if (window.matchMedia("(min-width: 638px)").matches) {
7970
- return;
7971
- }
7972
- if (element.tagName === "A" && ((_a = element.getAttribute("href")) == null ? void 0 : _a.startsWith("#"))) {
7973
- setMenuOpen(false);
7974
- }
8026
+ type: "button",
8027
+ title,
8028
+ disabled: isActive,
8029
+ onClick: (e) => {
8030
+ e.stopPropagation();
8031
+ onClick({ width, height });
7975
8032
  },
7976
- children: /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("div", { className: getClassName23("inner"), children: [
7977
- /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("div", { className: getClassName23("history"), children: [
7978
- /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(IconButton, { title: "undo", disabled: !hasPast, onClick: back, children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Undo2, { size: 21 }) }),
7979
- /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(IconButton, { title: "redo", disabled: !hasFuture, onClick: forward, children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Redo2, { size: 21 }) })
7980
- ] }),
7981
- /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_jsx_runtime37.Fragment, { children: renderHeaderActions && renderHeaderActions() })
7982
- ] })
8033
+ children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("span", { className: getClassNameButton("inner"), children })
7983
8034
  }
8035
+ ) });
8036
+ };
8037
+ var defaultZoomOptions = [
8038
+ { label: "25%", value: 0.25 },
8039
+ { label: "50%", value: 0.5 },
8040
+ { label: "75%", value: 0.75 },
8041
+ { label: "100%", value: 1 },
8042
+ { label: "125%", value: 1.25 },
8043
+ { label: "150%", value: 1.5 },
8044
+ { label: "200%", value: 2 }
8045
+ ];
8046
+ var ViewportControls = ({
8047
+ autoZoom,
8048
+ zoom,
8049
+ onViewportChange,
8050
+ onZoom
8051
+ }) => {
8052
+ var _a, _b;
8053
+ const viewports = useAppStore((s) => s.viewports);
8054
+ const defaultsContainAutoZoom = defaultZoomOptions.find(
8055
+ (option) => option.value === autoZoom
7984
8056
  );
7985
- }
7986
-
7987
- // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Header/styles.module.css#css-module
7988
- init_react_import();
7989
- var styles_module_default19 = { "PuckHeader": "_PuckHeader_dlc6d_1", "PuckHeader-inner": "_PuckHeader-inner_dlc6d_16", "PuckHeader-toggle": "_PuckHeader-toggle_dlc6d_33", "PuckHeader--rightSideBarVisible": "_PuckHeader--rightSideBarVisible_dlc6d_40", "PuckHeader-rightSideBarToggle": "_PuckHeader-rightSideBarToggle_dlc6d_40", "PuckHeader--leftSideBarVisible": "_PuckHeader--leftSideBarVisible_dlc6d_41", "PuckHeader-leftSideBarToggle": "_PuckHeader-leftSideBarToggle_dlc6d_41", "PuckHeader-title": "_PuckHeader-title_dlc6d_45", "PuckHeader-path": "_PuckHeader-path_dlc6d_49", "PuckHeader-tools": "_PuckHeader-tools_dlc6d_56", "PuckHeader-menuButton": "_PuckHeader-menuButton_dlc6d_62", "PuckHeader--menuOpen": "_PuckHeader--menuOpen_dlc6d_67" };
7990
-
7991
- // components/Puck/components/Header/index.tsx
7992
- var import_jsx_runtime38 = require("react/jsx-runtime");
7993
- var getClassName24 = get_class_name_factory_default("PuckHeader", styles_module_default19);
7994
- var HeaderInner = () => {
7995
- const {
7996
- onPublish,
7997
- renderHeader,
7998
- renderHeaderActions,
7999
- headerTitle,
8000
- headerPath,
8001
- iframe: _iframe
8002
- } = usePropsContext();
8003
- const dispatch = useAppStore((s) => s.dispatch);
8004
- const appStore = useAppStoreApi();
8005
- const defaultHeaderRender = (0, import_react52.useMemo)(() => {
8006
- if (renderHeader) {
8007
- console.warn(
8008
- "`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
8009
- );
8010
- const RenderHeader = (_a) => {
8011
- var _b = _a, { actions } = _b, props = __objRest(_b, ["actions"]);
8012
- const Comp = renderHeader;
8013
- const appState = useAppStore((s) => s.state);
8014
- return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState, children: actions }));
8015
- };
8016
- return RenderHeader;
8017
- }
8018
- return DefaultOverride;
8019
- }, [renderHeader]);
8020
- const defaultHeaderActionsRender = (0, import_react52.useMemo)(() => {
8021
- if (renderHeaderActions) {
8022
- console.warn(
8023
- "`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
8024
- );
8025
- const RenderHeader = (props) => {
8026
- const Comp = renderHeaderActions;
8027
- const appState = useAppStore((s) => s.state);
8028
- return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState }));
8029
- };
8030
- return RenderHeader;
8031
- }
8032
- return DefaultOverride;
8033
- }, [renderHeader]);
8034
- const CustomHeader = useAppStore(
8035
- (s) => s.overrides.header || defaultHeaderRender
8036
- );
8037
- const CustomHeaderActions = useAppStore(
8038
- (s) => s.overrides.headerActions || defaultHeaderActionsRender
8039
- );
8040
- const [menuOpen, setMenuOpen] = (0, import_react52.useState)(false);
8041
- const rootTitle = useAppStore((s) => {
8042
- var _a, _b;
8043
- const rootData = (_a = s.state.indexes.nodes["root"]) == null ? void 0 : _a.data;
8044
- return (_b = rootData.props.title) != null ? _b : "";
8045
- });
8046
- const leftSideBarVisible = useAppStore((s) => s.state.ui.leftSideBarVisible);
8047
- const rightSideBarVisible = useAppStore(
8048
- (s) => s.state.ui.rightSideBarVisible
8049
- );
8050
- const toggleSidebars = (0, import_react52.useCallback)(
8051
- (sidebar) => {
8052
- const widerViewport = window.matchMedia("(min-width: 638px)").matches;
8053
- const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
8054
- const oppositeSideBar = sidebar === "left" ? "rightSideBarVisible" : "leftSideBarVisible";
8055
- dispatch({
8056
- type: "setUi",
8057
- ui: __spreadValues({
8058
- [`${sidebar}SideBarVisible`]: !sideBarVisible
8059
- }, !widerViewport ? { [oppositeSideBar]: false } : {})
8060
- });
8061
- },
8062
- [dispatch, leftSideBarVisible, rightSideBarVisible]
8063
- );
8064
- return /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
8065
- CustomHeader,
8066
- {
8067
- actions: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_jsx_runtime38.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CustomHeaderActions, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
8068
- Button,
8069
- {
8070
- onClick: () => {
8071
- const data = appStore.getState().state.data;
8072
- onPublish && onPublish(data);
8073
- },
8074
- icon: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Globe, { size: "14px" }),
8075
- children: "Publish"
8076
- }
8077
- ) }) }),
8078
- children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
8079
- "header",
8057
+ const zoomOptions = (0, import_react49.useMemo)(
8058
+ () => [
8059
+ ...defaultZoomOptions,
8060
+ ...defaultsContainAutoZoom ? [] : [
8080
8061
  {
8081
- className: getClassName24({ leftSideBarVisible, rightSideBarVisible }),
8082
- children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: getClassName24("inner"), children: [
8083
- /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: getClassName24("toggle"), children: [
8084
- /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: getClassName24("leftSideBarToggle"), children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
8085
- IconButton,
8086
- {
8087
- onClick: () => {
8088
- toggleSidebars("left");
8089
- },
8090
- title: "Toggle left sidebar",
8091
- children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(PanelLeft, { focusable: "false" })
8092
- }
8093
- ) }),
8094
- /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: getClassName24("rightSideBarToggle"), children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
8095
- IconButton,
8096
- {
8097
- onClick: () => {
8098
- toggleSidebars("right");
8099
- },
8100
- title: "Toggle right sidebar",
8101
- children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(PanelRight, { focusable: "false" })
8102
- }
8103
- ) })
8104
- ] }),
8105
- /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: getClassName24("title"), children: /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(Heading, { rank: "2", size: "xs", children: [
8106
- headerTitle || rootTitle || "Page",
8107
- headerPath && /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(import_jsx_runtime38.Fragment, { children: [
8108
- " ",
8109
- /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("code", { className: getClassName24("path"), children: headerPath })
8110
- ] })
8111
- ] }) }),
8112
- /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: getClassName24("tools"), children: [
8113
- /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: getClassName24("menuButton"), children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
8114
- IconButton,
8115
- {
8116
- onClick: () => {
8117
- return setMenuOpen(!menuOpen);
8118
- },
8119
- title: "Toggle menu bar",
8120
- children: menuOpen ? /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ChevronUp, { focusable: "false" }) : /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(ChevronDown, { focusable: "false" })
8121
- }
8122
- ) }),
8123
- /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
8124
- MenuBar,
8125
- {
8126
- dispatch,
8127
- onPublish,
8128
- menuOpen,
8129
- renderHeaderActions: () => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CustomHeaderActions, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
8130
- Button,
8131
- {
8132
- onClick: () => {
8133
- const data = appStore.getState().state.data;
8134
- onPublish && onPublish(data);
8135
- },
8136
- icon: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Globe, { size: "14px" }),
8137
- children: "Publish"
8138
- }
8139
- ) }),
8140
- setMenuOpen
8141
- }
8142
- )
8143
- ] })
8144
- ] })
8062
+ value: autoZoom,
8063
+ label: `${(autoZoom * 100).toFixed(0)}% (Auto)`
8145
8064
  }
8146
- )
8147
- }
8065
+ ]
8066
+ ].filter((a) => a.value <= autoZoom).sort((a, b) => a.value > b.value ? 1 : -1),
8067
+ [autoZoom]
8148
8068
  );
8069
+ return /* @__PURE__ */ (0, import_jsx_runtime37.jsxs)("div", { className: getClassName24(), children: [
8070
+ viewports.map((viewport, i) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
8071
+ ViewportButton,
8072
+ {
8073
+ height: viewport.height,
8074
+ width: viewport.width,
8075
+ title: viewport.label ? `Switch to ${viewport.label} viewport` : "Switch viewport",
8076
+ onClick: onViewportChange,
8077
+ children: typeof viewport.icon === "string" ? icons[viewport.icon] || viewport.icon : viewport.icon || icons.Smartphone
8078
+ },
8079
+ i
8080
+ )),
8081
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: getClassName24("divider") }),
8082
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
8083
+ IconButton,
8084
+ {
8085
+ type: "button",
8086
+ title: "Zoom viewport out",
8087
+ disabled: zoom <= ((_a = zoomOptions[0]) == null ? void 0 : _a.value),
8088
+ onClick: (e) => {
8089
+ e.stopPropagation();
8090
+ onZoom(
8091
+ zoomOptions[Math.max(
8092
+ zoomOptions.findIndex((option) => option.value === zoom) - 1,
8093
+ 0
8094
+ )].value
8095
+ );
8096
+ },
8097
+ children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(ZoomOut, { size: 16 })
8098
+ }
8099
+ ),
8100
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
8101
+ IconButton,
8102
+ {
8103
+ type: "button",
8104
+ title: "Zoom viewport in",
8105
+ disabled: zoom >= ((_b = zoomOptions[zoomOptions.length - 1]) == null ? void 0 : _b.value),
8106
+ onClick: (e) => {
8107
+ e.stopPropagation();
8108
+ onZoom(
8109
+ zoomOptions[Math.min(
8110
+ zoomOptions.findIndex((option) => option.value === zoom) + 1,
8111
+ zoomOptions.length - 1
8112
+ )].value
8113
+ );
8114
+ },
8115
+ children: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(ZoomIn, { size: 16 })
8116
+ }
8117
+ ),
8118
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)("div", { className: getClassName24("divider") }),
8119
+ /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
8120
+ "select",
8121
+ {
8122
+ className: getClassName24("zoomSelect"),
8123
+ value: zoom.toString(),
8124
+ onChange: (e) => {
8125
+ onZoom(parseFloat(e.currentTarget.value));
8126
+ },
8127
+ children: zoomOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
8128
+ "option",
8129
+ {
8130
+ value: option.value,
8131
+ label: option.label
8132
+ },
8133
+ option.label
8134
+ ))
8135
+ }
8136
+ )
8137
+ ] });
8149
8138
  };
8150
- var Header = (0, import_react52.memo)(HeaderInner);
8151
8139
 
8152
- // components/SidebarSection/index.tsx
8140
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Canvas/styles.module.css#css-module
8153
8141
  init_react_import();
8142
+ var styles_module_default20 = { "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" };
8154
8143
 
8155
- // css-module:/home/runner/work/puck/puck/packages/core/components/SidebarSection/styles.module.css#css-module
8144
+ // lib/get-zoom-config.ts
8156
8145
  init_react_import();
8157
- var styles_module_default20 = { "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" };
8146
+ var RESET_ZOOM_SMALLER_THAN_FRAME = true;
8147
+ var getZoomConfig = (uiViewport, frame, zoom) => {
8148
+ const box = getBox(frame);
8149
+ const { width: frameWidth, height: frameHeight } = box.contentBox;
8150
+ const viewportHeight = uiViewport.height === "auto" ? frameHeight : uiViewport.height;
8151
+ let rootHeight = 0;
8152
+ let autoZoom = 1;
8153
+ if (uiViewport.width > frameWidth || viewportHeight > frameHeight) {
8154
+ const widthZoom = Math.min(frameWidth / uiViewport.width, 1);
8155
+ const heightZoom = Math.min(frameHeight / viewportHeight, 1);
8156
+ zoom = widthZoom;
8157
+ if (widthZoom < heightZoom) {
8158
+ rootHeight = viewportHeight / zoom;
8159
+ } else {
8160
+ rootHeight = viewportHeight;
8161
+ zoom = heightZoom;
8162
+ }
8163
+ autoZoom = zoom;
8164
+ } else {
8165
+ if (RESET_ZOOM_SMALLER_THAN_FRAME) {
8166
+ autoZoom = 1;
8167
+ zoom = 1;
8168
+ rootHeight = viewportHeight;
8169
+ }
8170
+ }
8171
+ return { autoZoom, rootHeight, zoom };
8172
+ };
8158
8173
 
8159
- // lib/use-breadcrumbs.ts
8160
- init_react_import();
8161
- var import_react53 = require("react");
8162
- var useBreadcrumbs = (renderCount) => {
8163
- const selectedId = useAppStore((s) => {
8164
- var _a;
8165
- return (_a = s.selectedItem) == null ? void 0 : _a.props.id;
8166
- });
8167
- const config = useAppStore((s) => s.config);
8168
- const path = useAppStore((s) => {
8169
- var _a;
8170
- return (_a = s.state.indexes.nodes[selectedId]) == null ? void 0 : _a.path;
8171
- });
8172
- const appStore = useAppStoreApi();
8173
- return (0, import_react53.useMemo)(() => {
8174
- const breadcrumbs = (path == null ? void 0 : path.map((zoneCompound) => {
8175
- var _a, _b, _c;
8176
- const [componentId] = zoneCompound.split(":");
8177
- if (componentId === "root") {
8178
- return {
8179
- label: "Page",
8180
- selector: null
8181
- };
8182
- }
8183
- const node = appStore.getState().state.indexes.nodes[componentId];
8184
- const parentId = node.path[node.path.length - 1];
8185
- const contentIds = ((_a = appStore.getState().state.indexes.zones[parentId]) == null ? void 0 : _a.contentIds) || [];
8186
- const index = contentIds.indexOf(componentId);
8187
- const label = node ? (_c = (_b = config.components[node.data.type]) == null ? void 0 : _b.label) != null ? _c : node.data.type : "Component";
8188
- return {
8189
- label,
8190
- selector: node ? {
8191
- index,
8192
- zone: node.path[node.path.length - 1]
8193
- } : null
8194
- };
8195
- })) || [];
8196
- if (renderCount) {
8197
- return breadcrumbs.slice(breadcrumbs.length - renderCount);
8174
+ // components/Puck/components/Canvas/index.tsx
8175
+ var import_shallow8 = require("zustand/react/shallow");
8176
+ var import_jsx_runtime38 = require("react/jsx-runtime");
8177
+ var getClassName25 = get_class_name_factory_default("PuckCanvas", styles_module_default20);
8178
+ var ZOOM_ON_CHANGE = true;
8179
+ var Canvas = () => {
8180
+ const {
8181
+ dispatch,
8182
+ overrides,
8183
+ setUi,
8184
+ zoomConfig,
8185
+ setZoomConfig,
8186
+ status,
8187
+ iframe
8188
+ } = useAppStore(
8189
+ (0, import_shallow8.useShallow)((s) => ({
8190
+ dispatch: s.dispatch,
8191
+ overrides: s.overrides,
8192
+ setUi: s.setUi,
8193
+ zoomConfig: s.zoomConfig,
8194
+ setZoomConfig: s.setZoomConfig,
8195
+ status: s.status,
8196
+ iframe: s.iframe
8197
+ }))
8198
+ );
8199
+ const { leftSideBarVisible, rightSideBarVisible, viewports } = useAppStore(
8200
+ (0, import_shallow8.useShallow)((s) => ({
8201
+ leftSideBarVisible: s.state.ui.leftSideBarVisible,
8202
+ rightSideBarVisible: s.state.ui.rightSideBarVisible,
8203
+ viewports: s.state.ui.viewports
8204
+ }))
8205
+ );
8206
+ const frameRef = (0, import_react50.useRef)(null);
8207
+ const [showTransition, setShowTransition] = (0, import_react50.useState)(false);
8208
+ const defaultRender = (0, import_react50.useMemo)(() => {
8209
+ const PuckDefault = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(import_jsx_runtime38.Fragment, { children });
8210
+ return PuckDefault;
8211
+ }, []);
8212
+ const CustomPreview = (0, import_react50.useMemo)(
8213
+ () => overrides.preview || defaultRender,
8214
+ [overrides]
8215
+ );
8216
+ const getFrameDimensions = (0, import_react50.useCallback)(() => {
8217
+ if (frameRef.current) {
8218
+ const frame = frameRef.current;
8219
+ const box = getBox(frame);
8220
+ return { width: box.contentBox.width, height: box.contentBox.height };
8221
+ }
8222
+ return { width: 0, height: 0 };
8223
+ }, [frameRef]);
8224
+ const resetAutoZoom = (0, import_react50.useCallback)(
8225
+ (newViewports = viewports) => {
8226
+ if (frameRef.current) {
8227
+ setZoomConfig(
8228
+ getZoomConfig(
8229
+ newViewports == null ? void 0 : newViewports.current,
8230
+ frameRef.current,
8231
+ zoomConfig.zoom
8232
+ )
8233
+ );
8234
+ }
8235
+ },
8236
+ [frameRef, zoomConfig, viewports]
8237
+ );
8238
+ (0, import_react50.useEffect)(() => {
8239
+ setShowTransition(false);
8240
+ resetAutoZoom(viewports);
8241
+ }, [frameRef, leftSideBarVisible, rightSideBarVisible]);
8242
+ (0, import_react50.useEffect)(() => {
8243
+ const { height: frameHeight } = getFrameDimensions();
8244
+ if (viewports.current.height === "auto") {
8245
+ setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
8246
+ rootHeight: frameHeight / zoomConfig.zoom
8247
+ }));
8198
8248
  }
8199
- return breadcrumbs;
8200
- }, [path, renderCount]);
8201
- };
8202
-
8203
- // components/SidebarSection/index.tsx
8204
- var import_jsx_runtime39 = require("react/jsx-runtime");
8205
- var getClassName25 = get_class_name_factory_default("SidebarSection", styles_module_default20);
8206
- var SidebarSection = ({
8207
- children,
8208
- title,
8209
- background,
8210
- showBreadcrumbs,
8211
- noBorderTop,
8212
- noPadding,
8213
- isLoading
8214
- }) => {
8215
- const setUi = useAppStore((s) => s.setUi);
8216
- const breadcrumbs = useBreadcrumbs(1);
8217
- return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
8249
+ }, [zoomConfig.zoom]);
8250
+ (0, import_react50.useEffect)(() => {
8251
+ if (ZOOM_ON_CHANGE) {
8252
+ setShowTransition(true);
8253
+ resetAutoZoom(viewports);
8254
+ }
8255
+ }, [viewports.current.width]);
8256
+ (0, import_react50.useEffect)(() => {
8257
+ const cb = () => {
8258
+ setShowTransition(false);
8259
+ resetAutoZoom();
8260
+ };
8261
+ window.addEventListener("resize", cb);
8262
+ return () => {
8263
+ window.removeEventListener("resize", cb);
8264
+ };
8265
+ }, []);
8266
+ const [showLoader, setShowLoader] = (0, import_react50.useState)(false);
8267
+ (0, import_react50.useEffect)(() => {
8268
+ setTimeout(() => {
8269
+ setShowLoader(true);
8270
+ }, 500);
8271
+ }, []);
8272
+ return /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)(
8218
8273
  "div",
8219
8274
  {
8220
- className: getClassName25({ noBorderTop, noPadding }),
8221
- style: { background },
8275
+ className: getClassName25({
8276
+ ready: status === "READY" || !iframe.enabled || !iframe.waitForStyles,
8277
+ showLoader
8278
+ }),
8279
+ onClick: () => dispatch({
8280
+ type: "setUi",
8281
+ ui: { itemSelector: null },
8282
+ recordHistory: true
8283
+ }),
8222
8284
  children: [
8223
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: getClassName25("title"), children: /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: getClassName25("breadcrumbs"), children: [
8224
- showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: getClassName25("breadcrumb"), children: [
8225
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
8226
- "button",
8227
- {
8228
- type: "button",
8229
- className: getClassName25("breadcrumbLabel"),
8230
- onClick: () => setUi({ itemSelector: breadcrumb.selector }),
8231
- children: breadcrumb.label
8285
+ viewports.controlsVisible && iframe.enabled && /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: getClassName25("controls"), children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
8286
+ ViewportControls,
8287
+ {
8288
+ autoZoom: zoomConfig.autoZoom,
8289
+ zoom: zoomConfig.zoom,
8290
+ onViewportChange: (viewport) => {
8291
+ setShowTransition(true);
8292
+ const uiViewport = __spreadProps(__spreadValues({}, viewport), {
8293
+ height: viewport.height || "auto",
8294
+ zoom: zoomConfig.zoom
8295
+ });
8296
+ const newUi = {
8297
+ viewports: __spreadProps(__spreadValues({}, viewports), { current: uiViewport }),
8298
+ itemSelector: null
8299
+ };
8300
+ setUi(newUi);
8301
+ if (ZOOM_ON_CHANGE) {
8302
+ resetAutoZoom(__spreadProps(__spreadValues({}, viewports), { current: uiViewport }));
8232
8303
  }
8233
- ),
8234
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(ChevronRight, { size: 16 })
8235
- ] }, i)) : null,
8236
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: getClassName25("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Heading, { rank: "2", size: "xs", children: title }) })
8237
- ] }) }),
8238
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: getClassName25("content"), children }),
8239
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: getClassName25("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Loader, { size: 32 }) })
8304
+ },
8305
+ onZoom: (zoom) => {
8306
+ setShowTransition(true);
8307
+ setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), { zoom }));
8308
+ }
8309
+ }
8310
+ ) }),
8311
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsxs)("div", { className: getClassName25("inner"), ref: frameRef, children: [
8312
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(
8313
+ "div",
8314
+ {
8315
+ className: getClassName25("root"),
8316
+ style: {
8317
+ width: iframe.enabled ? viewports.current.width : "100%",
8318
+ height: zoomConfig.rootHeight,
8319
+ transform: iframe.enabled ? `scale(${zoomConfig.zoom})` : void 0,
8320
+ transition: showTransition ? "width 150ms ease-out, height 150ms ease-out, transform 150ms ease-out" : "",
8321
+ overflow: iframe.enabled ? void 0 : "auto"
8322
+ },
8323
+ suppressHydrationWarning: true,
8324
+ id: "puck-canvas-root",
8325
+ onTransitionEnd: () => {
8326
+ window.dispatchEvent(
8327
+ new CustomEvent("viewportchange", {
8328
+ bubbles: true,
8329
+ cancelable: false
8330
+ })
8331
+ );
8332
+ },
8333
+ children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(CustomPreview, { children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Preview2, {}) })
8334
+ }
8335
+ ),
8336
+ /* @__PURE__ */ (0, import_jsx_runtime38.jsx)("div", { className: getClassName25("loader"), children: /* @__PURE__ */ (0, import_jsx_runtime38.jsx)(Loader, { size: 24 }) })
8337
+ ] })
8240
8338
  ]
8241
8339
  }
8242
8340
  );
8243
8341
  };
8244
8342
 
8245
- // components/Puck/components/Canvas/index.tsx
8246
- init_react_import();
8247
-
8248
- // ../../node_modules/css-box-model/dist/css-box-model.esm.js
8343
+ // lib/use-loaded-overrides.ts
8249
8344
  init_react_import();
8345
+ var import_react51 = require("react");
8250
8346
 
8251
- // ../../node_modules/tiny-invariant/dist/esm/tiny-invariant.js
8347
+ // lib/load-overrides.ts
8252
8348
  init_react_import();
8253
- var isProduction = process.env.NODE_ENV === "production";
8254
- var prefix = "Invariant failed";
8255
- function invariant(condition, message) {
8256
- if (condition) {
8257
- return;
8258
- }
8259
- if (isProduction) {
8260
- throw new Error(prefix);
8261
- }
8262
- var provided = typeof message === "function" ? message() : message;
8263
- var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
8264
- throw new Error(value);
8265
- }
8266
-
8267
- // ../../node_modules/css-box-model/dist/css-box-model.esm.js
8268
- var getRect = function getRect2(_ref) {
8269
- var top = _ref.top, right = _ref.right, bottom = _ref.bottom, left = _ref.left;
8270
- var width = right - left;
8271
- var height = bottom - top;
8272
- var rect = {
8273
- top,
8274
- right,
8275
- bottom,
8276
- left,
8277
- width,
8278
- height,
8279
- x: left,
8280
- y: top,
8281
- center: {
8282
- x: (right + left) / 2,
8283
- y: (bottom + top) / 2
8284
- }
8285
- };
8286
- return rect;
8287
- };
8288
- var expand = function expand2(target, expandBy) {
8289
- return {
8290
- top: target.top - expandBy.top,
8291
- left: target.left - expandBy.left,
8292
- bottom: target.bottom + expandBy.bottom,
8293
- right: target.right + expandBy.right
8294
- };
8295
- };
8296
- var shrink = function shrink2(target, shrinkBy) {
8297
- return {
8298
- top: target.top + shrinkBy.top,
8299
- left: target.left + shrinkBy.left,
8300
- bottom: target.bottom - shrinkBy.bottom,
8301
- right: target.right - shrinkBy.right
8302
- };
8303
- };
8304
- var noSpacing = {
8305
- top: 0,
8306
- right: 0,
8307
- bottom: 0,
8308
- left: 0
8309
- };
8310
- var createBox = function createBox2(_ref2) {
8311
- var borderBox = _ref2.borderBox, _ref2$margin = _ref2.margin, margin = _ref2$margin === void 0 ? noSpacing : _ref2$margin, _ref2$border = _ref2.border, border = _ref2$border === void 0 ? noSpacing : _ref2$border, _ref2$padding = _ref2.padding, padding = _ref2$padding === void 0 ? noSpacing : _ref2$padding;
8312
- var marginBox = getRect(expand(borderBox, margin));
8313
- var paddingBox = getRect(shrink(borderBox, border));
8314
- var contentBox = getRect(shrink(paddingBox, padding));
8315
- return {
8316
- marginBox,
8317
- borderBox: getRect(borderBox),
8318
- paddingBox,
8319
- contentBox,
8320
- margin,
8321
- border,
8322
- padding
8323
- };
8324
- };
8325
- var parse = function parse2(raw) {
8326
- var value = raw.slice(0, -2);
8327
- var suffix = raw.slice(-2);
8328
- if (suffix !== "px") {
8329
- return 0;
8330
- }
8331
- var result = Number(value);
8332
- !!isNaN(result) ? process.env.NODE_ENV !== "production" ? invariant(false, "Could not parse value [raw: " + raw + ", without suffix: " + value + "]") : invariant(false) : void 0;
8333
- return result;
8334
- };
8335
- var calculateBox = function calculateBox2(borderBox, styles2) {
8336
- var margin = {
8337
- top: parse(styles2.marginTop),
8338
- right: parse(styles2.marginRight),
8339
- bottom: parse(styles2.marginBottom),
8340
- left: parse(styles2.marginLeft)
8341
- };
8342
- var padding = {
8343
- top: parse(styles2.paddingTop),
8344
- right: parse(styles2.paddingRight),
8345
- bottom: parse(styles2.paddingBottom),
8346
- left: parse(styles2.paddingLeft)
8347
- };
8348
- var border = {
8349
- top: parse(styles2.borderTopWidth),
8350
- right: parse(styles2.borderRightWidth),
8351
- bottom: parse(styles2.borderBottomWidth),
8352
- left: parse(styles2.borderLeftWidth)
8353
- };
8354
- return createBox({
8355
- borderBox,
8356
- margin,
8357
- padding,
8358
- border
8349
+ var loadOverrides = ({
8350
+ overrides,
8351
+ plugins
8352
+ }) => {
8353
+ const collected = __spreadValues({}, overrides);
8354
+ plugins == null ? void 0 : plugins.forEach((plugin) => {
8355
+ Object.keys(plugin.overrides).forEach((_overridesType) => {
8356
+ const overridesType = _overridesType;
8357
+ if (overridesType === "fieldTypes") {
8358
+ const fieldTypes = plugin.overrides.fieldTypes;
8359
+ Object.keys(fieldTypes).forEach((fieldType) => {
8360
+ collected.fieldTypes = collected.fieldTypes || {};
8361
+ const childNode2 = collected.fieldTypes[fieldType];
8362
+ const Comp2 = (props) => fieldTypes[fieldType](__spreadProps(__spreadValues({}, props), {
8363
+ children: childNode2 ? childNode2(props) : props.children
8364
+ }));
8365
+ collected.fieldTypes[fieldType] = Comp2;
8366
+ });
8367
+ return;
8368
+ }
8369
+ const childNode = collected[overridesType];
8370
+ const Comp = (props) => plugin.overrides[overridesType](__spreadProps(__spreadValues({}, props), {
8371
+ children: childNode ? childNode(props) : props.children
8372
+ }));
8373
+ collected[overridesType] = Comp;
8374
+ });
8359
8375
  });
8360
- };
8361
- var getBox = function getBox2(el) {
8362
- var borderBox = el.getBoundingClientRect();
8363
- var styles2 = window.getComputedStyle(el);
8364
- return calculateBox(borderBox, styles2);
8376
+ return collected;
8365
8377
  };
8366
8378
 
8367
- // components/Puck/components/Canvas/index.tsx
8368
- var import_react55 = require("react");
8379
+ // lib/use-loaded-overrides.ts
8380
+ var useLoadedOverrides = ({
8381
+ overrides,
8382
+ plugins
8383
+ }) => {
8384
+ return (0, import_react51.useMemo)(() => {
8385
+ return loadOverrides({ overrides, plugins });
8386
+ }, [plugins, overrides]);
8387
+ };
8369
8388
 
8370
- // components/ViewportControls/index.tsx
8389
+ // components/DefaultOverride/index.tsx
8371
8390
  init_react_import();
8372
- var import_react54 = require("react");
8391
+ var import_jsx_runtime39 = require("react/jsx-runtime");
8392
+ var DefaultOverride = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_jsx_runtime39.Fragment, { children });
8373
8393
 
8374
- // css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
8394
+ // lib/use-inject-css.ts
8375
8395
  init_react_import();
8376
- var styles_module_default21 = { "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" };
8396
+ var import_react52 = require("react");
8397
+ var styles = ``;
8398
+ var useInjectStyleSheet = (initialStyles, iframeEnabled) => {
8399
+ const [el, setEl] = (0, import_react52.useState)();
8400
+ (0, import_react52.useEffect)(() => {
8401
+ setEl(document.createElement("style"));
8402
+ }, []);
8403
+ (0, import_react52.useEffect)(() => {
8404
+ var _a;
8405
+ if (!el || typeof window === "undefined") {
8406
+ return;
8407
+ }
8408
+ el.innerHTML = initialStyles;
8409
+ if (iframeEnabled) {
8410
+ const frame = getFrame();
8411
+ (_a = frame == null ? void 0 : frame.head) == null ? void 0 : _a.appendChild(el);
8412
+ }
8413
+ document.head.appendChild(el);
8414
+ }, [iframeEnabled, el]);
8415
+ return el;
8416
+ };
8417
+ var useInjectGlobalCss = (iframeEnabled) => {
8418
+ return useInjectStyleSheet(styles, iframeEnabled);
8419
+ };
8377
8420
 
8378
- // components/ViewportControls/index.tsx
8379
- var import_jsx_runtime40 = require("react/jsx-runtime");
8380
- var icons = {
8381
- Smartphone: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Smartphone, { size: 16 }),
8382
- Tablet: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Tablet, { size: 16 }),
8383
- Monitor: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Monitor, { size: 16 })
8421
+ // lib/use-preview-mode-hotkeys.ts
8422
+ init_react_import();
8423
+ var import_react53 = require("react");
8424
+ var usePreviewModeHotkeys = () => {
8425
+ const appStore = useAppStoreApi();
8426
+ const toggleInteractive = (0, import_react53.useCallback)(() => {
8427
+ const dispatch = appStore.getState().dispatch;
8428
+ dispatch({
8429
+ type: "setUi",
8430
+ ui: (ui) => ({
8431
+ previewMode: ui.previewMode === "edit" ? "interactive" : "edit"
8432
+ })
8433
+ });
8434
+ }, [appStore]);
8435
+ useHotkey({ meta: true, i: true }, toggleInteractive);
8436
+ useHotkey({ ctrl: true, i: true }, toggleInteractive);
8384
8437
  };
8385
- var getClassName26 = get_class_name_factory_default("ViewportControls", styles_module_default21);
8386
- var getClassNameButton = get_class_name_factory_default("ViewportButton", styles_module_default21);
8387
- var ViewportButton = ({
8388
- children,
8389
- height = "auto",
8390
- title,
8391
- width,
8392
- onClick
8393
- }) => {
8394
- const viewports = useAppStore((s) => s.state.ui.viewports);
8395
- const [isActive, setIsActive] = (0, import_react54.useState)(false);
8396
- (0, import_react54.useEffect)(() => {
8397
- setIsActive(width === viewports.current.width);
8398
- }, [width, viewports.current.width]);
8399
- return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
8400
- IconButton,
8401
- {
8402
- title,
8403
- disabled: isActive,
8404
- onClick: (e) => {
8405
- e.stopPropagation();
8406
- onClick({ width, height });
8407
- },
8408
- children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("span", { className: getClassNameButton("inner"), children })
8438
+
8439
+ // lib/use-puck.ts
8440
+ init_react_import();
8441
+ var import_react54 = require("react");
8442
+ var import_zustand6 = require("zustand");
8443
+ var generateUsePuck = (store) => {
8444
+ const history = {
8445
+ back: store.history.back,
8446
+ forward: store.history.forward,
8447
+ setHistories: store.history.setHistories,
8448
+ setHistoryIndex: store.history.setHistoryIndex,
8449
+ hasPast: store.history.hasPast(),
8450
+ hasFuture: store.history.hasFuture(),
8451
+ histories: store.history.histories,
8452
+ index: store.history.index
8453
+ };
8454
+ const storeData = {
8455
+ appState: makeStatePublic(store.state),
8456
+ config: store.config,
8457
+ dispatch: store.dispatch,
8458
+ getPermissions: store.permissions.getPermissions,
8459
+ refreshPermissions: store.permissions.refreshPermissions,
8460
+ history,
8461
+ selectedItem: store.selectedItem || null,
8462
+ getItemBySelector: (selector) => getItem(selector, store.state),
8463
+ getItemById: (id) => store.state.indexes.nodes[id].data,
8464
+ getSelectorForId: (id) => {
8465
+ const node = store.state.indexes.nodes[id];
8466
+ if (!node) return;
8467
+ const zoneCompound = `${node.parentId}:${node.zone}`;
8468
+ const index = store.state.indexes.zones[zoneCompound].contentIds.indexOf(id);
8469
+ return { zone: zoneCompound, index };
8409
8470
  }
8410
- ) });
8471
+ };
8472
+ return storeData;
8411
8473
  };
8412
- var defaultZoomOptions = [
8413
- { label: "25%", value: 0.25 },
8414
- { label: "50%", value: 0.5 },
8415
- { label: "75%", value: 0.75 },
8416
- { label: "100%", value: 1 },
8417
- { label: "125%", value: 1.25 },
8418
- { label: "150%", value: 1.5 },
8419
- { label: "200%", value: 2 }
8420
- ];
8421
- var ViewportControls = ({
8422
- autoZoom,
8423
- zoom,
8424
- onViewportChange,
8425
- onZoom
8426
- }) => {
8427
- var _a, _b;
8428
- const viewports = useAppStore((s) => s.viewports);
8429
- const defaultsContainAutoZoom = defaultZoomOptions.find(
8430
- (option) => option.value === autoZoom
8431
- );
8432
- const zoomOptions = (0, import_react54.useMemo)(
8433
- () => [
8434
- ...defaultZoomOptions,
8435
- ...defaultsContainAutoZoom ? [] : [
8436
- {
8437
- value: autoZoom,
8438
- label: `${(autoZoom * 100).toFixed(0)}% (Auto)`
8439
- }
8440
- ]
8441
- ].filter((a) => a.value <= autoZoom).sort((a, b) => a.value > b.value ? 1 : -1),
8442
- [autoZoom]
8474
+ var UsePuckStoreContext = (0, import_react54.createContext)(
8475
+ null
8476
+ );
8477
+ var convertToPickedStore = (store) => {
8478
+ return {
8479
+ state: store.state,
8480
+ config: store.config,
8481
+ dispatch: store.dispatch,
8482
+ permissions: store.permissions,
8483
+ history: store.history,
8484
+ selectedItem: store.selectedItem
8485
+ };
8486
+ };
8487
+ var useRegisterUsePuckStore = (appStore) => {
8488
+ const [usePuckStore] = (0, import_react54.useState)(
8489
+ () => (0, import_zustand6.createStore)(
8490
+ () => generateUsePuck(convertToPickedStore(appStore.getState()))
8491
+ )
8443
8492
  );
8444
- return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: getClassName26(), children: [
8445
- viewports.map((viewport, i) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
8446
- ViewportButton,
8447
- {
8448
- height: viewport.height,
8449
- width: viewport.width,
8450
- title: viewport.label ? `Switch to ${viewport.label} viewport` : "Switch viewport",
8451
- onClick: onViewportChange,
8452
- children: typeof viewport.icon === "string" ? icons[viewport.icon] || viewport.icon : viewport.icon || icons.Smartphone
8453
- },
8454
- i
8455
- )),
8456
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: getClassName26("divider") }),
8457
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
8458
- IconButton,
8459
- {
8460
- title: "Zoom viewport out",
8461
- disabled: zoom <= ((_a = zoomOptions[0]) == null ? void 0 : _a.value),
8462
- onClick: (e) => {
8463
- e.stopPropagation();
8464
- onZoom(
8465
- zoomOptions[Math.max(
8466
- zoomOptions.findIndex((option) => option.value === zoom) - 1,
8467
- 0
8468
- )].value
8469
- );
8470
- },
8471
- children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ZoomOut, { size: 16 })
8472
- }
8473
- ),
8474
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
8475
- IconButton,
8476
- {
8477
- title: "Zoom viewport in",
8478
- disabled: zoom >= ((_b = zoomOptions[zoomOptions.length - 1]) == null ? void 0 : _b.value),
8479
- onClick: (e) => {
8480
- e.stopPropagation();
8481
- onZoom(
8482
- zoomOptions[Math.min(
8483
- zoomOptions.findIndex((option) => option.value === zoom) + 1,
8484
- zoomOptions.length - 1
8485
- )].value
8486
- );
8487
- },
8488
- children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(ZoomIn, { size: 16 })
8489
- }
8490
- ),
8491
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)("div", { className: getClassName26("divider") }),
8492
- /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
8493
- "select",
8494
- {
8495
- className: getClassName26("zoomSelect"),
8496
- value: zoom.toString(),
8497
- onChange: (e) => {
8498
- onZoom(parseFloat(e.currentTarget.value));
8499
- },
8500
- children: zoomOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
8501
- "option",
8502
- {
8503
- value: option.value,
8504
- label: option.label
8505
- },
8506
- option.label
8507
- ))
8493
+ (0, import_react54.useEffect)(() => {
8494
+ return appStore.subscribe(
8495
+ (store) => convertToPickedStore(store),
8496
+ (pickedStore) => {
8497
+ usePuckStore.setState(generateUsePuck(pickedStore));
8508
8498
  }
8509
- )
8510
- ] });
8499
+ );
8500
+ }, []);
8501
+ return usePuckStore;
8511
8502
  };
8503
+ function createUsePuck() {
8504
+ return function usePuck2(selector) {
8505
+ const usePuckApi = (0, import_react54.useContext)(UsePuckStoreContext);
8506
+ if (!usePuckApi) {
8507
+ throw new Error("usePuck must be used inside <Puck>.");
8508
+ }
8509
+ const result = (0, import_zustand6.useStore)(
8510
+ usePuckApi,
8511
+ selector != null ? selector : (s) => s
8512
+ );
8513
+ return result;
8514
+ };
8515
+ }
8516
+ function usePuck() {
8517
+ (0, import_react54.useEffect)(() => {
8518
+ console.warn(
8519
+ "You're using the `usePuck` method without a selector, which may cause unnecessary re-renders. Replace with `createUsePuck` and provide a selector for improved performance."
8520
+ );
8521
+ }, []);
8522
+ return createUsePuck()((s) => s);
8523
+ }
8524
+ function useGetPuck() {
8525
+ const usePuckApi = (0, import_react54.useContext)(UsePuckStoreContext);
8526
+ if (!usePuckApi) {
8527
+ throw new Error("usePuckGet must be used inside <Puck>.");
8528
+ }
8529
+ return usePuckApi.getState;
8530
+ }
8531
+
8532
+ // components/Puck/index.tsx
8533
+ var import_fast_deep_equal3 = __toESM(require("fast-deep-equal"));
8534
+
8535
+ // components/Puck/components/Header/index.tsx
8536
+ init_react_import();
8537
+ var import_react55 = require("react");
8512
8538
 
8513
- // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Canvas/styles.module.css#css-module
8539
+ // components/MenuBar/index.tsx
8514
8540
  init_react_import();
8515
- var styles_module_default22 = { "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" };
8516
8541
 
8517
- // lib/get-zoom-config.ts
8542
+ // css-module:/home/runner/work/puck/puck/packages/core/components/MenuBar/styles.module.css#css-module
8518
8543
  init_react_import();
8519
- var RESET_ZOOM_SMALLER_THAN_FRAME = true;
8520
- var getZoomConfig = (uiViewport, frame, zoom) => {
8521
- const box = getBox(frame);
8522
- const { width: frameWidth, height: frameHeight } = box.contentBox;
8523
- const viewportHeight = uiViewport.height === "auto" ? frameHeight : uiViewport.height;
8524
- let rootHeight = 0;
8525
- let autoZoom = 1;
8526
- if (uiViewport.width > frameWidth || viewportHeight > frameHeight) {
8527
- const widthZoom = Math.min(frameWidth / uiViewport.width, 1);
8528
- const heightZoom = Math.min(frameHeight / viewportHeight, 1);
8529
- zoom = widthZoom;
8530
- if (widthZoom < heightZoom) {
8531
- rootHeight = viewportHeight / zoom;
8532
- } else {
8533
- rootHeight = viewportHeight;
8534
- zoom = heightZoom;
8535
- }
8536
- autoZoom = zoom;
8537
- } else {
8538
- if (RESET_ZOOM_SMALLER_THAN_FRAME) {
8539
- autoZoom = 1;
8540
- zoom = 1;
8541
- rootHeight = viewportHeight;
8542
- }
8543
- }
8544
- return { autoZoom, rootHeight, zoom };
8545
- };
8544
+ var styles_module_default21 = { "MenuBar": "_MenuBar_8pf8c_1", "MenuBar--menuOpen": "_MenuBar--menuOpen_8pf8c_14", "MenuBar-inner": "_MenuBar-inner_8pf8c_29", "MenuBar-history": "_MenuBar-history_8pf8c_45" };
8546
8545
 
8547
- // components/Puck/components/Canvas/index.tsx
8548
- var import_shallow8 = require("zustand/react/shallow");
8549
- var import_jsx_runtime41 = require("react/jsx-runtime");
8550
- var getClassName27 = get_class_name_factory_default("PuckCanvas", styles_module_default22);
8551
- var ZOOM_ON_CHANGE = true;
8552
- var Canvas = () => {
8553
- const {
8554
- dispatch,
8555
- overrides,
8556
- setUi,
8557
- zoomConfig,
8558
- setZoomConfig,
8559
- status,
8560
- iframe
8561
- } = useAppStore(
8562
- (0, import_shallow8.useShallow)((s) => ({
8563
- dispatch: s.dispatch,
8564
- overrides: s.overrides,
8565
- setUi: s.setUi,
8566
- zoomConfig: s.zoomConfig,
8567
- setZoomConfig: s.setZoomConfig,
8568
- status: s.status,
8569
- iframe: s.iframe
8570
- }))
8571
- );
8572
- const { leftSideBarVisible, rightSideBarVisible, viewports } = useAppStore(
8573
- (0, import_shallow8.useShallow)((s) => ({
8574
- leftSideBarVisible: s.state.ui.leftSideBarVisible,
8575
- rightSideBarVisible: s.state.ui.rightSideBarVisible,
8576
- viewports: s.state.ui.viewports
8577
- }))
8578
- );
8579
- const frameRef = (0, import_react55.useRef)(null);
8580
- const [showTransition, setShowTransition] = (0, import_react55.useState)(false);
8581
- const defaultRender = (0, import_react55.useMemo)(() => {
8582
- const PuckDefault = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(import_jsx_runtime41.Fragment, { children });
8583
- return PuckDefault;
8584
- }, []);
8585
- const CustomPreview = (0, import_react55.useMemo)(
8586
- () => overrides.preview || defaultRender,
8587
- [overrides]
8588
- );
8589
- const getFrameDimensions = (0, import_react55.useCallback)(() => {
8590
- if (frameRef.current) {
8591
- const frame = frameRef.current;
8592
- const box = getBox(frame);
8593
- return { width: box.contentBox.width, height: box.contentBox.height };
8594
- }
8595
- return { width: 0, height: 0 };
8596
- }, [frameRef]);
8597
- const resetAutoZoom = (0, import_react55.useCallback)(
8598
- (newViewports = viewports) => {
8599
- if (frameRef.current) {
8600
- setZoomConfig(
8601
- getZoomConfig(
8602
- newViewports == null ? void 0 : newViewports.current,
8603
- frameRef.current,
8604
- zoomConfig.zoom
8605
- )
8606
- );
8607
- }
8608
- },
8609
- [frameRef, zoomConfig, viewports]
8610
- );
8611
- (0, import_react55.useEffect)(() => {
8612
- setShowTransition(false);
8613
- resetAutoZoom(viewports);
8614
- }, [frameRef, leftSideBarVisible, rightSideBarVisible]);
8615
- (0, import_react55.useEffect)(() => {
8616
- const { height: frameHeight } = getFrameDimensions();
8617
- if (viewports.current.height === "auto") {
8618
- setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
8619
- rootHeight: frameHeight / zoomConfig.zoom
8620
- }));
8621
- }
8622
- }, [zoomConfig.zoom]);
8623
- (0, import_react55.useEffect)(() => {
8624
- if (ZOOM_ON_CHANGE) {
8625
- setShowTransition(true);
8626
- resetAutoZoom(viewports);
8627
- }
8628
- }, [viewports.current.width]);
8629
- (0, import_react55.useEffect)(() => {
8630
- const cb = () => {
8631
- setShowTransition(false);
8632
- resetAutoZoom();
8633
- };
8634
- window.addEventListener("resize", cb);
8635
- return () => {
8636
- window.removeEventListener("resize", cb);
8637
- };
8638
- }, []);
8639
- const [showLoader, setShowLoader] = (0, import_react55.useState)(false);
8640
- (0, import_react55.useEffect)(() => {
8641
- setTimeout(() => {
8642
- setShowLoader(true);
8643
- }, 500);
8644
- }, []);
8645
- return /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(
8546
+ // components/MenuBar/index.tsx
8547
+ var import_jsx_runtime40 = require("react/jsx-runtime");
8548
+ var getClassName26 = get_class_name_factory_default("MenuBar", styles_module_default21);
8549
+ function MenuBar({
8550
+ menuOpen = false,
8551
+ renderHeaderActions,
8552
+ setMenuOpen
8553
+ }) {
8554
+ const back = useAppStore((s) => s.history.back);
8555
+ const forward = useAppStore((s) => s.history.forward);
8556
+ const hasFuture = useAppStore((s) => s.history.hasFuture());
8557
+ const hasPast = useAppStore((s) => s.history.hasPast());
8558
+ return /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
8646
8559
  "div",
8647
8560
  {
8648
- className: getClassName27({
8649
- ready: status === "READY" || !iframe.enabled || !iframe.waitForStyles,
8650
- showLoader
8651
- }),
8652
- onClick: () => dispatch({
8653
- type: "setUi",
8654
- ui: { itemSelector: null },
8655
- recordHistory: true
8656
- }),
8657
- children: [
8658
- viewports.controlsVisible && iframe.enabled && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: getClassName27("controls"), children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
8659
- ViewportControls,
8660
- {
8661
- autoZoom: zoomConfig.autoZoom,
8662
- zoom: zoomConfig.zoom,
8663
- onViewportChange: (viewport) => {
8664
- setShowTransition(true);
8665
- const uiViewport = __spreadProps(__spreadValues({}, viewport), {
8666
- height: viewport.height || "auto",
8667
- zoom: zoomConfig.zoom
8668
- });
8669
- const newUi = {
8670
- viewports: __spreadProps(__spreadValues({}, viewports), { current: uiViewport }),
8671
- itemSelector: null
8672
- };
8673
- setUi(newUi);
8674
- if (ZOOM_ON_CHANGE) {
8675
- resetAutoZoom(__spreadProps(__spreadValues({}, viewports), { current: uiViewport }));
8676
- }
8677
- },
8678
- onZoom: (zoom) => {
8679
- setShowTransition(true);
8680
- setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), { zoom }));
8681
- }
8682
- }
8683
- ) }),
8684
- /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: getClassName27("inner"), ref: frameRef, children: [
8685
- /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
8686
- "div",
8561
+ className: getClassName26({ menuOpen }),
8562
+ onClick: (event) => {
8563
+ var _a;
8564
+ const element = event.target;
8565
+ if (window.matchMedia("(min-width: 638px)").matches) {
8566
+ return;
8567
+ }
8568
+ if (element.tagName === "A" && ((_a = element.getAttribute("href")) == null ? void 0 : _a.startsWith("#"))) {
8569
+ setMenuOpen(false);
8570
+ }
8571
+ },
8572
+ children: /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: getClassName26("inner"), children: [
8573
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)("div", { className: getClassName26("history"), children: [
8574
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
8575
+ IconButton,
8687
8576
  {
8688
- className: getClassName27("root"),
8689
- style: {
8690
- width: iframe.enabled ? viewports.current.width : "100%",
8691
- height: zoomConfig.rootHeight,
8692
- transform: iframe.enabled ? `scale(${zoomConfig.zoom})` : void 0,
8693
- transition: showTransition ? "width 150ms ease-out, height 150ms ease-out, transform 150ms ease-out" : "",
8694
- overflow: iframe.enabled ? void 0 : "auto"
8695
- },
8696
- suppressHydrationWarning: true,
8697
- id: "puck-canvas-root",
8698
- onTransitionEnd: () => {
8699
- window.dispatchEvent(
8700
- new CustomEvent("viewportchange", {
8701
- bubbles: true,
8702
- cancelable: false
8703
- })
8704
- );
8705
- },
8706
- children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(CustomPreview, { children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Preview2, {}) })
8577
+ type: "button",
8578
+ title: "undo",
8579
+ disabled: !hasPast,
8580
+ onClick: back,
8581
+ children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Undo2, { size: 21 })
8707
8582
  }
8708
8583
  ),
8709
- /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: getClassName27("loader"), children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Loader, { size: 24 }) })
8710
- ] })
8711
- ]
8584
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(
8585
+ IconButton,
8586
+ {
8587
+ type: "button",
8588
+ title: "redo",
8589
+ disabled: !hasFuture,
8590
+ onClick: forward,
8591
+ children: /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(Redo2, { size: 21 })
8592
+ }
8593
+ )
8594
+ ] }),
8595
+ /* @__PURE__ */ (0, import_jsx_runtime40.jsx)(import_jsx_runtime40.Fragment, { children: renderHeaderActions && renderHeaderActions() })
8596
+ ] })
8712
8597
  }
8713
8598
  );
8714
- };
8715
-
8716
- // components/Puck/components/Nav/index.tsx
8717
- init_react_import();
8599
+ }
8718
8600
 
8719
- // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Nav/styles.module.css#css-module
8601
+ // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Header/styles.module.css#css-module
8720
8602
  init_react_import();
8721
- var styles_module_default23 = { "Nav-list": "_Nav-list_b6txo_1", "NavSection": "_NavSection_b6txo_7", "Nav--slim": "_Nav--slim_b6txo_15", "NavSection-list": "_NavSection-list_b6txo_24", "NavSection-title": "_NavSection-title_b6txo_36", "NavItem-link": "_NavItem-link_b6txo_47", "NavItem-linkIcon": "_NavItem-linkIcon_b6txo_67", "NavItem--active": "_NavItem--active_b6txo_72", "NavItem": "_NavItem_b6txo_47", "NavItem-list": "_NavItem-list_b6txo_91" };
8722
-
8723
- // components/Puck/components/Nav/index.tsx
8724
- var import_jsx_runtime42 = require("react/jsx-runtime");
8725
- var getClassName28 = get_class_name_factory_default("Nav", styles_module_default23);
8726
- var getClassNameSection = get_class_name_factory_default("NavSection", styles_module_default23);
8727
- var getClassNameItem3 = get_class_name_factory_default("NavItem", styles_module_default23);
8728
- var MenuItem = ({
8729
- label,
8730
- icon,
8731
- items,
8732
- onClick,
8733
- isActive
8734
- }) => {
8735
- const showChildren = isActive;
8736
- return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)("li", { className: getClassNameItem3({ active: isActive }), children: [
8737
- onClick && /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)("div", { className: getClassNameItem3("link"), onClick, children: [
8738
- icon && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("span", { className: getClassNameItem3("linkIcon"), children: icon }),
8739
- /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("span", { className: getClassNameItem3("linkLabel"), children: label })
8740
- ] }),
8741
- items && showChildren && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("ul", { className: getClassNameItem3("list"), children: Object.entries(items).map(([key, item]) => /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(MenuItem, __spreadValues({}, item), key)) })
8742
- ] });
8743
- };
8744
- var NavSection = ({ title, items }) => {
8745
- return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)("li", { className: getClassNameSection(), children: [
8746
- title && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("div", { className: getClassNameSection("title"), children: title }),
8747
- /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("ul", { className: getClassNameSection("list"), children: Object.entries(items).map(([key, item]) => /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(MenuItem, __spreadValues({}, item), key)) })
8748
- ] });
8749
- };
8750
- var Nav = ({
8751
- navigation,
8752
- slim
8753
- }) => {
8754
- return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("nav", { className: getClassName28({ slim }), children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("ul", { className: getClassName28("list"), children: Object.entries(navigation).map(([key, section]) => {
8755
- return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(NavSection, { title: section.title, items: section.items }, key);
8756
- }) }) });
8757
- };
8603
+ var styles_module_default22 = { "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" };
8758
8604
 
8759
- // components/Puck/components/Layout/index.tsx
8760
- var import_jsx_runtime43 = require("react/jsx-runtime");
8761
- var getClassName29 = get_class_name_factory_default("Puck", styles_module_default17);
8762
- var getLayoutClassName = get_class_name_factory_default("PuckLayout", styles_module_default17);
8763
- var FieldSideBar = () => {
8764
- const title = useAppStore(
8765
- (s) => {
8766
- var _a, _b;
8767
- return s.selectedItem ? (_b = (_a = s.config.components[s.selectedItem.type]) == null ? void 0 : _a["label"]) != null ? _b : s.selectedItem.type.toString() : "Page";
8605
+ // components/Puck/components/Header/index.tsx
8606
+ var import_jsx_runtime41 = require("react/jsx-runtime");
8607
+ var getClassName27 = get_class_name_factory_default("PuckHeader", styles_module_default22);
8608
+ var HeaderInner = () => {
8609
+ const {
8610
+ onPublish,
8611
+ renderHeader,
8612
+ renderHeaderActions,
8613
+ headerTitle,
8614
+ headerPath,
8615
+ iframe: _iframe
8616
+ } = usePropsContext();
8617
+ const dispatch = useAppStore((s) => s.dispatch);
8618
+ const appStore = useAppStoreApi();
8619
+ const defaultHeaderRender = (0, import_react55.useMemo)(() => {
8620
+ if (renderHeader) {
8621
+ console.warn(
8622
+ "`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
8623
+ );
8624
+ const RenderHeader = (_a) => {
8625
+ var _b = _a, { actions } = _b, props = __objRest(_b, ["actions"]);
8626
+ const Comp = renderHeader;
8627
+ const appState = useAppStore((s) => s.state);
8628
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState, children: actions }));
8629
+ };
8630
+ return RenderHeader;
8631
+ }
8632
+ return DefaultOverride;
8633
+ }, [renderHeader]);
8634
+ const defaultHeaderActionsRender = (0, import_react55.useMemo)(() => {
8635
+ if (renderHeaderActions) {
8636
+ console.warn(
8637
+ "`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
8638
+ );
8639
+ const RenderHeader = (props) => {
8640
+ const Comp = renderHeaderActions;
8641
+ const appState = useAppStore((s) => s.state);
8642
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Comp, __spreadProps(__spreadValues({}, props), { dispatch, state: appState }));
8643
+ };
8644
+ return RenderHeader;
8768
8645
  }
8646
+ return DefaultOverride;
8647
+ }, [renderHeader]);
8648
+ const CustomHeader = useAppStore(
8649
+ (s) => s.overrides.header || defaultHeaderRender
8769
8650
  );
8770
- return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(SidebarSection, { noPadding: true, noBorderTop: true, showBreadcrumbs: true, title, children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Fields, {}) });
8771
- };
8772
- var Layout = ({ children }) => {
8773
- const {
8774
- iframe: _iframe,
8775
- dnd,
8776
- initialHistory: _initialHistory,
8777
- plugins
8778
- } = usePropsContext();
8779
- const iframe = (0, import_react56.useMemo)(
8780
- () => __spreadValues({
8781
- enabled: true,
8782
- waitForStyles: true
8783
- }, _iframe),
8784
- [_iframe]
8651
+ const CustomHeaderActions = useAppStore(
8652
+ (s) => s.overrides.headerActions || defaultHeaderActionsRender
8785
8653
  );
8786
- useInjectGlobalCss(iframe.enabled);
8654
+ const [menuOpen, setMenuOpen] = (0, import_react55.useState)(false);
8655
+ const rootTitle = useAppStore((s) => {
8656
+ var _a, _b;
8657
+ const rootData = (_a = s.state.indexes.nodes["root"]) == null ? void 0 : _a.data;
8658
+ return (_b = rootData.props.title) != null ? _b : "";
8659
+ });
8787
8660
  const leftSideBarVisible = useAppStore((s) => s.state.ui.leftSideBarVisible);
8788
8661
  const rightSideBarVisible = useAppStore(
8789
8662
  (s) => s.state.ui.rightSideBarVisible
8790
8663
  );
8791
- const dispatch = useAppStore((s) => s.dispatch);
8792
- (0, import_react56.useEffect)(() => {
8793
- if (!window.matchMedia("(min-width: 638px)").matches) {
8664
+ const toggleSidebars = (0, import_react55.useCallback)(
8665
+ (sidebar) => {
8666
+ const widerViewport = window.matchMedia("(min-width: 638px)").matches;
8667
+ const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
8668
+ const oppositeSideBar = sidebar === "left" ? "rightSideBarVisible" : "leftSideBarVisible";
8794
8669
  dispatch({
8795
8670
  type: "setUi",
8796
- ui: {
8797
- leftSideBarVisible: false,
8798
- rightSideBarVisible: false
8799
- }
8671
+ ui: __spreadValues({
8672
+ [`${sidebar}SideBarVisible`]: !sideBarVisible
8673
+ }, !widerViewport ? { [oppositeSideBar]: false } : {})
8800
8674
  });
8801
- }
8802
- const handleResize = () => {
8803
- if (!window.matchMedia("(min-width: 638px)").matches) {
8804
- dispatch({
8805
- type: "setUi",
8806
- ui: (ui) => __spreadValues(__spreadValues({}, ui), ui.rightSideBarVisible ? { leftSideBarVisible: false } : {})
8807
- });
8808
- }
8809
- };
8810
- window.addEventListener("resize", handleResize);
8811
- return () => {
8812
- window.removeEventListener("resize", handleResize);
8813
- };
8814
- }, []);
8815
- const overrides = useAppStore((s) => s.overrides);
8816
- const CustomPuck = (0, import_react56.useMemo)(
8817
- () => overrides.puck || DefaultOverride,
8818
- [overrides]
8675
+ },
8676
+ [dispatch, leftSideBarVisible, rightSideBarVisible]
8819
8677
  );
8820
- const [mounted, setMounted] = (0, import_react56.useState)(false);
8821
- (0, import_react56.useEffect)(() => {
8822
- setMounted(true);
8823
- }, []);
8824
- const ready = useAppStore((s) => s.status === "READY");
8825
- useMonitorHotkeys();
8826
- (0, import_react56.useEffect)(() => {
8827
- if (ready && iframe.enabled) {
8828
- const frameDoc = getFrame();
8829
- if (frameDoc) {
8830
- return monitorHotkeys(frameDoc);
8831
- }
8832
- }
8833
- }, [ready, iframe.enabled]);
8834
- usePreviewModeHotkeys();
8835
- const [view, setView] = (0, import_react56.useState)("blocks");
8836
- const pluginItems = (0, import_react56.useMemo)(() => {
8837
- const details = {};
8838
- plugins == null ? void 0 : plugins.forEach((plugin) => {
8839
- var _a, _b;
8840
- if (plugin.name && plugin.render) {
8841
- details[plugin.name] = {
8842
- label: (_a = plugin.label) != null ? _a : plugin.name,
8843
- icon: (_b = plugin.icon) != null ? _b : /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(ToyBrick, {}),
8678
+ return /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
8679
+ CustomHeader,
8680
+ {
8681
+ actions: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(import_jsx_runtime41.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(CustomHeaderActions, { children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
8682
+ Button,
8683
+ {
8844
8684
  onClick: () => {
8845
- setView(plugin.name);
8685
+ const data = appStore.getState().state.data;
8686
+ onPublish && onPublish(data);
8846
8687
  },
8847
- isActive: view === plugin.name,
8848
- render: plugin.render
8849
- };
8850
- }
8851
- });
8852
- return details;
8853
- }, [plugins, view]);
8854
- const PluginRender = (0, import_react56.useMemo)(() => {
8855
- var _a;
8856
- if (view === "blocks") {
8857
- return Components;
8858
- } else if (view === "outline") {
8859
- return Outline;
8860
- } else {
8861
- return (_a = pluginItems[view]) == null ? void 0 : _a.render;
8862
- }
8863
- }, [view]);
8864
- return /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: `Puck ${getClassName29()}`, children: [
8865
- /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(DragDropContext, { disableAutoScroll: dnd == null ? void 0 : dnd.disableAutoScroll, children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(CustomPuck, { children: children || /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
8866
- "div",
8867
- {
8868
- className: getLayoutClassName({
8869
- leftSideBarVisible,
8870
- mounted,
8871
- rightSideBarVisible
8872
- }),
8873
- children: /* @__PURE__ */ (0, import_jsx_runtime43.jsxs)("div", { className: getLayoutClassName("inner"), children: [
8874
- /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Header, {}),
8875
- /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: getLayoutClassName("nav"), children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
8876
- Nav,
8877
- {
8878
- slim: true,
8879
- navigation: {
8880
- main: {
8881
- items: __spreadValues({
8882
- build: {
8883
- label: "Blocks",
8884
- icon: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Hammer, {}),
8885
- onClick: () => {
8886
- setView("blocks");
8887
- },
8888
- isActive: view === "blocks"
8889
- },
8890
- outline: {
8891
- label: "Outline",
8892
- icon: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Layers, {}),
8688
+ icon: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Globe, { size: "14px" }),
8689
+ children: "Publish"
8690
+ }
8691
+ ) }) }),
8692
+ children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
8693
+ "header",
8694
+ {
8695
+ className: getClassName27({ leftSideBarVisible, rightSideBarVisible }),
8696
+ children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: getClassName27("inner"), children: [
8697
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: getClassName27("toggle"), children: [
8698
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: getClassName27("leftSideBarToggle"), children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
8699
+ IconButton,
8700
+ {
8701
+ type: "button",
8702
+ onClick: () => {
8703
+ toggleSidebars("left");
8704
+ },
8705
+ title: "Toggle left sidebar",
8706
+ children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(PanelLeft, { focusable: "false" })
8707
+ }
8708
+ ) }),
8709
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: getClassName27("rightSideBarToggle"), children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
8710
+ IconButton,
8711
+ {
8712
+ type: "button",
8713
+ onClick: () => {
8714
+ toggleSidebars("right");
8715
+ },
8716
+ title: "Toggle right sidebar",
8717
+ children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(PanelRight, { focusable: "false" })
8718
+ }
8719
+ ) })
8720
+ ] }),
8721
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: getClassName27("title"), children: /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(Heading, { rank: "2", size: "xs", children: [
8722
+ headerTitle || rootTitle || "Page",
8723
+ headerPath && /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, { children: [
8724
+ " ",
8725
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("code", { className: getClassName27("path"), children: headerPath })
8726
+ ] })
8727
+ ] }) }),
8728
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)("div", { className: getClassName27("tools"), children: [
8729
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)("div", { className: getClassName27("menuButton"), children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
8730
+ IconButton,
8731
+ {
8732
+ type: "button",
8733
+ onClick: () => {
8734
+ return setMenuOpen(!menuOpen);
8735
+ },
8736
+ title: "Toggle menu bar",
8737
+ children: menuOpen ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ChevronUp, { focusable: "false" }) : /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(ChevronDown, { focusable: "false" })
8738
+ }
8739
+ ) }),
8740
+ /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
8741
+ MenuBar,
8742
+ {
8743
+ dispatch,
8744
+ onPublish,
8745
+ menuOpen,
8746
+ renderHeaderActions: () => /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(CustomHeaderActions, { children: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(
8747
+ Button,
8748
+ {
8893
8749
  onClick: () => {
8894
- setView("outline");
8750
+ const data = appStore.getState().state.data;
8751
+ onPublish && onPublish(data);
8895
8752
  },
8896
- isActive: view === "outline"
8753
+ icon: /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Globe, { size: "14px" }),
8754
+ children: "Publish"
8897
8755
  }
8898
- }, pluginItems)
8756
+ ) }),
8757
+ setMenuOpen
8899
8758
  }
8900
- }
8901
- }
8902
- ) }),
8903
- /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: getLayoutClassName("leftSideBar"), children: leftSideBarVisible && /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(PluginRender, {}) }),
8904
- /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(Canvas, {}),
8905
- /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { className: getLayoutClassName("rightSideBar"), children: /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(FieldSideBar, {}) })
8906
- ] })
8907
- }
8908
- ) }) }),
8909
- /* @__PURE__ */ (0, import_jsx_runtime43.jsx)("div", { id: "puck-portal-root", className: getClassName29("portal") })
8910
- ] });
8759
+ )
8760
+ ] })
8761
+ ] })
8762
+ }
8763
+ )
8764
+ }
8765
+ );
8911
8766
  };
8767
+ var Header = (0, import_react55.memo)(HeaderInner);
8912
8768
 
8913
8769
  // components/Puck/index.tsx
8914
- var import_jsx_runtime44 = require("react/jsx-runtime");
8915
- var propsContext = (0, import_react57.createContext)({});
8770
+ var import_jsx_runtime42 = require("react/jsx-runtime");
8771
+ var getClassName28 = get_class_name_factory_default("Puck", styles_module_default14);
8772
+ var getLayoutClassName = get_class_name_factory_default("PuckLayout", styles_module_default14);
8773
+ var FieldSideBar = () => {
8774
+ const title = useAppStore(
8775
+ (s) => {
8776
+ var _a, _b;
8777
+ return s.selectedItem ? (_b = (_a = s.config.components[s.selectedItem.type]) == null ? void 0 : _a["label"]) != null ? _b : s.selectedItem.type.toString() : "Page";
8778
+ }
8779
+ );
8780
+ return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(SidebarSection, { noPadding: true, noBorderTop: true, showBreadcrumbs: true, title, children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(Fields, {}) });
8781
+ };
8782
+ var propsContext = (0, import_react56.createContext)({});
8916
8783
  function PropsProvider(props) {
8917
- return /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(propsContext.Provider, { value: props, children: props.children });
8784
+ return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(propsContext.Provider, { value: props, children: props.children });
8918
8785
  }
8919
- var usePropsContext = () => (0, import_react57.useContext)(propsContext);
8786
+ var usePropsContext = () => (0, import_react56.useContext)(propsContext);
8920
8787
  function PuckProvider({ children }) {
8921
8788
  const {
8922
8789
  config,
@@ -8932,14 +8799,14 @@ function PuckProvider({ children }) {
8932
8799
  metadata,
8933
8800
  onAction
8934
8801
  } = usePropsContext();
8935
- const iframe = (0, import_react57.useMemo)(
8802
+ const iframe = (0, import_react56.useMemo)(
8936
8803
  () => __spreadValues({
8937
8804
  enabled: true,
8938
8805
  waitForStyles: true
8939
8806
  }, _iframe),
8940
8807
  [_iframe]
8941
8808
  );
8942
- const [generatedAppState] = (0, import_react57.useState)(() => {
8809
+ const [generatedAppState] = (0, import_react56.useState)(() => {
8943
8810
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
8944
8811
  const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
8945
8812
  let clientUiState = {};
@@ -8999,7 +8866,7 @@ function PuckProvider({ children }) {
8999
8866
  return walkAppState(newAppState, config);
9000
8867
  });
9001
8868
  const { appendData = true } = _initialHistory || {};
9002
- const [blendedHistories] = (0, import_react57.useState)(
8869
+ const [blendedHistories] = (0, import_react56.useState)(
9003
8870
  [
9004
8871
  ...(_initialHistory == null ? void 0 : _initialHistory.histories) || [],
9005
8872
  ...appendData ? [{ state: generatedAppState }] : []
@@ -9019,7 +8886,7 @@ function PuckProvider({ children }) {
9019
8886
  overrides,
9020
8887
  plugins
9021
8888
  });
9022
- const generateAppStore = (0, import_react57.useCallback)(
8889
+ const generateAppStore = (0, import_react56.useCallback)(
9023
8890
  (state) => {
9024
8891
  return {
9025
8892
  state,
@@ -9043,15 +8910,15 @@ function PuckProvider({ children }) {
9043
8910
  metadata
9044
8911
  ]
9045
8912
  );
9046
- const [appStore] = (0, import_react57.useState)(
8913
+ const [appStore] = (0, import_react56.useState)(
9047
8914
  () => createAppStore(generateAppStore(initialAppState))
9048
8915
  );
9049
- (0, import_react57.useEffect)(() => {
8916
+ (0, import_react56.useEffect)(() => {
9050
8917
  if (process.env.NODE_ENV !== "production") {
9051
8918
  window.__PUCK_INTERNAL_DO_NOT_USE = { appStore };
9052
8919
  }
9053
8920
  }, [appStore]);
9054
- (0, import_react57.useEffect)(() => {
8921
+ (0, import_react56.useEffect)(() => {
9055
8922
  const state = appStore.getState().state;
9056
8923
  appStore.setState(__spreadValues({}, generateAppStore(state)));
9057
8924
  }, [config, plugins, loadedOverrides, viewports, iframe, onAction, metadata]);
@@ -9060,8 +8927,8 @@ function PuckProvider({ children }) {
9060
8927
  index: initialHistoryIndex,
9061
8928
  initialAppState
9062
8929
  });
9063
- const previousData = (0, import_react57.useRef)(null);
9064
- (0, import_react57.useEffect)(() => {
8930
+ const previousData = (0, import_react56.useRef)(null);
8931
+ (0, import_react56.useEffect)(() => {
9065
8932
  appStore.subscribe(
9066
8933
  (s) => s.state.data,
9067
8934
  (data) => {
@@ -9075,14 +8942,99 @@ function PuckProvider({ children }) {
9075
8942
  }, []);
9076
8943
  useRegisterPermissionsSlice(appStore, permissions);
9077
8944
  const uPuckStore = useRegisterUsePuckStore(appStore);
9078
- (0, import_react57.useEffect)(() => {
8945
+ (0, import_react56.useEffect)(() => {
9079
8946
  const { resolveAndCommitData } = appStore.getState();
9080
8947
  resolveAndCommitData();
9081
8948
  }, []);
9082
- return /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(appStoreContext.Provider, { value: appStore, children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(UsePuckStoreContext.Provider, { value: uPuckStore, children }) });
8949
+ return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(appStoreContext.Provider, { value: appStore, children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(UsePuckStoreContext.Provider, { value: uPuckStore, children }) });
8950
+ }
8951
+ function PuckLayout({ children }) {
8952
+ const {
8953
+ iframe: _iframe,
8954
+ dnd,
8955
+ initialHistory: _initialHistory
8956
+ } = usePropsContext();
8957
+ const iframe = (0, import_react56.useMemo)(
8958
+ () => __spreadValues({
8959
+ enabled: true,
8960
+ waitForStyles: true
8961
+ }, _iframe),
8962
+ [_iframe]
8963
+ );
8964
+ useInjectGlobalCss(iframe.enabled);
8965
+ const leftSideBarVisible = useAppStore((s) => s.state.ui.leftSideBarVisible);
8966
+ const rightSideBarVisible = useAppStore(
8967
+ (s) => s.state.ui.rightSideBarVisible
8968
+ );
8969
+ const dispatch = useAppStore((s) => s.dispatch);
8970
+ (0, import_react56.useEffect)(() => {
8971
+ if (!window.matchMedia("(min-width: 638px)").matches) {
8972
+ dispatch({
8973
+ type: "setUi",
8974
+ ui: {
8975
+ leftSideBarVisible: false,
8976
+ rightSideBarVisible: false
8977
+ }
8978
+ });
8979
+ }
8980
+ const handleResize = () => {
8981
+ if (!window.matchMedia("(min-width: 638px)").matches) {
8982
+ dispatch({
8983
+ type: "setUi",
8984
+ ui: (ui) => __spreadValues(__spreadValues({}, ui), ui.rightSideBarVisible ? { leftSideBarVisible: false } : {})
8985
+ });
8986
+ }
8987
+ };
8988
+ window.addEventListener("resize", handleResize);
8989
+ return () => {
8990
+ window.removeEventListener("resize", handleResize);
8991
+ };
8992
+ }, []);
8993
+ const overrides = useAppStore((s) => s.overrides);
8994
+ const CustomPuck = (0, import_react56.useMemo)(
8995
+ () => overrides.puck || DefaultOverride,
8996
+ [overrides]
8997
+ );
8998
+ const [mounted, setMounted] = (0, import_react56.useState)(false);
8999
+ (0, import_react56.useEffect)(() => {
9000
+ setMounted(true);
9001
+ }, []);
9002
+ const ready = useAppStore((s) => s.status === "READY");
9003
+ useMonitorHotkeys();
9004
+ (0, import_react56.useEffect)(() => {
9005
+ if (ready && iframe.enabled) {
9006
+ const frameDoc = getFrame();
9007
+ if (frameDoc) {
9008
+ return monitorHotkeys(frameDoc);
9009
+ }
9010
+ }
9011
+ }, [ready, iframe.enabled]);
9012
+ usePreviewModeHotkeys();
9013
+ return /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)("div", { className: `Puck ${getClassName28()}`, children: [
9014
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(DragDropContext, { disableAutoScroll: dnd == null ? void 0 : dnd.disableAutoScroll, children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(CustomPuck, { children: children || /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(
9015
+ "div",
9016
+ {
9017
+ className: getLayoutClassName({
9018
+ leftSideBarVisible,
9019
+ mounted,
9020
+ rightSideBarVisible
9021
+ }),
9022
+ children: /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)("div", { className: getLayoutClassName("inner"), children: [
9023
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(Header, {}),
9024
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsxs)("div", { className: getLayoutClassName("leftSideBar"), children: [
9025
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(SidebarSection, { title: "Components", noBorderTop: true, children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(Components, {}) }),
9026
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(SidebarSection, { title: "Outline", children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(Outline, {}) })
9027
+ ] }),
9028
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(Canvas, {}),
9029
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("div", { className: getLayoutClassName("rightSideBar"), children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(FieldSideBar, {}) })
9030
+ ] })
9031
+ }
9032
+ ) }) }),
9033
+ /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("div", { id: "puck-portal-root", className: getClassName28("portal") })
9034
+ ] });
9083
9035
  }
9084
9036
  function Puck(props) {
9085
- return /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(PropsProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(PuckProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(Layout, { children: props.children }) })) }));
9037
+ return /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(PropsProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(PuckProvider, __spreadProps(__spreadValues({}, props), { children: /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(PuckLayout, __spreadValues({}, props)) })) }));
9086
9038
  }
9087
9039
  Puck.Components = Components;
9088
9040
  Puck.Fields = Fields;
@@ -9217,14 +9169,6 @@ lucide-react/dist/esm/icons/globe.js:
9217
9169
  * See the LICENSE file in the root directory of this source tree.
9218
9170
  *)
9219
9171
 
9220
- lucide-react/dist/esm/icons/hammer.js:
9221
- (**
9222
- * @license lucide-react v0.468.0 - ISC
9223
- *
9224
- * This source code is licensed under the ISC license.
9225
- * See the LICENSE file in the root directory of this source tree.
9226
- *)
9227
-
9228
9172
  lucide-react/dist/esm/icons/hash.js:
9229
9173
  (**
9230
9174
  * @license lucide-react v0.468.0 - ISC
@@ -9353,14 +9297,6 @@ lucide-react/dist/esm/icons/tablet.js:
9353
9297
  * See the LICENSE file in the root directory of this source tree.
9354
9298
  *)
9355
9299
 
9356
- lucide-react/dist/esm/icons/toy-brick.js:
9357
- (**
9358
- * @license lucide-react v0.468.0 - ISC
9359
- *
9360
- * This source code is licensed under the ISC license.
9361
- * See the LICENSE file in the root directory of this source tree.
9362
- *)
9363
-
9364
9300
  lucide-react/dist/esm/icons/trash.js:
9365
9301
  (**
9366
9302
  * @license lucide-react v0.468.0 - ISC