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/*\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 {Key, Selection} from '@react-types/shared';\nimport {useMemo, useState} from 'react';\n\nexport interface ListOptions<T> {\n /** Initial items in the list. */\n initialItems?: T[];\n /** The keys for the initially selected items. */\n initialSelectedKeys?: 'all' | Iterable<Key>;\n /** The initial text to filter the list by. */\n initialFilterText?: string;\n /** A function that returns a unique key for an item object. */\n getKey?: (item: T) => Key;\n /** A function that returns whether a item matches the current filter text. */\n filter?: (item: T, filterText: string) => boolean;\n}\n\nexport interface ListData<T> {\n /** The items in the list. */\n items: T[];\n\n /** The keys of the currently selected items in the list. */\n selectedKeys: Selection;\n\n /** Sets the selected keys. */\n setSelectedKeys(keys: Selection): void;\n\n /** Adds the given keys to the current selected keys. */\n addKeysToSelection(keys: Selection): void;\n\n /** Removes the given keys from the current selected keys. */\n removeKeysFromSelection(keys: Selection): void;\n\n /** The current filter text. */\n filterText: string;\n\n /** Sets the filter text. */\n setFilterText(filterText: string): void;\n\n /**\n * Gets an item from the list by key.\n *\n * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): T | undefined;\n\n /**\n * Inserts items into the list at the given index.\n *\n * @param index - The index to insert into.\n * @param values - The values to insert.\n */\n insert(index: number, ...values: T[]): void;\n\n /**\n * Inserts items into the list before the item at the given key.\n *\n * @param key - The key of the item to insert before.\n * @param values - The values to insert.\n */\n insertBefore(key: Key, ...values: T[]): void;\n\n /**\n * Inserts items into the list after the item at the given key.\n *\n * @param key - The key of the item to insert after.\n * @param values - The values to insert.\n */\n insertAfter(key: Key, ...values: T[]): void;\n\n /**\n * Appends items to the list.\n *\n * @param values - The values to insert.\n */\n append(...values: T[]): void;\n\n /**\n * Prepends items to the list.\n *\n * @param value - The value to insert.\n */\n prepend(...values: T[]): void;\n\n /**\n * Removes items from the list by their keys.\n *\n * @param keys - The keys of the item to remove.\n */\n remove(...keys: Key[]): void;\n\n /**\n * Removes all items from the list that are currently\n * in the set of selected items.\n */\n removeSelectedItems(): void;\n\n /**\n * Moves an item within the list.\n *\n * @param key - The key of the item to move.\n * @param toIndex - The index to move the item to.\n */\n move(key: Key, toIndex: number): void;\n\n /**\n * Moves one or more items before a given key.\n *\n * @param key - The key of the item to move the items before.\n * @param keys - The keys of the items to move.\n */\n moveBefore(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Moves one or more items after a given key.\n *\n * @param key - The key of the item to move the items after.\n * @param keys - The keys of the items to move.\n */\n moveAfter(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Updates an item in the list.\n *\n * @param key - The key of the item to update.\n * @param newValue - The new value for the item, or a function that returns the new value based on\n * the previous value.\n */\n update(key: Key, newValue: T | ((prev: T) => T)): void;\n}\n\nexport interface ListState<T> {\n items: T[];\n selectedKeys: Selection;\n filterText: string;\n}\n\ninterface CreateListOptions<T, C> extends ListOptions<T> {\n cursor?: C;\n}\n\n/**\n * Manages state for an immutable list data structure, and provides convenience methods to\n * update the data over time.\n */\nexport function useListData<T>(options: ListOptions<T>): ListData<T> {\n let {\n initialItems = [],\n initialSelectedKeys,\n getKey = (item: any) => item.id ?? item.key,\n filter,\n initialFilterText = ''\n } = options;\n\n // Store both items and filteredItems in state so we can go back to the unfiltered list\n let [state, setState] = useState<ListState<T>>({\n items: initialItems,\n selectedKeys: initialSelectedKeys === 'all' ? 'all' : new Set(initialSelectedKeys || []),\n filterText: initialFilterText\n });\n\n let filteredItems = useMemo(\n () => (filter ? state.items.filter(item => filter(item, state.filterText)) : state.items),\n [state.items, state.filterText, filter]\n );\n\n return {\n ...state,\n items: filteredItems,\n ...createListActions({getKey}, setState),\n getItem(key: Key) {\n return state.items.find(item => getKey(item) === key);\n }\n };\n}\n\nexport function createListActions<T, C>(\n opts: CreateListOptions<T, C>,\n dispatch: (updater: (state: ListState<T>) => ListState<T>) => void\n): Omit<ListData<T>, 'items' | 'selectedKeys' | 'getItem' | 'filterText'> {\n let {cursor, getKey} = opts;\n return {\n setSelectedKeys(selectedKeys: Selection) {\n dispatch(state => ({\n ...state,\n selectedKeys\n }));\n },\n addKeysToSelection(selectedKeys: Selection) {\n dispatch(state => {\n if (state.selectedKeys === 'all') {\n return state;\n }\n if (selectedKeys === 'all') {\n return {\n ...state,\n selectedKeys: 'all'\n };\n }\n\n return {\n ...state,\n selectedKeys: new Set([...state.selectedKeys, ...selectedKeys])\n };\n });\n },\n removeKeysFromSelection(selectedKeys: Selection) {\n dispatch(state => {\n if (selectedKeys === 'all') {\n return {\n ...state,\n selectedKeys: new Set()\n };\n }\n\n let selection: Selection =\n state.selectedKeys === 'all'\n ? new Set(state.items.map(getKey!))\n : new Set(state.selectedKeys);\n for (let key of selectedKeys) {\n selection.delete(key);\n }\n return {\n ...state,\n selectedKeys: selection\n };\n });\n },\n setFilterText(filterText: string) {\n dispatch(state => ({\n ...state,\n filterText\n }));\n },\n insert(index: number, ...values: T[]) {\n dispatch(state => insert(state, index, ...values));\n },\n insertBefore(key: Key, ...values: T[]) {\n dispatch(state => {\n let index = state.items.findIndex(item => getKey?.(item) === key);\n if (index === -1) {\n if (state.items.length === 0) {\n index = 0;\n } else {\n return state;\n }\n }\n\n return insert(state, index, ...values);\n });\n },\n insertAfter(key: Key, ...values: T[]) {\n dispatch(state => {\n let index = state.items.findIndex(item => getKey?.(item) === key);\n if (index === -1) {\n if (state.items.length === 0) {\n index = 0;\n } else {\n return state;\n }\n }\n\n return insert(state, index + 1, ...values);\n });\n },\n prepend(...values: T[]) {\n dispatch(state => insert(state, 0, ...values));\n },\n append(...values: T[]) {\n dispatch(state => insert(state, state.items.length, ...values));\n },\n remove(...keys: Key[]) {\n dispatch(state => {\n let keySet = new Set(keys);\n let items = state.items.filter(item => !keySet.has(getKey!(item)));\n\n let selection: Selection = 'all';\n if (state.selectedKeys !== 'all') {\n selection = new Set(state.selectedKeys);\n for (let key of keys) {\n selection.delete(key);\n }\n }\n if (cursor == null && items.length === 0) {\n selection = new Set();\n }\n\n return {\n ...state,\n items,\n selectedKeys: selection\n };\n });\n },\n removeSelectedItems() {\n dispatch(state => {\n if (state.selectedKeys === 'all') {\n return {\n ...state,\n items: [],\n selectedKeys: new Set()\n };\n }\n\n let selectedKeys = state.selectedKeys;\n let items = state.items.filter(item => !selectedKeys.has(getKey!(item)));\n return {\n ...state,\n items,\n selectedKeys: new Set()\n };\n });\n },\n move(key: Key, toIndex: number) {\n dispatch(state => {\n let index = state.items.findIndex(item => getKey!(item) === key);\n if (index === -1) {\n return state;\n }\n\n let copy = state.items.slice();\n let [item] = copy.splice(index, 1);\n copy.splice(toIndex, 0, item);\n return {\n ...state,\n items: copy\n };\n });\n },\n moveBefore(key: Key, keys: Iterable<Key>) {\n dispatch(state => {\n let toIndex = state.items.findIndex(item => getKey!(item) === key);\n if (toIndex === -1) {\n return state;\n }\n\n // Find indices of keys to move. Sort them so that the order in the list is retained.\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n let indices = keyArray\n .map(key => state.items.findIndex(item => getKey!(item) === key))\n .sort((a, b) => a - b);\n return move(state, indices, toIndex);\n });\n },\n moveAfter(key: Key, keys: Iterable<Key>) {\n dispatch(state => {\n let toIndex = state.items.findIndex(item => getKey!(item) === key);\n if (toIndex === -1) {\n return state;\n }\n\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n let indices = keyArray\n .map(key => state.items.findIndex(item => getKey!(item) === key))\n .sort((a, b) => a - b);\n return move(state, indices, toIndex + 1);\n });\n },\n update(key: Key, newValue: T | ((prev: T) => T)) {\n dispatch(state => {\n let index = state.items.findIndex(item => getKey!(item) === key);\n if (index === -1) {\n return state;\n }\n\n let updatedValue: T;\n if (typeof newValue === 'function') {\n updatedValue = (newValue as (prev: T) => T)(state.items[index]);\n } else {\n updatedValue = newValue;\n }\n\n return {\n ...state,\n items: [...state.items.slice(0, index), updatedValue, ...state.items.slice(index + 1)]\n };\n });\n }\n };\n}\n\nfunction insert<T>(state: ListState<T>, index: number, ...values: T[]): ListState<T> {\n return {\n ...state,\n items: [...state.items.slice(0, index), ...values, ...state.items.slice(index)]\n };\n}\n\nfunction move<T>(state: ListState<T>, indices: number[], toIndex: number): ListState<T> {\n // Shift the target down by the number of items being moved from before the target\n toIndex -= indices.filter(index => index < toIndex).length;\n\n let moves = indices.map(from => ({\n from,\n to: toIndex++\n }));\n\n // Shift later from indices down if they have a larger index\n for (let i = 0; i < moves.length; i++) {\n let a = moves[i].from;\n for (let j = i; j < moves.length; j++) {\n let b = moves[j].from;\n\n if (b > a) {\n moves[j].from--;\n }\n }\n }\n\n // Interleave the moves so they can be applied one by one rather than all at once\n for (let i = 0; i < moves.length; i++) {\n let a = moves[i];\n for (let j = moves.length - 1; j > i; j--) {\n let b = moves[j];\n\n if (b.from < a.to) {\n a.to++;\n } else {\n b.from++;\n }\n }\n }\n\n let copy = state.items.slice();\n for (let move of moves) {\n let [item] = copy.splice(move.from, 1);\n copy.splice(move.to, 0, item);\n }\n\n return {\n ...state,\n items: copy\n };\n}\n"],"names":[],"version":3,"file":"useListData.mjs.map"}