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