@react-stately/dnd 3.0.0-alpha.1 → 3.0.0-alpha.10
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 +123 -154
- package/dist/main.js.map +1 -1
- package/dist/module.js +122 -145
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +8 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +4 -2
- package/src/useDraggableCollectionState.ts +48 -29
- package/src/useDroppableCollectionState.ts +1 -1
package/dist/main.js
CHANGED
|
@@ -1,168 +1,137 @@
|
|
|
1
|
-
var
|
|
2
|
-
useState
|
|
3
|
-
} = require("react");
|
|
1
|
+
var $1IdlX$react = require("react");
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function $parcel$interopDefault(a) {
|
|
8
|
-
return a && a.__esModule ? a.default : a;
|
|
3
|
+
function $parcel$export(e, n, v, s) {
|
|
4
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
5
|
}
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
};
|
|
7
|
+
$parcel$export(module.exports, "useDraggableCollectionState", () => $481a240e3d51b276$export$29efd034f1d79f81);
|
|
8
|
+
$parcel$export(module.exports, "useDroppableCollectionState", () => $6ce4cbfbe5e354f1$export$926850f6ecef79d0);
|
|
9
|
+
|
|
10
|
+
function $481a240e3d51b276$export$29efd034f1d79f81(props) {
|
|
11
|
+
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 = (key1)=>{
|
|
16
|
+
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
17
|
+
// other selected items are also dragged. If it is not selected, the only the clicked
|
|
18
|
+
// item is dragged. This matches native macOS behavior.
|
|
19
|
+
let keys = new Set(selectionManager.isSelected(key1) ? new Set([
|
|
20
|
+
...selectionManager.selectedKeys
|
|
21
|
+
].filter((key)=>!!collection.getItem(key)
|
|
22
|
+
)) : []);
|
|
23
|
+
keys.add(key1);
|
|
24
|
+
return keys;
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
collection: collection,
|
|
28
|
+
selectionManager: selectionManager,
|
|
29
|
+
get draggedKey () {
|
|
30
|
+
return draggedKey.current;
|
|
31
|
+
},
|
|
32
|
+
get draggingKeys () {
|
|
33
|
+
return draggingKeys.current;
|
|
34
|
+
},
|
|
35
|
+
isDragging (key) {
|
|
36
|
+
return draggingKeys.current.has(key);
|
|
37
|
+
},
|
|
38
|
+
getKeysForDrag: getKeys,
|
|
39
|
+
getItems (key) {
|
|
40
|
+
return getItems(getKeys(key));
|
|
41
|
+
},
|
|
42
|
+
preview: preview,
|
|
43
|
+
getAllowedDropOperations: getAllowedDropOperations,
|
|
44
|
+
startDrag (key, event) {
|
|
45
|
+
setDragging(true);
|
|
46
|
+
let keys = getKeys(key);
|
|
47
|
+
draggingKeys.current = keys;
|
|
48
|
+
draggedKey.current = key;
|
|
49
|
+
if (typeof onDragStart === 'function') onDragStart({
|
|
50
|
+
...event,
|
|
51
|
+
keys: keys
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
moveDrag (event) {
|
|
55
|
+
if (typeof onDragMove === 'function') onDragMove({
|
|
56
|
+
...event,
|
|
57
|
+
keys: draggingKeys.current
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
endDrag (event) {
|
|
61
|
+
if (typeof onDragEnd === 'function') onDragEnd({
|
|
62
|
+
...event,
|
|
63
|
+
keys: draggingKeys.current
|
|
64
|
+
});
|
|
65
|
+
setDragging(false);
|
|
66
|
+
draggingKeys.current = new Set();
|
|
67
|
+
draggedKey.current = null;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
75
70
|
}
|
|
76
71
|
|
|
77
|
-
exports.useDraggableCollectionState = useDraggableCollectionState;
|
|
78
72
|
|
|
79
|
-
function useDroppableCollectionState(props) {
|
|
80
|
-
let [target, setTarget] = useState(null);
|
|
81
73
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if ((dropTarget == null ? void 0 : dropTarget.type) === 'item' && (target == null ? void 0 : target.type) === 'item' && dropTarget.key !== target.key && dropTarget.dropPosition !== target.dropPosition && dropTarget.dropPosition !== 'on' && target.dropPosition !== 'on') {
|
|
140
|
-
return $e9dc567085e93bc34b98b82b1b477$var$isEqualDropTarget(getOppositeTarget(dropTarget), target) || $e9dc567085e93bc34b98b82b1b477$var$isEqualDropTarget(dropTarget, getOppositeTarget(target));
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return false;
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
getDropOperation(target, types, allowedOperations) {
|
|
147
|
-
return typeof props.getDropOperation === 'function' ? props.getDropOperation(target, types, allowedOperations) : allowedOperations[0];
|
|
74
|
+
function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) {
|
|
75
|
+
let [target1, setTarget] = $1IdlX$react.useState(null);
|
|
76
|
+
let getOppositeTarget = (target)=>{
|
|
77
|
+
if (target.dropPosition === 'before') {
|
|
78
|
+
let key = props.collection.getKeyBefore(target.key);
|
|
79
|
+
return key != null ? {
|
|
80
|
+
type: 'item',
|
|
81
|
+
key: key,
|
|
82
|
+
dropPosition: 'after'
|
|
83
|
+
} : null;
|
|
84
|
+
} else if (target.dropPosition === 'after') {
|
|
85
|
+
let key = props.collection.getKeyAfter(target.key);
|
|
86
|
+
return key != null ? {
|
|
87
|
+
type: 'item',
|
|
88
|
+
key: key,
|
|
89
|
+
dropPosition: 'before'
|
|
90
|
+
} : null;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
collection: props.collection,
|
|
95
|
+
selectionManager: props.selectionManager,
|
|
96
|
+
target: target1,
|
|
97
|
+
setTarget (newTarget) {
|
|
98
|
+
if (this.isDropTarget(newTarget)) return;
|
|
99
|
+
if (target1 && typeof props.onDropExit === 'function') props.onDropExit({
|
|
100
|
+
type: 'dropexit',
|
|
101
|
+
x: 0,
|
|
102
|
+
y: 0,
|
|
103
|
+
target: target1
|
|
104
|
+
});
|
|
105
|
+
if (newTarget && typeof props.onDropEnter === 'function') props.onDropEnter({
|
|
106
|
+
type: 'dropenter',
|
|
107
|
+
x: 0,
|
|
108
|
+
y: 0,
|
|
109
|
+
target: newTarget
|
|
110
|
+
});
|
|
111
|
+
setTarget(newTarget);
|
|
112
|
+
},
|
|
113
|
+
isDropTarget (dropTarget) {
|
|
114
|
+
if ($6ce4cbfbe5e354f1$var$isEqualDropTarget(dropTarget, target1)) return true;
|
|
115
|
+
// Check if the targets point at the same point between two items, one referring before, and the other after.
|
|
116
|
+
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));
|
|
117
|
+
return false;
|
|
118
|
+
},
|
|
119
|
+
getDropOperation (target, types, allowedOperations) {
|
|
120
|
+
return typeof props.getDropOperation === 'function' ? props.getDropOperation(target, types, allowedOperations) : allowedOperations[0];
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function $6ce4cbfbe5e354f1$var$isEqualDropTarget(a, b) {
|
|
125
|
+
if (!a) return !b;
|
|
126
|
+
switch(a.type){
|
|
127
|
+
case 'root':
|
|
128
|
+
return (b === null || b === void 0 ? void 0 : b.type) === 'root';
|
|
129
|
+
case 'item':
|
|
130
|
+
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;
|
|
148
131
|
}
|
|
149
|
-
|
|
150
|
-
};
|
|
151
132
|
}
|
|
152
133
|
|
|
153
|
-
exports.useDroppableCollectionState = useDroppableCollectionState;
|
|
154
134
|
|
|
155
|
-
function $e9dc567085e93bc34b98b82b1b477$var$isEqualDropTarget(a, b) {
|
|
156
|
-
if (!a) {
|
|
157
|
-
return !b;
|
|
158
|
-
}
|
|
159
135
|
|
|
160
|
-
switch (a.type) {
|
|
161
|
-
case 'root':
|
|
162
|
-
return (b == null ? void 0 : b.type) === 'root';
|
|
163
136
|
|
|
164
|
-
case 'item':
|
|
165
|
-
return (b == null ? void 0 : b.type) === 'item' && (b == null ? void 0 : b.key) === a.key && (b == null ? void 0 : b.dropPosition) === a.dropPosition;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
137
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;AAAA,SAASA,sBAAT,CAAgCC,CAAhC,EAAmC;AACjC,SAAOA,CAAC,IAAIA,CAAC,CAACC,UAAP,GAAoBD,CAAC,CAACE,OAAtB,GAAgCF,CAAvC;AACD;;AC+BM,SAASG,2BAAT,CAAqCC,KAArC,EAAkG;AACvG,MAAI,CAACC,YAAD,EAAeC,eAAf,IAAkCC,QAAQ,CAAC,IAAIC,GAAJ,EAAD,CAA9C;;AACA,MAAIC,OAAO,GAAIC,GAAD,IAAc;AAC1B;AACA;AACA;A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CAAlB,EAAgCb,MAAhC,CAAjB,IACLc,oDAAiB,CAACD,UAAD,EAAaX,iBAAiB,CAACF,MAAD,CAA9B,CADnB;AAED;;AAED,aAAO,KAAP;AACD,KAhDI;;AAiDLe,IAAAA,gBAAgB,CAACf,MAAD,EAASgB,KAAT,EAAgBC,iBAAhB,EAAmC;AACjD,aAAO,OAAO3C,KAAK,CAACyC,gBAAb,KAAkC,UAAlC,GACHzC,KAAK,CAACyC,gBAAN,CAAuBf,MAAvB,EAA+BgB,KAA/B,EAAsCC,iBAAtC,CADG,GAEHA,iBAAiB,CAAC,CAAD,CAFrB;AAGD;;AArDI,GAAP;AAuDD;;;;AAED,SAASH,oDAAT,CAA2B5C,CAA3B,EAA0CgD,CAA1C,EAAyD;AACvD,MAAI,CAAChD,CAAL,EAAQ;AACN,WAAO,CAACgD,CAAR;AACD;;AAED,UAAQhD,CAAC,CAACmC,IAAV;AACE,SAAK,MAAL;AACE,aAAO,CAAAa,CAAC,QAAD,YAAAA,CAAC,CAAEb,IAAH,MAAY,MAAnB;;AACF,SAAK,MAAL;AACE,aAAO,CAAAa,CAAC,QAAD,YAAAA,CAAC,CAAEb,IAAH,MAAY,MAAZ,IAAsB,CAAAa,CAAC,QAAD,YAAAA,CAAC,CAAEtC,GAAH,MAAWV,CAAC,CAACU,GAAnC,IAA0C,CAAAsC,CAAC,QAAD,YAAAA,CAAC,CAAEf,YAAH,MAAoBjC,CAAC,CAACiC,YAAvE;AAJJ;AAMD","sources":["./node_modules/@parcel/scope-hoisting/lib/helpers.js","./packages/@react-stately/dnd/src/useDraggableCollectionState.ts","./packages/@react-stately/dnd/src/useDroppableCollectionState.ts"],"sourcesContent":["function $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\nfunction $parcel$defineInteropFlag(a) {\n Object.defineProperty(a, '__esModule', {value: true});\n}\n\nfunction $parcel$exportWildcard(dest, source) {\n Object.keys(source).forEach(function(key) {\n if (key === 'default' || key === '__esModule') {\n return;\n }\n\n Object.defineProperty(dest, key, {\n enumerable: true,\n get: function get() {\n return source[key];\n },\n });\n });\n\n return dest;\n}\n\nfunction $parcel$missingModule(name) {\n var err = new Error(\"Cannot find module '\" + name + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n}\n\nvar $parcel$global =\n typeof globalThis !== 'undefined'\n ? globalThis\n : typeof self !== 'undefined'\n ? self\n : typeof window !== 'undefined'\n ? window\n : typeof global !== 'undefined'\n ? global\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, 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":["$parcel$interopDefault","a","__esModule","default","useDraggableCollectionState","props","draggingKeys","setDraggingKeys","useState","Set","getKeys","key","keys","selectionManager","isSelected","selectedKeys","add","collection","isDragging","has","getKeysForDrag","getItems","renderPreview","startDrag","event","onDragStart","moveDrag","onDragMove","endDrag","onDragEnd","useDroppableCollectionState","target","setTarget","getOppositeTarget","dropPosition","getKeyBefore","type","getKeyAfter","newTarget","isDropTarget","onDropExit","x","y","onDropEnter","dropTarget","isEqualDropTarget","getDropOperation","types","allowedOperations","b"],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;SCoCgB,yCAA2B,CAAC,KAAiC,EAA4B,CAAC;IACxG,GAAG,CAAC,CAAC,WACH,QAAQ,eACR,UAAU,qBACV,gBAAgB,gBAChB,WAAW,eACX,UAAU,cACV,SAAS,YACT,OAAO,6BACP,wBAAwB,EAC1B,CAAC,GAAG,KAAK;IACT,GAAG,IAAI,WAAW,IAAI,qBAAQ,CAAC,KAAK;IACpC,GAAG,CAAC,YAAY,GAAG,mBAAM,CAAC,GAAG,CAAC,GAAG;IACjC,GAAG,CAAC,UAAU,GAAG,mBAAM,CAAC,IAAI;IAC5B,GAAG,CAAC,OAAO,IAAI,IAAQ,GAAK,CAAC;QAC3B,EAAmF,AAAnF,iFAAmF;QACnF,EAAqF,AAArF,mFAAqF;QACrF,EAAuD,AAAvD,qDAAuD;QACvD,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAChB,gBAAgB,CAAC,UAAU,CAAC,IAAG,IAC3B,GAAG,CAAC,GAAG,CAAC,CAAC;eAAG,gBAAgB,CAAC,YAAY;QAAA,CAAC,CAAC,MAAM,EAAC,GAAG,KAAM,UAAU,CAAC,OAAO,CAAC,GAAG;aACjF,CAAC,CAAC;QAGR,IAAI,CAAC,GAAG,CAAC,IAAG;QACZ,MAAM,CAAC,IAAI;IACb,CAAC;IAED,MAAM,CAAC,CAAC;oBACN,UAAU;0BACV,gBAAgB;YACZ,UAAU,IAAG,CAAC;YAChB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,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 {DraggableCollectionOptions, 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, DragEndEvent, 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 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 getAllowedDropOperations?: () => DropOperation[],\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 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 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,155 +1,132 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
};
|
|
1
|
+
import {useState as $bBNwq$useState, useRef as $bBNwq$useRef} from "react";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function $b45bbbaf0c3785df$export$29efd034f1d79f81(props) {
|
|
5
|
+
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 = (key1)=>{
|
|
10
|
+
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
11
|
+
// other selected items are also dragged. If it is not selected, the only the clicked
|
|
12
|
+
// item is dragged. This matches native macOS behavior.
|
|
13
|
+
let keys = new Set(selectionManager.isSelected(key1) ? new Set([
|
|
14
|
+
...selectionManager.selectedKeys
|
|
15
|
+
].filter((key)=>!!collection.getItem(key)
|
|
16
|
+
)) : []);
|
|
17
|
+
keys.add(key1);
|
|
18
|
+
return keys;
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
collection: collection,
|
|
22
|
+
selectionManager: selectionManager,
|
|
23
|
+
get draggedKey () {
|
|
24
|
+
return draggedKey.current;
|
|
25
|
+
},
|
|
26
|
+
get draggingKeys () {
|
|
27
|
+
return draggingKeys.current;
|
|
28
|
+
},
|
|
29
|
+
isDragging (key) {
|
|
30
|
+
return draggingKeys.current.has(key);
|
|
31
|
+
},
|
|
32
|
+
getKeysForDrag: getKeys,
|
|
33
|
+
getItems (key) {
|
|
34
|
+
return getItems(getKeys(key));
|
|
35
|
+
},
|
|
36
|
+
preview: preview,
|
|
37
|
+
getAllowedDropOperations: getAllowedDropOperations,
|
|
38
|
+
startDrag (key, event) {
|
|
39
|
+
setDragging(true);
|
|
40
|
+
let keys = getKeys(key);
|
|
41
|
+
draggingKeys.current = keys;
|
|
42
|
+
draggedKey.current = key;
|
|
43
|
+
if (typeof onDragStart === 'function') onDragStart({
|
|
44
|
+
...event,
|
|
45
|
+
keys: keys
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
moveDrag (event) {
|
|
49
|
+
if (typeof onDragMove === 'function') onDragMove({
|
|
50
|
+
...event,
|
|
51
|
+
keys: draggingKeys.current
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
endDrag (event) {
|
|
55
|
+
if (typeof onDragEnd === 'function') onDragEnd({
|
|
56
|
+
...event,
|
|
57
|
+
keys: draggingKeys.current
|
|
58
|
+
});
|
|
59
|
+
setDragging(false);
|
|
60
|
+
draggingKeys.current = new Set();
|
|
61
|
+
draggedKey.current = null;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
67
64
|
}
|
|
68
|
-
export function useDroppableCollectionState(props) {
|
|
69
|
-
let [target, setTarget] = useState(null);
|
|
70
65
|
|
|
71
|
-
let getOppositeTarget = target => {
|
|
72
|
-
if (target.dropPosition === 'before') {
|
|
73
|
-
let key = props.collection.getKeyBefore(target.key);
|
|
74
|
-
return key != null ? {
|
|
75
|
-
type: 'item',
|
|
76
|
-
key,
|
|
77
|
-
dropPosition: 'after'
|
|
78
|
-
} : null;
|
|
79
|
-
} else if (target.dropPosition === 'after') {
|
|
80
|
-
let key = props.collection.getKeyAfter(target.key);
|
|
81
|
-
return key != null ? {
|
|
82
|
-
type: 'item',
|
|
83
|
-
key,
|
|
84
|
-
dropPosition: 'before'
|
|
85
|
-
} : null;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
return {
|
|
90
|
-
collection: props.collection,
|
|
91
|
-
selectionManager: props.selectionManager,
|
|
92
|
-
target,
|
|
93
|
-
|
|
94
|
-
setTarget(newTarget) {
|
|
95
|
-
if (this.isDropTarget(newTarget)) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (target && typeof props.onDropExit === 'function') {
|
|
100
|
-
props.onDropExit({
|
|
101
|
-
type: 'dropexit',
|
|
102
|
-
x: 0,
|
|
103
|
-
// todo
|
|
104
|
-
y: 0,
|
|
105
|
-
target
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (newTarget && typeof props.onDropEnter === 'function') {
|
|
110
|
-
props.onDropEnter({
|
|
111
|
-
type: 'dropenter',
|
|
112
|
-
x: 0,
|
|
113
|
-
// todo
|
|
114
|
-
y: 0,
|
|
115
|
-
target: newTarget
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
setTarget(newTarget);
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
isDropTarget(dropTarget) {
|
|
123
|
-
if ($dd31abc8396c596698a2b05e189ba$var$isEqualDropTarget(dropTarget, target)) {
|
|
124
|
-
return true;
|
|
125
|
-
} // Check if the targets point at the same point between two items, one referring before, and the other after.
|
|
126
66
|
|
|
127
67
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
68
|
+
function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
69
|
+
let [target1, setTarget] = $bBNwq$useState(null);
|
|
70
|
+
let getOppositeTarget = (target)=>{
|
|
71
|
+
if (target.dropPosition === 'before') {
|
|
72
|
+
let key = props.collection.getKeyBefore(target.key);
|
|
73
|
+
return key != null ? {
|
|
74
|
+
type: 'item',
|
|
75
|
+
key: key,
|
|
76
|
+
dropPosition: 'after'
|
|
77
|
+
} : null;
|
|
78
|
+
} else if (target.dropPosition === 'after') {
|
|
79
|
+
let key = props.collection.getKeyAfter(target.key);
|
|
80
|
+
return key != null ? {
|
|
81
|
+
type: 'item',
|
|
82
|
+
key: key,
|
|
83
|
+
dropPosition: 'before'
|
|
84
|
+
} : null;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
return {
|
|
88
|
+
collection: props.collection,
|
|
89
|
+
selectionManager: props.selectionManager,
|
|
90
|
+
target: target1,
|
|
91
|
+
setTarget (newTarget) {
|
|
92
|
+
if (this.isDropTarget(newTarget)) return;
|
|
93
|
+
if (target1 && typeof props.onDropExit === 'function') props.onDropExit({
|
|
94
|
+
type: 'dropexit',
|
|
95
|
+
x: 0,
|
|
96
|
+
y: 0,
|
|
97
|
+
target: target1
|
|
98
|
+
});
|
|
99
|
+
if (newTarget && typeof props.onDropEnter === 'function') props.onDropEnter({
|
|
100
|
+
type: 'dropenter',
|
|
101
|
+
x: 0,
|
|
102
|
+
y: 0,
|
|
103
|
+
target: newTarget
|
|
104
|
+
});
|
|
105
|
+
setTarget(newTarget);
|
|
106
|
+
},
|
|
107
|
+
isDropTarget (dropTarget) {
|
|
108
|
+
if ($e672e8bc247525d1$var$isEqualDropTarget(dropTarget, target1)) return true;
|
|
109
|
+
// Check if the targets point at the same point between two items, one referring before, and the other after.
|
|
110
|
+
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));
|
|
111
|
+
return false;
|
|
112
|
+
},
|
|
113
|
+
getDropOperation (target, types, allowedOperations) {
|
|
114
|
+
return typeof props.getDropOperation === 'function' ? props.getDropOperation(target, types, allowedOperations) : allowedOperations[0];
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function $e672e8bc247525d1$var$isEqualDropTarget(a, b) {
|
|
119
|
+
if (!a) return !b;
|
|
120
|
+
switch(a.type){
|
|
121
|
+
case 'root':
|
|
122
|
+
return (b === null || b === void 0 ? void 0 : b.type) === 'root';
|
|
123
|
+
case 'item':
|
|
124
|
+
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;
|
|
137
125
|
}
|
|
138
|
-
|
|
139
|
-
};
|
|
140
126
|
}
|
|
141
127
|
|
|
142
|
-
function $dd31abc8396c596698a2b05e189ba$var$isEqualDropTarget(a, b) {
|
|
143
|
-
if (!a) {
|
|
144
|
-
return !b;
|
|
145
|
-
}
|
|
146
128
|
|
|
147
|
-
switch (a.type) {
|
|
148
|
-
case 'root':
|
|
149
|
-
return (b == null ? void 0 : b.type) === 'root';
|
|
150
129
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
}
|
|
130
|
+
|
|
131
|
+
export {$b45bbbaf0c3785df$export$29efd034f1d79f81 as useDraggableCollectionState, $e672e8bc247525d1$export$926850f6ecef79d0 as useDroppableCollectionState};
|
|
155
132
|
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;OAiCO,SAASA,2BAAT,CAAqCC,KAArC,EAAkG;AACvG,MAAI,CAACC,YAAD,EAAeC,eAAf,IAAkCC,QAAQ,CAAC,IAAIC,GAAJ,EAAD,CAA9C;;AACA,MAAIC,OAAO,GAAIC,GAAD,IAAc;AAC1B;AACA;AACA;AACA,QAAIC,IAAI,GAAG,IAAIH,GAAJ,CACTJ,KAAK,CAACQ,gBAAN,CAAuBC,UAAvB,CAAkCH,GAAlC,IACIN,KAAK,CAACQ,gBAAN,CAAuBE,YAD3B,GAEI,EAHK,CAAX;AAMAH,IAAAA,IAAI,CAACI,GAAL,CAASL,GAAT;AACA,WAAOC,IAAP;AACD,GAZD;;AAcA,SAAO;AACLK,IAAAA,UAAU,EAAEZ,KAAK,CAACY,UADb;AAELJ,IAAAA,gBAAgB,EAAER,KAAK,CAACQ,gBAFnB;;AAGLK,IAAAA,UAAU,CAACP,GAAD,EAAM;AACd,aAAOL,YAAY,CAACa,GAAb,CAAiBR,GAAjB,CAAP;AACD,KALI;;AAMLS,IAAAA,cAAc,EAAEV,OANX;;AAOLW,IAAAA,QAAQ,CAACV,GAAD,EAAM;AACZ,aAAON,KAAK,CAACgB,QAAN,CAAeX,OAAO,CAACC,GAAD,CAAtB,CAAP;AACD,KATI;;AAULW,IAAAA,aAAa,CAACX,GAAD,EAAM;AACjB,UAAI,OAAON,KAAK,CAACiB,aAAb,KAA+B,UAAnC,EAA+C;AAC7C,eAAOjB,KAAK,CAACiB,aAAN,CAAoBZ,OAAO,CAACC,GAAD,CAA3B,EAAkCA,GAAlC,CAAP;AACD;;AAED,aAAO,IAAP;AACD,KAhBI;;AAiBLY,IAAAA,SAAS,CAACZ,GAAD,EAAMa,KAAN,EAAa;AACp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,CAACf,YAAvE;AAJJ;AAMD","sources":["./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\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":["useDraggableCollectionState","props","draggingKeys","setDraggingKeys","useState","Set","getKeys","key","keys","selectionManager","isSelected","selectedKeys","add","collection","isDragging","has","getKeysForDrag","getItems","renderPreview","startDrag","event","onDragStart","moveDrag","onDragMove","endDrag","onDragEnd","useDroppableCollectionState","target","setTarget","getOppositeTarget","dropPosition","getKeyBefore","type","getKeyAfter","newTarget","isDropTarget","onDropExit","x","y","onDropEnter","dropTarget","isEqualDropTarget","getDropOperation","types","allowedOperations","a","b"],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;SCoCgB,yCAA2B,CAAC,KAAiC,EAA4B,CAAC;IACxG,GAAG,CAAC,CAAC,WACH,QAAQ,eACR,UAAU,qBACV,gBAAgB,gBAChB,WAAW,eACX,UAAU,cACV,SAAS,YACT,OAAO,6BACP,wBAAwB,EAC1B,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,IAAQ,GAAK,CAAC;QAC3B,EAAmF,AAAnF,iFAAmF;QACnF,EAAqF,AAArF,mFAAqF;QACrF,EAAuD,AAAvD,qDAAuD;QACvD,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAChB,gBAAgB,CAAC,UAAU,CAAC,IAAG,IAC3B,GAAG,CAAC,GAAG,CAAC,CAAC;eAAG,gBAAgB,CAAC,YAAY;QAAA,CAAC,CAAC,MAAM,EAAC,GAAG,KAAM,UAAU,CAAC,OAAO,CAAC,GAAG;aACjF,CAAC,CAAC;QAGR,IAAI,CAAC,GAAG,CAAC,IAAG;QACZ,MAAM,CAAC,IAAI;IACb,CAAC;IAED,MAAM,CAAC,CAAC;oBACN,UAAU;0BACV,gBAAgB;YACZ,UAAU,IAAG,CAAC;YAChB,MAAM,CAAC,UAAU,CAAC,OAAO;QAC3B,CAAC;YACG,YAAY,IAAG,CAAC;YAClB,MAAM,CAAC,YAAY,CAAC,OAAO;QAC7B,CAAC;QACD,UAAU,EAAC,GAAG,EAAE,CAAC;YACf,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG;Q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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 {DraggableCollectionOptions, 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, DragEndEvent, 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 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 getAllowedDropOperations?: () => DropOperation[],\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 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 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,26 @@
|
|
|
1
|
-
import { Collection, DragEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragStartEvent, Node, DragTypes,
|
|
2
|
-
import { Key } from "react";
|
|
1
|
+
import { Collection, DragEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, Node, DragTypes, 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>;
|
|
17
|
+
getAllowedDropOperations?: () => DropOperation[];
|
|
15
18
|
startDrag(key: Key, event: DragStartEvent): void;
|
|
16
19
|
moveDrag(event: DragMoveEvent): void;
|
|
17
20
|
endDrag(event: DragEndEvent): void;
|
|
18
21
|
}
|
|
19
22
|
export function useDraggableCollectionState(props: DraggableCollectionOptions): DraggableCollectionState;
|
|
20
|
-
interface DroppableCollectionStateOptions extends DroppableCollectionProps {
|
|
23
|
+
export interface DroppableCollectionStateOptions extends DroppableCollectionProps {
|
|
21
24
|
collection: Collection<Node<unknown>>;
|
|
22
25
|
selectionManager: MultipleSelectionManager;
|
|
23
26
|
}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;AAgBA,2CAA4C,SAAQ,wBAAwB;IAC1E,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC,gBAAgB,EAAE,wBAAwB,CAAA;CAC3C;AAED;IACE,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,UAAU,EAAE,GAAG,GAAG,IAAI,CAAC;IACvB,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC;IAC9B,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,QAAQ,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,UAAU,mBAAmB,CAAC,CAAC;IACzC,wBAAwB,CAAC,EAAE,MAAM,aAAa,EAAE,CAAC;IACjD,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;IACrC,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAA;CACnC;AAED,4CAA4C,KAAK,EAAE,0BAA0B,GAAG,wBAAwB,CA+EvG;ACnGD,gDAAiD,SAAQ,wBAAwB;IAC/E,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC,gBAAgB,EAAE,wBAAwB,CAAA;CAC3C;AAED;IACE,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,YAAY,CAAC,MAAM,EAAE,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 type {DraggableCollectionOptions, DraggableCollectionState} from './useDraggableCollectionState';\nexport type {DroppableCollectionStateOptions, DroppableCollectionState} from './useDroppableCollectionState';\nexport {useDraggableCollectionState} from './useDraggableCollectionState';\nexport {useDroppableCollectionState} 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.10",
|
|
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.3",
|
|
22
|
+
"@react-stately/utils": "^3.5.1",
|
|
23
|
+
"@react-types/shared": "^3.14.1"
|
|
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": "b03ef51e6317547dd0a840f151e59d039b1e1fd3"
|
|
32
32
|
}
|
package/src/index.ts
CHANGED
|
@@ -10,5 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
export
|
|
14
|
-
export
|
|
13
|
+
export type {DraggableCollectionOptions, DraggableCollectionState} from './useDraggableCollectionState';
|
|
14
|
+
export type {DroppableCollectionStateOptions, DroppableCollectionState} from './useDroppableCollectionState';
|
|
15
|
+
export {useDraggableCollectionState} from './useDraggableCollectionState';
|
|
16
|
+
export {useDroppableCollectionState} from './useDroppableCollectionState';
|
|
@@ -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, DropOperation, 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,39 @@ 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>,
|
|
31
|
+
getAllowedDropOperations?: () => DropOperation[],
|
|
29
32
|
startDrag(key: Key, event: DragStartEvent): void,
|
|
30
33
|
moveDrag(event: DragMoveEvent): void,
|
|
31
34
|
endDrag(event: DragEndEvent): void
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
export function useDraggableCollectionState(props: DraggableCollectionOptions): DraggableCollectionState {
|
|
35
|
-
let
|
|
38
|
+
let {
|
|
39
|
+
getItems,
|
|
40
|
+
collection,
|
|
41
|
+
selectionManager,
|
|
42
|
+
onDragStart,
|
|
43
|
+
onDragMove,
|
|
44
|
+
onDragEnd,
|
|
45
|
+
preview,
|
|
46
|
+
getAllowedDropOperations
|
|
47
|
+
} = props;
|
|
48
|
+
let [, setDragging] = useState(false);
|
|
49
|
+
let draggingKeys = useRef(new Set<Key>());
|
|
50
|
+
let draggedKey = useRef(null);
|
|
36
51
|
let getKeys = (key: Key) => {
|
|
37
52
|
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
38
53
|
// other selected items are also dragged. If it is not selected, the only the clicked
|
|
39
54
|
// item is dragged. This matches native macOS behavior.
|
|
40
55
|
let keys = new Set(
|
|
41
|
-
|
|
42
|
-
?
|
|
56
|
+
selectionManager.isSelected(key)
|
|
57
|
+
? new Set([...selectionManager.selectedKeys].filter(key => !!collection.getItem(key)))
|
|
43
58
|
: []
|
|
44
59
|
);
|
|
45
60
|
|
|
@@ -48,50 +63,54 @@ export function useDraggableCollectionState(props: DraggableCollectionOptions):
|
|
|
48
63
|
};
|
|
49
64
|
|
|
50
65
|
return {
|
|
51
|
-
collection
|
|
52
|
-
selectionManager
|
|
66
|
+
collection,
|
|
67
|
+
selectionManager,
|
|
68
|
+
get draggedKey() {
|
|
69
|
+
return draggedKey.current;
|
|
70
|
+
},
|
|
71
|
+
get draggingKeys() {
|
|
72
|
+
return draggingKeys.current;
|
|
73
|
+
},
|
|
53
74
|
isDragging(key) {
|
|
54
|
-
return draggingKeys.has(key);
|
|
75
|
+
return draggingKeys.current.has(key);
|
|
55
76
|
},
|
|
56
77
|
getKeysForDrag: getKeys,
|
|
57
78
|
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;
|
|
79
|
+
return getItems(getKeys(key));
|
|
66
80
|
},
|
|
81
|
+
preview,
|
|
82
|
+
getAllowedDropOperations,
|
|
67
83
|
startDrag(key, event) {
|
|
84
|
+
setDragging(true);
|
|
68
85
|
let keys = getKeys(key);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (typeof
|
|
72
|
-
|
|
86
|
+
draggingKeys.current = keys;
|
|
87
|
+
draggedKey.current = key;
|
|
88
|
+
if (typeof onDragStart === 'function') {
|
|
89
|
+
onDragStart({
|
|
73
90
|
...event,
|
|
74
91
|
keys
|
|
75
92
|
});
|
|
76
93
|
}
|
|
77
94
|
},
|
|
78
95
|
moveDrag(event) {
|
|
79
|
-
if (typeof
|
|
80
|
-
|
|
96
|
+
if (typeof onDragMove === 'function') {
|
|
97
|
+
onDragMove({
|
|
81
98
|
...event,
|
|
82
|
-
keys: draggingKeys
|
|
99
|
+
keys: draggingKeys.current
|
|
83
100
|
});
|
|
84
101
|
}
|
|
85
102
|
},
|
|
86
103
|
endDrag(event) {
|
|
87
|
-
if (typeof
|
|
88
|
-
|
|
104
|
+
if (typeof onDragEnd === 'function') {
|
|
105
|
+
onDragEnd({
|
|
89
106
|
...event,
|
|
90
|
-
keys: draggingKeys
|
|
107
|
+
keys: draggingKeys.current
|
|
91
108
|
});
|
|
92
109
|
}
|
|
93
110
|
|
|
94
|
-
|
|
111
|
+
setDragging(false);
|
|
112
|
+
draggingKeys.current = new Set();
|
|
113
|
+
draggedKey.current = null;
|
|
95
114
|
}
|
|
96
115
|
};
|
|
97
116
|
}
|
|
@@ -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
|
}
|