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AAiE;IACjE,MAAM,mBAAmB,CAAA,GAAA,mBAAK,EAA8B;IAC5D,CAAA,GAAA,sBAAQ,EAAE;QACR,IACE,iBAAiB,UAAU,IAAI,QAC/B,CAAC,WAAW,OAAO,CAAC,iBAAiB,UAAU,KAC/C,iBAAiB,OAAO,EACxB;YACA,mGAAmG;YACnG,IAAI,MAAM,iBAAiB,OAAO,CAAC,WAAW,CAAC,iBAAiB,UAAU;YAC1E,IAAI,iBAA6B;YACjC,MAAO,OAAO,KAAM;gBAClB,IAAI,OAAO,WAAW,OAAO,CAAC;gBAC9B,IAAI,QAAQ,KAAK,IAAI,KAAK,UAAU,CAAC,iBAAiB,UAAU,CAAC,MAAM;oBACrE,iBAAiB;oBACjB;gBACF;gBAEA,MAAM,iBAAiB,OAAO,CAAC,WAAW,CAAC;YAC7C;YAEA,wCAAwC;YACxC,IAAI,kBAAkB,MAAM;gBAC1B,MAAM,iBAAiB,OAAO,CAAC,YAAY,CAAC,iBAAiB,UAAU;gBACvE,MAAO,OAAO,KAAM;oBAClB,IAAI,OAAO,WAAW,OAAO,CAAC;oBAC9B,IAAI,QAAQ,KAAK,IAAI,KAAK,UAAU,CAAC,iBAAiB,UAAU,CAAC,MAAM;wBACrE,iBAAiB;wBACjB;oBACF;oBAEA,MAAM,iBAAiB,OAAO,CAAC,YAAY,CAAC;gBAC9C;YACF;YAEA,iBAAiB,aAAa,CAAC;QACjC;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;KAAiB;AACnC","sources":["packages/react-stately/src/list/useListState.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, CollectionStateBase, Key, LayoutDelegate, Node} from '@react-types/shared';\nimport {ListCollection} from './ListCollection';\nimport {\n MultipleSelectionStateProps,\n useMultipleSelectionState\n} from '../selection/useMultipleSelectionState';\nimport {SelectionManager} from '../selection/SelectionManager';\nimport {useCallback, useEffect, useMemo, useRef} from 'react';\nimport {useCollection} from '../collections/useCollection';\n\nexport interface ListProps<T> extends CollectionStateBase<T>, MultipleSelectionStateProps {\n /** Filter function to generate a filtered list of nodes. */\n filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>;\n /** @private */\n suppressTextValueWarning?: boolean;\n /**\n * A delegate object that provides layout information for items in the collection.\n * This can be used to override the behavior of shift selection.\n */\n layoutDelegate?: LayoutDelegate;\n}\n\nexport interface ListState<T> {\n /** A collection of items in the list. */\n collection: Collection<Node<T>>;\n\n /** A set of items that are disabled. */\n disabledKeys: Set<Key>;\n\n /** A selection manager to read and update multiple selection state. */\n selectionManager: SelectionManager;\n}\n\n/**\n * Provides state management for list-like components. Handles building a collection\n * of items from props, and manages multiple selection state.\n */\nexport function useListState<T>(props: ListProps<T>): ListState<T> {\n let {filter, layoutDelegate} = props;\n\n let selectionState = useMultipleSelectionState(props);\n let disabledKeys = useMemo(\n () => (props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()),\n [props.disabledKeys]\n );\n\n let factory = useCallback(\n nodes =>\n filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>),\n [filter]\n );\n let context = useMemo(\n () => ({suppressTextValueWarning: props.suppressTextValueWarning}),\n [props.suppressTextValueWarning]\n );\n\n let collection = useCollection(props, factory, context);\n\n let selectionManager = useMemo(\n () => new SelectionManager(collection, selectionState, {layoutDelegate}),\n [collection, selectionState, layoutDelegate]\n );\n\n useFocusedKeyReset(collection, selectionManager);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\n}\n\n/**\n * Filters a collection using the provided filter function and returns a new ListState.\n */\nexport function UNSTABLE_useFilteredListState<T>(\n state: ListState<T>,\n filterFn: ((nodeValue: string, node: Node<T>) => boolean) | null | undefined\n): ListState<T> {\n let collection = useMemo(\n () => (filterFn ? state.collection.filter!(filterFn) : state.collection),\n [state.collection, filterFn]\n );\n let selectionManager = state.selectionManager.withCollection(collection);\n useFocusedKeyReset(collection, selectionManager);\n return {\n collection,\n selectionManager,\n disabledKeys: state.disabledKeys\n };\n}\n\nfunction useFocusedKeyReset<T>(\n collection: Collection<Node<T>>,\n selectionManager: SelectionManager\n) {\n // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<Collection<Node<T>> | null>(null);\n useEffect(() => {\n if (\n selectionManager.focusedKey != null &&\n !collection.getItem(selectionManager.focusedKey) &&\n cachedCollection.current\n ) {\n // Walk forward in the old collection to find the next key that still exists in the new collection.\n let key = cachedCollection.current.getKeyAfter(selectionManager.focusedKey);\n let nextFocusedKey: Key | null = null;\n while (key != null) {\n let node = collection.getItem(key);\n if (node && node.type === 'item' && !selectionManager.isDisabled(key)) {\n nextFocusedKey = key;\n break;\n }\n\n key = cachedCollection.current.getKeyAfter(key);\n }\n\n // If no such key exists, walk backward.\n if (nextFocusedKey == null) {\n key = cachedCollection.current.getKeyBefore(selectionManager.focusedKey);\n while (key != null) {\n let node = collection.getItem(key);\n if (node && node.type === 'item' && !selectionManager.isDisabled(key)) {\n nextFocusedKey = key;\n break;\n }\n\n key = cachedCollection.current.getKeyBefore(key);\n }\n }\n\n selectionManager.setFocusedKey(nextFocusedKey);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager]);\n}\n"],"names":[],"version":3,"file":"useListState.cjs.map"}