@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
|
@@ -1 +1 @@
|
|
|
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,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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"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;AAcD,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;AA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,MAAM,CAAC,MAAM,YAAY;IACtE,IAAI,UAAU,MAAM,OAAO,KAAI,gBAAA,0BAAA,IAAK,OAAO;IAC3C,IAAI,WAAW,4CAAsB;QACnC,GAAG,KAAK;iBACR;sBACA;IACF;IAEA,IAAI,MAAM,CAAA,GAAA,uBAAS,EAAE;IACrB,IAAI,KACF,yBAAW,0DAAC,4CAAgB;IAG9B,2DAA2D;IAC3D,MAAM,CAAA,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 {FocusableContext} from '@react-aria/interactions';\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>) => ReactNode;\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>) => ReactNode;\nexport 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 {\n let Component = ({node}) => render(node.props, node.props.ref, node);\n let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {\n let focusableProps = useContext(FocusableContext);\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(\n type,\n props,\n ref,\n 'children' in props ? props.children : null,\n null,\n node => (\n // Forward FocusableContext to real DOM tree so tooltips work.\n <FocusableContext.Provider value={focusableProps}>\n <Component node={node} />\n </FocusableContext.Provider>\n )\n );\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): (props: P & React.RefAttributes<E>) => 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 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"}
|
|
@@ -3,6 +3,7 @@ import {Document as $681cc3c98f569e39$export$b34a105447964f9f} from "./Document.
|
|
|
3
3
|
import {useCachedChildren as $e948873055cbafe4$export$727c8fc270210f13} from "./useCachedChildren.mjs";
|
|
4
4
|
import {Hidden as $f39a9eba43920ace$export$8dc98ba7eadeaa56} from "./Hidden.mjs";
|
|
5
5
|
import {createPortal as $95feo$createPortal} from "react-dom";
|
|
6
|
+
import {FocusableContext as $95feo$FocusableContext} from "@react-aria/interactions";
|
|
6
7
|
import $95feo$react, {createContext as $95feo$createContext, useContext as $95feo$useContext, useRef as $95feo$useRef, useCallback as $95feo$useCallback, useState as $95feo$useState, forwardRef as $95feo$forwardRef, useMemo as $95feo$useMemo} from "react";
|
|
7
8
|
import {useIsSSR as $95feo$useIsSSR} from "@react-aria/ssr";
|
|
8
9
|
import {useLayoutEffect as $95feo$useLayoutEffect} from "@react-aria/utils";
|
|
@@ -27,6 +28,7 @@ import {useSyncExternalStore as $95feo$useSyncExternalStore} from "use-sync-exte
|
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
|
|
31
|
+
|
|
30
32
|
const $e1995378a142960e$var$ShallowRenderContext = /*#__PURE__*/ (0, $95feo$createContext)(false);
|
|
31
33
|
const $e1995378a142960e$var$CollectionDocumentContext = /*#__PURE__*/ (0, $95feo$createContext)(null);
|
|
32
34
|
function $e1995378a142960e$export$bf788dd355e3a401(props) {
|
|
@@ -99,7 +101,7 @@ function $e1995378a142960e$var$useCollectionDocument(createCollection) {
|
|
|
99
101
|
(0, $95feo$useLayoutEffect)(()=>{
|
|
100
102
|
document.isMounted = true;
|
|
101
103
|
return ()=>{
|
|
102
|
-
// Mark unmounted so we can skip all of the collection updates caused by
|
|
104
|
+
// Mark unmounted so we can skip all of the collection updates caused by
|
|
103
105
|
// React calling removeChild on every item in the collection.
|
|
104
106
|
document.isMounted = false;
|
|
105
107
|
};
|
|
@@ -149,14 +151,18 @@ function $e1995378a142960e$var$useSSRCollectionNode(Type, props, ref, rendered,
|
|
|
149
151
|
function $e1995378a142960e$export$18af5c7a9e9b3664(type, render) {
|
|
150
152
|
let Component = ({ node: node })=>render(node.props, node.props.ref, node);
|
|
151
153
|
let Result = (0, $95feo$forwardRef)((props, ref)=>{
|
|
154
|
+
let focusableProps = (0, $95feo$useContext)((0, $95feo$FocusableContext));
|
|
152
155
|
let isShallow = (0, $95feo$useContext)($e1995378a142960e$var$ShallowRenderContext);
|
|
153
156
|
if (!isShallow) {
|
|
154
157
|
if (render.length >= 3) throw new Error(render.name + ' cannot be rendered outside a collection.');
|
|
155
158
|
return render(props, ref);
|
|
156
159
|
}
|
|
157
|
-
return $e1995378a142960e$var$useSSRCollectionNode(type, props, ref, 'children' in props ? props.children : null, null, (node)
|
|
160
|
+
return $e1995378a142960e$var$useSSRCollectionNode(type, props, ref, 'children' in props ? props.children : null, null, (node)=>// Forward FocusableContext to real DOM tree so tooltips work.
|
|
161
|
+
/*#__PURE__*/ (0, $95feo$react).createElement((0, $95feo$FocusableContext).Provider, {
|
|
162
|
+
value: focusableProps
|
|
163
|
+
}, /*#__PURE__*/ (0, $95feo$react).createElement(Component, {
|
|
158
164
|
node: node
|
|
159
|
-
}));
|
|
165
|
+
})));
|
|
160
166
|
});
|
|
161
167
|
// @ts-ignore
|
|
162
168
|
Result.displayName = render.name;
|
|
@@ -3,6 +3,7 @@ import {Document as $681cc3c98f569e39$export$b34a105447964f9f} from "./Document.
|
|
|
3
3
|
import {useCachedChildren as $e948873055cbafe4$export$727c8fc270210f13} from "./useCachedChildren.module.js";
|
|
4
4
|
import {Hidden as $f39a9eba43920ace$export$8dc98ba7eadeaa56} from "./Hidden.module.js";
|
|
5
5
|
import {createPortal as $95feo$createPortal} from "react-dom";
|
|
6
|
+
import {FocusableContext as $95feo$FocusableContext} from "@react-aria/interactions";
|
|
6
7
|
import $95feo$react, {createContext as $95feo$createContext, useContext as $95feo$useContext, useRef as $95feo$useRef, useCallback as $95feo$useCallback, useState as $95feo$useState, forwardRef as $95feo$forwardRef, useMemo as $95feo$useMemo} from "react";
|
|
7
8
|
import {useIsSSR as $95feo$useIsSSR} from "@react-aria/ssr";
|
|
8
9
|
import {useLayoutEffect as $95feo$useLayoutEffect} from "@react-aria/utils";
|
|
@@ -27,6 +28,7 @@ import {useSyncExternalStore as $95feo$useSyncExternalStore} from "use-sync-exte
|
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
|
|
31
|
+
|
|
30
32
|
const $e1995378a142960e$var$ShallowRenderContext = /*#__PURE__*/ (0, $95feo$createContext)(false);
|
|
31
33
|
const $e1995378a142960e$var$CollectionDocumentContext = /*#__PURE__*/ (0, $95feo$createContext)(null);
|
|
32
34
|
function $e1995378a142960e$export$bf788dd355e3a401(props) {
|
|
@@ -99,7 +101,7 @@ function $e1995378a142960e$var$useCollectionDocument(createCollection) {
|
|
|
99
101
|
(0, $95feo$useLayoutEffect)(()=>{
|
|
100
102
|
document.isMounted = true;
|
|
101
103
|
return ()=>{
|
|
102
|
-
// Mark unmounted so we can skip all of the collection updates caused by
|
|
104
|
+
// Mark unmounted so we can skip all of the collection updates caused by
|
|
103
105
|
// React calling removeChild on every item in the collection.
|
|
104
106
|
document.isMounted = false;
|
|
105
107
|
};
|
|
@@ -149,14 +151,18 @@ function $e1995378a142960e$var$useSSRCollectionNode(Type, props, ref, rendered,
|
|
|
149
151
|
function $e1995378a142960e$export$18af5c7a9e9b3664(type, render) {
|
|
150
152
|
let Component = ({ node: node })=>render(node.props, node.props.ref, node);
|
|
151
153
|
let Result = (0, $95feo$forwardRef)((props, ref)=>{
|
|
154
|
+
let focusableProps = (0, $95feo$useContext)((0, $95feo$FocusableContext));
|
|
152
155
|
let isShallow = (0, $95feo$useContext)($e1995378a142960e$var$ShallowRenderContext);
|
|
153
156
|
if (!isShallow) {
|
|
154
157
|
if (render.length >= 3) throw new Error(render.name + ' cannot be rendered outside a collection.');
|
|
155
158
|
return render(props, ref);
|
|
156
159
|
}
|
|
157
|
-
return $e1995378a142960e$var$useSSRCollectionNode(type, props, ref, 'children' in props ? props.children : null, null, (node)
|
|
160
|
+
return $e1995378a142960e$var$useSSRCollectionNode(type, props, ref, 'children' in props ? props.children : null, null, (node)=>// Forward FocusableContext to real DOM tree so tooltips work.
|
|
161
|
+
/*#__PURE__*/ (0, $95feo$react).createElement((0, $95feo$FocusableContext).Provider, {
|
|
162
|
+
value: focusableProps
|
|
163
|
+
}, /*#__PURE__*/ (0, $95feo$react).createElement(Component, {
|
|
158
164
|
node: node
|
|
159
|
-
}));
|
|
165
|
+
})));
|
|
160
166
|
});
|
|
161
167
|
// @ts-ignore
|
|
162
168
|
Result.displayName = render.name;
|
|
@@ -1 +1 @@
|
|
|
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,gC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E;IACrB,IAAI,eAAe,AAAC,CAAA,CAAA,gBAAA,0BAAA,IAAK,YAAY,KAAI,EAAE,AAAD,EAAG,MAAM,CAAC,MAAM,YAAY;IACtE,IAAI,UAAU,MAAM,OAAO,KAAI,gBAAA,0BAAA,IAAK,OAAO;IAC3C,IAAI,WAAW,4CAAsB;QACnC,GAAG,KAAK;iBACR;sBACA;IACF;IAEA,IAAI,MAAM,CAAA,GAAA,iBAAS,EAAE;IACrB,IAAI,KACF,yBAAW,gCAAC,4CAAgB;IAG9B,2DAA2D;IAC3D,MAAM,CAAA,GAAA,cAAM,EAAE,IAAO,CAAA;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"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;;AAcD,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,aAAK,EAAE;IACtB,8EAA8E;IAC9E,sEAAsE;IACtE,gEAAgE;IAChE,gDAAgD;IAChD,SAAS,OAAO,GAAG;IAEnB,IAAI,qBAAqB,CAAA,GAAA,kBAAU,EAAE;QACnC,OAAO,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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 {FocusableContext} from '@react-aria/interactions';\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>) => ReactNode;\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>) => ReactNode;\nexport 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 {\n let Component = ({node}) => render(node.props, node.props.ref, node);\n let Result = (forwardRef as forwardRefType)((props: P, ref: ForwardedRef<E>) => {\n let focusableProps = useContext(FocusableContext);\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(\n type,\n props,\n ref,\n 'children' in props ? props.children : null,\n null,\n node => (\n // Forward FocusableContext to real DOM tree so tooltips work.\n <FocusableContext.Provider value={focusableProps}>\n <Component node={node} />\n </FocusableContext.Provider>\n )\n );\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): (props: P & React.RefAttributes<E>) => 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 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/Document.main.js
CHANGED
|
@@ -64,8 +64,18 @@ class $c20afee375f3b2d6$export$410b0c854570d131 {
|
|
|
64
64
|
var _this_parentNode;
|
|
65
65
|
return ((_this_parentNode = this.parentNode) === null || _this_parentNode === void 0 ? void 0 : _this_parentNode.isConnected) || false;
|
|
66
66
|
}
|
|
67
|
+
invalidateChildIndices(child) {
|
|
68
|
+
if (this._minInvalidChildIndex == null || child.index < this._minInvalidChildIndex.index) this._minInvalidChildIndex = child;
|
|
69
|
+
}
|
|
70
|
+
updateChildIndices() {
|
|
71
|
+
let node = this._minInvalidChildIndex;
|
|
72
|
+
while(node){
|
|
73
|
+
node.index = node.previousSibling ? node.previousSibling.index + 1 : 0;
|
|
74
|
+
node = node.nextSibling;
|
|
75
|
+
}
|
|
76
|
+
this._minInvalidChildIndex = null;
|
|
77
|
+
}
|
|
67
78
|
appendChild(child) {
|
|
68
|
-
this.ownerDocument.startTransaction();
|
|
69
79
|
if (child.parentNode) child.parentNode.removeChild(child);
|
|
70
80
|
if (this.firstChild == null) this.firstChild = child;
|
|
71
81
|
if (this.lastChild) {
|
|
@@ -80,15 +90,10 @@ class $c20afee375f3b2d6$export$410b0c854570d131 {
|
|
|
80
90
|
child.nextSibling = null;
|
|
81
91
|
this.lastChild = child;
|
|
82
92
|
this.ownerDocument.markDirty(this);
|
|
83
|
-
if (child.hasSetProps) // Only add the node to the collection if we already received props for it.
|
|
84
|
-
// Otherwise wait until then so we have the correct id for the node.
|
|
85
|
-
this.ownerDocument.addNode(child);
|
|
86
|
-
this.ownerDocument.endTransaction();
|
|
87
93
|
this.ownerDocument.queueUpdate();
|
|
88
94
|
}
|
|
89
95
|
insertBefore(newNode, referenceNode) {
|
|
90
96
|
if (referenceNode == null) return this.appendChild(newNode);
|
|
91
|
-
this.ownerDocument.startTransaction();
|
|
92
97
|
if (newNode.parentNode) newNode.parentNode.removeChild(newNode);
|
|
93
98
|
newNode.nextSibling = referenceNode;
|
|
94
99
|
newNode.previousSibling = referenceNode.previousSibling;
|
|
@@ -97,24 +102,15 @@ class $c20afee375f3b2d6$export$410b0c854570d131 {
|
|
|
97
102
|
else if (referenceNode.previousSibling) referenceNode.previousSibling.nextSibling = newNode;
|
|
98
103
|
referenceNode.previousSibling = newNode;
|
|
99
104
|
newNode.parentNode = referenceNode.parentNode;
|
|
100
|
-
|
|
101
|
-
while(node){
|
|
102
|
-
node.index++;
|
|
103
|
-
node = node.nextSibling;
|
|
104
|
-
}
|
|
105
|
-
if (newNode.hasSetProps) this.ownerDocument.addNode(newNode);
|
|
106
|
-
this.ownerDocument.endTransaction();
|
|
105
|
+
this.invalidateChildIndices(referenceNode);
|
|
107
106
|
this.ownerDocument.queueUpdate();
|
|
108
107
|
}
|
|
109
108
|
removeChild(child) {
|
|
110
109
|
if (child.parentNode !== this || !this.ownerDocument.isMounted) return;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
node.index--;
|
|
115
|
-
node = node.nextSibling;
|
|
110
|
+
if (child.nextSibling) {
|
|
111
|
+
this.invalidateChildIndices(child.nextSibling);
|
|
112
|
+
child.nextSibling.previousSibling = child.previousSibling;
|
|
116
113
|
}
|
|
117
|
-
if (child.nextSibling) child.nextSibling.previousSibling = child.previousSibling;
|
|
118
114
|
if (child.previousSibling) child.previousSibling.nextSibling = child.nextSibling;
|
|
119
115
|
if (this.firstChild === child) this.firstChild = child.nextSibling;
|
|
120
116
|
if (this.lastChild === child) this.lastChild = child.previousSibling;
|
|
@@ -122,18 +118,38 @@ class $c20afee375f3b2d6$export$410b0c854570d131 {
|
|
|
122
118
|
child.nextSibling = null;
|
|
123
119
|
child.previousSibling = null;
|
|
124
120
|
child.index = 0;
|
|
125
|
-
this.ownerDocument.
|
|
126
|
-
this.ownerDocument.endTransaction();
|
|
121
|
+
this.ownerDocument.markDirty(child);
|
|
127
122
|
this.ownerDocument.queueUpdate();
|
|
128
123
|
}
|
|
129
124
|
addEventListener() {}
|
|
130
125
|
removeEventListener() {}
|
|
126
|
+
get previousVisibleSibling() {
|
|
127
|
+
let node = this.previousSibling;
|
|
128
|
+
while(node && node.isHidden)node = node.previousSibling;
|
|
129
|
+
return node;
|
|
130
|
+
}
|
|
131
|
+
get nextVisibleSibling() {
|
|
132
|
+
let node = this.nextSibling;
|
|
133
|
+
while(node && node.isHidden)node = node.nextSibling;
|
|
134
|
+
return node;
|
|
135
|
+
}
|
|
136
|
+
get firstVisibleChild() {
|
|
137
|
+
let node = this.firstChild;
|
|
138
|
+
while(node && node.isHidden)node = node.nextSibling;
|
|
139
|
+
return node;
|
|
140
|
+
}
|
|
141
|
+
get lastVisibleChild() {
|
|
142
|
+
let node = this.lastChild;
|
|
143
|
+
while(node && node.isHidden)node = node.previousSibling;
|
|
144
|
+
return node;
|
|
145
|
+
}
|
|
131
146
|
constructor(ownerDocument){
|
|
132
147
|
this._firstChild = null;
|
|
133
148
|
this._lastChild = null;
|
|
134
149
|
this._previousSibling = null;
|
|
135
150
|
this._nextSibling = null;
|
|
136
151
|
this._parentNode = null;
|
|
152
|
+
this._minInvalidChildIndex = null;
|
|
137
153
|
this.ownerDocument = ownerDocument;
|
|
138
154
|
}
|
|
139
155
|
}
|
|
@@ -149,62 +165,97 @@ class $c20afee375f3b2d6$export$dc064fe9e59310fd extends $c20afee375f3b2d6$export
|
|
|
149
165
|
if (this.parentNode instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd) return this.parentNode.level + (this.node.type === 'item' ? 1 : 0);
|
|
150
166
|
return 0;
|
|
151
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Lazily gets a mutable instance of a Node. If the node has already
|
|
170
|
+
* been cloned during this update cycle, it just returns the existing one.
|
|
171
|
+
*/ getMutableNode() {
|
|
172
|
+
if (!this.isMutated) {
|
|
173
|
+
this.node = this.node.clone();
|
|
174
|
+
this.isMutated = true;
|
|
175
|
+
}
|
|
176
|
+
this.ownerDocument.markDirty(this);
|
|
177
|
+
return this.node;
|
|
178
|
+
}
|
|
152
179
|
updateNode() {
|
|
153
|
-
var
|
|
154
|
-
let
|
|
180
|
+
var _this_previousVisibleSibling, _this_firstVisibleChild, _this_lastVisibleChild;
|
|
181
|
+
let nextSibling = this.nextVisibleSibling;
|
|
182
|
+
let node = this.getMutableNode();
|
|
155
183
|
node.index = this.index;
|
|
156
184
|
node.level = this.level;
|
|
157
185
|
node.parentKey = this.parentNode instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd ? this.parentNode.node.key : null;
|
|
158
|
-
var
|
|
159
|
-
node.prevKey = (
|
|
160
|
-
var
|
|
161
|
-
node.nextKey = (
|
|
186
|
+
var _this_previousVisibleSibling_node_key;
|
|
187
|
+
node.prevKey = (_this_previousVisibleSibling_node_key = (_this_previousVisibleSibling = this.previousVisibleSibling) === null || _this_previousVisibleSibling === void 0 ? void 0 : _this_previousVisibleSibling.node.key) !== null && _this_previousVisibleSibling_node_key !== void 0 ? _this_previousVisibleSibling_node_key : null;
|
|
188
|
+
var _nextSibling_node_key;
|
|
189
|
+
node.nextKey = (_nextSibling_node_key = nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.node.key) !== null && _nextSibling_node_key !== void 0 ? _nextSibling_node_key : null;
|
|
162
190
|
node.hasChildNodes = !!this.firstChild;
|
|
163
|
-
var
|
|
164
|
-
node.firstChildKey = (
|
|
165
|
-
var
|
|
166
|
-
node.lastChildKey = (
|
|
191
|
+
var _this_firstVisibleChild_node_key;
|
|
192
|
+
node.firstChildKey = (_this_firstVisibleChild_node_key = (_this_firstVisibleChild = this.firstVisibleChild) === null || _this_firstVisibleChild === void 0 ? void 0 : _this_firstVisibleChild.node.key) !== null && _this_firstVisibleChild_node_key !== void 0 ? _this_firstVisibleChild_node_key : null;
|
|
193
|
+
var _this_lastVisibleChild_node_key;
|
|
194
|
+
node.lastChildKey = (_this_lastVisibleChild_node_key = (_this_lastVisibleChild = this.lastVisibleChild) === null || _this_lastVisibleChild === void 0 ? void 0 : _this_lastVisibleChild.node.key) !== null && _this_lastVisibleChild_node_key !== void 0 ? _this_lastVisibleChild_node_key : null;
|
|
195
|
+
// Update the colIndex of sibling nodes if this node has a colSpan.
|
|
196
|
+
if ((node.colSpan != null || node.colIndex != null) && nextSibling) {
|
|
197
|
+
var _node_colIndex, _node_colSpan;
|
|
198
|
+
// This queues the next sibling for update, which means this happens recursively.
|
|
199
|
+
let nextColIndex = ((_node_colIndex = node.colIndex) !== null && _node_colIndex !== void 0 ? _node_colIndex : node.index) + ((_node_colSpan = node.colSpan) !== null && _node_colSpan !== void 0 ? _node_colSpan : 1);
|
|
200
|
+
if (nextColIndex !== nextSibling.node.colIndex) {
|
|
201
|
+
let siblingNode = nextSibling.getMutableNode();
|
|
202
|
+
siblingNode.colIndex = nextColIndex;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
167
205
|
}
|
|
168
206
|
setProps(obj, ref, rendered, render) {
|
|
169
|
-
let node = this.
|
|
170
|
-
let { value:
|
|
207
|
+
let node = this.getMutableNode();
|
|
208
|
+
let { value: value1, textValue: textValue, id: id, ...props } = obj;
|
|
171
209
|
props.ref = ref;
|
|
172
210
|
node.props = props;
|
|
173
211
|
node.rendered = rendered;
|
|
174
212
|
node.render = render;
|
|
175
|
-
node.value =
|
|
213
|
+
node.value = value1;
|
|
176
214
|
node.textValue = textValue || (typeof props.children === 'string' ? props.children : '') || obj['aria-label'] || '';
|
|
177
215
|
if (id != null && id !== node.key) {
|
|
178
216
|
if (this.hasSetProps) throw new Error('Cannot change the id of an item');
|
|
179
217
|
node.key = id;
|
|
180
218
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (!this.hasSetProps) {
|
|
184
|
-
this.ownerDocument.addNode(this);
|
|
185
|
-
this.ownerDocument.endTransaction();
|
|
186
|
-
this.hasSetProps = true;
|
|
187
|
-
}
|
|
219
|
+
if (props.colSpan != null) node.colSpan = props.colSpan;
|
|
220
|
+
this.hasSetProps = true;
|
|
188
221
|
this.ownerDocument.queueUpdate();
|
|
189
222
|
}
|
|
190
223
|
get style() {
|
|
191
|
-
|
|
224
|
+
// React sets display: none to hide elements during Suspense.
|
|
225
|
+
// We'll handle this by setting the element to hidden and invalidating
|
|
226
|
+
// its siblings/parent. Hidden elements remain in the Document, but
|
|
227
|
+
// are removed from the Collection.
|
|
228
|
+
let element = this;
|
|
229
|
+
return {
|
|
230
|
+
get display () {
|
|
231
|
+
return element.isHidden ? 'none' : '';
|
|
232
|
+
},
|
|
233
|
+
set display (value){
|
|
234
|
+
let isHidden = value === 'none';
|
|
235
|
+
if (element.isHidden !== isHidden) {
|
|
236
|
+
var _element_parentNode, _element_parentNode1;
|
|
237
|
+
// Mark parent node dirty if this element is currently the first or last visible child.
|
|
238
|
+
if (((_element_parentNode = element.parentNode) === null || _element_parentNode === void 0 ? void 0 : _element_parentNode.firstVisibleChild) === element || ((_element_parentNode1 = element.parentNode) === null || _element_parentNode1 === void 0 ? void 0 : _element_parentNode1.lastVisibleChild) === element) element.ownerDocument.markDirty(element.parentNode);
|
|
239
|
+
// Mark sibling visible elements dirty.
|
|
240
|
+
let prev = element.previousVisibleSibling;
|
|
241
|
+
let next = element.nextVisibleSibling;
|
|
242
|
+
if (prev) element.ownerDocument.markDirty(prev);
|
|
243
|
+
if (next) element.ownerDocument.markDirty(next);
|
|
244
|
+
// Mark self dirty.
|
|
245
|
+
element.isHidden = isHidden;
|
|
246
|
+
element.ownerDocument.markDirty(element);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
};
|
|
192
250
|
}
|
|
193
251
|
hasAttribute() {}
|
|
194
252
|
setAttribute() {}
|
|
195
253
|
setAttributeNS() {}
|
|
196
254
|
removeAttribute() {}
|
|
197
255
|
constructor(type, ownerDocument){
|
|
198
|
-
super(ownerDocument)
|
|
199
|
-
this.
|
|
200
|
-
;
|
|
201
|
-
this._index = 0;
|
|
202
|
-
this.hasSetProps = false;
|
|
256
|
+
super(ownerDocument), this.nodeType = 8 // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions)
|
|
257
|
+
, this.isMutated = true, this._index = 0, this.hasSetProps = false, this.isHidden = false;
|
|
203
258
|
this.node = new (0, $499e2959ba1abacc$exports.CollectionNode)(type, `react-aria-${++ownerDocument.nodeId}`);
|
|
204
|
-
// Start a transaction so that no updates are emitted from the collection
|
|
205
|
-
// until the props for this node are set. We don't know the real id for the
|
|
206
|
-
// node until then, so we need to avoid emitting collections in an inconsistent state.
|
|
207
|
-
this.ownerDocument.startTransaction();
|
|
208
259
|
}
|
|
209
260
|
}
|
|
210
261
|
class $c20afee375f3b2d6$export$b34a105447964f9f extends $c20afee375f3b2d6$export$410b0c854570d131 {
|
|
@@ -214,72 +265,70 @@ class $c20afee375f3b2d6$export$b34a105447964f9f extends $c20afee375f3b2d6$export
|
|
|
214
265
|
createElement(type) {
|
|
215
266
|
return new $c20afee375f3b2d6$export$dc064fe9e59310fd(type, this);
|
|
216
267
|
}
|
|
217
|
-
/**
|
|
218
|
-
* Lazily gets a mutable instance of a Node. If the node has already
|
|
219
|
-
* been cloned during this update cycle, it just returns the existing one.
|
|
220
|
-
*/ getMutableNode(element) {
|
|
221
|
-
let node = element.node;
|
|
222
|
-
if (!this.mutatedNodes.has(element)) {
|
|
223
|
-
node = element.node.clone();
|
|
224
|
-
this.mutatedNodes.add(element);
|
|
225
|
-
element.node = node;
|
|
226
|
-
}
|
|
227
|
-
this.markDirty(element);
|
|
228
|
-
return node;
|
|
229
|
-
}
|
|
230
268
|
getMutableCollection() {
|
|
231
|
-
if (!this.
|
|
232
|
-
|
|
233
|
-
this.collectionMutated = true;
|
|
234
|
-
}
|
|
235
|
-
return this.collection;
|
|
269
|
+
if (!this.nextCollection) this.nextCollection = this.collection.clone();
|
|
270
|
+
return this.nextCollection;
|
|
236
271
|
}
|
|
237
272
|
markDirty(node) {
|
|
238
273
|
this.dirtyNodes.add(node);
|
|
239
274
|
}
|
|
240
|
-
startTransaction() {
|
|
241
|
-
this.transactionCount++;
|
|
242
|
-
}
|
|
243
|
-
endTransaction() {
|
|
244
|
-
this.transactionCount--;
|
|
245
|
-
}
|
|
246
275
|
addNode(element) {
|
|
276
|
+
if (element.isHidden) return;
|
|
247
277
|
let collection = this.getMutableCollection();
|
|
248
|
-
if (!collection.getItem(element.node.key))
|
|
249
|
-
|
|
250
|
-
for (let child of element)this.addNode(child);
|
|
251
|
-
}
|
|
252
|
-
this.markDirty(element);
|
|
278
|
+
if (!collection.getItem(element.node.key)) for (let child of element)this.addNode(child);
|
|
279
|
+
collection.addNode(element.node);
|
|
253
280
|
}
|
|
254
281
|
removeNode(node) {
|
|
255
282
|
for (let child of node)this.removeNode(child);
|
|
256
283
|
let collection = this.getMutableCollection();
|
|
257
284
|
collection.removeNode(node.node.key);
|
|
258
|
-
this.markDirty(node);
|
|
259
285
|
}
|
|
260
286
|
/** Finalizes the collection update, updating all nodes and freezing the collection. */ getCollection() {
|
|
261
|
-
|
|
287
|
+
// If in a subscription update, return a clone of the existing collection.
|
|
288
|
+
// This ensures React will queue a render. React will call getCollection again
|
|
289
|
+
// during render, at which point all the updates will be complete and we can return
|
|
290
|
+
// the new collection.
|
|
291
|
+
if (this.inSubscription) return this.collection.clone();
|
|
292
|
+
// Reset queuedRender to false when getCollection is called during render.
|
|
293
|
+
this.queuedRender = false;
|
|
262
294
|
this.updateCollection();
|
|
263
295
|
return this.collection;
|
|
264
296
|
}
|
|
265
297
|
updateCollection() {
|
|
266
|
-
|
|
298
|
+
// First, remove disconnected nodes and update the indices of dirty element children.
|
|
299
|
+
for (let element of this.dirtyNodes)if (element instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd && (!element.isConnected || element.isHidden)) this.removeNode(element);
|
|
300
|
+
else element.updateChildIndices();
|
|
301
|
+
// Next, update dirty collection nodes.
|
|
302
|
+
for (let element of this.dirtyNodes)if (element instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd) {
|
|
303
|
+
if (element.isConnected && !element.isHidden) {
|
|
304
|
+
element.updateNode();
|
|
305
|
+
this.addNode(element);
|
|
306
|
+
}
|
|
307
|
+
element.isMutated = false;
|
|
308
|
+
}
|
|
267
309
|
this.dirtyNodes.clear();
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
310
|
+
// Finally, update the collection.
|
|
311
|
+
if (this.nextCollection) {
|
|
312
|
+
var _this_firstVisibleChild, _this_lastVisibleChild;
|
|
313
|
+
var _this_firstVisibleChild_node_key, _this_lastVisibleChild_node_key;
|
|
314
|
+
this.nextCollection.commit((_this_firstVisibleChild_node_key = (_this_firstVisibleChild = this.firstVisibleChild) === null || _this_firstVisibleChild === void 0 ? void 0 : _this_firstVisibleChild.node.key) !== null && _this_firstVisibleChild_node_key !== void 0 ? _this_firstVisibleChild_node_key : null, (_this_lastVisibleChild_node_key = (_this_lastVisibleChild = this.lastVisibleChild) === null || _this_lastVisibleChild === void 0 ? void 0 : _this_lastVisibleChild.node.key) !== null && _this_lastVisibleChild_node_key !== void 0 ? _this_lastVisibleChild_node_key : null, this.isSSR);
|
|
315
|
+
if (!this.isSSR) {
|
|
316
|
+
this.collection = this.nextCollection;
|
|
317
|
+
this.nextCollection = null;
|
|
318
|
+
}
|
|
275
319
|
}
|
|
276
|
-
this.collectionMutated = false;
|
|
277
320
|
}
|
|
278
321
|
queueUpdate() {
|
|
279
|
-
|
|
280
|
-
//
|
|
281
|
-
|
|
322
|
+
if (this.dirtyNodes.size === 0 || this.queuedRender) return;
|
|
323
|
+
// Only trigger subscriptions once during an update, when the first item changes.
|
|
324
|
+
// React's useSyncExternalStore will call getCollection immediately, to check whether the snapshot changed.
|
|
325
|
+
// If so, React will queue a render to happen after the current commit to our fake DOM finishes.
|
|
326
|
+
// We track whether getCollection is called in a subscription, and once it is called during render,
|
|
327
|
+
// we reset queuedRender back to false.
|
|
328
|
+
this.queuedRender = true;
|
|
329
|
+
this.inSubscription = true;
|
|
282
330
|
for (let fn of this.subscriptions)fn();
|
|
331
|
+
this.inSubscription = false;
|
|
283
332
|
}
|
|
284
333
|
subscribe(fn) {
|
|
285
334
|
this.subscriptions.add(fn);
|
|
@@ -295,20 +344,10 @@ class $c20afee375f3b2d6$export$b34a105447964f9f extends $c20afee375f3b2d6$export
|
|
|
295
344
|
}
|
|
296
345
|
constructor(collection){
|
|
297
346
|
// @ts-ignore
|
|
298
|
-
super(null)
|
|
299
|
-
this.
|
|
300
|
-
;
|
|
301
|
-
this.ownerDocument = this;
|
|
302
|
-
this.dirtyNodes = new Set();
|
|
303
|
-
this.isSSR = false;
|
|
304
|
-
this.nodeId = 0;
|
|
305
|
-
this.nodesByProps = new WeakMap();
|
|
306
|
-
this.isMounted = true;
|
|
307
|
-
this.mutatedNodes = new Set();
|
|
308
|
-
this.subscriptions = new Set();
|
|
309
|
-
this.transactionCount = 0;
|
|
347
|
+
super(null), this.nodeType = 11 // DOCUMENT_FRAGMENT_NODE
|
|
348
|
+
, this.ownerDocument = this, this.dirtyNodes = new Set(), this.isSSR = false, this.nodeId = 0, this.nodesByProps = new WeakMap(), this.isMounted = true, this.nextCollection = null, this.subscriptions = new Set(), this.queuedRender = false, this.inSubscription = false;
|
|
310
349
|
this.collection = collection;
|
|
311
|
-
this.
|
|
350
|
+
this.nextCollection = collection;
|
|
312
351
|
}
|
|
313
352
|
}
|
|
314
353
|
|