@react-aria/collections 3.0.0-nightly.5038 → 3.0.0-rc.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/BaseCollection.main.js +104 -0
- package/dist/BaseCollection.main.js.map +1 -1
- package/dist/BaseCollection.mjs +104 -0
- package/dist/BaseCollection.module.js +104 -0
- package/dist/BaseCollection.module.js.map +1 -1
- package/dist/CollectionBuilder.main.js +9 -3
- package/dist/CollectionBuilder.main.js.map +1 -1
- package/dist/CollectionBuilder.mjs +9 -3
- package/dist/CollectionBuilder.module.js +9 -3
- package/dist/CollectionBuilder.module.js.map +1 -1
- package/dist/Document.main.js +146 -107
- package/dist/Document.main.js.map +1 -1
- package/dist/Document.mjs +146 -107
- package/dist/Document.module.js +146 -107
- package/dist/Document.module.js.map +1 -1
- package/dist/Hidden.main.js +4 -11
- package/dist/Hidden.main.js.map +1 -1
- package/dist/Hidden.mjs +4 -11
- package/dist/Hidden.module.js +4 -11
- package/dist/Hidden.module.js.map +1 -1
- package/dist/types.d.ts +12 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/useCachedChildren.main.js +0 -2
- package/dist/useCachedChildren.main.js.map +1 -1
- package/dist/useCachedChildren.mjs +0 -2
- package/dist/useCachedChildren.module.js +0 -2
- package/dist/useCachedChildren.module.js.map +1 -1
- package/package.json +9 -8
- package/src/BaseCollection.ts +145 -10
- package/src/CollectionBuilder.tsx +20 -6
- package/src/Document.ts +210 -136
- package/src/Hidden.tsx +4 -12
- package/src/useCachedChildren.ts +3 -3
package/dist/Hidden.module.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {createPortal as $8SdCi$createPortal} from "react-dom";
|
|
2
1
|
import $8SdCi$react, {createContext as $8SdCi$createContext, useContext as $8SdCi$useContext, forwardRef as $8SdCi$forwardRef} from "react";
|
|
3
|
-
import {useIsSSR as $8SdCi$useIsSSR} from "@react-aria/ssr";
|
|
4
2
|
|
|
5
3
|
/*
|
|
6
4
|
* Copyright 2024 Adobe. All rights reserved.
|
|
@@ -13,8 +11,6 @@ import {useIsSSR as $8SdCi$useIsSSR} from "@react-aria/ssr";
|
|
|
13
11
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
12
|
* governing permissions and limitations under the License.
|
|
15
13
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
14
|
// React doesn't understand the <template> element, which doesn't have children like a normal element.
|
|
19
15
|
// It will throw an error during hydration when it expects the firstChild to contain content rendered
|
|
20
16
|
// on the server, when in reality, the browser will have placed this inside the `content` document fragment.
|
|
@@ -32,22 +28,19 @@ if (typeof HTMLTemplateElement !== 'undefined') {
|
|
|
32
28
|
});
|
|
33
29
|
}
|
|
34
30
|
const $f39a9eba43920ace$export$94b6d0abf7d33e8c = /*#__PURE__*/ (0, $8SdCi$createContext)(false);
|
|
35
|
-
// Portal to nowhere
|
|
36
|
-
const $f39a9eba43920ace$var$hiddenFragment = typeof DocumentFragment !== 'undefined' ? new DocumentFragment() : null;
|
|
37
31
|
function $f39a9eba43920ace$export$8dc98ba7eadeaa56(props) {
|
|
38
32
|
let isHidden = (0, $8SdCi$useContext)($f39a9eba43920ace$export$94b6d0abf7d33e8c);
|
|
39
|
-
let isSSR = (0, $8SdCi$useIsSSR)();
|
|
40
33
|
if (isHidden) // Don't hide again if we are already hidden.
|
|
41
34
|
return /*#__PURE__*/ (0, $8SdCi$react).createElement((0, $8SdCi$react).Fragment, null, props.children);
|
|
42
35
|
let children = /*#__PURE__*/ (0, $8SdCi$react).createElement($f39a9eba43920ace$export$94b6d0abf7d33e8c.Provider, {
|
|
43
36
|
value: true
|
|
44
37
|
}, props.children);
|
|
45
|
-
// In SSR, portals are not supported by React. Instead, render into a <template>
|
|
38
|
+
// In SSR, portals are not supported by React. Instead, always render into a <template>
|
|
46
39
|
// element, which the browser will never display to the user. In addition, the
|
|
47
|
-
// content is not part of the DOM tree, so it won't affect ids or other accessibility attributes.
|
|
48
|
-
return
|
|
40
|
+
// content is not part of the accessible DOM tree, so it won't affect ids or other accessibility attributes.
|
|
41
|
+
return /*#__PURE__*/ (0, $8SdCi$react).createElement("template", {
|
|
49
42
|
"data-react-aria-hidden": true
|
|
50
|
-
}, children)
|
|
43
|
+
}, children);
|
|
51
44
|
}
|
|
52
45
|
function $f39a9eba43920ace$export$86427a43e3e48ebb(fn) {
|
|
53
46
|
let Wrapper = (props, ref)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AAKD,sGAAsG;AACtG,qGAAqG;AACrG,4GAA4G;AAC5G,kHAAkH;AAClH,qDAAqD;AACrD,IAAI,OAAO,wBAAwB,aAAa;IAC9C,MAAM,gBAAgB,OAAO,wBAAwB,CAAC,KAAK,SAAS,EAAE,cAAe,GAAG;IACxF,OAAO,cAAc,CAAC,oBAAoB,SAAS,EAAE,cAAc;QACjE,cAAc;QACd,YAAY;QACZ,KAAK;YACH,IAAI,IAAI,CAAC,OAAO,CAAC,eAAe,EAC9B,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU;iBAE9B,OAAO,cAAc,IAAI,CAAC,IAAI;QAElC;IACF;AACF;AAEO,MAAM,0DAAgB,CAAA,GAAA,oBAAY,EAAW;AAE7C,SAAS,0CAAO,KAA4B;IACjD,IAAI,WAAW,CAAA,GAAA,iBAAS,EAAE;IAC1B,IAAI,UACF,6CAA6C;IAC7C,qBAAO,kEAAG,MAAM,QAAQ;IAG1B,IAAI,yBACF,gCAAC,0CAAc,QAAQ;QAAC,OAAA;OACrB,MAAM,QAAQ;IAInB,uFAAuF;IACvF,8EAA8E;IAC9E,4GAA4G;IAC5G,qBAAO,gCAAC;QAAS,0BAAA;OAAwB;AAC3C;AAIO,SAAS,0CAAmC,EAAwD;IACzG,IAAI,UAAU,CAAC,OAAU;QACvB,IAAI,WAAW,CAAA,GAAA,iBAAS,EAAE;QAC1B,IAAI,UACF,OAAO;QAGT,OAAO,GAAG,OAAO;IACnB;IACA,mCAAmC;IACnC,QAAQ,WAAW,GAAG,GAAG,WAAW,IAAI,GAAG,IAAI;IAC/C,OAAO,AAAC,CAAA,GAAA,iBAAS,EAAqB;AACxC;AAGO,SAAS;IACd,OAAO,CAAA,GAAA,iBAAS,EAAE;AACpB","sources":["packages/@react-aria/collections/src/Hidden.tsx"],"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 {forwardRefType} from '@react-types/shared';\nimport React, {createContext, forwardRef, ReactElement, ReactNode, useContext} from 'react';\n\n// React doesn't understand the <template> element, which doesn't have children like a normal element.\n// It will throw an error during hydration when it expects the firstChild to contain content rendered\n// on the server, when in reality, the browser will have placed this inside the `content` document fragment.\n// This monkey patches the firstChild property for our special hidden template elements to work around this error.\n// See https://github.com/facebook/react/issues/19932\nif (typeof HTMLTemplateElement !== 'undefined') {\n const getFirstChild = Object.getOwnPropertyDescriptor(Node.prototype, 'firstChild')!.get!;\n Object.defineProperty(HTMLTemplateElement.prototype, 'firstChild', {\n configurable: true,\n enumerable: true,\n get: function () {\n if (this.dataset.reactAriaHidden) {\n return this.content.firstChild;\n } else {\n return getFirstChild.call(this);\n }\n }\n });\n}\n\nexport const HiddenContext = createContext<boolean>(false);\n\nexport function Hidden(props: {children: ReactNode}): ReactNode {\n let isHidden = useContext(HiddenContext);\n if (isHidden) {\n // Don't hide again if we are already hidden.\n return <>{props.children}</>;\n }\n\n let children = (\n <HiddenContext.Provider value>\n {props.children}\n </HiddenContext.Provider>\n );\n\n // In SSR, portals are not supported by React. Instead, always render into a <template>\n // element, which the browser will never display to the user. In addition, the\n // content is not part of the accessible DOM tree, so it won't affect ids or other accessibility attributes.\n return <template data-react-aria-hidden>{children}</template>;\n}\n\n/** Creates a component that forwards its ref and returns null if it is in a hidden subtree. */\n// Note: this function is handled specially in the documentation generator. If you change it, you'll need to update DocsTransformer as well.\nexport function createHideableComponent<T, P = {}>(fn: (props: P, ref: React.Ref<T>) => ReactElement | null): (props: P & React.RefAttributes<T>) => ReactElement | null {\n let Wrapper = (props: P, ref: React.Ref<T>) => {\n let isHidden = useContext(HiddenContext);\n if (isHidden) {\n return null;\n }\n\n return fn(props, ref);\n };\n // @ts-ignore - for react dev tools\n Wrapper.displayName = fn.displayName || fn.name;\n return (forwardRef as forwardRefType)(Wrapper);\n}\n\n/** Returns whether the component is in a hidden subtree. */\nexport function useIsHidden(): boolean {\n return useContext(HiddenContext);\n}\n"],"names":[],"version":3,"file":"Hidden.module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -18,6 +18,8 @@ export class CollectionNode<T> implements Node<T> {
|
|
|
18
18
|
readonly lastChildKey: Key | null;
|
|
19
19
|
readonly props: any;
|
|
20
20
|
readonly render?: (node: Node<any>) => ReactElement;
|
|
21
|
+
readonly colSpan: number | null;
|
|
22
|
+
readonly colIndex: number | null;
|
|
21
23
|
constructor(type: string, key: Key);
|
|
22
24
|
get childNodes(): Iterable<Node<T>>;
|
|
23
25
|
clone(): CollectionNode<T>;
|
|
@@ -30,18 +32,19 @@ export class CollectionNode<T> implements Node<T> {
|
|
|
30
32
|
export class BaseCollection<T> implements _Collection1<Node<T>> {
|
|
31
33
|
get size(): number;
|
|
32
34
|
getKeys(): IterableIterator<Key>;
|
|
33
|
-
[Symbol.iterator]():
|
|
35
|
+
[Symbol.iterator](): IterableIterator<Node<T>>;
|
|
34
36
|
getChildren(key: Key): Iterable<Node<T>>;
|
|
35
|
-
getKeyBefore(key: Key): Key;
|
|
36
|
-
getKeyAfter(key: Key): Key;
|
|
37
|
-
getFirstKey(): Key;
|
|
38
|
-
getLastKey(): Key;
|
|
37
|
+
getKeyBefore(key: Key): Key | null;
|
|
38
|
+
getKeyAfter(key: Key): Key | null;
|
|
39
|
+
getFirstKey(): Key | null;
|
|
40
|
+
getLastKey(): Key | null;
|
|
39
41
|
getItem(key: Key): Node<T> | null;
|
|
40
42
|
at(): Node<T>;
|
|
41
43
|
clone(): this;
|
|
42
44
|
addNode(node: CollectionNode<T>): void;
|
|
43
45
|
removeNode(key: Key): void;
|
|
44
46
|
commit(firstKey: Key | null, lastKey: Key | null, isSSR?: boolean): void;
|
|
47
|
+
UNSTABLE_filter(filterFn: (nodeValue: string) => boolean): BaseCollection<T>;
|
|
45
48
|
}
|
|
46
49
|
export interface CachedChildrenOptions<T> {
|
|
47
50
|
/** Item objects in the collection. */
|
|
@@ -49,7 +52,7 @@ export interface CachedChildrenOptions<T> {
|
|
|
49
52
|
/** The contents of the collection. */
|
|
50
53
|
children?: ReactNode | ((item: T) => ReactNode);
|
|
51
54
|
/** Values that should invalidate the item cache when using dynamic collections. */
|
|
52
|
-
dependencies?: any
|
|
55
|
+
dependencies?: ReadonlyArray<any>;
|
|
53
56
|
/** A scope to prepend to all child item ids to ensure they are unique. */
|
|
54
57
|
idScope?: Key;
|
|
55
58
|
/** Whether to add `id` and `value` props to all child items. */
|
|
@@ -73,11 +76,11 @@ export interface CollectionBuilderProps<C extends BaseCollection<object>> {
|
|
|
73
76
|
* Builds a `Collection` from the children provided to the `content` prop, and passes it to the child render prop function.
|
|
74
77
|
*/
|
|
75
78
|
export function CollectionBuilder<C extends BaseCollection<object>>(props: CollectionBuilderProps<C>): ReactElement;
|
|
76
|
-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactElement): (props: P & React.RefAttributes<T>) =>
|
|
77
|
-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement): (props: P & React.RefAttributes<T>) =>
|
|
79
|
+
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactNode;
|
|
80
|
+
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactNode;
|
|
78
81
|
export function createBranchComponent<T extends object, P extends {
|
|
79
82
|
children?: any;
|
|
80
|
-
}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement, useChildren?: (props: P) => ReactNode): (props: P & React.RefAttributes<E>) =>
|
|
83
|
+
}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement, useChildren?: (props: P) => ReactNode): (props: P & React.RefAttributes<E>) => ReactNode;
|
|
81
84
|
export interface CollectionProps<T> extends CachedChildrenOptions<T> {
|
|
82
85
|
}
|
|
83
86
|
/** A Collection renders a list of items, automatically managing caching and keys. */
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAmBA,+DAA+D;AAC/D,4BAA4B,CAAC,CAAE,YAAW,KAAK,CAAC,CAAC;IAC/C,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;IACxC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAQ;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAM;IAChC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAa;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAK;IAC3B,QAAQ,CAAC,SAAS,EAAE,GAAG,GAAG,I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SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;AACrN,oCAAoC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;AAgCpO,sCAAsC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS;IAAC,QAAQ,CAAC,EAAE,GAAG,CAAA;CAAC,EAAE,CAAC,SAAS,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,YAAY,EAAE,WAAW,GAAE,CAAC,KAAK,EAAE,CAAC,KAAK,SAAiC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,MAAM,aAAa,CAAC,CAAC,CAAC,KAAK,SAAS,CAS5S;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} from './BaseCollection';\n\nexport type {CollectionBuilderProps, CollectionProps} from './CollectionBuilder';\nexport type {CachedChildrenOptions} from './useCachedChildren';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -32,9 +32,7 @@ function $245f3f827bea6653$export$727c8fc270210f13(props) {
|
|
|
32
32
|
var _rendered_props_id, _ref;
|
|
33
33
|
// @ts-ignore
|
|
34
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
|
-
// eslint-disable-next-line max-depth
|
|
36
35
|
if (key == null) throw new Error('Could not determine key for item');
|
|
37
|
-
// eslint-disable-next-line max-depth
|
|
38
36
|
if (idScope) key = idScope + ':' + key;
|
|
39
37
|
// Note: only works if wrapped Item passes through id...
|
|
40
38
|
rendered = (0, $6Tq0m$react.cloneElement)(rendered, addIdAndValue ? {
|
|
@@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cAAjB,gCAAA,qBAAqB,KAAK,GAAG,cAA7B,kBAAA,OAAiC,KAAK,EAAE;oBAElD,IAAI,OAAO,MACT,MAAM,IAAI,MAAM;oBAGlB,IAAI,SACF,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) {\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"}
|
|
@@ -26,9 +26,7 @@ function $e948873055cbafe4$export$727c8fc270210f13(props) {
|
|
|
26
26
|
var _rendered_props_id, _ref;
|
|
27
27
|
// @ts-ignore
|
|
28
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
|
-
// eslint-disable-next-line max-depth
|
|
30
29
|
if (key == null) throw new Error('Could not determine key for item');
|
|
31
|
-
// eslint-disable-next-line max-depth
|
|
32
30
|
if (idScope) key = idScope + ':' + key;
|
|
33
31
|
// Note: only works if wrapped Item passes through id...
|
|
34
32
|
rendered = (0, $luMFQ$cloneElement)(rendered, addIdAndValue ? {
|
|
@@ -26,9 +26,7 @@ function $e948873055cbafe4$export$727c8fc270210f13(props) {
|
|
|
26
26
|
var _rendered_props_id, _ref;
|
|
27
27
|
// @ts-ignore
|
|
28
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
|
-
// eslint-disable-next-line max-depth
|
|
30
29
|
if (key == null) throw new Error('Could not determine key for item');
|
|
31
|
-
// eslint-disable-next-line max-depth
|
|
32
30
|
if (idScope) key = idScope + ':' + key;
|
|
33
31
|
// Note: only works if wrapped Item passes through id...
|
|
34
32
|
rendered = (0, $luMFQ$cloneElement)(rendered, addIdAndValue ? {
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,SACF,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) {\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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/collections",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-rc.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,18 +22,19 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/
|
|
26
|
-
"@react-aria/
|
|
27
|
-
"@react-
|
|
25
|
+
"@react-aria/interactions": "^3.25.0",
|
|
26
|
+
"@react-aria/ssr": "^3.9.8",
|
|
27
|
+
"@react-aria/utils": "^3.28.2",
|
|
28
|
+
"@react-types/shared": "^3.29.0",
|
|
28
29
|
"@swc/helpers": "^0.5.0",
|
|
29
|
-
"use-sync-external-store": "^1.
|
|
30
|
+
"use-sync-external-store": "^1.4.0"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|
|
32
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0",
|
|
33
|
-
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
33
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
|
|
34
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
|
|
34
35
|
},
|
|
35
36
|
"publishConfig": {
|
|
36
37
|
"access": "public"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "9b66d270572f482948afee95622a85cdf68ed408"
|
|
39
40
|
}
|
package/src/BaseCollection.ts
CHANGED
|
@@ -35,6 +35,8 @@ export class CollectionNode<T> implements Node<T> {
|
|
|
35
35
|
readonly lastChildKey: Key | null = null;
|
|
36
36
|
readonly props: any = {};
|
|
37
37
|
readonly render?: (node: Node<any>) => ReactElement;
|
|
38
|
+
readonly colSpan: number | null = null;
|
|
39
|
+
readonly colIndex: number | null = null;
|
|
38
40
|
|
|
39
41
|
constructor(type: string, key: Key) {
|
|
40
42
|
this.type = type;
|
|
@@ -61,6 +63,8 @@ export class CollectionNode<T> implements Node<T> {
|
|
|
61
63
|
node.lastChildKey = this.lastChildKey;
|
|
62
64
|
node.props = this.props;
|
|
63
65
|
node.render = this.render;
|
|
66
|
+
node.colSpan = this.colSpan;
|
|
67
|
+
node.colIndex = this.colIndex;
|
|
64
68
|
return node;
|
|
65
69
|
}
|
|
66
70
|
}
|
|
@@ -76,15 +80,15 @@ export class BaseCollection<T> implements ICollection<Node<T>> {
|
|
|
76
80
|
private lastKey: Key | null = null;
|
|
77
81
|
private frozen = false;
|
|
78
82
|
|
|
79
|
-
get size() {
|
|
83
|
+
get size(): number {
|
|
80
84
|
return this.keyMap.size;
|
|
81
85
|
}
|
|
82
86
|
|
|
83
|
-
getKeys() {
|
|
87
|
+
getKeys(): IterableIterator<Key> {
|
|
84
88
|
return this.keyMap.keys();
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
*[Symbol.iterator]() {
|
|
91
|
+
*[Symbol.iterator](): IterableIterator<Node<T>> {
|
|
88
92
|
let node: Node<T> | undefined = this.firstKey != null ? this.keyMap.get(this.firstKey) : undefined;
|
|
89
93
|
while (node) {
|
|
90
94
|
yield node;
|
|
@@ -106,7 +110,7 @@ export class BaseCollection<T> implements ICollection<Node<T>> {
|
|
|
106
110
|
};
|
|
107
111
|
}
|
|
108
112
|
|
|
109
|
-
getKeyBefore(key: Key) {
|
|
113
|
+
getKeyBefore(key: Key): Key | null {
|
|
110
114
|
let node = this.keyMap.get(key);
|
|
111
115
|
if (!node) {
|
|
112
116
|
return null;
|
|
@@ -125,7 +129,7 @@ export class BaseCollection<T> implements ICollection<Node<T>> {
|
|
|
125
129
|
return node.parentKey;
|
|
126
130
|
}
|
|
127
131
|
|
|
128
|
-
getKeyAfter(key: Key) {
|
|
132
|
+
getKeyAfter(key: Key): Key | null {
|
|
129
133
|
let node = this.keyMap.get(key);
|
|
130
134
|
if (!node) {
|
|
131
135
|
return null;
|
|
@@ -150,11 +154,11 @@ export class BaseCollection<T> implements ICollection<Node<T>> {
|
|
|
150
154
|
return null;
|
|
151
155
|
}
|
|
152
156
|
|
|
153
|
-
getFirstKey() {
|
|
157
|
+
getFirstKey(): Key | null {
|
|
154
158
|
return this.firstKey;
|
|
155
159
|
}
|
|
156
160
|
|
|
157
|
-
getLastKey() {
|
|
161
|
+
getLastKey(): Key | null {
|
|
158
162
|
let node = this.lastKey != null ? this.keyMap.get(this.lastKey) : null;
|
|
159
163
|
while (node?.lastChildKey != null) {
|
|
160
164
|
node = this.keyMap.get(node.lastChildKey);
|
|
@@ -183,7 +187,7 @@ export class BaseCollection<T> implements ICollection<Node<T>> {
|
|
|
183
187
|
return collection;
|
|
184
188
|
}
|
|
185
189
|
|
|
186
|
-
addNode(node: CollectionNode<T>) {
|
|
190
|
+
addNode(node: CollectionNode<T>): void {
|
|
187
191
|
if (this.frozen) {
|
|
188
192
|
throw new Error('Cannot add a node to a frozen collection');
|
|
189
193
|
}
|
|
@@ -191,7 +195,7 @@ export class BaseCollection<T> implements ICollection<Node<T>> {
|
|
|
191
195
|
this.keyMap.set(node.key, node);
|
|
192
196
|
}
|
|
193
197
|
|
|
194
|
-
removeNode(key: Key) {
|
|
198
|
+
removeNode(key: Key): void {
|
|
195
199
|
if (this.frozen) {
|
|
196
200
|
throw new Error('Cannot remove a node to a frozen collection');
|
|
197
201
|
}
|
|
@@ -199,7 +203,7 @@ export class BaseCollection<T> implements ICollection<Node<T>> {
|
|
|
199
203
|
this.keyMap.delete(key);
|
|
200
204
|
}
|
|
201
205
|
|
|
202
|
-
commit(firstKey: Key | null, lastKey: Key | null, isSSR = false) {
|
|
206
|
+
commit(firstKey: Key | null, lastKey: Key | null, isSSR = false): void {
|
|
203
207
|
if (this.frozen) {
|
|
204
208
|
throw new Error('Cannot commit a frozen collection');
|
|
205
209
|
}
|
|
@@ -208,4 +212,135 @@ export class BaseCollection<T> implements ICollection<Node<T>> {
|
|
|
208
212
|
this.lastKey = lastKey;
|
|
209
213
|
this.frozen = !isSSR;
|
|
210
214
|
}
|
|
215
|
+
|
|
216
|
+
// TODO: this is pretty specific to menu, will need to check if it is generic enough
|
|
217
|
+
// Will need to handle varying levels I assume but will revisit after I get searchable menu working for base menu
|
|
218
|
+
// TODO: an alternative is to simply walk the collection and add all item nodes that match the filter and any sections/separators we encounter
|
|
219
|
+
// to an array, then walk that new array and fix all the next/Prev keys while adding them to the new collection
|
|
220
|
+
UNSTABLE_filter(filterFn: (nodeValue: string) => boolean): BaseCollection<T> {
|
|
221
|
+
let newCollection = new BaseCollection<T>();
|
|
222
|
+
// This tracks the absolute last node we've visited in the collection when filtering, used for setting up the filteredCollection's lastKey and
|
|
223
|
+
// for updating the next/prevKey for every non-filtered node.
|
|
224
|
+
let lastNode: Mutable<CollectionNode<T>> | null = null;
|
|
225
|
+
|
|
226
|
+
for (let node of this) {
|
|
227
|
+
if (node.type === 'section' && node.hasChildNodes) {
|
|
228
|
+
let clonedSection: Mutable<CollectionNode<T>> = (node as CollectionNode<T>).clone();
|
|
229
|
+
let lastChildInSection: Mutable<CollectionNode<T>> | null = null;
|
|
230
|
+
for (let child of this.getChildren(node.key)) {
|
|
231
|
+
if (shouldKeepNode(child, filterFn, this, newCollection)) {
|
|
232
|
+
let clonedChild: Mutable<CollectionNode<T>> = (child as CollectionNode<T>).clone();
|
|
233
|
+
// eslint-disable-next-line max-depth
|
|
234
|
+
if (lastChildInSection == null) {
|
|
235
|
+
clonedSection.firstChildKey = clonedChild.key;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// eslint-disable-next-line max-depth
|
|
239
|
+
if (newCollection.firstKey == null) {
|
|
240
|
+
newCollection.firstKey = clonedSection.key;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// eslint-disable-next-line max-depth
|
|
244
|
+
if (lastChildInSection && lastChildInSection.parentKey === clonedChild.parentKey) {
|
|
245
|
+
lastChildInSection.nextKey = clonedChild.key;
|
|
246
|
+
clonedChild.prevKey = lastChildInSection.key;
|
|
247
|
+
} else {
|
|
248
|
+
clonedChild.prevKey = null;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
clonedChild.nextKey = null;
|
|
252
|
+
newCollection.addNode(clonedChild);
|
|
253
|
+
lastChildInSection = clonedChild;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Add newly filtered section to collection if it has any valid child nodes, otherwise remove it and its header if any
|
|
258
|
+
if (lastChildInSection) {
|
|
259
|
+
if (lastChildInSection.type !== 'header') {
|
|
260
|
+
clonedSection.lastChildKey = lastChildInSection.key;
|
|
261
|
+
|
|
262
|
+
// If the old prev section was filtered out, will need to attach to whatever came before
|
|
263
|
+
// eslint-disable-next-line max-depth
|
|
264
|
+
if (lastNode == null) {
|
|
265
|
+
clonedSection.prevKey = null;
|
|
266
|
+
} else if (lastNode.type === 'section' || lastNode.type === 'separator') {
|
|
267
|
+
lastNode.nextKey = clonedSection.key;
|
|
268
|
+
clonedSection.prevKey = lastNode.key;
|
|
269
|
+
}
|
|
270
|
+
clonedSection.nextKey = null;
|
|
271
|
+
lastNode = clonedSection;
|
|
272
|
+
newCollection.addNode(clonedSection);
|
|
273
|
+
} else {
|
|
274
|
+
if (newCollection.firstKey === clonedSection.key) {
|
|
275
|
+
newCollection.firstKey = null;
|
|
276
|
+
}
|
|
277
|
+
newCollection.removeNode(lastChildInSection.key);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
} else if (node.type === 'separator') {
|
|
281
|
+
// will need to check if previous section key exists, if it does then we add the separator to the collection.
|
|
282
|
+
// After the full collection is created we'll need to remove it it is the last node in the section (aka no following section after the separator)
|
|
283
|
+
let clonedSeparator: Mutable<CollectionNode<T>> = (node as CollectionNode<T>).clone();
|
|
284
|
+
clonedSeparator.nextKey = null;
|
|
285
|
+
if (lastNode?.type === 'section') {
|
|
286
|
+
lastNode.nextKey = clonedSeparator.key;
|
|
287
|
+
clonedSeparator.prevKey = lastNode.key;
|
|
288
|
+
lastNode = clonedSeparator;
|
|
289
|
+
newCollection.addNode(clonedSeparator);
|
|
290
|
+
}
|
|
291
|
+
} else {
|
|
292
|
+
// At this point, the node is either a subdialogtrigger node or a standard row/item
|
|
293
|
+
let clonedNode: Mutable<CollectionNode<T>> = (node as CollectionNode<T>).clone();
|
|
294
|
+
if (shouldKeepNode(clonedNode, filterFn, this, newCollection)) {
|
|
295
|
+
if (newCollection.firstKey == null) {
|
|
296
|
+
newCollection.firstKey = clonedNode.key;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (lastNode != null && (lastNode.type !== 'section' && lastNode.type !== 'separator') && lastNode.parentKey === clonedNode.parentKey) {
|
|
300
|
+
lastNode.nextKey = clonedNode.key;
|
|
301
|
+
clonedNode.prevKey = lastNode.key;
|
|
302
|
+
} else {
|
|
303
|
+
clonedNode.prevKey = null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
clonedNode.nextKey = null;
|
|
307
|
+
newCollection.addNode(clonedNode);
|
|
308
|
+
lastNode = clonedNode;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (lastNode?.type === 'separator' && lastNode.nextKey === null) {
|
|
314
|
+
let lastSection;
|
|
315
|
+
if (lastNode.prevKey != null) {
|
|
316
|
+
lastSection = newCollection.getItem(lastNode.prevKey) as Mutable<CollectionNode<T>>;
|
|
317
|
+
lastSection.nextKey = null;
|
|
318
|
+
}
|
|
319
|
+
newCollection.removeNode(lastNode.key);
|
|
320
|
+
lastNode = lastSection;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
newCollection.lastKey = lastNode?.key || null;
|
|
324
|
+
|
|
325
|
+
return newCollection;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function shouldKeepNode<T>(node: Node<T>, filterFn: (nodeValue: string) => boolean, oldCollection: BaseCollection<T>, newCollection: BaseCollection<T>): boolean {
|
|
330
|
+
if (node.type === 'subdialogtrigger' || node.type === 'submenutrigger') {
|
|
331
|
+
// Subdialog wrapper should only have one child, if it passes the filter add it to the new collection since we don't need to
|
|
332
|
+
// do any extra handling for its first/next key
|
|
333
|
+
let triggerChild = [...oldCollection.getChildren(node.key)][0];
|
|
334
|
+
if (triggerChild && filterFn(triggerChild.textValue)) {
|
|
335
|
+
let clonedChild: Mutable<CollectionNode<T>> = (triggerChild as CollectionNode<T>).clone();
|
|
336
|
+
newCollection.addNode(clonedChild);
|
|
337
|
+
return true;
|
|
338
|
+
} else {
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
} else if (node.type === 'header') {
|
|
342
|
+
return true;
|
|
343
|
+
} else {
|
|
344
|
+
return filterFn(node.textValue);
|
|
345
|
+
}
|
|
211
346
|
}
|
|
@@ -14,6 +14,7 @@ import {BaseCollection} from './BaseCollection';
|
|
|
14
14
|
import {BaseNode, Document, ElementNode} from './Document';
|
|
15
15
|
import {CachedChildrenOptions, useCachedChildren} from './useCachedChildren';
|
|
16
16
|
import {createPortal} from 'react-dom';
|
|
17
|
+
import {FocusableContext} from '@react-aria/interactions';
|
|
17
18
|
import {forwardRefType, Node} from '@react-types/shared';
|
|
18
19
|
import {Hidden} from './Hidden';
|
|
19
20
|
import React, {createContext, ForwardedRef, forwardRef, JSX, ReactElement, ReactNode, useCallback, useContext, useMemo, useRef, useState} from 'react';
|
|
@@ -116,7 +117,7 @@ function useCollectionDocument<T extends object, C extends BaseCollection<T>>(cr
|
|
|
116
117
|
useLayoutEffect(() => {
|
|
117
118
|
document.isMounted = true;
|
|
118
119
|
return () => {
|
|
119
|
-
// Mark unmounted so we can skip all of the collection updates caused by
|
|
120
|
+
// Mark unmounted so we can skip all of the collection updates caused by
|
|
120
121
|
// React calling removeChild on every item in the collection.
|
|
121
122
|
document.isMounted = false;
|
|
122
123
|
};
|
|
@@ -156,11 +157,12 @@ function useSSRCollectionNode<T extends Element>(Type: string, props: object, re
|
|
|
156
157
|
return <Type ref={itemRef}>{children}</Type>;
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactElement): (props: P & React.RefAttributes<T>) =>
|
|
160
|
-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement): (props: P & React.RefAttributes<T>) =>
|
|
161
|
-
export function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement) {
|
|
160
|
+
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactNode;
|
|
161
|
+
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement): (props: P & React.RefAttributes<T>) => ReactNode;
|
|
162
|
+
export function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement): (props: P & React.RefAttributes<any>) => ReactNode {
|
|
162
163
|
let Component = ({node}) => render(node.props, node.props.ref, node);
|
|
163
164
|
let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {
|
|
165
|
+
let focusableProps = useContext(FocusableContext);
|
|
164
166
|
let isShallow = useContext(ShallowRenderContext);
|
|
165
167
|
if (!isShallow) {
|
|
166
168
|
if (render.length >= 3) {
|
|
@@ -169,14 +171,26 @@ export function createLeafComponent<P extends object, E extends Element>(type: s
|
|
|
169
171
|
return render(props, ref);
|
|
170
172
|
}
|
|
171
173
|
|
|
172
|
-
return useSSRCollectionNode(
|
|
174
|
+
return useSSRCollectionNode(
|
|
175
|
+
type,
|
|
176
|
+
props,
|
|
177
|
+
ref,
|
|
178
|
+
'children' in props ? props.children : null,
|
|
179
|
+
null,
|
|
180
|
+
node => (
|
|
181
|
+
// Forward FocusableContext to real DOM tree so tooltips work.
|
|
182
|
+
<FocusableContext.Provider value={focusableProps}>
|
|
183
|
+
<Component node={node} />
|
|
184
|
+
</FocusableContext.Provider>
|
|
185
|
+
)
|
|
186
|
+
);
|
|
173
187
|
});
|
|
174
188
|
// @ts-ignore
|
|
175
189
|
Result.displayName = render.name;
|
|
176
190
|
return Result;
|
|
177
191
|
}
|
|
178
192
|
|
|
179
|
-
export function createBranchComponent<T extends object, P extends {children?: any}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement, useChildren: (props: P) => ReactNode = useCollectionChildren) {
|
|
193
|
+
export function createBranchComponent<T extends object, P extends {children?: any}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement, useChildren: (props: P) => ReactNode = useCollectionChildren): (props: P & React.RefAttributes<E>) => ReactNode {
|
|
180
194
|
let Component = ({node}) => render(node.props, node.props.ref, node);
|
|
181
195
|
let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {
|
|
182
196
|
let children = useChildren(props);
|