@react-aria/selection 3.23.1 → 3.24.0

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.
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAkBM,MAAM;IA4CH,WAAW,IAAmB,EAAE;YACK;QAA3C,OAAO,IAAI,CAAC,gBAAgB,KAAK,SAAU,CAAA,EAAA,cAAA,KAAK,KAAK,cAAV,kCAAA,YAAY,UAAU,KAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,GAAG,CAAA;IACrG;IAEQ,oBAAoB,GAAe,EAAE,OAAiC,EAAc;QAC1F,IAAI,UAAU;QACd,MAAO,WAAW,KAAM;YACtB,IAAI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YACnC,IAAI,CAAA,iBAAA,2BAAA,KAAM,IAAI,MAAK,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,OAC5C,OAAO;YAGT,UAAU,QAAQ;QACpB;QAEA,OAAO;IACT;IAEA,WAAW,GAAQ,EAAE;QACnB,IAAI,UAAsB;QAC1B,UAAU,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;QACtC,OAAO,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAA,MAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;IAC9E;IAEA,eAAe,GAAQ,EAAE;QACvB,IAAI,UAAsB;QAC1B,UAAU,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;QACvC,OAAO,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAA,MAAO,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;IAC/E;IAEQ,QACN,GAAQ,EACR,OAAiC,EACjC,UAAuD,EACvD;QACA,IAAI,UAAsB;QAC1B,IAAI,WAAW,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC;QAC/C,IAAI,CAAC,YAAY,WAAW,MAC1B,OAAO;QAGT,mDAAmD;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AA,2CAAgB,EAAE,IAAI,CAAC,GAAG;QACtD;QAEA,wEAAwE;QACxE,mDAAmD;QACnD,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,WAAW,KAAK,YAAY;YAC9D,IAAI,CAAC,YAAY,GAAG;YACpB,IAAI,CAAC,aAAa,GAAG;QACvB;IACF;AA4NF","sources":["packages/@react-aria/selection/src/ListKeyboardDelegate.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 {Collection, Direction, DisabledBehavior, Key, KeyboardDelegate, LayoutDelegate, Node, Orientation, Rect, RefObject} from '@react-types/shared';\nimport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nimport {isScrollable} from '@react-aria/utils';\n\ninterface ListKeyboardDelegateOptions<T> {\n collection: Collection<Node<T>>,\n ref: RefObject<HTMLElement | null>,\n collator?: Intl.Collator,\n layout?: 'stack' | 'grid',\n orientation?: Orientation,\n direction?: Direction,\n disabledKeys?: Set<Key>,\n disabledBehavior?: DisabledBehavior,\n layoutDelegate?: LayoutDelegate\n}\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private collection: Collection<Node<T>>;\n private disabledKeys: Set<Key>;\n private disabledBehavior: DisabledBehavior;\n private ref: RefObject<HTMLElement | null>;\n private collator: Intl.Collator | undefined;\n private layout: 'stack' | 'grid';\n private orientation?: Orientation;\n private direction?: Direction;\n private layoutDelegate: LayoutDelegate;\n\n constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement | null>, collator?: Intl.Collator);\n constructor(options: ListKeyboardDelegateOptions<T>);\n constructor(...args: any[]) {\n if (args.length === 1) {\n let opts = args[0] as ListKeyboardDelegateOptions<T>;\n this.collection = opts.collection;\n this.ref = opts.ref;\n this.collator = opts.collator;\n this.disabledKeys = opts.disabledKeys || new Set();\n this.disabledBehavior = opts.disabledBehavior || 'all';\n this.orientation = opts.orientation || 'vertical';\n this.direction = opts.direction;\n this.layout = opts.layout || 'stack';\n this.layoutDelegate = opts.layoutDelegate || new DOMLayoutDelegate(opts.ref);\n } else {\n this.collection = args[0];\n this.disabledKeys = args[1];\n this.ref = args[2];\n this.collator = args[3];\n this.layout = 'stack';\n this.orientation = 'vertical';\n this.disabledBehavior = 'all';\n this.layoutDelegate = new DOMLayoutDelegate(this.ref);\n }\n\n // If this is a vertical stack, remove the left/right methods completely\n // so they aren't called by useDroppableCollection.\n if (this.layout === 'stack' && this.orientation === 'vertical') {\n this.getKeyLeftOf = undefined;\n this.getKeyRightOf = undefined;\n }\n }\n\n private isDisabled(item: Node<unknown>) {\n return this.disabledBehavior === 'all' && (item.props?.isDisabled || this.disabledKeys.has(item.key));\n }\n\n private findNextNonDisabled(key: Key | null, getNext: (key: Key) => Key | null): Key | null {\n let nextKey = key;\n while (nextKey != null) {\n let item = this.collection.getItem(nextKey);\n if (item?.type === 'item' && !this.isDisabled(item)) {\n return nextKey;\n }\n\n nextKey = getNext(nextKey);\n }\n\n return null;\n }\n\n getNextKey(key: Key) {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyAfter(nextKey);\n return this.findNextNonDisabled(nextKey, key => this.collection.getKeyAfter(key));\n }\n\n getPreviousKey(key: Key) {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyBefore(nextKey);\n return this.findNextNonDisabled(nextKey, key => this.collection.getKeyBefore(key));\n }\n\n private findKey(\n key: Key,\n nextKey: (key: Key) => Key | null,\n shouldSkip: (prevRect: Rect, itemRect: Rect) => boolean\n ) {\n let tempKey: Key | null = key;\n let itemRect = this.layoutDelegate.getItemRect(tempKey);\n if (!itemRect || tempKey == null) {\n return null;\n }\n\n // Find the item above or below in the same column.\n let prevRect = itemRect;\n do {\n tempKey = nextKey(tempKey);\n if (tempKey == null) {\n break;\n }\n itemRect = this.layoutDelegate.getItemRect(tempKey);\n } while (itemRect && shouldSkip(prevRect, itemRect) && tempKey != null);\n\n return tempKey;\n }\n\n private isSameRow(prevRect: Rect, itemRect: Rect) {\n return prevRect.y === itemRect.y || prevRect.x !== itemRect.x;\n }\n\n private isSameColumn(prevRect: Rect, itemRect: Rect) {\n return prevRect.x === itemRect.x || prevRect.y !== itemRect.y;\n }\n\n getKeyBelow(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getNextKey(key), this.isSameRow);\n } else {\n return this.getNextKey(key);\n }\n }\n\n getKeyAbove(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getPreviousKey(key), this.isSameRow);\n } else {\n return this.getPreviousKey(key);\n }\n }\n\n private getNextColumn(key: Key, right: boolean) {\n return right ? this.getPreviousKey(key) : this.getNextKey(key);\n }\n\n getKeyRightOf?(key: Key) {\n // This is a temporary solution for CardView until we refactor useSelectableCollection.\n // https://github.com/orgs/adobe/projects/19/views/32?pane=issue&itemId=77825042\n let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyRightOf' : 'getKeyLeftOf';\n if (this.layoutDelegate[layoutDelegateMethod]) {\n key = this.layoutDelegate[layoutDelegateMethod](key);\n return this.findNextNonDisabled(key, key => this.layoutDelegate[layoutDelegateMethod](key));\n }\n\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'rtl');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'rtl'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'rtl');\n }\n\n return null;\n }\n\n getKeyLeftOf?(key: Key) {\n let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyLeftOf' : 'getKeyRightOf';\n if (this.layoutDelegate[layoutDelegateMethod]) {\n key = this.layoutDelegate[layoutDelegateMethod](key);\n return this.findNextNonDisabled(key, key => this.layoutDelegate[layoutDelegateMethod](key));\n }\n\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'ltr');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'ltr'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'ltr');\n }\n\n return null;\n }\n\n getFirstKey() {\n let key = this.collection.getFirstKey();\n return this.findNextNonDisabled(key, key => this.collection.getKeyAfter(key));\n }\n\n getLastKey() {\n let key = this.collection.getLastKey();\n return this.findNextNonDisabled(key, key => this.collection.getKeyBefore(key));\n }\n\n getKeyPageAbove(key: Key) {\n let menu = this.ref.current;\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n if (menu && !isScrollable(menu)) {\n return this.getFirstKey();\n }\n\n let nextKey: Key | null = key;\n if (this.orientation === 'horizontal') {\n let pageX = Math.max(0, itemRect.x + itemRect.width - this.layoutDelegate.getVisibleRect().width);\n\n while (itemRect && itemRect.x > pageX && nextKey != null) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n } else {\n let pageY = Math.max(0, itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height);\n\n while (itemRect && itemRect.y > pageY && nextKey != null) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n }\n\n return nextKey ?? this.getFirstKey();\n }\n\n getKeyPageBelow(key: Key) {\n let menu = this.ref.current;\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n if (menu && !isScrollable(menu)) {\n return this.getLastKey();\n }\n\n let nextKey: Key | null = key;\n if (this.orientation === 'horizontal') {\n let pageX = Math.min(this.layoutDelegate.getContentSize().width, itemRect.y - itemRect.width + this.layoutDelegate.getVisibleRect().width);\n\n while (itemRect && itemRect.x < pageX && nextKey != null) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n } else {\n let pageY = Math.min(this.layoutDelegate.getContentSize().height, itemRect.y - itemRect.height + this.layoutDelegate.getVisibleRect().height);\n\n while (itemRect && itemRect.y < pageY && nextKey != null) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n }\n\n return nextKey ?? this.getLastKey();\n }\n\n getKeyForSearch(search: string, fromKey?: Key) {\n if (!this.collator) {\n return null;\n }\n\n let collection = this.collection;\n let key = fromKey || this.getFirstKey();\n while (key != null) {\n let item = collection.getItem(key);\n if (!item) {\n return null;\n }\n let substring = item.textValue.slice(0, search.length);\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.getNextKey(key);\n }\n\n return null;\n }\n}\n"],"names":[],"version":3,"file":"ListKeyboardDelegate.main.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAkBM,MAAM;IA4CH,WAAW,IAAmB,EAAE;YACK;QAA3C,OAAO,IAAI,CAAC,gBAAgB,KAAK,SAAU,CAAA,EAAA,cAAA,KAAK,KAAK,cAAV,kCAAA,YAAY,UAAU,KAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,GAAG,CAAA;IACrG;IAEQ,oBAAoB,GAAe,EAAE,OAAiC,EAAc;QAC1F,IAAI,UAAU;QACd,MAAO,WAAW,KAAM;YACtB,IAAI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YACnC,IAAI,CAAA,iBAAA,2BAAA,KAAM,IAAI,MAAK,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,OAC5C,OAAO;Y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AC,gBAAgB,GAAG,KAAK,gBAAgB,IAAI;YACjD,IAAI,CAAC,WAAW,GAAG,KAAK,WAAW,IAAI;YACvC,IAAI,CAAC,SAAS,GAAG,KAAK,SAAS;YAC/B,IAAI,CAAC,MAAM,GAAG,KAAK,MAAM,IAAI;YAC7B,IAAI,CAAC,cAAc,GAAG,KAAK,cAAc,IAAI,IAAI,CAAA,GAAA,2CAAgB,EAAE,KAAK,GAAG;QAC7E,OAAO;YACL,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE;YACzB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE;YAC3B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE;YACvB,IAAI,CAAC,MAAM,GAAG;YACd,IAAI,CAAC,WAAW,GAAG;YACnB,IAAI,CAAC,gBAAgB,GAAG;YACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA,GAAA,2CAAgB,EAAE,IAAI,CAAC,GAAG;QACtD;QAEA,wEAAwE;QACxE,mDAAmD;QACnD,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,WAAW,KAAK,YAAY;YAC9D,IAAI,CAAC,YAAY,GAAG;YACpB,IAAI,CAAC,aAAa,GAAG;QACvB;IACF;AA4NF","sources":["packages/@react-aria/selection/src/ListKeyboardDelegate.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 {Collection, Direction, DisabledBehavior, Key, KeyboardDelegate, LayoutDelegate, Node, Orientation, Rect, RefObject} from '@react-types/shared';\nimport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nimport {isScrollable} from '@react-aria/utils';\n\ninterface ListKeyboardDelegateOptions<T> {\n collection: Collection<Node<T>>,\n ref: RefObject<HTMLElement | null>,\n collator?: Intl.Collator,\n layout?: 'stack' | 'grid',\n orientation?: Orientation,\n direction?: Direction,\n disabledKeys?: Set<Key>,\n disabledBehavior?: DisabledBehavior,\n layoutDelegate?: LayoutDelegate\n}\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private collection: Collection<Node<T>>;\n private disabledKeys: Set<Key>;\n private disabledBehavior: DisabledBehavior;\n private ref: RefObject<HTMLElement | null>;\n private collator: Intl.Collator | undefined;\n private layout: 'stack' | 'grid';\n private orientation?: Orientation;\n private direction?: Direction;\n private layoutDelegate: LayoutDelegate;\n\n constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement | null>, collator?: Intl.Collator);\n constructor(options: ListKeyboardDelegateOptions<T>);\n constructor(...args: any[]) {\n if (args.length === 1) {\n let opts = args[0] as ListKeyboardDelegateOptions<T>;\n this.collection = opts.collection;\n this.ref = opts.ref;\n this.collator = opts.collator;\n this.disabledKeys = opts.disabledKeys || new Set();\n this.disabledBehavior = opts.disabledBehavior || 'all';\n this.orientation = opts.orientation || 'vertical';\n this.direction = opts.direction;\n this.layout = opts.layout || 'stack';\n this.layoutDelegate = opts.layoutDelegate || new DOMLayoutDelegate(opts.ref);\n } else {\n this.collection = args[0];\n this.disabledKeys = args[1];\n this.ref = args[2];\n this.collator = args[3];\n this.layout = 'stack';\n this.orientation = 'vertical';\n this.disabledBehavior = 'all';\n this.layoutDelegate = new DOMLayoutDelegate(this.ref);\n }\n\n // If this is a vertical stack, remove the left/right methods completely\n // so they aren't called by useDroppableCollection.\n if (this.layout === 'stack' && this.orientation === 'vertical') {\n this.getKeyLeftOf = undefined;\n this.getKeyRightOf = undefined;\n }\n }\n\n private isDisabled(item: Node<unknown>) {\n return this.disabledBehavior === 'all' && (item.props?.isDisabled || this.disabledKeys.has(item.key));\n }\n\n private findNextNonDisabled(key: Key | null, getNext: (key: Key) => Key | null): Key | null {\n let nextKey = key;\n while (nextKey != null) {\n let item = this.collection.getItem(nextKey);\n if (item?.type === 'item' && !this.isDisabled(item)) {\n return nextKey;\n }\n\n nextKey = getNext(nextKey);\n }\n\n return null;\n }\n\n getNextKey(key: Key): Key | null {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyAfter(nextKey);\n return this.findNextNonDisabled(nextKey, key => this.collection.getKeyAfter(key));\n }\n\n getPreviousKey(key: Key): Key | null {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyBefore(nextKey);\n return this.findNextNonDisabled(nextKey, key => this.collection.getKeyBefore(key));\n }\n\n private findKey(\n key: Key,\n nextKey: (key: Key) => Key | null,\n shouldSkip: (prevRect: Rect, itemRect: Rect) => boolean\n ) {\n let tempKey: Key | null = key;\n let itemRect = this.layoutDelegate.getItemRect(tempKey);\n if (!itemRect || tempKey == null) {\n return null;\n }\n\n // Find the item above or below in the same column.\n let prevRect = itemRect;\n do {\n tempKey = nextKey(tempKey);\n if (tempKey == null) {\n break;\n }\n itemRect = this.layoutDelegate.getItemRect(tempKey);\n } while (itemRect && shouldSkip(prevRect, itemRect) && tempKey != null);\n\n return tempKey;\n }\n\n private isSameRow(prevRect: Rect, itemRect: Rect) {\n return prevRect.y === itemRect.y || prevRect.x !== itemRect.x;\n }\n\n private isSameColumn(prevRect: Rect, itemRect: Rect) {\n return prevRect.x === itemRect.x || prevRect.y !== itemRect.y;\n }\n\n getKeyBelow(key: Key): Key | null {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getNextKey(key), this.isSameRow);\n } else {\n return this.getNextKey(key);\n }\n }\n\n getKeyAbove(key: Key): Key | null {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getPreviousKey(key), this.isSameRow);\n } else {\n return this.getPreviousKey(key);\n }\n }\n\n private getNextColumn(key: Key, right: boolean) {\n return right ? this.getPreviousKey(key) : this.getNextKey(key);\n }\n\n getKeyRightOf?(key: Key): Key | null {\n // This is a temporary solution for CardView until we refactor useSelectableCollection.\n // https://github.com/orgs/adobe/projects/19/views/32?pane=issue&itemId=77825042\n let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyRightOf' : 'getKeyLeftOf';\n if (this.layoutDelegate[layoutDelegateMethod]) {\n key = this.layoutDelegate[layoutDelegateMethod](key);\n return this.findNextNonDisabled(key, key => this.layoutDelegate[layoutDelegateMethod](key));\n }\n\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'rtl');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'rtl'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'rtl');\n }\n\n return null;\n }\n\n getKeyLeftOf?(key: Key): Key | null {\n let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyLeftOf' : 'getKeyRightOf';\n if (this.layoutDelegate[layoutDelegateMethod]) {\n key = this.layoutDelegate[layoutDelegateMethod](key);\n return this.findNextNonDisabled(key, key => this.layoutDelegate[layoutDelegateMethod](key));\n }\n\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'ltr');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'ltr'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'ltr');\n }\n\n return null;\n }\n\n getFirstKey(): Key | null {\n let key = this.collection.getFirstKey();\n return this.findNextNonDisabled(key, key => this.collection.getKeyAfter(key));\n }\n\n getLastKey(): Key | null {\n let key = this.collection.getLastKey();\n return this.findNextNonDisabled(key, key => this.collection.getKeyBefore(key));\n }\n\n getKeyPageAbove(key: Key): Key | null {\n let menu = this.ref.current;\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n if (menu && !isScrollable(menu)) {\n return this.getFirstKey();\n }\n\n let nextKey: Key | null = key;\n if (this.orientation === 'horizontal') {\n let pageX = Math.max(0, itemRect.x + itemRect.width - this.layoutDelegate.getVisibleRect().width);\n\n while (itemRect && itemRect.x > pageX && nextKey != null) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n } else {\n let pageY = Math.max(0, itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height);\n\n while (itemRect && itemRect.y > pageY && nextKey != null) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n }\n\n return nextKey ?? this.getFirstKey();\n }\n\n getKeyPageBelow(key: Key): Key | null {\n let menu = this.ref.current;\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n if (menu && !isScrollable(menu)) {\n return this.getLastKey();\n }\n\n let nextKey: Key | null = key;\n if (this.orientation === 'horizontal') {\n let pageX = Math.min(this.layoutDelegate.getContentSize().width, itemRect.y - itemRect.width + this.layoutDelegate.getVisibleRect().width);\n\n while (itemRect && itemRect.x < pageX && nextKey != null) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n } else {\n let pageY = Math.min(this.layoutDelegate.getContentSize().height, itemRect.y - itemRect.height + this.layoutDelegate.getVisibleRect().height);\n\n while (itemRect && itemRect.y < pageY && nextKey != null) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n }\n\n return nextKey ?? this.getLastKey();\n }\n\n getKeyForSearch(search: string, fromKey?: Key): Key | null {\n if (!this.collator) {\n return null;\n }\n\n let collection = this.collection;\n let key = fromKey || this.getFirstKey();\n while (key != null) {\n let item = collection.getItem(key);\n if (!item) {\n return null;\n }\n let substring = item.textValue.slice(0, search.length);\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.getNextKey(key);\n }\n\n return null;\n }\n}\n"],"names":[],"version":3,"file":"ListKeyboardDelegate.main.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAkBM,MAAM;IA4CH,WAAW,IAAmB,EAAE;YACK;QAA3C,OAAO,IAAI,CAAC,gBAAgB,KAAK,SAAU,CAAA,EAAA,cAAA,KAAK,KAAK,cAAV,kCAAA,YAAY,UAAU,KAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,GAAG,CAAA;IACrG;IAEQ,oBAAoB,GAAe,EAAE,OAAiC,EAAc;QAC1F,IAAI,UAAU;QACd,MAAO,WAAW,KAAM;YACtB,IAAI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YACnC,IAAI,CAAA,iBAAA,2BAAA,KAAM,IAAI,MAAK,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,OAC5C,OAAO;YAGT,UAAU,QAAQ;QACpB;QAEA,OAAO;IACT;IAEA,WAAW,GAAQ,EAAE;QACnB,IAAI,UAAsB;QAC1B,UAAU,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;QACtC,OAAO,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAA,MAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;IAC9E;IAEA,eAAe,GAAQ,EAAE;QACvB,IAAI,UAAsB;QAC1B,UAAU,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;QACvC,OAAO,IAAI,CAAC,mBAAmB,CAAC,SAAS,CAAA,MAAO,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC;IAC/E;IAEQ,QACN,GAAQ,EACR,OAAiC,EACjC,UAAuD,EACvD;QACA,IAAI,UAAsB;QAC1B,IAAI,WAAW,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC;QAC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AgB,GAAG;YACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA,GAAA,yCAAgB,EAAE,IAAI,CAAC,GAAG;QACtD;QAEA,wEAAwE;QACxE,mDAAmD;QACnD,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,WAAW,KAAK,YAAY;YAC9D,IAAI,CAAC,YAAY,GAAG;YACpB,IAAI,CAAC,aAAa,GAAG;QACvB;IACF;AA4NF","sources":["packages/@react-aria/selection/src/ListKeyboardDelegate.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 {Collection, Direction, DisabledBehavior, Key, KeyboardDelegate, LayoutDelegate, Node, Orientation, Rect, RefObject} from '@react-types/shared';\nimport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nimport {isScrollable} from '@react-aria/utils';\n\ninterface ListKeyboardDelegateOptions<T> {\n collection: Collection<Node<T>>,\n ref: RefObject<HTMLElement | null>,\n collator?: Intl.Collator,\n layout?: 'stack' | 'grid',\n orientation?: Orientation,\n direction?: Direction,\n disabledKeys?: Set<Key>,\n disabledBehavior?: DisabledBehavior,\n layoutDelegate?: LayoutDelegate\n}\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private collection: Collection<Node<T>>;\n private disabledKeys: Set<Key>;\n private disabledBehavior: DisabledBehavior;\n private ref: RefObject<HTMLElement | null>;\n private collator: Intl.Collator | undefined;\n private layout: 'stack' | 'grid';\n private orientation?: Orientation;\n private direction?: Direction;\n private layoutDelegate: LayoutDelegate;\n\n constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement | null>, collator?: Intl.Collator);\n constructor(options: ListKeyboardDelegateOptions<T>);\n constructor(...args: any[]) {\n if (args.length === 1) {\n let opts = args[0] as ListKeyboardDelegateOptions<T>;\n this.collection = opts.collection;\n this.ref = opts.ref;\n this.collator = opts.collator;\n this.disabledKeys = opts.disabledKeys || new Set();\n this.disabledBehavior = opts.disabledBehavior || 'all';\n this.orientation = opts.orientation || 'vertical';\n this.direction = opts.direction;\n this.layout = opts.layout || 'stack';\n this.layoutDelegate = opts.layoutDelegate || new DOMLayoutDelegate(opts.ref);\n } else {\n this.collection = args[0];\n this.disabledKeys = args[1];\n this.ref = args[2];\n this.collator = args[3];\n this.layout = 'stack';\n this.orientation = 'vertical';\n this.disabledBehavior = 'all';\n this.layoutDelegate = new DOMLayoutDelegate(this.ref);\n }\n\n // If this is a vertical stack, remove the left/right methods completely\n // so they aren't called by useDroppableCollection.\n if (this.layout === 'stack' && this.orientation === 'vertical') {\n this.getKeyLeftOf = undefined;\n this.getKeyRightOf = undefined;\n }\n }\n\n private isDisabled(item: Node<unknown>) {\n return this.disabledBehavior === 'all' && (item.props?.isDisabled || this.disabledKeys.has(item.key));\n }\n\n private findNextNonDisabled(key: Key | null, getNext: (key: Key) => Key | null): Key | null {\n let nextKey = key;\n while (nextKey != null) {\n let item = this.collection.getItem(nextKey);\n if (item?.type === 'item' && !this.isDisabled(item)) {\n return nextKey;\n }\n\n nextKey = getNext(nextKey);\n }\n\n return null;\n }\n\n getNextKey(key: Key) {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyAfter(nextKey);\n return this.findNextNonDisabled(nextKey, key => this.collection.getKeyAfter(key));\n }\n\n getPreviousKey(key: Key) {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyBefore(nextKey);\n return this.findNextNonDisabled(nextKey, key => this.collection.getKeyBefore(key));\n }\n\n private findKey(\n key: Key,\n nextKey: (key: Key) => Key | null,\n shouldSkip: (prevRect: Rect, itemRect: Rect) => boolean\n ) {\n let tempKey: Key | null = key;\n let itemRect = this.layoutDelegate.getItemRect(tempKey);\n if (!itemRect || tempKey == null) {\n return null;\n }\n\n // Find the item above or below in the same column.\n let prevRect = itemRect;\n do {\n tempKey = nextKey(tempKey);\n if (tempKey == null) {\n break;\n }\n itemRect = this.layoutDelegate.getItemRect(tempKey);\n } while (itemRect && shouldSkip(prevRect, itemRect) && tempKey != null);\n\n return tempKey;\n }\n\n private isSameRow(prevRect: Rect, itemRect: Rect) {\n return prevRect.y === itemRect.y || prevRect.x !== itemRect.x;\n }\n\n private isSameColumn(prevRect: Rect, itemRect: Rect) {\n return prevRect.x === itemRect.x || prevRect.y !== itemRect.y;\n }\n\n getKeyBelow(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getNextKey(key), this.isSameRow);\n } else {\n return this.getNextKey(key);\n }\n }\n\n getKeyAbove(key: Key) {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getPreviousKey(key), this.isSameRow);\n } else {\n return this.getPreviousKey(key);\n }\n }\n\n private getNextColumn(key: Key, right: boolean) {\n return right ? this.getPreviousKey(key) : this.getNextKey(key);\n }\n\n getKeyRightOf?(key: Key) {\n // This is a temporary solution for CardView until we refactor useSelectableCollection.\n // https://github.com/orgs/adobe/projects/19/views/32?pane=issue&itemId=77825042\n let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyRightOf' : 'getKeyLeftOf';\n if (this.layoutDelegate[layoutDelegateMethod]) {\n key = this.layoutDelegate[layoutDelegateMethod](key);\n return this.findNextNonDisabled(key, key => this.layoutDelegate[layoutDelegateMethod](key));\n }\n\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'rtl');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'rtl'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'rtl');\n }\n\n return null;\n }\n\n getKeyLeftOf?(key: Key) {\n let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyLeftOf' : 'getKeyRightOf';\n if (this.layoutDelegate[layoutDelegateMethod]) {\n key = this.layoutDelegate[layoutDelegateMethod](key);\n return this.findNextNonDisabled(key, key => this.layoutDelegate[layoutDelegateMethod](key));\n }\n\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'ltr');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'ltr'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'ltr');\n }\n\n return null;\n }\n\n getFirstKey() {\n let key = this.collection.getFirstKey();\n return this.findNextNonDisabled(key, key => this.collection.getKeyAfter(key));\n }\n\n getLastKey() {\n let key = this.collection.getLastKey();\n return this.findNextNonDisabled(key, key => this.collection.getKeyBefore(key));\n }\n\n getKeyPageAbove(key: Key) {\n let menu = this.ref.current;\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n if (menu && !isScrollable(menu)) {\n return this.getFirstKey();\n }\n\n let nextKey: Key | null = key;\n if (this.orientation === 'horizontal') {\n let pageX = Math.max(0, itemRect.x + itemRect.width - this.layoutDelegate.getVisibleRect().width);\n\n while (itemRect && itemRect.x > pageX && nextKey != null) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n } else {\n let pageY = Math.max(0, itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height);\n\n while (itemRect && itemRect.y > pageY && nextKey != null) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n }\n\n return nextKey ?? this.getFirstKey();\n }\n\n getKeyPageBelow(key: Key) {\n let menu = this.ref.current;\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n if (menu && !isScrollable(menu)) {\n return this.getLastKey();\n }\n\n let nextKey: Key | null = key;\n if (this.orientation === 'horizontal') {\n let pageX = Math.min(this.layoutDelegate.getContentSize().width, itemRect.y - itemRect.width + this.layoutDelegate.getVisibleRect().width);\n\n while (itemRect && itemRect.x < pageX && nextKey != null) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n } else {\n let pageY = Math.min(this.layoutDelegate.getContentSize().height, itemRect.y - itemRect.height + this.layoutDelegate.getVisibleRect().height);\n\n while (itemRect && itemRect.y < pageY && nextKey != null) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n }\n\n return nextKey ?? this.getLastKey();\n }\n\n getKeyForSearch(search: string, fromKey?: Key) {\n if (!this.collator) {\n return null;\n }\n\n let collection = this.collection;\n let key = fromKey || this.getFirstKey();\n while (key != null) {\n let item = collection.getItem(key);\n if (!item) {\n return null;\n }\n let substring = item.textValue.slice(0, search.length);\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.getNextKey(key);\n }\n\n return null;\n }\n}\n"],"names":[],"version":3,"file":"ListKeyboardDelegate.module.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAkBM,MAAM;IA4CH,WAAW,IAAmB,EAAE;YACK;QAA3C,OAAO,IAAI,CAAC,gBAAgB,KAAK,SAAU,CAAA,EAAA,cAAA,KAAK,KAAK,cAAV,kCAAA,YAAY,UAAU,KAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,GAAG,CAAA;IACrG;IAEQ,oBAAoB,GAAe,EAAE,OAAiC,EAAc;QAC1F,IAAI,UAAU;QACd,MAAO,WAAW,KAAM;YACtB,IAAI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;YACnC,IAAI,CAAA,iBAAA,2BAAA,KAAM,IAAI,MAAK,UA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Y,GAAG,KAAK,YAAY,IAAI,IAAI;YAC7C,IAAI,CAAC,gBAAgB,GAAG,KAAK,gBAAgB,IAAI;YACjD,IAAI,CAAC,WAAW,GAAG,KAAK,WAAW,IAAI;YACvC,IAAI,CAAC,SAAS,GAAG,KAAK,SAAS;YAC/B,IAAI,CAAC,MAAM,GAAG,KAAK,MAAM,IAAI;YAC7B,IAAI,CAAC,cAAc,GAAG,KAAK,cAAc,IAAI,IAAI,CAAA,GAAA,yCAAgB,EAAE,KAAK,GAAG;QAC7E,OAAO;YACL,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,EAAE;YACzB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE;YAC3B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,EAAE;YAClB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE;YACvB,IAAI,CAAC,MAAM,GAAG;YACd,IAAI,CAAC,WAAW,GAAG;YACnB,IAAI,CAAC,gBAAgB,GAAG;YACxB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAA,GAAA,yCAAgB,EAAE,IAAI,CAAC,GAAG;QACtD;QAEA,wEAAwE;QACxE,mDAAmD;QACnD,IAAI,IAAI,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,WAAW,KAAK,YAAY;YAC9D,IAAI,CAAC,YAAY,GAAG;YACpB,IAAI,CAAC,aAAa,GAAG;QACvB;IACF;AA4NF","sources":["packages/@react-aria/selection/src/ListKeyboardDelegate.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 {Collection, Direction, DisabledBehavior, Key, KeyboardDelegate, LayoutDelegate, Node, Orientation, Rect, RefObject} from '@react-types/shared';\nimport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nimport {isScrollable} from '@react-aria/utils';\n\ninterface ListKeyboardDelegateOptions<T> {\n collection: Collection<Node<T>>,\n ref: RefObject<HTMLElement | null>,\n collator?: Intl.Collator,\n layout?: 'stack' | 'grid',\n orientation?: Orientation,\n direction?: Direction,\n disabledKeys?: Set<Key>,\n disabledBehavior?: DisabledBehavior,\n layoutDelegate?: LayoutDelegate\n}\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n private collection: Collection<Node<T>>;\n private disabledKeys: Set<Key>;\n private disabledBehavior: DisabledBehavior;\n private ref: RefObject<HTMLElement | null>;\n private collator: Intl.Collator | undefined;\n private layout: 'stack' | 'grid';\n private orientation?: Orientation;\n private direction?: Direction;\n private layoutDelegate: LayoutDelegate;\n\n constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement | null>, collator?: Intl.Collator);\n constructor(options: ListKeyboardDelegateOptions<T>);\n constructor(...args: any[]) {\n if (args.length === 1) {\n let opts = args[0] as ListKeyboardDelegateOptions<T>;\n this.collection = opts.collection;\n this.ref = opts.ref;\n this.collator = opts.collator;\n this.disabledKeys = opts.disabledKeys || new Set();\n this.disabledBehavior = opts.disabledBehavior || 'all';\n this.orientation = opts.orientation || 'vertical';\n this.direction = opts.direction;\n this.layout = opts.layout || 'stack';\n this.layoutDelegate = opts.layoutDelegate || new DOMLayoutDelegate(opts.ref);\n } else {\n this.collection = args[0];\n this.disabledKeys = args[1];\n this.ref = args[2];\n this.collator = args[3];\n this.layout = 'stack';\n this.orientation = 'vertical';\n this.disabledBehavior = 'all';\n this.layoutDelegate = new DOMLayoutDelegate(this.ref);\n }\n\n // If this is a vertical stack, remove the left/right methods completely\n // so they aren't called by useDroppableCollection.\n if (this.layout === 'stack' && this.orientation === 'vertical') {\n this.getKeyLeftOf = undefined;\n this.getKeyRightOf = undefined;\n }\n }\n\n private isDisabled(item: Node<unknown>) {\n return this.disabledBehavior === 'all' && (item.props?.isDisabled || this.disabledKeys.has(item.key));\n }\n\n private findNextNonDisabled(key: Key | null, getNext: (key: Key) => Key | null): Key | null {\n let nextKey = key;\n while (nextKey != null) {\n let item = this.collection.getItem(nextKey);\n if (item?.type === 'item' && !this.isDisabled(item)) {\n return nextKey;\n }\n\n nextKey = getNext(nextKey);\n }\n\n return null;\n }\n\n getNextKey(key: Key): Key | null {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyAfter(nextKey);\n return this.findNextNonDisabled(nextKey, key => this.collection.getKeyAfter(key));\n }\n\n getPreviousKey(key: Key): Key | null {\n let nextKey: Key | null = key;\n nextKey = this.collection.getKeyBefore(nextKey);\n return this.findNextNonDisabled(nextKey, key => this.collection.getKeyBefore(key));\n }\n\n private findKey(\n key: Key,\n nextKey: (key: Key) => Key | null,\n shouldSkip: (prevRect: Rect, itemRect: Rect) => boolean\n ) {\n let tempKey: Key | null = key;\n let itemRect = this.layoutDelegate.getItemRect(tempKey);\n if (!itemRect || tempKey == null) {\n return null;\n }\n\n // Find the item above or below in the same column.\n let prevRect = itemRect;\n do {\n tempKey = nextKey(tempKey);\n if (tempKey == null) {\n break;\n }\n itemRect = this.layoutDelegate.getItemRect(tempKey);\n } while (itemRect && shouldSkip(prevRect, itemRect) && tempKey != null);\n\n return tempKey;\n }\n\n private isSameRow(prevRect: Rect, itemRect: Rect) {\n return prevRect.y === itemRect.y || prevRect.x !== itemRect.x;\n }\n\n private isSameColumn(prevRect: Rect, itemRect: Rect) {\n return prevRect.x === itemRect.x || prevRect.y !== itemRect.y;\n }\n\n getKeyBelow(key: Key): Key | null {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getNextKey(key), this.isSameRow);\n } else {\n return this.getNextKey(key);\n }\n }\n\n getKeyAbove(key: Key): Key | null {\n if (this.layout === 'grid' && this.orientation === 'vertical') {\n return this.findKey(key, (key) => this.getPreviousKey(key), this.isSameRow);\n } else {\n return this.getPreviousKey(key);\n }\n }\n\n private getNextColumn(key: Key, right: boolean) {\n return right ? this.getPreviousKey(key) : this.getNextKey(key);\n }\n\n getKeyRightOf?(key: Key): Key | null {\n // This is a temporary solution for CardView until we refactor useSelectableCollection.\n // https://github.com/orgs/adobe/projects/19/views/32?pane=issue&itemId=77825042\n let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyRightOf' : 'getKeyLeftOf';\n if (this.layoutDelegate[layoutDelegateMethod]) {\n key = this.layoutDelegate[layoutDelegateMethod](key);\n return this.findNextNonDisabled(key, key => this.layoutDelegate[layoutDelegateMethod](key));\n }\n\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'rtl');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'rtl'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'rtl');\n }\n\n return null;\n }\n\n getKeyLeftOf?(key: Key): Key | null {\n let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyLeftOf' : 'getKeyRightOf';\n if (this.layoutDelegate[layoutDelegateMethod]) {\n key = this.layoutDelegate[layoutDelegateMethod](key);\n return this.findNextNonDisabled(key, key => this.layoutDelegate[layoutDelegateMethod](key));\n }\n\n if (this.layout === 'grid') {\n if (this.orientation === 'vertical') {\n return this.getNextColumn(key, this.direction === 'ltr');\n } else {\n return this.findKey(key, (key) => this.getNextColumn(key, this.direction === 'ltr'), this.isSameColumn);\n }\n } else if (this.orientation === 'horizontal') {\n return this.getNextColumn(key, this.direction === 'ltr');\n }\n\n return null;\n }\n\n getFirstKey(): Key | null {\n let key = this.collection.getFirstKey();\n return this.findNextNonDisabled(key, key => this.collection.getKeyAfter(key));\n }\n\n getLastKey(): Key | null {\n let key = this.collection.getLastKey();\n return this.findNextNonDisabled(key, key => this.collection.getKeyBefore(key));\n }\n\n getKeyPageAbove(key: Key): Key | null {\n let menu = this.ref.current;\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n if (menu && !isScrollable(menu)) {\n return this.getFirstKey();\n }\n\n let nextKey: Key | null = key;\n if (this.orientation === 'horizontal') {\n let pageX = Math.max(0, itemRect.x + itemRect.width - this.layoutDelegate.getVisibleRect().width);\n\n while (itemRect && itemRect.x > pageX && nextKey != null) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n } else {\n let pageY = Math.max(0, itemRect.y + itemRect.height - this.layoutDelegate.getVisibleRect().height);\n\n while (itemRect && itemRect.y > pageY && nextKey != null) {\n nextKey = this.getKeyAbove(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n }\n\n return nextKey ?? this.getFirstKey();\n }\n\n getKeyPageBelow(key: Key): Key | null {\n let menu = this.ref.current;\n let itemRect = this.layoutDelegate.getItemRect(key);\n if (!itemRect) {\n return null;\n }\n\n if (menu && !isScrollable(menu)) {\n return this.getLastKey();\n }\n\n let nextKey: Key | null = key;\n if (this.orientation === 'horizontal') {\n let pageX = Math.min(this.layoutDelegate.getContentSize().width, itemRect.y - itemRect.width + this.layoutDelegate.getVisibleRect().width);\n\n while (itemRect && itemRect.x < pageX && nextKey != null) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n } else {\n let pageY = Math.min(this.layoutDelegate.getContentSize().height, itemRect.y - itemRect.height + this.layoutDelegate.getVisibleRect().height);\n\n while (itemRect && itemRect.y < pageY && nextKey != null) {\n nextKey = this.getKeyBelow(nextKey);\n itemRect = nextKey == null ? null : this.layoutDelegate.getItemRect(nextKey);\n }\n }\n\n return nextKey ?? this.getLastKey();\n }\n\n getKeyForSearch(search: string, fromKey?: Key): Key | null {\n if (!this.collator) {\n return null;\n }\n\n let collection = this.collection;\n let key = fromKey || this.getFirstKey();\n while (key != null) {\n let item = collection.getItem(key);\n if (!item) {\n return null;\n }\n let substring = item.textValue.slice(0, search.length);\n if (item.textValue && this.collator.compare(substring, search) === 0) {\n return key;\n }\n\n key = this.getNextKey(key);\n }\n\n return null;\n }\n}\n"],"names":[],"version":3,"file":"ListKeyboardDelegate.module.js.map"}
package/dist/types.d.ts CHANGED
@@ -57,6 +57,11 @@ export interface AriaSelectableCollectionOptions {
57
57
  * @default false
58
58
  */
59
59
  disallowSelectAll?: boolean;
60
+ /**
61
+ * Whether pressing the Escape should clear selection in the collection or not.
62
+ * @default 'clearSelection'
63
+ */
64
+ escapeKeyBehavior?: 'clearSelection' | 'none';
60
65
  /**
61
66
  * Whether selection should occur automatically on focus.
62
67
  * @default false
@@ -1 +1 @@
1
- {"mappings":";;ACqBA;IACE;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;CAClC;AAED;IACE;;OAEG;IACH,eAAe,EAAE,aAAa,CAAA;CAC/B;AAED;;GAEG;AACH,8BAA8B,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAyD5E;AChFD;IACE;;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;;OAEG;IACH,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAC;IACnC;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IACpC;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,aAAa,CAAC,EAAE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AkDnD,UAAU,CAAC,GAAG,EAAE,GAAG;IAMnB,cAAc,CAAC,GAAG,EAAE,GAAG;IAsCvB,WAAW,CAAC,GAAG,EAAE,GAAG;IAQpB,WAAW,CAAC,GAAG,EAAE,GAAG;IAYpB,aAAa,CAAC,CAAC,GAAG,EAAE,GAAG;IAsBvB,YAAY,CAAC,CAAC,GAAG,EAAE,GAAG;IAoBtB,WAAW;IAKX,UAAU;IAKV,eAAe,CAAC,GAAG,EAAE,GAAG;IA+BxB,eAAe,CAAC,GAAG,EAAE,GAAG;IA+BxB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG;CAsB9C;AChRD,0CAA2C,SAAQ,IAAI,CAAC,+BAA+B,EAAE,kBAAkB,CAAC;IAC1G;;OAEG;IACH,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC;;OAEG;IACH,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;CACvB;AAED;IACE;;OAEG;IACH,SAAS,EAAE,aAAa,CAAA;CACzB;AAED;;GAEG;AACH,kCAAkC,KAAK,EAAE,yBAAyB,GAAG,kBAAkB,CAmCtF","sources":["packages/@react-aria/selection/src/packages/@react-aria/selection/src/utils.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useTypeSelect.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableCollection.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableItem.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/DOMLayoutDelegate.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/ListKeyboardDelegate.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableList.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/index.ts","packages/@react-aria/selection/src/index.ts"],"sourcesContent":[null,null,null,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 {useSelectableCollection} from './useSelectableCollection';\nexport {useSelectableItem} from './useSelectableItem';\nexport {useSelectableList} from './useSelectableList';\nexport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nexport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nexport {useTypeSelect} from './useTypeSelect';\n\nexport type {AriaSelectableCollectionOptions, SelectableCollectionAria} from './useSelectableCollection';\nexport type {AriaSelectableListOptions, SelectableListAria} from './useSelectableList';\nexport type {SelectableItemOptions, SelectableItemStates, SelectableItemAria} from './useSelectableItem';\nexport type {AriaTypeSelectOptions, TypeSelectAria} from './useTypeSelect';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;ACqBA;IACE;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAA;CAClC;AAED;IACE;;OAEG;IACH,eAAe,EAAE,aAAa,CAAA;CAC/B;AAED;;GAEG;AACH,8BAA8B,OAAO,EAAE,qBAAqB,GAAG,cAAc,CAyD5E;AChFD;IACE;;OAEG;IACH,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;IACnC;;OAEG;IACH,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAC;IACnC;;;OA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;;OAEG;IACH,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;CACvB;AAED;IACE;;OAEG;IACH,SAAS,EAAE,aAAa,CAAA;CACzB;AAED;;GAEG;AACH,kCAAkC,KAAK,EAAE,yBAAyB,GAAG,kBAAkB,CAmCtF","sources":["packages/@react-aria/selection/src/packages/@react-aria/selection/src/utils.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useTypeSelect.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableCollection.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableItem.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/DOMLayoutDelegate.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/ListKeyboardDelegate.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/useSelectableList.ts","packages/@react-aria/selection/src/packages/@react-aria/selection/src/index.ts","packages/@react-aria/selection/src/index.ts"],"sourcesContent":[null,null,null,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 {useSelectableCollection} from './useSelectableCollection';\nexport {useSelectableItem} from './useSelectableItem';\nexport {useSelectableList} from './useSelectableList';\nexport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nexport {DOMLayoutDelegate} from './DOMLayoutDelegate';\nexport {useTypeSelect} from './useTypeSelect';\n\nexport type {AriaSelectableCollectionOptions, SelectableCollectionAria} from './useSelectableCollection';\nexport type {AriaSelectableListOptions, SelectableListAria} from './useSelectableList';\nexport type {SelectableItemOptions, SelectableItemStates, SelectableItemAria} from './useSelectableItem';\nexport type {AriaTypeSelectOptions, TypeSelectAria} from './useTypeSelect';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -32,7 +32,7 @@ $parcel$export(module.exports, "useSelectableCollection", () => $b6837c2f80a3c32
32
32
 
33
33
 
34
34
  function $b6837c2f80a3c32f$export$d6daf82dcd84e87c(options) {
35
- let { selectionManager: manager, keyboardDelegate: delegate, ref: ref, autoFocus: autoFocus = false, shouldFocusWrap: shouldFocusWrap = false, disallowEmptySelection: disallowEmptySelection = false, disallowSelectAll: disallowSelectAll = false, selectOnFocus: selectOnFocus = manager.selectionBehavior === 'replace', disallowTypeAhead: disallowTypeAhead = false, shouldUseVirtualFocus: shouldUseVirtualFocus, allowsTabNavigation: allowsTabNavigation = false, isVirtualized: isVirtualized, scrollRef: // If no scrollRef is provided, assume the collection ref is the scrollable region
35
+ let { selectionManager: manager, keyboardDelegate: delegate, ref: ref, autoFocus: autoFocus = false, shouldFocusWrap: shouldFocusWrap = false, disallowEmptySelection: disallowEmptySelection = false, disallowSelectAll: disallowSelectAll = false, escapeKeyBehavior: escapeKeyBehavior = 'clearSelection', selectOnFocus: selectOnFocus = manager.selectionBehavior === 'replace', disallowTypeAhead: disallowTypeAhead = false, shouldUseVirtualFocus: shouldUseVirtualFocus, allowsTabNavigation: allowsTabNavigation = false, isVirtualized: isVirtualized, scrollRef: // If no scrollRef is provided, assume the collection ref is the scrollable region
36
36
  scrollRef = ref, linkBehavior: linkBehavior = 'action' } = options;
37
37
  let { direction: direction } = (0, $bT8Bh$reactariai18n.useLocale)();
38
38
  let router = (0, $bT8Bh$reactariautils.useRouter)();
@@ -155,7 +155,7 @@ function $b6837c2f80a3c32f$export$d6daf82dcd84e87c(options) {
155
155
  }
156
156
  break;
157
157
  case 'Escape':
158
- if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {
158
+ if (escapeKeyBehavior === 'clearSelection' && !disallowEmptySelection && manager.selectedKeys.size !== 0) {
159
159
  e.stopPropagation();
160
160
  e.preventDef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QAAQ,UAAU;IACrD,OAAO;QACL,iBAAiB,CAAA,GAAA,gCAAS,EAAE,UAAU;sBACpC;YACA,mBAAmB;QACrB;IACF;AACF","sources":["packages/@react-aria/selection/src/useSelectableCollection.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 {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, isCtrlKeyPressed, mergeProps, scrollIntoView, scrollIntoViewport, useEffectEvent, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate, RefObject} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, KeyboardEvent, useEffect, useRef} from 'react';\nimport {focusSafely, getInteractionModality} from '@react-aria/interactions';\nimport {getFocusableTreeWalker, moveVirtualFocus} from '@react-aria/focus';\nimport {getItemElement, isNonContiguousSelectionModifier, useCollectionId} from './utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useLocale} from '@react-aria/i18n';\nimport {useTypeSelect} from './useTypeSelect';\n\nexport interface AriaSelectableCollectionOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * The ref attached to the element representing the collection.\n */\n ref: RefObject<HTMLElement | null>,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n * @default false\n */\n disallowSelectAll?: boolean,\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean,\n /**\n * Whether the collection items are contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.\n * If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement | null>,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override'\n}\n\nexport interface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: DOMAttributes\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(options: AriaSelectableCollectionOptions): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n selectOnFocus = manager.selectionBehavior === 'replace',\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n isVirtualized,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref,\n linkBehavior = 'action'\n } = options;\n let {direction} = useLocale();\n let router = useRouter();\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes\n if (e.altKey && e.key === 'Tab') {\n e.preventDefault();\n }\n\n // Keyboard events bubble through portals. Don't handle keyboard events\n // for elements outside the collection (e.g. menus).\n if (!ref.current?.contains(e.target as Element)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n // Set focused key and re-render synchronously to bring item into view if needed.\n flushSync(() => {\n manager.setFocusedKey(key, childFocus);\n });\n\n let item = getItemElement(ref, key);\n let itemProps = manager.getItemProps(key);\n if (item) {\n router.open(item, e, itemProps.href, itemProps.routerOptions);\n }\n\n return;\n }\n\n manager.setFocusedKey(key, childFocus);\n\n if (manager.isLink(key) && linkBehavior === 'override') {\n return;\n }\n\n if (e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(key);\n } else if (selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n manager.replaceSelection(key);\n }\n }\n };\n\n switch (e.key) {\n case 'ArrowDown': {\n if (delegate.getKeyBelow) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyBelow?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyAbove?.(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n let nextKey: Key | undefined | null = manager.focusedKey != null ? delegate.getKeyLeftOf?.(manager.focusedKey) : null;\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getFirstKey?.(manager.focusedKey) : delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n let nextKey: Key | undefined | null = manager.focusedKey != null ? delegate.getKeyRightOf?.(manager.focusedKey) : null;\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getLastKey?.(manager.focusedKey) : delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n e.preventDefault();\n let firstKey: Key | null = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (firstKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (lastKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'a':\n if (isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {\n e.stopPropagation();\n e.preventDefault();\n manager.clearSelection();\n }\n break;\n case 'Tab': {\n if (!allowsTabNavigation) {\n // There may be elements that are \"tabbable\" inside a collection (e.g. in a grid cell).\n // However, collections should be treated as a single tab stop, with arrow key navigation internally.\n // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.\n // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element\n // in the collection, so that the browser default behavior will apply starting from that element\n // rather than the currently focused one.\n if (e.shiftKey) {\n ref.current.focus();\n } else {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n let next: FocusableElement | undefined = undefined;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n\n if (next && !next.contains(document.activeElement)) {\n focusWithoutScrolling(next);\n }\n }\n break;\n }\n }\n }\n };\n\n // Store the scroll position so we can restore it later.\n /// TODO: should this happen all the time??\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', isVirtualized ? undefined : () => {\n scrollPos.current = {\n top: scrollRef.current?.scrollTop ?? 0,\n left: scrollRef.current?.scrollLeft ?? 0\n };\n });\n\n let onFocus = (e: FocusEvent) => {\n if (manager.isFocused) {\n // If a focus event bubbled through a portal, reset focus state.\n if (!e.currentTarget.contains(e.target)) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n manager.setFocused(true);\n if (manager.focusedKey == null) {\n let navigateToKey = (key: Key | undefined | null) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus && !manager.isSelected(key)) {\n manager.replaceSelection(key);\n }\n }\n };\n // If the user hasn't yet interacted with the collection, there will be no focusedKey set.\n // Attempt to detect whether the user is tabbing forward or backward into the collection\n // and either focus the first or last item accordingly.\n let relatedTarget = e.relatedTarget as Element;\n if (relatedTarget && (e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING)) {\n navigateToKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n } else {\n navigateToKey(manager.firstSelectedKey ?? delegate.getFirstKey?.());\n }\n } else if (!isVirtualized && scrollRef.current) {\n // Restore the scroll position to what it was before.\n scrollRef.current.scrollTop = scrollPos.current.top;\n scrollRef.current.scrollLeft = scrollPos.current.left;\n }\n\n if (manager.focusedKey != null && scrollRef.current) {\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = getItemElement(ref, manager.focusedKey);\n if (element instanceof HTMLElement) {\n // This prevents a flash of focus on the first/last element in the collection, or the collection itself.\n if (!element.contains(document.activeElement) && !shouldUseVirtualFocus) {\n focusWithoutScrolling(element);\n }\n\n let modality = getInteractionModality();\n if (modality === 'keyboard') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n };\n\n let onBlur = (e) => {\n // Don't set blurred and then focused again if moving focus within the collection.\n if (!e.currentTarget.contains(e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n // Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types\n // to focus the first key AFTER the collection updates.\n // TODO: potentially expand the usage of this\n let shouldVirtualFocusFirst = useRef(false);\n // Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events\n // at the autocomplete level\n // TODO: fix type later\n useEvent(ref, FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n let {detail} = e;\n e.stopPropagation();\n manager.setFocused(true);\n\n // If the user is typing forwards, autofocus the first option in the list.\n if (detail?.focusStrategy === 'first') {\n shouldVirtualFocusFirst.current = true;\n }\n });\n\n let updateActiveDescendant = useEffectEvent(() => {\n let keyToFocus = delegate.getFirstKey?.() ?? null;\n\n // If no focusable items exist in the list, make sure to clear any activedescendant that may still exist\n if (keyToFocus == null) {\n moveVirtualFocus(ref.current);\n\n // If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.\n // Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n } else {\n manager.setFocusedKey(keyToFocus);\n // Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key\n // If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key\n // after the collection updates after load\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n if (shouldVirtualFocusFirst.current) {\n updateActiveDescendant();\n }\n\n }, [manager.collection, updateActiveDescendant]);\n\n let resetFocusFirstFlag = useEffectEvent(() => {\n // If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't\n // accidentally move focus from under them. Skip this if the collection was empty because we might be in a load\n // state and will still want to focus the first item after load\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n resetFocusFirstFlag();\n }, [manager.focusedKey, resetFocusFirstFlag]);\n\n useEvent(ref, CLEAR_FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n e.stopPropagation();\n manager.setFocused(false);\n if (e.detail?.clearFocusKey) {\n manager.setFocusedKey(null);\n }\n });\n\n const autoFocusRef = useRef(autoFocus);\n const didAutoFocusRef = useRef(false);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey: Key | null = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey?.() ?? null;\n } if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey?.() ?? null;\n }\n\n // If there are any selected keys, make the first one the new focus target\n let selectedKeys = manager.selectedKeys;\n if (selectedKeys.size) {\n for (let key of selectedKeys) {\n if (manager.canSelectItem(key)) {\n focusedKey = key;\n break;\n }\n }\n }\n\n manager.setFocused(true);\n manager.setFocusedKey(focusedKey);\n\n // If no default focus key is selected, focus the collection itself.\n if (focusedKey == null && !shouldUseVirtualFocus && ref.current) {\n focusSafely(ref.current);\n }\n\n // Wait until the collection has items to autofocus.\n if (manager.collection.size > 0) {\n autoFocusRef.current = false;\n didAutoFocusRef.current = true;\n }\n }\n });\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n useEffect(() => {\n if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || didAutoFocusRef.current) && scrollRef.current && ref.current) {\n let modality = getInteractionModality();\n let element = getItemElement(ref, manager.focusedKey);\n if (!(element instanceof HTMLElement)) {\n // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).\n // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.\n return;\n }\n\n if (modality === 'keyboard' || didAutoFocusRef.current) {\n scrollIntoView(scrollRef.current, element);\n\n // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)\n if (modality !== 'virtual') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n\n // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.\n if (!shouldUseVirtualFocus && manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null && ref.current) {\n focusSafely(ref.current);\n }\n\n lastFocusedKey.current = manager.focusedKey;\n didAutoFocusRef.current = false;\n });\n\n // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.\n useEvent(ref, 'react-aria-focus-scope-restore', e => {\n e.preventDefault();\n manager.setFocused(true);\n });\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (scrollRef.current === e.target) {\n // Prevent focus going to the collection when clicking on the scrollbar.\n e.preventDefault();\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: manager\n });\n\n if (!disallowTypeAhead) {\n handlers = mergeProps(typeSelectProps, handlers);\n }\n\n // If nothing is focused within the collection, make the collection itself tabbable.\n // This will be marshalled to either the first or last item depending on where focus came from.\n let tabIndex: number | undefined = undefined;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n let collectionId = useCollectionId(manager.collection);\n return {\n collectionProps: mergeProps(handlers, {\n tabIndex,\n 'data-collection': collectionId\n })\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgGM,SAAS,0CAAwB,OAAwC;IAC9E,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,GAAG,aACH,YAAY,wBACZ,kBAAkB,+BAClB,yBAAyB,0BACzB,oBAAoB,0BACpB,oBAAoB,iCACpB,gBAAgB,QAAQ,iBAAiB,KAAK,8BAC9C,oBAAoB,8BACpB,qBAAqB,uBACrB,sBAAsB,sBACtB,aAAa,aACb,kFAAkF;IAClF,YAAY,mBACZ,eAAe,UAChB,GAAG;IACJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,SAAS,CAAA,GAAA,+BAAQ;IAErB,IAAI,YAAY,CAAC;YAQV;QAPL,6GAA6G;QAC7G,IAAI,EAAE,MAAM,IAAI,EAAE,GAAG,KAAK,OACxB,EAAE,cAAc;QAGlB,uEAAuE;QACvE,oDAAoD;QACpD,IAAI,GAAC,eAAA,IAAI,OAAO,cAAX,mCAAA,aAAa,QAAQ,CAAC,EAAE,MAAM,IACjC;QAGF,MAAM,gBAAgB,CAAC,KAAsB;YAC3C,IAAI,OAAO,MAAM;gBACf,IAAI,QAAQ,MAAM,CAAC,QAAQ,iBAAiB,eAAe,iBAAiB,CAAC,CAAA,GAAA,0DAA+B,EAAE,IAAI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AM,EAChC,wEAAwE;YACxE,EAAE,cAAc;QAEpB;IACF;IAEA,IAAI,mBAAC,eAAe,EAAC,GAAG,CAAA,GAAA,uCAAY,EAAE;QACpC,kBAAkB;QAClB,kBAAkB;IACpB;IAEA,IAAI,CAAC,mBACH,WAAW,CAAA,GAAA,gCAAS,EAAE,iBAAiB;IAGzC,oFAAoF;IACpF,+FAA+F;IAC/F,IAAI,WAA+B;IACnC,IAAI,CAAC,uBACH,WAAW,QAAQ,UAAU,IAAI,OAAO,IAAI;IAG9C,IAAI,eAAe,CAAA,GAAA,yCAAc,EAAE,QAAQ,UAAU;IACrD,OAAO;QACL,iBAAiB,CAAA,GAAA,gCAAS,EAAE,UAAU;sBACpC;YACA,mBAAmB;QACrB;IACF;AACF","sources":["packages/@react-aria/selection/src/useSelectableCollection.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 {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, isCtrlKeyPressed, mergeProps, scrollIntoView, scrollIntoViewport, useEffectEvent, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate, RefObject} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, KeyboardEvent, useEffect, useRef} from 'react';\nimport {focusSafely, getInteractionModality} from '@react-aria/interactions';\nimport {getFocusableTreeWalker, moveVirtualFocus} from '@react-aria/focus';\nimport {getItemElement, isNonContiguousSelectionModifier, useCollectionId} from './utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useLocale} from '@react-aria/i18n';\nimport {useTypeSelect} from './useTypeSelect';\n\nexport interface AriaSelectableCollectionOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * The ref attached to the element representing the collection.\n */\n ref: RefObject<HTMLElement | null>,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n * @default false\n */\n disallowSelectAll?: boolean,\n /**\n * Whether pressing the Escape should clear selection in the collection or not.\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none',\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean,\n /**\n * Whether the collection items are contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.\n * If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement | null>,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override'\n}\n\nexport interface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: DOMAttributes\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(options: AriaSelectableCollectionOptions): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n escapeKeyBehavior = 'clearSelection',\n selectOnFocus = manager.selectionBehavior === 'replace',\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n isVirtualized,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref,\n linkBehavior = 'action'\n } = options;\n let {direction} = useLocale();\n let router = useRouter();\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes\n if (e.altKey && e.key === 'Tab') {\n e.preventDefault();\n }\n\n // Keyboard events bubble through portals. Don't handle keyboard events\n // for elements outside the collection (e.g. menus).\n if (!ref.current?.contains(e.target as Element)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n // Set focused key and re-render synchronously to bring item into view if needed.\n flushSync(() => {\n manager.setFocusedKey(key, childFocus);\n });\n\n let item = getItemElement(ref, key);\n let itemProps = manager.getItemProps(key);\n if (item) {\n router.open(item, e, itemProps.href, itemProps.routerOptions);\n }\n\n return;\n }\n\n manager.setFocusedKey(key, childFocus);\n\n if (manager.isLink(key) && linkBehavior === 'override') {\n return;\n }\n\n if (e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(key);\n } else if (selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n manager.replaceSelection(key);\n }\n }\n };\n\n switch (e.key) {\n case 'ArrowDown': {\n if (delegate.getKeyBelow) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyBelow?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyAbove?.(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n let nextKey: Key | undefined | null = manager.focusedKey != null ? delegate.getKeyLeftOf?.(manager.focusedKey) : null;\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getFirstKey?.(manager.focusedKey) : delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n let nextKey: Key | undefined | null = manager.focusedKey != null ? delegate.getKeyRightOf?.(manager.focusedKey) : null;\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getLastKey?.(manager.focusedKey) : delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n e.preventDefault();\n let firstKey: Key | null = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (firstKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (lastKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'a':\n if (isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n if (escapeKeyBehavior === 'clearSelection' && !disallowEmptySelection && manager.selectedKeys.size !== 0) {\n e.stopPropagation();\n e.preventDefault();\n manager.clearSelection();\n }\n break;\n case 'Tab': {\n if (!allowsTabNavigation) {\n // There may be elements that are \"tabbable\" inside a collection (e.g. in a grid cell).\n // However, collections should be treated as a single tab stop, with arrow key navigation internally.\n // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.\n // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element\n // in the collection, so that the browser default behavior will apply starting from that element\n // rather than the currently focused one.\n if (e.shiftKey) {\n ref.current.focus();\n } else {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n let next: FocusableElement | undefined = undefined;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n\n if (next && !next.contains(document.activeElement)) {\n focusWithoutScrolling(next);\n }\n }\n break;\n }\n }\n }\n };\n\n // Store the scroll position so we can restore it later.\n /// TODO: should this happen all the time??\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', isVirtualized ? undefined : () => {\n scrollPos.current = {\n top: scrollRef.current?.scrollTop ?? 0,\n left: scrollRef.current?.scrollLeft ?? 0\n };\n });\n\n let onFocus = (e: FocusEvent) => {\n if (manager.isFocused) {\n // If a focus event bubbled through a portal, reset focus state.\n if (!e.currentTarget.contains(e.target)) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n manager.setFocused(true);\n if (manager.focusedKey == null) {\n let navigateToKey = (key: Key | undefined | null) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus && !manager.isSelected(key)) {\n manager.replaceSelection(key);\n }\n }\n };\n // If the user hasn't yet interacted with the collection, there will be no focusedKey set.\n // Attempt to detect whether the user is tabbing forward or backward into the collection\n // and either focus the first or last item accordingly.\n let relatedTarget = e.relatedTarget as Element;\n if (relatedTarget && (e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING)) {\n navigateToKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n } else {\n navigateToKey(manager.firstSelectedKey ?? delegate.getFirstKey?.());\n }\n } else if (!isVirtualized && scrollRef.current) {\n // Restore the scroll position to what it was before.\n scrollRef.current.scrollTop = scrollPos.current.top;\n scrollRef.current.scrollLeft = scrollPos.current.left;\n }\n\n if (manager.focusedKey != null && scrollRef.current) {\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = getItemElement(ref, manager.focusedKey);\n if (element instanceof HTMLElement) {\n // This prevents a flash of focus on the first/last element in the collection, or the collection itself.\n if (!element.contains(document.activeElement) && !shouldUseVirtualFocus) {\n focusWithoutScrolling(element);\n }\n\n let modality = getInteractionModality();\n if (modality === 'keyboard') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n };\n\n let onBlur = (e) => {\n // Don't set blurred and then focused again if moving focus within the collection.\n if (!e.currentTarget.contains(e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n // Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types\n // to focus the first key AFTER the collection updates.\n // TODO: potentially expand the usage of this\n let shouldVirtualFocusFirst = useRef(false);\n // Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events\n // at the autocomplete level\n // TODO: fix type later\n useEvent(ref, FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n let {detail} = e;\n e.stopPropagation();\n manager.setFocused(true);\n\n // If the user is typing forwards, autofocus the first option in the list.\n if (detail?.focusStrategy === 'first') {\n shouldVirtualFocusFirst.current = true;\n }\n });\n\n let updateActiveDescendant = useEffectEvent(() => {\n let keyToFocus = delegate.getFirstKey?.() ?? null;\n\n // If no focusable items exist in the list, make sure to clear any activedescendant that may still exist\n if (keyToFocus == null) {\n moveVirtualFocus(ref.current);\n\n // If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.\n // Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n } else {\n manager.setFocusedKey(keyToFocus);\n // Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key\n // If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key\n // after the collection updates after load\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n if (shouldVirtualFocusFirst.current) {\n updateActiveDescendant();\n }\n\n }, [manager.collection, updateActiveDescendant]);\n\n let resetFocusFirstFlag = useEffectEvent(() => {\n // If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't\n // accidentally move focus from under them. Skip this if the collection was empty because we might be in a load\n // state and will still want to focus the first item after load\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n resetFocusFirstFlag();\n }, [manager.focusedKey, resetFocusFirstFlag]);\n\n useEvent(ref, CLEAR_FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n e.stopPropagation();\n manager.setFocused(false);\n if (e.detail?.clearFocusKey) {\n manager.setFocusedKey(null);\n }\n });\n\n const autoFocusRef = useRef(autoFocus);\n const didAutoFocusRef = useRef(false);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey: Key | null = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey?.() ?? null;\n } if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey?.() ?? null;\n }\n\n // If there are any selected keys, make the first one the new focus target\n let selectedKeys = manager.selectedKeys;\n if (selectedKeys.size) {\n for (let key of selectedKeys) {\n if (manager.canSelectItem(key)) {\n focusedKey = key;\n break;\n }\n }\n }\n\n manager.setFocused(true);\n manager.setFocusedKey(focusedKey);\n\n // If no default focus key is selected, focus the collection itself.\n if (focusedKey == null && !shouldUseVirtualFocus && ref.current) {\n focusSafely(ref.current);\n }\n\n // Wait until the collection has items to autofocus.\n if (manager.collection.size > 0) {\n autoFocusRef.current = false;\n didAutoFocusRef.current = true;\n }\n }\n });\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n useEffect(() => {\n if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || didAutoFocusRef.current) && scrollRef.current && ref.current) {\n let modality = getInteractionModality();\n let element = getItemElement(ref, manager.focusedKey);\n if (!(element instanceof HTMLElement)) {\n // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).\n // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.\n return;\n }\n\n if (modality === 'keyboard' || didAutoFocusRef.current) {\n scrollIntoView(scrollRef.current, element);\n\n // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)\n if (modality !== 'virtual') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n\n // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.\n if (!shouldUseVirtualFocus && manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null && ref.current) {\n focusSafely(ref.current);\n }\n\n lastFocusedKey.current = manager.focusedKey;\n didAutoFocusRef.current = false;\n });\n\n // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.\n useEvent(ref, 'react-aria-focus-scope-restore', e => {\n e.preventDefault();\n manager.setFocused(true);\n });\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (scrollRef.current === e.target) {\n // Prevent focus going to the collection when clicking on the scrollbar.\n e.preventDefault();\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: manager\n });\n\n if (!disallowTypeAhead) {\n handlers = mergeProps(typeSelectProps, handlers);\n }\n\n // If nothing is focused within the collection, make the collection itself tabbable.\n // This will be marshalled to either the first or last item depending on where focus came from.\n let tabIndex: number | undefined = undefined;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n let collectionId = useCollectionId(manager.collection);\n return {\n collectionProps: mergeProps(handlers, {\n tabIndex,\n 'data-collection': collectionId\n })\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.main.js.map"}
@@ -26,7 +26,7 @@ import {useLocale as $3H3GQ$useLocale} from "@react-aria/i18n";
26
26
 
27
27
 
28
28
  function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
29
- let { selectionManager: manager, keyboardDelegate: delegate, ref: ref, autoFocus: autoFocus = false, shouldFocusWrap: shouldFocusWrap = false, disallowEmptySelection: disallowEmptySelection = false, disallowSelectAll: disallowSelectAll = false, selectOnFocus: selectOnFocus = manager.selectionBehavior === 'replace', disallowTypeAhead: disallowTypeAhead = false, shouldUseVirtualFocus: shouldUseVirtualFocus, allowsTabNavigation: allowsTabNavigation = false, isVirtualized: isVirtualized, scrollRef: // If no scrollRef is provided, assume the collection ref is the scrollable region
29
+ let { selectionManager: manager, keyboardDelegate: delegate, ref: ref, autoFocus: autoFocus = false, shouldFocusWrap: shouldFocusWrap = false, disallowEmptySelection: disallowEmptySelection = false, disallowSelectAll: disallowSelectAll = false, escapeKeyBehavior: escapeKeyBehavior = 'clearSelection', selectOnFocus: selectOnFocus = manager.selectionBehavior === 'replace', disallowTypeAhead: disallowTypeAhead = false, shouldUseVirtualFocus: shouldUseVirtualFocus, allowsTabNavigation: allowsTabNavigation = false, isVirtualized: isVirtualized, scrollRef: // If no scrollRef is provided, assume the collection ref is the scrollable region
30
30
  scrollRef = ref, linkBehavior: linkBehavior = 'action' } = options;
31
31
  let { direction: direction } = (0, $3H3GQ$useLocale)();
32
32
  let router = (0, $3H3GQ$useRouter)();
@@ -149,7 +149,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
149
149
  }
150
150
  break;
151
151
  case 'Escape':
152
- if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {
152
+ if (escapeKeyBehavior === 'clearSelection' && !disallowEmptySelection && manager.selectedKeys.size !== 0) {
153
153
  e.stopPropagation();
154
154
  e.preventDefault();
155
155
  manager.clearSelection();
@@ -26,7 +26,7 @@ import {useLocale as $3H3GQ$useLocale} from "@react-aria/i18n";
26
26
 
27
27
 
28
28
  function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
29
- let { selectionManager: manager, keyboardDelegate: delegate, ref: ref, autoFocus: autoFocus = false, shouldFocusWrap: shouldFocusWrap = false, disallowEmptySelection: disallowEmptySelection = false, disallowSelectAll: disallowSelectAll = false, selectOnFocus: selectOnFocus = manager.selectionBehavior === 'replace', disallowTypeAhead: disallowTypeAhead = false, shouldUseVirtualFocus: shouldUseVirtualFocus, allowsTabNavigation: allowsTabNavigation = false, isVirtualized: isVirtualized, scrollRef: // If no scrollRef is provided, assume the collection ref is the scrollable region
29
+ let { selectionManager: manager, keyboardDelegate: delegate, ref: ref, autoFocus: autoFocus = false, shouldFocusWrap: shouldFocusWrap = false, disallowEmptySelection: disallowEmptySelection = false, disallowSelectAll: disallowSelectAll = false, escapeKeyBehavior: escapeKeyBehavior = 'clearSelection', selectOnFocus: selectOnFocus = manager.selectionBehavior === 'replace', disallowTypeAhead: disallowTypeAhead = false, shouldUseVirtualFocus: shouldUseVirtualFocus, allowsTabNavigation: allowsTabNavigation = false, isVirtualized: isVirtualized, scrollRef: // If no scrollRef is provided, assume the collection ref is the scrollable region
30
30
  scrollRef = ref, linkBehavior: linkBehavior = 'action' } = options;
31
31
  let { direction: direction } = (0, $3H3GQ$useLocale)();
32
32
  let router = (0, $3H3GQ$useRouter)();
@@ -149,7 +149,7 @@ function $ae20dd8cbca75726$export$d6daf82dcd84e87c(options) {
149
149
  }
150
150
  break;
151
151
  case 'Escape':
152
- if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {
152
+ if (escapeKeyBehavior === 'clearSelection' && !disallowEmptySelection && manager.selectedKeys.size !== 0) {
153
153
  e.stopPropagation();
154
154
  e.preventDefault();
155
155
  manager.clearSelection();
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AA2FM,SAAS,0CAAwB,OAAwC;IAC9E,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,GAAG,aACH,YAAY,wBACZ,kBAAkB,+BAClB,yBAAyB,0BACzB,oBAAoB,sBACpB,gBAAgB,QAAQ,iBAAiB,KAAK,8BAC9C,oBAAoB,8BACpB,qBAAqB,uBACrB,sBAAsB,sBACtB,aAAa,aACb,kFAAkF;IAClF,YAAY,mBACZ,eAAe,UAChB,GAAG;IACJ,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,SAAS,CAAA,GAAA,gBAAQ;IAErB,IAAI,YAAY,CAAC;YAQV;QAPL,6GAA6G;QAC7G,IAAI,EA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AAO;QAGzB,eAAe,OAAO,GAAG,QAAQ,UAAU;QAC3C,gBAAgB,OAAO,GAAG;IAC5B;IAEA,sFAAsF;IACtF,CAAA,GAAA,eAAO,EAAE,KAAK,kCAAkC,CAAA;QAC9C,EAAE,cAAc;QAChB,QAAQ,UAAU,CAAC;IACrB;IAEA,IAAI,WAAW;mBACb;iBACA;gBACA;QACA,aAAY,CAAC;YACX,8CAA8C;YAC9C,IAAI,UAAU,OAAO,KAAK,EAAE,MAAM,EAChC,wEAAwE;YACxE,EAAE,cAAc;QAEpB;IACF;IAEA,IAAI,mBAAC,eAAe,EAAC,GAAG,CAAA,GAAA,yCAAY,EAAE;QACpC,kBAAkB;QAClB,kBAAkB;IACpB;IAEA,IAAI,CAAC,mBACH,WAAW,CAAA,GAAA,iBAAS,EAAE,iBAAiB;IAGzC,oFAAoF;IACpF,+FAA+F;IAC/F,IAAI,WAA+B;IACnC,IAAI,CAAC,uBACH,WAAW,QAAQ,UAAU,IAAI,OAAO,IAAI;IAG9C,IAAI,eAAe,CAAA,GAAA,yCAAc,EAAE,QAAQ,UAAU;IACrD,OAAO;QACL,iBAAiB,CAAA,GAAA,iBAAS,EAAE,UAAU;sBACpC;YACA,mBAAmB;QACrB;IACF;AACF","sources":["packages/@react-aria/selection/src/useSelectableCollection.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 {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, isCtrlKeyPressed, mergeProps, scrollIntoView, scrollIntoViewport, useEffectEvent, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate, RefObject} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, KeyboardEvent, useEffect, useRef} from 'react';\nimport {focusSafely, getInteractionModality} from '@react-aria/interactions';\nimport {getFocusableTreeWalker, moveVirtualFocus} from '@react-aria/focus';\nimport {getItemElement, isNonContiguousSelectionModifier, useCollectionId} from './utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useLocale} from '@react-aria/i18n';\nimport {useTypeSelect} from './useTypeSelect';\n\nexport interface AriaSelectableCollectionOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * The ref attached to the element representing the collection.\n */\n ref: RefObject<HTMLElement | null>,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n * @default false\n */\n disallowSelectAll?: boolean,\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean,\n /**\n * Whether the collection items are contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.\n * If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement | null>,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override'\n}\n\nexport interface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: DOMAttributes\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(options: AriaSelectableCollectionOptions): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n selectOnFocus = manager.selectionBehavior === 'replace',\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n isVirtualized,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref,\n linkBehavior = 'action'\n } = options;\n let {direction} = useLocale();\n let router = useRouter();\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes\n if (e.altKey && e.key === 'Tab') {\n e.preventDefault();\n }\n\n // Keyboard events bubble through portals. Don't handle keyboard events\n // for elements outside the collection (e.g. menus).\n if (!ref.current?.contains(e.target as Element)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n // Set focused key and re-render synchronously to bring item into view if needed.\n flushSync(() => {\n manager.setFocusedKey(key, childFocus);\n });\n\n let item = getItemElement(ref, key);\n let itemProps = manager.getItemProps(key);\n if (item) {\n router.open(item, e, itemProps.href, itemProps.routerOptions);\n }\n\n return;\n }\n\n manager.setFocusedKey(key, childFocus);\n\n if (manager.isLink(key) && linkBehavior === 'override') {\n return;\n }\n\n if (e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(key);\n } else if (selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n manager.replaceSelection(key);\n }\n }\n };\n\n switch (e.key) {\n case 'ArrowDown': {\n if (delegate.getKeyBelow) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyBelow?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyAbove?.(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n let nextKey: Key | undefined | null = manager.focusedKey != null ? delegate.getKeyLeftOf?.(manager.focusedKey) : null;\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getFirstKey?.(manager.focusedKey) : delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n let nextKey: Key | undefined | null = manager.focusedKey != null ? delegate.getKeyRightOf?.(manager.focusedKey) : null;\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getLastKey?.(manager.focusedKey) : delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n e.preventDefault();\n let firstKey: Key | null = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (firstKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (lastKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'a':\n if (isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {\n e.stopPropagation();\n e.preventDefault();\n manager.clearSelection();\n }\n break;\n case 'Tab': {\n if (!allowsTabNavigation) {\n // There may be elements that are \"tabbable\" inside a collection (e.g. in a grid cell).\n // However, collections should be treated as a single tab stop, with arrow key navigation internally.\n // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.\n // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element\n // in the collection, so that the browser default behavior will apply starting from that element\n // rather than the currently focused one.\n if (e.shiftKey) {\n ref.current.focus();\n } else {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n let next: FocusableElement | undefined = undefined;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n\n if (next && !next.contains(document.activeElement)) {\n focusWithoutScrolling(next);\n }\n }\n break;\n }\n }\n }\n };\n\n // Store the scroll position so we can restore it later.\n /// TODO: should this happen all the time??\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', isVirtualized ? undefined : () => {\n scrollPos.current = {\n top: scrollRef.current?.scrollTop ?? 0,\n left: scrollRef.current?.scrollLeft ?? 0\n };\n });\n\n let onFocus = (e: FocusEvent) => {\n if (manager.isFocused) {\n // If a focus event bubbled through a portal, reset focus state.\n if (!e.currentTarget.contains(e.target)) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n manager.setFocused(true);\n if (manager.focusedKey == null) {\n let navigateToKey = (key: Key | undefined | null) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus && !manager.isSelected(key)) {\n manager.replaceSelection(key);\n }\n }\n };\n // If the user hasn't yet interacted with the collection, there will be no focusedKey set.\n // Attempt to detect whether the user is tabbing forward or backward into the collection\n // and either focus the first or last item accordingly.\n let relatedTarget = e.relatedTarget as Element;\n if (relatedTarget && (e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING)) {\n navigateToKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n } else {\n navigateToKey(manager.firstSelectedKey ?? delegate.getFirstKey?.());\n }\n } else if (!isVirtualized && scrollRef.current) {\n // Restore the scroll position to what it was before.\n scrollRef.current.scrollTop = scrollPos.current.top;\n scrollRef.current.scrollLeft = scrollPos.current.left;\n }\n\n if (manager.focusedKey != null && scrollRef.current) {\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = getItemElement(ref, manager.focusedKey);\n if (element instanceof HTMLElement) {\n // This prevents a flash of focus on the first/last element in the collection, or the collection itself.\n if (!element.contains(document.activeElement) && !shouldUseVirtualFocus) {\n focusWithoutScrolling(element);\n }\n\n let modality = getInteractionModality();\n if (modality === 'keyboard') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n };\n\n let onBlur = (e) => {\n // Don't set blurred and then focused again if moving focus within the collection.\n if (!e.currentTarget.contains(e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n // Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types\n // to focus the first key AFTER the collection updates.\n // TODO: potentially expand the usage of this\n let shouldVirtualFocusFirst = useRef(false);\n // Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events\n // at the autocomplete level\n // TODO: fix type later\n useEvent(ref, FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n let {detail} = e;\n e.stopPropagation();\n manager.setFocused(true);\n\n // If the user is typing forwards, autofocus the first option in the list.\n if (detail?.focusStrategy === 'first') {\n shouldVirtualFocusFirst.current = true;\n }\n });\n\n let updateActiveDescendant = useEffectEvent(() => {\n let keyToFocus = delegate.getFirstKey?.() ?? null;\n\n // If no focusable items exist in the list, make sure to clear any activedescendant that may still exist\n if (keyToFocus == null) {\n moveVirtualFocus(ref.current);\n\n // If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.\n // Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n } else {\n manager.setFocusedKey(keyToFocus);\n // Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key\n // If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key\n // after the collection updates after load\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n if (shouldVirtualFocusFirst.current) {\n updateActiveDescendant();\n }\n\n }, [manager.collection, updateActiveDescendant]);\n\n let resetFocusFirstFlag = useEffectEvent(() => {\n // If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't\n // accidentally move focus from under them. Skip this if the collection was empty because we might be in a load\n // state and will still want to focus the first item after load\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n resetFocusFirstFlag();\n }, [manager.focusedKey, resetFocusFirstFlag]);\n\n useEvent(ref, CLEAR_FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n e.stopPropagation();\n manager.setFocused(false);\n if (e.detail?.clearFocusKey) {\n manager.setFocusedKey(null);\n }\n });\n\n const autoFocusRef = useRef(autoFocus);\n const didAutoFocusRef = useRef(false);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey: Key | null = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey?.() ?? null;\n } if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey?.() ?? null;\n }\n\n // If there are any selected keys, make the first one the new focus target\n let selectedKeys = manager.selectedKeys;\n if (selectedKeys.size) {\n for (let key of selectedKeys) {\n if (manager.canSelectItem(key)) {\n focusedKey = key;\n break;\n }\n }\n }\n\n manager.setFocused(true);\n manager.setFocusedKey(focusedKey);\n\n // If no default focus key is selected, focus the collection itself.\n if (focusedKey == null && !shouldUseVirtualFocus && ref.current) {\n focusSafely(ref.current);\n }\n\n // Wait until the collection has items to autofocus.\n if (manager.collection.size > 0) {\n autoFocusRef.current = false;\n didAutoFocusRef.current = true;\n }\n }\n });\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n useEffect(() => {\n if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || didAutoFocusRef.current) && scrollRef.current && ref.current) {\n let modality = getInteractionModality();\n let element = getItemElement(ref, manager.focusedKey);\n if (!(element instanceof HTMLElement)) {\n // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).\n // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.\n return;\n }\n\n if (modality === 'keyboard' || didAutoFocusRef.current) {\n scrollIntoView(scrollRef.current, element);\n\n // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)\n if (modality !== 'virtual') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n\n // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.\n if (!shouldUseVirtualFocus && manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null && ref.current) {\n focusSafely(ref.current);\n }\n\n lastFocusedKey.current = manager.focusedKey;\n didAutoFocusRef.current = false;\n });\n\n // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.\n useEvent(ref, 'react-aria-focus-scope-restore', e => {\n e.preventDefault();\n manager.setFocused(true);\n });\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (scrollRef.current === e.target) {\n // Prevent focus going to the collection when clicking on the scrollbar.\n e.preventDefault();\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: manager\n });\n\n if (!disallowTypeAhead) {\n handlers = mergeProps(typeSelectProps, handlers);\n }\n\n // If nothing is focused within the collection, make the collection itself tabbable.\n // This will be marshalled to either the first or last item depending on where focus came from.\n let tabIndex: number | undefined = undefined;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n let collectionId = useCollectionId(manager.collection);\n return {\n collectionProps: mergeProps(handlers, {\n tabIndex,\n 'data-collection': collectionId\n })\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.module.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AAgGM,SAAS,0CAAwB,OAAwC;IAC9E,IAAI,EACF,kBAAkB,OAAO,EACzB,kBAAkB,QAAQ,OAC1B,GAAG,aACH,YAAY,wBACZ,kBAAkB,+BAClB,yBAAyB,0BACz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,OAAO,EAAE;gBACtD,CAAA,GAAA,qBAAa,EAAE,UAAU,OAAO,EAAE;gBAElC,iFAAiF;gBACjF,IAAI,aAAa,WACf,CAAA,GAAA,yBAAiB,EAAE,SAAS;oBAAC,mBAAmB,IAAI,OAAO;gBAAA;YAE/D;QACF;QAEA,+FAA+F;QAC/F,IAAI,CAAC,yBAAyB,QAAQ,SAAS,IAAI,QAAQ,UAAU,IAAI,QAAQ,eAAe,OAAO,IAAI,QAAQ,IAAI,OAAO,EAC5H,CAAA,GAAA,kBAAU,EAAE,IAAI,OAAO;QAGzB,eAAe,OAAO,GAAG,QAAQ,UAAU;QAC3C,gBAAgB,OAAO,GAAG;IAC5B;IAEA,sFAAsF;IACtF,CAAA,GAAA,eAAO,EAAE,KAAK,kCAAkC,CAAA;QAC9C,EAAE,cAAc;QAChB,QAAQ,UAAU,CAAC;IACrB;IAEA,IAAI,WAAW;mBACb;iBACA;gBACA;QACA,aAAY,CAAC;YACX,8CAA8C;YAC9C,IAAI,UAAU,OAAO,KAAK,EAAE,MAAM,EAChC,wEAAwE;YACxE,EAAE,cAAc;QAEpB;IACF;IAEA,IAAI,mBAAC,eAAe,EAAC,GAAG,CAAA,GAAA,yCAAY,EAAE;QACpC,kBAAkB;QAClB,kBAAkB;IACpB;IAEA,IAAI,CAAC,mBACH,WAAW,CAAA,GAAA,iBAAS,EAAE,iBAAiB;IAGzC,oFAAoF;IACpF,+FAA+F;IAC/F,IAAI,WAA+B;IACnC,IAAI,CAAC,uBACH,WAAW,QAAQ,UAAU,IAAI,OAAO,IAAI;IAG9C,IAAI,eAAe,CAAA,GAAA,yCAAc,EAAE,QAAQ,UAAU;IACrD,OAAO;QACL,iBAAiB,CAAA,GAAA,iBAAS,EAAE,UAAU;sBACpC;YACA,mBAAmB;QACrB;IACF;AACF","sources":["packages/@react-aria/selection/src/useSelectableCollection.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 {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, isCtrlKeyPressed, mergeProps, scrollIntoView, scrollIntoViewport, useEffectEvent, useEvent, useRouter, useUpdateLayoutEffect} from '@react-aria/utils';\nimport {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate, RefObject} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, KeyboardEvent, useEffect, useRef} from 'react';\nimport {focusSafely, getInteractionModality} from '@react-aria/interactions';\nimport {getFocusableTreeWalker, moveVirtualFocus} from '@react-aria/focus';\nimport {getItemElement, isNonContiguousSelectionModifier, useCollectionId} from './utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useLocale} from '@react-aria/i18n';\nimport {useTypeSelect} from './useTypeSelect';\n\nexport interface AriaSelectableCollectionOptions {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A delegate object that implements behavior for keyboard focus movement.\n */\n keyboardDelegate: KeyboardDelegate,\n /**\n * The ref attached to the element representing the collection.\n */\n ref: RefObject<HTMLElement | null>,\n /**\n * Whether the collection or one of its items should be automatically focused upon render.\n * @default false\n */\n autoFocus?: boolean | FocusStrategy,\n /**\n * Whether focus should wrap around when the end/start is reached.\n * @default false\n */\n shouldFocusWrap?: boolean,\n /**\n * Whether the collection allows empty selection.\n * @default false\n */\n disallowEmptySelection?: boolean,\n /**\n * Whether the collection allows the user to select all items via keyboard shortcut.\n * @default false\n */\n disallowSelectAll?: boolean,\n /**\n * Whether pressing the Escape should clear selection in the collection or not.\n * @default 'clearSelection'\n */\n escapeKeyBehavior?: 'clearSelection' | 'none',\n /**\n * Whether selection should occur automatically on focus.\n * @default false\n */\n selectOnFocus?: boolean,\n /**\n * Whether typeahead is disabled.\n * @default false\n */\n disallowTypeAhead?: boolean,\n /**\n * Whether the collection items should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /**\n * Whether navigation through tab key is enabled.\n */\n allowsTabNavigation?: boolean,\n /**\n * Whether the collection items are contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for non-virtualized collections.\n * If not provided, defaults to the collection ref.\n */\n scrollRef?: RefObject<HTMLElement | null>,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override'\n}\n\nexport interface SelectableCollectionAria {\n /** Props for the collection element. */\n collectionProps: DOMAttributes\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(options: AriaSelectableCollectionOptions): SelectableCollectionAria {\n let {\n selectionManager: manager,\n keyboardDelegate: delegate,\n ref,\n autoFocus = false,\n shouldFocusWrap = false,\n disallowEmptySelection = false,\n disallowSelectAll = false,\n escapeKeyBehavior = 'clearSelection',\n selectOnFocus = manager.selectionBehavior === 'replace',\n disallowTypeAhead = false,\n shouldUseVirtualFocus,\n allowsTabNavigation = false,\n isVirtualized,\n // If no scrollRef is provided, assume the collection ref is the scrollable region\n scrollRef = ref,\n linkBehavior = 'action'\n } = options;\n let {direction} = useLocale();\n let router = useRouter();\n\n let onKeyDown = (e: KeyboardEvent) => {\n // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes\n if (e.altKey && e.key === 'Tab') {\n e.preventDefault();\n }\n\n // Keyboard events bubble through portals. Don't handle keyboard events\n // for elements outside the collection (e.g. menus).\n if (!ref.current?.contains(e.target as Element)) {\n return;\n }\n\n const navigateToKey = (key: Key | undefined, childFocus?: FocusStrategy) => {\n if (key != null) {\n if (manager.isLink(key) && linkBehavior === 'selection' && selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n // Set focused key and re-render synchronously to bring item into view if needed.\n flushSync(() => {\n manager.setFocusedKey(key, childFocus);\n });\n\n let item = getItemElement(ref, key);\n let itemProps = manager.getItemProps(key);\n if (item) {\n router.open(item, e, itemProps.href, itemProps.routerOptions);\n }\n\n return;\n }\n\n manager.setFocusedKey(key, childFocus);\n\n if (manager.isLink(key) && linkBehavior === 'override') {\n return;\n }\n\n if (e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(key);\n } else if (selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n manager.replaceSelection(key);\n }\n }\n };\n\n switch (e.key) {\n case 'ArrowDown': {\n if (delegate.getKeyBelow) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyBelow?.(manager.focusedKey)\n : delegate.getFirstKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowUp': {\n if (delegate.getKeyAbove) {\n let nextKey = manager.focusedKey != null\n ? delegate.getKeyAbove?.(manager.focusedKey)\n : delegate.getLastKey?.();\n if (nextKey == null && shouldFocusWrap) {\n nextKey = delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n }\n case 'ArrowLeft': {\n if (delegate.getKeyLeftOf) {\n let nextKey: Key | undefined | null = manager.focusedKey != null ? delegate.getKeyLeftOf?.(manager.focusedKey) : null;\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getFirstKey?.(manager.focusedKey) : delegate.getLastKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');\n }\n }\n break;\n }\n case 'ArrowRight': {\n if (delegate.getKeyRightOf) {\n let nextKey: Key | undefined | null = manager.focusedKey != null ? delegate.getKeyRightOf?.(manager.focusedKey) : null;\n if (nextKey == null && shouldFocusWrap) {\n nextKey = direction === 'rtl' ? delegate.getLastKey?.(manager.focusedKey) : delegate.getFirstKey?.(manager.focusedKey);\n }\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');\n }\n }\n break;\n }\n case 'Home':\n if (delegate.getFirstKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n e.preventDefault();\n let firstKey: Key | null = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(firstKey);\n if (firstKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(firstKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(firstKey);\n }\n }\n }\n break;\n case 'End':\n if (delegate.getLastKey) {\n if (manager.focusedKey === null && e.shiftKey) {\n return;\n }\n e.preventDefault();\n let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n manager.setFocusedKey(lastKey);\n if (lastKey != null) {\n if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n manager.extendSelection(lastKey);\n } else if (selectOnFocus) {\n manager.replaceSelection(lastKey);\n }\n }\n }\n break;\n case 'PageDown':\n if (delegate.getKeyPageBelow && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'PageUp':\n if (delegate.getKeyPageAbove && manager.focusedKey != null) {\n let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n if (nextKey != null) {\n e.preventDefault();\n navigateToKey(nextKey);\n }\n }\n break;\n case 'a':\n if (isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n e.preventDefault();\n manager.selectAll();\n }\n break;\n case 'Escape':\n if (escapeKeyBehavior === 'clearSelection' && !disallowEmptySelection && manager.selectedKeys.size !== 0) {\n e.stopPropagation();\n e.preventDefault();\n manager.clearSelection();\n }\n break;\n case 'Tab': {\n if (!allowsTabNavigation) {\n // There may be elements that are \"tabbable\" inside a collection (e.g. in a grid cell).\n // However, collections should be treated as a single tab stop, with arrow key navigation internally.\n // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.\n // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element\n // in the collection, so that the browser default behavior will apply starting from that element\n // rather than the currently focused one.\n if (e.shiftKey) {\n ref.current.focus();\n } else {\n let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n let next: FocusableElement | undefined = undefined;\n let last: FocusableElement;\n do {\n last = walker.lastChild() as FocusableElement;\n if (last) {\n next = last;\n }\n } while (last);\n\n if (next && !next.contains(document.activeElement)) {\n focusWithoutScrolling(next);\n }\n }\n break;\n }\n }\n }\n };\n\n // Store the scroll position so we can restore it later.\n /// TODO: should this happen all the time??\n let scrollPos = useRef({top: 0, left: 0});\n useEvent(scrollRef, 'scroll', isVirtualized ? undefined : () => {\n scrollPos.current = {\n top: scrollRef.current?.scrollTop ?? 0,\n left: scrollRef.current?.scrollLeft ?? 0\n };\n });\n\n let onFocus = (e: FocusEvent) => {\n if (manager.isFocused) {\n // If a focus event bubbled through a portal, reset focus state.\n if (!e.currentTarget.contains(e.target)) {\n manager.setFocused(false);\n }\n\n return;\n }\n\n // Focus events can bubble through portals. Ignore these events.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n manager.setFocused(true);\n if (manager.focusedKey == null) {\n let navigateToKey = (key: Key | undefined | null) => {\n if (key != null) {\n manager.setFocusedKey(key);\n if (selectOnFocus && !manager.isSelected(key)) {\n manager.replaceSelection(key);\n }\n }\n };\n // If the user hasn't yet interacted with the collection, there will be no focusedKey set.\n // Attempt to detect whether the user is tabbing forward or backward into the collection\n // and either focus the first or last item accordingly.\n let relatedTarget = e.relatedTarget as Element;\n if (relatedTarget && (e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING)) {\n navigateToKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n } else {\n navigateToKey(manager.firstSelectedKey ?? delegate.getFirstKey?.());\n }\n } else if (!isVirtualized && scrollRef.current) {\n // Restore the scroll position to what it was before.\n scrollRef.current.scrollTop = scrollPos.current.top;\n scrollRef.current.scrollLeft = scrollPos.current.left;\n }\n\n if (manager.focusedKey != null && scrollRef.current) {\n // Refocus and scroll the focused item into view if it exists within the scrollable region.\n let element = getItemElement(ref, manager.focusedKey);\n if (element instanceof HTMLElement) {\n // This prevents a flash of focus on the first/last element in the collection, or the collection itself.\n if (!element.contains(document.activeElement) && !shouldUseVirtualFocus) {\n focusWithoutScrolling(element);\n }\n\n let modality = getInteractionModality();\n if (modality === 'keyboard') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n };\n\n let onBlur = (e) => {\n // Don't set blurred and then focused again if moving focus within the collection.\n if (!e.currentTarget.contains(e.relatedTarget as HTMLElement)) {\n manager.setFocused(false);\n }\n };\n\n // Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types\n // to focus the first key AFTER the collection updates.\n // TODO: potentially expand the usage of this\n let shouldVirtualFocusFirst = useRef(false);\n // Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events\n // at the autocomplete level\n // TODO: fix type later\n useEvent(ref, FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n let {detail} = e;\n e.stopPropagation();\n manager.setFocused(true);\n\n // If the user is typing forwards, autofocus the first option in the list.\n if (detail?.focusStrategy === 'first') {\n shouldVirtualFocusFirst.current = true;\n }\n });\n\n let updateActiveDescendant = useEffectEvent(() => {\n let keyToFocus = delegate.getFirstKey?.() ?? null;\n\n // If no focusable items exist in the list, make sure to clear any activedescendant that may still exist\n if (keyToFocus == null) {\n moveVirtualFocus(ref.current);\n\n // If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.\n // Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n } else {\n manager.setFocusedKey(keyToFocus);\n // Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key\n // If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key\n // after the collection updates after load\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n if (shouldVirtualFocusFirst.current) {\n updateActiveDescendant();\n }\n\n }, [manager.collection, updateActiveDescendant]);\n\n let resetFocusFirstFlag = useEffectEvent(() => {\n // If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't\n // accidentally move focus from under them. Skip this if the collection was empty because we might be in a load\n // state and will still want to focus the first item after load\n if (manager.collection.size > 0) {\n shouldVirtualFocusFirst.current = false;\n }\n });\n\n useUpdateLayoutEffect(() => {\n resetFocusFirstFlag();\n }, [manager.focusedKey, resetFocusFirstFlag]);\n\n useEvent(ref, CLEAR_FOCUS_EVENT, !shouldUseVirtualFocus ? undefined : (e: any) => {\n e.stopPropagation();\n manager.setFocused(false);\n if (e.detail?.clearFocusKey) {\n manager.setFocusedKey(null);\n }\n });\n\n const autoFocusRef = useRef(autoFocus);\n const didAutoFocusRef = useRef(false);\n useEffect(() => {\n if (autoFocusRef.current) {\n let focusedKey: Key | null = null;\n\n // Check focus strategy to determine which item to focus\n if (autoFocus === 'first') {\n focusedKey = delegate.getFirstKey?.() ?? null;\n } if (autoFocus === 'last') {\n focusedKey = delegate.getLastKey?.() ?? null;\n }\n\n // If there are any selected keys, make the first one the new focus target\n let selectedKeys = manager.selectedKeys;\n if (selectedKeys.size) {\n for (let key of selectedKeys) {\n if (manager.canSelectItem(key)) {\n focusedKey = key;\n break;\n }\n }\n }\n\n manager.setFocused(true);\n manager.setFocusedKey(focusedKey);\n\n // If no default focus key is selected, focus the collection itself.\n if (focusedKey == null && !shouldUseVirtualFocus && ref.current) {\n focusSafely(ref.current);\n }\n\n // Wait until the collection has items to autofocus.\n if (manager.collection.size > 0) {\n autoFocusRef.current = false;\n didAutoFocusRef.current = true;\n }\n }\n });\n\n // Scroll the focused element into view when the focusedKey changes.\n let lastFocusedKey = useRef(manager.focusedKey);\n useEffect(() => {\n if (manager.isFocused && manager.focusedKey != null && (manager.focusedKey !== lastFocusedKey.current || didAutoFocusRef.current) && scrollRef.current && ref.current) {\n let modality = getInteractionModality();\n let element = getItemElement(ref, manager.focusedKey);\n if (!(element instanceof HTMLElement)) {\n // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).\n // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.\n return;\n }\n\n if (modality === 'keyboard' || didAutoFocusRef.current) {\n scrollIntoView(scrollRef.current, element);\n\n // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)\n if (modality !== 'virtual') {\n scrollIntoViewport(element, {containingElement: ref.current});\n }\n }\n }\n\n // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.\n if (!shouldUseVirtualFocus && manager.isFocused && manager.focusedKey == null && lastFocusedKey.current != null && ref.current) {\n focusSafely(ref.current);\n }\n\n lastFocusedKey.current = manager.focusedKey;\n didAutoFocusRef.current = false;\n });\n\n // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.\n useEvent(ref, 'react-aria-focus-scope-restore', e => {\n e.preventDefault();\n manager.setFocused(true);\n });\n\n let handlers = {\n onKeyDown,\n onFocus,\n onBlur,\n onMouseDown(e) {\n // Ignore events that bubbled through portals.\n if (scrollRef.current === e.target) {\n // Prevent focus going to the collection when clicking on the scrollbar.\n e.preventDefault();\n }\n }\n };\n\n let {typeSelectProps} = useTypeSelect({\n keyboardDelegate: delegate,\n selectionManager: manager\n });\n\n if (!disallowTypeAhead) {\n handlers = mergeProps(typeSelectProps, handlers);\n }\n\n // If nothing is focused within the collection, make the collection itself tabbable.\n // This will be marshalled to either the first or last item depending on where focus came from.\n let tabIndex: number | undefined = undefined;\n if (!shouldUseVirtualFocus) {\n tabIndex = manager.focusedKey == null ? 0 : -1;\n }\n\n let collectionId = useCollectionId(manager.collection);\n return {\n collectionProps: mergeProps(handlers, {\n tabIndex,\n 'data-collection': collectionId\n })\n };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.module.js.map"}
@@ -116,7 +116,9 @@ function $433b1145b0781e10$export$ecf600387e221c37(options) {
116
116
  // we want to be able to have the pointer down on the trigger that opens the menu and
117
117
  // the pointer up on the menu item rather than requiring a separate press.
118
118
  // For keyboard events, selection still occurs on key down.
119
- let itemPressProps = {};
119
+ let itemPressProps = {
120
+ ref: ref
121
+ };
120
122
  if (shouldSelectOnPressUp) {
121
123
  itemPressProps.onPressStart = (e)=>{
122
124
  modality.current = e.pointerType;
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAkGM,SAAS,0CAAkB,OAA8B;IAC9D,IAAI,MACF,EAAE,EACF,kBAAkB,OAAO,OACzB,GAAG,OACH,GAAG,yBACH,qBAAqB,yBACrB,qBAAqB,SACrB,KAAK,cACL,UAAU,YACV,QAAQ,8BACR,0BAA0B,gBAC1B,eAAe,UAChB,GAAG;IACJ,IAAI,SAAS,CAAA,GAAA,+BAAQ;IACrB,KAAK,CAAA,GAAA,2BAAI,EAAE;IACX,IAAI,WAAW,CAAC;QACd,IAAI,EAAE,WAAW,KAAK,cAAc,CAAA,GAAA,0DAA+B,EAAE,IACnE,QAAQ,eAAe,CAAC;aACnB;YACL,IAAI,QAAQ,aAAa,KAAK,QAC5B;YAGF,IAAI,QAAQ,MAAM,CAAC,MAAM;gBACvB,IAAI,iBAAiB,eAAe,IAAI,OAAO,EAAE;oBAC/C,IAAI,YAAY,QAAQ,YAAY,CAAC;oBACrC,OAAO,IAAI,CAAC,IAAI,OAAO,EAAE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C,CAAA,GAAA,8BAAO,EAAU,SAAS,EAC9B,EAAE,cAAc;IAEpB,IAAI;IAEJ,OAAO;QACL,WAAW,CAAA,GAAA,gCAAS,EAClB,WACA,mBAAmB,oBAAoB,wBAAwB,aAAa,CAAC,GAC7E,mBAAmB,iBAAiB,CAAC,GACrC;2BAAC;gCAAe;qBAAoB;gBAAS;QAAE,GAC/C,uEAAuE;QACvE,wBAAwB;YAAC,aAAa,CAAA,IAAK,EAAE,cAAc;QAAE,IAAI;mBAEnE;QACA,YAAY,QAAQ,UAAU,CAAC;QAC/B,WAAW,QAAQ,SAAS,IAAI,QAAQ,UAAU,KAAK;oBACvD;yBACA;mBACA;IACF;AACF;AAEA,SAAS;IACP,IAAI,QAAQ,OAAO,KAAK;IACxB,OAAO,CAAA,kBAAA,4BAAA,MAAO,GAAG,MAAK;AACxB;AAEA,SAAS;IACP,IAAI,QAAQ,OAAO,KAAK;IACxB,OAAO,CAAA,kBAAA,4BAAA,MAAO,GAAG,MAAK,OAAO,CAAA,kBAAA,4BAAA,MAAO,IAAI,MAAK;AAC/C","sources":["packages/@react-aria/selection/src/useSelectableItem.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 {DOMAttributes, DOMProps, FocusableElement, Key, LongPressEvent, PointerType, PressEvent, RefObject} from '@react-types/shared';\nimport {focusSafely, PressProps, useLongPress, usePress} from '@react-aria/interactions';\nimport {getCollectionId, isNonContiguousSelectionModifier} from './utils';\nimport {isCtrlKeyPressed, mergeProps, openLink, useId, useRouter} from '@react-aria/utils';\nimport {moveVirtualFocus} from '@react-aria/focus';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useEffect, useRef} from 'react';\n\nexport interface SelectableItemOptions extends DOMProps {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A unique key for the item.\n */\n key: Key,\n /**\n * Ref to the item.\n */\n ref: RefObject<FocusableElement | null>,\n /**\n * By default, selection occurs on pointer down. This can be strange if selecting an\n * item causes the UI to disappear immediately (e.g. menus).\n */\n shouldSelectOnPressUp?: boolean,\n /**\n * Whether selection requires the pointer/mouse down and up events to occur on the same target or triggers selection on\n * the target of the pointer/mouse up event.\n */\n allowsDifferentPressOrigin?: boolean,\n /**\n * Whether the option is contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * Function to focus the item.\n */\n focus?: () => void,\n /**\n * Whether the option should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /** Whether the item is disabled. */\n isDisabled?: boolean,\n /**\n * Handler that is called when a user performs an action on the item. The exact user event depends on\n * the collection's `selectionBehavior` prop and the interaction modality.\n */\n onAction?: () => void,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * - 'none': links are disabled for both selection and actions (e.g. handled elsewhere).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override' | 'none'\n}\n\nexport interface SelectableItemStates {\n /** Whether the item is currently in a pressed state. */\n isPressed: boolean,\n /** Whether the item is currently selected. */\n isSelected: boolean,\n /** Whether the item is currently focused. */\n isFocused: boolean,\n /**\n * Whether the item is non-interactive, i.e. both selection and actions are disabled and the item may\n * not be focused. Dependent on `disabledKeys` and `disabledBehavior`.\n */\n isDisabled: boolean,\n /**\n * Whether the item may be selected, dependent on `selectionMode`, `disabledKeys`, and `disabledBehavior`.\n */\n allowsSelection: boolean,\n /**\n * Whether the item has an action, dependent on `onAction`, `disabledKeys`,\n * and `disabledBehavior`. It may also change depending on the current selection state\n * of the list (e.g. when selection is primary). This can be used to enable or disable hover\n * styles or other visual indications of interactivity.\n */\n hasAction: boolean\n}\n\nexport interface SelectableItemAria extends SelectableItemStates {\n /**\n * Props to be spread on the item root node.\n */\n itemProps: DOMAttributes\n}\n\n/**\n * Handles interactions with an item in a selectable collection.\n */\nexport function useSelectableItem(options: SelectableItemOptions): SelectableItemAria {\n let {\n id,\n selectionManager: manager,\n key,\n ref,\n shouldSelectOnPressUp,\n shouldUseVirtualFocus,\n focus,\n isDisabled,\n onAction,\n allowsDifferentPressOrigin,\n linkBehavior = 'action'\n } = options;\n let router = useRouter();\n id = useId(id);\n let onSelect = (e: PressEvent | LongPressEvent | PointerEvent) => {\n if (e.pointerType === 'keyboard' && isNonContiguousSelectionModifier(e)) {\n manager.toggleSelection(key);\n } else {\n if (manager.selectionMode === 'none') {\n return;\n }\n\n if (manager.isLink(key)) {\n if (linkBehavior === 'selection' && ref.current) {\n let itemProps = manager.getItemProps(key);\n router.open(ref.current, e, itemProps.href, itemProps.routerOptions);\n // Always set selected keys back to what they were so that select and combobox close.\n manager.setSelectedKeys(manager.selectedKeys);\n return;\n } else if (linkBehavior === 'override' || linkBehavior === 'none') {\n return;\n }\n }\n\n if (manager.selectionMode === 'single') {\n if (manager.isSelected(key) && !manager.disallowEmptySelection) {\n manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n } else if (e && e.shiftKey) {\n manager.extendSelection(key);\n } else if (manager.selectionBehavior === 'toggle' || (e && (isCtrlKeyPressed(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 manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n }\n };\n\n // Focus the associated DOM node when this item becomes the focusedKey\n // TODO: can't make this useLayoutEffect bacause it breaks menus inside dialogs\n // However, if this is a useEffect, it runs twice and dispatches two blur events and immediately sets\n // aria-activeDescendant in useAutocomplete... I've worked around this for now\n useEffect(() => {\n let isFocused = key === manager.focusedKey;\n if (isFocused && manager.isFocused) {\n if (!shouldUseVirtualFocus) {\n if (focus) {\n focus();\n } else if (document.activeElement !== ref.current && ref.current) {\n focusSafely(ref.current);\n }\n } else {\n moveVirtualFocus(ref.current);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [ref, key, manager.focusedKey, manager.childFocusStrategy, manager.isFocused, shouldUseVirtualFocus]);\n\n isDisabled = isDisabled || manager.isDisabled(key);\n // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused\n // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver\n // on iOS 14 doesn't try to move real DOM focus to the item anyway.\n let itemProps: SelectableItemAria['itemProps'] = {};\n if (!shouldUseVirtualFocus && !isDisabled) {\n itemProps = {\n tabIndex: key === manager.focusedKey ? 0 : -1,\n onFocus(e) {\n if (e.target === ref.current) {\n manager.setFocusedKey(key);\n }\n }\n };\n } else if (isDisabled) {\n itemProps.onMouseDown = (e) => {\n // Prevent focus going to the body when clicking on a disabled item.\n e.preventDefault();\n };\n }\n\n // With checkbox selection, onAction (i.e. navigation) becomes primary, and occurs on a single click of the row.\n // Clicking the checkbox enters selection mode, after which clicking anywhere on any row toggles selection for that row.\n // With highlight selection, onAction is secondary, and occurs on double click. Single click selects the row.\n // With touch, onAction occurs on single tap, and long press enters selection mode.\n let isLinkOverride = manager.isLink(key) && linkBehavior === 'override';\n let hasLinkAction = manager.isLink(key) && linkBehavior !== 'selection' && linkBehavior !== 'none';\n let allowsSelection = !isDisabled && manager.canSelectItem(key) && !isLinkOverride;\n let allowsActions = (onAction || hasLinkAction) && !isDisabled;\n let hasPrimaryAction = allowsActions && (\n manager.selectionBehavior === 'replace'\n ? !allowsSelection\n : !allowsSelection || manager.isEmpty\n );\n let hasSecondaryAction = allowsActions && allowsSelection && manager.selectionBehavior === 'replace';\n let hasAction = hasPrimaryAction || hasSecondaryAction;\n let modality = useRef<PointerType | null>(null);\n\n let longPressEnabled = hasAction && allowsSelection;\n let longPressEnabledOnPressStart = useRef(false);\n let hadPrimaryActionOnPressStart = useRef(false);\n\n let performAction = (e) => {\n if (onAction) {\n onAction();\n }\n\n if (hasLinkAction && ref.current) {\n let itemProps = manager.getItemProps(key);\n router.open(ref.current, e, itemProps.href, itemProps.routerOptions);\n }\n };\n\n // By default, selection occurs on pointer down. This can be strange if selecting an\n // item causes the UI to disappear immediately (e.g. menus).\n // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.\n // onPress requires a pointer down event on the same element as pointer up. For menus,\n // we want to be able to have the pointer down on the trigger that opens the menu and\n // the pointer up on the menu item rather than requiring a separate press.\n // For keyboard events, selection still occurs on key down.\n let itemPressProps: PressProps = {};\n if (shouldSelectOnPressUp) {\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n longPressEnabledOnPressStart.current = longPressEnabled;\n if (e.pointerType === 'keyboard' && (!hasAction || isSelectionKey())) {\n onSelect(e);\n }\n };\n\n // If allowsDifferentPressOrigin and interacting with mouse, make selection happen on pressUp (e.g. open menu on press down, selection on menu item happens on press up.)\n // Otherwise, have selection happen onPress (prevents listview row selection when clicking on interactable elements in the row)\n if (!allowsDifferentPressOrigin) {\n itemPressProps.onPress = (e) => {\n if (hasPrimaryAction || (hasSecondaryAction && e.pointerType !== 'mouse')) {\n if (e.pointerType === 'keyboard' && !isActionKey()) {\n return;\n }\n\n performAction(e);\n } else if (e.pointerType !== 'keyboard' && allowsSelection) {\n onSelect(e);\n }\n };\n } else {\n itemPressProps.onPressUp = hasPrimaryAction ? undefined : (e) => {\n if (e.pointerType === 'mouse' && allowsSelection) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = hasPrimaryAction ? performAction : (e) => {\n if (e.pointerType !== 'keyboard' && e.pointerType !== 'mouse' && allowsSelection) {\n onSelect(e);\n }\n };\n }\n } else {\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n longPressEnabledOnPressStart.current = longPressEnabled;\n hadPrimaryActionOnPressStart.current = hasPrimaryAction;\n\n // Select on mouse down unless there is a primary action which will occur on mouse up.\n // For keyboard, select on key down. If there is an action, the Space key selects on key down,\n // and the Enter key performs onAction on key up.\n if (\n allowsSelection && (\n (e.pointerType === 'mouse' && !hasPrimaryAction) ||\n (e.pointerType === 'keyboard' && (!allowsActions || isSelectionKey()))\n )\n ) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = (e) => {\n // Selection occurs on touch up. Primary actions always occur on pointer up.\n // Both primary and secondary actions occur on Enter key up. The only exception\n // is secondary actions, which occur on double click with a mouse.\n if (\n e.pointerType === 'touch' ||\n e.pointerType === 'pen' ||\n e.pointerType === 'virtual' ||\n (e.pointerType === 'keyboard' && hasAction && isActionKey()) ||\n (e.pointerType === 'mouse' && hadPrimaryActionOnPressStart.current)\n ) {\n if (hasAction) {\n performAction(e);\n } else if (allowsSelection) {\n onSelect(e);\n }\n }\n };\n }\n\n itemProps['data-collection'] = getCollectionId(manager.collection);\n itemProps['data-key'] = key;\n itemPressProps.preventFocusOnPress = shouldUseVirtualFocus;\n\n // When using virtual focus, make sure the focused key gets updated on press.\n if (shouldUseVirtualFocus) {\n itemPressProps = mergeProps(itemPressProps, {\n onPressStart(e) {\n if (e.pointerType !== 'touch') {\n manager.setFocused(true);\n manager.setFocusedKey(key);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch') {\n manager.setFocused(true);\n manager.setFocusedKey(key);\n }\n }\n });\n }\n\n let {pressProps, isPressed} = usePress(itemPressProps);\n\n // Double clicking with a mouse with selectionBehavior = 'replace' performs an action.\n let onDoubleClick = hasSecondaryAction ? (e) => {\n if (modality.current === 'mouse') {\n e.stopPropagation();\n e.preventDefault();\n performAction(e);\n }\n } : undefined;\n\n // Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior\n // to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to\n // selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.\n let {longPressProps} = useLongPress({\n isDisabled: !longPressEnabled,\n onLongPress(e) {\n if (e.pointerType === 'touch') {\n onSelect(e);\n manager.setSelectionBehavior('toggle');\n }\n }\n });\n\n // Prevent native drag and drop on long press if we also select on long press.\n // Once the user is in selection mode, they can long press again to drag.\n // Use a capturing listener to ensure this runs before useDrag, regardless of\n // the order the props get merged.\n let onDragStartCapture = e => {\n if (modality.current === 'touch' && longPressEnabledOnPressStart.current) {\n e.preventDefault();\n }\n };\n\n // Prevent default on link clicks so that we control exactly\n // when they open (to match selection behavior).\n let onClick = manager.isLink(key) ? e => {\n if (!(openLink as any).isOpening) {\n e.preventDefault();\n }\n } : undefined;\n\n return {\n itemProps: mergeProps(\n itemProps,\n allowsSelection || hasPrimaryAction || shouldUseVirtualFocus ? pressProps : {},\n longPressEnabled ? longPressProps : {},\n {onDoubleClick, onDragStartCapture, onClick, id},\n // Prevent DOM focus from moving on mouse down when using virtual focus\n shouldUseVirtualFocus ? {onMouseDown: e => e.preventDefault()} : undefined\n ),\n isPressed,\n isSelected: manager.isSelected(key),\n isFocused: manager.isFocused && manager.focusedKey === key,\n isDisabled,\n allowsSelection,\n hasAction\n };\n}\n\nfunction isActionKey() {\n let event = window.event as KeyboardEvent;\n return event?.key === 'Enter';\n}\n\nfunction isSelectionKey() {\n let event = window.event as KeyboardEvent;\n return event?.key === ' ' || event?.code === 'Space';\n}\n"],"names":[],"version":3,"file":"useSelectableItem.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAkGM,SAAS,0CAAkB,OAA8B;IAC9D,IAAI,MACF,EAAE,EACF,kBAAkB,OAAO,OACzB,GAAG,OACH,GAAG,yBACH,qBAAqB,yBACrB,qBAAqB,SACrB,KAAK,cACL,UAAU,YACV,QAAQ,8BACR,0BAA0B,gBAC1B,eAAe,UAChB,GAAG;IACJ,IAAI,SAAS,CAAA,GAAA,+BAAQ;IACrB,KAAK,CAAA,GAAA,2BAAI,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,SAAS;gBAC7B,SAAS;gBACT,QAAQ,oBAAoB,CAAC;YAC/B;QACF;IACF;IAEA,8EAA8E;IAC9E,yEAAyE;IACzE,6EAA6E;IAC7E,kCAAkC;IAClC,IAAI,qBAAqB,CAAA;QACvB,IAAI,SAAS,OAAO,KAAK,WAAW,6BAA6B,OAAO,EACtE,EAAE,cAAc;IAEpB;IAEA,4DAA4D;IAC5D,gDAAgD;IAChD,IAAI,UAAU,QAAQ,MAAM,CAAC,OAAO,CAAA;QAClC,IAAI,CAAC,AAAC,CAAA,GAAA,8BAAO,EAAU,SAAS,EAC9B,EAAE,cAAc;IAEpB,IAAI;IAEJ,OAAO;QACL,WAAW,CAAA,GAAA,gCAAS,EAClB,WACA,mBAAmB,oBAAoB,wBAAwB,aAAa,CAAC,GAC7E,mBAAmB,iBAAiB,CAAC,GACrC;2BAAC;gCAAe;qBAAoB;gBAAS;QAAE,GAC/C,uEAAuE;QACvE,wBAAwB;YAAC,aAAa,CAAA,IAAK,EAAE,cAAc;QAAE,IAAI;mBAEnE;QACA,YAAY,QAAQ,UAAU,CAAC;QAC/B,WAAW,QAAQ,SAAS,IAAI,QAAQ,UAAU,KAAK;oBACvD;yBACA;mBACA;IACF;AACF;AAEA,SAAS;IACP,IAAI,QAAQ,OAAO,KAAK;IACxB,OAAO,CAAA,kBAAA,4BAAA,MAAO,GAAG,MAAK;AACxB;AAEA,SAAS;IACP,IAAI,QAAQ,OAAO,KAAK;IACxB,OAAO,CAAA,kBAAA,4BAAA,MAAO,GAAG,MAAK,OAAO,CAAA,kBAAA,4BAAA,MAAO,IAAI,MAAK;AAC/C","sources":["packages/@react-aria/selection/src/useSelectableItem.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 {DOMAttributes, DOMProps, FocusableElement, Key, LongPressEvent, PointerType, PressEvent, RefObject} from '@react-types/shared';\nimport {focusSafely, PressHookProps, useLongPress, usePress} from '@react-aria/interactions';\nimport {getCollectionId, isNonContiguousSelectionModifier} from './utils';\nimport {isCtrlKeyPressed, mergeProps, openLink, useId, useRouter} from '@react-aria/utils';\nimport {moveVirtualFocus} from '@react-aria/focus';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useEffect, useRef} from 'react';\n\nexport interface SelectableItemOptions extends DOMProps {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A unique key for the item.\n */\n key: Key,\n /**\n * Ref to the item.\n */\n ref: RefObject<FocusableElement | null>,\n /**\n * By default, selection occurs on pointer down. This can be strange if selecting an\n * item causes the UI to disappear immediately (e.g. menus).\n */\n shouldSelectOnPressUp?: boolean,\n /**\n * Whether selection requires the pointer/mouse down and up events to occur on the same target or triggers selection on\n * the target of the pointer/mouse up event.\n */\n allowsDifferentPressOrigin?: boolean,\n /**\n * Whether the option is contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * Function to focus the item.\n */\n focus?: () => void,\n /**\n * Whether the option should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /** Whether the item is disabled. */\n isDisabled?: boolean,\n /**\n * Handler that is called when a user performs an action on the item. The exact user event depends on\n * the collection's `selectionBehavior` prop and the interaction modality.\n */\n onAction?: () => void,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * - 'none': links are disabled for both selection and actions (e.g. handled elsewhere).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override' | 'none'\n}\n\nexport interface SelectableItemStates {\n /** Whether the item is currently in a pressed state. */\n isPressed: boolean,\n /** Whether the item is currently selected. */\n isSelected: boolean,\n /** Whether the item is currently focused. */\n isFocused: boolean,\n /**\n * Whether the item is non-interactive, i.e. both selection and actions are disabled and the item may\n * not be focused. Dependent on `disabledKeys` and `disabledBehavior`.\n */\n isDisabled: boolean,\n /**\n * Whether the item may be selected, dependent on `selectionMode`, `disabledKeys`, and `disabledBehavior`.\n */\n allowsSelection: boolean,\n /**\n * Whether the item has an action, dependent on `onAction`, `disabledKeys`,\n * and `disabledBehavior`. It may also change depending on the current selection state\n * of the list (e.g. when selection is primary). This can be used to enable or disable hover\n * styles or other visual indications of interactivity.\n */\n hasAction: boolean\n}\n\nexport interface SelectableItemAria extends SelectableItemStates {\n /**\n * Props to be spread on the item root node.\n */\n itemProps: DOMAttributes\n}\n\n/**\n * Handles interactions with an item in a selectable collection.\n */\nexport function useSelectableItem(options: SelectableItemOptions): SelectableItemAria {\n let {\n id,\n selectionManager: manager,\n key,\n ref,\n shouldSelectOnPressUp,\n shouldUseVirtualFocus,\n focus,\n isDisabled,\n onAction,\n allowsDifferentPressOrigin,\n linkBehavior = 'action'\n } = options;\n let router = useRouter();\n id = useId(id);\n let onSelect = (e: PressEvent | LongPressEvent | PointerEvent) => {\n if (e.pointerType === 'keyboard' && isNonContiguousSelectionModifier(e)) {\n manager.toggleSelection(key);\n } else {\n if (manager.selectionMode === 'none') {\n return;\n }\n\n if (manager.isLink(key)) {\n if (linkBehavior === 'selection' && ref.current) {\n let itemProps = manager.getItemProps(key);\n router.open(ref.current, e, itemProps.href, itemProps.routerOptions);\n // Always set selected keys back to what they were so that select and combobox close.\n manager.setSelectedKeys(manager.selectedKeys);\n return;\n } else if (linkBehavior === 'override' || linkBehavior === 'none') {\n return;\n }\n }\n\n if (manager.selectionMode === 'single') {\n if (manager.isSelected(key) && !manager.disallowEmptySelection) {\n manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n } else if (e && e.shiftKey) {\n manager.extendSelection(key);\n } else if (manager.selectionBehavior === 'toggle' || (e && (isCtrlKeyPressed(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 manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n }\n };\n\n // Focus the associated DOM node when this item becomes the focusedKey\n // TODO: can't make this useLayoutEffect bacause it breaks menus inside dialogs\n // However, if this is a useEffect, it runs twice and dispatches two blur events and immediately sets\n // aria-activeDescendant in useAutocomplete... I've worked around this for now\n useEffect(() => {\n let isFocused = key === manager.focusedKey;\n if (isFocused && manager.isFocused) {\n if (!shouldUseVirtualFocus) {\n if (focus) {\n focus();\n } else if (document.activeElement !== ref.current && ref.current) {\n focusSafely(ref.current);\n }\n } else {\n moveVirtualFocus(ref.current);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [ref, key, manager.focusedKey, manager.childFocusStrategy, manager.isFocused, shouldUseVirtualFocus]);\n\n isDisabled = isDisabled || manager.isDisabled(key);\n // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused\n // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver\n // on iOS 14 doesn't try to move real DOM focus to the item anyway.\n let itemProps: SelectableItemAria['itemProps'] = {};\n if (!shouldUseVirtualFocus && !isDisabled) {\n itemProps = {\n tabIndex: key === manager.focusedKey ? 0 : -1,\n onFocus(e) {\n if (e.target === ref.current) {\n manager.setFocusedKey(key);\n }\n }\n };\n } else if (isDisabled) {\n itemProps.onMouseDown = (e) => {\n // Prevent focus going to the body when clicking on a disabled item.\n e.preventDefault();\n };\n }\n\n // With checkbox selection, onAction (i.e. navigation) becomes primary, and occurs on a single click of the row.\n // Clicking the checkbox enters selection mode, after which clicking anywhere on any row toggles selection for that row.\n // With highlight selection, onAction is secondary, and occurs on double click. Single click selects the row.\n // With touch, onAction occurs on single tap, and long press enters selection mode.\n let isLinkOverride = manager.isLink(key) && linkBehavior === 'override';\n let hasLinkAction = manager.isLink(key) && linkBehavior !== 'selection' && linkBehavior !== 'none';\n let allowsSelection = !isDisabled && manager.canSelectItem(key) && !isLinkOverride;\n let allowsActions = (onAction || hasLinkAction) && !isDisabled;\n let hasPrimaryAction = allowsActions && (\n manager.selectionBehavior === 'replace'\n ? !allowsSelection\n : !allowsSelection || manager.isEmpty\n );\n let hasSecondaryAction = allowsActions && allowsSelection && manager.selectionBehavior === 'replace';\n let hasAction = hasPrimaryAction || hasSecondaryAction;\n let modality = useRef<PointerType | null>(null);\n\n let longPressEnabled = hasAction && allowsSelection;\n let longPressEnabledOnPressStart = useRef(false);\n let hadPrimaryActionOnPressStart = useRef(false);\n\n let performAction = (e) => {\n if (onAction) {\n onAction();\n }\n\n if (hasLinkAction && ref.current) {\n let itemProps = manager.getItemProps(key);\n router.open(ref.current, e, itemProps.href, itemProps.routerOptions);\n }\n };\n\n // By default, selection occurs on pointer down. This can be strange if selecting an\n // item causes the UI to disappear immediately (e.g. menus).\n // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.\n // onPress requires a pointer down event on the same element as pointer up. For menus,\n // we want to be able to have the pointer down on the trigger that opens the menu and\n // the pointer up on the menu item rather than requiring a separate press.\n // For keyboard events, selection still occurs on key down.\n let itemPressProps: PressHookProps = {ref};\n if (shouldSelectOnPressUp) {\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n longPressEnabledOnPressStart.current = longPressEnabled;\n if (e.pointerType === 'keyboard' && (!hasAction || isSelectionKey())) {\n onSelect(e);\n }\n };\n\n // If allowsDifferentPressOrigin and interacting with mouse, make selection happen on pressUp (e.g. open menu on press down, selection on menu item happens on press up.)\n // Otherwise, have selection happen onPress (prevents listview row selection when clicking on interactable elements in the row)\n if (!allowsDifferentPressOrigin) {\n itemPressProps.onPress = (e) => {\n if (hasPrimaryAction || (hasSecondaryAction && e.pointerType !== 'mouse')) {\n if (e.pointerType === 'keyboard' && !isActionKey()) {\n return;\n }\n\n performAction(e);\n } else if (e.pointerType !== 'keyboard' && allowsSelection) {\n onSelect(e);\n }\n };\n } else {\n itemPressProps.onPressUp = hasPrimaryAction ? undefined : (e) => {\n if (e.pointerType === 'mouse' && allowsSelection) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = hasPrimaryAction ? performAction : (e) => {\n if (e.pointerType !== 'keyboard' && e.pointerType !== 'mouse' && allowsSelection) {\n onSelect(e);\n }\n };\n }\n } else {\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n longPressEnabledOnPressStart.current = longPressEnabled;\n hadPrimaryActionOnPressStart.current = hasPrimaryAction;\n\n // Select on mouse down unless there is a primary action which will occur on mouse up.\n // For keyboard, select on key down. If there is an action, the Space key selects on key down,\n // and the Enter key performs onAction on key up.\n if (\n allowsSelection && (\n (e.pointerType === 'mouse' && !hasPrimaryAction) ||\n (e.pointerType === 'keyboard' && (!allowsActions || isSelectionKey()))\n )\n ) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = (e) => {\n // Selection occurs on touch up. Primary actions always occur on pointer up.\n // Both primary and secondary actions occur on Enter key up. The only exception\n // is secondary actions, which occur on double click with a mouse.\n if (\n e.pointerType === 'touch' ||\n e.pointerType === 'pen' ||\n e.pointerType === 'virtual' ||\n (e.pointerType === 'keyboard' && hasAction && isActionKey()) ||\n (e.pointerType === 'mouse' && hadPrimaryActionOnPressStart.current)\n ) {\n if (hasAction) {\n performAction(e);\n } else if (allowsSelection) {\n onSelect(e);\n }\n }\n };\n }\n\n itemProps['data-collection'] = getCollectionId(manager.collection);\n itemProps['data-key'] = key;\n itemPressProps.preventFocusOnPress = shouldUseVirtualFocus;\n\n // When using virtual focus, make sure the focused key gets updated on press.\n if (shouldUseVirtualFocus) {\n itemPressProps = mergeProps(itemPressProps, {\n onPressStart(e) {\n if (e.pointerType !== 'touch') {\n manager.setFocused(true);\n manager.setFocusedKey(key);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch') {\n manager.setFocused(true);\n manager.setFocusedKey(key);\n }\n }\n });\n }\n\n let {pressProps, isPressed} = usePress(itemPressProps);\n\n // Double clicking with a mouse with selectionBehavior = 'replace' performs an action.\n let onDoubleClick = hasSecondaryAction ? (e) => {\n if (modality.current === 'mouse') {\n e.stopPropagation();\n e.preventDefault();\n performAction(e);\n }\n } : undefined;\n\n // Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior\n // to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to\n // selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.\n let {longPressProps} = useLongPress({\n isDisabled: !longPressEnabled,\n onLongPress(e) {\n if (e.pointerType === 'touch') {\n onSelect(e);\n manager.setSelectionBehavior('toggle');\n }\n }\n });\n\n // Prevent native drag and drop on long press if we also select on long press.\n // Once the user is in selection mode, they can long press again to drag.\n // Use a capturing listener to ensure this runs before useDrag, regardless of\n // the order the props get merged.\n let onDragStartCapture = e => {\n if (modality.current === 'touch' && longPressEnabledOnPressStart.current) {\n e.preventDefault();\n }\n };\n\n // Prevent default on link clicks so that we control exactly\n // when they open (to match selection behavior).\n let onClick = manager.isLink(key) ? e => {\n if (!(openLink as any).isOpening) {\n e.preventDefault();\n }\n } : undefined;\n\n return {\n itemProps: mergeProps(\n itemProps,\n allowsSelection || hasPrimaryAction || shouldUseVirtualFocus ? pressProps : {},\n longPressEnabled ? longPressProps : {},\n {onDoubleClick, onDragStartCapture, onClick, id},\n // Prevent DOM focus from moving on mouse down when using virtual focus\n shouldUseVirtualFocus ? {onMouseDown: e => e.preventDefault()} : undefined\n ),\n isPressed,\n isSelected: manager.isSelected(key),\n isFocused: manager.isFocused && manager.focusedKey === key,\n isDisabled,\n allowsSelection,\n hasAction\n };\n}\n\nfunction isActionKey() {\n let event = window.event as KeyboardEvent;\n return event?.key === 'Enter';\n}\n\nfunction isSelectionKey() {\n let event = window.event as KeyboardEvent;\n return event?.key === ' ' || event?.code === 'Space';\n}\n"],"names":[],"version":3,"file":"useSelectableItem.main.js.map"}
@@ -110,7 +110,9 @@ function $880e95eb8b93ba9a$export$ecf600387e221c37(options) {
110
110
  // we want to be able to have the pointer down on the trigger that opens the menu and
111
111
  // the pointer up on the menu item rather than requiring a separate press.
112
112
  // For keyboard events, selection still occurs on key down.
113
- let itemPressProps = {};
113
+ let itemPressProps = {
114
+ ref: ref
115
+ };
114
116
  if (shouldSelectOnPressUp) {
115
117
  itemPressProps.onPressStart = (e)=>{
116
118
  modality.current = e.pointerType;
@@ -110,7 +110,9 @@ function $880e95eb8b93ba9a$export$ecf600387e221c37(options) {
110
110
  // we want to be able to have the pointer down on the trigger that opens the menu and
111
111
  // the pointer up on the menu item rather than requiring a separate press.
112
112
  // For keyboard events, selection still occurs on key down.
113
- let itemPressProps = {};
113
+ let itemPressProps = {
114
+ ref: ref
115
+ };
114
116
  if (shouldSelectOnPressUp) {
115
117
  itemPressProps.onPressStart = (e)=>{
116
118
  modality.current = e.pointerType;
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAkGM,SAAS,0CAAkB,OAA8B;IAC9D,IAAI,MACF,EAAE,EACF,kBAAkB,OAAO,OACzB,GAAG,OACH,GAAG,yBACH,qBAAqB,yBACrB,qBAAqB,SACrB,KAAK,cACL,UAAU,YACV,QAAQ,8BACR,0BAA0B,gBAC1B,eAAe,UAChB,GAAG;IACJ,IAAI,SAAS,CAAA,GAAA,gBAAQ;IACrB,KAAK,CAAA,GAAA,YAAI,EAAE;IACX,IAAI,WAAW,CAAC;QACd,IAAI,EAAE,WAAW,KAAK,cAAc,CAAA,GAAA,yCAA+B,EAAE,IACnE,QAAQ,eAAe,CAAC;aACnB;YACL,IAAI,QAAQ,aAAa,KAAK,QAC5B;YAGF,IAAI,QAAQ,MAAM,CAAC,MAAM;gBACvB,IAAI,iBAAiB,eAAe,IAAI,OAAO,EAAE;oBAC/C,IAAI,YAAY,QAAQ,YAAY,CAAC;oBACrC,OAAO,IAAI,CAAC,IAAI,OA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AAAC,CAAA,GAAA,eAAO,EAAU,SAAS,EAC9B,EAAE,cAAc;IAEpB,IAAI;IAEJ,OAAO;QACL,WAAW,CAAA,GAAA,iBAAS,EAClB,WACA,mBAAmB,oBAAoB,wBAAwB,aAAa,CAAC,GAC7E,mBAAmB,iBAAiB,CAAC,GACrC;2BAAC;gCAAe;qBAAoB;gBAAS;QAAE,GAC/C,uEAAuE;QACvE,wBAAwB;YAAC,aAAa,CAAA,IAAK,EAAE,cAAc;QAAE,IAAI;mBAEnE;QACA,YAAY,QAAQ,UAAU,CAAC;QAC/B,WAAW,QAAQ,SAAS,IAAI,QAAQ,UAAU,KAAK;oBACvD;yBACA;mBACA;IACF;AACF;AAEA,SAAS;IACP,IAAI,QAAQ,OAAO,KAAK;IACxB,OAAO,CAAA,kBAAA,4BAAA,MAAO,GAAG,MAAK;AACxB;AAEA,SAAS;IACP,IAAI,QAAQ,OAAO,KAAK;IACxB,OAAO,CAAA,kBAAA,4BAAA,MAAO,GAAG,MAAK,OAAO,CAAA,kBAAA,4BAAA,MAAO,IAAI,MAAK;AAC/C","sources":["packages/@react-aria/selection/src/useSelectableItem.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 {DOMAttributes, DOMProps, FocusableElement, Key, LongPressEvent, PointerType, PressEvent, RefObject} from '@react-types/shared';\nimport {focusSafely, PressProps, useLongPress, usePress} from '@react-aria/interactions';\nimport {getCollectionId, isNonContiguousSelectionModifier} from './utils';\nimport {isCtrlKeyPressed, mergeProps, openLink, useId, useRouter} from '@react-aria/utils';\nimport {moveVirtualFocus} from '@react-aria/focus';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useEffect, useRef} from 'react';\n\nexport interface SelectableItemOptions extends DOMProps {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A unique key for the item.\n */\n key: Key,\n /**\n * Ref to the item.\n */\n ref: RefObject<FocusableElement | null>,\n /**\n * By default, selection occurs on pointer down. This can be strange if selecting an\n * item causes the UI to disappear immediately (e.g. menus).\n */\n shouldSelectOnPressUp?: boolean,\n /**\n * Whether selection requires the pointer/mouse down and up events to occur on the same target or triggers selection on\n * the target of the pointer/mouse up event.\n */\n allowsDifferentPressOrigin?: boolean,\n /**\n * Whether the option is contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * Function to focus the item.\n */\n focus?: () => void,\n /**\n * Whether the option should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /** Whether the item is disabled. */\n isDisabled?: boolean,\n /**\n * Handler that is called when a user performs an action on the item. The exact user event depends on\n * the collection's `selectionBehavior` prop and the interaction modality.\n */\n onAction?: () => void,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * - 'none': links are disabled for both selection and actions (e.g. handled elsewhere).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override' | 'none'\n}\n\nexport interface SelectableItemStates {\n /** Whether the item is currently in a pressed state. */\n isPressed: boolean,\n /** Whether the item is currently selected. */\n isSelected: boolean,\n /** Whether the item is currently focused. */\n isFocused: boolean,\n /**\n * Whether the item is non-interactive, i.e. both selection and actions are disabled and the item may\n * not be focused. Dependent on `disabledKeys` and `disabledBehavior`.\n */\n isDisabled: boolean,\n /**\n * Whether the item may be selected, dependent on `selectionMode`, `disabledKeys`, and `disabledBehavior`.\n */\n allowsSelection: boolean,\n /**\n * Whether the item has an action, dependent on `onAction`, `disabledKeys`,\n * and `disabledBehavior`. It may also change depending on the current selection state\n * of the list (e.g. when selection is primary). This can be used to enable or disable hover\n * styles or other visual indications of interactivity.\n */\n hasAction: boolean\n}\n\nexport interface SelectableItemAria extends SelectableItemStates {\n /**\n * Props to be spread on the item root node.\n */\n itemProps: DOMAttributes\n}\n\n/**\n * Handles interactions with an item in a selectable collection.\n */\nexport function useSelectableItem(options: SelectableItemOptions): SelectableItemAria {\n let {\n id,\n selectionManager: manager,\n key,\n ref,\n shouldSelectOnPressUp,\n shouldUseVirtualFocus,\n focus,\n isDisabled,\n onAction,\n allowsDifferentPressOrigin,\n linkBehavior = 'action'\n } = options;\n let router = useRouter();\n id = useId(id);\n let onSelect = (e: PressEvent | LongPressEvent | PointerEvent) => {\n if (e.pointerType === 'keyboard' && isNonContiguousSelectionModifier(e)) {\n manager.toggleSelection(key);\n } else {\n if (manager.selectionMode === 'none') {\n return;\n }\n\n if (manager.isLink(key)) {\n if (linkBehavior === 'selection' && ref.current) {\n let itemProps = manager.getItemProps(key);\n router.open(ref.current, e, itemProps.href, itemProps.routerOptions);\n // Always set selected keys back to what they were so that select and combobox close.\n manager.setSelectedKeys(manager.selectedKeys);\n return;\n } else if (linkBehavior === 'override' || linkBehavior === 'none') {\n return;\n }\n }\n\n if (manager.selectionMode === 'single') {\n if (manager.isSelected(key) && !manager.disallowEmptySelection) {\n manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n } else if (e && e.shiftKey) {\n manager.extendSelection(key);\n } else if (manager.selectionBehavior === 'toggle' || (e && (isCtrlKeyPressed(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 manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n }\n };\n\n // Focus the associated DOM node when this item becomes the focusedKey\n // TODO: can't make this useLayoutEffect bacause it breaks menus inside dialogs\n // However, if this is a useEffect, it runs twice and dispatches two blur events and immediately sets\n // aria-activeDescendant in useAutocomplete... I've worked around this for now\n useEffect(() => {\n let isFocused = key === manager.focusedKey;\n if (isFocused && manager.isFocused) {\n if (!shouldUseVirtualFocus) {\n if (focus) {\n focus();\n } else if (document.activeElement !== ref.current && ref.current) {\n focusSafely(ref.current);\n }\n } else {\n moveVirtualFocus(ref.current);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [ref, key, manager.focusedKey, manager.childFocusStrategy, manager.isFocused, shouldUseVirtualFocus]);\n\n isDisabled = isDisabled || manager.isDisabled(key);\n // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused\n // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver\n // on iOS 14 doesn't try to move real DOM focus to the item anyway.\n let itemProps: SelectableItemAria['itemProps'] = {};\n if (!shouldUseVirtualFocus && !isDisabled) {\n itemProps = {\n tabIndex: key === manager.focusedKey ? 0 : -1,\n onFocus(e) {\n if (e.target === ref.current) {\n manager.setFocusedKey(key);\n }\n }\n };\n } else if (isDisabled) {\n itemProps.onMouseDown = (e) => {\n // Prevent focus going to the body when clicking on a disabled item.\n e.preventDefault();\n };\n }\n\n // With checkbox selection, onAction (i.e. navigation) becomes primary, and occurs on a single click of the row.\n // Clicking the checkbox enters selection mode, after which clicking anywhere on any row toggles selection for that row.\n // With highlight selection, onAction is secondary, and occurs on double click. Single click selects the row.\n // With touch, onAction occurs on single tap, and long press enters selection mode.\n let isLinkOverride = manager.isLink(key) && linkBehavior === 'override';\n let hasLinkAction = manager.isLink(key) && linkBehavior !== 'selection' && linkBehavior !== 'none';\n let allowsSelection = !isDisabled && manager.canSelectItem(key) && !isLinkOverride;\n let allowsActions = (onAction || hasLinkAction) && !isDisabled;\n let hasPrimaryAction = allowsActions && (\n manager.selectionBehavior === 'replace'\n ? !allowsSelection\n : !allowsSelection || manager.isEmpty\n );\n let hasSecondaryAction = allowsActions && allowsSelection && manager.selectionBehavior === 'replace';\n let hasAction = hasPrimaryAction || hasSecondaryAction;\n let modality = useRef<PointerType | null>(null);\n\n let longPressEnabled = hasAction && allowsSelection;\n let longPressEnabledOnPressStart = useRef(false);\n let hadPrimaryActionOnPressStart = useRef(false);\n\n let performAction = (e) => {\n if (onAction) {\n onAction();\n }\n\n if (hasLinkAction && ref.current) {\n let itemProps = manager.getItemProps(key);\n router.open(ref.current, e, itemProps.href, itemProps.routerOptions);\n }\n };\n\n // By default, selection occurs on pointer down. This can be strange if selecting an\n // item causes the UI to disappear immediately (e.g. menus).\n // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.\n // onPress requires a pointer down event on the same element as pointer up. For menus,\n // we want to be able to have the pointer down on the trigger that opens the menu and\n // the pointer up on the menu item rather than requiring a separate press.\n // For keyboard events, selection still occurs on key down.\n let itemPressProps: PressProps = {};\n if (shouldSelectOnPressUp) {\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n longPressEnabledOnPressStart.current = longPressEnabled;\n if (e.pointerType === 'keyboard' && (!hasAction || isSelectionKey())) {\n onSelect(e);\n }\n };\n\n // If allowsDifferentPressOrigin and interacting with mouse, make selection happen on pressUp (e.g. open menu on press down, selection on menu item happens on press up.)\n // Otherwise, have selection happen onPress (prevents listview row selection when clicking on interactable elements in the row)\n if (!allowsDifferentPressOrigin) {\n itemPressProps.onPress = (e) => {\n if (hasPrimaryAction || (hasSecondaryAction && e.pointerType !== 'mouse')) {\n if (e.pointerType === 'keyboard' && !isActionKey()) {\n return;\n }\n\n performAction(e);\n } else if (e.pointerType !== 'keyboard' && allowsSelection) {\n onSelect(e);\n }\n };\n } else {\n itemPressProps.onPressUp = hasPrimaryAction ? undefined : (e) => {\n if (e.pointerType === 'mouse' && allowsSelection) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = hasPrimaryAction ? performAction : (e) => {\n if (e.pointerType !== 'keyboard' && e.pointerType !== 'mouse' && allowsSelection) {\n onSelect(e);\n }\n };\n }\n } else {\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n longPressEnabledOnPressStart.current = longPressEnabled;\n hadPrimaryActionOnPressStart.current = hasPrimaryAction;\n\n // Select on mouse down unless there is a primary action which will occur on mouse up.\n // For keyboard, select on key down. If there is an action, the Space key selects on key down,\n // and the Enter key performs onAction on key up.\n if (\n allowsSelection && (\n (e.pointerType === 'mouse' && !hasPrimaryAction) ||\n (e.pointerType === 'keyboard' && (!allowsActions || isSelectionKey()))\n )\n ) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = (e) => {\n // Selection occurs on touch up. Primary actions always occur on pointer up.\n // Both primary and secondary actions occur on Enter key up. The only exception\n // is secondary actions, which occur on double click with a mouse.\n if (\n e.pointerType === 'touch' ||\n e.pointerType === 'pen' ||\n e.pointerType === 'virtual' ||\n (e.pointerType === 'keyboard' && hasAction && isActionKey()) ||\n (e.pointerType === 'mouse' && hadPrimaryActionOnPressStart.current)\n ) {\n if (hasAction) {\n performAction(e);\n } else if (allowsSelection) {\n onSelect(e);\n }\n }\n };\n }\n\n itemProps['data-collection'] = getCollectionId(manager.collection);\n itemProps['data-key'] = key;\n itemPressProps.preventFocusOnPress = shouldUseVirtualFocus;\n\n // When using virtual focus, make sure the focused key gets updated on press.\n if (shouldUseVirtualFocus) {\n itemPressProps = mergeProps(itemPressProps, {\n onPressStart(e) {\n if (e.pointerType !== 'touch') {\n manager.setFocused(true);\n manager.setFocusedKey(key);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch') {\n manager.setFocused(true);\n manager.setFocusedKey(key);\n }\n }\n });\n }\n\n let {pressProps, isPressed} = usePress(itemPressProps);\n\n // Double clicking with a mouse with selectionBehavior = 'replace' performs an action.\n let onDoubleClick = hasSecondaryAction ? (e) => {\n if (modality.current === 'mouse') {\n e.stopPropagation();\n e.preventDefault();\n performAction(e);\n }\n } : undefined;\n\n // Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior\n // to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to\n // selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.\n let {longPressProps} = useLongPress({\n isDisabled: !longPressEnabled,\n onLongPress(e) {\n if (e.pointerType === 'touch') {\n onSelect(e);\n manager.setSelectionBehavior('toggle');\n }\n }\n });\n\n // Prevent native drag and drop on long press if we also select on long press.\n // Once the user is in selection mode, they can long press again to drag.\n // Use a capturing listener to ensure this runs before useDrag, regardless of\n // the order the props get merged.\n let onDragStartCapture = e => {\n if (modality.current === 'touch' && longPressEnabledOnPressStart.current) {\n e.preventDefault();\n }\n };\n\n // Prevent default on link clicks so that we control exactly\n // when they open (to match selection behavior).\n let onClick = manager.isLink(key) ? e => {\n if (!(openLink as any).isOpening) {\n e.preventDefault();\n }\n } : undefined;\n\n return {\n itemProps: mergeProps(\n itemProps,\n allowsSelection || hasPrimaryAction || shouldUseVirtualFocus ? pressProps : {},\n longPressEnabled ? longPressProps : {},\n {onDoubleClick, onDragStartCapture, onClick, id},\n // Prevent DOM focus from moving on mouse down when using virtual focus\n shouldUseVirtualFocus ? {onMouseDown: e => e.preventDefault()} : undefined\n ),\n isPressed,\n isSelected: manager.isSelected(key),\n isFocused: manager.isFocused && manager.focusedKey === key,\n isDisabled,\n allowsSelection,\n hasAction\n };\n}\n\nfunction isActionKey() {\n let event = window.event as KeyboardEvent;\n return event?.key === 'Enter';\n}\n\nfunction isSelectionKey() {\n let event = window.event as KeyboardEvent;\n return event?.key === ' ' || event?.code === 'Space';\n}\n"],"names":[],"version":3,"file":"useSelectableItem.module.js.map"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAkGM,SAAS,0CAAkB,OAA8B;IAC9D,IAAI,MACF,EAAE,EACF,kBAAkB,OAAO,OACzB,GAAG,OACH,GAAG,yBACH,qBAAqB,yBACrB,qBAAqB,SACrB,KAAK,cACL,UAAU,YACV,QAAQ,8BACR,0BAA0B,gBAC1B,eAAe,UAChB,GAAG;IACJ,IAAI,SAAS,CAAA,GAAA,gBAAQ;IACrB,KAAK,CAAA,GAAA,YAAI,EAAE;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C7B,SAAS;gBACT,QAAQ,oBAAoB,CAAC;YAC/B;QACF;IACF;IAEA,8EAA8E;IAC9E,yEAAyE;IACzE,6EAA6E;IAC7E,kCAAkC;IAClC,IAAI,qBAAqB,CAAA;QACvB,IAAI,SAAS,OAAO,KAAK,WAAW,6BAA6B,OAAO,EACtE,EAAE,cAAc;IAEpB;IAEA,4DAA4D;IAC5D,gDAAgD;IAChD,IAAI,UAAU,QAAQ,MAAM,CAAC,OAAO,CAAA;QAClC,IAAI,CAAC,AAAC,CAAA,GAAA,eAAO,EAAU,SAAS,EAC9B,EAAE,cAAc;IAEpB,IAAI;IAEJ,OAAO;QACL,WAAW,CAAA,GAAA,iBAAS,EAClB,WACA,mBAAmB,oBAAoB,wBAAwB,aAAa,CAAC,GAC7E,mBAAmB,iBAAiB,CAAC,GACrC;2BAAC;gCAAe;qBAAoB;gBAAS;QAAE,GAC/C,uEAAuE;QACvE,wBAAwB;YAAC,aAAa,CAAA,IAAK,EAAE,cAAc;QAAE,IAAI;mBAEnE;QACA,YAAY,QAAQ,UAAU,CAAC;QAC/B,WAAW,QAAQ,SAAS,IAAI,QAAQ,UAAU,KAAK;oBACvD;yBACA;mBACA;IACF;AACF;AAEA,SAAS;IACP,IAAI,QAAQ,OAAO,KAAK;IACxB,OAAO,CAAA,kBAAA,4BAAA,MAAO,GAAG,MAAK;AACxB;AAEA,SAAS;IACP,IAAI,QAAQ,OAAO,KAAK;IACxB,OAAO,CAAA,kBAAA,4BAAA,MAAO,GAAG,MAAK,OAAO,CAAA,kBAAA,4BAAA,MAAO,IAAI,MAAK;AAC/C","sources":["packages/@react-aria/selection/src/useSelectableItem.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 {DOMAttributes, DOMProps, FocusableElement, Key, LongPressEvent, PointerType, PressEvent, RefObject} from '@react-types/shared';\nimport {focusSafely, PressHookProps, useLongPress, usePress} from '@react-aria/interactions';\nimport {getCollectionId, isNonContiguousSelectionModifier} from './utils';\nimport {isCtrlKeyPressed, mergeProps, openLink, useId, useRouter} from '@react-aria/utils';\nimport {moveVirtualFocus} from '@react-aria/focus';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useEffect, useRef} from 'react';\n\nexport interface SelectableItemOptions extends DOMProps {\n /**\n * An interface for reading and updating multiple selection state.\n */\n selectionManager: MultipleSelectionManager,\n /**\n * A unique key for the item.\n */\n key: Key,\n /**\n * Ref to the item.\n */\n ref: RefObject<FocusableElement | null>,\n /**\n * By default, selection occurs on pointer down. This can be strange if selecting an\n * item causes the UI to disappear immediately (e.g. menus).\n */\n shouldSelectOnPressUp?: boolean,\n /**\n * Whether selection requires the pointer/mouse down and up events to occur on the same target or triggers selection on\n * the target of the pointer/mouse up event.\n */\n allowsDifferentPressOrigin?: boolean,\n /**\n * Whether the option is contained in a virtual scroller.\n */\n isVirtualized?: boolean,\n /**\n * Function to focus the item.\n */\n focus?: () => void,\n /**\n * Whether the option should use virtual focus instead of being focused directly.\n */\n shouldUseVirtualFocus?: boolean,\n /** Whether the item is disabled. */\n isDisabled?: boolean,\n /**\n * Handler that is called when a user performs an action on the item. The exact user event depends on\n * the collection's `selectionBehavior` prop and the interaction modality.\n */\n onAction?: () => void,\n /**\n * The behavior of links in the collection.\n * - 'action': link behaves like onAction.\n * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n * - 'override': links override all other interactions (link items are not selectable).\n * - 'none': links are disabled for both selection and actions (e.g. handled elsewhere).\n * @default 'action'\n */\n linkBehavior?: 'action' | 'selection' | 'override' | 'none'\n}\n\nexport interface SelectableItemStates {\n /** Whether the item is currently in a pressed state. */\n isPressed: boolean,\n /** Whether the item is currently selected. */\n isSelected: boolean,\n /** Whether the item is currently focused. */\n isFocused: boolean,\n /**\n * Whether the item is non-interactive, i.e. both selection and actions are disabled and the item may\n * not be focused. Dependent on `disabledKeys` and `disabledBehavior`.\n */\n isDisabled: boolean,\n /**\n * Whether the item may be selected, dependent on `selectionMode`, `disabledKeys`, and `disabledBehavior`.\n */\n allowsSelection: boolean,\n /**\n * Whether the item has an action, dependent on `onAction`, `disabledKeys`,\n * and `disabledBehavior`. It may also change depending on the current selection state\n * of the list (e.g. when selection is primary). This can be used to enable or disable hover\n * styles or other visual indications of interactivity.\n */\n hasAction: boolean\n}\n\nexport interface SelectableItemAria extends SelectableItemStates {\n /**\n * Props to be spread on the item root node.\n */\n itemProps: DOMAttributes\n}\n\n/**\n * Handles interactions with an item in a selectable collection.\n */\nexport function useSelectableItem(options: SelectableItemOptions): SelectableItemAria {\n let {\n id,\n selectionManager: manager,\n key,\n ref,\n shouldSelectOnPressUp,\n shouldUseVirtualFocus,\n focus,\n isDisabled,\n onAction,\n allowsDifferentPressOrigin,\n linkBehavior = 'action'\n } = options;\n let router = useRouter();\n id = useId(id);\n let onSelect = (e: PressEvent | LongPressEvent | PointerEvent) => {\n if (e.pointerType === 'keyboard' && isNonContiguousSelectionModifier(e)) {\n manager.toggleSelection(key);\n } else {\n if (manager.selectionMode === 'none') {\n return;\n }\n\n if (manager.isLink(key)) {\n if (linkBehavior === 'selection' && ref.current) {\n let itemProps = manager.getItemProps(key);\n router.open(ref.current, e, itemProps.href, itemProps.routerOptions);\n // Always set selected keys back to what they were so that select and combobox close.\n manager.setSelectedKeys(manager.selectedKeys);\n return;\n } else if (linkBehavior === 'override' || linkBehavior === 'none') {\n return;\n }\n }\n\n if (manager.selectionMode === 'single') {\n if (manager.isSelected(key) && !manager.disallowEmptySelection) {\n manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n } else if (e && e.shiftKey) {\n manager.extendSelection(key);\n } else if (manager.selectionBehavior === 'toggle' || (e && (isCtrlKeyPressed(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 manager.toggleSelection(key);\n } else {\n manager.replaceSelection(key);\n }\n }\n };\n\n // Focus the associated DOM node when this item becomes the focusedKey\n // TODO: can't make this useLayoutEffect bacause it breaks menus inside dialogs\n // However, if this is a useEffect, it runs twice and dispatches two blur events and immediately sets\n // aria-activeDescendant in useAutocomplete... I've worked around this for now\n useEffect(() => {\n let isFocused = key === manager.focusedKey;\n if (isFocused && manager.isFocused) {\n if (!shouldUseVirtualFocus) {\n if (focus) {\n focus();\n } else if (document.activeElement !== ref.current && ref.current) {\n focusSafely(ref.current);\n }\n } else {\n moveVirtualFocus(ref.current);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [ref, key, manager.focusedKey, manager.childFocusStrategy, manager.isFocused, shouldUseVirtualFocus]);\n\n isDisabled = isDisabled || manager.isDisabled(key);\n // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused\n // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver\n // on iOS 14 doesn't try to move real DOM focus to the item anyway.\n let itemProps: SelectableItemAria['itemProps'] = {};\n if (!shouldUseVirtualFocus && !isDisabled) {\n itemProps = {\n tabIndex: key === manager.focusedKey ? 0 : -1,\n onFocus(e) {\n if (e.target === ref.current) {\n manager.setFocusedKey(key);\n }\n }\n };\n } else if (isDisabled) {\n itemProps.onMouseDown = (e) => {\n // Prevent focus going to the body when clicking on a disabled item.\n e.preventDefault();\n };\n }\n\n // With checkbox selection, onAction (i.e. navigation) becomes primary, and occurs on a single click of the row.\n // Clicking the checkbox enters selection mode, after which clicking anywhere on any row toggles selection for that row.\n // With highlight selection, onAction is secondary, and occurs on double click. Single click selects the row.\n // With touch, onAction occurs on single tap, and long press enters selection mode.\n let isLinkOverride = manager.isLink(key) && linkBehavior === 'override';\n let hasLinkAction = manager.isLink(key) && linkBehavior !== 'selection' && linkBehavior !== 'none';\n let allowsSelection = !isDisabled && manager.canSelectItem(key) && !isLinkOverride;\n let allowsActions = (onAction || hasLinkAction) && !isDisabled;\n let hasPrimaryAction = allowsActions && (\n manager.selectionBehavior === 'replace'\n ? !allowsSelection\n : !allowsSelection || manager.isEmpty\n );\n let hasSecondaryAction = allowsActions && allowsSelection && manager.selectionBehavior === 'replace';\n let hasAction = hasPrimaryAction || hasSecondaryAction;\n let modality = useRef<PointerType | null>(null);\n\n let longPressEnabled = hasAction && allowsSelection;\n let longPressEnabledOnPressStart = useRef(false);\n let hadPrimaryActionOnPressStart = useRef(false);\n\n let performAction = (e) => {\n if (onAction) {\n onAction();\n }\n\n if (hasLinkAction && ref.current) {\n let itemProps = manager.getItemProps(key);\n router.open(ref.current, e, itemProps.href, itemProps.routerOptions);\n }\n };\n\n // By default, selection occurs on pointer down. This can be strange if selecting an\n // item causes the UI to disappear immediately (e.g. menus).\n // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.\n // onPress requires a pointer down event on the same element as pointer up. For menus,\n // we want to be able to have the pointer down on the trigger that opens the menu and\n // the pointer up on the menu item rather than requiring a separate press.\n // For keyboard events, selection still occurs on key down.\n let itemPressProps: PressHookProps = {ref};\n if (shouldSelectOnPressUp) {\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n longPressEnabledOnPressStart.current = longPressEnabled;\n if (e.pointerType === 'keyboard' && (!hasAction || isSelectionKey())) {\n onSelect(e);\n }\n };\n\n // If allowsDifferentPressOrigin and interacting with mouse, make selection happen on pressUp (e.g. open menu on press down, selection on menu item happens on press up.)\n // Otherwise, have selection happen onPress (prevents listview row selection when clicking on interactable elements in the row)\n if (!allowsDifferentPressOrigin) {\n itemPressProps.onPress = (e) => {\n if (hasPrimaryAction || (hasSecondaryAction && e.pointerType !== 'mouse')) {\n if (e.pointerType === 'keyboard' && !isActionKey()) {\n return;\n }\n\n performAction(e);\n } else if (e.pointerType !== 'keyboard' && allowsSelection) {\n onSelect(e);\n }\n };\n } else {\n itemPressProps.onPressUp = hasPrimaryAction ? undefined : (e) => {\n if (e.pointerType === 'mouse' && allowsSelection) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = hasPrimaryAction ? performAction : (e) => {\n if (e.pointerType !== 'keyboard' && e.pointerType !== 'mouse' && allowsSelection) {\n onSelect(e);\n }\n };\n }\n } else {\n itemPressProps.onPressStart = (e) => {\n modality.current = e.pointerType;\n longPressEnabledOnPressStart.current = longPressEnabled;\n hadPrimaryActionOnPressStart.current = hasPrimaryAction;\n\n // Select on mouse down unless there is a primary action which will occur on mouse up.\n // For keyboard, select on key down. If there is an action, the Space key selects on key down,\n // and the Enter key performs onAction on key up.\n if (\n allowsSelection && (\n (e.pointerType === 'mouse' && !hasPrimaryAction) ||\n (e.pointerType === 'keyboard' && (!allowsActions || isSelectionKey()))\n )\n ) {\n onSelect(e);\n }\n };\n\n itemPressProps.onPress = (e) => {\n // Selection occurs on touch up. Primary actions always occur on pointer up.\n // Both primary and secondary actions occur on Enter key up. The only exception\n // is secondary actions, which occur on double click with a mouse.\n if (\n e.pointerType === 'touch' ||\n e.pointerType === 'pen' ||\n e.pointerType === 'virtual' ||\n (e.pointerType === 'keyboard' && hasAction && isActionKey()) ||\n (e.pointerType === 'mouse' && hadPrimaryActionOnPressStart.current)\n ) {\n if (hasAction) {\n performAction(e);\n } else if (allowsSelection) {\n onSelect(e);\n }\n }\n };\n }\n\n itemProps['data-collection'] = getCollectionId(manager.collection);\n itemProps['data-key'] = key;\n itemPressProps.preventFocusOnPress = shouldUseVirtualFocus;\n\n // When using virtual focus, make sure the focused key gets updated on press.\n if (shouldUseVirtualFocus) {\n itemPressProps = mergeProps(itemPressProps, {\n onPressStart(e) {\n if (e.pointerType !== 'touch') {\n manager.setFocused(true);\n manager.setFocusedKey(key);\n }\n },\n onPress(e) {\n if (e.pointerType === 'touch') {\n manager.setFocused(true);\n manager.setFocusedKey(key);\n }\n }\n });\n }\n\n let {pressProps, isPressed} = usePress(itemPressProps);\n\n // Double clicking with a mouse with selectionBehavior = 'replace' performs an action.\n let onDoubleClick = hasSecondaryAction ? (e) => {\n if (modality.current === 'mouse') {\n e.stopPropagation();\n e.preventDefault();\n performAction(e);\n }\n } : undefined;\n\n // Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior\n // to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to\n // selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.\n let {longPressProps} = useLongPress({\n isDisabled: !longPressEnabled,\n onLongPress(e) {\n if (e.pointerType === 'touch') {\n onSelect(e);\n manager.setSelectionBehavior('toggle');\n }\n }\n });\n\n // Prevent native drag and drop on long press if we also select on long press.\n // Once the user is in selection mode, they can long press again to drag.\n // Use a capturing listener to ensure this runs before useDrag, regardless of\n // the order the props get merged.\n let onDragStartCapture = e => {\n if (modality.current === 'touch' && longPressEnabledOnPressStart.current) {\n e.preventDefault();\n }\n };\n\n // Prevent default on link clicks so that we control exactly\n // when they open (to match selection behavior).\n let onClick = manager.isLink(key) ? e => {\n if (!(openLink as any).isOpening) {\n e.preventDefault();\n }\n } : undefined;\n\n return {\n itemProps: mergeProps(\n itemProps,\n allowsSelection || hasPrimaryAction || shouldUseVirtualFocus ? pressProps : {},\n longPressEnabled ? longPressProps : {},\n {onDoubleClick, onDragStartCapture, onClick, id},\n // Prevent DOM focus from moving on mouse down when using virtual focus\n shouldUseVirtualFocus ? {onMouseDown: e => e.preventDefault()} : undefined\n ),\n isPressed,\n isSelected: manager.isSelected(key),\n isFocused: manager.isFocused && manager.focusedKey === key,\n isDisabled,\n allowsSelection,\n hasAction\n };\n}\n\nfunction isActionKey() {\n let event = window.event as KeyboardEvent;\n return event?.key === 'Enter';\n}\n\nfunction isSelectionKey() {\n let event = window.event as KeyboardEvent;\n return event?.key === ' ' || event?.code === 'Space';\n}\n"],"names":[],"version":3,"file":"useSelectableItem.module.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAYM,SAAS,0CAAiC,CAAQ;IACvD,qFAAqF;IACrF,gEAAgE;IAChE,OAAO,CAAA,GAAA,mCAAY,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO;AAC/C;AAEO,SAAS,0CAAe,aAA4C,EAAE,GAAQ;QAElE,wBAIV;IALP,IAAI,WAAW,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,OAAO,MAAM,EAAE,CAAC;IACxD,IAAI,cAAa,yBAAA,cAAc,OAAO,cAArB,6CAAA,uBAAuB,OAAO,CAAC,UAAU;IAC1D,IAAI,YACF,WAAW,CAAC,kBAAkB,EAAE,IAAI,MAAM,CAAC,YAAY,EAAE,EAAE,UAAU;IAEvE,QAAO,0BAAA,cAAc,OAAO,cAArB,8CAAA,wBAAuB,aAAa,CAAC;AAC9C;AAEA,MAAM,sCAAgB,IAAI;AACnB,SAAS,0CAAgB,UAA2B;IACzD,IAAI,KAAK,CAAA,GAAA,2BAAI;IACb,oCAAc,GAAG,CAAC,YAAY;IAC9B,OAAO;AACT;AAEO,SAAS,0CAAgB,UAA2B;IACzD,OAAO,oCAAc,GAAG,CAAC;AAC3B","sources":["packages/@react-aria/selection/src/utils.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 {Collection, Key} from '@react-types/shared';\nimport {isAppleDevice, useId} from '@react-aria/utils';\nimport {RefObject} from 'react';\n\ninterface Event {\n altKey: boolean,\n ctrlKey: boolean,\n metaKey: boolean\n}\n\nexport function isNonContiguousSelectionModifier(e: Event) {\n // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.\n // On Windows and Ubuntu, Alt + Space has a system wide meaning.\n return isAppleDevice() ? e.altKey : e.ctrlKey;\n}\n\nexport function getItemElement(collectionRef: RefObject<HTMLElement | null>, key: Key) {\n let selector = `[data-key=\"${CSS.escape(String(key))}\"]`;\n let collection = collectionRef.current?.dataset.collection;\n if (collection) {\n selector = `[data-collection=\"${CSS.escape(collection)}\"]${selector}`;\n }\n return collectionRef.current?.querySelector(selector);\n}\n\nconst collectionMap = new WeakMap();\nexport function useCollectionId(collection: Collection<any>) {\n let id = useId();\n collectionMap.set(collection, id);\n return id;\n}\n\nexport function getCollectionId(collection: Collection<any>) {\n return collectionMap.get(collection)!;\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;AAYM,SAAS,0CAAiC,CAAQ;IACvD,qFAAqF;IACrF,gEAAgE;IAChE,OAAO,CAAA,GAAA,mCAAY,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO;AAC/C;AAEO,SAAS,0CAAe,aAA4C,EAAE,GAAQ;QAElE,wBAIV;IALP,IAAI,WAAW,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,OAAO,MAAM,EAAE,CAAC;IACxD,IAAI,cAAa,yBAAA,cAAc,OAAO,cAArB,6CAAA,uBAAuB,OAAO,CAAC,UAAU;IAC1D,IAAI,YACF,WAAW,CAAC,kBAAkB,EAAE,IAAI,MAAM,CAAC,YAAY,EAAE,EAAE,UAAU;IAEvE,QAAO,0BAAA,cAAc,OAAO,cAArB,8CAAA,wBAAuB,aAAa,CAAC;AAC9C;AAEA,MAAM,sCAAgB,IAAI;AACnB,SAAS,0CAAgB,UAA2B;IACzD,IAAI,KAAK,CAAA,GAAA,2BAAI;IACb,oCAAc,GAAG,CAAC,YAAY;IAC9B,OAAO;AACT;AAEO,SAAS,0CAAgB,UAA2B;IACzD,OAAO,oCAAc,GAAG,CAAC;AAC3B","sources":["packages/@react-aria/selection/src/utils.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 {Collection, Key} from '@react-types/shared';\nimport {isAppleDevice, useId} from '@react-aria/utils';\nimport {RefObject} from 'react';\n\ninterface Event {\n altKey: boolean,\n ctrlKey: boolean,\n metaKey: boolean\n}\n\nexport function isNonContiguousSelectionModifier(e: Event): boolean {\n // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.\n // On Windows and Ubuntu, Alt + Space has a system wide meaning.\n return isAppleDevice() ? e.altKey : e.ctrlKey;\n}\n\nexport function getItemElement(collectionRef: RefObject<HTMLElement | null>, key: Key): Element | null | undefined {\n let selector = `[data-key=\"${CSS.escape(String(key))}\"]`;\n let collection = collectionRef.current?.dataset.collection;\n if (collection) {\n selector = `[data-collection=\"${CSS.escape(collection)}\"]${selector}`;\n }\n return collectionRef.current?.querySelector(selector);\n}\n\nconst collectionMap = new WeakMap<Collection<any>, string>();\nexport function useCollectionId(collection: Collection<any>): string {\n let id = useId();\n collectionMap.set(collection, id);\n return id;\n}\n\nexport function getCollectionId(collection: Collection<any>): string {\n return collectionMap.get(collection)!;\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAYM,SAAS,0CAAiC,CAAQ;IACvD,qFAAqF;IACrF,gEAAgE;IAChE,OAAO,CAAA,GAAA,oBAAY,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO;AAC/C;AAEO,SAAS,0CAAe,aAA4C,EAAE,GAAQ;QAElE,wBAIV;IALP,IAAI,WAAW,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,OAAO,MAAM,EAAE,CAAC;IACxD,IAAI,cAAa,yBAAA,cAAc,OAAO,cAArB,6CAAA,uBAAuB,OAAO,CAAC,UAAU;IAC1D,IAAI,YACF,WAAW,CAAC,kBAAkB,EAAE,IAAI,MAAM,CAAC,YAAY,EAAE,EAAE,UAAU;IAEvE,QAAO,0BAAA,cAAc,OAAO,cAArB,8CAAA,wBAAuB,aAAa,CAAC;AAC9C;AAEA,MAAM,sCAAgB,IAAI;AACnB,SAAS,0CAAgB,UAA2B;IACzD,IAAI,KAAK,CAAA,GAAA,YAAI;IACb,oCAAc,GAAG,CAAC,YAAY;IAC9B,OAAO;AACT;AAEO,SAAS,0CAAgB,UAA2B;IACzD,OAAO,oCAAc,GAAG,CAAC;AAC3B","sources":["packages/@react-aria/selection/src/utils.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 {Collection, Key} from '@react-types/shared';\nimport {isAppleDevice, useId} from '@react-aria/utils';\nimport {RefObject} from 'react';\n\ninterface Event {\n altKey: boolean,\n ctrlKey: boolean,\n metaKey: boolean\n}\n\nexport function isNonContiguousSelectionModifier(e: Event) {\n // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.\n // On Windows and Ubuntu, Alt + Space has a system wide meaning.\n return isAppleDevice() ? e.altKey : e.ctrlKey;\n}\n\nexport function getItemElement(collectionRef: RefObject<HTMLElement | null>, key: Key) {\n let selector = `[data-key=\"${CSS.escape(String(key))}\"]`;\n let collection = collectionRef.current?.dataset.collection;\n if (collection) {\n selector = `[data-collection=\"${CSS.escape(collection)}\"]${selector}`;\n }\n return collectionRef.current?.querySelector(selector);\n}\n\nconst collectionMap = new WeakMap();\nexport function useCollectionId(collection: Collection<any>) {\n let id = useId();\n collectionMap.set(collection, id);\n return id;\n}\n\nexport function getCollectionId(collection: Collection<any>) {\n return collectionMap.get(collection)!;\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AAYM,SAAS,0CAAiC,CAAQ;IACvD,qFAAqF;IACrF,gEAAgE;IAChE,OAAO,CAAA,GAAA,oBAAY,MAAM,EAAE,MAAM,GAAG,EAAE,OAAO;AAC/C;AAEO,SAAS,0CAAe,aAA4C,EAAE,GAAQ;QAElE,wBAIV;IALP,IAAI,WAAW,CAAC,WAAW,EAAE,IAAI,MAAM,CAAC,OAAO,MAAM,EAAE,CAAC;IACxD,IAAI,cAAa,yBAAA,cAAc,OAAO,cAArB,6CAAA,uBAAuB,OAAO,CAAC,UAAU;IAC1D,IAAI,YACF,WAAW,CAAC,kBAAkB,EAAE,IAAI,MAAM,CAAC,YAAY,EAAE,EAAE,UAAU;IAEvE,QAAO,0BAAA,cAAc,OAAO,cAArB,8CAAA,wBAAuB,aAAa,CAAC;AAC9C;AAEA,MAAM,sCAAgB,IAAI;AACnB,SAAS,0CAAgB,UAA2B;IACzD,IAAI,KAAK,CAAA,GAAA,YAAI;IACb,oCAAc,GAAG,CAAC,YAAY;IAC9B,OAAO;AACT;AAEO,SAAS,0CAAgB,UAA2B;IACzD,OAAO,oCAAc,GAAG,CAAC;AAC3B","sources":["packages/@react-aria/selection/src/utils.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 {Collection, Key} from '@react-types/shared';\nimport {isAppleDevice, useId} from '@react-aria/utils';\nimport {RefObject} from 'react';\n\ninterface Event {\n altKey: boolean,\n ctrlKey: boolean,\n metaKey: boolean\n}\n\nexport function isNonContiguousSelectionModifier(e: Event): boolean {\n // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.\n // On Windows and Ubuntu, Alt + Space has a system wide meaning.\n return isAppleDevice() ? e.altKey : e.ctrlKey;\n}\n\nexport function getItemElement(collectionRef: RefObject<HTMLElement | null>, key: Key): Element | null | undefined {\n let selector = `[data-key=\"${CSS.escape(String(key))}\"]`;\n let collection = collectionRef.current?.dataset.collection;\n if (collection) {\n selector = `[data-collection=\"${CSS.escape(collection)}\"]${selector}`;\n }\n return collectionRef.current?.querySelector(selector);\n}\n\nconst collectionMap = new WeakMap<Collection<any>, string>();\nexport function useCollectionId(collection: Collection<any>): string {\n let id = useId();\n collectionMap.set(collection, id);\n return id;\n}\n\nexport function getCollectionId(collection: Collection<any>): string {\n return collectionMap.get(collection)!;\n}\n"],"names":[],"version":3,"file":"utils.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/selection",
3
- "version": "3.23.1",
3
+ "version": "3.24.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,12 +22,12 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/focus": "^3.20.1",
26
- "@react-aria/i18n": "^3.12.7",
27
- "@react-aria/interactions": "^3.24.1",
28
- "@react-aria/utils": "^3.28.1",
29
- "@react-stately/selection": "^3.20.0",
30
- "@react-types/shared": "^3.28.0",
25
+ "@react-aria/focus": "^3.20.2",
26
+ "@react-aria/i18n": "^3.12.8",
27
+ "@react-aria/interactions": "^3.25.0",
28
+ "@react-aria/utils": "^3.28.2",
29
+ "@react-stately/selection": "^3.20.1",
30
+ "@react-types/shared": "^3.29.0",
31
31
  "@swc/helpers": "^0.5.0"
32
32
  },
33
33
  "peerDependencies": {
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "9c4ebbc0c1972cc880febc29de995ca58caa3ba4"
40
+ "gitHead": "9b66d270572f482948afee95622a85cdf68ed408"
41
41
  }
@@ -88,13 +88,13 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
88
88
  return null;
89
89
  }
90
90
 
91
- getNextKey(key: Key) {
91
+ getNextKey(key: Key): Key | null {
92
92
  let nextKey: Key | null = key;
93
93
  nextKey = this.collection.getKeyAfter(nextKey);
94
94
  return this.findNextNonDisabled(nextKey, key => this.collection.getKeyAfter(key));
95
95
  }
96
96
 
97
- getPreviousKey(key: Key) {
97
+ getPreviousKey(key: Key): Key | null {
98
98
  let nextKey: Key | null = key;
99
99
  nextKey = this.collection.getKeyBefore(nextKey);
100
100
  return this.findNextNonDisabled(nextKey, key => this.collection.getKeyBefore(key));
@@ -132,7 +132,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
132
132
  return prevRect.x === itemRect.x || prevRect.y !== itemRect.y;
133
133
  }
134
134
 
135
- getKeyBelow(key: Key) {
135
+ getKeyBelow(key: Key): Key | null {
136
136
  if (this.layout === 'grid' && this.orientation === 'vertical') {
137
137
  return this.findKey(key, (key) => this.getNextKey(key), this.isSameRow);
138
138
  } else {
@@ -140,7 +140,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
140
140
  }
141
141
  }
142
142
 
143
- getKeyAbove(key: Key) {
143
+ getKeyAbove(key: Key): Key | null {
144
144
  if (this.layout === 'grid' && this.orientation === 'vertical') {
145
145
  return this.findKey(key, (key) => this.getPreviousKey(key), this.isSameRow);
146
146
  } else {
@@ -152,7 +152,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
152
152
  return right ? this.getPreviousKey(key) : this.getNextKey(key);
153
153
  }
154
154
 
155
- getKeyRightOf?(key: Key) {
155
+ getKeyRightOf?(key: Key): Key | null {
156
156
  // This is a temporary solution for CardView until we refactor useSelectableCollection.
157
157
  // https://github.com/orgs/adobe/projects/19/views/32?pane=issue&itemId=77825042
158
158
  let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyRightOf' : 'getKeyLeftOf';
@@ -174,7 +174,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
174
174
  return null;
175
175
  }
176
176
 
177
- getKeyLeftOf?(key: Key) {
177
+ getKeyLeftOf?(key: Key): Key | null {
178
178
  let layoutDelegateMethod = this.direction === 'ltr' ? 'getKeyLeftOf' : 'getKeyRightOf';
179
179
  if (this.layoutDelegate[layoutDelegateMethod]) {
180
180
  key = this.layoutDelegate[layoutDelegateMethod](key);
@@ -194,17 +194,17 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
194
194
  return null;
195
195
  }
196
196
 
197
- getFirstKey() {
197
+ getFirstKey(): Key | null {
198
198
  let key = this.collection.getFirstKey();
199
199
  return this.findNextNonDisabled(key, key => this.collection.getKeyAfter(key));
200
200
  }
201
201
 
202
- getLastKey() {
202
+ getLastKey(): Key | null {
203
203
  let key = this.collection.getLastKey();
204
204
  return this.findNextNonDisabled(key, key => this.collection.getKeyBefore(key));
205
205
  }
206
206
 
207
- getKeyPageAbove(key: Key) {
207
+ getKeyPageAbove(key: Key): Key | null {
208
208
  let menu = this.ref.current;
209
209
  let itemRect = this.layoutDelegate.getItemRect(key);
210
210
  if (!itemRect) {
@@ -235,7 +235,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
235
235
  return nextKey ?? this.getFirstKey();
236
236
  }
237
237
 
238
- getKeyPageBelow(key: Key) {
238
+ getKeyPageBelow(key: Key): Key | null {
239
239
  let menu = this.ref.current;
240
240
  let itemRect = this.layoutDelegate.getItemRect(key);
241
241
  if (!itemRect) {
@@ -266,7 +266,7 @@ export class ListKeyboardDelegate<T> implements KeyboardDelegate {
266
266
  return nextKey ?? this.getLastKey();
267
267
  }
268
268
 
269
- getKeyForSearch(search: string, fromKey?: Key) {
269
+ getKeyForSearch(search: string, fromKey?: Key): Key | null {
270
270
  if (!this.collator) {
271
271
  return null;
272
272
  }
@@ -54,6 +54,11 @@ export interface AriaSelectableCollectionOptions {
54
54
  * @default false
55
55
  */
56
56
  disallowSelectAll?: boolean,
57
+ /**
58
+ * Whether pressing the Escape should clear selection in the collection or not.
59
+ * @default 'clearSelection'
60
+ */
61
+ escapeKeyBehavior?: 'clearSelection' | 'none',
57
62
  /**
58
63
  * Whether selection should occur automatically on focus.
59
64
  * @default false
@@ -108,6 +113,7 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
108
113
  shouldFocusWrap = false,
109
114
  disallowEmptySelection = false,
110
115
  disallowSelectAll = false,
116
+ escapeKeyBehavior = 'clearSelection',
111
117
  selectOnFocus = manager.selectionBehavior === 'replace',
112
118
  disallowTypeAhead = false,
113
119
  shouldUseVirtualFocus,
@@ -279,7 +285,7 @@ export function useSelectableCollection(options: AriaSelectableCollectionOptions
279
285
  }
280
286
  break;
281
287
  case 'Escape':
282
- if (!disallowEmptySelection && manager.selectedKeys.size !== 0) {
288
+ if (escapeKeyBehavior === 'clearSelection' && !disallowEmptySelection && manager.selectedKeys.size !== 0) {
283
289
  e.stopPropagation();
284
290
  e.preventDefault();
285
291
  manager.clearSelection();
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {DOMAttributes, DOMProps, FocusableElement, Key, LongPressEvent, PointerType, PressEvent, RefObject} from '@react-types/shared';
14
- import {focusSafely, PressProps, useLongPress, usePress} from '@react-aria/interactions';
14
+ import {focusSafely, PressHookProps, useLongPress, usePress} from '@react-aria/interactions';
15
15
  import {getCollectionId, isNonContiguousSelectionModifier} from './utils';
16
16
  import {isCtrlKeyPressed, mergeProps, openLink, useId, useRouter} from '@react-aria/utils';
17
17
  import {moveVirtualFocus} from '@react-aria/focus';
@@ -239,7 +239,7 @@ export function useSelectableItem(options: SelectableItemOptions): SelectableIte
239
239
  // we want to be able to have the pointer down on the trigger that opens the menu and
240
240
  // the pointer up on the menu item rather than requiring a separate press.
241
241
  // For keyboard events, selection still occurs on key down.
242
- let itemPressProps: PressProps = {};
242
+ let itemPressProps: PressHookProps = {ref};
243
243
  if (shouldSelectOnPressUp) {
244
244
  itemPressProps.onPressStart = (e) => {
245
245
  modality.current = e.pointerType;
package/src/utils.ts CHANGED
@@ -20,13 +20,13 @@ interface Event {
20
20
  metaKey: boolean
21
21
  }
22
22
 
23
- export function isNonContiguousSelectionModifier(e: Event) {
23
+ export function isNonContiguousSelectionModifier(e: Event): boolean {
24
24
  // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.
25
25
  // On Windows and Ubuntu, Alt + Space has a system wide meaning.
26
26
  return isAppleDevice() ? e.altKey : e.ctrlKey;
27
27
  }
28
28
 
29
- export function getItemElement(collectionRef: RefObject<HTMLElement | null>, key: Key) {
29
+ export function getItemElement(collectionRef: RefObject<HTMLElement | null>, key: Key): Element | null | undefined {
30
30
  let selector = `[data-key="${CSS.escape(String(key))}"]`;
31
31
  let collection = collectionRef.current?.dataset.collection;
32
32
  if (collection) {
@@ -35,13 +35,13 @@ export function getItemElement(collectionRef: RefObject<HTMLElement | null>, key
35
35
  return collectionRef.current?.querySelector(selector);
36
36
  }
37
37
 
38
- const collectionMap = new WeakMap();
39
- export function useCollectionId(collection: Collection<any>) {
38
+ const collectionMap = new WeakMap<Collection<any>, string>();
39
+ export function useCollectionId(collection: Collection<any>): string {
40
40
  let id = useId();
41
41
  collectionMap.set(collection, id);
42
42
  return id;
43
43
  }
44
44
 
45
- export function getCollectionId(collection: Collection<any>) {
45
+ export function getCollectionId(collection: Collection<any>): string {
46
46
  return collectionMap.get(collection)!;
47
47
  }