@react-aria/collections 3.0.0-nightly.5038 → 3.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BaseCollection.main.js +104 -0
- package/dist/BaseCollection.main.js.map +1 -1
- package/dist/BaseCollection.mjs +104 -0
- package/dist/BaseCollection.module.js +104 -0
- package/dist/BaseCollection.module.js.map +1 -1
- package/dist/CollectionBuilder.main.js +9 -3
- package/dist/CollectionBuilder.main.js.map +1 -1
- package/dist/CollectionBuilder.mjs +9 -3
- package/dist/CollectionBuilder.module.js +9 -3
- package/dist/CollectionBuilder.module.js.map +1 -1
- package/dist/Document.main.js +146 -107
- package/dist/Document.main.js.map +1 -1
- package/dist/Document.mjs +146 -107
- package/dist/Document.module.js +146 -107
- package/dist/Document.module.js.map +1 -1
- package/dist/Hidden.main.js +4 -11
- package/dist/Hidden.main.js.map +1 -1
- package/dist/Hidden.mjs +4 -11
- package/dist/Hidden.module.js +4 -11
- package/dist/Hidden.module.js.map +1 -1
- package/dist/types.d.ts +12 -9
- package/dist/types.d.ts.map +1 -1
- package/dist/useCachedChildren.main.js +0 -2
- package/dist/useCachedChildren.main.js.map +1 -1
- package/dist/useCachedChildren.mjs +0 -2
- package/dist/useCachedChildren.module.js +0 -2
- package/dist/useCachedChildren.module.js.map +1 -1
- package/package.json +9 -8
- package/src/BaseCollection.ts +145 -10
- package/src/CollectionBuilder.tsx +20 -6
- package/src/Document.ts +210 -136
- package/src/Hidden.tsx +4 -12
- package/src/useCachedChildren.ts +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAYX,CAAC,CAAC,OAAO,QAAQ,CAAC,GAAG;QACnB,IAAI,OAAO,IAAI,CAAC,UAAU;QAC1B,MAAO,KAAM;YACX,MAAM;YACN,OAAO,KAAK,WAAW;QACzB;IACF;IAEA,IAAI,aAAa;QACf,OAAO,IAA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BAAgB,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, CollectionNode, Mutable} 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: CollectionNode<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 CollectionNode(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<CollectionNode<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"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AAwBM,MAAM;IAaX,CAAC,CAAC,OAAO,QAAQ,CAAC,GAA6B;QAC7C,IAAI,OAAO,IAAI,CAAC,UAAU;QAC1B,MAAO,KAAM;YACX,MAAM;YACN,OAAO,KAAK,WAAW;QACzB;IACF;IAEA,IAAI,aAAoC;QACtC,OAAO,IAAI,CAAC,WAAW;IACzB;IAEA,IAAI,WAAW,UAAiC,EAAE;QAChD,IAAI,CAAC,WAAW,GAAG;QACnB,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI;IACnC;IAEA,IAAI,YAAmC;QACrC,OAAO,IAAI,CAAC,UAAU;IACxB;IAEA,IAAI,UAAU,SAAgC,EAAE;QAC9C,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI;IACnC;IAEA,IAAI,kBAAyC;QAC3C,OAAO,IAAI,CAAC,gBAAgB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AChB;IACF;IApIA,YAAY,UAAa,CAAE;QACzB,aAAa;QACb,KAAK,CAAC,YAfR,WAAW,GAAI,yBAAyB;eACxC,gBAAgB,IAAI,OACpB,aAA+B,IAAI,YACnC,QAAQ,YACR,SAAS,QACT,eAAe,IAAI,gBACnB,YAAY,WAEJ,iBAA2B,WAC3B,gBAAiC,IAAI,YACrC,eAAe,YACf,iBAAiB;QAKvB,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,cAAc,GAAG;IACxB;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, CollectionNode, Mutable} from './BaseCollection';\nimport {CSSProperties, ForwardedRef, ReactElement, ReactNode} 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 private _minInvalidChildIndex: ElementNode<T> | null = null;\n ownerDocument: Document<T, any>;\n\n constructor(ownerDocument: Document<T, any>) {\n this.ownerDocument = ownerDocument;\n }\n\n *[Symbol.iterator](): Iterator<ElementNode<T>> {\n let node = this.firstChild;\n while (node) {\n yield node;\n node = node.nextSibling;\n }\n }\n\n get firstChild(): ElementNode<T> | null {\n return this._firstChild;\n }\n\n set firstChild(firstChild: ElementNode<T> | null) {\n this._firstChild = firstChild;\n this.ownerDocument.markDirty(this);\n }\n\n get lastChild(): ElementNode<T> | null {\n return this._lastChild;\n }\n\n set lastChild(lastChild: ElementNode<T> | null) {\n this._lastChild = lastChild;\n this.ownerDocument.markDirty(this);\n }\n\n get previousSibling(): ElementNode<T> | null {\n return this._previousSibling;\n }\n\n set previousSibling(previousSibling: ElementNode<T> | null) {\n this._previousSibling = previousSibling;\n this.ownerDocument.markDirty(this);\n }\n\n get nextSibling(): ElementNode<T> | null {\n return this._nextSibling;\n }\n\n set nextSibling(nextSibling: ElementNode<T> | null) {\n this._nextSibling = nextSibling;\n this.ownerDocument.markDirty(this);\n }\n\n get parentNode(): BaseNode<T> | null {\n return this._parentNode;\n }\n\n set parentNode(parentNode: BaseNode<T> | null) {\n this._parentNode = parentNode;\n this.ownerDocument.markDirty(this);\n }\n\n get isConnected(): boolean {\n return this.parentNode?.isConnected || false;\n }\n\n private invalidateChildIndices(child: ElementNode<T>): void {\n if (this._minInvalidChildIndex == null || child.index < this._minInvalidChildIndex.index) {\n this._minInvalidChildIndex = child;\n }\n }\n\n updateChildIndices(): void {\n let node = this._minInvalidChildIndex;\n while (node) {\n node.index = node.previousSibling ? node.previousSibling.index + 1 : 0;\n node = node.nextSibling;\n }\n this._minInvalidChildIndex = null;\n }\n\n appendChild(child: ElementNode<T>): void {\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 this.ownerDocument.queueUpdate();\n }\n\n insertBefore(newNode: ElementNode<T>, referenceNode: ElementNode<T>): void {\n if (referenceNode == null) {\n return this.appendChild(newNode);\n }\n\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 this.invalidateChildIndices(referenceNode);\n this.ownerDocument.queueUpdate();\n }\n\n removeChild(child: ElementNode<T>): void {\n if (child.parentNode !== this || !this.ownerDocument.isMounted) {\n return;\n }\n \n if (child.nextSibling) {\n this.invalidateChildIndices(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.markDirty(child);\n this.ownerDocument.queueUpdate();\n }\n\n addEventListener(): void {}\n removeEventListener(): void {}\n\n get previousVisibleSibling(): ElementNode<T> | null {\n let node = this.previousSibling;\n while (node && node.isHidden) {\n node = node.previousSibling;\n }\n return node;\n }\n\n get nextVisibleSibling(): ElementNode<T> | null {\n let node = this.nextSibling;\n while (node && node.isHidden) {\n node = node.nextSibling;\n }\n return node;\n }\n\n get firstVisibleChild(): ElementNode<T> | null {\n let node = this.firstChild;\n while (node && node.isHidden) {\n node = node.nextSibling;\n }\n return node;\n }\n\n get lastVisibleChild(): ElementNode<T> | null {\n let node = this.lastChild;\n while (node && node.isHidden) {\n node = node.previousSibling;\n }\n return node;\n }\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: CollectionNode<T>;\n isMutated = true;\n private _index: number = 0;\n hasSetProps = false;\n isHidden = false;\n\n constructor(type: string, ownerDocument: Document<T, any>) {\n super(ownerDocument);\n this.node = new CollectionNode(type, `react-aria-${++ownerDocument.nodeId}`);\n }\n\n get index(): number {\n return this._index;\n }\n\n set index(index: number) {\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 /**\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 private getMutableNode(): Mutable<CollectionNode<T>> {\n if (!this.isMutated) {\n this.node = this.node.clone();\n this.isMutated = true;\n }\n \n this.ownerDocument.markDirty(this);\n return this.node;\n }\n\n updateNode(): void {\n let nextSibling = this.nextVisibleSibling;\n let node = this.getMutableNode();\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.previousVisibleSibling?.node.key ?? null;\n node.nextKey = nextSibling?.node.key ?? null;\n node.hasChildNodes = !!this.firstChild;\n node.firstChildKey = this.firstVisibleChild?.node.key ?? null;\n node.lastChildKey = this.lastVisibleChild?.node.key ?? null;\n\n // Update the colIndex of sibling nodes if this node has a colSpan.\n if ((node.colSpan != null || node.colIndex != null) && nextSibling) {\n // This queues the next sibling for update, which means this happens recursively.\n let nextColIndex = (node.colIndex ?? node.index) + (node.colSpan ?? 1);\n if (nextColIndex !== nextSibling.node.colIndex) {\n let siblingNode = nextSibling.getMutableNode();\n siblingNode.colIndex = nextColIndex;\n }\n }\n }\n\n setProps<E extends Element>(obj: {[key: string]: any}, ref: ForwardedRef<E>, rendered?: ReactNode, render?: (node: Node<T>) => ReactElement): void {\n let node = this.getMutableNode();\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 (props.colSpan != null) {\n node.colSpan = props.colSpan;\n }\n\n this.hasSetProps = true;\n this.ownerDocument.queueUpdate();\n }\n\n get style(): CSSProperties {\n // React sets display: none to hide elements during Suspense.\n // We'll handle this by setting the element to hidden and invalidating\n // its siblings/parent. Hidden elements remain in the Document, but\n // are removed from the Collection.\n let element = this;\n return {\n get display() {\n return element.isHidden ? 'none' : '';\n },\n set display(value) {\n let isHidden = value === 'none';\n if (element.isHidden !== isHidden) {\n // Mark parent node dirty if this element is currently the first or last visible child.\n if (element.parentNode?.firstVisibleChild === element || element.parentNode?.lastVisibleChild === element) {\n element.ownerDocument.markDirty(element.parentNode);\n }\n\n // Mark sibling visible elements dirty.\n let prev = element.previousVisibleSibling;\n let next = element.nextVisibleSibling;\n if (prev) {\n element.ownerDocument.markDirty(prev);\n }\n if (next) {\n element.ownerDocument.markDirty(next);\n }\n\n // Mark self dirty.\n element.isHidden = isHidden;\n element.ownerDocument.markDirty(element);\n }\n }\n };\n }\n\n hasAttribute(): void {}\n setAttribute(): void {}\n setAttributeNS(): void {}\n removeAttribute(): void {}\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 nextCollection: C | null = null;\n private subscriptions: Set<() => void> = new Set();\n private queuedRender = false;\n private inSubscription = false;\n\n constructor(collection: C) {\n // @ts-ignore\n super(null);\n this.collection = collection;\n this.nextCollection = collection;\n }\n\n get isConnected(): boolean {\n return this.isMounted;\n }\n\n createElement(type: string): ElementNode<T> {\n return new ElementNode(type, this);\n }\n\n private getMutableCollection() {\n if (!this.nextCollection) {\n this.nextCollection = this.collection.clone();\n }\n\n return this.nextCollection;\n }\n\n markDirty(node: BaseNode<T>): void {\n this.dirtyNodes.add(node);\n }\n\n private addNode(element: ElementNode<T>): void {\n if (element.isHidden) {\n return;\n }\n\n let collection = this.getMutableCollection();\n if (!collection.getItem(element.node.key)) {\n for (let child of element) {\n this.addNode(child);\n }\n }\n\n collection.addNode(element.node);\n }\n\n private removeNode(node: ElementNode<T>): void {\n for (let child of node) {\n this.removeNode(child);\n }\n\n let collection = this.getMutableCollection();\n collection.removeNode(node.node.key);\n }\n\n /** Finalizes the collection update, updating all nodes and freezing the collection. */\n getCollection(): C {\n // If in a subscription update, return a clone of the existing collection.\n // This ensures React will queue a render. React will call getCollection again\n // during render, at which point all the updates will be complete and we can return\n // the new collection.\n if (this.inSubscription) {\n return this.collection.clone();\n }\n\n // Reset queuedRender to false when getCollection is called during render.\n this.queuedRender = false;\n\n this.updateCollection();\n return this.collection;\n }\n\n updateCollection(): void {\n // First, remove disconnected nodes and update the indices of dirty element children.\n for (let element of this.dirtyNodes) {\n if (element instanceof ElementNode && (!element.isConnected || element.isHidden)) {\n this.removeNode(element);\n } else {\n element.updateChildIndices();\n }\n }\n\n // Next, update dirty collection nodes.\n for (let element of this.dirtyNodes) {\n if (element instanceof ElementNode) {\n if (element.isConnected && !element.isHidden) {\n element.updateNode();\n this.addNode(element);\n }\n\n element.isMutated = false;\n }\n }\n\n this.dirtyNodes.clear();\n\n // Finally, update the collection.\n if (this.nextCollection) {\n this.nextCollection.commit(this.firstVisibleChild?.node.key ?? null, this.lastVisibleChild?.node.key ?? null, this.isSSR);\n if (!this.isSSR) {\n this.collection = this.nextCollection;\n this.nextCollection = null;\n }\n }\n }\n\n queueUpdate(): void {\n if (this.dirtyNodes.size === 0 || this.queuedRender) {\n return;\n }\n \n // Only trigger subscriptions once during an update, when the first item changes.\n // React's useSyncExternalStore will call getCollection immediately, to check whether the snapshot changed.\n // If so, React will queue a render to happen after the current commit to our fake DOM finishes.\n // We track whether getCollection is called in a subscription, and once it is called during render,\n // we reset queuedRender back to false.\n this.queuedRender = true;\n this.inSubscription = true;\n for (let fn of this.subscriptions) {\n fn();\n }\n this.inSubscription = false;\n }\n\n subscribe(fn: () => void) {\n this.subscriptions.add(fn);\n return (): boolean => this.subscriptions.delete(fn);\n }\n\n resetAfterSSR(): void {\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"}
|
package/dist/Document.mjs
CHANGED
|
@@ -58,8 +58,18 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
|
|
|
58
58
|
var _this_parentNode;
|
|
59
59
|
return ((_this_parentNode = this.parentNode) === null || _this_parentNode === void 0 ? void 0 : _this_parentNode.isConnected) || false;
|
|
60
60
|
}
|
|
61
|
+
invalidateChildIndices(child) {
|
|
62
|
+
if (this._minInvalidChildIndex == null || child.index < this._minInvalidChildIndex.index) this._minInvalidChildIndex = child;
|
|
63
|
+
}
|
|
64
|
+
updateChildIndices() {
|
|
65
|
+
let node = this._minInvalidChildIndex;
|
|
66
|
+
while(node){
|
|
67
|
+
node.index = node.previousSibling ? node.previousSibling.index + 1 : 0;
|
|
68
|
+
node = node.nextSibling;
|
|
69
|
+
}
|
|
70
|
+
this._minInvalidChildIndex = null;
|
|
71
|
+
}
|
|
61
72
|
appendChild(child) {
|
|
62
|
-
this.ownerDocument.startTransaction();
|
|
63
73
|
if (child.parentNode) child.parentNode.removeChild(child);
|
|
64
74
|
if (this.firstChild == null) this.firstChild = child;
|
|
65
75
|
if (this.lastChild) {
|
|
@@ -74,15 +84,10 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
|
|
|
74
84
|
child.nextSibling = null;
|
|
75
85
|
this.lastChild = child;
|
|
76
86
|
this.ownerDocument.markDirty(this);
|
|
77
|
-
if (child.hasSetProps) // Only add the node to the collection if we already received props for it.
|
|
78
|
-
// Otherwise wait until then so we have the correct id for the node.
|
|
79
|
-
this.ownerDocument.addNode(child);
|
|
80
|
-
this.ownerDocument.endTransaction();
|
|
81
87
|
this.ownerDocument.queueUpdate();
|
|
82
88
|
}
|
|
83
89
|
insertBefore(newNode, referenceNode) {
|
|
84
90
|
if (referenceNode == null) return this.appendChild(newNode);
|
|
85
|
-
this.ownerDocument.startTransaction();
|
|
86
91
|
if (newNode.parentNode) newNode.parentNode.removeChild(newNode);
|
|
87
92
|
newNode.nextSibling = referenceNode;
|
|
88
93
|
newNode.previousSibling = referenceNode.previousSibling;
|
|
@@ -91,24 +96,15 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
|
|
|
91
96
|
else if (referenceNode.previousSibling) referenceNode.previousSibling.nextSibling = newNode;
|
|
92
97
|
referenceNode.previousSibling = newNode;
|
|
93
98
|
newNode.parentNode = referenceNode.parentNode;
|
|
94
|
-
|
|
95
|
-
while(node){
|
|
96
|
-
node.index++;
|
|
97
|
-
node = node.nextSibling;
|
|
98
|
-
}
|
|
99
|
-
if (newNode.hasSetProps) this.ownerDocument.addNode(newNode);
|
|
100
|
-
this.ownerDocument.endTransaction();
|
|
99
|
+
this.invalidateChildIndices(referenceNode);
|
|
101
100
|
this.ownerDocument.queueUpdate();
|
|
102
101
|
}
|
|
103
102
|
removeChild(child) {
|
|
104
103
|
if (child.parentNode !== this || !this.ownerDocument.isMounted) return;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
node.index--;
|
|
109
|
-
node = node.nextSibling;
|
|
104
|
+
if (child.nextSibling) {
|
|
105
|
+
this.invalidateChildIndices(child.nextSibling);
|
|
106
|
+
child.nextSibling.previousSibling = child.previousSibling;
|
|
110
107
|
}
|
|
111
|
-
if (child.nextSibling) child.nextSibling.previousSibling = child.previousSibling;
|
|
112
108
|
if (child.previousSibling) child.previousSibling.nextSibling = child.nextSibling;
|
|
113
109
|
if (this.firstChild === child) this.firstChild = child.nextSibling;
|
|
114
110
|
if (this.lastChild === child) this.lastChild = child.previousSibling;
|
|
@@ -116,18 +112,38 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
|
|
|
116
112
|
child.nextSibling = null;
|
|
117
113
|
child.previousSibling = null;
|
|
118
114
|
child.index = 0;
|
|
119
|
-
this.ownerDocument.
|
|
120
|
-
this.ownerDocument.endTransaction();
|
|
115
|
+
this.ownerDocument.markDirty(child);
|
|
121
116
|
this.ownerDocument.queueUpdate();
|
|
122
117
|
}
|
|
123
118
|
addEventListener() {}
|
|
124
119
|
removeEventListener() {}
|
|
120
|
+
get previousVisibleSibling() {
|
|
121
|
+
let node = this.previousSibling;
|
|
122
|
+
while(node && node.isHidden)node = node.previousSibling;
|
|
123
|
+
return node;
|
|
124
|
+
}
|
|
125
|
+
get nextVisibleSibling() {
|
|
126
|
+
let node = this.nextSibling;
|
|
127
|
+
while(node && node.isHidden)node = node.nextSibling;
|
|
128
|
+
return node;
|
|
129
|
+
}
|
|
130
|
+
get firstVisibleChild() {
|
|
131
|
+
let node = this.firstChild;
|
|
132
|
+
while(node && node.isHidden)node = node.nextSibling;
|
|
133
|
+
return node;
|
|
134
|
+
}
|
|
135
|
+
get lastVisibleChild() {
|
|
136
|
+
let node = this.lastChild;
|
|
137
|
+
while(node && node.isHidden)node = node.previousSibling;
|
|
138
|
+
return node;
|
|
139
|
+
}
|
|
125
140
|
constructor(ownerDocument){
|
|
126
141
|
this._firstChild = null;
|
|
127
142
|
this._lastChild = null;
|
|
128
143
|
this._previousSibling = null;
|
|
129
144
|
this._nextSibling = null;
|
|
130
145
|
this._parentNode = null;
|
|
146
|
+
this._minInvalidChildIndex = null;
|
|
131
147
|
this.ownerDocument = ownerDocument;
|
|
132
148
|
}
|
|
133
149
|
}
|
|
@@ -143,62 +159,97 @@ class $681cc3c98f569e39$export$dc064fe9e59310fd extends $681cc3c98f569e39$export
|
|
|
143
159
|
if (this.parentNode instanceof $681cc3c98f569e39$export$dc064fe9e59310fd) return this.parentNode.level + (this.node.type === 'item' ? 1 : 0);
|
|
144
160
|
return 0;
|
|
145
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Lazily gets a mutable instance of a Node. If the node has already
|
|
164
|
+
* been cloned during this update cycle, it just returns the existing one.
|
|
165
|
+
*/ getMutableNode() {
|
|
166
|
+
if (!this.isMutated) {
|
|
167
|
+
this.node = this.node.clone();
|
|
168
|
+
this.isMutated = true;
|
|
169
|
+
}
|
|
170
|
+
this.ownerDocument.markDirty(this);
|
|
171
|
+
return this.node;
|
|
172
|
+
}
|
|
146
173
|
updateNode() {
|
|
147
|
-
var
|
|
148
|
-
let
|
|
174
|
+
var _this_previousVisibleSibling, _this_firstVisibleChild, _this_lastVisibleChild;
|
|
175
|
+
let nextSibling = this.nextVisibleSibling;
|
|
176
|
+
let node = this.getMutableNode();
|
|
149
177
|
node.index = this.index;
|
|
150
178
|
node.level = this.level;
|
|
151
179
|
node.parentKey = this.parentNode instanceof $681cc3c98f569e39$export$dc064fe9e59310fd ? this.parentNode.node.key : null;
|
|
152
|
-
var
|
|
153
|
-
node.prevKey = (
|
|
154
|
-
var
|
|
155
|
-
node.nextKey = (
|
|
180
|
+
var _this_previousVisibleSibling_node_key;
|
|
181
|
+
node.prevKey = (_this_previousVisibleSibling_node_key = (_this_previousVisibleSibling = this.previousVisibleSibling) === null || _this_previousVisibleSibling === void 0 ? void 0 : _this_previousVisibleSibling.node.key) !== null && _this_previousVisibleSibling_node_key !== void 0 ? _this_previousVisibleSibling_node_key : null;
|
|
182
|
+
var _nextSibling_node_key;
|
|
183
|
+
node.nextKey = (_nextSibling_node_key = nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.node.key) !== null && _nextSibling_node_key !== void 0 ? _nextSibling_node_key : null;
|
|
156
184
|
node.hasChildNodes = !!this.firstChild;
|
|
157
|
-
var
|
|
158
|
-
node.firstChildKey = (
|
|
159
|
-
var
|
|
160
|
-
node.lastChildKey = (
|
|
185
|
+
var _this_firstVisibleChild_node_key;
|
|
186
|
+
node.firstChildKey = (_this_firstVisibleChild_node_key = (_this_firstVisibleChild = this.firstVisibleChild) === null || _this_firstVisibleChild === void 0 ? void 0 : _this_firstVisibleChild.node.key) !== null && _this_firstVisibleChild_node_key !== void 0 ? _this_firstVisibleChild_node_key : null;
|
|
187
|
+
var _this_lastVisibleChild_node_key;
|
|
188
|
+
node.lastChildKey = (_this_lastVisibleChild_node_key = (_this_lastVisibleChild = this.lastVisibleChild) === null || _this_lastVisibleChild === void 0 ? void 0 : _this_lastVisibleChild.node.key) !== null && _this_lastVisibleChild_node_key !== void 0 ? _this_lastVisibleChild_node_key : null;
|
|
189
|
+
// Update the colIndex of sibling nodes if this node has a colSpan.
|
|
190
|
+
if ((node.colSpan != null || node.colIndex != null) && nextSibling) {
|
|
191
|
+
var _node_colIndex, _node_colSpan;
|
|
192
|
+
// This queues the next sibling for update, which means this happens recursively.
|
|
193
|
+
let nextColIndex = ((_node_colIndex = node.colIndex) !== null && _node_colIndex !== void 0 ? _node_colIndex : node.index) + ((_node_colSpan = node.colSpan) !== null && _node_colSpan !== void 0 ? _node_colSpan : 1);
|
|
194
|
+
if (nextColIndex !== nextSibling.node.colIndex) {
|
|
195
|
+
let siblingNode = nextSibling.getMutableNode();
|
|
196
|
+
siblingNode.colIndex = nextColIndex;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
161
199
|
}
|
|
162
200
|
setProps(obj, ref, rendered, render) {
|
|
163
|
-
let node = this.
|
|
164
|
-
let { value:
|
|
201
|
+
let node = this.getMutableNode();
|
|
202
|
+
let { value: value1, textValue: textValue, id: id, ...props } = obj;
|
|
165
203
|
props.ref = ref;
|
|
166
204
|
node.props = props;
|
|
167
205
|
node.rendered = rendered;
|
|
168
206
|
node.render = render;
|
|
169
|
-
node.value =
|
|
207
|
+
node.value = value1;
|
|
170
208
|
node.textValue = textValue || (typeof props.children === 'string' ? props.children : '') || obj['aria-label'] || '';
|
|
171
209
|
if (id != null && id !== node.key) {
|
|
172
210
|
if (this.hasSetProps) throw new Error('Cannot change the id of an item');
|
|
173
211
|
node.key = id;
|
|
174
212
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (!this.hasSetProps) {
|
|
178
|
-
this.ownerDocument.addNode(this);
|
|
179
|
-
this.ownerDocument.endTransaction();
|
|
180
|
-
this.hasSetProps = true;
|
|
181
|
-
}
|
|
213
|
+
if (props.colSpan != null) node.colSpan = props.colSpan;
|
|
214
|
+
this.hasSetProps = true;
|
|
182
215
|
this.ownerDocument.queueUpdate();
|
|
183
216
|
}
|
|
184
217
|
get style() {
|
|
185
|
-
|
|
218
|
+
// React sets display: none to hide elements during Suspense.
|
|
219
|
+
// We'll handle this by setting the element to hidden and invalidating
|
|
220
|
+
// its siblings/parent. Hidden elements remain in the Document, but
|
|
221
|
+
// are removed from the Collection.
|
|
222
|
+
let element = this;
|
|
223
|
+
return {
|
|
224
|
+
get display () {
|
|
225
|
+
return element.isHidden ? 'none' : '';
|
|
226
|
+
},
|
|
227
|
+
set display (value){
|
|
228
|
+
let isHidden = value === 'none';
|
|
229
|
+
if (element.isHidden !== isHidden) {
|
|
230
|
+
var _element_parentNode, _element_parentNode1;
|
|
231
|
+
// Mark parent node dirty if this element is currently the first or last visible child.
|
|
232
|
+
if (((_element_parentNode = element.parentNode) === null || _element_parentNode === void 0 ? void 0 : _element_parentNode.firstVisibleChild) === element || ((_element_parentNode1 = element.parentNode) === null || _element_parentNode1 === void 0 ? void 0 : _element_parentNode1.lastVisibleChild) === element) element.ownerDocument.markDirty(element.parentNode);
|
|
233
|
+
// Mark sibling visible elements dirty.
|
|
234
|
+
let prev = element.previousVisibleSibling;
|
|
235
|
+
let next = element.nextVisibleSibling;
|
|
236
|
+
if (prev) element.ownerDocument.markDirty(prev);
|
|
237
|
+
if (next) element.ownerDocument.markDirty(next);
|
|
238
|
+
// Mark self dirty.
|
|
239
|
+
element.isHidden = isHidden;
|
|
240
|
+
element.ownerDocument.markDirty(element);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
};
|
|
186
244
|
}
|
|
187
245
|
hasAttribute() {}
|
|
188
246
|
setAttribute() {}
|
|
189
247
|
setAttributeNS() {}
|
|
190
248
|
removeAttribute() {}
|
|
191
249
|
constructor(type, ownerDocument){
|
|
192
|
-
super(ownerDocument)
|
|
193
|
-
this.
|
|
194
|
-
;
|
|
195
|
-
this._index = 0;
|
|
196
|
-
this.hasSetProps = false;
|
|
250
|
+
super(ownerDocument), this.nodeType = 8 // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions)
|
|
251
|
+
, this.isMutated = true, this._index = 0, this.hasSetProps = false, this.isHidden = false;
|
|
197
252
|
this.node = new (0, $23b9f4fcf0fe224b$export$d68d59712b04d9d1)(type, `react-aria-${++ownerDocument.nodeId}`);
|
|
198
|
-
// Start a transaction so that no updates are emitted from the collection
|
|
199
|
-
// until the props for this node are set. We don't know the real id for the
|
|
200
|
-
// node until then, so we need to avoid emitting collections in an inconsistent state.
|
|
201
|
-
this.ownerDocument.startTransaction();
|
|
202
253
|
}
|
|
203
254
|
}
|
|
204
255
|
class $681cc3c98f569e39$export$b34a105447964f9f extends $681cc3c98f569e39$export$410b0c854570d131 {
|
|
@@ -208,72 +259,70 @@ class $681cc3c98f569e39$export$b34a105447964f9f extends $681cc3c98f569e39$export
|
|
|
208
259
|
createElement(type) {
|
|
209
260
|
return new $681cc3c98f569e39$export$dc064fe9e59310fd(type, this);
|
|
210
261
|
}
|
|
211
|
-
/**
|
|
212
|
-
* Lazily gets a mutable instance of a Node. If the node has already
|
|
213
|
-
* been cloned during this update cycle, it just returns the existing one.
|
|
214
|
-
*/ getMutableNode(element) {
|
|
215
|
-
let node = element.node;
|
|
216
|
-
if (!this.mutatedNodes.has(element)) {
|
|
217
|
-
node = element.node.clone();
|
|
218
|
-
this.mutatedNodes.add(element);
|
|
219
|
-
element.node = node;
|
|
220
|
-
}
|
|
221
|
-
this.markDirty(element);
|
|
222
|
-
return node;
|
|
223
|
-
}
|
|
224
262
|
getMutableCollection() {
|
|
225
|
-
if (!this.
|
|
226
|
-
|
|
227
|
-
this.collectionMutated = true;
|
|
228
|
-
}
|
|
229
|
-
return this.collection;
|
|
263
|
+
if (!this.nextCollection) this.nextCollection = this.collection.clone();
|
|
264
|
+
return this.nextCollection;
|
|
230
265
|
}
|
|
231
266
|
markDirty(node) {
|
|
232
267
|
this.dirtyNodes.add(node);
|
|
233
268
|
}
|
|
234
|
-
startTransaction() {
|
|
235
|
-
this.transactionCount++;
|
|
236
|
-
}
|
|
237
|
-
endTransaction() {
|
|
238
|
-
this.transactionCount--;
|
|
239
|
-
}
|
|
240
269
|
addNode(element) {
|
|
270
|
+
if (element.isHidden) return;
|
|
241
271
|
let collection = this.getMutableCollection();
|
|
242
|
-
if (!collection.getItem(element.node.key))
|
|
243
|
-
|
|
244
|
-
for (let child of element)this.addNode(child);
|
|
245
|
-
}
|
|
246
|
-
this.markDirty(element);
|
|
272
|
+
if (!collection.getItem(element.node.key)) for (let child of element)this.addNode(child);
|
|
273
|
+
collection.addNode(element.node);
|
|
247
274
|
}
|
|
248
275
|
removeNode(node) {
|
|
249
276
|
for (let child of node)this.removeNode(child);
|
|
250
277
|
let collection = this.getMutableCollection();
|
|
251
278
|
collection.removeNode(node.node.key);
|
|
252
|
-
this.markDirty(node);
|
|
253
279
|
}
|
|
254
280
|
/** Finalizes the collection update, updating all nodes and freezing the collection. */ getCollection() {
|
|
255
|
-
|
|
281
|
+
// If in a subscription update, return a clone of the existing collection.
|
|
282
|
+
// This ensures React will queue a render. React will call getCollection again
|
|
283
|
+
// during render, at which point all the updates will be complete and we can return
|
|
284
|
+
// the new collection.
|
|
285
|
+
if (this.inSubscription) return this.collection.clone();
|
|
286
|
+
// Reset queuedRender to false when getCollection is called during render.
|
|
287
|
+
this.queuedRender = false;
|
|
256
288
|
this.updateCollection();
|
|
257
289
|
return this.collection;
|
|
258
290
|
}
|
|
259
291
|
updateCollection() {
|
|
260
|
-
|
|
292
|
+
// First, remove disconnected nodes and update the indices of dirty element children.
|
|
293
|
+
for (let element of this.dirtyNodes)if (element instanceof $681cc3c98f569e39$export$dc064fe9e59310fd && (!element.isConnected || element.isHidden)) this.removeNode(element);
|
|
294
|
+
else element.updateChildIndices();
|
|
295
|
+
// Next, update dirty collection nodes.
|
|
296
|
+
for (let element of this.dirtyNodes)if (element instanceof $681cc3c98f569e39$export$dc064fe9e59310fd) {
|
|
297
|
+
if (element.isConnected && !element.isHidden) {
|
|
298
|
+
element.updateNode();
|
|
299
|
+
this.addNode(element);
|
|
300
|
+
}
|
|
301
|
+
element.isMutated = false;
|
|
302
|
+
}
|
|
261
303
|
this.dirtyNodes.clear();
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
304
|
+
// Finally, update the collection.
|
|
305
|
+
if (this.nextCollection) {
|
|
306
|
+
var _this_firstVisibleChild, _this_lastVisibleChild;
|
|
307
|
+
var _this_firstVisibleChild_node_key, _this_lastVisibleChild_node_key;
|
|
308
|
+
this.nextCollection.commit((_this_firstVisibleChild_node_key = (_this_firstVisibleChild = this.firstVisibleChild) === null || _this_firstVisibleChild === void 0 ? void 0 : _this_firstVisibleChild.node.key) !== null && _this_firstVisibleChild_node_key !== void 0 ? _this_firstVisibleChild_node_key : null, (_this_lastVisibleChild_node_key = (_this_lastVisibleChild = this.lastVisibleChild) === null || _this_lastVisibleChild === void 0 ? void 0 : _this_lastVisibleChild.node.key) !== null && _this_lastVisibleChild_node_key !== void 0 ? _this_lastVisibleChild_node_key : null, this.isSSR);
|
|
309
|
+
if (!this.isSSR) {
|
|
310
|
+
this.collection = this.nextCollection;
|
|
311
|
+
this.nextCollection = null;
|
|
312
|
+
}
|
|
269
313
|
}
|
|
270
|
-
this.collectionMutated = false;
|
|
271
314
|
}
|
|
272
315
|
queueUpdate() {
|
|
273
|
-
|
|
274
|
-
//
|
|
275
|
-
|
|
316
|
+
if (this.dirtyNodes.size === 0 || this.queuedRender) return;
|
|
317
|
+
// Only trigger subscriptions once during an update, when the first item changes.
|
|
318
|
+
// React's useSyncExternalStore will call getCollection immediately, to check whether the snapshot changed.
|
|
319
|
+
// If so, React will queue a render to happen after the current commit to our fake DOM finishes.
|
|
320
|
+
// We track whether getCollection is called in a subscription, and once it is called during render,
|
|
321
|
+
// we reset queuedRender back to false.
|
|
322
|
+
this.queuedRender = true;
|
|
323
|
+
this.inSubscription = true;
|
|
276
324
|
for (let fn of this.subscriptions)fn();
|
|
325
|
+
this.inSubscription = false;
|
|
277
326
|
}
|
|
278
327
|
subscribe(fn) {
|
|
279
328
|
this.subscriptions.add(fn);
|
|
@@ -289,20 +338,10 @@ class $681cc3c98f569e39$export$b34a105447964f9f extends $681cc3c98f569e39$export
|
|
|
289
338
|
}
|
|
290
339
|
constructor(collection){
|
|
291
340
|
// @ts-ignore
|
|
292
|
-
super(null)
|
|
293
|
-
this.
|
|
294
|
-
;
|
|
295
|
-
this.ownerDocument = this;
|
|
296
|
-
this.dirtyNodes = new Set();
|
|
297
|
-
this.isSSR = false;
|
|
298
|
-
this.nodeId = 0;
|
|
299
|
-
this.nodesByProps = new WeakMap();
|
|
300
|
-
this.isMounted = true;
|
|
301
|
-
this.mutatedNodes = new Set();
|
|
302
|
-
this.subscriptions = new Set();
|
|
303
|
-
this.transactionCount = 0;
|
|
341
|
+
super(null), this.nodeType = 11 // DOCUMENT_FRAGMENT_NODE
|
|
342
|
+
, this.ownerDocument = this, this.dirtyNodes = new Set(), this.isSSR = false, this.nodeId = 0, this.nodesByProps = new WeakMap(), this.isMounted = true, this.nextCollection = null, this.subscriptions = new Set(), this.queuedRender = false, this.inSubscription = false;
|
|
304
343
|
this.collection = collection;
|
|
305
|
-
this.
|
|
344
|
+
this.nextCollection = collection;
|
|
306
345
|
}
|
|
307
346
|
}
|
|
308
347
|
|