@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.mjs
CHANGED
@@ -205,7 +205,7 @@ init_react_import();
|
|
205
205
|
|
206
206
|
// css-module:/home/runner/work/puck/puck/packages/core/components/AutoField/styles.module.css#css-module
|
207
207
|
init_react_import();
|
208
|
-
var styles_module_default2 = { "InputWrapper": "
|
208
|
+
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" };
|
209
209
|
|
210
210
|
// components/AutoField/index.tsx
|
211
211
|
import {
|
@@ -3506,6 +3506,7 @@ import { Fragment as Fragment6, jsx as jsx22, jsxs as jsxs10 } from "react/jsx-r
|
|
3506
3506
|
var getClassName17 = get_class_name_factory_default("DropZone", styles_module_default12);
|
3507
3507
|
var getRandomColor = () => `#${Math.floor(Math.random() * 16777215).toString(16)}`;
|
3508
3508
|
var RENDER_DEBUG = false;
|
3509
|
+
var DropZoneEditPure = (props) => /* @__PURE__ */ jsx22(DropZoneEdit, __spreadValues({}, props));
|
3509
3510
|
var DropZoneEdit = forwardRef3(
|
3510
3511
|
function DropZoneEditInternal({
|
3511
3512
|
zone,
|
@@ -3665,10 +3666,10 @@ var DropZoneEdit = forwardRef3(
|
|
3665
3666
|
backgroundColor: RENDER_DEBUG ? getRandomColor() : void 0
|
3666
3667
|
}),
|
3667
3668
|
children: contentWithPreview.map((item, i) => {
|
3668
|
-
var _a, _b, _c, _d, _e;
|
3669
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
3669
3670
|
const componentId = item.props.id;
|
3670
3671
|
const puckProps = {
|
3671
|
-
renderDropZone:
|
3672
|
+
renderDropZone: DropZoneEditPure,
|
3672
3673
|
isEditing: true,
|
3673
3674
|
dragRef: null
|
3674
3675
|
};
|
@@ -3685,13 +3686,13 @@ var DropZoneEdit = forwardRef3(
|
|
3685
3686
|
const componentConfig = config.components[item.type];
|
3686
3687
|
let componentType = item.type;
|
3687
3688
|
let label = (_b = componentConfig == null ? void 0 : componentConfig["label"]) != null ? _b : item.type.toString();
|
3688
|
-
if (item.type === "preview"
|
3689
|
+
if (item.type === "preview") {
|
3689
3690
|
let Preview4 = function() {
|
3690
3691
|
return /* @__PURE__ */ jsx22(DrawerItemInner, { name: label, children: appContext2.overrides.componentItem });
|
3691
3692
|
};
|
3692
3693
|
var Preview3 = Preview4;
|
3693
|
-
componentType = preview.componentType;
|
3694
|
-
label = (
|
3694
|
+
componentType = (_c = preview == null ? void 0 : preview.componentType) != null ? _c : "__preview";
|
3695
|
+
label = (_f = (_e = (_d = config.components[componentType]) == null ? void 0 : _d.label) != null ? _e : componentType) != null ? _f : "Preview";
|
3695
3696
|
Render2 = Preview4;
|
3696
3697
|
}
|
3697
3698
|
return /* @__PURE__ */ jsx22(
|
@@ -3706,7 +3707,7 @@ var DropZoneEdit = forwardRef3(
|
|
3706
3707
|
zoneCompound,
|
3707
3708
|
depth: depth + 1,
|
3708
3709
|
index: i,
|
3709
|
-
isLoading: ((
|
3710
|
+
isLoading: ((_g = appContext2.componentState[componentId]) == null ? void 0 : _g.loadingCount) > 0,
|
3710
3711
|
isSelected,
|
3711
3712
|
label,
|
3712
3713
|
isEnabled,
|
@@ -3731,6 +3732,7 @@ var DropZoneEdit = forwardRef3(
|
|
3731
3732
|
);
|
3732
3733
|
}
|
3733
3734
|
);
|
3735
|
+
var DropZoneRenderPure = (props) => /* @__PURE__ */ jsx22(DropZoneRender, __spreadValues({}, props));
|
3734
3736
|
var DropZoneRender = forwardRef3(
|
3735
3737
|
function DropZoneRenderInternal({ className, style, zone }, ref) {
|
3736
3738
|
const ctx = useContext6(dropZoneContext);
|
@@ -3771,7 +3773,7 @@ var DropZoneRender = forwardRef3(
|
|
3771
3773
|
Component.render,
|
3772
3774
|
__spreadProps(__spreadValues({}, item.props), {
|
3773
3775
|
puck: {
|
3774
|
-
renderDropZone:
|
3776
|
+
renderDropZone: DropZoneRenderPure
|
3775
3777
|
}
|
3776
3778
|
})
|
3777
3779
|
)
|
@@ -4348,6 +4350,11 @@ var reduceUi = (ui, action) => {
|
|
4348
4350
|
itemSelector: { index: action.sourceIndex + 1, zone: action.sourceZone }
|
4349
4351
|
});
|
4350
4352
|
}
|
4353
|
+
if (action.type === "remove") {
|
4354
|
+
return __spreadProps(__spreadValues({}, ui), {
|
4355
|
+
itemSelector: null
|
4356
|
+
});
|
4357
|
+
}
|
4351
4358
|
return ui;
|
4352
4359
|
};
|
4353
4360
|
|
@@ -5254,9 +5261,9 @@ Drawer.Item = DrawerItem;
|
|
5254
5261
|
// components/Puck/index.tsx
|
5255
5262
|
init_react_import();
|
5256
5263
|
import {
|
5257
|
-
useCallback as
|
5258
|
-
useEffect as
|
5259
|
-
useMemo as
|
5264
|
+
useCallback as useCallback18,
|
5265
|
+
useEffect as useEffect24,
|
5266
|
+
useMemo as useMemo19,
|
5260
5267
|
useReducer,
|
5261
5268
|
useState as useState26
|
5262
5269
|
} from "react";
|
@@ -5452,36 +5459,61 @@ init_react_import();
|
|
5452
5459
|
|
5453
5460
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Fields/styles.module.css#css-module
|
5454
5461
|
init_react_import();
|
5455
|
-
var styles_module_default16 = { "PuckFields": "
|
5462
|
+
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" };
|
5456
5463
|
|
5457
5464
|
// components/Puck/components/Fields/index.tsx
|
5458
|
-
import {
|
5465
|
+
import { useMemo as useMemo12 } from "react";
|
5466
|
+
|
5467
|
+
// lib/use-resolved-fields.ts
|
5468
|
+
init_react_import();
|
5469
|
+
import { useCallback as useCallback13, useEffect as useEffect17, useMemo as useMemo11, useRef as useRef6, useState as useState19 } from "react";
|
5459
5470
|
|
5460
5471
|
// lib/use-parent.ts
|
5461
5472
|
init_react_import();
|
5462
|
-
import { useContext as useContext9 } from "react";
|
5463
|
-
var
|
5473
|
+
import { useCallback as useCallback12, useContext as useContext9 } from "react";
|
5474
|
+
var getParent = (itemSelector, pathData, data) => {
|
5464
5475
|
var _a;
|
5465
|
-
|
5466
|
-
const
|
5467
|
-
const
|
5468
|
-
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, state.data);
|
5476
|
+
if (!itemSelector) return null;
|
5477
|
+
const item = getItem(itemSelector, data);
|
5478
|
+
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, data);
|
5469
5479
|
const lastItem = breadcrumbs[breadcrumbs.length - 1];
|
5470
|
-
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector,
|
5480
|
+
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector, data)) != null ? _a : null : null;
|
5471
5481
|
return parent || null;
|
5472
5482
|
};
|
5483
|
+
var useGetParent = () => {
|
5484
|
+
const { state } = useAppContext();
|
5485
|
+
const { pathData } = useContext9(dropZoneContext) || {};
|
5486
|
+
return useCallback12(
|
5487
|
+
() => getParent(state.ui.itemSelector, pathData, state.data),
|
5488
|
+
[state.ui.itemSelector, pathData, state.data]
|
5489
|
+
);
|
5490
|
+
};
|
5491
|
+
var useParent = () => {
|
5492
|
+
return useGetParent()();
|
5493
|
+
};
|
5473
5494
|
|
5474
|
-
//
|
5475
|
-
|
5476
|
-
|
5495
|
+
// lib/use-on-value-change.ts
|
5496
|
+
init_react_import();
|
5497
|
+
import { useRef as useRef5, useEffect as useEffect16 } from "react";
|
5498
|
+
function useOnValueChange(value, onChange, compare = Object.is, deps = []) {
|
5499
|
+
const tracked = useRef5(value);
|
5500
|
+
useEffect16(() => {
|
5501
|
+
const oldValue = tracked.current;
|
5502
|
+
if (!compare(value, oldValue)) {
|
5503
|
+
tracked.current = value;
|
5504
|
+
onChange(value, oldValue);
|
5505
|
+
}
|
5506
|
+
}, [onChange, compare, value, ...deps]);
|
5507
|
+
}
|
5508
|
+
|
5509
|
+
// lib/selector-is.ts
|
5510
|
+
init_react_import();
|
5511
|
+
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);
|
5512
|
+
|
5513
|
+
// lib/use-resolved-fields.ts
|
5477
5514
|
var defaultPageFields = {
|
5478
5515
|
title: { type: "text" }
|
5479
5516
|
};
|
5480
|
-
var DefaultFields = ({
|
5481
|
-
children
|
5482
|
-
}) => {
|
5483
|
-
return /* @__PURE__ */ jsx27(Fragment8, { children });
|
5484
|
-
};
|
5485
5517
|
var useResolvedFields = () => {
|
5486
5518
|
var _a, _b;
|
5487
5519
|
const { selectedItem, state, config } = useAppContext();
|
@@ -5497,12 +5529,13 @@ var useResolvedFields = () => {
|
|
5497
5529
|
const [lastSelectedData, setLastSelectedData] = useState19({});
|
5498
5530
|
const [resolvedFields, setResolvedFields] = useState19(defaultFields);
|
5499
5531
|
const [fieldsLoading, setFieldsLoading] = useState19(false);
|
5532
|
+
const lastFields = useRef6(defaultFields);
|
5500
5533
|
const defaultResolveFields = (_componentData, _params) => defaultFields;
|
5501
5534
|
const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
|
5502
5535
|
const hasComponentResolver = selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields);
|
5503
5536
|
const hasRootResolver = !selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields);
|
5504
5537
|
const hasResolver = hasComponentResolver || hasRootResolver;
|
5505
|
-
const resolveFields =
|
5538
|
+
const resolveFields = useCallback13(
|
5506
5539
|
(..._0) => __async(void 0, [..._0], function* (fields = {}) {
|
5507
5540
|
var _a2;
|
5508
5541
|
const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
|
@@ -5514,7 +5547,7 @@ var useResolvedFields = () => {
|
|
5514
5547
|
{
|
5515
5548
|
changed,
|
5516
5549
|
fields,
|
5517
|
-
lastFields:
|
5550
|
+
lastFields: lastFields.current,
|
5518
5551
|
lastData,
|
5519
5552
|
appState: state,
|
5520
5553
|
parent
|
@@ -5525,7 +5558,7 @@ var useResolvedFields = () => {
|
|
5525
5558
|
return yield config.root.resolveFields(componentData, {
|
5526
5559
|
changed,
|
5527
5560
|
fields,
|
5528
|
-
lastFields:
|
5561
|
+
lastFields: lastFields.current,
|
5529
5562
|
lastData,
|
5530
5563
|
appState: state,
|
5531
5564
|
parent
|
@@ -5534,40 +5567,56 @@ var useResolvedFields = () => {
|
|
5534
5567
|
return defaultResolveFields(componentData, {
|
5535
5568
|
changed,
|
5536
5569
|
fields,
|
5537
|
-
lastFields:
|
5570
|
+
lastFields: lastFields.current,
|
5538
5571
|
lastData
|
5539
5572
|
});
|
5540
5573
|
}),
|
5541
|
-
[data, config, componentData, selectedItem,
|
5574
|
+
[data, config, componentData, selectedItem, state, parent]
|
5542
5575
|
);
|
5543
|
-
const
|
5544
|
-
|
5545
|
-
|
5546
|
-
}, [parent]);
|
5547
|
-
useEffect16(() => {
|
5548
|
-
var _a2;
|
5549
|
-
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || hasParent) {
|
5576
|
+
const triggerResolver = useCallback13(() => {
|
5577
|
+
var _a2, _b2;
|
5578
|
+
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" || parent) {
|
5550
5579
|
if (hasResolver) {
|
5551
5580
|
setFieldsLoading(true);
|
5552
5581
|
resolveFields(defaultFields).then((fields) => {
|
5553
5582
|
setResolvedFields(fields || {});
|
5583
|
+
lastFields.current = fields;
|
5554
5584
|
setFieldsLoading(false);
|
5555
5585
|
});
|
5556
|
-
|
5557
|
-
setResolvedFields(defaultFields);
|
5586
|
+
return;
|
5558
5587
|
}
|
5559
5588
|
}
|
5560
|
-
|
5561
|
-
|
5562
|
-
|
5589
|
+
setResolvedFields(defaultFields);
|
5590
|
+
}, [defaultFields, state.ui.itemSelector, hasResolver, parent]);
|
5591
|
+
useOnValueChange(
|
5563
5592
|
state.ui.itemSelector,
|
5564
|
-
|
5565
|
-
|
5566
|
-
|
5567
|
-
|
5593
|
+
() => {
|
5594
|
+
lastFields.current = defaultFields;
|
5595
|
+
},
|
5596
|
+
selectorIs
|
5597
|
+
);
|
5598
|
+
useOnValueChange(
|
5599
|
+
{ data, parent, itemSelector: state.ui.itemSelector },
|
5600
|
+
() => {
|
5601
|
+
triggerResolver();
|
5602
|
+
},
|
5603
|
+
(a, b) => JSON.stringify(a) === JSON.stringify(b)
|
5604
|
+
);
|
5605
|
+
useEffect17(() => {
|
5606
|
+
triggerResolver();
|
5607
|
+
}, []);
|
5568
5608
|
return [resolvedFields, fieldsLoading];
|
5569
5609
|
};
|
5570
|
-
|
5610
|
+
|
5611
|
+
// components/Puck/components/Fields/index.tsx
|
5612
|
+
import { Fragment as Fragment8, jsx as jsx27, jsxs as jsxs14 } from "react/jsx-runtime";
|
5613
|
+
var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
|
5614
|
+
var DefaultFields = ({
|
5615
|
+
children
|
5616
|
+
}) => {
|
5617
|
+
return /* @__PURE__ */ jsx27(Fragment8, { children });
|
5618
|
+
};
|
5619
|
+
var Fields = ({ wrapFields = true }) => {
|
5571
5620
|
var _a, _b;
|
5572
5621
|
const {
|
5573
5622
|
selectedItem,
|
@@ -5585,11 +5634,11 @@ var Fields = () => {
|
|
5585
5634
|
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;
|
5586
5635
|
const isLoading = fieldsResolving || componentResolving;
|
5587
5636
|
const rootProps = data.root.props || data.root;
|
5588
|
-
const Wrapper =
|
5637
|
+
const Wrapper = useMemo12(() => overrides.fields || DefaultFields, [overrides]);
|
5589
5638
|
return /* @__PURE__ */ jsxs14(
|
5590
5639
|
"form",
|
5591
5640
|
{
|
5592
|
-
className: getClassName21(),
|
5641
|
+
className: getClassName21({ wrapFields }),
|
5593
5642
|
onSubmit: (e) => {
|
5594
5643
|
e.preventDefault();
|
5595
5644
|
},
|
@@ -5665,7 +5714,7 @@ var Fields = () => {
|
|
5665
5714
|
item: selectedItem
|
5666
5715
|
});
|
5667
5716
|
const id = `${selectedItem.props.id}_${field.type}_${fieldName}`;
|
5668
|
-
return /* @__PURE__ */ jsx27(
|
5717
|
+
return /* @__PURE__ */ jsx27("div", { className: getClassName21("field"), children: /* @__PURE__ */ jsx27(
|
5669
5718
|
AutoFieldPrivate,
|
5670
5719
|
{
|
5671
5720
|
field,
|
@@ -5674,16 +5723,15 @@ var Fields = () => {
|
|
5674
5723
|
readOnly: !edit || readOnly[fieldName],
|
5675
5724
|
value: selectedItem.props[fieldName],
|
5676
5725
|
onChange
|
5677
|
-
}
|
5678
|
-
|
5679
|
-
);
|
5726
|
+
}
|
5727
|
+
) }, id);
|
5680
5728
|
} else {
|
5681
5729
|
const readOnly = data.root.readOnly || {};
|
5682
5730
|
const { edit } = getPermissions({
|
5683
5731
|
root: true
|
5684
5732
|
});
|
5685
5733
|
const id = `root_${field.type}_${fieldName}`;
|
5686
|
-
return /* @__PURE__ */ jsx27(
|
5734
|
+
return /* @__PURE__ */ jsx27("div", { className: getClassName21("field"), children: /* @__PURE__ */ jsx27(
|
5687
5735
|
AutoFieldPrivate,
|
5688
5736
|
{
|
5689
5737
|
field,
|
@@ -5692,9 +5740,8 @@ var Fields = () => {
|
|
5692
5740
|
readOnly: !edit || readOnly[fieldName],
|
5693
5741
|
value: rootProps[fieldName],
|
5694
5742
|
onChange
|
5695
|
-
}
|
5696
|
-
|
5697
|
-
);
|
5743
|
+
}
|
5744
|
+
) }, id);
|
5698
5745
|
}
|
5699
5746
|
}) }),
|
5700
5747
|
isLoading && /* @__PURE__ */ jsx27("div", { className: getClassName21("loadingOverlay"), children: /* @__PURE__ */ jsx27("div", { className: getClassName21("loadingOverlayInner"), children: /* @__PURE__ */ jsx27(Loader, { size: 16 }) }) })
|
@@ -5708,7 +5755,7 @@ init_react_import();
|
|
5708
5755
|
|
5709
5756
|
// lib/use-component-list.tsx
|
5710
5757
|
init_react_import();
|
5711
|
-
import { useEffect as
|
5758
|
+
import { useEffect as useEffect18, useState as useState20 } from "react";
|
5712
5759
|
|
5713
5760
|
// components/ComponentList/index.tsx
|
5714
5761
|
init_react_import();
|
@@ -5776,7 +5823,7 @@ ComponentList.Item = ComponentListItem;
|
|
5776
5823
|
import { jsx as jsx29 } from "react/jsx-runtime";
|
5777
5824
|
var useComponentList = (config, ui) => {
|
5778
5825
|
const [componentList, setComponentList] = useState20();
|
5779
|
-
|
5826
|
+
useEffect18(() => {
|
5780
5827
|
var _a, _b, _c;
|
5781
5828
|
if (Object.keys(ui.componentList).length > 0) {
|
5782
5829
|
const matchedComponents = [];
|
@@ -5845,25 +5892,25 @@ var useComponentList = (config, ui) => {
|
|
5845
5892
|
};
|
5846
5893
|
|
5847
5894
|
// components/Puck/components/Components/index.tsx
|
5848
|
-
import { useMemo as
|
5895
|
+
import { useMemo as useMemo13 } from "react";
|
5849
5896
|
import { jsx as jsx30 } from "react/jsx-runtime";
|
5850
5897
|
var Components = () => {
|
5851
5898
|
const { config, state, overrides } = useAppContext();
|
5852
5899
|
const componentList = useComponentList(config, state.ui);
|
5853
|
-
const Wrapper =
|
5900
|
+
const Wrapper = useMemo13(() => overrides.components || "div", [overrides]);
|
5854
5901
|
return /* @__PURE__ */ jsx30(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ jsx30(ComponentList, { id: "all" }) });
|
5855
5902
|
};
|
5856
5903
|
|
5857
5904
|
// components/Puck/components/Preview/index.tsx
|
5858
5905
|
init_react_import();
|
5859
|
-
import { useCallback as
|
5906
|
+
import { useCallback as useCallback14, useEffect as useEffect20, useRef as useRef8, useMemo as useMemo14 } from "react";
|
5860
5907
|
|
5861
5908
|
// components/AutoFrame/index.tsx
|
5862
5909
|
init_react_import();
|
5863
5910
|
import {
|
5864
5911
|
createContext as createContext5,
|
5865
5912
|
useContext as useContext10,
|
5866
|
-
useEffect as
|
5913
|
+
useEffect as useEffect19,
|
5867
5914
|
useState as useState21
|
5868
5915
|
} from "react";
|
5869
5916
|
import hash from "object-hash";
|
@@ -5911,7 +5958,7 @@ var CopyHostStyles = ({
|
|
5911
5958
|
onStylesLoaded = () => null
|
5912
5959
|
}) => {
|
5913
5960
|
const { document: doc, window: win } = useFrame();
|
5914
|
-
|
5961
|
+
useEffect19(() => {
|
5915
5962
|
if (!win || !doc) {
|
5916
5963
|
return () => {
|
5917
5964
|
};
|
@@ -6091,7 +6138,7 @@ function AutoFrame(_a) {
|
|
6091
6138
|
const [loaded, setLoaded] = useState21(false);
|
6092
6139
|
const [ctx, setCtx] = useState21({});
|
6093
6140
|
const [mountTarget, setMountTarget] = useState21();
|
6094
|
-
|
6141
|
+
useEffect19(() => {
|
6095
6142
|
var _a2;
|
6096
6143
|
if (frameRef.current) {
|
6097
6144
|
setCtx({
|
@@ -6185,7 +6232,7 @@ import { Fragment as Fragment10, jsx as jsx33 } from "react/jsx-runtime";
|
|
6185
6232
|
var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
|
6186
6233
|
var useBubbleIframeEvents = (ref) => {
|
6187
6234
|
const { status } = useAppContext();
|
6188
|
-
|
6235
|
+
useEffect20(() => {
|
6189
6236
|
var _a;
|
6190
6237
|
if (ref.current && status === "READY") {
|
6191
6238
|
const iframe = ref.current;
|
@@ -6224,7 +6271,7 @@ var useBubbleIframeEvents = (ref) => {
|
|
6224
6271
|
};
|
6225
6272
|
var Preview2 = ({ id = "puck-preview" }) => {
|
6226
6273
|
const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
|
6227
|
-
const Page =
|
6274
|
+
const Page = useCallback14(
|
6228
6275
|
(pageProps) => {
|
6229
6276
|
var _a, _b;
|
6230
6277
|
return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
|
@@ -6233,9 +6280,9 @@ var Preview2 = ({ id = "puck-preview" }) => {
|
|
6233
6280
|
},
|
6234
6281
|
[config.root]
|
6235
6282
|
);
|
6236
|
-
const Frame =
|
6283
|
+
const Frame = useMemo14(() => overrides.iframe, [overrides]);
|
6237
6284
|
const rootProps = state.data.root.props || state.data.root;
|
6238
|
-
const ref =
|
6285
|
+
const ref = useRef8(null);
|
6239
6286
|
useBubbleIframeEvents(ref);
|
6240
6287
|
const inner = state.ui.previewMode === "edit" ? /* @__PURE__ */ jsx33(
|
6241
6288
|
Page,
|
@@ -6485,13 +6532,13 @@ var LayerTree = ({
|
|
6485
6532
|
};
|
6486
6533
|
|
6487
6534
|
// components/Puck/components/Outline/index.tsx
|
6488
|
-
import { useCallback as
|
6535
|
+
import { useCallback as useCallback15, useMemo as useMemo15 } from "react";
|
6489
6536
|
import { Fragment as Fragment12, jsx as jsx35, jsxs as jsxs17 } from "react/jsx-runtime";
|
6490
6537
|
var Outline = () => {
|
6491
6538
|
const { dispatch, state, overrides, config } = useAppContext();
|
6492
6539
|
const { data, ui } = state;
|
6493
6540
|
const { itemSelector } = ui;
|
6494
|
-
const setItemSelector =
|
6541
|
+
const setItemSelector = useCallback15(
|
6495
6542
|
(newItemSelector) => {
|
6496
6543
|
dispatch({
|
6497
6544
|
type: "setUi",
|
@@ -6500,7 +6547,7 @@ var Outline = () => {
|
|
6500
6547
|
},
|
6501
6548
|
[]
|
6502
6549
|
);
|
6503
|
-
const Wrapper =
|
6550
|
+
const Wrapper = useMemo15(() => overrides.outline || "div", [overrides]);
|
6504
6551
|
return /* @__PURE__ */ jsx35(Wrapper, { children: /* @__PURE__ */ jsx35(dropZoneContext.Consumer, { children: (ctx) => /* @__PURE__ */ jsxs17(Fragment12, { children: [
|
6505
6552
|
(ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ jsx35(
|
6506
6553
|
LayerTree,
|
@@ -6787,16 +6834,16 @@ var getBox = function getBox2(el) {
|
|
6787
6834
|
|
6788
6835
|
// components/Puck/components/Canvas/index.tsx
|
6789
6836
|
import {
|
6790
|
-
useCallback as
|
6791
|
-
useEffect as
|
6792
|
-
useMemo as
|
6793
|
-
useRef as
|
6837
|
+
useCallback as useCallback16,
|
6838
|
+
useEffect as useEffect22,
|
6839
|
+
useMemo as useMemo17,
|
6840
|
+
useRef as useRef9,
|
6794
6841
|
useState as useState24
|
6795
6842
|
} from "react";
|
6796
6843
|
|
6797
6844
|
// components/ViewportControls/index.tsx
|
6798
6845
|
init_react_import();
|
6799
|
-
import { useEffect as
|
6846
|
+
import { useEffect as useEffect21, useMemo as useMemo16, useState as useState23 } from "react";
|
6800
6847
|
|
6801
6848
|
// css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
|
6802
6849
|
init_react_import();
|
@@ -6820,7 +6867,7 @@ var ViewportButton = ({
|
|
6820
6867
|
}) => {
|
6821
6868
|
const { state } = useAppContext();
|
6822
6869
|
const [isActive, setIsActive] = useState23(false);
|
6823
|
-
|
6870
|
+
useEffect21(() => {
|
6824
6871
|
setIsActive(width === state.ui.viewports.current.width);
|
6825
6872
|
}, [width, state.ui.viewports.current.width]);
|
6826
6873
|
return /* @__PURE__ */ jsx36("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ jsx36(
|
@@ -6856,7 +6903,7 @@ var ViewportControls = ({
|
|
6856
6903
|
const defaultsContainAutoZoom = defaultZoomOptions.find(
|
6857
6904
|
(option) => option.value === autoZoom
|
6858
6905
|
);
|
6859
|
-
const zoomOptions =
|
6906
|
+
const zoomOptions = useMemo16(
|
6860
6907
|
() => [
|
6861
6908
|
...defaultZoomOptions,
|
6862
6909
|
...defaultsContainAutoZoom ? [] : [
|
@@ -6979,17 +7026,17 @@ var Canvas = () => {
|
|
6979
7026
|
const { status, iframe } = useAppContext();
|
6980
7027
|
const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
|
6981
7028
|
const { ui } = state;
|
6982
|
-
const frameRef =
|
7029
|
+
const frameRef = useRef9(null);
|
6983
7030
|
const [showTransition, setShowTransition] = useState24(false);
|
6984
|
-
const defaultRender =
|
7031
|
+
const defaultRender = useMemo17(() => {
|
6985
7032
|
const PuckDefault = ({ children }) => /* @__PURE__ */ jsx37(Fragment13, { children });
|
6986
7033
|
return PuckDefault;
|
6987
7034
|
}, []);
|
6988
|
-
const CustomPreview =
|
7035
|
+
const CustomPreview = useMemo17(
|
6989
7036
|
() => overrides.preview || defaultRender,
|
6990
7037
|
[overrides]
|
6991
7038
|
);
|
6992
|
-
const getFrameDimensions =
|
7039
|
+
const getFrameDimensions = useCallback16(() => {
|
6993
7040
|
if (frameRef.current) {
|
6994
7041
|
const frame = frameRef.current;
|
6995
7042
|
const box = getBox(frame);
|
@@ -6997,7 +7044,7 @@ var Canvas = () => {
|
|
6997
7044
|
}
|
6998
7045
|
return { width: 0, height: 0 };
|
6999
7046
|
}, [frameRef]);
|
7000
|
-
const resetAutoZoom =
|
7047
|
+
const resetAutoZoom = useCallback16(
|
7001
7048
|
(ui2 = state.ui) => {
|
7002
7049
|
if (frameRef.current) {
|
7003
7050
|
setZoomConfig(
|
@@ -7007,11 +7054,11 @@ var Canvas = () => {
|
|
7007
7054
|
},
|
7008
7055
|
[frameRef, zoomConfig, state.ui]
|
7009
7056
|
);
|
7010
|
-
|
7057
|
+
useEffect22(() => {
|
7011
7058
|
setShowTransition(false);
|
7012
7059
|
resetAutoZoom();
|
7013
7060
|
}, [frameRef, ui.leftSideBarVisible, ui.rightSideBarVisible]);
|
7014
|
-
|
7061
|
+
useEffect22(() => {
|
7015
7062
|
const { height: frameHeight } = getFrameDimensions();
|
7016
7063
|
if (ui.viewports.current.height === "auto") {
|
7017
7064
|
setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
|
@@ -7019,13 +7066,13 @@ var Canvas = () => {
|
|
7019
7066
|
}));
|
7020
7067
|
}
|
7021
7068
|
}, [zoomConfig.zoom]);
|
7022
|
-
|
7069
|
+
useEffect22(() => {
|
7023
7070
|
if (ZOOM_ON_CHANGE) {
|
7024
7071
|
setShowTransition(true);
|
7025
7072
|
resetAutoZoom(ui);
|
7026
7073
|
}
|
7027
7074
|
}, [ui.viewports.current.width]);
|
7028
|
-
|
7075
|
+
useEffect22(() => {
|
7029
7076
|
const cb = () => {
|
7030
7077
|
setShowTransition(false);
|
7031
7078
|
resetAutoZoom();
|
@@ -7036,7 +7083,7 @@ var Canvas = () => {
|
|
7036
7083
|
};
|
7037
7084
|
}, []);
|
7038
7085
|
const [showLoader, setShowLoader] = useState24(false);
|
7039
|
-
|
7086
|
+
useEffect22(() => {
|
7040
7087
|
setTimeout(() => {
|
7041
7088
|
setShowLoader(true);
|
7042
7089
|
}, 500);
|
@@ -7114,7 +7161,7 @@ var Canvas = () => {
|
|
7114
7161
|
|
7115
7162
|
// lib/use-loaded-overrides.ts
|
7116
7163
|
init_react_import();
|
7117
|
-
import { useMemo as
|
7164
|
+
import { useMemo as useMemo18 } from "react";
|
7118
7165
|
|
7119
7166
|
// lib/load-overrides.ts
|
7120
7167
|
init_react_import();
|
@@ -7153,7 +7200,7 @@ var useLoadedOverrides = ({
|
|
7153
7200
|
overrides,
|
7154
7201
|
plugins
|
7155
7202
|
}) => {
|
7156
|
-
return
|
7203
|
+
return useMemo18(() => {
|
7157
7204
|
return loadOverrides({ overrides, plugins });
|
7158
7205
|
}, [plugins, overrides]);
|
7159
7206
|
};
|
@@ -7165,14 +7212,14 @@ var DefaultOverride = ({ children }) => /* @__PURE__ */ jsx38(Fragment14, { chil
|
|
7165
7212
|
|
7166
7213
|
// lib/use-inject-css.ts
|
7167
7214
|
init_react_import();
|
7168
|
-
import { useEffect as
|
7215
|
+
import { useEffect as useEffect23, useState as useState25 } from "react";
|
7169
7216
|
var styles = ``;
|
7170
7217
|
var useInjectStyleSheet = (initialStyles, iframeEnabled) => {
|
7171
7218
|
const [el, setEl] = useState25();
|
7172
|
-
|
7219
|
+
useEffect23(() => {
|
7173
7220
|
setEl(document.createElement("style"));
|
7174
7221
|
}, []);
|
7175
|
-
|
7222
|
+
useEffect23(() => {
|
7176
7223
|
var _a;
|
7177
7224
|
if (!el || typeof window === "undefined") {
|
7178
7225
|
return;
|
@@ -7192,10 +7239,10 @@ var useInjectGlobalCss = (iframeEnabled) => {
|
|
7192
7239
|
|
7193
7240
|
// lib/use-preview-mode-hotkeys.ts
|
7194
7241
|
init_react_import();
|
7195
|
-
import { useCallback as
|
7242
|
+
import { useCallback as useCallback17 } from "react";
|
7196
7243
|
import { useHotkeys as useHotkeys2 } from "react-hotkeys-hook";
|
7197
7244
|
var usePreviewModeHotkeys = (dispatch, iframeEnabled) => {
|
7198
|
-
const toggleInteractive =
|
7245
|
+
const toggleInteractive = useCallback17(() => {
|
7199
7246
|
dispatch({
|
7200
7247
|
type: "setUi",
|
7201
7248
|
ui: (ui) => ({
|
@@ -7340,11 +7387,11 @@ function Puck({
|
|
7340
7387
|
const [menuOpen, setMenuOpen] = useState26(false);
|
7341
7388
|
const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
|
7342
7389
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
7343
|
-
|
7390
|
+
useEffect24(() => {
|
7344
7391
|
if (onChange) onChange(data);
|
7345
7392
|
}, [data]);
|
7346
7393
|
const rootProps = data.root.props || data.root;
|
7347
|
-
const toggleSidebars =
|
7394
|
+
const toggleSidebars = useCallback18(
|
7348
7395
|
(sidebar) => {
|
7349
7396
|
const widerViewport = window.matchMedia("(min-width: 638px)").matches;
|
7350
7397
|
const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
|
@@ -7358,7 +7405,7 @@ function Puck({
|
|
7358
7405
|
},
|
7359
7406
|
[dispatch, leftSideBarVisible, rightSideBarVisible]
|
7360
7407
|
);
|
7361
|
-
|
7408
|
+
useEffect24(() => {
|
7362
7409
|
if (!window.matchMedia("(min-width: 638px)").matches) {
|
7363
7410
|
dispatch({
|
7364
7411
|
type: "setUi",
|
@@ -7381,7 +7428,7 @@ function Puck({
|
|
7381
7428
|
window.removeEventListener("resize", handleResize);
|
7382
7429
|
};
|
7383
7430
|
}, []);
|
7384
|
-
const defaultHeaderRender =
|
7431
|
+
const defaultHeaderRender = useMemo19(() => {
|
7385
7432
|
if (renderHeader) {
|
7386
7433
|
console.warn(
|
7387
7434
|
"`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
|
@@ -7395,7 +7442,7 @@ function Puck({
|
|
7395
7442
|
}
|
7396
7443
|
return DefaultOverride;
|
7397
7444
|
}, [renderHeader]);
|
7398
|
-
const defaultHeaderActionsRender =
|
7445
|
+
const defaultHeaderActionsRender = useMemo19(() => {
|
7399
7446
|
if (renderHeaderActions) {
|
7400
7447
|
console.warn(
|
7401
7448
|
"`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
|
@@ -7412,20 +7459,20 @@ function Puck({
|
|
7412
7459
|
overrides,
|
7413
7460
|
plugins
|
7414
7461
|
});
|
7415
|
-
const CustomPuck =
|
7462
|
+
const CustomPuck = useMemo19(
|
7416
7463
|
() => loadedOverrides.puck || DefaultOverride,
|
7417
7464
|
[loadedOverrides]
|
7418
7465
|
);
|
7419
|
-
const CustomHeader =
|
7466
|
+
const CustomHeader = useMemo19(
|
7420
7467
|
() => loadedOverrides.header || defaultHeaderRender,
|
7421
7468
|
[loadedOverrides]
|
7422
7469
|
);
|
7423
|
-
const CustomHeaderActions =
|
7470
|
+
const CustomHeaderActions = useMemo19(
|
7424
7471
|
() => loadedOverrides.headerActions || defaultHeaderActionsRender,
|
7425
7472
|
[loadedOverrides]
|
7426
7473
|
);
|
7427
7474
|
const [mounted, setMounted] = useState26(false);
|
7428
|
-
|
7475
|
+
useEffect24(() => {
|
7429
7476
|
setMounted(true);
|
7430
7477
|
}, []);
|
7431
7478
|
const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
|