@react-stately/list 3.10.9-nightly.5042 → 3.11.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -1,16 +1,16 @@
1
- import { Collection, Key, Node, CollectionStateBase, SingleSelection } from "@react-types/shared";
1
+ import { Collection, Key, Node, CollectionStateBase, LayoutDelegate, SingleSelection } from "@react-types/shared";
2
2
  import { MultipleSelectionStateProps, SelectionManager } from "@react-stately/selection";
3
3
  export class ListCollection<T> implements Collection<Node<T>> {
4
4
  constructor(nodes: Iterable<Node<T>>);
5
5
  [Symbol.iterator](): Generator<Node<T>, void, undefined>;
6
6
  get size(): number;
7
7
  getKeys(): IterableIterator<Key>;
8
- getKeyBefore(key: Key): Key;
9
- getKeyAfter(key: Key): Key;
10
- getFirstKey(): Key;
11
- getLastKey(): Key;
12
- getItem(key: Key): Node<T>;
13
- at(idx: number): Node<T>;
8
+ getKeyBefore(key: Key): Key | null;
9
+ getKeyAfter(key: Key): Key | null;
10
+ getFirstKey(): Key | null;
11
+ getLastKey(): Key | null;
12
+ getItem(key: Key): Node<T> | null;
13
+ at(idx: number): Node<T> | null;
14
14
  getChildren(key: Key): Iterable<Node<T>>;
15
15
  }
16
16
  export interface ListProps<T> extends CollectionStateBase<T>, MultipleSelectionStateProps {
@@ -18,6 +18,11 @@ export interface ListProps<T> extends CollectionStateBase<T>, MultipleSelectionS
18
18
  filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>;
19
19
  /** @private */
20
20
  suppressTextValueWarning?: boolean;
21
+ /**
22
+ * A delegate object that provides layout information for items in the collection.
23
+ * This can be used to override the behavior of shift selection.
24
+ */
25
+ layoutDelegate?: LayoutDelegate;
21
26
  }
22
27
  export interface ListState<T> {
23
28
  /** A collection of items in the list. */
@@ -1 +1 @@
1
- {"mappings":";;AAcA,4BAA4B,CAAC,CAAE,YAAW,WAAW,KAAK,CAAC,CAAC,CAAC;gBAM/C,KA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f,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;AAED,uCAAuC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC;IAC5D,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,GAAG,GAAG,IAAI,CAAC;IAEjC,6BAA6B;IAC7B,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;IAEtC,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,CAAA;CACtC;AAED;;;GAGG;AACH,yCAAyC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAsCpH","sources":["packages/@react-stately/list/src/packages/@react-stately/list/src/ListCollection.ts","packages/@react-stately/list/src/packages/@react-stately/list/src/useListState.ts","packages/@react-stately/list/src/packages/@react-stately/list/src/useSingleSelectListState.ts","packages/@react-stately/list/src/packages/@react-stately/list/src/index.ts","packages/@react-stately/list/src/index.ts"],"sourcesContent":[null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;AAcA,4BAA4B,CAAC,CAAE,YAAW,WAAW,KAAK,CAAC,CAAC,CAAC;gBAM/C,KAAK,EAAE,QA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AAC,CAAC,CAAC,CAAC;IACzD,eAAe;IACf,wBAAwB,CAAC,EAAE,OAAO,CAAA;CACnC;AAED,uCAAuC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC;IAC5D,+CAA+C;IAC/C,QAAQ,CAAC,WAAW,EAAE,GAAG,GAAG,IAAI,CAAC;IAEjC,6BAA6B;IAC7B,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;IAEtC,gDAAgD;IAChD,QAAQ,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,CAAA;CACtC;AAED;;;GAGG;AACH,yCAAyC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,sBAAsB,CAAC,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAsCpH","sources":["packages/@react-stately/list/src/packages/@react-stately/list/src/ListCollection.ts","packages/@react-stately/list/src/packages/@react-stately/list/src/useListState.ts","packages/@react-stately/list/src/packages/@react-stately/list/src/useSingleSelectListState.ts","packages/@react-stately/list/src/packages/@react-stately/list/src/index.ts","packages/@react-stately/list/src/index.ts"],"sourcesContent":[null,null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nexport type {ListProps, ListState} from './useListState';\nexport type {SingleSelectListProps, SingleSelectListState} from './useSingleSelectListState';\nexport {useListState} from './useListState';\nexport {useSingleSelectListState} from './useSingleSelectListState';\nexport {ListCollection} from './ListCollection';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -24,7 +24,7 @@ $parcel$export(module.exports, "useListState", () => $5450691d3629f6ea$export$2f
24
24
 
25
25
 
26
26
  function $5450691d3629f6ea$export$2f645645f7bca764(props) {
27
- let { filter: filter } = props;
27
+ let { filter: filter, layoutDelegate: layoutDelegate } = props;
28
28
  let selectionState = (0, $5RsKl$reactstatelyselection.useMultipleSelectionState)(props);
29
29
  let disabledKeys = (0, $5RsKl$react.useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
30
30
  props.disabledKeys
@@ -38,9 +38,12 @@ function $5450691d3629f6ea$export$2f645645f7bca764(props) {
38
38
  props.suppressTextValueWarning
39
39
  ]);
40
40
  let collection = (0, $5RsKl$reactstatelycollections.useCollection)(props, factory, context);
41
- let selectionManager = (0, $5RsKl$react.useMemo)(()=>new (0, $5RsKl$reactstatelyselection.SelectionManager)(collection, selectionState), [
41
+ let selectionManager = (0, $5RsKl$react.useMemo)(()=>new (0, $5RsKl$reactstatelyselection.SelectionManager)(collection, selectionState, {
42
+ layoutDelegate: layoutDelegate
43
+ }), [
42
44
  collection,
43
- selectionState
45
+ selectionState,
46
+ layoutDelegate
44
47
  ]);
45
48
  // Reset focused key if that item is deleted from the collection.
46
49
  const cachedCollection = (0, $5RsKl$react.useRef)(null);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA8BM,SAAS,0CAA+B,KAAmB;IAChE,IAAI,UAAC,MAAM,EAAC,GAAG;IAEf,IAAI,iBAAiB,CAAA,GAAA,sDAAwB,EAAE;IAC/C,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IACzB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OACvD;QAAC,MAAM,YAAY;KAAC;IAEtB,IAAI,UAAU,CAAA,GAAA,wBAAU,EAAE,CAAA,QAAS,SAAS,IAAI,CAAA,GAAA,wCAAa,EAAE,OAAO,UAAU,IAAI,CAAA,GAAA,wCAAa,EAAE,QAA6B;QAAC;KAAO;IACxI,IAAI,UAAU,CAAA,GAAA,oBAAM,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,OAAO,IACP,KAAK,GAAG,CAAC,AAAC,CAAA,CAAA,mBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,8BAAA,mBAAoB,CAAA,IAAK,OAAO,GAAG,KAC7C,CAAA,oBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,+BAAA,oBAAoB,GAEtB,AAAC,CAAA,CAAA,qBAAA,sBAAA,gCAAA,UAAW,MAAM,cAAjB,gCAAA,qBAAqB,CAAA,IAAK;YAC7B,IAAI,UAA0B;YAC9B,IAAI,qBAAqB;YACzB,MAAO,SAAS,EAAG;gBACjB,IAAI,CAAC,iBAAiB,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,GAAG;oBACtD,UAAU,SAAS,CAAC,MAAM;oBAC1B;gBACF;gBACA,gCAAgC;gBAChC,IAAI,QAAQ,UAAU,MAAM,GAAG,KAAK,CAAC,oBACnC;qBAEK;oBACL,qBAAqB;wBACR,mBACF;oBADX,IAAI,QAAS,CAAA,CAAA,oBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,+BAAA,oBAAoB,CAAA,GAC/B,QAAS,CAAA,oBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,+BAAA,oBAAoB;oBAE/B;gBACF;YACF;YACA,eAAe,aAAa,CAAC,UAAU,QAAQ,GAAG,GAAG;QACvD;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;0BACA;IACF;AACF","sources":["packages/@react-stately/list/src/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, Node} from '@react-types/shared';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCallback, useEffect, useMemo, useRef} from 'react';\nimport {useCollection} from '@react-stately/collections';\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\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 extends object>(props: ListProps<T>): ListState<T> {\n let {filter} = 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 let factory = useCallback(nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>), [filter]);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n let collection = useCollection(props, factory, context);\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\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 (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey) && cachedCollection.current) {\n const startItem = cachedCollection.current.getItem(selectionState.focusedKey);\n const cachedItemNodes = [...cachedCollection.current.getKeys()].map(\n key => {\n const itemNode = cachedCollection.current!.getItem(key);\n return itemNode?.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const itemNodes = [...collection.getKeys()].map(\n key => {\n const itemNode = collection.getItem(key);\n return itemNode?.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const diff: number = (cachedItemNodes?.length ?? 0) - (itemNodes?.length ?? 0);\n let index = Math.min(\n (\n diff > 1 ?\n Math.max((startItem?.index ?? 0) - diff + 1, 0) :\n startItem?.index ?? 0\n ),\n (itemNodes?.length ?? 0) - 1);\n let newNode: Node<T> | null = null;\n let isReverseSearching = false;\n while (index >= 0) {\n if (!selectionManager.isDisabled(itemNodes[index].key)) {\n newNode = itemNodes[index];\n break;\n }\n // Find next, not disabled item.\n if (index < itemNodes.length - 1 && !isReverseSearching) {\n index++;\n // Otherwise, find previous, not disabled item.\n } else {\n isReverseSearching = true;\n if (index > (startItem?.index ?? 0)) {\n index = (startItem?.index ?? 0);\n }\n index--;\n }\n }\n selectionState.setFocusedKey(newNode ? newNode.key : null);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useListState.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAmCM,SAAS,0CAA+B,KAAmB;IAChE,IAAI,UAAC,MAAM,kBAAE,cAAc,EAAC,GAAG;IAE/B,IAAI,iBAAiB,CAAA,GAAA,sDAAwB,EAAE;IAC/C,IAAI,eAAe,CAAA,GAAA,oBAAM,EAAE,IACzB,MAAM,YAAY,GAAG,IAAI,IAAI,MAAM,YAAY,IAAI,IAAI,OACvD;QAAC,MAAM,YAAY;KAAC;IAEtB,IAAI,UAAU,CAAA,GAAA,wBAAU,EAAE,CAAA,QAAS,SAAS,IAAI,CAAA,GAAA,wCAAa,EAAE,OAAO,UAAU,IAAI,CAAA,GAAA,wCAAa,EAAE,QAA6B;QAAC;KAAO;IACxI,IAAI,UAAU,CAAA,GAAA,oBAAM,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I,QAAQ,KAAK,GAAG,CAEhB,OAAO,IACP,KAAK,GAAG,CAAC,AAAC,CAAA,CAAA,mBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,8BAAA,mBAAoB,CAAA,IAAK,OAAO,GAAG,KAC7C,CAAA,oBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,+BAAA,oBAAoB,GAEtB,AAAC,CAAA,CAAA,qBAAA,sBAAA,gCAAA,UAAW,MAAM,cAAjB,gCAAA,qBAAqB,CAAA,IAAK;YAC7B,IAAI,UAA0B;YAC9B,IAAI,qBAAqB;YACzB,MAAO,SAAS,EAAG;gBACjB,IAAI,CAAC,iBAAiB,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,GAAG;oBACtD,UAAU,SAAS,CAAC,MAAM;oBAC1B;gBACF;gBACA,gCAAgC;gBAChC,IAAI,QAAQ,UAAU,MAAM,GAAG,KAAK,CAAC,oBACnC;qBAEK;oBACL,qBAAqB;wBACR,mBACF;oBADX,IAAI,QAAS,CAAA,CAAA,oBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,+BAAA,oBAAoB,CAAA,GAC/B,QAAS,CAAA,oBAAA,sBAAA,gCAAA,UAAW,KAAK,cAAhB,+BAAA,oBAAoB;oBAE/B;gBACF;YACF;YACA,eAAe,aAAa,CAAC,UAAU,QAAQ,GAAG,GAAG;QACvD;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;0BACA;IACF;AACF","sources":["packages/@react-stately/list/src/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 {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCallback, useEffect, useMemo, useRef} from 'react';\nimport {useCollection} from '@react-stately/collections';\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 extends object>(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 let factory = useCallback(nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>), [filter]);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\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 // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<Collection<Node<T>> | null>(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey) && cachedCollection.current) {\n const startItem = cachedCollection.current.getItem(selectionState.focusedKey);\n const cachedItemNodes = [...cachedCollection.current.getKeys()].map(\n key => {\n const itemNode = cachedCollection.current!.getItem(key);\n return itemNode?.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const itemNodes = [...collection.getKeys()].map(\n key => {\n const itemNode = collection.getItem(key);\n return itemNode?.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const diff: number = (cachedItemNodes?.length ?? 0) - (itemNodes?.length ?? 0);\n let index = Math.min(\n (\n diff > 1 ?\n Math.max((startItem?.index ?? 0) - diff + 1, 0) :\n startItem?.index ?? 0\n ),\n (itemNodes?.length ?? 0) - 1);\n let newNode: Node<T> | null = null;\n let isReverseSearching = false;\n while (index >= 0) {\n if (!selectionManager.isDisabled(itemNodes[index].key)) {\n newNode = itemNodes[index];\n break;\n }\n // Find next, not disabled item.\n if (index < itemNodes.length - 1 && !isReverseSearching) {\n index++;\n // Otherwise, find previous, not disabled item.\n } else {\n isReverseSearching = true;\n if (index > (startItem?.index ?? 0)) {\n index = (startItem?.index ?? 0);\n }\n index--;\n }\n }\n selectionState.setFocusedKey(newNode ? newNode.key : null);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useListState.main.js.map"}
@@ -18,7 +18,7 @@ import {useCollection as $d5vlZ$useCollection} from "@react-stately/collections"
18
18
 
19
19
 
20
20
  function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
21
- let { filter: filter } = props;
21
+ let { filter: filter, layoutDelegate: layoutDelegate } = props;
22
22
  let selectionState = (0, $d5vlZ$useMultipleSelectionState)(props);
23
23
  let disabledKeys = (0, $d5vlZ$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
24
24
  props.disabledKeys
@@ -32,9 +32,12 @@ function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
32
32
  props.suppressTextValueWarning
33
33
  ]);
34
34
  let collection = (0, $d5vlZ$useCollection)(props, factory, context);
35
- let selectionManager = (0, $d5vlZ$useMemo)(()=>new (0, $d5vlZ$SelectionManager)(collection, selectionState), [
35
+ let selectionManager = (0, $d5vlZ$useMemo)(()=>new (0, $d5vlZ$SelectionManager)(collection, selectionState, {
36
+ layoutDelegate: layoutDelegate
37
+ }), [
36
38
  collection,
37
- selectionState
39
+ selectionState,
40
+ layoutDelegate
38
41
  ]);
39
42
  // Reset focused key if that item is deleted from the collection.
40
43
  const cachedCollection = (0, $d5vlZ$useRef)(null);
@@ -18,7 +18,7 @@ import {useCollection as $d5vlZ$useCollection} from "@react-stately/collections"
18
18
 
19
19
 
20
20
  function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
21
- let { filter: filter } = props;
21
+ let { filter: filter, layoutDelegate: layoutDelegate } = props;
22
22
  let selectionState = (0, $d5vlZ$useMultipleSelectionState)(props);
23
23
  let disabledKeys = (0, $d5vlZ$useMemo)(()=>props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [
24
24
  props.disabledKeys
@@ -32,9 +32,12 @@ function $e72dd72e1c76a225$export$2f645645f7bca764(props) {
32
32
  props.suppressTextValueWarning
33
33
  ]);
34
34
  let collection = (0, $d5vlZ$useCollection)(props, factory, context);
35
- let selectionManager = (0, $d5vlZ$useMemo)(()=>new (0, $d5vlZ$SelectionManager)(collection, selectionState), [
35
+ let selectionManager = (0, $d5vlZ$useMemo)(()=>new (0, $d5vlZ$SelectionManager)(collection, selectionState, {
36
+ layoutDelegate: layoutDelegate
37
+ }), [
36
38
  collection,
37
- selectionState
39
+ selectionState,
40
+ layoutDelegate
38
41
  ]);
39
42
  // Reset focused key if that item is deleted from the collection.
40
43
  const cachedCollection = (0, $d5vlZ$useRef)(null);
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA8BM,SAAS,0CAA+B,KAAmB;IAChE,IAAI,UAA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OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;0BACA;IACF;AACF","sources":["packages/@react-stately/list/src/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, Node} from '@react-types/shared';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCallback, useEffect, useMemo, useRef} from 'react';\nimport {useCollection} from '@react-stately/collections';\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\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 extends object>(props: ListProps<T>): ListState<T> {\n let {filter} = 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 let factory = useCallback(nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>), [filter]);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n let collection = useCollection(props, factory, context);\n\n let selectionManager = useMemo(() =>\n new SelectionManager(collection, selectionState)\n , [collection, selectionState]\n );\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 (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey) && cachedCollection.current) {\n const startItem = cachedCollection.current.getItem(selectionState.focusedKey);\n const cachedItemNodes = [...cachedCollection.current.getKeys()].map(\n key => {\n const itemNode = cachedCollection.current!.getItem(key);\n return itemNode?.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const itemNodes = [...collection.getKeys()].map(\n key => {\n const itemNode = collection.getItem(key);\n return itemNode?.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const diff: number = (cachedItemNodes?.length ?? 0) - (itemNodes?.length ?? 0);\n let index = Math.min(\n (\n diff > 1 ?\n Math.max((startItem?.index ?? 0) - diff + 1, 0) :\n startItem?.index ?? 0\n ),\n (itemNodes?.length ?? 0) - 1);\n let newNode: Node<T> | null = null;\n let isReverseSearching = false;\n while (index >= 0) {\n if (!selectionManager.isDisabled(itemNodes[index].key)) {\n newNode = itemNodes[index];\n break;\n }\n // Find next, not disabled item.\n if (index < itemNodes.length - 1 && !isReverseSearching) {\n index++;\n // Otherwise, find previous, not disabled item.\n } else {\n isReverseSearching = true;\n if (index > (startItem?.index ?? 0)) {\n index = (startItem?.index ?? 0);\n }\n index--;\n }\n }\n selectionState.setFocusedKey(newNode ? newNode.key : null);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useListState.module.js.map"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAmCM,SAAS,0CAA+B,KAAmB;IAChE,IAAI,UAAC,MAAM,kBAAE,cAAc,EAAC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D;QACA,iBAAiB,OAAO,GAAG;IAC7B,GAAG;QAAC;QAAY;QAAkB;QAAgB,eAAe,UAAU;KAAC;IAE5E,OAAO;oBACL;sBACA;0BACA;IACF;AACF","sources":["packages/@react-stately/list/src/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 {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCallback, useEffect, useMemo, useRef} from 'react';\nimport {useCollection} from '@react-stately/collections';\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 extends object>(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 let factory = useCallback(nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>), [filter]);\n let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\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 // Reset focused key if that item is deleted from the collection.\n const cachedCollection = useRef<Collection<Node<T>> | null>(null);\n useEffect(() => {\n if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey) && cachedCollection.current) {\n const startItem = cachedCollection.current.getItem(selectionState.focusedKey);\n const cachedItemNodes = [...cachedCollection.current.getKeys()].map(\n key => {\n const itemNode = cachedCollection.current!.getItem(key);\n return itemNode?.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const itemNodes = [...collection.getKeys()].map(\n key => {\n const itemNode = collection.getItem(key);\n return itemNode?.type === 'item' ? itemNode : null;\n }\n ).filter(node => node !== null);\n const diff: number = (cachedItemNodes?.length ?? 0) - (itemNodes?.length ?? 0);\n let index = Math.min(\n (\n diff > 1 ?\n Math.max((startItem?.index ?? 0) - diff + 1, 0) :\n startItem?.index ?? 0\n ),\n (itemNodes?.length ?? 0) - 1);\n let newNode: Node<T> | null = null;\n let isReverseSearching = false;\n while (index >= 0) {\n if (!selectionManager.isDisabled(itemNodes[index].key)) {\n newNode = itemNodes[index];\n break;\n }\n // Find next, not disabled item.\n if (index < itemNodes.length - 1 && !isReverseSearching) {\n index++;\n // Otherwise, find previous, not disabled item.\n } else {\n isReverseSearching = true;\n if (index > (startItem?.index ?? 0)) {\n index = (startItem?.index ?? 0);\n }\n index--;\n }\n }\n selectionState.setFocusedKey(newNode ? newNode.key : null);\n }\n cachedCollection.current = collection;\n }, [collection, selectionManager, selectionState, selectionState.focusedKey]);\n\n return {\n collection,\n disabledKeys,\n selectionManager\n };\n}\n"],"names":[],"version":3,"file":"useListState.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/list",
3
- "version": "3.10.9-nightly.5042+68403fe55",
3
+ "version": "3.11.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,17 +22,17 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-stately/collections": "3.0.0-nightly.3114+68403fe55",
26
- "@react-stately/selection": "3.0.0-nightly.3114+68403fe55",
27
- "@react-stately/utils": "3.0.0-nightly.3114+68403fe55",
28
- "@react-types/shared": "3.0.0-nightly.3114+68403fe55",
25
+ "@react-stately/collections": "^3.12.0",
26
+ "@react-stately/selection": "^3.18.0",
27
+ "@react-stately/utils": "^3.10.5",
28
+ "@react-types/shared": "^3.26.0",
29
29
  "@swc/helpers": "^0.5.0"
30
30
  },
31
31
  "peerDependencies": {
32
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
32
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "68403fe55489dce3de1b3094c957d598ad719861"
37
+ "gitHead": "71f0ef23053f9e03ee7e97df736e8b083e006849"
38
38
  }
@@ -10,7 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import {Collection, CollectionStateBase, Key, Node} from '@react-types/shared';
13
+ import {Collection, CollectionStateBase, Key, LayoutDelegate, Node} from '@react-types/shared';
14
14
  import {ListCollection} from './ListCollection';
15
15
  import {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';
16
16
  import {useCallback, useEffect, useMemo, useRef} from 'react';
@@ -20,7 +20,12 @@ export interface ListProps<T> extends CollectionStateBase<T>, MultipleSelectionS
20
20
  /** Filter function to generate a filtered list of nodes. */
21
21
  filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,
22
22
  /** @private */
23
- suppressTextValueWarning?: boolean
23
+ suppressTextValueWarning?: boolean,
24
+ /**
25
+ * A delegate object that provides layout information for items in the collection.
26
+ * This can be used to override the behavior of shift selection.
27
+ */
28
+ layoutDelegate?: LayoutDelegate
24
29
  }
25
30
 
26
31
  export interface ListState<T> {
@@ -39,7 +44,7 @@ export interface ListState<T> {
39
44
  * of items from props, and manages multiple selection state.
40
45
  */
41
46
  export function useListState<T extends object>(props: ListProps<T>): ListState<T> {
42
- let {filter} = props;
47
+ let {filter, layoutDelegate} = props;
43
48
 
44
49
  let selectionState = useMultipleSelectionState(props);
45
50
  let disabledKeys = useMemo(() =>
@@ -52,8 +57,8 @@ export function useListState<T extends object>(props: ListProps<T>): ListState<T
52
57
  let collection = useCollection(props, factory, context);
53
58
 
54
59
  let selectionManager = useMemo(() =>
55
- new SelectionManager(collection, selectionState)
56
- , [collection, selectionState]
60
+ new SelectionManager(collection, selectionState, {layoutDelegate})
61
+ , [collection, selectionState, layoutDelegate]
57
62
  );
58
63
 
59
64
  // Reset focused key if that item is deleted from the collection.