@react-aria/dnd 3.0.0-nightly-77b3442e4-250522 → 3.0.0-nightly-1563243fe-250524

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.
@@ -0,0 +1,201 @@
1
+ var $2pOR2$reactstatelycollections = require("@react-stately/collections");
2
+
3
+
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+
8
+ $parcel$export(module.exports, "navigate", () => $6e16de4c92a0f271$export$ff7962acd6052c28);
9
+
10
+ function $6e16de4c92a0f271$export$ff7962acd6052c28(keyboardDelegate, collection, target, direction, rtl = false, wrap = false) {
11
+ switch(direction){
12
+ case 'left':
13
+ return rtl ? $6e16de4c92a0f271$var$nextDropTarget(keyboardDelegate, collection, target, wrap, 'left') : $6e16de4c92a0f271$var$previousDropTarget(keyboardDelegate, collection, target, wrap, 'left');
14
+ case 'right':
15
+ return rtl ? $6e16de4c92a0f271$var$previousDropTarget(keyboardDelegate, collection, target, wrap, 'right') : $6e16de4c92a0f271$var$nextDropTarget(keyboardDelegate, collection, target, wrap, 'right');
16
+ case 'up':
17
+ return $6e16de4c92a0f271$var$previousDropTarget(keyboardDelegate, collection, target, wrap);
18
+ case 'down':
19
+ return $6e16de4c92a0f271$var$nextDropTarget(keyboardDelegate, collection, target, wrap);
20
+ }
21
+ }
22
+ function $6e16de4c92a0f271$var$nextDropTarget(keyboardDelegate, collection, target, wrap = false, horizontal = null) {
23
+ if (!target) return {
24
+ type: 'root'
25
+ };
26
+ if (target.type === 'root') {
27
+ var _keyboardDelegate_getFirstKey;
28
+ var _keyboardDelegate_getFirstKey1;
29
+ let nextKey = (_keyboardDelegate_getFirstKey1 = (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate)) !== null && _keyboardDelegate_getFirstKey1 !== void 0 ? _keyboardDelegate_getFirstKey1 : null;
30
+ if (nextKey != null) return {
31
+ type: 'item',
32
+ key: nextKey,
33
+ dropPosition: 'before'
34
+ };
35
+ return null;
36
+ }
37
+ if (target.type === 'item') {
38
+ var _keyboardDelegate_getKeyRightOf, _keyboardDelegate_getKeyLeftOf, _keyboardDelegate_getKeyBelow;
39
+ let nextKey = null;
40
+ if (horizontal) nextKey = horizontal === 'right' ? (_keyboardDelegate_getKeyRightOf = keyboardDelegate.getKeyRightOf) === null || _keyboardDelegate_getKeyRightOf === void 0 ? void 0 : _keyboardDelegate_getKeyRightOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyLeftOf = keyboardDelegate.getKeyLeftOf) === null || _keyboardDelegate_getKeyLeftOf === void 0 ? void 0 : _keyboardDelegate_getKeyLeftOf.call(keyboardDelegate, target.key);
41
+ else nextKey = (_keyboardDelegate_getKeyBelow = keyboardDelegate.getKeyBelow) === null || _keyboardDelegate_getKeyBelow === void 0 ? void 0 : _keyboardDelegate_getKeyBelow.call(keyboardDelegate, target.key);
42
+ let nextCollectionKey = collection.getKeyAfter(target.key);
43
+ // If the keyboard delegate did not move to the next key in the collection,
44
+ // jump to that key with the same drop position. Otherwise, try the other
45
+ // drop positions on the current key first.
46
+ if (nextKey != null && nextKey !== nextCollectionKey) return {
47
+ type: 'item',
48
+ key: nextKey,
49
+ dropPosition: target.dropPosition
50
+ };
51
+ switch(target.dropPosition){
52
+ case 'before':
53
+ return {
54
+ type: 'item',
55
+ key: target.key,
56
+ dropPosition: 'on'
57
+ };
58
+ case 'on':
59
+ {
60
+ // If there are nested items, traverse to them prior to the "after" position of this target.
61
+ // If the next key is on the same level, then its "before" position is equivalent to this item's "after" position.
62
+ let targetNode = collection.getItem(target.key);
63
+ let nextNode = nextKey != null ? collection.getItem(nextKey) : null;
64
+ if (targetNode && nextNode && nextNode.level >= targetNode.level) return {
65
+ type: 'item',
66
+ key: nextNode.key,
67
+ dropPosition: 'before'
68
+ };
69
+ return {
70
+ type: 'item',
71
+ key: target.key,
72
+ dropPosition: 'after'
73
+ };
74
+ }
75
+ case 'after':
76
+ {
77
+ // If this is the last sibling in a level, traverse to the parent.
78
+ let targetNode = collection.getItem(target.key);
79
+ if (targetNode && targetNode.nextKey == null && targetNode.parentKey != null) {
80
+ // If the parent item has an item after it, use the "before" position.
81
+ let parentNode = collection.getItem(targetNode.parentKey);
82
+ if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.nextKey) != null) return {
83
+ type: 'item',
84
+ key: parentNode.nextKey,
85
+ dropPosition: 'before'
86
+ };
87
+ if (parentNode) return {
88
+ type: 'item',
89
+ key: parentNode.key,
90
+ dropPosition: 'after'
91
+ };
92
+ }
93
+ if ((targetNode === null || targetNode === void 0 ? void 0 : targetNode.nextKey) != null) return {
94
+ type: 'item',
95
+ key: targetNode.nextKey,
96
+ dropPosition: 'on'
97
+ };
98
+ }
99
+ }
100
+ }
101
+ if (wrap) return {
102
+ type: 'root'
103
+ };
104
+ return null;
105
+ }
106
+ function $6e16de4c92a0f271$var$previousDropTarget(keyboardDelegate, collection, target, wrap = false, horizontal = null) {
107
+ // Start after the last root-level item.
108
+ if (!target || wrap && target.type === 'root') {
109
+ var _keyboardDelegate_getLastKey;
110
+ // Keyboard delegate gets the deepest item but we want the shallowest.
111
+ let prevKey = null;
112
+ let lastKey = (_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate);
113
+ while(lastKey != null){
114
+ prevKey = lastKey;
115
+ let node = collection.getItem(lastKey);
116
+ lastKey = node === null || node === void 0 ? void 0 : node.parentKey;
117
+ }
118
+ if (prevKey != null) return {
119
+ type: 'item',
120
+ key: prevKey,
121
+ dropPosition: 'after'
122
+ };
123
+ return null;
124
+ }
125
+ if (target.type === 'item') {
126
+ var _keyboardDelegate_getKeyLeftOf, _keyboardDelegate_getKeyRightOf, _keyboardDelegate_getKeyAbove;
127
+ let prevKey = null;
128
+ if (horizontal) prevKey = horizontal === 'left' ? (_keyboardDelegate_getKeyLeftOf = keyboardDelegate.getKeyLeftOf) === null || _keyboardDelegate_getKeyLeftOf === void 0 ? void 0 : _keyboardDelegate_getKeyLeftOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyRightOf = keyboardDelegate.getKeyRightOf) === null || _keyboardDelegate_getKeyRightOf === void 0 ? void 0 : _keyboardDelegate_getKeyRightOf.call(keyboardDelegate, target.key);
129
+ else prevKey = (_keyboardDelegate_getKeyAbove = keyboardDelegate.getKeyAbove) === null || _keyboardDelegate_getKeyAbove === void 0 ? void 0 : _keyboardDelegate_getKeyAbove.call(keyboardDelegate, target.key);
130
+ let prevCollectionKey = collection.getKeyBefore(target.key);
131
+ // If the keyboard delegate did not move to the next key in the collection,
132
+ // jump to that key with the same drop position. Otherwise, try the other
133
+ // drop positions on the current key first.
134
+ if (prevKey != null && prevKey !== prevCollectionKey) return {
135
+ type: 'item',
136
+ key: prevKey,
137
+ dropPosition: target.dropPosition
138
+ };
139
+ switch(target.dropPosition){
140
+ case 'before':
141
+ {
142
+ // Move after the last child of the previous item.
143
+ let targetNode = collection.getItem(target.key);
144
+ if (targetNode && targetNode.prevKey != null) {
145
+ let lastChild = $6e16de4c92a0f271$var$getLastChild(collection, targetNode.prevKey);
146
+ if (lastChild) return lastChild;
147
+ }
148
+ if (prevKey != null) return {
149
+ type: 'item',
150
+ key: prevKey,
151
+ dropPosition: 'on'
152
+ };
153
+ return {
154
+ type: 'root'
155
+ };
156
+ }
157
+ case 'on':
158
+ return {
159
+ type: 'item',
160
+ key: target.key,
161
+ dropPosition: 'before'
162
+ };
163
+ case 'after':
164
+ {
165
+ // Move after the last child of this item.
166
+ let lastChild = $6e16de4c92a0f271$var$getLastChild(collection, target.key);
167
+ if (lastChild) return lastChild;
168
+ return {
169
+ type: 'item',
170
+ key: target.key,
171
+ dropPosition: 'on'
172
+ };
173
+ }
174
+ }
175
+ }
176
+ if (target.type !== 'root') return {
177
+ type: 'root'
178
+ };
179
+ return null;
180
+ }
181
+ function $6e16de4c92a0f271$var$getLastChild(collection, key) {
182
+ // getChildNodes still returns child tree items even when the item is collapsed.
183
+ // Checking if the next item has a greater level is a silly way to determine if the item is expanded.
184
+ let targetNode = collection.getItem(key);
185
+ let nextKey = collection.getKeyAfter(key);
186
+ let nextNode = nextKey != null ? collection.getItem(nextKey) : null;
187
+ if (targetNode && nextNode && nextNode.level > targetNode.level) {
188
+ let children = (0, $2pOR2$reactstatelycollections.getChildNodes)(targetNode, collection);
189
+ let lastChild = null;
190
+ for (let child of children)if (child.type === 'item') lastChild = child;
191
+ if (lastChild) return {
192
+ type: 'item',
193
+ key: lastChild.key,
194
+ dropPosition: 'after'
195
+ };
196
+ }
197
+ return null;
198
+ }
199
+
200
+
201
+ //# sourceMappingURL=DropTargetKeyboardNavigation.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;AAGO,SAAS,0CACd,gBAAkC,EAClC,UAAqC,EACrC,MAAqC,EACrC,SAA2C,EAC3C,MAAM,KAAK,EACX,OAAO,KAAK;IAEZ,OAAQ;QACN,KAAK;YACH,OAAO,MACH,qCAAe,kBAAkB,YAAY,QAAQ,MAAM,UAC3D,yCAAmB,kBAAkB,YAAY,QAAQ,MAAM;QACrE,KAAK;YACH,OAAO,MACH,yCAAmB,kBAAkB,YAAY,QAAQ,MAAM,WAC/D,qCAAe,kBAAkB,YAAY,QAAQ,MAAM;QACjE,KAAK;YACH,OAAO,yCAAmB,kBAAkB,YAAY,QAAQ;QAClE,KAAK;YACH,OAAO,qCAAe,kBAAkB,YAAY,QAAQ;IAChE;AACF;AAEA,SAAS,qCACP,gBAAkC,EAClC,UAAqC,EACrC,MAAqC,EACrC,OAAO,KAAK,EACZ,aAAsC,IAAI;IAE1C,IAAI,CAAC,QACH,OAAO;QACL,MAAM;IACR;IAGF,IAAI,OAAO,IAAI,KAAK,QAAQ;YACZ;YAAA;QAAd,IAA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;QAC/D,IAAI,WAAW,CAAA,GAAA,4CAAY,EAAE,YAAY;QACzC,IAAI,YAAkC;QACtC,KAAK,IAAI,SAAS,SAChB,IAAI,MAAM,IAAI,KAAK,QACjB,YAAY;QAIhB,IAAI,WACF,OAAO;YACL,MAAM;YACN,KAAK,UAAU,GAAG;YAClB,cAAc;QAChB;IAEJ;IAEA,OAAO;AACT","sources":["packages/@react-aria/dnd/src/DropTargetKeyboardNavigation.ts"],"sourcesContent":["import {Collection, DropTarget, Key, KeyboardDelegate, Node} from '@react-types/shared';\nimport {getChildNodes} from '@react-stately/collections';\n\nexport function navigate(\n keyboardDelegate: KeyboardDelegate,\n collection: Collection<Node<unknown>>,\n target: DropTarget | null | undefined,\n direction: 'left' | 'right' | 'up' | 'down',\n rtl = false,\n wrap = false\n): DropTarget | null {\n switch (direction) {\n case 'left':\n return rtl \n ? nextDropTarget(keyboardDelegate, collection, target, wrap, 'left')\n : previousDropTarget(keyboardDelegate, collection, target, wrap, 'left');\n case 'right':\n return rtl \n ? previousDropTarget(keyboardDelegate, collection, target, wrap, 'right')\n : nextDropTarget(keyboardDelegate, collection, target, wrap, 'right');\n case 'up':\n return previousDropTarget(keyboardDelegate, collection, target, wrap);\n case 'down':\n return nextDropTarget(keyboardDelegate, collection, target, wrap);\n }\n}\n\nfunction nextDropTarget(\n keyboardDelegate: KeyboardDelegate,\n collection: Collection<Node<unknown>>,\n target: DropTarget | null | undefined,\n wrap = false,\n horizontal: 'left' | 'right' | null = null\n): DropTarget | null {\n if (!target) {\n return {\n type: 'root'\n };\n }\n\n if (target.type === 'root') {\n let nextKey = keyboardDelegate.getFirstKey?.() ?? null;\n if (nextKey != null) {\n return {\n type: 'item',\n key: nextKey,\n dropPosition: 'before'\n };\n }\n\n return null;\n }\n\n if (target.type === 'item') {\n let nextKey: Key | null | undefined = null;\n if (horizontal) {\n nextKey = horizontal === 'right' ? keyboardDelegate.getKeyRightOf?.(target.key) : keyboardDelegate.getKeyLeftOf?.(target.key);\n } else {\n nextKey = keyboardDelegate.getKeyBelow?.(target.key);\n }\n let nextCollectionKey = collection.getKeyAfter(target.key);\n\n // If the keyboard delegate did not move to the next key in the collection,\n // jump to that key with the same drop position. Otherwise, try the other\n // drop positions on the current key first.\n if (nextKey != null && nextKey !== nextCollectionKey) {\n return {\n type: 'item',\n key: nextKey,\n dropPosition: target.dropPosition\n };\n }\n \n switch (target.dropPosition) {\n case 'before': {\n return {\n type: 'item',\n key: target.key,\n dropPosition: 'on'\n };\n }\n case 'on': {\n // If there are nested items, traverse to them prior to the \"after\" position of this target.\n // If the next key is on the same level, then its \"before\" position is equivalent to this item's \"after\" position.\n let targetNode = collection.getItem(target.key);\n let nextNode = nextKey != null ? collection.getItem(nextKey) : null;\n if (targetNode && nextNode && nextNode.level >= targetNode.level) {\n return {\n type: 'item',\n key: nextNode.key,\n dropPosition: 'before'\n };\n }\n\n return {\n type: 'item',\n key: target.key,\n dropPosition: 'after'\n };\n }\n case 'after': {\n // If this is the last sibling in a level, traverse to the parent.\n let targetNode = collection.getItem(target.key); \n if (targetNode && targetNode.nextKey == null && targetNode.parentKey != null) {\n // If the parent item has an item after it, use the \"before\" position.\n let parentNode = collection.getItem(targetNode.parentKey);\n if (parentNode?.nextKey != null) {\n return {\n type: 'item',\n key: parentNode.nextKey,\n dropPosition: 'before'\n };\n }\n\n if (parentNode) {\n return {\n type: 'item',\n key: parentNode.key,\n dropPosition: 'after'\n };\n }\n }\n\n if (targetNode?.nextKey != null) {\n return {\n type: 'item',\n key: targetNode.nextKey,\n dropPosition: 'on'\n };\n }\n }\n }\n }\n\n if (wrap) {\n return {\n type: 'root'\n };\n }\n\n return null;\n}\n\nfunction previousDropTarget(\n keyboardDelegate: KeyboardDelegate,\n collection: Collection<Node<unknown>>,\n target: DropTarget | null | undefined,\n wrap = false,\n horizontal: 'left' | 'right' | null = null\n): DropTarget | null {\n // Start after the last root-level item.\n if (!target || (wrap && target.type === 'root')) {\n // Keyboard delegate gets the deepest item but we want the shallowest.\n let prevKey: Key | null = null;\n let lastKey = keyboardDelegate.getLastKey?.();\n while (lastKey != null) {\n prevKey = lastKey;\n let node = collection.getItem(lastKey);\n lastKey = node?.parentKey;\n }\n\n if (prevKey != null) {\n return {\n type: 'item',\n key: prevKey,\n dropPosition: 'after'\n };\n }\n\n return null;\n }\n\n if (target.type === 'item') {\n let prevKey: Key | null | undefined = null;\n if (horizontal) {\n prevKey = horizontal === 'left' ? keyboardDelegate.getKeyLeftOf?.(target.key) : keyboardDelegate.getKeyRightOf?.(target.key);\n } else {\n prevKey = keyboardDelegate.getKeyAbove?.(target.key);\n }\n let prevCollectionKey = collection.getKeyBefore(target.key);\n\n // If the keyboard delegate did not move to the next key in the collection,\n // jump to that key with the same drop position. Otherwise, try the other\n // drop positions on the current key first.\n if (prevKey != null && prevKey !== prevCollectionKey) {\n return {\n type: 'item',\n key: prevKey,\n dropPosition: target.dropPosition\n };\n }\n\n switch (target.dropPosition) {\n case 'before': {\n // Move after the last child of the previous item.\n let targetNode = collection.getItem(target.key);\n if (targetNode && targetNode.prevKey != null) {\n let lastChild = getLastChild(collection, targetNode.prevKey);\n if (lastChild) {\n return lastChild;\n }\n }\n\n if (prevKey != null) {\n return {\n type: 'item',\n key: prevKey,\n dropPosition: 'on'\n };\n }\n\n return {\n type: 'root'\n };\n }\n case 'on': {\n return {\n type: 'item',\n key: target.key,\n dropPosition: 'before'\n };\n }\n case 'after': {\n // Move after the last child of this item.\n let lastChild = getLastChild(collection, target.key);\n if (lastChild) {\n return lastChild;\n }\n\n return {\n type: 'item',\n key: target.key,\n dropPosition: 'on'\n };\n }\n }\n }\n\n if (target.type !== 'root') {\n return {\n type: 'root'\n };\n }\n\n return null;\n}\n\nfunction getLastChild(collection: Collection<Node<unknown>>, key: Key): DropTarget | null {\n // getChildNodes still returns child tree items even when the item is collapsed.\n // Checking if the next item has a greater level is a silly way to determine if the item is expanded.\n let targetNode = collection.getItem(key);\n let nextKey = collection.getKeyAfter(key);\n let nextNode = nextKey != null ? collection.getItem(nextKey) : null;\n if (targetNode && nextNode && nextNode.level > targetNode.level) {\n let children = getChildNodes(targetNode, collection);\n let lastChild: Node<unknown> | null = null;\n for (let child of children) {\n if (child.type === 'item') {\n lastChild = child;\n }\n }\n\n if (lastChild) {\n return {\n type: 'item',\n key: lastChild.key,\n dropPosition: 'after'\n };\n }\n }\n\n return null;\n}\n"],"names":[],"version":3,"file":"DropTargetKeyboardNavigation.main.js.map"}
@@ -0,0 +1,196 @@
1
+ import {getChildNodes as $9nGAq$getChildNodes} from "@react-stately/collections";
2
+
3
+
4
+ function $e154566cef11553b$export$ff7962acd6052c28(keyboardDelegate, collection, target, direction, rtl = false, wrap = false) {
5
+ switch(direction){
6
+ case 'left':
7
+ return rtl ? $e154566cef11553b$var$nextDropTarget(keyboardDelegate, collection, target, wrap, 'left') : $e154566cef11553b$var$previousDropTarget(keyboardDelegate, collection, target, wrap, 'left');
8
+ case 'right':
9
+ return rtl ? $e154566cef11553b$var$previousDropTarget(keyboardDelegate, collection, target, wrap, 'right') : $e154566cef11553b$var$nextDropTarget(keyboardDelegate, collection, target, wrap, 'right');
10
+ case 'up':
11
+ return $e154566cef11553b$var$previousDropTarget(keyboardDelegate, collection, target, wrap);
12
+ case 'down':
13
+ return $e154566cef11553b$var$nextDropTarget(keyboardDelegate, collection, target, wrap);
14
+ }
15
+ }
16
+ function $e154566cef11553b$var$nextDropTarget(keyboardDelegate, collection, target, wrap = false, horizontal = null) {
17
+ if (!target) return {
18
+ type: 'root'
19
+ };
20
+ if (target.type === 'root') {
21
+ var _keyboardDelegate_getFirstKey;
22
+ var _keyboardDelegate_getFirstKey1;
23
+ let nextKey = (_keyboardDelegate_getFirstKey1 = (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate)) !== null && _keyboardDelegate_getFirstKey1 !== void 0 ? _keyboardDelegate_getFirstKey1 : null;
24
+ if (nextKey != null) return {
25
+ type: 'item',
26
+ key: nextKey,
27
+ dropPosition: 'before'
28
+ };
29
+ return null;
30
+ }
31
+ if (target.type === 'item') {
32
+ var _keyboardDelegate_getKeyRightOf, _keyboardDelegate_getKeyLeftOf, _keyboardDelegate_getKeyBelow;
33
+ let nextKey = null;
34
+ if (horizontal) nextKey = horizontal === 'right' ? (_keyboardDelegate_getKeyRightOf = keyboardDelegate.getKeyRightOf) === null || _keyboardDelegate_getKeyRightOf === void 0 ? void 0 : _keyboardDelegate_getKeyRightOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyLeftOf = keyboardDelegate.getKeyLeftOf) === null || _keyboardDelegate_getKeyLeftOf === void 0 ? void 0 : _keyboardDelegate_getKeyLeftOf.call(keyboardDelegate, target.key);
35
+ else nextKey = (_keyboardDelegate_getKeyBelow = keyboardDelegate.getKeyBelow) === null || _keyboardDelegate_getKeyBelow === void 0 ? void 0 : _keyboardDelegate_getKeyBelow.call(keyboardDelegate, target.key);
36
+ let nextCollectionKey = collection.getKeyAfter(target.key);
37
+ // If the keyboard delegate did not move to the next key in the collection,
38
+ // jump to that key with the same drop position. Otherwise, try the other
39
+ // drop positions on the current key first.
40
+ if (nextKey != null && nextKey !== nextCollectionKey) return {
41
+ type: 'item',
42
+ key: nextKey,
43
+ dropPosition: target.dropPosition
44
+ };
45
+ switch(target.dropPosition){
46
+ case 'before':
47
+ return {
48
+ type: 'item',
49
+ key: target.key,
50
+ dropPosition: 'on'
51
+ };
52
+ case 'on':
53
+ {
54
+ // If there are nested items, traverse to them prior to the "after" position of this target.
55
+ // If the next key is on the same level, then its "before" position is equivalent to this item's "after" position.
56
+ let targetNode = collection.getItem(target.key);
57
+ let nextNode = nextKey != null ? collection.getItem(nextKey) : null;
58
+ if (targetNode && nextNode && nextNode.level >= targetNode.level) return {
59
+ type: 'item',
60
+ key: nextNode.key,
61
+ dropPosition: 'before'
62
+ };
63
+ return {
64
+ type: 'item',
65
+ key: target.key,
66
+ dropPosition: 'after'
67
+ };
68
+ }
69
+ case 'after':
70
+ {
71
+ // If this is the last sibling in a level, traverse to the parent.
72
+ let targetNode = collection.getItem(target.key);
73
+ if (targetNode && targetNode.nextKey == null && targetNode.parentKey != null) {
74
+ // If the parent item has an item after it, use the "before" position.
75
+ let parentNode = collection.getItem(targetNode.parentKey);
76
+ if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.nextKey) != null) return {
77
+ type: 'item',
78
+ key: parentNode.nextKey,
79
+ dropPosition: 'before'
80
+ };
81
+ if (parentNode) return {
82
+ type: 'item',
83
+ key: parentNode.key,
84
+ dropPosition: 'after'
85
+ };
86
+ }
87
+ if ((targetNode === null || targetNode === void 0 ? void 0 : targetNode.nextKey) != null) return {
88
+ type: 'item',
89
+ key: targetNode.nextKey,
90
+ dropPosition: 'on'
91
+ };
92
+ }
93
+ }
94
+ }
95
+ if (wrap) return {
96
+ type: 'root'
97
+ };
98
+ return null;
99
+ }
100
+ function $e154566cef11553b$var$previousDropTarget(keyboardDelegate, collection, target, wrap = false, horizontal = null) {
101
+ // Start after the last root-level item.
102
+ if (!target || wrap && target.type === 'root') {
103
+ var _keyboardDelegate_getLastKey;
104
+ // Keyboard delegate gets the deepest item but we want the shallowest.
105
+ let prevKey = null;
106
+ let lastKey = (_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate);
107
+ while(lastKey != null){
108
+ prevKey = lastKey;
109
+ let node = collection.getItem(lastKey);
110
+ lastKey = node === null || node === void 0 ? void 0 : node.parentKey;
111
+ }
112
+ if (prevKey != null) return {
113
+ type: 'item',
114
+ key: prevKey,
115
+ dropPosition: 'after'
116
+ };
117
+ return null;
118
+ }
119
+ if (target.type === 'item') {
120
+ var _keyboardDelegate_getKeyLeftOf, _keyboardDelegate_getKeyRightOf, _keyboardDelegate_getKeyAbove;
121
+ let prevKey = null;
122
+ if (horizontal) prevKey = horizontal === 'left' ? (_keyboardDelegate_getKeyLeftOf = keyboardDelegate.getKeyLeftOf) === null || _keyboardDelegate_getKeyLeftOf === void 0 ? void 0 : _keyboardDelegate_getKeyLeftOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyRightOf = keyboardDelegate.getKeyRightOf) === null || _keyboardDelegate_getKeyRightOf === void 0 ? void 0 : _keyboardDelegate_getKeyRightOf.call(keyboardDelegate, target.key);
123
+ else prevKey = (_keyboardDelegate_getKeyAbove = keyboardDelegate.getKeyAbove) === null || _keyboardDelegate_getKeyAbove === void 0 ? void 0 : _keyboardDelegate_getKeyAbove.call(keyboardDelegate, target.key);
124
+ let prevCollectionKey = collection.getKeyBefore(target.key);
125
+ // If the keyboard delegate did not move to the next key in the collection,
126
+ // jump to that key with the same drop position. Otherwise, try the other
127
+ // drop positions on the current key first.
128
+ if (prevKey != null && prevKey !== prevCollectionKey) return {
129
+ type: 'item',
130
+ key: prevKey,
131
+ dropPosition: target.dropPosition
132
+ };
133
+ switch(target.dropPosition){
134
+ case 'before':
135
+ {
136
+ // Move after the last child of the previous item.
137
+ let targetNode = collection.getItem(target.key);
138
+ if (targetNode && targetNode.prevKey != null) {
139
+ let lastChild = $e154566cef11553b$var$getLastChild(collection, targetNode.prevKey);
140
+ if (lastChild) return lastChild;
141
+ }
142
+ if (prevKey != null) return {
143
+ type: 'item',
144
+ key: prevKey,
145
+ dropPosition: 'on'
146
+ };
147
+ return {
148
+ type: 'root'
149
+ };
150
+ }
151
+ case 'on':
152
+ return {
153
+ type: 'item',
154
+ key: target.key,
155
+ dropPosition: 'before'
156
+ };
157
+ case 'after':
158
+ {
159
+ // Move after the last child of this item.
160
+ let lastChild = $e154566cef11553b$var$getLastChild(collection, target.key);
161
+ if (lastChild) return lastChild;
162
+ return {
163
+ type: 'item',
164
+ key: target.key,
165
+ dropPosition: 'on'
166
+ };
167
+ }
168
+ }
169
+ }
170
+ if (target.type !== 'root') return {
171
+ type: 'root'
172
+ };
173
+ return null;
174
+ }
175
+ function $e154566cef11553b$var$getLastChild(collection, key) {
176
+ // getChildNodes still returns child tree items even when the item is collapsed.
177
+ // Checking if the next item has a greater level is a silly way to determine if the item is expanded.
178
+ let targetNode = collection.getItem(key);
179
+ let nextKey = collection.getKeyAfter(key);
180
+ let nextNode = nextKey != null ? collection.getItem(nextKey) : null;
181
+ if (targetNode && nextNode && nextNode.level > targetNode.level) {
182
+ let children = (0, $9nGAq$getChildNodes)(targetNode, collection);
183
+ let lastChild = null;
184
+ for (let child of children)if (child.type === 'item') lastChild = child;
185
+ if (lastChild) return {
186
+ type: 'item',
187
+ key: lastChild.key,
188
+ dropPosition: 'after'
189
+ };
190
+ }
191
+ return null;
192
+ }
193
+
194
+
195
+ export {$e154566cef11553b$export$ff7962acd6052c28 as navigate};
196
+ //# sourceMappingURL=DropTargetKeyboardNavigation.module.js.map
@@ -0,0 +1,196 @@
1
+ import {getChildNodes as $9nGAq$getChildNodes} from "@react-stately/collections";
2
+
3
+
4
+ function $e154566cef11553b$export$ff7962acd6052c28(keyboardDelegate, collection, target, direction, rtl = false, wrap = false) {
5
+ switch(direction){
6
+ case 'left':
7
+ return rtl ? $e154566cef11553b$var$nextDropTarget(keyboardDelegate, collection, target, wrap, 'left') : $e154566cef11553b$var$previousDropTarget(keyboardDelegate, collection, target, wrap, 'left');
8
+ case 'right':
9
+ return rtl ? $e154566cef11553b$var$previousDropTarget(keyboardDelegate, collection, target, wrap, 'right') : $e154566cef11553b$var$nextDropTarget(keyboardDelegate, collection, target, wrap, 'right');
10
+ case 'up':
11
+ return $e154566cef11553b$var$previousDropTarget(keyboardDelegate, collection, target, wrap);
12
+ case 'down':
13
+ return $e154566cef11553b$var$nextDropTarget(keyboardDelegate, collection, target, wrap);
14
+ }
15
+ }
16
+ function $e154566cef11553b$var$nextDropTarget(keyboardDelegate, collection, target, wrap = false, horizontal = null) {
17
+ if (!target) return {
18
+ type: 'root'
19
+ };
20
+ if (target.type === 'root') {
21
+ var _keyboardDelegate_getFirstKey;
22
+ var _keyboardDelegate_getFirstKey1;
23
+ let nextKey = (_keyboardDelegate_getFirstKey1 = (_keyboardDelegate_getFirstKey = keyboardDelegate.getFirstKey) === null || _keyboardDelegate_getFirstKey === void 0 ? void 0 : _keyboardDelegate_getFirstKey.call(keyboardDelegate)) !== null && _keyboardDelegate_getFirstKey1 !== void 0 ? _keyboardDelegate_getFirstKey1 : null;
24
+ if (nextKey != null) return {
25
+ type: 'item',
26
+ key: nextKey,
27
+ dropPosition: 'before'
28
+ };
29
+ return null;
30
+ }
31
+ if (target.type === 'item') {
32
+ var _keyboardDelegate_getKeyRightOf, _keyboardDelegate_getKeyLeftOf, _keyboardDelegate_getKeyBelow;
33
+ let nextKey = null;
34
+ if (horizontal) nextKey = horizontal === 'right' ? (_keyboardDelegate_getKeyRightOf = keyboardDelegate.getKeyRightOf) === null || _keyboardDelegate_getKeyRightOf === void 0 ? void 0 : _keyboardDelegate_getKeyRightOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyLeftOf = keyboardDelegate.getKeyLeftOf) === null || _keyboardDelegate_getKeyLeftOf === void 0 ? void 0 : _keyboardDelegate_getKeyLeftOf.call(keyboardDelegate, target.key);
35
+ else nextKey = (_keyboardDelegate_getKeyBelow = keyboardDelegate.getKeyBelow) === null || _keyboardDelegate_getKeyBelow === void 0 ? void 0 : _keyboardDelegate_getKeyBelow.call(keyboardDelegate, target.key);
36
+ let nextCollectionKey = collection.getKeyAfter(target.key);
37
+ // If the keyboard delegate did not move to the next key in the collection,
38
+ // jump to that key with the same drop position. Otherwise, try the other
39
+ // drop positions on the current key first.
40
+ if (nextKey != null && nextKey !== nextCollectionKey) return {
41
+ type: 'item',
42
+ key: nextKey,
43
+ dropPosition: target.dropPosition
44
+ };
45
+ switch(target.dropPosition){
46
+ case 'before':
47
+ return {
48
+ type: 'item',
49
+ key: target.key,
50
+ dropPosition: 'on'
51
+ };
52
+ case 'on':
53
+ {
54
+ // If there are nested items, traverse to them prior to the "after" position of this target.
55
+ // If the next key is on the same level, then its "before" position is equivalent to this item's "after" position.
56
+ let targetNode = collection.getItem(target.key);
57
+ let nextNode = nextKey != null ? collection.getItem(nextKey) : null;
58
+ if (targetNode && nextNode && nextNode.level >= targetNode.level) return {
59
+ type: 'item',
60
+ key: nextNode.key,
61
+ dropPosition: 'before'
62
+ };
63
+ return {
64
+ type: 'item',
65
+ key: target.key,
66
+ dropPosition: 'after'
67
+ };
68
+ }
69
+ case 'after':
70
+ {
71
+ // If this is the last sibling in a level, traverse to the parent.
72
+ let targetNode = collection.getItem(target.key);
73
+ if (targetNode && targetNode.nextKey == null && targetNode.parentKey != null) {
74
+ // If the parent item has an item after it, use the "before" position.
75
+ let parentNode = collection.getItem(targetNode.parentKey);
76
+ if ((parentNode === null || parentNode === void 0 ? void 0 : parentNode.nextKey) != null) return {
77
+ type: 'item',
78
+ key: parentNode.nextKey,
79
+ dropPosition: 'before'
80
+ };
81
+ if (parentNode) return {
82
+ type: 'item',
83
+ key: parentNode.key,
84
+ dropPosition: 'after'
85
+ };
86
+ }
87
+ if ((targetNode === null || targetNode === void 0 ? void 0 : targetNode.nextKey) != null) return {
88
+ type: 'item',
89
+ key: targetNode.nextKey,
90
+ dropPosition: 'on'
91
+ };
92
+ }
93
+ }
94
+ }
95
+ if (wrap) return {
96
+ type: 'root'
97
+ };
98
+ return null;
99
+ }
100
+ function $e154566cef11553b$var$previousDropTarget(keyboardDelegate, collection, target, wrap = false, horizontal = null) {
101
+ // Start after the last root-level item.
102
+ if (!target || wrap && target.type === 'root') {
103
+ var _keyboardDelegate_getLastKey;
104
+ // Keyboard delegate gets the deepest item but we want the shallowest.
105
+ let prevKey = null;
106
+ let lastKey = (_keyboardDelegate_getLastKey = keyboardDelegate.getLastKey) === null || _keyboardDelegate_getLastKey === void 0 ? void 0 : _keyboardDelegate_getLastKey.call(keyboardDelegate);
107
+ while(lastKey != null){
108
+ prevKey = lastKey;
109
+ let node = collection.getItem(lastKey);
110
+ lastKey = node === null || node === void 0 ? void 0 : node.parentKey;
111
+ }
112
+ if (prevKey != null) return {
113
+ type: 'item',
114
+ key: prevKey,
115
+ dropPosition: 'after'
116
+ };
117
+ return null;
118
+ }
119
+ if (target.type === 'item') {
120
+ var _keyboardDelegate_getKeyLeftOf, _keyboardDelegate_getKeyRightOf, _keyboardDelegate_getKeyAbove;
121
+ let prevKey = null;
122
+ if (horizontal) prevKey = horizontal === 'left' ? (_keyboardDelegate_getKeyLeftOf = keyboardDelegate.getKeyLeftOf) === null || _keyboardDelegate_getKeyLeftOf === void 0 ? void 0 : _keyboardDelegate_getKeyLeftOf.call(keyboardDelegate, target.key) : (_keyboardDelegate_getKeyRightOf = keyboardDelegate.getKeyRightOf) === null || _keyboardDelegate_getKeyRightOf === void 0 ? void 0 : _keyboardDelegate_getKeyRightOf.call(keyboardDelegate, target.key);
123
+ else prevKey = (_keyboardDelegate_getKeyAbove = keyboardDelegate.getKeyAbove) === null || _keyboardDelegate_getKeyAbove === void 0 ? void 0 : _keyboardDelegate_getKeyAbove.call(keyboardDelegate, target.key);
124
+ let prevCollectionKey = collection.getKeyBefore(target.key);
125
+ // If the keyboard delegate did not move to the next key in the collection,
126
+ // jump to that key with the same drop position. Otherwise, try the other
127
+ // drop positions on the current key first.
128
+ if (prevKey != null && prevKey !== prevCollectionKey) return {
129
+ type: 'item',
130
+ key: prevKey,
131
+ dropPosition: target.dropPosition
132
+ };
133
+ switch(target.dropPosition){
134
+ case 'before':
135
+ {
136
+ // Move after the last child of the previous item.
137
+ let targetNode = collection.getItem(target.key);
138
+ if (targetNode && targetNode.prevKey != null) {
139
+ let lastChild = $e154566cef11553b$var$getLastChild(collection, targetNode.prevKey);
140
+ if (lastChild) return lastChild;
141
+ }
142
+ if (prevKey != null) return {
143
+ type: 'item',
144
+ key: prevKey,
145
+ dropPosition: 'on'
146
+ };
147
+ return {
148
+ type: 'root'
149
+ };
150
+ }
151
+ case 'on':
152
+ return {
153
+ type: 'item',
154
+ key: target.key,
155
+ dropPosition: 'before'
156
+ };
157
+ case 'after':
158
+ {
159
+ // Move after the last child of this item.
160
+ let lastChild = $e154566cef11553b$var$getLastChild(collection, target.key);
161
+ if (lastChild) return lastChild;
162
+ return {
163
+ type: 'item',
164
+ key: target.key,
165
+ dropPosition: 'on'
166
+ };
167
+ }
168
+ }
169
+ }
170
+ if (target.type !== 'root') return {
171
+ type: 'root'
172
+ };
173
+ return null;
174
+ }
175
+ function $e154566cef11553b$var$getLastChild(collection, key) {
176
+ // getChildNodes still returns child tree items even when the item is collapsed.
177
+ // Checking if the next item has a greater level is a silly way to determine if the item is expanded.
178
+ let targetNode = collection.getItem(key);
179
+ let nextKey = collection.getKeyAfter(key);
180
+ let nextNode = nextKey != null ? collection.getItem(nextKey) : null;
181
+ if (targetNode && nextNode && nextNode.level > targetNode.level) {
182
+ let children = (0, $9nGAq$getChildNodes)(targetNode, collection);
183
+ let lastChild = null;
184
+ for (let child of children)if (child.type === 'item') lastChild = child;
185
+ if (lastChild) return {
186
+ type: 'item',
187
+ key: lastChild.key,
188
+ dropPosition: 'after'
189
+ };
190
+ }
191
+ return null;
192
+ }
193
+
194
+
195
+ export {$e154566cef11553b$export$ff7962acd6052c28 as navigate};
196
+ //# sourceMappingURL=DropTargetKeyboardNavigation.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;AAGO,SAAS,0CACd,gBAAkC,EAClC,UAAqC,EACrC,MAAqC,EACrC,SAA2C,EAC3C,MAAM,KAAK,EACX,OAAO,KAAK;IAEZ,OAAQ;QACN,KAAK;YACH,OAAO,MACH,qCAAe,kBAAkB,YAAY,QAAQ,MAAM,UAC3D,yCAAmB,kBAAkB,YAAY,QAAQ,MAAM;QACrE,KAAK;YACH,OAAO,MACH,yCAAmB,kBAAkB,YAAY,QAAQ,MAAM,WAC/D,qCAAe,kBAAkB,YAAY,QAAQ,MAAM;QACjE,KAAK;YACH,OAAO,yCAAmB,kBAAkB,YAAY,QAAQ;QAClE,KAAK;YACH,OAAO,qCAAe,k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AE,GAAQ;IACnE,gFAAgF;IAChF,qGAAqG;IACrG,IAAI,aAAa,WAAW,OAAO,CAAC;IACpC,IAAI,UAAU,WAAW,WAAW,CAAC;IACrC,IAAI,WAAW,WAAW,OAAO,WAAW,OAAO,CAAC,WAAW;IAC/D,IAAI,cAAc,YAAY,SAAS,KAAK,GAAG,WAAW,KAAK,EAAE;QAC/D,IAAI,WAAW,CAAA,GAAA,oBAAY,EAAE,YAAY;QACzC,IAAI,YAAkC;QACtC,KAAK,IAAI,SAAS,SAChB,IAAI,MAAM,IAAI,KAAK,QACjB,YAAY;QAIhB,IAAI,WACF,OAAO;YACL,MAAM;YACN,KAAK,UAAU,GAAG;YAClB,cAAc;QAChB;IAEJ;IAEA,OAAO;AACT","sources":["packages/@react-aria/dnd/src/DropTargetKeyboardNavigation.ts"],"sourcesContent":["import {Collection, DropTarget, Key, KeyboardDelegate, Node} from '@react-types/shared';\nimport {getChildNodes} from '@react-stately/collections';\n\nexport function navigate(\n keyboardDelegate: KeyboardDelegate,\n collection: Collection<Node<unknown>>,\n target: DropTarget | null | undefined,\n direction: 'left' | 'right' | 'up' | 'down',\n rtl = false,\n wrap = false\n): DropTarget | null {\n switch (direction) {\n case 'left':\n return rtl \n ? nextDropTarget(keyboardDelegate, collection, target, wrap, 'left')\n : previousDropTarget(keyboardDelegate, collection, target, wrap, 'left');\n case 'right':\n return rtl \n ? previousDropTarget(keyboardDelegate, collection, target, wrap, 'right')\n : nextDropTarget(keyboardDelegate, collection, target, wrap, 'right');\n case 'up':\n return previousDropTarget(keyboardDelegate, collection, target, wrap);\n case 'down':\n return nextDropTarget(keyboardDelegate, collection, target, wrap);\n }\n}\n\nfunction nextDropTarget(\n keyboardDelegate: KeyboardDelegate,\n collection: Collection<Node<unknown>>,\n target: DropTarget | null | undefined,\n wrap = false,\n horizontal: 'left' | 'right' | null = null\n): DropTarget | null {\n if (!target) {\n return {\n type: 'root'\n };\n }\n\n if (target.type === 'root') {\n let nextKey = keyboardDelegate.getFirstKey?.() ?? null;\n if (nextKey != null) {\n return {\n type: 'item',\n key: nextKey,\n dropPosition: 'before'\n };\n }\n\n return null;\n }\n\n if (target.type === 'item') {\n let nextKey: Key | null | undefined = null;\n if (horizontal) {\n nextKey = horizontal === 'right' ? keyboardDelegate.getKeyRightOf?.(target.key) : keyboardDelegate.getKeyLeftOf?.(target.key);\n } else {\n nextKey = keyboardDelegate.getKeyBelow?.(target.key);\n }\n let nextCollectionKey = collection.getKeyAfter(target.key);\n\n // If the keyboard delegate did not move to the next key in the collection,\n // jump to that key with the same drop position. Otherwise, try the other\n // drop positions on the current key first.\n if (nextKey != null && nextKey !== nextCollectionKey) {\n return {\n type: 'item',\n key: nextKey,\n dropPosition: target.dropPosition\n };\n }\n \n switch (target.dropPosition) {\n case 'before': {\n return {\n type: 'item',\n key: target.key,\n dropPosition: 'on'\n };\n }\n case 'on': {\n // If there are nested items, traverse to them prior to the \"after\" position of this target.\n // If the next key is on the same level, then its \"before\" position is equivalent to this item's \"after\" position.\n let targetNode = collection.getItem(target.key);\n let nextNode = nextKey != null ? collection.getItem(nextKey) : null;\n if (targetNode && nextNode && nextNode.level >= targetNode.level) {\n return {\n type: 'item',\n key: nextNode.key,\n dropPosition: 'before'\n };\n }\n\n return {\n type: 'item',\n key: target.key,\n dropPosition: 'after'\n };\n }\n case 'after': {\n // If this is the last sibling in a level, traverse to the parent.\n let targetNode = collection.getItem(target.key); \n if (targetNode && targetNode.nextKey == null && targetNode.parentKey != null) {\n // If the parent item has an item after it, use the \"before\" position.\n let parentNode = collection.getItem(targetNode.parentKey);\n if (parentNode?.nextKey != null) {\n return {\n type: 'item',\n key: parentNode.nextKey,\n dropPosition: 'before'\n };\n }\n\n if (parentNode) {\n return {\n type: 'item',\n key: parentNode.key,\n dropPosition: 'after'\n };\n }\n }\n\n if (targetNode?.nextKey != null) {\n return {\n type: 'item',\n key: targetNode.nextKey,\n dropPosition: 'on'\n };\n }\n }\n }\n }\n\n if (wrap) {\n return {\n type: 'root'\n };\n }\n\n return null;\n}\n\nfunction previousDropTarget(\n keyboardDelegate: KeyboardDelegate,\n collection: Collection<Node<unknown>>,\n target: DropTarget | null | undefined,\n wrap = false,\n horizontal: 'left' | 'right' | null = null\n): DropTarget | null {\n // Start after the last root-level item.\n if (!target || (wrap && target.type === 'root')) {\n // Keyboard delegate gets the deepest item but we want the shallowest.\n let prevKey: Key | null = null;\n let lastKey = keyboardDelegate.getLastKey?.();\n while (lastKey != null) {\n prevKey = lastKey;\n let node = collection.getItem(lastKey);\n lastKey = node?.parentKey;\n }\n\n if (prevKey != null) {\n return {\n type: 'item',\n key: prevKey,\n dropPosition: 'after'\n };\n }\n\n return null;\n }\n\n if (target.type === 'item') {\n let prevKey: Key | null | undefined = null;\n if (horizontal) {\n prevKey = horizontal === 'left' ? keyboardDelegate.getKeyLeftOf?.(target.key) : keyboardDelegate.getKeyRightOf?.(target.key);\n } else {\n prevKey = keyboardDelegate.getKeyAbove?.(target.key);\n }\n let prevCollectionKey = collection.getKeyBefore(target.key);\n\n // If the keyboard delegate did not move to the next key in the collection,\n // jump to that key with the same drop position. Otherwise, try the other\n // drop positions on the current key first.\n if (prevKey != null && prevKey !== prevCollectionKey) {\n return {\n type: 'item',\n key: prevKey,\n dropPosition: target.dropPosition\n };\n }\n\n switch (target.dropPosition) {\n case 'before': {\n // Move after the last child of the previous item.\n let targetNode = collection.getItem(target.key);\n if (targetNode && targetNode.prevKey != null) {\n let lastChild = getLastChild(collection, targetNode.prevKey);\n if (lastChild) {\n return lastChild;\n }\n }\n\n if (prevKey != null) {\n return {\n type: 'item',\n key: prevKey,\n dropPosition: 'on'\n };\n }\n\n return {\n type: 'root'\n };\n }\n case 'on': {\n return {\n type: 'item',\n key: target.key,\n dropPosition: 'before'\n };\n }\n case 'after': {\n // Move after the last child of this item.\n let lastChild = getLastChild(collection, target.key);\n if (lastChild) {\n return lastChild;\n }\n\n return {\n type: 'item',\n key: target.key,\n dropPosition: 'on'\n };\n }\n }\n }\n\n if (target.type !== 'root') {\n return {\n type: 'root'\n };\n }\n\n return null;\n}\n\nfunction getLastChild(collection: Collection<Node<unknown>>, key: Key): DropTarget | null {\n // getChildNodes still returns child tree items even when the item is collapsed.\n // Checking if the next item has a greater level is a silly way to determine if the item is expanded.\n let targetNode = collection.getItem(key);\n let nextKey = collection.getKeyAfter(key);\n let nextNode = nextKey != null ? collection.getItem(nextKey) : null;\n if (targetNode && nextNode && nextNode.level > targetNode.level) {\n let children = getChildNodes(targetNode, collection);\n let lastChild: Node<unknown> | null = null;\n for (let child of children) {\n if (child.type === 'item') {\n lastChild = child;\n }\n }\n\n if (lastChild) {\n return {\n type: 'item',\n key: lastChild.key,\n dropPosition: 'after'\n };\n }\n }\n\n return null;\n}\n"],"names":[],"version":3,"file":"DropTargetKeyboardNavigation.module.js.map"}