@react-stately/collections 3.12.10 → 3.13.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.
- package/dist/import.mjs +7 -7
- package/dist/main.js +16 -16
- package/dist/main.js.map +1 -1
- package/dist/module.js +7 -7
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +7 -0
- package/package.json +17 -13
- package/src/index.ts +8 -7
- package/dist/CollectionBuilder.main.js +0 -223
- package/dist/CollectionBuilder.main.js.map +0 -1
- package/dist/CollectionBuilder.mjs +0 -214
- package/dist/CollectionBuilder.module.js +0 -214
- package/dist/CollectionBuilder.module.js.map +0 -1
- package/dist/Item.main.js +0 -68
- package/dist/Item.main.js.map +0 -1
- package/dist/Item.mjs +0 -59
- package/dist/Item.module.js +0 -59
- package/dist/Item.module.js.map +0 -1
- package/dist/Section.main.js +0 -60
- package/dist/Section.main.js.map +0 -1
- package/dist/Section.mjs +0 -51
- package/dist/Section.module.js +0 -51
- package/dist/Section.module.js.map +0 -1
- package/dist/getChildNodes.main.js +0 -81
- package/dist/getChildNodes.main.js.map +0 -1
- package/dist/getChildNodes.mjs +0 -72
- package/dist/getChildNodes.module.js +0 -72
- package/dist/getChildNodes.module.js.map +0 -1
- package/dist/getItemCount.main.js +0 -38
- package/dist/getItemCount.main.js.map +0 -1
- package/dist/getItemCount.mjs +0 -33
- package/dist/getItemCount.module.js +0 -33
- package/dist/getItemCount.module.js.map +0 -1
- package/dist/types.d.ts +0 -36
- package/dist/types.d.ts.map +0 -1
- package/dist/useCollection.main.js +0 -44
- package/dist/useCollection.main.js.map +0 -1
- package/dist/useCollection.mjs +0 -39
- package/dist/useCollection.module.js +0 -39
- package/dist/useCollection.module.js.map +0 -1
- package/src/CollectionBuilder.ts +0 -283
- package/src/Item.ts +0 -80
- package/src/Section.ts +0 -59
- package/src/getChildNodes.ts +0 -95
- package/src/getItemCount.ts +0 -39
- package/src/types.ts +0 -31
- package/src/useCollection.ts +0 -34
package/src/getItemCount.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {Collection, Node} from '@react-types/shared';
|
|
14
|
-
import {getChildNodes} from './getChildNodes';
|
|
15
|
-
|
|
16
|
-
const cache = new WeakMap<Iterable<unknown>, number>();
|
|
17
|
-
|
|
18
|
-
export function getItemCount<T>(collection: Collection<Node<T>>): number {
|
|
19
|
-
let count = cache.get(collection);
|
|
20
|
-
if (count != null) {
|
|
21
|
-
return count;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// TS isn't smart enough to know we've ensured count is a number, so use a new variable
|
|
25
|
-
let counter = 0;
|
|
26
|
-
let countItems = (items: Iterable<Node<T>>) => {
|
|
27
|
-
for (let item of items) {
|
|
28
|
-
if (item.type === 'section') {
|
|
29
|
-
countItems(getChildNodes(item, collection));
|
|
30
|
-
} else if (item.type === 'item') {
|
|
31
|
-
counter++;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
countItems(collection);
|
|
37
|
-
cache.set(collection, counter);
|
|
38
|
-
return counter;
|
|
39
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {Key} from '@react-types/shared';
|
|
14
|
-
import {ReactElement, ReactNode} from 'react';
|
|
15
|
-
|
|
16
|
-
export interface PartialNode<T> {
|
|
17
|
-
type?: string,
|
|
18
|
-
key?: Key | null,
|
|
19
|
-
value?: T,
|
|
20
|
-
element?: ReactElement | null,
|
|
21
|
-
wrapper?: (element: ReactElement) => ReactElement,
|
|
22
|
-
rendered?: ReactNode,
|
|
23
|
-
textValue?: string,
|
|
24
|
-
'aria-label'?: string,
|
|
25
|
-
index?: number,
|
|
26
|
-
renderer?: (item: T) => ReactElement | null,
|
|
27
|
-
hasChildNodes?: boolean,
|
|
28
|
-
childNodes?: () => IterableIterator<PartialNode<T>>,
|
|
29
|
-
props?: any,
|
|
30
|
-
shouldInvalidate?: (context: any) => boolean
|
|
31
|
-
}
|
package/src/useCollection.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {Collection, CollectionStateBase, Node} from '@react-types/shared';
|
|
14
|
-
import {CollectionBuilder} from './CollectionBuilder';
|
|
15
|
-
import {ReactElement, useMemo} from 'react';
|
|
16
|
-
|
|
17
|
-
interface CollectionOptions<T, C extends Collection<Node<T>>> extends Omit<CollectionStateBase<T, C>, 'children'> {
|
|
18
|
-
children?: ReactElement<any> | null | (ReactElement<any> | null)[] | ((item: T) => ReactElement<any> | null)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type CollectionFactory<T, C extends Collection<Node<T>>> = (node: Iterable<Node<T>>) => C;
|
|
22
|
-
|
|
23
|
-
export function useCollection<T extends object, C extends Collection<Node<T>> = Collection<Node<T>>>(props: CollectionOptions<T, C>, factory: CollectionFactory<T, C>, context?: unknown): C {
|
|
24
|
-
let builder = useMemo(() => new CollectionBuilder<T>(), []);
|
|
25
|
-
let {children, items, collection} = props;
|
|
26
|
-
let result = useMemo(() => {
|
|
27
|
-
if (collection) {
|
|
28
|
-
return collection;
|
|
29
|
-
}
|
|
30
|
-
let nodes = builder.build({children, items}, context);
|
|
31
|
-
return factory(nodes);
|
|
32
|
-
}, [builder, children, items, collection, context, factory]);
|
|
33
|
-
return result;
|
|
34
|
-
}
|