@measured/puck 0.18.0-canary.63b8b9a → 0.18.0-canary.97d25d4
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.css +44 -47
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +171 -125
- package/dist/index.mjs +162 -116
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -308,7 +308,7 @@ init_react_import();
|
|
308
308
|
|
309
309
|
// css-module:/home/runner/work/puck/puck/packages/core/components/AutoField/styles.module.css#css-module
|
310
310
|
init_react_import();
|
311
|
-
var styles_module_default2 = { "InputWrapper": "
|
311
|
+
var styles_module_default2 = { "InputWrapper": "_InputWrapper_1h1p1_1", "Input-label": "_Input-label_1h1p1_5", "Input-labelIcon": "_Input-labelIcon_1h1p1_14", "Input-disabledIcon": "_Input-disabledIcon_1h1p1_21", "Input-input": "_Input-input_1h1p1_26", "Input": "_Input_1h1p1_1", "Input--readOnly": "_Input--readOnly_1h1p1_70", "Input-radioGroupItems": "_Input-radioGroupItems_1h1p1_81", "Input-radio": "_Input-radio_1h1p1_81", "Input-radioInner": "_Input-radioInner_1h1p1_98", "Input-radioInput": "_Input-radioInput_1h1p1_143" };
|
312
312
|
|
313
313
|
// components/AutoField/index.tsx
|
314
314
|
var import_react20 = require("react");
|
@@ -1697,12 +1697,13 @@ var DefaultField = ({
|
|
1697
1697
|
field,
|
1698
1698
|
onChange,
|
1699
1699
|
readOnly,
|
1700
|
-
value,
|
1700
|
+
value: _value,
|
1701
1701
|
name,
|
1702
1702
|
label,
|
1703
1703
|
Label: Label2,
|
1704
1704
|
id
|
1705
1705
|
}) => {
|
1706
|
+
const value = _value;
|
1706
1707
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
1707
1708
|
Label2,
|
1708
1709
|
{
|
@@ -1720,7 +1721,7 @@ var DefaultField = ({
|
|
1720
1721
|
type: field.type,
|
1721
1722
|
title: label || name,
|
1722
1723
|
name,
|
1723
|
-
value:
|
1724
|
+
value: (value == null ? void 0 : value.toString) ? value.toString() : "",
|
1724
1725
|
onChange: (e) => {
|
1725
1726
|
if (field.type === "number") {
|
1726
1727
|
const numberValue = Number(e.currentTarget.value);
|
@@ -3823,7 +3824,7 @@ var DropZoneEdit = (0, import_react29.forwardRef)(
|
|
3823
3824
|
backgroundColor: RENDER_DEBUG ? getRandomColor() : void 0
|
3824
3825
|
}),
|
3825
3826
|
children: contentWithPreview.map((item, i) => {
|
3826
|
-
var _a, _b, _c, _d, _e;
|
3827
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
3827
3828
|
const componentId = item.props.id;
|
3828
3829
|
const puckProps = {
|
3829
3830
|
renderDropZone: DropZoneEditPure,
|
@@ -3843,13 +3844,13 @@ var DropZoneEdit = (0, import_react29.forwardRef)(
|
|
3843
3844
|
const componentConfig = config.components[item.type];
|
3844
3845
|
let componentType = item.type;
|
3845
3846
|
let label = (_b = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _b : item.type.toString();
|
3846
|
-
if (item.type === "preview"
|
3847
|
+
if (item.type === "preview") {
|
3847
3848
|
let Preview4 = function() {
|
3848
3849
|
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DrawerItemInner, { name: label, children: appContext2.overrides.componentItem });
|
3849
3850
|
};
|
3850
3851
|
var Preview3 = Preview4;
|
3851
|
-
componentType = preview.componentType;
|
3852
|
-
label = (
|
3852
|
+
componentType = (_c = preview == null ? void 0 : preview.componentType) != null ? _c : "__preview";
|
3853
|
+
label = (_f = (_e = (_d = config.components[componentType]) == null ? void 0 : _d.label) != null ? _e : componentType) != null ? _f : "Preview";
|
3853
3854
|
Render2 = Preview4;
|
3854
3855
|
}
|
3855
3856
|
return /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
@@ -3864,7 +3865,7 @@ var DropZoneEdit = (0, import_react29.forwardRef)(
|
|
3864
3865
|
zoneCompound,
|
3865
3866
|
depth: depth + 1,
|
3866
3867
|
index: i,
|
3867
|
-
isLoading: ((
|
3868
|
+
isLoading: ((_g = appContext2.componentState[componentId]) == null ? void 0 : _g.loadingCount) > 0,
|
3868
3869
|
isSelected,
|
3869
3870
|
label,
|
3870
3871
|
isEnabled,
|
@@ -4507,6 +4508,11 @@ var reduceUi = (ui, action) => {
|
|
4507
4508
|
itemSelector: { index: action.sourceIndex + 1, zone: action.sourceZone }
|
4508
4509
|
});
|
4509
4510
|
}
|
4511
|
+
if (action.type === "remove") {
|
4512
|
+
return __spreadProps(__spreadValues({}, ui), {
|
4513
|
+
itemSelector: null
|
4514
|
+
});
|
4515
|
+
}
|
4510
4516
|
return ui;
|
4511
4517
|
};
|
4512
4518
|
|
@@ -5403,7 +5409,7 @@ Drawer.Item = DrawerItem;
|
|
5403
5409
|
|
5404
5410
|
// components/Puck/index.tsx
|
5405
5411
|
init_react_import();
|
5406
|
-
var
|
5412
|
+
var import_react50 = require("react");
|
5407
5413
|
|
5408
5414
|
// components/SidebarSection/index.tsx
|
5409
5415
|
init_react_import();
|
@@ -5596,36 +5602,61 @@ init_react_import();
|
|
5596
5602
|
|
5597
5603
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Fields/styles.module.css#css-module
|
5598
5604
|
init_react_import();
|
5599
|
-
var styles_module_default16 = { "PuckFields": "
|
5605
|
+
var styles_module_default16 = { "PuckFields": "_PuckFields_10bh7_1", "PuckFields--isLoading": "_PuckFields--isLoading_10bh7_6", "PuckFields-loadingOverlay": "_PuckFields-loadingOverlay_10bh7_10", "PuckFields-loadingOverlayInner": "_PuckFields-loadingOverlayInner_10bh7_25", "PuckFields-field": "_PuckFields-field_10bh7_32", "PuckFields--wrapFields": "_PuckFields--wrapFields_10bh7_36" };
|
5600
5606
|
|
5601
5607
|
// components/Puck/components/Fields/index.tsx
|
5602
|
-
var
|
5608
|
+
var import_react37 = require("react");
|
5609
|
+
|
5610
|
+
// lib/use-resolved-fields.ts
|
5611
|
+
init_react_import();
|
5612
|
+
var import_react36 = require("react");
|
5603
5613
|
|
5604
5614
|
// lib/use-parent.ts
|
5605
5615
|
init_react_import();
|
5606
5616
|
var import_react34 = require("react");
|
5607
|
-
var
|
5617
|
+
var getParent = (itemSelector, pathData, data) => {
|
5608
5618
|
var _a;
|
5609
|
-
|
5610
|
-
const
|
5611
|
-
const
|
5612
|
-
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, state.data);
|
5619
|
+
if (!itemSelector) return null;
|
5620
|
+
const item = getItem(itemSelector, data);
|
5621
|
+
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, data);
|
5613
5622
|
const lastItem = breadcrumbs[breadcrumbs.length - 1];
|
5614
|
-
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector,
|
5623
|
+
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector, data)) != null ? _a : null : null;
|
5615
5624
|
return parent || null;
|
5616
5625
|
};
|
5626
|
+
var useGetParent = () => {
|
5627
|
+
const { state } = useAppContext();
|
5628
|
+
const { pathData } = (0, import_react34.useContext)(dropZoneContext) || {};
|
5629
|
+
return (0, import_react34.useCallback)(
|
5630
|
+
() => getParent(state.ui.itemSelector, pathData, state.data),
|
5631
|
+
[state.ui.itemSelector, pathData, state.data]
|
5632
|
+
);
|
5633
|
+
};
|
5634
|
+
var useParent = () => {
|
5635
|
+
return useGetParent()();
|
5636
|
+
};
|
5617
5637
|
|
5618
|
-
//
|
5619
|
-
|
5620
|
-
var
|
5638
|
+
// lib/use-on-value-change.ts
|
5639
|
+
init_react_import();
|
5640
|
+
var import_react35 = require("react");
|
5641
|
+
function useOnValueChange(value, onChange, compare = Object.is, deps = []) {
|
5642
|
+
const tracked = (0, import_react35.useRef)(value);
|
5643
|
+
(0, import_react35.useEffect)(() => {
|
5644
|
+
const oldValue = tracked.current;
|
5645
|
+
if (!compare(value, oldValue)) {
|
5646
|
+
tracked.current = value;
|
5647
|
+
onChange(value, oldValue);
|
5648
|
+
}
|
5649
|
+
}, [onChange, compare, value, ...deps]);
|
5650
|
+
}
|
5651
|
+
|
5652
|
+
// lib/selector-is.ts
|
5653
|
+
init_react_import();
|
5654
|
+
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);
|
5655
|
+
|
5656
|
+
// lib/use-resolved-fields.ts
|
5621
5657
|
var defaultPageFields = {
|
5622
5658
|
title: { type: "text" }
|
5623
5659
|
};
|
5624
|
-
var DefaultFields = ({
|
5625
|
-
children
|
5626
|
-
}) => {
|
5627
|
-
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_jsx_runtime27.Fragment, { children });
|
5628
|
-
};
|
5629
5660
|
var useResolvedFields = () => {
|
5630
5661
|
var _a, _b;
|
5631
5662
|
const { selectedItem, state, config } = useAppContext();
|
@@ -5633,20 +5664,21 @@ var useResolvedFields = () => {
|
|
5633
5664
|
const { data } = state;
|
5634
5665
|
const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
|
5635
5666
|
const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
|
5636
|
-
const defaultFields = (0,
|
5667
|
+
const defaultFields = (0, import_react36.useMemo)(
|
5637
5668
|
() => (selectedItem ? componentConfig == null ? void 0 : componentConfig.fields : rootFields) || {},
|
5638
5669
|
[selectedItem, rootFields, componentConfig == null ? void 0 : componentConfig.fields]
|
5639
5670
|
);
|
5640
5671
|
const rootProps = data.root.props || data.root;
|
5641
|
-
const [lastSelectedData, setLastSelectedData] = (0,
|
5642
|
-
const [resolvedFields, setResolvedFields] = (0,
|
5643
|
-
const [fieldsLoading, setFieldsLoading] = (0,
|
5672
|
+
const [lastSelectedData, setLastSelectedData] = (0, import_react36.useState)({});
|
5673
|
+
const [resolvedFields, setResolvedFields] = (0, import_react36.useState)(defaultFields);
|
5674
|
+
const [fieldsLoading, setFieldsLoading] = (0, import_react36.useState)(false);
|
5675
|
+
const lastFields = (0, import_react36.useRef)(defaultFields);
|
5644
5676
|
const defaultResolveFields = (_componentData, _params) => defaultFields;
|
5645
5677
|
const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
|
5646
5678
|
const hasComponentResolver = selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields);
|
5647
5679
|
const hasRootResolver = !selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields);
|
5648
5680
|
const hasResolver = hasComponentResolver || hasRootResolver;
|
5649
|
-
const resolveFields = (0,
|
5681
|
+
const resolveFields = (0, import_react36.useCallback)(
|
5650
5682
|
(..._0) => __async(void 0, [..._0], function* (fields = {}) {
|
5651
5683
|
var _a2;
|
5652
5684
|
const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
|
@@ -5658,7 +5690,7 @@ var useResolvedFields = () => {
|
|
5658
5690
|
{
|
5659
5691
|
changed,
|
5660
5692
|
fields,
|
5661
|
-
lastFields:
|
5693
|
+
lastFields: lastFields.current,
|
5662
5694
|
lastData,
|
5663
5695
|
appState: state,
|
5664
5696
|
parent
|
@@ -5669,7 +5701,7 @@ var useResolvedFields = () => {
|
|
5669
5701
|
return yield config.root.resolveFields(componentData, {
|
5670
5702
|
changed,
|
5671
5703
|
fields,
|
5672
|
-
lastFields:
|
5704
|
+
lastFields: lastFields.current,
|
5673
5705
|
lastData,
|
5674
5706
|
appState: state,
|
5675
5707
|
parent
|
@@ -5678,40 +5710,56 @@ var useResolvedFields = () => {
|
|
5678
5710
|
return defaultResolveFields(componentData, {
|
5679
5711
|
changed,
|
5680
5712
|
fields,
|
5681
|
-
lastFields:
|
5713
|
+
lastFields: lastFields.current,
|
5682
5714
|
lastData
|
5683
5715
|
});
|
5684
5716
|
}),
|
5685
|
-
[data, config, componentData, selectedItem,
|
5717
|
+
[data, config, componentData, selectedItem, state, parent]
|
5686
5718
|
);
|
5687
|
-
const
|
5688
|
-
(0, import_react35.useEffect)(() => {
|
5689
|
-
setHasParent(!!parent);
|
5690
|
-
}, [parent]);
|
5691
|
-
(0, import_react35.useEffect)(() => {
|
5719
|
+
const triggerResolver = (0, import_react36.useCallback)(() => {
|
5692
5720
|
var _a2, _b2;
|
5693
|
-
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" ||
|
5721
|
+
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" || parent) {
|
5694
5722
|
if (hasResolver) {
|
5695
5723
|
setFieldsLoading(true);
|
5696
5724
|
resolveFields(defaultFields).then((fields) => {
|
5697
5725
|
setResolvedFields(fields || {});
|
5726
|
+
lastFields.current = fields;
|
5698
5727
|
setFieldsLoading(false);
|
5699
5728
|
});
|
5700
|
-
|
5701
|
-
setResolvedFields(defaultFields);
|
5729
|
+
return;
|
5702
5730
|
}
|
5703
5731
|
}
|
5704
|
-
|
5705
|
-
|
5706
|
-
|
5732
|
+
setResolvedFields(defaultFields);
|
5733
|
+
}, [defaultFields, state.ui.itemSelector, hasResolver, parent]);
|
5734
|
+
useOnValueChange(
|
5707
5735
|
state.ui.itemSelector,
|
5708
|
-
|
5709
|
-
|
5710
|
-
|
5711
|
-
|
5736
|
+
() => {
|
5737
|
+
lastFields.current = defaultFields;
|
5738
|
+
},
|
5739
|
+
selectorIs
|
5740
|
+
);
|
5741
|
+
useOnValueChange(
|
5742
|
+
{ data, parent, itemSelector: state.ui.itemSelector },
|
5743
|
+
() => {
|
5744
|
+
triggerResolver();
|
5745
|
+
},
|
5746
|
+
(a, b) => JSON.stringify(a) === JSON.stringify(b)
|
5747
|
+
);
|
5748
|
+
(0, import_react36.useEffect)(() => {
|
5749
|
+
triggerResolver();
|
5750
|
+
}, []);
|
5712
5751
|
return [resolvedFields, fieldsLoading];
|
5713
5752
|
};
|
5714
|
-
|
5753
|
+
|
5754
|
+
// components/Puck/components/Fields/index.tsx
|
5755
|
+
var import_jsx_runtime27 = require("react/jsx-runtime");
|
5756
|
+
var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
|
5757
|
+
var DefaultFields = ({
|
5758
|
+
children
|
5759
|
+
}) => {
|
5760
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_jsx_runtime27.Fragment, { children });
|
5761
|
+
};
|
5762
|
+
var Fields = ({ wrapFields = true }) => {
|
5715
5763
|
var _a, _b;
|
5716
5764
|
const {
|
5717
5765
|
selectedItem,
|
@@ -5729,11 +5777,11 @@ var Fields = () => {
|
|
5729
5777
|
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;
|
5730
5778
|
const isLoading = fieldsResolving || componentResolving;
|
5731
5779
|
const rootProps = data.root.props || data.root;
|
5732
|
-
const Wrapper = (0,
|
5780
|
+
const Wrapper = (0, import_react37.useMemo)(() => overrides.fields || DefaultFields, [overrides]);
|
5733
5781
|
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
|
5734
5782
|
"form",
|
5735
5783
|
{
|
5736
|
-
className: getClassName21(),
|
5784
|
+
className: getClassName21({ wrapFields }),
|
5737
5785
|
onSubmit: (e) => {
|
5738
5786
|
e.preventDefault();
|
5739
5787
|
},
|
@@ -5809,7 +5857,7 @@ var Fields = () => {
|
|
5809
5857
|
item: selectedItem
|
5810
5858
|
});
|
5811
5859
|
const id = `${selectedItem.props.id}_${field.type}_${fieldName}`;
|
5812
|
-
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
5860
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: getClassName21("field"), children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
5813
5861
|
AutoFieldPrivate,
|
5814
5862
|
{
|
5815
5863
|
field,
|
@@ -5818,16 +5866,15 @@ var Fields = () => {
|
|
5818
5866
|
readOnly: !edit || readOnly[fieldName],
|
5819
5867
|
value: selectedItem.props[fieldName],
|
5820
5868
|
onChange
|
5821
|
-
}
|
5822
|
-
|
5823
|
-
);
|
5869
|
+
}
|
5870
|
+
) }, id);
|
5824
5871
|
} else {
|
5825
5872
|
const readOnly = data.root.readOnly || {};
|
5826
5873
|
const { edit } = getPermissions({
|
5827
5874
|
root: true
|
5828
5875
|
});
|
5829
5876
|
const id = `root_${field.type}_${fieldName}`;
|
5830
|
-
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
5877
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: getClassName21("field"), children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
5831
5878
|
AutoFieldPrivate,
|
5832
5879
|
{
|
5833
5880
|
field,
|
@@ -5836,9 +5883,8 @@ var Fields = () => {
|
|
5836
5883
|
readOnly: !edit || readOnly[fieldName],
|
5837
5884
|
value: rootProps[fieldName],
|
5838
5885
|
onChange
|
5839
|
-
}
|
5840
|
-
|
5841
|
-
);
|
5886
|
+
}
|
5887
|
+
) }, id);
|
5842
5888
|
}
|
5843
5889
|
}) }),
|
5844
5890
|
isLoading && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: getClassName21("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: getClassName21("loadingOverlayInner"), children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Loader, { size: 16 }) }) })
|
@@ -5852,7 +5898,7 @@ init_react_import();
|
|
5852
5898
|
|
5853
5899
|
// lib/use-component-list.tsx
|
5854
5900
|
init_react_import();
|
5855
|
-
var
|
5901
|
+
var import_react38 = require("react");
|
5856
5902
|
|
5857
5903
|
// components/ComponentList/index.tsx
|
5858
5904
|
init_react_import();
|
@@ -5919,8 +5965,8 @@ ComponentList.Item = ComponentListItem;
|
|
5919
5965
|
// lib/use-component-list.tsx
|
5920
5966
|
var import_jsx_runtime29 = require("react/jsx-runtime");
|
5921
5967
|
var useComponentList = (config, ui) => {
|
5922
|
-
const [componentList, setComponentList] = (0,
|
5923
|
-
(0,
|
5968
|
+
const [componentList, setComponentList] = (0, import_react38.useState)();
|
5969
|
+
(0, import_react38.useEffect)(() => {
|
5924
5970
|
var _a, _b, _c;
|
5925
5971
|
if (Object.keys(ui.componentList).length > 0) {
|
5926
5972
|
const matchedComponents = [];
|
@@ -5989,22 +6035,22 @@ var useComponentList = (config, ui) => {
|
|
5989
6035
|
};
|
5990
6036
|
|
5991
6037
|
// components/Puck/components/Components/index.tsx
|
5992
|
-
var
|
6038
|
+
var import_react39 = require("react");
|
5993
6039
|
var import_jsx_runtime30 = require("react/jsx-runtime");
|
5994
6040
|
var Components = () => {
|
5995
6041
|
const { config, state, overrides } = useAppContext();
|
5996
6042
|
const componentList = useComponentList(config, state.ui);
|
5997
|
-
const Wrapper = (0,
|
6043
|
+
const Wrapper = (0, import_react39.useMemo)(() => overrides.components || "div", [overrides]);
|
5998
6044
|
return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(ComponentList, { id: "all" }) });
|
5999
6045
|
};
|
6000
6046
|
|
6001
6047
|
// components/Puck/components/Preview/index.tsx
|
6002
6048
|
init_react_import();
|
6003
|
-
var
|
6049
|
+
var import_react41 = require("react");
|
6004
6050
|
|
6005
6051
|
// components/AutoFrame/index.tsx
|
6006
6052
|
init_react_import();
|
6007
|
-
var
|
6053
|
+
var import_react40 = require("react");
|
6008
6054
|
var import_object_hash = __toESM(require("object-hash"));
|
6009
6055
|
var import_react_dom3 = require("react-dom");
|
6010
6056
|
var import_jsx_runtime31 = require("react/jsx-runtime");
|
@@ -6050,7 +6096,7 @@ var CopyHostStyles = ({
|
|
6050
6096
|
onStylesLoaded = () => null
|
6051
6097
|
}) => {
|
6052
6098
|
const { document: doc, window: win } = useFrame();
|
6053
|
-
(0,
|
6099
|
+
(0, import_react40.useEffect)(() => {
|
6054
6100
|
if (!win || !doc) {
|
6055
6101
|
return () => {
|
6056
6102
|
};
|
@@ -6209,8 +6255,8 @@ var CopyHostStyles = ({
|
|
6209
6255
|
}, []);
|
6210
6256
|
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_jsx_runtime31.Fragment, { children });
|
6211
6257
|
};
|
6212
|
-
var autoFrameContext = (0,
|
6213
|
-
var useFrame = () => (0,
|
6258
|
+
var autoFrameContext = (0, import_react40.createContext)({});
|
6259
|
+
var useFrame = () => (0, import_react40.useContext)(autoFrameContext);
|
6214
6260
|
function AutoFrame(_a) {
|
6215
6261
|
var _b = _a, {
|
6216
6262
|
children,
|
@@ -6227,10 +6273,10 @@ function AutoFrame(_a) {
|
|
6227
6273
|
"onStylesLoaded",
|
6228
6274
|
"frameRef"
|
6229
6275
|
]);
|
6230
|
-
const [loaded, setLoaded] = (0,
|
6231
|
-
const [ctx, setCtx] = (0,
|
6232
|
-
const [mountTarget, setMountTarget] = (0,
|
6233
|
-
(0,
|
6276
|
+
const [loaded, setLoaded] = (0, import_react40.useState)(false);
|
6277
|
+
const [ctx, setCtx] = (0, import_react40.useState)({});
|
6278
|
+
const [mountTarget, setMountTarget] = (0, import_react40.useState)();
|
6279
|
+
(0, import_react40.useEffect)(() => {
|
6234
6280
|
var _a2;
|
6235
6281
|
if (frameRef.current) {
|
6236
6282
|
setCtx({
|
@@ -6324,7 +6370,7 @@ var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
6324
6370
|
var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
|
6325
6371
|
var useBubbleIframeEvents = (ref) => {
|
6326
6372
|
const { status } = useAppContext();
|
6327
|
-
(0,
|
6373
|
+
(0, import_react41.useEffect)(() => {
|
6328
6374
|
var _a;
|
6329
6375
|
if (ref.current && status === "READY") {
|
6330
6376
|
const iframe = ref.current;
|
@@ -6363,7 +6409,7 @@ var useBubbleIframeEvents = (ref) => {
|
|
6363
6409
|
};
|
6364
6410
|
var Preview2 = ({ id = "puck-preview" }) => {
|
6365
6411
|
const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
|
6366
|
-
const Page = (0,
|
6412
|
+
const Page = (0, import_react41.useCallback)(
|
6367
6413
|
(pageProps) => {
|
6368
6414
|
var _a, _b;
|
6369
6415
|
return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
|
@@ -6372,9 +6418,9 @@ var Preview2 = ({ id = "puck-preview" }) => {
|
|
6372
6418
|
},
|
6373
6419
|
[config.root]
|
6374
6420
|
);
|
6375
|
-
const Frame = (0,
|
6421
|
+
const Frame = (0, import_react41.useMemo)(() => overrides.iframe, [overrides]);
|
6376
6422
|
const rootProps = state.data.root.props || state.data.root;
|
6377
|
-
const ref = (0,
|
6423
|
+
const ref = (0, import_react41.useRef)(null);
|
6378
6424
|
useBubbleIframeEvents(ref);
|
6379
6425
|
const inner = state.ui.previewMode === "edit" ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
|
6380
6426
|
Page,
|
@@ -6471,7 +6517,7 @@ var scrollIntoView = (el) => {
|
|
6471
6517
|
};
|
6472
6518
|
|
6473
6519
|
// components/LayerTree/index.tsx
|
6474
|
-
var
|
6520
|
+
var import_react42 = require("react");
|
6475
6521
|
|
6476
6522
|
// lib/is-child-of-zone.ts
|
6477
6523
|
init_react_import();
|
@@ -6517,7 +6563,7 @@ var LayerTree = ({
|
|
6517
6563
|
label
|
6518
6564
|
}) => {
|
6519
6565
|
const zones = data.zones || {};
|
6520
|
-
const ctx = (0,
|
6566
|
+
const ctx = (0, import_react42.useContext)(dropZoneContext);
|
6521
6567
|
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
|
6522
6568
|
label && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: getClassName24("zoneTitle"), children: [
|
6523
6569
|
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Layers, { size: "16" }) }),
|
@@ -6624,13 +6670,13 @@ var LayerTree = ({
|
|
6624
6670
|
};
|
6625
6671
|
|
6626
6672
|
// components/Puck/components/Outline/index.tsx
|
6627
|
-
var
|
6673
|
+
var import_react43 = require("react");
|
6628
6674
|
var import_jsx_runtime35 = require("react/jsx-runtime");
|
6629
6675
|
var Outline = () => {
|
6630
6676
|
const { dispatch, state, overrides, config } = useAppContext();
|
6631
6677
|
const { data, ui } = state;
|
6632
6678
|
const { itemSelector } = ui;
|
6633
|
-
const setItemSelector = (0,
|
6679
|
+
const setItemSelector = (0, import_react43.useCallback)(
|
6634
6680
|
(newItemSelector) => {
|
6635
6681
|
dispatch({
|
6636
6682
|
type: "setUi",
|
@@ -6639,7 +6685,7 @@ var Outline = () => {
|
|
6639
6685
|
},
|
6640
6686
|
[]
|
6641
6687
|
);
|
6642
|
-
const Wrapper = (0,
|
6688
|
+
const Wrapper = (0, import_react43.useMemo)(() => overrides.outline || "div", [overrides]);
|
6643
6689
|
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: [
|
6644
6690
|
(ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
|
6645
6691
|
LayerTree,
|
@@ -6753,19 +6799,19 @@ function usePuckHistory({
|
|
6753
6799
|
|
6754
6800
|
// lib/use-history-store.ts
|
6755
6801
|
init_react_import();
|
6756
|
-
var
|
6802
|
+
var import_react44 = require("react");
|
6757
6803
|
var import_use_debounce3 = require("use-debounce");
|
6758
6804
|
var EMPTY_HISTORY_INDEX = 0;
|
6759
6805
|
function useHistoryStore(initialHistory) {
|
6760
6806
|
var _a, _b;
|
6761
|
-
const [histories, setHistories] = (0,
|
6807
|
+
const [histories, setHistories] = (0, import_react44.useState)(
|
6762
6808
|
(_a = initialHistory == null ? void 0 : initialHistory.histories) != null ? _a : []
|
6763
6809
|
);
|
6764
6810
|
const updateHistories = (histories2) => {
|
6765
6811
|
setHistories(histories2);
|
6766
6812
|
setIndex(histories2.length - 1);
|
6767
6813
|
};
|
6768
|
-
const [index, setIndex] = (0,
|
6814
|
+
const [index, setIndex] = (0, import_react44.useState)(
|
6769
6815
|
(_b = initialHistory == null ? void 0 : initialHistory.index) != null ? _b : EMPTY_HISTORY_INDEX
|
6770
6816
|
);
|
6771
6817
|
const hasPast = index > EMPTY_HISTORY_INDEX;
|
@@ -6925,11 +6971,11 @@ var getBox = function getBox2(el) {
|
|
6925
6971
|
};
|
6926
6972
|
|
6927
6973
|
// components/Puck/components/Canvas/index.tsx
|
6928
|
-
var
|
6974
|
+
var import_react46 = require("react");
|
6929
6975
|
|
6930
6976
|
// components/ViewportControls/index.tsx
|
6931
6977
|
init_react_import();
|
6932
|
-
var
|
6978
|
+
var import_react45 = require("react");
|
6933
6979
|
|
6934
6980
|
// css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
|
6935
6981
|
init_react_import();
|
@@ -6952,8 +6998,8 @@ var ViewportButton = ({
|
|
6952
6998
|
onClick
|
6953
6999
|
}) => {
|
6954
7000
|
const { state } = useAppContext();
|
6955
|
-
const [isActive, setIsActive] = (0,
|
6956
|
-
(0,
|
7001
|
+
const [isActive, setIsActive] = (0, import_react45.useState)(false);
|
7002
|
+
(0, import_react45.useEffect)(() => {
|
6957
7003
|
setIsActive(width === state.ui.viewports.current.width);
|
6958
7004
|
}, [width, state.ui.viewports.current.width]);
|
6959
7005
|
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
@@ -6989,7 +7035,7 @@ var ViewportControls = ({
|
|
6989
7035
|
const defaultsContainAutoZoom = defaultZoomOptions.find(
|
6990
7036
|
(option) => option.value === autoZoom
|
6991
7037
|
);
|
6992
|
-
const zoomOptions = (0,
|
7038
|
+
const zoomOptions = (0, import_react45.useMemo)(
|
6993
7039
|
() => [
|
6994
7040
|
...defaultZoomOptions,
|
6995
7041
|
...defaultsContainAutoZoom ? [] : [
|
@@ -7112,17 +7158,17 @@ var Canvas = () => {
|
|
7112
7158
|
const { status, iframe } = useAppContext();
|
7113
7159
|
const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
|
7114
7160
|
const { ui } = state;
|
7115
|
-
const frameRef = (0,
|
7116
|
-
const [showTransition, setShowTransition] = (0,
|
7117
|
-
const defaultRender = (0,
|
7161
|
+
const frameRef = (0, import_react46.useRef)(null);
|
7162
|
+
const [showTransition, setShowTransition] = (0, import_react46.useState)(false);
|
7163
|
+
const defaultRender = (0, import_react46.useMemo)(() => {
|
7118
7164
|
const PuckDefault = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_jsx_runtime37.Fragment, { children });
|
7119
7165
|
return PuckDefault;
|
7120
7166
|
}, []);
|
7121
|
-
const CustomPreview = (0,
|
7167
|
+
const CustomPreview = (0, import_react46.useMemo)(
|
7122
7168
|
() => overrides.preview || defaultRender,
|
7123
7169
|
[overrides]
|
7124
7170
|
);
|
7125
|
-
const getFrameDimensions = (0,
|
7171
|
+
const getFrameDimensions = (0, import_react46.useCallback)(() => {
|
7126
7172
|
if (frameRef.current) {
|
7127
7173
|
const frame = frameRef.current;
|
7128
7174
|
const box = getBox(frame);
|
@@ -7130,7 +7176,7 @@ var Canvas = () => {
|
|
7130
7176
|
}
|
7131
7177
|
return { width: 0, height: 0 };
|
7132
7178
|
}, [frameRef]);
|
7133
|
-
const resetAutoZoom = (0,
|
7179
|
+
const resetAutoZoom = (0, import_react46.useCallback)(
|
7134
7180
|
(ui2 = state.ui) => {
|
7135
7181
|
if (frameRef.current) {
|
7136
7182
|
setZoomConfig(
|
@@ -7140,11 +7186,11 @@ var Canvas = () => {
|
|
7140
7186
|
},
|
7141
7187
|
[frameRef, zoomConfig, state.ui]
|
7142
7188
|
);
|
7143
|
-
(0,
|
7189
|
+
(0, import_react46.useEffect)(() => {
|
7144
7190
|
setShowTransition(false);
|
7145
7191
|
resetAutoZoom();
|
7146
7192
|
}, [frameRef, ui.leftSideBarVisible, ui.rightSideBarVisible]);
|
7147
|
-
(0,
|
7193
|
+
(0, import_react46.useEffect)(() => {
|
7148
7194
|
const { height: frameHeight } = getFrameDimensions();
|
7149
7195
|
if (ui.viewports.current.height === "auto") {
|
7150
7196
|
setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
|
@@ -7152,13 +7198,13 @@ var Canvas = () => {
|
|
7152
7198
|
}));
|
7153
7199
|
}
|
7154
7200
|
}, [zoomConfig.zoom]);
|
7155
|
-
(0,
|
7201
|
+
(0, import_react46.useEffect)(() => {
|
7156
7202
|
if (ZOOM_ON_CHANGE) {
|
7157
7203
|
setShowTransition(true);
|
7158
7204
|
resetAutoZoom(ui);
|
7159
7205
|
}
|
7160
7206
|
}, [ui.viewports.current.width]);
|
7161
|
-
(0,
|
7207
|
+
(0, import_react46.useEffect)(() => {
|
7162
7208
|
const cb = () => {
|
7163
7209
|
setShowTransition(false);
|
7164
7210
|
resetAutoZoom();
|
@@ -7168,8 +7214,8 @@ var Canvas = () => {
|
|
7168
7214
|
window.removeEventListener("resize", cb);
|
7169
7215
|
};
|
7170
7216
|
}, []);
|
7171
|
-
const [showLoader, setShowLoader] = (0,
|
7172
|
-
(0,
|
7217
|
+
const [showLoader, setShowLoader] = (0, import_react46.useState)(false);
|
7218
|
+
(0, import_react46.useEffect)(() => {
|
7173
7219
|
setTimeout(() => {
|
7174
7220
|
setShowLoader(true);
|
7175
7221
|
}, 500);
|
@@ -7247,7 +7293,7 @@ var Canvas = () => {
|
|
7247
7293
|
|
7248
7294
|
// lib/use-loaded-overrides.ts
|
7249
7295
|
init_react_import();
|
7250
|
-
var
|
7296
|
+
var import_react47 = require("react");
|
7251
7297
|
|
7252
7298
|
// lib/load-overrides.ts
|
7253
7299
|
init_react_import();
|
@@ -7286,7 +7332,7 @@ var useLoadedOverrides = ({
|
|
7286
7332
|
overrides,
|
7287
7333
|
plugins
|
7288
7334
|
}) => {
|
7289
|
-
return (0,
|
7335
|
+
return (0, import_react47.useMemo)(() => {
|
7290
7336
|
return loadOverrides({ overrides, plugins });
|
7291
7337
|
}, [plugins, overrides]);
|
7292
7338
|
};
|
@@ -7298,14 +7344,14 @@ var DefaultOverride = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime38
|
|
7298
7344
|
|
7299
7345
|
// lib/use-inject-css.ts
|
7300
7346
|
init_react_import();
|
7301
|
-
var
|
7347
|
+
var import_react48 = require("react");
|
7302
7348
|
var styles = ``;
|
7303
7349
|
var useInjectStyleSheet = (initialStyles, iframeEnabled) => {
|
7304
|
-
const [el, setEl] = (0,
|
7305
|
-
(0,
|
7350
|
+
const [el, setEl] = (0, import_react48.useState)();
|
7351
|
+
(0, import_react48.useEffect)(() => {
|
7306
7352
|
setEl(document.createElement("style"));
|
7307
7353
|
}, []);
|
7308
|
-
(0,
|
7354
|
+
(0, import_react48.useEffect)(() => {
|
7309
7355
|
var _a;
|
7310
7356
|
if (!el || typeof window === "undefined") {
|
7311
7357
|
return;
|
@@ -7325,10 +7371,10 @@ var useInjectGlobalCss = (iframeEnabled) => {
|
|
7325
7371
|
|
7326
7372
|
// lib/use-preview-mode-hotkeys.ts
|
7327
7373
|
init_react_import();
|
7328
|
-
var
|
7374
|
+
var import_react49 = require("react");
|
7329
7375
|
var import_react_hotkeys_hook2 = require("react-hotkeys-hook");
|
7330
7376
|
var usePreviewModeHotkeys = (dispatch, iframeEnabled) => {
|
7331
|
-
const toggleInteractive = (0,
|
7377
|
+
const toggleInteractive = (0, import_react49.useCallback)(() => {
|
7332
7378
|
dispatch({
|
7333
7379
|
type: "setUi",
|
7334
7380
|
ui: (ui) => ({
|
@@ -7380,7 +7426,7 @@ function Puck({
|
|
7380
7426
|
waitForStyles: true
|
7381
7427
|
}, _iframe);
|
7382
7428
|
useInjectGlobalCss(iframe.enabled);
|
7383
|
-
const [generatedAppState] = (0,
|
7429
|
+
const [generatedAppState] = (0, import_react50.useState)(() => {
|
7384
7430
|
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
7385
7431
|
const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
|
7386
7432
|
let clientUiState = {};
|
@@ -7452,14 +7498,14 @@ function Puck({
|
|
7452
7498
|
histories,
|
7453
7499
|
index: initialHistoryIndex
|
7454
7500
|
});
|
7455
|
-
const [reducer] = (0,
|
7501
|
+
const [reducer] = (0, import_react50.useState)(
|
7456
7502
|
() => createReducer({
|
7457
7503
|
config,
|
7458
7504
|
record: historyStore.record,
|
7459
7505
|
onAction
|
7460
7506
|
})
|
7461
7507
|
);
|
7462
|
-
const [appState, dispatch] = (0,
|
7508
|
+
const [appState, dispatch] = (0, import_react50.useReducer)(
|
7463
7509
|
reducer,
|
7464
7510
|
flushZones(initialAppState)
|
7465
7511
|
);
|
@@ -7470,14 +7516,14 @@ function Puck({
|
|
7470
7516
|
historyStore,
|
7471
7517
|
iframeEnabled: (_a = _iframe == null ? void 0 : _iframe.enabled) != null ? _a : true
|
7472
7518
|
});
|
7473
|
-
const [menuOpen, setMenuOpen] = (0,
|
7519
|
+
const [menuOpen, setMenuOpen] = (0, import_react50.useState)(false);
|
7474
7520
|
const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
|
7475
7521
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
7476
|
-
(0,
|
7522
|
+
(0, import_react50.useEffect)(() => {
|
7477
7523
|
if (onChange) onChange(data);
|
7478
7524
|
}, [data]);
|
7479
7525
|
const rootProps = data.root.props || data.root;
|
7480
|
-
const toggleSidebars = (0,
|
7526
|
+
const toggleSidebars = (0, import_react50.useCallback)(
|
7481
7527
|
(sidebar) => {
|
7482
7528
|
const widerViewport = window.matchMedia("(min-width: 638px)").matches;
|
7483
7529
|
const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
|
@@ -7491,7 +7537,7 @@ function Puck({
|
|
7491
7537
|
},
|
7492
7538
|
[dispatch, leftSideBarVisible, rightSideBarVisible]
|
7493
7539
|
);
|
7494
|
-
(0,
|
7540
|
+
(0, import_react50.useEffect)(() => {
|
7495
7541
|
if (!window.matchMedia("(min-width: 638px)").matches) {
|
7496
7542
|
dispatch({
|
7497
7543
|
type: "setUi",
|
@@ -7514,7 +7560,7 @@ function Puck({
|
|
7514
7560
|
window.removeEventListener("resize", handleResize);
|
7515
7561
|
};
|
7516
7562
|
}, []);
|
7517
|
-
const defaultHeaderRender = (0,
|
7563
|
+
const defaultHeaderRender = (0, import_react50.useMemo)(() => {
|
7518
7564
|
if (renderHeader) {
|
7519
7565
|
console.warn(
|
7520
7566
|
"`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
|
@@ -7528,7 +7574,7 @@ function Puck({
|
|
7528
7574
|
}
|
7529
7575
|
return DefaultOverride;
|
7530
7576
|
}, [renderHeader]);
|
7531
|
-
const defaultHeaderActionsRender = (0,
|
7577
|
+
const defaultHeaderActionsRender = (0, import_react50.useMemo)(() => {
|
7532
7578
|
if (renderHeaderActions) {
|
7533
7579
|
console.warn(
|
7534
7580
|
"`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
|
@@ -7545,20 +7591,20 @@ function Puck({
|
|
7545
7591
|
overrides,
|
7546
7592
|
plugins
|
7547
7593
|
});
|
7548
|
-
const CustomPuck = (0,
|
7594
|
+
const CustomPuck = (0, import_react50.useMemo)(
|
7549
7595
|
() => loadedOverrides.puck || DefaultOverride,
|
7550
7596
|
[loadedOverrides]
|
7551
7597
|
);
|
7552
|
-
const CustomHeader = (0,
|
7598
|
+
const CustomHeader = (0, import_react50.useMemo)(
|
7553
7599
|
() => loadedOverrides.header || defaultHeaderRender,
|
7554
7600
|
[loadedOverrides]
|
7555
7601
|
);
|
7556
|
-
const CustomHeaderActions = (0,
|
7602
|
+
const CustomHeaderActions = (0, import_react50.useMemo)(
|
7557
7603
|
() => loadedOverrides.headerActions || defaultHeaderActionsRender,
|
7558
7604
|
[loadedOverrides]
|
7559
7605
|
);
|
7560
|
-
const [mounted, setMounted] = (0,
|
7561
|
-
(0,
|
7606
|
+
const [mounted, setMounted] = (0, import_react50.useState)(false);
|
7607
|
+
(0, import_react50.useEffect)(() => {
|
7562
7608
|
setMounted(true);
|
7563
7609
|
}, []);
|
7564
7610
|
const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
|