@react-aria/collections 3.0.3 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/import.mjs +7 -5
  2. package/dist/main.js +20 -18
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +7 -5
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +8 -0
  7. package/package.json +14 -15
  8. package/src/index.ts +8 -7
  9. package/dist/BaseCollection.main.js +0 -271
  10. package/dist/BaseCollection.main.js.map +0 -1
  11. package/dist/BaseCollection.mjs +0 -260
  12. package/dist/BaseCollection.module.js +0 -260
  13. package/dist/BaseCollection.module.js.map +0 -1
  14. package/dist/CollectionBuilder.main.js +0 -242
  15. package/dist/CollectionBuilder.main.js.map +0 -1
  16. package/dist/CollectionBuilder.mjs +0 -230
  17. package/dist/CollectionBuilder.module.js +0 -230
  18. package/dist/CollectionBuilder.module.js.map +0 -1
  19. package/dist/Document.main.js +0 -369
  20. package/dist/Document.main.js.map +0 -1
  21. package/dist/Document.mjs +0 -364
  22. package/dist/Document.module.js +0 -364
  23. package/dist/Document.module.js.map +0 -1
  24. package/dist/Hidden.main.js +0 -90
  25. package/dist/Hidden.main.js.map +0 -1
  26. package/dist/Hidden.mjs +0 -79
  27. package/dist/Hidden.module.js +0 -79
  28. package/dist/Hidden.module.js.map +0 -1
  29. package/dist/types.d.ts +0 -119
  30. package/dist/types.d.ts.map +0 -1
  31. package/dist/useCachedChildren.main.js +0 -61
  32. package/dist/useCachedChildren.main.js.map +0 -1
  33. package/dist/useCachedChildren.mjs +0 -56
  34. package/dist/useCachedChildren.module.js +0 -56
  35. package/dist/useCachedChildren.module.js.map +0 -1
  36. package/src/BaseCollection.ts +0 -353
  37. package/src/CollectionBuilder.tsx +0 -265
  38. package/src/Document.ts +0 -569
  39. package/src/Hidden.tsx +0 -97
  40. package/src/useCachedChildren.ts +0 -70
@@ -1,242 +0,0 @@
1
- var $499e2959ba1abacc$exports = require("./BaseCollection.main.js");
2
- var $c20afee375f3b2d6$exports = require("./Document.main.js");
3
- var $245f3f827bea6653$exports = require("./useCachedChildren.main.js");
4
- var $eaaf60978b89fc58$exports = require("./Hidden.main.js");
5
- var $4ftIM$reactdom = require("react-dom");
6
- var $4ftIM$reactariainteractions = require("@react-aria/interactions");
7
- var $4ftIM$react = require("react");
8
- var $4ftIM$reactariassr = require("@react-aria/ssr");
9
- var $4ftIM$usesyncexternalstoreshimindexjs = require("use-sync-external-store/shim/index.js");
10
-
11
-
12
- function $parcel$interopDefault(a) {
13
- return a && a.__esModule ? a.default : a;
14
- }
15
-
16
- function $parcel$export(e, n, v, s) {
17
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
18
- }
19
-
20
- $parcel$export(module.exports, "CollectionBuilder", () => $f20386e2aa690b4a$export$bf788dd355e3a401);
21
- $parcel$export(module.exports, "createLeafComponent", () => $f20386e2aa690b4a$export$18af5c7a9e9b3664);
22
- $parcel$export(module.exports, "createBranchComponent", () => $f20386e2aa690b4a$export$e953bb1cd0f19726);
23
- $parcel$export(module.exports, "Collection", () => $f20386e2aa690b4a$export$fb8073518f34e6ec);
24
- /*
25
- * Copyright 2024 Adobe. All rights reserved.
26
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
27
- * you may not use this file except in compliance with the License. You may obtain a copy
28
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
29
- *
30
- * Unless required by applicable law or agreed to in writing, software distributed under
31
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
32
- * OF ANY KIND, either express or implied. See the License for the specific language
33
- * governing permissions and limitations under the License.
34
- */
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
- const $f20386e2aa690b4a$var$ShallowRenderContext = /*#__PURE__*/ (0, $4ftIM$react.createContext)(false);
44
- const $f20386e2aa690b4a$var$CollectionDocumentContext = /*#__PURE__*/ (0, $4ftIM$react.createContext)(null);
45
- function $f20386e2aa690b4a$export$bf788dd355e3a401(props) {
46
- // If a document was provided above us, we're already in a hidden tree. Just render the content.
47
- let doc = (0, $4ftIM$react.useContext)($f20386e2aa690b4a$var$CollectionDocumentContext);
48
- if (doc) // The React types prior to 18 did not allow returning ReactNode from components
49
- // even though the actual implementation since React 16 did.
50
- // We must return ReactElement so that TS does not complain that <CollectionBuilder>
51
- // is not a valid JSX element with React 16 and 17 types.
52
- // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544
53
- return props.content;
54
- // Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.
55
- // This should always come before the real DOM content so we have built the collection by the time it renders during SSR.
56
- // This is fine. CollectionDocumentContext never changes after mounting.
57
- // eslint-disable-next-line react-hooks/rules-of-hooks
58
- let { collection: collection, document: document } = $f20386e2aa690b4a$var$useCollectionDocument(props.createCollection);
59
- return /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement((0, ($parcel$interopDefault($4ftIM$react))).Fragment, null, /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement((0, $eaaf60978b89fc58$exports.Hidden), null, /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement($f20386e2aa690b4a$var$CollectionDocumentContext.Provider, {
60
- value: document
61
- }, props.content)), /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement($f20386e2aa690b4a$var$CollectionInner, {
62
- render: props.children,
63
- collection: collection
64
- }));
65
- }
66
- function $f20386e2aa690b4a$var$CollectionInner({ collection: collection, render: render }) {
67
- return render(collection);
68
- }
69
- // React 16 and 17 don't support useSyncExternalStore natively, and the shim provided by React does not support getServerSnapshot.
70
- // This wrapper uses the shim, but additionally calls getServerSnapshot during SSR (according to SSRProvider).
71
- function $f20386e2aa690b4a$var$useSyncExternalStoreFallback(subscribe, getSnapshot, getServerSnapshot) {
72
- let isSSR = (0, $4ftIM$reactariassr.useIsSSR)();
73
- let isSSRRef = (0, $4ftIM$react.useRef)(isSSR);
74
- // This is read immediately inside the wrapper, which also runs during render.
75
- // We just need a ref to avoid invalidating the callback itself, which
76
- // would cause React to re-run the callback more than necessary.
77
- // eslint-disable-next-line rulesdir/pure-render
78
- isSSRRef.current = isSSR;
79
- let getSnapshotWrapper = (0, $4ftIM$react.useCallback)(()=>{
80
- return isSSRRef.current ? getServerSnapshot() : getSnapshot();
81
- }, [
82
- getSnapshot,
83
- getServerSnapshot
84
- ]);
85
- return (0, $4ftIM$usesyncexternalstoreshimindexjs.useSyncExternalStore)(subscribe, getSnapshotWrapper);
86
- }
87
- const $f20386e2aa690b4a$var$useSyncExternalStore = typeof (0, ($parcel$interopDefault($4ftIM$react)))['useSyncExternalStore'] === 'function' ? (0, ($parcel$interopDefault($4ftIM$react)))['useSyncExternalStore'] : $f20386e2aa690b4a$var$useSyncExternalStoreFallback;
88
- function $f20386e2aa690b4a$var$useCollectionDocument(createCollection) {
89
- // The document instance is mutable, and should never change between renders.
90
- // useSyncExternalStore is used to subscribe to updates, which vends immutable Collection objects.
91
- let [document] = (0, $4ftIM$react.useState)(()=>new (0, $c20afee375f3b2d6$exports.Document)((createCollection === null || createCollection === void 0 ? void 0 : createCollection()) || new (0, $499e2959ba1abacc$exports.BaseCollection)()));
92
- let subscribe = (0, $4ftIM$react.useCallback)((fn)=>document.subscribe(fn), [
93
- document
94
- ]);
95
- let getSnapshot = (0, $4ftIM$react.useCallback)(()=>{
96
- let collection = document.getCollection();
97
- if (document.isSSR) // After SSR is complete, reset the document to empty so it is ready for React to render the portal into.
98
- // We do this _after_ getting the collection above so that the collection still has content in it from SSR
99
- // during the current render, before React has finished the client render.
100
- document.resetAfterSSR();
101
- return collection;
102
- }, [
103
- document
104
- ]);
105
- let getServerSnapshot = (0, $4ftIM$react.useCallback)(()=>{
106
- document.isSSR = true;
107
- return document.getCollection();
108
- }, [
109
- document
110
- ]);
111
- let collection = $f20386e2aa690b4a$var$useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
112
- return {
113
- collection: collection,
114
- document: document
115
- };
116
- }
117
- const $f20386e2aa690b4a$var$SSRContext = /*#__PURE__*/ (0, $4ftIM$react.createContext)(null);
118
- function $f20386e2aa690b4a$var$createCollectionNodeClass(type) {
119
- var _class;
120
- let NodeClass = (_class = class extends (0, $499e2959ba1abacc$exports.CollectionNode) {
121
- }, _class.type = type, _class);
122
- return NodeClass;
123
- }
124
- function $f20386e2aa690b4a$var$useSSRCollectionNode(CollectionNodeClass, props, ref, rendered, children, render) {
125
- // To prevent breaking change, if CollectionNodeClass is a string, create a CollectionNodeClass using the string as the type
126
- if (typeof CollectionNodeClass === 'string') CollectionNodeClass = $f20386e2aa690b4a$var$createCollectionNodeClass(CollectionNodeClass);
127
- // During SSR, portals are not supported, so the collection children will be wrapped in an SSRContext.
128
- // Since SSR occurs only once, we assume that the elements are rendered in order and never re-render.
129
- // Therefore we can create elements in our collection document during render so that they are in the
130
- // collection by the time we need to use the collection to render to the real DOM.
131
- // After hydration, we switch to client rendering using the portal.
132
- let itemRef = (0, $4ftIM$react.useCallback)((element)=>{
133
- element === null || element === void 0 ? void 0 : element.setProps(props, ref, CollectionNodeClass, rendered, render);
134
- }, [
135
- props,
136
- ref,
137
- rendered,
138
- render,
139
- CollectionNodeClass
140
- ]);
141
- let parentNode = (0, $4ftIM$react.useContext)($f20386e2aa690b4a$var$SSRContext);
142
- if (parentNode) {
143
- // Guard against double rendering in strict mode.
144
- let element = parentNode.ownerDocument.nodesByProps.get(props);
145
- if (!element) {
146
- element = parentNode.ownerDocument.createElement(CollectionNodeClass.type);
147
- element.setProps(props, ref, CollectionNodeClass, rendered, render);
148
- parentNode.appendChild(element);
149
- parentNode.ownerDocument.updateCollection();
150
- parentNode.ownerDocument.nodesByProps.set(props, element);
151
- }
152
- return children ? /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement($f20386e2aa690b4a$var$SSRContext.Provider, {
153
- value: element
154
- }, children) : null;
155
- }
156
- // @ts-ignore
157
- return /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement(CollectionNodeClass.type, {
158
- ref: itemRef
159
- }, children);
160
- }
161
- function $f20386e2aa690b4a$export$18af5c7a9e9b3664(CollectionNodeClass, render) {
162
- let Component = ({ node: node })=>render(node.props, node.props.ref, node);
163
- let Result = (0, $4ftIM$react.forwardRef)((props, ref)=>{
164
- let focusableProps = (0, $4ftIM$react.useContext)((0, $4ftIM$reactariainteractions.FocusableContext));
165
- let isShallow = (0, $4ftIM$react.useContext)($f20386e2aa690b4a$var$ShallowRenderContext);
166
- if (!isShallow) {
167
- if (render.length >= 3) throw new Error(render.name + ' cannot be rendered outside a collection.');
168
- return render(props, ref);
169
- }
170
- return $f20386e2aa690b4a$var$useSSRCollectionNode(CollectionNodeClass, props, ref, 'children' in props ? props.children : null, null, (node)=>// Forward FocusableContext to real DOM tree so tooltips work.
171
- /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement((0, $4ftIM$reactariainteractions.FocusableContext).Provider, {
172
- value: focusableProps
173
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement(Component, {
174
- node: node
175
- })));
176
- });
177
- // @ts-ignore
178
- Result.displayName = render.name;
179
- return Result;
180
- }
181
- function $f20386e2aa690b4a$export$e953bb1cd0f19726(CollectionNodeClass, render, useChildren = $f20386e2aa690b4a$var$useCollectionChildren) {
182
- let Component = ({ node: node })=>render(node.props, node.props.ref, node);
183
- let Result = (0, $4ftIM$react.forwardRef)((props, ref)=>{
184
- let children = useChildren(props);
185
- var _useSSRCollectionNode;
186
- return (_useSSRCollectionNode = $f20386e2aa690b4a$var$useSSRCollectionNode(CollectionNodeClass, props, ref, null, children, (node)=>/*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement(Component, {
187
- node: node
188
- }))) !== null && _useSSRCollectionNode !== void 0 ? _useSSRCollectionNode : /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement((0, ($parcel$interopDefault($4ftIM$react))).Fragment, null);
189
- });
190
- // @ts-ignore
191
- Result.displayName = render.name;
192
- return Result;
193
- }
194
- function $f20386e2aa690b4a$var$useCollectionChildren(options) {
195
- return (0, $245f3f827bea6653$exports.useCachedChildren)({
196
- ...options,
197
- addIdAndValue: true
198
- });
199
- }
200
- const $f20386e2aa690b4a$var$CollectionContext = /*#__PURE__*/ (0, $4ftIM$react.createContext)(null);
201
- function $f20386e2aa690b4a$export$fb8073518f34e6ec(props) {
202
- let ctx = (0, $4ftIM$react.useContext)($f20386e2aa690b4a$var$CollectionContext);
203
- let dependencies = ((ctx === null || ctx === void 0 ? void 0 : ctx.dependencies) || []).concat(props.dependencies);
204
- var _props_idScope;
205
- let idScope = (_props_idScope = props.idScope) !== null && _props_idScope !== void 0 ? _props_idScope : ctx === null || ctx === void 0 ? void 0 : ctx.idScope;
206
- let children = $f20386e2aa690b4a$var$useCollectionChildren({
207
- ...props,
208
- idScope: idScope,
209
- dependencies: dependencies
210
- });
211
- let doc = (0, $4ftIM$react.useContext)($f20386e2aa690b4a$var$CollectionDocumentContext);
212
- if (doc) children = /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement($f20386e2aa690b4a$var$CollectionRoot, null, children);
213
- // Propagate dependencies and idScope to child collections.
214
- ctx = (0, $4ftIM$react.useMemo)(()=>({
215
- dependencies: dependencies,
216
- idScope: idScope
217
- }), [
218
- idScope,
219
- ...dependencies
220
- ]);
221
- return /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement($f20386e2aa690b4a$var$CollectionContext.Provider, {
222
- value: ctx
223
- }, children);
224
- }
225
- function $f20386e2aa690b4a$var$CollectionRoot({ children: children }) {
226
- let doc = (0, $4ftIM$react.useContext)($f20386e2aa690b4a$var$CollectionDocumentContext);
227
- let wrappedChildren = (0, $4ftIM$react.useMemo)(()=>/*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement($f20386e2aa690b4a$var$CollectionDocumentContext.Provider, {
228
- value: null
229
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement($f20386e2aa690b4a$var$ShallowRenderContext.Provider, {
230
- value: true
231
- }, children)), [
232
- children
233
- ]);
234
- // During SSR, we render the content directly, and append nodes to the document during render.
235
- // The collection children return null so that nothing is actually rendered into the HTML.
236
- return (0, $4ftIM$reactariassr.useIsSSR)() ? /*#__PURE__*/ (0, ($parcel$interopDefault($4ftIM$react))).createElement($f20386e2aa690b4a$var$SSRContext.Provider, {
237
- value: doc
238
- }, wrappedChildren) : /*#__PURE__*/ (0, $4ftIM$reactdom.createPortal)(wrappedChildren, doc);
239
- }
240
-
241
-
242
- //# sourceMappingURL=CollectionBuilder.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;;AAaD,MAAM,2DAAuB,CAAA,GAAA,0BAAY,EAAE;AAC3C,MAAM,gEAA4B,CAAA,GAAA,0BAAY,EAA6C;AAWpF,SAAS,0CAAoD,KAAgC;IAClG,gGAAgG;IAChG,IAAI,MAAM,CAAA,GAAA,uBAAS,EAAE;IACrB,IAAI,KACF,gFAAgF;IAChF,4DAA4D;IAC5D,oFAAoF;IACpF,yDAAyD;IACzD,kEAAkE;IAClE,OAAO,MAAM,OAAO;IAGtB,qHAAqH;IACrH,yHAAyH;IAEzH,wEAAwE;IACxE,sDAAsD;IACtD,IAAI,cAAC,UAAU,YAAE,QAAQ,EAAC,GAAG,4CAAsB,MAAM,gBAAgB;IACzE,qBACE,oIACE,0DAAC,CAAA,GAAA,gCAAK,uBACJ,0DAAC,gDAA0B,QAAQ;QAAC,OAAO;OACxC,MAAM,OAAO,kBAGlB,0DAAC;QAAgB,QAAQ,MAAM,QAAQ;QAAE,YAAY;;AAG3D;AAEA,SAAS,sCAAgB,cAAC,UAAU,UAAE,MAAM,EAAC;IAC3C,OAAO,OAAO;AAChB;AAOA,kIAAkI;AAClI,8GAA8G;AAC9G,S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CAAA,CAAA,gBAAA,0BAAA,IAAK,YAAY,KAAI,EAAE,AAAD,EAAG,MAAM,CAAC,MAAM,YAAY;QACxD;IAAd,IAAI,UAAU,CAAA,iBAAA,MAAM,OAAO,cAAb,4BAAA,iBAAiB,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, CollectionNode} 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, Key, 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 {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 return {collection, document};\n}\n\nconst SSRContext = createContext<BaseNode<any> | null>(null);\n\nexport type CollectionNodeClass<T> = {\n new (key: Key): CollectionNode<T>,\n readonly type: string\n};\n\nfunction createCollectionNodeClass(type: string): CollectionNodeClass<any> {\n let NodeClass = class extends CollectionNode<any> {\n static readonly type = type;\n };\n return NodeClass;\n}\n\nfunction useSSRCollectionNode<T extends Element>(CollectionNodeClass: CollectionNodeClass<T> | string, props: object, ref: ForwardedRef<T>, rendered?: any, children?: ReactNode, render?: (node: Node<any>) => ReactElement) {\n // To prevent breaking change, if CollectionNodeClass is a string, create a CollectionNodeClass using the string as the type\n if (typeof CollectionNodeClass === 'string') {\n CollectionNodeClass = createCollectionNodeClass(CollectionNodeClass);\n }\n\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, CollectionNodeClass, rendered, render);\n }, [props, ref, rendered, render, CollectionNodeClass]);\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(CollectionNodeClass.type);\n element.setProps(props, ref, CollectionNodeClass, 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 <CollectionNodeClass.type ref={itemRef}>{children}</CollectionNodeClass.type>;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function createLeafComponent<T extends object, P extends object, E extends Element>(CollectionNodeClass: CollectionNodeClass<any> | string, render: (props: P, ref: ForwardedRef<E>) => ReactElement | null): (props: P & React.RefAttributes<E>) => ReactElement | null;\nexport function createLeafComponent<T extends object, P extends object, E extends Element>(CollectionNodeClass: CollectionNodeClass<any> | string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement | null): (props: P & React.RefAttributes<E>) => ReactElement | null;\nexport function createLeafComponent<P extends object, E extends Element>(CollectionNodeClass: CollectionNodeClass<any> | string, render: (props: P, ref: ForwardedRef<E>, node?: any) => ReactElement | null): (props: P & React.RefAttributes<any>) => ReactElement | null {\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 CollectionNodeClass,\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>(CollectionNodeClass: CollectionNodeClass<any> | string, render: (props: P, ref: ForwardedRef<E>, node: Node<T>) => ReactElement | null, useChildren: (props: P) => ReactNode = useCollectionChildren): (props: P & React.RefAttributes<E>) => ReactElement | null {\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(CollectionNodeClass, 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,230 +0,0 @@
1
- import {BaseCollection as $23b9f4fcf0fe224b$export$408d25a4e12db025, CollectionNode as $23b9f4fcf0fe224b$export$d68d59712b04d9d1} from "./BaseCollection.mjs";
2
- import {Document as $681cc3c98f569e39$export$b34a105447964f9f} from "./Document.mjs";
3
- import {useCachedChildren as $e948873055cbafe4$export$727c8fc270210f13} from "./useCachedChildren.mjs";
4
- import {Hidden as $f39a9eba43920ace$export$8dc98ba7eadeaa56} from "./Hidden.mjs";
5
- import {createPortal as $95feo$createPortal} from "react-dom";
6
- import {FocusableContext as $95feo$FocusableContext} from "@react-aria/interactions";
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";
8
- import {useIsSSR as $95feo$useIsSSR} from "@react-aria/ssr";
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) // The React types prior to 18 did not allow returning ReactNode from components
36
- // even though the actual implementation since React 16 did.
37
- // We must return ReactElement so that TS does not complain that <CollectionBuilder>
38
- // is not a valid JSX element with React 16 and 17 types.
39
- // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544
40
- return props.content;
41
- // Otherwise, render a hidden copy of the children so that we can build the collection before constructing the state.
42
- // This should always come before the real DOM content so we have built the collection by the time it renders during SSR.
43
- // This is fine. CollectionDocumentContext never changes after mounting.
44
- // eslint-disable-next-line react-hooks/rules-of-hooks
45
- let { collection: collection, document: document } = $e1995378a142960e$var$useCollectionDocument(props.createCollection);
46
- 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, {
47
- value: document
48
- }, props.content)), /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$CollectionInner, {
49
- render: props.children,
50
- collection: collection
51
- }));
52
- }
53
- function $e1995378a142960e$var$CollectionInner({ collection: collection, render: render }) {
54
- return render(collection);
55
- }
56
- // React 16 and 17 don't support useSyncExternalStore natively, and the shim provided by React does not support getServerSnapshot.
57
- // This wrapper uses the shim, but additionally calls getServerSnapshot during SSR (according to SSRProvider).
58
- function $e1995378a142960e$var$useSyncExternalStoreFallback(subscribe, getSnapshot, getServerSnapshot) {
59
- let isSSR = (0, $95feo$useIsSSR)();
60
- let isSSRRef = (0, $95feo$useRef)(isSSR);
61
- // This is read immediately inside the wrapper, which also runs during render.
62
- // We just need a ref to avoid invalidating the callback itself, which
63
- // would cause React to re-run the callback more than necessary.
64
- // eslint-disable-next-line rulesdir/pure-render
65
- isSSRRef.current = isSSR;
66
- let getSnapshotWrapper = (0, $95feo$useCallback)(()=>{
67
- return isSSRRef.current ? getServerSnapshot() : getSnapshot();
68
- }, [
69
- getSnapshot,
70
- getServerSnapshot
71
- ]);
72
- return (0, $95feo$useSyncExternalStore)(subscribe, getSnapshotWrapper);
73
- }
74
- const $e1995378a142960e$var$useSyncExternalStore = typeof (0, $95feo$react)['useSyncExternalStore'] === 'function' ? (0, $95feo$react)['useSyncExternalStore'] : $e1995378a142960e$var$useSyncExternalStoreFallback;
75
- function $e1995378a142960e$var$useCollectionDocument(createCollection) {
76
- // The document instance is mutable, and should never change between renders.
77
- // useSyncExternalStore is used to subscribe to updates, which vends immutable Collection objects.
78
- let [document] = (0, $95feo$useState)(()=>new (0, $681cc3c98f569e39$export$b34a105447964f9f)((createCollection === null || createCollection === void 0 ? void 0 : createCollection()) || new (0, $23b9f4fcf0fe224b$export$408d25a4e12db025)()));
79
- let subscribe = (0, $95feo$useCallback)((fn)=>document.subscribe(fn), [
80
- document
81
- ]);
82
- let getSnapshot = (0, $95feo$useCallback)(()=>{
83
- let collection = document.getCollection();
84
- if (document.isSSR) // After SSR is complete, reset the document to empty so it is ready for React to render the portal into.
85
- // We do this _after_ getting the collection above so that the collection still has content in it from SSR
86
- // during the current render, before React has finished the client render.
87
- document.resetAfterSSR();
88
- return collection;
89
- }, [
90
- document
91
- ]);
92
- let getServerSnapshot = (0, $95feo$useCallback)(()=>{
93
- document.isSSR = true;
94
- return document.getCollection();
95
- }, [
96
- document
97
- ]);
98
- let collection = $e1995378a142960e$var$useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
99
- return {
100
- collection: collection,
101
- document: document
102
- };
103
- }
104
- const $e1995378a142960e$var$SSRContext = /*#__PURE__*/ (0, $95feo$createContext)(null);
105
- function $e1995378a142960e$var$createCollectionNodeClass(type) {
106
- var _class;
107
- let NodeClass = (_class = class extends (0, $23b9f4fcf0fe224b$export$d68d59712b04d9d1) {
108
- }, _class.type = type, _class);
109
- return NodeClass;
110
- }
111
- function $e1995378a142960e$var$useSSRCollectionNode(CollectionNodeClass, props, ref, rendered, children, render) {
112
- // To prevent breaking change, if CollectionNodeClass is a string, create a CollectionNodeClass using the string as the type
113
- if (typeof CollectionNodeClass === 'string') CollectionNodeClass = $e1995378a142960e$var$createCollectionNodeClass(CollectionNodeClass);
114
- // During SSR, portals are not supported, so the collection children will be wrapped in an SSRContext.
115
- // Since SSR occurs only once, we assume that the elements are rendered in order and never re-render.
116
- // Therefore we can create elements in our collection document during render so that they are in the
117
- // collection by the time we need to use the collection to render to the real DOM.
118
- // After hydration, we switch to client rendering using the portal.
119
- let itemRef = (0, $95feo$useCallback)((element)=>{
120
- element === null || element === void 0 ? void 0 : element.setProps(props, ref, CollectionNodeClass, rendered, render);
121
- }, [
122
- props,
123
- ref,
124
- rendered,
125
- render,
126
- CollectionNodeClass
127
- ]);
128
- let parentNode = (0, $95feo$useContext)($e1995378a142960e$var$SSRContext);
129
- if (parentNode) {
130
- // Guard against double rendering in strict mode.
131
- let element = parentNode.ownerDocument.nodesByProps.get(props);
132
- if (!element) {
133
- element = parentNode.ownerDocument.createElement(CollectionNodeClass.type);
134
- element.setProps(props, ref, CollectionNodeClass, rendered, render);
135
- parentNode.appendChild(element);
136
- parentNode.ownerDocument.updateCollection();
137
- parentNode.ownerDocument.nodesByProps.set(props, element);
138
- }
139
- return children ? /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$SSRContext.Provider, {
140
- value: element
141
- }, children) : null;
142
- }
143
- // @ts-ignore
144
- return /*#__PURE__*/ (0, $95feo$react).createElement(CollectionNodeClass.type, {
145
- ref: itemRef
146
- }, children);
147
- }
148
- function $e1995378a142960e$export$18af5c7a9e9b3664(CollectionNodeClass, render) {
149
- let Component = ({ node: node })=>render(node.props, node.props.ref, node);
150
- let Result = (0, $95feo$forwardRef)((props, ref)=>{
151
- let focusableProps = (0, $95feo$useContext)((0, $95feo$FocusableContext));
152
- let isShallow = (0, $95feo$useContext)($e1995378a142960e$var$ShallowRenderContext);
153
- if (!isShallow) {
154
- if (render.length >= 3) throw new Error(render.name + ' cannot be rendered outside a collection.');
155
- return render(props, ref);
156
- }
157
- return $e1995378a142960e$var$useSSRCollectionNode(CollectionNodeClass, props, ref, 'children' in props ? props.children : null, null, (node)=>// Forward FocusableContext to real DOM tree so tooltips work.
158
- /*#__PURE__*/ (0, $95feo$react).createElement((0, $95feo$FocusableContext).Provider, {
159
- value: focusableProps
160
- }, /*#__PURE__*/ (0, $95feo$react).createElement(Component, {
161
- node: node
162
- })));
163
- });
164
- // @ts-ignore
165
- Result.displayName = render.name;
166
- return Result;
167
- }
168
- function $e1995378a142960e$export$e953bb1cd0f19726(CollectionNodeClass, render, useChildren = $e1995378a142960e$var$useCollectionChildren) {
169
- let Component = ({ node: node })=>render(node.props, node.props.ref, node);
170
- let Result = (0, $95feo$forwardRef)((props, ref)=>{
171
- let children = useChildren(props);
172
- var _useSSRCollectionNode;
173
- return (_useSSRCollectionNode = $e1995378a142960e$var$useSSRCollectionNode(CollectionNodeClass, props, ref, null, children, (node)=>/*#__PURE__*/ (0, $95feo$react).createElement(Component, {
174
- node: node
175
- }))) !== null && _useSSRCollectionNode !== void 0 ? _useSSRCollectionNode : /*#__PURE__*/ (0, $95feo$react).createElement((0, $95feo$react).Fragment, null);
176
- });
177
- // @ts-ignore
178
- Result.displayName = render.name;
179
- return Result;
180
- }
181
- function $e1995378a142960e$var$useCollectionChildren(options) {
182
- return (0, $e948873055cbafe4$export$727c8fc270210f13)({
183
- ...options,
184
- addIdAndValue: true
185
- });
186
- }
187
- const $e1995378a142960e$var$CollectionContext = /*#__PURE__*/ (0, $95feo$createContext)(null);
188
- function $e1995378a142960e$export$fb8073518f34e6ec(props) {
189
- let ctx = (0, $95feo$useContext)($e1995378a142960e$var$CollectionContext);
190
- let dependencies = ((ctx === null || ctx === void 0 ? void 0 : ctx.dependencies) || []).concat(props.dependencies);
191
- var _props_idScope;
192
- let idScope = (_props_idScope = props.idScope) !== null && _props_idScope !== void 0 ? _props_idScope : ctx === null || ctx === void 0 ? void 0 : ctx.idScope;
193
- let children = $e1995378a142960e$var$useCollectionChildren({
194
- ...props,
195
- idScope: idScope,
196
- dependencies: dependencies
197
- });
198
- let doc = (0, $95feo$useContext)($e1995378a142960e$var$CollectionDocumentContext);
199
- if (doc) children = /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$CollectionRoot, null, children);
200
- // Propagate dependencies and idScope to child collections.
201
- ctx = (0, $95feo$useMemo)(()=>({
202
- dependencies: dependencies,
203
- idScope: idScope
204
- }), [
205
- idScope,
206
- ...dependencies
207
- ]);
208
- return /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$CollectionContext.Provider, {
209
- value: ctx
210
- }, children);
211
- }
212
- function $e1995378a142960e$var$CollectionRoot({ children: children }) {
213
- let doc = (0, $95feo$useContext)($e1995378a142960e$var$CollectionDocumentContext);
214
- let wrappedChildren = (0, $95feo$useMemo)(()=>/*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$CollectionDocumentContext.Provider, {
215
- value: null
216
- }, /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$ShallowRenderContext.Provider, {
217
- value: true
218
- }, children)), [
219
- children
220
- ]);
221
- // During SSR, we render the content directly, and append nodes to the document during render.
222
- // The collection children return null so that nothing is actually rendered into the HTML.
223
- return (0, $95feo$useIsSSR)() ? /*#__PURE__*/ (0, $95feo$react).createElement($e1995378a142960e$var$SSRContext.Provider, {
224
- value: doc
225
- }, wrappedChildren) : /*#__PURE__*/ (0, $95feo$createPortal)(wrappedChildren, doc);
226
- }
227
-
228
-
229
- export {$e1995378a142960e$export$bf788dd355e3a401 as CollectionBuilder, $e1995378a142960e$export$18af5c7a9e9b3664 as createLeafComponent, $e1995378a142960e$export$e953bb1cd0f19726 as createBranchComponent, $e1995378a142960e$export$fb8073518f34e6ec as Collection};
230
- //# sourceMappingURL=CollectionBuilder.module.js.map