Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

@react-stately/selection

Package Overview
Dependencies
Maintainers
2
Versions
1305
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-stately/selection - npm Package Compare versions

Comparing version
3.3.0
to
3.4.0
+19
-3
dist/main.js

@@ -57,2 +57,3 @@ var {

let focusedKeyRef = useRef(null);
let childFocusStrategyRef = useRef(null);
let [, setFocusedKey] = useState(null);

@@ -80,4 +81,13 @@ let selectedKeysProp = useMemo(() => $e792d6adfd95a7ce87c6dd8b719ea117$var$convertSelection(props.selectedKeys), [props.selectedKeys]);

setFocusedKey(k) {
get childFocusStrategy() {
return childFocusStrategyRef.current;
},
setFocusedKey(k, childFocusStrategy) {
if (childFocusStrategy === void 0) {
childFocusStrategy = 'first';
}
focusedKeyRef.current = k;
childFocusStrategyRef.current = childFocusStrategy;
setFocusedKey(k);

@@ -158,2 +168,8 @@ },

}
/** Whether the first or last child of the focused key should receive focus. */
get childFocusStrategy() {
return this.state.childFocusStrategy;
}
/**

@@ -164,4 +180,4 @@ * Sets the focused key.

setFocusedKey(key) {
this.state.setFocusedKey(key);
setFocusedKey(key, childFocusStrategy) {
this.state.setFocusedKey(key, childFocusStrategy);
}

@@ -168,0 +184,0 @@ /**

+1
-1

@@ -1,1 +0,1 @@

{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;;;AAcA;;;;AAIO,MAAMA,gDAAN,SAAwBC,GAAxB,CAAiC;AAItCC,EAAAA,WAAW,CAACC,IAAD,EAAmCC,SAAnC,EAAoDC,UAApD,EAAsE;AAC/E,UAAMF,IAAN;AAD+E,SAHjFC,SAGiF;AAAA,SAFjFC,UAEiF;;AAE/E,QAAIF,IAAI,YAAYH,gDAApB,EAA+B;AAC7B,WAAKI,SAAL,GAAiBA,SAAS,IAAID,IAAI,CAACC,SAAnC;AACA,WAAKC,UAAL,GAAkBA,UAAU,IAAIF,IAAI,CAAC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,EAAqC;AACnC,UAAI,KAAKiC,UAAL,CAAgBF,GAAhB,KAAwB,CAAC,KAAK9B,sBAAlC,EAA0D;AACxD,aAAK6D,eAAL,CAAqB/B,GAArB;AACD,OAFD,MAEO;AACL,aAAKgC,gBAAL,CAAsBhC,GAAtB;AACD;AACF,KAND,MAMO,IAAIyC,CAAC,IAAIA,CAAC,CAACC,QAAX,EAAqB;AAC1B,WAAKzB,eAAL,CAAqBjB,GAArB;AACD,KAFM,MAEA;AACL,WAAK+B,eAAL,CAAqB/B,GAArB;AACD;AACF;;AAhU+D","sources":["./packages/@react-stately/selection/src/Selection.ts","./packages/@react-stately/selection/src/useMultipleSelectionState.ts","./packages/@react-stately/selection/src/SelectionManager.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 {Key} from 'react';\n\n/**\n * A Selection is a special Set containing Keys, which also has an anchor\n * and current selected key for use when range selecting.\n */\nexport class Selection extends Set<Key> {\n anchorKey: Key;\n currentKey: Key;\n\n constructor(keys?: Iterable<Key> | Selection, anchorKey?: Key, currentKey?: Key) {\n super(keys);\n if (keys instanceof Selection) {\n this.anchorKey = anchorKey || keys.anchorKey;\n this.currentKey = currentKey || keys.currentKey;\n } else {\n this.anchorKey = anchorKey;\n this.currentKey = currentKey;\n }\n }\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Key, useMemo, useRef, useState} from 'react';\nimport {MultipleSelection, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(props: MultipleSelection): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection\n } = props;\n\n // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.\n // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).\n let isFocusedRef = useRef(false);\n let [, setFocused] = useState(false);\n let focusedKeyRef = useRef(null);\n let [, setFocusedKey] = useState(null);\n let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);\n let defaultSelectedKeys = useMemo(() => convertSelection(props.defaultSelectedKeys, new Selection()), [props.defaultSelectedKeys]);\n let [selectedKeys, setSelectedKeys] = useControlledState(\n selectedKeysProp,\n defaultSelectedKeys,\n props.onSelectionChange\n );\n let disabledKeysProp = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n return {\n selectionMode,\n disallowEmptySelection,\n get isFocused() {\n return isFocusedRef.current;\n },\n setFocused(f) {\n isFocusedRef.current = f;\n setFocused(f);\n },\n get focusedKey() {\n return focusedKeyRef.current;\n },\n setFocusedKey(k) {\n focusedKeyRef.current = k;\n setFocusedKey(k);\n },\n selectedKeys,\n setSelectedKeys,\n disabledKeys: disabledKeysProp\n };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Selection {\n if (!selection) {\n return defaultValue;\n }\n\n return selection === 'all'\n ? 'all'\n : new Selection(selection);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node, PressEvent, SelectionMode} from '@react-types/shared';\nimport {Key} from 'react';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n private collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean;\n\n constructor(collection: Collection<Node<unknown>>, state: MultipleSelectionState, options?: SelectionManagerOptions) {\n this.collection = collection;\n this.state = state;\n this.allowsCellSelection = options?.allowsCellSelection ?? false;\n this._isSelectAll = null;\n }\n\n /**\n * The type of selection that is allowed in the collection.\n */\n get selectionMode(): SelectionMode {\n return this.state.selectionMode;\n }\n\n /**\n * Whether the collection allows empty selection.\n */\n get disallowEmptySelection(): boolean {\n return this.state.disallowEmptySelection;\n }\n\n /**\n * Whether the collection is currently focused.\n */\n get isFocused(): boolean {\n return this.state.isFocused;\n }\n\n /**\n * Sets whether the collection is focused.\n */\n setFocused(isFocused: boolean) {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key {\n return this.state.focusedKey;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key) {\n this.state.setFocusedKey(key);\n }\n\n /**\n * The currently selected keys in the collection.\n */\n get selectedKeys(): Set<Key> {\n return this.state.selectedKeys === 'all'\n ? new Set(this.getSelectAllKeys())\n : this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key) {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n key = this.getKey(key);\n return this.state.selectedKeys === 'all' || this.state.selectedKeys.has(key);\n }\n\n /**\n * Whether the selection is empty.\n */\n get isEmpty(): boolean {\n return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n }\n\n /**\n * Whether all items in the collection are selected.\n */\n get isSelectAll(): boolean {\n if (this.isEmpty) {\n return false;\n }\n\n if (this.state.selectedKeys === 'all') {\n return true;\n }\n\n if (this._isSelectAll != null) {\n return this._isSelectAll;\n }\n\n let allKeys = this.getSelectAllKeys();\n let selectedKeys = this.state.selectedKeys;\n this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n return this._isSelectAll;\n }\n\n get firstSelectedKey(): Key | null {\n let first: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!first || item?.index < first.index) {\n first = item;\n }\n }\n\n return first?.key;\n }\n\n get lastSelectedKey(): Key | null {\n let last: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!last || item?.index > last.index) {\n last = item;\n }\n }\n\n return last?.key;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key) {\n toKey = this.getKey(toKey);\n this.state.setSelectedKeys(selectedKeys => {\n // Only select the one key if coming from a select all.\n if (selectedKeys === 'all') {\n return new Selection([toKey], toKey, toKey);\n }\n\n let selection = selectedKeys as Selection;\n let anchorKey = selection.anchorKey || toKey;\n let keys = new Selection(selection, anchorKey, toKey);\n for (let key of this.getKeyRange(anchorKey, selection.currentKey || toKey)) {\n keys.delete(key);\n }\n\n for (let key of this.getKeyRange(toKey, anchorKey)) {\n if (!this.state.disabledKeys.has(key)) {\n keys.add(key);\n }\n }\n\n return keys;\n });\n }\n\n private getKeyRange(from: Key, to: Key) {\n let fromItem = this.collection.getItem(from);\n let toItem = this.collection.getItem(to);\n if (fromItem && toItem) {\n if (fromItem.index <= toItem.index) {\n return this.getKeyRangeInternal(from, to);\n }\n\n return this.getKeyRangeInternal(to, from);\n }\n\n return [];\n }\n\n private getKeyRangeInternal(from: Key, to: Key) {\n let keys: Key[] = [];\n let key = from;\n while (key) {\n let item = this.collection.getItem(key);\n if (item && item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection)) {\n keys.push(key);\n }\n\n if (key === to) {\n return keys;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return [];\n }\n\n private getKey(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n // ¯\\_(ツ)_/¯\n return key;\n }\n\n // If cell selection is allowed, just return the key.\n if (item.type === 'cell' && this.allowsCellSelection) {\n return key;\n }\n\n // Find a parent item to select\n while (item.type !== 'item' && item.parentKey) {\n item = this.collection.getItem(item.parentKey);\n }\n\n if (!item || item.type !== 'item') {\n return null;\n }\n\n return item.key;\n }\n\n /**\n * Toggles whether the given key is selected.\n */\n toggleSelection(key: Key) {\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(selectedKeys => {\n let keys = new Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : selectedKeys);\n if (keys.has(key)) {\n keys.delete(key);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else {\n keys.add(key);\n keys.anchorKey = key;\n keys.currentKey = key;\n }\n\n return keys;\n });\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key) {\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(new Selection([key], key, key));\n }\n\n private getSelectAllKeys() {\n let keys: Key[] = [];\n let addKeys = (key: Key) => {\n while (key) {\n if (!this.state.disabledKeys.has(key)) {\n let item = this.collection.getItem(key);\n if (item.type === 'item') {\n keys.push(key);\n }\n\n // Add child keys. If cell selection is allowed, then include item children too.\n if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n addKeys([...item.childNodes][0].key);\n }\n }\n\n key = this.collection.getKeyAfter(key);\n }\n };\n\n addKeys(this.collection.getFirstKey());\n return keys;\n }\n\n /**\n * Selects all items in the collection.\n */\n selectAll() {\n if (this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection() {\n if (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0) {\n this.state.setSelectedKeys(new Selection());\n }\n }\n\n /**\n * Toggles between select all and an empty selection.\n */\n toggleSelectAll() {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | PointerEvent) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n if (this.isSelected(key) && !this.disallowEmptySelection) {\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n } else if (e && e.shiftKey) {\n this.extendSelection(key);\n } else {\n this.toggleSelection(key);\n }\n }\n}\n"],"names":["Selection","Set","constructor","keys","anchorKey","currentKey","useMultipleSelectionState","props","selectionMode","disallowEmptySelection","isFocusedRef","useRef","setFocused","useState","focusedKeyRef","setFocusedKey","selectedKeysProp","useMemo","convertSelection","selectedKeys","defaultSelectedKeys","setSelectedKeys","useControlledState","onSelectionChange","disabledKeysProp","disabledKeys","isFocused","current","f","focusedKey","k","selection","defaultValue","SelectionManager","collection","state","options","allowsCellSelection","_isSelectAll","key","getSelectAllKeys","isSelected","getKey","has","isEmpty","size","isSelectAll","allKeys","every","firstSelectedKey","first","item","getItem","index","lastSelectedKey","last","extendSelection","toKey","getKeyRange","delete","add","from","to","fromItem","toItem","getKeyRangeInternal","type","push","getKeyAfter","parentKey","toggleSelection","replaceSelection","addKeys","hasChildNodes","childNodes","getFirstKey","selectAll","clearSelection","toggleSelectAll","select","e","shiftKey"],"version":3,"file":"main.js.map"}
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;;;AAcA;;;;AAIO,MAAMA,gDAAN,SAAwBC,GAAxB,CAAiC;AAItCC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1E,IAAP;AACD;AAED;;;;;AAGA2E,EAAAA,SAAS,GAAG;AACV,QAAI,KAAKtE,aAAL,KAAuB,UAA3B,EAAuC;AACrC,WAAK6B,KAAL,CAAWf,eAAX,CAA2B,KAA3B;AACD;AACF;AAED;;;;;AAGAyD,EAAAA,cAAc,GAAG;AACf,QAAI,KAAK1C,KAAL,CAAWjB,YAAX,KAA4B,KAA5B,IAAqC,KAAKiB,KAAL,CAAWjB,YAAX,CAAwB2B,IAAxB,GAA+B,CAAxE,EAA2E;AACzE,WAAKV,KAAL,CAAWf,eAAX,CAA2B,sDAA3B;AACD;AACF;AAED;;;;;AAGA0D,EAAAA,eAAe,GAAG;AAChB,QAAI,KAAKhC,WAAT,EAAsB;AACpB,WAAK+B,cAAL;AACD,KAFD,MAEO;AACL,WAAKD,SAAL;AACD;AACF;;AAEDG,EAAAA,MAAM,CAACxC,GAAD,EAAWyC,CAAX,EAA0C;AAC9C,QAAI,KAAK1E,aAAL,KAAuB,MAA3B,EAAmC;AACjC;AACD;;AAED,QAAI,KAAKA,aAAL,KAAuB,QAA3B,EAAqC;AACnC,UAAI,KAAKmC,UAAL,CAAgBF,GAAhB,KAAwB,CAAC,KAAKhC,sBAAlC,EAA0D;AACxD,aAAK+D,eAAL,CAAqB/B,GAArB;AACD,OAFD,MAEO;AACL,aAAKgC,gBAAL,CAAsBhC,GAAtB;AACD;AACF,KAND,MAMO,IAAIyC,CAAC,IAAIA,CAAC,CAACC,QAAX,EAAqB;AAC1B,WAAKzB,eAAL,CAAqBjB,GAArB;AACD,KAFM,MAEA;AACL,WAAK+B,eAAL,CAAqB/B,GAArB;AACD;AACF;;AArU+D","sources":["./packages/@react-stately/selection/src/Selection.ts","./packages/@react-stately/selection/src/useMultipleSelectionState.ts","./packages/@react-stately/selection/src/SelectionManager.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 {Key} from 'react';\n\n/**\n * A Selection is a special Set containing Keys, which also has an anchor\n * and current selected key for use when range selecting.\n */\nexport class Selection extends Set<Key> {\n anchorKey: Key;\n currentKey: Key;\n\n constructor(keys?: Iterable<Key> | Selection, anchorKey?: Key, currentKey?: Key) {\n super(keys);\n if (keys instanceof Selection) {\n this.anchorKey = anchorKey || keys.anchorKey;\n this.currentKey = currentKey || keys.currentKey;\n } else {\n this.anchorKey = anchorKey;\n this.currentKey = currentKey;\n }\n }\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Key, useMemo, useRef, useState} from 'react';\nimport {MultipleSelection, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(props: MultipleSelection): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection\n } = props;\n\n // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.\n // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).\n let isFocusedRef = useRef(false);\n let [, setFocused] = useState(false);\n let focusedKeyRef = useRef(null);\n let childFocusStrategyRef = useRef(null);\n let [, setFocusedKey] = useState(null);\n let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);\n let defaultSelectedKeys = useMemo(() => convertSelection(props.defaultSelectedKeys, new Selection()), [props.defaultSelectedKeys]);\n let [selectedKeys, setSelectedKeys] = useControlledState(\n selectedKeysProp,\n defaultSelectedKeys,\n props.onSelectionChange\n );\n let disabledKeysProp = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n return {\n selectionMode,\n disallowEmptySelection,\n get isFocused() {\n return isFocusedRef.current;\n },\n setFocused(f) {\n isFocusedRef.current = f;\n setFocused(f);\n },\n get focusedKey() {\n return focusedKeyRef.current;\n },\n get childFocusStrategy() {\n return childFocusStrategyRef.current;\n },\n setFocusedKey(k, childFocusStrategy = 'first') {\n focusedKeyRef.current = k;\n childFocusStrategyRef.current = childFocusStrategy;\n setFocusedKey(k);\n },\n selectedKeys,\n setSelectedKeys,\n disabledKeys: disabledKeysProp\n };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Selection {\n if (!selection) {\n return defaultValue;\n }\n\n return selection === 'all'\n ? 'all'\n : new Selection(selection);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, FocusStrategy, Node, PressEvent, SelectionMode} from '@react-types/shared';\nimport {Key} from 'react';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n private collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean;\n\n constructor(collection: Collection<Node<unknown>>, state: MultipleSelectionState, options?: SelectionManagerOptions) {\n this.collection = collection;\n this.state = state;\n this.allowsCellSelection = options?.allowsCellSelection ?? false;\n this._isSelectAll = null;\n }\n\n /**\n * The type of selection that is allowed in the collection.\n */\n get selectionMode(): SelectionMode {\n return this.state.selectionMode;\n }\n\n /**\n * Whether the collection allows empty selection.\n */\n get disallowEmptySelection(): boolean {\n return this.state.disallowEmptySelection;\n }\n\n /**\n * Whether the collection is currently focused.\n */\n get isFocused(): boolean {\n return this.state.isFocused;\n }\n\n /**\n * Sets whether the collection is focused.\n */\n setFocused(isFocused: boolean) {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key {\n return this.state.focusedKey;\n }\n\n /** Whether the first or last child of the focused key should receive focus. */\n get childFocusStrategy(): FocusStrategy {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key, childFocusStrategy?: FocusStrategy) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\n\n /**\n * The currently selected keys in the collection.\n */\n get selectedKeys(): Set<Key> {\n return this.state.selectedKeys === 'all'\n ? new Set(this.getSelectAllKeys())\n : this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key) {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n key = this.getKey(key);\n return this.state.selectedKeys === 'all' || this.state.selectedKeys.has(key);\n }\n\n /**\n * Whether the selection is empty.\n */\n get isEmpty(): boolean {\n return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n }\n\n /**\n * Whether all items in the collection are selected.\n */\n get isSelectAll(): boolean {\n if (this.isEmpty) {\n return false;\n }\n\n if (this.state.selectedKeys === 'all') {\n return true;\n }\n\n if (this._isSelectAll != null) {\n return this._isSelectAll;\n }\n\n let allKeys = this.getSelectAllKeys();\n let selectedKeys = this.state.selectedKeys;\n this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n return this._isSelectAll;\n }\n\n get firstSelectedKey(): Key | null {\n let first: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!first || item?.index < first.index) {\n first = item;\n }\n }\n\n return first?.key;\n }\n\n get lastSelectedKey(): Key | null {\n let last: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!last || item?.index > last.index) {\n last = item;\n }\n }\n\n return last?.key;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key) {\n toKey = this.getKey(toKey);\n this.state.setSelectedKeys(selectedKeys => {\n // Only select the one key if coming from a select all.\n if (selectedKeys === 'all') {\n return new Selection([toKey], toKey, toKey);\n }\n\n let selection = selectedKeys as Selection;\n let anchorKey = selection.anchorKey || toKey;\n let keys = new Selection(selection, anchorKey, toKey);\n for (let key of this.getKeyRange(anchorKey, selection.currentKey || toKey)) {\n keys.delete(key);\n }\n\n for (let key of this.getKeyRange(toKey, anchorKey)) {\n if (!this.state.disabledKeys.has(key)) {\n keys.add(key);\n }\n }\n\n return keys;\n });\n }\n\n private getKeyRange(from: Key, to: Key) {\n let fromItem = this.collection.getItem(from);\n let toItem = this.collection.getItem(to);\n if (fromItem && toItem) {\n if (fromItem.index <= toItem.index) {\n return this.getKeyRangeInternal(from, to);\n }\n\n return this.getKeyRangeInternal(to, from);\n }\n\n return [];\n }\n\n private getKeyRangeInternal(from: Key, to: Key) {\n let keys: Key[] = [];\n let key = from;\n while (key) {\n let item = this.collection.getItem(key);\n if (item && item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection)) {\n keys.push(key);\n }\n\n if (key === to) {\n return keys;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return [];\n }\n\n private getKey(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n // ¯\\_(ツ)_/¯\n return key;\n }\n\n // If cell selection is allowed, just return the key.\n if (item.type === 'cell' && this.allowsCellSelection) {\n return key;\n }\n\n // Find a parent item to select\n while (item.type !== 'item' && item.parentKey) {\n item = this.collection.getItem(item.parentKey);\n }\n\n if (!item || item.type !== 'item') {\n return null;\n }\n\n return item.key;\n }\n\n /**\n * Toggles whether the given key is selected.\n */\n toggleSelection(key: Key) {\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(selectedKeys => {\n let keys = new Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : selectedKeys);\n if (keys.has(key)) {\n keys.delete(key);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else {\n keys.add(key);\n keys.anchorKey = key;\n keys.currentKey = key;\n }\n\n return keys;\n });\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key) {\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(new Selection([key], key, key));\n }\n\n private getSelectAllKeys() {\n let keys: Key[] = [];\n let addKeys = (key: Key) => {\n while (key) {\n if (!this.state.disabledKeys.has(key)) {\n let item = this.collection.getItem(key);\n if (item.type === 'item') {\n keys.push(key);\n }\n\n // Add child keys. If cell selection is allowed, then include item children too.\n if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n addKeys([...item.childNodes][0].key);\n }\n }\n\n key = this.collection.getKeyAfter(key);\n }\n };\n\n addKeys(this.collection.getFirstKey());\n return keys;\n }\n\n /**\n * Selects all items in the collection.\n */\n selectAll() {\n if (this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection() {\n if (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0) {\n this.state.setSelectedKeys(new Selection());\n }\n }\n\n /**\n * Toggles between select all and an empty selection.\n */\n toggleSelectAll() {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | PointerEvent) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n if (this.isSelected(key) && !this.disallowEmptySelection) {\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n } else if (e && e.shiftKey) {\n this.extendSelection(key);\n } else {\n this.toggleSelection(key);\n }\n }\n}\n"],"names":["Selection","Set","constructor","keys","anchorKey","currentKey","useMultipleSelectionState","props","selectionMode","disallowEmptySelection","isFocusedRef","useRef","setFocused","useState","focusedKeyRef","childFocusStrategyRef","setFocusedKey","selectedKeysProp","useMemo","convertSelection","selectedKeys","defaultSelectedKeys","setSelectedKeys","useControlledState","onSelectionChange","disabledKeysProp","disabledKeys","isFocused","current","f","focusedKey","childFocusStrategy","k","selection","defaultValue","SelectionManager","collection","state","options","allowsCellSelection","_isSelectAll","key","getSelectAllKeys","isSelected","getKey","has","isEmpty","size","isSelectAll","allKeys","every","firstSelectedKey","first","item","getItem","index","lastSelectedKey","last","extendSelection","toKey","getKeyRange","delete","add","from","to","fromItem","toItem","getKeyRangeInternal","type","push","getKeyAfter","parentKey","toggleSelection","replaceSelection","addKeys","hasChildNodes","childNodes","getFirstKey","selectAll","clearSelection","toggleSelectAll","select","e","shiftKey"],"version":3,"file":"main.js.map"}

@@ -50,2 +50,3 @@ import { useControlledState } from "@react-stately/utils";

let focusedKeyRef = useRef(null);
let childFocusStrategyRef = useRef(null);
let [, setFocusedKey] = useState(null);

@@ -73,4 +74,13 @@ let selectedKeysProp = useMemo(() => $c86d35e876e048ac11515eee40c7$var$convertSelection(props.selectedKeys), [props.selectedKeys]);

setFocusedKey(k) {
get childFocusStrategy() {
return childFocusStrategyRef.current;
},
setFocusedKey(k, childFocusStrategy) {
if (childFocusStrategy === void 0) {
childFocusStrategy = 'first';
}
focusedKeyRef.current = k;
childFocusStrategyRef.current = childFocusStrategy;
setFocusedKey(k);

@@ -149,2 +159,8 @@ },

}
/** Whether the first or last child of the focused key should receive focus. */
get childFocusStrategy() {
return this.state.childFocusStrategy;
}
/**

@@ -155,4 +171,4 @@ * Sets the focused key.

setFocusedKey(key) {
this.state.setFocusedKey(key);
setFocusedKey(key, childFocusStrategy) {
this.state.setFocusedKey(key, childFocusStrategy);
}

@@ -159,0 +175,0 @@ /**

@@ -1,1 +0,1 @@

{"mappings":";;;AAAA;;;;;;;;;;;;AAcA;;;;AAIO,MAAMA,gDAAN,SAAwBC,GAAxB,CAAiC;AAItCC,EAAAA,WAAW,CAACC,IAAD,EAAmCC,SAAnC,EAAoDC,UAApD,EAAsE;AAC/E,UAAMF,IAAN;AAD+E,SAHjFC,SAGiF;AAAA,SAFjFC,UAEiF;;AAE/E,QAAIF,IAAI,YAAYH,gDAApB,EAA+B;AAC7B,WAAKI,SAAL,GAAiBA,SAAS,IAAID,IAAI,CAACC,SAAnC;AACA,WAAKC,UAAL,GAAkBA,UAAU,IAAIF,IAAI,CAACE,UAArC;AACD,KAHD,MAGO;AACL,WAAKD,SAAL,GAAiBA,SAAjB;AACA,WAAKC,UAAL,GAAkBA,UAAlB;AACD;AACF;;AAbqC;;ACAxC;;;OAGO,SAASC,yBAAT,CAAmCC,KAAnC,EAAqF;AAC1F,MAAI;AACFC,IAAAA,aAAa,GAAG,MADd;AAEFC,IAAAA;AAFE,MAGAF,KAHJ,CAD0F,CAM1F;AACA;;AACA,MAAIG,YAAY,GAAGC,MAAM,CAAC,KAAD,CAAzB;AACA,MAAI,GAAGC,UAAH,IAAiBC,QAAQ,CAAC,KAAD,CAA7B;AACA,MAAIC,aAAa,GAAGH,MAAM,CAAC,IAAD,CAA1B;AACA,MAAI,GAAGI,aAAH,IAAoBF,QAAQ,CAAC,IAAD,CAAhC;AACA,MAAIG,gBAAgB,GAAGC,OAAO,CAAC,MAAMC,kDAAgB,CAACX,KAAK,CAACY,YAAP,CAAvB,EAA6C,CAACZ,KAAK,CAACY,YAAP,CAA7C,CAA9B;AACA,MAAIC,mBAAmB,GA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AuB,UAA3B,EAAuC;AACrC,WAAK2B,KAAL,CAAWd,eAAX,CAA2B,KAA3B;AACD;AACF;AAED;;;;;AAGAwD,EAAAA,cAAc,GAAG;AACf,QAAI,KAAK1C,KAAL,CAAWhB,YAAX,KAA4B,KAA5B,IAAqC,KAAKgB,KAAL,CAAWhB,YAAX,CAAwB0B,IAAxB,GAA+B,CAAxE,EAA2E;AACzE,WAAKV,KAAL,CAAWd,eAAX,CAA2B,sDAA3B;AACD;AACF;AAED;;;;;AAGAyD,EAAAA,eAAe,GAAG;AAChB,QAAI,KAAKhC,WAAT,EAAsB;AACpB,WAAK+B,cAAL;AACD,KAFD,MAEO;AACL,WAAKD,SAAL;AACD;AACF;;AAEDG,EAAAA,MAAM,CAACxC,GAAD,EAAWyC,CAAX,EAA0C;AAC9C,QAAI,KAAKxE,aAAL,KAAuB,MAA3B,EAAmC;AACjC;AACD;;AAED,QAAI,KAAKA,aAAL,KAAuB,QAA3B,EAAqC;AACnC,UAAI,KAAKiC,UAAL,CAAgBF,GAAhB,KAAwB,CAAC,KAAK9B,sBAAlC,EAA0D;AACxD,aAAK6D,eAAL,CAAqB/B,GAArB;AACD,OAFD,MAEO;AACL,aAAKgC,gBAAL,CAAsBhC,GAAtB;AACD;AACF,KAND,MAMO,IAAIyC,CAAC,IAAIA,CAAC,CAACC,QAAX,EAAqB;AAC1B,WAAKzB,eAAL,CAAqBjB,GAArB;AACD,KAFM,MAEA;AACL,WAAK+B,eAAL,CAAqB/B,GAArB;AACD;AACF;;AAhU+D","sources":["./packages/@react-stately/selection/src/Selection.ts","./packages/@react-stately/selection/src/useMultipleSelectionState.ts","./packages/@react-stately/selection/src/SelectionManager.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 {Key} from 'react';\n\n/**\n * A Selection is a special Set containing Keys, which also has an anchor\n * and current selected key for use when range selecting.\n */\nexport class Selection extends Set<Key> {\n anchorKey: Key;\n currentKey: Key;\n\n constructor(keys?: Iterable<Key> | Selection, anchorKey?: Key, currentKey?: Key) {\n super(keys);\n if (keys instanceof Selection) {\n this.anchorKey = anchorKey || keys.anchorKey;\n this.currentKey = currentKey || keys.currentKey;\n } else {\n this.anchorKey = anchorKey;\n this.currentKey = currentKey;\n }\n }\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Key, useMemo, useRef, useState} from 'react';\nimport {MultipleSelection, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(props: MultipleSelection): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection\n } = props;\n\n // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.\n // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).\n let isFocusedRef = useRef(false);\n let [, setFocused] = useState(false);\n let focusedKeyRef = useRef(null);\n let [, setFocusedKey] = useState(null);\n let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);\n let defaultSelectedKeys = useMemo(() => convertSelection(props.defaultSelectedKeys, new Selection()), [props.defaultSelectedKeys]);\n let [selectedKeys, setSelectedKeys] = useControlledState(\n selectedKeysProp,\n defaultSelectedKeys,\n props.onSelectionChange\n );\n let disabledKeysProp = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n return {\n selectionMode,\n disallowEmptySelection,\n get isFocused() {\n return isFocusedRef.current;\n },\n setFocused(f) {\n isFocusedRef.current = f;\n setFocused(f);\n },\n get focusedKey() {\n return focusedKeyRef.current;\n },\n setFocusedKey(k) {\n focusedKeyRef.current = k;\n setFocusedKey(k);\n },\n selectedKeys,\n setSelectedKeys,\n disabledKeys: disabledKeysProp\n };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Selection {\n if (!selection) {\n return defaultValue;\n }\n\n return selection === 'all'\n ? 'all'\n : new Selection(selection);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Node, PressEvent, SelectionMode} from '@react-types/shared';\nimport {Key} from 'react';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n private collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean;\n\n constructor(collection: Collection<Node<unknown>>, state: MultipleSelectionState, options?: SelectionManagerOptions) {\n this.collection = collection;\n this.state = state;\n this.allowsCellSelection = options?.allowsCellSelection ?? false;\n this._isSelectAll = null;\n }\n\n /**\n * The type of selection that is allowed in the collection.\n */\n get selectionMode(): SelectionMode {\n return this.state.selectionMode;\n }\n\n /**\n * Whether the collection allows empty selection.\n */\n get disallowEmptySelection(): boolean {\n return this.state.disallowEmptySelection;\n }\n\n /**\n * Whether the collection is currently focused.\n */\n get isFocused(): boolean {\n return this.state.isFocused;\n }\n\n /**\n * Sets whether the collection is focused.\n */\n setFocused(isFocused: boolean) {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key {\n return this.state.focusedKey;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key) {\n this.state.setFocusedKey(key);\n }\n\n /**\n * The currently selected keys in the collection.\n */\n get selectedKeys(): Set<Key> {\n return this.state.selectedKeys === 'all'\n ? new Set(this.getSelectAllKeys())\n : this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key) {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n key = this.getKey(key);\n return this.state.selectedKeys === 'all' || this.state.selectedKeys.has(key);\n }\n\n /**\n * Whether the selection is empty.\n */\n get isEmpty(): boolean {\n return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n }\n\n /**\n * Whether all items in the collection are selected.\n */\n get isSelectAll(): boolean {\n if (this.isEmpty) {\n return false;\n }\n\n if (this.state.selectedKeys === 'all') {\n return true;\n }\n\n if (this._isSelectAll != null) {\n return this._isSelectAll;\n }\n\n let allKeys = this.getSelectAllKeys();\n let selectedKeys = this.state.selectedKeys;\n this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n return this._isSelectAll;\n }\n\n get firstSelectedKey(): Key | null {\n let first: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!first || item?.index < first.index) {\n first = item;\n }\n }\n\n return first?.key;\n }\n\n get lastSelectedKey(): Key | null {\n let last: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!last || item?.index > last.index) {\n last = item;\n }\n }\n\n return last?.key;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key) {\n toKey = this.getKey(toKey);\n this.state.setSelectedKeys(selectedKeys => {\n // Only select the one key if coming from a select all.\n if (selectedKeys === 'all') {\n return new Selection([toKey], toKey, toKey);\n }\n\n let selection = selectedKeys as Selection;\n let anchorKey = selection.anchorKey || toKey;\n let keys = new Selection(selection, anchorKey, toKey);\n for (let key of this.getKeyRange(anchorKey, selection.currentKey || toKey)) {\n keys.delete(key);\n }\n\n for (let key of this.getKeyRange(toKey, anchorKey)) {\n if (!this.state.disabledKeys.has(key)) {\n keys.add(key);\n }\n }\n\n return keys;\n });\n }\n\n private getKeyRange(from: Key, to: Key) {\n let fromItem = this.collection.getItem(from);\n let toItem = this.collection.getItem(to);\n if (fromItem && toItem) {\n if (fromItem.index <= toItem.index) {\n return this.getKeyRangeInternal(from, to);\n }\n\n return this.getKeyRangeInternal(to, from);\n }\n\n return [];\n }\n\n private getKeyRangeInternal(from: Key, to: Key) {\n let keys: Key[] = [];\n let key = from;\n while (key) {\n let item = this.collection.getItem(key);\n if (item && item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection)) {\n keys.push(key);\n }\n\n if (key === to) {\n return keys;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return [];\n }\n\n private getKey(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n // ¯\\_(ツ)_/¯\n return key;\n }\n\n // If cell selection is allowed, just return the key.\n if (item.type === 'cell' && this.allowsCellSelection) {\n return key;\n }\n\n // Find a parent item to select\n while (item.type !== 'item' && item.parentKey) {\n item = this.collection.getItem(item.parentKey);\n }\n\n if (!item || item.type !== 'item') {\n return null;\n }\n\n return item.key;\n }\n\n /**\n * Toggles whether the given key is selected.\n */\n toggleSelection(key: Key) {\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(selectedKeys => {\n let keys = new Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : selectedKeys);\n if (keys.has(key)) {\n keys.delete(key);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else {\n keys.add(key);\n keys.anchorKey = key;\n keys.currentKey = key;\n }\n\n return keys;\n });\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key) {\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(new Selection([key], key, key));\n }\n\n private getSelectAllKeys() {\n let keys: Key[] = [];\n let addKeys = (key: Key) => {\n while (key) {\n if (!this.state.disabledKeys.has(key)) {\n let item = this.collection.getItem(key);\n if (item.type === 'item') {\n keys.push(key);\n }\n\n // Add child keys. If cell selection is allowed, then include item children too.\n if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n addKeys([...item.childNodes][0].key);\n }\n }\n\n key = this.collection.getKeyAfter(key);\n }\n };\n\n addKeys(this.collection.getFirstKey());\n return keys;\n }\n\n /**\n * Selects all items in the collection.\n */\n selectAll() {\n if (this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection() {\n if (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0) {\n this.state.setSelectedKeys(new Selection());\n }\n }\n\n /**\n * Toggles between select all and an empty selection.\n */\n toggleSelectAll() {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | PointerEvent) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n if (this.isSelected(key) && !this.disallowEmptySelection) {\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n } else if (e && e.shiftKey) {\n this.extendSelection(key);\n } else {\n this.toggleSelection(key);\n }\n }\n}\n"],"names":["Selection","Set","constructor","keys","anchorKey","currentKey","useMultipleSelectionState","props","selectionMode","disallowEmptySelection","isFocusedRef","useRef","setFocused","useState","focusedKeyRef","setFocusedKey","selectedKeysProp","useMemo","convertSelection","selectedKeys","defaultSelectedKeys","setSelectedKeys","useControlledState","onSelectionChange","disabledKeysProp","disabledKeys","isFocused","current","f","focusedKey","k","selection","defaultValue","SelectionManager","collection","state","options","allowsCellSelection","_isSelectAll","key","getSelectAllKeys","isSelected","getKey","has","isEmpty","size","isSelectAll","allKeys","every","firstSelectedKey","first","item","getItem","index","lastSelectedKey","last","extendSelection","toKey","getKeyRange","delete","add","from","to","fromItem","toItem","getKeyRangeInternal","type","push","getKeyAfter","parentKey","toggleSelection","replaceSelection","addKeys","hasChildNodes","childNodes","getFirstKey","selectAll","clearSelection","toggleSelectAll","select","e","shiftKey"],"version":3,"file":"module.js.map"}
{"mappings":";;;AAAA;;;;;;;;;;;;AAcA;;;;AAIO,MAAMA,gDAAN,SAAwBC,GAAxB,CAAiC;AAItCC,EAAAA,WAAW,CAACC,IAAD,EAAmCC,SAAnC,EAAoDC,UAApD,EAAsE;AAC/E,UAAMF,IAAN;AAD+E,SAHjFC,SAGiF;AAAA,SAFjFC,UAEiF;;AAE/E,QAAIF,IAAI,YAAYH,gDAApB,EAA+B;AAC7B,WAAKI,SAAL,GAAiBA,SAAS,IAAID,IAAI,CAACC,SAAnC;AACA,WAAKC,UAAL,GAAkBA,UAAU,IAAIF,IAAI,CAACE,UAArC;AACD,KAHD,MAGO;AACL,WAAKD,SAAL,GAAiBA,SAAjB;AACA,WAAKC,UAAL,GAAkBA,UAAlB;AACD;AACF;;AAbqC;;ACAxC;;;OAGO,SAASC,yBAAT,CAAmCC,KAAnC,EAAqF;AAC1F,MAAI;AACFC,IAAAA,aAAa,GAAG,MADd;AAEFC,IAAAA;AAFE,MAGAF,KAHJ,CAD0F,CAM1F;AACA;;AACA,MAAIG,YAAY,GAAGC,MAAM,CAAC,KAAD,CAAzB;AACA,MAAI,GAAGC,UAAH,IAAiBC,QAAQ,CAAC,KAAD,CA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,aAAL,KAAuB,QAA3B,EAAqC;AACnC,UAAI,KAAKmC,UAAL,CAAgBF,GAAhB,KAAwB,CAAC,KAAKhC,sBAAlC,EAA0D;AACxD,aAAK+D,eAAL,CAAqB/B,GAArB;AACD,OAFD,MAEO;AACL,aAAKgC,gBAAL,CAAsBhC,GAAtB;AACD;AACF,KAND,MAMO,IAAIyC,CAAC,IAAIA,CAAC,CAACC,QAAX,EAAqB;AAC1B,WAAKzB,eAAL,CAAqBjB,GAArB;AACD,KAFM,MAEA;AACL,WAAK+B,eAAL,CAAqB/B,GAArB;AACD;AACF;;AArU+D","sources":["./packages/@react-stately/selection/src/Selection.ts","./packages/@react-stately/selection/src/useMultipleSelectionState.ts","./packages/@react-stately/selection/src/SelectionManager.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 {Key} from 'react';\n\n/**\n * A Selection is a special Set containing Keys, which also has an anchor\n * and current selected key for use when range selecting.\n */\nexport class Selection extends Set<Key> {\n anchorKey: Key;\n currentKey: Key;\n\n constructor(keys?: Iterable<Key> | Selection, anchorKey?: Key, currentKey?: Key) {\n super(keys);\n if (keys instanceof Selection) {\n this.anchorKey = anchorKey || keys.anchorKey;\n this.currentKey = currentKey || keys.currentKey;\n } else {\n this.anchorKey = anchorKey;\n this.currentKey = currentKey;\n }\n }\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Key, useMemo, useRef, useState} from 'react';\nimport {MultipleSelection, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(props: MultipleSelection): MultipleSelectionState {\n let {\n selectionMode = 'none' as SelectionMode,\n disallowEmptySelection\n } = props;\n\n // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.\n // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).\n let isFocusedRef = useRef(false);\n let [, setFocused] = useState(false);\n let focusedKeyRef = useRef(null);\n let childFocusStrategyRef = useRef(null);\n let [, setFocusedKey] = useState(null);\n let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);\n let defaultSelectedKeys = useMemo(() => convertSelection(props.defaultSelectedKeys, new Selection()), [props.defaultSelectedKeys]);\n let [selectedKeys, setSelectedKeys] = useControlledState(\n selectedKeysProp,\n defaultSelectedKeys,\n props.onSelectionChange\n );\n let disabledKeysProp = useMemo(() =>\n props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n , [props.disabledKeys]);\n\n return {\n selectionMode,\n disallowEmptySelection,\n get isFocused() {\n return isFocusedRef.current;\n },\n setFocused(f) {\n isFocusedRef.current = f;\n setFocused(f);\n },\n get focusedKey() {\n return focusedKeyRef.current;\n },\n get childFocusStrategy() {\n return childFocusStrategyRef.current;\n },\n setFocusedKey(k, childFocusStrategy = 'first') {\n focusedKeyRef.current = k;\n childFocusStrategyRef.current = childFocusStrategy;\n setFocusedKey(k);\n },\n selectedKeys,\n setSelectedKeys,\n disabledKeys: disabledKeysProp\n };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Selection {\n if (!selection) {\n return defaultValue;\n }\n\n return selection === 'all'\n ? 'all'\n : new Selection(selection);\n}\n","/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, FocusStrategy, Node, PressEvent, SelectionMode} from '@react-types/shared';\nimport {Key} from 'react';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n private collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean;\n\n constructor(collection: Collection<Node<unknown>>, state: MultipleSelectionState, options?: SelectionManagerOptions) {\n this.collection = collection;\n this.state = state;\n this.allowsCellSelection = options?.allowsCellSelection ?? false;\n this._isSelectAll = null;\n }\n\n /**\n * The type of selection that is allowed in the collection.\n */\n get selectionMode(): SelectionMode {\n return this.state.selectionMode;\n }\n\n /**\n * Whether the collection allows empty selection.\n */\n get disallowEmptySelection(): boolean {\n return this.state.disallowEmptySelection;\n }\n\n /**\n * Whether the collection is currently focused.\n */\n get isFocused(): boolean {\n return this.state.isFocused;\n }\n\n /**\n * Sets whether the collection is focused.\n */\n setFocused(isFocused: boolean) {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key {\n return this.state.focusedKey;\n }\n\n /** Whether the first or last child of the focused key should receive focus. */\n get childFocusStrategy(): FocusStrategy {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key, childFocusStrategy?: FocusStrategy) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\n\n /**\n * The currently selected keys in the collection.\n */\n get selectedKeys(): Set<Key> {\n return this.state.selectedKeys === 'all'\n ? new Set(this.getSelectAllKeys())\n : this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key) {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n key = this.getKey(key);\n return this.state.selectedKeys === 'all' || this.state.selectedKeys.has(key);\n }\n\n /**\n * Whether the selection is empty.\n */\n get isEmpty(): boolean {\n return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n }\n\n /**\n * Whether all items in the collection are selected.\n */\n get isSelectAll(): boolean {\n if (this.isEmpty) {\n return false;\n }\n\n if (this.state.selectedKeys === 'all') {\n return true;\n }\n\n if (this._isSelectAll != null) {\n return this._isSelectAll;\n }\n\n let allKeys = this.getSelectAllKeys();\n let selectedKeys = this.state.selectedKeys;\n this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n return this._isSelectAll;\n }\n\n get firstSelectedKey(): Key | null {\n let first: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!first || item?.index < first.index) {\n first = item;\n }\n }\n\n return first?.key;\n }\n\n get lastSelectedKey(): Key | null {\n let last: Node<unknown> | null = null;\n for (let key of this.state.selectedKeys) {\n let item = this.collection.getItem(key);\n if (!last || item?.index > last.index) {\n last = item;\n }\n }\n\n return last?.key;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key) {\n toKey = this.getKey(toKey);\n this.state.setSelectedKeys(selectedKeys => {\n // Only select the one key if coming from a select all.\n if (selectedKeys === 'all') {\n return new Selection([toKey], toKey, toKey);\n }\n\n let selection = selectedKeys as Selection;\n let anchorKey = selection.anchorKey || toKey;\n let keys = new Selection(selection, anchorKey, toKey);\n for (let key of this.getKeyRange(anchorKey, selection.currentKey || toKey)) {\n keys.delete(key);\n }\n\n for (let key of this.getKeyRange(toKey, anchorKey)) {\n if (!this.state.disabledKeys.has(key)) {\n keys.add(key);\n }\n }\n\n return keys;\n });\n }\n\n private getKeyRange(from: Key, to: Key) {\n let fromItem = this.collection.getItem(from);\n let toItem = this.collection.getItem(to);\n if (fromItem && toItem) {\n if (fromItem.index <= toItem.index) {\n return this.getKeyRangeInternal(from, to);\n }\n\n return this.getKeyRangeInternal(to, from);\n }\n\n return [];\n }\n\n private getKeyRangeInternal(from: Key, to: Key) {\n let keys: Key[] = [];\n let key = from;\n while (key) {\n let item = this.collection.getItem(key);\n if (item && item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection)) {\n keys.push(key);\n }\n\n if (key === to) {\n return keys;\n }\n\n key = this.collection.getKeyAfter(key);\n }\n\n return [];\n }\n\n private getKey(key: Key) {\n let item = this.collection.getItem(key);\n if (!item) {\n // ¯\\_(ツ)_/¯\n return key;\n }\n\n // If cell selection is allowed, just return the key.\n if (item.type === 'cell' && this.allowsCellSelection) {\n return key;\n }\n\n // Find a parent item to select\n while (item.type !== 'item' && item.parentKey) {\n item = this.collection.getItem(item.parentKey);\n }\n\n if (!item || item.type !== 'item') {\n return null;\n }\n\n return item.key;\n }\n\n /**\n * Toggles whether the given key is selected.\n */\n toggleSelection(key: Key) {\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(selectedKeys => {\n let keys = new Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : selectedKeys);\n if (keys.has(key)) {\n keys.delete(key);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else {\n keys.add(key);\n keys.anchorKey = key;\n keys.currentKey = key;\n }\n\n return keys;\n });\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key) {\n key = this.getKey(key);\n if (key == null) {\n return;\n }\n\n this.state.setSelectedKeys(new Selection([key], key, key));\n }\n\n private getSelectAllKeys() {\n let keys: Key[] = [];\n let addKeys = (key: Key) => {\n while (key) {\n if (!this.state.disabledKeys.has(key)) {\n let item = this.collection.getItem(key);\n if (item.type === 'item') {\n keys.push(key);\n }\n\n // Add child keys. If cell selection is allowed, then include item children too.\n if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n addKeys([...item.childNodes][0].key);\n }\n }\n\n key = this.collection.getKeyAfter(key);\n }\n };\n\n addKeys(this.collection.getFirstKey());\n return keys;\n }\n\n /**\n * Selects all items in the collection.\n */\n selectAll() {\n if (this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection() {\n if (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0) {\n this.state.setSelectedKeys(new Selection());\n }\n }\n\n /**\n * Toggles between select all and an empty selection.\n */\n toggleSelectAll() {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | PointerEvent) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n if (this.isSelected(key) && !this.disallowEmptySelection) {\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n } else if (e && e.shiftKey) {\n this.extendSelection(key);\n } else {\n this.toggleSelection(key);\n }\n }\n}\n"],"names":["Selection","Set","constructor","keys","anchorKey","currentKey","useMultipleSelectionState","props","selectionMode","disallowEmptySelection","isFocusedRef","useRef","setFocused","useState","focusedKeyRef","childFocusStrategyRef","setFocusedKey","selectedKeysProp","useMemo","convertSelection","selectedKeys","defaultSelectedKeys","setSelectedKeys","useControlledState","onSelectionChange","disabledKeysProp","disabledKeys","isFocused","current","f","focusedKey","childFocusStrategy","k","selection","defaultValue","SelectionManager","collection","state","options","allowsCellSelection","_isSelectAll","key","getSelectAllKeys","isSelected","getKey","has","isEmpty","size","isSelectAll","allKeys","every","firstSelectedKey","first","item","getItem","index","lastSelectedKey","last","extendSelection","toKey","getKeyRange","delete","add","from","to","fromItem","toItem","getKeyRangeInternal","type","push","getKeyAfter","parentKey","toggleSelection","replaceSelection","addKeys","hasChildNodes","childNodes","getFirstKey","selectAll","clearSelection","toggleSelectAll","select","e","shiftKey"],"version":3,"file":"module.js.map"}

@@ -0,3 +1,3 @@

import { FocusStrategy, PressEvent, Selection, SelectionMode, MultipleSelection, Collection, Node } from "@react-types/shared";
import { Key } from "react";
import { PressEvent, Selection, SelectionMode, MultipleSelection, Collection, Node } from "@react-types/shared";
export interface FocusState {

@@ -10,4 +10,6 @@ /** Whether the collection is currently focused. */

readonly focusedKey: Key;
/** Sets the focused key. */
setFocusedKey(key: Key): void;
/** Whether the first or last child of the focused key should receive focus. */
readonly childFocusStrategy: FocusStrategy;
/** Sets the focused key, and optionally, whether the first or last child of that key should receive focus. */
setFocusedKey(key: Key, child?: FocusStrategy): void;
}

@@ -101,6 +103,8 @@ export interface SingleSelectionState extends FocusState {

get focusedKey(): Key;
/** Whether the first or last child of the focused key should receive focus. */
get childFocusStrategy(): FocusStrategy;
/**
* Sets the focused key.
*/
setFocusedKey(key: Key): void;
setFocusedKey(key: Key, childFocusStrategy?: FocusStrategy): void;
/**

@@ -107,0 +111,0 @@ * The currently selected keys in the collection.

@@ -1,1 +0,1 @@

{"mappings":"A;A;AAeA;IACE,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,8CAA8C;IAC9C,UAAU,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IACrC,iDAAiD;IACjD,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC;IACzB,4BAA4B;IAC5B,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAA;CAC9B;AAED,qCAAsC,SAAQ,UAAU;IACtD,qDAAqD;IACrD,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAC1C,oDAAoD;IACpD,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC;IA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,eAAe,CAAC,GAAG,EAAE,GAAG;IAsBxB;A;OAEG;IACH,gBAAgB,CAAC,GAAG,EAAE,GAAG;IAiCzB;A;OAEG;IACH,SAAS;IAMT;A;OAEG;IACH,cAAc;IAMd;A;OAEG;IACH,eAAe;IAQf,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,GAAG,YAAY;CAiB/C","sources":["./packages/@react-stately/selection/src/packages/@react-stately/selection/src/types.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/Selection.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/useMultipleSelectionState.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/SelectionManager.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/index.ts"],"sourcesContent":[null,null,null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
{"mappings":"A;A;AAeA;IACE,mDAAmD;IACnD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,8CAA8C;IAC9C,UAAU,CAAC,SAAS,EAAE,OAAO,GAAG,IAAI,CAAC;IACrC,iDAAiD;IACjD,QAAQ,CAAC,UAAU,EAAE,GAAG,CAAC;IACzB,+EAA+E;IAC/E,QAAQ,CAAC,kBAAkB,EAAE,aAAa,CAAC;IAC3C,8GAA8G;IAC9G,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,IAAI,CAAA;CACrD;AAED,qCAAsC,SAAQ,UAAU;IACtD,qDAAqD;IACrD,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAC1C,oDAAoD;IACpD,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC;IAC1B,+CAA+C;IAC/C,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAA;CAC/B;AAED,uCAAwC,SAAQ,UAAU;IACxD,+DAA+D;IAC/D,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,qDAA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;IAiCzB;A;OAEG;IACH,SAAS;IAMT;A;OAEG;IACH,cAAc;IAMd;A;OAEG;IACH,eAAe;IAQf,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,GAAG,YAAY;CAiB/C","sources":["./packages/@react-stately/selection/src/packages/@react-stately/selection/src/types.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/Selection.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/useMultipleSelectionState.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/SelectionManager.ts","./packages/@react-stately/selection/src/packages/@react-stately/selection/src/index.ts"],"sourcesContent":[null,null,null,null,null],"names":[],"version":3,"file":"types.d.ts.map"}
{
"name": "@react-stately/selection",
"version": "3.3.0",
"version": "3.4.0",
"description": "Spectrum UI components in React",

@@ -21,5 +21,5 @@ "license": "Apache-2.0",

"@babel/runtime": "^7.6.2",
"@react-stately/collections": "^3.2.1",
"@react-stately/collections": "^3.3.1",
"@react-stately/utils": "^3.1.1",
"@react-types/shared": "^3.3.0"
"@react-types/shared": "^3.5.0"
},

@@ -32,3 +32,3 @@ "peerDependencies": {

},
"gitHead": "9f738a06ea4e256c8d975f00502b4b0bbabb8f65"
"gitHead": "9920ffaa2596a03c4498a15cb940bd2f4ba5cd6a"
}

@@ -13,3 +13,3 @@ /*

import {Collection, Node, PressEvent, SelectionMode} from '@react-types/shared';
import {Collection, FocusStrategy, Node, PressEvent, SelectionMode} from '@react-types/shared';
import {Key} from 'react';

@@ -74,7 +74,12 @@ import {MultipleSelectionManager, MultipleSelectionState} from './types';

/** Whether the first or last child of the focused key should receive focus. */
get childFocusStrategy(): FocusStrategy {
return this.state.childFocusStrategy;
}
/**
* Sets the focused key.
*/
setFocusedKey(key: Key) {
this.state.setFocusedKey(key);
setFocusedKey(key: Key, childFocusStrategy?: FocusStrategy) {
this.state.setFocusedKey(key, childFocusStrategy);
}

@@ -81,0 +86,0 @@

@@ -13,4 +13,4 @@ /*

import {FocusStrategy, PressEvent, Selection, SelectionMode} from '@react-types/shared';
import {Key} from 'react';
import {PressEvent, Selection, SelectionMode} from '@react-types/shared';

@@ -24,4 +24,6 @@ export interface FocusState {

readonly focusedKey: Key,
/** Sets the focused key. */
setFocusedKey(key: Key): void
/** Whether the first or last child of the focused key should receive focus. */
readonly childFocusStrategy: FocusStrategy,
/** Sets the focused key, and optionally, whether the first or last child of that key should receive focus. */
setFocusedKey(key: Key, child?: FocusStrategy): void
}

@@ -28,0 +30,0 @@

@@ -33,2 +33,3 @@ /*

let focusedKeyRef = useRef(null);
let childFocusStrategyRef = useRef(null);
let [, setFocusedKey] = useState(null);

@@ -59,4 +60,8 @@ let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);

},
setFocusedKey(k) {
get childFocusStrategy() {
return childFocusStrategyRef.current;
},
setFocusedKey(k, childFocusStrategy = 'first') {
focusedKeyRef.current = k;
childFocusStrategyRef.current = childFocusStrategy;
setFocusedKey(k);

@@ -63,0 +68,0 @@ },