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