@measured/puck 0.12.0-canary.da2bc0f → 0.12.0-canary.f882878

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -327,7 +327,7 @@ var require_react_is_development = __commonJS({
327
327
  var ContextProvider = REACT_PROVIDER_TYPE;
328
328
  var Element = REACT_ELEMENT_TYPE;
329
329
  var ForwardRef = REACT_FORWARD_REF_TYPE;
330
- var Fragment13 = REACT_FRAGMENT_TYPE;
330
+ var Fragment14 = REACT_FRAGMENT_TYPE;
331
331
  var Lazy = REACT_LAZY_TYPE;
332
332
  var Memo = REACT_MEMO_TYPE;
333
333
  var Portal = REACT_PORTAL_TYPE;
@@ -386,7 +386,7 @@ var require_react_is_development = __commonJS({
386
386
  exports.ContextProvider = ContextProvider;
387
387
  exports.Element = Element;
388
388
  exports.ForwardRef = ForwardRef;
389
- exports.Fragment = Fragment13;
389
+ exports.Fragment = Fragment14;
390
390
  exports.Lazy = Lazy;
391
391
  exports.Memo = Memo;
392
392
  exports.Portal = Portal;
@@ -760,7 +760,7 @@ var require_factoryWithTypeCheckers = __commonJS({
760
760
  function validate(props, propName, componentName, location, propFullName) {
761
761
  if (!(props[propName] instanceof expectedClass)) {
762
762
  var expectedClassName = expectedClass.name || ANONYMOUS;
763
- var actualClassName = getClassName19(props[propName]);
763
+ var actualClassName = getClassName20(props[propName]);
764
764
  return new PropTypeError("Invalid " + location + " `" + propFullName + "` of type " + ("`" + actualClassName + "` supplied to `" + componentName + "`, expected ") + ("instance of `" + expectedClassName + "`."));
765
765
  }
766
766
  return null;
@@ -1012,7 +1012,7 @@ var require_factoryWithTypeCheckers = __commonJS({
1012
1012
  return type;
1013
1013
  }
1014
1014
  }
1015
- function getClassName19(propValue) {
1015
+ function getClassName20(propValue) {
1016
1016
  if (!propValue.constructor || !propValue.constructor.name) {
1017
1017
  return ANONYMOUS;
1018
1018
  }
@@ -9040,7 +9040,7 @@ var require_react_dom_development = __commonJS({
9040
9040
  var HostPortal = 4;
9041
9041
  var HostComponent = 5;
9042
9042
  var HostText = 6;
9043
- var Fragment13 = 7;
9043
+ var Fragment14 = 7;
9044
9044
  var Mode = 8;
9045
9045
  var ContextConsumer = 9;
9046
9046
  var ContextProvider = 10;
@@ -10196,7 +10196,7 @@ var require_react_dom_development = __commonJS({
10196
10196
  return "DehydratedFragment";
10197
10197
  case ForwardRef:
10198
10198
  return getWrappedName$1(type, type.render, "ForwardRef");
10199
- case Fragment13:
10199
+ case Fragment14:
10200
10200
  return "Fragment";
10201
10201
  case HostComponent:
10202
10202
  return type;
@@ -19867,7 +19867,7 @@ var require_react_dom_development = __commonJS({
19867
19867
  }
19868
19868
  }
19869
19869
  function updateFragment2(returnFiber, current2, fragment, lanes, key) {
19870
- if (current2 === null || current2.tag !== Fragment13) {
19870
+ if (current2 === null || current2.tag !== Fragment14) {
19871
19871
  var created = createFiberFromFragment(fragment, returnFiber.mode, lanes, key);
19872
19872
  created.return = returnFiber;
19873
19873
  return created;
@@ -20270,7 +20270,7 @@ var require_react_dom_development = __commonJS({
20270
20270
  if (child.key === key) {
20271
20271
  var elementType = element.type;
20272
20272
  if (elementType === REACT_FRAGMENT_TYPE) {
20273
- if (child.tag === Fragment13) {
20273
+ if (child.tag === Fragment14) {
20274
20274
  deleteRemainingChildren(returnFiber, child.sibling);
20275
20275
  var existing = useFiber(child, element.props.children);
20276
20276
  existing.return = returnFiber;
@@ -24445,7 +24445,7 @@ var require_react_dom_development = __commonJS({
24445
24445
  var _resolvedProps2 = workInProgress2.elementType === type ? _unresolvedProps2 : resolveDefaultProps(type, _unresolvedProps2);
24446
24446
  return updateForwardRef(current2, workInProgress2, type, _resolvedProps2, renderLanes2);
24447
24447
  }
24448
- case Fragment13:
24448
+ case Fragment14:
24449
24449
  return updateFragment(current2, workInProgress2, renderLanes2);
24450
24450
  case Mode:
24451
24451
  return updateMode(current2, workInProgress2, renderLanes2);
@@ -24718,7 +24718,7 @@ var require_react_dom_development = __commonJS({
24718
24718
  case SimpleMemoComponent:
24719
24719
  case FunctionComponent:
24720
24720
  case ForwardRef:
24721
- case Fragment13:
24721
+ case Fragment14:
24722
24722
  case Mode:
24723
24723
  case Profiler:
24724
24724
  case ContextConsumer:
@@ -28977,7 +28977,7 @@ var require_react_dom_development = __commonJS({
28977
28977
  return fiber;
28978
28978
  }
28979
28979
  function createFiberFromFragment(elements, mode, lanes, key) {
28980
- var fiber = createFiber(Fragment13, elements, key, mode);
28980
+ var fiber = createFiber(Fragment14, elements, key, mode);
28981
28981
  fiber.lanes = lanes;
28982
28982
  return fiber;
28983
28983
  }
@@ -30125,7 +30125,7 @@ var import_react2 = require("react");
30125
30125
 
30126
30126
  // css-module:/home/runner/work/puck/puck/packages/core/components/Button/Button.module.css#css-module
30127
30127
  init_react_import();
30128
- var Button_module_default = { "Button": "_Button_zx1c8_1", "Button--medium": "_Button--medium_zx1c8_21", "Button--large": "_Button--large_zx1c8_28", "Button-icon": "_Button-icon_zx1c8_35", "Button--primary": "_Button--primary_zx1c8_43", "Button--secondary": "_Button--secondary_zx1c8_52", "Button--flush": "_Button--flush_zx1c8_63", "Button--disabled": "_Button--disabled_zx1c8_67", "Button--fullWidth": "_Button--fullWidth_zx1c8_77" };
30128
+ var Button_module_default = { "Button": "_Button_1brfa_1", "Button--medium": "_Button--medium_1brfa_22", "Button--large": "_Button--large_1brfa_29", "Button-icon": "_Button-icon_1brfa_36", "Button--primary": "_Button--primary_1brfa_44", "Button--secondary": "_Button--secondary_1brfa_53", "Button--flush": "_Button--flush_1brfa_64", "Button--disabled": "_Button--disabled_1brfa_68", "Button--fullWidth": "_Button--fullWidth_1brfa_78" };
30129
30129
 
30130
30130
  // lib/get-class-name-factory.ts
30131
30131
  init_react_import();
@@ -31974,6 +31974,7 @@ var defaultAppState = {
31974
31974
  data: { content: [], root: { title: "" } },
31975
31975
  ui: {
31976
31976
  leftSideBarVisible: true,
31977
+ rightSideBarVisible: true,
31977
31978
  arrayState: {},
31978
31979
  itemSelector: null,
31979
31980
  componentList: {}
@@ -32301,7 +32302,7 @@ var import_react26 = require("react");
32301
32302
 
32302
32303
  // css-module:/home/runner/work/puck/puck/packages/core/components/IconButton/IconButton.module.css#css-module
32303
32304
  init_react_import();
32304
- var IconButton_module_default = { "IconButton": "_IconButton_13gzt_1" };
32305
+ var IconButton_module_default = { "IconButton": "_IconButton_38xdr_1", "IconButton-title": "_IconButton-title_38xdr_18" };
32305
32306
 
32306
32307
  // components/IconButton/IconButton.tsx
32307
32308
  var import_react_spinners3 = require("react-spinners");
@@ -32346,10 +32347,11 @@ var IconButton = ({
32346
32347
  href,
32347
32348
  title,
32348
32349
  children: [
32350
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: getClassName4("title"), children: title }),
32349
32351
  children,
32350
32352
  loading && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
32351
32353
  "\xA0\xA0",
32352
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_spinners3.ClipLoader, { color: "inherit", size: "14px" })
32354
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_spinners3.ClipLoader, { "aria-label": "Loading", color: "inherit", size: "14px" })
32353
32355
  ] })
32354
32356
  ]
32355
32357
  }
@@ -32367,7 +32369,7 @@ init_react_import();
32367
32369
 
32368
32370
  // css-module:/home/runner/work/puck/puck/packages/core/components/InputOrGroup/styles.module.css#css-module
32369
32371
  init_react_import();
32370
- var styles_module_default3 = { "Input": "_Input_199j9_1", "Input-label": "_Input-label_199j9_27", "Input-labelIcon": "_Input-labelIcon_199j9_35", "Input-disabledIcon": "_Input-disabledIcon_199j9_41", "Input-input": "_Input-input_199j9_46", "Input--readOnly": "_Input--readOnly_199j9_68", "Input-radioGroupItems": "_Input-radioGroupItems_199j9_86", "Input-radio": "_Input-radio_199j9_86", "Input-radioInner": "_Input-radioInner_199j9_103", "Input-radioInput": "_Input-radioInput_199j9_125" };
32372
+ var styles_module_default3 = { "Input": "_Input_1jyrm_1", "Input-label": "_Input-label_1jyrm_27", "Input-labelIcon": "_Input-labelIcon_1jyrm_35", "Input-disabledIcon": "_Input-disabledIcon_1jyrm_41", "Input-input": "_Input-input_1jyrm_46", "Input--readOnly": "_Input--readOnly_1jyrm_69", "Input-radioGroupItems": "_Input-radioGroupItems_1jyrm_87", "Input-radio": "_Input-radio_1jyrm_87", "Input-radioInner": "_Input-radioInner_1jyrm_104", "Input-radioInput": "_Input-radioInput_1jyrm_126" };
32371
32373
 
32372
32374
  // components/InputOrGroup/index.tsx
32373
32375
  var import_react31 = require("react");
@@ -32380,7 +32382,7 @@ init_react_import();
32380
32382
 
32381
32383
  // css-module:/home/runner/work/puck/puck/packages/core/components/InputOrGroup/fields/ArrayField/styles.module.css#css-module
32382
32384
  init_react_import();
32383
- var styles_module_default4 = { "ArrayField": "_ArrayField_hsw7n_5", "ArrayField--isDraggingFrom": "_ArrayField--isDraggingFrom_hsw7n_13", "ArrayField-addButton": "_ArrayField-addButton_hsw7n_17", "ArrayField--hasItems": "_ArrayField--hasItems_hsw7n_31", "ArrayFieldItem": "_ArrayFieldItem_hsw7n_45", "ArrayFieldItem--isDragging": "_ArrayFieldItem--isDragging_hsw7n_53", "ArrayFieldItem--isExpanded": "_ArrayFieldItem--isExpanded_hsw7n_58", "ArrayFieldItem-summary": "_ArrayFieldItem-summary_hsw7n_73", "ArrayFieldItem--readOnly": "_ArrayFieldItem--readOnly_hsw7n_86", "ArrayFieldItem-body": "_ArrayFieldItem-body_hsw7n_107", "ArrayFieldItem-fieldset": "_ArrayFieldItem-fieldset_hsw7n_115", "ArrayFieldItem-rhs": "_ArrayFieldItem-rhs_hsw7n_122", "ArrayFieldItem-actions": "_ArrayFieldItem-actions_hsw7n_128", "ArrayFieldItem-action": "_ArrayFieldItem-action_hsw7n_128" };
32385
+ var styles_module_default4 = { "ArrayField": "_ArrayField_1auyc_5", "ArrayField--isDraggingFrom": "_ArrayField--isDraggingFrom_1auyc_13", "ArrayField-addButton": "_ArrayField-addButton_1auyc_17", "ArrayField--hasItems": "_ArrayField--hasItems_1auyc_31", "ArrayFieldItem": "_ArrayFieldItem_1auyc_45", "ArrayFieldItem--isDragging": "_ArrayFieldItem--isDragging_1auyc_53", "ArrayFieldItem--isExpanded": "_ArrayFieldItem--isExpanded_1auyc_58", "ArrayFieldItem-summary": "_ArrayFieldItem-summary_1auyc_73", "ArrayFieldItem--readOnly": "_ArrayFieldItem--readOnly_1auyc_86", "ArrayFieldItem-body": "_ArrayFieldItem-body_1auyc_107", "ArrayFieldItem-fieldset": "_ArrayFieldItem-fieldset_1auyc_115", "ArrayFieldItem-rhs": "_ArrayFieldItem-rhs_1auyc_122", "ArrayFieldItem-actions": "_ArrayFieldItem-actions_1auyc_128", "ArrayFieldItem-action": "_ArrayFieldItem-action_1auyc_128" };
32384
32386
 
32385
32387
  // components/InputOrGroup/fields/ArrayField/index.tsx
32386
32388
  var import_dnd4 = require("@hello-pangea/dnd");
@@ -32434,11 +32436,6 @@ var Draggable2 = ({
32434
32436
  );
32435
32437
  };
32436
32438
 
32437
- // lib/generate-id.ts
32438
- init_react_import();
32439
- var import_crypto = require("crypto");
32440
- var generateId = (type) => `${type}-${(0, import_crypto.randomBytes)(20).toString("hex")}`;
32441
-
32442
32439
  // components/InputOrGroup/fields/ArrayField/index.tsx
32443
32440
  var import_react27 = require("react");
32444
32441
 
@@ -32465,47 +32462,59 @@ var ArrayField = ({
32465
32462
  name,
32466
32463
  label,
32467
32464
  readOnly,
32468
- readOnlyFields = {}
32465
+ readOnlyFields = {},
32466
+ id
32469
32467
  }) => {
32470
- const [arrayFieldId] = (0, import_react27.useState)(generateId("ArrayField"));
32471
32468
  const { state, setUi } = useAppContext();
32472
- const arrayStateRef = (0, import_react27.useRef)(
32473
- state.ui.arrayState[arrayFieldId] || {
32474
- items: [],
32475
- openId: ""
32476
- }
32477
- );
32478
- const arrayState = arrayStateRef.current;
32479
- const setArrayState = (0, import_react27.useCallback)(
32480
- (partialArrayState, recordHistory = false) => {
32481
- setUi(
32482
- {
32483
- arrayState: __spreadProps(__spreadValues({}, state.ui.arrayState), {
32484
- [arrayFieldId]: __spreadValues(__spreadValues({}, arrayState), partialArrayState)
32485
- })
32486
- },
32487
- recordHistory
32488
- );
32489
- arrayStateRef.current = __spreadValues(__spreadValues({}, arrayState), partialArrayState);
32469
+ const arrayState = state.ui.arrayState[id] || {
32470
+ items: Array.from(value || []).map((item, idx) => {
32471
+ return {
32472
+ _originalIndex: idx,
32473
+ _arrayId: `${id}-${idx}`,
32474
+ data: item
32475
+ };
32476
+ }),
32477
+ openId: ""
32478
+ };
32479
+ const [localState, setLocalState] = (0, import_react27.useState)({ arrayState, value });
32480
+ (0, import_react27.useEffect)(() => {
32481
+ setLocalState({ arrayState, value });
32482
+ }, [value, state.ui.arrayState[id]]);
32483
+ const mapArrayStateToUi = (0, import_react27.useCallback)(
32484
+ (partialArrayState) => {
32485
+ return {
32486
+ arrayState: __spreadProps(__spreadValues({}, state.ui.arrayState), {
32487
+ [id]: __spreadValues(__spreadValues({}, arrayState), partialArrayState)
32488
+ })
32489
+ };
32490
32490
  },
32491
32491
  [arrayState]
32492
32492
  );
32493
- (0, import_react27.useEffect)(() => {
32494
- let highestIndex = arrayState.items.reduce(
32493
+ const getHighestIndex = (0, import_react27.useCallback)(() => {
32494
+ return arrayState.items.reduce(
32495
32495
  (acc, item) => item._originalIndex > acc ? item._originalIndex : acc,
32496
32496
  -1
32497
32497
  );
32498
- const newItems = Array.from(value || []).map((item, idx) => {
32499
- var _a;
32500
- const arrayStateItem = arrayState.items[idx];
32501
- return {
32502
- _originalIndex: typeof (arrayStateItem == null ? void 0 : arrayStateItem._originalIndex) !== "undefined" ? arrayStateItem._originalIndex : ++highestIndex,
32503
- _arrayId: ((_a = arrayState.items[idx]) == null ? void 0 : _a._arrayId) || generateId("ArrayItem"),
32504
- data: item
32505
- };
32506
- });
32507
- setArrayState({ items: newItems });
32508
- }, [value]);
32498
+ }, [arrayState]);
32499
+ const regenerateArrayState = (0, import_react27.useCallback)(
32500
+ (value2) => {
32501
+ let highestIndex = getHighestIndex();
32502
+ const newItems = Array.from(value2 || []).map((item, idx) => {
32503
+ var _a;
32504
+ const arrayStateItem = arrayState.items[idx];
32505
+ return {
32506
+ _originalIndex: typeof (arrayStateItem == null ? void 0 : arrayStateItem._originalIndex) !== "undefined" ? arrayStateItem._originalIndex : ++highestIndex,
32507
+ _arrayId: ((_a = arrayState.items[idx]) == null ? void 0 : _a._arrayId) || `${id}-${highestIndex}`,
32508
+ data: item
32509
+ };
32510
+ });
32511
+ return __spreadProps(__spreadValues({}, arrayState), { items: newItems });
32512
+ },
32513
+ [arrayState]
32514
+ );
32515
+ (0, import_react27.useEffect)(() => {
32516
+ setUi(mapArrayStateToUi(arrayState));
32517
+ }, []);
32509
32518
  if (field.type !== "array" || !field.arrayFields) {
32510
32519
  return null;
32511
32520
  }
@@ -32520,15 +32529,27 @@ var ArrayField = ({
32520
32529
  import_dnd5.DragDropContext,
32521
32530
  {
32522
32531
  onDragEnd: (event) => {
32523
- var _a;
32532
+ var _a, _b;
32524
32533
  if (event.destination) {
32525
32534
  const newValue = reorder(
32526
- arrayState.items,
32535
+ value,
32527
32536
  event.source.index,
32528
32537
  (_a = event.destination) == null ? void 0 : _a.index
32529
32538
  );
32530
- setArrayState(__spreadProps(__spreadValues({}, arrayState), { items: newValue }), false);
32531
- onChange(newValue.map(({ data }) => data));
32539
+ const newArrayStateItems = reorder(
32540
+ arrayState.items,
32541
+ event.source.index,
32542
+ (_b = event.destination) == null ? void 0 : _b.index
32543
+ );
32544
+ onChange(newValue, {
32545
+ arrayState: __spreadProps(__spreadValues({}, state.ui.arrayState), {
32546
+ [id]: __spreadProps(__spreadValues({}, arrayState), { items: newArrayStateItems })
32547
+ })
32548
+ });
32549
+ setLocalState({
32550
+ value: newValue,
32551
+ arrayState: __spreadProps(__spreadValues({}, arrayState), { items: newArrayStateItems })
32552
+ });
32532
32553
  }
32533
32554
  },
32534
32555
  children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_dnd4.Droppable, { droppableId: "array", isDropDisabled: readOnly, children: (provided, snapshot) => {
@@ -32541,8 +32562,9 @@ var ArrayField = ({
32541
32562
  hasItems: Array.isArray(value) && value.length > 0
32542
32563
  }),
32543
32564
  children: [
32544
- arrayState.items.map(({ data }, i) => {
32545
- const { _arrayId, _originalIndex = i } = arrayState.items[i] || {};
32565
+ localState.arrayState.items.map((item, i) => {
32566
+ const { _arrayId = `${id}-${i}`, _originalIndex = i } = item;
32567
+ const data = Array.from(localState.value || [])[i];
32546
32568
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
32547
32569
  Draggable2,
32548
32570
  {
@@ -32550,7 +32572,7 @@ var ArrayField = ({
32550
32572
  index: i,
32551
32573
  className: (_, snapshot2) => getClassNameItem({
32552
32574
  isExpanded: arrayState.openId === _arrayId,
32553
- isDragging: snapshot2.isDragging,
32575
+ isDragging: snapshot2 == null ? void 0 : snapshot2.isDragging,
32554
32576
  readOnly
32555
32577
  }),
32556
32578
  isDragDisabled: readOnly,
@@ -32560,13 +32582,17 @@ var ArrayField = ({
32560
32582
  {
32561
32583
  onClick: () => {
32562
32584
  if (arrayState.openId === _arrayId) {
32563
- setArrayState({
32564
- openId: ""
32565
- });
32585
+ setUi(
32586
+ mapArrayStateToUi({
32587
+ openId: ""
32588
+ })
32589
+ );
32566
32590
  } else {
32567
- setArrayState({
32568
- openId: _arrayId
32569
- });
32591
+ setUi(
32592
+ mapArrayStateToUi({
32593
+ openId: _arrayId
32594
+ })
32595
+ );
32570
32596
  }
32571
32597
  },
32572
32598
  className: getClassNameItem("summary"),
@@ -32586,11 +32612,12 @@ var ArrayField = ({
32586
32612
  ];
32587
32613
  existingValue.splice(i, 1);
32588
32614
  existingItems.splice(i, 1);
32589
- setArrayState(
32590
- { items: existingItems },
32591
- true
32615
+ onChange(
32616
+ existingValue,
32617
+ mapArrayStateToUi({
32618
+ items: existingItems
32619
+ })
32592
32620
  );
32593
- onChange(existingValue);
32594
32621
  },
32595
32622
  title: "Delete",
32596
32623
  children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(trash_default, { size: 16 })
@@ -32611,15 +32638,18 @@ var ArrayField = ({
32611
32638
  {
32612
32639
  name: subFieldName,
32613
32640
  label: subField.label || fieldName,
32641
+ id: `${id}_${fieldName}`,
32614
32642
  readOnly: typeof readOnlyFields[subFieldName] !== "undefined" ? readOnlyFields[subFieldName] : readOnlyFields[wildcardFieldName],
32615
32643
  readOnlyFields,
32616
32644
  field: subField,
32617
32645
  value: data[fieldName],
32618
- onChange: (val) => onChange(
32619
- replace(value, i, __spreadProps(__spreadValues({}, data), {
32620
- [fieldName]: val
32621
- }))
32622
- )
32646
+ onChange: (val) => {
32647
+ onChange(
32648
+ replace(value, i, __spreadProps(__spreadValues({}, data), {
32649
+ [fieldName]: val
32650
+ }))
32651
+ );
32652
+ }
32623
32653
  },
32624
32654
  subFieldName
32625
32655
  );
@@ -32637,7 +32667,12 @@ var ArrayField = ({
32637
32667
  className: getClassName6("addButton"),
32638
32668
  onClick: () => {
32639
32669
  const existingValue = value || [];
32640
- onChange([...existingValue, field.defaultItemProps || {}]);
32670
+ const newValue = [
32671
+ ...existingValue,
32672
+ field.defaultItemProps || {}
32673
+ ];
32674
+ const newArrayState = regenerateArrayState(newValue);
32675
+ onChange(newValue, mapArrayStateToUi(newArrayState));
32641
32676
  },
32642
32677
  children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(plus_default, { size: "21" })
32643
32678
  }
@@ -32662,7 +32697,8 @@ var DefaultField = ({
32662
32697
  readOnly,
32663
32698
  value,
32664
32699
  name,
32665
- label
32700
+ label,
32701
+ id
32666
32702
  }) => {
32667
32703
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
32668
32704
  FieldLabelInternal,
@@ -32688,7 +32724,8 @@ var DefaultField = ({
32688
32724
  onChange(e.currentTarget.value);
32689
32725
  }
32690
32726
  },
32691
- readOnly
32727
+ readOnly,
32728
+ id
32692
32729
  }
32693
32730
  )
32694
32731
  }
@@ -32777,7 +32814,8 @@ var ExternalInput = ({
32777
32814
  field,
32778
32815
  onChange,
32779
32816
  value = null,
32780
- name
32817
+ name,
32818
+ id
32781
32819
  }) => {
32782
32820
  const { mapProp = (val) => val } = field || {};
32783
32821
  const [data, setData] = (0, import_react29.useState)([]);
@@ -32811,6 +32849,7 @@ var ExternalInput = ({
32811
32849
  dataSelected: !!value,
32812
32850
  modalVisible: isOpen
32813
32851
  }),
32852
+ id,
32814
32853
  children: [
32815
32854
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: getClassName10("actions"), children: [
32816
32855
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
@@ -32888,7 +32927,8 @@ var ExternalField = ({
32888
32927
  onChange,
32889
32928
  value,
32890
32929
  name,
32891
- label
32930
+ label,
32931
+ id
32892
32932
  }) => {
32893
32933
  var _a, _b, _c;
32894
32934
  const validField = field;
@@ -32924,7 +32964,8 @@ var ExternalField = ({
32924
32964
  }) : validField.fetchList
32925
32965
  }),
32926
32966
  onChange,
32927
- value
32967
+ value,
32968
+ id
32928
32969
  }
32929
32970
  )
32930
32971
  }
@@ -32940,7 +32981,8 @@ var RadioField = ({
32940
32981
  onChange,
32941
32982
  readOnly,
32942
32983
  value,
32943
- name
32984
+ name,
32985
+ id
32944
32986
  }) => {
32945
32987
  if (field.type !== "radio" || !field.options) {
32946
32988
  return null;
@@ -32952,7 +32994,7 @@ var RadioField = ({
32952
32994
  label: field.label || name,
32953
32995
  readOnly,
32954
32996
  el: "div",
32955
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: getClassName11("radioGroupItems"), children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
32997
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: getClassName11("radioGroupItems"), id, children: field.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
32956
32998
  "label",
32957
32999
  {
32958
33000
  className: getClassName11("radio"),
@@ -32994,7 +33036,8 @@ var SelectField = ({
32994
33036
  label,
32995
33037
  value,
32996
33038
  name,
32997
- readOnly
33039
+ readOnly,
33040
+ id
32998
33041
  }) => {
32999
33042
  if (field.type !== "select" || !field.options) {
33000
33043
  return null;
@@ -33008,6 +33051,7 @@ var SelectField = ({
33008
33051
  children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
33009
33052
  "select",
33010
33053
  {
33054
+ id,
33011
33055
  className: getClassName12("input"),
33012
33056
  disabled: readOnly,
33013
33057
  onChange: (e) => {
@@ -33041,7 +33085,8 @@ var TextareaField = ({
33041
33085
  readOnly,
33042
33086
  value,
33043
33087
  name,
33044
- label
33088
+ label,
33089
+ id
33045
33090
  }) => {
33046
33091
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
33047
33092
  FieldLabelInternal,
@@ -33052,6 +33097,7 @@ var TextareaField = ({
33052
33097
  children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
33053
33098
  "textarea",
33054
33099
  {
33100
+ id,
33055
33101
  className: getClassName13("input"),
33056
33102
  autoComplete: "off",
33057
33103
  name,
@@ -33094,7 +33140,6 @@ var FieldLabelInternal = ({
33094
33140
  el = "label",
33095
33141
  readOnly
33096
33142
  }) => {
33097
- const El = el;
33098
33143
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
33099
33144
  FieldLabel,
33100
33145
  {
@@ -33112,15 +33157,15 @@ var InputOrGroup = (_a) => {
33112
33157
  const { name, field, value, readOnly } = props;
33113
33158
  const [localValue, setLocalValue] = (0, import_react31.useState)(value);
33114
33159
  const onChangeDb = (0, import_use_debounce2.useDebouncedCallback)(
33115
- (val) => {
33116
- onChange(val);
33160
+ (val, ui) => {
33161
+ onChange(val, ui);
33117
33162
  },
33118
33163
  50,
33119
33164
  { leading: true }
33120
33165
  );
33121
- const onChangeLocal = (0, import_react31.useCallback)((val) => {
33166
+ const onChangeLocal = (0, import_react31.useCallback)((val, ui) => {
33122
33167
  setLocalValue(val);
33123
- onChangeDb(val);
33168
+ onChangeDb(val, ui);
33124
33169
  }, []);
33125
33170
  (0, import_react31.useEffect)(() => {
33126
33171
  setLocalValue(value);
@@ -33415,6 +33460,13 @@ var import_react35 = require("react");
33415
33460
  // lib/use-action-history.ts
33416
33461
  init_react_import();
33417
33462
  var import_react34 = require("react");
33463
+
33464
+ // lib/generate-id.ts
33465
+ init_react_import();
33466
+ var import_crypto = require("crypto");
33467
+ var generateId = (type) => `${type}-${(0, import_crypto.randomBytes)(20).toString("hex")}`;
33468
+
33469
+ // lib/use-action-history.ts
33418
33470
  var EMPTY_HISTORY_INDEX = -1;
33419
33471
  function useActionHistory() {
33420
33472
  const [histories, setHistories] = (0, import_react34.useState)([]);
@@ -33823,13 +33875,19 @@ var storeInterceptor = (reducer) => {
33823
33875
  return newAppState;
33824
33876
  };
33825
33877
  };
33878
+ var setAction = (state, action) => {
33879
+ if (typeof action.state === "object") {
33880
+ return __spreadValues(__spreadValues({}, state), action.state);
33881
+ }
33882
+ return __spreadValues(__spreadValues({}, state), action.state(state));
33883
+ };
33826
33884
  var createReducer = ({
33827
33885
  config
33828
33886
  }) => storeInterceptor((state, action) => {
33829
33887
  const data = reduceData(state.data, action, config);
33830
33888
  const ui = reduceUi(state.ui, action);
33831
33889
  if (action.type === "set") {
33832
- return __spreadValues(__spreadValues({}, state), action.state);
33890
+ return setAction(state, action);
33833
33891
  }
33834
33892
  return { data, ui };
33835
33893
  });
@@ -34200,10 +34258,10 @@ var resolveRootData = (data, config) => __async(void 0, null, function* () {
34200
34258
  });
34201
34259
 
34202
34260
  // lib/use-resolved-data.ts
34203
- var useResolvedData = (data, config, dispatch) => {
34204
- const [{ resolverKey, newData }, setResolverState] = (0, import_react38.useState)({
34261
+ var useResolvedData = (appState, config, dispatch) => {
34262
+ const [{ resolverKey, newAppState }, setResolverState] = (0, import_react38.useState)({
34205
34263
  resolverKey: 0,
34206
- newData: data
34264
+ newAppState: appState
34207
34265
  });
34208
34266
  const [componentState, setComponentState] = (0, import_react38.useState)({});
34209
34267
  const deferredSetStates = {};
@@ -34223,14 +34281,23 @@ var useResolvedData = (data, config, dispatch) => {
34223
34281
  []
34224
34282
  );
34225
34283
  const runResolvers = () => __async(void 0, null, function* () {
34284
+ const newData = newAppState.data;
34226
34285
  const flatContent = Object.keys(newData.zones || {}).reduce((acc, zone) => [...acc, ...newData.zones[zone]], newData.content).filter((item) => !!config.components[item.type].resolveData);
34227
34286
  const applyIfChange = (dynamicDataMap, dynamicRoot) => {
34228
- const processed = applyDynamicProps(data, dynamicDataMap, dynamicRoot);
34229
- const containsChanges = JSON.stringify(data) !== JSON.stringify(processed);
34287
+ const processed = applyDynamicProps(
34288
+ appState.data,
34289
+ dynamicDataMap,
34290
+ dynamicRoot
34291
+ );
34292
+ const processedAppState = __spreadProps(__spreadValues({}, appState), { data: processed });
34293
+ const containsChanges = JSON.stringify(appState) !== JSON.stringify(processedAppState);
34230
34294
  if (containsChanges) {
34231
34295
  dispatch({
34232
- type: "setData",
34233
- data: (prev) => applyDynamicProps(prev, dynamicDataMap, dynamicRoot),
34296
+ type: "set",
34297
+ state: (prev) => __spreadProps(__spreadValues({}, prev), {
34298
+ data: applyDynamicProps(prev.data, dynamicDataMap, dynamicRoot),
34299
+ ui: __spreadValues(__spreadValues({}, prev.ui), newAppState.ui)
34300
+ }),
34234
34301
  recordHistory: resolverKey > 0
34235
34302
  });
34236
34303
  }
@@ -34268,10 +34335,10 @@ var useResolvedData = (data, config, dispatch) => {
34268
34335
  (0, import_react38.useEffect)(() => {
34269
34336
  runResolvers();
34270
34337
  }, [resolverKey]);
34271
- const resolveData = (0, import_react38.useCallback)((newData2 = data) => {
34338
+ const resolveData = (0, import_react38.useCallback)((newAppState2 = appState) => {
34272
34339
  setResolverState((curr) => ({
34273
34340
  resolverKey: curr.resolverKey + 1,
34274
- newData: newData2
34341
+ newAppState: newAppState2
34275
34342
  }));
34276
34343
  }, []);
34277
34344
  return {
@@ -34280,13 +34347,86 @@ var useResolvedData = (data, config, dispatch) => {
34280
34347
  };
34281
34348
  };
34282
34349
 
34350
+ // components/MenuBar/index.tsx
34351
+ init_react_import();
34352
+
34353
+ // css-module:/home/runner/work/puck/puck/packages/core/components/MenuBar/styles.module.css#css-module
34354
+ init_react_import();
34355
+ var styles_module_default12 = { "MenuBar": "_MenuBar_12sp7_1", "MenuBar--menuOpen": "_MenuBar--menuOpen_12sp7_14", "MenuBar-inner": "_MenuBar-inner_12sp7_29", "MenuBar-history": "_MenuBar-history_12sp7_45" };
34356
+
34357
+ // components/MenuBar/index.tsx
34358
+ var import_jsx_runtime22 = require("react/jsx-runtime");
34359
+ var getClassName18 = get_class_name_factory_default("MenuBar", styles_module_default12);
34360
+ var MenuBar = ({
34361
+ appState,
34362
+ data = { content: [], root: { props: { title: "" } } },
34363
+ dispatch,
34364
+ menuOpen = false,
34365
+ onPublish,
34366
+ renderHeaderActions,
34367
+ setMenuOpen
34368
+ }) => {
34369
+ const { canForward, canRewind, rewind, forward } = usePuckHistory({
34370
+ appState,
34371
+ dispatch
34372
+ });
34373
+ return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34374
+ "div",
34375
+ {
34376
+ className: getClassName18({ menuOpen }),
34377
+ onClick: (event) => {
34378
+ var _a;
34379
+ const element = event.target;
34380
+ if (window.matchMedia("(min-width: 638px)").matches) {
34381
+ return;
34382
+ }
34383
+ if (element.tagName === "A" && ((_a = element.getAttribute("href")) == null ? void 0 : _a.startsWith("#"))) {
34384
+ setMenuOpen(false);
34385
+ }
34386
+ },
34387
+ children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: getClassName18("inner"), children: [
34388
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: getClassName18("history"), children: [
34389
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(IconButton, { title: "undo", disabled: !canRewind, onClick: rewind, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34390
+ chevron_left_default,
34391
+ {
34392
+ size: 21,
34393
+ stroke: canRewind ? "var(--puck-color-black)" : "var(--puck-color-grey-7)"
34394
+ }
34395
+ ) }),
34396
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(IconButton, { title: "redo", disabled: !canForward, onClick: forward, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34397
+ chevron_right_default,
34398
+ {
34399
+ size: 21,
34400
+ stroke: canForward ? "var(--puck-color-black)" : "var(--puck-color-grey-7)"
34401
+ }
34402
+ ) })
34403
+ ] }),
34404
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(import_jsx_runtime22.Fragment, { children: renderHeaderActions && renderHeaderActions({
34405
+ state: appState,
34406
+ dispatch
34407
+ }) }),
34408
+ /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34409
+ Button,
34410
+ {
34411
+ onClick: () => {
34412
+ onPublish(data);
34413
+ },
34414
+ icon: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(globe_default, { size: "14px" }),
34415
+ children: "Publish"
34416
+ }
34417
+ ) })
34418
+ ] })
34419
+ }
34420
+ );
34421
+ };
34422
+
34283
34423
  // css-module:/home/runner/work/puck/puck/packages/core/components/Puck/styles.module.css#css-module
34284
34424
  init_react_import();
34285
- var styles_module_default12 = { "Puck": "_Puck_vj9gy_19", "Puck--leftSideBarVisible": "_Puck--leftSideBarVisible_vj9gy_36", "Puck-header": "_Puck-header_vj9gy_72", "Puck-headerInner": "_Puck-headerInner_vj9gy_79", "Puck-headerToggle": "_Puck-headerToggle_vj9gy_89", "Puck-headerTitle": "_Puck-headerTitle_vj9gy_93", "Puck-headerPath": "_Puck-headerPath_vj9gy_97", "Puck-headerTools": "_Puck-headerTools_vj9gy_104", "Puck-leftSideBar": "_Puck-leftSideBar_vj9gy_110", "Puck-frame": "_Puck-frame_vj9gy_119", "Puck-root": "_Puck-root_vj9gy_127", "Puck-page": "_Puck-page_vj9gy_139", "Puck-rightSideBar": "_Puck-rightSideBar_vj9gy_143" };
34425
+ var styles_module_default13 = { "Puck": "_Puck_103k9_19", "Puck--leftSideBarVisible": "_Puck--leftSideBarVisible_103k9_35", "Puck--rightSideBarVisible": "_Puck--rightSideBarVisible_103k9_41", "Puck-header": "_Puck-header_103k9_95", "Puck-headerInner": "_Puck-headerInner_103k9_104", "Puck-headerToggle": "_Puck-headerToggle_103k9_114", "Puck-rightSideBarToggle": "_Puck-rightSideBarToggle_103k9_121", "Puck-leftSideBarToggle": "_Puck-leftSideBarToggle_103k9_126", "Puck-headerTitle": "_Puck-headerTitle_103k9_130", "Puck-headerPath": "_Puck-headerPath_103k9_134", "Puck-headerTools": "_Puck-headerTools_103k9_141", "Puck-menuButton": "_Puck-menuButton_103k9_147", "Puck--menuOpen": "_Puck--menuOpen_103k9_152", "Puck-leftSideBar": "_Puck-leftSideBar_103k9_126", "Puck-frame": "_Puck-frame_103k9_171", "Puck-root": "_Puck-root_103k9_179", "Puck-page": "_Puck-page_103k9_192", "Puck-rightSideBar": "_Puck-rightSideBar_103k9_121" };
34286
34426
 
34287
34427
  // components/Puck/index.tsx
34288
- var import_jsx_runtime22 = require("react/jsx-runtime");
34289
- var getClassName18 = get_class_name_factory_default("Puck", styles_module_default12);
34428
+ var import_jsx_runtime23 = require("react/jsx-runtime");
34429
+ var getClassName19 = get_class_name_factory_default("Puck", styles_module_default13);
34290
34430
  var defaultPageFields = {
34291
34431
  title: { type: "text" }
34292
34432
  };
@@ -34298,7 +34438,7 @@ var PluginRenderer = ({
34298
34438
  renderMethod
34299
34439
  }) => {
34300
34440
  return plugins.filter((item) => item[renderMethod]).map((item) => item[renderMethod]).reduce(
34301
- (accChildren, Item) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(Item, { dispatch, state, children: accChildren }),
34441
+ (accChildren, Item) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(Item, { dispatch, state, children: accChildren }),
34302
34442
  children
34303
34443
  );
34304
34444
  };
@@ -34341,15 +34481,12 @@ function Puck({
34341
34481
  );
34342
34482
  const { data, ui } = appState;
34343
34483
  const { resolveData, componentState } = useResolvedData(
34344
- data,
34484
+ appState,
34345
34485
  config,
34346
34486
  dispatch
34347
34487
  );
34348
- const { canForward, canRewind, rewind, forward } = usePuckHistory({
34349
- appState,
34350
- dispatch
34351
- });
34352
- const { itemSelector, leftSideBarVisible } = ui;
34488
+ const [menuOpen, setMenuOpen] = (0, import_react39.useState)(false);
34489
+ const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
34353
34490
  const setItemSelector = (0, import_react39.useCallback)(
34354
34491
  (newItemSelector) => {
34355
34492
  dispatch({
@@ -34363,7 +34500,7 @@ function Puck({
34363
34500
  const Page = (0, import_react39.useCallback)(
34364
34501
  (pageProps) => {
34365
34502
  var _a2, _b2;
34366
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34503
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34367
34504
  PluginRenderer,
34368
34505
  {
34369
34506
  plugins,
@@ -34377,7 +34514,7 @@ function Puck({
34377
34514
  [config.root]
34378
34515
  );
34379
34516
  const PageFieldWrapper = (0, import_react39.useCallback)(
34380
- (props) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34517
+ (props) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34381
34518
  PluginRenderer,
34382
34519
  {
34383
34520
  plugins,
@@ -34390,7 +34527,7 @@ function Puck({
34390
34527
  []
34391
34528
  );
34392
34529
  const ComponentFieldWrapper = (0, import_react39.useCallback)(
34393
- (props) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34530
+ (props) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34394
34531
  PluginRenderer,
34395
34532
  {
34396
34533
  plugins,
@@ -34403,7 +34540,7 @@ function Puck({
34403
34540
  []
34404
34541
  );
34405
34542
  const ComponentListWrapper = (0, import_react39.useCallback)((props) => {
34406
- const children = /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34543
+ const children = /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34407
34544
  PluginRenderer,
34408
34545
  {
34409
34546
  plugins,
@@ -34437,12 +34574,49 @@ function Puck({
34437
34574
  );
34438
34575
  }
34439
34576
  }, []);
34440
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { children: [
34441
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34577
+ const toggleSidebars = (0, import_react39.useCallback)(
34578
+ (sidebar) => {
34579
+ const widerViewport = window.matchMedia("(min-width: 638px)").matches;
34580
+ const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
34581
+ const oppositeSideBar = sidebar === "left" ? "rightSideBarVisible" : "leftSideBarVisible";
34582
+ dispatch({
34583
+ type: "setUi",
34584
+ ui: __spreadValues({
34585
+ [`${sidebar}SideBarVisible`]: !sideBarVisible
34586
+ }, !widerViewport ? { [oppositeSideBar]: false } : {})
34587
+ });
34588
+ },
34589
+ [dispatch, leftSideBarVisible, rightSideBarVisible]
34590
+ );
34591
+ (0, import_react39.useEffect)(() => {
34592
+ if (!window.matchMedia("(min-width: 638px)").matches) {
34593
+ dispatch({
34594
+ type: "setUi",
34595
+ ui: {
34596
+ leftSideBarVisible: false,
34597
+ rightSideBarVisible: false
34598
+ }
34599
+ });
34600
+ }
34601
+ const handleResize = () => {
34602
+ if (!window.matchMedia("(min-width: 638px)").matches) {
34603
+ dispatch({
34604
+ type: "setUi",
34605
+ ui: (ui2) => __spreadValues(__spreadValues({}, ui2), ui2.rightSideBarVisible ? { leftSideBarVisible: false } : {})
34606
+ });
34607
+ }
34608
+ };
34609
+ window.addEventListener("resize", handleResize);
34610
+ return () => {
34611
+ window.removeEventListener("resize", handleResize);
34612
+ };
34613
+ }, []);
34614
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { children: [
34615
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34442
34616
  AppProvider,
34443
34617
  {
34444
34618
  value: { state: appState, dispatch, config, componentState },
34445
- children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34619
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34446
34620
  import_dnd7.DragDropContext,
34447
34621
  {
34448
34622
  onDragUpdate: (update) => {
@@ -34495,7 +34669,7 @@ function Puck({
34495
34669
  });
34496
34670
  }
34497
34671
  },
34498
- children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34672
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34499
34673
  DropZoneProvider,
34500
34674
  {
34501
34675
  value: {
@@ -34509,239 +34683,260 @@ function Puck({
34509
34683
  mode: "edit",
34510
34684
  areaId: "root"
34511
34685
  },
34512
- children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(dropZoneContext.Consumer, { children: (ctx) => {
34686
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(dropZoneContext.Consumer, { children: (ctx) => {
34513
34687
  var _a2, _b2;
34514
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: getClassName18({ leftSideBarVisible }), children: [
34515
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("header", { className: getClassName18("header"), children: renderHeader ? renderHeader({
34516
- children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34517
- Button,
34518
- {
34519
- onClick: () => {
34520
- onPublish(data);
34521
- },
34522
- icon: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(globe_default, { size: "14px" }),
34523
- children: "Publish"
34524
- }
34525
- ),
34526
- dispatch,
34527
- state: appState
34528
- }) : /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: getClassName18("headerInner"), children: [
34529
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: getClassName18("headerToggle"), children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34530
- IconButton,
34531
- {
34532
- onClick: () => dispatch({
34533
- type: "setUi",
34534
- ui: {
34535
- leftSideBarVisible: !leftSideBarVisible
34536
- }
34537
- }),
34538
- title: "Toggle left sidebar",
34539
- children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(sidebar_default, {})
34540
- }
34541
- ) }),
34542
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: getClassName18("headerTitle"), children: /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(Heading, { rank: 2, size: "xs", children: [
34543
- headerTitle || rootProps.title || "Page",
34544
- headerPath && /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(import_jsx_runtime22.Fragment, { children: [
34545
- " ",
34546
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("code", { className: getClassName18("headerPath"), children: headerPath })
34547
- ] })
34548
- ] }) }),
34549
- /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: getClassName18("headerTools"), children: [
34550
- /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { style: { display: "flex" }, children: [
34551
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34552
- IconButton,
34688
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
34689
+ "div",
34690
+ {
34691
+ className: getClassName19({
34692
+ leftSideBarVisible,
34693
+ menuOpen,
34694
+ rightSideBarVisible
34695
+ }),
34696
+ children: [
34697
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("header", { className: getClassName19("header"), children: renderHeader ? renderHeader({
34698
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34699
+ Button,
34553
34700
  {
34554
- title: "undo",
34555
- disabled: !canRewind,
34556
- onClick: rewind,
34557
- children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34558
- chevron_left_default,
34559
- {
34560
- size: 21,
34561
- stroke: canRewind ? "var(--puck-color-black)" : "var(--puck-color-grey-7)"
34562
- }
34563
- )
34701
+ onClick: () => {
34702
+ onPublish(data);
34703
+ },
34704
+ icon: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(globe_default, { size: "14px" }),
34705
+ children: "Publish"
34564
34706
  }
34565
34707
  ),
34566
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34567
- IconButton,
34568
- {
34569
- title: "redo",
34570
- disabled: !canForward,
34571
- onClick: forward,
34572
- children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34573
- chevron_right_default,
34574
- {
34575
- size: 21,
34576
- stroke: canForward ? "var(--puck-color-black)" : "var(--puck-color-grey-7)"
34577
- }
34578
- )
34579
- }
34580
- )
34581
- ] }),
34582
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { children: renderHeaderActions && renderHeaderActions({
34583
- state: appState,
34584
- dispatch
34585
- }) }),
34586
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34587
- Button,
34588
- {
34589
- onClick: () => {
34590
- onPublish(data);
34591
- },
34592
- icon: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(globe_default, { size: "14px" }),
34593
- children: "Publish"
34594
- }
34595
- ) })
34596
- ] })
34597
- ] }) }),
34598
- /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)("div", { className: getClassName18("leftSideBar"), children: [
34599
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(SidebarSection, { title: "Components", children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ComponentListWrapper, { children: componentList ? componentList : /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(ComponentList, { id: "all" }) }) }),
34600
- /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(SidebarSection, { title: "Outline", children: [
34601
- (ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34602
- LayerTree,
34603
- {
34604
- data,
34605
- label: areaContainsZones(data, "root") ? rootDroppableId : "",
34606
- zoneContent: data.content,
34607
- setItemSelector,
34608
- itemSelector
34609
- }
34610
- ),
34611
- Object.entries(findZonesForArea(data, "root")).map(
34612
- ([zoneKey, zone]) => {
34613
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34708
+ dispatch,
34709
+ state: appState
34710
+ }) : /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: getClassName19("headerInner"), children: [
34711
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: getClassName19("headerToggle"), children: [
34712
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: getClassName19("leftSideBarToggle"), children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34713
+ IconButton,
34714
+ {
34715
+ onClick: () => {
34716
+ toggleSidebars("left");
34717
+ },
34718
+ title: "Toggle left sidebar",
34719
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(sidebar_default, { focusable: "false" })
34720
+ }
34721
+ ) }),
34722
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: getClassName19("rightSideBarToggle"), children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34723
+ IconButton,
34724
+ {
34725
+ onClick: () => {
34726
+ toggleSidebars("right");
34727
+ },
34728
+ title: "Toggle right sidebar",
34729
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(sidebar_default, { focusable: "false" })
34730
+ }
34731
+ ) })
34732
+ ] }),
34733
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: getClassName19("headerTitle"), children: /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(Heading, { rank: 2, size: "xs", children: [
34734
+ headerTitle || rootProps.title || "Page",
34735
+ headerPath && /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(import_jsx_runtime23.Fragment, { children: [
34736
+ " ",
34737
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("code", { className: getClassName19("headerPath"), children: headerPath })
34738
+ ] })
34739
+ ] }) }),
34740
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: getClassName19("headerTools"), children: [
34741
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: getClassName19("menuButton"), children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34742
+ IconButton,
34743
+ {
34744
+ onClick: () => {
34745
+ return setMenuOpen(!menuOpen);
34746
+ },
34747
+ title: "Toggle menu bar",
34748
+ children: menuOpen ? /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(chevron_up_default, { focusable: "false" }) : /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(chevron_down_default, { focusable: "false" })
34749
+ }
34750
+ ) }),
34751
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34752
+ MenuBar,
34753
+ {
34754
+ appState,
34755
+ data,
34756
+ dispatch,
34757
+ onPublish,
34758
+ menuOpen,
34759
+ renderHeaderActions,
34760
+ setMenuOpen
34761
+ }
34762
+ )
34763
+ ] })
34764
+ ] }) }),
34765
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)("div", { className: getClassName19("leftSideBar"), children: [
34766
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(SidebarSection, { title: "Components", children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ComponentListWrapper, { children: componentList ? componentList : /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(ComponentList, { id: "all" }) }) }),
34767
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(SidebarSection, { title: "Outline", children: [
34768
+ (ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34614
34769
  LayerTree,
34615
34770
  {
34616
34771
  data,
34617
- label: zoneKey,
34618
- zone: zoneKey,
34619
- zoneContent: zone,
34772
+ label: areaContainsZones(data, "root") ? rootDroppableId : "",
34773
+ zoneContent: data.content,
34620
34774
  setItemSelector,
34621
34775
  itemSelector
34622
- },
34623
- zoneKey
34624
- );
34625
- }
34626
- )
34627
- ] })
34628
- ] }),
34629
- /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
34630
- "div",
34631
- {
34632
- className: getClassName18("frame"),
34633
- onClick: () => setItemSelector(null),
34634
- id: "puck-frame",
34635
- children: [
34636
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: getClassName18("root"), children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: getClassName18("page"), children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34637
- Page,
34638
- __spreadProps(__spreadValues({
34639
- dispatch,
34640
- state: appState
34641
- }, rootProps), {
34642
- children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZone, { zone: rootDroppableId })
34643
- })
34644
- ) }) }),
34645
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34646
- "div",
34647
- {
34648
- style: {
34649
- background: "var(--puck-color-grey-10)",
34650
- height: "100%",
34651
- flexGrow: 1
34652
34776
  }
34653
- }
34654
- )
34655
- ]
34656
- }
34657
- ),
34658
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { className: getClassName18("rightSideBar"), children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(FieldWrapper, { dispatch, state: appState, children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34659
- SidebarSection,
34660
- {
34661
- noPadding: true,
34662
- showBreadcrumbs: true,
34663
- title: selectedItem ? selectedItem.type : "Page",
34664
- isLoading: selectedItem ? (_a2 = componentState[selectedItem == null ? void 0 : selectedItem.props.id]) == null ? void 0 : _a2.loading : (_b2 = componentState["puck-root"]) == null ? void 0 : _b2.loading,
34665
- children: Object.keys(fields).map((fieldName) => {
34666
- const field = fields[fieldName];
34667
- const onChange2 = (value) => {
34668
- var _a3, _b3;
34669
- let currentProps;
34670
- if (selectedItem) {
34671
- currentProps = selectedItem.props;
34672
- } else {
34673
- currentProps = rootProps;
34674
- }
34675
- const newProps = __spreadProps(__spreadValues({}, currentProps), {
34676
- [fieldName]: value
34677
- });
34678
- if (itemSelector) {
34679
- const action = {
34680
- type: "replace",
34681
- destinationIndex: itemSelector.index,
34682
- destinationZone: itemSelector.zone || rootDroppableId,
34683
- data: __spreadProps(__spreadValues({}, selectedItem), { props: newProps })
34684
- };
34685
- if ((_a3 = config.components[selectedItem.type]) == null ? void 0 : _a3.resolveData) {
34686
- resolveData(replaceAction(data, action));
34687
- } else {
34688
- dispatch(action);
34777
+ ),
34778
+ Object.entries(findZonesForArea(data, "root")).map(
34779
+ ([zoneKey, zone]) => {
34780
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34781
+ LayerTree,
34782
+ {
34783
+ data,
34784
+ label: zoneKey,
34785
+ zone: zoneKey,
34786
+ zoneContent: zone,
34787
+ setItemSelector,
34788
+ itemSelector
34789
+ },
34790
+ zoneKey
34791
+ );
34689
34792
  }
34690
- } else {
34691
- if (data.root.props) {
34692
- if ((_b3 = config.root) == null ? void 0 : _b3.resolveData) {
34693
- resolveData(__spreadProps(__spreadValues({}, data), {
34694
- root: { props: newProps }
34695
- }));
34793
+ )
34794
+ ] })
34795
+ ] }),
34796
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsxs)(
34797
+ "div",
34798
+ {
34799
+ className: getClassName19("frame"),
34800
+ onClick: () => setItemSelector(null),
34801
+ id: "puck-frame",
34802
+ children: [
34803
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: getClassName19("root"), children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: getClassName19("page"), children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34804
+ Page,
34805
+ __spreadProps(__spreadValues({
34806
+ dispatch,
34807
+ state: appState
34808
+ }, rootProps), {
34809
+ children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DropZone, { zone: rootDroppableId })
34810
+ })
34811
+ ) }) }),
34812
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34813
+ "div",
34814
+ {
34815
+ style: {
34816
+ background: "var(--puck-color-grey-10)",
34817
+ height: "100%",
34818
+ flexGrow: 1
34819
+ }
34820
+ }
34821
+ )
34822
+ ]
34823
+ }
34824
+ ),
34825
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { className: getClassName19("rightSideBar"), children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(FieldWrapper, { dispatch, state: appState, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34826
+ SidebarSection,
34827
+ {
34828
+ noPadding: true,
34829
+ showBreadcrumbs: true,
34830
+ title: selectedItem ? selectedItem.type : "Page",
34831
+ isLoading: selectedItem ? (_a2 = componentState[selectedItem == null ? void 0 : selectedItem.props.id]) == null ? void 0 : _a2.loading : (_b2 = componentState["puck-root"]) == null ? void 0 : _b2.loading,
34832
+ children: Object.keys(fields).map((fieldName) => {
34833
+ const field = fields[fieldName];
34834
+ const onChange2 = (value, updatedUi) => {
34835
+ var _a3, _b3;
34836
+ let currentProps;
34837
+ if (selectedItem) {
34838
+ currentProps = selectedItem.props;
34696
34839
  } else {
34697
- dispatch({
34698
- type: "setData",
34699
- data: { root: { props: newProps } }
34700
- });
34840
+ currentProps = rootProps;
34701
34841
  }
34702
- } else {
34703
- dispatch({
34704
- type: "setData",
34705
- data: { root: newProps }
34842
+ const newProps = __spreadProps(__spreadValues({}, currentProps), {
34843
+ [fieldName]: value
34706
34844
  });
34845
+ if (itemSelector) {
34846
+ const replaceActionData = {
34847
+ type: "replace",
34848
+ destinationIndex: itemSelector.index,
34849
+ destinationZone: itemSelector.zone || rootDroppableId,
34850
+ data: __spreadProps(__spreadValues({}, selectedItem), { props: newProps })
34851
+ };
34852
+ const replacedData = replaceAction(
34853
+ data,
34854
+ replaceActionData
34855
+ );
34856
+ const setActionData = {
34857
+ type: "set",
34858
+ state: {
34859
+ data: __spreadValues(__spreadValues({}, data), replacedData),
34860
+ ui: __spreadValues(__spreadValues({}, ui), updatedUi)
34861
+ }
34862
+ };
34863
+ if ((_a3 = config.components[selectedItem.type]) == null ? void 0 : _a3.resolveData) {
34864
+ resolveData(
34865
+ setAction(appState, setActionData)
34866
+ );
34867
+ } else {
34868
+ dispatch(__spreadProps(__spreadValues({}, setActionData), {
34869
+ recordHistory: true
34870
+ }));
34871
+ }
34872
+ } else {
34873
+ if (data.root.props) {
34874
+ if ((_b3 = config.root) == null ? void 0 : _b3.resolveData) {
34875
+ resolveData({
34876
+ ui: __spreadValues(__spreadValues({}, ui), updatedUi),
34877
+ data: __spreadProps(__spreadValues({}, data), {
34878
+ root: { props: newProps }
34879
+ })
34880
+ });
34881
+ } else {
34882
+ dispatch({
34883
+ type: "set",
34884
+ state: {
34885
+ ui: __spreadValues(__spreadValues({}, ui), updatedUi),
34886
+ data: __spreadProps(__spreadValues({}, data), {
34887
+ root: { props: newProps }
34888
+ })
34889
+ },
34890
+ recordHistory: true
34891
+ });
34892
+ }
34893
+ } else {
34894
+ dispatch({
34895
+ type: "setData",
34896
+ data: { root: newProps }
34897
+ });
34898
+ }
34899
+ }
34900
+ };
34901
+ if (selectedItem && itemSelector) {
34902
+ const { readOnly = {} } = selectedItem;
34903
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34904
+ InputOrGroup,
34905
+ {
34906
+ field,
34907
+ name: fieldName,
34908
+ id: `${selectedItem.props.id}_${fieldName}`,
34909
+ label: field.label,
34910
+ readOnly: readOnly[fieldName],
34911
+ readOnlyFields: readOnly,
34912
+ value: selectedItem.props[fieldName],
34913
+ onChange: onChange2
34914
+ },
34915
+ `${selectedItem.props.id}_${fieldName}`
34916
+ );
34917
+ } else {
34918
+ const { readOnly = {} } = data.root;
34919
+ return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34920
+ InputOrGroup,
34921
+ {
34922
+ field,
34923
+ name: fieldName,
34924
+ id: `root_${fieldName}`,
34925
+ label: field.label,
34926
+ readOnly: readOnly[fieldName],
34927
+ readOnlyFields: readOnly,
34928
+ value: rootProps[fieldName],
34929
+ onChange: onChange2
34930
+ },
34931
+ `page_${fieldName}`
34932
+ );
34707
34933
  }
34708
- }
34709
- };
34710
- if (selectedItem && itemSelector) {
34711
- const { readOnly = {} } = selectedItem;
34712
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34713
- InputOrGroup,
34714
- {
34715
- field,
34716
- name: fieldName,
34717
- label: field.label,
34718
- readOnly: readOnly[fieldName],
34719
- readOnlyFields: readOnly,
34720
- value: selectedItem.props[fieldName],
34721
- onChange: onChange2
34722
- },
34723
- `${selectedItem.props.id}_${fieldName}`
34724
- );
34725
- } else {
34726
- const { readOnly = {} } = data.root;
34727
- return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
34728
- InputOrGroup,
34729
- {
34730
- field,
34731
- name: fieldName,
34732
- label: field.label,
34733
- readOnly: readOnly[fieldName],
34734
- readOnlyFields: readOnly,
34735
- value: rootProps[fieldName],
34736
- onChange: onChange2
34737
- },
34738
- `page_${fieldName}`
34739
- );
34934
+ })
34740
34935
  }
34741
- })
34742
- }
34743
- ) }) })
34744
- ] });
34936
+ ) }) })
34937
+ ]
34938
+ }
34939
+ );
34745
34940
  } })
34746
34941
  }
34747
34942
  )
@@ -34749,19 +34944,19 @@ function Puck({
34749
34944
  )
34750
34945
  }
34751
34946
  ),
34752
- /* @__PURE__ */ (0, import_jsx_runtime22.jsx)("div", { id: "puck-portal-root" })
34947
+ /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { id: "puck-portal-root" })
34753
34948
  ] });
34754
34949
  }
34755
34950
 
34756
34951
  // components/Render/index.tsx
34757
34952
  init_react_import();
34758
- var import_jsx_runtime23 = require("react/jsx-runtime");
34953
+ var import_jsx_runtime24 = require("react/jsx-runtime");
34759
34954
  function Render({ config, data }) {
34760
34955
  var _a;
34761
34956
  const rootProps = data.root.props || data.root;
34762
34957
  const title = rootProps.title || "";
34763
34958
  if ((_a = config.root) == null ? void 0 : _a.render) {
34764
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DropZoneProvider, { value: { data, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34959
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(DropZoneProvider, { value: { data, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
34765
34960
  config.root.render,
34766
34961
  __spreadProps(__spreadValues({}, rootProps), {
34767
34962
  puck: {
@@ -34770,11 +34965,11 @@ function Render({ config, data }) {
34770
34965
  title,
34771
34966
  editMode: false,
34772
34967
  id: "puck-root",
34773
- children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DropZone, { zone: rootDroppableId })
34968
+ children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(DropZone, { zone: rootDroppableId })
34774
34969
  })
34775
34970
  ) });
34776
34971
  }
34777
- return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DropZoneProvider, { value: { data, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(DropZone, { zone: rootDroppableId }) });
34972
+ return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(DropZoneProvider, { value: { data, config, mode: "render" }, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(DropZone, { zone: rootDroppableId }) });
34778
34973
  }
34779
34974
 
34780
34975
  // lib/resolve-all-data.ts