@react-stately/selection
Advanced tools
Comparing version 3.5.0 to 3.6.0
@@ -189,2 +189,11 @@ var { | ||
/** | ||
* The raw selection value for the collection. | ||
* Either 'all' for select all, or a set of keys. | ||
*/ | ||
get rawSelection() { | ||
return this.state.selectedKeys; | ||
} | ||
/** | ||
* Returns whether a key is selected. | ||
@@ -272,14 +281,13 @@ */ | ||
toKey = this.getKey(toKey); | ||
this.state.setSelectedKeys(selectedKeys => { | ||
// Only select the one key if coming from a select all. | ||
if (selectedKeys === 'all') { | ||
return new $cc81f14158b02e1e259a5a46d24f0c$export$Selection([toKey], toKey, toKey); | ||
} | ||
let selection; // Only select the one key if coming from a select all. | ||
let selection = selectedKeys; | ||
let anchorKey = selection.anchorKey || toKey; | ||
let keys = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(selection, anchorKey, toKey); | ||
if (this.state.selectedKeys === 'all') { | ||
selection = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection([toKey], toKey, toKey); | ||
} else { | ||
let selectedKeys = this.state.selectedKeys; | ||
let anchorKey = selectedKeys.anchorKey || toKey; | ||
selection = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(selectedKeys, anchorKey, toKey); | ||
for (let key of this.getKeyRange(anchorKey, selection.currentKey || toKey)) { | ||
keys.delete(key); | ||
for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey)) { | ||
selection.delete(key); | ||
} | ||
@@ -289,8 +297,8 @@ | ||
if (!this.state.disabledKeys.has(key)) { | ||
keys.add(key); | ||
selection.add(key); | ||
} | ||
} | ||
} | ||
return keys; | ||
}); | ||
this.state.setSelectedKeys(selection); | ||
} | ||
@@ -370,16 +378,14 @@ | ||
this.state.setSelectedKeys(selectedKeys => { | ||
let keys = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : selectedKeys); | ||
let keys = new $cc81f14158b02e1e259a5a46d24f0c$export$Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys); | ||
if (keys.has(key)) { | ||
keys.delete(key); // TODO: move anchor to last selected key... | ||
// Does `current` need to move here too? | ||
} else { | ||
keys.add(key); | ||
keys.anchorKey = key; | ||
keys.currentKey = key; | ||
} | ||
if (keys.has(key)) { | ||
keys.delete(key); // TODO: move anchor to last selected key... | ||
// Does `current` need to move here too? | ||
} else { | ||
keys.add(key); | ||
keys.anchorKey = key; | ||
keys.currentKey = key; | ||
} | ||
return keys; | ||
}); | ||
this.state.setSelectedKeys(keys); | ||
} | ||
@@ -386,0 +392,0 @@ /** |
@@ -180,2 +180,11 @@ import { useControlledState } from "@react-stately/utils"; | ||
/** | ||
* The raw selection value for the collection. | ||
* Either 'all' for select all, or a set of keys. | ||
*/ | ||
get rawSelection() { | ||
return this.state.selectedKeys; | ||
} | ||
/** | ||
* Returns whether a key is selected. | ||
@@ -263,14 +272,13 @@ */ | ||
toKey = this.getKey(toKey); | ||
this.state.setSelectedKeys(selectedKeys => { | ||
// Only select the one key if coming from a select all. | ||
if (selectedKeys === 'all') { | ||
return new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection([toKey], toKey, toKey); | ||
} | ||
let selection; // Only select the one key if coming from a select all. | ||
let selection = selectedKeys; | ||
let anchorKey = selection.anchorKey || toKey; | ||
let keys = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(selection, anchorKey, toKey); | ||
if (this.state.selectedKeys === 'all') { | ||
selection = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection([toKey], toKey, toKey); | ||
} else { | ||
let selectedKeys = this.state.selectedKeys; | ||
let anchorKey = selectedKeys.anchorKey || toKey; | ||
selection = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(selectedKeys, anchorKey, toKey); | ||
for (let key of this.getKeyRange(anchorKey, selection.currentKey || toKey)) { | ||
keys.delete(key); | ||
for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey || toKey)) { | ||
selection.delete(key); | ||
} | ||
@@ -280,8 +288,8 @@ | ||
if (!this.state.disabledKeys.has(key)) { | ||
keys.add(key); | ||
selection.add(key); | ||
} | ||
} | ||
} | ||
return keys; | ||
}); | ||
this.state.setSelectedKeys(selection); | ||
} | ||
@@ -361,16 +369,14 @@ | ||
this.state.setSelectedKeys(selectedKeys => { | ||
let keys = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : selectedKeys); | ||
let keys = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys); | ||
if (keys.has(key)) { | ||
keys.delete(key); // TODO: move anchor to last selected key... | ||
// Does `current` need to move here too? | ||
} else { | ||
keys.add(key); | ||
keys.anchorKey = key; | ||
keys.currentKey = key; | ||
} | ||
if (keys.has(key)) { | ||
keys.delete(key); // TODO: move anchor to last selected key... | ||
// Does `current` need to move here too? | ||
} else { | ||
keys.add(key); | ||
keys.anchorKey = key; | ||
keys.currentKey = key; | ||
} | ||
return keys; | ||
}); | ||
this.state.setSelectedKeys(keys); | ||
} | ||
@@ -377,0 +383,0 @@ /** |
@@ -117,2 +117,7 @@ import { FocusStrategy, PressEvent, Selection, SelectionMode, MultipleSelection, Collection, Node } from "@react-types/shared"; | ||
/** | ||
* The raw selection value for the collection. | ||
* Either 'all' for select all, or a set of keys. | ||
*/ | ||
get rawSelection(): Selection; | ||
/** | ||
* Returns whether a key is selected. | ||
@@ -119,0 +124,0 @@ */ |
{ | ||
"name": "@react-stately/selection", | ||
"version": "3.5.0", | ||
"version": "3.6.0", | ||
"description": "Spectrum UI components in React", | ||
@@ -23,3 +23,3 @@ "license": "Apache-2.0", | ||
"@react-stately/utils": "^3.2.1", | ||
"@react-types/shared": "^3.6.0" | ||
"@react-types/shared": "^3.7.0" | ||
}, | ||
@@ -32,3 +32,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "3aae08e7d8a75382bedcddac7c86107e40db9296" | ||
"gitHead": "83b70255d97b3068988f8972e9c9a39a7352926e" | ||
} |
@@ -13,3 +13,3 @@ /* | ||
import {Collection, FocusStrategy, Node, PressEvent, SelectionMode} from '@react-types/shared'; | ||
import {Collection, FocusStrategy, Selection as ISelection, Node, PressEvent, SelectionMode} from '@react-types/shared'; | ||
import {Key} from 'react'; | ||
@@ -96,2 +96,10 @@ import {MultipleSelectionManager, MultipleSelectionState} from './types'; | ||
/** | ||
* The raw selection value for the collection. | ||
* Either 'all' for select all, or a set of keys. | ||
*/ | ||
get rawSelection(): ISelection { | ||
return this.state.selectedKeys; | ||
} | ||
/** | ||
* Returns whether a key is selected. | ||
@@ -166,13 +174,14 @@ */ | ||
toKey = this.getKey(toKey); | ||
this.state.setSelectedKeys(selectedKeys => { | ||
// Only select the one key if coming from a select all. | ||
if (selectedKeys === 'all') { | ||
return new Selection([toKey], toKey, toKey); | ||
} | ||
let selection = selectedKeys as Selection; | ||
let anchorKey = selection.anchorKey || toKey; | ||
let keys = new Selection(selection, anchorKey, toKey); | ||
for (let key of this.getKeyRange(anchorKey, selection.currentKey || toKey)) { | ||
keys.delete(key); | ||
let selection: Selection; | ||
// Only select the one key if coming from a select all. | ||
if (this.state.selectedKeys === 'all') { | ||
selection = new Selection([toKey], toKey, toKey); | ||
} 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)) { | ||
selection.delete(key); | ||
} | ||
@@ -182,8 +191,8 @@ | ||
if (!this.state.disabledKeys.has(key)) { | ||
keys.add(key); | ||
selection.add(key); | ||
} | ||
} | ||
} | ||
return keys; | ||
}); | ||
this.state.setSelectedKeys(selection); | ||
} | ||
@@ -257,16 +266,14 @@ | ||
this.state.setSelectedKeys(selectedKeys => { | ||
let keys = new Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : selectedKeys); | ||
if (keys.has(key)) { | ||
keys.delete(key); | ||
// TODO: move anchor to last selected key... | ||
// Does `current` need to move here too? | ||
} else { | ||
keys.add(key); | ||
keys.anchorKey = key; | ||
keys.currentKey = key; | ||
} | ||
let keys = new Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys); | ||
if (keys.has(key)) { | ||
keys.delete(key); | ||
// TODO: move anchor to last selected key... | ||
// Does `current` need to move here too? | ||
} else { | ||
keys.add(key); | ||
keys.anchorKey = key; | ||
keys.currentKey = key; | ||
} | ||
return keys; | ||
}); | ||
this.state.setSelectedKeys(keys); | ||
} | ||
@@ -273,0 +280,0 @@ |
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
120096
1542
Updated@react-types/shared@^3.7.0