@react-aria/selection 3.27.1 → 3.28.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.
Files changed (52) hide show
  1. package/dist/import.mjs +7 -7
  2. package/dist/main.js +12 -12
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +7 -7
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +10 -0
  7. package/package.json +15 -17
  8. package/src/index.ts +10 -10
  9. package/dist/DOMLayoutDelegate.main.js +0 -59
  10. package/dist/DOMLayoutDelegate.main.js.map +0 -1
  11. package/dist/DOMLayoutDelegate.mjs +0 -54
  12. package/dist/DOMLayoutDelegate.module.js +0 -54
  13. package/dist/DOMLayoutDelegate.module.js.map +0 -1
  14. package/dist/ListKeyboardDelegate.main.js +0 -197
  15. package/dist/ListKeyboardDelegate.main.js.map +0 -1
  16. package/dist/ListKeyboardDelegate.mjs +0 -192
  17. package/dist/ListKeyboardDelegate.module.js +0 -192
  18. package/dist/ListKeyboardDelegate.module.js.map +0 -1
  19. package/dist/types.d.ts +0 -258
  20. package/dist/types.d.ts.map +0 -1
  21. package/dist/useSelectableCollection.main.js +0 -403
  22. package/dist/useSelectableCollection.main.js.map +0 -1
  23. package/dist/useSelectableCollection.mjs +0 -398
  24. package/dist/useSelectableCollection.module.js +0 -398
  25. package/dist/useSelectableCollection.module.js.map +0 -1
  26. package/dist/useSelectableItem.main.js +0 -263
  27. package/dist/useSelectableItem.main.js.map +0 -1
  28. package/dist/useSelectableItem.mjs +0 -258
  29. package/dist/useSelectableItem.module.js +0 -258
  30. package/dist/useSelectableItem.module.js.map +0 -1
  31. package/dist/useSelectableList.main.js +0 -63
  32. package/dist/useSelectableList.main.js.map +0 -1
  33. package/dist/useSelectableList.mjs +0 -58
  34. package/dist/useSelectableList.module.js +0 -58
  35. package/dist/useSelectableList.module.js.map +0 -1
  36. package/dist/useTypeSelect.main.js +0 -77
  37. package/dist/useTypeSelect.main.js.map +0 -1
  38. package/dist/useTypeSelect.mjs +0 -72
  39. package/dist/useTypeSelect.module.js +0 -72
  40. package/dist/useTypeSelect.module.js.map +0 -1
  41. package/dist/utils.main.js +0 -46
  42. package/dist/utils.main.js.map +0 -1
  43. package/dist/utils.mjs +0 -38
  44. package/dist/utils.module.js +0 -38
  45. package/dist/utils.module.js.map +0 -1
  46. package/src/DOMLayoutDelegate.ts +0 -61
  47. package/src/ListKeyboardDelegate.ts +0 -291
  48. package/src/useSelectableCollection.ts +0 -593
  49. package/src/useSelectableItem.ts +0 -422
  50. package/src/useSelectableList.ts +0 -85
  51. package/src/useTypeSelect.ts +0 -117
  52. package/src/utils.ts +0 -47
@@ -1,72 +0,0 @@
1
- import {useRef as $dAE4Y$useRef} from "react";
2
- import {nodeContains as $dAE4Y$nodeContains} from "@react-aria/utils";
3
-
4
- /*
5
- * Copyright 2020 Adobe. All rights reserved.
6
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License. You may obtain a copy
8
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software distributed under
11
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- * OF ANY KIND, either express or implied. See the License for the specific language
13
- * governing permissions and limitations under the License.
14
- */
15
-
16
- /**
17
- * Controls how long to wait before clearing the typeahead buffer.
18
- */ const $fb3050f43d946246$var$TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second
19
- function $fb3050f43d946246$export$e32c88dfddc6e1d8(options) {
20
- let { keyboardDelegate: keyboardDelegate, selectionManager: selectionManager, onTypeSelect: onTypeSelect } = options;
21
- let state = (0, $dAE4Y$useRef)({
22
- search: '',
23
- timeout: undefined
24
- }).current;
25
- let onKeyDown = (e)=>{
26
- let character = $fb3050f43d946246$var$getStringForKey(e.key);
27
- if (!character || e.ctrlKey || e.metaKey || !(0, $dAE4Y$nodeContains)(e.currentTarget, e.target) || state.search.length === 0 && character === ' ') return;
28
- // Do not propagate the Spacebar event if it's meant to be part of the search.
29
- // When we time out, the search term becomes empty, hence the check on length.
30
- // Trimming is to account for the case of pressing the Spacebar more than once,
31
- // which should cycle through the selection/deselection of the focused item.
32
- if (character === ' ' && state.search.trim().length > 0) {
33
- e.preventDefault();
34
- if (!('continuePropagation' in e)) e.stopPropagation();
35
- }
36
- state.search += character;
37
- if (keyboardDelegate.getKeyForSearch != null) {
38
- // Use the delegate to find a key to focus.
39
- // Prioritize items after the currently focused item, falling back to searching the whole list.
40
- let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);
41
- // If no key found, search from the top.
42
- if (key == null) key = keyboardDelegate.getKeyForSearch(state.search);
43
- if (key != null) {
44
- selectionManager.setFocusedKey(key);
45
- if (onTypeSelect) onTypeSelect(key);
46
- }
47
- }
48
- clearTimeout(state.timeout);
49
- state.timeout = setTimeout(()=>{
50
- state.search = '';
51
- }, $fb3050f43d946246$var$TYPEAHEAD_DEBOUNCE_WAIT_MS);
52
- };
53
- return {
54
- typeSelectProps: {
55
- // Using a capturing listener to catch the keydown event before
56
- // other hooks in order to handle the Spacebar event.
57
- onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined
58
- }
59
- };
60
- }
61
- function $fb3050f43d946246$var$getStringForKey(key) {
62
- // If the key is of length 1, it is an ASCII value.
63
- // Otherwise, if there are no ASCII characters in the key name,
64
- // it is a Unicode character.
65
- // See https://www.w3.org/TR/uievents-key/
66
- if (key.length === 1 || !/^[A-Z]/i.test(key)) return key;
67
- return '';
68
- }
69
-
70
-
71
- export {$fb3050f43d946246$export$e32c88dfddc6e1d8 as useTypeSelect};
72
- //# sourceMappingURL=useTypeSelect.module.js.map
@@ -1,72 +0,0 @@
1
- import {useRef as $dAE4Y$useRef} from "react";
2
- import {nodeContains as $dAE4Y$nodeContains} from "@react-aria/utils";
3
-
4
- /*
5
- * Copyright 2020 Adobe. All rights reserved.
6
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
7
- * you may not use this file except in compliance with the License. You may obtain a copy
8
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software distributed under
11
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
12
- * OF ANY KIND, either express or implied. See the License for the specific language
13
- * governing permissions and limitations under the License.
14
- */
15
-
16
- /**
17
- * Controls how long to wait before clearing the typeahead buffer.
18
- */ const $fb3050f43d946246$var$TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second
19
- function $fb3050f43d946246$export$e32c88dfddc6e1d8(options) {
20
- let { keyboardDelegate: keyboardDelegate, selectionManager: selectionManager, onTypeSelect: onTypeSelect } = options;
21
- let state = (0, $dAE4Y$useRef)({
22
- search: '',
23
- timeout: undefined
24
- }).current;
25
- let onKeyDown = (e)=>{
26
- let character = $fb3050f43d946246$var$getStringForKey(e.key);
27
- if (!character || e.ctrlKey || e.metaKey || !(0, $dAE4Y$nodeContains)(e.currentTarget, e.target) || state.search.length === 0 && character === ' ') return;
28
- // Do not propagate the Spacebar event if it's meant to be part of the search.
29
- // When we time out, the search term becomes empty, hence the check on length.
30
- // Trimming is to account for the case of pressing the Spacebar more than once,
31
- // which should cycle through the selection/deselection of the focused item.
32
- if (character === ' ' && state.search.trim().length > 0) {
33
- e.preventDefault();
34
- if (!('continuePropagation' in e)) e.stopPropagation();
35
- }
36
- state.search += character;
37
- if (keyboardDelegate.getKeyForSearch != null) {
38
- // Use the delegate to find a key to focus.
39
- // Prioritize items after the currently focused item, falling back to searching the whole list.
40
- let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);
41
- // If no key found, search from the top.
42
- if (key == null) key = keyboardDelegate.getKeyForSearch(state.search);
43
- if (key != null) {
44
- selectionManager.setFocusedKey(key);
45
- if (onTypeSelect) onTypeSelect(key);
46
- }
47
- }
48
- clearTimeout(state.timeout);
49
- state.timeout = setTimeout(()=>{
50
- state.search = '';
51
- }, $fb3050f43d946246$var$TYPEAHEAD_DEBOUNCE_WAIT_MS);
52
- };
53
- return {
54
- typeSelectProps: {
55
- // Using a capturing listener to catch the keydown event before
56
- // other hooks in order to handle the Spacebar event.
57
- onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined
58
- }
59
- };
60
- }
61
- function $fb3050f43d946246$var$getStringForKey(key) {
62
- // If the key is of length 1, it is an ASCII value.
63
- // Otherwise, if there are no ASCII characters in the key name,
64
- // it is a Unicode character.
65
- // See https://www.w3.org/TR/uievents-key/
66
- if (key.length === 1 || !/^[A-Z]/i.test(key)) return key;
67
- return '';
68
- }
69
-
70
-
71
- export {$fb3050f43d946246$export$e32c88dfddc6e1d8 as useTypeSelect};
72
- //# sourceMappingURL=useTypeSelect.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAOD;;CAEC,GACD,MAAM,mDAA6B,MAAM,WAAW;AA2B7C,SAAS,0CAAc,OAA8B;IAC1D,IAAI,oBAAC,gBAAgB,oBAAE,gBAAgB,gBAAE,YAAY,EAAC,GAAG;IACzD,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAwE;QACvF,QAAQ;QACR,SAAS;IACX,GAAG,OAAO;IAEV,IAAI,YAAY,CAAC;QACf,IAAI,YAAY,sCAAgB,EAAE,GAAG;QACrC,IAAI,CAAC,aAAa,EAAE,OAAO,IAAI,EAAE,OAAO,IAAI,CAAC,CAAA,GAAA,mBAAW,EAAE,EAAE,aAAa,EAAE,EAAE,MAAM,KAAqB,MAAM,MAAM,CAAC,MAAM,KAAK,KAAK,cAAc,KACjJ;QAGF,8EAA8E;QAC9E,8EAA8E;QAC9E,+EAA+E;QAC/E,4EAA4E;QAC5E,IAAI,cAAc,OAAO,MAAM,MAAM,CAAC,IAAI,GAAG,MAAM,GAAG,GAAG;YACvD,EAAE,cAAc;YAChB,IAAI,CAAE,CAAA,yBAAyB,CAAA,GAC7B,EAAE,eAAe;QAErB;QAEA,MAAM,MAAM,IAAI;QAEhB,IAAI,iBAAiB,eAAe,IAAI,MAAM;YAC5C,2CAA2C;YAC3C,+FAA+F;YAC/F,IAAI,MAAM,iBAAiB,eAAe,CAAC,MAAM,MAAM,EAAE,iBAAiB,UAAU;YAEpF,wCAAwC;YACxC,IAAI,OAAO,MACT,MAAM,iBAAiB,eAAe,CAAC,MAAM,MAAM;YAGrD,IAAI,OAAO,MAAM;gBACf,iBAAiB,aAAa,CAAC;gBAC/B,IAAI,cACF,aAAa;YAEjB;QACF;QAEA,aAAa,MAAM,OAAO;QAC1B,MAAM,OAAO,GAAG,WAAW;YACzB,MAAM,MAAM,GAAG;QACjB,GAAG;IACL;IAEA,OAAO;QACL,iBAAiB;YACf,+DAA+D;YAC/D,qDAAqD;YACrD,kBAAkB,iBAAiB,eAAe,GAAG,YAAY;QACnE;IACF;AACF;AAEA,SAAS,sCAAgB,GAAW;IAClC,mDAAmD;IACnD,+DAA+D;IAC/D,6BAA6B;IAC7B,0CAA0C;IAC1C,IAAI,IAAI,MAAM,KAAK,KAAK,CAAC,UAAU,IAAI,CAAC,MACtC,OAAO;IAGT,OAAO;AACT","sources":["packages/@react-aria/selection/src/useTypeSelect.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 {DOMAttributes, Key, KeyboardDelegate} from '@react-types/shared';\nimport {KeyboardEvent, useRef} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {nodeContains} from '@react-aria/utils';\n\n/**\n * Controls how long to wait before clearing the typeahead buffer.\n */\nconst TYPEAHEAD_DEBOUNCE_WAIT_MS = 1000; // 1 second\n\nexport interface AriaTypeSelectOptions {\n /**\n * A delegate that returns collection item keys with respect to visual layout.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * Called when an item is focused by typing.\n */\n onTypeSelect?: (key: Key) => void\n}\n\nexport interface TypeSelectAria {\n /**\n * Props to be spread on the owner of the options.\n */\n typeSelectProps: DOMAttributes\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function useTypeSelect(options: AriaTypeSelectOptions): TypeSelectAria {\n let {keyboardDelegate, selectionManager, onTypeSelect} = options;\n let state = useRef<{search: string, timeout: ReturnType<typeof setTimeout> | undefined}>({\n search: '',\n timeout: undefined\n }).current;\n\n let onKeyDown = (e: KeyboardEvent) => {\n let character = getStringForKey(e.key);\n if (!character || e.ctrlKey || e.metaKey || !nodeContains(e.currentTarget, e.target as HTMLElement) || (state.search.length === 0 && character === ' ')) {\n return;\n }\n\n // Do not propagate the Spacebar event if it's meant to be part of the search.\n // When we time out, the search term becomes empty, hence the check on length.\n // Trimming is to account for the case of pressing the Spacebar more than once,\n // which should cycle through the selection/deselection of the focused item.\n if (character === ' ' && state.search.trim().length > 0) {\n e.preventDefault();\n if (!('continuePropagation' in e)) {\n e.stopPropagation();\n }\n }\n\n state.search += character;\n\n if (keyboardDelegate.getKeyForSearch != null) {\n // Use the delegate to find a key to focus.\n // Prioritize items after the currently focused item, falling back to searching the whole list.\n let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);\n\n // If no key found, search from the top.\n if (key == null) {\n key = keyboardDelegate.getKeyForSearch(state.search);\n }\n\n if (key != null) {\n selectionManager.setFocusedKey(key);\n if (onTypeSelect) {\n onTypeSelect(key);\n }\n }\n }\n\n clearTimeout(state.timeout);\n state.timeout = setTimeout(() => {\n state.search = '';\n }, TYPEAHEAD_DEBOUNCE_WAIT_MS);\n };\n\n return {\n typeSelectProps: {\n // Using a capturing listener to catch the keydown event before\n // other hooks in order to handle the Spacebar event.\n onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : undefined\n }\n };\n}\n\nfunction getStringForKey(key: string) {\n // If the key is of length 1, it is an ASCII value.\n // Otherwise, if there are no ASCII characters in the key name,\n // it is a Unicode character.\n // See https://www.w3.org/TR/uievents-key/\n if (key.length === 1 || !/^[A-Z]/i.test(key)) {\n return key;\n }\n\n return '';\n}\n"],"names":[],"version":3,"file":"useTypeSelect.module.js.map"}
@@ -1,46 +0,0 @@
1
- var $gP8Dl$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, "isNonContiguousSelectionModifier", () => $ee0bdf4faa47f2a8$export$d3e3bd3e26688c04);
9
- $parcel$export(module.exports, "getItemElement", () => $ee0bdf4faa47f2a8$export$c3d8340acf92597f);
10
- $parcel$export(module.exports, "useCollectionId", () => $ee0bdf4faa47f2a8$export$881eb0d9f3605d9d);
11
- $parcel$export(module.exports, "getCollectionId", () => $ee0bdf4faa47f2a8$export$6aeb1680a0ae8741);
12
- /*
13
- * Copyright 2020 Adobe. All rights reserved.
14
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
15
- * you may not use this file except in compliance with the License. You may obtain a copy
16
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
17
- *
18
- * Unless required by applicable law or agreed to in writing, software distributed under
19
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
20
- * OF ANY KIND, either express or implied. See the License for the specific language
21
- * governing permissions and limitations under the License.
22
- */
23
- function $ee0bdf4faa47f2a8$export$d3e3bd3e26688c04(e) {
24
- // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.
25
- // On Windows and Ubuntu, Alt + Space has a system wide meaning.
26
- return (0, $gP8Dl$reactariautils.isAppleDevice)() ? e.altKey : e.ctrlKey;
27
- }
28
- function $ee0bdf4faa47f2a8$export$c3d8340acf92597f(collectionRef, key) {
29
- var _collectionRef_current, _collectionRef_current1;
30
- let selector = `[data-key="${CSS.escape(String(key))}"]`;
31
- let collection = (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dataset.collection;
32
- if (collection) selector = `[data-collection="${CSS.escape(collection)}"]${selector}`;
33
- return (_collectionRef_current1 = collectionRef.current) === null || _collectionRef_current1 === void 0 ? void 0 : _collectionRef_current1.querySelector(selector);
34
- }
35
- const $ee0bdf4faa47f2a8$var$collectionMap = new WeakMap();
36
- function $ee0bdf4faa47f2a8$export$881eb0d9f3605d9d(collection) {
37
- let id = (0, $gP8Dl$reactariautils.useId)();
38
- $ee0bdf4faa47f2a8$var$collectionMap.set(collection, id);
39
- return id;
40
- }
41
- function $ee0bdf4faa47f2a8$export$6aeb1680a0ae8741(collection) {
42
- return $ee0bdf4faa47f2a8$var$collectionMap.get(collection);
43
- }
44
-
45
-
46
- //# sourceMappingURL=utils.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAYM,SAAS,0CAAiC,CAAQ;IACvD,qFAAqF;IACrF,gEAAgE;IAChE,OAAO,CAAA,GAAA,mCAAY,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO;AAC/C;AAEO,SAAS,0CAAe,aAA4C,EAAE,GAAQ;QAElE,wBAIV;IALP,IAAI,WAAW,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,OAAO,MAAM,EAAE,CAAC;IACxD,IAAI,cAAa,yBAAA,cAAc,OAAO,cAArB,6CAAA,uBAAuB,OAAO,CAAC,UAAU;IAC1D,IAAI,YACF,WAAW,CAAC,kBAAkB,EAAE,IAAI,MAAM,CAAC,YAAY,EAAE,EAAE,UAAU;IAEvE,QAAO,0BAAA,cAAc,OAAO,cAArB,8CAAA,wBAAuB,aAAa,CAAC;AAC9C;AAEA,MAAM,sCAAgB,IAAI;AACnB,SAAS,0CAAgB,UAA2B;IACzD,IAAI,KAAK,CAAA,GAAA,2BAAI;IACb,oCAAc,GAAG,CAAC,YAAY;IAC9B,OAAO;AACT;AAEO,SAAS,0CAAgB,UAA2B;IACzD,OAAO,oCAAc,GAAG,CAAC;AAC3B","sources":["packages/@react-aria/selection/src/utils.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, Key} from '@react-types/shared';\nimport {isAppleDevice, useId} from '@react-aria/utils';\nimport {RefObject} from 'react';\n\ninterface Event {\n altKey: boolean,\n ctrlKey: boolean,\n metaKey: boolean\n}\n\nexport function isNonContiguousSelectionModifier(e: Event): boolean {\n // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.\n // On Windows and Ubuntu, Alt + Space has a system wide meaning.\n return isAppleDevice() ? e.altKey : e.ctrlKey;\n}\n\nexport function getItemElement(collectionRef: RefObject<HTMLElement | null>, key: Key): Element | null | undefined {\n let selector = `[data-key=\"${CSS.escape(String(key))}\"]`;\n let collection = collectionRef.current?.dataset.collection;\n if (collection) {\n selector = `[data-collection=\"${CSS.escape(collection)}\"]${selector}`;\n }\n return collectionRef.current?.querySelector(selector);\n}\n\nconst collectionMap = new WeakMap<Collection<any>, string>();\nexport function useCollectionId(collection: Collection<any>): string {\n let id = useId();\n collectionMap.set(collection, id);\n return id;\n}\n\nexport function getCollectionId(collection: Collection<any>): string {\n return collectionMap.get(collection)!;\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
package/dist/utils.mjs DELETED
@@ -1,38 +0,0 @@
1
- import {isAppleDevice as $jUnAJ$isAppleDevice, useId as $jUnAJ$useId} 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
- function $feb5ffebff200149$export$d3e3bd3e26688c04(e) {
15
- // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.
16
- // On Windows and Ubuntu, Alt + Space has a system wide meaning.
17
- return (0, $jUnAJ$isAppleDevice)() ? e.altKey : e.ctrlKey;
18
- }
19
- function $feb5ffebff200149$export$c3d8340acf92597f(collectionRef, key) {
20
- var _collectionRef_current, _collectionRef_current1;
21
- let selector = `[data-key="${CSS.escape(String(key))}"]`;
22
- let collection = (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dataset.collection;
23
- if (collection) selector = `[data-collection="${CSS.escape(collection)}"]${selector}`;
24
- return (_collectionRef_current1 = collectionRef.current) === null || _collectionRef_current1 === void 0 ? void 0 : _collectionRef_current1.querySelector(selector);
25
- }
26
- const $feb5ffebff200149$var$collectionMap = new WeakMap();
27
- function $feb5ffebff200149$export$881eb0d9f3605d9d(collection) {
28
- let id = (0, $jUnAJ$useId)();
29
- $feb5ffebff200149$var$collectionMap.set(collection, id);
30
- return id;
31
- }
32
- function $feb5ffebff200149$export$6aeb1680a0ae8741(collection) {
33
- return $feb5ffebff200149$var$collectionMap.get(collection);
34
- }
35
-
36
-
37
- export {$feb5ffebff200149$export$d3e3bd3e26688c04 as isNonContiguousSelectionModifier, $feb5ffebff200149$export$c3d8340acf92597f as getItemElement, $feb5ffebff200149$export$881eb0d9f3605d9d as useCollectionId, $feb5ffebff200149$export$6aeb1680a0ae8741 as getCollectionId};
38
- //# sourceMappingURL=utils.module.js.map
@@ -1,38 +0,0 @@
1
- import {isAppleDevice as $jUnAJ$isAppleDevice, useId as $jUnAJ$useId} 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
- function $feb5ffebff200149$export$d3e3bd3e26688c04(e) {
15
- // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.
16
- // On Windows and Ubuntu, Alt + Space has a system wide meaning.
17
- return (0, $jUnAJ$isAppleDevice)() ? e.altKey : e.ctrlKey;
18
- }
19
- function $feb5ffebff200149$export$c3d8340acf92597f(collectionRef, key) {
20
- var _collectionRef_current, _collectionRef_current1;
21
- let selector = `[data-key="${CSS.escape(String(key))}"]`;
22
- let collection = (_collectionRef_current = collectionRef.current) === null || _collectionRef_current === void 0 ? void 0 : _collectionRef_current.dataset.collection;
23
- if (collection) selector = `[data-collection="${CSS.escape(collection)}"]${selector}`;
24
- return (_collectionRef_current1 = collectionRef.current) === null || _collectionRef_current1 === void 0 ? void 0 : _collectionRef_current1.querySelector(selector);
25
- }
26
- const $feb5ffebff200149$var$collectionMap = new WeakMap();
27
- function $feb5ffebff200149$export$881eb0d9f3605d9d(collection) {
28
- let id = (0, $jUnAJ$useId)();
29
- $feb5ffebff200149$var$collectionMap.set(collection, id);
30
- return id;
31
- }
32
- function $feb5ffebff200149$export$6aeb1680a0ae8741(collection) {
33
- return $feb5ffebff200149$var$collectionMap.get(collection);
34
- }
35
-
36
-
37
- export {$feb5ffebff200149$export$d3e3bd3e26688c04 as isNonContiguousSelectionModifier, $feb5ffebff200149$export$c3d8340acf92597f as getItemElement, $feb5ffebff200149$export$881eb0d9f3605d9d as useCollectionId, $feb5ffebff200149$export$6aeb1680a0ae8741 as getCollectionId};
38
- //# sourceMappingURL=utils.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAYM,SAAS,0CAAiC,CAAQ;IACvD,qFAAqF;IACrF,gEAAgE;IAChE,OAAO,CAAA,GAAA,oBAAY,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO;AAC/C;AAEO,SAAS,0CAAe,aAA4C,EAAE,GAAQ;QAElE,wBAIV;IALP,IAAI,WAAW,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,OAAO,MAAM,EAAE,CAAC;IACxD,IAAI,cAAa,yBAAA,cAAc,OAAO,cAArB,6CAAA,uBAAuB,OAAO,CAAC,UAAU;IAC1D,IAAI,YACF,WAAW,CAAC,kBAAkB,EAAE,IAAI,MAAM,CAAC,YAAY,EAAE,EAAE,UAAU;IAEvE,QAAO,0BAAA,cAAc,OAAO,cAArB,8CAAA,wBAAuB,aAAa,CAAC;AAC9C;AAEA,MAAM,sCAAgB,IAAI;AACnB,SAAS,0CAAgB,UAA2B;IACzD,IAAI,KAAK,CAAA,GAAA,YAAI;IACb,oCAAc,GAAG,CAAC,YAAY;IAC9B,OAAO;AACT;AAEO,SAAS,0CAAgB,UAA2B;IACzD,OAAO,oCAAc,GAAG,CAAC;AAC3B","sources":["packages/@react-aria/selection/src/utils.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, Key} from '@react-types/shared';\nimport {isAppleDevice, useId} from '@react-aria/utils';\nimport {RefObject} from 'react';\n\ninterface Event {\n altKey: boolean,\n ctrlKey: boolean,\n metaKey: boolean\n}\n\nexport function isNonContiguousSelectionModifier(e: Event): boolean {\n // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.\n // On Windows and Ubuntu, Alt + Space has a system wide meaning.\n return isAppleDevice() ? e.altKey : e.ctrlKey;\n}\n\nexport function getItemElement(collectionRef: RefObject<HTMLElement | null>, key: Key): Element | null | undefined {\n let selector = `[data-key=\"${CSS.escape(String(key))}\"]`;\n let collection = collectionRef.current?.dataset.collection;\n if (collection) {\n selector = `[data-collection=\"${CSS.escape(collection)}\"]${selector}`;\n }\n return collectionRef.current?.querySelector(selector);\n}\n\nconst collectionMap = new WeakMap<Collection<any>, string>();\nexport function useCollectionId(collection: Collection<any>): string {\n let id = useId();\n collectionMap.set(collection, id);\n return id;\n}\n\nexport function getCollectionId(collection: Collection<any>): string {\n return collectionMap.get(collection)!;\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
@@ -1,61 +0,0 @@
1
- /*
2
- * Copyright 2024 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {getItemElement} from './utils';
14
- import {Key, LayoutDelegate, Rect, RefObject, Size} from '@react-types/shared';
15
-
16
- export class DOMLayoutDelegate implements LayoutDelegate {
17
- private ref: RefObject<HTMLElement | null>;
18
-
19
- constructor(ref: RefObject<HTMLElement | null>) {
20
- this.ref = ref;
21
- }
22
-
23
- getItemRect(key: Key): Rect | null {
24
- let container = this.ref.current;
25
- if (!container) {
26
- return null;
27
- }
28
- let item = key != null ? getItemElement(this.ref, key) : null;
29
- if (!item) {
30
- return null;
31
- }
32
-
33
- let containerRect = container.getBoundingClientRect();
34
- let itemRect = item.getBoundingClientRect();
35
-
36
- return {
37
- x: itemRect.left - containerRect.left - container.clientLeft + container.scrollLeft,
38
- y: itemRect.top - containerRect.top - container.clientTop + container.scrollTop,
39
- width: itemRect.width,
40
- height: itemRect.height
41
- };
42
- }
43
-
44
- getContentSize(): Size {
45
- let container = this.ref.current;
46
- return {
47
- width: container?.scrollWidth ?? 0,
48
- height: container?.scrollHeight ?? 0
49
- };
50
- }
51
-
52
- getVisibleRect(): Rect {
53
- let container = this.ref.current;
54
- return {
55
- x: container?.scrollLeft ?? 0,
56
- y: container?.scrollTop ?? 0,
57
- width: container?.clientWidth ?? 0,
58
- height: container?.clientHeight ?? 0
59
- };
60
- }
61
- }
@@ -1,291 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- import {Collection, Direction, DisabledBehavior, Key, KeyboardDelegate, LayoutDelegate, Node, Orientation, Rect, RefObject} from '@react-types/shared';
14
- import {DOMLayoutDelegate} from './DOMLayoutDelegate';
15
- import {isScrollable} from '@react-aria/utils';
16
-
17
- interface ListKeyboardDelegateOptions<T> {
18
- collection: Collection<Node<T>>,
19
- ref: RefObject<HTMLElement | null>,
20
- collator?: Intl.Collator,
21
- layout?: 'stack' | 'grid',
22
- orientation?: Orientation,
23
- direction?: Direction,
24
- disabledKeys?: Set<Key>,
25
- disabledBehavior?: DisabledBehavior,
26
- layoutDelegate?: LayoutDelegate
27
- }
28
-
29
- export class ListKeyboardDelegate<T> implements KeyboardDelegate {
30
- private collection: Collection<Node<T>>;
31
- private disabledKeys: Set<Key>;
32
- private disabledBehavior: DisabledBehavior;
33
- private ref: RefObject<HTMLElement | null>;
34
- private collator: Intl.Collator | undefined;
35
- private layout: 'stack' | 'grid';
36
- private orientation?: Orientation;
37
- private direction?: Direction;
38
- private layoutDelegate: LayoutDelegate;
39
-
40
- constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement | null>, collator?: Intl.Collator);
41
- constructor(options: ListKeyboardDelegateOptions<T>);
42
- constructor(...args: any[]) {
43
- if (args.length === 1) {
44
- let opts = args[0] as ListKeyboardDelegateOptions<T>;
45
- this.collection = opts.collection;
46
- this.ref = opts.ref;
47
- this.collator = opts.collator;
48
- this.disabledKeys = opts.disabledKeys || new Set();
49
- this.disabledBehavior = opts.disabledBehavior || 'all';
50
- this.orientation = opts.orientation || 'vertical';
51
- this.direction = opts.direction;
52
- this.layout = opts.layout || 'stack';
53
- this.layoutDelegate = opts.layoutDelegate || new DOMLayoutDelegate(opts.ref);
54
- } else {
55
- this.collection = args[0];
56
- this.disabledKeys = args[1];
57
- this.ref = args[2];
58
- this.collator = args[3];
59
- this.layout = 'stack';
60
- this.orientation = 'vertical';
61
- this.disabledBehavior = 'all';
62
- this.layoutDelegate = new DOMLayoutDelegate(this.ref);
63
- }
64
-
65
- // If this is a vertical stack, remove the left/right methods completely
66
- // so they aren't called by useDroppableCollection.
67
- if (this.layout === 'stack' && this.orientation === 'vertical') {
68
- this.getKeyLeftOf = undefined;
69
- this.getKeyRightOf = undefined;
70
- }
71
- }
72
-
73
- private isDisabled(item: Node<unknown>) {
74
- return this.disabledBehavior === 'all' && (item.props?.isDisabled || this.disabledKeys.has(item.key));
75
- }
76
-
77
- private findNextNonDisabled(key: Key | null, getNext: (key: Key) => Key | null): Key | null {
78
- let nextKey = key;
79
- while (nextKey != null) {
80
- let item = this.collection.getItem(nextKey);
81
- if (item?.type === 'item' && !this.isDisabled(item)) {
82
- return nextKey;
83
- }
84
-
85
- nextKey = getNext(nextKey);
86
- }
87
-
88
- return null;
89
- }
90
-
91
- getNextKey(key: Key): Key | null {
92
- let nextKey: Key | null = key;
93
- nextKey = this.collection.getKeyAfter(nextKey);
94
- return this.findNextNonDisabled(nextKey, key => this.collection.getKeyAfter(key));
95
- }
96
-
97
- getPreviousKey(key: Key): Key | null {
98
- let nextKey: Key | null = key;
99
- nextKey = this.collection.getKeyBefore(nextKey);
100
- return this.findNextNonDisabled(nextKey, key => this.collection.getKeyBefore(key));
101
- }
102
-
103
- private findKey(
104
- key: Key,
105
- nextKey: (key: Key) => Key | null,
106
- shouldSkip: (prevRect: Rect, itemRect: Rect) => boolean
107
- ) {
108
- let tempKey: Key | null = key;
109
- let itemRect = this.layoutDelegate.getItemRect(tempKey);
110
- if (!itemRect || tempKey == null) {
111
- return null;
112
- }
113
-
114
- // Find the item above or below in the same column.
115
- let prevRect = itemRect;
116
- do {
117
- tempKey = nextKey(tempKey);
118
- if (tempKey == null) {
119
- break;
120
- }
121
- itemRect = this.layoutDelegate.getItemRect(tempKey);
122
- } while (itemRect && shouldSkip(prevRect, itemRect) && tempKey != null);
123
-
124
- return tempKey;
125
- }
126
-
127
- private isSameRow(prevRect: Rect, itemRect: Rect) {
128
- return prevRect.y === itemRect.y || prevRect.x !== itemRect.x;
129
- }
130
-
131
- private isSameColumn(prevRect: Rect, itemRect: Rect) {
132
- return prevRect.x === itemRect.x || prevRect.y !== itemRect.y;
133
- }
134
-
135
- getKeyBelow(key: Key): Key | null {
136
- if (this.layout === 'grid' && this.orientation === 'vertical') {
137
- return this.findKey(key, (key) => this.getNextKey(key), this.isSameRow);
138
- } else {
139
- return this.getNextKey(key);
140
- }
141
- }
142
-
143
- getKeyAbove(key: Key): Key | null {
144
- if (this.layout === 'grid' && this.orientation === 'vertical') {
145
- return this.findKey(key, (key) => this.getPreviousKey(key), this.isSameRow);
146
- } else {
147
- return this.getPreviousKey(key);
148
- }
149
- }
150
-
151
- private getNextColumn(key: Key, right: boolean) {
152
- return right ? this.getPreviousKey(key) : this.getNextKey(key);
153
- }
154
-
155
- getKeyRightOf?(key: Key): Key | null {
156
- // This is a temporary solution for CardView until we refactor useSelectableCollection.
157
- // https://github.com/orgs/adobe/projects/19/views/32?pane=issue&itemId=77825042
158
- let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyRightOf' : 'getKeyLeftOf';
159
- if (this.layoutDelegate[layoutDelegateMethod]) {
160
- key = this.layoutDelegate[layoutDelegateMethod](key);
161
- return this.findNextNonDisabled(key, key => this.layoutDelegate[layoutDelegateMethod](key));
162
- }
163
-
164
- if (this.layout === 'grid') {
165
- if (this.orientation === 'vertical') {
166
- return this.getNextColumn(key, this.direction === 'rtl');
167
- } else {
168
- return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'rtl'), this.isSameColumn);
169
- }
170
- } else if (this.orientation === 'horizontal') {
171
- return this.getNextColumn(key, this.direction === 'rtl');
172
- }
173
-
174
- return null;
175
- }
176
-
177
- getKeyLeftOf?(key: Key): Key | null {
178
- let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyLeftOf' : 'getKeyRightOf';
179
- if (this.layoutDelegate[layoutDelegateMethod]) {
180
- key = this.layoutDelegate[layoutDelegateMethod](key);
181
- return this.findNextNonDisabled(key, key => this.layoutDelegate[layoutDelegateMethod](key));
182
- }
183
-
184
- if (this.layout === 'grid') {
185
- if (this.orientation === 'vertical') {
186
- return this.getNextColumn(key, this.direction === 'ltr');
187
- } else {
188
- return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'ltr'), this.isSameColumn);
189
- }
190
- } else if (this.orientation === 'horizontal') {
191
- return this.getNextColumn(key, this.direction === 'ltr');
192
- }
193
-
194
- return null;
195
- }
196
-
197
- getFirstKey(): Key | null {
198
- let key = this.collection.getFirstKey();
199
- return this.findNextNonDisabled(key, key => this.collection.getKeyAfter(key));
200
- }
201
-
202
- getLastKey(): Key | null {
203
- let key = this.collection.getLastKey();
204
- return this.findNextNonDisabled(key, key => this.collection.getKeyBefore(key));
205
- }
206
-
207
- getKeyPageAbove(key: Key): Key | null {
208
- let menu = this.ref.current;
209
- let itemRect = this.layoutDelegate.getItemRect(key);
210
- if (!itemRect) {
211
- return null;
212
- }
213
-
214
- if (menu && !isScrollable(menu)) {
215
- return this.getFirstKey();
216
- }
217
-
218
- let nextKey: Key | null = key;
219
- if (this.orientation === 'horizontal') {
220
- let pageX = Math.max(0, itemRect.x + itemRect.width - this.layoutDelegate.getVisibleRect().width);
221
-
222
- while (itemRect && itemRect.x > pageX && nextKey != null) {
223
- nextKey = this.getKeyAbove(nextKey);
224
- itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);
225
- }
226
- } else {
227
- let pageY = Math.max(0, itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height);
228
-
229
- while (itemRect && itemRect.y > pageY && nextKey != null) {
230
- nextKey = this.getKeyAbove(nextKey);
231
- itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);
232
- }
233
- }
234
-
235
- return nextKey ?? this.getFirstKey();
236
- }
237
-
238
- getKeyPageBelow(key: Key): Key | null {
239
- let menu = this.ref.current;
240
- let itemRect = this.layoutDelegate.getItemRect(key);
241
- if (!itemRect) {
242
- return null;
243
- }
244
-
245
- if (menu && !isScrollable(menu)) {
246
- return this.getLastKey();
247
- }
248
-
249
- let nextKey: Key | null = key;
250
- if (this.orientation === 'horizontal') {
251
- let pageX = Math.min(this.layoutDelegate.getContentSize().width, itemRect.y - itemRect.width + this.layoutDelegate.getVisibleRect().width);
252
-
253
- while (itemRect && itemRect.x < pageX && nextKey != null) {
254
- nextKey = this.getKeyBelow(nextKey);
255
- itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);
256
- }
257
- } else {
258
- let pageY = Math.min(this.layoutDelegate.getContentSize().height, itemRect.y - itemRect.height + this.layoutDelegate.getVisibleRect().height);
259
-
260
- while (itemRect && itemRect.y < pageY && nextKey != null) {
261
- nextKey = this.getKeyBelow(nextKey);
262
- itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);
263
- }
264
- }
265
-
266
- return nextKey ?? this.getLastKey();
267
- }
268
-
269
- getKeyForSearch(search: string, fromKey?: Key): Key | null {
270
- if (!this.collator) {
271
- return null;
272
- }
273
-
274
- let collection = this.collection;
275
- let key = fromKey || this.getFirstKey();
276
- while (key != null) {
277
- let item = collection.getItem(key);
278
- if (!item) {
279
- return null;
280
- }
281
- let substring = item.textValue.slice(0, search.length);
282
- if (item.textValue && this.collator.compare(substring, search) === 0) {
283
- return key;
284
- }
285
-
286
- key = this.getNextKey(key);
287
- }
288
-
289
- return null;
290
- }
291
- }