@react-aria/collections 3.0.0-alpha.1 → 3.0.0-nightly.2988

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/dist/BaseCollection.main.js +157 -0
  3. package/dist/BaseCollection.main.js.map +1 -0
  4. package/dist/BaseCollection.mjs +151 -0
  5. package/dist/BaseCollection.module.js +151 -0
  6. package/dist/BaseCollection.module.js.map +1 -0
  7. package/dist/CollectionBuilder.main.js +233 -0
  8. package/dist/CollectionBuilder.main.js.map +1 -0
  9. package/dist/CollectionBuilder.mjs +221 -0
  10. package/dist/CollectionBuilder.module.js +221 -0
  11. package/dist/CollectionBuilder.module.js.map +1 -0
  12. package/dist/Document.main.js +316 -0
  13. package/dist/Document.main.js.map +1 -0
  14. package/dist/Document.mjs +311 -0
  15. package/dist/Document.module.js +311 -0
  16. package/dist/Document.module.js.map +1 -0
  17. package/dist/Hidden.main.js +79 -0
  18. package/dist/Hidden.main.js.map +1 -0
  19. package/dist/Hidden.mjs +68 -0
  20. package/dist/Hidden.module.js +68 -0
  21. package/dist/Hidden.module.js.map +1 -0
  22. package/dist/import.mjs +23 -0
  23. package/dist/main.js +27 -348
  24. package/dist/main.js.map +1 -0
  25. package/dist/module.js +17 -318
  26. package/dist/module.js.map +1 -0
  27. package/dist/types.d.ts +81 -24
  28. package/dist/types.d.ts.map +1 -1
  29. package/dist/useCachedChildren.main.js +63 -0
  30. package/dist/useCachedChildren.main.js.map +1 -0
  31. package/dist/useCachedChildren.mjs +58 -0
  32. package/dist/useCachedChildren.module.js +58 -0
  33. package/dist/useCachedChildren.module.js.map +1 -0
  34. package/package.json +17 -10
  35. package/src/BaseCollection.ts +211 -0
  36. package/src/CollectionBuilder.tsx +237 -0
  37. package/src/Document.ts +453 -0
  38. package/src/Hidden.tsx +84 -0
  39. package/src/index.ts +19 -0
  40. package/src/useCachedChildren.ts +70 -0
@@ -0,0 +1,221 @@
1
+ import {BaseCollection as $23b9f4fcf0fe224b$export$408d25a4e12db025} from "./BaseCollection.module.js";
2
+ import {Document as $681cc3c98f569e39$export$b34a105447964f9f} from "./Document.module.js";
3
+ import {useCachedChildren as $e948873055cbafe4$export$727c8fc270210f13} from "./useCachedChildren.module.js";
4
+ import {Hidden as $f39a9eba43920ace$export$8dc98ba7eadeaa56} from "./Hidden.module.js";
5
+ import {createPortal as $95feo$createPortal} from "react-dom";
6
+ 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
+ import {useIsSSR as $95feo$useIsSSR} from "@react-aria/ssr";
8
+ import {useLayoutEffect as $95feo$useLayoutEffect} from "@react-aria/utils";
9
+ import {useSyncExternalStore as $95feo$useSyncExternalStore} from "use-sync-external-store/shim/index.js";
10
+
11
+ /*
12
+ * Copyright 2024 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+ const $e1995378a142960e$var$ShallowRenderContext = /*#__PURE__*/ (0, $95feo$createContext)(false);
31
+ const $e1995378a142960e$var$CollectionDocumentContext = /*#__PURE__*/ (0, $95feo$createContext)(null);
32
+ function $e1995378a142960e$export$bf788dd355e3a401(props) {
33
+ // If a document was provided above us, we're already in a hidden tree. Just render the content.
34
+ let doc = (0, $95feo$useContext)($e1995378a142960e$var$CollectionDocumentContext);
35
+ if (doc) return props.content;
36
+ // Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.
37
+ // This should always come before the real DOM content so we have built the collection by the time it renders during SSR.
38
+ // This is fine. CollectionDocumentContext never changes after mounting.
39
+ // eslint-disable-next-line react-hooks/rules-of-hooks
40
+ let { collection: collection, document: document } = $e1995378a142960e$var$useCollectionDocument(props.createCollection);
41
+ return /*#__PURE__*/ (0, $95feo$react).createElement((0, $95feo$react).Fragment, null, /*#__PURE__*/ (0, $95feo$react).createElement((0, $f39a9eba43920ace$export$8dc98ba7eadeaa56), null, /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$CollectionDocumentContext.Provider, {
42
+ value: document
43
+ }, props.content)), /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$CollectionInner, {
44
+ render: props.children,
45
+ collection: collection
46
+ }));
47
+ }
48
+ function $e1995378a142960e$var$CollectionInner({ collection: collection, render: render }) {
49
+ return render(collection);
50
+ }
51
+ // React 16 and 17 don't support useSyncExternalStore natively, and the shim provided by React does not support getServerSnapshot.
52
+ // This wrapper uses the shim, but additionally calls getServerSnapshot during SSR (according to SSRProvider).
53
+ function $e1995378a142960e$var$useSyncExternalStoreFallback(subscribe, getSnapshot, getServerSnapshot) {
54
+ let isSSR = (0, $95feo$useIsSSR)();
55
+ let isSSRRef = (0, $95feo$useRef)(isSSR);
56
+ // This is read immediately inside the wrapper, which also runs during render.
57
+ // We just need a ref to avoid invalidating the callback itself, which
58
+ // would cause React to re-run the callback more than necessary.
59
+ // eslint-disable-next-line rulesdir/pure-render
60
+ isSSRRef.current = isSSR;
61
+ let getSnapshotWrapper = (0, $95feo$useCallback)(()=>{
62
+ return isSSRRef.current ? getServerSnapshot() : getSnapshot();
63
+ }, [
64
+ getSnapshot,
65
+ getServerSnapshot
66
+ ]);
67
+ return (0, $95feo$useSyncExternalStore)(subscribe, getSnapshotWrapper);
68
+ }
69
+ const $e1995378a142960e$var$useSyncExternalStore = typeof (0, $95feo$react)['useSyncExternalStore'] === 'function' ? (0, $95feo$react)['useSyncExternalStore'] : $e1995378a142960e$var$useSyncExternalStoreFallback;
70
+ function $e1995378a142960e$var$useCollectionDocument(createCollection) {
71
+ // The document instance is mutable, and should never change between renders.
72
+ // useSyncExternalStore is used to subscribe to updates, which vends immutable Collection objects.
73
+ let [document] = (0, $95feo$useState)(()=>new (0, $681cc3c98f569e39$export$b34a105447964f9f)((createCollection === null || createCollection === void 0 ? void 0 : createCollection()) || new (0, $23b9f4fcf0fe224b$export$408d25a4e12db025)()));
74
+ let subscribe = (0, $95feo$useCallback)((fn)=>document.subscribe(fn), [
75
+ document
76
+ ]);
77
+ let getSnapshot = (0, $95feo$useCallback)(()=>{
78
+ let collection = document.getCollection();
79
+ if (document.isSSR) // After SSR is complete, reset the document to empty so it is ready for React to render the portal into.
80
+ // We do this _after_ getting the collection above so that the collection still has content in it from SSR
81
+ // during the current render, before React has finished the client render.
82
+ document.resetAfterSSR();
83
+ return collection;
84
+ }, [
85
+ document
86
+ ]);
87
+ let getServerSnapshot = (0, $95feo$useCallback)(()=>{
88
+ document.isSSR = true;
89
+ return document.getCollection();
90
+ }, [
91
+ document
92
+ ]);
93
+ let collection = $e1995378a142960e$var$useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
94
+ (0, $95feo$useLayoutEffect)(()=>{
95
+ document.isMounted = true;
96
+ return ()=>{
97
+ // Mark unmounted so we can skip all of the collection updates caused by
98
+ // React calling removeChild on every item in the collection.
99
+ document.isMounted = false;
100
+ };
101
+ }, [
102
+ document
103
+ ]);
104
+ return {
105
+ collection: collection,
106
+ document: document
107
+ };
108
+ }
109
+ const $e1995378a142960e$var$SSRContext = /*#__PURE__*/ (0, $95feo$createContext)(null);
110
+ function $e1995378a142960e$var$useSSRCollectionNode(Type, props, ref, rendered, children, render) {
111
+ // During SSR, portals are not supported, so the collection children will be wrapped in an SSRContext.
112
+ // Since SSR occurs only once, we assume that the elements are rendered in order and never re-render.
113
+ // Therefore we can create elements in our collection document during render so that they are in the
114
+ // collection by the time we need to use the collection to render to the real DOM.
115
+ // After hydration, we switch to client rendering using the portal.
116
+ let itemRef = (0, $95feo$useCallback)((element)=>{
117
+ element === null || element === void 0 ? void 0 : element.setProps(props, ref, rendered, render);
118
+ }, [
119
+ props,
120
+ ref,
121
+ rendered,
122
+ render
123
+ ]);
124
+ let parentNode = (0, $95feo$useContext)($e1995378a142960e$var$SSRContext);
125
+ if (parentNode) {
126
+ // Guard against double rendering in strict mode.
127
+ let element = parentNode.ownerDocument.nodesByProps.get(props);
128
+ if (!element) {
129
+ element = parentNode.ownerDocument.createElement(Type);
130
+ element.setProps(props, ref, rendered, render);
131
+ parentNode.appendChild(element);
132
+ parentNode.ownerDocument.updateCollection();
133
+ parentNode.ownerDocument.nodesByProps.set(props, element);
134
+ }
135
+ return children ? /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$SSRContext.Provider, {
136
+ value: element
137
+ }, children) : null;
138
+ }
139
+ // @ts-ignore
140
+ return /*#__PURE__*/ (0, $95feo$react).createElement(Type, {
141
+ ref: itemRef
142
+ }, children);
143
+ }
144
+ function $e1995378a142960e$export$18af5c7a9e9b3664(type, render) {
145
+ let Component = ({ node: node })=>render(node.props, node.props.ref, node);
146
+ let Result = (0, $95feo$forwardRef)((props, ref)=>{
147
+ let isShallow = (0, $95feo$useContext)($e1995378a142960e$var$ShallowRenderContext);
148
+ if (!isShallow) {
149
+ if (render.length >= 3) throw new Error(render.name + ' cannot be rendered outside a collection.');
150
+ return render(props, ref);
151
+ }
152
+ return $e1995378a142960e$var$useSSRCollectionNode(type, props, ref, 'children' in props ? props.children : null, null, (node)=>/*#__PURE__*/ (0, $95feo$react).createElement(Component, {
153
+ node: node
154
+ }));
155
+ });
156
+ // @ts-ignore
157
+ Result.displayName = render.name;
158
+ return Result;
159
+ }
160
+ function $e1995378a142960e$export$e953bb1cd0f19726(type, render, useChildren = $e1995378a142960e$var$useCollectionChildren) {
161
+ let Component = ({ node: node })=>render(node.props, node.props.ref, node);
162
+ let Result = (0, $95feo$forwardRef)((props, ref)=>{
163
+ let children = useChildren(props);
164
+ var _useSSRCollectionNode;
165
+ return (_useSSRCollectionNode = $e1995378a142960e$var$useSSRCollectionNode(type, props, ref, null, children, (node)=>/*#__PURE__*/ (0, $95feo$react).createElement(Component, {
166
+ node: node
167
+ }))) !== null && _useSSRCollectionNode !== void 0 ? _useSSRCollectionNode : /*#__PURE__*/ (0, $95feo$react).createElement((0, $95feo$react).Fragment, null);
168
+ });
169
+ // @ts-ignore
170
+ Result.displayName = render.name;
171
+ return Result;
172
+ }
173
+ function $e1995378a142960e$var$useCollectionChildren(options) {
174
+ return (0, $e948873055cbafe4$export$727c8fc270210f13)({
175
+ ...options,
176
+ addIdAndValue: true
177
+ });
178
+ }
179
+ const $e1995378a142960e$var$CollectionContext = /*#__PURE__*/ (0, $95feo$createContext)(null);
180
+ function $e1995378a142960e$export$fb8073518f34e6ec(props) {
181
+ let ctx = (0, $95feo$useContext)($e1995378a142960e$var$CollectionContext);
182
+ let dependencies = ((ctx === null || ctx === void 0 ? void 0 : ctx.dependencies) || []).concat(props.dependencies);
183
+ let idScope = props.idScope || (ctx === null || ctx === void 0 ? void 0 : ctx.idScope);
184
+ let children = $e1995378a142960e$var$useCollectionChildren({
185
+ ...props,
186
+ idScope: idScope,
187
+ dependencies: dependencies
188
+ });
189
+ let doc = (0, $95feo$useContext)($e1995378a142960e$var$CollectionDocumentContext);
190
+ if (doc) children = /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$CollectionRoot, null, children);
191
+ // Propagate dependencies and idScope to child collections.
192
+ ctx = (0, $95feo$useMemo)(()=>({
193
+ dependencies: dependencies,
194
+ idScope: idScope
195
+ }), [
196
+ idScope,
197
+ ...dependencies
198
+ ]);
199
+ return /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$CollectionContext.Provider, {
200
+ value: ctx
201
+ }, children);
202
+ }
203
+ function $e1995378a142960e$var$CollectionRoot({ children: children }) {
204
+ let doc = (0, $95feo$useContext)($e1995378a142960e$var$CollectionDocumentContext);
205
+ let wrappedChildren = (0, $95feo$useMemo)(()=>/*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$CollectionDocumentContext.Provider, {
206
+ value: null
207
+ }, /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$ShallowRenderContext.Provider, {
208
+ value: true
209
+ }, children)), [
210
+ children
211
+ ]);
212
+ // During SSR, we render the content directly, and append nodes to the document during render.
213
+ // The collection children return null so that nothing is actually rendered into the HTML.
214
+ return (0, $95feo$useIsSSR)() ? /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$SSRContext.Provider, {
215
+ value: doc
216
+ }, wrappedChildren) : /*#__PURE__*/ (0, $95feo$createPortal)(wrappedChildren, doc);
217
+ }
218
+
219
+
220
+ export {$e1995378a142960e$export$bf788dd355e3a401 as CollectionBuilder, $e1995378a142960e$export$18af5c7a9e9b3664 as createLeafComponent, $e1995378a142960e$export$e953bb1cd0f19726 as createBranchComponent, $e1995378a142960e$export$fb8073518f34e6ec as Collection};
221
+ //# sourceMappingURL=CollectionBuilder.module.js.map
@@ -0,0 +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,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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AM,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>) {\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"}
@@ -0,0 +1,316 @@
1
+ var $499e2959ba1abacc$exports = require("./BaseCollection.main.js");
2
+
3
+
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
6
+ }
7
+
8
+ $parcel$export(module.exports, "Document", () => $c20afee375f3b2d6$export$b34a105447964f9f);
9
+ /*
10
+ * Copyright 2024 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+ class $c20afee375f3b2d6$export$410b0c854570d131 {
21
+ *[Symbol.iterator]() {
22
+ let node = this.firstChild;
23
+ while(node){
24
+ yield node;
25
+ node = node.nextSibling;
26
+ }
27
+ }
28
+ get firstChild() {
29
+ return this._firstChild;
30
+ }
31
+ set firstChild(firstChild) {
32
+ this._firstChild = firstChild;
33
+ this.ownerDocument.markDirty(this);
34
+ }
35
+ get lastChild() {
36
+ return this._lastChild;
37
+ }
38
+ set lastChild(lastChild) {
39
+ this._lastChild = lastChild;
40
+ this.ownerDocument.markDirty(this);
41
+ }
42
+ get previousSibling() {
43
+ return this._previousSibling;
44
+ }
45
+ set previousSibling(previousSibling) {
46
+ this._previousSibling = previousSibling;
47
+ this.ownerDocument.markDirty(this);
48
+ }
49
+ get nextSibling() {
50
+ return this._nextSibling;
51
+ }
52
+ set nextSibling(nextSibling) {
53
+ this._nextSibling = nextSibling;
54
+ this.ownerDocument.markDirty(this);
55
+ }
56
+ get parentNode() {
57
+ return this._parentNode;
58
+ }
59
+ set parentNode(parentNode) {
60
+ this._parentNode = parentNode;
61
+ this.ownerDocument.markDirty(this);
62
+ }
63
+ get isConnected() {
64
+ var _this_parentNode;
65
+ return ((_this_parentNode = this.parentNode) === null || _this_parentNode === void 0 ? void 0 : _this_parentNode.isConnected) || false;
66
+ }
67
+ appendChild(child) {
68
+ this.ownerDocument.startTransaction();
69
+ if (child.parentNode) child.parentNode.removeChild(child);
70
+ if (this.firstChild == null) this.firstChild = child;
71
+ if (this.lastChild) {
72
+ this.lastChild.nextSibling = child;
73
+ child.index = this.lastChild.index + 1;
74
+ child.previousSibling = this.lastChild;
75
+ } else {
76
+ child.previousSibling = null;
77
+ child.index = 0;
78
+ }
79
+ child.parentNode = this;
80
+ child.nextSibling = null;
81
+ this.lastChild = child;
82
+ 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
+ this.ownerDocument.queueUpdate();
88
+ }
89
+ insertBefore(newNode, referenceNode) {
90
+ if (referenceNode == null) return this.appendChild(newNode);
91
+ this.ownerDocument.startTransaction();
92
+ if (newNode.parentNode) newNode.parentNode.removeChild(newNode);
93
+ newNode.nextSibling = referenceNode;
94
+ newNode.previousSibling = referenceNode.previousSibling;
95
+ newNode.index = referenceNode.index;
96
+ if (this.firstChild === referenceNode) this.firstChild = newNode;
97
+ else if (referenceNode.previousSibling) referenceNode.previousSibling.nextSibling = newNode;
98
+ referenceNode.previousSibling = newNode;
99
+ newNode.parentNode = referenceNode.parentNode;
100
+ let node = referenceNode;
101
+ while(node){
102
+ node.index++;
103
+ node = node.nextSibling;
104
+ }
105
+ if (newNode.hasSetProps) this.ownerDocument.addNode(newNode);
106
+ this.ownerDocument.endTransaction();
107
+ this.ownerDocument.queueUpdate();
108
+ }
109
+ removeChild(child) {
110
+ if (child.parentNode !== this || !this.ownerDocument.isMounted) return;
111
+ this.ownerDocument.startTransaction();
112
+ let node = child.nextSibling;
113
+ while(node){
114
+ node.index--;
115
+ node = node.nextSibling;
116
+ }
117
+ if (child.nextSibling) child.nextSibling.previousSibling = child.previousSibling;
118
+ if (child.previousSibling) child.previousSibling.nextSibling = child.nextSibling;
119
+ if (this.firstChild === child) this.firstChild = child.nextSibling;
120
+ if (this.lastChild === child) this.lastChild = child.previousSibling;
121
+ child.parentNode = null;
122
+ child.nextSibling = null;
123
+ child.previousSibling = null;
124
+ child.index = 0;
125
+ this.ownerDocument.removeNode(child);
126
+ this.ownerDocument.endTransaction();
127
+ this.ownerDocument.queueUpdate();
128
+ }
129
+ addEventListener() {}
130
+ removeEventListener() {}
131
+ constructor(ownerDocument){
132
+ this._firstChild = null;
133
+ this._lastChild = null;
134
+ this._previousSibling = null;
135
+ this._nextSibling = null;
136
+ this._parentNode = null;
137
+ this.ownerDocument = ownerDocument;
138
+ }
139
+ }
140
+ class $c20afee375f3b2d6$export$dc064fe9e59310fd extends $c20afee375f3b2d6$export$410b0c854570d131 {
141
+ get index() {
142
+ return this._index;
143
+ }
144
+ set index(index) {
145
+ this._index = index;
146
+ this.ownerDocument.markDirty(this);
147
+ }
148
+ get level() {
149
+ if (this.parentNode instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd) return this.parentNode.level + (this.node.type === 'item' ? 1 : 0);
150
+ return 0;
151
+ }
152
+ updateNode() {
153
+ var _this_previousSibling, _this_nextSibling, _this_firstChild, _this_lastChild;
154
+ let node = this.ownerDocument.getMutableNode(this);
155
+ node.index = this.index;
156
+ node.level = this.level;
157
+ node.parentKey = this.parentNode instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd ? this.parentNode.node.key : null;
158
+ var _this_previousSibling_node_key;
159
+ node.prevKey = (_this_previousSibling_node_key = (_this_previousSibling = this.previousSibling) === null || _this_previousSibling === void 0 ? void 0 : _this_previousSibling.node.key) !== null && _this_previousSibling_node_key !== void 0 ? _this_previousSibling_node_key : null;
160
+ var _this_nextSibling_node_key;
161
+ node.nextKey = (_this_nextSibling_node_key = (_this_nextSibling = this.nextSibling) === null || _this_nextSibling === void 0 ? void 0 : _this_nextSibling.node.key) !== null && _this_nextSibling_node_key !== void 0 ? _this_nextSibling_node_key : null;
162
+ node.hasChildNodes = !!this.firstChild;
163
+ var _this_firstChild_node_key;
164
+ node.firstChildKey = (_this_firstChild_node_key = (_this_firstChild = this.firstChild) === null || _this_firstChild === void 0 ? void 0 : _this_firstChild.node.key) !== null && _this_firstChild_node_key !== void 0 ? _this_firstChild_node_key : null;
165
+ var _this_lastChild_node_key;
166
+ node.lastChildKey = (_this_lastChild_node_key = (_this_lastChild = this.lastChild) === null || _this_lastChild === void 0 ? void 0 : _this_lastChild.node.key) !== null && _this_lastChild_node_key !== void 0 ? _this_lastChild_node_key : null;
167
+ }
168
+ setProps(obj, ref, rendered, render) {
169
+ let node = this.ownerDocument.getMutableNode(this);
170
+ let { value: value, textValue: textValue, id: id, ...props } = obj;
171
+ props.ref = ref;
172
+ node.props = props;
173
+ node.rendered = rendered;
174
+ node.render = render;
175
+ node.value = value;
176
+ node.textValue = textValue || (typeof props.children === 'string' ? props.children : '') || obj['aria-label'] || '';
177
+ if (id != null && id !== node.key) {
178
+ if (this.hasSetProps) throw new Error('Cannot change the id of an item');
179
+ node.key = id;
180
+ }
181
+ // If this is the first time props have been set, end the transaction started in the constructor
182
+ // so this node can be emitted.
183
+ if (!this.hasSetProps) {
184
+ this.ownerDocument.addNode(this);
185
+ this.ownerDocument.endTransaction();
186
+ this.hasSetProps = true;
187
+ }
188
+ this.ownerDocument.queueUpdate();
189
+ }
190
+ get style() {
191
+ return {};
192
+ }
193
+ hasAttribute() {}
194
+ setAttribute() {}
195
+ setAttributeNS() {}
196
+ removeAttribute() {}
197
+ constructor(type, ownerDocument){
198
+ super(ownerDocument);
199
+ this.nodeType = 8 // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions)
200
+ ;
201
+ this._index = 0;
202
+ this.hasSetProps = false;
203
+ this.node = new (0, $499e2959ba1abacc$exports.NodeValue)(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
+ }
209
+ }
210
+ class $c20afee375f3b2d6$export$b34a105447964f9f extends $c20afee375f3b2d6$export$410b0c854570d131 {
211
+ get isConnected() {
212
+ return this.isMounted;
213
+ }
214
+ createElement(type) {
215
+ return new $c20afee375f3b2d6$export$dc064fe9e59310fd(type, this);
216
+ }
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
+ getMutableCollection() {
231
+ if (!this.isSSR && !this.collectionMutated) {
232
+ this.collection = this.collection.clone();
233
+ this.collectionMutated = true;
234
+ }
235
+ return this.collection;
236
+ }
237
+ markDirty(node) {
238
+ this.dirtyNodes.add(node);
239
+ }
240
+ startTransaction() {
241
+ this.transactionCount++;
242
+ }
243
+ endTransaction() {
244
+ this.transactionCount--;
245
+ }
246
+ addNode(element) {
247
+ let collection = this.getMutableCollection();
248
+ if (!collection.getItem(element.node.key)) {
249
+ collection.addNode(element.node);
250
+ for (let child of element)this.addNode(child);
251
+ }
252
+ this.markDirty(element);
253
+ }
254
+ removeNode(node) {
255
+ for (let child of node)this.removeNode(child);
256
+ let collection = this.getMutableCollection();
257
+ collection.removeNode(node.node.key);
258
+ this.markDirty(node);
259
+ }
260
+ /** Finalizes the collection update, updating all nodes and freezing the collection. */ getCollection() {
261
+ if (this.transactionCount > 0) return this.collection;
262
+ this.updateCollection();
263
+ return this.collection;
264
+ }
265
+ updateCollection() {
266
+ for (let element of this.dirtyNodes)if (element instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd && element.isConnected) element.updateNode();
267
+ this.dirtyNodes.clear();
268
+ if (this.mutatedNodes.size || this.collectionMutated) {
269
+ var _this_firstChild, _this_lastChild;
270
+ let collection = this.getMutableCollection();
271
+ for (let element of this.mutatedNodes)if (element.isConnected) collection.addNode(element.node);
272
+ var _this_firstChild_node_key, _this_lastChild_node_key;
273
+ collection.commit((_this_firstChild_node_key = (_this_firstChild = this.firstChild) === null || _this_firstChild === void 0 ? void 0 : _this_firstChild.node.key) !== null && _this_firstChild_node_key !== void 0 ? _this_firstChild_node_key : null, (_this_lastChild_node_key = (_this_lastChild = this.lastChild) === null || _this_lastChild === void 0 ? void 0 : _this_lastChild.node.key) !== null && _this_lastChild_node_key !== void 0 ? _this_lastChild_node_key : null, this.isSSR);
274
+ this.mutatedNodes.clear();
275
+ }
276
+ this.collectionMutated = false;
277
+ }
278
+ queueUpdate() {
279
+ // Don't emit any updates if there is a transaction in progress.
280
+ // queueUpdate should be called again after the transaction.
281
+ if (this.dirtyNodes.size === 0 || this.transactionCount > 0) return;
282
+ for (let fn of this.subscriptions)fn();
283
+ }
284
+ subscribe(fn) {
285
+ this.subscriptions.add(fn);
286
+ return ()=>this.subscriptions.delete(fn);
287
+ }
288
+ resetAfterSSR() {
289
+ if (this.isSSR) {
290
+ this.isSSR = false;
291
+ this.firstChild = null;
292
+ this.lastChild = null;
293
+ this.nodeId = 0;
294
+ }
295
+ }
296
+ constructor(collection){
297
+ // @ts-ignore
298
+ super(null);
299
+ this.nodeType = 11 // DOCUMENT_FRAGMENT_NODE
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;
310
+ this.collection = collection;
311
+ this.collectionMutated = true;
312
+ }
313
+ }
314
+
315
+
316
+ //# sourceMappingURL=Document.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;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CAAC,UAAU,GAAG;YAClB,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,MAAM,GAAG;QAChB;IACF;IApIA,YAAY,UAAa,CAAE;QACzB,aAAa;QACb,KAAK,CAAC;aAfR,WAAW,GAAI,yBAAyB;;aACxC,gBAAgB,IAAI;aACpB,aAA+B,IAAI;aACnC,QAAQ;aACR,SAAS;aACT,eAAe,IAAI;aACnB,YAAY;aAGJ,eAAoC,IAAI;aACxC,gBAAiC,IAAI;aACrC,mBAAmB;QAKzB,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,iBAAiB,GAAG;IAC3B;AAgIF","sources":["packages/@react-aria/collections/src/Document.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {BaseCollection, Mutable, NodeValue} from './BaseCollection';\nimport {ForwardedRef, ReactElement} from 'react';\nimport {Node} from '@react-types/shared';\n\n// This Collection implementation is perhaps a little unusual. It works by rendering the React tree into a\n// Portal to a fake DOM implementation. This gives us efficient access to the tree of rendered objects, and\n// supports React features like composition and context. We use this fake DOM to access the full set of elements\n// before we render into the real DOM, which allows us to render a subset of the elements (e.g. virtualized scrolling),\n// and compute properties like the total number of items. It also enables keyboard navigation, selection, and other features.\n// React takes care of efficiently rendering components and updating the collection for us via this fake DOM.\n//\n// The DOM is a mutable API, and React expects the node instances to remain stable over time. So the implementation is split\n// into two parts. Each mutable fake DOM node owns an instance of an immutable collection node. When a fake DOM node is updated,\n// it queues a second render for the collection. Multiple updates to a collection can be queued at once. Collection nodes are\n// lazily copied on write, so only the changed nodes need to be cloned. During the second render, the new immutable collection\n// is finalized by updating the map of Key -> Node with the new cloned nodes. Then the new collection is frozen so it can no\n// longer be mutated, and returned to the calling component to render.\n\n/**\n * A mutable node in the fake DOM tree. When mutated, it marks itself as dirty\n * and queues an update with the owner document.\n */\nexport class BaseNode<T> {\n private _firstChild: ElementNode<T> | null = null;\n private _lastChild: ElementNode<T> | null = null;\n private _previousSibling: ElementNode<T> | null = null;\n private _nextSibling: ElementNode<T> | null = null;\n private _parentNode: BaseNode<T> | null = null;\n ownerDocument: Document<T, any>;\n\n constructor(ownerDocument: Document<T, any>) {\n this.ownerDocument = ownerDocument;\n }\n\n *[Symbol.iterator]() {\n let node = this.firstChild;\n while (node) {\n yield node;\n node = node.nextSibling;\n }\n }\n\n get firstChild() {\n return this._firstChild;\n }\n\n set firstChild(firstChild) {\n this._firstChild = firstChild;\n this.ownerDocument.markDirty(this);\n }\n\n get lastChild() {\n return this._lastChild;\n }\n\n set lastChild(lastChild) {\n this._lastChild = lastChild;\n this.ownerDocument.markDirty(this);\n }\n\n get previousSibling() {\n return this._previousSibling;\n }\n\n set previousSibling(previousSibling) {\n this._previousSibling = previousSibling;\n this.ownerDocument.markDirty(this);\n }\n\n get nextSibling() {\n return this._nextSibling;\n }\n\n set nextSibling(nextSibling) {\n this._nextSibling = nextSibling;\n this.ownerDocument.markDirty(this);\n }\n\n get parentNode() {\n return this._parentNode;\n }\n\n set parentNode(parentNode) {\n this._parentNode = parentNode;\n this.ownerDocument.markDirty(this);\n }\n\n get isConnected() {\n return this.parentNode?.isConnected || false;\n }\n\n appendChild(child: ElementNode<T>) {\n this.ownerDocument.startTransaction();\n if (child.parentNode) {\n child.parentNode.removeChild(child);\n }\n\n if (this.firstChild == null) {\n this.firstChild = child;\n }\n\n if (this.lastChild) {\n this.lastChild.nextSibling = child;\n child.index = this.lastChild.index + 1;\n child.previousSibling = this.lastChild;\n } else {\n child.previousSibling = null;\n child.index = 0;\n }\n\n child.parentNode = this;\n child.nextSibling = null;\n this.lastChild = child;\n\n this.ownerDocument.markDirty(this);\n if (child.hasSetProps) {\n // Only add the node to the collection if we already received props for it.\n // Otherwise wait until then so we have the correct id for the node.\n this.ownerDocument.addNode(child);\n }\n\n this.ownerDocument.endTransaction();\n this.ownerDocument.queueUpdate();\n }\n\n insertBefore(newNode: ElementNode<T>, referenceNode: ElementNode<T>) {\n if (referenceNode == null) {\n return this.appendChild(newNode);\n }\n\n this.ownerDocument.startTransaction();\n if (newNode.parentNode) {\n newNode.parentNode.removeChild(newNode);\n }\n\n newNode.nextSibling = referenceNode;\n newNode.previousSibling = referenceNode.previousSibling;\n newNode.index = referenceNode.index;\n\n if (this.firstChild === referenceNode) {\n this.firstChild = newNode;\n } else if (referenceNode.previousSibling) {\n referenceNode.previousSibling.nextSibling = newNode;\n }\n\n referenceNode.previousSibling = newNode;\n newNode.parentNode = referenceNode.parentNode;\n\n let node: ElementNode<T> | null = referenceNode;\n while (node) {\n node.index++;\n node = node.nextSibling;\n }\n\n if (newNode.hasSetProps) {\n this.ownerDocument.addNode(newNode);\n }\n\n this.ownerDocument.endTransaction();\n this.ownerDocument.queueUpdate();\n }\n\n removeChild(child: ElementNode<T>) {\n if (child.parentNode !== this || !this.ownerDocument.isMounted) {\n return;\n }\n\n this.ownerDocument.startTransaction();\n let node = child.nextSibling;\n while (node) {\n node.index--;\n node = node.nextSibling;\n }\n\n if (child.nextSibling) {\n child.nextSibling.previousSibling = child.previousSibling;\n }\n\n if (child.previousSibling) {\n child.previousSibling.nextSibling = child.nextSibling;\n }\n\n if (this.firstChild === child) {\n this.firstChild = child.nextSibling;\n }\n\n if (this.lastChild === child) {\n this.lastChild = child.previousSibling;\n }\n\n child.parentNode = null;\n child.nextSibling = null;\n child.previousSibling = null;\n child.index = 0;\n\n this.ownerDocument.removeNode(child);\n this.ownerDocument.endTransaction();\n this.ownerDocument.queueUpdate();\n }\n\n addEventListener() {}\n removeEventListener() {}\n}\n\n/**\n * A mutable element node in the fake DOM tree. It owns an immutable\n * Collection Node which is copied on write.\n */\nexport class ElementNode<T> extends BaseNode<T> {\n nodeType = 8; // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions)\n node: NodeValue<T>;\n private _index: number = 0;\n hasSetProps = false;\n\n constructor(type: string, ownerDocument: Document<T, any>) {\n super(ownerDocument);\n this.node = new NodeValue(type, `react-aria-${++ownerDocument.nodeId}`);\n // Start a transaction so that no updates are emitted from the collection\n // until the props for this node are set. We don't know the real id for the\n // node until then, so we need to avoid emitting collections in an inconsistent state.\n this.ownerDocument.startTransaction();\n }\n\n get index() {\n return this._index;\n }\n\n set index(index) {\n this._index = index;\n this.ownerDocument.markDirty(this);\n }\n\n get level(): number {\n if (this.parentNode instanceof ElementNode) {\n return this.parentNode.level + (this.node.type === 'item' ? 1 : 0);\n }\n\n return 0;\n }\n\n updateNode() {\n let node = this.ownerDocument.getMutableNode(this);\n node.index = this.index;\n node.level = this.level;\n node.parentKey = this.parentNode instanceof ElementNode ? this.parentNode.node.key : null;\n node.prevKey = this.previousSibling?.node.key ?? null;\n node.nextKey = this.nextSibling?.node.key ?? null;\n node.hasChildNodes = !!this.firstChild;\n node.firstChildKey = this.firstChild?.node.key ?? null;\n node.lastChildKey = this.lastChild?.node.key ?? null;\n }\n\n setProps<E extends Element>(obj: any, ref: ForwardedRef<E>, rendered?: any, render?: (node: Node<T>) => ReactElement) {\n let node = this.ownerDocument.getMutableNode(this);\n let {value, textValue, id, ...props} = obj;\n props.ref = ref;\n node.props = props;\n node.rendered = rendered;\n node.render = render;\n node.value = value;\n node.textValue = textValue || (typeof props.children === 'string' ? props.children : '') || obj['aria-label'] || '';\n if (id != null && id !== node.key) {\n if (this.hasSetProps) {\n throw new Error('Cannot change the id of an item');\n }\n node.key = id;\n }\n\n // If this is the first time props have been set, end the transaction started in the constructor\n // so this node can be emitted.\n if (!this.hasSetProps) {\n this.ownerDocument.addNode(this);\n this.ownerDocument.endTransaction();\n this.hasSetProps = true;\n }\n\n this.ownerDocument.queueUpdate();\n }\n\n get style() {\n return {};\n }\n\n hasAttribute() {}\n setAttribute() {}\n setAttributeNS() {}\n removeAttribute() {}\n}\n\n/**\n * A mutable Document in the fake DOM. It owns an immutable Collection instance,\n * which is lazily copied on write during updates.\n */\nexport class Document<T, C extends BaseCollection<T> = BaseCollection<T>> extends BaseNode<T> {\n nodeType = 11; // DOCUMENT_FRAGMENT_NODE\n ownerDocument = this;\n dirtyNodes: Set<BaseNode<T>> = new Set();\n isSSR = false;\n nodeId = 0;\n nodesByProps = new WeakMap<object, ElementNode<T>>();\n isMounted = true;\n private collection: C;\n private collectionMutated: boolean;\n private mutatedNodes: Set<ElementNode<T>> = new Set();\n private subscriptions: Set<() => void> = new Set();\n private transactionCount = 0;\n\n constructor(collection: C) {\n // @ts-ignore\n super(null);\n this.collection = collection;\n this.collectionMutated = true;\n }\n\n get isConnected() {\n return this.isMounted;\n }\n\n createElement(type: string) {\n return new ElementNode(type, this);\n }\n\n /**\n * Lazily gets a mutable instance of a Node. If the node has already\n * been cloned during this update cycle, it just returns the existing one.\n */\n getMutableNode(element: ElementNode<T>): Mutable<NodeValue<T>> {\n let node = element.node;\n if (!this.mutatedNodes.has(element)) {\n node = element.node.clone();\n this.mutatedNodes.add(element);\n element.node = node;\n }\n this.markDirty(element);\n return node;\n }\n\n private getMutableCollection() {\n if (!this.isSSR && !this.collectionMutated) {\n this.collection = this.collection.clone();\n this.collectionMutated = true;\n }\n\n return this.collection;\n }\n\n markDirty(node: BaseNode<T>) {\n this.dirtyNodes.add(node);\n }\n\n startTransaction() {\n this.transactionCount++;\n }\n\n endTransaction() {\n this.transactionCount--;\n }\n\n addNode(element: ElementNode<T>) {\n let collection = this.getMutableCollection();\n if (!collection.getItem(element.node.key)) {\n collection.addNode(element.node);\n\n for (let child of element) {\n this.addNode(child);\n }\n }\n\n this.markDirty(element);\n }\n\n removeNode(node: ElementNode<T>) {\n for (let child of node) {\n this.removeNode(child);\n }\n\n let collection = this.getMutableCollection();\n collection.removeNode(node.node.key);\n this.markDirty(node);\n }\n\n /** Finalizes the collection update, updating all nodes and freezing the collection. */\n getCollection(): C {\n if (this.transactionCount > 0) {\n return this.collection;\n }\n\n this.updateCollection();\n return this.collection;\n }\n\n updateCollection() {\n for (let element of this.dirtyNodes) {\n if (element instanceof ElementNode && element.isConnected) {\n element.updateNode();\n }\n }\n\n this.dirtyNodes.clear();\n\n if (this.mutatedNodes.size || this.collectionMutated) {\n let collection = this.getMutableCollection();\n for (let element of this.mutatedNodes) {\n if (element.isConnected) {\n collection.addNode(element.node);\n }\n }\n\n collection.commit(this.firstChild?.node.key ?? null, this.lastChild?.node.key ?? null, this.isSSR);\n this.mutatedNodes.clear();\n }\n\n this.collectionMutated = false;\n }\n\n queueUpdate() {\n // Don't emit any updates if there is a transaction in progress.\n // queueUpdate should be called again after the transaction.\n if (this.dirtyNodes.size === 0 || this.transactionCount > 0) {\n return;\n }\n\n for (let fn of this.subscriptions) {\n fn();\n }\n }\n\n subscribe(fn: () => void) {\n this.subscriptions.add(fn);\n return () => this.subscriptions.delete(fn);\n }\n\n resetAfterSSR() {\n if (this.isSSR) {\n this.isSSR = false;\n this.firstChild = null;\n this.lastChild = null;\n this.nodeId = 0;\n }\n }\n}\n"],"names":[],"version":3,"file":"Document.main.js.map"}