@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.mjs
CHANGED
@@ -1504,12 +1504,13 @@ var DefaultField = ({
|
|
1504
1504
|
field,
|
1505
1505
|
onChange,
|
1506
1506
|
readOnly,
|
1507
|
-
value,
|
1507
|
+
value: _value,
|
1508
1508
|
name,
|
1509
1509
|
label,
|
1510
1510
|
Label: Label2,
|
1511
1511
|
id
|
1512
1512
|
}) => {
|
1513
|
+
const value = _value;
|
1513
1514
|
return /* @__PURE__ */ jsx9(
|
1514
1515
|
Label2,
|
1515
1516
|
{
|
@@ -1527,7 +1528,7 @@ var DefaultField = ({
|
|
1527
1528
|
type: field.type,
|
1528
1529
|
title: label || name,
|
1529
1530
|
name,
|
1530
|
-
value:
|
1531
|
+
value: (value == null ? void 0 : value.toString) ? value.toString() : "",
|
1531
1532
|
onChange: (e) => {
|
1532
1533
|
if (field.type === "number") {
|
1533
1534
|
const numberValue = Number(e.currentTarget.value);
|
@@ -2436,7 +2437,7 @@ import {
|
|
2436
2437
|
useContext as useContext7,
|
2437
2438
|
useEffect as useEffect15,
|
2438
2439
|
useId,
|
2439
|
-
useRef as
|
2440
|
+
useRef as useRef3,
|
2440
2441
|
useState as useState17
|
2441
2442
|
} from "react";
|
2442
2443
|
import { AutoScroller, defaultPreset } from "@dnd-kit/dom";
|
@@ -2449,7 +2450,7 @@ import {
|
|
2449
2450
|
useContext as useContext6,
|
2450
2451
|
useEffect as useEffect14,
|
2451
2452
|
useMemo as useMemo8,
|
2452
|
-
useRef as
|
2453
|
+
useRef as useRef2
|
2453
2454
|
} from "react";
|
2454
2455
|
|
2455
2456
|
// components/DraggableComponent/index.tsx
|
@@ -2459,7 +2460,7 @@ import {
|
|
2459
2460
|
useContext as useContext5,
|
2460
2461
|
useEffect as useEffect10,
|
2461
2462
|
useMemo as useMemo7,
|
2462
|
-
useRef
|
2463
|
+
useRef,
|
2463
2464
|
useState as useState13
|
2464
2465
|
} from "react";
|
2465
2466
|
|
@@ -3047,7 +3048,7 @@ var DraggableComponent = ({
|
|
3047
3048
|
}
|
3048
3049
|
});
|
3049
3050
|
const thisIsDragging = status === "dragging";
|
3050
|
-
const ref =
|
3051
|
+
const ref = useRef(null);
|
3051
3052
|
const refSetter = useCallback7(
|
3052
3053
|
(el) => {
|
3053
3054
|
sortableRef(el);
|
@@ -3098,13 +3099,19 @@ var DraggableComponent = ({
|
|
3098
3099
|
}
|
3099
3100
|
}, [ref.current]);
|
3100
3101
|
useEffect10(() => {
|
3101
|
-
|
3102
|
-
|
3102
|
+
ctx == null ? void 0 : ctx.registerPath(
|
3103
|
+
id,
|
3104
|
+
{
|
3103
3105
|
index,
|
3104
3106
|
zone: zoneCompound
|
3105
|
-
}
|
3106
|
-
|
3107
|
-
|
3107
|
+
},
|
3108
|
+
componentType
|
3109
|
+
);
|
3110
|
+
return () => {
|
3111
|
+
var _a;
|
3112
|
+
(_a = ctx == null ? void 0 : ctx.unregisterPath) == null ? void 0 : _a.call(ctx, id);
|
3113
|
+
};
|
3114
|
+
}, [id, zoneCompound, index, componentType]);
|
3108
3115
|
const CustomActionBar = useMemo7(
|
3109
3116
|
() => overrides.actionBar || DefaultActionBar,
|
3110
3117
|
[overrides.actionBar]
|
@@ -3424,9 +3431,20 @@ var useContentWithPreview = (content, zoneCompound) => {
|
|
3424
3431
|
};
|
3425
3432
|
}
|
3426
3433
|
);
|
3434
|
+
const {
|
3435
|
+
state: {
|
3436
|
+
ui: { isDragging }
|
3437
|
+
}
|
3438
|
+
} = useAppContext();
|
3427
3439
|
const [contentWithPreview, setContentWithPreview] = useState15(content);
|
3440
|
+
const [localPreview, setLocalPreview] = useState15(
|
3441
|
+
preview
|
3442
|
+
);
|
3428
3443
|
const updateContent = useRenderedCallback(
|
3429
|
-
(content2, preview2) => {
|
3444
|
+
(content2, preview2, isDragging2) => {
|
3445
|
+
if (isDragging2 && !previewExists) {
|
3446
|
+
return;
|
3447
|
+
}
|
3430
3448
|
if (preview2) {
|
3431
3449
|
if (preview2.type === "insert") {
|
3432
3450
|
setContentWithPreview(
|
@@ -3456,13 +3474,14 @@ var useContentWithPreview = (content, zoneCompound) => {
|
|
3456
3474
|
previewExists ? content2.filter((item) => item.props.id !== draggedItemId) : content2
|
3457
3475
|
);
|
3458
3476
|
}
|
3477
|
+
setLocalPreview(preview2);
|
3459
3478
|
},
|
3460
3479
|
[draggedItemId, previewExists]
|
3461
3480
|
);
|
3462
3481
|
useEffect12(() => {
|
3463
|
-
updateContent(content, preview);
|
3464
|
-
}, [content, preview]);
|
3465
|
-
return contentWithPreview;
|
3482
|
+
updateContent(content, preview, isDragging);
|
3483
|
+
}, [content, preview, isDragging]);
|
3484
|
+
return [contentWithPreview, localPreview];
|
3466
3485
|
};
|
3467
3486
|
|
3468
3487
|
// components/DropZone/lib/use-drag-axis.ts
|
@@ -3542,8 +3561,7 @@ var DropZoneEdit = forwardRef3(
|
|
3542
3561
|
isDeepestZone,
|
3543
3562
|
inNextDeepestArea,
|
3544
3563
|
draggedComponentType,
|
3545
|
-
userIsDragging
|
3546
|
-
preview
|
3564
|
+
userIsDragging
|
3547
3565
|
} = useContextStore(ZoneStoreContext, (s) => {
|
3548
3566
|
var _a, _b, _c;
|
3549
3567
|
return {
|
@@ -3551,8 +3569,7 @@ var DropZoneEdit = forwardRef3(
|
|
3551
3569
|
inNextDeepestArea: s.nextAreaDepthIndex[areaId || ""],
|
3552
3570
|
draggedItemId: (_b = s.draggedItem) == null ? void 0 : _b.id,
|
3553
3571
|
draggedComponentType: (_c = s.draggedItem) == null ? void 0 : _c.data.componentType,
|
3554
|
-
userIsDragging: !!s.draggedItem
|
3555
|
-
preview: s.previewIndex[zoneCompound]
|
3572
|
+
userIsDragging: !!s.draggedItem
|
3556
3573
|
};
|
3557
3574
|
});
|
3558
3575
|
const { itemSelector } = appContext2.state.ui;
|
@@ -3577,7 +3594,7 @@ var DropZoneEdit = forwardRef3(
|
|
3577
3594
|
}
|
3578
3595
|
return data.content || [];
|
3579
3596
|
}, [data, zoneCompound]);
|
3580
|
-
const ref =
|
3597
|
+
const ref = useRef2(null);
|
3581
3598
|
const acceptsTarget = useCallback10(
|
3582
3599
|
(componentType) => {
|
3583
3600
|
if (!componentType) {
|
@@ -3618,7 +3635,10 @@ var DropZoneEdit = forwardRef3(
|
|
3618
3635
|
if (isEnabled) {
|
3619
3636
|
isEnabled = acceptsTarget(draggedComponentType);
|
3620
3637
|
}
|
3621
|
-
const contentWithPreview = useContentWithPreview(
|
3638
|
+
const [contentWithPreview, preview] = useContentWithPreview(
|
3639
|
+
content,
|
3640
|
+
zoneCompound
|
3641
|
+
);
|
3622
3642
|
const isDropEnabled = isEnabled && (preview ? contentWithPreview.length === 1 : contentWithPreview.length === 0);
|
3623
3643
|
const droppableConfig = {
|
3624
3644
|
id: zoneCompound,
|
@@ -3663,7 +3683,7 @@ var DropZoneEdit = forwardRef3(
|
|
3663
3683
|
"data-puck-dnd": zoneCompound,
|
3664
3684
|
style: __spreadProps(__spreadValues({}, style), {
|
3665
3685
|
"--min-empty-height": `${minEmptyHeight}px`,
|
3666
|
-
backgroundColor: RENDER_DEBUG ? getRandomColor() : void 0
|
3686
|
+
backgroundColor: RENDER_DEBUG ? getRandomColor() : style == null ? void 0 : style.backgroundColor
|
3667
3687
|
}),
|
3668
3688
|
children: contentWithPreview.map((item, i) => {
|
3669
3689
|
var _a, _b, _c, _d, _e, _f, _g;
|
@@ -4734,7 +4754,7 @@ function useDragListener(type, fn, deps = []) {
|
|
4734
4754
|
}
|
4735
4755
|
var AREA_CHANGE_DEBOUNCE_MS = 100;
|
4736
4756
|
var useTempDisableFallback = (timeout3) => {
|
4737
|
-
const lastFallbackDisable =
|
4757
|
+
const lastFallbackDisable = useRef3(null);
|
4738
4758
|
return useCallback11((manager) => {
|
4739
4759
|
collisionStore.setState({ fallbackEnabled: false });
|
4740
4760
|
const fallbackId = generateId();
|
@@ -4754,7 +4774,7 @@ var DragDropContextClient = ({
|
|
4754
4774
|
const { state, config, dispatch, resolveData } = useAppContext();
|
4755
4775
|
const id = useId();
|
4756
4776
|
const { data } = state;
|
4757
|
-
const debouncedParamsRef =
|
4777
|
+
const debouncedParamsRef = useRef3(null);
|
4758
4778
|
const tempDisableFallback = useTempDisableFallback(100);
|
4759
4779
|
const [zoneStore] = useState17(
|
4760
4780
|
() => createStore3(() => ({
|
@@ -4893,30 +4913,36 @@ var DragDropContextClient = ({
|
|
4893
4913
|
]);
|
4894
4914
|
const [dragListeners, setDragListeners] = useState17({});
|
4895
4915
|
const [pathData, setPathData] = useState17();
|
4896
|
-
const dragMode =
|
4916
|
+
const dragMode = useRef3(null);
|
4897
4917
|
const registerPath = useCallback11(
|
4898
|
-
(selector) => {
|
4899
|
-
const item = getItem(selector, data);
|
4900
|
-
if (!item) {
|
4901
|
-
return;
|
4902
|
-
}
|
4918
|
+
(id2, selector, label) => {
|
4903
4919
|
const [area] = getZoneId(selector.zone);
|
4904
4920
|
setPathData((latestPathData = {}) => {
|
4905
4921
|
const parentPathData = latestPathData[area] || { path: [] };
|
4906
4922
|
return __spreadProps(__spreadValues({}, latestPathData), {
|
4907
|
-
[
|
4923
|
+
[id2]: {
|
4908
4924
|
path: [
|
4909
4925
|
...parentPathData.path,
|
4910
4926
|
...selector.zone ? [selector.zone] : []
|
4911
4927
|
],
|
4912
|
-
label
|
4928
|
+
label
|
4913
4929
|
}
|
4914
4930
|
});
|
4915
4931
|
});
|
4916
4932
|
},
|
4917
4933
|
[data, setPathData]
|
4918
4934
|
);
|
4919
|
-
const
|
4935
|
+
const unregisterPath = useCallback11(
|
4936
|
+
(id2) => {
|
4937
|
+
setPathData((latestPathData = {}) => {
|
4938
|
+
const newPathData = __spreadValues({}, latestPathData);
|
4939
|
+
delete newPathData[id2];
|
4940
|
+
return newPathData;
|
4941
|
+
});
|
4942
|
+
},
|
4943
|
+
[data, setPathData]
|
4944
|
+
);
|
4945
|
+
const initialSelector = useRef3(void 0);
|
4920
4946
|
return /* @__PURE__ */ jsx23("div", { id, children: /* @__PURE__ */ jsx23(
|
4921
4947
|
dragListenerContext.Provider,
|
4922
4948
|
{
|
@@ -5112,6 +5138,7 @@ var DragDropContextClient = ({
|
|
5112
5138
|
areaId: "root",
|
5113
5139
|
depth: 0,
|
5114
5140
|
registerPath,
|
5141
|
+
unregisterPath,
|
5115
5142
|
pathData,
|
5116
5143
|
path: []
|
5117
5144
|
},
|
@@ -5261,9 +5288,9 @@ Drawer.Item = DrawerItem;
|
|
5261
5288
|
// components/Puck/index.tsx
|
5262
5289
|
init_react_import();
|
5263
5290
|
import {
|
5264
|
-
useCallback as
|
5265
|
-
useEffect as
|
5266
|
-
useMemo as
|
5291
|
+
useCallback as useCallback18,
|
5292
|
+
useEffect as useEffect24,
|
5293
|
+
useMemo as useMemo19,
|
5267
5294
|
useReducer,
|
5268
5295
|
useState as useState26
|
5269
5296
|
} from "react";
|
@@ -5462,33 +5489,58 @@ init_react_import();
|
|
5462
5489
|
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" };
|
5463
5490
|
|
5464
5491
|
// components/Puck/components/Fields/index.tsx
|
5465
|
-
import {
|
5492
|
+
import { useMemo as useMemo12 } from "react";
|
5493
|
+
|
5494
|
+
// lib/use-resolved-fields.ts
|
5495
|
+
init_react_import();
|
5496
|
+
import { useCallback as useCallback13, useEffect as useEffect17, useMemo as useMemo11, useRef as useRef5, useState as useState19 } from "react";
|
5466
5497
|
|
5467
5498
|
// lib/use-parent.ts
|
5468
5499
|
init_react_import();
|
5469
|
-
import { useContext as useContext9 } from "react";
|
5470
|
-
var
|
5500
|
+
import { useCallback as useCallback12, useContext as useContext9 } from "react";
|
5501
|
+
var getParent = (itemSelector, pathData, data) => {
|
5471
5502
|
var _a;
|
5472
|
-
|
5473
|
-
const
|
5474
|
-
const
|
5475
|
-
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, state.data);
|
5503
|
+
if (!itemSelector) return null;
|
5504
|
+
const item = getItem(itemSelector, data);
|
5505
|
+
const breadcrumbs = convertPathDataToBreadcrumbs(item, pathData, data);
|
5476
5506
|
const lastItem = breadcrumbs[breadcrumbs.length - 1];
|
5477
|
-
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector,
|
5507
|
+
const parent = (lastItem == null ? void 0 : lastItem.selector) ? (_a = getItem(lastItem.selector, data)) != null ? _a : null : null;
|
5478
5508
|
return parent || null;
|
5479
5509
|
};
|
5510
|
+
var useGetParent = () => {
|
5511
|
+
const { state } = useAppContext();
|
5512
|
+
const { pathData } = useContext9(dropZoneContext) || {};
|
5513
|
+
return useCallback12(
|
5514
|
+
() => getParent(state.ui.itemSelector, pathData, state.data),
|
5515
|
+
[state.ui.itemSelector, pathData, state.data]
|
5516
|
+
);
|
5517
|
+
};
|
5518
|
+
var useParent = () => {
|
5519
|
+
return useGetParent()();
|
5520
|
+
};
|
5480
5521
|
|
5481
|
-
//
|
5482
|
-
|
5483
|
-
|
5522
|
+
// lib/use-on-value-change.ts
|
5523
|
+
init_react_import();
|
5524
|
+
import { useRef as useRef4, useEffect as useEffect16 } from "react";
|
5525
|
+
function useOnValueChange(value, onChange, compare = Object.is, deps = []) {
|
5526
|
+
const tracked = useRef4(value);
|
5527
|
+
useEffect16(() => {
|
5528
|
+
const oldValue = tracked.current;
|
5529
|
+
if (!compare(value, oldValue)) {
|
5530
|
+
tracked.current = value;
|
5531
|
+
onChange(value, oldValue);
|
5532
|
+
}
|
5533
|
+
}, [onChange, compare, value, ...deps]);
|
5534
|
+
}
|
5535
|
+
|
5536
|
+
// lib/selector-is.ts
|
5537
|
+
init_react_import();
|
5538
|
+
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);
|
5539
|
+
|
5540
|
+
// lib/use-resolved-fields.ts
|
5484
5541
|
var defaultPageFields = {
|
5485
5542
|
title: { type: "text" }
|
5486
5543
|
};
|
5487
|
-
var DefaultFields = ({
|
5488
|
-
children
|
5489
|
-
}) => {
|
5490
|
-
return /* @__PURE__ */ jsx27(Fragment8, { children });
|
5491
|
-
};
|
5492
5544
|
var useResolvedFields = () => {
|
5493
5545
|
var _a, _b;
|
5494
5546
|
const { selectedItem, state, config } = useAppContext();
|
@@ -5504,12 +5556,13 @@ var useResolvedFields = () => {
|
|
5504
5556
|
const [lastSelectedData, setLastSelectedData] = useState19({});
|
5505
5557
|
const [resolvedFields, setResolvedFields] = useState19(defaultFields);
|
5506
5558
|
const [fieldsLoading, setFieldsLoading] = useState19(false);
|
5559
|
+
const lastFields = useRef5(defaultFields);
|
5507
5560
|
const defaultResolveFields = (_componentData, _params) => defaultFields;
|
5508
5561
|
const componentData = selectedItem ? selectedItem : { props: rootProps, readOnly: data.root.readOnly };
|
5509
5562
|
const hasComponentResolver = selectedItem && (componentConfig == null ? void 0 : componentConfig.resolveFields);
|
5510
5563
|
const hasRootResolver = !selectedItem && ((_b = config.root) == null ? void 0 : _b.resolveFields);
|
5511
5564
|
const hasResolver = hasComponentResolver || hasRootResolver;
|
5512
|
-
const resolveFields =
|
5565
|
+
const resolveFields = useCallback13(
|
5513
5566
|
(..._0) => __async(void 0, [..._0], function* (fields = {}) {
|
5514
5567
|
var _a2;
|
5515
5568
|
const lastData = ((_a2 = lastSelectedData.props) == null ? void 0 : _a2.id) === componentData.props.id ? lastSelectedData : null;
|
@@ -5521,7 +5574,7 @@ var useResolvedFields = () => {
|
|
5521
5574
|
{
|
5522
5575
|
changed,
|
5523
5576
|
fields,
|
5524
|
-
lastFields:
|
5577
|
+
lastFields: lastFields.current,
|
5525
5578
|
lastData,
|
5526
5579
|
appState: state,
|
5527
5580
|
parent
|
@@ -5532,7 +5585,7 @@ var useResolvedFields = () => {
|
|
5532
5585
|
return yield config.root.resolveFields(componentData, {
|
5533
5586
|
changed,
|
5534
5587
|
fields,
|
5535
|
-
lastFields:
|
5588
|
+
lastFields: lastFields.current,
|
5536
5589
|
lastData,
|
5537
5590
|
appState: state,
|
5538
5591
|
parent
|
@@ -5541,39 +5594,55 @@ var useResolvedFields = () => {
|
|
5541
5594
|
return defaultResolveFields(componentData, {
|
5542
5595
|
changed,
|
5543
5596
|
fields,
|
5544
|
-
lastFields:
|
5597
|
+
lastFields: lastFields.current,
|
5545
5598
|
lastData
|
5546
5599
|
});
|
5547
5600
|
}),
|
5548
|
-
[data, config, componentData, selectedItem,
|
5601
|
+
[data, config, componentData, selectedItem, state, parent]
|
5549
5602
|
);
|
5550
|
-
const
|
5551
|
-
useEffect16(() => {
|
5552
|
-
setHasParent(!!parent);
|
5553
|
-
}, [parent]);
|
5554
|
-
useEffect16(() => {
|
5603
|
+
const triggerResolver = useCallback13(() => {
|
5555
5604
|
var _a2, _b2;
|
5556
|
-
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" ||
|
5605
|
+
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || ((_b2 = state.ui.itemSelector) == null ? void 0 : _b2.zone) === "default-zone" || parent) {
|
5557
5606
|
if (hasResolver) {
|
5558
5607
|
setFieldsLoading(true);
|
5559
5608
|
resolveFields(defaultFields).then((fields) => {
|
5560
5609
|
setResolvedFields(fields || {});
|
5610
|
+
lastFields.current = fields;
|
5561
5611
|
setFieldsLoading(false);
|
5562
5612
|
});
|
5563
5613
|
return;
|
5564
5614
|
}
|
5565
5615
|
}
|
5566
5616
|
setResolvedFields(defaultFields);
|
5567
|
-
}, [
|
5568
|
-
|
5569
|
-
defaultFields,
|
5617
|
+
}, [defaultFields, state.ui.itemSelector, hasResolver, parent]);
|
5618
|
+
useOnValueChange(
|
5570
5619
|
state.ui.itemSelector,
|
5571
|
-
|
5572
|
-
|
5573
|
-
|
5574
|
-
|
5620
|
+
() => {
|
5621
|
+
lastFields.current = defaultFields;
|
5622
|
+
},
|
5623
|
+
selectorIs
|
5624
|
+
);
|
5625
|
+
useOnValueChange(
|
5626
|
+
{ data, parent, itemSelector: state.ui.itemSelector },
|
5627
|
+
() => {
|
5628
|
+
triggerResolver();
|
5629
|
+
},
|
5630
|
+
(a, b) => JSON.stringify(a) === JSON.stringify(b)
|
5631
|
+
);
|
5632
|
+
useEffect17(() => {
|
5633
|
+
triggerResolver();
|
5634
|
+
}, []);
|
5575
5635
|
return [resolvedFields, fieldsLoading];
|
5576
5636
|
};
|
5637
|
+
|
5638
|
+
// components/Puck/components/Fields/index.tsx
|
5639
|
+
import { Fragment as Fragment8, jsx as jsx27, jsxs as jsxs14 } from "react/jsx-runtime";
|
5640
|
+
var getClassName21 = get_class_name_factory_default("PuckFields", styles_module_default16);
|
5641
|
+
var DefaultFields = ({
|
5642
|
+
children
|
5643
|
+
}) => {
|
5644
|
+
return /* @__PURE__ */ jsx27(Fragment8, { children });
|
5645
|
+
};
|
5577
5646
|
var Fields = ({ wrapFields = true }) => {
|
5578
5647
|
var _a, _b;
|
5579
5648
|
const {
|
@@ -5592,7 +5661,7 @@ var Fields = ({ wrapFields = true }) => {
|
|
5592
5661
|
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;
|
5593
5662
|
const isLoading = fieldsResolving || componentResolving;
|
5594
5663
|
const rootProps = data.root.props || data.root;
|
5595
|
-
const Wrapper =
|
5664
|
+
const Wrapper = useMemo12(() => overrides.fields || DefaultFields, [overrides]);
|
5596
5665
|
return /* @__PURE__ */ jsxs14(
|
5597
5666
|
"form",
|
5598
5667
|
{
|
@@ -5713,7 +5782,7 @@ init_react_import();
|
|
5713
5782
|
|
5714
5783
|
// lib/use-component-list.tsx
|
5715
5784
|
init_react_import();
|
5716
|
-
import { useEffect as
|
5785
|
+
import { useEffect as useEffect18, useState as useState20 } from "react";
|
5717
5786
|
|
5718
5787
|
// components/ComponentList/index.tsx
|
5719
5788
|
init_react_import();
|
@@ -5781,7 +5850,7 @@ ComponentList.Item = ComponentListItem;
|
|
5781
5850
|
import { jsx as jsx29 } from "react/jsx-runtime";
|
5782
5851
|
var useComponentList = (config, ui) => {
|
5783
5852
|
const [componentList, setComponentList] = useState20();
|
5784
|
-
|
5853
|
+
useEffect18(() => {
|
5785
5854
|
var _a, _b, _c;
|
5786
5855
|
if (Object.keys(ui.componentList).length > 0) {
|
5787
5856
|
const matchedComponents = [];
|
@@ -5850,25 +5919,25 @@ var useComponentList = (config, ui) => {
|
|
5850
5919
|
};
|
5851
5920
|
|
5852
5921
|
// components/Puck/components/Components/index.tsx
|
5853
|
-
import { useMemo as
|
5922
|
+
import { useMemo as useMemo13 } from "react";
|
5854
5923
|
import { jsx as jsx30 } from "react/jsx-runtime";
|
5855
5924
|
var Components = () => {
|
5856
5925
|
const { config, state, overrides } = useAppContext();
|
5857
5926
|
const componentList = useComponentList(config, state.ui);
|
5858
|
-
const Wrapper =
|
5927
|
+
const Wrapper = useMemo13(() => overrides.components || "div", [overrides]);
|
5859
5928
|
return /* @__PURE__ */ jsx30(Wrapper, { children: componentList ? componentList : /* @__PURE__ */ jsx30(ComponentList, { id: "all" }) });
|
5860
5929
|
};
|
5861
5930
|
|
5862
5931
|
// components/Puck/components/Preview/index.tsx
|
5863
5932
|
init_react_import();
|
5864
|
-
import { useCallback as
|
5933
|
+
import { useCallback as useCallback14, useEffect as useEffect20, useRef as useRef7, useMemo as useMemo14 } from "react";
|
5865
5934
|
|
5866
5935
|
// components/AutoFrame/index.tsx
|
5867
5936
|
init_react_import();
|
5868
5937
|
import {
|
5869
5938
|
createContext as createContext5,
|
5870
5939
|
useContext as useContext10,
|
5871
|
-
useEffect as
|
5940
|
+
useEffect as useEffect19,
|
5872
5941
|
useState as useState21
|
5873
5942
|
} from "react";
|
5874
5943
|
import hash from "object-hash";
|
@@ -5916,7 +5985,7 @@ var CopyHostStyles = ({
|
|
5916
5985
|
onStylesLoaded = () => null
|
5917
5986
|
}) => {
|
5918
5987
|
const { document: doc, window: win } = useFrame();
|
5919
|
-
|
5988
|
+
useEffect19(() => {
|
5920
5989
|
if (!win || !doc) {
|
5921
5990
|
return () => {
|
5922
5991
|
};
|
@@ -6096,7 +6165,7 @@ function AutoFrame(_a) {
|
|
6096
6165
|
const [loaded, setLoaded] = useState21(false);
|
6097
6166
|
const [ctx, setCtx] = useState21({});
|
6098
6167
|
const [mountTarget, setMountTarget] = useState21();
|
6099
|
-
|
6168
|
+
useEffect19(() => {
|
6100
6169
|
var _a2;
|
6101
6170
|
if (frameRef.current) {
|
6102
6171
|
setCtx({
|
@@ -6190,7 +6259,7 @@ import { Fragment as Fragment10, jsx as jsx33 } from "react/jsx-runtime";
|
|
6190
6259
|
var getClassName23 = get_class_name_factory_default("PuckPreview", styles_module_default18);
|
6191
6260
|
var useBubbleIframeEvents = (ref) => {
|
6192
6261
|
const { status } = useAppContext();
|
6193
|
-
|
6262
|
+
useEffect20(() => {
|
6194
6263
|
var _a;
|
6195
6264
|
if (ref.current && status === "READY") {
|
6196
6265
|
const iframe = ref.current;
|
@@ -6229,7 +6298,7 @@ var useBubbleIframeEvents = (ref) => {
|
|
6229
6298
|
};
|
6230
6299
|
var Preview2 = ({ id = "puck-preview" }) => {
|
6231
6300
|
const { config, dispatch, state, setStatus, iframe, overrides } = useAppContext();
|
6232
|
-
const Page =
|
6301
|
+
const Page = useCallback14(
|
6233
6302
|
(pageProps) => {
|
6234
6303
|
var _a, _b;
|
6235
6304
|
return ((_a = config.root) == null ? void 0 : _a.render) ? (_b = config.root) == null ? void 0 : _b.render(__spreadValues({
|
@@ -6238,9 +6307,9 @@ var Preview2 = ({ id = "puck-preview" }) => {
|
|
6238
6307
|
},
|
6239
6308
|
[config.root]
|
6240
6309
|
);
|
6241
|
-
const Frame =
|
6310
|
+
const Frame = useMemo14(() => overrides.iframe, [overrides]);
|
6242
6311
|
const rootProps = state.data.root.props || state.data.root;
|
6243
|
-
const ref =
|
6312
|
+
const ref = useRef7(null);
|
6244
6313
|
useBubbleIframeEvents(ref);
|
6245
6314
|
const inner = state.ui.previewMode === "edit" ? /* @__PURE__ */ jsx33(
|
6246
6315
|
Page,
|
@@ -6490,13 +6559,13 @@ var LayerTree = ({
|
|
6490
6559
|
};
|
6491
6560
|
|
6492
6561
|
// components/Puck/components/Outline/index.tsx
|
6493
|
-
import { useCallback as
|
6562
|
+
import { useCallback as useCallback15, useMemo as useMemo15 } from "react";
|
6494
6563
|
import { Fragment as Fragment12, jsx as jsx35, jsxs as jsxs17 } from "react/jsx-runtime";
|
6495
6564
|
var Outline = () => {
|
6496
6565
|
const { dispatch, state, overrides, config } = useAppContext();
|
6497
6566
|
const { data, ui } = state;
|
6498
6567
|
const { itemSelector } = ui;
|
6499
|
-
const setItemSelector =
|
6568
|
+
const setItemSelector = useCallback15(
|
6500
6569
|
(newItemSelector) => {
|
6501
6570
|
dispatch({
|
6502
6571
|
type: "setUi",
|
@@ -6505,7 +6574,7 @@ var Outline = () => {
|
|
6505
6574
|
},
|
6506
6575
|
[]
|
6507
6576
|
);
|
6508
|
-
const Wrapper =
|
6577
|
+
const Wrapper = useMemo15(() => overrides.outline || "div", [overrides]);
|
6509
6578
|
return /* @__PURE__ */ jsx35(Wrapper, { children: /* @__PURE__ */ jsx35(dropZoneContext.Consumer, { children: (ctx) => /* @__PURE__ */ jsxs17(Fragment12, { children: [
|
6510
6579
|
(ctx == null ? void 0 : ctx.activeZones) && (ctx == null ? void 0 : ctx.activeZones[rootDroppableId]) && /* @__PURE__ */ jsx35(
|
6511
6580
|
LayerTree,
|
@@ -6792,16 +6861,16 @@ var getBox = function getBox2(el) {
|
|
6792
6861
|
|
6793
6862
|
// components/Puck/components/Canvas/index.tsx
|
6794
6863
|
import {
|
6795
|
-
useCallback as
|
6796
|
-
useEffect as
|
6797
|
-
useMemo as
|
6798
|
-
useRef as
|
6864
|
+
useCallback as useCallback16,
|
6865
|
+
useEffect as useEffect22,
|
6866
|
+
useMemo as useMemo17,
|
6867
|
+
useRef as useRef8,
|
6799
6868
|
useState as useState24
|
6800
6869
|
} from "react";
|
6801
6870
|
|
6802
6871
|
// components/ViewportControls/index.tsx
|
6803
6872
|
init_react_import();
|
6804
|
-
import { useEffect as
|
6873
|
+
import { useEffect as useEffect21, useMemo as useMemo16, useState as useState23 } from "react";
|
6805
6874
|
|
6806
6875
|
// css-module:/home/runner/work/puck/puck/packages/core/components/ViewportControls/styles.module.css#css-module
|
6807
6876
|
init_react_import();
|
@@ -6825,7 +6894,7 @@ var ViewportButton = ({
|
|
6825
6894
|
}) => {
|
6826
6895
|
const { state } = useAppContext();
|
6827
6896
|
const [isActive, setIsActive] = useState23(false);
|
6828
|
-
|
6897
|
+
useEffect21(() => {
|
6829
6898
|
setIsActive(width === state.ui.viewports.current.width);
|
6830
6899
|
}, [width, state.ui.viewports.current.width]);
|
6831
6900
|
return /* @__PURE__ */ jsx36("span", { className: getClassNameButton({ isActive }), children: /* @__PURE__ */ jsx36(
|
@@ -6861,7 +6930,7 @@ var ViewportControls = ({
|
|
6861
6930
|
const defaultsContainAutoZoom = defaultZoomOptions.find(
|
6862
6931
|
(option) => option.value === autoZoom
|
6863
6932
|
);
|
6864
|
-
const zoomOptions =
|
6933
|
+
const zoomOptions = useMemo16(
|
6865
6934
|
() => [
|
6866
6935
|
...defaultZoomOptions,
|
6867
6936
|
...defaultsContainAutoZoom ? [] : [
|
@@ -6984,17 +7053,17 @@ var Canvas = () => {
|
|
6984
7053
|
const { status, iframe } = useAppContext();
|
6985
7054
|
const { dispatch, state, overrides, setUi, zoomConfig, setZoomConfig } = useAppContext();
|
6986
7055
|
const { ui } = state;
|
6987
|
-
const frameRef =
|
7056
|
+
const frameRef = useRef8(null);
|
6988
7057
|
const [showTransition, setShowTransition] = useState24(false);
|
6989
|
-
const defaultRender =
|
7058
|
+
const defaultRender = useMemo17(() => {
|
6990
7059
|
const PuckDefault = ({ children }) => /* @__PURE__ */ jsx37(Fragment13, { children });
|
6991
7060
|
return PuckDefault;
|
6992
7061
|
}, []);
|
6993
|
-
const CustomPreview =
|
7062
|
+
const CustomPreview = useMemo17(
|
6994
7063
|
() => overrides.preview || defaultRender,
|
6995
7064
|
[overrides]
|
6996
7065
|
);
|
6997
|
-
const getFrameDimensions =
|
7066
|
+
const getFrameDimensions = useCallback16(() => {
|
6998
7067
|
if (frameRef.current) {
|
6999
7068
|
const frame = frameRef.current;
|
7000
7069
|
const box = getBox(frame);
|
@@ -7002,7 +7071,7 @@ var Canvas = () => {
|
|
7002
7071
|
}
|
7003
7072
|
return { width: 0, height: 0 };
|
7004
7073
|
}, [frameRef]);
|
7005
|
-
const resetAutoZoom =
|
7074
|
+
const resetAutoZoom = useCallback16(
|
7006
7075
|
(ui2 = state.ui) => {
|
7007
7076
|
if (frameRef.current) {
|
7008
7077
|
setZoomConfig(
|
@@ -7012,11 +7081,11 @@ var Canvas = () => {
|
|
7012
7081
|
},
|
7013
7082
|
[frameRef, zoomConfig, state.ui]
|
7014
7083
|
);
|
7015
|
-
|
7084
|
+
useEffect22(() => {
|
7016
7085
|
setShowTransition(false);
|
7017
7086
|
resetAutoZoom();
|
7018
7087
|
}, [frameRef, ui.leftSideBarVisible, ui.rightSideBarVisible]);
|
7019
|
-
|
7088
|
+
useEffect22(() => {
|
7020
7089
|
const { height: frameHeight } = getFrameDimensions();
|
7021
7090
|
if (ui.viewports.current.height === "auto") {
|
7022
7091
|
setZoomConfig(__spreadProps(__spreadValues({}, zoomConfig), {
|
@@ -7024,13 +7093,13 @@ var Canvas = () => {
|
|
7024
7093
|
}));
|
7025
7094
|
}
|
7026
7095
|
}, [zoomConfig.zoom]);
|
7027
|
-
|
7096
|
+
useEffect22(() => {
|
7028
7097
|
if (ZOOM_ON_CHANGE) {
|
7029
7098
|
setShowTransition(true);
|
7030
7099
|
resetAutoZoom(ui);
|
7031
7100
|
}
|
7032
7101
|
}, [ui.viewports.current.width]);
|
7033
|
-
|
7102
|
+
useEffect22(() => {
|
7034
7103
|
const cb = () => {
|
7035
7104
|
setShowTransition(false);
|
7036
7105
|
resetAutoZoom();
|
@@ -7041,7 +7110,7 @@ var Canvas = () => {
|
|
7041
7110
|
};
|
7042
7111
|
}, []);
|
7043
7112
|
const [showLoader, setShowLoader] = useState24(false);
|
7044
|
-
|
7113
|
+
useEffect22(() => {
|
7045
7114
|
setTimeout(() => {
|
7046
7115
|
setShowLoader(true);
|
7047
7116
|
}, 500);
|
@@ -7119,7 +7188,7 @@ var Canvas = () => {
|
|
7119
7188
|
|
7120
7189
|
// lib/use-loaded-overrides.ts
|
7121
7190
|
init_react_import();
|
7122
|
-
import { useMemo as
|
7191
|
+
import { useMemo as useMemo18 } from "react";
|
7123
7192
|
|
7124
7193
|
// lib/load-overrides.ts
|
7125
7194
|
init_react_import();
|
@@ -7158,7 +7227,7 @@ var useLoadedOverrides = ({
|
|
7158
7227
|
overrides,
|
7159
7228
|
plugins
|
7160
7229
|
}) => {
|
7161
|
-
return
|
7230
|
+
return useMemo18(() => {
|
7162
7231
|
return loadOverrides({ overrides, plugins });
|
7163
7232
|
}, [plugins, overrides]);
|
7164
7233
|
};
|
@@ -7170,14 +7239,14 @@ var DefaultOverride = ({ children }) => /* @__PURE__ */ jsx38(Fragment14, { chil
|
|
7170
7239
|
|
7171
7240
|
// lib/use-inject-css.ts
|
7172
7241
|
init_react_import();
|
7173
|
-
import { useEffect as
|
7242
|
+
import { useEffect as useEffect23, useState as useState25 } from "react";
|
7174
7243
|
var styles = ``;
|
7175
7244
|
var useInjectStyleSheet = (initialStyles, iframeEnabled) => {
|
7176
7245
|
const [el, setEl] = useState25();
|
7177
|
-
|
7246
|
+
useEffect23(() => {
|
7178
7247
|
setEl(document.createElement("style"));
|
7179
7248
|
}, []);
|
7180
|
-
|
7249
|
+
useEffect23(() => {
|
7181
7250
|
var _a;
|
7182
7251
|
if (!el || typeof window === "undefined") {
|
7183
7252
|
return;
|
@@ -7197,10 +7266,10 @@ var useInjectGlobalCss = (iframeEnabled) => {
|
|
7197
7266
|
|
7198
7267
|
// lib/use-preview-mode-hotkeys.ts
|
7199
7268
|
init_react_import();
|
7200
|
-
import { useCallback as
|
7269
|
+
import { useCallback as useCallback17 } from "react";
|
7201
7270
|
import { useHotkeys as useHotkeys2 } from "react-hotkeys-hook";
|
7202
7271
|
var usePreviewModeHotkeys = (dispatch, iframeEnabled) => {
|
7203
|
-
const toggleInteractive =
|
7272
|
+
const toggleInteractive = useCallback17(() => {
|
7204
7273
|
dispatch({
|
7205
7274
|
type: "setUi",
|
7206
7275
|
ui: (ui) => ({
|
@@ -7345,11 +7414,11 @@ function Puck({
|
|
7345
7414
|
const [menuOpen, setMenuOpen] = useState26(false);
|
7346
7415
|
const { itemSelector, leftSideBarVisible, rightSideBarVisible } = ui;
|
7347
7416
|
const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
|
7348
|
-
|
7417
|
+
useEffect24(() => {
|
7349
7418
|
if (onChange) onChange(data);
|
7350
7419
|
}, [data]);
|
7351
7420
|
const rootProps = data.root.props || data.root;
|
7352
|
-
const toggleSidebars =
|
7421
|
+
const toggleSidebars = useCallback18(
|
7353
7422
|
(sidebar) => {
|
7354
7423
|
const widerViewport = window.matchMedia("(min-width: 638px)").matches;
|
7355
7424
|
const sideBarVisible = sidebar === "left" ? leftSideBarVisible : rightSideBarVisible;
|
@@ -7363,7 +7432,7 @@ function Puck({
|
|
7363
7432
|
},
|
7364
7433
|
[dispatch, leftSideBarVisible, rightSideBarVisible]
|
7365
7434
|
);
|
7366
|
-
|
7435
|
+
useEffect24(() => {
|
7367
7436
|
if (!window.matchMedia("(min-width: 638px)").matches) {
|
7368
7437
|
dispatch({
|
7369
7438
|
type: "setUi",
|
@@ -7386,7 +7455,7 @@ function Puck({
|
|
7386
7455
|
window.removeEventListener("resize", handleResize);
|
7387
7456
|
};
|
7388
7457
|
}, []);
|
7389
|
-
const defaultHeaderRender =
|
7458
|
+
const defaultHeaderRender = useMemo19(() => {
|
7390
7459
|
if (renderHeader) {
|
7391
7460
|
console.warn(
|
7392
7461
|
"`renderHeader` is deprecated. Please use `overrides.header` and the `usePuck` hook instead"
|
@@ -7400,7 +7469,7 @@ function Puck({
|
|
7400
7469
|
}
|
7401
7470
|
return DefaultOverride;
|
7402
7471
|
}, [renderHeader]);
|
7403
|
-
const defaultHeaderActionsRender =
|
7472
|
+
const defaultHeaderActionsRender = useMemo19(() => {
|
7404
7473
|
if (renderHeaderActions) {
|
7405
7474
|
console.warn(
|
7406
7475
|
"`renderHeaderActions` is deprecated. Please use `overrides.headerActions` and the `usePuck` hook instead."
|
@@ -7417,20 +7486,20 @@ function Puck({
|
|
7417
7486
|
overrides,
|
7418
7487
|
plugins
|
7419
7488
|
});
|
7420
|
-
const CustomPuck =
|
7489
|
+
const CustomPuck = useMemo19(
|
7421
7490
|
() => loadedOverrides.puck || DefaultOverride,
|
7422
7491
|
[loadedOverrides]
|
7423
7492
|
);
|
7424
|
-
const CustomHeader =
|
7493
|
+
const CustomHeader = useMemo19(
|
7425
7494
|
() => loadedOverrides.header || defaultHeaderRender,
|
7426
7495
|
[loadedOverrides]
|
7427
7496
|
);
|
7428
|
-
const CustomHeaderActions =
|
7497
|
+
const CustomHeaderActions = useMemo19(
|
7429
7498
|
() => loadedOverrides.headerActions || defaultHeaderActionsRender,
|
7430
7499
|
[loadedOverrides]
|
7431
7500
|
);
|
7432
7501
|
const [mounted, setMounted] = useState26(false);
|
7433
|
-
|
7502
|
+
useEffect24(() => {
|
7434
7503
|
setMounted(true);
|
7435
7504
|
}, []);
|
7436
7505
|
const selectedComponentConfig = selectedItem && config.components[selectedItem.type];
|