@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 +7 -7
- package/dist/index.js +60 -59
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -111,14 +111,14 @@ type ArrayState = {
|
|
111
111
|
items: ItemWithId[];
|
112
112
|
openId: string;
|
113
113
|
};
|
114
|
-
type
|
114
|
+
type UiState = {
|
115
115
|
leftSideBarVisible: boolean;
|
116
116
|
itemSelector?: ItemSelector | null;
|
117
117
|
arrayState: Record<string, ArrayState | undefined>;
|
118
118
|
};
|
119
|
-
type
|
119
|
+
type AppState = {
|
120
120
|
data: Data;
|
121
|
-
|
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: "
|
175
|
-
|
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
|
-
|
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,
|
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
|
3178
|
+
var defaultAppState = {
|
3179
3179
|
data: { content: [], root: { title: "" } },
|
3180
|
-
|
3180
|
+
ui: {
|
3181
3181
|
leftSideBarVisible: true,
|
3182
3182
|
arrayState: {}
|
3183
3183
|
}
|
3184
3184
|
};
|
3185
3185
|
var appContext = (0, import_react24.createContext)({
|
3186
|
-
|
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.
|
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
|
-
|
3196
|
+
setUi: (ui, recordHistory) => {
|
3197
3197
|
return mainContext.dispatch({
|
3198
|
-
type: "
|
3199
|
-
|
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 {
|
3220
|
-
const arrayState =
|
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
|
-
|
3229
|
+
setUi(
|
3230
3230
|
{
|
3231
|
-
arrayState: __spreadProps(__spreadValues({},
|
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
|
-
|
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 {
|
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: () =>
|
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 = (
|
4012
|
-
var _recordHistory = ({
|
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",
|
4020
|
+
dispatch({ type: "set", state: newSnapshot });
|
4016
4021
|
},
|
4017
4022
|
rewind: () => {
|
4018
|
-
dispatch({ type: "set",
|
4023
|
+
dispatch({ type: "set", state: snapshot });
|
4019
4024
|
}
|
4020
4025
|
});
|
4021
4026
|
};
|
4022
4027
|
function usePuckHistory({
|
4023
|
-
|
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)(
|
4031
|
-
const handleRecordDiff = (0, import_use_debounce2.useDebouncedCallback)((
|
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:
|
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 = (
|
4330
|
-
if (action.type === "
|
4331
|
-
return __spreadValues(__spreadValues({},
|
4334
|
+
var reduceState = (ui, action) => {
|
4335
|
+
if (action.type === "setUi") {
|
4336
|
+
return __spreadValues(__spreadValues({}, ui), action.ui);
|
4332
4337
|
}
|
4333
|
-
return
|
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 (
|
4342
|
-
const
|
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(
|
4356
|
+
recordDiff(newAppState);
|
4352
4357
|
}
|
4353
|
-
return
|
4358
|
+
return newAppState;
|
4354
4359
|
};
|
4355
4360
|
};
|
4356
|
-
var createReducer = ({ config }) => storeInterceptor((
|
4357
|
-
const data = reduceData(
|
4358
|
-
const
|
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({},
|
4365
|
+
return __spreadValues(__spreadValues({}, state), action.state);
|
4361
4366
|
}
|
4362
|
-
return { data,
|
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 = (
|
4531
|
-
const containsZones = typeof
|
4535
|
+
var flushZones = (appState) => {
|
4536
|
+
const containsZones = typeof appState.data.zones !== "undefined";
|
4532
4537
|
if (containsZones) {
|
4533
|
-
Object.keys(
|
4534
|
-
addToZoneCache(zone,
|
4538
|
+
Object.keys(appState.data.zones || {}).forEach((zone) => {
|
4539
|
+
addToZoneCache(zone, appState.data.zones[zone]);
|
4535
4540
|
});
|
4536
|
-
return __spreadProps(__spreadValues({},
|
4537
|
-
data: __spreadProps(__spreadValues({},
|
4541
|
+
return __spreadProps(__spreadValues({}, appState), {
|
4542
|
+
data: __spreadProps(__spreadValues({}, appState.data), {
|
4538
4543
|
zones: {}
|
4539
4544
|
})
|
4540
4545
|
});
|
4541
4546
|
}
|
4542
|
-
return
|
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
|
4575
|
-
data: initialData
|
4576
|
-
|
4577
|
-
|
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(
|
4584
|
+
flushZones(initialAppState)
|
4584
4585
|
);
|
4585
|
-
const { data,
|
4586
|
+
const { data, ui } = appState;
|
4586
4587
|
const { canForward, canRewind, rewind, forward } = usePuckHistory({
|
4587
|
-
|
4588
|
+
appState,
|
4588
4589
|
dispatch
|
4589
4590
|
});
|
4590
|
-
const { itemSelector, leftSideBarVisible } =
|
4591
|
+
const { itemSelector, leftSideBarVisible } = ui;
|
4591
4592
|
const setItemSelector = (0, import_react32.useCallback)(
|
4592
4593
|
(newItemSelector) => {
|
4593
4594
|
dispatch({
|
4594
|
-
type: "
|
4595
|
-
|
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: {
|
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: "
|
4777
|
-
|
4777
|
+
type: "setUi",
|
4778
|
+
ui: {
|
4778
4779
|
leftSideBarVisible: !leftSideBarVisible
|
4779
4780
|
}
|
4780
4781
|
}),
|