@measured/puck 0.9.1-canary.f4e8d4a → 0.10.0-canary.3fe6284
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +26 -8
- package/dist/index.js +184 -126
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -3,6 +3,11 @@ import { ReactElement, ReactNode, CSSProperties } from 'react';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
4
4
|
import { DragStart, DragUpdate } from 'react-beautiful-dnd';
|
5
5
|
|
6
|
+
type ItemSelector = {
|
7
|
+
index: number;
|
8
|
+
zone?: string;
|
9
|
+
};
|
10
|
+
|
6
11
|
type Adaptor<AdaptorParams = {}> = {
|
7
12
|
name: string;
|
8
13
|
fetchList: (adaptorParams?: AdaptorParams) => Promise<Record<string, any>[] | null>;
|
@@ -98,6 +103,14 @@ type Data<Props extends {
|
|
98
103
|
content: Content<Props>;
|
99
104
|
zones?: Record<string, Content<Props>>;
|
100
105
|
};
|
106
|
+
type AppState = {
|
107
|
+
leftSideBarVisible: boolean;
|
108
|
+
itemSelector?: ItemSelector | null;
|
109
|
+
};
|
110
|
+
type AppData = {
|
111
|
+
data: Data;
|
112
|
+
state: AppState;
|
113
|
+
};
|
101
114
|
|
102
115
|
declare const Button: ({ children, href, onClick, variant, type, disabled, tabIndex, newTab, fullWidth, icon, size, }: {
|
103
116
|
children: ReactNode;
|
@@ -113,11 +126,6 @@ declare const Button: ({ children, href, onClick, variant, type, disabled, tabIn
|
|
113
126
|
size?: "medium" | "large" | undefined;
|
114
127
|
}) => react_jsx_runtime.JSX.Element;
|
115
128
|
|
116
|
-
type ItemSelector = {
|
117
|
-
index: number;
|
118
|
-
zone?: string;
|
119
|
-
};
|
120
|
-
|
121
129
|
type InsertAction = {
|
122
130
|
type: "insert";
|
123
131
|
componentType: string;
|
@@ -153,10 +161,18 @@ type RemoveAction = {
|
|
153
161
|
index: number;
|
154
162
|
zone: string;
|
155
163
|
};
|
164
|
+
type SetStateAction = {
|
165
|
+
type: "setState";
|
166
|
+
state: Partial<AppState>;
|
167
|
+
};
|
156
168
|
type SetDataAction = {
|
157
|
-
type: "
|
169
|
+
type: "setData";
|
158
170
|
data: Partial<Data>;
|
159
171
|
};
|
172
|
+
type SetAction = {
|
173
|
+
type: "set";
|
174
|
+
appData: Partial<AppData>;
|
175
|
+
};
|
160
176
|
type RegisterZoneAction = {
|
161
177
|
type: "registerZone";
|
162
178
|
zone: string;
|
@@ -165,7 +181,9 @@ type UnregisterZoneAction = {
|
|
165
181
|
type: "unregisterZone";
|
166
182
|
zone: string;
|
167
183
|
};
|
168
|
-
type PuckAction =
|
184
|
+
type PuckAction = {
|
185
|
+
recordHistory?: boolean;
|
186
|
+
} & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetStateAction | RegisterZoneAction | UnregisterZoneAction);
|
169
187
|
|
170
188
|
type PathData = Record<string, {
|
171
189
|
selector: ItemSelector | null;
|
@@ -265,4 +283,4 @@ declare const FieldLabel: ({ children, icon, label, }: {
|
|
265
283
|
label: string;
|
266
284
|
}) => react_jsx_runtime.JSX.Element;
|
267
285
|
|
268
|
-
export { Adaptor, Button, ComponentConfig, Config, Content, Data, DefaultComponentProps, DefaultRootProps, DropZone, DropZoneProvider, Field, FieldLabel, Fields, IconButton, Puck, Render, dropZoneContext };
|
286
|
+
export { Adaptor, AppData, AppState, Button, ComponentConfig, Config, Content, Data, DefaultComponentProps, DefaultRootProps, DropZone, DropZoneProvider, Field, FieldLabel, Fields, IconButton, Puck, Render, dropZoneContext };
|
package/dist/index.js
CHANGED
@@ -3033,6 +3033,12 @@ var ExternalInput = ({
|
|
3033
3033
|
const [data, setData] = (0, import_react23.useState)([]);
|
3034
3034
|
const [isOpen, setOpen] = (0, import_react23.useState)(false);
|
3035
3035
|
const [selectedData, setSelectedData] = (0, import_react23.useState)(value);
|
3036
|
+
const keys = (0, import_react23.useMemo)(
|
3037
|
+
() => Object.keys(data).filter(
|
3038
|
+
(key) => typeof data[key] === "string" || typeof data[key] === "number"
|
3039
|
+
),
|
3040
|
+
[data]
|
3041
|
+
);
|
3036
3042
|
(0, import_react23.useEffect)(() => {
|
3037
3043
|
(() => __async(void 0, null, function* () {
|
3038
3044
|
if (field.adaptor) {
|
@@ -3089,7 +3095,7 @@ var ExternalInput = ({
|
|
3089
3095
|
children: [
|
3090
3096
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h2", { className: getClassName5("modalHeading"), children: "Select content" }),
|
3091
3097
|
data.length ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: getClassName5("modalTableWrapper"), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("table", { children: [
|
3092
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("tr", { children:
|
3098
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("tr", { children: keys.map((key) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("th", { style: { textAlign: "left" }, children: key }, key)) }) }),
|
3093
3099
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("tbody", { children: data.map((item, i) => {
|
3094
3100
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
3095
3101
|
"tr",
|
@@ -3100,7 +3106,7 @@ var ExternalInput = ({
|
|
3100
3106
|
setOpen(false);
|
3101
3107
|
setSelectedData(item);
|
3102
3108
|
},
|
3103
|
-
children:
|
3109
|
+
children: keys.map((key) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("td", { children: item[key] }, key))
|
3104
3110
|
},
|
3105
3111
|
i
|
3106
3112
|
);
|
@@ -3522,96 +3528,9 @@ var SidebarSection = ({
|
|
3522
3528
|
] });
|
3523
3529
|
};
|
3524
3530
|
|
3525
|
-
//
|
3531
|
+
// reducer/index.ts
|
3526
3532
|
init_react_import();
|
3527
3533
|
|
3528
|
-
// lib/insert.ts
|
3529
|
-
init_react_import();
|
3530
|
-
var insert = (list, index, item) => {
|
3531
|
-
const result = Array.from(list);
|
3532
|
-
result.splice(index, 0, item);
|
3533
|
-
return result;
|
3534
|
-
};
|
3535
|
-
|
3536
|
-
// lib/remove.ts
|
3537
|
-
init_react_import();
|
3538
|
-
var remove = (list, index) => {
|
3539
|
-
const result = Array.from(list);
|
3540
|
-
result.splice(index, 1);
|
3541
|
-
return result;
|
3542
|
-
};
|
3543
|
-
|
3544
|
-
// lib/reduce-related-zones.ts
|
3545
|
-
init_react_import();
|
3546
|
-
|
3547
|
-
// lib/generate-id.ts
|
3548
|
-
init_react_import();
|
3549
|
-
var import_crypto = require("crypto");
|
3550
|
-
var generateId = (type) => `${type}-${(0, import_crypto.randomBytes)(20).toString("hex")}`;
|
3551
|
-
|
3552
|
-
// lib/reduce-related-zones.ts
|
3553
|
-
var reduceRelatedZones = (item, data, fn) => {
|
3554
|
-
return __spreadProps(__spreadValues({}, data), {
|
3555
|
-
zones: Object.keys(data.zones || {}).reduce(
|
3556
|
-
(acc, key) => {
|
3557
|
-
const [parentId] = getZoneId(key);
|
3558
|
-
if (parentId === item.props.id) {
|
3559
|
-
const zones = data.zones;
|
3560
|
-
return fn(acc, key, zones[key]);
|
3561
|
-
}
|
3562
|
-
return __spreadProps(__spreadValues({}, acc), { [key]: data.zones[key] });
|
3563
|
-
},
|
3564
|
-
{}
|
3565
|
-
)
|
3566
|
-
});
|
3567
|
-
};
|
3568
|
-
var findRelatedByZoneId = (zoneId, data) => {
|
3569
|
-
const [zoneParentId] = getZoneId(zoneId);
|
3570
|
-
return (data.zones[zoneId] || []).reduce((acc, zoneItem) => {
|
3571
|
-
const related = findRelatedByItem(zoneItem, data);
|
3572
|
-
if (zoneItem.props.id === zoneParentId) {
|
3573
|
-
return __spreadProps(__spreadValues(__spreadValues({}, acc), related), { [zoneId]: zoneItem });
|
3574
|
-
}
|
3575
|
-
return __spreadValues(__spreadValues({}, acc), related);
|
3576
|
-
}, {});
|
3577
|
-
};
|
3578
|
-
var findRelatedByItem = (item, data) => {
|
3579
|
-
return Object.keys(data.zones || {}).reduce((acc, zoneId) => {
|
3580
|
-
const [zoneParentId] = getZoneId(zoneId);
|
3581
|
-
if (item.props.id === zoneParentId) {
|
3582
|
-
const related = findRelatedByZoneId(zoneId, data);
|
3583
|
-
return __spreadProps(__spreadValues(__spreadValues({}, acc), related), {
|
3584
|
-
[zoneId]: data.zones[zoneId]
|
3585
|
-
});
|
3586
|
-
}
|
3587
|
-
return acc;
|
3588
|
-
}, {});
|
3589
|
-
};
|
3590
|
-
var removeRelatedZones = (item, data) => {
|
3591
|
-
const newData = __spreadValues({}, data);
|
3592
|
-
const related = findRelatedByItem(item, data);
|
3593
|
-
Object.keys(related).forEach((key) => {
|
3594
|
-
delete newData.zones[key];
|
3595
|
-
});
|
3596
|
-
return newData;
|
3597
|
-
};
|
3598
|
-
var duplicateRelatedZones = (item, data, newId) => {
|
3599
|
-
return reduceRelatedZones(item, data, (acc, key, zone) => {
|
3600
|
-
const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
|
3601
|
-
props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
|
3602
|
-
}));
|
3603
|
-
const dupeOfDupes = dupedZone.reduce(
|
3604
|
-
(dupeOfDupes2, item2, index) => __spreadValues(__spreadValues({}, dupeOfDupes2), duplicateRelatedZones(zone[index], data, item2.props.id).zones),
|
3605
|
-
acc
|
3606
|
-
);
|
3607
|
-
const [_, zoneId] = getZoneId(key);
|
3608
|
-
return __spreadProps(__spreadValues({}, dupeOfDupes), {
|
3609
|
-
[key]: zone,
|
3610
|
-
[`${newId}:${zoneId}`]: dupedZone
|
3611
|
-
});
|
3612
|
-
});
|
3613
|
-
};
|
3614
|
-
|
3615
3534
|
// lib/use-puck-history.ts
|
3616
3535
|
init_react_import();
|
3617
3536
|
var import_react26 = require("react");
|
@@ -3667,37 +3586,37 @@ var import_deep_diff = require("deep-diff");
|
|
3667
3586
|
var DEBOUNCE_TIME = 250;
|
3668
3587
|
var RECORD_DIFF = "RECORD_DIFF";
|
3669
3588
|
var historyEmitter = (0, import_event_emitter.default)();
|
3670
|
-
var recordDiff = (
|
3589
|
+
var recordDiff = (newAppData) => historyEmitter.emit(RECORD_DIFF, newAppData);
|
3671
3590
|
function usePuckHistory({
|
3672
|
-
|
3591
|
+
appData,
|
3673
3592
|
dispatch
|
3674
3593
|
}) {
|
3675
3594
|
const { canForward, canRewind, rewind, forward, record } = useActionHistory();
|
3676
3595
|
(0, import_react_hotkeys_hook.useHotkeys)("meta+z", rewind, { preventDefault: true });
|
3677
3596
|
(0, import_react_hotkeys_hook.useHotkeys)("meta+shift+z", forward, { preventDefault: true });
|
3678
3597
|
(0, import_react_hotkeys_hook.useHotkeys)("meta+y", forward, { preventDefault: true });
|
3679
|
-
const [snapshot] = (0, import_use_debounce2.useDebounce)(
|
3680
|
-
const handleRecordDiff = (0, import_use_debounce2.useDebouncedCallback)((
|
3681
|
-
const _diff = (0, import_deep_diff.diff)(snapshot,
|
3598
|
+
const [snapshot] = (0, import_use_debounce2.useDebounce)(appData, DEBOUNCE_TIME);
|
3599
|
+
const handleRecordDiff = (0, import_use_debounce2.useDebouncedCallback)((newAppData) => {
|
3600
|
+
const _diff = (0, import_deep_diff.diff)(snapshot, newAppData);
|
3682
3601
|
if (!_diff) {
|
3683
3602
|
return;
|
3684
3603
|
}
|
3685
3604
|
record({
|
3686
3605
|
forward: () => {
|
3687
|
-
const target = structuredClone(
|
3606
|
+
const target = structuredClone(appData);
|
3688
3607
|
_diff.reduce((target2, change) => {
|
3689
3608
|
(0, import_deep_diff.applyChange)(target2, true, change);
|
3690
3609
|
return target2;
|
3691
3610
|
}, target);
|
3692
|
-
dispatch({ type: "set",
|
3611
|
+
dispatch({ type: "set", appData: target });
|
3693
3612
|
},
|
3694
3613
|
rewind: () => {
|
3695
|
-
const target = structuredClone(
|
3614
|
+
const target = structuredClone(appData);
|
3696
3615
|
_diff.reduce((target2, change) => {
|
3697
3616
|
(0, import_deep_diff.revertChange)(target2, true, change);
|
3698
3617
|
return target2;
|
3699
3618
|
}, target);
|
3700
|
-
dispatch({ type: "set",
|
3619
|
+
dispatch({ type: "set", appData: target });
|
3701
3620
|
}
|
3702
3621
|
});
|
3703
3622
|
}, DEBOUNCE_TIME);
|
@@ -3716,21 +3635,102 @@ function usePuckHistory({
|
|
3716
3635
|
};
|
3717
3636
|
}
|
3718
3637
|
|
3719
|
-
//
|
3638
|
+
// reducer/data.ts
|
3639
|
+
init_react_import();
|
3640
|
+
|
3641
|
+
// lib/insert.ts
|
3642
|
+
init_react_import();
|
3643
|
+
var insert = (list, index, item) => {
|
3644
|
+
const result = Array.from(list);
|
3645
|
+
result.splice(index, 0, item);
|
3646
|
+
return result;
|
3647
|
+
};
|
3648
|
+
|
3649
|
+
// lib/remove.ts
|
3650
|
+
init_react_import();
|
3651
|
+
var remove = (list, index) => {
|
3652
|
+
const result = Array.from(list);
|
3653
|
+
result.splice(index, 1);
|
3654
|
+
return result;
|
3655
|
+
};
|
3656
|
+
|
3657
|
+
// lib/reduce-related-zones.ts
|
3658
|
+
init_react_import();
|
3659
|
+
|
3660
|
+
// lib/generate-id.ts
|
3661
|
+
init_react_import();
|
3662
|
+
var import_crypto = require("crypto");
|
3663
|
+
var generateId = (type) => `${type}-${(0, import_crypto.randomBytes)(20).toString("hex")}`;
|
3664
|
+
|
3665
|
+
// lib/reduce-related-zones.ts
|
3666
|
+
var reduceRelatedZones = (item, data, fn) => {
|
3667
|
+
return __spreadProps(__spreadValues({}, data), {
|
3668
|
+
zones: Object.keys(data.zones || {}).reduce(
|
3669
|
+
(acc, key) => {
|
3670
|
+
const [parentId] = getZoneId(key);
|
3671
|
+
if (parentId === item.props.id) {
|
3672
|
+
const zones = data.zones;
|
3673
|
+
return fn(acc, key, zones[key]);
|
3674
|
+
}
|
3675
|
+
return __spreadProps(__spreadValues({}, acc), { [key]: data.zones[key] });
|
3676
|
+
},
|
3677
|
+
{}
|
3678
|
+
)
|
3679
|
+
});
|
3680
|
+
};
|
3681
|
+
var findRelatedByZoneId = (zoneId, data) => {
|
3682
|
+
const [zoneParentId] = getZoneId(zoneId);
|
3683
|
+
return (data.zones[zoneId] || []).reduce((acc, zoneItem) => {
|
3684
|
+
const related = findRelatedByItem(zoneItem, data);
|
3685
|
+
if (zoneItem.props.id === zoneParentId) {
|
3686
|
+
return __spreadProps(__spreadValues(__spreadValues({}, acc), related), { [zoneId]: zoneItem });
|
3687
|
+
}
|
3688
|
+
return __spreadValues(__spreadValues({}, acc), related);
|
3689
|
+
}, {});
|
3690
|
+
};
|
3691
|
+
var findRelatedByItem = (item, data) => {
|
3692
|
+
return Object.keys(data.zones || {}).reduce((acc, zoneId) => {
|
3693
|
+
const [zoneParentId] = getZoneId(zoneId);
|
3694
|
+
if (item.props.id === zoneParentId) {
|
3695
|
+
const related = findRelatedByZoneId(zoneId, data);
|
3696
|
+
return __spreadProps(__spreadValues(__spreadValues({}, acc), related), {
|
3697
|
+
[zoneId]: data.zones[zoneId]
|
3698
|
+
});
|
3699
|
+
}
|
3700
|
+
return acc;
|
3701
|
+
}, {});
|
3702
|
+
};
|
3703
|
+
var removeRelatedZones = (item, data) => {
|
3704
|
+
const newData = __spreadValues({}, data);
|
3705
|
+
const related = findRelatedByItem(item, data);
|
3706
|
+
Object.keys(related).forEach((key) => {
|
3707
|
+
delete newData.zones[key];
|
3708
|
+
});
|
3709
|
+
return newData;
|
3710
|
+
};
|
3711
|
+
var duplicateRelatedZones = (item, data, newId) => {
|
3712
|
+
return reduceRelatedZones(item, data, (acc, key, zone) => {
|
3713
|
+
const dupedZone = zone.map((zoneItem) => __spreadProps(__spreadValues({}, zoneItem), {
|
3714
|
+
props: __spreadProps(__spreadValues({}, zoneItem.props), { id: generateId(zoneItem.type) })
|
3715
|
+
}));
|
3716
|
+
const dupeOfDupes = dupedZone.reduce(
|
3717
|
+
(dupeOfDupes2, item2, index) => __spreadValues(__spreadValues({}, dupeOfDupes2), duplicateRelatedZones(zone[index], data, item2.props.id).zones),
|
3718
|
+
acc
|
3719
|
+
);
|
3720
|
+
const [_, zoneId] = getZoneId(key);
|
3721
|
+
return __spreadProps(__spreadValues({}, dupeOfDupes), {
|
3722
|
+
[key]: zone,
|
3723
|
+
[`${newId}:${zoneId}`]: dupedZone
|
3724
|
+
});
|
3725
|
+
});
|
3726
|
+
};
|
3727
|
+
|
3728
|
+
// reducer/data.ts
|
3720
3729
|
var zoneCache = {};
|
3721
3730
|
var addToZoneCache = (key, data) => {
|
3722
3731
|
zoneCache[key] = data;
|
3723
3732
|
};
|
3724
|
-
var
|
3725
|
-
return (data, action) => {
|
3726
|
-
const newData = reducer(data, action);
|
3727
|
-
if (!["registerZone", "unregisterZone", "set"].includes(action.type)) {
|
3728
|
-
recordDiff(newData);
|
3729
|
-
}
|
3730
|
-
return newData;
|
3731
|
-
};
|
3732
|
-
};
|
3733
|
-
var createReducer = ({ config }) => storeInterceptor((data, action) => {
|
3733
|
+
var reduceData = (data, action, config) => {
|
3734
3734
|
if (action.type === "insert") {
|
3735
3735
|
const emptyComponentData = {
|
3736
3736
|
type: action.componentType,
|
@@ -3910,10 +3910,48 @@ var createReducer = ({ config }) => storeInterceptor((data, action) => {
|
|
3910
3910
|
}
|
3911
3911
|
return __spreadProps(__spreadValues({}, data), { zones: _zones });
|
3912
3912
|
}
|
3913
|
-
if (action.type === "
|
3913
|
+
if (action.type === "setData") {
|
3914
3914
|
return __spreadValues(__spreadValues({}, data), action.data);
|
3915
3915
|
}
|
3916
3916
|
return data;
|
3917
|
+
};
|
3918
|
+
|
3919
|
+
// reducer/state.ts
|
3920
|
+
init_react_import();
|
3921
|
+
var reduceState = (state, action) => {
|
3922
|
+
if (action.type === "setState") {
|
3923
|
+
return __spreadValues(__spreadValues({}, state), action.state);
|
3924
|
+
}
|
3925
|
+
return state;
|
3926
|
+
};
|
3927
|
+
|
3928
|
+
// reducer/actions.tsx
|
3929
|
+
init_react_import();
|
3930
|
+
|
3931
|
+
// reducer/index.ts
|
3932
|
+
var storeInterceptor = (reducer) => {
|
3933
|
+
return (appData, action) => {
|
3934
|
+
const newAppData = reducer(appData, action);
|
3935
|
+
const isValidType = ![
|
3936
|
+
"registerZone",
|
3937
|
+
"unregisterZone",
|
3938
|
+
"setData",
|
3939
|
+
"setState",
|
3940
|
+
"set"
|
3941
|
+
].includes(action.type);
|
3942
|
+
if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
|
3943
|
+
recordDiff(newAppData);
|
3944
|
+
}
|
3945
|
+
return newAppData;
|
3946
|
+
};
|
3947
|
+
};
|
3948
|
+
var createReducer = ({ config }) => storeInterceptor((appData, action) => {
|
3949
|
+
const data = reduceData(appData.data, action, config);
|
3950
|
+
const state = reduceState(appData.state, action);
|
3951
|
+
if (action.type === "set") {
|
3952
|
+
return __spreadValues(__spreadValues({}, appData), action.appData);
|
3953
|
+
}
|
3954
|
+
return { data, state };
|
3917
3955
|
});
|
3918
3956
|
|
3919
3957
|
// components/LayerTree/index.tsx
|
@@ -4084,17 +4122,19 @@ var areaContainsZones = (data, area) => {
|
|
4084
4122
|
|
4085
4123
|
// lib/flush-zones.ts
|
4086
4124
|
init_react_import();
|
4087
|
-
var flushZones = (
|
4088
|
-
const containsZones = typeof data.zones !== "undefined";
|
4125
|
+
var flushZones = (appData) => {
|
4126
|
+
const containsZones = typeof appData.data.zones !== "undefined";
|
4089
4127
|
if (containsZones) {
|
4090
|
-
Object.keys(data.zones || {}).forEach((zone) => {
|
4091
|
-
addToZoneCache(zone, data.zones[zone]);
|
4128
|
+
Object.keys(appData.data.zones || {}).forEach((zone) => {
|
4129
|
+
addToZoneCache(zone, appData.data.zones[zone]);
|
4092
4130
|
});
|
4093
|
-
return __spreadProps(__spreadValues({},
|
4094
|
-
|
4131
|
+
return __spreadProps(__spreadValues({}, appData), {
|
4132
|
+
data: __spreadProps(__spreadValues({}, appData.data), {
|
4133
|
+
zones: {}
|
4134
|
+
})
|
4095
4135
|
});
|
4096
4136
|
}
|
4097
|
-
return
|
4137
|
+
return appData;
|
4098
4138
|
};
|
4099
4139
|
|
4100
4140
|
// components/Puck/index.tsx
|
@@ -4126,15 +4166,29 @@ function Puck({
|
|
4126
4166
|
}) {
|
4127
4167
|
var _a, _b;
|
4128
4168
|
const [reducer] = (0, import_react28.useState)(() => createReducer({ config }));
|
4129
|
-
const
|
4169
|
+
const initialAppData = {
|
4170
|
+
data: initialData,
|
4171
|
+
state: { leftSideBarVisible: true, itemSelector: null }
|
4172
|
+
};
|
4173
|
+
const [appData, dispatch] = (0, import_react28.useReducer)(
|
4130
4174
|
reducer,
|
4131
|
-
flushZones(
|
4175
|
+
flushZones(initialAppData)
|
4132
4176
|
);
|
4177
|
+
const { data, state } = appData;
|
4133
4178
|
const { canForward, canRewind, rewind, forward } = usePuckHistory({
|
4134
|
-
|
4179
|
+
appData,
|
4135
4180
|
dispatch
|
4136
4181
|
});
|
4137
|
-
const
|
4182
|
+
const { itemSelector, leftSideBarVisible } = state;
|
4183
|
+
const setItemSelector = (0, import_react28.useCallback)(
|
4184
|
+
(newItemSelector) => {
|
4185
|
+
dispatch({
|
4186
|
+
type: "setState",
|
4187
|
+
state: { itemSelector: newItemSelector }
|
4188
|
+
});
|
4189
|
+
},
|
4190
|
+
[]
|
4191
|
+
);
|
4138
4192
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
4139
4193
|
const Page = (0, import_react28.useCallback)(
|
4140
4194
|
(pageProps) => {
|
@@ -4183,7 +4237,6 @@ function Puck({
|
|
4183
4237
|
onChange(data);
|
4184
4238
|
}, [data]);
|
4185
4239
|
const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
|
4186
|
-
const [leftSidebarVisible, setLeftSidebarVisible] = (0, import_react28.useState)(true);
|
4187
4240
|
const [draggedItem, setDraggedItem] = (0, import_react28.useState)();
|
4188
4241
|
return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "puck", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
4189
4242
|
import_react_beautiful_dnd4.DragDropContext,
|
@@ -4263,7 +4316,7 @@ function Puck({
|
|
4263
4316
|
style: {
|
4264
4317
|
display: "grid",
|
4265
4318
|
gridTemplateAreas: '"header header header" "left editor right"',
|
4266
|
-
gridTemplateColumns: `${
|
4319
|
+
gridTemplateColumns: `${leftSideBarVisible ? "288px" : "0px"} auto 288px`,
|
4267
4320
|
gridTemplateRows: "min-content auto",
|
4268
4321
|
height: "100vh",
|
4269
4322
|
position: "fixed",
|
@@ -4316,7 +4369,12 @@ function Puck({
|
|
4316
4369
|
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
4317
4370
|
IconButton,
|
4318
4371
|
{
|
4319
|
-
onClick: () =>
|
4372
|
+
onClick: () => dispatch({
|
4373
|
+
type: "setState",
|
4374
|
+
state: {
|
4375
|
+
leftSideBarVisible: !leftSideBarVisible
|
4376
|
+
}
|
4377
|
+
}),
|
4320
4378
|
title: "Toggle left sidebar",
|
4321
4379
|
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(sidebar_default, {})
|
4322
4380
|
}
|
@@ -4552,7 +4610,7 @@ function Puck({
|
|
4552
4610
|
});
|
4553
4611
|
} else {
|
4554
4612
|
dispatch({
|
4555
|
-
type: "
|
4613
|
+
type: "setData",
|
4556
4614
|
data: { root: newProps }
|
4557
4615
|
});
|
4558
4616
|
}
|