@measured/puck 0.18.0-canary.01d9695 → 0.18.0-canary.057e23b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.css +44 -47
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +163 -118
- package/dist/index.mjs +145 -100
- 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 {
|
@@ -4350,6 +4350,11 @@ var reduceUi = (ui, action) => {
|
|
4350
4350
|
itemSelector: { index: action.sourceIndex + 1, zone: action.sourceZone }
|
4351
4351
|
});
|
4352
4352
|
}
|
4353
|
+
if (action.type === "remove") {
|
4354
|
+
return __spreadProps(__spreadValues({}, ui), {
|
4355
|
+
itemSelector: null
|
4356
|
+
});
|
4357
|
+
}
|
4353
4358
|
return ui;
|
4354
4359
|
};
|
4355
4360
|
|
@@ -5256,9 +5261,9 @@ Drawer.Item = DrawerItem;
|
|
5256
5261
|
// components/Puck/index.tsx
|
5257
5262
|
init_react_import();
|
5258
5263
|
import {
|
5259
|
-
useCallback as
|
5260
|
-
useEffect as
|
5261
|
-
useMemo as
|
5264
|
+
useCallback as useCallback18,
|
5265
|
+
useEffect as useEffect24,
|
5266
|
+
useMemo as useMemo19,
|
5262
5267
|
useReducer,
|
5263
5268
|
useState as useState26
|
5264
5269
|
} from "react";
|
@@ -5454,36 +5459,61 @@ init_react_import();
|
|
5454
5459
|
|
5455
5460
|
// css-module:/home/runner/work/puck/puck/packages/core/components/Puck/components/Fields/styles.module.css#css-module
|
5456
5461
|
init_react_import();
|
5457
|
-
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" };
|
5458
5463
|
|
5459
5464
|
// components/Puck/components/Fields/index.tsx
|
5460
|
-
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";
|
5461
5470
|
|
5462
5471
|
// lib/use-parent.ts
|
5463
5472
|
init_react_import();
|
5464
|
-
import { useContext as useContext9 } from "react";
|
5465
|
-
var
|
5473
|
+
import { useCallback as useCallback12, useContext as useContext9 } from "react";
|
5474
|
+
var getParent = (itemSelector, pathData, data) => {
|
5466
5475
|
var _a;
|
5467
|
-
|
5468
|
-
const
|
5469
|
-
const
|
5470
|
-
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);
|
5471
5479
|
const lastItem = breadcrumbs[breadcrumbs.length - 1];
|
5472
|
-
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;
|
5473
5481
|
return parent || null;
|
5474
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
|
+
};
|
5475
5494
|
|
5476
|
-
//
|
5477
|
-
|
5478
|
-
|
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
|
5479
5514
|
var defaultPageFields = {
|
5480
5515
|
title: { type: "text" }
|
5481
5516
|
};
|
5482
|
-
var DefaultFields = ({
|
5483
|
-
children
|
5484
|
-
}) => {
|
5485
|
-
return /* @__PURE__ */ jsx27(Fragment8, { children });
|
5486
|
-
};
|
5487
5517
|
var useResolvedFields = () => {
|
5488
5518
|
var _a, _b;
|
5489
5519
|
const { selectedItem, state, config } = useAppContext();
|
@@ -5499,12 +5529,13 @@ var useResolvedFields = () => {
|
|
5499
5529
|
const [lastSelectedData, setLastSelectedData] = useState19({});
|
5500
5530
|
const [resolvedFields, setResolvedFields] = useState19(defaultFields);
|
5501
5531
|
const [fieldsLoading, setFieldsLoading] = useState19(false);
|
5532
|
+
const lastFields = useRef6(defaultFields);
|
5502
5533
|
const defaultResolveFields = (_componentData, _params) => defaultFields;
|
5503
5534
|
const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
|
5504
5535
|
const hasComponentResolver = selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields);
|
5505
5536
|
const hasRootResolver = !selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields);
|
5506
5537
|
const hasResolver = hasComponentResolver || hasRootResolver;
|
5507
|
-
const resolveFields =
|
5538
|
+
const resolveFields = useCallback13(
|
5508
5539
|
(..._0) => __async(void 0, [..._0], function* (fields = {}) {
|
5509
5540
|
var _a2;
|
5510
5541
|
const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
|
@@ -5516,7 +5547,7 @@ var useResolvedFields = () => {
|
|
5516
5547
|
{
|
5517
5548
|
changed,
|
5518
5549
|
fields,
|
5519
|
-
lastFields:
|
5550
|
+
lastFields: lastFields.current,
|
5520
5551
|
lastData,
|
5521
5552
|
appState: state,
|
5522
5553
|
parent
|
@@ -5527,7 +5558,7 @@ var useResolvedFields = () => {
|
|
5527
5558
|
return yield config.root.resolveFields(componentData, {
|
5528
5559
|
changed,
|
5529
5560
|
fields,
|
5530
|
-
lastFields:
|
5561
|
+
lastFields: lastFields.current,
|
5531
5562
|
lastData,
|
5532
5563
|
appState: state,
|
5533
5564
|
parent
|
@@ -5536,40 +5567,56 @@ var useResolvedFields = () => {
|
|
5536
5567
|
return defaultResolveFields(componentData, {
|
5537
5568
|
changed,
|
5538
5569
|
fields,
|
5539
|
-
lastFields:
|
5570
|
+
lastFields: lastFields.current,
|
5540
5571
|
lastData
|
5541
5572
|
});
|
5542
5573
|
}),
|
5543
|
-
[data, config, componentData, selectedItem,
|
5574
|
+
[data, config, componentData, selectedItem, state, parent]
|
5544
5575
|
);
|
5545
|
-
const
|
5546
|
-
useEffect16(() => {
|
5547
|
-
setHasParent(!!parent);
|
5548
|
-
}, [parent]);
|
5549
|
-
useEffect16(() => {
|
5576
|
+
const triggerResolver = useCallback13(() => {
|
5550
5577
|
var _a2, _b2;
|
5551
|
-
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" ||
|
5578
|
+
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" || parent) {
|
5552
5579
|
if (hasResolver) {
|
5553
5580
|
setFieldsLoading(true);
|
5554
5581
|
resolveFields(defaultFields).then((fields) => {
|
5555
5582
|
setResolvedFields(fields || {});
|
5583
|
+
lastFields.current = fields;
|
5556
5584
|
setFieldsLoading(false);
|
5557
5585
|
});
|
5558
|
-
|
5559
|
-
setResolvedFields(defaultFields);
|
5586
|
+
return;
|
5560
5587
|
}
|
5561
5588
|
}
|
5562
|
-
|
5563
|
-
|
5564
|
-
|
5589
|
+
setResolvedFields(defaultFields);
|
5590
|
+
}, [defaultFields, state.ui.itemSelector, hasResolver, parent]);
|
5591
|
+
useOnValueChange(
|
5565
5592
|
state.ui.itemSelector,
|
5566
|
-
|
5567
|
-
|
5568
|
-
|
5569
|
-
|
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
|
+
}, []);
|
5570
5608
|
return [resolvedFields, fieldsLoading];
|
5571
5609
|
};
|
5572
|
-
|
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 }) => {
|
5573
5620
|
var _a, _b;
|
5574
5621
|
const {
|
5575
5622
|
selectedItem,
|
@@ -5587,11 +5634,11 @@ var Fields = () => {
|
|
5587
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;
|
5588
5635
|
const isLoading = fieldsResolving || componentResolving;
|
5589
5636
|
const rootProps = data.root.props || data.root;
|
5590
|
-
const Wrapper =
|
5637
|
+
const Wrapper = useMemo12(() => overrides.fields || DefaultFields, [overrides]);
|
5591
5638
|
return /* @__PURE__ */ jsxs14(
|
5592
5639
|
"form",
|
5593
5640
|
{
|
5594
|
-
className: getClassName21(),
|
5641
|
+
className: getClassName21({ wrapFields }),
|
5595
5642
|
onSubmit: (e) => {
|
5596
5643
|
e.preventDefault();
|
5597
5644
|
},
|
@@ -5667,7 +5714,7 @@ var Fields = () => {
|
|
5667
5714
|
item: selectedItem
|
5668
5715
|
});
|
5669
5716
|
const id = `${selectedItem.props.id}_${field.type}_${fieldName}`;
|
5670
|
-
return /* @__PURE__ */ jsx27(
|
5717
|
+
return /* @__PURE__ */ jsx27("div", { className: getClassName21("field"), children: /* @__PURE__ */ jsx27(
|
5671
5718
|
AutoFieldPrivate,
|
5672
5719
|
{
|
5673
5720
|
field,
|
@@ -5676,16 +5723,15 @@ var Fields = () => {
|
|
5676
5723
|
readOnly: !edit || readOnly[fieldName],
|
5677
5724
|
value: selectedItem.props[fieldName],
|
5678
5725
|
onChange
|
5679
|
-
}
|
5680
|
-
|
5681
|
-
);
|
5726
|
+
}
|
5727
|
+
) }, id);
|
5682
5728
|
} else {
|
5683
5729
|
const readOnly = data.root.readOnly || {};
|
5684
5730
|
const { edit } = getPermissions({
|
5685
5731
|
root: true
|
5686
5732
|
});
|
5687
5733
|
const id = `root_${field.type}_${fieldName}`;
|
5688
|
-
return /* @__PURE__ */ jsx27(
|
5734
|
+
return /* @__PURE__ */ jsx27("div", { className: getClassName21("field"), children: /* @__PURE__ */ jsx27(
|
5689
5735
|
AutoFieldPrivate,
|
5690
5736
|
{
|
5691
5737
|
field,
|
@@ -5694,9 +5740,8 @@ var Fields = () => {
|
|
5694
5740
|
readOnly: !edit || readOnly[fieldName],
|
5695
5741
|
value: rootProps[fieldName],
|
5696
5742
|
onChange
|
5697
|
-
}
|
5698
|
-
|
5699
|
-
);
|
5743
|
+
}
|
5744
|
+
) }, id);
|
5700
5745
|
}
|
5701
5746
|
}) }),
|
5702
5747
|
isLoading && /* @__PURE__ */ jsx27("div", { className: getClassName21("loadingOverlay"), children: /* @__PURE__ */ jsx27("div", { className: getClassName21("loadingOverlayInner"), children: /* @__PURE__ */ jsx27(Loader, { size: 16 }) }) })
|
@@ -5710,7 +5755,7 @@ init_react_import();
|
|
5710
5755
|
|
5711
5756
|
// lib/use-component-list.tsx
|
5712
5757
|
init_react_import();
|
5713
|
-
import { useEffect as
|
5758
|
+
import { useEffect as useEffect18, useState as useState20 } from "react";
|
5714
5759
|
|
5715
5760
|
// components/ComponentList/index.tsx
|
5716
5761
|
init_react_import();
|
@@ -5778,7 +5823,7 @@ ComponentList.Item = ComponentListItem;
|
|
5778
5823
|
import { jsx as jsx29 } from "react/jsx-runtime";
|
5779
5824
|
var useComponentList = (config, ui) => {
|
5780
5825
|
const [componentList, setComponentList] = useState20();
|
5781
|
-
|
5826
|
+
useEffect18(() => {
|
5782
5827
|
var _a, _b, _c;
|
5783
5828
|
if (Object.keys(ui.componentList).length > 0) {
|
5784
5829
|
const matchedComponents = [];
|
@@ -5847,25 +5892,25 @@ var useComponentList = (config, ui) => {
|
|
5847
5892
|
};
|
5848
5893
|
|
5849
5894
|
// components/Puck/components/Components/index.tsx
|
5850
|
-
import { useMemo as
|
5895
|
+
import { useMemo as useMemo13 } from "react";
|
5851
5896
|
import { jsx as jsx30 } from "react/jsx-runtime";
|
5852
5897
|
var Components = () => {
|
5853
5898
|
const { config, state, overrides } = useAppContext();
|
5854
5899
|
const componentList = useComponentList(config, state.ui);
|
5855
|
-
const Wrapper =
|
5900
|
+
const Wrapper = useMemo13(() => overrides.components || "div", [overrides]);
|
5856
5901
|
return /* @__PURE__ */ jsx30(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ jsx30(ComponentList, { id: "all" }) });
|
5857
5902
|
};
|
5858
5903
|
|
5859
5904
|
// components/Puck/components/Preview/index.tsx
|
5860
5905
|
init_react_import();
|
5861
|
-
import { useCallback as
|
5906
|
+
import { useCallback as useCallback14, useEffect as useEffect20, useRef as useRef8, useMemo as useMemo14 } from "react";
|
5862
5907
|
|
5863
5908
|
// components/AutoFrame/index.tsx
|
5864
5909
|
init_react_import();
|
5865
5910
|
import {
|
5866
5911
|
createContext as createContext5,
|
5867
5912
|
useContext as useContext10,
|
5868
|
-
useEffect as
|
5913
|
+
useEffect as useEffect19,
|
5869
5914
|
useState as useState21
|
5870
5915
|
} from "react";
|
5871
5916
|
import hash from "object-hash";
|
@@ -5913,7 +5958,7 @@ var CopyHostStyles = ({
|
|
5913
5958
|
onStylesLoaded = () => null
|
5914
5959
|
}) => {
|
5915
5960
|
const { document: doc, window: win } = useFrame();
|
5916
|
-
|
5961
|
+
useEffect19(() => {
|
5917
5962
|
if (!win || !doc) {
|
5918
5963
|
return () => {
|
5919
5964
|
};
|
@@ -6093,7 +6138,7 @@ function AutoFrame(_a) {
|
|
6093
6138
|
const [loaded, setLoaded] = useState21(false);
|
6094
6139
|
const [ctx, setCtx] = useState21({});
|
6095
6140
|
const [mountTarget, setMountTarget] = useState21();
|
6096
|
-
|
6141
|
+
useEffect19(() => {
|
6097
6142
|
var _a2;
|
6098
6143
|
if (frameRef.current) {
|
6099
6144
|
setCtx({
|
@@ -6187,7 +6232,7 @@ import { Fragment as Fragment10, jsx as jsx33 } from "react/jsx-runtime";
|
|
6187
6232
|
var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
|
6188
6233
|
var useBubbleIframeEvents = (ref) => {
|
6189
6234
|
const { status } = useAppContext();
|
6190
|
-
|
6235
|
+
useEffect20(() => {
|
6191
6236
|
var _a;
|
6192
6237
|
if (ref.current && status === "READY") {
|
6193
6238
|
const iframe = ref.current;
|
@@ -6226,7 +6271,7 @@ var useBubbleIframeEvents = (ref) => {
|
|
6226
6271
|
};
|
6227
6272
|
var Preview2 = ({ id = "puck-preview" }) => {
|
6228
6273
|
const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
|
6229
|
-
const Page =
|
6274
|
+
const Page = useCallback14(
|
6230
6275
|
(pageProps) => {
|
6231
6276
|
var _a, _b;
|
6232
6277
|
return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
|
@@ -6235,9 +6280,9 @@ var Preview2 = ({ id = "puck-preview" }) => {
|
|
6235
6280
|
},
|
6236
6281
|
[config.root]
|
6237
6282
|
);
|
6238
|
-
const Frame =
|
6283
|
+
const Frame = useMemo14(() => overrides.iframe, [overrides]);
|
6239
6284
|
const rootProps = state.data.root.props || state.data.root;
|
6240
|
-
const ref =
|
6285
|
+
const ref = useRef8(null);
|
6241
6286
|
useBubbleIframeEvents(ref);
|
6242
6287
|
const inner = state.ui.previewMode === "edit" ? /* @__PURE__ */ jsx33(
|
6243
6288
|
Page,
|
@@ -6487,13 +6532,13 @@ var LayerTree = ({
|
|
6487
6532
|
};
|
6488
6533
|
|
6489
6534
|
// components/Puck/components/Outline/index.tsx
|
6490
|
-
import { useCallback as
|
6535
|
+
import { useCallback as useCallback15, useMemo as useMemo15 } from "react";
|
6491
6536
|
import { Fragment as Fragment12, jsx as jsx35, jsxs as jsxs17 } from "react/jsx-runtime";
|
6492
6537
|
var Outline = () => {
|
6493
6538
|
const { dispatch, state, overrides, config } = useAppContext();
|
6494
6539
|
const { data, ui } = state;
|
6495
6540
|
const { itemSelector } = ui;
|
6496
|
-
const setItemSelector =
|
6541
|
+
const setItemSelector = useCallback15(
|
6497
6542
|
(newItemSelector) => {
|
6498
6543
|
dispatch({
|
6499
6544
|
type: "setUi",
|
@@ -6502,7 +6547,7 @@ var Outline = () => {
|
|
6502
6547
|
},
|
6503
6548
|
[]
|
6504
6549
|
);
|
6505
|
-
const Wrapper =
|
6550
|
+
const Wrapper = useMemo15(() => overrides.outline || "div", [overrides]);
|
6506
6551
|
return /* @__PURE__ */ jsx35(Wrapper, { children: /* @__PURE__ */ jsx35(dropZoneContext.Consumer, { children: (ctx) => /* @__PURE__ */ jsxs17(Fragment12, { children: [
|
6507
6552
|
(ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ jsx35(
|
6508
6553
|
LayerTree,
|
@@ -6789,16 +6834,16 @@ var getBox = function getBox2(el) {
|
|
6789
6834
|
|
6790
6835
|
// components/Puck/components/Canvas/index.tsx
|
6791
6836
|
import {
|
6792
|
-
useCallback as
|
6793
|
-
useEffect as
|
6794
|
-
useMemo as
|
6795
|
-
useRef as
|
6837
|
+
useCallback as useCallback16,
|
6838
|
+
useEffect as useEffect22,
|
6839
|
+
useMemo as useMemo17,
|
6840
|
+
useRef as useRef9,
|
6796
6841
|
useState as useState24
|
6797
6842
|
} from "react";
|
6798
6843
|
|
6799
6844
|
// components/ViewportControls/index.tsx
|
6800
6845
|
init_react_import();
|
6801
|
-
import { useEffect as
|
6846
|
+
import { useEffect as useEffect21, useMemo as useMemo16, useState as useState23 } from "react";
|
6802
6847
|
|
6803
6848
|
// css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
|
6804
6849
|
init_react_import();
|
@@ -6822,7 +6867,7 @@ var ViewportButton = ({
|
|
6822
6867
|
}) => {
|
6823
6868
|
const { state } = useAppContext();
|
6824
6869
|
const [isActive, setIsActive] = useState23(false);
|
6825
|
-
|
6870
|
+
useEffect21(() => {
|
6826
6871
|
setIsActive(width === state.ui.viewports.current.width);
|
6827
6872
|
}, [width, state.ui.viewports.current.width]);
|
6828
6873
|
return /* @__PURE__ */ jsx36("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ jsx36(
|
@@ -6858,7 +6903,7 @@ var ViewportControls = ({
|
|
6858
6903
|
const defaultsContainAutoZoom = defaultZoomOptions.find(
|
6859
6904
|
(option) => option.value === autoZoom
|
6860
6905
|
);
|
6861
|
-
const zoomOptions =
|
6906
|
+
const zoomOptions = useMemo16(
|
6862
6907
|
() => [
|
6863
6908
|
...defaultZoomOptions,
|
6864
6909
|
...defaultsContainAutoZoom ? [] : [
|
@@ -6981,17 +7026,17 @@ var Canvas = () => {
|
|
6981
7026
|
const { status, iframe } = useAppContext();
|
6982
7027
|
const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
|
6983
7028
|
const { ui } = state;
|
6984
|
-
const frameRef =
|
7029
|
+
const frameRef = useRef9(null);
|
6985
7030
|
const [showTransition, setShowTransition] = useState24(false);
|
6986
|
-
const defaultRender =
|
7031
|
+
const defaultRender = useMemo17(() => {
|
6987
7032
|
const PuckDefault = ({ children }) => /* @__PURE__ */ jsx37(Fragment13, { children });
|
6988
7033
|
return PuckDefault;
|
6989
7034
|
}, []);
|
6990
|
-
const CustomPreview =
|
7035
|
+
const CustomPreview = useMemo17(
|
6991
7036
|
() => overrides.preview || defaultRender,
|
6992
7037
|
[overrides]
|
6993
7038
|
);
|
6994
|
-
const getFrameDimensions =
|
7039
|
+
const getFrameDimensions = useCallback16(() => {
|
6995
7040
|
if (frameRef.current) {
|
6996
7041
|
const frame = frameRef.current;
|
6997
7042
|
const box = getBox(frame);
|
@@ -6999,7 +7044,7 @@ var Canvas = () => {
|
|
6999
7044
|
}
|
7000
7045
|
return { width: 0, height: 0 };
|
7001
7046
|
}, [frameRef]);
|
7002
|
-
const resetAutoZoom =
|
7047
|
+
const resetAutoZoom = useCallback16(
|
7003
7048
|
(ui2 = state.ui) => {
|
7004
7049
|
if (frameRef.current) {
|
7005
7050
|
setZoomConfig(
|
@@ -7009,11 +7054,11 @@ var Canvas = () => {
|
|
7009
7054
|
},
|
7010
7055
|
[frameRef, zoomConfig, state.ui]
|
7011
7056
|
);
|
7012
|
-
|
7057
|
+
useEffect22(() => {
|
7013
7058
|
setShowTransition(false);
|
7014
7059
|
resetAutoZoom();
|
7015
7060
|
}, [frameRef, ui.leftSideBarVisible, ui.rightSideBarVisible]);
|
7016
|
-
|
7061
|
+
useEffect22(() => {
|
7017
7062
|
const { height: frameHeight } = getFrameDimensions();
|
7018
7063
|
if (ui.viewports.current.height === "auto") {
|
7019
7064
|
setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
|
@@ -7021,13 +7066,13 @@ var Canvas = () => {
|
|
7021
7066
|
}));
|
7022
7067
|
}
|
7023
7068
|
}, [zoomConfig.zoom]);
|
7024
|
-
|
7069
|
+
useEffect22(() => {
|
7025
7070
|
if (ZOOM_ON_CHANGE) {
|
7026
7071
|
setShowTransition(true);
|
7027
7072
|
resetAutoZoom(ui);
|
7028
7073
|
}
|
7029
7074
|
}, [ui.viewports.current.width]);
|
7030
|
-
|
7075
|
+
useEffect22(() => {
|
7031
7076
|
const cb = () => {
|
7032
7077
|
setShowTransition(false);
|
7033
7078
|
resetAutoZoom();
|
@@ -7038,7 +7083,7 @@ var Canvas = () => {
|
|
7038
7083
|
};
|
7039
7084
|
}, []);
|
7040
7085
|
const [showLoader, setShowLoader] = useState24(false);
|
7041
|
-
|
7086
|
+
useEffect22(() => {
|
7042
7087
|
setTimeout(() => {
|
7043
7088
|
setShowLoader(true);
|
7044
7089
|
}, 500);
|
@@ -7116,7 +7161,7 @@ var Canvas = () => {
|
|
7116
7161
|
|
7117
7162
|
// lib/use-loaded-overrides.ts
|
7118
7163
|
init_react_import();
|
7119
|
-
import { useMemo as
|
7164
|
+
import { useMemo as useMemo18 } from "react";
|
7120
7165
|
|
7121
7166
|
// lib/load-overrides.ts
|
7122
7167
|
init_react_import();
|
@@ -7155,7 +7200,7 @@ var useLoadedOverrides = ({
|
|
7155
7200
|
overrides,
|
7156
7201
|
plugins
|
7157
7202
|
}) => {
|
7158
|
-
return
|
7203
|
+
return useMemo18(() => {
|
7159
7204
|
return loadOverrides({ overrides, plugins });
|
7160
7205
|
}, [plugins, overrides]);
|
7161
7206
|
};
|
@@ -7167,14 +7212,14 @@ var DefaultOverride = ({ children }) => /* @__PURE__ */ jsx38(Fragment14, { chil
|
|
7167
7212
|
|
7168
7213
|
// lib/use-inject-css.ts
|
7169
7214
|
init_react_import();
|
7170
|
-
import { useEffect as
|
7215
|
+
import { useEffect as useEffect23, useState as useState25 } from "react";
|
7171
7216
|
var styles = ``;
|
7172
7217
|
var useInjectStyleSheet = (initialStyles, iframeEnabled) => {
|
7173
7218
|
const [el, setEl] = useState25();
|
7174
|
-
|
7219
|
+
useEffect23(() => {
|
7175
7220
|
setEl(document.createElement("style"));
|
7176
7221
|
}, []);
|
7177
|
-
|
7222
|
+
useEffect23(() => {
|
7178
7223
|
var _a;
|
7179
7224
|
if (!el || typeof window === "undefined") {
|
7180
7225
|
return;
|
@@ -7194,10 +7239,10 @@ var useInjectGlobalCss = (iframeEnabled) => {
|
|
7194
7239
|
|
7195
7240
|
// lib/use-preview-mode-hotkeys.ts
|
7196
7241
|
init_react_import();
|
7197
|
-
import { useCallback as
|
7242
|
+
import { useCallback as useCallback17 } from "react";
|
7198
7243
|
import { useHotkeys as useHotkeys2 } from "react-hotkeys-hook";
|
7199
7244
|
var usePreviewModeHotkeys = (dispatch, iframeEnabled) => {
|
7200
|
-
const toggleInteractive =
|
7245
|
+
const toggleInteractive = useCallback17(() => {
|
7201
7246
|
dispatch({
|
7202
7247
|
type: "setUi",
|
7203
7248
|
ui: (ui) => ({
|
@@ -7342,11 +7387,11 @@ function Puck({
|
|
7342
7387
|
const [menuOpen, setMenuOpen] = useState26(false);
|
7343
7388
|
const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
|
7344
7389
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
7345
|
-
|
7390
|
+
useEffect24(() => {
|
7346
7391
|
if (onChange) onChange(data);
|
7347
7392
|
}, [data]);
|
7348
7393
|
const rootProps = data.root.props || data.root;
|
7349
|
-
const toggleSidebars =
|
7394
|
+
const toggleSidebars = useCallback18(
|
7350
7395
|
(sidebar) => {
|
7351
7396
|
const widerViewport = window.matchMedia("(min-width: 638px)").matches;
|
7352
7397
|
const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
|
@@ -7360,7 +7405,7 @@ function Puck({
|
|
7360
7405
|
},
|
7361
7406
|
[dispatch, leftSideBarVisible, rightSideBarVisible]
|
7362
7407
|
);
|
7363
|
-
|
7408
|
+
useEffect24(() => {
|
7364
7409
|
if (!window.matchMedia("(min-width: 638px)").matches) {
|
7365
7410
|
dispatch({
|
7366
7411
|
type: "setUi",
|
@@ -7383,7 +7428,7 @@ function Puck({
|
|
7383
7428
|
window.removeEventListener("resize", handleResize);
|
7384
7429
|
};
|
7385
7430
|
}, []);
|
7386
|
-
const defaultHeaderRender =
|
7431
|
+
const defaultHeaderRender = useMemo19(() => {
|
7387
7432
|
if (renderHeader) {
|
7388
7433
|
console.warn(
|
7389
7434
|
"`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
|
@@ -7397,7 +7442,7 @@ function Puck({
|
|
7397
7442
|
}
|
7398
7443
|
return DefaultOverride;
|
7399
7444
|
}, [renderHeader]);
|
7400
|
-
const defaultHeaderActionsRender =
|
7445
|
+
const defaultHeaderActionsRender = useMemo19(() => {
|
7401
7446
|
if (renderHeaderActions) {
|
7402
7447
|
console.warn(
|
7403
7448
|
"`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
|
@@ -7414,20 +7459,20 @@ function Puck({
|
|
7414
7459
|
overrides,
|
7415
7460
|
plugins
|
7416
7461
|
});
|
7417
|
-
const CustomPuck =
|
7462
|
+
const CustomPuck = useMemo19(
|
7418
7463
|
() => loadedOverrides.puck || DefaultOverride,
|
7419
7464
|
[loadedOverrides]
|
7420
7465
|
);
|
7421
|
-
const CustomHeader =
|
7466
|
+
const CustomHeader = useMemo19(
|
7422
7467
|
() => loadedOverrides.header || defaultHeaderRender,
|
7423
7468
|
[loadedOverrides]
|
7424
7469
|
);
|
7425
|
-
const CustomHeaderActions =
|
7470
|
+
const CustomHeaderActions = useMemo19(
|
7426
7471
|
() => loadedOverrides.headerActions || defaultHeaderActionsRender,
|
7427
7472
|
[loadedOverrides]
|
7428
7473
|
);
|
7429
7474
|
const [mounted, setMounted] = useState26(false);
|
7430
|
-
|
7475
|
+
useEffect24(() => {
|
7431
7476
|
setMounted(true);
|
7432
7477
|
}, []);
|
7433
7478
|
const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
|
package/package.json
CHANGED