@react-stately/list
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -41,2 +41,4 @@ var { | ||
constructor(nodes) { | ||
var _last; | ||
this.keyMap = new Map(); | ||
@@ -71,2 +73,3 @@ this.iterable = void 0; | ||
this.firstKey = key; | ||
node.prevKey = undefined; | ||
} | ||
@@ -78,8 +81,9 @@ | ||
last = node; | ||
last = node; // Set nextKey as undefined since this might be the last node | ||
// If it isn't the last node, last.nextKey will properly set at start of new loop | ||
last.nextKey = undefined; | ||
} | ||
if (last) { | ||
this.lastKey = last.key; | ||
} | ||
this.lastKey = (_last = last) == null ? void 0 : _last.key; | ||
} | ||
@@ -128,6 +132,12 @@ | ||
function useListState(props) { | ||
let { | ||
filter | ||
} = props; | ||
let selectionState = useMultipleSelectionState(props); | ||
let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]); | ||
let collection = useCollection(props, nodes => new $b42f1d5166481a4c34c86bbfb4215e1$export$ListCollection(nodes)); // Reset focused key if that item is deleted from the collection. | ||
let factory = nodes => filter ? new $b42f1d5166481a4c34c86bbfb4215e1$export$ListCollection(filter(nodes)) : new $b42f1d5166481a4c34c86bbfb4215e1$export$ListCollection(nodes); | ||
let collection = useCollection(props, factory, null, [filter]); // Reset focused key if that item is deleted from the collection. | ||
useEffect(() => { | ||
@@ -134,0 +144,0 @@ if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) { |
@@ -22,2 +22,4 @@ import { useControlledState } from "@react-stately/utils"; | ||
constructor(nodes) { | ||
var _last; | ||
this.keyMap = new Map(); | ||
@@ -52,2 +54,3 @@ this.iterable = void 0; | ||
this.firstKey = key; | ||
node.prevKey = undefined; | ||
} | ||
@@ -59,8 +62,9 @@ | ||
last = node; | ||
last = node; // Set nextKey as undefined since this might be the last node | ||
// If it isn't the last node, last.nextKey will properly set at start of new loop | ||
last.nextKey = undefined; | ||
} | ||
if (last) { | ||
this.lastKey = last.key; | ||
} | ||
this.lastKey = (_last = last) == null ? void 0 : _last.key; | ||
} | ||
@@ -109,6 +113,12 @@ | ||
export function useListState(props) { | ||
let { | ||
filter | ||
} = props; | ||
let selectionState = useMultipleSelectionState(props); | ||
let disabledKeys = useMemo(() => props.disabledKeys ? new Set(props.disabledKeys) : new Set(), [props.disabledKeys]); | ||
let collection = useCollection(props, nodes => new $ed5d55e571caf578a4f08babbaa26be$export$ListCollection(nodes)); // Reset focused key if that item is deleted from the collection. | ||
let factory = nodes => filter ? new $ed5d55e571caf578a4f08babbaa26be$export$ListCollection(filter(nodes)) : new $ed5d55e571caf578a4f08babbaa26be$export$ListCollection(nodes); | ||
let collection = useCollection(props, factory, null, [filter]); // Reset focused key if that item is deleted from the collection. | ||
useEffect(() => { | ||
@@ -115,0 +125,0 @@ if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) { |
@@ -5,2 +5,4 @@ import { Collection, CollectionBase, MultipleSelection, Node, SingleSelection } from "@react-types/shared"; | ||
export interface ListProps<T> extends CollectionBase<T>, MultipleSelection { | ||
/** Filter function to generate a filtered list of nodes. */ | ||
filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>; | ||
} | ||
@@ -21,2 +23,4 @@ export interface ListState<T> { | ||
export interface SingleSelectListProps<T> extends CollectionBase<T>, SingleSelection { | ||
/** Filter function to generate a filtered list of nodes. */ | ||
filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>; | ||
} | ||
@@ -23,0 +27,0 @@ export interface SingleSelectListState<T> extends ListState<T> { |
{ | ||
"name": "@react-stately/list", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "Spectrum UI components in React", | ||
@@ -21,6 +21,6 @@ "license": "Apache-2.0", | ||
"@babel/runtime": "^7.6.2", | ||
"@react-stately/collections": "^3.1.0", | ||
"@react-stately/selection": "^3.1.0", | ||
"@react-stately/collections": "^3.2.0", | ||
"@react-stately/selection": "^3.2.0", | ||
"@react-stately/utils": "^3.1.0", | ||
"@react-types/shared": "^3.1.0" | ||
"@react-types/shared": "^3.2.0" | ||
}, | ||
@@ -33,3 +33,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "211099972fe75ee581892efd01a7f89dfb9cdf69" | ||
"gitHead": "661f0f2e3b8648a75aae83043267954700059fe0" | ||
} |
@@ -47,2 +47,3 @@ /* | ||
this.firstKey = key; | ||
node.prevKey = undefined; | ||
} | ||
@@ -55,7 +56,9 @@ | ||
last = node; | ||
// Set nextKey as undefined since this might be the last node | ||
// If it isn't the last node, last.nextKey will properly set at start of new loop | ||
last.nextKey = undefined; | ||
} | ||
if (last) { | ||
this.lastKey = last.key; | ||
} | ||
this.lastKey = last?.key; | ||
} | ||
@@ -62,0 +65,0 @@ |
@@ -19,3 +19,6 @@ /* | ||
export interface ListProps<T> extends CollectionBase<T>, MultipleSelection {} | ||
export interface ListProps<T> extends CollectionBase<T>, MultipleSelection { | ||
/** Filter function to generate a filtered list of nodes. */ | ||
filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>> | ||
} | ||
export interface ListState<T> { | ||
@@ -37,2 +40,6 @@ /** A collection of items in the list. */ | ||
export function useListState<T extends object>(props: ListProps<T>): ListState<T> { | ||
let { | ||
filter | ||
} = props; | ||
let selectionState = useMultipleSelectionState(props); | ||
@@ -43,4 +50,6 @@ let disabledKeys = useMemo(() => | ||
let collection = useCollection(props, nodes => new ListCollection(nodes)); | ||
let factory = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>); | ||
let collection = useCollection(props, factory, null, [filter]); | ||
// Reset focused key if that item is deleted from the collection. | ||
@@ -47,0 +56,0 @@ useEffect(() => { |
@@ -19,3 +19,6 @@ /* | ||
export interface SingleSelectListProps<T> extends CollectionBase<T>, SingleSelection {} | ||
export interface SingleSelectListProps<T> extends CollectionBase<T>, SingleSelection { | ||
/** Filter function to generate a filtered list of nodes. */ | ||
filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>> | ||
} | ||
export interface SingleSelectListState<T> extends ListState<T> { | ||
@@ -22,0 +25,0 @@ /** The key for the currently selected item. */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59875
542