@measured/puck 0.17.4-canary.e414e34 → 0.17.4-canary.e778246
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +3 -3
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +193 -121
- package/dist/index.mjs +176 -104
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
@@ -1551,12 +1551,13 @@ var DefaultField = ({
|
|
1551
1551
|
field,
|
1552
1552
|
onChange,
|
1553
1553
|
readOnly,
|
1554
|
-
value,
|
1554
|
+
value: _value,
|
1555
1555
|
name,
|
1556
1556
|
label,
|
1557
1557
|
Label,
|
1558
1558
|
id
|
1559
1559
|
}) => {
|
1560
|
+
const value = _value;
|
1560
1561
|
return /* @__PURE__ */ jsx11(
|
1561
1562
|
Label,
|
1562
1563
|
{
|
@@ -1574,7 +1575,7 @@ var DefaultField = ({
|
|
1574
1575
|
type: field.type,
|
1575
1576
|
title: label || name,
|
1576
1577
|
name,
|
1577
|
-
value:
|
1578
|
+
value: (value == null ? void 0 : value.toString) ? value.toString() : "",
|
1578
1579
|
onChange: (e) => {
|
1579
1580
|
if (field.type === "number") {
|
1580
1581
|
const numberValue = Number(e.currentTarget.value);
|
@@ -1689,29 +1690,57 @@ import { useEffect as useEffect6, useState as useState7 } from "react";
|
|
1689
1690
|
init_react_import();
|
1690
1691
|
var Button_module_default = { "Button": "_Button_1t64k_1", "Button--medium": "_Button--medium_1t64k_29", "Button--large": "_Button--large_1t64k_37", "Button-icon": "_Button-icon_1t64k_44", "Button--primary": "_Button--primary_1t64k_48", "Button--secondary": "_Button--secondary_1t64k_67", "Button--flush": "_Button--flush_1t64k_84", "Button--disabled": "_Button--disabled_1t64k_88", "Button--fullWidth": "_Button--fullWidth_1t64k_95", "Button-spinner": "_Button-spinner_1t64k_100" };
|
1691
1692
|
|
1693
|
+
// lib/filter-data-attrs.ts
|
1694
|
+
init_react_import();
|
1695
|
+
var dataAttrRe = /^(data-.*)$/;
|
1696
|
+
var filterDataAttrs = (props) => {
|
1697
|
+
let filteredProps = {};
|
1698
|
+
for (const prop in props) {
|
1699
|
+
if (Object.prototype.hasOwnProperty.call(props, prop) && dataAttrRe.test(prop)) {
|
1700
|
+
filteredProps[prop] = props[prop];
|
1701
|
+
}
|
1702
|
+
}
|
1703
|
+
return filteredProps;
|
1704
|
+
};
|
1705
|
+
|
1692
1706
|
// components/Button/Button.tsx
|
1693
1707
|
import { jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
|
1694
1708
|
var getClassName9 = get_class_name_factory_default("Button", Button_module_default);
|
1695
|
-
var Button = ({
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
+
var Button = (_a) => {
|
1710
|
+
var _b = _a, {
|
1711
|
+
children,
|
1712
|
+
href,
|
1713
|
+
onClick,
|
1714
|
+
variant = "primary",
|
1715
|
+
type,
|
1716
|
+
disabled,
|
1717
|
+
tabIndex,
|
1718
|
+
newTab,
|
1719
|
+
fullWidth,
|
1720
|
+
icon,
|
1721
|
+
size = "medium",
|
1722
|
+
loading: loadingProp = false
|
1723
|
+
} = _b, props = __objRest(_b, [
|
1724
|
+
"children",
|
1725
|
+
"href",
|
1726
|
+
"onClick",
|
1727
|
+
"variant",
|
1728
|
+
"type",
|
1729
|
+
"disabled",
|
1730
|
+
"tabIndex",
|
1731
|
+
"newTab",
|
1732
|
+
"fullWidth",
|
1733
|
+
"icon",
|
1734
|
+
"size",
|
1735
|
+
"loading"
|
1736
|
+
]);
|
1709
1737
|
const [loading, setLoading] = useState7(loadingProp);
|
1710
1738
|
useEffect6(() => setLoading(loadingProp), [loadingProp]);
|
1711
1739
|
const ElementType = href ? "a" : type ? "button" : "span";
|
1740
|
+
const dataAttrs = filterDataAttrs(props);
|
1712
1741
|
const el = /* @__PURE__ */ jsxs6(
|
1713
1742
|
ElementType,
|
1714
|
-
{
|
1743
|
+
__spreadProps(__spreadValues({
|
1715
1744
|
className: getClassName9({
|
1716
1745
|
primary: variant === "primary",
|
1717
1746
|
secondary: variant === "secondary",
|
@@ -1731,13 +1760,14 @@ var Button = ({
|
|
1731
1760
|
tabIndex,
|
1732
1761
|
target: newTab ? "_blank" : void 0,
|
1733
1762
|
rel: newTab ? "noreferrer" : void 0,
|
1734
|
-
href
|
1763
|
+
href
|
1764
|
+
}, dataAttrs), {
|
1735
1765
|
children: [
|
1736
1766
|
icon && /* @__PURE__ */ jsx14("div", { className: getClassName9("icon"), children: icon }),
|
1737
1767
|
children,
|
1738
1768
|
loading && /* @__PURE__ */ jsx14("div", { className: getClassName9("spinner"), children: /* @__PURE__ */ jsx14(Loader, { size: 14 }) })
|
1739
1769
|
]
|
1740
|
-
}
|
1770
|
+
})
|
1741
1771
|
);
|
1742
1772
|
return el;
|
1743
1773
|
};
|
@@ -3150,9 +3180,9 @@ function DropZone(props) {
|
|
3150
3180
|
// components/Puck/index.tsx
|
3151
3181
|
init_react_import();
|
3152
3182
|
import {
|
3153
|
-
useCallback as
|
3154
|
-
useEffect as
|
3155
|
-
useMemo as
|
3183
|
+
useCallback as useCallback12,
|
3184
|
+
useEffect as useEffect19,
|
3185
|
+
useMemo as useMemo17,
|
3156
3186
|
useReducer,
|
3157
3187
|
useState as useState21
|
3158
3188
|
} from "react";
|
@@ -3766,33 +3796,58 @@ init_react_import();
|
|
3766
3796
|
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" };
|
3767
3797
|
|
3768
3798
|
// components/Puck/components/Fields/index.tsx
|
3769
|
-
import {
|
3799
|
+
import { useMemo as useMemo10 } from "react";
|
3800
|
+
|
3801
|
+
// lib/use-resolved-fields.ts
|
3802
|
+
init_react_import();
|
3803
|
+
import { useCallback as useCallback8, useEffect as useEffect14, useMemo as useMemo9, useRef as useRef3, useState as useState15 } from "react";
|
3770
3804
|
|
3771
3805
|
// lib/use-parent.ts
|
3772
3806
|
init_react_import();
|
3773
|
-
import { useContext as useContext7 } from "react";
|
3774
|
-
var
|
3807
|
+
import { useCallback as useCallback7, useContext as useContext7 } from "react";
|
3808
|
+
var getParent = (itemSelector, pathData, data) => {
|
3775
3809
|
var _a;
|
3776
|
-
|
3777
|
-
const
|
3778
|
-
const
|
3779
|
-
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, state.data);
|
3810
|
+
if (!itemSelector) return null;
|
3811
|
+
const item = getItem(itemSelector, data);
|
3812
|
+
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, data);
|
3780
3813
|
const lastItem = breadcrumbs[breadcrumbs.length - 1];
|
3781
|
-
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector,
|
3814
|
+
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector, data)) != null ? _a : null : null;
|
3782
3815
|
return parent || null;
|
3783
3816
|
};
|
3817
|
+
var useGetParent = () => {
|
3818
|
+
const { state } = useAppContext();
|
3819
|
+
const { pathData } = useContext7(dropZoneContext) || {};
|
3820
|
+
return useCallback7(
|
3821
|
+
() => getParent(state.ui.itemSelector, pathData, state.data),
|
3822
|
+
[state.ui.itemSelector, pathData, state.data]
|
3823
|
+
);
|
3824
|
+
};
|
3825
|
+
var useParent = () => {
|
3826
|
+
return useGetParent()();
|
3827
|
+
};
|
3784
3828
|
|
3785
|
-
//
|
3786
|
-
|
3787
|
-
|
3829
|
+
// lib/use-on-value-change.ts
|
3830
|
+
init_react_import();
|
3831
|
+
import { useRef as useRef2, useEffect as useEffect13 } from "react";
|
3832
|
+
function useOnValueChange(value, onChange, compare = Object.is, deps = []) {
|
3833
|
+
const tracked = useRef2(value);
|
3834
|
+
useEffect13(() => {
|
3835
|
+
const oldValue = tracked.current;
|
3836
|
+
if (!compare(value, oldValue)) {
|
3837
|
+
tracked.current = value;
|
3838
|
+
onChange(value, oldValue);
|
3839
|
+
}
|
3840
|
+
}, [onChange, compare, value, ...deps]);
|
3841
|
+
}
|
3842
|
+
|
3843
|
+
// lib/selector-is.ts
|
3844
|
+
init_react_import();
|
3845
|
+
var selectorIs = (a, b) => (a == null ? void 0 : a.zone) === (b == null ? void 0 : b.zone) && (a == null ? void 0 : a.index) === (b == null ? void 0 : b.index);
|
3846
|
+
|
3847
|
+
// lib/use-resolved-fields.ts
|
3788
3848
|
var defaultPageFields = {
|
3789
3849
|
title: { type: "text" }
|
3790
3850
|
};
|
3791
|
-
var DefaultFields = ({
|
3792
|
-
children
|
3793
|
-
}) => {
|
3794
|
-
return /* @__PURE__ */ jsx28(Fragment12, { children });
|
3795
|
-
};
|
3796
3851
|
var useResolvedFields = () => {
|
3797
3852
|
var _a, _b;
|
3798
3853
|
const { selectedItem, state, config } = useAppContext();
|
@@ -3808,12 +3863,13 @@ var useResolvedFields = () => {
|
|
3808
3863
|
const [lastSelectedData, setLastSelectedData] = useState15({});
|
3809
3864
|
const [resolvedFields, setResolvedFields] = useState15(defaultFields);
|
3810
3865
|
const [fieldsLoading, setFieldsLoading] = useState15(false);
|
3866
|
+
const lastFields = useRef3(defaultFields);
|
3811
3867
|
const defaultResolveFields = (_componentData, _params) => defaultFields;
|
3812
3868
|
const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
|
3813
3869
|
const hasComponentResolver = selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields);
|
3814
3870
|
const hasRootResolver = !selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields);
|
3815
3871
|
const hasResolver = hasComponentResolver || hasRootResolver;
|
3816
|
-
const resolveFields =
|
3872
|
+
const resolveFields = useCallback8(
|
3817
3873
|
(..._0) => __async(void 0, [..._0], function* (fields = {}) {
|
3818
3874
|
var _a2;
|
3819
3875
|
const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
|
@@ -3825,7 +3881,7 @@ var useResolvedFields = () => {
|
|
3825
3881
|
{
|
3826
3882
|
changed,
|
3827
3883
|
fields,
|
3828
|
-
lastFields:
|
3884
|
+
lastFields: lastFields.current,
|
3829
3885
|
lastData,
|
3830
3886
|
appState: state,
|
3831
3887
|
parent
|
@@ -3836,7 +3892,7 @@ var useResolvedFields = () => {
|
|
3836
3892
|
return yield config.root.resolveFields(componentData, {
|
3837
3893
|
changed,
|
3838
3894
|
fields,
|
3839
|
-
lastFields:
|
3895
|
+
lastFields: lastFields.current,
|
3840
3896
|
lastData,
|
3841
3897
|
appState: state,
|
3842
3898
|
parent
|
@@ -3845,40 +3901,56 @@ var useResolvedFields = () => {
|
|
3845
3901
|
return defaultResolveFields(componentData, {
|
3846
3902
|
changed,
|
3847
3903
|
fields,
|
3848
|
-
lastFields:
|
3904
|
+
lastFields: lastFields.current,
|
3849
3905
|
lastData
|
3850
3906
|
});
|
3851
3907
|
}),
|
3852
|
-
[data, config, componentData, selectedItem,
|
3908
|
+
[data, config, componentData, selectedItem, state, parent]
|
3853
3909
|
);
|
3854
|
-
const
|
3855
|
-
useEffect13(() => {
|
3856
|
-
setHasParent(!!parent);
|
3857
|
-
}, [parent]);
|
3858
|
-
useEffect13(() => {
|
3910
|
+
const triggerResolver = useCallback8(() => {
|
3859
3911
|
var _a2, _b2;
|
3860
|
-
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" ||
|
3912
|
+
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" || parent) {
|
3861
3913
|
if (hasResolver) {
|
3862
3914
|
setFieldsLoading(true);
|
3863
3915
|
resolveFields(defaultFields).then((fields) => {
|
3864
3916
|
setResolvedFields(fields || {});
|
3917
|
+
lastFields.current = fields;
|
3865
3918
|
setFieldsLoading(false);
|
3866
3919
|
});
|
3867
|
-
|
3868
|
-
setResolvedFields(defaultFields);
|
3920
|
+
return;
|
3869
3921
|
}
|
3870
3922
|
}
|
3871
|
-
|
3872
|
-
|
3873
|
-
|
3923
|
+
setResolvedFields(defaultFields);
|
3924
|
+
}, [defaultFields, state.ui.itemSelector, hasResolver, parent]);
|
3925
|
+
useOnValueChange(
|
3874
3926
|
state.ui.itemSelector,
|
3875
|
-
|
3876
|
-
|
3877
|
-
|
3878
|
-
|
3927
|
+
() => {
|
3928
|
+
lastFields.current = defaultFields;
|
3929
|
+
},
|
3930
|
+
selectorIs
|
3931
|
+
);
|
3932
|
+
useOnValueChange(
|
3933
|
+
{ data, parent, itemSelector: state.ui.itemSelector },
|
3934
|
+
() => {
|
3935
|
+
triggerResolver();
|
3936
|
+
},
|
3937
|
+
(a, b) => JSON.stringify(a) === JSON.stringify(b)
|
3938
|
+
);
|
3939
|
+
useEffect14(() => {
|
3940
|
+
triggerResolver();
|
3941
|
+
}, []);
|
3879
3942
|
return [resolvedFields, fieldsLoading];
|
3880
3943
|
};
|
3881
|
-
|
3944
|
+
|
3945
|
+
// components/Puck/components/Fields/index.tsx
|
3946
|
+
import { Fragment as Fragment12, jsx as jsx28, jsxs as jsxs15 } from "react/jsx-runtime";
|
3947
|
+
var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
|
3948
|
+
var DefaultFields = ({
|
3949
|
+
children
|
3950
|
+
}) => {
|
3951
|
+
return /* @__PURE__ */ jsx28(Fragment12, { children });
|
3952
|
+
};
|
3953
|
+
var Fields = ({ wrapFields = true }) => {
|
3882
3954
|
var _a, _b;
|
3883
3955
|
const {
|
3884
3956
|
selectedItem,
|
@@ -3896,7 +3968,7 @@ var Fields = () => {
|
|
3896
3968
|
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;
|
3897
3969
|
const isLoading = fieldsResolving || componentResolving;
|
3898
3970
|
const rootProps = data.root.props || data.root;
|
3899
|
-
const Wrapper =
|
3971
|
+
const Wrapper = useMemo10(() => overrides.fields || DefaultFields, [overrides]);
|
3900
3972
|
return /* @__PURE__ */ jsxs15(
|
3901
3973
|
"form",
|
3902
3974
|
{
|
@@ -4019,7 +4091,7 @@ init_react_import();
|
|
4019
4091
|
|
4020
4092
|
// lib/use-component-list.tsx
|
4021
4093
|
init_react_import();
|
4022
|
-
import { useEffect as
|
4094
|
+
import { useEffect as useEffect15, useState as useState16 } from "react";
|
4023
4095
|
|
4024
4096
|
// components/ComponentList/index.tsx
|
4025
4097
|
init_react_import();
|
@@ -4098,7 +4170,7 @@ ComponentList.Item = ComponentListItem;
|
|
4098
4170
|
import { jsx as jsx30 } from "react/jsx-runtime";
|
4099
4171
|
var useComponentList = (config, ui) => {
|
4100
4172
|
const [componentList, setComponentList] = useState16();
|
4101
|
-
|
4173
|
+
useEffect15(() => {
|
4102
4174
|
var _a, _b, _c;
|
4103
4175
|
if (Object.keys(ui.componentList).length > 0) {
|
4104
4176
|
const matchedComponents = [];
|
@@ -4167,26 +4239,26 @@ var useComponentList = (config, ui) => {
|
|
4167
4239
|
};
|
4168
4240
|
|
4169
4241
|
// components/Puck/components/Components/index.tsx
|
4170
|
-
import { useMemo as
|
4242
|
+
import { useMemo as useMemo11 } from "react";
|
4171
4243
|
import { jsx as jsx31 } from "react/jsx-runtime";
|
4172
4244
|
var Components = () => {
|
4173
4245
|
const { config, state, overrides } = useAppContext();
|
4174
4246
|
const componentList = useComponentList(config, state.ui);
|
4175
|
-
const Wrapper =
|
4247
|
+
const Wrapper = useMemo11(() => overrides.components || "div", [overrides]);
|
4176
4248
|
return /* @__PURE__ */ jsx31(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ jsx31(ComponentList, { id: "all" }) });
|
4177
4249
|
};
|
4178
4250
|
|
4179
4251
|
// components/Puck/components/Preview/index.tsx
|
4180
4252
|
init_react_import();
|
4181
|
-
import { useCallback as
|
4253
|
+
import { useCallback as useCallback9, useMemo as useMemo12 } from "react";
|
4182
4254
|
|
4183
4255
|
// components/AutoFrame/index.tsx
|
4184
4256
|
init_react_import();
|
4185
4257
|
import {
|
4186
4258
|
createContext as createContext5,
|
4187
4259
|
useContext as useContext8,
|
4188
|
-
useEffect as
|
4189
|
-
useRef as
|
4260
|
+
useEffect as useEffect16,
|
4261
|
+
useRef as useRef4,
|
4190
4262
|
useState as useState17
|
4191
4263
|
} from "react";
|
4192
4264
|
import hash from "object-hash";
|
@@ -4234,7 +4306,7 @@ var CopyHostStyles = ({
|
|
4234
4306
|
onStylesLoaded = () => null
|
4235
4307
|
}) => {
|
4236
4308
|
const { document: doc, window: win } = useFrame();
|
4237
|
-
|
4309
|
+
useEffect16(() => {
|
4238
4310
|
if (!win || !doc) {
|
4239
4311
|
return () => {
|
4240
4312
|
};
|
@@ -4411,9 +4483,9 @@ function AutoFrame(_a) {
|
|
4411
4483
|
]);
|
4412
4484
|
const [loaded, setLoaded] = useState17(false);
|
4413
4485
|
const [ctx, setCtx] = useState17({});
|
4414
|
-
const ref =
|
4486
|
+
const ref = useRef4(null);
|
4415
4487
|
const [mountTarget, setMountTarget] = useState17();
|
4416
|
-
|
4488
|
+
useEffect16(() => {
|
4417
4489
|
var _a2;
|
4418
4490
|
if (ref.current) {
|
4419
4491
|
setCtx({
|
@@ -4449,7 +4521,7 @@ import { Fragment as Fragment14, jsx as jsx33 } from "react/jsx-runtime";
|
|
4449
4521
|
var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
|
4450
4522
|
var Preview = ({ id = "puck-preview" }) => {
|
4451
4523
|
const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
|
4452
|
-
const Page =
|
4524
|
+
const Page = useCallback9(
|
4453
4525
|
(pageProps) => {
|
4454
4526
|
var _a, _b;
|
4455
4527
|
return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
|
@@ -4458,7 +4530,7 @@ var Preview = ({ id = "puck-preview" }) => {
|
|
4458
4530
|
},
|
4459
4531
|
[config.root]
|
4460
4532
|
);
|
4461
|
-
const Frame =
|
4533
|
+
const Frame = useMemo12(() => overrides.iframe, [overrides]);
|
4462
4534
|
const rootProps = state.data.root.props || state.data.root;
|
4463
4535
|
return /* @__PURE__ */ jsx33(
|
4464
4536
|
"div",
|
@@ -4680,13 +4752,13 @@ var LayerTree = ({
|
|
4680
4752
|
};
|
4681
4753
|
|
4682
4754
|
// components/Puck/components/Outline/index.tsx
|
4683
|
-
import { useCallback as
|
4755
|
+
import { useCallback as useCallback10, useMemo as useMemo13 } from "react";
|
4684
4756
|
import { Fragment as Fragment16, jsx as jsx35, jsxs as jsxs18 } from "react/jsx-runtime";
|
4685
4757
|
var Outline = () => {
|
4686
4758
|
const { dispatch, state, overrides, config } = useAppContext();
|
4687
4759
|
const { data, ui } = state;
|
4688
4760
|
const { itemSelector } = ui;
|
4689
|
-
const setItemSelector =
|
4761
|
+
const setItemSelector = useCallback10(
|
4690
4762
|
(newItemSelector) => {
|
4691
4763
|
dispatch({
|
4692
4764
|
type: "setUi",
|
@@ -4695,7 +4767,7 @@ var Outline = () => {
|
|
4695
4767
|
},
|
4696
4768
|
[]
|
4697
4769
|
);
|
4698
|
-
const Wrapper =
|
4770
|
+
const Wrapper = useMemo13(() => overrides.outline || "div", [overrides]);
|
4699
4771
|
return /* @__PURE__ */ jsx35(Wrapper, { children: /* @__PURE__ */ jsx35(dropZoneContext.Consumer, { children: (ctx) => /* @__PURE__ */ jsxs18(Fragment16, { children: [
|
4700
4772
|
(ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ jsx35(
|
4701
4773
|
LayerTree,
|
@@ -4982,16 +5054,16 @@ var getBox = function getBox2(el) {
|
|
4982
5054
|
|
4983
5055
|
// components/Puck/components/Canvas/index.tsx
|
4984
5056
|
import {
|
4985
|
-
useCallback as
|
4986
|
-
useEffect as
|
4987
|
-
useMemo as
|
4988
|
-
useRef as
|
5057
|
+
useCallback as useCallback11,
|
5058
|
+
useEffect as useEffect18,
|
5059
|
+
useMemo as useMemo15,
|
5060
|
+
useRef as useRef5,
|
4989
5061
|
useState as useState20
|
4990
5062
|
} from "react";
|
4991
5063
|
|
4992
5064
|
// components/ViewportControls/index.tsx
|
4993
5065
|
init_react_import();
|
4994
|
-
import { useEffect as
|
5066
|
+
import { useEffect as useEffect17, useMemo as useMemo14, useState as useState19 } from "react";
|
4995
5067
|
|
4996
5068
|
// css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
|
4997
5069
|
init_react_import();
|
@@ -5015,7 +5087,7 @@ var ViewportButton = ({
|
|
5015
5087
|
}) => {
|
5016
5088
|
const { state } = useAppContext();
|
5017
5089
|
const [isActive, setIsActive] = useState19(false);
|
5018
|
-
|
5090
|
+
useEffect17(() => {
|
5019
5091
|
setIsActive(width === state.ui.viewports.current.width);
|
5020
5092
|
}, [width, state.ui.viewports.current.width]);
|
5021
5093
|
return /* @__PURE__ */ jsx36("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ jsx36(
|
@@ -5051,7 +5123,7 @@ var ViewportControls = ({
|
|
5051
5123
|
const defaultsContainAutoZoom = defaultZoomOptions.find(
|
5052
5124
|
(option) => option.value === autoZoom
|
5053
5125
|
);
|
5054
|
-
const zoomOptions =
|
5126
|
+
const zoomOptions = useMemo14(
|
5055
5127
|
() => [
|
5056
5128
|
...defaultZoomOptions,
|
5057
5129
|
...defaultsContainAutoZoom ? [] : [
|
@@ -5174,17 +5246,17 @@ var Canvas = () => {
|
|
5174
5246
|
const { status, iframe } = useAppContext();
|
5175
5247
|
const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
|
5176
5248
|
const { ui } = state;
|
5177
|
-
const frameRef =
|
5249
|
+
const frameRef = useRef5(null);
|
5178
5250
|
const [showTransition, setShowTransition] = useState20(false);
|
5179
|
-
const defaultRender =
|
5251
|
+
const defaultRender = useMemo15(() => {
|
5180
5252
|
const PuckDefault = ({ children }) => /* @__PURE__ */ jsx37(Fragment17, { children });
|
5181
5253
|
return PuckDefault;
|
5182
5254
|
}, []);
|
5183
|
-
const CustomPreview =
|
5255
|
+
const CustomPreview = useMemo15(
|
5184
5256
|
() => overrides.preview || defaultRender,
|
5185
5257
|
[overrides]
|
5186
5258
|
);
|
5187
|
-
const getFrameDimensions =
|
5259
|
+
const getFrameDimensions = useCallback11(() => {
|
5188
5260
|
if (frameRef.current) {
|
5189
5261
|
const frame = frameRef.current;
|
5190
5262
|
const box = getBox(frame);
|
@@ -5192,7 +5264,7 @@ var Canvas = () => {
|
|
5192
5264
|
}
|
5193
5265
|
return { width: 0, height: 0 };
|
5194
5266
|
}, [frameRef]);
|
5195
|
-
const resetAutoZoom =
|
5267
|
+
const resetAutoZoom = useCallback11(
|
5196
5268
|
(ui2 = state.ui) => {
|
5197
5269
|
if (frameRef.current) {
|
5198
5270
|
setZoomConfig(
|
@@ -5202,11 +5274,11 @@ var Canvas = () => {
|
|
5202
5274
|
},
|
5203
5275
|
[frameRef, zoomConfig, state.ui]
|
5204
5276
|
);
|
5205
|
-
|
5277
|
+
useEffect18(() => {
|
5206
5278
|
setShowTransition(false);
|
5207
5279
|
resetAutoZoom();
|
5208
5280
|
}, [frameRef, ui.leftSideBarVisible, ui.rightSideBarVisible]);
|
5209
|
-
|
5281
|
+
useEffect18(() => {
|
5210
5282
|
const { height: frameHeight } = getFrameDimensions();
|
5211
5283
|
if (ui.viewports.current.height === "auto") {
|
5212
5284
|
setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
|
@@ -5214,13 +5286,13 @@ var Canvas = () => {
|
|
5214
5286
|
}));
|
5215
5287
|
}
|
5216
5288
|
}, [zoomConfig.zoom]);
|
5217
|
-
|
5289
|
+
useEffect18(() => {
|
5218
5290
|
if (ZOOM_ON_CHANGE) {
|
5219
5291
|
setShowTransition(true);
|
5220
5292
|
resetAutoZoom(ui);
|
5221
5293
|
}
|
5222
5294
|
}, [ui.viewports.current.width]);
|
5223
|
-
|
5295
|
+
useEffect18(() => {
|
5224
5296
|
const observer = new ResizeObserver(() => {
|
5225
5297
|
setShowTransition(false);
|
5226
5298
|
resetAutoZoom();
|
@@ -5233,7 +5305,7 @@ var Canvas = () => {
|
|
5233
5305
|
};
|
5234
5306
|
}, []);
|
5235
5307
|
const [showLoader, setShowLoader] = useState20(false);
|
5236
|
-
|
5308
|
+
useEffect18(() => {
|
5237
5309
|
setTimeout(() => {
|
5238
5310
|
setShowLoader(true);
|
5239
5311
|
}, 500);
|
@@ -5336,7 +5408,7 @@ var insertComponent = (componentType, zone, index, {
|
|
5336
5408
|
|
5337
5409
|
// lib/use-loaded-overrides.ts
|
5338
5410
|
init_react_import();
|
5339
|
-
import { useMemo as
|
5411
|
+
import { useMemo as useMemo16 } from "react";
|
5340
5412
|
|
5341
5413
|
// lib/load-overrides.ts
|
5342
5414
|
init_react_import();
|
@@ -5375,7 +5447,7 @@ var useLoadedOverrides = ({
|
|
5375
5447
|
overrides,
|
5376
5448
|
plugins
|
5377
5449
|
}) => {
|
5378
|
-
return
|
5450
|
+
return useMemo16(() => {
|
5379
5451
|
return loadOverrides({ overrides, plugins });
|
5380
5452
|
}, [plugins, overrides]);
|
5381
5453
|
};
|
@@ -5506,7 +5578,7 @@ function Puck({
|
|
5506
5578
|
});
|
5507
5579
|
const [menuOpen, setMenuOpen] = useState21(false);
|
5508
5580
|
const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
|
5509
|
-
const setItemSelector =
|
5581
|
+
const setItemSelector = useCallback12(
|
5510
5582
|
(newItemSelector) => {
|
5511
5583
|
if (newItemSelector === itemSelector) return;
|
5512
5584
|
dispatch({
|
@@ -5518,13 +5590,13 @@ function Puck({
|
|
5518
5590
|
[itemSelector]
|
5519
5591
|
);
|
5520
5592
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
5521
|
-
|
5593
|
+
useEffect19(() => {
|
5522
5594
|
if (onChange) onChange(data);
|
5523
5595
|
}, [data]);
|
5524
5596
|
const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
|
5525
5597
|
const [draggedItem, setDraggedItem] = useState21();
|
5526
5598
|
const rootProps = data.root.props || data.root;
|
5527
|
-
const toggleSidebars =
|
5599
|
+
const toggleSidebars = useCallback12(
|
5528
5600
|
(sidebar) => {
|
5529
5601
|
const widerViewport = window.matchMedia("(min-width: 638px)").matches;
|
5530
5602
|
const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
|
@@ -5538,7 +5610,7 @@ function Puck({
|
|
5538
5610
|
},
|
5539
5611
|
[dispatch, leftSideBarVisible, rightSideBarVisible]
|
5540
5612
|
);
|
5541
|
-
|
5613
|
+
useEffect19(() => {
|
5542
5614
|
if (!window.matchMedia("(min-width: 638px)").matches) {
|
5543
5615
|
dispatch({
|
5544
5616
|
type: "setUi",
|
@@ -5561,7 +5633,7 @@ function Puck({
|
|
5561
5633
|
window.removeEventListener("resize", handleResize);
|
5562
5634
|
};
|
5563
5635
|
}, []);
|
5564
|
-
const defaultHeaderRender =
|
5636
|
+
const defaultHeaderRender = useMemo17(() => {
|
5565
5637
|
if (renderHeader) {
|
5566
5638
|
console.warn(
|
5567
5639
|
"`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
|
@@ -5575,7 +5647,7 @@ function Puck({
|
|
5575
5647
|
}
|
5576
5648
|
return DefaultOverride;
|
5577
5649
|
}, [renderHeader]);
|
5578
|
-
const defaultHeaderActionsRender =
|
5650
|
+
const defaultHeaderActionsRender = useMemo17(() => {
|
5579
5651
|
if (renderHeaderActions) {
|
5580
5652
|
console.warn(
|
5581
5653
|
"`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
|
@@ -5592,20 +5664,20 @@ function Puck({
|
|
5592
5664
|
overrides,
|
5593
5665
|
plugins
|
5594
5666
|
});
|
5595
|
-
const CustomPuck =
|
5667
|
+
const CustomPuck = useMemo17(
|
5596
5668
|
() => loadedOverrides.puck || DefaultOverride,
|
5597
5669
|
[loadedOverrides]
|
5598
5670
|
);
|
5599
|
-
const CustomHeader =
|
5671
|
+
const CustomHeader = useMemo17(
|
5600
5672
|
() => loadedOverrides.header || defaultHeaderRender,
|
5601
5673
|
[loadedOverrides]
|
5602
5674
|
);
|
5603
|
-
const CustomHeaderActions =
|
5675
|
+
const CustomHeaderActions = useMemo17(
|
5604
5676
|
() => loadedOverrides.headerActions || defaultHeaderActionsRender,
|
5605
5677
|
[loadedOverrides]
|
5606
5678
|
);
|
5607
5679
|
const [mounted, setMounted] = useState21(false);
|
5608
|
-
|
5680
|
+
useEffect19(() => {
|
5609
5681
|
setMounted(true);
|
5610
5682
|
}, []);
|
5611
5683
|
const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
|
package/package.json
CHANGED