@react-aria/collections 3.0.0-nightly.3022 → 3.0.0-nightly.4743
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/CollectionBuilder.main.js +6 -1
- package/dist/CollectionBuilder.main.js.map +1 -1
- package/dist/CollectionBuilder.mjs +6 -1
- package/dist/CollectionBuilder.module.js +6 -1
- package/dist/CollectionBuilder.module.js.map +1 -1
- package/dist/Hidden.main.js.map +1 -1
- package/dist/Hidden.module.js.map +1 -1
- package/dist/types.d.ts +5 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/CollectionBuilder.tsx +11 -6
- package/src/Hidden.tsx +2 -2
|
@@ -45,7 +45,12 @@ const $f20386e2aa690b4a$var$CollectionDocumentContext = /*#__PURE__*/ (0, $4ftIM
|
|
|
45
45
|
function $f20386e2aa690b4a$export$bf788dd355e3a401(props) {
|
|
46
46
|
// If a document was provided above us, we're already in a hidden tree. Just render the content.
|
|
47
47
|
let doc = (0, $4ftIM$react.useContext)($f20386e2aa690b4a$var$CollectionDocumentContext);
|
|
48
|
-
if (doc)
|
|
48
|
+
if (doc) // The React types prior to 18 did not allow returning ReactNode from components
|
|
49
|
+
// even though the actual implementation since React 16 did.
|
|
50
|
+
// We must return ReactElement so that TS does not complain that <CollectionBuilder>
|
|
51
|
+
// is not a valid JSX element with React 16 and 17 types.
|
|
52
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544
|
|
53
|
+
return props.content;
|
|
49
54
|
// Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.
|
|
50
55
|
// This should always come before the real DOM content so we have built the collection by the time it renders during SSR.
|
|
51
56
|
// This is fine. CollectionDocumentContext never changes after mounting.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;AAaD,MAAM,2DAAuB,CAAA,GAAA,0BAAY,EAAE;A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/collections/src/CollectionBuilder.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 {BaseCollection} from './BaseCollection';\nimport {BaseNode, Document, ElementNode} from './Document';\nimport {CachedChildrenOptions, useCachedChildren} from './useCachedChildren';\nimport {createPortal} from 'react-dom';\nimport {forwardRefType, Node} from '@react-types/shared';\nimport {Hidden} from './Hidden';\nimport React, {createContext, ForwardedRef, forwardRef, JSX, ReactElement, ReactNode, useCallback, useContext, useMemo, useRef, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\nimport {useLayoutEffect} from '@react-aria/utils';\nimport {useSyncExternalStore as useSyncExternalStoreShim} from 'use-sync-external-store/shim/index.js';\n\nconst ShallowRenderContext = createContext(false);\nconst CollectionDocumentContext = createContext<Document<any, BaseCollection<any>> | null>(null);\n\nexport interface CollectionBuilderProps<C extends BaseCollection<object>> {\n content: ReactNode,\n children: (collection: C) => ReactNode,\n createCollection?: () => C\n}\n\n/**\n * Builds a `Collection` from the children provided to the `content` prop, and passes it to the child render prop function.\n */\nexport function CollectionBuilder<C extends BaseCollection<object>>(props: CollectionBuilderProps<C>) {\n // If a document was provided above us, we're already in a hidden tree. Just render the content.\n let doc = useContext(CollectionDocumentContext);\n if (doc) {\n return props.content;\n }\n\n // Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.\n // This should always come before the real DOM content so we have built the collection by the time it renders during SSR.\n\n // This is fine. CollectionDocumentContext never changes after mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let {collection, document} = useCollectionDocument(props.createCollection);\n return (\n <>\n <Hidden>\n <CollectionDocumentContext.Provider value={document}>\n {props.content}\n </CollectionDocumentContext.Provider>\n </Hidden>\n <CollectionInner render={props.children} collection={collection} />\n </>\n );\n}\n\nfunction CollectionInner({collection, render}) {\n return render(collection);\n}\n\ninterface CollectionDocumentResult<T, C extends BaseCollection<T>> {\n collection: C,\n document: Document<T, C>\n}\n\n// React 16 and 17 don't support useSyncExternalStore natively, and the shim provided by React does not support getServerSnapshot.\n// This wrapper uses the shim, but additionally calls getServerSnapshot during SSR (according to SSRProvider).\nfunction useSyncExternalStoreFallback<C>(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => C, getServerSnapshot: () => C): C {\n let isSSR = useIsSSR();\n let isSSRRef = useRef(isSSR);\n // This is read immediately inside the wrapper, which also runs during render.\n // We just need a ref to avoid invalidating the callback itself, which\n // would cause React to re-run the callback more than necessary.\n // eslint-disable-next-line rulesdir/pure-render\n isSSRRef.current = isSSR;\n\n let getSnapshotWrapper = useCallback(() => {\n return isSSRRef.current ? getServerSnapshot() : getSnapshot();\n }, [getSnapshot, getServerSnapshot]);\n return useSyncExternalStoreShim(subscribe, getSnapshotWrapper);\n}\n\nconst useSyncExternalStore = typeof React['useSyncExternalStore'] === 'function'\n ? React['useSyncExternalStore']\n : useSyncExternalStoreFallback;\n\nfunction useCollectionDocument<T extends object, C extends BaseCollection<T>>(createCollection?: () => C): CollectionDocumentResult<T, C> {\n // The document instance is mutable, and should never change between renders.\n // useSyncExternalStore is used to subscribe to updates, which vends immutable Collection objects.\n let [document] = useState(() => new Document<T, C>(createCollection?.() || new BaseCollection() as C));\n let subscribe = useCallback((fn: () => void) => document.subscribe(fn), [document]);\n let getSnapshot = useCallback(() => {\n let collection = document.getCollection();\n if (document.isSSR) {\n // After SSR is complete, reset the document to empty so it is ready for React to render the portal into.\n // We do this _after_ getting the collection above so that the collection still has content in it from SSR\n // during the current render, before React has finished the client render.\n document.resetAfterSSR();\n }\n return collection;\n }, [document]);\n let getServerSnapshot = useCallback(() => {\n document.isSSR = true;\n return document.getCollection();\n }, [document]);\n let collection = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n useLayoutEffect(() => {\n document.isMounted = true;\n return () => {\n // Mark unmounted so we can skip all of the collection updates caused by \n // React calling removeChild on every item in the collection.\n document.isMounted = false;\n };\n }, [document]);\n return {collection, document};\n}\n\nconst SSRContext = createContext<BaseNode<any> | null>(null);\n\nfunction useSSRCollectionNode<T extends Element>(Type: string, props: object, ref: ForwardedRef<T>, rendered?: any, children?: ReactNode, render?: (node: Node<T>) => ReactElement) {\n // During SSR, portals are not supported, so the collection children will be wrapped in an SSRContext.\n // Since SSR occurs only once, we assume that the elements are rendered in order and never re-render.\n // Therefore we can create elements in our collection document during render so that they are in the\n // collection by the time we need to use the collection to render to the real DOM.\n // After hydration, we switch to client rendering using the portal.\n let itemRef = useCallback((element: ElementNode<any> | null) => {\n element?.setProps(props, ref, rendered, render);\n }, [props, ref, rendered, render]);\n let parentNode = useContext(SSRContext);\n if (parentNode) {\n // Guard against double rendering in strict mode.\n let element = parentNode.ownerDocument.nodesByProps.get(props);\n if (!element) {\n element = parentNode.ownerDocument.createElement(Type);\n element.setProps(props, ref, rendered, render);\n parentNode.appendChild(element);\n parentNode.ownerDocument.updateCollection();\n parentNode.ownerDocument.nodesByProps.set(props, element);\n }\n\n return children\n ? <SSRContext.Provider value={element}>{children}</SSRContext.Provider>\n : null;\n }\n\n // @ts-ignore\n return <Type ref={itemRef}>{children}</Type>;\n}\n\nexport function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactNode): (props: P & React.RefAttributes<T>) => ReactNode | null;\nexport function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactNode): (props: P & React.RefAttributes<T>) => ReactNode | null;\nexport function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactNode) {\n let Component = ({node}) => render(node.props, node.props.ref, node);\n let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {\n let isShallow = useContext(ShallowRenderContext);\n if (!isShallow) {\n if (render.length >= 3) {\n throw new Error(render.name + ' cannot be rendered outside a collection.');\n }\n return render(props, ref);\n }\n\n return useSSRCollectionNode(type, props, ref, 'children' in props ? props.children : null, null, node => <Component node={node} />);\n });\n // @ts-ignore\n Result.displayName = render.name;\n return Result;\n}\n\nexport function createBranchComponent<T extends object, P extends {children?: any}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactNode, useChildren: (props: P) => ReactNode = useCollectionChildren) {\n let Component = ({node}) => render(node.props, node.props.ref, node);\n let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {\n let children = useChildren(props);\n return useSSRCollectionNode(type, props, ref, null, children, node => <Component node={node} />) ?? <></>;\n });\n // @ts-ignore\n Result.displayName = render.name;\n return Result;\n}\n\nfunction useCollectionChildren<T extends object>(options: CachedChildrenOptions<T>) {\n return useCachedChildren({...options, addIdAndValue: true});\n}\n\nexport interface CollectionProps<T> extends CachedChildrenOptions<T> {}\n\nconst CollectionContext = createContext<CachedChildrenOptions<unknown> | null>(null);\n\n/** A Collection renders a list of items, automatically managing caching and keys. */\nexport function Collection<T extends object>(props: CollectionProps<T>): JSX.Element {\n let ctx = useContext(CollectionContext)!;\n let dependencies = (ctx?.dependencies || []).concat(props.dependencies);\n let idScope = props.idScope || ctx?.idScope;\n let children = useCollectionChildren({\n ...props,\n idScope,\n dependencies\n });\n\n let doc = useContext(CollectionDocumentContext);\n if (doc) {\n children = <CollectionRoot>{children}</CollectionRoot>;\n }\n\n // Propagate dependencies and idScope to child collections.\n ctx = useMemo(() => ({\n dependencies,\n idScope\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }), [idScope, ...dependencies]);\n\n return (\n <CollectionContext.Provider value={ctx}>\n {children}\n </CollectionContext.Provider>\n );\n}\n\nfunction CollectionRoot({children}) {\n let doc = useContext(CollectionDocumentContext);\n let wrappedChildren = useMemo(() => (\n <CollectionDocumentContext.Provider value={null}>\n <ShallowRenderContext.Provider value>\n {children}\n </ShallowRenderContext.Provider>\n </CollectionDocumentContext.Provider>\n ), [children]);\n // During SSR, we render the content directly, and append nodes to the document during render.\n // The collection children return null so that nothing is actually rendered into the HTML.\n return useIsSSR()\n ? <SSRContext.Provider value={doc}>{wrappedChildren}</SSRContext.Provider>\n : createPortal(wrappedChildren, doc as unknown as Element);\n}\n"],"names":[],"version":3,"file":"CollectionBuilder.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;AAaD,MAAM,2DAAuB,CAAA,GAAA,0BAAY,EAAE;AAC3C,MAAM,gEAA4B,CAAA,GAAA,0BAAY,EAA6C;AAWpF,SAAS,0CAAoD,KAAgC;IAClG,gGAAgG;IAChG,IAAI,MAAM,CAAA,GAAA,uBAAS,EAAE;IACrB,IAAI,KACF,gFAAgF;IAChF,4DAA4D;IAC5D,oFAAoF;IACpF,yDAAyD;IACzD,kEAAkE;IAClE,OAAO,MAAM,OAAO;IAGtB,qHAAqH;IACrH,yHAAyH;IAEzH,wEAAwE;IACxE,sDAAsD;IACtD,IAAI,cAAC,UAAU,YAAE,QAAQ,EAAC,GAAG,4CAAsB,MAAM,gBAAgB;IACzE,qBACE,oIACE,0DAAC,CAAA,GAAA,gCAAK,uBACJ,0DAAC,gDAA0B,QAAQ;QAAC,OAAO;OACxC,MAAM,OAAO,kBAGlB,0DAAC;QAAgB,QAAQ,MAAM,QAAQ;QAAE,YAAY;;AAG3D;AAEA,SAAS,sCAAgB,cAAC,UAAU,UAAE,MAAM,EAAC;IAC3C,OAAO,OAAO;AAChB;AAOA,kIAAkI;AAClI,8GAA8G;AAC9G,SAAS,mDAAgC,SAAoD,EAAE,WAAoB,EAAE,iBAA0B;IAC7I,IAAI,QAAQ,CAAA,GAAA,4BAAO;IACnB,IA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AAA,GAAA,oBAAM,EAAE,IAAO,CAAA;0BACnB;qBACA;QAEF,CAAA,GAAI;QAAC;WAAY;KAAa;IAE9B,qBACE,0DAAC,wCAAkB,QAAQ;QAAC,OAAO;OAChC;AAGP;AAEA,SAAS,qCAAe,YAAC,QAAQ,EAAC;IAChC,IAAI,MAAM,CAAA,GAAA,uBAAS,EAAE;IACrB,IAAI,kBAAkB,CAAA,GAAA,oBAAM,EAAE,kBAC5B,0DAAC,gDAA0B,QAAQ;YAAC,OAAO;yBACzC,0DAAC,2CAAqB,QAAQ;YAAC,OAAA;WAC5B,YAGJ;QAAC;KAAS;IACb,8FAA8F;IAC9F,0FAA0F;IAC1F,OAAO,CAAA,GAAA,4BAAO,oBACV,0DAAC,iCAAW,QAAQ;QAAC,OAAO;OAAM,iCAClC,CAAA,GAAA,4BAAW,EAAE,iBAAiB;AACpC","sources":["packages/@react-aria/collections/src/CollectionBuilder.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 {BaseCollection} from './BaseCollection';\nimport {BaseNode, Document, ElementNode} from './Document';\nimport {CachedChildrenOptions, useCachedChildren} from './useCachedChildren';\nimport {createPortal} from 'react-dom';\nimport {forwardRefType, Node} from '@react-types/shared';\nimport {Hidden} from './Hidden';\nimport React, {createContext, ForwardedRef, forwardRef, JSX, ReactElement, ReactNode, useCallback, useContext, useMemo, useRef, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\nimport {useLayoutEffect} from '@react-aria/utils';\nimport {useSyncExternalStore as useSyncExternalStoreShim} from 'use-sync-external-store/shim/index.js';\n\nconst ShallowRenderContext = createContext(false);\nconst CollectionDocumentContext = createContext<Document<any, BaseCollection<any>> | null>(null);\n\nexport interface CollectionBuilderProps<C extends BaseCollection<object>> {\n content: ReactNode,\n children: (collection: C) => ReactNode,\n createCollection?: () => C\n}\n\n/**\n * Builds a `Collection` from the children provided to the `content` prop, and passes it to the child render prop function.\n */\nexport function CollectionBuilder<C extends BaseCollection<object>>(props: CollectionBuilderProps<C>): ReactElement {\n // If a document was provided above us, we're already in a hidden tree. Just render the content.\n let doc = useContext(CollectionDocumentContext);\n if (doc) {\n // The React types prior to 18 did not allow returning ReactNode from components\n // even though the actual implementation since React 16 did.\n // We must return ReactElement so that TS does not complain that <CollectionBuilder>\n // is not a valid JSX element with React 16 and 17 types.\n // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544\n return props.content as ReactElement;\n }\n\n // Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.\n // This should always come before the real DOM content so we have built the collection by the time it renders during SSR.\n\n // This is fine. CollectionDocumentContext never changes after mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let {collection, document} = useCollectionDocument(props.createCollection);\n return (\n <>\n <Hidden>\n <CollectionDocumentContext.Provider value={document}>\n {props.content}\n </CollectionDocumentContext.Provider>\n </Hidden>\n <CollectionInner render={props.children} collection={collection} />\n </>\n );\n}\n\nfunction CollectionInner({collection, render}) {\n return render(collection);\n}\n\ninterface CollectionDocumentResult<T, C extends BaseCollection<T>> {\n collection: C,\n document: Document<T, C>\n}\n\n// React 16 and 17 don't support useSyncExternalStore natively, and the shim provided by React does not support getServerSnapshot.\n// This wrapper uses the shim, but additionally calls getServerSnapshot during SSR (according to SSRProvider).\nfunction useSyncExternalStoreFallback<C>(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => C, getServerSnapshot: () => C): C {\n let isSSR = useIsSSR();\n let isSSRRef = useRef(isSSR);\n // This is read immediately inside the wrapper, which also runs during render.\n // We just need a ref to avoid invalidating the callback itself, which\n // would cause React to re-run the callback more than necessary.\n // eslint-disable-next-line rulesdir/pure-render\n isSSRRef.current = isSSR;\n\n let getSnapshotWrapper = useCallback(() => {\n return isSSRRef.current ? getServerSnapshot() : getSnapshot();\n }, [getSnapshot, getServerSnapshot]);\n return useSyncExternalStoreShim(subscribe, getSnapshotWrapper);\n}\n\nconst useSyncExternalStore = typeof React['useSyncExternalStore'] === 'function'\n ? React['useSyncExternalStore']\n : useSyncExternalStoreFallback;\n\nfunction useCollectionDocument<T extends object, C extends BaseCollection<T>>(createCollection?: () => C): CollectionDocumentResult<T, C> {\n // The document instance is mutable, and should never change between renders.\n // useSyncExternalStore is used to subscribe to updates, which vends immutable Collection objects.\n let [document] = useState(() => new Document<T, C>(createCollection?.() || new BaseCollection() as C));\n let subscribe = useCallback((fn: () => void) => document.subscribe(fn), [document]);\n let getSnapshot = useCallback(() => {\n let collection = document.getCollection();\n if (document.isSSR) {\n // After SSR is complete, reset the document to empty so it is ready for React to render the portal into.\n // We do this _after_ getting the collection above so that the collection still has content in it from SSR\n // during the current render, before React has finished the client render.\n document.resetAfterSSR();\n }\n return collection;\n }, [document]);\n let getServerSnapshot = useCallback(() => {\n document.isSSR = true;\n return document.getCollection();\n }, [document]);\n let collection = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n useLayoutEffect(() => {\n document.isMounted = true;\n return () => {\n // Mark unmounted so we can skip all of the collection updates caused by \n // React calling removeChild on every item in the collection.\n document.isMounted = false;\n };\n }, [document]);\n return {collection, document};\n}\n\nconst SSRContext = createContext<BaseNode<any> | null>(null);\n\nfunction useSSRCollectionNode<T extends Element>(Type: string, props: object, ref: ForwardedRef<T>, rendered?: any, children?: ReactNode, render?: (node: Node<T>) => ReactElement) {\n // During SSR, portals are not supported, so the collection children will be wrapped in an SSRContext.\n // Since SSR occurs only once, we assume that the elements are rendered in order and never re-render.\n // Therefore we can create elements in our collection document during render so that they are in the\n // collection by the time we need to use the collection to render to the real DOM.\n // After hydration, we switch to client rendering using the portal.\n let itemRef = useCallback((element: ElementNode<any> | null) => {\n element?.setProps(props, ref, rendered, render);\n }, [props, ref, rendered, render]);\n let parentNode = useContext(SSRContext);\n if (parentNode) {\n // Guard against double rendering in strict mode.\n let element = parentNode.ownerDocument.nodesByProps.get(props);\n if (!element) {\n element = parentNode.ownerDocument.createElement(Type);\n element.setProps(props, ref, rendered, render);\n parentNode.appendChild(element);\n parentNode.ownerDocument.updateCollection();\n parentNode.ownerDocument.nodesByProps.set(props, element);\n }\n\n return children\n ? <SSRContext.Provider value={element}>{children}</SSRContext.Provider>\n : null;\n }\n\n // @ts-ignore\n return <Type ref={itemRef}>{children}</Type>;\n}\n\nexport 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>) => ReactElement | null;\nexport 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>) => ReactElement | null;\nexport function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement) {\n let Component = ({node}) => render(node.props, node.props.ref, node);\n let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {\n let isShallow = useContext(ShallowRenderContext);\n if (!isShallow) {\n if (render.length >= 3) {\n throw new Error(render.name + ' cannot be rendered outside a collection.');\n }\n return render(props, ref);\n }\n\n return useSSRCollectionNode(type, props, ref, 'children' in props ? props.children : null, null, node => <Component node={node} />);\n });\n // @ts-ignore\n Result.displayName = render.name;\n return Result;\n}\n\nexport 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) {\n let Component = ({node}) => render(node.props, node.props.ref, node);\n let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {\n let children = useChildren(props);\n return useSSRCollectionNode(type, props, ref, null, children, node => <Component node={node} />) ?? <></>;\n });\n // @ts-ignore\n Result.displayName = render.name;\n return Result;\n}\n\nfunction useCollectionChildren<T extends object>(options: CachedChildrenOptions<T>) {\n return useCachedChildren({...options, addIdAndValue: true});\n}\n\nexport interface CollectionProps<T> extends CachedChildrenOptions<T> {}\n\nconst CollectionContext = createContext<CachedChildrenOptions<unknown> | null>(null);\n\n/** A Collection renders a list of items, automatically managing caching and keys. */\nexport function Collection<T extends object>(props: CollectionProps<T>): JSX.Element {\n let ctx = useContext(CollectionContext)!;\n let dependencies = (ctx?.dependencies || []).concat(props.dependencies);\n let idScope = props.idScope || ctx?.idScope;\n let children = useCollectionChildren({\n ...props,\n idScope,\n dependencies\n });\n\n let doc = useContext(CollectionDocumentContext);\n if (doc) {\n children = <CollectionRoot>{children}</CollectionRoot>;\n }\n\n // Propagate dependencies and idScope to child collections.\n ctx = useMemo(() => ({\n dependencies,\n idScope\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }), [idScope, ...dependencies]);\n\n return (\n <CollectionContext.Provider value={ctx}>\n {children}\n </CollectionContext.Provider>\n );\n}\n\nfunction CollectionRoot({children}) {\n let doc = useContext(CollectionDocumentContext);\n let wrappedChildren = useMemo(() => (\n <CollectionDocumentContext.Provider value={null}>\n <ShallowRenderContext.Provider value>\n {children}\n </ShallowRenderContext.Provider>\n </CollectionDocumentContext.Provider>\n ), [children]);\n // During SSR, we render the content directly, and append nodes to the document during render.\n // The collection children return null so that nothing is actually rendered into the HTML.\n return useIsSSR()\n ? <SSRContext.Provider value={doc}>{wrappedChildren}</SSRContext.Provider>\n : createPortal(wrappedChildren, doc as unknown as Element);\n}\n"],"names":[],"version":3,"file":"CollectionBuilder.main.js.map"}
|
|
@@ -32,7 +32,12 @@ const $e1995378a142960e$var$CollectionDocumentContext = /*#__PURE__*/ (0, $95feo
|
|
|
32
32
|
function $e1995378a142960e$export$bf788dd355e3a401(props) {
|
|
33
33
|
// If a document was provided above us, we're already in a hidden tree. Just render the content.
|
|
34
34
|
let doc = (0, $95feo$useContext)($e1995378a142960e$var$CollectionDocumentContext);
|
|
35
|
-
if (doc)
|
|
35
|
+
if (doc) // The React types prior to 18 did not allow returning ReactNode from components
|
|
36
|
+
// even though the actual implementation since React 16 did.
|
|
37
|
+
// We must return ReactElement so that TS does not complain that <CollectionBuilder>
|
|
38
|
+
// is not a valid JSX element with React 16 and 17 types.
|
|
39
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544
|
|
40
|
+
return props.content;
|
|
36
41
|
// Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.
|
|
37
42
|
// This should always come before the real DOM content so we have built the collection by the time it renders during SSR.
|
|
38
43
|
// This is fine. CollectionDocumentContext never changes after mounting.
|
|
@@ -32,7 +32,12 @@ const $e1995378a142960e$var$CollectionDocumentContext = /*#__PURE__*/ (0, $95feo
|
|
|
32
32
|
function $e1995378a142960e$export$bf788dd355e3a401(props) {
|
|
33
33
|
// If a document was provided above us, we're already in a hidden tree. Just render the content.
|
|
34
34
|
let doc = (0, $95feo$useContext)($e1995378a142960e$var$CollectionDocumentContext);
|
|
35
|
-
if (doc)
|
|
35
|
+
if (doc) // The React types prior to 18 did not allow returning ReactNode from components
|
|
36
|
+
// even though the actual implementation since React 16 did.
|
|
37
|
+
// We must return ReactElement so that TS does not complain that <CollectionBuilder>
|
|
38
|
+
// is not a valid JSX element with React 16 and 17 types.
|
|
39
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544
|
|
40
|
+
return props.content;
|
|
36
41
|
// Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.
|
|
37
42
|
// This should always come before the real DOM content so we have built the collection by the time it renders during SSR.
|
|
38
43
|
// This is fine. CollectionDocumentContext never changes after mounting.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;AAaD,MAAM,2DAAuB,CAAA,GAAA,oBAAY,EAAE;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ollectionBuilder.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 {BaseCollection} from './BaseCollection';\nimport {BaseNode, Document, ElementNode} from './Document';\nimport {CachedChildrenOptions, useCachedChildren} from './useCachedChildren';\nimport {createPortal} from 'react-dom';\nimport {forwardRefType, Node} from '@react-types/shared';\nimport {Hidden} from './Hidden';\nimport React, {createContext, ForwardedRef, forwardRef, JSX, ReactElement, ReactNode, useCallback, useContext, useMemo, useRef, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\nimport {useLayoutEffect} from '@react-aria/utils';\nimport {useSyncExternalStore as useSyncExternalStoreShim} from 'use-sync-external-store/shim/index.js';\n\nconst ShallowRenderContext = createContext(false);\nconst CollectionDocumentContext = createContext<Document<any, BaseCollection<any>> | null>(null);\n\nexport interface CollectionBuilderProps<C extends BaseCollection<object>> {\n content: ReactNode,\n children: (collection: C) => ReactNode,\n createCollection?: () => C\n}\n\n/**\n * Builds a `Collection` from the children provided to the `content` prop, and passes it to the child render prop function.\n */\nexport function CollectionBuilder<C extends BaseCollection<object>>(props: CollectionBuilderProps<C>) {\n // If a document was provided above us, we're already in a hidden tree. Just render the content.\n let doc = useContext(CollectionDocumentContext);\n if (doc) {\n return props.content;\n }\n\n // Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.\n // This should always come before the real DOM content so we have built the collection by the time it renders during SSR.\n\n // This is fine. CollectionDocumentContext never changes after mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let {collection, document} = useCollectionDocument(props.createCollection);\n return (\n <>\n <Hidden>\n <CollectionDocumentContext.Provider value={document}>\n {props.content}\n </CollectionDocumentContext.Provider>\n </Hidden>\n <CollectionInner render={props.children} collection={collection} />\n </>\n );\n}\n\nfunction CollectionInner({collection, render}) {\n return render(collection);\n}\n\ninterface CollectionDocumentResult<T, C extends BaseCollection<T>> {\n collection: C,\n document: Document<T, C>\n}\n\n// React 16 and 17 don't support useSyncExternalStore natively, and the shim provided by React does not support getServerSnapshot.\n// This wrapper uses the shim, but additionally calls getServerSnapshot during SSR (according to SSRProvider).\nfunction useSyncExternalStoreFallback<C>(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => C, getServerSnapshot: () => C): C {\n let isSSR = useIsSSR();\n let isSSRRef = useRef(isSSR);\n // This is read immediately inside the wrapper, which also runs during render.\n // We just need a ref to avoid invalidating the callback itself, which\n // would cause React to re-run the callback more than necessary.\n // eslint-disable-next-line rulesdir/pure-render\n isSSRRef.current = isSSR;\n\n let getSnapshotWrapper = useCallback(() => {\n return isSSRRef.current ? getServerSnapshot() : getSnapshot();\n }, [getSnapshot, getServerSnapshot]);\n return useSyncExternalStoreShim(subscribe, getSnapshotWrapper);\n}\n\nconst useSyncExternalStore = typeof React['useSyncExternalStore'] === 'function'\n ? React['useSyncExternalStore']\n : useSyncExternalStoreFallback;\n\nfunction useCollectionDocument<T extends object, C extends BaseCollection<T>>(createCollection?: () => C): CollectionDocumentResult<T, C> {\n // The document instance is mutable, and should never change between renders.\n // useSyncExternalStore is used to subscribe to updates, which vends immutable Collection objects.\n let [document] = useState(() => new Document<T, C>(createCollection?.() || new BaseCollection() as C));\n let subscribe = useCallback((fn: () => void) => document.subscribe(fn), [document]);\n let getSnapshot = useCallback(() => {\n let collection = document.getCollection();\n if (document.isSSR) {\n // After SSR is complete, reset the document to empty so it is ready for React to render the portal into.\n // We do this _after_ getting the collection above so that the collection still has content in it from SSR\n // during the current render, before React has finished the client render.\n document.resetAfterSSR();\n }\n return collection;\n }, [document]);\n let getServerSnapshot = useCallback(() => {\n document.isSSR = true;\n return document.getCollection();\n }, [document]);\n let collection = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n useLayoutEffect(() => {\n document.isMounted = true;\n return () => {\n // Mark unmounted so we can skip all of the collection updates caused by \n // React calling removeChild on every item in the collection.\n document.isMounted = false;\n };\n }, [document]);\n return {collection, document};\n}\n\nconst SSRContext = createContext<BaseNode<any> | null>(null);\n\nfunction useSSRCollectionNode<T extends Element>(Type: string, props: object, ref: ForwardedRef<T>, rendered?: any, children?: ReactNode, render?: (node: Node<T>) => ReactElement) {\n // During SSR, portals are not supported, so the collection children will be wrapped in an SSRContext.\n // Since SSR occurs only once, we assume that the elements are rendered in order and never re-render.\n // Therefore we can create elements in our collection document during render so that they are in the\n // collection by the time we need to use the collection to render to the real DOM.\n // After hydration, we switch to client rendering using the portal.\n let itemRef = useCallback((element: ElementNode<any> | null) => {\n element?.setProps(props, ref, rendered, render);\n }, [props, ref, rendered, render]);\n let parentNode = useContext(SSRContext);\n if (parentNode) {\n // Guard against double rendering in strict mode.\n let element = parentNode.ownerDocument.nodesByProps.get(props);\n if (!element) {\n element = parentNode.ownerDocument.createElement(Type);\n element.setProps(props, ref, rendered, render);\n parentNode.appendChild(element);\n parentNode.ownerDocument.updateCollection();\n parentNode.ownerDocument.nodesByProps.set(props, element);\n }\n\n return children\n ? <SSRContext.Provider value={element}>{children}</SSRContext.Provider>\n : null;\n }\n\n // @ts-ignore\n return <Type ref={itemRef}>{children}</Type>;\n}\n\nexport function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) => ReactNode): (props: P & React.RefAttributes<T>) => ReactNode | null;\nexport function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactNode): (props: P & React.RefAttributes<T>) => ReactNode | null;\nexport function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactNode) {\n let Component = ({node}) => render(node.props, node.props.ref, node);\n let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {\n let isShallow = useContext(ShallowRenderContext);\n if (!isShallow) {\n if (render.length >= 3) {\n throw new Error(render.name + ' cannot be rendered outside a collection.');\n }\n return render(props, ref);\n }\n\n return useSSRCollectionNode(type, props, ref, 'children' in props ? props.children : null, null, node => <Component node={node} />);\n });\n // @ts-ignore\n Result.displayName = render.name;\n return Result;\n}\n\nexport function createBranchComponent<T extends object, P extends {children?: any}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactNode, useChildren: (props: P) => ReactNode = useCollectionChildren) {\n let Component = ({node}) => render(node.props, node.props.ref, node);\n let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {\n let children = useChildren(props);\n return useSSRCollectionNode(type, props, ref, null, children, node => <Component node={node} />) ?? <></>;\n });\n // @ts-ignore\n Result.displayName = render.name;\n return Result;\n}\n\nfunction useCollectionChildren<T extends object>(options: CachedChildrenOptions<T>) {\n return useCachedChildren({...options, addIdAndValue: true});\n}\n\nexport interface CollectionProps<T> extends CachedChildrenOptions<T> {}\n\nconst CollectionContext = createContext<CachedChildrenOptions<unknown> | null>(null);\n\n/** A Collection renders a list of items, automatically managing caching and keys. */\nexport function Collection<T extends object>(props: CollectionProps<T>): JSX.Element {\n let ctx = useContext(CollectionContext)!;\n let dependencies = (ctx?.dependencies || []).concat(props.dependencies);\n let idScope = props.idScope || ctx?.idScope;\n let children = useCollectionChildren({\n ...props,\n idScope,\n dependencies\n });\n\n let doc = useContext(CollectionDocumentContext);\n if (doc) {\n children = <CollectionRoot>{children}</CollectionRoot>;\n }\n\n // Propagate dependencies and idScope to child collections.\n ctx = useMemo(() => ({\n dependencies,\n idScope\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }), [idScope, ...dependencies]);\n\n return (\n <CollectionContext.Provider value={ctx}>\n {children}\n </CollectionContext.Provider>\n );\n}\n\nfunction CollectionRoot({children}) {\n let doc = useContext(CollectionDocumentContext);\n let wrappedChildren = useMemo(() => (\n <CollectionDocumentContext.Provider value={null}>\n <ShallowRenderContext.Provider value>\n {children}\n </ShallowRenderContext.Provider>\n </CollectionDocumentContext.Provider>\n ), [children]);\n // During SSR, we render the content directly, and append nodes to the document during render.\n // The collection children return null so that nothing is actually rendered into the HTML.\n return useIsSSR()\n ? <SSRContext.Provider value={doc}>{wrappedChildren}</SSRContext.Provider>\n : createPortal(wrappedChildren, doc as unknown as Element);\n}\n"],"names":[],"version":3,"file":"CollectionBuilder.module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;AAaD,MAAM,2DAAuB,CAAA,GAAA,oBAAY,EAAE;AAC3C,MAAM,gEAA4B,CAAA,GAAA,oBAAY,EAA6C;AAWpF,SAAS,0CAAoD,KAAgC;IAClG,gGAAgG;IAChG,IAAI,MAAM,CAAA,GAAA,iBAAS,EAAE;IACrB,IAAI,KACF,gFAAgF;IAChF,4DAA4D;IAC5D,oFAAoF;IACpF,yDAAyD;IACzD,kEAAkE;IAClE,OAAO,MAAM,OAAO;IAGtB,qHAAqH;IACrH,yHAAyH;IAEzH,wEAAwE;IACxE,sDAAsD;IACtD,IAAI,cAAC,UAAU,YAAE,QAAQ,EAAC,GAAG,4CAAsB,MAAM,gBAAgB;IACzE,qBACE,gFACE,gCAAC,CAAA,GAAA,yCAAK,uBACJ,gCAAC,gDAA0B,QAAQ;QAAC,OAAO;OACxC,MAAM,OAAO,kBAGlB,gCAAC;QAAgB,QAAQ,MAAM,QAAQ;QAAE,YAAY;;AAG3D;AAEA,SAAS,sCAAgB,cAAC,UAAU,UAAE,MAAM,EAAC;IAC3C,OAAO,OAAO;AAChB;AAOA,kIAAkI;AAClI,8GAA8G;AAC9G,SAAS,mDAAgC,SAAoD,EAAE,WAAoB,EAAE,iBAA0B;IAC7I,IAAI,QAAQ,CAAA,GAAA,eAAO;IACnB,IAAI,WAAW,CAAA,GAAA,aAA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AAA;0BACnB;qBACA;QAEF,CAAA,GAAI;QAAC;WAAY;KAAa;IAE9B,qBACE,gCAAC,wCAAkB,QAAQ;QAAC,OAAO;OAChC;AAGP;AAEA,SAAS,qCAAe,YAAC,QAAQ,EAAC;IAChC,IAAI,MAAM,CAAA,GAAA,iBAAS,EAAE;IACrB,IAAI,kBAAkB,CAAA,GAAA,cAAM,EAAE,kBAC5B,gCAAC,gDAA0B,QAAQ;YAAC,OAAO;yBACzC,gCAAC,2CAAqB,QAAQ;YAAC,OAAA;WAC5B,YAGJ;QAAC;KAAS;IACb,8FAA8F;IAC9F,0FAA0F;IAC1F,OAAO,CAAA,GAAA,eAAO,oBACV,gCAAC,iCAAW,QAAQ;QAAC,OAAO;OAAM,iCAClC,CAAA,GAAA,mBAAW,EAAE,iBAAiB;AACpC","sources":["packages/@react-aria/collections/src/CollectionBuilder.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 {BaseCollection} from './BaseCollection';\nimport {BaseNode, Document, ElementNode} from './Document';\nimport {CachedChildrenOptions, useCachedChildren} from './useCachedChildren';\nimport {createPortal} from 'react-dom';\nimport {forwardRefType, Node} from '@react-types/shared';\nimport {Hidden} from './Hidden';\nimport React, {createContext, ForwardedRef, forwardRef, JSX, ReactElement, ReactNode, useCallback, useContext, useMemo, useRef, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\nimport {useLayoutEffect} from '@react-aria/utils';\nimport {useSyncExternalStore as useSyncExternalStoreShim} from 'use-sync-external-store/shim/index.js';\n\nconst ShallowRenderContext = createContext(false);\nconst CollectionDocumentContext = createContext<Document<any, BaseCollection<any>> | null>(null);\n\nexport interface CollectionBuilderProps<C extends BaseCollection<object>> {\n content: ReactNode,\n children: (collection: C) => ReactNode,\n createCollection?: () => C\n}\n\n/**\n * Builds a `Collection` from the children provided to the `content` prop, and passes it to the child render prop function.\n */\nexport function CollectionBuilder<C extends BaseCollection<object>>(props: CollectionBuilderProps<C>): ReactElement {\n // If a document was provided above us, we're already in a hidden tree. Just render the content.\n let doc = useContext(CollectionDocumentContext);\n if (doc) {\n // The React types prior to 18 did not allow returning ReactNode from components\n // even though the actual implementation since React 16 did.\n // We must return ReactElement so that TS does not complain that <CollectionBuilder>\n // is not a valid JSX element with React 16 and 17 types.\n // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544\n return props.content as ReactElement;\n }\n\n // Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.\n // This should always come before the real DOM content so we have built the collection by the time it renders during SSR.\n\n // This is fine. CollectionDocumentContext never changes after mounting.\n // eslint-disable-next-line react-hooks/rules-of-hooks\n let {collection, document} = useCollectionDocument(props.createCollection);\n return (\n <>\n <Hidden>\n <CollectionDocumentContext.Provider value={document}>\n {props.content}\n </CollectionDocumentContext.Provider>\n </Hidden>\n <CollectionInner render={props.children} collection={collection} />\n </>\n );\n}\n\nfunction CollectionInner({collection, render}) {\n return render(collection);\n}\n\ninterface CollectionDocumentResult<T, C extends BaseCollection<T>> {\n collection: C,\n document: Document<T, C>\n}\n\n// React 16 and 17 don't support useSyncExternalStore natively, and the shim provided by React does not support getServerSnapshot.\n// This wrapper uses the shim, but additionally calls getServerSnapshot during SSR (according to SSRProvider).\nfunction useSyncExternalStoreFallback<C>(subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => C, getServerSnapshot: () => C): C {\n let isSSR = useIsSSR();\n let isSSRRef = useRef(isSSR);\n // This is read immediately inside the wrapper, which also runs during render.\n // We just need a ref to avoid invalidating the callback itself, which\n // would cause React to re-run the callback more than necessary.\n // eslint-disable-next-line rulesdir/pure-render\n isSSRRef.current = isSSR;\n\n let getSnapshotWrapper = useCallback(() => {\n return isSSRRef.current ? getServerSnapshot() : getSnapshot();\n }, [getSnapshot, getServerSnapshot]);\n return useSyncExternalStoreShim(subscribe, getSnapshotWrapper);\n}\n\nconst useSyncExternalStore = typeof React['useSyncExternalStore'] === 'function'\n ? React['useSyncExternalStore']\n : useSyncExternalStoreFallback;\n\nfunction useCollectionDocument<T extends object, C extends BaseCollection<T>>(createCollection?: () => C): CollectionDocumentResult<T, C> {\n // The document instance is mutable, and should never change between renders.\n // useSyncExternalStore is used to subscribe to updates, which vends immutable Collection objects.\n let [document] = useState(() => new Document<T, C>(createCollection?.() || new BaseCollection() as C));\n let subscribe = useCallback((fn: () => void) => document.subscribe(fn), [document]);\n let getSnapshot = useCallback(() => {\n let collection = document.getCollection();\n if (document.isSSR) {\n // After SSR is complete, reset the document to empty so it is ready for React to render the portal into.\n // We do this _after_ getting the collection above so that the collection still has content in it from SSR\n // during the current render, before React has finished the client render.\n document.resetAfterSSR();\n }\n return collection;\n }, [document]);\n let getServerSnapshot = useCallback(() => {\n document.isSSR = true;\n return document.getCollection();\n }, [document]);\n let collection = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n useLayoutEffect(() => {\n document.isMounted = true;\n return () => {\n // Mark unmounted so we can skip all of the collection updates caused by \n // React calling removeChild on every item in the collection.\n document.isMounted = false;\n };\n }, [document]);\n return {collection, document};\n}\n\nconst SSRContext = createContext<BaseNode<any> | null>(null);\n\nfunction useSSRCollectionNode<T extends Element>(Type: string, props: object, ref: ForwardedRef<T>, rendered?: any, children?: ReactNode, render?: (node: Node<T>) => ReactElement) {\n // During SSR, portals are not supported, so the collection children will be wrapped in an SSRContext.\n // Since SSR occurs only once, we assume that the elements are rendered in order and never re-render.\n // Therefore we can create elements in our collection document during render so that they are in the\n // collection by the time we need to use the collection to render to the real DOM.\n // After hydration, we switch to client rendering using the portal.\n let itemRef = useCallback((element: ElementNode<any> | null) => {\n element?.setProps(props, ref, rendered, render);\n }, [props, ref, rendered, render]);\n let parentNode = useContext(SSRContext);\n if (parentNode) {\n // Guard against double rendering in strict mode.\n let element = parentNode.ownerDocument.nodesByProps.get(props);\n if (!element) {\n element = parentNode.ownerDocument.createElement(Type);\n element.setProps(props, ref, rendered, render);\n parentNode.appendChild(element);\n parentNode.ownerDocument.updateCollection();\n parentNode.ownerDocument.nodesByProps.set(props, element);\n }\n\n return children\n ? <SSRContext.Provider value={element}>{children}</SSRContext.Provider>\n : null;\n }\n\n // @ts-ignore\n return <Type ref={itemRef}>{children}</Type>;\n}\n\nexport 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>) => ReactElement | null;\nexport 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>) => ReactElement | null;\nexport function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement) {\n let Component = ({node}) => render(node.props, node.props.ref, node);\n let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {\n let isShallow = useContext(ShallowRenderContext);\n if (!isShallow) {\n if (render.length >= 3) {\n throw new Error(render.name + ' cannot be rendered outside a collection.');\n }\n return render(props, ref);\n }\n\n return useSSRCollectionNode(type, props, ref, 'children' in props ? props.children : null, null, node => <Component node={node} />);\n });\n // @ts-ignore\n Result.displayName = render.name;\n return Result;\n}\n\nexport 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) {\n let Component = ({node}) => render(node.props, node.props.ref, node);\n let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {\n let children = useChildren(props);\n return useSSRCollectionNode(type, props, ref, null, children, node => <Component node={node} />) ?? <></>;\n });\n // @ts-ignore\n Result.displayName = render.name;\n return Result;\n}\n\nfunction useCollectionChildren<T extends object>(options: CachedChildrenOptions<T>) {\n return useCachedChildren({...options, addIdAndValue: true});\n}\n\nexport interface CollectionProps<T> extends CachedChildrenOptions<T> {}\n\nconst CollectionContext = createContext<CachedChildrenOptions<unknown> | null>(null);\n\n/** A Collection renders a list of items, automatically managing caching and keys. */\nexport function Collection<T extends object>(props: CollectionProps<T>): JSX.Element {\n let ctx = useContext(CollectionContext)!;\n let dependencies = (ctx?.dependencies || []).concat(props.dependencies);\n let idScope = props.idScope || ctx?.idScope;\n let children = useCollectionChildren({\n ...props,\n idScope,\n dependencies\n });\n\n let doc = useContext(CollectionDocumentContext);\n if (doc) {\n children = <CollectionRoot>{children}</CollectionRoot>;\n }\n\n // Propagate dependencies and idScope to child collections.\n ctx = useMemo(() => ({\n dependencies,\n idScope\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }), [idScope, ...dependencies]);\n\n return (\n <CollectionContext.Provider value={ctx}>\n {children}\n </CollectionContext.Provider>\n );\n}\n\nfunction CollectionRoot({children}) {\n let doc = useContext(CollectionDocumentContext);\n let wrappedChildren = useMemo(() => (\n <CollectionDocumentContext.Provider value={null}>\n <ShallowRenderContext.Provider value>\n {children}\n </ShallowRenderContext.Provider>\n </CollectionDocumentContext.Provider>\n ), [children]);\n // During SSR, we render the content directly, and append nodes to the document during render.\n // The collection children return null so that nothing is actually rendered into the HTML.\n return useIsSSR()\n ? <SSRContext.Provider value={doc}>{wrappedChildren}</SSRContext.Provider>\n : createPortal(wrappedChildren, doc as unknown as Element);\n}\n"],"names":[],"version":3,"file":"CollectionBuilder.module.js.map"}
|
package/dist/Hidden.main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAOD,sGAAsG;AACtG,qGAAqG;AACrG,4GAA4G;AAC5G,kHAAkH;AAClH,qDAAqD;AACr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AC,OAAO,CAAC,UAAU;iBAE9B,OAAO,cAAc,IAAI,CAAC,IAAI;QAElC;IACF;AACF;AAEO,MAAM,0DAAgB,CAAA,GAAA,0BAAY,EAAW;AAEpD,oBAAoB;AACpB,MAAM,uCAAiB,OAAO,qBAAqB,cAAc,IAAI,qBAAqB;AAEnF,SAAS,0CAAO,KAA4B;IACjD,IAAI,WAAW,CAAA,GAAA,uBAAS,EAAE;IAC1B,IAAI,QAAQ,CAAA,GAAA,4BAAO;IACnB,IAAI,UACF,6CAA6C;IAC7C,qBAAO,sHAAG,MAAM,QAAQ;IAG1B,IAAI,yBACF,0DAAC,0CAAc,QAAQ;QAAC,OAAA;OACrB,MAAM,QAAQ;IAInB,gFAAgF;IAChF,8EAA8E;IAC9E,iGAAiG;IACjG,OAAO,sBACH,0DAAC;QAAS,0BAAA;OAAwB,0BAClC,CAAA,GAAA,4BAAW,EAAE,UAAU;AAC7B;AAIO,SAAS,0CAAmC,EAAwD;IACzG,IAAI,UAAU,CAAC,OAAU;QACvB,IAAI,WAAW,CAAA,GAAA,uBAAS,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,uBAAS,EAAqB;AACxC;AAGO,SAAS;IACd,OAAO,CAAA,GAAA,uBAAS,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 {createPortal} from 'react-dom';\nimport {forwardRefType} from '@react-types/shared';\nimport React, {createContext, forwardRef, ReactElement, ReactNode, useContext} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\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\n// Portal to nowhere\nconst hiddenFragment = typeof DocumentFragment !== 'undefined' ? new DocumentFragment() : null;\n\nexport function Hidden(props: {children: ReactNode}) {\n let isHidden = useContext(HiddenContext);\n let isSSR = useIsSSR();\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, 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 DOM tree, so it won't affect ids or other accessibility attributes.\n return isSSR\n ? <template data-react-aria-hidden>{children}</template>\n : createPortal(children, hiddenFragment!);\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.main.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAOD,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;AAEpD,oBAAoB;AACpB,MAAM,uCAAiB,OAAO,qBAAqB,cAAc,IAAI,qBAAqB;AAEnF,SAAS,0CAAO,KAA4B;IACjD,IAAI,WAAW,CAAA,GAAA,iBAAS,EAAE;IAC1B,IAAI,QAAQ,CAAA,GAAA,eAAO;IACnB,IAAI,UACF,6CAA6C;IAC7C,qBAAO,kEAAG,MAAM,QAAQ;IAG1B,IAAI,yBACF,gCAAC,0CAAc,QAAQ;QAAC,OAAA;OACrB,MAAM,QAAQ;IAInB,gFAAgF;IAChF,8EAA8E;IAC9E,iGAAiG;IACjG,OAAO,sBACH,gCAAC;QAAS,0BAAA;OAAwB,0BAClC,CAAA,GAAA,mBAAW,EAAE,UAAU;AAC7B;AAIO,SAAS,0CAAmC,
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;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pB","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 {createPortal} from 'react-dom';\nimport {forwardRefType} from '@react-types/shared';\nimport React, {createContext, forwardRef, ReactElement, ReactNode, useContext} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\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\n// Portal to nowhere\nconst hiddenFragment = typeof DocumentFragment !== 'undefined' ? new DocumentFragment() : null;\n\nexport function Hidden(props: {children: ReactNode}) {\n let isHidden = useContext(HiddenContext);\n let isSSR = useIsSSR();\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, 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 DOM tree, so it won't affect ids or other accessibility attributes.\n return isSSR\n ? <template data-react-aria-hidden>{children}</template>\n : createPortal(children, hiddenFragment!);\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
|
@@ -61,7 +61,7 @@ export interface CachedChildrenOptions<T> {
|
|
|
61
61
|
*/
|
|
62
62
|
export function useCachedChildren<T extends object>(props: CachedChildrenOptions<T>): ReactNode;
|
|
63
63
|
/** Creates a component that forwards its ref and returns null if it is in a hidden subtree. */
|
|
64
|
-
export function createHideableComponent<T, P = {}>(fn: (props: P, ref: React.Ref<T>) =>
|
|
64
|
+
export function createHideableComponent<T, P = {}>(fn: (props: P, ref: React.Ref<T>) => ReactElement | null): (props: P & React.RefAttributes<T>) => ReactElement | null;
|
|
65
65
|
/** Returns whether the component is in a hidden subtree. */
|
|
66
66
|
export function useIsHidden(): boolean;
|
|
67
67
|
export interface CollectionBuilderProps<C extends BaseCollection<object>> {
|
|
@@ -72,12 +72,12 @@ export interface CollectionBuilderProps<C extends BaseCollection<object>> {
|
|
|
72
72
|
/**
|
|
73
73
|
* Builds a `Collection` from the children provided to the `content` prop, and passes it to the child render prop function.
|
|
74
74
|
*/
|
|
75
|
-
export function CollectionBuilder<C extends BaseCollection<object>>(props: CollectionBuilderProps<C>):
|
|
76
|
-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) =>
|
|
77
|
-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) =>
|
|
75
|
+
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>) => ReactElement | null;
|
|
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>) => ReactElement | null;
|
|
78
78
|
export function createBranchComponent<T extends object, P extends {
|
|
79
79
|
children?: any;
|
|
80
|
-
}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) =>
|
|
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>) => React.ReactElement | null;
|
|
81
81
|
export interface CollectionProps<T> extends CachedChildrenOptions<T> {
|
|
82
82
|
}
|
|
83
83
|
/** 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;I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E,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,YAAY,GAAG,IAAI,CAAC;AAC/N,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,YAAY,GAAG,IAAI,CAAC;AAmB9O,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,oEASzP;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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/collections",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.4743+f0aa6aace",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/ssr": "3.9.
|
|
26
|
-
"@react-aria/utils": "3.0.0-nightly.
|
|
27
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
25
|
+
"@react-aria/ssr": "3.9.6-nightly.4743+f0aa6aace",
|
|
26
|
+
"@react-aria/utils": "3.0.0-nightly.3026+f0aa6aace",
|
|
27
|
+
"@react-types/shared": "3.0.0-nightly.3026+f0aa6aace",
|
|
28
28
|
"@swc/helpers": "^0.5.0",
|
|
29
29
|
"use-sync-external-store": "^1.2.0"
|
|
30
30
|
},
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "f0aa6aacee60af265dc8994b9274ccf072a850aa"
|
|
39
39
|
}
|
|
@@ -33,11 +33,16 @@ export interface CollectionBuilderProps<C extends BaseCollection<object>> {
|
|
|
33
33
|
/**
|
|
34
34
|
* Builds a `Collection` from the children provided to the `content` prop, and passes it to the child render prop function.
|
|
35
35
|
*/
|
|
36
|
-
export function CollectionBuilder<C extends BaseCollection<object>>(props: CollectionBuilderProps<C>) {
|
|
36
|
+
export function CollectionBuilder<C extends BaseCollection<object>>(props: CollectionBuilderProps<C>): ReactElement {
|
|
37
37
|
// If a document was provided above us, we're already in a hidden tree. Just render the content.
|
|
38
38
|
let doc = useContext(CollectionDocumentContext);
|
|
39
39
|
if (doc) {
|
|
40
|
-
|
|
40
|
+
// The React types prior to 18 did not allow returning ReactNode from components
|
|
41
|
+
// even though the actual implementation since React 16 did.
|
|
42
|
+
// We must return ReactElement so that TS does not complain that <CollectionBuilder>
|
|
43
|
+
// is not a valid JSX element with React 16 and 17 types.
|
|
44
|
+
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544
|
|
45
|
+
return props.content as ReactElement;
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
// Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.
|
|
@@ -151,9 +156,9 @@ function useSSRCollectionNode<T extends Element>(Type: string, props: object, re
|
|
|
151
156
|
return <Type ref={itemRef}>{children}</Type>;
|
|
152
157
|
}
|
|
153
158
|
|
|
154
|
-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>) =>
|
|
155
|
-
export function createLeafComponent<T extends object, P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) =>
|
|
156
|
-
export function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) =>
|
|
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>) => ReactElement | null;
|
|
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>) => ReactElement | null;
|
|
161
|
+
export function createLeafComponent<P extends object, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement) {
|
|
157
162
|
let Component = ({node}) => render(node.props, node.props.ref, node);
|
|
158
163
|
let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {
|
|
159
164
|
let isShallow = useContext(ShallowRenderContext);
|
|
@@ -171,7 +176,7 @@ export function createLeafComponent<P extends object, E extends Element>(type: s
|
|
|
171
176
|
return Result;
|
|
172
177
|
}
|
|
173
178
|
|
|
174
|
-
export function createBranchComponent<T extends object, P extends {children?: any}, E extends Element>(type: string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) =>
|
|
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) {
|
|
175
180
|
let Component = ({node}) => render(node.props, node.props.ref, node);
|
|
176
181
|
let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {
|
|
177
182
|
let children = useChildren(props);
|
package/src/Hidden.tsx
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import {createPortal} from 'react-dom';
|
|
14
14
|
import {forwardRefType} from '@react-types/shared';
|
|
15
|
-
import React, {createContext, forwardRef, ReactNode, useContext} from 'react';
|
|
15
|
+
import React, {createContext, forwardRef, ReactElement, ReactNode, useContext} from 'react';
|
|
16
16
|
import {useIsSSR} from '@react-aria/ssr';
|
|
17
17
|
|
|
18
18
|
// React doesn't understand the <template> element, which doesn't have children like a normal element.
|
|
@@ -64,7 +64,7 @@ export function Hidden(props: {children: ReactNode}) {
|
|
|
64
64
|
|
|
65
65
|
/** Creates a component that forwards its ref and returns null if it is in a hidden subtree. */
|
|
66
66
|
// Note: this function is handled specially in the documentation generator. If you change it, you'll need to update DocsTransformer as well.
|
|
67
|
-
export function createHideableComponent<T, P = {}>(fn: (props: P, ref: React.Ref<T>) =>
|
|
67
|
+
export function createHideableComponent<T, P = {}>(fn: (props: P, ref: React.Ref<T>) => ReactElement | null): (props: P & React.RefAttributes<T>) => ReactElement | null {
|
|
68
68
|
let Wrapper = (props: P, ref: React.Ref<T>) => {
|
|
69
69
|
let isHidden = useContext(HiddenContext);
|
|
70
70
|
if (isHidden) {
|