@react-stately/selection 3.19.0 → 3.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -303,6 +303,12 @@ class $8112da6fa5bbc322$export$6c8a5aaad13c9852 {
303
303
  var _this_collection_getItem;
304
304
  return (_this_collection_getItem = this.collection.getItem(key)) === null || _this_collection_getItem === void 0 ? void 0 : _this_collection_getItem.props;
305
305
  }
306
+ withCollection(collection) {
307
+ return new $8112da6fa5bbc322$export$6c8a5aaad13c9852(collection, this.state, {
308
+ allowsCellSelection: this.allowsCellSelection,
309
+ layoutDelegate: this.layoutDelegate || undefined
310
+ });
311
+ }
306
312
  constructor(collection, state, options){
307
313
  this.collection = collection;
308
314
  this.state = state;
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA0BM,MAAM;IAeX;;GAEC,GACD,IAAI,gBAA+B;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa;IACjC;IAEA;;GAEC,GACD,IAAI,yBAAkC;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB;IAC1C;IAEA;;GAEC,GACD,IAAI,oBAAuC;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB;IACrC;IAEA;;GAEC,GACD,qBAAqB,iBAAoC,EAAE;QACzD,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC;IAClC;IAEA;;GAEC,GACD,IAAI,YAAqB;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS;IAC7B;IAEA;;GAEC,GACD,WAAW,SAAkB,EAAE;QAC7B,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;IACxB;IAEA;;GAEC,GACD,IAAI,aAAyB;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU;IAC9B;IAEA,6EAA6E,GAC7E,IAAI,qBAA2C;QAC7C,OAAO,IAAI,CAAC,KAAK,CAAC,kBAAkB;IACtC;IAEA;;GAE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,+CAAA,yBAA8B,KAAK;IAC5C;IAtdA,YAAY,UAAqC,EAAE,KAA6B,EAAE,OAAiC,CAAE;QACnH,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,KAAK,GAAG;YACc;QAA3B,IAAI,CAAC,mBAAmB,GAAG,CAAA,+BAAA,oBAAA,8BAAA,QAAS,mBAAmB,cAA5B,0CAAA,+BAAgC;QAC3D,IAAI,CAAC,YAAY,GAAG;QACpB,IAAI,CAAC,cAAc,GAAG,CAAA,oBAAA,8BAAA,QAAS,cAAc,KAAI;IACnD;AAidF","sources":["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 {\n Collection, DisabledBehavior,\n FocusStrategy,\n Selection as ISelection,\n Key,\n LayoutDelegate,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {compareNodeOrder, getChildNodes, getFirstItem} from '@react-stately/collections';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean,\n layoutDelegate?: LayoutDelegate\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean | null;\n private layoutDelegate: LayoutDelegate | null;\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 this.layoutDelegate = options?.layoutDelegate || 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 * The selection behavior for the collection.\n */\n get selectionBehavior(): SelectionBehavior {\n return this.state.selectionBehavior;\n }\n\n /**\n * Sets the selection behavior for the collection.\n */\n setSelectionBehavior(selectionBehavior: SelectionBehavior) {\n this.state.setSelectionBehavior(selectionBehavior);\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 | null {\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 | null {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy) {\n if (key == null || this.collection.getItem(key)) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\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 * The raw selection value for the collection.\n * Either 'all' for select all, or a set of keys.\n */\n get rawSelection(): ISelection {\n return 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 let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return false;\n }\n return this.state.selectedKeys === 'all'\n ? this.canSelectItem(mappedKey)\n : this.state.selectedKeys.has(mappedKey);\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 && compareNodeOrder(this.collection, item, first) < 0)) {\n first = item;\n }\n }\n\n return first?.key ?? null;\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 && compareNodeOrder(this.collection, item, last) > 0)) {\n last = item;\n }\n }\n\n return last?.key ?? null;\n }\n\n get disabledKeys(): Set<Key> {\n return this.state.disabledKeys;\n }\n\n get disabledBehavior(): DisabledBehavior {\n return this.state.disabledBehavior;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n this.replaceSelection(toKey);\n return;\n }\n\n let mappedToKey = this.getKey(toKey);\n if (mappedToKey == null) {\n return;\n }\n\n let selection: Selection;\n\n // Only select the one key if coming from a select all.\n if (this.state.selectedKeys === 'all') {\n selection = new Selection([mappedToKey], mappedToKey, mappedToKey);\n } else {\n let selectedKeys = this.state.selectedKeys as Selection;\n let anchorKey = selectedKeys.anchorKey ?? mappedToKey;\n selection = new Selection(selectedKeys, anchorKey, mappedToKey);\n for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? mappedToKey)) {\n selection.delete(key);\n }\n\n for (let key of this.getKeyRange(mappedToKey, anchorKey)) {\n if (this.canSelectItem(key)) {\n selection.add(key);\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\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 (compareNodeOrder(this.collection, fromItem, toItem) <= 0) {\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 if (this.layoutDelegate?.getKeyRange) {\n return this.layoutDelegate.getKeyRange(from, to);\n }\n\n let keys: Key[] = [];\n let key: Key | null = from;\n while (key != null) {\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 && item.type !== 'item' && item.parentKey != null) {\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 if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single' && !this.isSelected(key)) {\n this.replaceSelection(key);\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let keys = new Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);\n if (keys.has(mappedKey)) {\n keys.delete(mappedKey);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else if (this.canSelectItem(mappedKey)) {\n keys.add(mappedKey);\n keys.anchorKey = mappedKey;\n keys.currentKey = mappedKey;\n }\n\n if (this.disallowEmptySelection && keys.size === 0) {\n return;\n }\n\n this.state.setSelectedKeys(keys);\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let selection = this.canSelectItem(mappedKey)\n ? new Selection([mappedKey], mappedKey, mappedKey)\n : new Selection();\n\n this.state.setSelectedKeys(selection);\n }\n\n /**\n * Replaces the selection with the given keys.\n */\n setSelectedKeys(keys: Iterable<Key>) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let selection = new Selection();\n for (let key of keys) {\n let mappedKey = this.getKey(key);\n if (mappedKey != null) {\n selection.add(mappedKey);\n if (this.selectionMode === 'single') {\n break;\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getSelectAllKeys() {\n let keys: Key[] = [];\n let addKeys = (key: Key | null) => {\n while (key != null) {\n if (this.canSelectItem(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(getFirstItem(getChildNodes(item, this.collection))?.key ?? null);\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.isSelectAll && 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.disallowEmptySelection && (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 | LongPressEvent | 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 (this.selectionBehavior === 'toggle' || (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))) {\n // 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\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n }\n\n /**\n * Returns whether the current selection is equal to the given selection.\n */\n isSelectionEqual(selection: Set<Key>) {\n if (selection === this.state.selectedKeys) {\n return true;\n }\n\n // Check if the set of keys match.\n let selectedKeys = this.selectedKeys;\n if (selection.size !== selectedKeys.size) {\n return false;\n }\n\n for (let key of selection) {\n if (!selectedKeys.has(key)) {\n return false;\n }\n }\n\n for (let key of selectedKeys) {\n if (!selection.has(key)) {\n return false;\n }\n }\n\n return true;\n }\n\n canSelectItem(key: Key) {\n if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {\n return false;\n }\n\n let item = this.collection.getItem(key);\n if (!item || item?.props?.isDisabled || (item.type === 'cell' && !this.allowsCellSelection)) {\n return false;\n }\n\n return true;\n }\n\n isDisabled(key: Key) {\n return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!this.collection.getItem(key)?.props?.isDisabled);\n }\n\n isLink(key: Key) {\n return !!this.collection.getItem(key)?.props?.href;\n }\n\n getItemProps(key: Key) {\n return this.collection.getItem(key)?.props;\n }\n}\n"],"names":[],"version":3,"file":"SelectionManager.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AA0BM,MAAM;IAeX;;GAEC,GACD,IAAI,gBAA+B;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa;IACjC;IAEA;;GAEC,GACD,IAAI,yBAAkC;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB;IAC1C;IAEA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AC2D,gCAAA;QAAvF,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,KAAK,SAAU,CAAA,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAC,2BAAA,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAxB,gDAAA,iCAAA,yBAA8B,KAAK,cAAnC,qDAAA,+BAAqC,UAAU,CAAD;IACvI;IAEA,OAAO,GAAQ,EAAW;YACf,gCAAA;QAAT,OAAO,CAAC,GAAC,2BAAA,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAxB,gDAAA,iCAAA,yBAA8B,KAAK,cAAnC,qDAAA,+BAAqC,IAAI;IACpD;IAEA,aAAa,GAAQ,EAAO;YACnB;QAAP,QAAO,2BAAA,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAxB,+CAAA,yBAA8B,KAAK;IAC5C;IAEA,eAAe,UAAqC,EAAoB;QACtE,OAAO,IAAI,0CAAiB,YAAY,IAAI,CAAC,KAAK,EAAE;YAClD,qBAAqB,IAAI,CAAC,mBAAmB;YAC7C,gBAAgB,IAAI,CAAC,cAAc,IAAI;QACzC;IACF;IA7dA,YAAY,UAAqC,EAAE,KAA6B,EAAE,OAAiC,CAAE;QACnH,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,KAAK,GAAG;YACc;QAA3B,IAAI,CAAC,mBAAmB,GAAG,CAAA,+BAAA,oBAAA,8BAAA,QAAS,mBAAmB,cAA5B,0CAAA,+BAAgC;QAC3D,IAAI,CAAC,YAAY,GAAG;QACpB,IAAI,CAAC,cAAc,GAAG,CAAA,oBAAA,8BAAA,QAAS,cAAc,KAAI;IACnD;AAwdF","sources":["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 {\n Collection, DisabledBehavior,\n FocusStrategy,\n Selection as ISelection,\n Key,\n LayoutDelegate,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {compareNodeOrder, getChildNodes, getFirstItem} from '@react-stately/collections';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean,\n layoutDelegate?: LayoutDelegate\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean | null;\n private layoutDelegate: LayoutDelegate | null;\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 this.layoutDelegate = options?.layoutDelegate || 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 * The selection behavior for the collection.\n */\n get selectionBehavior(): SelectionBehavior {\n return this.state.selectionBehavior;\n }\n\n /**\n * Sets the selection behavior for the collection.\n */\n setSelectionBehavior(selectionBehavior: SelectionBehavior): void {\n this.state.setSelectionBehavior(selectionBehavior);\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): void {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key | null {\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 | null {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void {\n if (key == null || this.collection.getItem(key)) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\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 * The raw selection value for the collection.\n * Either 'all' for select all, or a set of keys.\n */\n get rawSelection(): ISelection {\n return this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key): boolean {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return false;\n }\n return this.state.selectedKeys === 'all'\n ? this.canSelectItem(mappedKey)\n : this.state.selectedKeys.has(mappedKey);\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 && compareNodeOrder(this.collection, item, first) < 0)) {\n first = item;\n }\n }\n\n return first?.key ?? null;\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 && compareNodeOrder(this.collection, item, last) > 0)) {\n last = item;\n }\n }\n\n return last?.key ?? null;\n }\n\n get disabledKeys(): Set<Key> {\n return this.state.disabledKeys;\n }\n\n get disabledBehavior(): DisabledBehavior {\n return this.state.disabledBehavior;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n this.replaceSelection(toKey);\n return;\n }\n\n let mappedToKey = this.getKey(toKey);\n if (mappedToKey == null) {\n return;\n }\n\n let selection: Selection;\n\n // Only select the one key if coming from a select all.\n if (this.state.selectedKeys === 'all') {\n selection = new Selection([mappedToKey], mappedToKey, mappedToKey);\n } else {\n let selectedKeys = this.state.selectedKeys as Selection;\n let anchorKey = selectedKeys.anchorKey ?? mappedToKey;\n selection = new Selection(selectedKeys, anchorKey, mappedToKey);\n for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? mappedToKey)) {\n selection.delete(key);\n }\n\n for (let key of this.getKeyRange(mappedToKey, anchorKey)) {\n if (this.canSelectItem(key)) {\n selection.add(key);\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\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 (compareNodeOrder(this.collection, fromItem, toItem) <= 0) {\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 if (this.layoutDelegate?.getKeyRange) {\n return this.layoutDelegate.getKeyRange(from, to);\n }\n\n let keys: Key[] = [];\n let key: Key | null = from;\n while (key != null) {\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 && item.type !== 'item' && item.parentKey != null) {\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): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single' && !this.isSelected(key)) {\n this.replaceSelection(key);\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let keys = new Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);\n if (keys.has(mappedKey)) {\n keys.delete(mappedKey);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else if (this.canSelectItem(mappedKey)) {\n keys.add(mappedKey);\n keys.anchorKey = mappedKey;\n keys.currentKey = mappedKey;\n }\n\n if (this.disallowEmptySelection && keys.size === 0) {\n return;\n }\n\n this.state.setSelectedKeys(keys);\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let selection = this.canSelectItem(mappedKey)\n ? new Selection([mappedKey], mappedKey, mappedKey)\n : new Selection();\n\n this.state.setSelectedKeys(selection);\n }\n\n /**\n * Replaces the selection with the given keys.\n */\n setSelectedKeys(keys: Iterable<Key>): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let selection = new Selection();\n for (let key of keys) {\n let mappedKey = this.getKey(key);\n if (mappedKey != null) {\n selection.add(mappedKey);\n if (this.selectionMode === 'single') {\n break;\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getSelectAllKeys() {\n let keys: Key[] = [];\n let addKeys = (key: Key | null) => {\n while (key != null) {\n if (this.canSelectItem(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(getFirstItem(getChildNodes(item, this.collection))?.key ?? null);\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(): void {\n if (!this.isSelectAll && this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection(): void {\n if (!this.disallowEmptySelection && (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(): void {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void {\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 (this.selectionBehavior === 'toggle' || (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))) {\n // 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\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n }\n\n /**\n * Returns whether the current selection is equal to the given selection.\n */\n isSelectionEqual(selection: Set<Key>): boolean {\n if (selection === this.state.selectedKeys) {\n return true;\n }\n\n // Check if the set of keys match.\n let selectedKeys = this.selectedKeys;\n if (selection.size !== selectedKeys.size) {\n return false;\n }\n\n for (let key of selection) {\n if (!selectedKeys.has(key)) {\n return false;\n }\n }\n\n for (let key of selectedKeys) {\n if (!selection.has(key)) {\n return false;\n }\n }\n\n return true;\n }\n\n canSelectItem(key: Key): boolean {\n if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {\n return false;\n }\n\n let item = this.collection.getItem(key);\n if (!item || item?.props?.isDisabled || (item.type === 'cell' && !this.allowsCellSelection)) {\n return false;\n }\n\n return true;\n }\n\n isDisabled(key: Key): boolean {\n return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!this.collection.getItem(key)?.props?.isDisabled);\n }\n\n isLink(key: Key): boolean {\n return !!this.collection.getItem(key)?.props?.href;\n }\n\n getItemProps(key: Key): any {\n return this.collection.getItem(key)?.props;\n }\n\n withCollection(collection: Collection<Node<unknown>>): SelectionManager {\n return new SelectionManager(collection, this.state, {\n allowsCellSelection: this.allowsCellSelection,\n layoutDelegate: this.layoutDelegate || undefined\n });\n }\n}\n"],"names":[],"version":3,"file":"SelectionManager.main.js.map"}
@@ -297,6 +297,12 @@ class $d496c0a20b6e58ec$export$6c8a5aaad13c9852 {
297
297
  var _this_collection_getItem;
298
298
  return (_this_collection_getItem = this.collection.getItem(key)) === null || _this_collection_getItem === void 0 ? void 0 : _this_collection_getItem.props;
299
299
  }
300
+ withCollection(collection) {
301
+ return new $d496c0a20b6e58ec$export$6c8a5aaad13c9852(collection, this.state, {
302
+ allowsCellSelection: this.allowsCellSelection,
303
+ layoutDelegate: this.layoutDelegate || undefined
304
+ });
305
+ }
300
306
  constructor(collection, state, options){
301
307
  this.collection = collection;
302
308
  this.state = state;
@@ -297,6 +297,12 @@ class $d496c0a20b6e58ec$export$6c8a5aaad13c9852 {
297
297
  var _this_collection_getItem;
298
298
  return (_this_collection_getItem = this.collection.getItem(key)) === null || _this_collection_getItem === void 0 ? void 0 : _this_collection_getItem.props;
299
299
  }
300
+ withCollection(collection) {
301
+ return new $d496c0a20b6e58ec$export$6c8a5aaad13c9852(collection, this.state, {
302
+ allowsCellSelection: this.allowsCellSelection,
303
+ layoutDelegate: this.layoutDelegate || undefined
304
+ });
305
+ }
300
306
  constructor(collection, state, options){
301
307
  this.collection = collection;
302
308
  this.state = state;
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA0BM,MAAM;IAeX;;GAEC,GACD,IAAI,gBAA+B;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa;IACjC;IAEA;;GAEC,GACD,IAAI,yBAAkC;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB;IAC1C;IAEA;;GAEC,GACD,IAAI,oBAAuC;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB;IACrC;IAEA;;GAEC,GACD,qBAAqB,iBAAoC,EAAE;QACzD,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC;IAClC;IAEA;;GAEC,GACD,IAAI,YAAqB;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS;IAC7B;IAEA;;GAEC,GACD,WAAW,SAAkB,EAAE;QAC7B,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;IACxB;IAEA;;GAEC,GACD,IAAI,aAAyB;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU;IAC9B;IAEA,6EAA6E,GAC7E,IAAI,qBAA2C;QAC7C,OAAO,IAAI,CAAC,KAAK,CAAC,kBAAkB;IACtC;IAEA;;GAEC,GACD,cAAc,GAAe,EAAE,kBAAkC,EAAE;QACjE,IAAI,OAAO,QAAQ,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,MACzC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK;IAElC;IAEA;;GAEC,GACD,IAAI,eAAyB;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,KAAK,QAC/B,IAAI,IAAI,IAAI,CAAC,gBAAgB,MAC7B,IAAI,CAAC,KAAK,CAAC,YAAY;IAC7B;IAEA;;;GAGC,GACD,IAAI,eAA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nD;AAidF","sources":["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 {\n Collection, DisabledBehavior,\n FocusStrategy,\n Selection as ISelection,\n Key,\n LayoutDelegate,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {compareNodeOrder, getChildNodes, getFirstItem} from '@react-stately/collections';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean,\n layoutDelegate?: LayoutDelegate\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean | null;\n private layoutDelegate: LayoutDelegate | null;\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 this.layoutDelegate = options?.layoutDelegate || 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 * The selection behavior for the collection.\n */\n get selectionBehavior(): SelectionBehavior {\n return this.state.selectionBehavior;\n }\n\n /**\n * Sets the selection behavior for the collection.\n */\n setSelectionBehavior(selectionBehavior: SelectionBehavior) {\n this.state.setSelectionBehavior(selectionBehavior);\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 | null {\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 | null {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy) {\n if (key == null || this.collection.getItem(key)) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\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 * The raw selection value for the collection.\n * Either 'all' for select all, or a set of keys.\n */\n get rawSelection(): ISelection {\n return 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 let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return false;\n }\n return this.state.selectedKeys === 'all'\n ? this.canSelectItem(mappedKey)\n : this.state.selectedKeys.has(mappedKey);\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 && compareNodeOrder(this.collection, item, first) < 0)) {\n first = item;\n }\n }\n\n return first?.key ?? null;\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 && compareNodeOrder(this.collection, item, last) > 0)) {\n last = item;\n }\n }\n\n return last?.key ?? null;\n }\n\n get disabledKeys(): Set<Key> {\n return this.state.disabledKeys;\n }\n\n get disabledBehavior(): DisabledBehavior {\n return this.state.disabledBehavior;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n this.replaceSelection(toKey);\n return;\n }\n\n let mappedToKey = this.getKey(toKey);\n if (mappedToKey == null) {\n return;\n }\n\n let selection: Selection;\n\n // Only select the one key if coming from a select all.\n if (this.state.selectedKeys === 'all') {\n selection = new Selection([mappedToKey], mappedToKey, mappedToKey);\n } else {\n let selectedKeys = this.state.selectedKeys as Selection;\n let anchorKey = selectedKeys.anchorKey ?? mappedToKey;\n selection = new Selection(selectedKeys, anchorKey, mappedToKey);\n for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? mappedToKey)) {\n selection.delete(key);\n }\n\n for (let key of this.getKeyRange(mappedToKey, anchorKey)) {\n if (this.canSelectItem(key)) {\n selection.add(key);\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\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 (compareNodeOrder(this.collection, fromItem, toItem) <= 0) {\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 if (this.layoutDelegate?.getKeyRange) {\n return this.layoutDelegate.getKeyRange(from, to);\n }\n\n let keys: Key[] = [];\n let key: Key | null = from;\n while (key != null) {\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 && item.type !== 'item' && item.parentKey != null) {\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 if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single' && !this.isSelected(key)) {\n this.replaceSelection(key);\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let keys = new Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);\n if (keys.has(mappedKey)) {\n keys.delete(mappedKey);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else if (this.canSelectItem(mappedKey)) {\n keys.add(mappedKey);\n keys.anchorKey = mappedKey;\n keys.currentKey = mappedKey;\n }\n\n if (this.disallowEmptySelection && keys.size === 0) {\n return;\n }\n\n this.state.setSelectedKeys(keys);\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let selection = this.canSelectItem(mappedKey)\n ? new Selection([mappedKey], mappedKey, mappedKey)\n : new Selection();\n\n this.state.setSelectedKeys(selection);\n }\n\n /**\n * Replaces the selection with the given keys.\n */\n setSelectedKeys(keys: Iterable<Key>) {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let selection = new Selection();\n for (let key of keys) {\n let mappedKey = this.getKey(key);\n if (mappedKey != null) {\n selection.add(mappedKey);\n if (this.selectionMode === 'single') {\n break;\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getSelectAllKeys() {\n let keys: Key[] = [];\n let addKeys = (key: Key | null) => {\n while (key != null) {\n if (this.canSelectItem(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(getFirstItem(getChildNodes(item, this.collection))?.key ?? null);\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.isSelectAll && 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.disallowEmptySelection && (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 | LongPressEvent | 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 (this.selectionBehavior === 'toggle' || (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))) {\n // 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\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n }\n\n /**\n * Returns whether the current selection is equal to the given selection.\n */\n isSelectionEqual(selection: Set<Key>) {\n if (selection === this.state.selectedKeys) {\n return true;\n }\n\n // Check if the set of keys match.\n let selectedKeys = this.selectedKeys;\n if (selection.size !== selectedKeys.size) {\n return false;\n }\n\n for (let key of selection) {\n if (!selectedKeys.has(key)) {\n return false;\n }\n }\n\n for (let key of selectedKeys) {\n if (!selection.has(key)) {\n return false;\n }\n }\n\n return true;\n }\n\n canSelectItem(key: Key) {\n if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {\n return false;\n }\n\n let item = this.collection.getItem(key);\n if (!item || item?.props?.isDisabled || (item.type === 'cell' && !this.allowsCellSelection)) {\n return false;\n }\n\n return true;\n }\n\n isDisabled(key: Key) {\n return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!this.collection.getItem(key)?.props?.isDisabled);\n }\n\n isLink(key: Key) {\n return !!this.collection.getItem(key)?.props?.href;\n }\n\n getItemProps(key: Key) {\n return this.collection.getItem(key)?.props;\n }\n}\n"],"names":[],"version":3,"file":"SelectionManager.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AA0BM,MAAM;IAeX;;GAEC,GACD,IAAI,gBAA+B;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa;IACjC;IAEA;;GAEC,GACD,IAAI,yBAAkC;QACpC,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB;IAC1C;IAEA;;GAEC,GACD,IAAI,oBAAuC;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAiB;IACrC;IAEA;;GAEC,GACD,qBAAqB,iBAAoC,EAAQ;QAC/D,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC;IAClC;IAEA;;GAEC,GACD,IAAI,YAAqB;QACvB,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS;IAC7B;IAEA;;GAEC,GACD,WAAW,SAAkB,EAAQ;QACnC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;IACxB;IAEA;;GAEC,GACD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C,OAAO,CAAC,kBAAxB,gDAAA,iCAAA,yBAA8B,KAAK,cAAnC,qDAAA,+BAAqC,IAAI;IACpD;IAEA,aAAa,GAAQ,EAAO;YACnB;QAAP,QAAO,2BAAA,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,kBAAxB,+CAAA,yBAA8B,KAAK;IAC5C;IAEA,eAAe,UAAqC,EAAoB;QACtE,OAAO,IAAI,0CAAiB,YAAY,IAAI,CAAC,KAAK,EAAE;YAClD,qBAAqB,IAAI,CAAC,mBAAmB;YAC7C,gBAAgB,IAAI,CAAC,cAAc,IAAI;QACzC;IACF;IA7dA,YAAY,UAAqC,EAAE,KAA6B,EAAE,OAAiC,CAAE;QACnH,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,KAAK,GAAG;YACc;QAA3B,IAAI,CAAC,mBAAmB,GAAG,CAAA,+BAAA,oBAAA,8BAAA,QAAS,mBAAmB,cAA5B,0CAAA,+BAAgC;QAC3D,IAAI,CAAC,YAAY,GAAG;QACpB,IAAI,CAAC,cAAc,GAAG,CAAA,oBAAA,8BAAA,QAAS,cAAc,KAAI;IACnD;AAwdF","sources":["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 {\n Collection, DisabledBehavior,\n FocusStrategy,\n Selection as ISelection,\n Key,\n LayoutDelegate,\n LongPressEvent,\n Node,\n PressEvent,\n SelectionBehavior,\n SelectionMode\n} from '@react-types/shared';\nimport {compareNodeOrder, getChildNodes, getFirstItem} from '@react-stately/collections';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n allowsCellSelection?: boolean,\n layoutDelegate?: LayoutDelegate\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n collection: Collection<Node<unknown>>;\n private state: MultipleSelectionState;\n private allowsCellSelection: boolean;\n private _isSelectAll: boolean | null;\n private layoutDelegate: LayoutDelegate | null;\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 this.layoutDelegate = options?.layoutDelegate || 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 * The selection behavior for the collection.\n */\n get selectionBehavior(): SelectionBehavior {\n return this.state.selectionBehavior;\n }\n\n /**\n * Sets the selection behavior for the collection.\n */\n setSelectionBehavior(selectionBehavior: SelectionBehavior): void {\n this.state.setSelectionBehavior(selectionBehavior);\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): void {\n this.state.setFocused(isFocused);\n }\n\n /**\n * The current focused key in the collection.\n */\n get focusedKey(): Key | null {\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 | null {\n return this.state.childFocusStrategy;\n }\n\n /**\n * Sets the focused key.\n */\n setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void {\n if (key == null || this.collection.getItem(key)) {\n this.state.setFocusedKey(key, childFocusStrategy);\n }\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 * The raw selection value for the collection.\n * Either 'all' for select all, or a set of keys.\n */\n get rawSelection(): ISelection {\n return this.state.selectedKeys;\n }\n\n /**\n * Returns whether a key is selected.\n */\n isSelected(key: Key): boolean {\n if (this.state.selectionMode === 'none') {\n return false;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return false;\n }\n return this.state.selectedKeys === 'all'\n ? this.canSelectItem(mappedKey)\n : this.state.selectedKeys.has(mappedKey);\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 && compareNodeOrder(this.collection, item, first) < 0)) {\n first = item;\n }\n }\n\n return first?.key ?? null;\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 && compareNodeOrder(this.collection, item, last) > 0)) {\n last = item;\n }\n }\n\n return last?.key ?? null;\n }\n\n get disabledKeys(): Set<Key> {\n return this.state.disabledKeys;\n }\n\n get disabledBehavior(): DisabledBehavior {\n return this.state.disabledBehavior;\n }\n\n /**\n * Extends the selection to the given key.\n */\n extendSelection(toKey: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single') {\n this.replaceSelection(toKey);\n return;\n }\n\n let mappedToKey = this.getKey(toKey);\n if (mappedToKey == null) {\n return;\n }\n\n let selection: Selection;\n\n // Only select the one key if coming from a select all.\n if (this.state.selectedKeys === 'all') {\n selection = new Selection([mappedToKey], mappedToKey, mappedToKey);\n } else {\n let selectedKeys = this.state.selectedKeys as Selection;\n let anchorKey = selectedKeys.anchorKey ?? mappedToKey;\n selection = new Selection(selectedKeys, anchorKey, mappedToKey);\n for (let key of this.getKeyRange(anchorKey, selectedKeys.currentKey ?? mappedToKey)) {\n selection.delete(key);\n }\n\n for (let key of this.getKeyRange(mappedToKey, anchorKey)) {\n if (this.canSelectItem(key)) {\n selection.add(key);\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\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 (compareNodeOrder(this.collection, fromItem, toItem) <= 0) {\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 if (this.layoutDelegate?.getKeyRange) {\n return this.layoutDelegate.getKeyRange(from, to);\n }\n\n let keys: Key[] = [];\n let key: Key | null = from;\n while (key != null) {\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 && item.type !== 'item' && item.parentKey != null) {\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): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n if (this.selectionMode === 'single' && !this.isSelected(key)) {\n this.replaceSelection(key);\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let keys = new Selection(this.state.selectedKeys === 'all' ? this.getSelectAllKeys() : this.state.selectedKeys);\n if (keys.has(mappedKey)) {\n keys.delete(mappedKey);\n // TODO: move anchor to last selected key...\n // Does `current` need to move here too?\n } else if (this.canSelectItem(mappedKey)) {\n keys.add(mappedKey);\n keys.anchorKey = mappedKey;\n keys.currentKey = mappedKey;\n }\n\n if (this.disallowEmptySelection && keys.size === 0) {\n return;\n }\n\n this.state.setSelectedKeys(keys);\n }\n\n /**\n * Replaces the selection with only the given key.\n */\n replaceSelection(key: Key): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let mappedKey = this.getKey(key);\n if (mappedKey == null) {\n return;\n }\n\n let selection = this.canSelectItem(mappedKey)\n ? new Selection([mappedKey], mappedKey, mappedKey)\n : new Selection();\n\n this.state.setSelectedKeys(selection);\n }\n\n /**\n * Replaces the selection with the given keys.\n */\n setSelectedKeys(keys: Iterable<Key>): void {\n if (this.selectionMode === 'none') {\n return;\n }\n\n let selection = new Selection();\n for (let key of keys) {\n let mappedKey = this.getKey(key);\n if (mappedKey != null) {\n selection.add(mappedKey);\n if (this.selectionMode === 'single') {\n break;\n }\n }\n }\n\n this.state.setSelectedKeys(selection);\n }\n\n private getSelectAllKeys() {\n let keys: Key[] = [];\n let addKeys = (key: Key | null) => {\n while (key != null) {\n if (this.canSelectItem(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(getFirstItem(getChildNodes(item, this.collection))?.key ?? null);\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(): void {\n if (!this.isSelectAll && this.selectionMode === 'multiple') {\n this.state.setSelectedKeys('all');\n }\n }\n\n /**\n * Removes all keys from the selection.\n */\n clearSelection(): void {\n if (!this.disallowEmptySelection && (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(): void {\n if (this.isSelectAll) {\n this.clearSelection();\n } else {\n this.selectAll();\n }\n }\n\n select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void {\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 (this.selectionBehavior === 'toggle' || (e && (e.pointerType === 'touch' || e.pointerType === 'virtual'))) {\n // 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\n this.toggleSelection(key);\n } else {\n this.replaceSelection(key);\n }\n }\n\n /**\n * Returns whether the current selection is equal to the given selection.\n */\n isSelectionEqual(selection: Set<Key>): boolean {\n if (selection === this.state.selectedKeys) {\n return true;\n }\n\n // Check if the set of keys match.\n let selectedKeys = this.selectedKeys;\n if (selection.size !== selectedKeys.size) {\n return false;\n }\n\n for (let key of selection) {\n if (!selectedKeys.has(key)) {\n return false;\n }\n }\n\n for (let key of selectedKeys) {\n if (!selection.has(key)) {\n return false;\n }\n }\n\n return true;\n }\n\n canSelectItem(key: Key): boolean {\n if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {\n return false;\n }\n\n let item = this.collection.getItem(key);\n if (!item || item?.props?.isDisabled || (item.type === 'cell' && !this.allowsCellSelection)) {\n return false;\n }\n\n return true;\n }\n\n isDisabled(key: Key): boolean {\n return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!this.collection.getItem(key)?.props?.isDisabled);\n }\n\n isLink(key: Key): boolean {\n return !!this.collection.getItem(key)?.props?.href;\n }\n\n getItemProps(key: Key): any {\n return this.collection.getItem(key)?.props;\n }\n\n withCollection(collection: Collection<Node<unknown>>): SelectionManager {\n return new SelectionManager(collection, this.state, {\n allowsCellSelection: this.allowsCellSelection,\n layoutDelegate: this.layoutDelegate || undefined\n });\n }\n}\n"],"names":[],"version":3,"file":"SelectionManager.module.js.map"}
package/dist/types.d.ts CHANGED
@@ -212,6 +212,7 @@ export class SelectionManager implements MultipleSelectionManager {
212
212
  isDisabled(key: Key): boolean;
213
213
  isLink(key: Key): boolean;
214
214
  getItemProps(key: Key): any;
215
+ withCollection(collection: Collection<Node<unknown>>): SelectionManager;
215
216
  }
216
217
 
217
218
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"mappings":";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,GAAG,IAAI,CAAC;IAChC,+EAA+E;IAC/E,QAAQ,CAAC,kBAAkB,EAAE,aAAa,GAAG,IAAI,CAAC;IAClD,8GAA8G;IAC9G,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,IAAI,CAAA;CAC5D;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,GAAG,IAAI,CAAA;CACtC;AAED,uCAAwC,SAAQ,UAAU;IACxD,+DAA+D;IAC/D,QAAQ,CAAC,aAAa,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BAAgB,IAAI,GAAG,GAAG,IAAI,CAUjC;IAED,IAAI,eAAe,IAAI,GAAG,GAAG,IAAI,CAUhC;IAED,IAAI,YAAY,IAAI,GAAG,CAAC,GAAG,CAAC,CAE3B;IAED,IAAI,gBAAgB,IAAI,gBAAgB,CAEvC;IAED;;OAEG;IACH,eAAe,CAAC,KAAK,EAAE,GAAG;IAmG1B;;OAEG;IACH,eAAe,CAAC,GAAG,EAAE,GAAG;IAiCxB;;OAEG;IACH,gBAAgB,CAAC,GAAG,EAAE,GAAG;IAiBzB;;OAEG;IACH,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC;IA2CnC;;OAEG;IACH,SAAS;IAMT;;OAEG;IACH,cAAc;IAMd;;OAEG;IACH,eAAe;IAQf,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,GAAG,cAAc,GAAG,YAAY;IAmB/D;;OAEG;IACH,gBAAgB,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC;IA0BpC,aAAa,CAAC,GAAG,EAAE,GAAG;IAatB,UAAU,CAAC,GAAG,EAAE,GAAG;IAInB,MAAM,CAAC,GAAG,EAAE,GAAG;IAIf,YAAY,CAAC,GAAG,EAAE,GAAG;CAGtB","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","packages/@react-stately/selection/src/index.ts"],"sourcesContent":[null,null,null,null,null,"/*\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\nexport type {MultipleSelectionStateProps} from './useMultipleSelectionState';\nexport type {FocusState, SingleSelectionState, MultipleSelectionState, MultipleSelectionManager} from './types';\nexport {useMultipleSelectionState} from './useMultipleSelectionState';\nexport {SelectionManager} from './SelectionManager';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";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,GAAG,IAAI,CAAC;IAChC,+EAA+E;IAC/E,QAAQ,CAAC,kBAAkB,EAAE,aAAa,GAAG,IAAI,CAAC;IAClD,8GAA8G;IAC9G,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,IAAI,CAAA;CAC5D;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,GAAG,IAAI,CAAA;CACtC;AAED,uCAAwC,SAAQ,UAAU;IACxD,+DAA+D;IAC/D,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,iDAAiD;IACjD,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAC9C,sDAAsD;IACtD,oBAAoB,CAAC,iBAAiB,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACjE,qDAAqD;IACrD,QAAQ,CAAC,sBAAsB,EAAE,OAAO,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I,gBAAgB,CAEvC;IAED;;OAEG;IACH,eAAe,CAAC,KAAK,EAAE,GAAG,GAAG,IAAI;IAmGjC;;OAEG;IACH,eAAe,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI;IAiC/B;;OAEG;IACH,gBAAgB,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI;IAiBhC;;OAEG;IACH,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI;IA2C1C;;OAEG;IACH,SAAS,IAAI,IAAI;IAMjB;;OAEG;IACH,cAAc,IAAI,IAAI;IAMtB;;OAEG;IACH,eAAe,IAAI,IAAI;IAQvB,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,GAAG,cAAc,GAAG,YAAY,GAAG,IAAI;IAmBtE;;OAEG;IACH,gBAAgB,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,OAAO;IA0B9C,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO;IAahC,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO;IAI7B,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO;IAIzB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG;IAI3B,cAAc,CAAC,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,GAAG,gBAAgB;CAMxE","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","packages/@react-stately/selection/src/index.ts"],"sourcesContent":[null,null,null,null,null,"/*\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\nexport type {MultipleSelectionStateProps} from './useMultipleSelectionState';\nexport type {FocusState, SingleSelectionState, MultipleSelectionState, MultipleSelectionManager} from './types';\nexport {useMultipleSelectionState} from './useMultipleSelectionState';\nexport {SelectionManager} from './SelectionManager';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/selection",
3
- "version": "3.19.0",
3
+ "version": "3.20.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,9 +22,9 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/collections": "^3.12.1",
26
- "@react-stately/utils": "^3.10.5",
27
- "@react-types/shared": "^3.27.0",
25
+ "@react-stately/collections": "^3.12.3",
26
+ "@react-stately/utils": "^3.10.6",
27
+ "@react-types/shared": "^3.29.0",
28
28
  "@swc/helpers": "^0.5.0"
29
29
  },
30
30
  "peerDependencies": {
@@ -33,5 +33,5 @@
33
33
  "publishConfig": {
34
34
  "access": "public"
35
35
  },
36
- "gitHead": "09e7f44bebdc9d89122926b2b439a0a38a2814ea"
36
+ "gitHead": "9b66d270572f482948afee95622a85cdf68ed408"
37
37
  }
@@ -73,7 +73,7 @@ export class SelectionManager implements MultipleSelectionManager {
73
73
  /**
74
74
  * Sets the selection behavior for the collection.
75
75
  */
76
- setSelectionBehavior(selectionBehavior: SelectionBehavior) {
76
+ setSelectionBehavior(selectionBehavior: SelectionBehavior): void {
77
77
  this.state.setSelectionBehavior(selectionBehavior);
78
78
  }
79
79
 
@@ -87,7 +87,7 @@ export class SelectionManager implements MultipleSelectionManager {
87
87
  /**
88
88
  * Sets whether the collection is focused.
89
89
  */
90
- setFocused(isFocused: boolean) {
90
+ setFocused(isFocused: boolean): void {
91
91
  this.state.setFocused(isFocused);
92
92
  }
93
93
 
@@ -106,7 +106,7 @@ export class SelectionManager implements MultipleSelectionManager {
106
106
  /**
107
107
  * Sets the focused key.
108
108
  */
109
- setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy) {
109
+ setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void {
110
110
  if (key == null || this.collection.getItem(key)) {
111
111
  this.state.setFocusedKey(key, childFocusStrategy);
112
112
  }
@@ -132,7 +132,7 @@ export class SelectionManager implements MultipleSelectionManager {
132
132
  /**
133
133
  * Returns whether a key is selected.
134
134
  */
135
- isSelected(key: Key) {
135
+ isSelected(key: Key): boolean {
136
136
  if (this.state.selectionMode === 'none') {
137
137
  return false;
138
138
  }
@@ -210,7 +210,7 @@ export class SelectionManager implements MultipleSelectionManager {
210
210
  /**
211
211
  * Extends the selection to the given key.
212
212
  */
213
- extendSelection(toKey: Key) {
213
+ extendSelection(toKey: Key): void {
214
214
  if (this.selectionMode === 'none') {
215
215
  return;
216
216
  }
@@ -312,7 +312,7 @@ export class SelectionManager implements MultipleSelectionManager {
312
312
  /**
313
313
  * Toggles whether the given key is selected.
314
314
  */
315
- toggleSelection(key: Key) {
315
+ toggleSelection(key: Key): void {
316
316
  if (this.selectionMode === 'none') {
317
317
  return;
318
318
  }
@@ -348,7 +348,7 @@ export class SelectionManager implements MultipleSelectionManager {
348
348
  /**
349
349
  * Replaces the selection with only the given key.
350
350
  */
351
- replaceSelection(key: Key) {
351
+ replaceSelection(key: Key): void {
352
352
  if (this.selectionMode === 'none') {
353
353
  return;
354
354
  }
@@ -368,7 +368,7 @@ export class SelectionManager implements MultipleSelectionManager {
368
368
  /**
369
369
  * Replaces the selection with the given keys.
370
370
  */
371
- setSelectedKeys(keys: Iterable<Key>) {
371
+ setSelectedKeys(keys: Iterable<Key>): void {
372
372
  if (this.selectionMode === 'none') {
373
373
  return;
374
374
  }
@@ -414,7 +414,7 @@ export class SelectionManager implements MultipleSelectionManager {
414
414
  /**
415
415
  * Selects all items in the collection.
416
416
  */
417
- selectAll() {
417
+ selectAll(): void {
418
418
  if (!this.isSelectAll && this.selectionMode === 'multiple') {
419
419
  this.state.setSelectedKeys('all');
420
420
  }
@@ -423,7 +423,7 @@ export class SelectionManager implements MultipleSelectionManager {
423
423
  /**
424
424
  * Removes all keys from the selection.
425
425
  */
426
- clearSelection() {
426
+ clearSelection(): void {
427
427
  if (!this.disallowEmptySelection && (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0)) {
428
428
  this.state.setSelectedKeys(new Selection());
429
429
  }
@@ -432,7 +432,7 @@ export class SelectionManager implements MultipleSelectionManager {
432
432
  /**
433
433
  * Toggles between select all and an empty selection.
434
434
  */
435
- toggleSelectAll() {
435
+ toggleSelectAll(): void {
436
436
  if (this.isSelectAll) {
437
437
  this.clearSelection();
438
438
  } else {
@@ -440,7 +440,7 @@ export class SelectionManager implements MultipleSelectionManager {
440
440
  }
441
441
  }
442
442
 
443
- select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent) {
443
+ select(key: Key, e?: PressEvent | LongPressEvent | PointerEvent): void {
444
444
  if (this.selectionMode === 'none') {
445
445
  return;
446
446
  }
@@ -462,7 +462,7 @@ export class SelectionManager implements MultipleSelectionManager {
462
462
  /**
463
463
  * Returns whether the current selection is equal to the given selection.
464
464
  */
465
- isSelectionEqual(selection: Set<Key>) {
465
+ isSelectionEqual(selection: Set<Key>): boolean {
466
466
  if (selection === this.state.selectedKeys) {
467
467
  return true;
468
468
  }
@@ -488,7 +488,7 @@ export class SelectionManager implements MultipleSelectionManager {
488
488
  return true;
489
489
  }
490
490
 
491
- canSelectItem(key: Key) {
491
+ canSelectItem(key: Key): boolean {
492
492
  if (this.state.selectionMode === 'none' || this.state.disabledKeys.has(key)) {
493
493
  return false;
494
494
  }
@@ -501,15 +501,22 @@ export class SelectionManager implements MultipleSelectionManager {
501
501
  return true;
502
502
  }
503
503
 
504
- isDisabled(key: Key) {
504
+ isDisabled(key: Key): boolean {
505
505
  return this.state.disabledBehavior === 'all' && (this.state.disabledKeys.has(key) || !!this.collection.getItem(key)?.props?.isDisabled);
506
506
  }
507
507
 
508
- isLink(key: Key) {
508
+ isLink(key: Key): boolean {
509
509
  return !!this.collection.getItem(key)?.props?.href;
510
510
  }
511
511
 
512
- getItemProps(key: Key) {
512
+ getItemProps(key: Key): any {
513
513
  return this.collection.getItem(key)?.props;
514
514
  }
515
+
516
+ withCollection(collection: Collection<Node<unknown>>): SelectionManager {
517
+ return new SelectionManager(collection, this.state, {
518
+ allowsCellSelection: this.allowsCellSelection,
519
+ layoutDelegate: this.layoutDelegate || undefined
520
+ });
521
+ }
515
522
  }