@react-stately/dnd 3.0.1-nightly.3598 → 3.0.1-nightly.3600
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/main.js +71 -43
- package/dist/main.js.map +1 -1
- package/dist/module.mjs +71 -43
- package/dist/module.mjs.map +1 -1
- package/package.json +5 -5
package/dist/main.js
CHANGED
|
@@ -6,21 +6,40 @@ function $parcel$export(e, n, v, s) {
|
|
|
6
6
|
|
|
7
7
|
$parcel$export(module.exports, "useDraggableCollectionState", () => $481a240e3d51b276$export$29efd034f1d79f81);
|
|
8
8
|
$parcel$export(module.exports, "useDroppableCollectionState", () => $6ce4cbfbe5e354f1$export$926850f6ecef79d0);
|
|
9
|
-
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
11
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
+
* governing permissions and limitations under the License.
|
|
19
|
+
*/ /*
|
|
20
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
21
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
22
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
23
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
24
|
+
*
|
|
25
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
26
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
27
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
28
|
+
* governing permissions and limitations under the License.
|
|
29
|
+
*/
|
|
10
30
|
function $481a240e3d51b276$export$29efd034f1d79f81(props) {
|
|
11
31
|
let { getItems: getItems , collection: collection , selectionManager: selectionManager , onDragStart: onDragStart , onDragMove: onDragMove , onDragEnd: onDragEnd , preview: preview , getAllowedDropOperations: getAllowedDropOperations } = props;
|
|
12
|
-
let [, setDragging] = $1IdlX$react.useState(false);
|
|
13
|
-
let draggingKeys = $1IdlX$react.useRef(new Set());
|
|
14
|
-
let draggedKey = $1IdlX$react.useRef(null);
|
|
15
|
-
let getKeys = (
|
|
32
|
+
let [, setDragging] = (0, $1IdlX$react.useState)(false);
|
|
33
|
+
let draggingKeys = (0, $1IdlX$react.useRef)(new Set());
|
|
34
|
+
let draggedKey = (0, $1IdlX$react.useRef)(null);
|
|
35
|
+
let getKeys = (key)=>{
|
|
16
36
|
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
17
37
|
// other selected items are also dragged. If it is not selected, the only the clicked
|
|
18
38
|
// item is dragged. This matches native macOS behavior.
|
|
19
|
-
let keys = new Set(selectionManager.isSelected(
|
|
39
|
+
let keys = new Set(selectionManager.isSelected(key) ? new Set([
|
|
20
40
|
...selectionManager.selectedKeys
|
|
21
|
-
].filter((key)=>!!collection.getItem(key)
|
|
22
|
-
)
|
|
23
|
-
keys.add(key1);
|
|
41
|
+
].filter((key)=>!!collection.getItem(key))) : []);
|
|
42
|
+
keys.add(key);
|
|
24
43
|
return keys;
|
|
25
44
|
};
|
|
26
45
|
return {
|
|
@@ -46,20 +65,20 @@ function $481a240e3d51b276$export$29efd034f1d79f81(props) {
|
|
|
46
65
|
let keys = getKeys(key);
|
|
47
66
|
draggingKeys.current = keys;
|
|
48
67
|
draggedKey.current = key;
|
|
49
|
-
if (typeof onDragStart ===
|
|
68
|
+
if (typeof onDragStart === "function") onDragStart({
|
|
50
69
|
...event,
|
|
51
70
|
keys: keys
|
|
52
71
|
});
|
|
53
72
|
},
|
|
54
73
|
moveDrag (event) {
|
|
55
|
-
if (typeof onDragMove ===
|
|
74
|
+
if (typeof onDragMove === "function") onDragMove({
|
|
56
75
|
...event,
|
|
57
76
|
keys: draggingKeys.current
|
|
58
77
|
});
|
|
59
78
|
},
|
|
60
79
|
endDrag (event) {
|
|
61
80
|
let { isInternal: isInternal } = event;
|
|
62
|
-
if (typeof onDragEnd ===
|
|
81
|
+
if (typeof onDragEnd === "function") onDragEnd({
|
|
63
82
|
...event,
|
|
64
83
|
keys: draggingKeys.current,
|
|
65
84
|
isInternal: isInternal
|
|
@@ -72,44 +91,53 @@ function $481a240e3d51b276$export$29efd034f1d79f81(props) {
|
|
|
72
91
|
}
|
|
73
92
|
|
|
74
93
|
|
|
75
|
-
|
|
94
|
+
/*
|
|
95
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
96
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
97
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
98
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
99
|
+
*
|
|
100
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
101
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
102
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
103
|
+
* governing permissions and limitations under the License.
|
|
104
|
+
*/
|
|
76
105
|
function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) {
|
|
77
|
-
let { acceptedDragTypes: acceptedDragTypes =
|
|
78
|
-
let [
|
|
79
|
-
let targetRef = $1IdlX$react.useRef(null);
|
|
106
|
+
let { acceptedDragTypes: acceptedDragTypes = "all" , onInsert: onInsert , onRootDrop: onRootDrop , onItemDrop: onItemDrop , onReorder: onReorder , shouldAcceptItemDrop: shouldAcceptItemDrop , collection: collection , selectionManager: selectionManager , onDropEnter: onDropEnter , getDropOperation: getDropOperation , onDrop: onDrop } = props;
|
|
107
|
+
let [target, setTarget] = (0, $1IdlX$react.useState)(null);
|
|
108
|
+
let targetRef = (0, $1IdlX$react.useRef)(null);
|
|
80
109
|
let getOppositeTarget = (target)=>{
|
|
81
|
-
if (target.dropPosition ===
|
|
110
|
+
if (target.dropPosition === "before") {
|
|
82
111
|
let key = collection.getKeyBefore(target.key);
|
|
83
112
|
return key != null ? {
|
|
84
|
-
type:
|
|
113
|
+
type: "item",
|
|
85
114
|
key: key,
|
|
86
|
-
dropPosition:
|
|
115
|
+
dropPosition: "after"
|
|
87
116
|
} : null;
|
|
88
|
-
} else if (target.dropPosition ===
|
|
89
|
-
let
|
|
90
|
-
return
|
|
91
|
-
type:
|
|
92
|
-
key:
|
|
93
|
-
dropPosition:
|
|
117
|
+
} else if (target.dropPosition === "after") {
|
|
118
|
+
let key1 = collection.getKeyAfter(target.key);
|
|
119
|
+
return key1 != null ? {
|
|
120
|
+
type: "item",
|
|
121
|
+
key: key1,
|
|
122
|
+
dropPosition: "before"
|
|
94
123
|
} : null;
|
|
95
124
|
}
|
|
96
125
|
};
|
|
97
|
-
let defaultGetDropOperation = $1IdlX$react.useCallback((e)=>{
|
|
126
|
+
let defaultGetDropOperation = (0, $1IdlX$react.useCallback)((e)=>{
|
|
98
127
|
let { target: target , types: types , allowedOperations: allowedOperations , isInternal: isInternal , draggingKeys: draggingKeys } = e;
|
|
99
|
-
if (acceptedDragTypes ===
|
|
100
|
-
|
|
101
|
-
let
|
|
102
|
-
let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');
|
|
128
|
+
if (acceptedDragTypes === "all" || acceptedDragTypes.some((type)=>types.has(type))) {
|
|
129
|
+
let isValidInsert = onInsert && target.type === "item" && !isInternal && (target.dropPosition === "before" || target.dropPosition === "after");
|
|
130
|
+
let isValidReorder = onReorder && target.type === "item" && isInternal && (target.dropPosition === "before" || target.dropPosition === "after");
|
|
103
131
|
// Feedback was that internal root drop was weird so preventing that from happening
|
|
104
|
-
let isValidRootDrop = onRootDrop && target.type ===
|
|
132
|
+
let isValidRootDrop = onRootDrop && target.type === "root" && !isInternal;
|
|
105
133
|
// Automatically prevent items (i.e. folders) from being dropped on themselves.
|
|
106
|
-
let isValidOnItemDrop = onItemDrop && target.type ===
|
|
134
|
+
let isValidOnItemDrop = onItemDrop && target.type === "item" && target.dropPosition === "on" && !(isInternal && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));
|
|
107
135
|
if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {
|
|
108
136
|
if (getDropOperation) return getDropOperation(target, types, allowedOperations);
|
|
109
137
|
else return allowedOperations[0];
|
|
110
138
|
}
|
|
111
139
|
}
|
|
112
|
-
return
|
|
140
|
+
return "cancel";
|
|
113
141
|
}, [
|
|
114
142
|
acceptedDragTypes,
|
|
115
143
|
getDropOperation,
|
|
@@ -123,18 +151,18 @@ function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) {
|
|
|
123
151
|
return {
|
|
124
152
|
collection: collection,
|
|
125
153
|
selectionManager: selectionManager,
|
|
126
|
-
target:
|
|
154
|
+
target: target,
|
|
127
155
|
setTarget (newTarget) {
|
|
128
156
|
if (this.isDropTarget(newTarget)) return;
|
|
129
157
|
let target = targetRef.current;
|
|
130
|
-
if (target && typeof props.onDropExit ===
|
|
131
|
-
type:
|
|
158
|
+
if (target && typeof props.onDropExit === "function") props.onDropExit({
|
|
159
|
+
type: "dropexit",
|
|
132
160
|
x: 0,
|
|
133
161
|
y: 0,
|
|
134
162
|
target: target
|
|
135
163
|
});
|
|
136
|
-
if (newTarget && typeof onDropEnter ===
|
|
137
|
-
type:
|
|
164
|
+
if (newTarget && typeof onDropEnter === "function") onDropEnter({
|
|
165
|
+
type: "dropenter",
|
|
138
166
|
x: 0,
|
|
139
167
|
y: 0,
|
|
140
168
|
target: newTarget
|
|
@@ -146,7 +174,7 @@ function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) {
|
|
|
146
174
|
let target = targetRef.current;
|
|
147
175
|
if ($6ce4cbfbe5e354f1$var$isEqualDropTarget(dropTarget, target)) return true;
|
|
148
176
|
// Check if the targets point at the same point between two items, one referring before, and the other after.
|
|
149
|
-
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) ===
|
|
177
|
+
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) === "item" && (target === null || target === void 0 ? void 0 : target.type) === "item" && dropTarget.key !== target.key && dropTarget.dropPosition !== target.dropPosition && dropTarget.dropPosition !== "on" && target.dropPosition !== "on") return $6ce4cbfbe5e354f1$var$isEqualDropTarget(getOppositeTarget(dropTarget), target) || $6ce4cbfbe5e354f1$var$isEqualDropTarget(dropTarget, getOppositeTarget(target));
|
|
150
178
|
return false;
|
|
151
179
|
},
|
|
152
180
|
getDropOperation (e) {
|
|
@@ -157,10 +185,10 @@ function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) {
|
|
|
157
185
|
function $6ce4cbfbe5e354f1$var$isEqualDropTarget(a, b) {
|
|
158
186
|
if (!a) return !b;
|
|
159
187
|
switch(a.type){
|
|
160
|
-
case
|
|
161
|
-
return (b === null || b === void 0 ? void 0 : b.type) ===
|
|
162
|
-
case
|
|
163
|
-
return (b === null || b === void 0 ? void 0 : b.type) ===
|
|
188
|
+
case "root":
|
|
189
|
+
return (b === null || b === void 0 ? void 0 : b.type) === "root";
|
|
190
|
+
case "item":
|
|
191
|
+
return (b === null || b === void 0 ? void 0 : b.type) === "item" && (b === null || b === void 0 ? void 0 : b.key) === a.key && (b === null || b === void 0 ? void 0 : b.dropPosition) === a.dropPosition;
|
|
164
192
|
}
|
|
165
193
|
}
|
|
166
194
|
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;SCqDgB,yCAA2B,CAAC,KAAsC,EAA4B,CAAC;IAC7G,GAAG,CAAC,CAAC,WACH,QAAQ,eACR,UAAU,qBACV,gBAAgB,gBAChB,WAAW,eACX,UAAU,cACV,SAAS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,CAAO,GAAP,CAAC,CAAE,IAAI,MAAK,CAAM;QAC3B,IAAI,CAAC,CAAM;YACT,MAAM,EAAC,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAO,GAAP,IAAI,CAAJ,CAAO,GAAP,CAAC,CAAE,IAAI,MAAK,CAAM,UAAI,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAM,GAAN,IAAI,CAAJ,CAAM,GAAN,CAAC,CAAE,GAAG,MAAK,CAAC,CAAC,GAAG,KAAI,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAe,GAAf,IAAI,CAAJ,CAAe,GAAf,CAAC,CAAE,YAAY,MAAK,CAAC,CAAC,YAAY;;AAEzF,CAAC;;","sources":["packages/@react-stately/dnd/src/index.ts","packages/@react-stately/dnd/src/useDraggableCollectionState.ts","packages/@react-stately/dnd/src/useDroppableCollectionState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {DraggableCollectionStateOptions, DraggableCollectionState} from './useDraggableCollectionState';\nexport type {DroppableCollectionStateOptions, DroppableCollectionState} from './useDroppableCollectionState';\nexport {useDraggableCollectionState} from './useDraggableCollectionState';\nexport {useDroppableCollectionState} from './useDroppableCollectionState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, DraggableCollectionEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, Node} from '@react-types/shared';\nimport {Key, RefObject, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\nexport interface DraggableCollectionStateOptions extends DraggableCollectionProps {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DraggableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The key of the item that initiated a drag. */\n draggedKey: Key | null,\n /** The keys of the items that are currently being dragged. */\n draggingKeys: Set<Key>,\n /** Returns whether the given key is currently being dragged. */\n isDragging(key: Key): boolean,\n /** Returns the keys of the items that will be dragged with the given key (e.g. selected items). */\n getKeysForDrag(key: Key): Set<Key>,\n /** Returns the items to drag for the given key. */\n getItems(key: Key): DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\n /** Begins a drag for the given key. This triggers the onDragStart event. */\n startDrag(key: Key, event: DragStartEvent): void,\n /** Triggers an onDragMove event. */\n moveDrag(event: DragMoveEvent): void,\n /** Ends the current drag, and emits an onDragEnd event. */\n endDrag(event: DraggableCollectionEndEvent): void\n}\n\n/**\n * Manages state for a draggable collection.\n */\nexport function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState {\n let {\n getItems,\n collection,\n selectionManager,\n onDragStart,\n onDragMove,\n onDragEnd,\n preview,\n getAllowedDropOperations\n } = props;\n let [, setDragging] = useState(false);\n let draggingKeys = useRef(new Set<Key>());\n let draggedKey = useRef(null);\n let getKeys = (key: Key) => {\n // The clicked item is always added to the drag. If it is selected, then all of the\n // other selected items are also dragged. If it is not selected, the only the clicked\n // item is dragged. This matches native macOS behavior.\n let keys = new Set(\n selectionManager.isSelected(key)\n ? new Set([...selectionManager.selectedKeys].filter(key => !!collection.getItem(key)))\n : []\n );\n\n keys.add(key);\n return keys;\n };\n\n return {\n collection,\n selectionManager,\n get draggedKey() {\n return draggedKey.current;\n },\n get draggingKeys() {\n return draggingKeys.current;\n },\n isDragging(key) {\n return draggingKeys.current.has(key);\n },\n getKeysForDrag: getKeys,\n getItems(key) {\n return getItems(getKeys(key));\n },\n preview,\n getAllowedDropOperations,\n startDrag(key, event) {\n setDragging(true);\n let keys = getKeys(key);\n draggingKeys.current = keys;\n draggedKey.current = key;\n if (typeof onDragStart === 'function') {\n onDragStart({\n ...event,\n keys\n });\n }\n },\n moveDrag(event) {\n if (typeof onDragMove === 'function') {\n onDragMove({\n ...event,\n keys: draggingKeys.current\n });\n }\n },\n endDrag(event) {\n let {\n isInternal\n } = event;\n\n if (typeof onDragEnd === 'function') {\n onDragEnd({\n ...event,\n keys: draggingKeys.current,\n isInternal\n });\n }\n\n setDragging(false);\n draggingKeys.current = new Set();\n draggedKey.current = null;\n }\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, DragTypes, DropOperation, DroppableCollectionProps, DropTarget, ItemDropTarget, Node} from '@react-types/shared';\nimport {Key, useCallback, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\ninterface DropOperationEvent {\n target: DropTarget,\n types: DragTypes,\n allowedOperations: DropOperation[],\n isInternal: boolean,\n draggingKeys: Set<Key>\n}\n\nexport interface DroppableCollectionStateOptions extends Omit<DroppableCollectionProps, 'onDropMove' | 'onDropActivate'> {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DroppableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The current drop target. */\n target: DropTarget | null,\n /** Sets the current drop target. */\n setTarget(target: DropTarget): void,\n /** Returns whether the given target is equivalent to the current drop target. */\n isDropTarget(target: DropTarget): boolean,\n /** Returns the drop operation for the given parameters. */\n getDropOperation(e: DropOperationEvent): DropOperation\n}\n\n/**\n * Manages state for a droppable collection.\n */\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let {\n acceptedDragTypes = 'all',\n onInsert,\n onRootDrop,\n onItemDrop,\n onReorder,\n shouldAcceptItemDrop,\n collection,\n selectionManager,\n onDropEnter,\n getDropOperation,\n onDrop\n } = props;\n let [target, setTarget] = useState<DropTarget>(null);\n let targetRef = useRef<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\n if (target.dropPosition === 'before') {\n let key = collection.getKeyBefore(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'after'} : null;\n } else if (target.dropPosition === 'after') {\n let key = collection.getKeyAfter(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'before'} : null;\n }\n };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\n\n if (acceptedDragTypes === 'all' || acceptedDragTypes.some(type => types.has(type))) {\n let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n // Feedback was that internal root drop was weird so preventing that from happening\n let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;\n // Automatically prevent items (i.e. folders) from being dropped on themselves.\n let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));\n\n if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {\n if (getDropOperation) {\n return getDropOperation(target, types, allowedOperations);\n } else {\n return allowedOperations[0];\n }\n }\n }\n\n return 'cancel';\n }, [acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);\n\n return {\n collection,\n selectionManager,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\n let target = targetRef.current;\n if (target && typeof props.onDropExit === 'function') {\n props.onDropExit({\n type: 'dropexit',\n x: 0, // todo\n y: 0,\n target\n });\n }\n\n if (newTarget && typeof onDropEnter === 'function') {\n onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n targetRef.current = newTarget;\n setTarget(newTarget);\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\n if (isEqualDropTarget(dropTarget, target)) {\n return true;\n }\n\n // Check if the targets point at the same point between two items, one referring before, and the other after.\n if (\n dropTarget?.type === 'item' &&\n target?.type === 'item' &&\n dropTarget.key !== target.key &&\n dropTarget.dropPosition !== target.dropPosition &&\n dropTarget.dropPosition !== 'on' &&\n target.dropPosition !== 'on'\n ) {\n return isEqualDropTarget(getOppositeTarget(dropTarget), target) ||\n isEqualDropTarget(dropTarget, getOppositeTarget(target));\n }\n\n return false;\n },\n getDropOperation(e) {\n return defaultGetDropOperation(e);\n }\n };\n}\n\nfunction isEqualDropTarget(a: DropTarget, b: DropTarget) {\n if (!a) {\n return !b;\n }\n\n switch (a.type) {\n case 'root':\n return b?.type === 'root';\n case 'item':\n return b?.type === 'item' && b?.key === a.key && b?.dropPosition === a.dropPosition;\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;AAyCO,SAAS,0CAA4B,KAAsC,EAA4B;IAC5G,IAAI,YACF,SAAQ,cACR,WAAU,oBACV,iBAAgB,eAChB,YAAW,cACX,WAAU,aACV,UAAS,WACT,QAAO,4BACP,yBAAwB,EACzB,GAAG;IACJ,IAAI,GAAG,YAAY,GAAG,CAAA,GAAA,qBAAO,EAAE,KAAK;IACpC,IAAI,eAAe,CAAA,GAAA,mBAAK,EAAE,IAAI;IAC9B,IAAI,aAAa,CAAA,GAAA,mBAAK,EAAE,IAAI;IAC5B,IAAI,UAAU,CAAC,MAAa;QAC1B,mFAAmF;QACnF,qFAAqF;QACrF,uDAAuD;QACvD,IAAI,OAAO,IAAI,IACb,iBAAiB,UAAU,CAAC,OACxB,IAAI,IAAI;eAAI,iBAAiB,YAAY;SAAC,CAAC,MAAM,CAAC,CAAA,MAAO,CAAC,CAAC,WAAW,OAAO,CAAC,SAC9E,EAAE;QAGR,KAAK,GAAG,CAAC;QACT,OAAO;IACT;IAEA,OAAO;oBACL;0BACA;QACA,IAAI,cAAa;YACf,OAAO,WAAW,OAAO;QAC3B;QACA,IAAI,gBAAe;YACjB,OAAO,aAAa,OAAO;QAC7B;QACA,YAAW,GAAG,EAAE;YACd,OAAO,aAAa,OAAO,CAAC,GAAG,CAAC;QAClC;QACA,gBAAgB;QAChB,UAAS,GAAG,EAAE;YACZ,OAAO,SAAS,QAAQ;QAC1B;iBACA;kCACA;QACA,WAAU,GAAG,EAAE,KAAK,EAAE;YACpB,YAAY,IAAI;YAChB,IAAI,OAAO,QAAQ;YACnB,aAAa,OAAO,GAAG;YACvB,WAAW,OAAO,GAAG;YACrB,IAAI,OAAO,gBAAgB,YAC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QAAQ;YACV;YAGF,UAAU,OAAO,GAAG;YACpB,UAAU;QACZ;QACA,cAAa,UAAU,EAAE;YACvB,IAAI,SAAS,UAAU,OAAO;YAC9B,IAAI,wCAAkB,YAAY,SAChC,OAAO,IAAI;YAGb,6GAA6G;YAC7G,IACE,CAAA,uBAAA,wBAAA,KAAA,IAAA,WAAY,IAAI,AAAD,MAAM,UACrB,CAAA,mBAAA,oBAAA,KAAA,IAAA,OAAQ,IAAI,AAAD,MAAM,UACjB,WAAW,GAAG,KAAK,OAAO,GAAG,IAC7B,WAAW,YAAY,KAAK,OAAO,YAAY,IAC/C,WAAW,YAAY,KAAK,QAC5B,OAAO,YAAY,KAAK,MAExB,OAAO,wCAAkB,kBAAkB,aAAa,WACtD,wCAAkB,YAAY,kBAAkB;YAGpD,OAAO,KAAK;QACd;QACA,kBAAiB,CAAC,EAAE;YAClB,OAAO,wBAAwB;QACjC;IACF;AACF;AAEA,SAAS,wCAAkB,CAAa,EAAE,CAAa,EAAE;IACvD,IAAI,CAAC,GACH,OAAO,CAAC;IAGV,OAAQ,EAAE,IAAI;QACZ,KAAK;YACH,OAAO,CAAA,cAAA,eAAA,KAAA,IAAA,EAAG,IAAI,AAAD,MAAM;QACrB,KAAK;YACH,OAAO,CAAA,cAAA,eAAA,KAAA,IAAA,EAAG,IAAI,AAAD,MAAM,UAAU,CAAA,cAAA,eAAA,KAAA,IAAA,EAAG,GAAG,AAAD,MAAM,EAAE,GAAG,IAAI,CAAA,cAAA,eAAA,KAAA,IAAA,EAAG,YAAY,AAAD,MAAM,EAAE,YAAY;IACvF;AACF;","sources":["packages/@react-stately/dnd/src/index.ts","packages/@react-stately/dnd/src/useDraggableCollectionState.ts","packages/@react-stately/dnd/src/useDroppableCollectionState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {DraggableCollectionStateOptions, DraggableCollectionState} from './useDraggableCollectionState';\nexport type {DroppableCollectionStateOptions, DroppableCollectionState} from './useDroppableCollectionState';\nexport {useDraggableCollectionState} from './useDraggableCollectionState';\nexport {useDroppableCollectionState} from './useDroppableCollectionState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, DraggableCollectionEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, Node} from '@react-types/shared';\nimport {Key, RefObject, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\nexport interface DraggableCollectionStateOptions extends DraggableCollectionProps {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DraggableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The key of the item that initiated a drag. */\n draggedKey: Key | null,\n /** The keys of the items that are currently being dragged. */\n draggingKeys: Set<Key>,\n /** Returns whether the given key is currently being dragged. */\n isDragging(key: Key): boolean,\n /** Returns the keys of the items that will be dragged with the given key (e.g. selected items). */\n getKeysForDrag(key: Key): Set<Key>,\n /** Returns the items to drag for the given key. */\n getItems(key: Key): DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\n /** Begins a drag for the given key. This triggers the onDragStart event. */\n startDrag(key: Key, event: DragStartEvent): void,\n /** Triggers an onDragMove event. */\n moveDrag(event: DragMoveEvent): void,\n /** Ends the current drag, and emits an onDragEnd event. */\n endDrag(event: DraggableCollectionEndEvent): void\n}\n\n/**\n * Manages state for a draggable collection.\n */\nexport function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState {\n let {\n getItems,\n collection,\n selectionManager,\n onDragStart,\n onDragMove,\n onDragEnd,\n preview,\n getAllowedDropOperations\n } = props;\n let [, setDragging] = useState(false);\n let draggingKeys = useRef(new Set<Key>());\n let draggedKey = useRef(null);\n let getKeys = (key: Key) => {\n // The clicked item is always added to the drag. If it is selected, then all of the\n // other selected items are also dragged. If it is not selected, the only the clicked\n // item is dragged. This matches native macOS behavior.\n let keys = new Set(\n selectionManager.isSelected(key)\n ? new Set([...selectionManager.selectedKeys].filter(key => !!collection.getItem(key)))\n : []\n );\n\n keys.add(key);\n return keys;\n };\n\n return {\n collection,\n selectionManager,\n get draggedKey() {\n return draggedKey.current;\n },\n get draggingKeys() {\n return draggingKeys.current;\n },\n isDragging(key) {\n return draggingKeys.current.has(key);\n },\n getKeysForDrag: getKeys,\n getItems(key) {\n return getItems(getKeys(key));\n },\n preview,\n getAllowedDropOperations,\n startDrag(key, event) {\n setDragging(true);\n let keys = getKeys(key);\n draggingKeys.current = keys;\n draggedKey.current = key;\n if (typeof onDragStart === 'function') {\n onDragStart({\n ...event,\n keys\n });\n }\n },\n moveDrag(event) {\n if (typeof onDragMove === 'function') {\n onDragMove({\n ...event,\n keys: draggingKeys.current\n });\n }\n },\n endDrag(event) {\n let {\n isInternal\n } = event;\n\n if (typeof onDragEnd === 'function') {\n onDragEnd({\n ...event,\n keys: draggingKeys.current,\n isInternal\n });\n }\n\n setDragging(false);\n draggingKeys.current = new Set();\n draggedKey.current = null;\n }\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, DragTypes, DropOperation, DroppableCollectionProps, DropTarget, ItemDropTarget, Node} from '@react-types/shared';\nimport {Key, useCallback, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\ninterface DropOperationEvent {\n target: DropTarget,\n types: DragTypes,\n allowedOperations: DropOperation[],\n isInternal: boolean,\n draggingKeys: Set<Key>\n}\n\nexport interface DroppableCollectionStateOptions extends Omit<DroppableCollectionProps, 'onDropMove' | 'onDropActivate'> {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DroppableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The current drop target. */\n target: DropTarget | null,\n /** Sets the current drop target. */\n setTarget(target: DropTarget): void,\n /** Returns whether the given target is equivalent to the current drop target. */\n isDropTarget(target: DropTarget): boolean,\n /** Returns the drop operation for the given parameters. */\n getDropOperation(e: DropOperationEvent): DropOperation\n}\n\n/**\n * Manages state for a droppable collection.\n */\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let {\n acceptedDragTypes = 'all',\n onInsert,\n onRootDrop,\n onItemDrop,\n onReorder,\n shouldAcceptItemDrop,\n collection,\n selectionManager,\n onDropEnter,\n getDropOperation,\n onDrop\n } = props;\n let [target, setTarget] = useState<DropTarget>(null);\n let targetRef = useRef<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\n if (target.dropPosition === 'before') {\n let key = collection.getKeyBefore(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'after'} : null;\n } else if (target.dropPosition === 'after') {\n let key = collection.getKeyAfter(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'before'} : null;\n }\n };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\n\n if (acceptedDragTypes === 'all' || acceptedDragTypes.some(type => types.has(type))) {\n let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n // Feedback was that internal root drop was weird so preventing that from happening\n let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;\n // Automatically prevent items (i.e. folders) from being dropped on themselves.\n let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));\n\n if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {\n if (getDropOperation) {\n return getDropOperation(target, types, allowedOperations);\n } else {\n return allowedOperations[0];\n }\n }\n }\n\n return 'cancel';\n }, [acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);\n\n return {\n collection,\n selectionManager,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\n let target = targetRef.current;\n if (target && typeof props.onDropExit === 'function') {\n props.onDropExit({\n type: 'dropexit',\n x: 0, // todo\n y: 0,\n target\n });\n }\n\n if (newTarget && typeof onDropEnter === 'function') {\n onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n targetRef.current = newTarget;\n setTarget(newTarget);\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\n if (isEqualDropTarget(dropTarget, target)) {\n return true;\n }\n\n // Check if the targets point at the same point between two items, one referring before, and the other after.\n if (\n dropTarget?.type === 'item' &&\n target?.type === 'item' &&\n dropTarget.key !== target.key &&\n dropTarget.dropPosition !== target.dropPosition &&\n dropTarget.dropPosition !== 'on' &&\n target.dropPosition !== 'on'\n ) {\n return isEqualDropTarget(getOppositeTarget(dropTarget), target) ||\n isEqualDropTarget(dropTarget, getOppositeTarget(target));\n }\n\n return false;\n },\n getDropOperation(e) {\n return defaultGetDropOperation(e);\n }\n };\n}\n\nfunction isEqualDropTarget(a: DropTarget, b: DropTarget) {\n if (!a) {\n return !b;\n }\n\n switch (a.type) {\n case 'root':\n return b?.type === 'root';\n case 'item':\n return b?.type === 'item' && b?.key === a.key && b?.dropPosition === a.dropPosition;\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.mjs
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
import {useState as $bBNwq$useState, useRef as $bBNwq$useRef, useCallback as $bBNwq$useCallback} from "react";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/ /*
|
|
14
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
15
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
16
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
17
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
18
|
+
*
|
|
19
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
20
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
21
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
22
|
+
* governing permissions and limitations under the License.
|
|
23
|
+
*/
|
|
4
24
|
function $b45bbbaf0c3785df$export$29efd034f1d79f81(props) {
|
|
5
25
|
let { getItems: getItems , collection: collection , selectionManager: selectionManager , onDragStart: onDragStart , onDragMove: onDragMove , onDragEnd: onDragEnd , preview: preview , getAllowedDropOperations: getAllowedDropOperations } = props;
|
|
6
|
-
let [, setDragging] = $bBNwq$useState(false);
|
|
7
|
-
let draggingKeys = $bBNwq$useRef(new Set());
|
|
8
|
-
let draggedKey = $bBNwq$useRef(null);
|
|
9
|
-
let getKeys = (
|
|
26
|
+
let [, setDragging] = (0, $bBNwq$useState)(false);
|
|
27
|
+
let draggingKeys = (0, $bBNwq$useRef)(new Set());
|
|
28
|
+
let draggedKey = (0, $bBNwq$useRef)(null);
|
|
29
|
+
let getKeys = (key)=>{
|
|
10
30
|
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
11
31
|
// other selected items are also dragged. If it is not selected, the only the clicked
|
|
12
32
|
// item is dragged. This matches native macOS behavior.
|
|
13
|
-
let keys = new Set(selectionManager.isSelected(
|
|
33
|
+
let keys = new Set(selectionManager.isSelected(key) ? new Set([
|
|
14
34
|
...selectionManager.selectedKeys
|
|
15
|
-
].filter((key)=>!!collection.getItem(key)
|
|
16
|
-
)
|
|
17
|
-
keys.add(key1);
|
|
35
|
+
].filter((key)=>!!collection.getItem(key))) : []);
|
|
36
|
+
keys.add(key);
|
|
18
37
|
return keys;
|
|
19
38
|
};
|
|
20
39
|
return {
|
|
@@ -40,20 +59,20 @@ function $b45bbbaf0c3785df$export$29efd034f1d79f81(props) {
|
|
|
40
59
|
let keys = getKeys(key);
|
|
41
60
|
draggingKeys.current = keys;
|
|
42
61
|
draggedKey.current = key;
|
|
43
|
-
if (typeof onDragStart ===
|
|
62
|
+
if (typeof onDragStart === "function") onDragStart({
|
|
44
63
|
...event,
|
|
45
64
|
keys: keys
|
|
46
65
|
});
|
|
47
66
|
},
|
|
48
67
|
moveDrag (event) {
|
|
49
|
-
if (typeof onDragMove ===
|
|
68
|
+
if (typeof onDragMove === "function") onDragMove({
|
|
50
69
|
...event,
|
|
51
70
|
keys: draggingKeys.current
|
|
52
71
|
});
|
|
53
72
|
},
|
|
54
73
|
endDrag (event) {
|
|
55
74
|
let { isInternal: isInternal } = event;
|
|
56
|
-
if (typeof onDragEnd ===
|
|
75
|
+
if (typeof onDragEnd === "function") onDragEnd({
|
|
57
76
|
...event,
|
|
58
77
|
keys: draggingKeys.current,
|
|
59
78
|
isInternal: isInternal
|
|
@@ -66,44 +85,53 @@ function $b45bbbaf0c3785df$export$29efd034f1d79f81(props) {
|
|
|
66
85
|
}
|
|
67
86
|
|
|
68
87
|
|
|
69
|
-
|
|
88
|
+
/*
|
|
89
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
90
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
91
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
92
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
93
|
+
*
|
|
94
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
95
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
96
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
97
|
+
* governing permissions and limitations under the License.
|
|
98
|
+
*/
|
|
70
99
|
function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
71
|
-
let { acceptedDragTypes: acceptedDragTypes =
|
|
72
|
-
let [
|
|
73
|
-
let targetRef = $bBNwq$useRef(null);
|
|
100
|
+
let { acceptedDragTypes: acceptedDragTypes = "all" , onInsert: onInsert , onRootDrop: onRootDrop , onItemDrop: onItemDrop , onReorder: onReorder , shouldAcceptItemDrop: shouldAcceptItemDrop , collection: collection , selectionManager: selectionManager , onDropEnter: onDropEnter , getDropOperation: getDropOperation , onDrop: onDrop } = props;
|
|
101
|
+
let [target, setTarget] = (0, $bBNwq$useState)(null);
|
|
102
|
+
let targetRef = (0, $bBNwq$useRef)(null);
|
|
74
103
|
let getOppositeTarget = (target)=>{
|
|
75
|
-
if (target.dropPosition ===
|
|
104
|
+
if (target.dropPosition === "before") {
|
|
76
105
|
let key = collection.getKeyBefore(target.key);
|
|
77
106
|
return key != null ? {
|
|
78
|
-
type:
|
|
107
|
+
type: "item",
|
|
79
108
|
key: key,
|
|
80
|
-
dropPosition:
|
|
109
|
+
dropPosition: "after"
|
|
81
110
|
} : null;
|
|
82
|
-
} else if (target.dropPosition ===
|
|
83
|
-
let
|
|
84
|
-
return
|
|
85
|
-
type:
|
|
86
|
-
key:
|
|
87
|
-
dropPosition:
|
|
111
|
+
} else if (target.dropPosition === "after") {
|
|
112
|
+
let key1 = collection.getKeyAfter(target.key);
|
|
113
|
+
return key1 != null ? {
|
|
114
|
+
type: "item",
|
|
115
|
+
key: key1,
|
|
116
|
+
dropPosition: "before"
|
|
88
117
|
} : null;
|
|
89
118
|
}
|
|
90
119
|
};
|
|
91
|
-
let defaultGetDropOperation = $bBNwq$useCallback((e)=>{
|
|
120
|
+
let defaultGetDropOperation = (0, $bBNwq$useCallback)((e)=>{
|
|
92
121
|
let { target: target , types: types , allowedOperations: allowedOperations , isInternal: isInternal , draggingKeys: draggingKeys } = e;
|
|
93
|
-
if (acceptedDragTypes ===
|
|
94
|
-
|
|
95
|
-
let
|
|
96
|
-
let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');
|
|
122
|
+
if (acceptedDragTypes === "all" || acceptedDragTypes.some((type)=>types.has(type))) {
|
|
123
|
+
let isValidInsert = onInsert && target.type === "item" && !isInternal && (target.dropPosition === "before" || target.dropPosition === "after");
|
|
124
|
+
let isValidReorder = onReorder && target.type === "item" && isInternal && (target.dropPosition === "before" || target.dropPosition === "after");
|
|
97
125
|
// Feedback was that internal root drop was weird so preventing that from happening
|
|
98
|
-
let isValidRootDrop = onRootDrop && target.type ===
|
|
126
|
+
let isValidRootDrop = onRootDrop && target.type === "root" && !isInternal;
|
|
99
127
|
// Automatically prevent items (i.e. folders) from being dropped on themselves.
|
|
100
|
-
let isValidOnItemDrop = onItemDrop && target.type ===
|
|
128
|
+
let isValidOnItemDrop = onItemDrop && target.type === "item" && target.dropPosition === "on" && !(isInternal && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));
|
|
101
129
|
if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {
|
|
102
130
|
if (getDropOperation) return getDropOperation(target, types, allowedOperations);
|
|
103
131
|
else return allowedOperations[0];
|
|
104
132
|
}
|
|
105
133
|
}
|
|
106
|
-
return
|
|
134
|
+
return "cancel";
|
|
107
135
|
}, [
|
|
108
136
|
acceptedDragTypes,
|
|
109
137
|
getDropOperation,
|
|
@@ -117,18 +145,18 @@ function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
|
117
145
|
return {
|
|
118
146
|
collection: collection,
|
|
119
147
|
selectionManager: selectionManager,
|
|
120
|
-
target:
|
|
148
|
+
target: target,
|
|
121
149
|
setTarget (newTarget) {
|
|
122
150
|
if (this.isDropTarget(newTarget)) return;
|
|
123
151
|
let target = targetRef.current;
|
|
124
|
-
if (target && typeof props.onDropExit ===
|
|
125
|
-
type:
|
|
152
|
+
if (target && typeof props.onDropExit === "function") props.onDropExit({
|
|
153
|
+
type: "dropexit",
|
|
126
154
|
x: 0,
|
|
127
155
|
y: 0,
|
|
128
156
|
target: target
|
|
129
157
|
});
|
|
130
|
-
if (newTarget && typeof onDropEnter ===
|
|
131
|
-
type:
|
|
158
|
+
if (newTarget && typeof onDropEnter === "function") onDropEnter({
|
|
159
|
+
type: "dropenter",
|
|
132
160
|
x: 0,
|
|
133
161
|
y: 0,
|
|
134
162
|
target: newTarget
|
|
@@ -140,7 +168,7 @@ function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
|
140
168
|
let target = targetRef.current;
|
|
141
169
|
if ($e672e8bc247525d1$var$isEqualDropTarget(dropTarget, target)) return true;
|
|
142
170
|
// Check if the targets point at the same point between two items, one referring before, and the other after.
|
|
143
|
-
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) ===
|
|
171
|
+
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) === "item" && (target === null || target === void 0 ? void 0 : target.type) === "item" && dropTarget.key !== target.key && dropTarget.dropPosition !== target.dropPosition && dropTarget.dropPosition !== "on" && target.dropPosition !== "on") return $e672e8bc247525d1$var$isEqualDropTarget(getOppositeTarget(dropTarget), target) || $e672e8bc247525d1$var$isEqualDropTarget(dropTarget, getOppositeTarget(target));
|
|
144
172
|
return false;
|
|
145
173
|
},
|
|
146
174
|
getDropOperation (e) {
|
|
@@ -151,10 +179,10 @@ function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
|
151
179
|
function $e672e8bc247525d1$var$isEqualDropTarget(a, b) {
|
|
152
180
|
if (!a) return !b;
|
|
153
181
|
switch(a.type){
|
|
154
|
-
case
|
|
155
|
-
return (b === null || b === void 0 ? void 0 : b.type) ===
|
|
156
|
-
case
|
|
157
|
-
return (b === null || b === void 0 ? void 0 : b.type) ===
|
|
182
|
+
case "root":
|
|
183
|
+
return (b === null || b === void 0 ? void 0 : b.type) === "root";
|
|
184
|
+
case "item":
|
|
185
|
+
return (b === null || b === void 0 ? void 0 : b.type) === "item" && (b === null || b === void 0 ? void 0 : b.key) === a.key && (b === null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C,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC;SAEQ,uCAAiB,CAAC,CAAa,EAAE,CAAa,EAAE,CAAC;IACxD,EAAE,GAAG,CAAC,EACJ,MAAM,EAAE,CAAC;IAGX,MAAM,CAAE,CAAC,CAAC,IAAI;QACZ,IAAI,CAAC,CAAM;YACT,MAAM,EAAC,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAO,GAAP,IAAI,CAAJ,CAAO,GAAP,CAAC,CAAE,IAAI,MAAK,CAAM;QAC3B,IAAI,CAAC,CAAM;YACT,MAAM,EAAC,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAO,GAAP,IAAI,CAAJ,CAAO,GAAP,CAAC,CAAE,IAAI,MAAK,CAAM,UAAI,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAM,GAAN,IAAI,CAAJ,CAAM,GAAN,CAAC,CAAE,GAAG,MAAK,CAAC,CAAC,GAAG,KAAI,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAe,GAAf,IAAI,CAAJ,CAAe,GAAf,CAAC,CAAE,YAAY,MAAK,CAAC,CAAC,YAAY;;AAEzF,CAAC;;","sources":["packages/@react-stately/dnd/src/index.ts","packages/@react-stately/dnd/src/useDraggableCollectionState.ts","packages/@react-stately/dnd/src/useDroppableCollectionState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {DraggableCollectionStateOptions, DraggableCollectionState} from './useDraggableCollectionState';\nexport type {DroppableCollectionStateOptions, DroppableCollectionState} from './useDroppableCollectionState';\nexport {useDraggableCollectionState} from './useDraggableCollectionState';\nexport {useDroppableCollectionState} from './useDroppableCollectionState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, DraggableCollectionEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, Node} from '@react-types/shared';\nimport {Key, RefObject, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\nexport interface DraggableCollectionStateOptions extends DraggableCollectionProps {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DraggableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The key of the item that initiated a drag. */\n draggedKey: Key | null,\n /** The keys of the items that are currently being dragged. */\n draggingKeys: Set<Key>,\n /** Returns whether the given key is currently being dragged. */\n isDragging(key: Key): boolean,\n /** Returns the keys of the items that will be dragged with the given key (e.g. selected items). */\n getKeysForDrag(key: Key): Set<Key>,\n /** Returns the items to drag for the given key. */\n getItems(key: Key): DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\n /** Begins a drag for the given key. This triggers the onDragStart event. */\n startDrag(key: Key, event: DragStartEvent): void,\n /** Triggers an onDragMove event. */\n moveDrag(event: DragMoveEvent): void,\n /** Ends the current drag, and emits an onDragEnd event. */\n endDrag(event: DraggableCollectionEndEvent): void\n}\n\n/**\n * Manages state for a draggable collection.\n */\nexport function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState {\n let {\n getItems,\n collection,\n selectionManager,\n onDragStart,\n onDragMove,\n onDragEnd,\n preview,\n getAllowedDropOperations\n } = props;\n let [, setDragging] = useState(false);\n let draggingKeys = useRef(new Set<Key>());\n let draggedKey = useRef(null);\n let getKeys = (key: Key) => {\n // The clicked item is always added to the drag. If it is selected, then all of the\n // other selected items are also dragged. If it is not selected, the only the clicked\n // item is dragged. This matches native macOS behavior.\n let keys = new Set(\n selectionManager.isSelected(key)\n ? new Set([...selectionManager.selectedKeys].filter(key => !!collection.getItem(key)))\n : []\n );\n\n keys.add(key);\n return keys;\n };\n\n return {\n collection,\n selectionManager,\n get draggedKey() {\n return draggedKey.current;\n },\n get draggingKeys() {\n return draggingKeys.current;\n },\n isDragging(key) {\n return draggingKeys.current.has(key);\n },\n getKeysForDrag: getKeys,\n getItems(key) {\n return getItems(getKeys(key));\n },\n preview,\n getAllowedDropOperations,\n startDrag(key, event) {\n setDragging(true);\n let keys = getKeys(key);\n draggingKeys.current = keys;\n draggedKey.current = key;\n if (typeof onDragStart === 'function') {\n onDragStart({\n ...event,\n keys\n });\n }\n },\n moveDrag(event) {\n if (typeof onDragMove === 'function') {\n onDragMove({\n ...event,\n keys: draggingKeys.current\n });\n }\n },\n endDrag(event) {\n let {\n isInternal\n } = event;\n\n if (typeof onDragEnd === 'function') {\n onDragEnd({\n ...event,\n keys: draggingKeys.current,\n isInternal\n });\n }\n\n setDragging(false);\n draggingKeys.current = new Set();\n draggedKey.current = null;\n }\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, DragTypes, DropOperation, DroppableCollectionProps, DropTarget, ItemDropTarget, Node} from '@react-types/shared';\nimport {Key, useCallback, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\ninterface DropOperationEvent {\n target: DropTarget,\n types: DragTypes,\n allowedOperations: DropOperation[],\n isInternal: boolean,\n draggingKeys: Set<Key>\n}\n\nexport interface DroppableCollectionStateOptions extends Omit<DroppableCollectionProps, 'onDropMove' | 'onDropActivate'> {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DroppableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The current drop target. */\n target: DropTarget | null,\n /** Sets the current drop target. */\n setTarget(target: DropTarget): void,\n /** Returns whether the given target is equivalent to the current drop target. */\n isDropTarget(target: DropTarget): boolean,\n /** Returns the drop operation for the given parameters. */\n getDropOperation(e: DropOperationEvent): DropOperation\n}\n\n/**\n * Manages state for a droppable collection.\n */\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let {\n acceptedDragTypes = 'all',\n onInsert,\n onRootDrop,\n onItemDrop,\n onReorder,\n shouldAcceptItemDrop,\n collection,\n selectionManager,\n onDropEnter,\n getDropOperation,\n onDrop\n } = props;\n let [target, setTarget] = useState<DropTarget>(null);\n let targetRef = useRef<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\n if (target.dropPosition === 'before') {\n let key = collection.getKeyBefore(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'after'} : null;\n } else if (target.dropPosition === 'after') {\n let key = collection.getKeyAfter(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'before'} : null;\n }\n };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\n\n if (acceptedDragTypes === 'all' || acceptedDragTypes.some(type => types.has(type))) {\n let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n // Feedback was that internal root drop was weird so preventing that from happening\n let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;\n // Automatically prevent items (i.e. folders) from being dropped on themselves.\n let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));\n\n if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {\n if (getDropOperation) {\n return getDropOperation(target, types, allowedOperations);\n } else {\n return allowedOperations[0];\n }\n }\n }\n\n return 'cancel';\n }, [acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);\n\n return {\n collection,\n selectionManager,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\n let target = targetRef.current;\n if (target && typeof props.onDropExit === 'function') {\n props.onDropExit({\n type: 'dropexit',\n x: 0, // todo\n y: 0,\n target\n });\n }\n\n if (newTarget && typeof onDropEnter === 'function') {\n onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n targetRef.current = newTarget;\n setTarget(newTarget);\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\n if (isEqualDropTarget(dropTarget, target)) {\n return true;\n }\n\n // Check if the targets point at the same point between two items, one referring before, and the other after.\n if (\n dropTarget?.type === 'item' &&\n target?.type === 'item' &&\n dropTarget.key !== target.key &&\n dropTarget.dropPosition !== target.dropPosition &&\n dropTarget.dropPosition !== 'on' &&\n target.dropPosition !== 'on'\n ) {\n return isEqualDropTarget(getOppositeTarget(dropTarget), target) ||\n isEqualDropTarget(dropTarget, getOppositeTarget(target));\n }\n\n return false;\n },\n getDropOperation(e) {\n return defaultGetDropOperation(e);\n }\n };\n}\n\nfunction isEqualDropTarget(a: DropTarget, b: DropTarget) {\n if (!a) {\n return !b;\n }\n\n switch (a.type) {\n case 'root':\n return b?.type === 'root';\n case 'item':\n return b?.type === 'item' && b?.key === a.key && b?.dropPosition === a.dropPosition;\n }\n}\n"],"names":[],"version":3,"file":"module.mjs.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;AAyCO,SAAS,0CAA4B,KAAsC,EAA4B;IAC5G,IAAI,YACF,SAAQ,cACR,WAAU,oBACV,iBAAgB,eAChB,YAAW,cACX,WAAU,aACV,UAAS,WACT,QAAO,4BACP,yBAAwB,EACzB,GAAG;IACJ,IAAI,GAAG,YAAY,GAAG,CAAA,GAAA,eAAO,EAAE,KAAK;IACpC,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE,IAAI;IAC9B,IAAI,aAAa,CAAA,GAAA,aAAK,EAAE,IAAI;IAC5B,IAAI,UAAU,CAAC,MAAa;QAC1B,mFAAmF;QACnF,qFAAqF;QACrF,uDAAuD;QACvD,IAAI,OAAO,IAAI,IACb,iBAAiB,UAAU,CAAC,OACxB,IAAI,IAAI;eAAI,iBAAiB,YAAY;SAAC,CAAC,MAAM,CAAC,CAAA,MAAO,CAAC,CAAC,WAAW,OAAO,CAAC,SAC9E,EAAE;QAGR,KAAK,GAAG,CAAC;QACT,OAAO;IACT;IAEA,OAAO;oBACL;0BACA;QACA,IAAI,cAAa;YACf,OAAO,WAAW,OAAO;QAC3B;QACA,IAAI,gBAAe;YACjB,OAAO,aAAa,OAAO;QAC7B;QACA,YAAW,GAAG,EAAE;YACd,OAAO,a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,EAAE,YAAY;IACvF;AACF;","sources":["packages/@react-stately/dnd/src/index.ts","packages/@react-stately/dnd/src/useDraggableCollectionState.ts","packages/@react-stately/dnd/src/useDroppableCollectionState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {DraggableCollectionStateOptions, DraggableCollectionState} from './useDraggableCollectionState';\nexport type {DroppableCollectionStateOptions, DroppableCollectionState} from './useDroppableCollectionState';\nexport {useDraggableCollectionState} from './useDraggableCollectionState';\nexport {useDroppableCollectionState} from './useDroppableCollectionState';\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, DraggableCollectionEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, Node} from '@react-types/shared';\nimport {Key, RefObject, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\nexport interface DraggableCollectionStateOptions extends DraggableCollectionProps {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DraggableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The key of the item that initiated a drag. */\n draggedKey: Key | null,\n /** The keys of the items that are currently being dragged. */\n draggingKeys: Set<Key>,\n /** Returns whether the given key is currently being dragged. */\n isDragging(key: Key): boolean,\n /** Returns the keys of the items that will be dragged with the given key (e.g. selected items). */\n getKeysForDrag(key: Key): Set<Key>,\n /** Returns the items to drag for the given key. */\n getItems(key: Key): DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\n /** Begins a drag for the given key. This triggers the onDragStart event. */\n startDrag(key: Key, event: DragStartEvent): void,\n /** Triggers an onDragMove event. */\n moveDrag(event: DragMoveEvent): void,\n /** Ends the current drag, and emits an onDragEnd event. */\n endDrag(event: DraggableCollectionEndEvent): void\n}\n\n/**\n * Manages state for a draggable collection.\n */\nexport function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState {\n let {\n getItems,\n collection,\n selectionManager,\n onDragStart,\n onDragMove,\n onDragEnd,\n preview,\n getAllowedDropOperations\n } = props;\n let [, setDragging] = useState(false);\n let draggingKeys = useRef(new Set<Key>());\n let draggedKey = useRef(null);\n let getKeys = (key: Key) => {\n // The clicked item is always added to the drag. If it is selected, then all of the\n // other selected items are also dragged. If it is not selected, the only the clicked\n // item is dragged. This matches native macOS behavior.\n let keys = new Set(\n selectionManager.isSelected(key)\n ? new Set([...selectionManager.selectedKeys].filter(key => !!collection.getItem(key)))\n : []\n );\n\n keys.add(key);\n return keys;\n };\n\n return {\n collection,\n selectionManager,\n get draggedKey() {\n return draggedKey.current;\n },\n get draggingKeys() {\n return draggingKeys.current;\n },\n isDragging(key) {\n return draggingKeys.current.has(key);\n },\n getKeysForDrag: getKeys,\n getItems(key) {\n return getItems(getKeys(key));\n },\n preview,\n getAllowedDropOperations,\n startDrag(key, event) {\n setDragging(true);\n let keys = getKeys(key);\n draggingKeys.current = keys;\n draggedKey.current = key;\n if (typeof onDragStart === 'function') {\n onDragStart({\n ...event,\n keys\n });\n }\n },\n moveDrag(event) {\n if (typeof onDragMove === 'function') {\n onDragMove({\n ...event,\n keys: draggingKeys.current\n });\n }\n },\n endDrag(event) {\n let {\n isInternal\n } = event;\n\n if (typeof onDragEnd === 'function') {\n onDragEnd({\n ...event,\n keys: draggingKeys.current,\n isInternal\n });\n }\n\n setDragging(false);\n draggingKeys.current = new Set();\n draggedKey.current = null;\n }\n };\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, DragTypes, DropOperation, DroppableCollectionProps, DropTarget, ItemDropTarget, Node} from '@react-types/shared';\nimport {Key, useCallback, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\ninterface DropOperationEvent {\n target: DropTarget,\n types: DragTypes,\n allowedOperations: DropOperation[],\n isInternal: boolean,\n draggingKeys: Set<Key>\n}\n\nexport interface DroppableCollectionStateOptions extends Omit<DroppableCollectionProps, 'onDropMove' | 'onDropActivate'> {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DroppableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The current drop target. */\n target: DropTarget | null,\n /** Sets the current drop target. */\n setTarget(target: DropTarget): void,\n /** Returns whether the given target is equivalent to the current drop target. */\n isDropTarget(target: DropTarget): boolean,\n /** Returns the drop operation for the given parameters. */\n getDropOperation(e: DropOperationEvent): DropOperation\n}\n\n/**\n * Manages state for a droppable collection.\n */\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let {\n acceptedDragTypes = 'all',\n onInsert,\n onRootDrop,\n onItemDrop,\n onReorder,\n shouldAcceptItemDrop,\n collection,\n selectionManager,\n onDropEnter,\n getDropOperation,\n onDrop\n } = props;\n let [target, setTarget] = useState<DropTarget>(null);\n let targetRef = useRef<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\n if (target.dropPosition === 'before') {\n let key = collection.getKeyBefore(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'after'} : null;\n } else if (target.dropPosition === 'after') {\n let key = collection.getKeyAfter(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'before'} : null;\n }\n };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\n\n if (acceptedDragTypes === 'all' || acceptedDragTypes.some(type => types.has(type))) {\n let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n // Feedback was that internal root drop was weird so preventing that from happening\n let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;\n // Automatically prevent items (i.e. folders) from being dropped on themselves.\n let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));\n\n if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {\n if (getDropOperation) {\n return getDropOperation(target, types, allowedOperations);\n } else {\n return allowedOperations[0];\n }\n }\n }\n\n return 'cancel';\n }, [acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);\n\n return {\n collection,\n selectionManager,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\n let target = targetRef.current;\n if (target && typeof props.onDropExit === 'function') {\n props.onDropExit({\n type: 'dropexit',\n x: 0, // todo\n y: 0,\n target\n });\n }\n\n if (newTarget && typeof onDropEnter === 'function') {\n onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n targetRef.current = newTarget;\n setTarget(newTarget);\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\n if (isEqualDropTarget(dropTarget, target)) {\n return true;\n }\n\n // Check if the targets point at the same point between two items, one referring before, and the other after.\n if (\n dropTarget?.type === 'item' &&\n target?.type === 'item' &&\n dropTarget.key !== target.key &&\n dropTarget.dropPosition !== target.dropPosition &&\n dropTarget.dropPosition !== 'on' &&\n target.dropPosition !== 'on'\n ) {\n return isEqualDropTarget(getOppositeTarget(dropTarget), target) ||\n isEqualDropTarget(dropTarget, getOppositeTarget(target));\n }\n\n return false;\n },\n getDropOperation(e) {\n return defaultGetDropOperation(e);\n }\n };\n}\n\nfunction isEqualDropTarget(a: DropTarget, b: DropTarget) {\n if (!a) {\n return !b;\n }\n\n switch (a.type) {\n case 'root':\n return b?.type === 'root';\n case 'item':\n return b?.type === 'item' && b?.key === a.key && b?.dropPosition === a.dropPosition;\n }\n}\n"],"names":[],"version":3,"file":"module.mjs.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/dnd",
|
|
3
|
-
"version": "3.0.1-nightly.
|
|
3
|
+
"version": "3.0.1-nightly.3600+bfce84fee",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@react-
|
|
27
|
-
"@
|
|
25
|
+
"@react-stately/selection": "3.0.0-nightly.1900+bfce84fee",
|
|
26
|
+
"@react-types/shared": "3.0.0-nightly.1900+bfce84fee",
|
|
27
|
+
"@swc/helpers": "^0.4.14"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "bfce84fee12a027d9cbc38b43e1747e3e4b4b169"
|
|
36
36
|
}
|