Socket
Socket
Sign inDemoInstall

@react-stately/selection

Package Overview
Dependencies
Maintainers
2
Versions
760
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.15.0 to 3.15.1

56

dist/SelectionManager.main.js

@@ -69,3 +69,3 @@ var $21c847070f1f9569$exports = require("./Selection.main.js");

*/ get selectedKeys() {
return this.state.selectedKeys === "all" ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
return this.state.selectedKeys === 'all' ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
}

@@ -81,5 +81,5 @@ /**

*/ isSelected(key) {
if (this.state.selectionMode === "none") return false;
if (this.state.selectionMode === 'none') return false;
key = this.getKey(key);
return this.state.selectedKeys === "all" ? this.canSelectItem(key) : this.state.selectedKeys.has(key);
return this.state.selectedKeys === 'all' ? this.canSelectItem(key) : this.state.selectedKeys.has(key);
}

@@ -89,3 +89,3 @@ /**

*/ get isEmpty() {
return this.state.selectedKeys !== "all" && this.state.selectedKeys.size === 0;
return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;
}

@@ -96,3 +96,3 @@ /**

if (this.isEmpty) return false;
if (this.state.selectedKeys === "all") return true;
if (this.state.selectedKeys === 'all') return true;
if (this._isSelectAll != null) return this._isSelectAll;

@@ -129,4 +129,4 @@ let allKeys = this.getSelectAllKeys();

*/ extendSelection(toKey) {
if (this.selectionMode === "none") return;
if (this.selectionMode === "single") {
if (this.selectionMode === 'none') return;
if (this.selectionMode === 'single') {
this.replaceSelection(toKey);

@@ -138,3 +138,3 @@ return;

// Only select the one key if coming from a select all.
if (this.state.selectedKeys === "all") selection = new (0, $21c847070f1f9569$exports.Selection)([
if (this.state.selectedKeys === 'all') selection = new (0, $21c847070f1f9569$exports.Selection)([
toKey

@@ -165,3 +165,3 @@ ], toKey, toKey);

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;

@@ -177,6 +177,6 @@ key = this.collection.getKeyAfter(key);

// If cell selection is allowed, just return the key.
if (item.type === "cell" && this.allowsCellSelection) return key;
if (item.type === 'cell' && this.allowsCellSelection) return key;
// Find a parent item to select
while(item.type !== "item" && item.parentKey != null)item = this.collection.getItem(item.parentKey);
if (!item || item.type !== "item") return null;
while(item.type !== 'item' && item.parentKey != null)item = this.collection.getItem(item.parentKey);
if (!item || item.type !== 'item') return null;
return item.key;

@@ -187,4 +187,4 @@ }

*/ toggleSelection(key) {
if (this.selectionMode === "none") return;
if (this.selectionMode === "single" && !this.isSelected(key)) {
if (this.selectionMode === 'none') return;
if (this.selectionMode === 'single' && !this.isSelected(key)) {
this.replaceSelection(key);

@@ -195,3 +195,3 @@ return;

if (key == null) return;
let keys = new (0, $21c847070f1f9569$exports.Selection)(this.state.selectedKeys === "all" ? this.getSelectAllKeys() : this.state.selectedKeys);
let keys = new (0, $21c847070f1f9569$exports.Selection)(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);
if (keys.has(key)) keys.delete(key);

@@ -209,3 +209,3 @@ else if (this.canSelectItem(key)) {

*/ replaceSelection(key) {
if (this.selectionMode === "none") return;
if (this.selectionMode === 'none') return;
key = this.getKey(key);

@@ -221,3 +221,3 @@ if (key == null) return;

*/ setSelectedKeys(keys) {
if (this.selectionMode === "none") return;
if (this.selectionMode === 'none') return;
let selection = new (0, $21c847070f1f9569$exports.Selection)();

@@ -228,3 +228,3 @@ for (let key of keys){

selection.add(key);
if (this.selectionMode === "single") break;
if (this.selectionMode === 'single') break;
}

@@ -240,5 +240,5 @@ }

let item = this.collection.getItem(key);
if (item.type === "item") keys.push(key);
if (item.type === 'item') keys.push(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.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) addKeys((0, $ia6MY$reactstatelycollections.getFirstItem)((0, $ia6MY$reactstatelycollections.getChildNodes)(item, this.collection)).key);
}

@@ -254,3 +254,3 @@ key = this.collection.getKeyAfter(key);

*/ selectAll() {
if (!this.isSelectAll && this.selectionMode === "multiple") this.state.setSelectedKeys("all");
if (!this.isSelectAll && this.selectionMode === 'multiple') this.state.setSelectedKeys('all');
}

@@ -260,3 +260,3 @@ /**

*/ clearSelection() {
if (!this.disallowEmptySelection && (this.state.selectedKeys === "all" || this.state.selectedKeys.size > 0)) this.state.setSelectedKeys(new (0, $21c847070f1f9569$exports.Selection)());
if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) this.state.setSelectedKeys(new (0, $21c847070f1f9569$exports.Selection)());
}

@@ -270,7 +270,7 @@ /**

select(key, e) {
if (this.selectionMode === "none") return;
if (this.selectionMode === "single") {
if (this.selectionMode === 'none') return;
if (this.selectionMode === 'single') {
if (this.isSelected(key) && !this.disallowEmptySelection) this.toggleSelection(key);
else this.replaceSelection(key);
} else if (this.selectionBehavior === "toggle" || e && (e.pointerType === "touch" || e.pointerType === "virtual")) // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys
} else if (this.selectionBehavior === 'toggle' || e && (e.pointerType === 'touch' || e.pointerType === 'virtual')) // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys
this.toggleSelection(key);

@@ -296,5 +296,5 @@ else this.replaceSelection(key);

var _item_props;
if (this.state.selectionMode === "none" || this.state.disabledKeys.has(key)) return false;
if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) return false;
let item = this.collection.getItem(key);
if (!item || (item === null || item === void 0 ? void 0 : (_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.isDisabled) || item.type === "cell" && !this.allowsCellSelection) return false;
if (!item || (item === null || item === void 0 ? void 0 : (_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.isDisabled) || item.type === 'cell' && !this.allowsCellSelection) return false;
return true;

@@ -304,3 +304,3 @@ }

var _this_collection_getItem_props, _this_collection_getItem;
return this.state.disabledBehavior === "all" && (this.state.disabledKeys.has(key) || !!((_this_collection_getItem = this.collection.getItem(key)) === null || _this_collection_getItem === void 0 ? void 0 : (_this_collection_getItem_props = _this_collection_getItem.props) === null || _this_collection_getItem_props === void 0 ? void 0 : _this_collection_getItem_props.isDisabled));
return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!((_this_collection_getItem = this.collection.getItem(key)) === null || _this_collection_getItem === void 0 ? void 0 : (_this_collection_getItem_props = _this_collection_getItem.props) === null || _this_collection_getItem_props === void 0 ? void 0 : _this_collection_getItem_props.isDisabled));
}

@@ -307,0 +307,0 @@ isLink(key) {

@@ -63,3 +63,3 @@ import {Selection as $e40ea825a81a3709$export$52baac22726c72bf} from "./Selection.module.js";

*/ get selectedKeys() {
return this.state.selectedKeys === "all" ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
return this.state.selectedKeys === 'all' ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;
}

@@ -75,5 +75,5 @@ /**

*/ isSelected(key) {
if (this.state.selectionMode === "none") return false;
if (this.state.selectionMode === 'none') return false;
key = this.getKey(key);
return this.state.selectedKeys === "all" ? this.canSelectItem(key) : this.state.selectedKeys.has(key);
return this.state.selectedKeys === 'all' ? this.canSelectItem(key) : this.state.selectedKeys.has(key);
}

@@ -83,3 +83,3 @@ /**

*/ get isEmpty() {
return this.state.selectedKeys !== "all" && this.state.selectedKeys.size === 0;
return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;
}

@@ -90,3 +90,3 @@ /**

if (this.isEmpty) return false;
if (this.state.selectedKeys === "all") return true;
if (this.state.selectedKeys === 'all') return true;
if (this._isSelectAll != null) return this._isSelectAll;

@@ -123,4 +123,4 @@ let allKeys = this.getSelectAllKeys();

*/ extendSelection(toKey) {
if (this.selectionMode === "none") return;
if (this.selectionMode === "single") {
if (this.selectionMode === 'none') return;
if (this.selectionMode === 'single') {
this.replaceSelection(toKey);

@@ -132,3 +132,3 @@ return;

// Only select the one key if coming from a select all.
if (this.state.selectedKeys === "all") selection = new (0, $e40ea825a81a3709$export$52baac22726c72bf)([
if (this.state.selectedKeys === 'all') selection = new (0, $e40ea825a81a3709$export$52baac22726c72bf)([
toKey

@@ -159,3 +159,3 @@ ], toKey, toKey);

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;

@@ -171,6 +171,6 @@ key = this.collection.getKeyAfter(key);

// If cell selection is allowed, just return the key.
if (item.type === "cell" && this.allowsCellSelection) return key;
if (item.type === 'cell' && this.allowsCellSelection) return key;
// Find a parent item to select
while(item.type !== "item" && item.parentKey != null)item = this.collection.getItem(item.parentKey);
if (!item || item.type !== "item") return null;
while(item.type !== 'item' && item.parentKey != null)item = this.collection.getItem(item.parentKey);
if (!item || item.type !== 'item') return null;
return item.key;

@@ -181,4 +181,4 @@ }

*/ toggleSelection(key) {
if (this.selectionMode === "none") return;
if (this.selectionMode === "single" && !this.isSelected(key)) {
if (this.selectionMode === 'none') return;
if (this.selectionMode === 'single' && !this.isSelected(key)) {
this.replaceSelection(key);

@@ -189,3 +189,3 @@ return;

if (key == null) return;
let keys = new (0, $e40ea825a81a3709$export$52baac22726c72bf)(this.state.selectedKeys === "all" ? this.getSelectAllKeys() : this.state.selectedKeys);
let keys = new (0, $e40ea825a81a3709$export$52baac22726c72bf)(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);
if (keys.has(key)) keys.delete(key);

@@ -203,3 +203,3 @@ else if (this.canSelectItem(key)) {

*/ replaceSelection(key) {
if (this.selectionMode === "none") return;
if (this.selectionMode === 'none') return;
key = this.getKey(key);

@@ -215,3 +215,3 @@ if (key == null) return;

*/ setSelectedKeys(keys) {
if (this.selectionMode === "none") return;
if (this.selectionMode === 'none') return;
let selection = new (0, $e40ea825a81a3709$export$52baac22726c72bf)();

@@ -222,3 +222,3 @@ for (let key of keys){

selection.add(key);
if (this.selectionMode === "single") break;
if (this.selectionMode === 'single') break;
}

@@ -234,5 +234,5 @@ }

let item = this.collection.getItem(key);
if (item.type === "item") keys.push(key);
if (item.type === 'item') keys.push(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.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) addKeys((0, $jkhUT$getFirstItem)((0, $jkhUT$getChildNodes)(item, this.collection)).key);
}

@@ -248,3 +248,3 @@ key = this.collection.getKeyAfter(key);

*/ selectAll() {
if (!this.isSelectAll && this.selectionMode === "multiple") this.state.setSelectedKeys("all");
if (!this.isSelectAll && this.selectionMode === 'multiple') this.state.setSelectedKeys('all');
}

@@ -254,3 +254,3 @@ /**

*/ clearSelection() {
if (!this.disallowEmptySelection && (this.state.selectedKeys === "all" || this.state.selectedKeys.size > 0)) this.state.setSelectedKeys(new (0, $e40ea825a81a3709$export$52baac22726c72bf)());
if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) this.state.setSelectedKeys(new (0, $e40ea825a81a3709$export$52baac22726c72bf)());
}

@@ -264,7 +264,7 @@ /**

select(key, e) {
if (this.selectionMode === "none") return;
if (this.selectionMode === "single") {
if (this.selectionMode === 'none') return;
if (this.selectionMode === 'single') {
if (this.isSelected(key) && !this.disallowEmptySelection) this.toggleSelection(key);
else this.replaceSelection(key);
} else if (this.selectionBehavior === "toggle" || e && (e.pointerType === "touch" || e.pointerType === "virtual")) // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys
} else if (this.selectionBehavior === 'toggle' || e && (e.pointerType === 'touch' || e.pointerType === 'virtual')) // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys
this.toggleSelection(key);

@@ -290,5 +290,5 @@ else this.replaceSelection(key);

var _item_props;
if (this.state.selectionMode === "none" || this.state.disabledKeys.has(key)) return false;
if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) return false;
let item = this.collection.getItem(key);
if (!item || (item === null || item === void 0 ? void 0 : (_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.isDisabled) || item.type === "cell" && !this.allowsCellSelection) return false;
if (!item || (item === null || item === void 0 ? void 0 : (_item_props = item.props) === null || _item_props === void 0 ? void 0 : _item_props.isDisabled) || item.type === 'cell' && !this.allowsCellSelection) return false;
return true;

@@ -298,3 +298,3 @@ }

var _this_collection_getItem_props, _this_collection_getItem;
return this.state.disabledBehavior === "all" && (this.state.disabledKeys.has(key) || !!((_this_collection_getItem = this.collection.getItem(key)) === null || _this_collection_getItem === void 0 ? void 0 : (_this_collection_getItem_props = _this_collection_getItem.props) === null || _this_collection_getItem_props === void 0 ? void 0 : _this_collection_getItem_props.isDisabled));
return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!((_this_collection_getItem = this.collection.getItem(key)) === null || _this_collection_getItem === void 0 ? void 0 : (_this_collection_getItem_props = _this_collection_getItem.props) === null || _this_collection_getItem_props === void 0 ? void 0 : _this_collection_getItem_props.isDisabled));
}

@@ -301,0 +301,0 @@ isLink(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, allowDuplicateSelectionEvents: allowDuplicateSelectionEvents, selectionBehavior: selectionBehaviorProp = 'toggle', disabledBehavior: disabledBehavior = 'all' } = props;
// We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.

@@ -54,3 +54,3 @@ // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).

// to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.
if (selectionBehaviorProp === "replace" && selectionBehavior === "toggle" && typeof selectedKeys === "object" && selectedKeys.size === 0) setSelectionBehavior("replace");
if (selectionBehaviorProp === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) setSelectionBehavior('replace');
// If the selectionBehavior prop changes, update the state as well.

@@ -84,3 +84,3 @@ let lastSelectionBehavior = (0, $byFPT$react.useRef)(selectionBehaviorProp);

},
setFocusedKey (k, childFocusStrategy = "first") {
setFocusedKey (k, childFocusStrategy = 'first') {
focusedKeyRef.current = k;

@@ -100,3 +100,3 @@ childFocusStrategyRef.current = childFocusStrategy;

if (!selection) return defaultValue;
return selection === "all" ? "all" : new (0, $21c847070f1f9569$exports.Selection)(selection);
return selection === 'all' ? 'all' : new (0, $21c847070f1f9569$exports.Selection)(selection);
}

@@ -103,0 +103,0 @@

@@ -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, allowDuplicateSelectionEvents: allowDuplicateSelectionEvents, selectionBehavior: selectionBehaviorProp = 'toggle', disabledBehavior: disabledBehavior = 'all' } = props;
// We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.

@@ -48,3 +48,3 @@ // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).

// to enter selection mode on touch), and the selection becomes empty, reset the selection behavior.
if (selectionBehaviorProp === "replace" && selectionBehavior === "toggle" && typeof selectedKeys === "object" && selectedKeys.size === 0) setSelectionBehavior("replace");
if (selectionBehaviorProp === 'replace' && selectionBehavior === 'toggle' && typeof selectedKeys === 'object' && selectedKeys.size === 0) setSelectionBehavior('replace');
// If the selectionBehavior prop changes, update the state as well.

@@ -78,3 +78,3 @@ let lastSelectionBehavior = (0, $6tM1y$useRef)(selectionBehaviorProp);

},
setFocusedKey (k, childFocusStrategy = "first") {
setFocusedKey (k, childFocusStrategy = 'first') {
focusedKeyRef.current = k;

@@ -94,3 +94,3 @@ childFocusStrategyRef.current = childFocusStrategy;

if (!selection) return defaultValue;
return selection === "all" ? "all" : new (0, $e40ea825a81a3709$export$52baac22726c72bf)(selection);
return selection === 'all' ? 'all' : new (0, $e40ea825a81a3709$export$52baac22726c72bf)(selection);
}

@@ -97,0 +97,0 @@

{
"name": "@react-stately/selection",
"version": "3.15.0",
"version": "3.15.1",
"description": "Spectrum UI components in React",

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

"dependencies": {
"@react-stately/collections": "^3.10.6",
"@react-stately/utils": "^3.10.0",
"@react-types/shared": "^3.23.0",
"@react-stately/collections": "^3.10.7",
"@react-stately/utils": "^3.10.1",
"@react-types/shared": "^3.23.1",
"@swc/helpers": "^0.5.0"

@@ -37,3 +37,3 @@ },

},
"gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
"gitHead": "b77d7d594dff4dcfb5359bffbcfd18142b146433"
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc