@measured/puck 0.18.0-canary.4b589f6 → 0.18.0-canary.99e9ecb
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +89 -41
- package/dist/index.mjs +90 -42
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -3664,7 +3664,7 @@ var getClassName17 = get_class_name_factory_default("DropZone", styles_module_de
|
|
3664
3664
|
var getRandomColor = () => `#${Math.floor(Math.random() * 16777215).toString(16)}`;
|
3665
3665
|
var RENDER_DEBUG = false;
|
3666
3666
|
var DropZoneEdit = (0, import_react29.forwardRef)(
|
3667
|
-
function
|
3667
|
+
function DropZoneEditInternal({
|
3668
3668
|
zone,
|
3669
3669
|
allow,
|
3670
3670
|
disallow,
|
@@ -3825,7 +3825,7 @@ var DropZoneEdit = (0, import_react29.forwardRef)(
|
|
3825
3825
|
var _a, _b, _c, _d, _e;
|
3826
3826
|
const componentId = item.props.id;
|
3827
3827
|
const puckProps = {
|
3828
|
-
renderDropZone:
|
3828
|
+
renderDropZone: (props) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZoneEdit, __spreadValues({}, props)),
|
3829
3829
|
isEditing: true,
|
3830
3830
|
dragRef: null
|
3831
3831
|
};
|
@@ -3889,7 +3889,7 @@ var DropZoneEdit = (0, import_react29.forwardRef)(
|
|
3889
3889
|
}
|
3890
3890
|
);
|
3891
3891
|
var DropZoneRender = (0, import_react29.forwardRef)(
|
3892
|
-
function
|
3892
|
+
function DropZoneRenderInternal({ className, style, zone }, ref) {
|
3893
3893
|
const ctx = (0, import_react29.useContext)(dropZoneContext);
|
3894
3894
|
const { data, areaId = "root", config } = ctx || {};
|
3895
3895
|
let zoneCompound = rootDroppableId;
|
@@ -3927,7 +3927,9 @@ var DropZoneRender = (0, import_react29.forwardRef)(
|
|
3927
3927
|
children: /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(
|
3928
3928
|
Component.render,
|
3929
3929
|
__spreadProps(__spreadValues({}, item.props), {
|
3930
|
-
puck: {
|
3930
|
+
puck: {
|
3931
|
+
renderDropZone: (props) => /* @__PURE__ */ (0, import_jsx_runtime22.jsx)(DropZoneRender, __spreadValues({}, props))
|
3932
|
+
}
|
3931
3933
|
})
|
3932
3934
|
)
|
3933
3935
|
},
|
@@ -4002,6 +4004,48 @@ var getFrame = () => {
|
|
4002
4004
|
return (frameEl == null ? void 0 : frameEl.ownerDocument) || document;
|
4003
4005
|
};
|
4004
4006
|
|
4007
|
+
// lib/global-position.ts
|
4008
|
+
init_react_import();
|
4009
|
+
var GlobalPosition = class {
|
4010
|
+
constructor(target, original) {
|
4011
|
+
this.scaleFactor = 1;
|
4012
|
+
this.frameEl = null;
|
4013
|
+
this.frameRect = null;
|
4014
|
+
var _a;
|
4015
|
+
this.target = target;
|
4016
|
+
this.original = original;
|
4017
|
+
this.frameEl = document.querySelector("iframe");
|
4018
|
+
if (this.frameEl) {
|
4019
|
+
this.frameRect = this.frameEl.getBoundingClientRect();
|
4020
|
+
this.scaleFactor = this.frameRect.width / (((_a = this.frameEl.contentWindow) == null ? void 0 : _a.innerWidth) || 1);
|
4021
|
+
}
|
4022
|
+
}
|
4023
|
+
get x() {
|
4024
|
+
return this.original.x;
|
4025
|
+
}
|
4026
|
+
get y() {
|
4027
|
+
return this.original.y;
|
4028
|
+
}
|
4029
|
+
get global() {
|
4030
|
+
if (document !== this.target.ownerDocument && this.frameRect) {
|
4031
|
+
return {
|
4032
|
+
x: this.x * this.scaleFactor + this.frameRect.left,
|
4033
|
+
y: this.y * this.scaleFactor + this.frameRect.top
|
4034
|
+
};
|
4035
|
+
}
|
4036
|
+
return this.original;
|
4037
|
+
}
|
4038
|
+
get frame() {
|
4039
|
+
if (document === this.target.ownerDocument && this.frameRect) {
|
4040
|
+
return {
|
4041
|
+
x: (this.x - this.frameRect.left) / this.scaleFactor,
|
4042
|
+
y: (this.y - this.frameRect.top) / this.scaleFactor
|
4043
|
+
};
|
4044
|
+
}
|
4045
|
+
return this.original;
|
4046
|
+
}
|
4047
|
+
};
|
4048
|
+
|
4005
4049
|
// lib/dnd/NestedDroppablePlugin.ts
|
4006
4050
|
var depthSort = (candidates) => {
|
4007
4051
|
return candidates.sort((a, b) => {
|
@@ -4031,10 +4075,12 @@ var getZoneId2 = (candidate) => {
|
|
4031
4075
|
}
|
4032
4076
|
return id;
|
4033
4077
|
};
|
4034
|
-
var getPointerCollisions = (position, manager
|
4035
|
-
var _a;
|
4078
|
+
var getPointerCollisions = (position, manager) => {
|
4036
4079
|
const candidates = [];
|
4037
|
-
let elements = ownerDocument.elementsFromPoint(
|
4080
|
+
let elements = position.target.ownerDocument.elementsFromPoint(
|
4081
|
+
position.x,
|
4082
|
+
position.y
|
4083
|
+
);
|
4038
4084
|
const previewFrame = elements.find(
|
4039
4085
|
(el) => el.getAttribute("data-puck-preview")
|
4040
4086
|
);
|
@@ -4043,17 +4089,9 @@ var getPointerCollisions = (position, manager, ownerDocument) => {
|
|
4043
4089
|
elements = [drawer];
|
4044
4090
|
}
|
4045
4091
|
if (previewFrame) {
|
4046
|
-
const
|
4047
|
-
if (
|
4048
|
-
|
4049
|
-
const frame = getFrame();
|
4050
|
-
if (frame) {
|
4051
|
-
const scaleFactor = rect.width / (((_a = iframe.contentWindow) == null ? void 0 : _a.innerWidth) || 1);
|
4052
|
-
elements = frame.elementsFromPoint(
|
4053
|
-
(position.x - rect.left) / scaleFactor,
|
4054
|
-
(position.y - rect.top) / scaleFactor
|
4055
|
-
);
|
4056
|
-
}
|
4092
|
+
const frame = getFrame();
|
4093
|
+
if (frame) {
|
4094
|
+
elements = frame.elementsFromPoint(position.frame.x, position.frame.y);
|
4057
4095
|
}
|
4058
4096
|
}
|
4059
4097
|
if (elements) {
|
@@ -4070,9 +4108,9 @@ var getPointerCollisions = (position, manager, ownerDocument) => {
|
|
4070
4108
|
}
|
4071
4109
|
return candidates;
|
4072
4110
|
};
|
4073
|
-
var findDeepestCandidate = (position, manager
|
4111
|
+
var findDeepestCandidate = (position, manager) => {
|
4074
4112
|
var _a;
|
4075
|
-
const candidates = getPointerCollisions(position, manager
|
4113
|
+
const candidates = getPointerCollisions(position, manager);
|
4076
4114
|
if (candidates.length > 0) {
|
4077
4115
|
const sortedCandidates = depthSort(candidates);
|
4078
4116
|
const draggable = manager.dragOperation.source;
|
@@ -4125,22 +4163,18 @@ var createNestedDroppablePlugin = ({ onChange }, id) => class NestedDroppablePlu
|
|
4125
4163
|
}
|
4126
4164
|
const cleanupEffect = (0, import_state.effects)(() => {
|
4127
4165
|
const handleMove = (event) => {
|
4128
|
-
const
|
4166
|
+
const target = event.originalTarget || event.target;
|
4167
|
+
const position = new GlobalPosition(target, {
|
4129
4168
|
x: event.clientX,
|
4130
4169
|
y: event.clientY
|
4131
|
-
};
|
4132
|
-
const target = event.originalTarget || event.target;
|
4133
|
-
const ownerDocument = target == null ? void 0 : target.ownerDocument;
|
4170
|
+
});
|
4134
4171
|
const elements = document.elementsFromPoint(
|
4135
|
-
|
4136
|
-
|
4172
|
+
position.global.x,
|
4173
|
+
position.global.y
|
4137
4174
|
);
|
4138
4175
|
const overEl = elements.some((el) => el.id === id);
|
4139
4176
|
if (overEl) {
|
4140
|
-
onChange(
|
4141
|
-
findDeepestCandidate(position, manager, ownerDocument),
|
4142
|
-
manager
|
4143
|
-
);
|
4177
|
+
onChange(findDeepestCandidate(position, manager), manager);
|
4144
4178
|
}
|
4145
4179
|
};
|
4146
4180
|
const handleMoveThrottled = throttle(handleMove, 50);
|
@@ -5342,7 +5376,7 @@ var Drawer = ({
|
|
5342
5376
|
"Warning: The `direction` prop on Drawer is deprecated and no longer required to achieve multi-directional dragging."
|
5343
5377
|
);
|
5344
5378
|
}
|
5345
|
-
const
|
5379
|
+
const id = (0, import_react32.useId)();
|
5346
5380
|
const { ref } = useDroppableSafe({
|
5347
5381
|
id,
|
5348
5382
|
type: "void",
|
@@ -5643,19 +5677,33 @@ var useResolvedFields = () => {
|
|
5643
5677
|
lastData
|
5644
5678
|
});
|
5645
5679
|
}),
|
5646
|
-
[data, config, componentData, selectedItem, resolvedFields, state]
|
5680
|
+
[data, config, componentData, selectedItem, resolvedFields, state, parent]
|
5647
5681
|
);
|
5682
|
+
const [hasParent, setHasParent] = (0, import_react35.useState)(false);
|
5648
5683
|
(0, import_react35.useEffect)(() => {
|
5649
|
-
|
5650
|
-
|
5651
|
-
|
5652
|
-
|
5653
|
-
|
5654
|
-
|
5655
|
-
|
5656
|
-
|
5684
|
+
setHasParent(!!parent);
|
5685
|
+
}, [parent]);
|
5686
|
+
(0, import_react35.useEffect)(() => {
|
5687
|
+
var _a2;
|
5688
|
+
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || hasParent) {
|
5689
|
+
if (hasResolver) {
|
5690
|
+
setFieldsLoading(true);
|
5691
|
+
resolveFields(defaultFields).then((fields) => {
|
5692
|
+
setResolvedFields(fields || {});
|
5693
|
+
setFieldsLoading(false);
|
5694
|
+
});
|
5695
|
+
} else {
|
5696
|
+
setResolvedFields(defaultFields);
|
5697
|
+
}
|
5657
5698
|
}
|
5658
|
-
}, [
|
5699
|
+
}, [
|
5700
|
+
data,
|
5701
|
+
defaultFields,
|
5702
|
+
state.ui.itemSelector,
|
5703
|
+
selectedItem,
|
5704
|
+
hasResolver,
|
5705
|
+
hasParent
|
5706
|
+
]);
|
5659
5707
|
return [resolvedFields, fieldsLoading];
|
5660
5708
|
};
|
5661
5709
|
var Fields = () => {
|
package/dist/index.mjs
CHANGED
@@ -2425,7 +2425,7 @@ init_react_import();
|
|
2425
2425
|
var styles_module_default10 = { "Drawer": "_Drawer_fkqfo_1", "Drawer-draggable": "_Drawer-draggable_fkqfo_8", "Drawer-draggableBg": "_Drawer-draggableBg_fkqfo_12", "Drawer-draggableFg": "_Drawer-draggableFg_fkqfo_21", "DrawerItem-draggable": "_DrawerItem-draggable_fkqfo_25", "DrawerItem--disabled": "_DrawerItem--disabled_fkqfo_38", "DrawerItem": "_DrawerItem_fkqfo_25", "Drawer--isDraggingFrom": "_Drawer--isDraggingFrom_fkqfo_48", "DrawerItem-name": "_DrawerItem-name_fkqfo_66" };
|
2426
2426
|
|
2427
2427
|
// components/Drawer/index.tsx
|
2428
|
-
import { useMemo as useMemo9, useState as useState18 } from "react";
|
2428
|
+
import { useId as useId2, useMemo as useMemo9, useState as useState18 } from "react";
|
2429
2429
|
|
2430
2430
|
// components/DragDropContext/index.tsx
|
2431
2431
|
init_react_import();
|
@@ -3507,7 +3507,7 @@ var getClassName17 = get_class_name_factory_default("DropZone", styles_module_de
|
|
3507
3507
|
var getRandomColor = () => `#${Math.floor(Math.random() * 16777215).toString(16)}`;
|
3508
3508
|
var RENDER_DEBUG = false;
|
3509
3509
|
var DropZoneEdit = forwardRef3(
|
3510
|
-
function
|
3510
|
+
function DropZoneEditInternal({
|
3511
3511
|
zone,
|
3512
3512
|
allow,
|
3513
3513
|
disallow,
|
@@ -3668,7 +3668,7 @@ var DropZoneEdit = forwardRef3(
|
|
3668
3668
|
var _a, _b, _c, _d, _e;
|
3669
3669
|
const componentId = item.props.id;
|
3670
3670
|
const puckProps = {
|
3671
|
-
renderDropZone:
|
3671
|
+
renderDropZone: (props) => /* @__PURE__ */ jsx22(DropZoneEdit, __spreadValues({}, props)),
|
3672
3672
|
isEditing: true,
|
3673
3673
|
dragRef: null
|
3674
3674
|
};
|
@@ -3732,7 +3732,7 @@ var DropZoneEdit = forwardRef3(
|
|
3732
3732
|
}
|
3733
3733
|
);
|
3734
3734
|
var DropZoneRender = forwardRef3(
|
3735
|
-
function
|
3735
|
+
function DropZoneRenderInternal({ className, style, zone }, ref) {
|
3736
3736
|
const ctx = useContext6(dropZoneContext);
|
3737
3737
|
const { data, areaId = "root", config } = ctx || {};
|
3738
3738
|
let zoneCompound = rootDroppableId;
|
@@ -3770,7 +3770,9 @@ var DropZoneRender = forwardRef3(
|
|
3770
3770
|
children: /* @__PURE__ */ jsx22(
|
3771
3771
|
Component.render,
|
3772
3772
|
__spreadProps(__spreadValues({}, item.props), {
|
3773
|
-
puck: {
|
3773
|
+
puck: {
|
3774
|
+
renderDropZone: (props) => /* @__PURE__ */ jsx22(DropZoneRender, __spreadValues({}, props))
|
3775
|
+
}
|
3774
3776
|
})
|
3775
3777
|
)
|
3776
3778
|
},
|
@@ -3845,6 +3847,48 @@ var getFrame = () => {
|
|
3845
3847
|
return (frameEl == null ? void 0 : frameEl.ownerDocument) || document;
|
3846
3848
|
};
|
3847
3849
|
|
3850
|
+
// lib/global-position.ts
|
3851
|
+
init_react_import();
|
3852
|
+
var GlobalPosition = class {
|
3853
|
+
constructor(target, original) {
|
3854
|
+
this.scaleFactor = 1;
|
3855
|
+
this.frameEl = null;
|
3856
|
+
this.frameRect = null;
|
3857
|
+
var _a;
|
3858
|
+
this.target = target;
|
3859
|
+
this.original = original;
|
3860
|
+
this.frameEl = document.querySelector("iframe");
|
3861
|
+
if (this.frameEl) {
|
3862
|
+
this.frameRect = this.frameEl.getBoundingClientRect();
|
3863
|
+
this.scaleFactor = this.frameRect.width / (((_a = this.frameEl.contentWindow) == null ? void 0 : _a.innerWidth) || 1);
|
3864
|
+
}
|
3865
|
+
}
|
3866
|
+
get x() {
|
3867
|
+
return this.original.x;
|
3868
|
+
}
|
3869
|
+
get y() {
|
3870
|
+
return this.original.y;
|
3871
|
+
}
|
3872
|
+
get global() {
|
3873
|
+
if (document !== this.target.ownerDocument && this.frameRect) {
|
3874
|
+
return {
|
3875
|
+
x: this.x * this.scaleFactor + this.frameRect.left,
|
3876
|
+
y: this.y * this.scaleFactor + this.frameRect.top
|
3877
|
+
};
|
3878
|
+
}
|
3879
|
+
return this.original;
|
3880
|
+
}
|
3881
|
+
get frame() {
|
3882
|
+
if (document === this.target.ownerDocument && this.frameRect) {
|
3883
|
+
return {
|
3884
|
+
x: (this.x - this.frameRect.left) / this.scaleFactor,
|
3885
|
+
y: (this.y - this.frameRect.top) / this.scaleFactor
|
3886
|
+
};
|
3887
|
+
}
|
3888
|
+
return this.original;
|
3889
|
+
}
|
3890
|
+
};
|
3891
|
+
|
3848
3892
|
// lib/dnd/NestedDroppablePlugin.ts
|
3849
3893
|
var depthSort = (candidates) => {
|
3850
3894
|
return candidates.sort((a, b) => {
|
@@ -3874,10 +3918,12 @@ var getZoneId2 = (candidate) => {
|
|
3874
3918
|
}
|
3875
3919
|
return id;
|
3876
3920
|
};
|
3877
|
-
var getPointerCollisions = (position, manager
|
3878
|
-
var _a;
|
3921
|
+
var getPointerCollisions = (position, manager) => {
|
3879
3922
|
const candidates = [];
|
3880
|
-
let elements = ownerDocument.elementsFromPoint(
|
3923
|
+
let elements = position.target.ownerDocument.elementsFromPoint(
|
3924
|
+
position.x,
|
3925
|
+
position.y
|
3926
|
+
);
|
3881
3927
|
const previewFrame = elements.find(
|
3882
3928
|
(el) => el.getAttribute("data-puck-preview")
|
3883
3929
|
);
|
@@ -3886,17 +3932,9 @@ var getPointerCollisions = (position, manager, ownerDocument) => {
|
|
3886
3932
|
elements = [drawer];
|
3887
3933
|
}
|
3888
3934
|
if (previewFrame) {
|
3889
|
-
const
|
3890
|
-
if (
|
3891
|
-
|
3892
|
-
const frame = getFrame();
|
3893
|
-
if (frame) {
|
3894
|
-
const scaleFactor = rect.width / (((_a = iframe.contentWindow) == null ? void 0 : _a.innerWidth) || 1);
|
3895
|
-
elements = frame.elementsFromPoint(
|
3896
|
-
(position.x - rect.left) / scaleFactor,
|
3897
|
-
(position.y - rect.top) / scaleFactor
|
3898
|
-
);
|
3899
|
-
}
|
3935
|
+
const frame = getFrame();
|
3936
|
+
if (frame) {
|
3937
|
+
elements = frame.elementsFromPoint(position.frame.x, position.frame.y);
|
3900
3938
|
}
|
3901
3939
|
}
|
3902
3940
|
if (elements) {
|
@@ -3913,9 +3951,9 @@ var getPointerCollisions = (position, manager, ownerDocument) => {
|
|
3913
3951
|
}
|
3914
3952
|
return candidates;
|
3915
3953
|
};
|
3916
|
-
var findDeepestCandidate = (position, manager
|
3954
|
+
var findDeepestCandidate = (position, manager) => {
|
3917
3955
|
var _a;
|
3918
|
-
const candidates = getPointerCollisions(position, manager
|
3956
|
+
const candidates = getPointerCollisions(position, manager);
|
3919
3957
|
if (candidates.length > 0) {
|
3920
3958
|
const sortedCandidates = depthSort(candidates);
|
3921
3959
|
const draggable = manager.dragOperation.source;
|
@@ -3968,22 +4006,18 @@ var createNestedDroppablePlugin = ({ onChange }, id) => class NestedDroppablePlu
|
|
3968
4006
|
}
|
3969
4007
|
const cleanupEffect = effects(() => {
|
3970
4008
|
const handleMove = (event) => {
|
3971
|
-
const
|
4009
|
+
const target = event.originalTarget || event.target;
|
4010
|
+
const position = new GlobalPosition(target, {
|
3972
4011
|
x: event.clientX,
|
3973
4012
|
y: event.clientY
|
3974
|
-
};
|
3975
|
-
const target = event.originalTarget || event.target;
|
3976
|
-
const ownerDocument = target == null ? void 0 : target.ownerDocument;
|
4013
|
+
});
|
3977
4014
|
const elements = document.elementsFromPoint(
|
3978
|
-
|
3979
|
-
|
4015
|
+
position.global.x,
|
4016
|
+
position.global.y
|
3980
4017
|
);
|
3981
4018
|
const overEl = elements.some((el) => el.id === id);
|
3982
4019
|
if (overEl) {
|
3983
|
-
onChange(
|
3984
|
-
findDeepestCandidate(position, manager, ownerDocument),
|
3985
|
-
manager
|
3986
|
-
);
|
4020
|
+
onChange(findDeepestCandidate(position, manager), manager);
|
3987
4021
|
}
|
3988
4022
|
};
|
3989
4023
|
const handleMoveThrottled = throttle(handleMove, 50);
|
@@ -5194,7 +5228,7 @@ var Drawer = ({
|
|
5194
5228
|
"Warning: The `direction` prop on Drawer is deprecated and no longer required to achieve multi-directional dragging."
|
5195
5229
|
);
|
5196
5230
|
}
|
5197
|
-
const
|
5231
|
+
const id = useId2();
|
5198
5232
|
const { ref } = useDroppableSafe({
|
5199
5233
|
id,
|
5200
5234
|
type: "void",
|
@@ -5501,19 +5535,33 @@ var useResolvedFields = () => {
|
|
5501
5535
|
lastData
|
5502
5536
|
});
|
5503
5537
|
}),
|
5504
|
-
[data, config, componentData, selectedItem, resolvedFields, state]
|
5538
|
+
[data, config, componentData, selectedItem, resolvedFields, state, parent]
|
5505
5539
|
);
|
5540
|
+
const [hasParent, setHasParent] = useState19(false);
|
5506
5541
|
useEffect16(() => {
|
5507
|
-
|
5508
|
-
|
5509
|
-
|
5510
|
-
|
5511
|
-
|
5512
|
-
|
5513
|
-
|
5514
|
-
|
5542
|
+
setHasParent(!!parent);
|
5543
|
+
}, [parent]);
|
5544
|
+
useEffect16(() => {
|
5545
|
+
var _a2;
|
5546
|
+
if (!((_a2 = state.ui.itemSelector) == null ? void 0 : _a2.zone) || hasParent) {
|
5547
|
+
if (hasResolver) {
|
5548
|
+
setFieldsLoading(true);
|
5549
|
+
resolveFields(defaultFields).then((fields) => {
|
5550
|
+
setResolvedFields(fields || {});
|
5551
|
+
setFieldsLoading(false);
|
5552
|
+
});
|
5553
|
+
} else {
|
5554
|
+
setResolvedFields(defaultFields);
|
5555
|
+
}
|
5515
5556
|
}
|
5516
|
-
}, [
|
5557
|
+
}, [
|
5558
|
+
data,
|
5559
|
+
defaultFields,
|
5560
|
+
state.ui.itemSelector,
|
5561
|
+
selectedItem,
|
5562
|
+
hasResolver,
|
5563
|
+
hasParent
|
5564
|
+
]);
|
5517
5565
|
return [resolvedFields, fieldsLoading];
|
5518
5566
|
};
|
5519
5567
|
var Fields = () => {
|
package/package.json
CHANGED