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