@react-aria/collections 3.0.2 → 3.1.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.
Files changed (40) hide show
  1. package/dist/import.mjs +7 -5
  2. package/dist/main.js +20 -18
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +7 -5
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +8 -0
  7. package/package.json +14 -15
  8. package/src/index.ts +8 -7
  9. package/dist/BaseCollection.main.js +0 -271
  10. package/dist/BaseCollection.main.js.map +0 -1
  11. package/dist/BaseCollection.mjs +0 -260
  12. package/dist/BaseCollection.module.js +0 -260
  13. package/dist/BaseCollection.module.js.map +0 -1
  14. package/dist/CollectionBuilder.main.js +0 -242
  15. package/dist/CollectionBuilder.main.js.map +0 -1
  16. package/dist/CollectionBuilder.mjs +0 -230
  17. package/dist/CollectionBuilder.module.js +0 -230
  18. package/dist/CollectionBuilder.module.js.map +0 -1
  19. package/dist/Document.main.js +0 -367
  20. package/dist/Document.main.js.map +0 -1
  21. package/dist/Document.mjs +0 -362
  22. package/dist/Document.module.js +0 -362
  23. package/dist/Document.module.js.map +0 -1
  24. package/dist/Hidden.main.js +0 -72
  25. package/dist/Hidden.main.js.map +0 -1
  26. package/dist/Hidden.mjs +0 -61
  27. package/dist/Hidden.module.js +0 -61
  28. package/dist/Hidden.module.js.map +0 -1
  29. package/dist/types.d.ts +0 -114
  30. package/dist/types.d.ts.map +0 -1
  31. package/dist/useCachedChildren.main.js +0 -61
  32. package/dist/useCachedChildren.main.js.map +0 -1
  33. package/dist/useCachedChildren.mjs +0 -56
  34. package/dist/useCachedChildren.module.js +0 -56
  35. package/dist/useCachedChildren.module.js.map +0 -1
  36. package/src/BaseCollection.ts +0 -353
  37. package/src/CollectionBuilder.tsx +0 -265
  38. package/src/Document.ts +0 -562
  39. package/src/Hidden.tsx +0 -76
  40. package/src/useCachedChildren.ts +0 -70
package/dist/types.d.ts DELETED
@@ -1,114 +0,0 @@
1
- import { Collection as _Collection1, Key, Node } from "@react-types/shared";
2
- import React, { ReactElement, ReactNode, ForwardedRef, JSX } from "react";
3
- type FilterFn<T> = (textValue: string, node: Node<T>) => boolean;
4
- /** An immutable object representing a Node in a Collection. */
5
- export class CollectionNode<T> implements Node<T> {
6
- static readonly type: string;
7
- readonly type: string;
8
- readonly key: Key;
9
- readonly value: T | null;
10
- readonly level: number;
11
- readonly hasChildNodes: boolean;
12
- readonly rendered: ReactNode;
13
- readonly textValue: string;
14
- readonly 'aria-label'?: string;
15
- readonly index: number;
16
- readonly parentKey: Key | null;
17
- readonly prevKey: Key | null;
18
- readonly nextKey: Key | null;
19
- readonly firstChildKey: Key | null;
20
- readonly lastChildKey: Key | null;
21
- readonly props: any;
22
- readonly render?: (node: Node<any>) => ReactElement;
23
- readonly colSpan: number | null;
24
- readonly colIndex: number | null;
25
- constructor(key: Key);
26
- get childNodes(): Iterable<Node<T>>;
27
- clone(): this;
28
- filter(collection: BaseCollection<T>, newCollection: BaseCollection<T>, filterFn: FilterFn<T>): CollectionNode<T> | null;
29
- }
30
- export class FilterableNode<T> extends CollectionNode<T> {
31
- filter(collection: BaseCollection<T>, newCollection: BaseCollection<T>, filterFn: FilterFn<T>): CollectionNode<T> | null;
32
- }
33
- export class HeaderNode extends CollectionNode<unknown> {
34
- static readonly type = "header";
35
- }
36
- export class LoaderNode extends CollectionNode<unknown> {
37
- static readonly type = "loader";
38
- }
39
- export class ItemNode<T> extends FilterableNode<T> {
40
- static readonly type = "item";
41
- filter(collection: BaseCollection<T>, newCollection: BaseCollection<T>, filterFn: FilterFn<T>): ItemNode<T> | null;
42
- }
43
- export class SectionNode<T> extends FilterableNode<T> {
44
- static readonly type = "section";
45
- filter(collection: BaseCollection<T>, newCollection: BaseCollection<T>, filterFn: FilterFn<T>): SectionNode<T> | null;
46
- }
47
- /**
48
- * An immutable Collection implementation. Updates are only allowed
49
- * when it is not marked as frozen. This can be subclassed to implement
50
- * custom collection behaviors.
51
- */
52
- export class BaseCollection<T> implements _Collection1<Node<T>> {
53
- get size(): number;
54
- getKeys(): IterableIterator<Key>;
55
- [Symbol.iterator](): IterableIterator<Node<T>>;
56
- getChildren(key: Key): Iterable<Node<T>>;
57
- getKeyBefore(key: Key): Key | null;
58
- getKeyAfter(key: Key): Key | null;
59
- getFirstKey(): Key | null;
60
- getLastKey(): Key | null;
61
- getItem(key: Key): Node<T> | null;
62
- at(): Node<T>;
63
- clone(): this;
64
- addNode(node: CollectionNode<T>): void;
65
- addDescendants(node: CollectionNode<T>, oldCollection: BaseCollection<T>): void;
66
- removeNode(key: Key): void;
67
- commit(firstKey: Key | null, lastKey: Key | null, isSSR?: boolean): void;
68
- filter(filterFn: FilterFn<T>): this;
69
- }
70
- export interface CachedChildrenOptions<T> {
71
- /** Item objects in the collection. */
72
- items?: Iterable<T>;
73
- /** The contents of the collection. */
74
- children?: ReactNode | ((item: T) => ReactNode);
75
- /** Values that should invalidate the item cache when using dynamic collections. */
76
- dependencies?: ReadonlyArray<any>;
77
- /** A scope to prepend to all child item ids to ensure they are unique. */
78
- idScope?: Key;
79
- /** Whether to add `id` and `value` props to all child items. */
80
- addIdAndValue?: boolean;
81
- }
82
- /**
83
- * Maps over a list of items and renders React elements for them. Each rendered item is
84
- * cached based on object identity, and React keys are generated from the `key` or `id` property.
85
- */
86
- export function useCachedChildren<T extends object>(props: CachedChildrenOptions<T>): ReactNode;
87
- /** Creates a component that forwards its ref and returns null if it is in a hidden subtree. */
88
- export function createHideableComponent<T, P = {}>(fn: (props: P, ref: React.Ref<T>) => ReactElement | null): (props: P & React.RefAttributes<T>) => ReactElement | null;
89
- /** Returns whether the component is in a hidden subtree. */
90
- export function useIsHidden(): boolean;
91
- export interface CollectionBuilderProps<C extends BaseCollection<object>> {
92
- content: ReactNode;
93
- children: (collection: C) => ReactNode;
94
- createCollection?: () => C;
95
- }
96
- /**
97
- * Builds a `Collection` from the children provided to the `content` prop, and passes it to the child render prop function.
98
- */
99
- export function CollectionBuilder<C extends BaseCollection<object>>(props: CollectionBuilderProps<C>): ReactElement;
100
- type CollectionNodeClass<T> = {
101
- new (key: Key): CollectionNode<T>;
102
- readonly type: string;
103
- };
104
- export function createLeafComponent<T extends object, P extends object, E extends Element>(CollectionNodeClass: CollectionNodeClass<any> | string, render: (props: P, ref: ForwardedRef<E>) => ReactElement | null): (props: P & React.RefAttributes<E>) => ReactElement | null;
105
- export function createLeafComponent<T extends object, P extends object, E extends Element>(CollectionNodeClass: CollectionNodeClass<any> | string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement | null): (props: P & React.RefAttributes<E>) => ReactElement | null;
106
- export function createBranchComponent<T extends object, P extends {
107
- children?: any;
108
- }, E extends Element>(CollectionNodeClass: CollectionNodeClass<any> | string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement | null, useChildren?: (props: P) => ReactNode): (props: P & React.RefAttributes<E>) => ReactElement | null;
109
- export interface CollectionProps<T> extends CachedChildrenOptions<T> {
110
- }
111
- /** A Collection renders a list of items, automatically managing caching and keys. */
112
- export function Collection<T extends object>(props: CollectionProps<T>): JSX.Element;
113
-
114
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAmBA,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,OAAO,CAAC;AAEjE,+DAA+D;AAC/D,4BAA4B,CAAC,CAAE,YAAW,KAAK,CAAC,CAAC;IAC/C,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAQ;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAK;IAC3B,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAS;I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,SAAS;IAAC,QAAQ,CAAC,EAAE,GAAG,CAAA;CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,qBAAqB,oBAAoB,GAAG,CAAC,GAAG,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,YAAY,GAAG,IAAI,EAAE,WAAW,GAAE,CAAC,KAAK,EAAE,CAAC,KAAK,SAAiC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,KAAK,YAAY,GAAG,IAAI,CASvW;AAMD,iCAAiC,CAAC,CAAE,SAAQ,sBAAsB,CAAC,CAAC;CAAG;AAIvE,qFAAqF;AACrF,2BAA2B,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC,GAAG,IAAI,OAAO,CA2BnF","sources":["packages/@react-aria/collections/src/packages/@react-aria/collections/src/BaseCollection.ts","packages/@react-aria/collections/src/packages/@react-aria/collections/src/Document.ts","packages/@react-aria/collections/src/packages/@react-aria/collections/src/useCachedChildren.ts","packages/@react-aria/collections/src/packages/@react-aria/collections/src/Hidden.tsx","packages/@react-aria/collections/src/packages/@react-aria/collections/src/CollectionBuilder.tsx","packages/@react-aria/collections/src/packages/@react-aria/collections/src/index.ts","packages/@react-aria/collections/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,"/*\n * Copyright 2024 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 {CollectionBuilder, Collection, createLeafComponent, createBranchComponent} from './CollectionBuilder';\nexport {createHideableComponent, useIsHidden} from './Hidden';\nexport {useCachedChildren} from './useCachedChildren';\nexport {BaseCollection, CollectionNode, ItemNode, SectionNode, FilterableNode, LoaderNode, HeaderNode} from './BaseCollection';\n\nexport type {CollectionBuilderProps, CollectionProps} from './CollectionBuilder';\nexport type {CachedChildrenOptions} from './useCachedChildren';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -1,61 +0,0 @@
1
- var $6Tq0m$react = require("react");
2
-
3
-
4
- function $parcel$export(e, n, v, s) {
5
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
- }
7
-
8
- $parcel$export(module.exports, "useCachedChildren", () => $245f3f827bea6653$export$727c8fc270210f13);
9
- /*
10
- * Copyright 2024 Adobe. All rights reserved.
11
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License. You may obtain a copy
13
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
- *
15
- * Unless required by applicable law or agreed to in writing, software distributed under
16
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
- * OF ANY KIND, either express or implied. See the License for the specific language
18
- * governing permissions and limitations under the License.
19
- */
20
- function $245f3f827bea6653$export$727c8fc270210f13(props) {
21
- let { children: children, items: items, idScope: idScope, addIdAndValue: addIdAndValue, dependencies: dependencies = [] } = props;
22
- // Invalidate the cache whenever the parent value changes.
23
- // eslint-disable-next-line react-hooks/exhaustive-deps
24
- let cache = (0, $6Tq0m$react.useMemo)(()=>new WeakMap(), dependencies);
25
- return (0, $6Tq0m$react.useMemo)(()=>{
26
- if (items && typeof children === 'function') {
27
- let res = [];
28
- for (let item of items){
29
- let rendered = cache.get(item);
30
- if (!rendered) {
31
- rendered = children(item);
32
- var _rendered_props_id, _ref;
33
- // @ts-ignore
34
- let key = (_ref = (_rendered_props_id = rendered.props.id) !== null && _rendered_props_id !== void 0 ? _rendered_props_id : item.key) !== null && _ref !== void 0 ? _ref : item.id;
35
- if (key == null) throw new Error('Could not determine key for item');
36
- if (idScope != null) key = idScope + ':' + key;
37
- // Note: only works if wrapped Item passes through id...
38
- rendered = (0, $6Tq0m$react.cloneElement)(rendered, addIdAndValue ? {
39
- key: key,
40
- id: key,
41
- value: item
42
- } : {
43
- key: key
44
- });
45
- cache.set(item, rendered);
46
- }
47
- res.push(rendered);
48
- }
49
- return res;
50
- } else if (typeof children !== 'function') return children;
51
- }, [
52
- children,
53
- items,
54
- cache,
55
- idScope,
56
- addIdAndValue
57
- ]);
58
- }
59
-
60
-
61
- //# sourceMappingURL=useCachedChildren.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAsBM,SAAS,0CAAoC,KAA+B;IACjF,IAAI,YAAC,QAAQ,SAAE,KAAK,WAAE,OAAO,iBAAE,aAAa,gBAAE,eAAe,EAAE,EAAC,GAAG;IAEnE,0DAA0D;IAC1D,uDAAuD;IACvD,IAAI,QAAQ,CAAA,GAAA,oBAAM,EAAE,IAAM,IAAI,WAAW;IACzC,OAAO,CAAA,GAAA,oBAAM,EAAE;QACb,IAAI,SAAS,OAAO,aAAa,YAAY;YAC3C,IAAI,MAAsB,EAAE;YAC5B,KAAK,IAAI,QAAQ,MAAO;gBACtB,IAAI,WAAW,MAAM,GAAG,CAAC;gBACzB,IAAI,CAAC,UAAU;oBACb,WAAW,SAAS;wBAEV,oBAAA;oBADV,aAAa;oBACb,IAAI,MAAM,CAAA,OAAA,CAAA,qBAAA,SAAS,KAAK,CAAC,EAAE,cAAjB,gCAAA,qBAAqB,KAAK,GAAG,cAA7B,kBAAA,OAAiC,KAAK,EAAE;oBAElD,IAAI,OAAO,MACT,MAAM,IAAI,MAAM;oBAGlB,IAAI,WAAW,MACb,MAAM,UAAU,MAAM;oBAExB,wDAAwD;oBACxD,WAAW,CAAA,GAAA,yBAAW,EACpB,UACA,gBAAgB;6BAAC;wBAAK,IAAI;wBAAK,OAAO;oBAAI,IAAI;6BAAC;oBAAG;oBAEpD,MAAM,GAAG,CAAC,MAAM;gBAClB;gBACA,IAAI,IAAI,CAAC;YACX;YACA,OAAO;QACT,OAAO,IAAI,OAAO,aAAa,YAC7B,OAAO;IAEX,GAAG;QAAC;QAAU;QAAO;QAAO;QAAS;KAAc;AACrD","sources":["packages/@react-aria/collections/src/useCachedChildren.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {cloneElement, ReactElement, ReactNode, useMemo} from 'react';\nimport {Key} from '@react-types/shared';\n\nexport interface CachedChildrenOptions<T> {\n /** Item objects in the collection. */\n items?: Iterable<T>,\n /** The contents of the collection. */\n children?: ReactNode | ((item: T) => ReactNode),\n /** Values that should invalidate the item cache when using dynamic collections. */\n dependencies?: ReadonlyArray<any>,\n /** A scope to prepend to all child item ids to ensure they are unique. */\n idScope?: Key,\n /** Whether to add `id` and `value` props to all child items. */\n addIdAndValue?: boolean\n}\n\n/**\n * Maps over a list of items and renders React elements for them. Each rendered item is\n * cached based on object identity, and React keys are generated from the `key` or `id` property.\n */\nexport function useCachedChildren<T extends object>(props: CachedChildrenOptions<T>): ReactNode {\n let {children, items, idScope, addIdAndValue, dependencies = []} = props;\n\n // Invalidate the cache whenever the parent value changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n let cache = useMemo(() => new WeakMap(), dependencies);\n return useMemo(() => {\n if (items && typeof children === 'function') {\n let res: ReactElement[] = [];\n for (let item of items) {\n let rendered = cache.get(item);\n if (!rendered) {\n rendered = children(item);\n // @ts-ignore\n let key = rendered.props.id ?? item.key ?? item.id;\n \n if (key == null) {\n throw new Error('Could not determine key for item');\n }\n \n if (idScope != null) {\n key = idScope + ':' + key;\n }\n // Note: only works if wrapped Item passes through id...\n rendered = cloneElement(\n rendered,\n addIdAndValue ? {key, id: key, value: item} : {key}\n );\n cache.set(item, rendered);\n }\n res.push(rendered);\n }\n return res;\n } else if (typeof children !== 'function') {\n return children;\n }\n }, [children, items, cache, idScope, addIdAndValue]);\n}\n"],"names":[],"version":3,"file":"useCachedChildren.main.js.map"}
@@ -1,56 +0,0 @@
1
- import {useMemo as $luMFQ$useMemo, cloneElement as $luMFQ$cloneElement} from "react";
2
-
3
- /*
4
- * Copyright 2024 Adobe. All rights reserved.
5
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License. You may obtain a copy
7
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
- * OF ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
13
- */
14
- function $e948873055cbafe4$export$727c8fc270210f13(props) {
15
- let { children: children, items: items, idScope: idScope, addIdAndValue: addIdAndValue, dependencies: dependencies = [] } = props;
16
- // Invalidate the cache whenever the parent value changes.
17
- // eslint-disable-next-line react-hooks/exhaustive-deps
18
- let cache = (0, $luMFQ$useMemo)(()=>new WeakMap(), dependencies);
19
- return (0, $luMFQ$useMemo)(()=>{
20
- if (items && typeof children === 'function') {
21
- let res = [];
22
- for (let item of items){
23
- let rendered = cache.get(item);
24
- if (!rendered) {
25
- rendered = children(item);
26
- var _rendered_props_id, _ref;
27
- // @ts-ignore
28
- let key = (_ref = (_rendered_props_id = rendered.props.id) !== null && _rendered_props_id !== void 0 ? _rendered_props_id : item.key) !== null && _ref !== void 0 ? _ref : item.id;
29
- if (key == null) throw new Error('Could not determine key for item');
30
- if (idScope != null) key = idScope + ':' + key;
31
- // Note: only works if wrapped Item passes through id...
32
- rendered = (0, $luMFQ$cloneElement)(rendered, addIdAndValue ? {
33
- key: key,
34
- id: key,
35
- value: item
36
- } : {
37
- key: key
38
- });
39
- cache.set(item, rendered);
40
- }
41
- res.push(rendered);
42
- }
43
- return res;
44
- } else if (typeof children !== 'function') return children;
45
- }, [
46
- children,
47
- items,
48
- cache,
49
- idScope,
50
- addIdAndValue
51
- ]);
52
- }
53
-
54
-
55
- export {$e948873055cbafe4$export$727c8fc270210f13 as useCachedChildren};
56
- //# sourceMappingURL=useCachedChildren.module.js.map
@@ -1,56 +0,0 @@
1
- import {useMemo as $luMFQ$useMemo, cloneElement as $luMFQ$cloneElement} from "react";
2
-
3
- /*
4
- * Copyright 2024 Adobe. All rights reserved.
5
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License. You may obtain a copy
7
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software distributed under
10
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
- * OF ANY KIND, either express or implied. See the License for the specific language
12
- * governing permissions and limitations under the License.
13
- */
14
- function $e948873055cbafe4$export$727c8fc270210f13(props) {
15
- let { children: children, items: items, idScope: idScope, addIdAndValue: addIdAndValue, dependencies: dependencies = [] } = props;
16
- // Invalidate the cache whenever the parent value changes.
17
- // eslint-disable-next-line react-hooks/exhaustive-deps
18
- let cache = (0, $luMFQ$useMemo)(()=>new WeakMap(), dependencies);
19
- return (0, $luMFQ$useMemo)(()=>{
20
- if (items && typeof children === 'function') {
21
- let res = [];
22
- for (let item of items){
23
- let rendered = cache.get(item);
24
- if (!rendered) {
25
- rendered = children(item);
26
- var _rendered_props_id, _ref;
27
- // @ts-ignore
28
- let key = (_ref = (_rendered_props_id = rendered.props.id) !== null && _rendered_props_id !== void 0 ? _rendered_props_id : item.key) !== null && _ref !== void 0 ? _ref : item.id;
29
- if (key == null) throw new Error('Could not determine key for item');
30
- if (idScope != null) key = idScope + ':' + key;
31
- // Note: only works if wrapped Item passes through id...
32
- rendered = (0, $luMFQ$cloneElement)(rendered, addIdAndValue ? {
33
- key: key,
34
- id: key,
35
- value: item
36
- } : {
37
- key: key
38
- });
39
- cache.set(item, rendered);
40
- }
41
- res.push(rendered);
42
- }
43
- return res;
44
- } else if (typeof children !== 'function') return children;
45
- }, [
46
- children,
47
- items,
48
- cache,
49
- idScope,
50
- addIdAndValue
51
- ]);
52
- }
53
-
54
-
55
- export {$e948873055cbafe4$export$727c8fc270210f13 as useCachedChildren};
56
- //# sourceMappingURL=useCachedChildren.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;AAAA;;;;;;;;;;CAUC;AAsBM,SAAS,0CAAoC,KAA+B;IACjF,IAAI,YAAC,QAAQ,SAAE,KAAK,WAAE,OAAO,iBAAE,aAAa,gBAAE,eAAe,EAAE,EAAC,GAAG;IAEnE,0DAA0D;IAC1D,uDAAuD;IACvD,IAAI,QAAQ,CAAA,GAAA,cAAM,EAAE,IAAM,IAAI,WAAW;IACzC,OAAO,CAAA,GAAA,cAAM,EAAE;QACb,IAAI,SAAS,OAAO,aAAa,YAAY;YAC3C,IAAI,MAAsB,EAAE;YAC5B,KAAK,IAAI,QAAQ,MAAO;gBACtB,IAAI,WAAW,MAAM,GAAG,CAAC;gBACzB,IAAI,CAAC,UAAU;oBACb,WAAW,SAAS;wBAEV,oBAAA;oBADV,aAAa;oBACb,IAAI,MAAM,CAAA,OAAA,CAAA,qBAAA,SAAS,KAAK,CAAC,EAAE,cAAjB,gCAAA,qBAAqB,KAAK,GAAG,cAA7B,kBAAA,OAAiC,KAAK,EAAE;oBAElD,IAAI,OAAO,MACT,MAAM,IAAI,MAAM;oBAGlB,IAAI,WAAW,MACb,MAAM,UAAU,MAAM;oBAExB,wDAAwD;oBACxD,WAAW,CAAA,GAAA,mBAAW,EACpB,UACA,gBAAgB;6BAAC;wBAAK,IAAI;wBAAK,OAAO;oBAAI,IAAI;6BAAC;oBAAG;oBAEpD,MAAM,GAAG,CAAC,MAAM;gBAClB;gBACA,IAAI,IAAI,CAAC;YACX;YACA,OAAO;QACT,OAAO,IAAI,OAAO,aAAa,YAC7B,OAAO;IAEX,GAAG;QAAC;QAAU;QAAO;QAAO;QAAS;KAAc;AACrD","sources":["packages/@react-aria/collections/src/useCachedChildren.ts"],"sourcesContent":["/*\n * Copyright 2024 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 {cloneElement, ReactElement, ReactNode, useMemo} from 'react';\nimport {Key} from '@react-types/shared';\n\nexport interface CachedChildrenOptions<T> {\n /** Item objects in the collection. */\n items?: Iterable<T>,\n /** The contents of the collection. */\n children?: ReactNode | ((item: T) => ReactNode),\n /** Values that should invalidate the item cache when using dynamic collections. */\n dependencies?: ReadonlyArray<any>,\n /** A scope to prepend to all child item ids to ensure they are unique. */\n idScope?: Key,\n /** Whether to add `id` and `value` props to all child items. */\n addIdAndValue?: boolean\n}\n\n/**\n * Maps over a list of items and renders React elements for them. Each rendered item is\n * cached based on object identity, and React keys are generated from the `key` or `id` property.\n */\nexport function useCachedChildren<T extends object>(props: CachedChildrenOptions<T>): ReactNode {\n let {children, items, idScope, addIdAndValue, dependencies = []} = props;\n\n // Invalidate the cache whenever the parent value changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n let cache = useMemo(() => new WeakMap(), dependencies);\n return useMemo(() => {\n if (items && typeof children === 'function') {\n let res: ReactElement[] = [];\n for (let item of items) {\n let rendered = cache.get(item);\n if (!rendered) {\n rendered = children(item);\n // @ts-ignore\n let key = rendered.props.id ?? item.key ?? item.id;\n \n if (key == null) {\n throw new Error('Could not determine key for item');\n }\n \n if (idScope != null) {\n key = idScope + ':' + key;\n }\n // Note: only works if wrapped Item passes through id...\n rendered = cloneElement(\n rendered,\n addIdAndValue ? {key, id: key, value: item} : {key}\n );\n cache.set(item, rendered);\n }\n res.push(rendered);\n }\n return res;\n } else if (typeof children !== 'function') {\n return children;\n }\n }, [children, items, cache, idScope, addIdAndValue]);\n}\n"],"names":[],"version":3,"file":"useCachedChildren.module.js.map"}