@measured/puck 0.10.0-canary.6a9145c → 0.10.0-canary.8d47fd7

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -111,14 +111,14 @@ type ArrayState = {
111
111
  items: ItemWithId[];
112
112
  openId: string;
113
113
  };
114
- type AppState = {
114
+ type UiState = {
115
115
  leftSideBarVisible: boolean;
116
116
  itemSelector?: ItemSelector | null;
117
117
  arrayState: Record<string, ArrayState | undefined>;
118
118
  };
119
- type AppData = {
119
+ type AppState = {
120
120
  data: Data;
121
- state: AppState;
121
+ ui: UiState;
122
122
  };
123
123
 
124
124
  declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, }: {
@@ -171,8 +171,8 @@ type RemoveAction = {
171
171
  zone: string;
172
172
  };
173
173
  type SetStateAction = {
174
- type: "setState";
175
- state: Partial<AppState>;
174
+ type: "setUi";
175
+ ui: Partial<UiState>;
176
176
  };
177
177
  type SetDataAction = {
178
178
  type: "setData";
@@ -180,7 +180,7 @@ type SetDataAction = {
180
180
  };
181
181
  type SetAction = {
182
182
  type: "set";
183
- appData: Partial<AppData>;
183
+ state: Partial<AppState>;
184
184
  };
185
185
  type RegisterZoneAction = {
186
186
  type: "registerZone";
@@ -292,4 +292,4 @@ declare const FieldLabel: ({ children, icon, label, }: {
292
292
  label: string;
293
293
  }) => react_jsx_runtime.JSX.Element;
294
294
 
295
- export { Adaptor, AppData, AppState, ArrayState, Button, ComponentConfig, Config, Content, Data, DefaultComponentProps, DefaultRootProps, DropZone, DropZoneProvider, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, dropZoneContext };
295
+ export { Adaptor, AppState, ArrayState, Button, ComponentConfig, Config, Content, Data, DefaultComponentProps, DefaultRootProps, DropZone, DropZoneProvider, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, UiState, dropZoneContext };
package/dist/index.js CHANGED
@@ -3175,28 +3175,28 @@ var DragIcon = () => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { class
3175
3175
  // components/Puck/context.tsx
3176
3176
  init_react_import();
3177
3177
  var import_react24 = require("react");
3178
- var defaultAppData = {
3178
+ var defaultAppState = {
3179
3179
  data: { content: [], root: { title: "" } },
3180
- state: {
3180
+ ui: {
3181
3181
  leftSideBarVisible: true,
3182
3182
  arrayState: {}
3183
3183
  }
3184
3184
  };
3185
3185
  var appContext = (0, import_react24.createContext)({
3186
- appData: defaultAppData,
3186
+ state: defaultAppState,
3187
3187
  dispatch: () => null
3188
3188
  });
3189
3189
  var AppProvider = appContext.Provider;
3190
3190
  var useAppContext = () => {
3191
3191
  const mainContext = (0, import_react24.useContext)(appContext);
3192
- const selectedItem = mainContext.appData.state.itemSelector ? getItem(mainContext.appData.state.itemSelector, mainContext.appData.data) : void 0;
3192
+ const selectedItem = mainContext.state.ui.itemSelector ? getItem(mainContext.state.ui.itemSelector, mainContext.state.data) : void 0;
3193
3193
  return __spreadProps(__spreadValues({}, mainContext), {
3194
3194
  // Helpers
3195
3195
  selectedItem,
3196
- setState: (state, recordHistory) => {
3196
+ setUi: (ui, recordHistory) => {
3197
3197
  return mainContext.dispatch({
3198
- type: "setState",
3199
- state,
3198
+ type: "setUi",
3199
+ ui,
3200
3200
  recordHistory
3201
3201
  });
3202
3202
  }
@@ -3216,8 +3216,8 @@ var ArrayField = ({
3216
3216
  label
3217
3217
  }) => {
3218
3218
  const [arrayFieldId] = (0, import_react25.useState)(generateId("ArrayField"));
3219
- const { appData, setState } = useAppContext();
3220
- const arrayState = appData.state.arrayState[arrayFieldId] || {
3219
+ const { state, setUi } = useAppContext();
3220
+ const arrayState = state.ui.arrayState[arrayFieldId] || {
3221
3221
  items: Array.from(value).map((v) => ({
3222
3222
  _arrayId: generateId("ArrayItem"),
3223
3223
  data: v
@@ -3226,9 +3226,9 @@ var ArrayField = ({
3226
3226
  };
3227
3227
  const setArrayState = (0, import_react25.useCallback)(
3228
3228
  (newArrayState, recordHistory = false) => {
3229
- setState(
3229
+ setUi(
3230
3230
  {
3231
- arrayState: __spreadProps(__spreadValues({}, appData.state.arrayState), {
3231
+ arrayState: __spreadProps(__spreadValues({}, state.ui.arrayState), {
3232
3232
  [arrayFieldId]: __spreadValues(__spreadValues({}, arrayState), newArrayState)
3233
3233
  })
3234
3234
  },
@@ -3903,7 +3903,7 @@ var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
3903
3903
  };
3904
3904
  var useBreadcrumbs = (renderCount) => {
3905
3905
  const {
3906
- appData: { data },
3906
+ state: { data },
3907
3907
  selectedItem
3908
3908
  } = useAppContext();
3909
3909
  const dzContext = (0, import_react28.useContext)(dropZoneContext);
@@ -3930,7 +3930,7 @@ var SidebarSection = ({
3930
3930
  showBreadcrumbs,
3931
3931
  noPadding
3932
3932
  }) => {
3933
- const { setState } = useAppContext();
3933
+ const { setUi } = useAppContext();
3934
3934
  const breadcrumbs = useBreadcrumbs(1);
3935
3935
  return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: getClassName16({ noPadding }), style: { background }, children: [
3936
3936
  /* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: getClassName16("title"), children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: getClassName16("breadcrumbs"), children: [
@@ -3939,7 +3939,7 @@ var SidebarSection = ({
3939
3939
  "div",
3940
3940
  {
3941
3941
  className: getClassName16("breadcrumbLabel"),
3942
- onClick: () => setState({ itemSelector: breadcrumb.selector }),
3942
+ onClick: () => setUi({ itemSelector: breadcrumb.selector }),
3943
3943
  children: breadcrumb.label
3944
3944
  }
3945
3945
  ),
@@ -4008,30 +4008,35 @@ var import_use_debounce2 = require("use-debounce");
4008
4008
  var DEBOUNCE_TIME = 250;
4009
4009
  var RECORD_DIFF = "RECORD_DIFF";
4010
4010
  var historyEmitter = (0, import_event_emitter.default)();
4011
- var recordDiff = (newAppData) => historyEmitter.emit(RECORD_DIFF, newAppData);
4012
- var _recordHistory = ({ snapshot, newSnapshot, record, dispatch }) => {
4011
+ var recordDiff = (newAppState) => historyEmitter.emit(RECORD_DIFF, newAppState);
4012
+ var _recordHistory = ({
4013
+ snapshot,
4014
+ newSnapshot,
4015
+ record,
4016
+ dispatch
4017
+ }) => {
4013
4018
  record({
4014
4019
  forward: () => {
4015
- dispatch({ type: "set", appData: newSnapshot });
4020
+ dispatch({ type: "set", state: newSnapshot });
4016
4021
  },
4017
4022
  rewind: () => {
4018
- dispatch({ type: "set", appData: snapshot });
4023
+ dispatch({ type: "set", state: snapshot });
4019
4024
  }
4020
4025
  });
4021
4026
  };
4022
4027
  function usePuckHistory({
4023
- appData,
4028
+ appState,
4024
4029
  dispatch
4025
4030
  }) {
4026
4031
  const { canForward, canRewind, rewind, forward, record } = useActionHistory();
4027
4032
  (0, import_react_hotkeys_hook.useHotkeys)("meta+z", rewind, { preventDefault: true });
4028
4033
  (0, import_react_hotkeys_hook.useHotkeys)("meta+shift+z", forward, { preventDefault: true });
4029
4034
  (0, import_react_hotkeys_hook.useHotkeys)("meta+y", forward, { preventDefault: true });
4030
- const [snapshot] = (0, import_use_debounce2.useDebounce)(appData, DEBOUNCE_TIME);
4031
- const handleRecordDiff = (0, import_use_debounce2.useDebouncedCallback)((newAppData) => {
4035
+ const [snapshot] = (0, import_use_debounce2.useDebounce)(appState, DEBOUNCE_TIME);
4036
+ const handleRecordDiff = (0, import_use_debounce2.useDebouncedCallback)((newAppState) => {
4032
4037
  return _recordHistory({
4033
4038
  snapshot,
4034
- newSnapshot: newAppData,
4039
+ newSnapshot: newAppState,
4035
4040
  record,
4036
4041
  dispatch
4037
4042
  });
@@ -4326,11 +4331,11 @@ var reduceData = (data, action, config) => {
4326
4331
 
4327
4332
  // reducer/state.ts
4328
4333
  init_react_import();
4329
- var reduceState = (state, action) => {
4330
- if (action.type === "setState") {
4331
- return __spreadValues(__spreadValues({}, state), action.state);
4334
+ var reduceState = (ui, action) => {
4335
+ if (action.type === "setUi") {
4336
+ return __spreadValues(__spreadValues({}, ui), action.ui);
4332
4337
  }
4333
- return state;
4338
+ return ui;
4334
4339
  };
4335
4340
 
4336
4341
  // reducer/actions.tsx
@@ -4338,8 +4343,8 @@ init_react_import();
4338
4343
 
4339
4344
  // reducer/index.ts
4340
4345
  var storeInterceptor = (reducer) => {
4341
- return (appData, action) => {
4342
- const newAppData = reducer(appData, action);
4346
+ return (state, action) => {
4347
+ const newAppState = reducer(state, action);
4343
4348
  const isValidType = ![
4344
4349
  "registerZone",
4345
4350
  "unregisterZone",
@@ -4348,18 +4353,18 @@ var storeInterceptor = (reducer) => {
4348
4353
  "set"
4349
4354
  ].includes(action.type);
4350
4355
  if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
4351
- recordDiff(newAppData);
4356
+ recordDiff(newAppState);
4352
4357
  }
4353
- return newAppData;
4358
+ return newAppState;
4354
4359
  };
4355
4360
  };
4356
- var createReducer = ({ config }) => storeInterceptor((appData, action) => {
4357
- const data = reduceData(appData.data, action, config);
4358
- const state = reduceState(appData.state, action);
4361
+ var createReducer = ({ config }) => storeInterceptor((state, action) => {
4362
+ const data = reduceData(state.data, action, config);
4363
+ const ui = reduceState(state.ui, action);
4359
4364
  if (action.type === "set") {
4360
- return __spreadValues(__spreadValues({}, appData), action.appData);
4365
+ return __spreadValues(__spreadValues({}, state), action.state);
4361
4366
  }
4362
- return { data, state };
4367
+ return { data, ui };
4363
4368
  });
4364
4369
 
4365
4370
  // components/LayerTree/index.tsx
@@ -4527,19 +4532,19 @@ var areaContainsZones = (data, area) => {
4527
4532
 
4528
4533
  // lib/flush-zones.ts
4529
4534
  init_react_import();
4530
- var flushZones = (appData) => {
4531
- const containsZones = typeof appData.data.zones !== "undefined";
4535
+ var flushZones = (appState) => {
4536
+ const containsZones = typeof appState.data.zones !== "undefined";
4532
4537
  if (containsZones) {
4533
- Object.keys(appData.data.zones || {}).forEach((zone) => {
4534
- addToZoneCache(zone, appData.data.zones[zone]);
4538
+ Object.keys(appState.data.zones || {}).forEach((zone) => {
4539
+ addToZoneCache(zone, appState.data.zones[zone]);
4535
4540
  });
4536
- return __spreadProps(__spreadValues({}, appData), {
4537
- data: __spreadProps(__spreadValues({}, appData.data), {
4541
+ return __spreadProps(__spreadValues({}, appState), {
4542
+ data: __spreadProps(__spreadValues({}, appState.data), {
4538
4543
  zones: {}
4539
4544
  })
4540
4545
  });
4541
4546
  }
4542
- return appData;
4547
+ return appState;
4543
4548
  };
4544
4549
 
4545
4550
  // components/Puck/index.tsx
@@ -4571,28 +4576,24 @@ function Puck({
4571
4576
  }) {
4572
4577
  var _a, _b;
4573
4578
  const [reducer] = (0, import_react32.useState)(() => createReducer({ config }));
4574
- const initialAppData = {
4575
- data: initialData,
4576
- state: {
4577
- leftSideBarVisible: true,
4578
- arrayState: {}
4579
- }
4580
- };
4581
- const [appData, dispatch] = (0, import_react32.useReducer)(
4579
+ const initialAppState = __spreadProps(__spreadValues({}, defaultAppState), {
4580
+ data: initialData
4581
+ });
4582
+ const [appState, dispatch] = (0, import_react32.useReducer)(
4582
4583
  reducer,
4583
- flushZones(initialAppData)
4584
+ flushZones(initialAppState)
4584
4585
  );
4585
- const { data, state } = appData;
4586
+ const { data, ui } = appState;
4586
4587
  const { canForward, canRewind, rewind, forward } = usePuckHistory({
4587
- appData,
4588
+ appState,
4588
4589
  dispatch
4589
4590
  });
4590
- const { itemSelector, leftSideBarVisible } = state;
4591
+ const { itemSelector, leftSideBarVisible } = ui;
4591
4592
  const setItemSelector = (0, import_react32.useCallback)(
4592
4593
  (newItemSelector) => {
4593
4594
  dispatch({
4594
- type: "setState",
4595
- state: { itemSelector: newItemSelector }
4595
+ type: "setUi",
4596
+ ui: { itemSelector: newItemSelector }
4596
4597
  });
4597
4598
  },
4598
4599
  []
@@ -4646,7 +4647,7 @@ function Puck({
4646
4647
  }, [data]);
4647
4648
  const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
4648
4649
  const [draggedItem, setDraggedItem] = (0, import_react32.useState)();
4649
- return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "puck", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(AppProvider, { value: { appData, dispatch }, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4650
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "puck", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(AppProvider, { value: { state: appState, dispatch }, children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
4650
4651
  import_react_beautiful_dnd5.DragDropContext,
4651
4652
  {
4652
4653
  onDragUpdate: (update) => {
@@ -4773,8 +4774,8 @@ function Puck({
4773
4774
  IconButton,
4774
4775
  {
4775
4776
  onClick: () => dispatch({
4776
- type: "setState",
4777
- state: {
4777
+ type: "setUi",
4778
+ ui: {
4778
4779
  leftSideBarVisible: !leftSideBarVisible
4779
4780
  }
4780
4781
  }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.10.0-canary.6a9145c",
3
+ "version": "0.10.0-canary.8d47fd7",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",