@react-aria/selection 3.17.5 → 3.18.0
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/ListKeyboardDelegate.main.js +200 -0
- package/dist/ListKeyboardDelegate.main.js.map +1 -0
- package/dist/ListKeyboardDelegate.mjs +195 -0
- package/dist/ListKeyboardDelegate.module.js +195 -0
- package/dist/ListKeyboardDelegate.module.js.map +1 -0
- package/dist/import.mjs +5 -794
- package/dist/main.js +10 -799
- package/dist/main.js.map +1 -1
- package/dist/module.js +5 -794
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useSelectableCollection.main.js +304 -0
- package/dist/useSelectableCollection.main.js.map +1 -0
- package/dist/useSelectableCollection.mjs +299 -0
- package/dist/useSelectableCollection.module.js +299 -0
- package/dist/useSelectableCollection.module.js.map +1 -0
- package/dist/useSelectableItem.main.js +213 -0
- package/dist/useSelectableItem.main.js.map +1 -0
- package/dist/useSelectableItem.mjs +208 -0
- package/dist/useSelectableItem.module.js +208 -0
- package/dist/useSelectableItem.module.js.map +1 -0
- package/dist/useSelectableList.main.js +61 -0
- package/dist/useSelectableList.main.js.map +1 -0
- package/dist/useSelectableList.mjs +56 -0
- package/dist/useSelectableList.module.js +56 -0
- package/dist/useSelectableList.module.js.map +1 -0
- package/dist/useTypeSelect.main.js +73 -0
- package/dist/useTypeSelect.main.js.map +1 -0
- package/dist/useTypeSelect.mjs +68 -0
- package/dist/useTypeSelect.module.js +68 -0
- package/dist/useTypeSelect.module.js.map +1 -0
- package/dist/utils.main.js +32 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +26 -0
- package/dist/utils.module.js +26 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +8 -8
- package/src/ListKeyboardDelegate.ts +15 -7
- package/src/useSelectableCollection.ts +5 -3
- package/src/useSelectableItem.ts +4 -2
- package/src/useSelectableList.ts +7 -1
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
var $doKEG$reactariautils = require("@react-aria/utils");
|
|
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, "ListKeyboardDelegate", () => $836f880b12dcae5c$export$a05409b8bb224a5a);
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
11
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
+
* governing permissions and limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
class $836f880b12dcae5c$export$a05409b8bb224a5a {
|
|
21
|
+
isDisabled(item) {
|
|
22
|
+
var _item_props;
|
|
23
|
+
return this.disabledBehavior === "all" && (((_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.isDisabled) || this.disabledKeys.has(item.key));
|
|
24
|
+
}
|
|
25
|
+
getNextKey(key) {
|
|
26
|
+
key = this.collection.getKeyAfter(key);
|
|
27
|
+
while(key != null){
|
|
28
|
+
let item = this.collection.getItem(key);
|
|
29
|
+
if (item.type === "item" && !this.isDisabled(item)) return key;
|
|
30
|
+
key = this.collection.getKeyAfter(key);
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
getPreviousKey(key) {
|
|
35
|
+
key = this.collection.getKeyBefore(key);
|
|
36
|
+
while(key != null){
|
|
37
|
+
let item = this.collection.getItem(key);
|
|
38
|
+
if (item.type === "item" && !this.isDisabled(item)) return key;
|
|
39
|
+
key = this.collection.getKeyBefore(key);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
findKey(key, nextKey, shouldSkip) {
|
|
44
|
+
let item = this.getItem(key);
|
|
45
|
+
if (!item) return null;
|
|
46
|
+
// Find the item above or below in the same column.
|
|
47
|
+
let prevRect = item.getBoundingClientRect();
|
|
48
|
+
do {
|
|
49
|
+
key = nextKey(key);
|
|
50
|
+
item = this.getItem(key);
|
|
51
|
+
}while (item && shouldSkip(prevRect, item.getBoundingClientRect()));
|
|
52
|
+
return key;
|
|
53
|
+
}
|
|
54
|
+
isSameRow(prevRect, itemRect) {
|
|
55
|
+
return prevRect.top === itemRect.top || prevRect.left !== itemRect.left;
|
|
56
|
+
}
|
|
57
|
+
isSameColumn(prevRect, itemRect) {
|
|
58
|
+
return prevRect.left === itemRect.left || prevRect.top !== itemRect.top;
|
|
59
|
+
}
|
|
60
|
+
getKeyBelow(key) {
|
|
61
|
+
if (this.layout === "grid" && this.orientation === "vertical") return this.findKey(key, (key)=>this.getNextKey(key), this.isSameRow);
|
|
62
|
+
else return this.getNextKey(key);
|
|
63
|
+
}
|
|
64
|
+
getKeyAbove(key) {
|
|
65
|
+
if (this.layout === "grid" && this.orientation === "vertical") return this.findKey(key, (key)=>this.getPreviousKey(key), this.isSameRow);
|
|
66
|
+
else return this.getPreviousKey(key);
|
|
67
|
+
}
|
|
68
|
+
getNextColumn(key, right) {
|
|
69
|
+
return right ? this.getPreviousKey(key) : this.getNextKey(key);
|
|
70
|
+
}
|
|
71
|
+
getKeyRightOf(key) {
|
|
72
|
+
if (this.layout === "grid") {
|
|
73
|
+
if (this.orientation === "vertical") return this.getNextColumn(key, this.direction === "rtl");
|
|
74
|
+
else return this.findKey(key, (key)=>this.getNextColumn(key, this.direction === "rtl"), this.isSameColumn);
|
|
75
|
+
} else if (this.orientation === "horizontal") return this.getNextColumn(key, this.direction === "rtl");
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
getKeyLeftOf(key) {
|
|
79
|
+
if (this.layout === "grid") {
|
|
80
|
+
if (this.orientation === "vertical") return this.getNextColumn(key, this.direction === "ltr");
|
|
81
|
+
else return this.findKey(key, (key)=>this.getNextColumn(key, this.direction === "ltr"), this.isSameColumn);
|
|
82
|
+
} else if (this.orientation === "horizontal") return this.getNextColumn(key, this.direction === "ltr");
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
getFirstKey() {
|
|
86
|
+
let key = this.collection.getFirstKey();
|
|
87
|
+
while(key != null){
|
|
88
|
+
let item = this.collection.getItem(key);
|
|
89
|
+
if ((item === null || item === void 0 ? void 0 : item.type) === "item" && !this.isDisabled(item)) return key;
|
|
90
|
+
key = this.collection.getKeyAfter(key);
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
getLastKey() {
|
|
95
|
+
let key = this.collection.getLastKey();
|
|
96
|
+
while(key != null){
|
|
97
|
+
let item = this.collection.getItem(key);
|
|
98
|
+
if (item.type === "item" && !this.isDisabled(item)) return key;
|
|
99
|
+
key = this.collection.getKeyBefore(key);
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
getItem(key) {
|
|
104
|
+
return key !== null ? this.ref.current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`) : null;
|
|
105
|
+
}
|
|
106
|
+
getKeyPageAbove(key) {
|
|
107
|
+
let menu = this.ref.current;
|
|
108
|
+
let item = this.getItem(key);
|
|
109
|
+
if (!item) return null;
|
|
110
|
+
if (!(0, $doKEG$reactariautils.isScrollable)(menu)) return this.getFirstKey();
|
|
111
|
+
let containerRect = menu.getBoundingClientRect();
|
|
112
|
+
let itemRect = item.getBoundingClientRect();
|
|
113
|
+
if (this.orientation === "horizontal") {
|
|
114
|
+
let containerX = containerRect.x - menu.scrollLeft;
|
|
115
|
+
let pageX = Math.max(0, itemRect.x - containerX + itemRect.width - containerRect.width);
|
|
116
|
+
while(item && itemRect.x - containerX > pageX){
|
|
117
|
+
key = this.getKeyAbove(key);
|
|
118
|
+
item = key == null ? null : this.getItem(key);
|
|
119
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
let containerY = containerRect.y - menu.scrollTop;
|
|
123
|
+
let pageY = Math.max(0, itemRect.y - containerY + itemRect.height - containerRect.height);
|
|
124
|
+
while(item && itemRect.y - containerY > pageY){
|
|
125
|
+
key = this.getKeyAbove(key);
|
|
126
|
+
item = key == null ? null : this.getItem(key);
|
|
127
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return key !== null && key !== void 0 ? key : this.getFirstKey();
|
|
131
|
+
}
|
|
132
|
+
getKeyPageBelow(key) {
|
|
133
|
+
let menu = this.ref.current;
|
|
134
|
+
let item = this.getItem(key);
|
|
135
|
+
if (!item) return null;
|
|
136
|
+
if (!(0, $doKEG$reactariautils.isScrollable)(menu)) return this.getLastKey();
|
|
137
|
+
let containerRect = menu.getBoundingClientRect();
|
|
138
|
+
let itemRect = item.getBoundingClientRect();
|
|
139
|
+
if (this.orientation === "horizontal") {
|
|
140
|
+
let containerX = containerRect.x - menu.scrollLeft;
|
|
141
|
+
let pageX = Math.min(menu.scrollWidth, itemRect.x - containerX - itemRect.width + containerRect.width);
|
|
142
|
+
while(item && itemRect.x - containerX < pageX){
|
|
143
|
+
key = this.getKeyBelow(key);
|
|
144
|
+
item = key == null ? null : this.getItem(key);
|
|
145
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
let containerY = containerRect.y - menu.scrollTop;
|
|
149
|
+
let pageY = Math.min(menu.scrollHeight, itemRect.y - containerY - itemRect.height + containerRect.height);
|
|
150
|
+
while(item && itemRect.y - containerY < pageY){
|
|
151
|
+
key = this.getKeyBelow(key);
|
|
152
|
+
item = key == null ? null : this.getItem(key);
|
|
153
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return key !== null && key !== void 0 ? key : this.getLastKey();
|
|
157
|
+
}
|
|
158
|
+
getKeyForSearch(search, fromKey) {
|
|
159
|
+
if (!this.collator) return null;
|
|
160
|
+
let collection = this.collection;
|
|
161
|
+
let key = fromKey || this.getFirstKey();
|
|
162
|
+
while(key != null){
|
|
163
|
+
let item = collection.getItem(key);
|
|
164
|
+
let substring = item.textValue.slice(0, search.length);
|
|
165
|
+
if (item.textValue && this.collator.compare(substring, search) === 0) return key;
|
|
166
|
+
key = this.getKeyBelow(key);
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
constructor(...args){
|
|
171
|
+
if (args.length === 1) {
|
|
172
|
+
let opts = args[0];
|
|
173
|
+
this.collection = opts.collection;
|
|
174
|
+
this.ref = opts.ref;
|
|
175
|
+
this.collator = opts.collator;
|
|
176
|
+
this.disabledKeys = opts.disabledKeys || new Set();
|
|
177
|
+
this.disabledBehavior = opts.disabledBehavior || "all";
|
|
178
|
+
this.orientation = opts.orientation;
|
|
179
|
+
this.direction = opts.direction;
|
|
180
|
+
this.layout = opts.layout || "stack";
|
|
181
|
+
} else {
|
|
182
|
+
this.collection = args[0];
|
|
183
|
+
this.disabledKeys = args[1];
|
|
184
|
+
this.ref = args[2];
|
|
185
|
+
this.collator = args[3];
|
|
186
|
+
this.layout = "stack";
|
|
187
|
+
this.orientation = "vertical";
|
|
188
|
+
this.disabledBehavior = "all";
|
|
189
|
+
}
|
|
190
|
+
// If this is a vertical stack, remove the left/right methods completely
|
|
191
|
+
// so they aren't called by useDroppableCollection.
|
|
192
|
+
if (this.layout === "stack" && this.orientation === "vertical") {
|
|
193
|
+
this.getKeyLeftOf = undefined;
|
|
194
|
+
this.getKe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AC,YAAY,GAAG;YACpB,IAAI,CAAC,aAAa,GAAG;QACvB;IACF;AAyOF","sources":["packages/@react-aria/selection/src/ListKeyboardDelegate.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, Direction, DisabledBehavior, Key, KeyboardDelegate, Node, Orientation} from '@react-types/shared';\nimport {isScrollable} from '@react-aria/utils';\nimport {RefObject} from 'react';\n\ninterface ListKeyboardDelegateOptions<T> {\n collection: Collection<Node<T>>,\n ref: RefObject<HTMLElement>,\n collator?: Intl.Collator,\n layout?: 'stack' | 'grid',\n orientation?: Orientation,\n direction?: Direction,\n disabledKeys?: Set<Key>,\n disabledBehavior?: DisabledBehavior\n}\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private collection: Collection<Node<T>>;\n private disabledKeys: Set<Key>;\n private disabledBehavior: DisabledBehavior;\n private ref: RefObject<HTMLElement>;\n private collator: Intl.Collator | undefined;\n private layout: 'stack' | 'grid';\n private orientation?: Orientation;\n private direction?: Direction;\n\n constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement>, collator?: Intl.Collator);\n constructor(options: ListKeyboardDelegateOptions<T>);\n constructor(...args: any[]) {\n if (args.length === 1) {\n let opts = args[0] as ListKeyboardDelegateOptions<T>;\n this.collection = opts.collection;\n this.ref = opts.ref;\n this.collator = opts.collator;\n this.disabledKeys = opts.disabledKeys || new Set();\n this.disabledBehavior = opts.disabledBehavior || 'all';\n this.orientation = opts.orientation;\n this.direction = opts.direction;\n this.layout = opts.layout || 'stack';\n } else {\n this.collection = args[0];\n this.disabledKeys = args[1];\n this.ref = args[2];\n this.collator = args[3];\n this.layout = 'stack';\n this.orientation = 'vertical';\n this.disabledBehavior = 'all';\n }\n\n // If this is a vertical stack, remove the left/right methods completely\n // so they aren't called by useDroppableCollection.\n if (this.layout === 'stack' && this.orientation === 'vertical') {\n this.getKeyLeftOf = undefined;\n this.getKeyRightOf = undefined;\n }\n }\n\n private isDisabled(item: Node<unknown>) {\n return this.disabledBehavior === 'all' && (item.props?.isDisabled || this.disabledKeys.has(item.key));\n }\n\n getNextKey(key: Key) {\n key = this.collection.getKeyAfter(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return null;\n }\n\n getPreviousKey(key: Key) {\n key = this.collection.getKeyBefore(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n\n return null;\n }\n\n private findKey(\n key: Key,\n nextKey: (key: Key) => Key,\n shouldSkip: (prevRect: DOMRect, itemRect: DOMRect) => boolean\n ) {\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n // Find the item above or below in the same column.\n let prevRect = item.getBoundingClientRect();\n do {\n key = nextKey(key);\n item = this.getItem(key);\n } while (item && shouldSkip(prevRect, item.getBoundingClientRect()));\n\n return key;\n }\n\n private isSameRow(prevRect: DOMRect, itemRect: DOMRect) {\n return prevRect.top === itemRect.top || prevRect.left !== itemRect.left;\n }\n\n private isSameColumn(prevRect: DOMRect, itemRect: DOMRect) {\n return prevRect.left === itemRect.left || prevRect.top !== itemRect.top;\n }\n\n getKeyBelow(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getNextKey(key), this.isSameRow);\n } else {\n return this.getNextKey(key);\n }\n }\n\n getKeyAbove(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getPreviousKey(key), this.isSameRow);\n } else {\n return this.getPreviousKey(key);\n }\n }\n\n private getNextColumn(key: Key, right: boolean) {\n return right ? this.getPreviousKey(key) : this.getNextKey(key);\n }\n\n getKeyRightOf(key: Key) {\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'rtl');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'rtl'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'rtl');\n }\n\n return null;\n }\n\n getKeyLeftOf(key: Key) {\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'ltr');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'ltr'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'ltr');\n }\n\n return null;\n }\n\n getFirstKey() {\n let key = this.collection.getFirstKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item?.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return null;\n }\n\n getLastKey() {\n let key = this.collection.getLastKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n\n return null;\n }\n\n private getItem(key: Key): HTMLElement {\n return key !== null ? this.ref.current.querySelector(`[data-key=\"${CSS.escape(key.toString())}\"]`) : null;\n }\n\n getKeyPageAbove(key: Key) {\n let menu = this.ref.current;\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n if (!isScrollable(menu)) {\n return this.getFirstKey();\n }\n\n let containerRect = menu.getBoundingClientRect();\n let itemRect = item.getBoundingClientRect();\n if (this.orientation === 'horizontal') {\n let containerX = containerRect.x - menu.scrollLeft;\n let pageX = Math.max(0, (itemRect.x - containerX) + itemRect.width - containerRect.width);\n\n while (item && (itemRect.x - containerX) > pageX) {\n key = this.getKeyAbove(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n } else {\n let containerY = containerRect.y - menu.scrollTop;\n let pageY = Math.max(0, (itemRect.y - containerY) + itemRect.height - containerRect.height);\n\n while (item && (itemRect.y - containerY) > pageY) {\n key = this.getKeyAbove(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n }\n\n return key ?? this.getFirstKey();\n }\n\n getKeyPageBelow(key: Key) {\n let menu = this.ref.current;\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n if (!isScrollable(menu)) {\n return this.getLastKey();\n }\n\n let containerRect = menu.getBoundingClientRect();\n let itemRect = item.getBoundingClientRect();\n if (this.orientation === 'horizontal') {\n let containerX = containerRect.x - menu.scrollLeft;\n let pageX = Math.min(menu.scrollWidth, (itemRect.x - containerX) - itemRect.width + containerRect.width);\n\n while (item && (itemRect.x - containerX) < pageX) {\n key = this.getKeyBelow(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n } else {\n let containerY = containerRect.y - menu.scrollTop;\n let pageY = Math.min(menu.scrollHeight, (itemRect.y - containerY) - itemRect.height + containerRect.height);\n\n while (item && (itemRect.y - containerY) < pageY) {\n key = this.getKeyBelow(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n }\n\n return key ?? this.getLastKey();\n }\n\n getKeyForSearch(search: string, fromKey?: Key) {\n if (!this.collator) {\n return null;\n }\n\n let collection = this.collection;\n let key = fromKey || this.getFirstKey();\n while (key != null) {\n let item = collection.getItem(key);\n let substring = item.textValue.slice(0, search.length);\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.getKeyBelow(key);\n }\n\n return null;\n }\n}\n"],"names":[],"version":3,"file":"ListKeyboardDelegate.main.js.map"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {isScrollable as $eak97$isScrollable} from "@react-aria/utils";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
class $2a25aae57d74318e$export$a05409b8bb224a5a {
|
|
15
|
+
isDisabled(item) {
|
|
16
|
+
var _item_props;
|
|
17
|
+
return this.disabledBehavior === "all" && (((_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.isDisabled) || this.disabledKeys.has(item.key));
|
|
18
|
+
}
|
|
19
|
+
getNextKey(key) {
|
|
20
|
+
key = this.collection.getKeyAfter(key);
|
|
21
|
+
while(key != null){
|
|
22
|
+
let item = this.collection.getItem(key);
|
|
23
|
+
if (item.type === "item" && !this.isDisabled(item)) return key;
|
|
24
|
+
key = this.collection.getKeyAfter(key);
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
getPreviousKey(key) {
|
|
29
|
+
key = this.collection.getKeyBefore(key);
|
|
30
|
+
while(key != null){
|
|
31
|
+
let item = this.collection.getItem(key);
|
|
32
|
+
if (item.type === "item" && !this.isDisabled(item)) return key;
|
|
33
|
+
key = this.collection.getKeyBefore(key);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
findKey(key, nextKey, shouldSkip) {
|
|
38
|
+
let item = this.getItem(key);
|
|
39
|
+
if (!item) return null;
|
|
40
|
+
// Find the item above or below in the same column.
|
|
41
|
+
let prevRect = item.getBoundingClientRect();
|
|
42
|
+
do {
|
|
43
|
+
key = nextKey(key);
|
|
44
|
+
item = this.getItem(key);
|
|
45
|
+
}while (item && shouldSkip(prevRect, item.getBoundingClientRect()));
|
|
46
|
+
return key;
|
|
47
|
+
}
|
|
48
|
+
isSameRow(prevRect, itemRect) {
|
|
49
|
+
return prevRect.top === itemRect.top || prevRect.left !== itemRect.left;
|
|
50
|
+
}
|
|
51
|
+
isSameColumn(prevRect, itemRect) {
|
|
52
|
+
return prevRect.left === itemRect.left || prevRect.top !== itemRect.top;
|
|
53
|
+
}
|
|
54
|
+
getKeyBelow(key) {
|
|
55
|
+
if (this.layout === "grid" && this.orientation === "vertical") return this.findKey(key, (key)=>this.getNextKey(key), this.isSameRow);
|
|
56
|
+
else return this.getNextKey(key);
|
|
57
|
+
}
|
|
58
|
+
getKeyAbove(key) {
|
|
59
|
+
if (this.layout === "grid" && this.orientation === "vertical") return this.findKey(key, (key)=>this.getPreviousKey(key), this.isSameRow);
|
|
60
|
+
else return this.getPreviousKey(key);
|
|
61
|
+
}
|
|
62
|
+
getNextColumn(key, right) {
|
|
63
|
+
return right ? this.getPreviousKey(key) : this.getNextKey(key);
|
|
64
|
+
}
|
|
65
|
+
getKeyRightOf(key) {
|
|
66
|
+
if (this.layout === "grid") {
|
|
67
|
+
if (this.orientation === "vertical") return this.getNextColumn(key, this.direction === "rtl");
|
|
68
|
+
else return this.findKey(key, (key)=>this.getNextColumn(key, this.direction === "rtl"), this.isSameColumn);
|
|
69
|
+
} else if (this.orientation === "horizontal") return this.getNextColumn(key, this.direction === "rtl");
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
getKeyLeftOf(key) {
|
|
73
|
+
if (this.layout === "grid") {
|
|
74
|
+
if (this.orientation === "vertical") return this.getNextColumn(key, this.direction === "ltr");
|
|
75
|
+
else return this.findKey(key, (key)=>this.getNextColumn(key, this.direction === "ltr"), this.isSameColumn);
|
|
76
|
+
} else if (this.orientation === "horizontal") return this.getNextColumn(key, this.direction === "ltr");
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
getFirstKey() {
|
|
80
|
+
let key = this.collection.getFirstKey();
|
|
81
|
+
while(key != null){
|
|
82
|
+
let item = this.collection.getItem(key);
|
|
83
|
+
if ((item === null || item === void 0 ? void 0 : item.type) === "item" && !this.isDisabled(item)) return key;
|
|
84
|
+
key = this.collection.getKeyAfter(key);
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
getLastKey() {
|
|
89
|
+
let key = this.collection.getLastKey();
|
|
90
|
+
while(key != null){
|
|
91
|
+
let item = this.collection.getItem(key);
|
|
92
|
+
if (item.type === "item" && !this.isDisabled(item)) return key;
|
|
93
|
+
key = this.collection.getKeyBefore(key);
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
getItem(key) {
|
|
98
|
+
return key !== null ? this.ref.current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`) : null;
|
|
99
|
+
}
|
|
100
|
+
getKeyPageAbove(key) {
|
|
101
|
+
let menu = this.ref.current;
|
|
102
|
+
let item = this.getItem(key);
|
|
103
|
+
if (!item) return null;
|
|
104
|
+
if (!(0, $eak97$isScrollable)(menu)) return this.getFirstKey();
|
|
105
|
+
let containerRect = menu.getBoundingClientRect();
|
|
106
|
+
let itemRect = item.getBoundingClientRect();
|
|
107
|
+
if (this.orientation === "horizontal") {
|
|
108
|
+
let containerX = containerRect.x - menu.scrollLeft;
|
|
109
|
+
let pageX = Math.max(0, itemRect.x - containerX + itemRect.width - containerRect.width);
|
|
110
|
+
while(item && itemRect.x - containerX > pageX){
|
|
111
|
+
key = this.getKeyAbove(key);
|
|
112
|
+
item = key == null ? null : this.getItem(key);
|
|
113
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
let containerY = containerRect.y - menu.scrollTop;
|
|
117
|
+
let pageY = Math.max(0, itemRect.y - containerY + itemRect.height - containerRect.height);
|
|
118
|
+
while(item && itemRect.y - containerY > pageY){
|
|
119
|
+
key = this.getKeyAbove(key);
|
|
120
|
+
item = key == null ? null : this.getItem(key);
|
|
121
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return key !== null && key !== void 0 ? key : this.getFirstKey();
|
|
125
|
+
}
|
|
126
|
+
getKeyPageBelow(key) {
|
|
127
|
+
let menu = this.ref.current;
|
|
128
|
+
let item = this.getItem(key);
|
|
129
|
+
if (!item) return null;
|
|
130
|
+
if (!(0, $eak97$isScrollable)(menu)) return this.getLastKey();
|
|
131
|
+
let containerRect = menu.getBoundingClientRect();
|
|
132
|
+
let itemRect = item.getBoundingClientRect();
|
|
133
|
+
if (this.orientation === "horizontal") {
|
|
134
|
+
let containerX = containerRect.x - menu.scrollLeft;
|
|
135
|
+
let pageX = Math.min(menu.scrollWidth, itemRect.x - containerX - itemRect.width + containerRect.width);
|
|
136
|
+
while(item && itemRect.x - containerX < pageX){
|
|
137
|
+
key = this.getKeyBelow(key);
|
|
138
|
+
item = key == null ? null : this.getItem(key);
|
|
139
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
let containerY = containerRect.y - menu.scrollTop;
|
|
143
|
+
let pageY = Math.min(menu.scrollHeight, itemRect.y - containerY - itemRect.height + containerRect.height);
|
|
144
|
+
while(item && itemRect.y - containerY < pageY){
|
|
145
|
+
key = this.getKeyBelow(key);
|
|
146
|
+
item = key == null ? null : this.getItem(key);
|
|
147
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return key !== null && key !== void 0 ? key : this.getLastKey();
|
|
151
|
+
}
|
|
152
|
+
getKeyForSearch(search, fromKey) {
|
|
153
|
+
if (!this.collator) return null;
|
|
154
|
+
let collection = this.collection;
|
|
155
|
+
let key = fromKey || this.getFirstKey();
|
|
156
|
+
while(key != null){
|
|
157
|
+
let item = collection.getItem(key);
|
|
158
|
+
let substring = item.textValue.slice(0, search.length);
|
|
159
|
+
if (item.textValue && this.collator.compare(substring, search) === 0) return key;
|
|
160
|
+
key = this.getKeyBelow(key);
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
constructor(...args){
|
|
165
|
+
if (args.length === 1) {
|
|
166
|
+
let opts = args[0];
|
|
167
|
+
this.collection = opts.collection;
|
|
168
|
+
this.ref = opts.ref;
|
|
169
|
+
this.collator = opts.collator;
|
|
170
|
+
this.disabledKeys = opts.disabledKeys || new Set();
|
|
171
|
+
this.disabledBehavior = opts.disabledBehavior || "all";
|
|
172
|
+
this.orientation = opts.orientation;
|
|
173
|
+
this.direction = opts.direction;
|
|
174
|
+
this.layout = opts.layout || "stack";
|
|
175
|
+
} else {
|
|
176
|
+
this.collection = args[0];
|
|
177
|
+
this.disabledKeys = args[1];
|
|
178
|
+
this.ref = args[2];
|
|
179
|
+
this.collator = args[3];
|
|
180
|
+
this.layout = "stack";
|
|
181
|
+
this.orientation = "vertical";
|
|
182
|
+
this.disabledBehavior = "all";
|
|
183
|
+
}
|
|
184
|
+
// If this is a vertical stack, remove the left/right methods completely
|
|
185
|
+
// so they aren't called by useDroppableCollection.
|
|
186
|
+
if (this.layout === "stack" && this.orientation === "vertical") {
|
|
187
|
+
this.getKeyLeftOf = undefined;
|
|
188
|
+
this.getKeyRightOf = undefined;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
export {$2a25aae57d74318e$export$a05409b8bb224a5a as ListKeyboardDelegate};
|
|
195
|
+
//# sourceMappingURL=ListKeyboardDelegate.mjs.map
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {isScrollable as $eak97$isScrollable} from "@react-aria/utils";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
5
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
7
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
10
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
11
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
|
+
* governing permissions and limitations under the License.
|
|
13
|
+
*/
|
|
14
|
+
class $2a25aae57d74318e$export$a05409b8bb224a5a {
|
|
15
|
+
isDisabled(item) {
|
|
16
|
+
var _item_props;
|
|
17
|
+
return this.disabledBehavior === "all" && (((_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.isDisabled) || this.disabledKeys.has(item.key));
|
|
18
|
+
}
|
|
19
|
+
getNextKey(key) {
|
|
20
|
+
key = this.collection.getKeyAfter(key);
|
|
21
|
+
while(key != null){
|
|
22
|
+
let item = this.collection.getItem(key);
|
|
23
|
+
if (item.type === "item" && !this.isDisabled(item)) return key;
|
|
24
|
+
key = this.collection.getKeyAfter(key);
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
getPreviousKey(key) {
|
|
29
|
+
key = this.collection.getKeyBefore(key);
|
|
30
|
+
while(key != null){
|
|
31
|
+
let item = this.collection.getItem(key);
|
|
32
|
+
if (item.type === "item" && !this.isDisabled(item)) return key;
|
|
33
|
+
key = this.collection.getKeyBefore(key);
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
findKey(key, nextKey, shouldSkip) {
|
|
38
|
+
let item = this.getItem(key);
|
|
39
|
+
if (!item) return null;
|
|
40
|
+
// Find the item above or below in the same column.
|
|
41
|
+
let prevRect = item.getBoundingClientRect();
|
|
42
|
+
do {
|
|
43
|
+
key = nextKey(key);
|
|
44
|
+
item = this.getItem(key);
|
|
45
|
+
}while (item && shouldSkip(prevRect, item.getBoundingClientRect()));
|
|
46
|
+
return key;
|
|
47
|
+
}
|
|
48
|
+
isSameRow(prevRect, itemRect) {
|
|
49
|
+
return prevRect.top === itemRect.top || prevRect.left !== itemRect.left;
|
|
50
|
+
}
|
|
51
|
+
isSameColumn(prevRect, itemRect) {
|
|
52
|
+
return prevRect.left === itemRect.left || prevRect.top !== itemRect.top;
|
|
53
|
+
}
|
|
54
|
+
getKeyBelow(key) {
|
|
55
|
+
if (this.layout === "grid" && this.orientation === "vertical") return this.findKey(key, (key)=>this.getNextKey(key), this.isSameRow);
|
|
56
|
+
else return this.getNextKey(key);
|
|
57
|
+
}
|
|
58
|
+
getKeyAbove(key) {
|
|
59
|
+
if (this.layout === "grid" && this.orientation === "vertical") return this.findKey(key, (key)=>this.getPreviousKey(key), this.isSameRow);
|
|
60
|
+
else return this.getPreviousKey(key);
|
|
61
|
+
}
|
|
62
|
+
getNextColumn(key, right) {
|
|
63
|
+
return right ? this.getPreviousKey(key) : this.getNextKey(key);
|
|
64
|
+
}
|
|
65
|
+
getKeyRightOf(key) {
|
|
66
|
+
if (this.layout === "grid") {
|
|
67
|
+
if (this.orientation === "vertical") return this.getNextColumn(key, this.direction === "rtl");
|
|
68
|
+
else return this.findKey(key, (key)=>this.getNextColumn(key, this.direction === "rtl"), this.isSameColumn);
|
|
69
|
+
} else if (this.orientation === "horizontal") return this.getNextColumn(key, this.direction === "rtl");
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
getKeyLeftOf(key) {
|
|
73
|
+
if (this.layout === "grid") {
|
|
74
|
+
if (this.orientation === "vertical") return this.getNextColumn(key, this.direction === "ltr");
|
|
75
|
+
else return this.findKey(key, (key)=>this.getNextColumn(key, this.direction === "ltr"), this.isSameColumn);
|
|
76
|
+
} else if (this.orientation === "horizontal") return this.getNextColumn(key, this.direction === "ltr");
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
getFirstKey() {
|
|
80
|
+
let key = this.collection.getFirstKey();
|
|
81
|
+
while(key != null){
|
|
82
|
+
let item = this.collection.getItem(key);
|
|
83
|
+
if ((item === null || item === void 0 ? void 0 : item.type) === "item" && !this.isDisabled(item)) return key;
|
|
84
|
+
key = this.collection.getKeyAfter(key);
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
getLastKey() {
|
|
89
|
+
let key = this.collection.getLastKey();
|
|
90
|
+
while(key != null){
|
|
91
|
+
let item = this.collection.getItem(key);
|
|
92
|
+
if (item.type === "item" && !this.isDisabled(item)) return key;
|
|
93
|
+
key = this.collection.getKeyBefore(key);
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
getItem(key) {
|
|
98
|
+
return key !== null ? this.ref.current.querySelector(`[data-key="${CSS.escape(key.toString())}"]`) : null;
|
|
99
|
+
}
|
|
100
|
+
getKeyPageAbove(key) {
|
|
101
|
+
let menu = this.ref.current;
|
|
102
|
+
let item = this.getItem(key);
|
|
103
|
+
if (!item) return null;
|
|
104
|
+
if (!(0, $eak97$isScrollable)(menu)) return this.getFirstKey();
|
|
105
|
+
let containerRect = menu.getBoundingClientRect();
|
|
106
|
+
let itemRect = item.getBoundingClientRect();
|
|
107
|
+
if (this.orientation === "horizontal") {
|
|
108
|
+
let containerX = containerRect.x - menu.scrollLeft;
|
|
109
|
+
let pageX = Math.max(0, itemRect.x - containerX + itemRect.width - containerRect.width);
|
|
110
|
+
while(item && itemRect.x - containerX > pageX){
|
|
111
|
+
key = this.getKeyAbove(key);
|
|
112
|
+
item = key == null ? null : this.getItem(key);
|
|
113
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
114
|
+
}
|
|
115
|
+
} else {
|
|
116
|
+
let containerY = containerRect.y - menu.scrollTop;
|
|
117
|
+
let pageY = Math.max(0, itemRect.y - containerY + itemRect.height - containerRect.height);
|
|
118
|
+
while(item && itemRect.y - containerY > pageY){
|
|
119
|
+
key = this.getKeyAbove(key);
|
|
120
|
+
item = key == null ? null : this.getItem(key);
|
|
121
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return key !== null && key !== void 0 ? key : this.getFirstKey();
|
|
125
|
+
}
|
|
126
|
+
getKeyPageBelow(key) {
|
|
127
|
+
let menu = this.ref.current;
|
|
128
|
+
let item = this.getItem(key);
|
|
129
|
+
if (!item) return null;
|
|
130
|
+
if (!(0, $eak97$isScrollable)(menu)) return this.getLastKey();
|
|
131
|
+
let containerRect = menu.getBoundingClientRect();
|
|
132
|
+
let itemRect = item.getBoundingClientRect();
|
|
133
|
+
if (this.orientation === "horizontal") {
|
|
134
|
+
let containerX = containerRect.x - menu.scrollLeft;
|
|
135
|
+
let pageX = Math.min(menu.scrollWidth, itemRect.x - containerX - itemRect.width + containerRect.width);
|
|
136
|
+
while(item && itemRect.x - containerX < pageX){
|
|
137
|
+
key = this.getKeyBelow(key);
|
|
138
|
+
item = key == null ? null : this.getItem(key);
|
|
139
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
let containerY = containerRect.y - menu.scrollTop;
|
|
143
|
+
let pageY = Math.min(menu.scrollHeight, itemRect.y - containerY - itemRect.height + containerRect.height);
|
|
144
|
+
while(item && itemRect.y - containerY < pageY){
|
|
145
|
+
key = this.getKeyBelow(key);
|
|
146
|
+
item = key == null ? null : this.getItem(key);
|
|
147
|
+
itemRect = item === null || item === void 0 ? void 0 : item.getBoundingClientRect();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return key !== null && key !== void 0 ? key : this.getLastKey();
|
|
151
|
+
}
|
|
152
|
+
getKeyForSearch(search, fromKey) {
|
|
153
|
+
if (!this.collator) return null;
|
|
154
|
+
let collection = this.collection;
|
|
155
|
+
let key = fromKey || this.getFirstKey();
|
|
156
|
+
while(key != null){
|
|
157
|
+
let item = collection.getItem(key);
|
|
158
|
+
let substring = item.textValue.slice(0, search.length);
|
|
159
|
+
if (item.textValue && this.collator.compare(substring, search) === 0) return key;
|
|
160
|
+
key = this.getKeyBelow(key);
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
constructor(...args){
|
|
165
|
+
if (args.length === 1) {
|
|
166
|
+
let opts = args[0];
|
|
167
|
+
this.collection = opts.collection;
|
|
168
|
+
this.ref = opts.ref;
|
|
169
|
+
this.collator = opts.collator;
|
|
170
|
+
this.disabledKeys = opts.disabledKeys || new Set();
|
|
171
|
+
this.disabledBehavior = opts.disabledBehavior || "all";
|
|
172
|
+
this.orientation = opts.orientation;
|
|
173
|
+
this.direction = opts.direction;
|
|
174
|
+
this.layout = opts.layout || "stack";
|
|
175
|
+
} else {
|
|
176
|
+
this.collection = args[0];
|
|
177
|
+
this.disabledKeys = args[1];
|
|
178
|
+
this.ref = args[2];
|
|
179
|
+
this.collator = args[3];
|
|
180
|
+
this.layout = "stack";
|
|
181
|
+
this.orientation = "vertical";
|
|
182
|
+
this.disabledBehavior = "all";
|
|
183
|
+
}
|
|
184
|
+
// If this is a vertical stack, remove the left/right methods completely
|
|
185
|
+
// so they aren't called by useDroppableCollection.
|
|
186
|
+
if (this.layout === "stack" && this.orientation === "vertical") {
|
|
187
|
+
this.getKeyLeftOf = undefined;
|
|
188
|
+
this.getKeyRightOf = undefined;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
export {$2a25aae57d74318e$export$a05409b8bb224a5a as ListKeyboardDelegate};
|
|
195
|
+
//# sourceMappingURL=ListKeyboardDelegate.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;AAAA;;;;;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AI,KAAK,SAAS,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,YAAY,GACjE,OAAO;YAGT,MAAM,IAAI,CAAC,WAAW,CAAC;QACzB;QAEA,OAAO;IACT;IAnQA,YAAY,GAAG,IAAW,CAAE;QAC1B,IAAI,KAAK,MAAM,KAAK,GAAG;YACrB,IAAI,OAAO,IAAI,CAAC,EAAE;YAClB,IAAI,CAAC,UAAU,GAAG,KAAK,UAAU;YACjC,IAAI,CAAC,GAAG,GAAG,KAAK,GAAG;YACnB,IAAI,CAAC,QAAQ,GAAG,KAAK,QAAQ;YAC7B,IAAI,CAAC,YAAY,GAAG,KAAK,YAAY,IAAI,IAAI;YAC7C,IAAI,CAAC,gBAAgB,GAAG,KAAK,gBAAgB,IAAI;YACjD,IAAI,CAAC,WAAW,GAAG,KAAK,WAAW;YACnC,IAAI,CAAC,SAAS,GAAG,KAAK,SAAS;YAC/B,IAAI,CAAC,MAAM,GAAG,KAAK,MAAM,IAAI;QAC/B,OAAO;YACL,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE;YACzB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE;YAC3B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE;YACvB,IAAI,CAAC,MAAM,GAAG;YACd,IAAI,CAAC,WAAW,GAAG;YACnB,IAAI,CAAC,gBAAgB,GAAG;QAC1B;QAEA,wEAAwE;QACxE,mDAAmD;QACnD,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,WAAW,KAAK,YAAY;YAC9D,IAAI,CAAC,YAAY,GAAG;YACpB,IAAI,CAAC,aAAa,GAAG;QACvB;IACF;AAyOF","sources":["packages/@react-aria/selection/src/ListKeyboardDelegate.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, Direction, DisabledBehavior, Key, KeyboardDelegate, Node, Orientation} from '@react-types/shared';\nimport {isScrollable} from '@react-aria/utils';\nimport {RefObject} from 'react';\n\ninterface ListKeyboardDelegateOptions<T> {\n collection: Collection<Node<T>>,\n ref: RefObject<HTMLElement>,\n collator?: Intl.Collator,\n layout?: 'stack' | 'grid',\n orientation?: Orientation,\n direction?: Direction,\n disabledKeys?: Set<Key>,\n disabledBehavior?: DisabledBehavior\n}\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private collection: Collection<Node<T>>;\n private disabledKeys: Set<Key>;\n private disabledBehavior: DisabledBehavior;\n private ref: RefObject<HTMLElement>;\n private collator: Intl.Collator | undefined;\n private layout: 'stack' | 'grid';\n private orientation?: Orientation;\n private direction?: Direction;\n\n constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement>, collator?: Intl.Collator);\n constructor(options: ListKeyboardDelegateOptions<T>);\n constructor(...args: any[]) {\n if (args.length === 1) {\n let opts = args[0] as ListKeyboardDelegateOptions<T>;\n this.collection = opts.collection;\n this.ref = opts.ref;\n this.collator = opts.collator;\n this.disabledKeys = opts.disabledKeys || new Set();\n this.disabledBehavior = opts.disabledBehavior || 'all';\n this.orientation = opts.orientation;\n this.direction = opts.direction;\n this.layout = opts.layout || 'stack';\n } else {\n this.collection = args[0];\n this.disabledKeys = args[1];\n this.ref = args[2];\n this.collator = args[3];\n this.layout = 'stack';\n this.orientation = 'vertical';\n this.disabledBehavior = 'all';\n }\n\n // If this is a vertical stack, remove the left/right methods completely\n // so they aren't called by useDroppableCollection.\n if (this.layout === 'stack' && this.orientation === 'vertical') {\n this.getKeyLeftOf = undefined;\n this.getKeyRightOf = undefined;\n }\n }\n\n private isDisabled(item: Node<unknown>) {\n return this.disabledBehavior === 'all' && (item.props?.isDisabled || this.disabledKeys.has(item.key));\n }\n\n getNextKey(key: Key) {\n key = this.collection.getKeyAfter(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return null;\n }\n\n getPreviousKey(key: Key) {\n key = this.collection.getKeyBefore(key);\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n\n return null;\n }\n\n private findKey(\n key: Key,\n nextKey: (key: Key) => Key,\n shouldSkip: (prevRect: DOMRect, itemRect: DOMRect) => boolean\n ) {\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n // Find the item above or below in the same column.\n let prevRect = item.getBoundingClientRect();\n do {\n key = nextKey(key);\n item = this.getItem(key);\n } while (item && shouldSkip(prevRect, item.getBoundingClientRect()));\n\n return key;\n }\n\n private isSameRow(prevRect: DOMRect, itemRect: DOMRect) {\n return prevRect.top === itemRect.top || prevRect.left !== itemRect.left;\n }\n\n private isSameColumn(prevRect: DOMRect, itemRect: DOMRect) {\n return prevRect.left === itemRect.left || prevRect.top !== itemRect.top;\n }\n\n getKeyBelow(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getNextKey(key), this.isSameRow);\n } else {\n return this.getNextKey(key);\n }\n }\n\n getKeyAbove(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getPreviousKey(key), this.isSameRow);\n } else {\n return this.getPreviousKey(key);\n }\n }\n\n private getNextColumn(key: Key, right: boolean) {\n return right ? this.getPreviousKey(key) : this.getNextKey(key);\n }\n\n getKeyRightOf(key: Key) {\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'rtl');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'rtl'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'rtl');\n }\n\n return null;\n }\n\n getKeyLeftOf(key: Key) {\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'ltr');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'ltr'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'ltr');\n }\n\n return null;\n }\n\n getFirstKey() {\n let key = this.collection.getFirstKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item?.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return null;\n }\n\n getLastKey() {\n let key = this.collection.getLastKey();\n while (key != null) {\n let item = this.collection.getItem(key);\n if (item.type === 'item' && !this.isDisabled(item)) {\n return key;\n }\n\n key = this.collection.getKeyBefore(key);\n }\n\n return null;\n }\n\n private getItem(key: Key): HTMLElement {\n return key !== null ? this.ref.current.querySelector(`[data-key=\"${CSS.escape(key.toString())}\"]`) : null;\n }\n\n getKeyPageAbove(key: Key) {\n let menu = this.ref.current;\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n if (!isScrollable(menu)) {\n return this.getFirstKey();\n }\n\n let containerRect = menu.getBoundingClientRect();\n let itemRect = item.getBoundingClientRect();\n if (this.orientation === 'horizontal') {\n let containerX = containerRect.x - menu.scrollLeft;\n let pageX = Math.max(0, (itemRect.x - containerX) + itemRect.width - containerRect.width);\n\n while (item && (itemRect.x - containerX) > pageX) {\n key = this.getKeyAbove(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n } else {\n let containerY = containerRect.y - menu.scrollTop;\n let pageY = Math.max(0, (itemRect.y - containerY) + itemRect.height - containerRect.height);\n\n while (item && (itemRect.y - containerY) > pageY) {\n key = this.getKeyAbove(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n }\n\n return key ?? this.getFirstKey();\n }\n\n getKeyPageBelow(key: Key) {\n let menu = this.ref.current;\n let item = this.getItem(key);\n if (!item) {\n return null;\n }\n\n if (!isScrollable(menu)) {\n return this.getLastKey();\n }\n\n let containerRect = menu.getBoundingClientRect();\n let itemRect = item.getBoundingClientRect();\n if (this.orientation === 'horizontal') {\n let containerX = containerRect.x - menu.scrollLeft;\n let pageX = Math.min(menu.scrollWidth, (itemRect.x - containerX) - itemRect.width + containerRect.width);\n\n while (item && (itemRect.x - containerX) < pageX) {\n key = this.getKeyBelow(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n } else {\n let containerY = containerRect.y - menu.scrollTop;\n let pageY = Math.min(menu.scrollHeight, (itemRect.y - containerY) - itemRect.height + containerRect.height);\n\n while (item && (itemRect.y - containerY) < pageY) {\n key = this.getKeyBelow(key);\n item = key == null ? null : this.getItem(key);\n itemRect = item?.getBoundingClientRect();\n }\n }\n\n return key ?? this.getLastKey();\n }\n\n getKeyForSearch(search: string, fromKey?: Key) {\n if (!this.collator) {\n return null;\n }\n\n let collection = this.collection;\n let key = fromKey || this.getFirstKey();\n while (key != null) {\n let item = collection.getItem(key);\n let substring = item.textValue.slice(0, search.length);\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.getKeyBelow(key);\n }\n\n return null;\n }\n}\n"],"names":[],"version":3,"file":"ListKeyboardDelegate.module.js.map"}
|