@react-stately/selection
Advanced tools
Comparing version 3.17.0 to 3.18.0
@@ -24,4 +24,4 @@ | ||
} else { | ||
this.anchorKey = anchorKey; | ||
this.currentKey = currentKey; | ||
this.anchorKey = anchorKey !== null && anchorKey !== void 0 ? anchorKey : null; | ||
this.currentKey = currentKey !== null && currentKey !== void 0 ? currentKey : null; | ||
} | ||
@@ -28,0 +28,0 @@ } |
@@ -18,4 +18,4 @@ /* | ||
} else { | ||
this.anchorKey = anchorKey; | ||
this.currentKey = currentKey; | ||
this.anchorKey = anchorKey !== null && anchorKey !== void 0 ? anchorKey : null; | ||
this.currentKey = currentKey !== null && currentKey !== void 0 ? currentKey : null; | ||
} | ||
@@ -22,0 +22,0 @@ } |
@@ -81,4 +81,5 @@ var $21c847070f1f9569$exports = require("./Selection.main.js"); | ||
if (this.state.selectionMode === 'none') return false; | ||
key = this.getKey(key); | ||
return this.state.selectedKeys === 'all' ? this.canSelectItem(key) : this.state.selectedKeys.has(key); | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey == null) return false; | ||
return this.state.selectedKeys === 'all' ? this.canSelectItem(mappedKey) : this.state.selectedKeys.has(mappedKey); | ||
} | ||
@@ -107,3 +108,4 @@ /** | ||
} | ||
return first === null || first === void 0 ? void 0 : first.key; | ||
var _first_key; | ||
return (_first_key = first === null || first === void 0 ? void 0 : first.key) !== null && _first_key !== void 0 ? _first_key : null; | ||
} | ||
@@ -116,3 +118,4 @@ get lastSelectedKey() { | ||
} | ||
return last === null || last === void 0 ? void 0 : last.key; | ||
var _last_key; | ||
return (_last_key = last === null || last === void 0 ? void 0 : last.key) !== null && _last_key !== void 0 ? _last_key : null; | ||
} | ||
@@ -133,16 +136,17 @@ get disabledKeys() { | ||
} | ||
toKey = this.getKey(toKey); | ||
let mappedToKey = this.getKey(toKey); | ||
if (mappedToKey == null) return; | ||
let selection; | ||
// Only select the one key if coming from a select all. | ||
if (this.state.selectedKeys === 'all') selection = new (0, $21c847070f1f9569$exports.Selection)([ | ||
toKey | ||
], toKey, toKey); | ||
mappedToKey | ||
], mappedToKey, mappedToKey); | ||
else { | ||
let selectedKeys = this.state.selectedKeys; | ||
var _selectedKeys_anchorKey; | ||
let anchorKey = (_selectedKeys_anchorKey = selectedKeys.anchorKey) !== null && _selectedKeys_anchorKey !== void 0 ? _selectedKeys_anchorKey : toKey; | ||
selection = new (0, $21c847070f1f9569$exports.Selection)(selectedKeys, anchorKey, toKey); | ||
let anchorKey = (_selectedKeys_anchorKey = selectedKeys.anchorKey) !== null && _selectedKeys_anchorKey !== void 0 ? _selectedKeys_anchorKey : mappedToKey; | ||
selection = new (0, $21c847070f1f9569$exports.Selection)(selectedKeys, anchorKey, mappedToKey); | ||
var _selectedKeys_currentKey; | ||
for (let key of this.getKeyRange(anchorKey, (_selectedKeys_currentKey = selectedKeys.currentKey) !== null && _selectedKeys_currentKey !== void 0 ? _selectedKeys_currentKey : toKey))selection.delete(key); | ||
for (let key of this.getKeyRange(toKey, anchorKey))if (this.canSelectItem(key)) selection.add(key); | ||
for (let key of this.getKeyRange(anchorKey, (_selectedKeys_currentKey = selectedKeys.currentKey) !== null && _selectedKeys_currentKey !== void 0 ? _selectedKeys_currentKey : mappedToKey))selection.delete(key); | ||
for (let key of this.getKeyRange(mappedToKey, anchorKey))if (this.canSelectItem(key)) selection.add(key); | ||
} | ||
@@ -167,3 +171,3 @@ this.state.setSelectedKeys(selection); | ||
let item = this.collection.getItem(key); | ||
if (item && item.type === 'item' || item.type === 'cell' && this.allowsCellSelection) keys.push(key); | ||
if (item && (item.type === 'item' || item.type === 'cell' && this.allowsCellSelection)) keys.push(key); | ||
if (key === to) return keys; | ||
@@ -181,3 +185,3 @@ key = this.collection.getKeyAfter(key); | ||
// Find a parent item to select | ||
while(item.type !== 'item' && item.parentKey != null)item = this.collection.getItem(item.parentKey); | ||
while(item && item.type !== 'item' && item.parentKey != null)item = this.collection.getItem(item.parentKey); | ||
if (!item || item.type !== 'item') return null; | ||
@@ -194,10 +198,10 @@ return item.key; | ||
} | ||
key = this.getKey(key); | ||
if (key == null) return; | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey == null) return; | ||
let keys = new (0, $21c847070f1f9569$exports.Selection)(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys); | ||
if (keys.has(key)) keys.delete(key); | ||
else if (this.canSelectItem(key)) { | ||
keys.add(key); | ||
keys.anchorKey = key; | ||
keys.currentKey = key; | ||
if (keys.has(mappedKey)) keys.delete(mappedKey); | ||
else if (this.canSelectItem(mappedKey)) { | ||
keys.add(mappedKey); | ||
keys.anchorKey = mappedKey; | ||
keys.currentKey = mappedKey; | ||
} | ||
@@ -211,7 +215,7 @@ if (this.disallowEmptySelection && keys.size === 0) return; | ||
if (this.selectionMode === 'none') return; | ||
key = this.getKey(key); | ||
if (key == null) return; | ||
let selection = this.canSelectItem(key) ? new (0, $21c847070f1f9569$exports.Selection)([ | ||
key | ||
], key, key) : new (0, $21c847070f1f9569$exports.Selection)(); | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey == null) return; | ||
let selection = this.canSelectItem(mappedKey) ? new (0, $21c847070f1f9569$exports.Selection)([ | ||
mappedKey | ||
], mappedKey, mappedKey) : new (0, $21c847070f1f9569$exports.Selection)(); | ||
this.state.setSelectedKeys(selection); | ||
@@ -225,5 +229,5 @@ } | ||
for (let key of keys){ | ||
key = this.getKey(key); | ||
if (key != null) { | ||
selection.add(key); | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey != null) { | ||
selection.add(mappedKey); | ||
if (this.selectionMode === 'single') break; | ||
@@ -239,6 +243,8 @@ } | ||
if (this.canSelectItem(key)) { | ||
var _getFirstItem; | ||
let item = this.collection.getItem(key); | ||
if (item.type === 'item') keys.push(key); | ||
if ((item === null || item === void 0 ? void 0 : item.type) === 'item') keys.push(key); | ||
var _getFirstItem_key; | ||
// Add child keys. If cell selection is allowed, then include item children too. | ||
if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) addKeys((0, $ia6MY$reactstatelycollections.getFirstItem)((0, $ia6MY$reactstatelycollections.getChildNodes)(item, this.collection)).key); | ||
if ((item === null || item === void 0 ? void 0 : item.hasChildNodes) && (this.allowsCellSelection || item.type !== 'item')) addKeys((_getFirstItem_key = (_getFirstItem = (0, $ia6MY$reactstatelycollections.getFirstItem)((0, $ia6MY$reactstatelycollections.getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _getFirstItem_key !== void 0 ? _getFirstItem_key : null); | ||
} | ||
@@ -245,0 +251,0 @@ key = this.collection.getKeyAfter(key); |
@@ -75,4 +75,5 @@ import {Selection as $e40ea825a81a3709$export$52baac22726c72bf} from "./Selection.module.js"; | ||
if (this.state.selectionMode === 'none') return false; | ||
key = this.getKey(key); | ||
return this.state.selectedKeys === 'all' ? this.canSelectItem(key) : this.state.selectedKeys.has(key); | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey == null) return false; | ||
return this.state.selectedKeys === 'all' ? this.canSelectItem(mappedKey) : this.state.selectedKeys.has(mappedKey); | ||
} | ||
@@ -101,3 +102,4 @@ /** | ||
} | ||
return first === null || first === void 0 ? void 0 : first.key; | ||
var _first_key; | ||
return (_first_key = first === null || first === void 0 ? void 0 : first.key) !== null && _first_key !== void 0 ? _first_key : null; | ||
} | ||
@@ -110,3 +112,4 @@ get lastSelectedKey() { | ||
} | ||
return last === null || last === void 0 ? void 0 : last.key; | ||
var _last_key; | ||
return (_last_key = last === null || last === void 0 ? void 0 : last.key) !== null && _last_key !== void 0 ? _last_key : null; | ||
} | ||
@@ -127,16 +130,17 @@ get disabledKeys() { | ||
} | ||
toKey = this.getKey(toKey); | ||
let mappedToKey = this.getKey(toKey); | ||
if (mappedToKey == null) return; | ||
let selection; | ||
// Only select the one key if coming from a select all. | ||
if (this.state.selectedKeys === 'all') selection = new (0, $e40ea825a81a3709$export$52baac22726c72bf)([ | ||
toKey | ||
], toKey, toKey); | ||
mappedToKey | ||
], mappedToKey, mappedToKey); | ||
else { | ||
let selectedKeys = this.state.selectedKeys; | ||
var _selectedKeys_anchorKey; | ||
let anchorKey = (_selectedKeys_anchorKey = selectedKeys.anchorKey) !== null && _selectedKeys_anchorKey !== void 0 ? _selectedKeys_anchorKey : toKey; | ||
selection = new (0, $e40ea825a81a3709$export$52baac22726c72bf)(selectedKeys, anchorKey, toKey); | ||
let anchorKey = (_selectedKeys_anchorKey = selectedKeys.anchorKey) !== null && _selectedKeys_anchorKey !== void 0 ? _selectedKeys_anchorKey : mappedToKey; | ||
selection = new (0, $e40ea825a81a3709$export$52baac22726c72bf)(selectedKeys, anchorKey, mappedToKey); | ||
var _selectedKeys_currentKey; | ||
for (let key of this.getKeyRange(anchorKey, (_selectedKeys_currentKey = selectedKeys.currentKey) !== null && _selectedKeys_currentKey !== void 0 ? _selectedKeys_currentKey : toKey))selection.delete(key); | ||
for (let key of this.getKeyRange(toKey, anchorKey))if (this.canSelectItem(key)) selection.add(key); | ||
for (let key of this.getKeyRange(anchorKey, (_selectedKeys_currentKey = selectedKeys.currentKey) !== null && _selectedKeys_currentKey !== void 0 ? _selectedKeys_currentKey : mappedToKey))selection.delete(key); | ||
for (let key of this.getKeyRange(mappedToKey, anchorKey))if (this.canSelectItem(key)) selection.add(key); | ||
} | ||
@@ -161,3 +165,3 @@ this.state.setSelectedKeys(selection); | ||
let item = this.collection.getItem(key); | ||
if (item && item.type === 'item' || item.type === 'cell' && this.allowsCellSelection) keys.push(key); | ||
if (item && (item.type === 'item' || item.type === 'cell' && this.allowsCellSelection)) keys.push(key); | ||
if (key === to) return keys; | ||
@@ -175,3 +179,3 @@ key = this.collection.getKeyAfter(key); | ||
// Find a parent item to select | ||
while(item.type !== 'item' && item.parentKey != null)item = this.collection.getItem(item.parentKey); | ||
while(item && item.type !== 'item' && item.parentKey != null)item = this.collection.getItem(item.parentKey); | ||
if (!item || item.type !== 'item') return null; | ||
@@ -188,10 +192,10 @@ return item.key; | ||
} | ||
key = this.getKey(key); | ||
if (key == null) return; | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey == null) return; | ||
let keys = new (0, $e40ea825a81a3709$export$52baac22726c72bf)(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys); | ||
if (keys.has(key)) keys.delete(key); | ||
else if (this.canSelectItem(key)) { | ||
keys.add(key); | ||
keys.anchorKey = key; | ||
keys.currentKey = key; | ||
if (keys.has(mappedKey)) keys.delete(mappedKey); | ||
else if (this.canSelectItem(mappedKey)) { | ||
keys.add(mappedKey); | ||
keys.anchorKey = mappedKey; | ||
keys.currentKey = mappedKey; | ||
} | ||
@@ -205,7 +209,7 @@ if (this.disallowEmptySelection && keys.size === 0) return; | ||
if (this.selectionMode === 'none') return; | ||
key = this.getKey(key); | ||
if (key == null) return; | ||
let selection = this.canSelectItem(key) ? new (0, $e40ea825a81a3709$export$52baac22726c72bf)([ | ||
key | ||
], key, key) : new (0, $e40ea825a81a3709$export$52baac22726c72bf)(); | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey == null) return; | ||
let selection = this.canSelectItem(mappedKey) ? new (0, $e40ea825a81a3709$export$52baac22726c72bf)([ | ||
mappedKey | ||
], mappedKey, mappedKey) : new (0, $e40ea825a81a3709$export$52baac22726c72bf)(); | ||
this.state.setSelectedKeys(selection); | ||
@@ -219,5 +223,5 @@ } | ||
for (let key of keys){ | ||
key = this.getKey(key); | ||
if (key != null) { | ||
selection.add(key); | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey != null) { | ||
selection.add(mappedKey); | ||
if (this.selectionMode === 'single') break; | ||
@@ -233,6 +237,8 @@ } | ||
if (this.canSelectItem(key)) { | ||
var _getFirstItem; | ||
let item = this.collection.getItem(key); | ||
if (item.type === 'item') keys.push(key); | ||
if ((item === null || item === void 0 ? void 0 : item.type) === 'item') keys.push(key); | ||
var _getFirstItem_key; | ||
// Add child keys. If cell selection is allowed, then include item children too. | ||
if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) addKeys((0, $jkhUT$getFirstItem)((0, $jkhUT$getChildNodes)(item, this.collection)).key); | ||
if ((item === null || item === void 0 ? void 0 : item.hasChildNodes) && (this.allowsCellSelection || item.type !== 'item')) addKeys((_getFirstItem_key = (_getFirstItem = (0, $jkhUT$getFirstItem)((0, $jkhUT$getChildNodes)(item, this.collection))) === null || _getFirstItem === void 0 ? void 0 : _getFirstItem.key) !== null && _getFirstItem_key !== void 0 ? _getFirstItem_key : null); | ||
} | ||
@@ -239,0 +245,0 @@ key = this.collection.getKeyAfter(key); |
@@ -8,5 +8,5 @@ import { DisabledBehavior, FocusStrategy, Key, LongPressEvent, PressEvent, Selection, SelectionBehavior, SelectionMode, MultipleSelection, Collection, LayoutDelegate, Node } from "@react-types/shared"; | ||
/** The current focused key in the collection. */ | ||
readonly focusedKey: Key; | ||
readonly focusedKey: Key | null; | ||
/** Whether the first or last child of the focused key should receive focus. */ | ||
readonly childFocusStrategy: FocusStrategy; | ||
readonly childFocusStrategy: FocusStrategy | null; | ||
/** Sets the focused key, and optionally, whether the first or last child of that key should receive focus. */ | ||
@@ -116,2 +116,3 @@ setFocusedKey(key: Key | null, child?: FocusStrategy): void; | ||
export class SelectionManager implements MultipleSelectionManager { | ||
collection: Collection<Node<unknown>>; | ||
constructor(collection: Collection<Node<unknown>>, state: MultipleSelectionState, options?: SelectionManagerOptions); | ||
@@ -145,5 +146,5 @@ /** | ||
*/ | ||
get focusedKey(): Key; | ||
get focusedKey(): Key | null; | ||
/** Whether the first or last child of the focused key should receive focus. */ | ||
get childFocusStrategy(): FocusStrategy; | ||
get childFocusStrategy(): FocusStrategy | null; | ||
/** | ||
@@ -150,0 +151,0 @@ * Sets the focused key. |
@@ -32,3 +32,3 @@ var $21c847070f1f9569$exports = require("./Selection.main.js"); | ||
function $1adc19da2128bba9$export$253fe78d46329472(props) { | ||
let { selectionMode: selectionMode = 'none', disallowEmptySelection: disallowEmptySelection, allowDuplicateSelectionEvents: allowDuplicateSelectionEvents, selectionBehavior: selectionBehaviorProp = 'toggle', disabledBehavior: disabledBehavior = 'all' } = props; | ||
let { selectionMode: selectionMode = 'none', disallowEmptySelection: disallowEmptySelection = false, allowDuplicateSelectionEvents: allowDuplicateSelectionEvents, selectionBehavior: selectionBehaviorProp = 'toggle', disabledBehavior: disabledBehavior = 'all' } = props; | ||
// We want synchronous updates to `isFocused` and `focusedKey` after their setters are called. | ||
@@ -35,0 +35,0 @@ // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async). |
@@ -26,3 +26,3 @@ import {Selection as $e40ea825a81a3709$export$52baac22726c72bf} from "./Selection.module.js"; | ||
function $7af3f5b51489e0b5$export$253fe78d46329472(props) { | ||
let { selectionMode: selectionMode = 'none', disallowEmptySelection: disallowEmptySelection, allowDuplicateSelectionEvents: allowDuplicateSelectionEvents, selectionBehavior: selectionBehaviorProp = 'toggle', disabledBehavior: disabledBehavior = 'all' } = props; | ||
let { selectionMode: selectionMode = 'none', disallowEmptySelection: disallowEmptySelection = false, allowDuplicateSelectionEvents: allowDuplicateSelectionEvents, selectionBehavior: selectionBehaviorProp = 'toggle', disabledBehavior: disabledBehavior = 'all' } = props; | ||
// We want synchronous updates to `isFocused` and `focusedKey` after their setters are called. | ||
@@ -29,0 +29,0 @@ // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async). |
{ | ||
"name": "@react-stately/selection", | ||
"version": "3.17.0", | ||
"version": "3.18.0", | ||
"description": "Spectrum UI components in React", | ||
@@ -25,13 +25,14 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@react-stately/collections": "^3.11.0", | ||
"@react-stately/utils": "^3.10.4", | ||
"@react-types/shared": "^3.25.0", | ||
"@react-stately/collections": "^3.12.0", | ||
"@react-stately/utils": "^3.10.5", | ||
"@react-types/shared": "^3.26.0", | ||
"@swc/helpers": "^0.5.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0" | ||
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} | ||
}, | ||
"gitHead": "71f0ef23053f9e03ee7e97df736e8b083e006849" | ||
} |
@@ -20,6 +20,6 @@ /* | ||
export class Selection extends Set<Key> { | ||
anchorKey: Key; | ||
currentKey: Key; | ||
anchorKey: Key | null; | ||
currentKey: Key | null; | ||
constructor(keys?: Iterable<Key> | Selection, anchorKey?: Key, currentKey?: Key) { | ||
constructor(keys?: Iterable<Key> | Selection, anchorKey?: Key | null, currentKey?: Key | null) { | ||
super(keys); | ||
@@ -30,6 +30,6 @@ if (keys instanceof Selection) { | ||
} else { | ||
this.anchorKey = anchorKey; | ||
this.currentKey = currentKey; | ||
this.anchorKey = anchorKey ?? null; | ||
this.currentKey = currentKey ?? null; | ||
} | ||
} | ||
} |
@@ -38,6 +38,6 @@ /* | ||
export class SelectionManager implements MultipleSelectionManager { | ||
private collection: Collection<Node<unknown>>; | ||
collection: Collection<Node<unknown>>; | ||
private state: MultipleSelectionState; | ||
private allowsCellSelection: boolean; | ||
private _isSelectAll: boolean; | ||
private _isSelectAll: boolean | null; | ||
private layoutDelegate: LayoutDelegate | null; | ||
@@ -98,3 +98,3 @@ | ||
*/ | ||
get focusedKey(): Key { | ||
get focusedKey(): Key | null { | ||
return this.state.focusedKey; | ||
@@ -104,3 +104,3 @@ } | ||
/** Whether the first or last child of the focused key should receive focus. */ | ||
get childFocusStrategy(): FocusStrategy { | ||
get childFocusStrategy(): FocusStrategy | null { | ||
return this.state.childFocusStrategy; | ||
@@ -143,6 +143,9 @@ } | ||
key = this.getKey(key); | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey == null) { | ||
return false; | ||
} | ||
return this.state.selectedKeys === 'all' | ||
? this.canSelectItem(key) | ||
: this.state.selectedKeys.has(key); | ||
? this.canSelectItem(mappedKey) | ||
: this.state.selectedKeys.has(mappedKey); | ||
} | ||
@@ -188,3 +191,3 @@ | ||
return first?.key; | ||
return first?.key ?? null; | ||
} | ||
@@ -201,3 +204,3 @@ | ||
return last?.key; | ||
return last?.key ?? null; | ||
} | ||
@@ -226,3 +229,6 @@ | ||
toKey = this.getKey(toKey); | ||
let mappedToKey = this.getKey(toKey); | ||
if (mappedToKey == null) { | ||
return; | ||
} | ||
@@ -233,12 +239,12 @@ let selection: Selection; | ||
if (this.state.selectedKeys === 'all') { | ||
selection = new Selection([toKey], toKey, toKey); | ||
selection = new Selection([mappedToKey], mappedToKey, mappedToKey); | ||
} else { | ||
let selectedKeys = this.state.selectedKeys as Selection; | ||
let anchorKey = selectedKeys.anchorKey ?? toKey; | ||
selection = new Selection(selectedKeys, anchorKey, toKey); | ||
for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? toKey)) { | ||
let anchorKey = selectedKeys.anchorKey ?? mappedToKey; | ||
selection = new Selection(selectedKeys, anchorKey, mappedToKey); | ||
for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? mappedToKey)) { | ||
selection.delete(key); | ||
} | ||
for (let key of this.getKeyRange(toKey, anchorKey)) { | ||
for (let key of this.getKeyRange(mappedToKey, anchorKey)) { | ||
if (this.canSelectItem(key)) { | ||
@@ -273,6 +279,6 @@ selection.add(key); | ||
let keys: Key[] = []; | ||
let key = from; | ||
let key: Key | null = from; | ||
while (key != null) { | ||
let item = this.collection.getItem(key); | ||
if (item && item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection)) { | ||
if (item && (item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection))) { | ||
keys.push(key); | ||
@@ -304,3 +310,3 @@ } | ||
// Find a parent item to select | ||
while (item.type !== 'item' && item.parentKey != null) { | ||
while (item && item.type !== 'item' && item.parentKey != null) { | ||
item = this.collection.getItem(item.parentKey); | ||
@@ -329,4 +335,4 @@ } | ||
key = this.getKey(key); | ||
if (key == null) { | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey == null) { | ||
return; | ||
@@ -336,10 +342,10 @@ } | ||
let keys = new Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys); | ||
if (keys.has(key)) { | ||
keys.delete(key); | ||
if (keys.has(mappedKey)) { | ||
keys.delete(mappedKey); | ||
// TODO: move anchor to last selected key... | ||
// Does `current` need to move here too? | ||
} else if (this.canSelectItem(key)) { | ||
keys.add(key); | ||
keys.anchorKey = key; | ||
keys.currentKey = key; | ||
} else if (this.canSelectItem(mappedKey)) { | ||
keys.add(mappedKey); | ||
keys.anchorKey = mappedKey; | ||
keys.currentKey = mappedKey; | ||
} | ||
@@ -362,9 +368,9 @@ | ||
key = this.getKey(key); | ||
if (key == null) { | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey == null) { | ||
return; | ||
} | ||
let selection = this.canSelectItem(key) | ||
? new Selection([key], key, key) | ||
let selection = this.canSelectItem(mappedKey) | ||
? new Selection([mappedKey], mappedKey, mappedKey) | ||
: new Selection(); | ||
@@ -385,5 +391,5 @@ | ||
for (let key of keys) { | ||
key = this.getKey(key); | ||
if (key != null) { | ||
selection.add(key); | ||
let mappedKey = this.getKey(key); | ||
if (mappedKey != null) { | ||
selection.add(mappedKey); | ||
if (this.selectionMode === 'single') { | ||
@@ -400,7 +406,7 @@ break; | ||
let keys: Key[] = []; | ||
let addKeys = (key: Key) => { | ||
let addKeys = (key: Key | null) => { | ||
while (key != null) { | ||
if (this.canSelectItem(key)) { | ||
let item = this.collection.getItem(key); | ||
if (item.type === 'item') { | ||
if (item?.type === 'item') { | ||
keys.push(key); | ||
@@ -410,4 +416,4 @@ } | ||
// Add child keys. If cell selection is allowed, then include item children too. | ||
if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) { | ||
addKeys(getFirstItem(getChildNodes(item, this.collection)).key); | ||
if (item?.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) { | ||
addKeys(getFirstItem(getChildNodes(item, this.collection))?.key ?? null); | ||
} | ||
@@ -414,0 +420,0 @@ } |
@@ -22,5 +22,5 @@ /* | ||
/** The current focused key in the collection. */ | ||
readonly focusedKey: Key, | ||
readonly focusedKey: Key | null, | ||
/** Whether the first or last child of the focused key should receive focus. */ | ||
readonly childFocusStrategy: FocusStrategy, | ||
readonly childFocusStrategy: FocusStrategy | null, | ||
/** Sets the focused key, and optionally, whether the first or last child of that key should receive focus. */ | ||
@@ -27,0 +27,0 @@ setFocusedKey(key: Key | null, child?: FocusStrategy): void |
@@ -13,3 +13,3 @@ /* | ||
import {DisabledBehavior, Key, MultipleSelection, SelectionBehavior, SelectionMode} from '@react-types/shared'; | ||
import {DisabledBehavior, FocusStrategy, Key, MultipleSelection, SelectionBehavior, SelectionMode} from '@react-types/shared'; | ||
import {MultipleSelectionState} from './types'; | ||
@@ -49,3 +49,3 @@ import {Selection} from './Selection'; | ||
selectionMode = 'none' as SelectionMode, | ||
disallowEmptySelection, | ||
disallowEmptySelection = false, | ||
allowDuplicateSelectionEvents, | ||
@@ -60,5 +60,5 @@ selectionBehavior: selectionBehaviorProp = 'toggle', | ||
let [, setFocused] = useState(false); | ||
let focusedKeyRef = useRef(null); | ||
let childFocusStrategyRef = useRef(null); | ||
let [, setFocusedKey] = useState(null); | ||
let focusedKeyRef = useRef<Key | null>(null); | ||
let childFocusStrategyRef = useRef<FocusStrategy | null>(null); | ||
let [, setFocusedKey] = useState<Key | null>(null); | ||
let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]); | ||
@@ -68,3 +68,3 @@ let defaultSelectedKeys = useMemo(() => convertSelection(props.defaultSelectedKeys, new Selection()), [props.defaultSelectedKeys]); | ||
selectedKeysProp, | ||
defaultSelectedKeys, | ||
defaultSelectedKeys!, | ||
props.onSelectionChange | ||
@@ -126,3 +126,3 @@ ); | ||
function convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Set<Key> { | ||
function convertSelection(selection: 'all' | Iterable<Key> | null | undefined, defaultValue?: Selection): 'all' | Set<Key> | undefined { | ||
if (!selection) { | ||
@@ -129,0 +129,0 @@ return defaultValue; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
183058
30
2252
+ Addedreact@19.0.0-rc-fb9a90fa48-20240614(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removedreact@18.3.1(transitive)
Updated@react-stately/utils@^3.10.5
Updated@react-types/shared@^3.26.0