@measured/puck 0.10.0-canary.74cd3a7 → 0.10.0-canary.8d47fd7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +9 -9
- package/dist/index.js +170 -104
- 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";
|
|
@@ -195,9 +195,9 @@ type PuckAction = {
|
|
|
195
195
|
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetStateAction | RegisterZoneAction | UnregisterZoneAction);
|
|
196
196
|
|
|
197
197
|
type PathData = Record<string, {
|
|
198
|
-
|
|
198
|
+
path: string[];
|
|
199
199
|
label: string;
|
|
200
|
-
}
|
|
200
|
+
}>;
|
|
201
201
|
type DropZoneContext = {
|
|
202
202
|
data: Data;
|
|
203
203
|
config: Config;
|
|
@@ -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
|
@@ -2646,7 +2646,7 @@ var getZoneId = (zoneCompound) => {
|
|
|
2646
2646
|
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
|
2647
2647
|
return zoneCompound.split(":");
|
|
2648
2648
|
}
|
|
2649
|
-
return [
|
|
2649
|
+
return [rootDroppableId, zoneCompound];
|
|
2650
2650
|
};
|
|
2651
2651
|
|
|
2652
2652
|
// components/DropZone/context.tsx
|
|
@@ -2713,15 +2713,15 @@ var DropZoneProvider = ({
|
|
|
2713
2713
|
}
|
|
2714
2714
|
const [area] = getZoneId(selector.zone);
|
|
2715
2715
|
setPathData((latestPathData = {}) => {
|
|
2716
|
-
const
|
|
2716
|
+
const parentPathData = latestPathData[area] || { path: [] };
|
|
2717
2717
|
return __spreadProps(__spreadValues({}, latestPathData), {
|
|
2718
|
-
[item.props.id]:
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
selector
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2718
|
+
[item.props.id]: {
|
|
2719
|
+
path: [
|
|
2720
|
+
...parentPathData.path,
|
|
2721
|
+
...selector.zone ? [selector.zone] : []
|
|
2722
|
+
],
|
|
2723
|
+
label: item.type
|
|
2724
|
+
}
|
|
2725
2725
|
});
|
|
2726
2726
|
});
|
|
2727
2727
|
},
|
|
@@ -3090,7 +3090,7 @@ var IconButton = ({
|
|
|
3090
3090
|
|
|
3091
3091
|
// components/Puck/index.tsx
|
|
3092
3092
|
init_react_import();
|
|
3093
|
-
var
|
|
3093
|
+
var import_react32 = require("react");
|
|
3094
3094
|
var import_react_beautiful_dnd5 = require("react-beautiful-dnd");
|
|
3095
3095
|
|
|
3096
3096
|
// components/InputOrGroup/index.tsx
|
|
@@ -3175,26 +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.state.ui.itemSelector ? getItem(mainContext.state.ui.itemSelector, mainContext.state.data) : void 0;
|
|
3192
3193
|
return __spreadProps(__spreadValues({}, mainContext), {
|
|
3193
|
-
//
|
|
3194
|
-
|
|
3194
|
+
// Helpers
|
|
3195
|
+
selectedItem,
|
|
3196
|
+
setUi: (ui, recordHistory) => {
|
|
3195
3197
|
return mainContext.dispatch({
|
|
3196
|
-
type: "
|
|
3197
|
-
|
|
3198
|
+
type: "setUi",
|
|
3199
|
+
ui,
|
|
3198
3200
|
recordHistory
|
|
3199
3201
|
});
|
|
3200
3202
|
}
|
|
@@ -3214,8 +3216,8 @@ var ArrayField = ({
|
|
|
3214
3216
|
label
|
|
3215
3217
|
}) => {
|
|
3216
3218
|
const [arrayFieldId] = (0, import_react25.useState)(generateId("ArrayField"));
|
|
3217
|
-
const {
|
|
3218
|
-
const arrayState =
|
|
3219
|
+
const { state, setUi } = useAppContext();
|
|
3220
|
+
const arrayState = state.ui.arrayState[arrayFieldId] || {
|
|
3219
3221
|
items: Array.from(value).map((v) => ({
|
|
3220
3222
|
_arrayId: generateId("ArrayItem"),
|
|
3221
3223
|
data: v
|
|
@@ -3224,9 +3226,9 @@ var ArrayField = ({
|
|
|
3224
3226
|
};
|
|
3225
3227
|
const setArrayState = (0, import_react25.useCallback)(
|
|
3226
3228
|
(newArrayState, recordHistory = false) => {
|
|
3227
|
-
|
|
3229
|
+
setUi(
|
|
3228
3230
|
{
|
|
3229
|
-
arrayState: __spreadProps(__spreadValues({},
|
|
3231
|
+
arrayState: __spreadProps(__spreadValues({}, state.ui.arrayState), {
|
|
3230
3232
|
[arrayFieldId]: __spreadValues(__spreadValues({}, arrayState), newArrayState)
|
|
3231
3233
|
})
|
|
3232
3234
|
},
|
|
@@ -3447,12 +3449,17 @@ var ExternalInput = ({
|
|
|
3447
3449
|
const [data, setData] = (0, import_react26.useState)([]);
|
|
3448
3450
|
const [isOpen, setOpen] = (0, import_react26.useState)(false);
|
|
3449
3451
|
const [selectedData, setSelectedData] = (0, import_react26.useState)(value);
|
|
3450
|
-
const keys = (0, import_react26.useMemo)(
|
|
3451
|
-
|
|
3452
|
-
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3452
|
+
const keys = (0, import_react26.useMemo)(() => {
|
|
3453
|
+
const validKeys = /* @__PURE__ */ new Set();
|
|
3454
|
+
for (const item of data) {
|
|
3455
|
+
for (const key of Object.keys(item)) {
|
|
3456
|
+
if (typeof item[key] === "string" || typeof item[key] === "number") {
|
|
3457
|
+
validKeys.add(key);
|
|
3458
|
+
}
|
|
3459
|
+
}
|
|
3460
|
+
}
|
|
3461
|
+
return Array.from(validKeys);
|
|
3462
|
+
}, [data]);
|
|
3456
3463
|
(0, import_react26.useEffect)(() => {
|
|
3457
3464
|
(() => __async(void 0, null, function* () {
|
|
3458
3465
|
if (field.adaptor) {
|
|
@@ -3847,6 +3854,72 @@ var Heading = ({ children, rank, size = "m" }) => {
|
|
|
3847
3854
|
);
|
|
3848
3855
|
};
|
|
3849
3856
|
|
|
3857
|
+
// lib/use-breadcrumbs.ts
|
|
3858
|
+
init_react_import();
|
|
3859
|
+
var import_react28 = require("react");
|
|
3860
|
+
var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
|
|
3861
|
+
const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
|
|
3862
|
+
const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
|
|
3863
|
+
if (!id) {
|
|
3864
|
+
return [];
|
|
3865
|
+
}
|
|
3866
|
+
return currentPathData == null ? void 0 : currentPathData.path.reduce((acc, zoneCompound) => {
|
|
3867
|
+
const [area] = getZoneId(zoneCompound);
|
|
3868
|
+
if (area === rootDroppableId) {
|
|
3869
|
+
return [
|
|
3870
|
+
{
|
|
3871
|
+
label: "Page",
|
|
3872
|
+
selector: null
|
|
3873
|
+
}
|
|
3874
|
+
];
|
|
3875
|
+
}
|
|
3876
|
+
const parentZoneCompound = acc.length > 0 ? acc[acc.length - 1].zoneCompound : rootDroppableId;
|
|
3877
|
+
let parentZone = data.content;
|
|
3878
|
+
if (parentZoneCompound && parentZoneCompound !== rootDroppableId) {
|
|
3879
|
+
parentZone = data.zones[parentZoneCompound];
|
|
3880
|
+
}
|
|
3881
|
+
if (!parentZone) {
|
|
3882
|
+
return acc;
|
|
3883
|
+
}
|
|
3884
|
+
const itemIndex = parentZone.findIndex(
|
|
3885
|
+
(queryItem) => queryItem.props.id === area
|
|
3886
|
+
);
|
|
3887
|
+
const item = parentZone[itemIndex];
|
|
3888
|
+
if (!item) {
|
|
3889
|
+
return acc;
|
|
3890
|
+
}
|
|
3891
|
+
return [
|
|
3892
|
+
...acc,
|
|
3893
|
+
{
|
|
3894
|
+
label: item.type.toString(),
|
|
3895
|
+
selector: {
|
|
3896
|
+
index: itemIndex,
|
|
3897
|
+
zone: parentZoneCompound
|
|
3898
|
+
},
|
|
3899
|
+
zoneCompound
|
|
3900
|
+
}
|
|
3901
|
+
];
|
|
3902
|
+
}, []);
|
|
3903
|
+
};
|
|
3904
|
+
var useBreadcrumbs = (renderCount) => {
|
|
3905
|
+
const {
|
|
3906
|
+
state: { data },
|
|
3907
|
+
selectedItem
|
|
3908
|
+
} = useAppContext();
|
|
3909
|
+
const dzContext = (0, import_react28.useContext)(dropZoneContext);
|
|
3910
|
+
return (0, import_react28.useMemo)(() => {
|
|
3911
|
+
const breadcrumbs = convertPathDataToBreadcrumbs(
|
|
3912
|
+
selectedItem,
|
|
3913
|
+
dzContext == null ? void 0 : dzContext.pathData,
|
|
3914
|
+
data
|
|
3915
|
+
);
|
|
3916
|
+
if (renderCount) {
|
|
3917
|
+
return breadcrumbs.slice(breadcrumbs.length - renderCount);
|
|
3918
|
+
}
|
|
3919
|
+
return breadcrumbs;
|
|
3920
|
+
}, [selectedItem, dzContext == null ? void 0 : dzContext.pathData, renderCount]);
|
|
3921
|
+
};
|
|
3922
|
+
|
|
3850
3923
|
// components/SidebarSection/index.tsx
|
|
3851
3924
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
3852
3925
|
var getClassName16 = get_class_name_factory_default("SidebarSection", styles_module_default8);
|
|
@@ -3854,23 +3927,24 @@ var SidebarSection = ({
|
|
|
3854
3927
|
children,
|
|
3855
3928
|
title,
|
|
3856
3929
|
background,
|
|
3857
|
-
|
|
3858
|
-
breadcrumbClick,
|
|
3930
|
+
showBreadcrumbs,
|
|
3859
3931
|
noPadding
|
|
3860
3932
|
}) => {
|
|
3933
|
+
const { setUi } = useAppContext();
|
|
3934
|
+
const breadcrumbs = useBreadcrumbs(1);
|
|
3861
3935
|
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: getClassName16({ noPadding }), style: { background }, children: [
|
|
3862
3936
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: getClassName16("title"), children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: getClassName16("breadcrumbs"), children: [
|
|
3863
|
-
breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: getClassName16("breadcrumb"), children: [
|
|
3937
|
+
showBreadcrumbs ? breadcrumbs.map((breadcrumb, i) => /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: getClassName16("breadcrumb"), children: [
|
|
3864
3938
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
3865
3939
|
"div",
|
|
3866
3940
|
{
|
|
3867
3941
|
className: getClassName16("breadcrumbLabel"),
|
|
3868
|
-
onClick: () =>
|
|
3942
|
+
onClick: () => setUi({ itemSelector: breadcrumb.selector }),
|
|
3869
3943
|
children: breadcrumb.label
|
|
3870
3944
|
}
|
|
3871
3945
|
),
|
|
3872
3946
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(chevron_right_default, { size: 16 })
|
|
3873
|
-
] }, i)),
|
|
3947
|
+
] }, i)) : null,
|
|
3874
3948
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: getClassName16("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(Heading, { rank: 2, size: "xs", children: title }) })
|
|
3875
3949
|
] }) }),
|
|
3876
3950
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: getClassName16("content"), children })
|
|
@@ -3882,15 +3956,15 @@ init_react_import();
|
|
|
3882
3956
|
|
|
3883
3957
|
// lib/use-puck-history.ts
|
|
3884
3958
|
init_react_import();
|
|
3885
|
-
var
|
|
3959
|
+
var import_react30 = require("react");
|
|
3886
3960
|
|
|
3887
3961
|
// lib/use-action-history.ts
|
|
3888
3962
|
init_react_import();
|
|
3889
|
-
var
|
|
3963
|
+
var import_react29 = require("react");
|
|
3890
3964
|
var EMPTY_HISTORY_INDEX = -1;
|
|
3891
3965
|
function useActionHistory() {
|
|
3892
|
-
const [histories, setHistories] = (0,
|
|
3893
|
-
const [currentHistoryIndex, setCurrentHistoryIndex] = (0,
|
|
3966
|
+
const [histories, setHistories] = (0, import_react29.useState)([]);
|
|
3967
|
+
const [currentHistoryIndex, setCurrentHistoryIndex] = (0, import_react29.useState)(EMPTY_HISTORY_INDEX);
|
|
3894
3968
|
const currentHistory = histories[currentHistoryIndex];
|
|
3895
3969
|
const canRewind = currentHistoryIndex > EMPTY_HISTORY_INDEX;
|
|
3896
3970
|
const canForward = currentHistoryIndex < histories.length - 1;
|
|
@@ -3934,35 +4008,40 @@ var import_use_debounce2 = require("use-debounce");
|
|
|
3934
4008
|
var DEBOUNCE_TIME = 250;
|
|
3935
4009
|
var RECORD_DIFF = "RECORD_DIFF";
|
|
3936
4010
|
var historyEmitter = (0, import_event_emitter.default)();
|
|
3937
|
-
var recordDiff = (
|
|
3938
|
-
var _recordHistory = ({
|
|
4011
|
+
var recordDiff = (newAppState) => historyEmitter.emit(RECORD_DIFF, newAppState);
|
|
4012
|
+
var _recordHistory = ({
|
|
4013
|
+
snapshot,
|
|
4014
|
+
newSnapshot,
|
|
4015
|
+
record,
|
|
4016
|
+
dispatch
|
|
4017
|
+
}) => {
|
|
3939
4018
|
record({
|
|
3940
4019
|
forward: () => {
|
|
3941
|
-
dispatch({ type: "set",
|
|
4020
|
+
dispatch({ type: "set", state: newSnapshot });
|
|
3942
4021
|
},
|
|
3943
4022
|
rewind: () => {
|
|
3944
|
-
dispatch({ type: "set",
|
|
4023
|
+
dispatch({ type: "set", state: snapshot });
|
|
3945
4024
|
}
|
|
3946
4025
|
});
|
|
3947
4026
|
};
|
|
3948
4027
|
function usePuckHistory({
|
|
3949
|
-
|
|
4028
|
+
appState,
|
|
3950
4029
|
dispatch
|
|
3951
4030
|
}) {
|
|
3952
4031
|
const { canForward, canRewind, rewind, forward, record } = useActionHistory();
|
|
3953
4032
|
(0, import_react_hotkeys_hook.useHotkeys)("meta+z", rewind, { preventDefault: true });
|
|
3954
4033
|
(0, import_react_hotkeys_hook.useHotkeys)("meta+shift+z", forward, { preventDefault: true });
|
|
3955
4034
|
(0, import_react_hotkeys_hook.useHotkeys)("meta+y", forward, { preventDefault: true });
|
|
3956
|
-
const [snapshot] = (0, import_use_debounce2.useDebounce)(
|
|
3957
|
-
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) => {
|
|
3958
4037
|
return _recordHistory({
|
|
3959
4038
|
snapshot,
|
|
3960
|
-
newSnapshot:
|
|
4039
|
+
newSnapshot: newAppState,
|
|
3961
4040
|
record,
|
|
3962
4041
|
dispatch
|
|
3963
4042
|
});
|
|
3964
4043
|
}, DEBOUNCE_TIME);
|
|
3965
|
-
(0,
|
|
4044
|
+
(0, import_react30.useEffect)(() => {
|
|
3966
4045
|
historyEmitter.on(RECORD_DIFF, handleRecordDiff);
|
|
3967
4046
|
return () => {
|
|
3968
4047
|
historyEmitter.off(RECORD_DIFF, handleRecordDiff);
|
|
@@ -4252,11 +4331,11 @@ var reduceData = (data, action, config) => {
|
|
|
4252
4331
|
|
|
4253
4332
|
// reducer/state.ts
|
|
4254
4333
|
init_react_import();
|
|
4255
|
-
var reduceState = (
|
|
4256
|
-
if (action.type === "
|
|
4257
|
-
return __spreadValues(__spreadValues({},
|
|
4334
|
+
var reduceState = (ui, action) => {
|
|
4335
|
+
if (action.type === "setUi") {
|
|
4336
|
+
return __spreadValues(__spreadValues({}, ui), action.ui);
|
|
4258
4337
|
}
|
|
4259
|
-
return
|
|
4338
|
+
return ui;
|
|
4260
4339
|
};
|
|
4261
4340
|
|
|
4262
4341
|
// reducer/actions.tsx
|
|
@@ -4264,8 +4343,8 @@ init_react_import();
|
|
|
4264
4343
|
|
|
4265
4344
|
// reducer/index.ts
|
|
4266
4345
|
var storeInterceptor = (reducer) => {
|
|
4267
|
-
return (
|
|
4268
|
-
const
|
|
4346
|
+
return (state, action) => {
|
|
4347
|
+
const newAppState = reducer(state, action);
|
|
4269
4348
|
const isValidType = ![
|
|
4270
4349
|
"registerZone",
|
|
4271
4350
|
"unregisterZone",
|
|
@@ -4274,18 +4353,18 @@ var storeInterceptor = (reducer) => {
|
|
|
4274
4353
|
"set"
|
|
4275
4354
|
].includes(action.type);
|
|
4276
4355
|
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
|
4277
|
-
recordDiff(
|
|
4356
|
+
recordDiff(newAppState);
|
|
4278
4357
|
}
|
|
4279
|
-
return
|
|
4358
|
+
return newAppState;
|
|
4280
4359
|
};
|
|
4281
4360
|
};
|
|
4282
|
-
var createReducer = ({ config }) => storeInterceptor((
|
|
4283
|
-
const data = reduceData(
|
|
4284
|
-
const
|
|
4361
|
+
var createReducer = ({ config }) => storeInterceptor((state, action) => {
|
|
4362
|
+
const data = reduceData(state.data, action, config);
|
|
4363
|
+
const ui = reduceState(state.ui, action);
|
|
4285
4364
|
if (action.type === "set") {
|
|
4286
|
-
return __spreadValues(__spreadValues({},
|
|
4365
|
+
return __spreadValues(__spreadValues({}, state), action.state);
|
|
4287
4366
|
}
|
|
4288
|
-
return { data,
|
|
4367
|
+
return { data, ui };
|
|
4289
4368
|
});
|
|
4290
4369
|
|
|
4291
4370
|
// components/LayerTree/index.tsx
|
|
@@ -4307,7 +4386,7 @@ var scrollIntoView = (el) => {
|
|
|
4307
4386
|
};
|
|
4308
4387
|
|
|
4309
4388
|
// components/LayerTree/index.tsx
|
|
4310
|
-
var
|
|
4389
|
+
var import_react31 = require("react");
|
|
4311
4390
|
|
|
4312
4391
|
// lib/find-zones-for-area.ts
|
|
4313
4392
|
init_react_import();
|
|
@@ -4326,12 +4405,9 @@ init_react_import();
|
|
|
4326
4405
|
var isChildOfZone = (item, maybeChild, ctx) => {
|
|
4327
4406
|
var _a;
|
|
4328
4407
|
const { data, pathData = {} } = ctx || {};
|
|
4329
|
-
return maybeChild && data ? !!((_a = pathData[maybeChild.props.id]) == null ? void 0 : _a.find((
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
return (pathItem == null ? void 0 : pathItem.props.id) === item.props.id;
|
|
4333
|
-
}
|
|
4334
|
-
return false;
|
|
4408
|
+
return maybeChild && data ? !!((_a = pathData[maybeChild.props.id]) == null ? void 0 : _a.path.find((zoneCompound) => {
|
|
4409
|
+
const [area] = getZoneId(zoneCompound);
|
|
4410
|
+
return area === item.props.id;
|
|
4335
4411
|
})) : false;
|
|
4336
4412
|
};
|
|
4337
4413
|
|
|
@@ -4348,7 +4424,7 @@ var LayerTree = ({
|
|
|
4348
4424
|
label
|
|
4349
4425
|
}) => {
|
|
4350
4426
|
const zones = data.zones || {};
|
|
4351
|
-
const ctx = (0,
|
|
4427
|
+
const ctx = (0, import_react31.useContext)(dropZoneContext);
|
|
4352
4428
|
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
|
|
4353
4429
|
label && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: getClassName17("zoneTitle"), children: [
|
|
4354
4430
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName17("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(layers_default, { size: "16" }) }),
|
|
@@ -4456,19 +4532,19 @@ var areaContainsZones = (data, area) => {
|
|
|
4456
4532
|
|
|
4457
4533
|
// lib/flush-zones.ts
|
|
4458
4534
|
init_react_import();
|
|
4459
|
-
var flushZones = (
|
|
4460
|
-
const containsZones = typeof
|
|
4535
|
+
var flushZones = (appState) => {
|
|
4536
|
+
const containsZones = typeof appState.data.zones !== "undefined";
|
|
4461
4537
|
if (containsZones) {
|
|
4462
|
-
Object.keys(
|
|
4463
|
-
addToZoneCache(zone,
|
|
4538
|
+
Object.keys(appState.data.zones || {}).forEach((zone) => {
|
|
4539
|
+
addToZoneCache(zone, appState.data.zones[zone]);
|
|
4464
4540
|
});
|
|
4465
|
-
return __spreadProps(__spreadValues({},
|
|
4466
|
-
data: __spreadProps(__spreadValues({},
|
|
4541
|
+
return __spreadProps(__spreadValues({}, appState), {
|
|
4542
|
+
data: __spreadProps(__spreadValues({}, appState.data), {
|
|
4467
4543
|
zones: {}
|
|
4468
4544
|
})
|
|
4469
4545
|
});
|
|
4470
4546
|
}
|
|
4471
|
-
return
|
|
4547
|
+
return appState;
|
|
4472
4548
|
};
|
|
4473
4549
|
|
|
4474
4550
|
// components/Puck/index.tsx
|
|
@@ -4499,35 +4575,31 @@ function Puck({
|
|
|
4499
4575
|
headerPath
|
|
4500
4576
|
}) {
|
|
4501
4577
|
var _a, _b;
|
|
4502
|
-
const [reducer] = (0,
|
|
4503
|
-
const
|
|
4504
|
-
data: initialData
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
arrayState: {}
|
|
4508
|
-
}
|
|
4509
|
-
};
|
|
4510
|
-
const [appData, dispatch] = (0, import_react31.useReducer)(
|
|
4578
|
+
const [reducer] = (0, import_react32.useState)(() => createReducer({ config }));
|
|
4579
|
+
const initialAppState = __spreadProps(__spreadValues({}, defaultAppState), {
|
|
4580
|
+
data: initialData
|
|
4581
|
+
});
|
|
4582
|
+
const [appState, dispatch] = (0, import_react32.useReducer)(
|
|
4511
4583
|
reducer,
|
|
4512
|
-
flushZones(
|
|
4584
|
+
flushZones(initialAppState)
|
|
4513
4585
|
);
|
|
4514
|
-
const { data,
|
|
4586
|
+
const { data, ui } = appState;
|
|
4515
4587
|
const { canForward, canRewind, rewind, forward } = usePuckHistory({
|
|
4516
|
-
|
|
4588
|
+
appState,
|
|
4517
4589
|
dispatch
|
|
4518
4590
|
});
|
|
4519
|
-
const { itemSelector, leftSideBarVisible } =
|
|
4520
|
-
const setItemSelector = (0,
|
|
4591
|
+
const { itemSelector, leftSideBarVisible } = ui;
|
|
4592
|
+
const setItemSelector = (0, import_react32.useCallback)(
|
|
4521
4593
|
(newItemSelector) => {
|
|
4522
4594
|
dispatch({
|
|
4523
|
-
type: "
|
|
4524
|
-
|
|
4595
|
+
type: "setUi",
|
|
4596
|
+
ui: { itemSelector: newItemSelector }
|
|
4525
4597
|
});
|
|
4526
4598
|
},
|
|
4527
4599
|
[]
|
|
4528
4600
|
);
|
|
4529
4601
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
|
4530
|
-
const Page = (0,
|
|
4602
|
+
const Page = (0, import_react32.useCallback)(
|
|
4531
4603
|
(pageProps) => {
|
|
4532
4604
|
var _a2, _b2;
|
|
4533
4605
|
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
@@ -4542,7 +4614,7 @@ function Puck({
|
|
|
4542
4614
|
},
|
|
4543
4615
|
[config.root]
|
|
4544
4616
|
);
|
|
4545
|
-
const PageFieldWrapper = (0,
|
|
4617
|
+
const PageFieldWrapper = (0, import_react32.useCallback)(
|
|
4546
4618
|
(props) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
4547
4619
|
PluginRenderer,
|
|
4548
4620
|
{
|
|
@@ -4554,7 +4626,7 @@ function Puck({
|
|
|
4554
4626
|
),
|
|
4555
4627
|
[]
|
|
4556
4628
|
);
|
|
4557
|
-
const ComponentFieldWrapper = (0,
|
|
4629
|
+
const ComponentFieldWrapper = (0, import_react32.useCallback)(
|
|
4558
4630
|
(props) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
4559
4631
|
PluginRenderer,
|
|
4560
4632
|
{
|
|
@@ -4569,13 +4641,13 @@ function Puck({
|
|
|
4569
4641
|
const FieldWrapper = itemSelector ? ComponentFieldWrapper : PageFieldWrapper;
|
|
4570
4642
|
const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
|
|
4571
4643
|
let fields = selectedItem ? ((_b = config.components[selectedItem.type]) == null ? void 0 : _b.fields) || {} : rootFields;
|
|
4572
|
-
(0,
|
|
4644
|
+
(0, import_react32.useEffect)(() => {
|
|
4573
4645
|
if (onChange)
|
|
4574
4646
|
onChange(data);
|
|
4575
4647
|
}, [data]);
|
|
4576
4648
|
const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
|
|
4577
|
-
const [draggedItem, setDraggedItem] = (0,
|
|
4578
|
-
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: "puck", children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(AppProvider, { value: {
|
|
4649
|
+
const [draggedItem, setDraggedItem] = (0, import_react32.useState)();
|
|
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)(
|
|
4579
4651
|
import_react_beautiful_dnd5.DragDropContext,
|
|
4580
4652
|
{
|
|
4581
4653
|
onDragUpdate: (update) => {
|
|
@@ -4642,11 +4714,6 @@ function Puck({
|
|
|
4642
4714
|
areaId: "root"
|
|
4643
4715
|
},
|
|
4644
4716
|
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(dropZoneContext.Consumer, { children: (ctx) => {
|
|
4645
|
-
let path = (ctx == null ? void 0 : ctx.pathData) && selectedItem ? ctx == null ? void 0 : ctx.pathData[selectedItem == null ? void 0 : selectedItem.props.id] : void 0;
|
|
4646
|
-
if (path) {
|
|
4647
|
-
path = [{ label: "Page", selector: null }, ...path];
|
|
4648
|
-
path = path.slice(path.length - 2, path.length - 1);
|
|
4649
|
-
}
|
|
4650
4717
|
return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
|
|
4651
4718
|
"div",
|
|
4652
4719
|
{
|
|
@@ -4707,8 +4774,8 @@ function Puck({
|
|
|
4707
4774
|
IconButton,
|
|
4708
4775
|
{
|
|
4709
4776
|
onClick: () => dispatch({
|
|
4710
|
-
type: "
|
|
4711
|
-
|
|
4777
|
+
type: "setUi",
|
|
4778
|
+
ui: {
|
|
4712
4779
|
leftSideBarVisible: !leftSideBarVisible
|
|
4713
4780
|
}
|
|
4714
4781
|
}),
|
|
@@ -4904,8 +4971,7 @@ function Puck({
|
|
|
4904
4971
|
SidebarSection,
|
|
4905
4972
|
{
|
|
4906
4973
|
noPadding: true,
|
|
4907
|
-
|
|
4908
|
-
breadcrumbClick: (breadcrumb) => setItemSelector(breadcrumb.selector),
|
|
4974
|
+
showBreadcrumbs: true,
|
|
4909
4975
|
title: selectedItem ? selectedItem.type : "Page",
|
|
4910
4976
|
children: Object.keys(fields).map((fieldName) => {
|
|
4911
4977
|
var _a2, _b2, _c, _d;
|