@measured/puck 0.10.0-canary.2a12826 → 0.10.0-canary.6a9145c
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 +3 -3
- package/dist/index.js +104 -44
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -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, AppData, AppState, ArrayState, Button, ComponentConfig, Config, Content, Data, DefaultComponentProps, DefaultRootProps, DropZone, DropZoneProvider, Field, FieldLabel, Fields, IconButton, ItemWithId, Puck, Render, dropZoneContext };
|
|
295
|
+
export { Adaptor, AppData, AppState, ArrayState, Button, ComponentConfig, Config, Content, Data, DefaultComponentProps, DefaultRootProps, DropZone, DropZoneProvider, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, 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
|
|
@@ -3189,8 +3189,10 @@ var appContext = (0, import_react24.createContext)({
|
|
|
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
3193
|
return __spreadProps(__spreadValues({}, mainContext), {
|
|
3193
|
-
//
|
|
3194
|
+
// Helpers
|
|
3195
|
+
selectedItem,
|
|
3194
3196
|
setState: (state, recordHistory) => {
|
|
3195
3197
|
return mainContext.dispatch({
|
|
3196
3198
|
type: "setState",
|
|
@@ -3852,6 +3854,72 @@ var Heading = ({ children, rank, size = "m" }) => {
|
|
|
3852
3854
|
);
|
|
3853
3855
|
};
|
|
3854
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
|
+
appData: { 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
|
+
|
|
3855
3923
|
// components/SidebarSection/index.tsx
|
|
3856
3924
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
|
3857
3925
|
var getClassName16 = get_class_name_factory_default("SidebarSection", styles_module_default8);
|
|
@@ -3859,23 +3927,24 @@ var SidebarSection = ({
|
|
|
3859
3927
|
children,
|
|
3860
3928
|
title,
|
|
3861
3929
|
background,
|
|
3862
|
-
|
|
3863
|
-
breadcrumbClick,
|
|
3930
|
+
showBreadcrumbs,
|
|
3864
3931
|
noPadding
|
|
3865
3932
|
}) => {
|
|
3933
|
+
const { setState } = useAppContext();
|
|
3934
|
+
const breadcrumbs = useBreadcrumbs(1);
|
|
3866
3935
|
return /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: getClassName16({ noPadding }), style: { background }, children: [
|
|
3867
3936
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: getClassName16("title"), children: /* @__PURE__ */ (0, import_jsx_runtime19.jsxs)("div", { className: getClassName16("breadcrumbs"), children: [
|
|
3868
|
-
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: [
|
|
3869
3938
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
3870
3939
|
"div",
|
|
3871
3940
|
{
|
|
3872
3941
|
className: getClassName16("breadcrumbLabel"),
|
|
3873
|
-
onClick: () =>
|
|
3942
|
+
onClick: () => setState({ itemSelector: breadcrumb.selector }),
|
|
3874
3943
|
children: breadcrumb.label
|
|
3875
3944
|
}
|
|
3876
3945
|
),
|
|
3877
3946
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(chevron_right_default, { size: 16 })
|
|
3878
|
-
] }, i)),
|
|
3947
|
+
] }, i)) : null,
|
|
3879
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 }) })
|
|
3880
3949
|
] }) }),
|
|
3881
3950
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)("div", { className: getClassName16("content"), children })
|
|
@@ -3887,15 +3956,15 @@ init_react_import();
|
|
|
3887
3956
|
|
|
3888
3957
|
// lib/use-puck-history.ts
|
|
3889
3958
|
init_react_import();
|
|
3890
|
-
var
|
|
3959
|
+
var import_react30 = require("react");
|
|
3891
3960
|
|
|
3892
3961
|
// lib/use-action-history.ts
|
|
3893
3962
|
init_react_import();
|
|
3894
|
-
var
|
|
3963
|
+
var import_react29 = require("react");
|
|
3895
3964
|
var EMPTY_HISTORY_INDEX = -1;
|
|
3896
3965
|
function useActionHistory() {
|
|
3897
|
-
const [histories, setHistories] = (0,
|
|
3898
|
-
const [currentHistoryIndex, setCurrentHistoryIndex] = (0,
|
|
3966
|
+
const [histories, setHistories] = (0, import_react29.useState)([]);
|
|
3967
|
+
const [currentHistoryIndex, setCurrentHistoryIndex] = (0, import_react29.useState)(EMPTY_HISTORY_INDEX);
|
|
3899
3968
|
const currentHistory = histories[currentHistoryIndex];
|
|
3900
3969
|
const canRewind = currentHistoryIndex > EMPTY_HISTORY_INDEX;
|
|
3901
3970
|
const canForward = currentHistoryIndex < histories.length - 1;
|
|
@@ -3967,7 +4036,7 @@ function usePuckHistory({
|
|
|
3967
4036
|
dispatch
|
|
3968
4037
|
});
|
|
3969
4038
|
}, DEBOUNCE_TIME);
|
|
3970
|
-
(0,
|
|
4039
|
+
(0, import_react30.useEffect)(() => {
|
|
3971
4040
|
historyEmitter.on(RECORD_DIFF, handleRecordDiff);
|
|
3972
4041
|
return () => {
|
|
3973
4042
|
historyEmitter.off(RECORD_DIFF, handleRecordDiff);
|
|
@@ -4312,7 +4381,7 @@ var scrollIntoView = (el) => {
|
|
|
4312
4381
|
};
|
|
4313
4382
|
|
|
4314
4383
|
// components/LayerTree/index.tsx
|
|
4315
|
-
var
|
|
4384
|
+
var import_react31 = require("react");
|
|
4316
4385
|
|
|
4317
4386
|
// lib/find-zones-for-area.ts
|
|
4318
4387
|
init_react_import();
|
|
@@ -4331,12 +4400,9 @@ init_react_import();
|
|
|
4331
4400
|
var isChildOfZone = (item, maybeChild, ctx) => {
|
|
4332
4401
|
var _a;
|
|
4333
4402
|
const { data, pathData = {} } = ctx || {};
|
|
4334
|
-
return maybeChild && data ? !!((_a = pathData[maybeChild.props.id]) == null ? void 0 : _a.find((
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
return (pathItem == null ? void 0 : pathItem.props.id) === item.props.id;
|
|
4338
|
-
}
|
|
4339
|
-
return false;
|
|
4403
|
+
return maybeChild && data ? !!((_a = pathData[maybeChild.props.id]) == null ? void 0 : _a.path.find((zoneCompound) => {
|
|
4404
|
+
const [area] = getZoneId(zoneCompound);
|
|
4405
|
+
return area === item.props.id;
|
|
4340
4406
|
})) : false;
|
|
4341
4407
|
};
|
|
4342
4408
|
|
|
@@ -4353,7 +4419,7 @@ var LayerTree = ({
|
|
|
4353
4419
|
label
|
|
4354
4420
|
}) => {
|
|
4355
4421
|
const zones = data.zones || {};
|
|
4356
|
-
const ctx = (0,
|
|
4422
|
+
const ctx = (0, import_react31.useContext)(dropZoneContext);
|
|
4357
4423
|
return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)(import_jsx_runtime20.Fragment, { children: [
|
|
4358
4424
|
label && /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: getClassName17("zoneTitle"), children: [
|
|
4359
4425
|
/* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName17("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(layers_default, { size: "16" }) }),
|
|
@@ -4504,7 +4570,7 @@ function Puck({
|
|
|
4504
4570
|
headerPath
|
|
4505
4571
|
}) {
|
|
4506
4572
|
var _a, _b;
|
|
4507
|
-
const [reducer] = (0,
|
|
4573
|
+
const [reducer] = (0, import_react32.useState)(() => createReducer({ config }));
|
|
4508
4574
|
const initialAppData = {
|
|
4509
4575
|
data: initialData,
|
|
4510
4576
|
state: {
|
|
@@ -4512,7 +4578,7 @@ function Puck({
|
|
|
4512
4578
|
arrayState: {}
|
|
4513
4579
|
}
|
|
4514
4580
|
};
|
|
4515
|
-
const [appData, dispatch] = (0,
|
|
4581
|
+
const [appData, dispatch] = (0, import_react32.useReducer)(
|
|
4516
4582
|
reducer,
|
|
4517
4583
|
flushZones(initialAppData)
|
|
4518
4584
|
);
|
|
@@ -4522,7 +4588,7 @@ function Puck({
|
|
|
4522
4588
|
dispatch
|
|
4523
4589
|
});
|
|
4524
4590
|
const { itemSelector, leftSideBarVisible } = state;
|
|
4525
|
-
const setItemSelector = (0,
|
|
4591
|
+
const setItemSelector = (0, import_react32.useCallback)(
|
|
4526
4592
|
(newItemSelector) => {
|
|
4527
4593
|
dispatch({
|
|
4528
4594
|
type: "setState",
|
|
@@ -4532,7 +4598,7 @@ function Puck({
|
|
|
4532
4598
|
[]
|
|
4533
4599
|
);
|
|
4534
4600
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
|
4535
|
-
const Page = (0,
|
|
4601
|
+
const Page = (0, import_react32.useCallback)(
|
|
4536
4602
|
(pageProps) => {
|
|
4537
4603
|
var _a2, _b2;
|
|
4538
4604
|
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
@@ -4547,7 +4613,7 @@ function Puck({
|
|
|
4547
4613
|
},
|
|
4548
4614
|
[config.root]
|
|
4549
4615
|
);
|
|
4550
|
-
const PageFieldWrapper = (0,
|
|
4616
|
+
const PageFieldWrapper = (0, import_react32.useCallback)(
|
|
4551
4617
|
(props) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
4552
4618
|
PluginRenderer,
|
|
4553
4619
|
{
|
|
@@ -4559,7 +4625,7 @@ function Puck({
|
|
|
4559
4625
|
),
|
|
4560
4626
|
[]
|
|
4561
4627
|
);
|
|
4562
|
-
const ComponentFieldWrapper = (0,
|
|
4628
|
+
const ComponentFieldWrapper = (0, import_react32.useCallback)(
|
|
4563
4629
|
(props) => /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(
|
|
4564
4630
|
PluginRenderer,
|
|
4565
4631
|
{
|
|
@@ -4574,12 +4640,12 @@ function Puck({
|
|
|
4574
4640
|
const FieldWrapper = itemSelector ? ComponentFieldWrapper : PageFieldWrapper;
|
|
4575
4641
|
const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
|
|
4576
4642
|
let fields = selectedItem ? ((_b = config.components[selectedItem.type]) == null ? void 0 : _b.fields) || {} : rootFields;
|
|
4577
|
-
(0,
|
|
4643
|
+
(0, import_react32.useEffect)(() => {
|
|
4578
4644
|
if (onChange)
|
|
4579
4645
|
onChange(data);
|
|
4580
4646
|
}, [data]);
|
|
4581
4647
|
const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
|
|
4582
|
-
const [draggedItem, setDraggedItem] = (0,
|
|
4648
|
+
const [draggedItem, setDraggedItem] = (0, import_react32.useState)();
|
|
4583
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)(
|
|
4584
4650
|
import_react_beautiful_dnd5.DragDropContext,
|
|
4585
4651
|
{
|
|
@@ -4647,11 +4713,6 @@ function Puck({
|
|
|
4647
4713
|
areaId: "root"
|
|
4648
4714
|
},
|
|
4649
4715
|
children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(dropZoneContext.Consumer, { children: (ctx) => {
|
|
4650
|
-
let path = (ctx == null ? void 0 : ctx.pathData) && selectedItem ? ctx == null ? void 0 : ctx.pathData[selectedItem == null ? void 0 : selectedItem.props.id] : void 0;
|
|
4651
|
-
if (path) {
|
|
4652
|
-
path = [{ label: "Page", selector: null }, ...path];
|
|
4653
|
-
path = path.slice(path.length - 2, path.length - 1);
|
|
4654
|
-
}
|
|
4655
4716
|
return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(
|
|
4656
4717
|
"div",
|
|
4657
4718
|
{
|
|
@@ -4909,8 +4970,7 @@ function Puck({
|
|
|
4909
4970
|
SidebarSection,
|
|
4910
4971
|
{
|
|
4911
4972
|
noPadding: true,
|
|
4912
|
-
|
|
4913
|
-
breadcrumbClick: (breadcrumb) => setItemSelector(breadcrumb.selector),
|
|
4973
|
+
showBreadcrumbs: true,
|
|
4914
4974
|
title: selectedItem ? selectedItem.type : "Page",
|
|
4915
4975
|
children: Object.keys(fields).map((fieldName) => {
|
|
4916
4976
|
var _a2, _b2, _c, _d;
|