UNPKG

30 kBJavaScriptView Raw
1import {createPortal as $18I52$createPortal} from "react-dom";
2import {useIsSSR as $18I52$useIsSSR, mergeProps as $18I52$mergeProps} from "react-aria";
3import $18I52$react, {useMemo as $18I52$useMemo, cloneElement as $18I52$cloneElement, createContext as $18I52$createContext, useRef as $18I52$useRef, useCallback as $18I52$useCallback, useContext as $18I52$useContext, forwardRef as $18I52$forwardRef} from "react";
4import {useSyncExternalStore as $18I52$useSyncExternalStore} from "use-sync-external-store/shim/index.js";
5
6/*
7 * Copyright 2022 Adobe. All rights reserved.
8 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License. You may obtain a copy
10 * of the License at http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software distributed under
13 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14 * OF ANY KIND, either express or implied. See the License for the specific language
15 * governing permissions and limitations under the License.
16 */
17
18
19
20class $7135fc7d473fd974$export$f5d856d854e74713 {
21 get childNodes() {
22 throw new Error('childNodes is not supported');
23 }
24 clone() {
25 let node = new $7135fc7d473fd974$export$f5d856d854e74713(this.type, this.key);
26 node.value = this.value;
27 node.level = this.level;
28 node.hasChildNodes = this.hasChildNodes;
29 node.rendered = this.rendered;
30 node.textValue = this.textValue;
31 node['aria-label'] = this['aria-label'];
32 node.index = this.index;
33 node.parentKey = this.parentKey;
34 node.prevKey = this.prevKey;
35 node.nextKey = this.nextKey;
36 node.firstChildKey = this.firstChildKey;
37 node.lastChildKey = this.lastChildKey;
38 node.props = this.props;
39 return node;
40 }
41 constructor(type, key){
42 this.value = null;
43 this.level = 0;
44 this.hasChildNodes = false;
45 this.rendered = null;
46 this.textValue = '';
47 this['aria-label'] = undefined;
48 this.index = 0;
49 this.parentKey = null;
50 this.prevKey = null;
51 this.nextKey = null;
52 this.firstChildKey = null;
53 this.lastChildKey = null;
54 this.props = {};
55 this.type = type;
56 this.key = key;
57 }
58}
59/**
60 * A mutable node in the fake DOM tree. When mutated, it marks itself as dirty
61 * and queues an update with the owner document.
62 */ class $7135fc7d473fd974$var$BaseNode {
63 *[Symbol.iterator]() {
64 let node = this.firstChild;
65 while(node){
66 yield node;
67 node = node.nextSibling;
68 }
69 }
70 get firstChild() {
71 return this._firstChild;
72 }
73 set firstChild(firstChild) {
74 this._firstChild = firstChild;
75 this.ownerDocument.markDirty(this);
76 }
77 get lastChild() {
78 return this._lastChild;
79 }
80 set lastChild(lastChild) {
81 this._lastChild = lastChild;
82 this.ownerDocument.markDirty(this);
83 }
84 get previousSibling() {
85 return this._previousSibling;
86 }
87 set previousSibling(previousSibling) {
88 this._previousSibling = previousSibling;
89 this.ownerDocument.markDirty(this);
90 }
91 get nextSibling() {
92 return this._nextSibling;
93 }
94 set nextSibling(nextSibling) {
95 this._nextSibling = nextSibling;
96 this.ownerDocument.markDirty(this);
97 }
98 get parentNode() {
99 return this._parentNode;
100 }
101 set parentNode(parentNode) {
102 this._parentNode = parentNode;
103 this.ownerDocument.markDirty(this);
104 }
105 get isConnected() {
106 var _this_parentNode;
107 return ((_this_parentNode = this.parentNode) === null || _this_parentNode === void 0 ? void 0 : _this_parentNode.isConnected) || false;
108 }
109 appendChild(child) {
110 this.ownerDocument.startTransaction();
111 if (child.parentNode) child.parentNode.removeChild(child);
112 if (this.firstChild == null) this.firstChild = child;
113 if (this.lastChild) {
114 this.lastChild.nextSibling = child;
115 child.index = this.lastChild.index + 1;
116 child.previousSibling = this.lastChild;
117 } else {
118 child.previousSibling = null;
119 child.index = 0;
120 }
121 child.parentNode = this;
122 child.nextSibling = null;
123 this.lastChild = child;
124 this.ownerDocument.markDirty(this);
125 if (child.hasSetProps) // Only add the node to the collection if we already received props for it.
126 // Otherwise wait until then so we have the correct id for the node.
127 this.ownerDocument.addNode(child);
128 this.ownerDocument.endTransaction();
129 this.ownerDocument.queueUpdate();
130 }
131 insertBefore(newNode, referenceNode) {
132 if (referenceNode == null) return this.appendChild(newNode);
133 this.ownerDocument.startTransaction();
134 if (newNode.parentNode) newNode.parentNode.removeChild(newNode);
135 newNode.nextSibling = referenceNode;
136 newNode.previousSibling = referenceNode.previousSibling;
137 newNode.index = referenceNode.index;
138 if (this.firstChild === referenceNode) this.firstChild = newNode;
139 else if (referenceNode.previousSibling) referenceNode.previousSibling.nextSibling = newNode;
140 referenceNode.previousSibling = newNode;
141 newNode.parentNode = referenceNode.parentNode;
142 let node = referenceNode;
143 while(node){
144 node.index++;
145 node = node.nextSibling;
146 }
147 if (newNode.hasSetProps) this.ownerDocument.addNode(newNode);
148 this.ownerDocument.endTransaction();
149 this.ownerDocument.queueUpdate();
150 }
151 removeChild(child) {
152 if (child.parentNode !== this) return;
153 this.ownerDocument.startTransaction();
154 let node = child.nextSibling;
155 while(node){
156 node.index--;
157 node = node.nextSibling;
158 }
159 if (child.nextSibling) child.nextSibling.previousSibling = child.previousSibling;
160 if (child.previousSibling) child.previousSibling.nextSibling = child.nextSibling;
161 if (this.firstChild === child) this.firstChild = child.nextSibling;
162 if (this.lastChild === child) this.lastChild = child.previousSibling;
163 child.parentNode = null;
164 child.nextSibling = null;
165 child.previousSibling = null;
166 child.index = 0;
167 this.ownerDocument.removeNode(child);
168 this.ownerDocument.endTransaction();
169 this.ownerDocument.queueUpdate();
170 }
171 addEventListener() {}
172 removeEventListener() {}
173 constructor(ownerDocument){
174 this._firstChild = null;
175 this._lastChild = null;
176 this._previousSibling = null;
177 this._nextSibling = null;
178 this._parentNode = null;
179 this.ownerDocument = ownerDocument;
180 }
181}
182class $7135fc7d473fd974$export$dc064fe9e59310fd extends $7135fc7d473fd974$var$BaseNode {
183 get index() {
184 return this._index;
185 }
186 set index(index) {
187 this._index = index;
188 this.ownerDocument.markDirty(this);
189 }
190 get level() {
191 if (this.parentNode instanceof $7135fc7d473fd974$export$dc064fe9e59310fd) return this.parentNode.level + (this.node.type === 'item' ? 1 : 0);
192 return 0;
193 }
194 updateNode() {
195 var _this_previousSibling, _this_nextSibling, _this_firstChild, _this_lastChild;
196 let node = this.ownerDocument.getMutableNode(this);
197 node.index = this.index;
198 node.level = this.level;
199 node.parentKey = this.parentNode instanceof $7135fc7d473fd974$export$dc064fe9e59310fd ? this.parentNode.node.key : null;
200 var _this_previousSibling_node_key;
201 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;
202 var _this_nextSibling_node_key;
203 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;
204 node.hasChildNodes = !!this.firstChild;
205 var _this_firstChild_node_key;
206 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;
207 var _this_lastChild_node_key;
208 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;
209 }
210 setProps(obj, ref, rendered) {
211 let node = this.ownerDocument.getMutableNode(this);
212 let { value: value, textValue: textValue, id: id, ...props } = obj;
213 props.ref = ref;
214 node.props = props;
215 node.rendered = rendered;
216 node.value = value;
217 node.textValue = textValue || (typeof rendered === 'string' ? rendered : '') || obj['aria-label'] || '';
218 if (id != null && id !== node.key) {
219 if (this.hasSetProps) throw new Error('Cannot change the id of an item');
220 node.key = id;
221 }
222 // If this is the first time props have been set, end the transaction started in the constructor
223 // so this node can be emitted.
224 if (!this.hasSetProps) {
225 this.ownerDocument.addNode(this);
226 this.ownerDocument.endTransaction();
227 this.hasSetProps = true;
228 }
229 this.ownerDocument.queueUpdate();
230 }
231 get style() {
232 return {};
233 }
234 hasAttribute() {}
235 setAttribute() {}
236 setAttributeNS() {}
237 removeAttribute() {}
238 constructor(type, ownerDocument){
239 super(ownerDocument);
240 this.nodeType = 8 // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions)
241 ;
242 this._index = 0;
243 this.hasSetProps = false;
244 this.node = new $7135fc7d473fd974$export$f5d856d854e74713(type, `react-aria-${++ownerDocument.nodeId}`);
245 // Start a transaction so that no updates are emitted from the collection
246 // until the props for this node are set. We don't know the real id for the
247 // node until then, so we need to avoid emitting collections in an inconsistent state.
248 this.ownerDocument.startTransaction();
249 }
250}
251class $7135fc7d473fd974$export$408d25a4e12db025 {
252 get size() {
253 return this.keyMap.size;
254 }
255 getKeys() {
256 return this.keyMap.keys();
257 }
258 *[Symbol.iterator]() {
259 let node = this.firstKey != null ? this.keyMap.get(this.firstKey) : undefined;
260 while(node){
261 yield node;
262 node = node.nextKey != null ? this.keyMap.get(node.nextKey) : undefined;
263 }
264 }
265 getChildren(key) {
266 let keyMap = this.keyMap;
267 return {
268 *[Symbol.iterator] () {
269 let parent = keyMap.get(key);
270 let node = (parent === null || parent === void 0 ? void 0 : parent.firstChildKey) != null ? keyMap.get(parent.firstChildKey) : null;
271 while(node){
272 yield node;
273 node = node.nextKey != null ? keyMap.get(node.nextKey) : undefined;
274 }
275 }
276 };
277 }
278 getKeyBefore(key) {
279 let node = this.keyMap.get(key);
280 if (!node) return null;
281 if (node.prevKey != null) {
282 node = this.keyMap.get(node.prevKey);
283 while(node && node.type !== 'item' && node.lastChildKey != null)node = this.keyMap.get(node.lastChildKey);
284 var _node_key;
285 return (_node_key = node === null || node === void 0 ? void 0 : node.key) !== null && _node_key !== void 0 ? _node_key : null;
286 }
287 return node.parentKey;
288 }
289 getKeyAfter(key) {
290 let node = this.keyMap.get(key);
291 if (!node) return null;
292 if (node.type !== 'item' && node.firstChildKey != null) return node.firstChildKey;
293 while(node){
294 if (node.nextKey != null) return node.nextKey;
295 if (node.parentKey != null) node = this.keyMap.get(node.parentKey);
296 else return null;
297 }
298 return null;
299 }
300 getFirstKey() {
301 return this.firstKey;
302 }
303 getLastKey() {
304 let node = this.lastKey != null ? this.keyMap.get(this.lastKey) : null;
305 while((node === null || node === void 0 ? void 0 : node.lastChildKey) != null)node = this.keyMap.get(node.lastChildKey);
306 var _node_key;
307 return (_node_key = node === null || node === void 0 ? void 0 : node.key) !== null && _node_key !== void 0 ? _node_key : null;
308 }
309 getItem(key) {
310 var _this_keyMap_get;
311 return (_this_keyMap_get = this.keyMap.get(key)) !== null && _this_keyMap_get !== void 0 ? _this_keyMap_get : null;
312 }
313 at() {
314 throw new Error('Not implemented');
315 }
316 clone() {
317 // We need to clone using this.constructor so that subclasses have the right prototype.
318 // TypeScript isn't happy about this yet.
319 // https://github.com/microsoft/TypeScript/issues/3841
320 let Constructor = this.constructor;
321 let collection = new Constructor();
322 collection.keyMap = new Map(this.keyMap);
323 collection.firstKey = this.firstKey;
324 collection.lastKey = this.lastKey;
325 return collection;
326 }
327 addNode(node) {
328 if (this.frozen) throw new Error('Cannot add a node to a frozen collection');
329 this.keyMap.set(node.key, node);
330 }
331 removeNode(key) {
332 if (this.frozen) throw new Error('Cannot remove a node to a frozen collection');
333 this.keyMap.delete(key);
334 }
335 commit(firstKey, lastKey, isSSR = false) {
336 if (this.frozen) throw new Error('Cannot commit a frozen collection');
337 this.firstKey = firstKey;
338 this.lastKey = lastKey;
339 this.frozen = !isSSR;
340 }
341 constructor(){
342 this.keyMap = new Map();
343 this.firstKey = null;
344 this.lastKey = null;
345 this.frozen = false;
346 }
347}
348class $7135fc7d473fd974$export$b34a105447964f9f extends $7135fc7d473fd974$var$BaseNode {
349 get isConnected() {
350 return true;
351 }
352 createElement(type) {
353 return new $7135fc7d473fd974$export$dc064fe9e59310fd(type, this);
354 }
355 /**
356 * Lazily gets a mutable instance of a Node. If the node has already
357 * been cloned during this update cycle, it just returns the existing one.
358 */ getMutableNode(element) {
359 let node = element.node;
360 if (!this.mutatedNodes.has(element)) {
361 node = element.node.clone();
362 this.mutatedNodes.add(element);
363 element.node = node;
364 }
365 this.markDirty(element);
366 return node;
367 }
368 getMutableCollection() {
369 if (!this.isSSR && !this.collectionMutated) {
370 this.collection = this.collection.clone();
371 this.collectionMutated = true;
372 }
373 return this.collection;
374 }
375 markDirty(node) {
376 this.dirtyNodes.add(node);
377 }
378 startTransaction() {
379 this.transactionCount++;
380 }
381 endTransaction() {
382 this.transactionCount--;
383 }
384 addNode(element) {
385 let collection = this.getMutableCollection();
386 if (!collection.getItem(element.node.key)) {
387 collection.addNode(element.node);
388 for (let child of element)this.addNode(child);
389 }
390 this.markDirty(element);
391 }
392 removeNode(node) {
393 for (let child of node)this.removeNode(child);
394 let collection = this.getMutableCollection();
395 collection.removeNode(node.node.key);
396 this.markDirty(node);
397 }
398 /** Finalizes the collection update, updating all nodes and freezing the collection. */ getCollection() {
399 if (this.transactionCount > 0) return this.collection;
400 this.updateCollection();
401 return this.collection;
402 }
403 updateCollection() {
404 for (let element of this.dirtyNodes)if (element instanceof $7135fc7d473fd974$export$dc064fe9e59310fd && element.isConnected) element.updateNode();
405 this.dirtyNodes.clear();
406 if (this.mutatedNodes.size || this.collectionMutated) {
407 var _this_firstChild, _this_lastChild;
408 let collection = this.getMutableCollection();
409 for (let element of this.mutatedNodes)if (element.isConnected) collection.addNode(element.node);
410 var _this_firstChild_node_key, _this_lastChild_node_key;
411 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);
412 this.mutatedNodes.clear();
413 }
414 this.collectionMutated = false;
415 }
416 queueUpdate() {
417 // Don't emit any updates if there is a transaction in progress.
418 // queueUpdate should be called again after the transaction.
419 if (this.dirtyNodes.size === 0 || this.transactionCount > 0) return;
420 for (let fn of this.subscriptions)fn();
421 }
422 subscribe(fn) {
423 this.subscriptions.add(fn);
424 return ()=>this.subscriptions.delete(fn);
425 }
426 resetAfterSSR() {
427 if (this.isSSR) {
428 this.isSSR = false;
429 this.firstChild = null;
430 this.lastChild = null;
431 this.nodeId = 0;
432 }
433 }
434 constructor(collection){
435 // @ts-ignore
436 super(null);
437 this.nodeType = 11 // DOCUMENT_FRAGMENT_NODE
438 ;
439 this.ownerDocument = this;
440 this.dirtyNodes = new Set();
441 this.isSSR = false;
442 this.nodeId = 0;
443 this.nodesByProps = new WeakMap();
444 this.mutatedNodes = new Set();
445 this.subscriptions = new Set();
446 this.transactionCount = 0;
447 this.collection = collection;
448 this.collectionMutated = true;
449 }
450}
451function $7135fc7d473fd974$export$727c8fc270210f13(props) {
452 let { children: children, items: items, idScope: idScope, addIdAndValue: addIdAndValue, dependencies: dependencies = [] } = props;
453 // Invalidate the cache whenever the parent value changes.
454 // eslint-disable-next-line react-hooks/exhaustive-deps
455 let cache = (0, $18I52$useMemo)(()=>new WeakMap(), dependencies);
456 return (0, $18I52$useMemo)(()=>{
457 if (items && typeof children === 'function') {
458 let res = [];
459 for (let item of items){
460 let rendered = cache.get(item);
461 if (!rendered) {
462 rendered = children(item);
463 var _rendered_props_id, _ref;
464 // @ts-ignore
465 let key = (_ref = (_rendered_props_id = rendered.props.id) !== null && _rendered_props_id !== void 0 ? _rendered_props_id : item.key) !== null && _ref !== void 0 ? _ref : item.id;
466 // eslint-disable-next-line max-depth
467 if (key == null) throw new Error('Could not determine key for item');
468 // eslint-disable-next-line max-depth
469 if (idScope) key = idScope + ':' + key;
470 // Note: only works if wrapped Item passes through id...
471 rendered = /*#__PURE__*/ (0, $18I52$cloneElement)(rendered, addIdAndValue ? {
472 key: key,
473 id: key,
474 value: item
475 } : {
476 key: key
477 });
478 cache.set(item, rendered);
479 }
480 res.push(rendered);
481 }
482 return res;
483 } else if (typeof children !== 'function') return children;
484 }, [
485 children,
486 items,
487 cache,
488 idScope,
489 addIdAndValue
490 ]);
491}
492function $7135fc7d473fd974$export$901dbff4e54a6dd0(props) {
493 return $7135fc7d473fd974$export$727c8fc270210f13({
494 ...props,
495 addIdAndValue: true
496 });
497}
498const $7135fc7d473fd974$var$ShallowRenderContext = /*#__PURE__*/ (0, $18I52$createContext)(false);
499function $7135fc7d473fd974$export$6cd28814d92fa9c9(props, initialCollection) {
500 let { collection: collection, document: document } = $7135fc7d473fd974$export$7cd71aa5ddd6dc4e(initialCollection);
501 let portal = $7135fc7d473fd974$export$ad42d5efb4461b31(props, document);
502 return {
503 portal: portal,
504 collection: collection
505 };
506}
507// React 16 and 17 don't support useSyncExternalStore natively, and the shim provided by React does not support getServerSnapshot.
508// This wrapper uses the shim, but additionally calls getServerSnapshot during SSR (according to SSRProvider).
509function $7135fc7d473fd974$var$useSyncExternalStoreFallback(subscribe, getSnapshot, getServerSnapshot) {
510 let isSSR = (0, $18I52$useIsSSR)();
511 let isSSRRef = (0, $18I52$useRef)(isSSR);
512 // This is read immediately inside the wrapper, which also runs during render.
513 // We just need a ref to avoid invalidating the callback itself, which
514 // would cause React to re-run the callback more than necessary.
515 // eslint-disable-next-line rulesdir/pure-render
516 isSSRRef.current = isSSR;
517 let getSnapshotWrapper = (0, $18I52$useCallback)(()=>{
518 return isSSRRef.current ? getServerSnapshot() : getSnapshot();
519 }, [
520 getSnapshot,
521 getServerSnapshot
522 ]);
523 return (0, $18I52$useSyncExternalStore)(subscribe, getSnapshotWrapper);
524}
525const $7135fc7d473fd974$var$useSyncExternalStore = typeof (0, $18I52$react)['useSyncExternalStore'] === 'function' ? (0, $18I52$react)['useSyncExternalStore'] : $7135fc7d473fd974$var$useSyncExternalStoreFallback;
526function $7135fc7d473fd974$export$7cd71aa5ddd6dc4e(initialCollection) {
527 // The document instance is mutable, and should never change between renders.
528 // useSyncExternalStore is used to subscribe to updates, which vends immutable Collection objects.
529 let document = (0, $18I52$useMemo)(()=>new $7135fc7d473fd974$export$b34a105447964f9f(initialCollection || new $7135fc7d473fd974$export$408d25a4e12db025()), [
530 initialCollection
531 ]);
532 let subscribe = (0, $18I52$useCallback)((fn)=>document.subscribe(fn), [
533 document
534 ]);
535 let getSnapshot = (0, $18I52$useCallback)(()=>{
536 let collection = document.getCollection();
537 if (document.isSSR) // After SSR is complete, reset the document to empty so it is ready for React to render the portal into.
538 // We do this _after_ getting the collection above so that the collection still has content in it from SSR
539 // during the current render, before React has finished the client render.
540 document.resetAfterSSR();
541 return collection;
542 }, [
543 document
544 ]);
545 let getServerSnapshot = (0, $18I52$useCallback)(()=>{
546 document.isSSR = true;
547 return document.getCollection();
548 }, [
549 document
550 ]);
551 let collection = $7135fc7d473fd974$var$useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
552 return {
553 collection: collection,
554 document: document
555 };
556}
557const $7135fc7d473fd974$var$SSRContext = /*#__PURE__*/ (0, $18I52$createContext)(null);
558const $7135fc7d473fd974$export$8c25dea96356a8b6 = /*#__PURE__*/ (0, $18I52$createContext)(null);
559function $7135fc7d473fd974$export$ad42d5efb4461b31(props, document) {
560 let ctx = (0, $18I52$useContext)($7135fc7d473fd974$export$8c25dea96356a8b6);
561 let doc = document !== null && document !== void 0 ? document : ctx;
562 let children = $7135fc7d473fd974$export$901dbff4e54a6dd0(props);
563 let wrappedChildren = (0, $18I52$useMemo)(()=>/*#__PURE__*/ (0, $18I52$react).createElement($7135fc7d473fd974$var$ShallowRenderContext.Provider, {
564 value: true
565 }, children), [
566 children
567 ]);
568 // During SSR, we render the content directly, and append nodes to the document during render.
569 // The collection children return null so that nothing is actually rendered into the HTML.
570 return (0, $18I52$useIsSSR)() ? /*#__PURE__*/ (0, $18I52$react).createElement($7135fc7d473fd974$var$SSRContext.Provider, {
571 value: doc
572 }, wrappedChildren) : /*#__PURE__*/ (0, $18I52$createPortal)(wrappedChildren, doc);
573}
574function $7135fc7d473fd974$export$813b5978dd974d8(props) {
575 return /*#__PURE__*/ (0, $18I52$react).createElement((0, $18I52$react).Fragment, null, $7135fc7d473fd974$export$ad42d5efb4461b31(props));
576}
577function $7135fc7d473fd974$export$aeba0b1fb3dcd8b8(type, props, ref) {
578 let isShallow = (0, $18I52$useContext)($7135fc7d473fd974$var$ShallowRenderContext);
579 var _useSSRCollectionNode;
580 if (isShallow) // Elements cannot be re-parented, so the context will always be there.
581 // eslint-disable-next-line react-hooks/rules-of-hooks
582 return (_useSSRCollectionNode = $7135fc7d473fd974$export$e7c29ae2353b16ea(type, props, ref, 'children' in props ? props.children : null)) !== null && _useSSRCollectionNode !== void 0 ? _useSSRCollectionNode : /*#__PURE__*/ (0, $18I52$react).createElement((0, $18I52$react).Fragment, null);
583 return null;
584}
585function $7135fc7d473fd974$export$636783d3732b5559(props, ref, rendered) {
586 // Return a callback ref that sets the props object on the fake DOM node.
587 return (0, $18I52$useCallback)((element)=>{
588 element === null || element === void 0 ? void 0 : element.setProps(props, ref, rendered);
589 }, [
590 props,
591 ref,
592 rendered
593 ]);
594}
595function $7135fc7d473fd974$export$e7c29ae2353b16ea(Type, props, ref, rendered, children) {
596 // During SSR, portals are not supported, so the collection children will be wrapped in an SSRContext.
597 // Since SSR occurs only once, we assume that the elements are rendered in order and never re-render.
598 // Therefore we can create elements in our collection document during render so that they are in the
599 // collection by the time we need to use the collection to render to the real DOM.
600 // After hydration, we switch to client rendering using the portal.
601 let itemRef = $7135fc7d473fd974$export$636783d3732b5559(props, ref, rendered);
602 let parentNode = (0, $18I52$useContext)($7135fc7d473fd974$var$SSRContext);
603 if (parentNode) {
604 // Guard against double rendering in strict mode.
605 let element = parentNode.ownerDocument.nodesByProps.get(props);
606 if (!element) {
607 element = parentNode.ownerDocument.createElement(Type);
608 element.setProps(props, ref, rendered);
609 parentNode.appendChild(element);
610 parentNode.ownerDocument.updateCollection();
611 parentNode.ownerDocument.nodesByProps.set(props, element);
612 }
613 return children ? /*#__PURE__*/ (0, $18I52$react).createElement($7135fc7d473fd974$var$SSRContext.Provider, {
614 value: element
615 }, children) : null;
616 }
617 // @ts-ignore
618 return /*#__PURE__*/ (0, $18I52$react).createElement(Type, {
619 ref: itemRef
620 }, children);
621}
622function $7135fc7d473fd974$var$Section(props, ref) {
623 let children = $7135fc7d473fd974$export$901dbff4e54a6dd0(props);
624 return $7135fc7d473fd974$export$e7c29ae2353b16ea('section', props, ref, null, children);
625}
626const $7135fc7d473fd974$export$6e2c8f0811a474ce = /*#__PURE__*/ (0, $18I52$forwardRef)($7135fc7d473fd974$var$Section);
627const $7135fc7d473fd974$export$db36075d98ba73d3 = /*#__PURE__*/ (0, $18I52$createContext)(null);
628const $7135fc7d473fd974$export$4feb769f8ddf26c5 = /*#__PURE__*/ (0, $18I52$createContext)(null);
629function $7135fc7d473fd974$export$fb8073518f34e6ec(props) {
630 let ctx = (0, $18I52$useContext)($7135fc7d473fd974$export$db36075d98ba73d3);
631 props = (0, $18I52$mergeProps)(ctx, props);
632 props.dependencies = ((ctx === null || ctx === void 0 ? void 0 : ctx.dependencies) || []).concat(props.dependencies);
633 let renderer = typeof props.children === 'function' ? props.children : null;
634 return /*#__PURE__*/ (0, $18I52$react).createElement($7135fc7d473fd974$export$4feb769f8ddf26c5.Provider, {
635 value: renderer
636 }, $7135fc7d473fd974$export$901dbff4e54a6dd0(props));
637}
638
639
640export {$7135fc7d473fd974$export$f5d856d854e74713 as NodeValue, $7135fc7d473fd974$export$dc064fe9e59310fd as ElementNode, $7135fc7d473fd974$export$408d25a4e12db025 as BaseCollection, $7135fc7d473fd974$export$b34a105447964f9f as Document, $7135fc7d473fd974$export$727c8fc270210f13 as useCachedChildren, $7135fc7d473fd974$export$901dbff4e54a6dd0 as useCollectionChildren, $7135fc7d473fd974$export$6cd28814d92fa9c9 as useCollection, $7135fc7d473fd974$export$7cd71aa5ddd6dc4e as useCollectionDocument, $7135fc7d473fd974$export$ad42d5efb4461b31 as useCollectionPortal, $7135fc7d473fd974$export$8c25dea96356a8b6 as CollectionDocumentContext, $7135fc7d473fd974$export$813b5978dd974d8 as CollectionPortal, $7135fc7d473fd974$export$aeba0b1fb3dcd8b8 as useShallowRender, $7135fc7d473fd974$export$e7c29ae2353b16ea as useSSRCollectionNode, $7135fc7d473fd974$export$636783d3732b5559 as useCollectionItemRef, $7135fc7d473fd974$export$6e2c8f0811a474ce as Section, $7135fc7d473fd974$export$db36075d98ba73d3 as CollectionContext, $7135fc7d473fd974$export$4feb769f8ddf26c5 as CollectionRendererContext, $7135fc7d473fd974$export$fb8073518f34e6ec as Collection};
641//# sourceMappingURL=Collection.module.js.map