@measured/puck 0.17.4-canary.e414e34 → 0.17.4
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.js
CHANGED
@@ -1736,12 +1736,13 @@ var DefaultField = ({
|
|
1736
1736
|
field,
|
1737
1737
|
onChange,
|
1738
1738
|
readOnly,
|
1739
|
-
value,
|
1739
|
+
value: _value,
|
1740
1740
|
name,
|
1741
1741
|
label,
|
1742
1742
|
Label,
|
1743
1743
|
id
|
1744
1744
|
}) => {
|
1745
|
+
const value = _value;
|
1745
1746
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
1746
1747
|
Label,
|
1747
1748
|
{
|
@@ -1759,7 +1760,7 @@ var DefaultField = ({
|
|
1759
1760
|
type: field.type,
|
1760
1761
|
title: label || name,
|
1761
1762
|
name,
|
1762
|
-
value:
|
1763
|
+
value: (value == null ? void 0 : value.toString) ? value.toString() : "",
|
1763
1764
|
onChange: (e) => {
|
1764
1765
|
if (field.type === "number") {
|
1765
1766
|
const numberValue = Number(e.currentTarget.value);
|
@@ -1868,29 +1869,57 @@ var import_react11 = require("react");
|
|
1868
1869
|
init_react_import();
|
1869
1870
|
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" };
|
1870
1871
|
|
1872
|
+
// lib/filter-data-attrs.ts
|
1873
|
+
init_react_import();
|
1874
|
+
var dataAttrRe = /^(data-.*)$/;
|
1875
|
+
var filterDataAttrs = (props) => {
|
1876
|
+
let filteredProps = {};
|
1877
|
+
for (const prop in props) {
|
1878
|
+
if (Object.prototype.hasOwnProperty.call(props, prop) && dataAttrRe.test(prop)) {
|
1879
|
+
filteredProps[prop] = props[prop];
|
1880
|
+
}
|
1881
|
+
}
|
1882
|
+
return filteredProps;
|
1883
|
+
};
|
1884
|
+
|
1871
1885
|
// components/Button/Button.tsx
|
1872
1886
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
1873
1887
|
var getClassName9 = get_class_name_factory_default("Button", Button_module_default);
|
1874
|
-
var Button = ({
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
+
var Button = (_a) => {
|
1889
|
+
var _b = _a, {
|
1890
|
+
children,
|
1891
|
+
href,
|
1892
|
+
onClick,
|
1893
|
+
variant = "primary",
|
1894
|
+
type,
|
1895
|
+
disabled,
|
1896
|
+
tabIndex,
|
1897
|
+
newTab,
|
1898
|
+
fullWidth,
|
1899
|
+
icon,
|
1900
|
+
size = "medium",
|
1901
|
+
loading: loadingProp = false
|
1902
|
+
} = _b, props = __objRest(_b, [
|
1903
|
+
"children",
|
1904
|
+
"href",
|
1905
|
+
"onClick",
|
1906
|
+
"variant",
|
1907
|
+
"type",
|
1908
|
+
"disabled",
|
1909
|
+
"tabIndex",
|
1910
|
+
"newTab",
|
1911
|
+
"fullWidth",
|
1912
|
+
"icon",
|
1913
|
+
"size",
|
1914
|
+
"loading"
|
1915
|
+
]);
|
1888
1916
|
const [loading, setLoading] = (0, import_react11.useState)(loadingProp);
|
1889
1917
|
(0, import_react11.useEffect)(() => setLoading(loadingProp), [loadingProp]);
|
1890
1918
|
const ElementType = href ? "a" : type ? "button" : "span";
|
1919
|
+
const dataAttrs = filterDataAttrs(props);
|
1891
1920
|
const el = /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
1892
1921
|
ElementType,
|
1893
|
-
{
|
1922
|
+
__spreadProps(__spreadValues({
|
1894
1923
|
className: getClassName9({
|
1895
1924
|
primary: variant === "primary",
|
1896
1925
|
secondary: variant === "secondary",
|
@@ -1910,13 +1939,14 @@ var Button = ({
|
|
1910
1939
|
tabIndex,
|
1911
1940
|
target: newTab ? "_blank" : void 0,
|
1912
1941
|
rel: newTab ? "noreferrer" : void 0,
|
1913
|
-
href
|
1942
|
+
href
|
1943
|
+
}, dataAttrs), {
|
1914
1944
|
children: [
|
1915
1945
|
icon && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: getClassName9("icon"), children: icon }),
|
1916
1946
|
children,
|
1917
1947
|
loading && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: getClassName9("spinner"), children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Loader, { size: 14 }) })
|
1918
1948
|
]
|
1919
|
-
}
|
1949
|
+
})
|
1920
1950
|
);
|
1921
1951
|
return el;
|
1922
1952
|
};
|
@@ -3316,7 +3346,7 @@ function DropZone(props) {
|
|
3316
3346
|
|
3317
3347
|
// components/Puck/index.tsx
|
3318
3348
|
init_react_import();
|
3319
|
-
var
|
3349
|
+
var import_react39 = require("react");
|
3320
3350
|
|
3321
3351
|
// lib/use-placeholder-style.ts
|
3322
3352
|
init_react_import();
|
@@ -3927,33 +3957,58 @@ init_react_import();
|
|
3927
3957
|
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" };
|
3928
3958
|
|
3929
3959
|
// components/Puck/components/Fields/index.tsx
|
3930
|
-
var
|
3960
|
+
var import_react28 = require("react");
|
3961
|
+
|
3962
|
+
// lib/use-resolved-fields.ts
|
3963
|
+
init_react_import();
|
3964
|
+
var import_react27 = require("react");
|
3931
3965
|
|
3932
3966
|
// lib/use-parent.ts
|
3933
3967
|
init_react_import();
|
3934
3968
|
var import_react25 = require("react");
|
3935
|
-
var
|
3969
|
+
var getParent = (itemSelector, pathData, data) => {
|
3936
3970
|
var _a;
|
3937
|
-
|
3938
|
-
const
|
3939
|
-
const
|
3940
|
-
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, state.data);
|
3971
|
+
if (!itemSelector) return null;
|
3972
|
+
const item = getItem(itemSelector, data);
|
3973
|
+
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, data);
|
3941
3974
|
const lastItem = breadcrumbs[breadcrumbs.length - 1];
|
3942
|
-
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector,
|
3975
|
+
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector, data)) != null ? _a : null : null;
|
3943
3976
|
return parent || null;
|
3944
3977
|
};
|
3978
|
+
var useGetParent = () => {
|
3979
|
+
const { state } = useAppContext();
|
3980
|
+
const { pathData } = (0, import_react25.useContext)(dropZoneContext) || {};
|
3981
|
+
return (0, import_react25.useCallback)(
|
3982
|
+
() => getParent(state.ui.itemSelector, pathData, state.data),
|
3983
|
+
[state.ui.itemSelector, pathData, state.data]
|
3984
|
+
);
|
3985
|
+
};
|
3986
|
+
var useParent = () => {
|
3987
|
+
return useGetParent()();
|
3988
|
+
};
|
3945
3989
|
|
3946
|
-
//
|
3947
|
-
|
3948
|
-
var
|
3990
|
+
// lib/use-on-value-change.ts
|
3991
|
+
init_react_import();
|
3992
|
+
var import_react26 = require("react");
|
3993
|
+
function useOnValueChange(value, onChange, compare = Object.is, deps = []) {
|
3994
|
+
const tracked = (0, import_react26.useRef)(value);
|
3995
|
+
(0, import_react26.useEffect)(() => {
|
3996
|
+
const oldValue = tracked.current;
|
3997
|
+
if (!compare(value, oldValue)) {
|
3998
|
+
tracked.current = value;
|
3999
|
+
onChange(value, oldValue);
|
4000
|
+
}
|
4001
|
+
}, [onChange, compare, value, ...deps]);
|
4002
|
+
}
|
4003
|
+
|
4004
|
+
// lib/selector-is.ts
|
4005
|
+
init_react_import();
|
4006
|
+
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);
|
4007
|
+
|
4008
|
+
// lib/use-resolved-fields.ts
|
3949
4009
|
var defaultPageFields = {
|
3950
4010
|
title: { type: "text" }
|
3951
4011
|
};
|
3952
|
-
var DefaultFields = ({
|
3953
|
-
children
|
3954
|
-
}) => {
|
3955
|
-
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_jsx_runtime28.Fragment, { children });
|
3956
|
-
};
|
3957
4012
|
var useResolvedFields = () => {
|
3958
4013
|
var _a, _b;
|
3959
4014
|
const { selectedItem, state, config } = useAppContext();
|
@@ -3961,20 +4016,21 @@ var useResolvedFields = () => {
|
|
3961
4016
|
const { data } = state;
|
3962
4017
|
const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
|
3963
4018
|
const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
|
3964
|
-
const defaultFields = (0,
|
4019
|
+
const defaultFields = (0, import_react27.useMemo)(
|
3965
4020
|
() => (selectedItem ? componentConfig == null ? void 0 : componentConfig.fields : rootFields) || {},
|
3966
4021
|
[selectedItem, rootFields, componentConfig == null ? void 0 : componentConfig.fields]
|
3967
4022
|
);
|
3968
4023
|
const rootProps = data.root.props || data.root;
|
3969
|
-
const [lastSelectedData, setLastSelectedData] = (0,
|
3970
|
-
const [resolvedFields, setResolvedFields] = (0,
|
3971
|
-
const [fieldsLoading, setFieldsLoading] = (0,
|
4024
|
+
const [lastSelectedData, setLastSelectedData] = (0, import_react27.useState)({});
|
4025
|
+
const [resolvedFields, setResolvedFields] = (0, import_react27.useState)(defaultFields);
|
4026
|
+
const [fieldsLoading, setFieldsLoading] = (0, import_react27.useState)(false);
|
4027
|
+
const lastFields = (0, import_react27.useRef)(defaultFields);
|
3972
4028
|
const defaultResolveFields = (_componentData, _params) => defaultFields;
|
3973
4029
|
const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
|
3974
4030
|
const hasComponentResolver = selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields);
|
3975
4031
|
const hasRootResolver = !selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields);
|
3976
4032
|
const hasResolver = hasComponentResolver || hasRootResolver;
|
3977
|
-
const resolveFields = (0,
|
4033
|
+
const resolveFields = (0, import_react27.useCallback)(
|
3978
4034
|
(..._0) => __async(void 0, [..._0], function* (fields = {}) {
|
3979
4035
|
var _a2;
|
3980
4036
|
const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
|
@@ -3986,7 +4042,7 @@ var useResolvedFields = () => {
|
|
3986
4042
|
{
|
3987
4043
|
changed,
|
3988
4044
|
fields,
|
3989
|
-
lastFields:
|
4045
|
+
lastFields: lastFields.current,
|
3990
4046
|
lastData,
|
3991
4047
|
appState: state,
|
3992
4048
|
parent
|
@@ -3997,7 +4053,7 @@ var useResolvedFields = () => {
|
|
3997
4053
|
return yield config.root.resolveFields(componentData, {
|
3998
4054
|
changed,
|
3999
4055
|
fields,
|
4000
|
-
lastFields:
|
4056
|
+
lastFields: lastFields.current,
|
4001
4057
|
lastData,
|
4002
4058
|
appState: state,
|
4003
4059
|
parent
|
@@ -4006,40 +4062,56 @@ var useResolvedFields = () => {
|
|
4006
4062
|
return defaultResolveFields(componentData, {
|
4007
4063
|
changed,
|
4008
4064
|
fields,
|
4009
|
-
lastFields:
|
4065
|
+
lastFields: lastFields.current,
|
4010
4066
|
lastData
|
4011
4067
|
});
|
4012
4068
|
}),
|
4013
|
-
[data, config, componentData, selectedItem,
|
4069
|
+
[data, config, componentData, selectedItem, state, parent]
|
4014
4070
|
);
|
4015
|
-
const
|
4016
|
-
(0, import_react26.useEffect)(() => {
|
4017
|
-
setHasParent(!!parent);
|
4018
|
-
}, [parent]);
|
4019
|
-
(0, import_react26.useEffect)(() => {
|
4071
|
+
const triggerResolver = (0, import_react27.useCallback)(() => {
|
4020
4072
|
var _a2, _b2;
|
4021
|
-
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" ||
|
4073
|
+
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" || parent) {
|
4022
4074
|
if (hasResolver) {
|
4023
4075
|
setFieldsLoading(true);
|
4024
4076
|
resolveFields(defaultFields).then((fields) => {
|
4025
4077
|
setResolvedFields(fields || {});
|
4078
|
+
lastFields.current = fields;
|
4026
4079
|
setFieldsLoading(false);
|
4027
4080
|
});
|
4028
|
-
|
4029
|
-
setResolvedFields(defaultFields);
|
4081
|
+
return;
|
4030
4082
|
}
|
4031
4083
|
}
|
4032
|
-
|
4033
|
-
|
4034
|
-
|
4084
|
+
setResolvedFields(defaultFields);
|
4085
|
+
}, [defaultFields, state.ui.itemSelector, hasResolver, parent]);
|
4086
|
+
useOnValueChange(
|
4035
4087
|
state.ui.itemSelector,
|
4036
|
-
|
4037
|
-
|
4038
|
-
|
4039
|
-
|
4088
|
+
() => {
|
4089
|
+
lastFields.current = defaultFields;
|
4090
|
+
},
|
4091
|
+
selectorIs
|
4092
|
+
);
|
4093
|
+
useOnValueChange(
|
4094
|
+
{ data, parent, itemSelector: state.ui.itemSelector },
|
4095
|
+
() => {
|
4096
|
+
triggerResolver();
|
4097
|
+
},
|
4098
|
+
(a, b) => JSON.stringify(a) === JSON.stringify(b)
|
4099
|
+
);
|
4100
|
+
(0, import_react27.useEffect)(() => {
|
4101
|
+
triggerResolver();
|
4102
|
+
}, []);
|
4040
4103
|
return [resolvedFields, fieldsLoading];
|
4041
4104
|
};
|
4042
|
-
|
4105
|
+
|
4106
|
+
// components/Puck/components/Fields/index.tsx
|
4107
|
+
var import_jsx_runtime28 = require("react/jsx-runtime");
|
4108
|
+
var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
|
4109
|
+
var DefaultFields = ({
|
4110
|
+
children
|
4111
|
+
}) => {
|
4112
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_jsx_runtime28.Fragment, { children });
|
4113
|
+
};
|
4114
|
+
var Fields = ({ wrapFields = true }) => {
|
4043
4115
|
var _a, _b;
|
4044
4116
|
const {
|
4045
4117
|
selectedItem,
|
@@ -4057,7 +4129,7 @@ var Fields = () => {
|
|
4057
4129
|
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;
|
4058
4130
|
const isLoading = fieldsResolving || componentResolving;
|
4059
4131
|
const rootProps = data.root.props || data.root;
|
4060
|
-
const Wrapper = (0,
|
4132
|
+
const Wrapper = (0, import_react28.useMemo)(() => overrides.fields || DefaultFields, [overrides]);
|
4061
4133
|
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
4062
4134
|
"form",
|
4063
4135
|
{
|
@@ -4180,7 +4252,7 @@ init_react_import();
|
|
4180
4252
|
|
4181
4253
|
// lib/use-component-list.tsx
|
4182
4254
|
init_react_import();
|
4183
|
-
var
|
4255
|
+
var import_react29 = require("react");
|
4184
4256
|
|
4185
4257
|
// components/ComponentList/index.tsx
|
4186
4258
|
init_react_import();
|
@@ -4258,8 +4330,8 @@ ComponentList.Item = ComponentListItem;
|
|
4258
4330
|
// lib/use-component-list.tsx
|
4259
4331
|
var import_jsx_runtime30 = require("react/jsx-runtime");
|
4260
4332
|
var useComponentList = (config, ui) => {
|
4261
|
-
const [componentList, setComponentList] = (0,
|
4262
|
-
(0,
|
4333
|
+
const [componentList, setComponentList] = (0, import_react29.useState)();
|
4334
|
+
(0, import_react29.useEffect)(() => {
|
4263
4335
|
var _a, _b, _c;
|
4264
4336
|
if (Object.keys(ui.componentList).length > 0) {
|
4265
4337
|
const matchedComponents = [];
|
@@ -4328,22 +4400,22 @@ var useComponentList = (config, ui) => {
|
|
4328
4400
|
};
|
4329
4401
|
|
4330
4402
|
// components/Puck/components/Components/index.tsx
|
4331
|
-
var
|
4403
|
+
var import_react30 = require("react");
|
4332
4404
|
var import_jsx_runtime31 = require("react/jsx-runtime");
|
4333
4405
|
var Components = () => {
|
4334
4406
|
const { config, state, overrides } = useAppContext();
|
4335
4407
|
const componentList = useComponentList(config, state.ui);
|
4336
|
-
const Wrapper = (0,
|
4408
|
+
const Wrapper = (0, import_react30.useMemo)(() => overrides.components || "div", [overrides]);
|
4337
4409
|
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(ComponentList, { id: "all" }) });
|
4338
4410
|
};
|
4339
4411
|
|
4340
4412
|
// components/Puck/components/Preview/index.tsx
|
4341
4413
|
init_react_import();
|
4342
|
-
var
|
4414
|
+
var import_react32 = require("react");
|
4343
4415
|
|
4344
4416
|
// components/AutoFrame/index.tsx
|
4345
4417
|
init_react_import();
|
4346
|
-
var
|
4418
|
+
var import_react31 = require("react");
|
4347
4419
|
var import_object_hash = __toESM(require("object-hash"));
|
4348
4420
|
var import_react_dom2 = require("react-dom");
|
4349
4421
|
var import_jsx_runtime32 = require("react/jsx-runtime");
|
@@ -4389,7 +4461,7 @@ var CopyHostStyles = ({
|
|
4389
4461
|
onStylesLoaded = () => null
|
4390
4462
|
}) => {
|
4391
4463
|
const { document: doc, window: win } = useFrame();
|
4392
|
-
(0,
|
4464
|
+
(0, import_react31.useEffect)(() => {
|
4393
4465
|
if (!win || !doc) {
|
4394
4466
|
return () => {
|
4395
4467
|
};
|
@@ -4548,8 +4620,8 @@ var CopyHostStyles = ({
|
|
4548
4620
|
}, []);
|
4549
4621
|
return /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(import_jsx_runtime32.Fragment, { children });
|
4550
4622
|
};
|
4551
|
-
var autoFrameContext = (0,
|
4552
|
-
var useFrame = () => (0,
|
4623
|
+
var autoFrameContext = (0, import_react31.createContext)({});
|
4624
|
+
var useFrame = () => (0, import_react31.useContext)(autoFrameContext);
|
4553
4625
|
function AutoFrame(_a) {
|
4554
4626
|
var _b = _a, {
|
4555
4627
|
children,
|
@@ -4564,11 +4636,11 @@ function AutoFrame(_a) {
|
|
4564
4636
|
"id",
|
4565
4637
|
"onStylesLoaded"
|
4566
4638
|
]);
|
4567
|
-
const [loaded, setLoaded] = (0,
|
4568
|
-
const [ctx, setCtx] = (0,
|
4569
|
-
const ref = (0,
|
4570
|
-
const [mountTarget, setMountTarget] = (0,
|
4571
|
-
(0,
|
4639
|
+
const [loaded, setLoaded] = (0, import_react31.useState)(false);
|
4640
|
+
const [ctx, setCtx] = (0, import_react31.useState)({});
|
4641
|
+
const ref = (0, import_react31.useRef)(null);
|
4642
|
+
const [mountTarget, setMountTarget] = (0, import_react31.useState)();
|
4643
|
+
(0, import_react31.useEffect)(() => {
|
4572
4644
|
var _a2;
|
4573
4645
|
if (ref.current) {
|
4574
4646
|
setCtx({
|
@@ -4604,7 +4676,7 @@ var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
4604
4676
|
var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
|
4605
4677
|
var Preview = ({ id = "puck-preview" }) => {
|
4606
4678
|
const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
|
4607
|
-
const Page = (0,
|
4679
|
+
const Page = (0, import_react32.useCallback)(
|
4608
4680
|
(pageProps) => {
|
4609
4681
|
var _a, _b;
|
4610
4682
|
return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
|
@@ -4613,7 +4685,7 @@ var Preview = ({ id = "puck-preview" }) => {
|
|
4613
4685
|
},
|
4614
4686
|
[config.root]
|
4615
4687
|
);
|
4616
|
-
const Frame = (0,
|
4688
|
+
const Frame = (0, import_react32.useMemo)(() => overrides.iframe, [overrides]);
|
4617
4689
|
const rootProps = state.data.root.props || state.data.root;
|
4618
4690
|
return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
|
4619
4691
|
"div",
|
@@ -4702,7 +4774,7 @@ var scrollIntoView = (el) => {
|
|
4702
4774
|
};
|
4703
4775
|
|
4704
4776
|
// components/LayerTree/index.tsx
|
4705
|
-
var
|
4777
|
+
var import_react33 = require("react");
|
4706
4778
|
|
4707
4779
|
// lib/is-child-of-zone.ts
|
4708
4780
|
init_react_import();
|
@@ -4729,7 +4801,7 @@ var LayerTree = ({
|
|
4729
4801
|
label
|
4730
4802
|
}) => {
|
4731
4803
|
const zones = data.zones || {};
|
4732
|
-
const ctx = (0,
|
4804
|
+
const ctx = (0, import_react33.useContext)(dropZoneContext);
|
4733
4805
|
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
|
4734
4806
|
label && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: getClassName24("zoneTitle"), children: [
|
4735
4807
|
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Layers, { size: "16" }) }),
|
@@ -4835,13 +4907,13 @@ var LayerTree = ({
|
|
4835
4907
|
};
|
4836
4908
|
|
4837
4909
|
// components/Puck/components/Outline/index.tsx
|
4838
|
-
var
|
4910
|
+
var import_react34 = require("react");
|
4839
4911
|
var import_jsx_runtime35 = require("react/jsx-runtime");
|
4840
4912
|
var Outline = () => {
|
4841
4913
|
const { dispatch, state, overrides, config } = useAppContext();
|
4842
4914
|
const { data, ui } = state;
|
4843
4915
|
const { itemSelector } = ui;
|
4844
|
-
const setItemSelector = (0,
|
4916
|
+
const setItemSelector = (0, import_react34.useCallback)(
|
4845
4917
|
(newItemSelector) => {
|
4846
4918
|
dispatch({
|
4847
4919
|
type: "setUi",
|
@@ -4850,7 +4922,7 @@ var Outline = () => {
|
|
4850
4922
|
},
|
4851
4923
|
[]
|
4852
4924
|
);
|
4853
|
-
const Wrapper = (0,
|
4925
|
+
const Wrapper = (0, import_react34.useMemo)(() => overrides.outline || "div", [overrides]);
|
4854
4926
|
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Wrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(dropZoneContext.Consumer, { children: (ctx) => /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_jsx_runtime35.Fragment, { children: [
|
4855
4927
|
(ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
|
4856
4928
|
LayerTree,
|
@@ -4964,19 +5036,19 @@ function usePuckHistory({
|
|
4964
5036
|
|
4965
5037
|
// lib/use-history-store.ts
|
4966
5038
|
init_react_import();
|
4967
|
-
var
|
5039
|
+
var import_react35 = require("react");
|
4968
5040
|
var import_use_debounce3 = require("use-debounce");
|
4969
5041
|
var EMPTY_HISTORY_INDEX = 0;
|
4970
5042
|
function useHistoryStore(initialHistory) {
|
4971
5043
|
var _a, _b;
|
4972
|
-
const [histories, setHistories] = (0,
|
5044
|
+
const [histories, setHistories] = (0, import_react35.useState)(
|
4973
5045
|
(_a = initialHistory == null ? void 0 : initialHistory.histories) != null ? _a : []
|
4974
5046
|
);
|
4975
5047
|
const updateHistories = (histories2) => {
|
4976
5048
|
setHistories(histories2);
|
4977
5049
|
setIndex(histories2.length - 1);
|
4978
5050
|
};
|
4979
|
-
const [index, setIndex] = (0,
|
5051
|
+
const [index, setIndex] = (0, import_react35.useState)(
|
4980
5052
|
(_b = initialHistory == null ? void 0 : initialHistory.index) != null ? _b : EMPTY_HISTORY_INDEX
|
4981
5053
|
);
|
4982
5054
|
const hasPast = index > EMPTY_HISTORY_INDEX;
|
@@ -5136,11 +5208,11 @@ var getBox = function getBox2(el) {
|
|
5136
5208
|
};
|
5137
5209
|
|
5138
5210
|
// components/Puck/components/Canvas/index.tsx
|
5139
|
-
var
|
5211
|
+
var import_react37 = require("react");
|
5140
5212
|
|
5141
5213
|
// components/ViewportControls/index.tsx
|
5142
5214
|
init_react_import();
|
5143
|
-
var
|
5215
|
+
var import_react36 = require("react");
|
5144
5216
|
|
5145
5217
|
// css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
|
5146
5218
|
init_react_import();
|
@@ -5163,8 +5235,8 @@ var ViewportButton = ({
|
|
5163
5235
|
onClick
|
5164
5236
|
}) => {
|
5165
5237
|
const { state } = useAppContext();
|
5166
|
-
const [isActive, setIsActive] = (0,
|
5167
|
-
(0,
|
5238
|
+
const [isActive, setIsActive] = (0, import_react36.useState)(false);
|
5239
|
+
(0, import_react36.useEffect)(() => {
|
5168
5240
|
setIsActive(width === state.ui.viewports.current.width);
|
5169
5241
|
}, [width, state.ui.viewports.current.width]);
|
5170
5242
|
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
@@ -5200,7 +5272,7 @@ var ViewportControls = ({
|
|
5200
5272
|
const defaultsContainAutoZoom = defaultZoomOptions.find(
|
5201
5273
|
(option) => option.value === autoZoom
|
5202
5274
|
);
|
5203
|
-
const zoomOptions = (0,
|
5275
|
+
const zoomOptions = (0, import_react36.useMemo)(
|
5204
5276
|
() => [
|
5205
5277
|
...defaultZoomOptions,
|
5206
5278
|
...defaultsContainAutoZoom ? [] : [
|
@@ -5323,17 +5395,17 @@ var Canvas = () => {
|
|
5323
5395
|
const { status, iframe } = useAppContext();
|
5324
5396
|
const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
|
5325
5397
|
const { ui } = state;
|
5326
|
-
const frameRef = (0,
|
5327
|
-
const [showTransition, setShowTransition] = (0,
|
5328
|
-
const defaultRender = (0,
|
5398
|
+
const frameRef = (0, import_react37.useRef)(null);
|
5399
|
+
const [showTransition, setShowTransition] = (0, import_react37.useState)(false);
|
5400
|
+
const defaultRender = (0, import_react37.useMemo)(() => {
|
5329
5401
|
const PuckDefault = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_jsx_runtime37.Fragment, { children });
|
5330
5402
|
return PuckDefault;
|
5331
5403
|
}, []);
|
5332
|
-
const CustomPreview = (0,
|
5404
|
+
const CustomPreview = (0, import_react37.useMemo)(
|
5333
5405
|
() => overrides.preview || defaultRender,
|
5334
5406
|
[overrides]
|
5335
5407
|
);
|
5336
|
-
const getFrameDimensions = (0,
|
5408
|
+
const getFrameDimensions = (0, import_react37.useCallback)(() => {
|
5337
5409
|
if (frameRef.current) {
|
5338
5410
|
const frame = frameRef.current;
|
5339
5411
|
const box = getBox(frame);
|
@@ -5341,7 +5413,7 @@ var Canvas = () => {
|
|
5341
5413
|
}
|
5342
5414
|
return { width: 0, height: 0 };
|
5343
5415
|
}, [frameRef]);
|
5344
|
-
const resetAutoZoom = (0,
|
5416
|
+
const resetAutoZoom = (0, import_react37.useCallback)(
|
5345
5417
|
(ui2 = state.ui) => {
|
5346
5418
|
if (frameRef.current) {
|
5347
5419
|
setZoomConfig(
|
@@ -5351,11 +5423,11 @@ var Canvas = () => {
|
|
5351
5423
|
},
|
5352
5424
|
[frameRef, zoomConfig, state.ui]
|
5353
5425
|
);
|
5354
|
-
(0,
|
5426
|
+
(0, import_react37.useEffect)(() => {
|
5355
5427
|
setShowTransition(false);
|
5356
5428
|
resetAutoZoom();
|
5357
5429
|
}, [frameRef, ui.leftSideBarVisible, ui.rightSideBarVisible]);
|
5358
|
-
(0,
|
5430
|
+
(0, import_react37.useEffect)(() => {
|
5359
5431
|
const { height: frameHeight } = getFrameDimensions();
|
5360
5432
|
if (ui.viewports.current.height === "auto") {
|
5361
5433
|
setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
|
@@ -5363,13 +5435,13 @@ var Canvas = () => {
|
|
5363
5435
|
}));
|
5364
5436
|
}
|
5365
5437
|
}, [zoomConfig.zoom]);
|
5366
|
-
(0,
|
5438
|
+
(0, import_react37.useEffect)(() => {
|
5367
5439
|
if (ZOOM_ON_CHANGE) {
|
5368
5440
|
setShowTransition(true);
|
5369
5441
|
resetAutoZoom(ui);
|
5370
5442
|
}
|
5371
5443
|
}, [ui.viewports.current.width]);
|
5372
|
-
(0,
|
5444
|
+
(0, import_react37.useEffect)(() => {
|
5373
5445
|
const observer = new ResizeObserver(() => {
|
5374
5446
|
setShowTransition(false);
|
5375
5447
|
resetAutoZoom();
|
@@ -5381,8 +5453,8 @@ var Canvas = () => {
|
|
5381
5453
|
observer.disconnect();
|
5382
5454
|
};
|
5383
5455
|
}, []);
|
5384
|
-
const [showLoader, setShowLoader] = (0,
|
5385
|
-
(0,
|
5456
|
+
const [showLoader, setShowLoader] = (0, import_react37.useState)(false);
|
5457
|
+
(0, import_react37.useEffect)(() => {
|
5386
5458
|
setTimeout(() => {
|
5387
5459
|
setShowLoader(true);
|
5388
5460
|
}, 500);
|
@@ -5485,7 +5557,7 @@ var insertComponent = (componentType, zone, index, {
|
|
5485
5557
|
|
5486
5558
|
// lib/use-loaded-overrides.ts
|
5487
5559
|
init_react_import();
|
5488
|
-
var
|
5560
|
+
var import_react38 = require("react");
|
5489
5561
|
|
5490
5562
|
// lib/load-overrides.ts
|
5491
5563
|
init_react_import();
|
@@ -5524,7 +5596,7 @@ var useLoadedOverrides = ({
|
|
5524
5596
|
overrides,
|
5525
5597
|
plugins
|
5526
5598
|
}) => {
|
5527
|
-
return (0,
|
5599
|
+
return (0, import_react38.useMemo)(() => {
|
5528
5600
|
return loadOverrides({ overrides, plugins });
|
5529
5601
|
}, [plugins, overrides]);
|
5530
5602
|
};
|
@@ -5563,7 +5635,7 @@ function Puck({
|
|
5563
5635
|
enabled: true,
|
5564
5636
|
waitForStyles: true
|
5565
5637
|
}, _iframe);
|
5566
|
-
const [generatedAppState] = (0,
|
5638
|
+
const [generatedAppState] = (0, import_react39.useState)(() => {
|
5567
5639
|
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
5568
5640
|
const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
|
5569
5641
|
let clientUiState = {};
|
@@ -5635,14 +5707,14 @@ function Puck({
|
|
5635
5707
|
histories,
|
5636
5708
|
index: initialHistoryIndex
|
5637
5709
|
});
|
5638
|
-
const [reducer] = (0,
|
5710
|
+
const [reducer] = (0, import_react39.useState)(
|
5639
5711
|
() => createReducer({
|
5640
5712
|
config,
|
5641
5713
|
record: historyStore.record,
|
5642
5714
|
onAction
|
5643
5715
|
})
|
5644
5716
|
);
|
5645
|
-
const [appState, dispatch] = (0,
|
5717
|
+
const [appState, dispatch] = (0, import_react39.useReducer)(
|
5646
5718
|
reducer,
|
5647
5719
|
flushZones(initialAppState)
|
5648
5720
|
);
|
@@ -5653,9 +5725,9 @@ function Puck({
|
|
5653
5725
|
historyStore,
|
5654
5726
|
iframeEnabled: (_a = _iframe == null ? void 0 : _iframe.enabled) != null ? _a : true
|
5655
5727
|
});
|
5656
|
-
const [menuOpen, setMenuOpen] = (0,
|
5728
|
+
const [menuOpen, setMenuOpen] = (0, import_react39.useState)(false);
|
5657
5729
|
const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
|
5658
|
-
const setItemSelector = (0,
|
5730
|
+
const setItemSelector = (0, import_react39.useCallback)(
|
5659
5731
|
(newItemSelector) => {
|
5660
5732
|
if (newItemSelector === itemSelector) return;
|
5661
5733
|
dispatch({
|
@@ -5667,13 +5739,13 @@ function Puck({
|
|
5667
5739
|
[itemSelector]
|
5668
5740
|
);
|
5669
5741
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
5670
|
-
(0,
|
5742
|
+
(0, import_react39.useEffect)(() => {
|
5671
5743
|
if (onChange) onChange(data);
|
5672
5744
|
}, [data]);
|
5673
5745
|
const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
|
5674
|
-
const [draggedItem, setDraggedItem] = (0,
|
5746
|
+
const [draggedItem, setDraggedItem] = (0, import_react39.useState)();
|
5675
5747
|
const rootProps = data.root.props || data.root;
|
5676
|
-
const toggleSidebars = (0,
|
5748
|
+
const toggleSidebars = (0, import_react39.useCallback)(
|
5677
5749
|
(sidebar) => {
|
5678
5750
|
const widerViewport = window.matchMedia("(min-width: 638px)").matches;
|
5679
5751
|
const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
|
@@ -5687,7 +5759,7 @@ function Puck({
|
|
5687
5759
|
},
|
5688
5760
|
[dispatch, leftSideBarVisible, rightSideBarVisible]
|
5689
5761
|
);
|
5690
|
-
(0,
|
5762
|
+
(0, import_react39.useEffect)(() => {
|
5691
5763
|
if (!window.matchMedia("(min-width: 638px)").matches) {
|
5692
5764
|
dispatch({
|
5693
5765
|
type: "setUi",
|
@@ -5710,7 +5782,7 @@ function Puck({
|
|
5710
5782
|
window.removeEventListener("resize", handleResize);
|
5711
5783
|
};
|
5712
5784
|
}, []);
|
5713
|
-
const defaultHeaderRender = (0,
|
5785
|
+
const defaultHeaderRender = (0, import_react39.useMemo)(() => {
|
5714
5786
|
if (renderHeader) {
|
5715
5787
|
console.warn(
|
5716
5788
|
"`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
|
@@ -5724,7 +5796,7 @@ function Puck({
|
|
5724
5796
|
}
|
5725
5797
|
return DefaultOverride;
|
5726
5798
|
}, [renderHeader]);
|
5727
|
-
const defaultHeaderActionsRender = (0,
|
5799
|
+
const defaultHeaderActionsRender = (0, import_react39.useMemo)(() => {
|
5728
5800
|
if (renderHeaderActions) {
|
5729
5801
|
console.warn(
|
5730
5802
|
"`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
|
@@ -5741,20 +5813,20 @@ function Puck({
|
|
5741
5813
|
overrides,
|
5742
5814
|
plugins
|
5743
5815
|
});
|
5744
|
-
const CustomPuck = (0,
|
5816
|
+
const CustomPuck = (0, import_react39.useMemo)(
|
5745
5817
|
() => loadedOverrides.puck || DefaultOverride,
|
5746
5818
|
[loadedOverrides]
|
5747
5819
|
);
|
5748
|
-
const CustomHeader = (0,
|
5820
|
+
const CustomHeader = (0, import_react39.useMemo)(
|
5749
5821
|
() => loadedOverrides.header || defaultHeaderRender,
|
5750
5822
|
[loadedOverrides]
|
5751
5823
|
);
|
5752
|
-
const CustomHeaderActions = (0,
|
5824
|
+
const CustomHeaderActions = (0, import_react39.useMemo)(
|
5753
5825
|
() => loadedOverrides.headerActions || defaultHeaderActionsRender,
|
5754
5826
|
[loadedOverrides]
|
5755
5827
|
);
|
5756
|
-
const [mounted, setMounted] = (0,
|
5757
|
-
(0,
|
5828
|
+
const [mounted, setMounted] = (0, import_react39.useState)(false);
|
5829
|
+
(0, import_react39.useEffect)(() => {
|
5758
5830
|
setMounted(true);
|
5759
5831
|
}, []);
|
5760
5832
|
const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
|