@measured/puck 0.17.0-canary.35170f8 → 0.17.0-canary.8959ff1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +90 -71
- package/dist/index.mjs +26 -7
- package/dist/{resolve-all-data-Ch-Pcasj.d.mts → resolve-all-data-C7aAQCY3.d.mts} +1 -0
- package/dist/{resolve-all-data-Ch-Pcasj.d.ts → resolve-all-data-C7aAQCY3.d.ts} +1 -0
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { F as FieldProps, a as Field, C as Config, D as Data, I as ItemSelector, P as PuckAction, b as DropZoneProps, U as UserGenerics, c as UiState, O as OnAction, d as Permissions, e as Plugin, f as Overrides, V as Viewports, g as IframeConfig, h as InitialHistory, i as DefaultComponentProps, j as DefaultRootFieldProps, H as History, A as AppState, E as ExtractPropsFromConfig, k as ExtractRootPropsFromConfig, l as ComponentDataMap } from './resolve-all-data-
|
2
|
-
export { L as Adaptor, J as ArrayField, r as ArrayState, a2 as AsFieldProps, B as BaseData, y as BaseField, t as ComponentConfig, w as ComponentData, x as Content, X as CustomField, $ as DefaultRootProps, _ as DefaultRootRenderProps, W as ExternalField, Q as ExternalFieldWithAdaptor, p as FieldRenderFunctions, Y as Fields, q as ItemWithId, M as MappedItem, N as NumberField, K as ObjectField, n as OverrideKey, s as PuckComponent, Z as PuckContext, G as RadioField, v as RootData, R as RootDataWithProps, u as RootDataWithoutProps, S as SelectField, T as TextField, z as TextareaField, m as Viewport, a3 as WithChildren, a0 as WithId, a1 as WithPuckProps, o as overrideKeys, a4 as resolveAllData } from './resolve-all-data-
|
1
|
+
import { F as FieldProps, a as Field, C as Config, D as Data, I as ItemSelector, P as PuckAction, b as DropZoneProps, U as UserGenerics, c as UiState, O as OnAction, d as Permissions, e as Plugin, f as Overrides, V as Viewports, g as IframeConfig, h as InitialHistory, i as DefaultComponentProps, j as DefaultRootFieldProps, H as History, A as AppState, E as ExtractPropsFromConfig, k as ExtractRootPropsFromConfig, l as ComponentDataMap } from './resolve-all-data-C7aAQCY3.mjs';
|
2
|
+
export { L as Adaptor, J as ArrayField, r as ArrayState, a2 as AsFieldProps, B as BaseData, y as BaseField, t as ComponentConfig, w as ComponentData, x as Content, X as CustomField, $ as DefaultRootProps, _ as DefaultRootRenderProps, W as ExternalField, Q as ExternalFieldWithAdaptor, p as FieldRenderFunctions, Y as Fields, q as ItemWithId, M as MappedItem, N as NumberField, K as ObjectField, n as OverrideKey, s as PuckComponent, Z as PuckContext, G as RadioField, v as RootData, R as RootDataWithProps, u as RootDataWithoutProps, S as SelectField, T as TextField, z as TextareaField, m as Viewport, a3 as WithChildren, a0 as WithId, a1 as WithPuckProps, o as overrideKeys, a4 as resolveAllData } from './resolve-all-data-C7aAQCY3.mjs';
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
4
4
|
import * as react from 'react';
|
5
5
|
import { ReactNode, SyntheticEvent, ReactElement, CSSProperties } from 'react';
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { F as FieldProps, a as Field, C as Config, D as Data, I as ItemSelector, P as PuckAction, b as DropZoneProps, U as UserGenerics, c as UiState, O as OnAction, d as Permissions, e as Plugin, f as Overrides, V as Viewports, g as IframeConfig, h as InitialHistory, i as DefaultComponentProps, j as DefaultRootFieldProps, H as History, A as AppState, E as ExtractPropsFromConfig, k as ExtractRootPropsFromConfig, l as ComponentDataMap } from './resolve-all-data-
|
2
|
-
export { L as Adaptor, J as ArrayField, r as ArrayState, a2 as AsFieldProps, B as BaseData, y as BaseField, t as ComponentConfig, w as ComponentData, x as Content, X as CustomField, $ as DefaultRootProps, _ as DefaultRootRenderProps, W as ExternalField, Q as ExternalFieldWithAdaptor, p as FieldRenderFunctions, Y as Fields, q as ItemWithId, M as MappedItem, N as NumberField, K as ObjectField, n as OverrideKey, s as PuckComponent, Z as PuckContext, G as RadioField, v as RootData, R as RootDataWithProps, u as RootDataWithoutProps, S as SelectField, T as TextField, z as TextareaField, m as Viewport, a3 as WithChildren, a0 as WithId, a1 as WithPuckProps, o as overrideKeys, a4 as resolveAllData } from './resolve-all-data-
|
1
|
+
import { F as FieldProps, a as Field, C as Config, D as Data, I as ItemSelector, P as PuckAction, b as DropZoneProps, U as UserGenerics, c as UiState, O as OnAction, d as Permissions, e as Plugin, f as Overrides, V as Viewports, g as IframeConfig, h as InitialHistory, i as DefaultComponentProps, j as DefaultRootFieldProps, H as History, A as AppState, E as ExtractPropsFromConfig, k as ExtractRootPropsFromConfig, l as ComponentDataMap } from './resolve-all-data-C7aAQCY3.js';
|
2
|
+
export { L as Adaptor, J as ArrayField, r as ArrayState, a2 as AsFieldProps, B as BaseData, y as BaseField, t as ComponentConfig, w as ComponentData, x as Content, X as CustomField, $ as DefaultRootProps, _ as DefaultRootRenderProps, W as ExternalField, Q as ExternalFieldWithAdaptor, p as FieldRenderFunctions, Y as Fields, q as ItemWithId, M as MappedItem, N as NumberField, K as ObjectField, n as OverrideKey, s as PuckComponent, Z as PuckContext, G as RadioField, v as RootData, R as RootDataWithProps, u as RootDataWithoutProps, S as SelectField, T as TextField, z as TextareaField, m as Viewport, a3 as WithChildren, a0 as WithId, a1 as WithPuckProps, o as overrideKeys, a4 as resolveAllData } from './resolve-all-data-C7aAQCY3.js';
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
4
4
|
import * as react from 'react';
|
5
5
|
import { ReactNode, SyntheticEvent, ReactElement, CSSProperties } from 'react';
|
package/dist/index.js
CHANGED
@@ -3128,7 +3128,7 @@ function DropZone(props) {
|
|
3128
3128
|
|
3129
3129
|
// components/Puck/index.tsx
|
3130
3130
|
init_react_import();
|
3131
|
-
var
|
3131
|
+
var import_react33 = require("react");
|
3132
3132
|
|
3133
3133
|
// lib/use-placeholder-style.ts
|
3134
3134
|
init_react_import();
|
@@ -3735,7 +3735,23 @@ init_react_import();
|
|
3735
3735
|
var styles_module_default16 = { "PuckFields": "_PuckFields_jp3lw_1", "PuckFields--isLoading": "_PuckFields--isLoading_jp3lw_6", "PuckFields-loadingOverlay": "_PuckFields-loadingOverlay_jp3lw_10", "PuckFields-loadingOverlayInner": "_PuckFields-loadingOverlayInner_jp3lw_25" };
|
3736
3736
|
|
3737
3737
|
// components/Puck/components/Fields/index.tsx
|
3738
|
+
var import_react22 = require("react");
|
3739
|
+
|
3740
|
+
// lib/use-parent.ts
|
3741
|
+
init_react_import();
|
3738
3742
|
var import_react21 = require("react");
|
3743
|
+
var useParent = (itemSelector) => {
|
3744
|
+
var _a;
|
3745
|
+
const { selectedItem, state } = useAppContext();
|
3746
|
+
const { pathData } = (0, import_react21.useContext)(dropZoneContext) || {};
|
3747
|
+
const item = itemSelector ? getItem(itemSelector, state.data) : selectedItem;
|
3748
|
+
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, state.data);
|
3749
|
+
const lastItem = breadcrumbs[breadcrumbs.length - 1];
|
3750
|
+
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector, state.data)) != null ? _a : null : null;
|
3751
|
+
return parent || null;
|
3752
|
+
};
|
3753
|
+
|
3754
|
+
// components/Puck/components/Fields/index.tsx
|
3739
3755
|
var import_jsx_runtime27 = require("react/jsx-runtime");
|
3740
3756
|
var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
|
3741
3757
|
var defaultPageFields = {
|
@@ -3749,23 +3765,24 @@ var DefaultFields = ({
|
|
3749
3765
|
var useResolvedFields = () => {
|
3750
3766
|
var _a, _b;
|
3751
3767
|
const { selectedItem, state, config } = useAppContext();
|
3768
|
+
const parent = useParent();
|
3752
3769
|
const { data } = state;
|
3753
3770
|
const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
|
3754
3771
|
const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
|
3755
|
-
const defaultFields = (0,
|
3772
|
+
const defaultFields = (0, import_react22.useMemo)(
|
3756
3773
|
() => (selectedItem ? componentConfig == null ? void 0 : componentConfig.fields : rootFields) || {},
|
3757
3774
|
[selectedItem, rootFields, componentConfig == null ? void 0 : componentConfig.fields]
|
3758
3775
|
);
|
3759
3776
|
const rootProps = data.root.props || data.root;
|
3760
|
-
const [lastSelectedData, setLastSelectedData] = (0,
|
3761
|
-
const [resolvedFields, setResolvedFields] = (0,
|
3762
|
-
const [fieldsLoading, setFieldsLoading] = (0,
|
3777
|
+
const [lastSelectedData, setLastSelectedData] = (0, import_react22.useState)({});
|
3778
|
+
const [resolvedFields, setResolvedFields] = (0, import_react22.useState)(defaultFields);
|
3779
|
+
const [fieldsLoading, setFieldsLoading] = (0, import_react22.useState)(false);
|
3763
3780
|
const defaultResolveFields = (_componentData, _params) => defaultFields;
|
3764
3781
|
const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
|
3765
3782
|
const hasComponentResolver = selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields);
|
3766
3783
|
const hasRootResolver = !selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields);
|
3767
3784
|
const hasResolver = hasComponentResolver || hasRootResolver;
|
3768
|
-
const resolveFields = (0,
|
3785
|
+
const resolveFields = (0, import_react22.useCallback)(
|
3769
3786
|
(..._0) => __async(void 0, [..._0], function* (fields = {}) {
|
3770
3787
|
var _a2;
|
3771
3788
|
const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
|
@@ -3779,7 +3796,8 @@ var useResolvedFields = () => {
|
|
3779
3796
|
fields,
|
3780
3797
|
lastFields: resolvedFields,
|
3781
3798
|
lastData,
|
3782
|
-
appState: state
|
3799
|
+
appState: state,
|
3800
|
+
parent
|
3783
3801
|
}
|
3784
3802
|
);
|
3785
3803
|
}
|
@@ -3789,7 +3807,8 @@ var useResolvedFields = () => {
|
|
3789
3807
|
fields,
|
3790
3808
|
lastFields: resolvedFields,
|
3791
3809
|
lastData,
|
3792
|
-
appState: state
|
3810
|
+
appState: state,
|
3811
|
+
parent
|
3793
3812
|
});
|
3794
3813
|
}
|
3795
3814
|
return defaultResolveFields(componentData, {
|
@@ -3801,7 +3820,7 @@ var useResolvedFields = () => {
|
|
3801
3820
|
}),
|
3802
3821
|
[data, config, componentData, selectedItem, resolvedFields, state]
|
3803
3822
|
);
|
3804
|
-
(0,
|
3823
|
+
(0, import_react22.useEffect)(() => {
|
3805
3824
|
if (hasResolver) {
|
3806
3825
|
setFieldsLoading(true);
|
3807
3826
|
resolveFields(defaultFields).then((fields) => {
|
@@ -3811,7 +3830,7 @@ var useResolvedFields = () => {
|
|
3811
3830
|
} else {
|
3812
3831
|
setResolvedFields(defaultFields);
|
3813
3832
|
}
|
3814
|
-
}, [data, defaultFields,
|
3833
|
+
}, [data, defaultFields, selectedItem, hasResolver]);
|
3815
3834
|
return [resolvedFields, fieldsLoading];
|
3816
3835
|
};
|
3817
3836
|
var Fields = () => {
|
@@ -3832,7 +3851,7 @@ var Fields = () => {
|
|
3832
3851
|
const componentResolving = selectedItem ? ((_a = componentState[selectedItem == null ? void 0 : selectedItem.props.id]) == null ? void 0 : _a.loadingCount) > 0 : ((_b = componentState["puck-root"]) == null ? void 0 : _b.loadingCount) > 0;
|
3833
3852
|
const isLoading = fieldsResolving || componentResolving;
|
3834
3853
|
const rootProps = data.root.props || data.root;
|
3835
|
-
const Wrapper = (0,
|
3854
|
+
const Wrapper = (0, import_react22.useMemo)(() => overrides.fields || DefaultFields, [overrides]);
|
3836
3855
|
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
|
3837
3856
|
"form",
|
3838
3857
|
{
|
@@ -3953,7 +3972,7 @@ init_react_import();
|
|
3953
3972
|
|
3954
3973
|
// lib/use-component-list.tsx
|
3955
3974
|
init_react_import();
|
3956
|
-
var
|
3975
|
+
var import_react23 = require("react");
|
3957
3976
|
|
3958
3977
|
// components/ComponentList/index.tsx
|
3959
3978
|
init_react_import();
|
@@ -4031,8 +4050,8 @@ ComponentList.Item = ComponentListItem;
|
|
4031
4050
|
// lib/use-component-list.tsx
|
4032
4051
|
var import_jsx_runtime29 = require("react/jsx-runtime");
|
4033
4052
|
var useComponentList = (config, ui) => {
|
4034
|
-
const [componentList, setComponentList] = (0,
|
4035
|
-
(0,
|
4053
|
+
const [componentList, setComponentList] = (0, import_react23.useState)();
|
4054
|
+
(0, import_react23.useEffect)(() => {
|
4036
4055
|
var _a, _b, _c;
|
4037
4056
|
if (Object.keys(ui.componentList).length > 0) {
|
4038
4057
|
const matchedComponents = [];
|
@@ -4101,22 +4120,22 @@ var useComponentList = (config, ui) => {
|
|
4101
4120
|
};
|
4102
4121
|
|
4103
4122
|
// components/Puck/components/Components/index.tsx
|
4104
|
-
var
|
4123
|
+
var import_react24 = require("react");
|
4105
4124
|
var import_jsx_runtime30 = require("react/jsx-runtime");
|
4106
4125
|
var Components = () => {
|
4107
4126
|
const { config, state, overrides } = useAppContext();
|
4108
4127
|
const componentList = useComponentList(config, state.ui);
|
4109
|
-
const Wrapper = (0,
|
4128
|
+
const Wrapper = (0, import_react24.useMemo)(() => overrides.components || "div", [overrides]);
|
4110
4129
|
return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(ComponentList, { id: "all" }) });
|
4111
4130
|
};
|
4112
4131
|
|
4113
4132
|
// components/Puck/components/Preview/index.tsx
|
4114
4133
|
init_react_import();
|
4115
|
-
var
|
4134
|
+
var import_react26 = require("react");
|
4116
4135
|
|
4117
4136
|
// components/AutoFrame/index.tsx
|
4118
4137
|
init_react_import();
|
4119
|
-
var
|
4138
|
+
var import_react25 = require("react");
|
4120
4139
|
var import_object_hash = __toESM(require("object-hash"));
|
4121
4140
|
var import_react_dom2 = require("react-dom");
|
4122
4141
|
var import_jsx_runtime31 = require("react/jsx-runtime");
|
@@ -4162,7 +4181,7 @@ var CopyHostStyles = ({
|
|
4162
4181
|
onStylesLoaded = () => null
|
4163
4182
|
}) => {
|
4164
4183
|
const { document: doc, window: win } = useFrame();
|
4165
|
-
(0,
|
4184
|
+
(0, import_react25.useEffect)(() => {
|
4166
4185
|
if (!win || !doc) {
|
4167
4186
|
return () => {
|
4168
4187
|
};
|
@@ -4321,8 +4340,8 @@ var CopyHostStyles = ({
|
|
4321
4340
|
}, []);
|
4322
4341
|
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_jsx_runtime31.Fragment, { children });
|
4323
4342
|
};
|
4324
|
-
var autoFrameContext = (0,
|
4325
|
-
var useFrame = () => (0,
|
4343
|
+
var autoFrameContext = (0, import_react25.createContext)({});
|
4344
|
+
var useFrame = () => (0, import_react25.useContext)(autoFrameContext);
|
4326
4345
|
function AutoFrame(_a) {
|
4327
4346
|
var _b = _a, {
|
4328
4347
|
children,
|
@@ -4337,11 +4356,11 @@ function AutoFrame(_a) {
|
|
4337
4356
|
"id",
|
4338
4357
|
"onStylesLoaded"
|
4339
4358
|
]);
|
4340
|
-
const [loaded, setLoaded] = (0,
|
4341
|
-
const [ctx, setCtx] = (0,
|
4342
|
-
const ref = (0,
|
4343
|
-
const [mountTarget, setMountTarget] = (0,
|
4344
|
-
(0,
|
4359
|
+
const [loaded, setLoaded] = (0, import_react25.useState)(false);
|
4360
|
+
const [ctx, setCtx] = (0, import_react25.useState)({});
|
4361
|
+
const ref = (0, import_react25.useRef)(null);
|
4362
|
+
const [mountTarget, setMountTarget] = (0, import_react25.useState)();
|
4363
|
+
(0, import_react25.useEffect)(() => {
|
4345
4364
|
var _a2;
|
4346
4365
|
if (ref.current) {
|
4347
4366
|
setCtx({
|
@@ -4377,7 +4396,7 @@ var import_jsx_runtime32 = require("react/jsx-runtime");
|
|
4377
4396
|
var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
|
4378
4397
|
var Preview = ({ id = "puck-preview" }) => {
|
4379
4398
|
const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
|
4380
|
-
const Page = (0,
|
4399
|
+
const Page = (0, import_react26.useCallback)(
|
4381
4400
|
(pageProps) => {
|
4382
4401
|
var _a, _b;
|
4383
4402
|
return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
|
@@ -4386,7 +4405,7 @@ var Preview = ({ id = "puck-preview" }) => {
|
|
4386
4405
|
},
|
4387
4406
|
[config.root]
|
4388
4407
|
);
|
4389
|
-
const Frame = (0,
|
4408
|
+
const Frame = (0, import_react26.useMemo)(() => overrides.iframe, [overrides]);
|
4390
4409
|
const rootProps = state.data.root.props || state.data.root;
|
4391
4410
|
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
|
4392
4411
|
"div",
|
@@ -4475,7 +4494,7 @@ var scrollIntoView = (el) => {
|
|
4475
4494
|
};
|
4476
4495
|
|
4477
4496
|
// components/LayerTree/index.tsx
|
4478
|
-
var
|
4497
|
+
var import_react27 = require("react");
|
4479
4498
|
|
4480
4499
|
// lib/is-child-of-zone.ts
|
4481
4500
|
init_react_import();
|
@@ -4502,7 +4521,7 @@ var LayerTree = ({
|
|
4502
4521
|
label
|
4503
4522
|
}) => {
|
4504
4523
|
const zones = data.zones || {};
|
4505
|
-
const ctx = (0,
|
4524
|
+
const ctx = (0, import_react27.useContext)(dropZoneContext);
|
4506
4525
|
return /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(import_jsx_runtime33.Fragment, { children: [
|
4507
4526
|
label && /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)("div", { className: getClassName24("zoneTitle"), children: [
|
4508
4527
|
/* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(Layers, { size: "16" }) }),
|
@@ -4608,13 +4627,13 @@ var LayerTree = ({
|
|
4608
4627
|
};
|
4609
4628
|
|
4610
4629
|
// components/Puck/components/Outline/index.tsx
|
4611
|
-
var
|
4630
|
+
var import_react28 = require("react");
|
4612
4631
|
var import_jsx_runtime34 = require("react/jsx-runtime");
|
4613
4632
|
var Outline = () => {
|
4614
4633
|
const { dispatch, state, overrides, config } = useAppContext();
|
4615
4634
|
const { data, ui } = state;
|
4616
4635
|
const { itemSelector } = ui;
|
4617
|
-
const setItemSelector = (0,
|
4636
|
+
const setItemSelector = (0, import_react28.useCallback)(
|
4618
4637
|
(newItemSelector) => {
|
4619
4638
|
dispatch({
|
4620
4639
|
type: "setUi",
|
@@ -4623,7 +4642,7 @@ var Outline = () => {
|
|
4623
4642
|
},
|
4624
4643
|
[]
|
4625
4644
|
);
|
4626
|
-
const Wrapper = (0,
|
4645
|
+
const Wrapper = (0, import_react28.useMemo)(() => overrides.outline || "div", [overrides]);
|
4627
4646
|
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Wrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(dropZoneContext.Consumer, { children: (ctx) => /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
|
4628
4647
|
(ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
4629
4648
|
LayerTree,
|
@@ -4712,19 +4731,19 @@ function usePuckHistory({
|
|
4712
4731
|
|
4713
4732
|
// lib/use-history-store.ts
|
4714
4733
|
init_react_import();
|
4715
|
-
var
|
4734
|
+
var import_react29 = require("react");
|
4716
4735
|
var import_use_debounce3 = require("use-debounce");
|
4717
4736
|
var EMPTY_HISTORY_INDEX = 0;
|
4718
4737
|
function useHistoryStore(initialHistory) {
|
4719
4738
|
var _a, _b;
|
4720
|
-
const [histories, setHistories] = (0,
|
4739
|
+
const [histories, setHistories] = (0, import_react29.useState)(
|
4721
4740
|
(_a = initialHistory == null ? void 0 : initialHistory.histories) != null ? _a : []
|
4722
4741
|
);
|
4723
4742
|
const updateHistories = (histories2) => {
|
4724
4743
|
setHistories(histories2);
|
4725
4744
|
setIndex(histories2.length - 1);
|
4726
4745
|
};
|
4727
|
-
const [index, setIndex] = (0,
|
4746
|
+
const [index, setIndex] = (0, import_react29.useState)(
|
4728
4747
|
(_b = initialHistory == null ? void 0 : initialHistory.index) != null ? _b : EMPTY_HISTORY_INDEX
|
4729
4748
|
);
|
4730
4749
|
const hasPast = index > EMPTY_HISTORY_INDEX;
|
@@ -4884,11 +4903,11 @@ var getBox = function getBox2(el) {
|
|
4884
4903
|
};
|
4885
4904
|
|
4886
4905
|
// components/Puck/components/Canvas/index.tsx
|
4887
|
-
var
|
4906
|
+
var import_react31 = require("react");
|
4888
4907
|
|
4889
4908
|
// components/ViewportControls/index.tsx
|
4890
4909
|
init_react_import();
|
4891
|
-
var
|
4910
|
+
var import_react30 = require("react");
|
4892
4911
|
|
4893
4912
|
// css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
|
4894
4913
|
init_react_import();
|
@@ -4911,8 +4930,8 @@ var ViewportButton = ({
|
|
4911
4930
|
onClick
|
4912
4931
|
}) => {
|
4913
4932
|
const { state } = useAppContext();
|
4914
|
-
const [isActive, setIsActive] = (0,
|
4915
|
-
(0,
|
4933
|
+
const [isActive, setIsActive] = (0, import_react30.useState)(false);
|
4934
|
+
(0, import_react30.useEffect)(() => {
|
4916
4935
|
setIsActive(width === state.ui.viewports.current.width);
|
4917
4936
|
}, [width, state.ui.viewports.current.width]);
|
4918
4937
|
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
|
@@ -4948,7 +4967,7 @@ var ViewportControls = ({
|
|
4948
4967
|
const defaultsContainAutoZoom = defaultZoomOptions.find(
|
4949
4968
|
(option) => option.value === autoZoom
|
4950
4969
|
);
|
4951
|
-
const zoomOptions = (0,
|
4970
|
+
const zoomOptions = (0, import_react30.useMemo)(
|
4952
4971
|
() => [
|
4953
4972
|
...defaultZoomOptions,
|
4954
4973
|
...defaultsContainAutoZoom ? [] : [
|
@@ -5071,17 +5090,17 @@ var Canvas = () => {
|
|
5071
5090
|
const { status, iframe } = useAppContext();
|
5072
5091
|
const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
|
5073
5092
|
const { ui } = state;
|
5074
|
-
const frameRef = (0,
|
5075
|
-
const [showTransition, setShowTransition] = (0,
|
5076
|
-
const defaultRender = (0,
|
5093
|
+
const frameRef = (0, import_react31.useRef)(null);
|
5094
|
+
const [showTransition, setShowTransition] = (0, import_react31.useState)(false);
|
5095
|
+
const defaultRender = (0, import_react31.useMemo)(() => {
|
5077
5096
|
const PuckDefault = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(import_jsx_runtime36.Fragment, { children });
|
5078
5097
|
return PuckDefault;
|
5079
5098
|
}, []);
|
5080
|
-
const CustomPreview = (0,
|
5099
|
+
const CustomPreview = (0, import_react31.useMemo)(
|
5081
5100
|
() => overrides.preview || defaultRender,
|
5082
5101
|
[overrides]
|
5083
5102
|
);
|
5084
|
-
const getFrameDimensions = (0,
|
5103
|
+
const getFrameDimensions = (0, import_react31.useCallback)(() => {
|
5085
5104
|
if (frameRef.current) {
|
5086
5105
|
const frame = frameRef.current;
|
5087
5106
|
const box = getBox(frame);
|
@@ -5089,7 +5108,7 @@ var Canvas = () => {
|
|
5089
5108
|
}
|
5090
5109
|
return { width: 0, height: 0 };
|
5091
5110
|
}, [frameRef]);
|
5092
|
-
const resetAutoZoom = (0,
|
5111
|
+
const resetAutoZoom = (0, import_react31.useCallback)(
|
5093
5112
|
(ui2 = state.ui) => {
|
5094
5113
|
if (frameRef.current) {
|
5095
5114
|
setZoomConfig(
|
@@ -5099,11 +5118,11 @@ var Canvas = () => {
|
|
5099
5118
|
},
|
5100
5119
|
[frameRef, zoomConfig, state.ui]
|
5101
5120
|
);
|
5102
|
-
(0,
|
5121
|
+
(0, import_react31.useEffect)(() => {
|
5103
5122
|
setShowTransition(false);
|
5104
5123
|
resetAutoZoom();
|
5105
5124
|
}, [frameRef, ui.leftSideBarVisible, ui.rightSideBarVisible]);
|
5106
|
-
(0,
|
5125
|
+
(0, import_react31.useEffect)(() => {
|
5107
5126
|
const { height: frameHeight } = getFrameDimensions();
|
5108
5127
|
if (ui.viewports.current.height === "auto") {
|
5109
5128
|
setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
|
@@ -5111,13 +5130,13 @@ var Canvas = () => {
|
|
5111
5130
|
}));
|
5112
5131
|
}
|
5113
5132
|
}, [zoomConfig.zoom]);
|
5114
|
-
(0,
|
5133
|
+
(0, import_react31.useEffect)(() => {
|
5115
5134
|
if (ZOOM_ON_CHANGE) {
|
5116
5135
|
setShowTransition(true);
|
5117
5136
|
resetAutoZoom(ui);
|
5118
5137
|
}
|
5119
5138
|
}, [ui.viewports.current.width]);
|
5120
|
-
(0,
|
5139
|
+
(0, import_react31.useEffect)(() => {
|
5121
5140
|
const observer = new ResizeObserver(() => {
|
5122
5141
|
setShowTransition(false);
|
5123
5142
|
resetAutoZoom();
|
@@ -5129,8 +5148,8 @@ var Canvas = () => {
|
|
5129
5148
|
observer.disconnect();
|
5130
5149
|
};
|
5131
5150
|
}, []);
|
5132
|
-
const [showLoader, setShowLoader] = (0,
|
5133
|
-
(0,
|
5151
|
+
const [showLoader, setShowLoader] = (0, import_react31.useState)(false);
|
5152
|
+
(0, import_react31.useEffect)(() => {
|
5134
5153
|
setTimeout(() => {
|
5135
5154
|
setShowLoader(true);
|
5136
5155
|
}, 500);
|
@@ -5233,7 +5252,7 @@ var insertComponent = (componentType, zone, index, {
|
|
5233
5252
|
|
5234
5253
|
// lib/use-loaded-overrides.ts
|
5235
5254
|
init_react_import();
|
5236
|
-
var
|
5255
|
+
var import_react32 = require("react");
|
5237
5256
|
|
5238
5257
|
// lib/load-overrides.ts
|
5239
5258
|
init_react_import();
|
@@ -5272,7 +5291,7 @@ var useLoadedOverrides = ({
|
|
5272
5291
|
overrides,
|
5273
5292
|
plugins
|
5274
5293
|
}) => {
|
5275
|
-
return (0,
|
5294
|
+
return (0, import_react32.useMemo)(() => {
|
5276
5295
|
return loadOverrides({ overrides, plugins });
|
5277
5296
|
}, [plugins, overrides]);
|
5278
5297
|
};
|
@@ -5311,7 +5330,7 @@ function Puck({
|
|
5311
5330
|
enabled: true,
|
5312
5331
|
waitForStyles: true
|
5313
5332
|
}, _iframe);
|
5314
|
-
const [generatedAppState] = (0,
|
5333
|
+
const [generatedAppState] = (0, import_react33.useState)(() => {
|
5315
5334
|
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
5316
5335
|
const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
|
5317
5336
|
let clientUiState = {};
|
@@ -5383,22 +5402,22 @@ function Puck({
|
|
5383
5402
|
histories,
|
5384
5403
|
index: initialHistoryIndex
|
5385
5404
|
});
|
5386
|
-
const [reducer] = (0,
|
5405
|
+
const [reducer] = (0, import_react33.useState)(
|
5387
5406
|
() => createReducer({
|
5388
5407
|
config,
|
5389
5408
|
record: historyStore.record,
|
5390
5409
|
onAction
|
5391
5410
|
})
|
5392
5411
|
);
|
5393
|
-
const [appState, dispatch] = (0,
|
5412
|
+
const [appState, dispatch] = (0, import_react33.useReducer)(
|
5394
5413
|
reducer,
|
5395
5414
|
flushZones(initialAppState)
|
5396
5415
|
);
|
5397
5416
|
const { data, ui } = appState;
|
5398
5417
|
const history = usePuckHistory({ dispatch, initialAppState, historyStore });
|
5399
|
-
const [menuOpen, setMenuOpen] = (0,
|
5418
|
+
const [menuOpen, setMenuOpen] = (0, import_react33.useState)(false);
|
5400
5419
|
const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
|
5401
|
-
const setItemSelector = (0,
|
5420
|
+
const setItemSelector = (0, import_react33.useCallback)(
|
5402
5421
|
(newItemSelector) => {
|
5403
5422
|
if (newItemSelector === itemSelector) return;
|
5404
5423
|
dispatch({
|
@@ -5410,13 +5429,13 @@ function Puck({
|
|
5410
5429
|
[itemSelector]
|
5411
5430
|
);
|
5412
5431
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
5413
|
-
(0,
|
5432
|
+
(0, import_react33.useEffect)(() => {
|
5414
5433
|
if (onChange) onChange(data);
|
5415
5434
|
}, [data]);
|
5416
5435
|
const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
|
5417
|
-
const [draggedItem, setDraggedItem] = (0,
|
5436
|
+
const [draggedItem, setDraggedItem] = (0, import_react33.useState)();
|
5418
5437
|
const rootProps = data.root.props || data.root;
|
5419
|
-
const toggleSidebars = (0,
|
5438
|
+
const toggleSidebars = (0, import_react33.useCallback)(
|
5420
5439
|
(sidebar) => {
|
5421
5440
|
const widerViewport = window.matchMedia("(min-width: 638px)").matches;
|
5422
5441
|
const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
|
@@ -5430,7 +5449,7 @@ function Puck({
|
|
5430
5449
|
},
|
5431
5450
|
[dispatch, leftSideBarVisible, rightSideBarVisible]
|
5432
5451
|
);
|
5433
|
-
(0,
|
5452
|
+
(0, import_react33.useEffect)(() => {
|
5434
5453
|
if (!window.matchMedia("(min-width: 638px)").matches) {
|
5435
5454
|
dispatch({
|
5436
5455
|
type: "setUi",
|
@@ -5453,7 +5472,7 @@ function Puck({
|
|
5453
5472
|
window.removeEventListener("resize", handleResize);
|
5454
5473
|
};
|
5455
5474
|
}, []);
|
5456
|
-
const defaultHeaderRender = (0,
|
5475
|
+
const defaultHeaderRender = (0, import_react33.useMemo)(() => {
|
5457
5476
|
if (renderHeader) {
|
5458
5477
|
console.warn(
|
5459
5478
|
"`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
|
@@ -5467,7 +5486,7 @@ function Puck({
|
|
5467
5486
|
}
|
5468
5487
|
return DefaultOverride;
|
5469
5488
|
}, [renderHeader]);
|
5470
|
-
const defaultHeaderActionsRender = (0,
|
5489
|
+
const defaultHeaderActionsRender = (0, import_react33.useMemo)(() => {
|
5471
5490
|
if (renderHeaderActions) {
|
5472
5491
|
console.warn(
|
5473
5492
|
"`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
|
@@ -5484,20 +5503,20 @@ function Puck({
|
|
5484
5503
|
overrides,
|
5485
5504
|
plugins
|
5486
5505
|
});
|
5487
|
-
const CustomPuck = (0,
|
5506
|
+
const CustomPuck = (0, import_react33.useMemo)(
|
5488
5507
|
() => loadedOverrides.puck || DefaultOverride,
|
5489
5508
|
[loadedOverrides]
|
5490
5509
|
);
|
5491
|
-
const CustomHeader = (0,
|
5510
|
+
const CustomHeader = (0, import_react33.useMemo)(
|
5492
5511
|
() => loadedOverrides.header || defaultHeaderRender,
|
5493
5512
|
[loadedOverrides]
|
5494
5513
|
);
|
5495
|
-
const CustomHeaderActions = (0,
|
5514
|
+
const CustomHeaderActions = (0, import_react33.useMemo)(
|
5496
5515
|
() => loadedOverrides.headerActions || defaultHeaderActionsRender,
|
5497
5516
|
[loadedOverrides]
|
5498
5517
|
);
|
5499
|
-
const [mounted, setMounted] = (0,
|
5500
|
-
(0,
|
5518
|
+
const [mounted, setMounted] = (0, import_react33.useState)(false);
|
5519
|
+
(0, import_react33.useEffect)(() => {
|
5501
5520
|
setMounted(true);
|
5502
5521
|
}, []);
|
5503
5522
|
const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
|
package/dist/index.mjs
CHANGED
@@ -3572,6 +3572,22 @@ var styles_module_default16 = { "PuckFields": "_PuckFields_jp3lw_1", "PuckFields
|
|
3572
3572
|
|
3573
3573
|
// components/Puck/components/Fields/index.tsx
|
3574
3574
|
import { useCallback as useCallback7, useEffect as useEffect13, useMemo as useMemo6, useState as useState15 } from "react";
|
3575
|
+
|
3576
|
+
// lib/use-parent.ts
|
3577
|
+
init_react_import();
|
3578
|
+
import { useContext as useContext5 } from "react";
|
3579
|
+
var useParent = (itemSelector) => {
|
3580
|
+
var _a;
|
3581
|
+
const { selectedItem, state } = useAppContext();
|
3582
|
+
const { pathData } = useContext5(dropZoneContext) || {};
|
3583
|
+
const item = itemSelector ? getItem(itemSelector, state.data) : selectedItem;
|
3584
|
+
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, state.data);
|
3585
|
+
const lastItem = breadcrumbs[breadcrumbs.length - 1];
|
3586
|
+
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector, state.data)) != null ? _a : null : null;
|
3587
|
+
return parent || null;
|
3588
|
+
};
|
3589
|
+
|
3590
|
+
// components/Puck/components/Fields/index.tsx
|
3575
3591
|
import { Fragment as Fragment12, jsx as jsx27, jsxs as jsxs15 } from "react/jsx-runtime";
|
3576
3592
|
var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
|
3577
3593
|
var defaultPageFields = {
|
@@ -3585,6 +3601,7 @@ var DefaultFields = ({
|
|
3585
3601
|
var useResolvedFields = () => {
|
3586
3602
|
var _a, _b;
|
3587
3603
|
const { selectedItem, state, config } = useAppContext();
|
3604
|
+
const parent = useParent();
|
3588
3605
|
const { data } = state;
|
3589
3606
|
const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
|
3590
3607
|
const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
|
@@ -3615,7 +3632,8 @@ var useResolvedFields = () => {
|
|
3615
3632
|
fields,
|
3616
3633
|
lastFields: resolvedFields,
|
3617
3634
|
lastData,
|
3618
|
-
appState: state
|
3635
|
+
appState: state,
|
3636
|
+
parent
|
3619
3637
|
}
|
3620
3638
|
);
|
3621
3639
|
}
|
@@ -3625,7 +3643,8 @@ var useResolvedFields = () => {
|
|
3625
3643
|
fields,
|
3626
3644
|
lastFields: resolvedFields,
|
3627
3645
|
lastData,
|
3628
|
-
appState: state
|
3646
|
+
appState: state,
|
3647
|
+
parent
|
3629
3648
|
});
|
3630
3649
|
}
|
3631
3650
|
return defaultResolveFields(componentData, {
|
@@ -3647,7 +3666,7 @@ var useResolvedFields = () => {
|
|
3647
3666
|
} else {
|
3648
3667
|
setResolvedFields(defaultFields);
|
3649
3668
|
}
|
3650
|
-
}, [data, defaultFields,
|
3669
|
+
}, [data, defaultFields, selectedItem, hasResolver]);
|
3651
3670
|
return [resolvedFields, fieldsLoading];
|
3652
3671
|
};
|
3653
3672
|
var Fields = () => {
|
@@ -3954,7 +3973,7 @@ import { useCallback as useCallback8, useMemo as useMemo8 } from "react";
|
|
3954
3973
|
init_react_import();
|
3955
3974
|
import {
|
3956
3975
|
createContext as createContext4,
|
3957
|
-
useContext as
|
3976
|
+
useContext as useContext6,
|
3958
3977
|
useEffect as useEffect15,
|
3959
3978
|
useRef as useRef3,
|
3960
3979
|
useState as useState17
|
@@ -4164,7 +4183,7 @@ var CopyHostStyles = ({
|
|
4164
4183
|
return /* @__PURE__ */ jsx31(Fragment13, { children });
|
4165
4184
|
};
|
4166
4185
|
var autoFrameContext = createContext4({});
|
4167
|
-
var useFrame = () =>
|
4186
|
+
var useFrame = () => useContext6(autoFrameContext);
|
4168
4187
|
function AutoFrame(_a) {
|
4169
4188
|
var _b = _a, {
|
4170
4189
|
children,
|
@@ -4317,7 +4336,7 @@ var scrollIntoView = (el) => {
|
|
4317
4336
|
};
|
4318
4337
|
|
4319
4338
|
// components/LayerTree/index.tsx
|
4320
|
-
import { useContext as
|
4339
|
+
import { useContext as useContext7 } from "react";
|
4321
4340
|
|
4322
4341
|
// lib/is-child-of-zone.ts
|
4323
4342
|
init_react_import();
|
@@ -4344,7 +4363,7 @@ var LayerTree = ({
|
|
4344
4363
|
label
|
4345
4364
|
}) => {
|
4346
4365
|
const zones = data.zones || {};
|
4347
|
-
const ctx =
|
4366
|
+
const ctx = useContext7(dropZoneContext);
|
4348
4367
|
return /* @__PURE__ */ jsxs17(Fragment15, { children: [
|
4349
4368
|
label && /* @__PURE__ */ jsxs17("div", { className: getClassName24("zoneTitle"), children: [
|
4350
4369
|
/* @__PURE__ */ jsx33("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ jsx33(Layers, { size: "16" }) }),
|
@@ -145,6 +145,7 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
145
145
|
lastFields: Fields<FieldProps>;
|
146
146
|
lastData: DataShape | null;
|
147
147
|
appState: AppState;
|
148
|
+
parent: ComponentData | null;
|
148
149
|
}) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
|
149
150
|
resolveData?: (data: DataShape, params: {
|
150
151
|
changed: Partial<Record<keyof FieldProps, boolean>>;
|
@@ -145,6 +145,7 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
|
|
145
145
|
lastFields: Fields<FieldProps>;
|
146
146
|
lastData: DataShape | null;
|
147
147
|
appState: AppState;
|
148
|
+
parent: ComponentData | null;
|
148
149
|
}) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
|
149
150
|
resolveData?: (data: DataShape, params: {
|
150
151
|
changed: Partial<Record<keyof FieldProps, boolean>>;
|
package/dist/rsc.d.mts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
|
-
import { C as Config, D as Data } from './resolve-all-data-
|
3
|
-
export { a4 as resolveAllData } from './resolve-all-data-
|
2
|
+
import { C as Config, D as Data } from './resolve-all-data-C7aAQCY3.mjs';
|
3
|
+
export { a4 as resolveAllData } from './resolve-all-data-C7aAQCY3.mjs';
|
4
4
|
import 'react';
|
5
5
|
|
6
6
|
declare function Render<UserConfig extends Config = Config>({ config, data, }: {
|
package/dist/rsc.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
|
-
import { C as Config, D as Data } from './resolve-all-data-
|
3
|
-
export { a4 as resolveAllData } from './resolve-all-data-
|
2
|
+
import { C as Config, D as Data } from './resolve-all-data-C7aAQCY3.js';
|
3
|
+
export { a4 as resolveAllData } from './resolve-all-data-C7aAQCY3.js';
|
4
4
|
import 'react';
|
5
5
|
|
6
6
|
declare function Render<UserConfig extends Config = Config>({ config, data, }: {
|
package/package.json
CHANGED