@react-stately/dnd 3.0.0-alpha.4 → 3.0.0-alpha.7
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 +42 -30
- package/dist/main.js.map +1 -1
- package/dist/module.js +41 -29
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +7 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/useDraggableCollectionState.ts +45 -29
- package/src/useDroppableCollectionState.ts +1 -1
package/dist/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var $
|
|
1
|
+
var $1IdlX$react = require("react");
|
|
2
2
|
|
|
3
3
|
function $parcel$exportWildcard(dest, source) {
|
|
4
4
|
Object.keys(source).forEach(function(key) {
|
|
@@ -19,65 +19,77 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
19
19
|
function $parcel$export(e, n, v, s) {
|
|
20
20
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
21
21
|
}
|
|
22
|
-
var $
|
|
22
|
+
var $481a240e3d51b276$exports = {};
|
|
23
23
|
|
|
24
|
-
$parcel$export($
|
|
24
|
+
$parcel$export($481a240e3d51b276$exports, "useDraggableCollectionState", () => $481a240e3d51b276$export$29efd034f1d79f81);
|
|
25
25
|
|
|
26
|
-
function $
|
|
27
|
-
let
|
|
26
|
+
function $481a240e3d51b276$export$29efd034f1d79f81(props) {
|
|
27
|
+
let { getItems: getItems , collection: collection , selectionManager: selectionManager , onDragStart: onDragStart , onDragMove: onDragMove , onDragEnd: onDragEnd , preview: preview } = props;
|
|
28
|
+
let [, setDragging] = $1IdlX$react.useState(false);
|
|
29
|
+
let draggingKeys = $1IdlX$react.useRef(new Set());
|
|
30
|
+
let draggedKey = $1IdlX$react.useRef(null);
|
|
28
31
|
let getKeys = (key)=>{
|
|
29
32
|
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
30
33
|
// other selected items are also dragged. If it is not selected, the only the clicked
|
|
31
34
|
// item is dragged. This matches native macOS behavior.
|
|
32
|
-
let keys = new Set(
|
|
35
|
+
let keys = new Set(selectionManager.isSelected(key) ? new Set([
|
|
36
|
+
...selectionManager.selectedKeys
|
|
37
|
+
]) : []);
|
|
33
38
|
keys.add(key);
|
|
34
39
|
return keys;
|
|
35
40
|
};
|
|
36
41
|
return {
|
|
37
|
-
collection:
|
|
38
|
-
selectionManager:
|
|
42
|
+
collection: collection,
|
|
43
|
+
selectionManager: selectionManager,
|
|
44
|
+
get draggedKey () {
|
|
45
|
+
return draggedKey.current;
|
|
46
|
+
},
|
|
47
|
+
get draggingKeys () {
|
|
48
|
+
return draggingKeys.current;
|
|
49
|
+
},
|
|
39
50
|
isDragging (key) {
|
|
40
|
-
return draggingKeys.has(key);
|
|
51
|
+
return draggingKeys.current.has(key);
|
|
41
52
|
},
|
|
42
53
|
getKeysForDrag: getKeys,
|
|
43
54
|
getItems (key) {
|
|
44
|
-
return
|
|
45
|
-
},
|
|
46
|
-
renderPreview (key) {
|
|
47
|
-
if (typeof props.renderPreview === 'function') return props.renderPreview(getKeys(key), key);
|
|
48
|
-
return null;
|
|
55
|
+
return getItems(getKeys(key));
|
|
49
56
|
},
|
|
57
|
+
preview: preview,
|
|
50
58
|
startDrag (key, event) {
|
|
59
|
+
setDragging(true);
|
|
51
60
|
let keys = getKeys(key);
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
draggingKeys.current = keys;
|
|
62
|
+
draggedKey.current = key;
|
|
63
|
+
if (typeof onDragStart === 'function') onDragStart({
|
|
54
64
|
...event,
|
|
55
65
|
keys: keys
|
|
56
66
|
});
|
|
57
67
|
},
|
|
58
68
|
moveDrag (event) {
|
|
59
|
-
if (typeof
|
|
69
|
+
if (typeof onDragMove === 'function') onDragMove({
|
|
60
70
|
...event,
|
|
61
|
-
keys: draggingKeys
|
|
71
|
+
keys: draggingKeys.current
|
|
62
72
|
});
|
|
63
73
|
},
|
|
64
74
|
endDrag (event) {
|
|
65
|
-
if (typeof
|
|
75
|
+
if (typeof onDragEnd === 'function') onDragEnd({
|
|
66
76
|
...event,
|
|
67
|
-
keys: draggingKeys
|
|
77
|
+
keys: draggingKeys.current
|
|
68
78
|
});
|
|
69
|
-
|
|
79
|
+
setDragging(false);
|
|
80
|
+
draggingKeys.current = new Set();
|
|
81
|
+
draggedKey.current = null;
|
|
70
82
|
}
|
|
71
83
|
};
|
|
72
84
|
}
|
|
73
85
|
|
|
74
86
|
|
|
75
|
-
var $
|
|
87
|
+
var $6ce4cbfbe5e354f1$exports = {};
|
|
76
88
|
|
|
77
|
-
$parcel$export($
|
|
89
|
+
$parcel$export($6ce4cbfbe5e354f1$exports, "useDroppableCollectionState", () => $6ce4cbfbe5e354f1$export$926850f6ecef79d0);
|
|
78
90
|
|
|
79
|
-
function $
|
|
80
|
-
let [target1, setTarget] = $
|
|
91
|
+
function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) {
|
|
92
|
+
let [target1, setTarget] = $1IdlX$react.useState(null);
|
|
81
93
|
let getOppositeTarget = (target)=>{
|
|
82
94
|
if (target.dropPosition === 'before') {
|
|
83
95
|
let key = props.collection.getKeyBefore(target.key);
|
|
@@ -116,9 +128,9 @@ function $f67e1fddbca9a82e$export$926850f6ecef79d0(props) {
|
|
|
116
128
|
setTarget(newTarget);
|
|
117
129
|
},
|
|
118
130
|
isDropTarget (dropTarget) {
|
|
119
|
-
if ($
|
|
131
|
+
if ($6ce4cbfbe5e354f1$var$isEqualDropTarget(dropTarget, target1)) return true;
|
|
120
132
|
// Check if the targets point at the same point between two items, one referring before, and the other after.
|
|
121
|
-
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) === 'item' && (target1 === null || target1 === void 0 ? void 0 : target1.type) === 'item' && dropTarget.key !== target1.key && dropTarget.dropPosition !== target1.dropPosition && dropTarget.dropPosition !== 'on' && target1.dropPosition !== 'on') return $
|
|
133
|
+
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) === 'item' && (target1 === null || target1 === void 0 ? void 0 : target1.type) === 'item' && dropTarget.key !== target1.key && dropTarget.dropPosition !== target1.dropPosition && dropTarget.dropPosition !== 'on' && target1.dropPosition !== 'on') return $6ce4cbfbe5e354f1$var$isEqualDropTarget(getOppositeTarget(dropTarget), target1) || $6ce4cbfbe5e354f1$var$isEqualDropTarget(dropTarget, getOppositeTarget(target1));
|
|
122
134
|
return false;
|
|
123
135
|
},
|
|
124
136
|
getDropOperation (target, types, allowedOperations) {
|
|
@@ -126,7 +138,7 @@ function $f67e1fddbca9a82e$export$926850f6ecef79d0(props) {
|
|
|
126
138
|
}
|
|
127
139
|
};
|
|
128
140
|
}
|
|
129
|
-
function $
|
|
141
|
+
function $6ce4cbfbe5e354f1$var$isEqualDropTarget(a, b) {
|
|
130
142
|
if (!a) return !b;
|
|
131
143
|
switch(a.type){
|
|
132
144
|
case 'root':
|
|
@@ -137,8 +149,8 @@ function $f67e1fddbca9a82e$var$isEqualDropTarget(a, b) {
|
|
|
137
149
|
}
|
|
138
150
|
|
|
139
151
|
|
|
140
|
-
$parcel$exportWildcard(module.exports, $
|
|
141
|
-
$parcel$exportWildcard(module.exports, $
|
|
152
|
+
$parcel$exportWildcard(module.exports, $481a240e3d51b276$exports);
|
|
153
|
+
$parcel$exportWildcard(module.exports, $6ce4cbfbe5e354f1$exports);
|
|
142
154
|
|
|
143
155
|
|
|
144
156
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;SCiCgB,yCAA2B,CAAC,KAAiC,EAA4B,CAAC;IACxG,GAAG,EAAE,YAAY,EAAE,eAAe,IAAI,qBAAQ,CAAC,GAAG,CAAC,GAAG;IACtD,GAAG,CAAC,OAAO,IAAI,GAAQ,GAAK,CAAC;QAC3B,EAAmF,AAAnF,iFAAmF;QACnF,EAAqF,AAArF,mFAAqF;QACrF,EAAuD,AAAvD,q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AC,MAAM,CAAC,KAAK,CAAC,gBAAgB,KAAK,CAAU,YAC/C,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,iBAAiB,IACvD,iBAAiB,CAAC,CAAC;QACzB,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 * from './useDraggableCollectionState';\nexport * 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, DragEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragStartEvent, Node} from '@react-types/shared';\nimport {Key, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\ninterface DraggableCollectionOptions extends DraggableCollectionProps {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DraggableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n isDragging(key: Key): boolean,\n getKeysForDrag(key: Key): Set<Key>,\n getItems(key: Key): DragItem[],\n renderPreview(key: Key): JSX.Element,\n startDrag(key: Key, event: DragStartEvent): void,\n moveDrag(event: DragMoveEvent): void,\n endDrag(event: DragEndEvent): void\n}\n\nexport function useDraggableCollectionState(props: DraggableCollectionOptions): DraggableCollectionState {\n let [draggingKeys, setDraggingKeys] = useState(new Set<Key>());\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 props.selectionManager.isSelected(key)\n ? props.selectionManager.selectedKeys\n : []\n );\n\n keys.add(key);\n return keys;\n };\n\n return {\n collection: props.collection,\n selectionManager: props.selectionManager,\n isDragging(key) {\n return draggingKeys.has(key);\n },\n getKeysForDrag: getKeys,\n getItems(key) {\n return props.getItems(getKeys(key));\n },\n renderPreview(key) {\n if (typeof props.renderPreview === 'function') {\n return props.renderPreview(getKeys(key), key);\n }\n\n return null;\n },\n startDrag(key, event) {\n let keys = getKeys(key);\n setDraggingKeys(keys);\n\n if (typeof props.onDragStart === 'function') {\n props.onDragStart({\n ...event,\n keys\n });\n }\n },\n moveDrag(event) {\n if (typeof props.onDragMove === 'function') {\n props.onDragMove({\n ...event,\n keys: draggingKeys\n });\n }\n },\n endDrag(event) {\n if (typeof props.onDragEnd === 'function') {\n props.onDragEnd({\n ...event,\n keys: draggingKeys\n });\n }\n\n setDraggingKeys(new Set());\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 {MultipleSelectionManager} from '@react-stately/selection';\nimport {useState} from 'react';\n\ninterface DroppableCollectionStateOptions extends DroppableCollectionProps {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DroppableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n target: DropTarget,\n setTarget(target: DropTarget): void,\n isDropTarget(target: DropTarget): boolean,\n getDropOperation(target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]): DropOperation\n}\n\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let [target, setTarget] = useState<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\n if (target.dropPosition === 'before') {\n let key = props.collection.getKeyBefore(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'after'} : null;\n } else if (target.dropPosition === 'after') {\n let key = props.collection.getKeyAfter(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'before'} : null;\n }\n };\n\n return {\n collection: props.collection,\n selectionManager: props.selectionManager,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\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 props.onDropEnter === 'function') {\n props.onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n setTarget(newTarget);\n },\n isDropTarget(dropTarget) {\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(target, types, allowedOperations) {\n return typeof props.getDropOperation === 'function'\n ? props.getDropOperation(target, types, allowedOperations)\n : allowedOperations[0];\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":";;;;;;;;;;;;;;;;;;;;;;;;;SCmCgB,yCAA2B,CAAC,KAAiC,EAA4B,CAAC;IACxG,GAAG,CAAC,CAAC,WACH,QAAQ,eACR,UAAU,qBACV,gBAAgB,gBAChB,WAAW,eACX,UAAU,cACV,SAAS,YACT,OAAO,EACT,CAAC,GAA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nd/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 * from './useDraggableCollectionState';\nexport * 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, DragEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, Node} from '@react-types/shared';\nimport {Key, RefObject, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\nexport interface DraggableCollectionOptions extends DraggableCollectionProps {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DraggableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n draggedKey: Key | null,\n draggingKeys: Set<Key>,\n isDragging(key: Key): boolean,\n getKeysForDrag(key: Key): Set<Key>,\n getItems(key: Key): DragItem[],\n preview?: RefObject<DragPreviewRenderer>,\n startDrag(key: Key, event: DragStartEvent): void,\n moveDrag(event: DragMoveEvent): void,\n endDrag(event: DragEndEvent): void\n}\n\nexport function useDraggableCollectionState(props: DraggableCollectionOptions): DraggableCollectionState {\n let {\n getItems,\n collection,\n selectionManager,\n onDragStart,\n onDragMove,\n onDragEnd,\n preview\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])\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 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 if (typeof onDragEnd === 'function') {\n onDragEnd({\n ...event,\n keys: draggingKeys.current\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 {MultipleSelectionManager} from '@react-stately/selection';\nimport {useState} from 'react';\n\nexport interface DroppableCollectionStateOptions extends DroppableCollectionProps {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DroppableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n target: DropTarget,\n setTarget(target: DropTarget): void,\n isDropTarget(target: DropTarget): boolean,\n getDropOperation(target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]): DropOperation\n}\n\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let [target, setTarget] = useState<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\n if (target.dropPosition === 'before') {\n let key = props.collection.getKeyBefore(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'after'} : null;\n } else if (target.dropPosition === 'after') {\n let key = props.collection.getKeyAfter(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'before'} : null;\n }\n };\n\n return {\n collection: props.collection,\n selectionManager: props.selectionManager,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\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 props.onDropEnter === 'function') {\n props.onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n setTarget(newTarget);\n },\n isDropTarget(dropTarget) {\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(target, types, allowedOperations) {\n return typeof props.getDropOperation === 'function'\n ? props.getDropOperation(target, types, allowedOperations)\n : allowedOperations[0];\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.js
CHANGED
|
@@ -1,67 +1,79 @@
|
|
|
1
|
-
import {useState as $
|
|
1
|
+
import {useState as $bBNwq$useState, useRef as $bBNwq$useRef} from "react";
|
|
2
2
|
|
|
3
3
|
function $parcel$export(e, n, v, s) {
|
|
4
4
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
5
5
|
}
|
|
6
|
-
var $
|
|
6
|
+
var $b45bbbaf0c3785df$exports = {};
|
|
7
7
|
|
|
8
|
-
$parcel$export($
|
|
8
|
+
$parcel$export($b45bbbaf0c3785df$exports, "useDraggableCollectionState", () => $b45bbbaf0c3785df$export$29efd034f1d79f81);
|
|
9
9
|
|
|
10
|
-
function $
|
|
11
|
-
let
|
|
10
|
+
function $b45bbbaf0c3785df$export$29efd034f1d79f81(props) {
|
|
11
|
+
let { getItems: getItems , collection: collection , selectionManager: selectionManager , onDragStart: onDragStart , onDragMove: onDragMove , onDragEnd: onDragEnd , preview: preview } = props;
|
|
12
|
+
let [, setDragging] = $bBNwq$useState(false);
|
|
13
|
+
let draggingKeys = $bBNwq$useRef(new Set());
|
|
14
|
+
let draggedKey = $bBNwq$useRef(null);
|
|
12
15
|
let getKeys = (key)=>{
|
|
13
16
|
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
14
17
|
// other selected items are also dragged. If it is not selected, the only the clicked
|
|
15
18
|
// item is dragged. This matches native macOS behavior.
|
|
16
|
-
let keys = new Set(
|
|
19
|
+
let keys = new Set(selectionManager.isSelected(key) ? new Set([
|
|
20
|
+
...selectionManager.selectedKeys
|
|
21
|
+
]) : []);
|
|
17
22
|
keys.add(key);
|
|
18
23
|
return keys;
|
|
19
24
|
};
|
|
20
25
|
return {
|
|
21
|
-
collection:
|
|
22
|
-
selectionManager:
|
|
26
|
+
collection: collection,
|
|
27
|
+
selectionManager: selectionManager,
|
|
28
|
+
get draggedKey () {
|
|
29
|
+
return draggedKey.current;
|
|
30
|
+
},
|
|
31
|
+
get draggingKeys () {
|
|
32
|
+
return draggingKeys.current;
|
|
33
|
+
},
|
|
23
34
|
isDragging (key) {
|
|
24
|
-
return draggingKeys.has(key);
|
|
35
|
+
return draggingKeys.current.has(key);
|
|
25
36
|
},
|
|
26
37
|
getKeysForDrag: getKeys,
|
|
27
38
|
getItems (key) {
|
|
28
|
-
return
|
|
29
|
-
},
|
|
30
|
-
renderPreview (key) {
|
|
31
|
-
if (typeof props.renderPreview === 'function') return props.renderPreview(getKeys(key), key);
|
|
32
|
-
return null;
|
|
39
|
+
return getItems(getKeys(key));
|
|
33
40
|
},
|
|
41
|
+
preview: preview,
|
|
34
42
|
startDrag (key, event) {
|
|
43
|
+
setDragging(true);
|
|
35
44
|
let keys = getKeys(key);
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
draggingKeys.current = keys;
|
|
46
|
+
draggedKey.current = key;
|
|
47
|
+
if (typeof onDragStart === 'function') onDragStart({
|
|
38
48
|
...event,
|
|
39
49
|
keys: keys
|
|
40
50
|
});
|
|
41
51
|
},
|
|
42
52
|
moveDrag (event) {
|
|
43
|
-
if (typeof
|
|
53
|
+
if (typeof onDragMove === 'function') onDragMove({
|
|
44
54
|
...event,
|
|
45
|
-
keys: draggingKeys
|
|
55
|
+
keys: draggingKeys.current
|
|
46
56
|
});
|
|
47
57
|
},
|
|
48
58
|
endDrag (event) {
|
|
49
|
-
if (typeof
|
|
59
|
+
if (typeof onDragEnd === 'function') onDragEnd({
|
|
50
60
|
...event,
|
|
51
|
-
keys: draggingKeys
|
|
61
|
+
keys: draggingKeys.current
|
|
52
62
|
});
|
|
53
|
-
|
|
63
|
+
setDragging(false);
|
|
64
|
+
draggingKeys.current = new Set();
|
|
65
|
+
draggedKey.current = null;
|
|
54
66
|
}
|
|
55
67
|
};
|
|
56
68
|
}
|
|
57
69
|
|
|
58
70
|
|
|
59
|
-
var $
|
|
71
|
+
var $e672e8bc247525d1$exports = {};
|
|
60
72
|
|
|
61
|
-
$parcel$export($
|
|
73
|
+
$parcel$export($e672e8bc247525d1$exports, "useDroppableCollectionState", () => $e672e8bc247525d1$export$926850f6ecef79d0);
|
|
62
74
|
|
|
63
|
-
function $
|
|
64
|
-
let [target1, setTarget] = $
|
|
75
|
+
function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
76
|
+
let [target1, setTarget] = $bBNwq$useState(null);
|
|
65
77
|
let getOppositeTarget = (target)=>{
|
|
66
78
|
if (target.dropPosition === 'before') {
|
|
67
79
|
let key = props.collection.getKeyBefore(target.key);
|
|
@@ -100,9 +112,9 @@ function $dfea42730c00d81f$export$926850f6ecef79d0(props) {
|
|
|
100
112
|
setTarget(newTarget);
|
|
101
113
|
},
|
|
102
114
|
isDropTarget (dropTarget) {
|
|
103
|
-
if ($
|
|
115
|
+
if ($e672e8bc247525d1$var$isEqualDropTarget(dropTarget, target1)) return true;
|
|
104
116
|
// Check if the targets point at the same point between two items, one referring before, and the other after.
|
|
105
|
-
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) === 'item' && (target1 === null || target1 === void 0 ? void 0 : target1.type) === 'item' && dropTarget.key !== target1.key && dropTarget.dropPosition !== target1.dropPosition && dropTarget.dropPosition !== 'on' && target1.dropPosition !== 'on') return $
|
|
117
|
+
if ((dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.type) === 'item' && (target1 === null || target1 === void 0 ? void 0 : target1.type) === 'item' && dropTarget.key !== target1.key && dropTarget.dropPosition !== target1.dropPosition && dropTarget.dropPosition !== 'on' && target1.dropPosition !== 'on') return $e672e8bc247525d1$var$isEqualDropTarget(getOppositeTarget(dropTarget), target1) || $e672e8bc247525d1$var$isEqualDropTarget(dropTarget, getOppositeTarget(target1));
|
|
106
118
|
return false;
|
|
107
119
|
},
|
|
108
120
|
getDropOperation (target, types, allowedOperations) {
|
|
@@ -110,7 +122,7 @@ function $dfea42730c00d81f$export$926850f6ecef79d0(props) {
|
|
|
110
122
|
}
|
|
111
123
|
};
|
|
112
124
|
}
|
|
113
|
-
function $
|
|
125
|
+
function $e672e8bc247525d1$var$isEqualDropTarget(a, b) {
|
|
114
126
|
if (!a) return !b;
|
|
115
127
|
switch(a.type){
|
|
116
128
|
case 'root':
|
|
@@ -123,5 +135,5 @@ function $dfea42730c00d81f$var$isEqualDropTarget(a, b) {
|
|
|
123
135
|
|
|
124
136
|
|
|
125
137
|
|
|
126
|
-
export {$
|
|
138
|
+
export {$b45bbbaf0c3785df$export$29efd034f1d79f81 as useDraggableCollectionState, $e672e8bc247525d1$export$926850f6ecef79d0 as useDroppableCollectionState};
|
|
127
139
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;SCiCgB,yCAA2B,CAAC,KAAiC,EAA4B,CAAC;IACxG,GAAG,EAAE,YAAY,EAAE,eAAe,IAAI,eAAQ,CAAC,GAAG,CAAC,GAAG;IACtD,GAAG,CAAC,OAAO,IAAI,GAAQ,GAAK,CAAC;QAC3B,EAAmF,AAAnF,iFAAmF;QACnF,EAAqF,AAArF,mFAAqF;QACrF,EAAuD,AAAvD,qDAAuD;QACvD,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAChB,KAAK,CAAC,gBAAgB,CAAC,UAAU,CAAC,GAAG,IACjC,KAAK,CAAC,gBAAgB,CAAC,YAAY,GACnC,CAAC,CAAC;QAGR,IAAI,CAAC,GAAG,CAAC,GAAG;QACZ,MAAM,CAAC,IAAI;IACb,CAAC;IAED,MAAM,CAAC,CAAC;QACN,UAA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E,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 * from './useDraggableCollectionState';\nexport * 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, DragEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragStartEvent, Node} from '@react-types/shared';\nimport {Key, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\ninterface DraggableCollectionOptions extends DraggableCollectionProps {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DraggableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n isDragging(key: Key): boolean,\n getKeysForDrag(key: Key): Set<Key>,\n getItems(key: Key): DragItem[],\n renderPreview(key: Key): JSX.Element,\n startDrag(key: Key, event: DragStartEvent): void,\n moveDrag(event: DragMoveEvent): void,\n endDrag(event: DragEndEvent): void\n}\n\nexport function useDraggableCollectionState(props: DraggableCollectionOptions): DraggableCollectionState {\n let [draggingKeys, setDraggingKeys] = useState(new Set<Key>());\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 props.selectionManager.isSelected(key)\n ? props.selectionManager.selectedKeys\n : []\n );\n\n keys.add(key);\n return keys;\n };\n\n return {\n collection: props.collection,\n selectionManager: props.selectionManager,\n isDragging(key) {\n return draggingKeys.has(key);\n },\n getKeysForDrag: getKeys,\n getItems(key) {\n return props.getItems(getKeys(key));\n },\n renderPreview(key) {\n if (typeof props.renderPreview === 'function') {\n return props.renderPreview(getKeys(key), key);\n }\n\n return null;\n },\n startDrag(key, event) {\n let keys = getKeys(key);\n setDraggingKeys(keys);\n\n if (typeof props.onDragStart === 'function') {\n props.onDragStart({\n ...event,\n keys\n });\n }\n },\n moveDrag(event) {\n if (typeof props.onDragMove === 'function') {\n props.onDragMove({\n ...event,\n keys: draggingKeys\n });\n }\n },\n endDrag(event) {\n if (typeof props.onDragEnd === 'function') {\n props.onDragEnd({\n ...event,\n keys: draggingKeys\n });\n }\n\n setDraggingKeys(new Set());\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 {MultipleSelectionManager} from '@react-stately/selection';\nimport {useState} from 'react';\n\ninterface DroppableCollectionStateOptions extends DroppableCollectionProps {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DroppableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n target: DropTarget,\n setTarget(target: DropTarget): void,\n isDropTarget(target: DropTarget): boolean,\n getDropOperation(target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]): DropOperation\n}\n\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let [target, setTarget] = useState<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\n if (target.dropPosition === 'before') {\n let key = props.collection.getKeyBefore(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'after'} : null;\n } else if (target.dropPosition === 'after') {\n let key = props.collection.getKeyAfter(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'before'} : null;\n }\n };\n\n return {\n collection: props.collection,\n selectionManager: props.selectionManager,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\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 props.onDropEnter === 'function') {\n props.onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n setTarget(newTarget);\n },\n isDropTarget(dropTarget) {\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(target, types, allowedOperations) {\n return typeof props.getDropOperation === 'function'\n ? props.getDropOperation(target, types, allowedOperations)\n : allowedOperations[0];\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.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;SCmCgB,yCAA2B,CAAC,KAAiC,EAA4B,CAAC;IACxG,GAAG,CAAC,CAAC,WACH,QAAQ,eACR,UAAU,qBACV,gBAAgB,gBAChB,WAAW,eACX,UAAU,cACV,SAAS,YACT,OAAO,EACT,CAAC,GAAG,KAAK;IACT,GAAG,IAAI,WAAW,IAAI,eAAQ,CAAC,KAAK;IACpC,GAAG,CAAC,YAAY,GAAG,aAAM,CAAC,GAAG,CAAC,GAAG;IACjC,GAAG,CAAC,UAAU,GAAG,aAAM,CAAC,IAAI;IAC5B,GAAG,CAAC,OAAO,IAAI,GAAQ,GAAK,CAAC;QAC3B,EAAmF,AAAnF,iFAAmF;QACnF,EAAqF,AAArF,mFAAqF;QACrF,EAAuD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,iBAAiB,EAAE,CAAC;YAClD,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,KAAK,CAAU,YAC/C,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,KAAK,EAAE,iBAAiB,IACvD,iBAAiB,CAAC,CAAC;QACzB,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 * from './useDraggableCollectionState';\nexport * 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, DragEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, Node} from '@react-types/shared';\nimport {Key, RefObject, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\nexport interface DraggableCollectionOptions extends DraggableCollectionProps {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DraggableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n draggedKey: Key | null,\n draggingKeys: Set<Key>,\n isDragging(key: Key): boolean,\n getKeysForDrag(key: Key): Set<Key>,\n getItems(key: Key): DragItem[],\n preview?: RefObject<DragPreviewRenderer>,\n startDrag(key: Key, event: DragStartEvent): void,\n moveDrag(event: DragMoveEvent): void,\n endDrag(event: DragEndEvent): void\n}\n\nexport function useDraggableCollectionState(props: DraggableCollectionOptions): DraggableCollectionState {\n let {\n getItems,\n collection,\n selectionManager,\n onDragStart,\n onDragMove,\n onDragEnd,\n preview\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])\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 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 if (typeof onDragEnd === 'function') {\n onDragEnd({\n ...event,\n keys: draggingKeys.current\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 {MultipleSelectionManager} from '@react-stately/selection';\nimport {useState} from 'react';\n\nexport interface DroppableCollectionStateOptions extends DroppableCollectionProps {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DroppableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n target: DropTarget,\n setTarget(target: DropTarget): void,\n isDropTarget(target: DropTarget): boolean,\n getDropOperation(target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]): DropOperation\n}\n\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let [target, setTarget] = useState<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\n if (target.dropPosition === 'before') {\n let key = props.collection.getKeyBefore(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'after'} : null;\n } else if (target.dropPosition === 'after') {\n let key = props.collection.getKeyAfter(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'before'} : null;\n }\n };\n\n return {\n collection: props.collection,\n selectionManager: props.selectionManager,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\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 props.onDropEnter === 'function') {\n props.onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n setTarget(newTarget);\n },\n isDropTarget(dropTarget) {\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(target, types, allowedOperations) {\n return typeof props.getDropOperation === 'function'\n ? props.getDropOperation(target, types, allowedOperations)\n : allowedOperations[0];\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.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { Collection, DragEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragStartEvent, Node, DragTypes, DropOperation, DroppableCollectionProps, DropTarget } from "@react-types/shared";
|
|
2
|
-
import { Key } from "react";
|
|
1
|
+
import { Collection, DragEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, Node, DragTypes, DropOperation, DroppableCollectionProps, DropTarget } from "@react-types/shared";
|
|
2
|
+
import { Key, RefObject } from "react";
|
|
3
3
|
import { MultipleSelectionManager } from "@react-stately/selection";
|
|
4
|
-
interface DraggableCollectionOptions extends DraggableCollectionProps {
|
|
4
|
+
export interface DraggableCollectionOptions extends DraggableCollectionProps {
|
|
5
5
|
collection: Collection<Node<unknown>>;
|
|
6
6
|
selectionManager: MultipleSelectionManager;
|
|
7
7
|
}
|
|
8
8
|
export interface DraggableCollectionState {
|
|
9
9
|
collection: Collection<Node<unknown>>;
|
|
10
10
|
selectionManager: MultipleSelectionManager;
|
|
11
|
+
draggedKey: Key | null;
|
|
12
|
+
draggingKeys: Set<Key>;
|
|
11
13
|
isDragging(key: Key): boolean;
|
|
12
14
|
getKeysForDrag(key: Key): Set<Key>;
|
|
13
15
|
getItems(key: Key): DragItem[];
|
|
14
|
-
|
|
16
|
+
preview?: RefObject<DragPreviewRenderer>;
|
|
15
17
|
startDrag(key: Key, event: DragStartEvent): void;
|
|
16
18
|
moveDrag(event: DragMoveEvent): void;
|
|
17
19
|
endDrag(event: DragEndEvent): void;
|
|
18
20
|
}
|
|
19
21
|
export function useDraggableCollectionState(props: DraggableCollectionOptions): DraggableCollectionState;
|
|
20
|
-
interface DroppableCollectionStateOptions extends DroppableCollectionProps {
|
|
22
|
+
export interface DroppableCollectionStateOptions extends DroppableCollectionProps {
|
|
21
23
|
collection: Collection<Node<unknown>>;
|
|
22
24
|
selectionManager: MultipleSelectionManager;
|
|
23
25
|
}
|
package/dist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,UAAU,GAAG,OAAO,CAAC;IAC1C,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,aAAa,EAAE,GAAG,aAAa,CAAA;CAC1G;AAED,4CAA4C,KAAK,EAAE,+BAA+B,GAAG,wBAAwB,CAoE5G","sources":["packages/@react-stately/dnd/src/packages/@react-stately/dnd/src/useDraggableCollectionState.ts","packages/@react-stately/dnd/src/packages/@react-stately/dnd/src/useDroppableCollectionState.ts","packages/@react-stately/dnd/src/packages/@react-stately/dnd/src/index.ts","packages/@react-stately/dnd/src/index.ts"],"sourcesContent":[null,null,null,"/*\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 * from './useDraggableCollectionState';\nexport * from './useDroppableCollectionState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/dnd",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.7",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@babel/runtime": "^7.6.2",
|
|
21
|
-
"@react-stately/selection": "^3.
|
|
22
|
-
"@react-stately/utils": "^3.
|
|
23
|
-
"@react-types/shared": "^3.
|
|
21
|
+
"@react-stately/selection": "^3.10.0",
|
|
22
|
+
"@react-stately/utils": "^3.5.0",
|
|
23
|
+
"@react-types/shared": "^3.13.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"react": "^16.8.0 || ^17.0.0-rc.1"
|
|
26
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "8f921ec5094e7c2b3c301bcb6133372e35a2052b"
|
|
32
32
|
}
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {Collection, DragEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragStartEvent, Node} from '@react-types/shared';
|
|
14
|
-
import {Key, useState} from 'react';
|
|
13
|
+
import {Collection, DragEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, Node} from '@react-types/shared';
|
|
14
|
+
import {Key, RefObject, useRef, useState} from 'react';
|
|
15
15
|
import {MultipleSelectionManager} from '@react-stately/selection';
|
|
16
16
|
|
|
17
|
-
interface DraggableCollectionOptions extends DraggableCollectionProps {
|
|
17
|
+
export interface DraggableCollectionOptions extends DraggableCollectionProps {
|
|
18
18
|
collection: Collection<Node<unknown>>,
|
|
19
19
|
selectionManager: MultipleSelectionManager
|
|
20
20
|
}
|
|
@@ -22,24 +22,37 @@ interface DraggableCollectionOptions extends DraggableCollectionProps {
|
|
|
22
22
|
export interface DraggableCollectionState {
|
|
23
23
|
collection: Collection<Node<unknown>>,
|
|
24
24
|
selectionManager: MultipleSelectionManager,
|
|
25
|
+
draggedKey: Key | null,
|
|
26
|
+
draggingKeys: Set<Key>,
|
|
25
27
|
isDragging(key: Key): boolean,
|
|
26
28
|
getKeysForDrag(key: Key): Set<Key>,
|
|
27
29
|
getItems(key: Key): DragItem[],
|
|
28
|
-
|
|
30
|
+
preview?: RefObject<DragPreviewRenderer>,
|
|
29
31
|
startDrag(key: Key, event: DragStartEvent): void,
|
|
30
32
|
moveDrag(event: DragMoveEvent): void,
|
|
31
33
|
endDrag(event: DragEndEvent): void
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export function useDraggableCollectionState(props: DraggableCollectionOptions): DraggableCollectionState {
|
|
35
|
-
let
|
|
37
|
+
let {
|
|
38
|
+
getItems,
|
|
39
|
+
collection,
|
|
40
|
+
selectionManager,
|
|
41
|
+
onDragStart,
|
|
42
|
+
onDragMove,
|
|
43
|
+
onDragEnd,
|
|
44
|
+
preview
|
|
45
|
+
} = props;
|
|
46
|
+
let [, setDragging] = useState(false);
|
|
47
|
+
let draggingKeys = useRef(new Set<Key>());
|
|
48
|
+
let draggedKey = useRef(null);
|
|
36
49
|
let getKeys = (key: Key) => {
|
|
37
50
|
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
38
51
|
// other selected items are also dragged. If it is not selected, the only the clicked
|
|
39
52
|
// item is dragged. This matches native macOS behavior.
|
|
40
53
|
let keys = new Set(
|
|
41
|
-
|
|
42
|
-
?
|
|
54
|
+
selectionManager.isSelected(key)
|
|
55
|
+
? new Set([...selectionManager.selectedKeys])
|
|
43
56
|
: []
|
|
44
57
|
);
|
|
45
58
|
|
|
@@ -48,50 +61,53 @@ export function useDraggableCollectionState(props: DraggableCollectionOptions):
|
|
|
48
61
|
};
|
|
49
62
|
|
|
50
63
|
return {
|
|
51
|
-
collection
|
|
52
|
-
selectionManager
|
|
64
|
+
collection,
|
|
65
|
+
selectionManager,
|
|
66
|
+
get draggedKey() {
|
|
67
|
+
return draggedKey.current;
|
|
68
|
+
},
|
|
69
|
+
get draggingKeys() {
|
|
70
|
+
return draggingKeys.current;
|
|
71
|
+
},
|
|
53
72
|
isDragging(key) {
|
|
54
|
-
return draggingKeys.has(key);
|
|
73
|
+
return draggingKeys.current.has(key);
|
|
55
74
|
},
|
|
56
75
|
getKeysForDrag: getKeys,
|
|
57
76
|
getItems(key) {
|
|
58
|
-
return
|
|
59
|
-
},
|
|
60
|
-
renderPreview(key) {
|
|
61
|
-
if (typeof props.renderPreview === 'function') {
|
|
62
|
-
return props.renderPreview(getKeys(key), key);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return null;
|
|
77
|
+
return getItems(getKeys(key));
|
|
66
78
|
},
|
|
79
|
+
preview,
|
|
67
80
|
startDrag(key, event) {
|
|
81
|
+
setDragging(true);
|
|
68
82
|
let keys = getKeys(key);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (typeof
|
|
72
|
-
|
|
83
|
+
draggingKeys.current = keys;
|
|
84
|
+
draggedKey.current = key;
|
|
85
|
+
if (typeof onDragStart === 'function') {
|
|
86
|
+
onDragStart({
|
|
73
87
|
...event,
|
|
74
88
|
keys
|
|
75
89
|
});
|
|
76
90
|
}
|
|
77
91
|
},
|
|
78
92
|
moveDrag(event) {
|
|
79
|
-
if (typeof
|
|
80
|
-
|
|
93
|
+
if (typeof onDragMove === 'function') {
|
|
94
|
+
onDragMove({
|
|
81
95
|
...event,
|
|
82
|
-
keys: draggingKeys
|
|
96
|
+
keys: draggingKeys.current
|
|
83
97
|
});
|
|
84
98
|
}
|
|
85
99
|
},
|
|
86
100
|
endDrag(event) {
|
|
87
|
-
if (typeof
|
|
88
|
-
|
|
101
|
+
if (typeof onDragEnd === 'function') {
|
|
102
|
+
onDragEnd({
|
|
89
103
|
...event,
|
|
90
|
-
keys: draggingKeys
|
|
104
|
+
keys: draggingKeys.current
|
|
91
105
|
});
|
|
92
106
|
}
|
|
93
107
|
|
|
94
|
-
|
|
108
|
+
setDragging(false);
|
|
109
|
+
draggingKeys.current = new Set();
|
|
110
|
+
draggedKey.current = null;
|
|
95
111
|
}
|
|
96
112
|
};
|
|
97
113
|
}
|
|
@@ -14,7 +14,7 @@ import {Collection, DragTypes, DropOperation, DroppableCollectionProps, DropTarg
|
|
|
14
14
|
import {MultipleSelectionManager} from '@react-stately/selection';
|
|
15
15
|
import {useState} from 'react';
|
|
16
16
|
|
|
17
|
-
interface DroppableCollectionStateOptions extends DroppableCollectionProps {
|
|
17
|
+
export interface DroppableCollectionStateOptions extends DroppableCollectionProps {
|
|
18
18
|
collection: Collection<Node<unknown>>,
|
|
19
19
|
selectionManager: MultipleSelectionManager
|
|
20
20
|
}
|