@measured/puck 0.18.0-canary.1f76f81 → 0.18.0-canary.29e5580
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/dist/index.css +1 -0
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +197 -128
- package/dist/index.mjs +188 -119
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -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);
|
@@ -3255,13 +3256,19 @@ var DraggableComponent = ({
|
|
3255
3256
|
}
|
3256
3257
|
}, [ref.current]);
|
3257
3258
|
(0, import_react23.useEffect)(() => {
|
3258
|
-
|
3259
|
-
|
3259
|
+
ctx == null ? void 0 : ctx.registerPath(
|
3260
|
+
id,
|
3261
|
+
{
|
3260
3262
|
index,
|
3261
3263
|
zone: zoneCompound
|
3262
|
-
}
|
3263
|
-
|
3264
|
-
|
3264
|
+
},
|
3265
|
+
componentType
|
3266
|
+
);
|
3267
|
+
return () => {
|
3268
|
+
var _a;
|
3269
|
+
(_a = ctx == null ? void 0 : ctx.unregisterPath) == null ? void 0 : _a.call(ctx, id);
|
3270
|
+
};
|
3271
|
+
}, [id, zoneCompound, index, componentType]);
|
3265
3272
|
const CustomActionBar = (0, import_react23.useMemo)(
|
3266
3273
|
() => overrides.actionBar || DefaultActionBar,
|
3267
3274
|
[overrides.actionBar]
|
@@ -3581,9 +3588,20 @@ var useContentWithPreview = (content, zoneCompound) => {
|
|
3581
3588
|
};
|
3582
3589
|
}
|
3583
3590
|
);
|
3591
|
+
const {
|
3592
|
+
state: {
|
3593
|
+
ui: { isDragging }
|
3594
|
+
}
|
3595
|
+
} = useAppContext();
|
3584
3596
|
const [contentWithPreview, setContentWithPreview] = (0, import_react27.useState)(content);
|
3597
|
+
const [localPreview, setLocalPreview] = (0, import_react27.useState)(
|
3598
|
+
preview
|
3599
|
+
);
|
3585
3600
|
const updateContent = useRenderedCallback(
|
3586
|
-
(content2, preview2) => {
|
3601
|
+
(content2, preview2, isDragging2) => {
|
3602
|
+
if (isDragging2 && !previewExists) {
|
3603
|
+
return;
|
3604
|
+
}
|
3587
3605
|
if (preview2) {
|
3588
3606
|
if (preview2.type === "insert") {
|
3589
3607
|
setContentWithPreview(
|
@@ -3613,13 +3631,14 @@ var useContentWithPreview = (content, zoneCompound) => {
|
|
3613
3631
|
previewExists ? content2.filter((item) => item.props.id !== draggedItemId) : content2
|
3614
3632
|
);
|
3615
3633
|
}
|
3634
|
+
setLocalPreview(preview2);
|
3616
3635
|
},
|
3617
3636
|
[draggedItemId, previewExists]
|
3618
3637
|
);
|
3619
3638
|
(0, import_react27.useEffect)(() => {
|
3620
|
-
updateContent(content, preview);
|
3621
|
-
}, [content, preview]);
|
3622
|
-
return contentWithPreview;
|
3639
|
+
updateContent(content, preview, isDragging);
|
3640
|
+
}, [content, preview, isDragging]);
|
3641
|
+
return [contentWithPreview, localPreview];
|
3623
3642
|
};
|
3624
3643
|
|
3625
3644
|
// components/DropZone/lib/use-drag-axis.ts
|
@@ -3699,8 +3718,7 @@ var DropZoneEdit = (0, import_react29.forwardRef)(
|
|
3699
3718
|
isDeepestZone,
|
3700
3719
|
inNextDeepestArea,
|
3701
3720
|
draggedComponentType,
|
3702
|
-
userIsDragging
|
3703
|
-
preview
|
3721
|
+
userIsDragging
|
3704
3722
|
} = useContextStore(ZoneStoreContext, (s) => {
|
3705
3723
|
var _a, _b, _c;
|
3706
3724
|
return {
|
@@ -3708,8 +3726,7 @@ var DropZoneEdit = (0, import_react29.forwardRef)(
|
|
3708
3726
|
inNextDeepestArea: s.nextAreaDepthIndex[areaId || ""],
|
3709
3727
|
draggedItemId: (_b = s.draggedItem) == null ? void 0 : _b.id,
|
3710
3728
|
draggedComponentType: (_c = s.draggedItem) == null ? void 0 : _c.data.componentType,
|
3711
|
-
userIsDragging: !!s.draggedItem
|
3712
|
-
preview: s.previewIndex[zoneCompound]
|
3729
|
+
userIsDragging: !!s.draggedItem
|
3713
3730
|
};
|
3714
3731
|
});
|
3715
3732
|
const { itemSelector } = appContext2.state.ui;
|
@@ -3775,7 +3792,10 @@ var DropZoneEdit = (0, import_react29.forwardRef)(
|
|
3775
3792
|
if (isEnabled) {
|
3776
3793
|
isEnabled = acceptsTarget(draggedComponentType);
|
3777
3794
|
}
|
3778
|
-
const contentWithPreview = useContentWithPreview(
|
3795
|
+
const [contentWithPreview, preview] = useContentWithPreview(
|
3796
|
+
content,
|
3797
|
+
zoneCompound
|
3798
|
+
);
|
3779
3799
|
const isDropEnabled = isEnabled && (preview ? contentWithPreview.length === 1 : contentWithPreview.length === 0);
|
3780
3800
|
const droppableConfig = {
|
3781
3801
|
id: zoneCompound,
|
@@ -3820,7 +3840,7 @@ var DropZoneEdit = (0, import_react29.forwardRef)(
|
|
3820
3840
|
"data-puck-dnd": zoneCompound,
|
3821
3841
|
style: __spreadProps(__spreadValues({}, style), {
|
3822
3842
|
"--min-empty-height": `${minEmptyHeight}px`,
|
3823
|
-
backgroundColor: RENDER_DEBUG ? getRandomColor() : void 0
|
3843
|
+
backgroundColor: RENDER_DEBUG ? getRandomColor() : style == null ? void 0 : style.backgroundColor
|
3824
3844
|
}),
|
3825
3845
|
children: contentWithPreview.map((item, i) => {
|
3826
3846
|
var _a, _b, _c, _d, _e, _f, _g;
|
@@ -5043,27 +5063,33 @@ var DragDropContextClient = ({
|
|
5043
5063
|
const [pathData, setPathData] = (0, import_react31.useState)();
|
5044
5064
|
const dragMode = (0, import_react31.useRef)(null);
|
5045
5065
|
const registerPath = (0, import_react31.useCallback)(
|
5046
|
-
(selector) => {
|
5047
|
-
const item = getItem(selector, data);
|
5048
|
-
if (!item) {
|
5049
|
-
return;
|
5050
|
-
}
|
5066
|
+
(id2, selector, label) => {
|
5051
5067
|
const [area] = getZoneId(selector.zone);
|
5052
5068
|
setPathData((latestPathData = {}) => {
|
5053
5069
|
const parentPathData = latestPathData[area] || { path: [] };
|
5054
5070
|
return __spreadProps(__spreadValues({}, latestPathData), {
|
5055
|
-
[
|
5071
|
+
[id2]: {
|
5056
5072
|
path: [
|
5057
5073
|
...parentPathData.path,
|
5058
5074
|
...selector.zone ? [selector.zone] : []
|
5059
5075
|
],
|
5060
|
-
label
|
5076
|
+
label
|
5061
5077
|
}
|
5062
5078
|
});
|
5063
5079
|
});
|
5064
5080
|
},
|
5065
5081
|
[data, setPathData]
|
5066
5082
|
);
|
5083
|
+
const unregisterPath = (0, import_react31.useCallback)(
|
5084
|
+
(id2) => {
|
5085
|
+
setPathData((latestPathData = {}) => {
|
5086
|
+
const newPathData = __spreadValues({}, latestPathData);
|
5087
|
+
delete newPathData[id2];
|
5088
|
+
return newPathData;
|
5089
|
+
});
|
5090
|
+
},
|
5091
|
+
[data, setPathData]
|
5092
|
+
);
|
5067
5093
|
const initialSelector = (0, import_react31.useRef)(void 0);
|
5068
5094
|
return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)("div", { id, children: /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
5069
5095
|
dragListenerContext.Provider,
|
@@ -5260,6 +5286,7 @@ var DragDropContextClient = ({
|
|
5260
5286
|
areaId: "root",
|
5261
5287
|
depth: 0,
|
5262
5288
|
registerPath,
|
5289
|
+
unregisterPath,
|
5263
5290
|
pathData,
|
5264
5291
|
path: []
|
5265
5292
|
},
|
@@ -5408,7 +5435,7 @@ Drawer.Item = DrawerItem;
|
|
5408
5435
|
|
5409
5436
|
// components/Puck/index.tsx
|
5410
5437
|
init_react_import();
|
5411
|
-
var
|
5438
|
+
var import_react50 = require("react");
|
5412
5439
|
|
5413
5440
|
// components/SidebarSection/index.tsx
|
5414
5441
|
init_react_import();
|
@@ -5604,33 +5631,58 @@ init_react_import();
|
|
5604
5631
|
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" };
|
5605
5632
|
|
5606
5633
|
// components/Puck/components/Fields/index.tsx
|
5607
|
-
var
|
5634
|
+
var import_react37 = require("react");
|
5635
|
+
|
5636
|
+
// lib/use-resolved-fields.ts
|
5637
|
+
init_react_import();
|
5638
|
+
var import_react36 = require("react");
|
5608
5639
|
|
5609
5640
|
// lib/use-parent.ts
|
5610
5641
|
init_react_import();
|
5611
5642
|
var import_react34 = require("react");
|
5612
|
-
var
|
5643
|
+
var getParent = (itemSelector, pathData, data) => {
|
5613
5644
|
var _a;
|
5614
|
-
|
5615
|
-
const
|
5616
|
-
const
|
5617
|
-
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, state.data);
|
5645
|
+
if (!itemSelector) return null;
|
5646
|
+
const item = getItem(itemSelector, data);
|
5647
|
+
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, data);
|
5618
5648
|
const lastItem = breadcrumbs[breadcrumbs.length - 1];
|
5619
|
-
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector,
|
5649
|
+
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector, data)) != null ? _a : null : null;
|
5620
5650
|
return parent || null;
|
5621
5651
|
};
|
5652
|
+
var useGetParent = () => {
|
5653
|
+
const { state } = useAppContext();
|
5654
|
+
const { pathData } = (0, import_react34.useContext)(dropZoneContext) || {};
|
5655
|
+
return (0, import_react34.useCallback)(
|
5656
|
+
() => getParent(state.ui.itemSelector, pathData, state.data),
|
5657
|
+
[state.ui.itemSelector, pathData, state.data]
|
5658
|
+
);
|
5659
|
+
};
|
5660
|
+
var useParent = () => {
|
5661
|
+
return useGetParent()();
|
5662
|
+
};
|
5622
5663
|
|
5623
|
-
//
|
5624
|
-
|
5625
|
-
var
|
5664
|
+
// lib/use-on-value-change.ts
|
5665
|
+
init_react_import();
|
5666
|
+
var import_react35 = require("react");
|
5667
|
+
function useOnValueChange(value, onChange, compare = Object.is, deps = []) {
|
5668
|
+
const tracked = (0, import_react35.useRef)(value);
|
5669
|
+
(0, import_react35.useEffect)(() => {
|
5670
|
+
const oldValue = tracked.current;
|
5671
|
+
if (!compare(value, oldValue)) {
|
5672
|
+
tracked.current = value;
|
5673
|
+
onChange(value, oldValue);
|
5674
|
+
}
|
5675
|
+
}, [onChange, compare, value, ...deps]);
|
5676
|
+
}
|
5677
|
+
|
5678
|
+
// lib/selector-is.ts
|
5679
|
+
init_react_import();
|
5680
|
+
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);
|
5681
|
+
|
5682
|
+
// lib/use-resolved-fields.ts
|
5626
5683
|
var defaultPageFields = {
|
5627
5684
|
title: { type: "text" }
|
5628
5685
|
};
|
5629
|
-
var DefaultFields = ({
|
5630
|
-
children
|
5631
|
-
}) => {
|
5632
|
-
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_jsx_runtime27.Fragment, { children });
|
5633
|
-
};
|
5634
5686
|
var useResolvedFields = () => {
|
5635
5687
|
var _a, _b;
|
5636
5688
|
const { selectedItem, state, config } = useAppContext();
|
@@ -5638,20 +5690,21 @@ var useResolvedFields = () => {
|
|
5638
5690
|
const { data } = state;
|
5639
5691
|
const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
|
5640
5692
|
const componentConfig = selectedItem ? config.components[selectedItem.type] : null;
|
5641
|
-
const defaultFields = (0,
|
5693
|
+
const defaultFields = (0, import_react36.useMemo)(
|
5642
5694
|
() => (selectedItem ? componentConfig == null ? void 0 : componentConfig.fields : rootFields) || {},
|
5643
5695
|
[selectedItem, rootFields, componentConfig == null ? void 0 : componentConfig.fields]
|
5644
5696
|
);
|
5645
5697
|
const rootProps = data.root.props || data.root;
|
5646
|
-
const [lastSelectedData, setLastSelectedData] = (0,
|
5647
|
-
const [resolvedFields, setResolvedFields] = (0,
|
5648
|
-
const [fieldsLoading, setFieldsLoading] = (0,
|
5698
|
+
const [lastSelectedData, setLastSelectedData] = (0, import_react36.useState)({});
|
5699
|
+
const [resolvedFields, setResolvedFields] = (0, import_react36.useState)(defaultFields);
|
5700
|
+
const [fieldsLoading, setFieldsLoading] = (0, import_react36.useState)(false);
|
5701
|
+
const lastFields = (0, import_react36.useRef)(defaultFields);
|
5649
5702
|
const defaultResolveFields = (_componentData, _params) => defaultFields;
|
5650
5703
|
const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
|
5651
5704
|
const hasComponentResolver = selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields);
|
5652
5705
|
const hasRootResolver = !selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields);
|
5653
5706
|
const hasResolver = hasComponentResolver || hasRootResolver;
|
5654
|
-
const resolveFields = (0,
|
5707
|
+
const resolveFields = (0, import_react36.useCallback)(
|
5655
5708
|
(..._0) => __async(void 0, [..._0], function* (fields = {}) {
|
5656
5709
|
var _a2;
|
5657
5710
|
const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
|
@@ -5663,7 +5716,7 @@ var useResolvedFields = () => {
|
|
5663
5716
|
{
|
5664
5717
|
changed,
|
5665
5718
|
fields,
|
5666
|
-
lastFields:
|
5719
|
+
lastFields: lastFields.current,
|
5667
5720
|
lastData,
|
5668
5721
|
appState: state,
|
5669
5722
|
parent
|
@@ -5674,7 +5727,7 @@ var useResolvedFields = () => {
|
|
5674
5727
|
return yield config.root.resolveFields(componentData, {
|
5675
5728
|
changed,
|
5676
5729
|
fields,
|
5677
|
-
lastFields:
|
5730
|
+
lastFields: lastFields.current,
|
5678
5731
|
lastData,
|
5679
5732
|
appState: state,
|
5680
5733
|
parent
|
@@ -5683,39 +5736,55 @@ var useResolvedFields = () => {
|
|
5683
5736
|
return defaultResolveFields(componentData, {
|
5684
5737
|
changed,
|
5685
5738
|
fields,
|
5686
|
-
lastFields:
|
5739
|
+
lastFields: lastFields.current,
|
5687
5740
|
lastData
|
5688
5741
|
});
|
5689
5742
|
}),
|
5690
|
-
[data, config, componentData, selectedItem,
|
5743
|
+
[data, config, componentData, selectedItem, state, parent]
|
5691
5744
|
);
|
5692
|
-
const
|
5693
|
-
(0, import_react35.useEffect)(() => {
|
5694
|
-
setHasParent(!!parent);
|
5695
|
-
}, [parent]);
|
5696
|
-
(0, import_react35.useEffect)(() => {
|
5745
|
+
const triggerResolver = (0, import_react36.useCallback)(() => {
|
5697
5746
|
var _a2, _b2;
|
5698
|
-
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" ||
|
5747
|
+
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" || parent) {
|
5699
5748
|
if (hasResolver) {
|
5700
5749
|
setFieldsLoading(true);
|
5701
5750
|
resolveFields(defaultFields).then((fields) => {
|
5702
5751
|
setResolvedFields(fields || {});
|
5752
|
+
lastFields.current = fields;
|
5703
5753
|
setFieldsLoading(false);
|
5704
5754
|
});
|
5705
5755
|
return;
|
5706
5756
|
}
|
5707
5757
|
}
|
5708
5758
|
setResolvedFields(defaultFields);
|
5709
|
-
}, [
|
5710
|
-
|
5711
|
-
defaultFields,
|
5759
|
+
}, [defaultFields, state.ui.itemSelector, hasResolver, parent]);
|
5760
|
+
useOnValueChange(
|
5712
5761
|
state.ui.itemSelector,
|
5713
|
-
|
5714
|
-
|
5715
|
-
|
5716
|
-
|
5762
|
+
() => {
|
5763
|
+
lastFields.current = defaultFields;
|
5764
|
+
},
|
5765
|
+
selectorIs
|
5766
|
+
);
|
5767
|
+
useOnValueChange(
|
5768
|
+
{ data, parent, itemSelector: state.ui.itemSelector },
|
5769
|
+
() => {
|
5770
|
+
triggerResolver();
|
5771
|
+
},
|
5772
|
+
(a, b) => JSON.stringify(a) === JSON.stringify(b)
|
5773
|
+
);
|
5774
|
+
(0, import_react36.useEffect)(() => {
|
5775
|
+
triggerResolver();
|
5776
|
+
}, []);
|
5717
5777
|
return [resolvedFields, fieldsLoading];
|
5718
5778
|
};
|
5779
|
+
|
5780
|
+
// components/Puck/components/Fields/index.tsx
|
5781
|
+
var import_jsx_runtime27 = require("react/jsx-runtime");
|
5782
|
+
var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
|
5783
|
+
var DefaultFields = ({
|
5784
|
+
children
|
5785
|
+
}) => {
|
5786
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(import_jsx_runtime27.Fragment, { children });
|
5787
|
+
};
|
5719
5788
|
var Fields = ({ wrapFields = true }) => {
|
5720
5789
|
var _a, _b;
|
5721
5790
|
const {
|
@@ -5734,7 +5803,7 @@ var Fields = ({ wrapFields = true }) => {
|
|
5734
5803
|
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;
|
5735
5804
|
const isLoading = fieldsResolving || componentResolving;
|
5736
5805
|
const rootProps = data.root.props || data.root;
|
5737
|
-
const Wrapper = (0,
|
5806
|
+
const Wrapper = (0, import_react37.useMemo)(() => overrides.fields || DefaultFields, [overrides]);
|
5738
5807
|
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
|
5739
5808
|
"form",
|
5740
5809
|
{
|
@@ -5855,7 +5924,7 @@ init_react_import();
|
|
5855
5924
|
|
5856
5925
|
// lib/use-component-list.tsx
|
5857
5926
|
init_react_import();
|
5858
|
-
var
|
5927
|
+
var import_react38 = require("react");
|
5859
5928
|
|
5860
5929
|
// components/ComponentList/index.tsx
|
5861
5930
|
init_react_import();
|
@@ -5922,8 +5991,8 @@ ComponentList.Item = ComponentListItem;
|
|
5922
5991
|
// lib/use-component-list.tsx
|
5923
5992
|
var import_jsx_runtime29 = require("react/jsx-runtime");
|
5924
5993
|
var useComponentList = (config, ui) => {
|
5925
|
-
const [componentList, setComponentList] = (0,
|
5926
|
-
(0,
|
5994
|
+
const [componentList, setComponentList] = (0, import_react38.useState)();
|
5995
|
+
(0, import_react38.useEffect)(() => {
|
5927
5996
|
var _a, _b, _c;
|
5928
5997
|
if (Object.keys(ui.componentList).length > 0) {
|
5929
5998
|
const matchedComponents = [];
|
@@ -5992,22 +6061,22 @@ var useComponentList = (config, ui) => {
|
|
5992
6061
|
};
|
5993
6062
|
|
5994
6063
|
// components/Puck/components/Components/index.tsx
|
5995
|
-
var
|
6064
|
+
var import_react39 = require("react");
|
5996
6065
|
var import_jsx_runtime30 = require("react/jsx-runtime");
|
5997
6066
|
var Components = () => {
|
5998
6067
|
const { config, state, overrides } = useAppContext();
|
5999
6068
|
const componentList = useComponentList(config, state.ui);
|
6000
|
-
const Wrapper = (0,
|
6069
|
+
const Wrapper = (0, import_react39.useMemo)(() => overrides.components || "div", [overrides]);
|
6001
6070
|
return /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ (0, import_jsx_runtime30.jsx)(ComponentList, { id: "all" }) });
|
6002
6071
|
};
|
6003
6072
|
|
6004
6073
|
// components/Puck/components/Preview/index.tsx
|
6005
6074
|
init_react_import();
|
6006
|
-
var
|
6075
|
+
var import_react41 = require("react");
|
6007
6076
|
|
6008
6077
|
// components/AutoFrame/index.tsx
|
6009
6078
|
init_react_import();
|
6010
|
-
var
|
6079
|
+
var import_react40 = require("react");
|
6011
6080
|
var import_object_hash = __toESM(require("object-hash"));
|
6012
6081
|
var import_react_dom3 = require("react-dom");
|
6013
6082
|
var import_jsx_runtime31 = require("react/jsx-runtime");
|
@@ -6053,7 +6122,7 @@ var CopyHostStyles = ({
|
|
6053
6122
|
onStylesLoaded = () => null
|
6054
6123
|
}) => {
|
6055
6124
|
const { document: doc, window: win } = useFrame();
|
6056
|
-
(0,
|
6125
|
+
(0, import_react40.useEffect)(() => {
|
6057
6126
|
if (!win || !doc) {
|
6058
6127
|
return () => {
|
6059
6128
|
};
|
@@ -6212,8 +6281,8 @@ var CopyHostStyles = ({
|
|
6212
6281
|
}, []);
|
6213
6282
|
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_jsx_runtime31.Fragment, { children });
|
6214
6283
|
};
|
6215
|
-
var autoFrameContext = (0,
|
6216
|
-
var useFrame = () => (0,
|
6284
|
+
var autoFrameContext = (0, import_react40.createContext)({});
|
6285
|
+
var useFrame = () => (0, import_react40.useContext)(autoFrameContext);
|
6217
6286
|
function AutoFrame(_a) {
|
6218
6287
|
var _b = _a, {
|
6219
6288
|
children,
|
@@ -6230,10 +6299,10 @@ function AutoFrame(_a) {
|
|
6230
6299
|
"onStylesLoaded",
|
6231
6300
|
"frameRef"
|
6232
6301
|
]);
|
6233
|
-
const [loaded, setLoaded] = (0,
|
6234
|
-
const [ctx, setCtx] = (0,
|
6235
|
-
const [mountTarget, setMountTarget] = (0,
|
6236
|
-
(0,
|
6302
|
+
const [loaded, setLoaded] = (0, import_react40.useState)(false);
|
6303
|
+
const [ctx, setCtx] = (0, import_react40.useState)({});
|
6304
|
+
const [mountTarget, setMountTarget] = (0, import_react40.useState)();
|
6305
|
+
(0, import_react40.useEffect)(() => {
|
6237
6306
|
var _a2;
|
6238
6307
|
if (frameRef.current) {
|
6239
6308
|
setCtx({
|
@@ -6327,7 +6396,7 @@ var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
6327
6396
|
var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
|
6328
6397
|
var useBubbleIframeEvents = (ref) => {
|
6329
6398
|
const { status } = useAppContext();
|
6330
|
-
(0,
|
6399
|
+
(0, import_react41.useEffect)(() => {
|
6331
6400
|
var _a;
|
6332
6401
|
if (ref.current && status === "READY") {
|
6333
6402
|
const iframe = ref.current;
|
@@ -6366,7 +6435,7 @@ var useBubbleIframeEvents = (ref) => {
|
|
6366
6435
|
};
|
6367
6436
|
var Preview2 = ({ id = "puck-preview" }) => {
|
6368
6437
|
const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
|
6369
|
-
const Page = (0,
|
6438
|
+
const Page = (0, import_react41.useCallback)(
|
6370
6439
|
(pageProps) => {
|
6371
6440
|
var _a, _b;
|
6372
6441
|
return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
|
@@ -6375,9 +6444,9 @@ var Preview2 = ({ id = "puck-preview" }) => {
|
|
6375
6444
|
},
|
6376
6445
|
[config.root]
|
6377
6446
|
);
|
6378
|
-
const Frame = (0,
|
6447
|
+
const Frame = (0, import_react41.useMemo)(() => overrides.iframe, [overrides]);
|
6379
6448
|
const rootProps = state.data.root.props || state.data.root;
|
6380
|
-
const ref = (0,
|
6449
|
+
const ref = (0, import_react41.useRef)(null);
|
6381
6450
|
useBubbleIframeEvents(ref);
|
6382
6451
|
const inner = state.ui.previewMode === "edit" ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(
|
6383
6452
|
Page,
|
@@ -6474,7 +6543,7 @@ var scrollIntoView = (el) => {
|
|
6474
6543
|
};
|
6475
6544
|
|
6476
6545
|
// components/LayerTree/index.tsx
|
6477
|
-
var
|
6546
|
+
var import_react42 = require("react");
|
6478
6547
|
|
6479
6548
|
// lib/is-child-of-zone.ts
|
6480
6549
|
init_react_import();
|
@@ -6520,7 +6589,7 @@ var LayerTree = ({
|
|
6520
6589
|
label
|
6521
6590
|
}) => {
|
6522
6591
|
const zones = data.zones || {};
|
6523
|
-
const ctx = (0,
|
6592
|
+
const ctx = (0, import_react42.useContext)(dropZoneContext);
|
6524
6593
|
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
|
6525
6594
|
label && /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: getClassName24("zoneTitle"), children: [
|
6526
6595
|
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassName24("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Layers, { size: "16" }) }),
|
@@ -6627,13 +6696,13 @@ var LayerTree = ({
|
|
6627
6696
|
};
|
6628
6697
|
|
6629
6698
|
// components/Puck/components/Outline/index.tsx
|
6630
|
-
var
|
6699
|
+
var import_react43 = require("react");
|
6631
6700
|
var import_jsx_runtime35 = require("react/jsx-runtime");
|
6632
6701
|
var Outline = () => {
|
6633
6702
|
const { dispatch, state, overrides, config } = useAppContext();
|
6634
6703
|
const { data, ui } = state;
|
6635
6704
|
const { itemSelector } = ui;
|
6636
|
-
const setItemSelector = (0,
|
6705
|
+
const setItemSelector = (0, import_react43.useCallback)(
|
6637
6706
|
(newItemSelector) => {
|
6638
6707
|
dispatch({
|
6639
6708
|
type: "setUi",
|
@@ -6642,7 +6711,7 @@ var Outline = () => {
|
|
6642
6711
|
},
|
6643
6712
|
[]
|
6644
6713
|
);
|
6645
|
-
const Wrapper = (0,
|
6714
|
+
const Wrapper = (0, import_react43.useMemo)(() => overrides.outline || "div", [overrides]);
|
6646
6715
|
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: [
|
6647
6716
|
(ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
|
6648
6717
|
LayerTree,
|
@@ -6756,19 +6825,19 @@ function usePuckHistory({
|
|
6756
6825
|
|
6757
6826
|
// lib/use-history-store.ts
|
6758
6827
|
init_react_import();
|
6759
|
-
var
|
6828
|
+
var import_react44 = require("react");
|
6760
6829
|
var import_use_debounce3 = require("use-debounce");
|
6761
6830
|
var EMPTY_HISTORY_INDEX = 0;
|
6762
6831
|
function useHistoryStore(initialHistory) {
|
6763
6832
|
var _a, _b;
|
6764
|
-
const [histories, setHistories] = (0,
|
6833
|
+
const [histories, setHistories] = (0, import_react44.useState)(
|
6765
6834
|
(_a = initialHistory == null ? void 0 : initialHistory.histories) != null ? _a : []
|
6766
6835
|
);
|
6767
6836
|
const updateHistories = (histories2) => {
|
6768
6837
|
setHistories(histories2);
|
6769
6838
|
setIndex(histories2.length - 1);
|
6770
6839
|
};
|
6771
|
-
const [index, setIndex] = (0,
|
6840
|
+
const [index, setIndex] = (0, import_react44.useState)(
|
6772
6841
|
(_b = initialHistory == null ? void 0 : initialHistory.index) != null ? _b : EMPTY_HISTORY_INDEX
|
6773
6842
|
);
|
6774
6843
|
const hasPast = index > EMPTY_HISTORY_INDEX;
|
@@ -6928,11 +6997,11 @@ var getBox = function getBox2(el) {
|
|
6928
6997
|
};
|
6929
6998
|
|
6930
6999
|
// components/Puck/components/Canvas/index.tsx
|
6931
|
-
var
|
7000
|
+
var import_react46 = require("react");
|
6932
7001
|
|
6933
7002
|
// components/ViewportControls/index.tsx
|
6934
7003
|
init_react_import();
|
6935
|
-
var
|
7004
|
+
var import_react45 = require("react");
|
6936
7005
|
|
6937
7006
|
// css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
|
6938
7007
|
init_react_import();
|
@@ -6955,8 +7024,8 @@ var ViewportButton = ({
|
|
6955
7024
|
onClick
|
6956
7025
|
}) => {
|
6957
7026
|
const { state } = useAppContext();
|
6958
|
-
const [isActive, setIsActive] = (0,
|
6959
|
-
(0,
|
7027
|
+
const [isActive, setIsActive] = (0, import_react45.useState)(false);
|
7028
|
+
(0, import_react45.useEffect)(() => {
|
6960
7029
|
setIsActive(width === state.ui.viewports.current.width);
|
6961
7030
|
}, [width, state.ui.viewports.current.width]);
|
6962
7031
|
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(
|
@@ -6992,7 +7061,7 @@ var ViewportControls = ({
|
|
6992
7061
|
const defaultsContainAutoZoom = defaultZoomOptions.find(
|
6993
7062
|
(option) => option.value === autoZoom
|
6994
7063
|
);
|
6995
|
-
const zoomOptions = (0,
|
7064
|
+
const zoomOptions = (0, import_react45.useMemo)(
|
6996
7065
|
() => [
|
6997
7066
|
...defaultZoomOptions,
|
6998
7067
|
...defaultsContainAutoZoom ? [] : [
|
@@ -7115,17 +7184,17 @@ var Canvas = () => {
|
|
7115
7184
|
const { status, iframe } = useAppContext();
|
7116
7185
|
const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
|
7117
7186
|
const { ui } = state;
|
7118
|
-
const frameRef = (0,
|
7119
|
-
const [showTransition, setShowTransition] = (0,
|
7120
|
-
const defaultRender = (0,
|
7187
|
+
const frameRef = (0, import_react46.useRef)(null);
|
7188
|
+
const [showTransition, setShowTransition] = (0, import_react46.useState)(false);
|
7189
|
+
const defaultRender = (0, import_react46.useMemo)(() => {
|
7121
7190
|
const PuckDefault = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_jsx_runtime37.Fragment, { children });
|
7122
7191
|
return PuckDefault;
|
7123
7192
|
}, []);
|
7124
|
-
const CustomPreview = (0,
|
7193
|
+
const CustomPreview = (0, import_react46.useMemo)(
|
7125
7194
|
() => overrides.preview || defaultRender,
|
7126
7195
|
[overrides]
|
7127
7196
|
);
|
7128
|
-
const getFrameDimensions = (0,
|
7197
|
+
const getFrameDimensions = (0, import_react46.useCallback)(() => {
|
7129
7198
|
if (frameRef.current) {
|
7130
7199
|
const frame = frameRef.current;
|
7131
7200
|
const box = getBox(frame);
|
@@ -7133,7 +7202,7 @@ var Canvas = () => {
|
|
7133
7202
|
}
|
7134
7203
|
return { width: 0, height: 0 };
|
7135
7204
|
}, [frameRef]);
|
7136
|
-
const resetAutoZoom = (0,
|
7205
|
+
const resetAutoZoom = (0, import_react46.useCallback)(
|
7137
7206
|
(ui2 = state.ui) => {
|
7138
7207
|
if (frameRef.current) {
|
7139
7208
|
setZoomConfig(
|
@@ -7143,11 +7212,11 @@ var Canvas = () => {
|
|
7143
7212
|
},
|
7144
7213
|
[frameRef, zoomConfig, state.ui]
|
7145
7214
|
);
|
7146
|
-
(0,
|
7215
|
+
(0, import_react46.useEffect)(() => {
|
7147
7216
|
setShowTransition(false);
|
7148
7217
|
resetAutoZoom();
|
7149
7218
|
}, [frameRef, ui.leftSideBarVisible, ui.rightSideBarVisible]);
|
7150
|
-
(0,
|
7219
|
+
(0, import_react46.useEffect)(() => {
|
7151
7220
|
const { height: frameHeight } = getFrameDimensions();
|
7152
7221
|
if (ui.viewports.current.height === "auto") {
|
7153
7222
|
setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
|
@@ -7155,13 +7224,13 @@ var Canvas = () => {
|
|
7155
7224
|
}));
|
7156
7225
|
}
|
7157
7226
|
}, [zoomConfig.zoom]);
|
7158
|
-
(0,
|
7227
|
+
(0, import_react46.useEffect)(() => {
|
7159
7228
|
if (ZOOM_ON_CHANGE) {
|
7160
7229
|
setShowTransition(true);
|
7161
7230
|
resetAutoZoom(ui);
|
7162
7231
|
}
|
7163
7232
|
}, [ui.viewports.current.width]);
|
7164
|
-
(0,
|
7233
|
+
(0, import_react46.useEffect)(() => {
|
7165
7234
|
const cb = () => {
|
7166
7235
|
setShowTransition(false);
|
7167
7236
|
resetAutoZoom();
|
@@ -7171,8 +7240,8 @@ var Canvas = () => {
|
|
7171
7240
|
window.removeEventListener("resize", cb);
|
7172
7241
|
};
|
7173
7242
|
}, []);
|
7174
|
-
const [showLoader, setShowLoader] = (0,
|
7175
|
-
(0,
|
7243
|
+
const [showLoader, setShowLoader] = (0, import_react46.useState)(false);
|
7244
|
+
(0, import_react46.useEffect)(() => {
|
7176
7245
|
setTimeout(() => {
|
7177
7246
|
setShowLoader(true);
|
7178
7247
|
}, 500);
|
@@ -7250,7 +7319,7 @@ var Canvas = () => {
|
|
7250
7319
|
|
7251
7320
|
// lib/use-loaded-overrides.ts
|
7252
7321
|
init_react_import();
|
7253
|
-
var
|
7322
|
+
var import_react47 = require("react");
|
7254
7323
|
|
7255
7324
|
// lib/load-overrides.ts
|
7256
7325
|
init_react_import();
|
@@ -7289,7 +7358,7 @@ var useLoadedOverrides = ({
|
|
7289
7358
|
overrides,
|
7290
7359
|
plugins
|
7291
7360
|
}) => {
|
7292
|
-
return (0,
|
7361
|
+
return (0, import_react47.useMemo)(() => {
|
7293
7362
|
return loadOverrides({ overrides, plugins });
|
7294
7363
|
}, [plugins, overrides]);
|
7295
7364
|
};
|
@@ -7301,14 +7370,14 @@ var DefaultOverride = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime38
|
|
7301
7370
|
|
7302
7371
|
// lib/use-inject-css.ts
|
7303
7372
|
init_react_import();
|
7304
|
-
var
|
7373
|
+
var import_react48 = require("react");
|
7305
7374
|
var styles = ``;
|
7306
7375
|
var useInjectStyleSheet = (initialStyles, iframeEnabled) => {
|
7307
|
-
const [el, setEl] = (0,
|
7308
|
-
(0,
|
7376
|
+
const [el, setEl] = (0, import_react48.useState)();
|
7377
|
+
(0, import_react48.useEffect)(() => {
|
7309
7378
|
setEl(document.createElement("style"));
|
7310
7379
|
}, []);
|
7311
|
-
(0,
|
7380
|
+
(0, import_react48.useEffect)(() => {
|
7312
7381
|
var _a;
|
7313
7382
|
if (!el || typeof window === "undefined") {
|
7314
7383
|
return;
|
@@ -7328,10 +7397,10 @@ var useInjectGlobalCss = (iframeEnabled) => {
|
|
7328
7397
|
|
7329
7398
|
// lib/use-preview-mode-hotkeys.ts
|
7330
7399
|
init_react_import();
|
7331
|
-
var
|
7400
|
+
var import_react49 = require("react");
|
7332
7401
|
var import_react_hotkeys_hook2 = require("react-hotkeys-hook");
|
7333
7402
|
var usePreviewModeHotkeys = (dispatch, iframeEnabled) => {
|
7334
|
-
const toggleInteractive = (0,
|
7403
|
+
const toggleInteractive = (0, import_react49.useCallback)(() => {
|
7335
7404
|
dispatch({
|
7336
7405
|
type: "setUi",
|
7337
7406
|
ui: (ui) => ({
|
@@ -7383,7 +7452,7 @@ function Puck({
|
|
7383
7452
|
waitForStyles: true
|
7384
7453
|
}, _iframe);
|
7385
7454
|
useInjectGlobalCss(iframe.enabled);
|
7386
|
-
const [generatedAppState] = (0,
|
7455
|
+
const [generatedAppState] = (0, import_react50.useState)(() => {
|
7387
7456
|
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
7388
7457
|
const initial = __spreadValues(__spreadValues({}, defaultAppState.ui), initialUi);
|
7389
7458
|
let clientUiState = {};
|
@@ -7455,14 +7524,14 @@ function Puck({
|
|
7455
7524
|
histories,
|
7456
7525
|
index: initialHistoryIndex
|
7457
7526
|
});
|
7458
|
-
const [reducer] = (0,
|
7527
|
+
const [reducer] = (0, import_react50.useState)(
|
7459
7528
|
() => createReducer({
|
7460
7529
|
config,
|
7461
7530
|
record: historyStore.record,
|
7462
7531
|
onAction
|
7463
7532
|
})
|
7464
7533
|
);
|
7465
|
-
const [appState, dispatch] = (0,
|
7534
|
+
const [appState, dispatch] = (0, import_react50.useReducer)(
|
7466
7535
|
reducer,
|
7467
7536
|
flushZones(initialAppState)
|
7468
7537
|
);
|
@@ -7473,14 +7542,14 @@ function Puck({
|
|
7473
7542
|
historyStore,
|
7474
7543
|
iframeEnabled: (_a = _iframe == null ? void 0 : _iframe.enabled) != null ? _a : true
|
7475
7544
|
});
|
7476
|
-
const [menuOpen, setMenuOpen] = (0,
|
7545
|
+
const [menuOpen, setMenuOpen] = (0, import_react50.useState)(false);
|
7477
7546
|
const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
|
7478
7547
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
7479
|
-
(0,
|
7548
|
+
(0, import_react50.useEffect)(() => {
|
7480
7549
|
if (onChange) onChange(data);
|
7481
7550
|
}, [data]);
|
7482
7551
|
const rootProps = data.root.props || data.root;
|
7483
|
-
const toggleSidebars = (0,
|
7552
|
+
const toggleSidebars = (0, import_react50.useCallback)(
|
7484
7553
|
(sidebar) => {
|
7485
7554
|
const widerViewport = window.matchMedia("(min-width: 638px)").matches;
|
7486
7555
|
const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
|
@@ -7494,7 +7563,7 @@ function Puck({
|
|
7494
7563
|
},
|
7495
7564
|
[dispatch, leftSideBarVisible, rightSideBarVisible]
|
7496
7565
|
);
|
7497
|
-
(0,
|
7566
|
+
(0, import_react50.useEffect)(() => {
|
7498
7567
|
if (!window.matchMedia("(min-width: 638px)").matches) {
|
7499
7568
|
dispatch({
|
7500
7569
|
type: "setUi",
|
@@ -7517,7 +7586,7 @@ function Puck({
|
|
7517
7586
|
window.removeEventListener("resize", handleResize);
|
7518
7587
|
};
|
7519
7588
|
}, []);
|
7520
|
-
const defaultHeaderRender = (0,
|
7589
|
+
const defaultHeaderRender = (0, import_react50.useMemo)(() => {
|
7521
7590
|
if (renderHeader) {
|
7522
7591
|
console.warn(
|
7523
7592
|
"`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
|
@@ -7531,7 +7600,7 @@ function Puck({
|
|
7531
7600
|
}
|
7532
7601
|
return DefaultOverride;
|
7533
7602
|
}, [renderHeader]);
|
7534
|
-
const defaultHeaderActionsRender = (0,
|
7603
|
+
const defaultHeaderActionsRender = (0, import_react50.useMemo)(() => {
|
7535
7604
|
if (renderHeaderActions) {
|
7536
7605
|
console.warn(
|
7537
7606
|
"`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
|
@@ -7548,20 +7617,20 @@ function Puck({
|
|
7548
7617
|
overrides,
|
7549
7618
|
plugins
|
7550
7619
|
});
|
7551
|
-
const CustomPuck = (0,
|
7620
|
+
const CustomPuck = (0, import_react50.useMemo)(
|
7552
7621
|
() => loadedOverrides.puck || DefaultOverride,
|
7553
7622
|
[loadedOverrides]
|
7554
7623
|
);
|
7555
|
-
const CustomHeader = (0,
|
7624
|
+
const CustomHeader = (0, import_react50.useMemo)(
|
7556
7625
|
() => loadedOverrides.header || defaultHeaderRender,
|
7557
7626
|
[loadedOverrides]
|
7558
7627
|
);
|
7559
|
-
const CustomHeaderActions = (0,
|
7628
|
+
const CustomHeaderActions = (0, import_react50.useMemo)(
|
7560
7629
|
() => loadedOverrides.headerActions || defaultHeaderActionsRender,
|
7561
7630
|
[loadedOverrides]
|
7562
7631
|
);
|
7563
|
-
const [mounted, setMounted] = (0,
|
7564
|
-
(0,
|
7632
|
+
const [mounted, setMounted] = (0, import_react50.useState)(false);
|
7633
|
+
(0, import_react50.useEffect)(() => {
|
7565
7634
|
setMounted(true);
|
7566
7635
|
}, []);
|
7567
7636
|
const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
|