@measured/puck 0.12.0-canary.349f44d → 0.12.0-canary.3f8ebc0

Sign up to get free protection for your applications and to get access to all the features.
@@ -171,7 +171,6 @@ type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps
171
171
  type ItemWithId = {
172
172
  _arrayId: string;
173
173
  _originalIndex: number;
174
- data: any;
175
174
  };
176
175
  type ArrayState = {
177
176
  items: ItemWithId[];
package/dist/index.d.ts CHANGED
@@ -1,10 +1,45 @@
1
- import { U as UiState, D as Data, A as AppState, C as Config, I as ItemSelector, M as MappedItem, R as RootDataWithProps, a as DefaultRootProps, b as RootData } from './Config-e71a51c7.js';
2
- export { d as Adaptor, c as ArrayField, p as ArrayState, l as BaseData, B as BaseField, k as ComponentConfig, m as ComponentData, i as Content, f as CustomField, g as DefaultComponentProps, q as DropZone, e as ExternalField, E as ExternalFieldWithAdaptor, F as Field, h as Fields, o as ItemWithId, P as PuckComponent, j as PuckContext, n as RootDataWithoutProps, S as SelectField, T as TextField } from './Config-e71a51c7.js';
1
+ import { D as Data, C as Config, I as ItemSelector, U as UiState, A as AppState, M as MappedItem, R as RootDataWithProps, a as DefaultRootProps, b as RootData } from './Config-35e6eaae.js';
2
+ export { d as Adaptor, c as ArrayField, p as ArrayState, l as BaseData, B as BaseField, k as ComponentConfig, m as ComponentData, i as Content, f as CustomField, g as DefaultComponentProps, q as DropZone, e as ExternalField, E as ExternalFieldWithAdaptor, F as Field, h as Fields, o as ItemWithId, P as PuckComponent, j as PuckContext, n as RootDataWithoutProps, S as SelectField, T as TextField } from './Config-35e6eaae.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
5
  import { ReactNode, CSSProperties, SyntheticEvent, ReactElement } from 'react';
6
6
  import { DragStart, DragUpdate } from '@hello-pangea/dnd';
7
7
 
8
+ type PathData = Record<string, {
9
+ path: string[];
10
+ label: string;
11
+ }>;
12
+ type DropZoneContext = {
13
+ data: Data;
14
+ config: Config;
15
+ componentState?: Record<string, any>;
16
+ itemSelector?: ItemSelector | null;
17
+ setItemSelector?: (newIndex: ItemSelector | null) => void;
18
+ dispatch?: (action: PuckAction) => void;
19
+ areaId?: string;
20
+ draggedItem?: DragStart & Partial<DragUpdate>;
21
+ placeholderStyle?: CSSProperties;
22
+ hoveringArea?: string | null;
23
+ setHoveringArea?: (area: string | null) => void;
24
+ hoveringZone?: string | null;
25
+ setHoveringZone?: (zone: string | null) => void;
26
+ hoveringComponent?: string | null;
27
+ setHoveringComponent?: (id: string | null) => void;
28
+ registerZoneArea?: (areaId: string) => void;
29
+ areasWithZones?: Record<string, boolean>;
30
+ registerZone?: (zoneCompound: string) => void;
31
+ unregisterZone?: (zoneCompound: string) => void;
32
+ activeZones?: Record<string, boolean>;
33
+ pathData?: PathData;
34
+ registerPath?: (selector: ItemSelector) => void;
35
+ mode?: "edit" | "render";
36
+ } | null;
37
+ declare const dropZoneContext: react.Context<DropZoneContext>;
38
+ declare const DropZoneProvider: ({ children, value, }: {
39
+ children: ReactNode;
40
+ value: DropZoneContext;
41
+ }) => react_jsx_runtime.JSX.Element;
42
+
8
43
  type InsertAction = {
9
44
  type: "insert";
10
45
  componentType: string;
@@ -50,7 +85,7 @@ type SetDataAction = {
50
85
  };
51
86
  type SetAction = {
52
87
  type: "set";
53
- state: Partial<AppState>;
88
+ state: Partial<AppState> | ((previous: AppState) => Partial<AppState>);
54
89
  };
55
90
  type RegisterZoneAction = {
56
91
  type: "registerZone";
@@ -64,41 +99,6 @@ type PuckAction = {
64
99
  recordHistory?: boolean;
65
100
  } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
66
101
 
67
- type PathData = Record<string, {
68
- path: string[];
69
- label: string;
70
- }>;
71
- type DropZoneContext = {
72
- data: Data;
73
- config: Config;
74
- componentState?: Record<string, any>;
75
- itemSelector?: ItemSelector | null;
76
- setItemSelector?: (newIndex: ItemSelector | null) => void;
77
- dispatch?: (action: PuckAction) => void;
78
- areaId?: string;
79
- draggedItem?: DragStart & Partial<DragUpdate>;
80
- placeholderStyle?: CSSProperties;
81
- hoveringArea?: string | null;
82
- setHoveringArea?: (area: string | null) => void;
83
- hoveringZone?: string | null;
84
- setHoveringZone?: (zone: string | null) => void;
85
- hoveringComponent?: string | null;
86
- setHoveringComponent?: (id: string | null) => void;
87
- registerZoneArea?: (areaId: string) => void;
88
- areasWithZones?: Record<string, boolean>;
89
- registerZone?: (zoneCompound: string) => void;
90
- unregisterZone?: (zoneCompound: string) => void;
91
- activeZones?: Record<string, boolean>;
92
- pathData?: PathData;
93
- registerPath?: (selector: ItemSelector) => void;
94
- mode?: "edit" | "render";
95
- } | null;
96
- declare const dropZoneContext: react.Context<DropZoneContext>;
97
- declare const DropZoneProvider: ({ children, value, }: {
98
- children: ReactNode;
99
- value: DropZoneContext;
100
- }) => react_jsx_runtime.JSX.Element;
101
-
102
102
  declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, }: {
103
103
  children: ReactNode;
104
104
  href?: string | undefined;
@@ -188,4 +188,4 @@ declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }:
188
188
  className?: string | undefined;
189
189
  }) => react_jsx_runtime.JSX.Element;
190
190
 
191
- export { AppState, Button, Config, Data, DefaultRootProps, DropZoneProvider, FieldLabel, IconButton, MappedItem, Puck, Render, RootData, RootDataWithProps, UiState, dropZoneContext, resolveAllData };
191
+ export { AppState, Button, Config, Data, DefaultRootProps, DropZoneProvider, FieldLabel, IconButton, MappedItem, Puck, PuckAction, Render, RootData, RootDataWithProps, UiState, dropZoneContext, resolveAllData };
package/dist/index.js CHANGED
@@ -32436,11 +32436,6 @@ var Draggable2 = ({
32436
32436
  );
32437
32437
  };
32438
32438
 
32439
- // lib/generate-id.ts
32440
- init_react_import();
32441
- var import_crypto = require("crypto");
32442
- var generateId = (type) => `${type}-${(0, import_crypto.randomBytes)(20).toString("hex")}`;
32443
-
32444
32439
  // components/InputOrGroup/fields/ArrayField/index.tsx
32445
32440
  var import_react27 = require("react");
32446
32441
 
@@ -32467,47 +32462,59 @@ var ArrayField = ({
32467
32462
  name,
32468
32463
  label,
32469
32464
  readOnly,
32470
- readOnlyFields = {}
32465
+ readOnlyFields = {},
32466
+ id
32471
32467
  }) => {
32472
- const [arrayFieldId] = (0, import_react27.useState)(generateId("ArrayField"));
32473
32468
  const { state, setUi } = useAppContext();
32474
- const arrayStateRef = (0, import_react27.useRef)(
32475
- state.ui.arrayState[arrayFieldId] || {
32476
- items: [],
32477
- openId: ""
32478
- }
32479
- );
32480
- const arrayState = arrayStateRef.current;
32481
- const setArrayState = (0, import_react27.useCallback)(
32482
- (partialArrayState, recordHistory = false) => {
32483
- setUi(
32484
- {
32485
- arrayState: __spreadProps(__spreadValues({}, state.ui.arrayState), {
32486
- [arrayFieldId]: __spreadValues(__spreadValues({}, arrayState), partialArrayState)
32487
- })
32488
- },
32489
- recordHistory
32490
- );
32491
- 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
+ };
32492
32490
  },
32493
32491
  [arrayState]
32494
32492
  );
32495
- (0, import_react27.useEffect)(() => {
32496
- let highestIndex = arrayState.items.reduce(
32493
+ const getHighestIndex = (0, import_react27.useCallback)(() => {
32494
+ return arrayState.items.reduce(
32497
32495
  (acc, item) => item._originalIndex > acc ? item._originalIndex : acc,
32498
32496
  -1
32499
32497
  );
32500
- const newItems = Array.from(value || []).map((item, idx) => {
32501
- var _a;
32502
- const arrayStateItem = arrayState.items[idx];
32503
- return {
32504
- _originalIndex: typeof (arrayStateItem == null ? void 0 : arrayStateItem._originalIndex) !== "undefined" ? arrayStateItem._originalIndex : ++highestIndex,
32505
- _arrayId: ((_a = arrayState.items[idx]) == null ? void 0 : _a._arrayId) || generateId("ArrayItem"),
32506
- data: item
32507
- };
32508
- });
32509
- setArrayState({ items: newItems });
32510
- }, [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
+ }, []);
32511
32518
  if (field.type !== "array" || !field.arrayFields) {
32512
32519
  return null;
32513
32520
  }
@@ -32522,15 +32529,27 @@ var ArrayField = ({
32522
32529
  import_dnd5.DragDropContext,
32523
32530
  {
32524
32531
  onDragEnd: (event) => {
32525
- var _a;
32532
+ var _a, _b;
32526
32533
  if (event.destination) {
32527
32534
  const newValue = reorder(
32528
- arrayState.items,
32535
+ value,
32529
32536
  event.source.index,
32530
32537
  (_a = event.destination) == null ? void 0 : _a.index
32531
32538
  );
32532
- setArrayState(__spreadProps(__spreadValues({}, arrayState), { items: newValue }), false);
32533
- 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
+ });
32534
32553
  }
32535
32554
  },
32536
32555
  children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_dnd4.Droppable, { droppableId: "array", isDropDisabled: readOnly, children: (provided, snapshot) => {
@@ -32543,8 +32562,9 @@ var ArrayField = ({
32543
32562
  hasItems: Array.isArray(value) && value.length > 0
32544
32563
  }),
32545
32564
  children: [
32546
- arrayState.items.map(({ data }, i) => {
32547
- 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];
32548
32568
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
32549
32569
  Draggable2,
32550
32570
  {
@@ -32552,7 +32572,7 @@ var ArrayField = ({
32552
32572
  index: i,
32553
32573
  className: (_, snapshot2) => getClassNameItem({
32554
32574
  isExpanded: arrayState.openId === _arrayId,
32555
- isDragging: snapshot2.isDragging,
32575
+ isDragging: snapshot2 == null ? void 0 : snapshot2.isDragging,
32556
32576
  readOnly
32557
32577
  }),
32558
32578
  isDragDisabled: readOnly,
@@ -32562,13 +32582,17 @@ var ArrayField = ({
32562
32582
  {
32563
32583
  onClick: () => {
32564
32584
  if (arrayState.openId === _arrayId) {
32565
- setArrayState({
32566
- openId: ""
32567
- });
32585
+ setUi(
32586
+ mapArrayStateToUi({
32587
+ openId: ""
32588
+ })
32589
+ );
32568
32590
  } else {
32569
- setArrayState({
32570
- openId: _arrayId
32571
- });
32591
+ setUi(
32592
+ mapArrayStateToUi({
32593
+ openId: _arrayId
32594
+ })
32595
+ );
32572
32596
  }
32573
32597
  },
32574
32598
  className: getClassNameItem("summary"),
@@ -32588,11 +32612,12 @@ var ArrayField = ({
32588
32612
  ];
32589
32613
  existingValue.splice(i, 1);
32590
32614
  existingItems.splice(i, 1);
32591
- setArrayState(
32592
- { items: existingItems },
32593
- true
32615
+ onChange(
32616
+ existingValue,
32617
+ mapArrayStateToUi({
32618
+ items: existingItems
32619
+ })
32594
32620
  );
32595
- onChange(existingValue);
32596
32621
  },
32597
32622
  title: "Delete",
32598
32623
  children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(trash_default, { size: 16 })
@@ -32613,15 +32638,18 @@ var ArrayField = ({
32613
32638
  {
32614
32639
  name: subFieldName,
32615
32640
  label: subField.label || fieldName,
32641
+ id: `${id}_${fieldName}`,
32616
32642
  readOnly: typeof readOnlyFields[subFieldName] !== "undefined" ? readOnlyFields[subFieldName] : readOnlyFields[wildcardFieldName],
32617
32643
  readOnlyFields,
32618
32644
  field: subField,
32619
32645
  value: data[fieldName],
32620
- onChange: (val) => onChange(
32621
- replace(value, i, __spreadProps(__spreadValues({}, data), {
32622
- [fieldName]: val
32623
- }))
32624
- )
32646
+ onChange: (val) => {
32647
+ onChange(
32648
+ replace(value, i, __spreadProps(__spreadValues({}, data), {
32649
+ [fieldName]: val
32650
+ }))
32651
+ );
32652
+ }
32625
32653
  },
32626
32654
  subFieldName
32627
32655
  );
@@ -32639,7 +32667,12 @@ var ArrayField = ({
32639
32667
  className: getClassName6("addButton"),
32640
32668
  onClick: () => {
32641
32669
  const existingValue = value || [];
32642
- onChange([...existingValue, field.defaultItemProps || {}]);
32670
+ const newValue = [
32671
+ ...existingValue,
32672
+ field.defaultItemProps || {}
32673
+ ];
32674
+ const newArrayState = regenerateArrayState(newValue);
32675
+ onChange(newValue, mapArrayStateToUi(newArrayState));
32643
32676
  },
32644
32677
  children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(plus_default, { size: "21" })
32645
32678
  }
@@ -32664,7 +32697,8 @@ var DefaultField = ({
32664
32697
  readOnly,
32665
32698
  value,
32666
32699
  name,
32667
- label
32700
+ label,
32701
+ id
32668
32702
  }) => {
32669
32703
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
32670
32704
  FieldLabelInternal,
@@ -32690,7 +32724,8 @@ var DefaultField = ({
32690
32724
  onChange(e.currentTarget.value);
32691
32725
  }
32692
32726
  },
32693
- readOnly
32727
+ readOnly,
32728
+ id
32694
32729
  }
32695
32730
  )
32696
32731
  }
@@ -32779,7 +32814,8 @@ var ExternalInput = ({
32779
32814
  field,
32780
32815
  onChange,
32781
32816
  value = null,
32782
- name
32817
+ name,
32818
+ id
32783
32819
  }) => {
32784
32820
  const { mapProp = (val) => val } = field || {};
32785
32821
  const [data, setData] = (0, import_react29.useState)([]);
@@ -32813,6 +32849,7 @@ var ExternalInput = ({
32813
32849
  dataSelected: !!value,
32814
32850
  modalVisible: isOpen
32815
32851
  }),
32852
+ id,
32816
32853
  children: [
32817
32854
  /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: getClassName10("actions"), children: [
32818
32855
  /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
@@ -32890,7 +32927,8 @@ var ExternalField = ({
32890
32927
  onChange,
32891
32928
  value,
32892
32929
  name,
32893
- label
32930
+ label,
32931
+ id
32894
32932
  }) => {
32895
32933
  var _a, _b, _c;
32896
32934
  const validField = field;
@@ -32926,7 +32964,8 @@ var ExternalField = ({
32926
32964
  }) : validField.fetchList
32927
32965
  }),
32928
32966
  onChange,
32929
- value
32967
+ value,
32968
+ id
32930
32969
  }
32931
32970
  )
32932
32971
  }
@@ -32942,7 +32981,8 @@ var RadioField = ({
32942
32981
  onChange,
32943
32982
  readOnly,
32944
32983
  value,
32945
- name
32984
+ name,
32985
+ id
32946
32986
  }) => {
32947
32987
  if (field.type !== "radio" || !field.options) {
32948
32988
  return null;
@@ -32954,7 +32994,7 @@ var RadioField = ({
32954
32994
  label: field.label || name,
32955
32995
  readOnly,
32956
32996
  el: "div",
32957
- 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)(
32958
32998
  "label",
32959
32999
  {
32960
33000
  className: getClassName11("radio"),
@@ -32996,7 +33036,8 @@ var SelectField = ({
32996
33036
  label,
32997
33037
  value,
32998
33038
  name,
32999
- readOnly
33039
+ readOnly,
33040
+ id
33000
33041
  }) => {
33001
33042
  if (field.type !== "select" || !field.options) {
33002
33043
  return null;
@@ -33010,6 +33051,7 @@ var SelectField = ({
33010
33051
  children: /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
33011
33052
  "select",
33012
33053
  {
33054
+ id,
33013
33055
  className: getClassName12("input"),
33014
33056
  disabled: readOnly,
33015
33057
  onChange: (e) => {
@@ -33043,7 +33085,8 @@ var TextareaField = ({
33043
33085
  readOnly,
33044
33086
  value,
33045
33087
  name,
33046
- label
33088
+ label,
33089
+ id
33047
33090
  }) => {
33048
33091
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
33049
33092
  FieldLabelInternal,
@@ -33054,6 +33097,7 @@ var TextareaField = ({
33054
33097
  children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
33055
33098
  "textarea",
33056
33099
  {
33100
+ id,
33057
33101
  className: getClassName13("input"),
33058
33102
  autoComplete: "off",
33059
33103
  name,
@@ -33096,7 +33140,6 @@ var FieldLabelInternal = ({
33096
33140
  el = "label",
33097
33141
  readOnly
33098
33142
  }) => {
33099
- const El = el;
33100
33143
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
33101
33144
  FieldLabel,
33102
33145
  {
@@ -33114,15 +33157,15 @@ var InputOrGroup = (_a) => {
33114
33157
  const { name, field, value, readOnly } = props;
33115
33158
  const [localValue, setLocalValue] = (0, import_react31.useState)(value);
33116
33159
  const onChangeDb = (0, import_use_debounce2.useDebouncedCallback)(
33117
- (val) => {
33118
- onChange(val);
33160
+ (val, ui) => {
33161
+ onChange(val, ui);
33119
33162
  },
33120
33163
  50,
33121
33164
  { leading: true }
33122
33165
  );
33123
- const onChangeLocal = (0, import_react31.useCallback)((val) => {
33166
+ const onChangeLocal = (0, import_react31.useCallback)((val, ui) => {
33124
33167
  setLocalValue(val);
33125
- onChangeDb(val);
33168
+ onChangeDb(val, ui);
33126
33169
  }, []);
33127
33170
  (0, import_react31.useEffect)(() => {
33128
33171
  setLocalValue(value);
@@ -33417,6 +33460,13 @@ var import_react35 = require("react");
33417
33460
  // lib/use-action-history.ts
33418
33461
  init_react_import();
33419
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
33420
33470
  var EMPTY_HISTORY_INDEX = -1;
33421
33471
  function useActionHistory() {
33422
33472
  const [histories, setHistories] = (0, import_react34.useState)([]);
@@ -33825,13 +33875,19 @@ var storeInterceptor = (reducer) => {
33825
33875
  return newAppState;
33826
33876
  };
33827
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
+ };
33828
33884
  var createReducer = ({
33829
33885
  config
33830
33886
  }) => storeInterceptor((state, action) => {
33831
33887
  const data = reduceData(state.data, action, config);
33832
33888
  const ui = reduceUi(state.ui, action);
33833
33889
  if (action.type === "set") {
33834
- return __spreadValues(__spreadValues({}, state), action.state);
33890
+ return setAction(state, action);
33835
33891
  }
33836
33892
  return { data, ui };
33837
33893
  });
@@ -34202,10 +34258,10 @@ var resolveRootData = (data, config) => __async(void 0, null, function* () {
34202
34258
  });
34203
34259
 
34204
34260
  // lib/use-resolved-data.ts
34205
- var useResolvedData = (data, config, dispatch) => {
34206
- const [{ resolverKey, newData }, setResolverState] = (0, import_react38.useState)({
34261
+ var useResolvedData = (appState, config, dispatch) => {
34262
+ const [{ resolverKey, newAppState }, setResolverState] = (0, import_react38.useState)({
34207
34263
  resolverKey: 0,
34208
- newData: data
34264
+ newAppState: appState
34209
34265
  });
34210
34266
  const [componentState, setComponentState] = (0, import_react38.useState)({});
34211
34267
  const deferredSetStates = {};
@@ -34225,14 +34281,23 @@ var useResolvedData = (data, config, dispatch) => {
34225
34281
  []
34226
34282
  );
34227
34283
  const runResolvers = () => __async(void 0, null, function* () {
34284
+ const newData = newAppState.data;
34228
34285
  const flatContent = Object.keys(newData.zones || {}).reduce((acc, zone) => [...acc, ...newData.zones[zone]], newData.content).filter((item) => !!config.components[item.type].resolveData);
34229
34286
  const applyIfChange = (dynamicDataMap, dynamicRoot) => {
34230
- const processed = applyDynamicProps(data, dynamicDataMap, dynamicRoot);
34231
- 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);
34232
34294
  if (containsChanges) {
34233
34295
  dispatch({
34234
- type: "setData",
34235
- 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
+ }),
34236
34301
  recordHistory: resolverKey > 0
34237
34302
  });
34238
34303
  }
@@ -34270,10 +34335,10 @@ var useResolvedData = (data, config, dispatch) => {
34270
34335
  (0, import_react38.useEffect)(() => {
34271
34336
  runResolvers();
34272
34337
  }, [resolverKey]);
34273
- const resolveData = (0, import_react38.useCallback)((newData2 = data) => {
34338
+ const resolveData = (0, import_react38.useCallback)((newAppState2 = appState) => {
34274
34339
  setResolverState((curr) => ({
34275
34340
  resolverKey: curr.resolverKey + 1,
34276
- newData: newData2
34341
+ newAppState: newAppState2
34277
34342
  }));
34278
34343
  }, []);
34279
34344
  return {
@@ -34416,7 +34481,7 @@ function Puck({
34416
34481
  );
34417
34482
  const { data, ui } = appState;
34418
34483
  const { resolveData, componentState } = useResolvedData(
34419
- data,
34484
+ appState,
34420
34485
  config,
34421
34486
  dispatch
34422
34487
  );
@@ -34766,7 +34831,7 @@ function Puck({
34766
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,
34767
34832
  children: Object.keys(fields).map((fieldName) => {
34768
34833
  const field = fields[fieldName];
34769
- const onChange2 = (value) => {
34834
+ const onChange2 = (value, updatedUi) => {
34770
34835
  var _a3, _b3;
34771
34836
  let currentProps;
34772
34837
  if (selectedItem) {
@@ -34778,27 +34843,51 @@ function Puck({
34778
34843
  [fieldName]: value
34779
34844
  });
34780
34845
  if (itemSelector) {
34781
- const action = {
34846
+ const replaceActionData = {
34782
34847
  type: "replace",
34783
34848
  destinationIndex: itemSelector.index,
34784
34849
  destinationZone: itemSelector.zone || rootDroppableId,
34785
34850
  data: __spreadProps(__spreadValues({}, selectedItem), { props: newProps })
34786
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
+ };
34787
34863
  if ((_a3 = config.components[selectedItem.type]) == null ? void 0 : _a3.resolveData) {
34788
- resolveData(replaceAction(data, action));
34864
+ resolveData(
34865
+ setAction(appState, setActionData)
34866
+ );
34789
34867
  } else {
34790
- dispatch(action);
34868
+ dispatch(__spreadProps(__spreadValues({}, setActionData), {
34869
+ recordHistory: true
34870
+ }));
34791
34871
  }
34792
34872
  } else {
34793
34873
  if (data.root.props) {
34794
34874
  if ((_b3 = config.root) == null ? void 0 : _b3.resolveData) {
34795
- resolveData(__spreadProps(__spreadValues({}, data), {
34796
- root: { props: newProps }
34797
- }));
34875
+ resolveData({
34876
+ ui: __spreadValues(__spreadValues({}, ui), updatedUi),
34877
+ data: __spreadProps(__spreadValues({}, data), {
34878
+ root: { props: newProps }
34879
+ })
34880
+ });
34798
34881
  } else {
34799
34882
  dispatch({
34800
- type: "setData",
34801
- data: { root: { props: newProps } }
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
34802
34891
  });
34803
34892
  }
34804
34893
  } else {
@@ -34816,6 +34905,7 @@ function Puck({
34816
34905
  {
34817
34906
  field,
34818
34907
  name: fieldName,
34908
+ id: `${selectedItem.props.id}_${fieldName}`,
34819
34909
  label: field.label,
34820
34910
  readOnly: readOnly[fieldName],
34821
34911
  readOnlyFields: readOnly,
@@ -34831,6 +34921,7 @@ function Puck({
34831
34921
  {
34832
34922
  field,
34833
34923
  name: fieldName,
34924
+ id: `root_${fieldName}`,
34834
34925
  label: field.label,
34835
34926
  readOnly: readOnly[fieldName],
34836
34927
  readOnlyFields: readOnly,
package/dist/rsc.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as Config, D as Data } from './Config-e71a51c7.js';
2
+ import { C as Config, D as Data } from './Config-35e6eaae.js';
3
3
  import 'react';
4
4
 
5
5
  declare function Render({ config, data }: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.12.0-canary.349f44d",
3
+ "version": "0.12.0-canary.3f8ebc0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",