@react-aria/collections 3.0.0-nightly-74cac946a-250317 → 3.0.0-nightly-e00dc8373-250318

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/Document.mjs CHANGED
@@ -70,7 +70,6 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
70
70
  this._minInvalidChildIndex = null;
71
71
  }
72
72
  appendChild(child) {
73
- this.ownerDocument.startTransaction();
74
73
  if (child.parentNode) child.parentNode.removeChild(child);
75
74
  if (this.firstChild == null) this.firstChild = child;
76
75
  if (this.lastChild) {
@@ -85,15 +84,10 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
85
84
  child.nextSibling = null;
86
85
  this.lastChild = child;
87
86
  this.ownerDocument.markDirty(this);
88
- if (child.hasSetProps) // Only add the node to the collection if we already received props for it.
89
- // Otherwise wait until then so we have the correct id for the node.
90
- this.ownerDocument.addNode(child);
91
- this.ownerDocument.endTransaction();
92
87
  this.ownerDocument.queueUpdate();
93
88
  }
94
89
  insertBefore(newNode, referenceNode) {
95
90
  if (referenceNode == null) return this.appendChild(newNode);
96
- this.ownerDocument.startTransaction();
97
91
  if (newNode.parentNode) newNode.parentNode.removeChild(newNode);
98
92
  newNode.nextSibling = referenceNode;
99
93
  newNode.previousSibling = referenceNode.previousSibling;
@@ -103,13 +97,10 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
103
97
  referenceNode.previousSibling = newNode;
104
98
  newNode.parentNode = referenceNode.parentNode;
105
99
  this.invalidateChildIndices(referenceNode);
106
- if (newNode.hasSetProps) this.ownerDocument.addNode(newNode);
107
- this.ownerDocument.endTransaction();
108
100
  this.ownerDocument.queueUpdate();
109
101
  }
110
102
  removeChild(child) {
111
103
  if (child.parentNode !== this || !this.ownerDocument.isMounted) return;
112
- this.ownerDocument.startTransaction();
113
104
  if (child.nextSibling) {
114
105
  this.invalidateChildIndices(child.nextSibling);
115
106
  child.nextSibling.previousSibling = child.previousSibling;
@@ -121,12 +112,31 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
121
112
  child.nextSibling = null;
122
113
  child.previousSibling = null;
123
114
  child.index = 0;
124
- this.ownerDocument.removeNode(child);
125
- this.ownerDocument.endTransaction();
115
+ this.ownerDocument.markDirty(child);
126
116
  this.ownerDocument.queueUpdate();
127
117
  }
128
118
  addEventListener() {}
129
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
+ }
130
140
  constructor(ownerDocument){
131
141
  this._firstChild = null;
132
142
  this._lastChild = null;
@@ -149,57 +159,88 @@ class $681cc3c98f569e39$export$dc064fe9e59310fd extends $681cc3c98f569e39$export
149
159
  if (this.parentNode instanceof $681cc3c98f569e39$export$dc064fe9e59310fd) return this.parentNode.level + (this.node.type === 'item' ? 1 : 0);
150
160
  return 0;
151
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
+ }
152
173
  updateNode() {
153
- var _this_previousSibling, _this_nextSibling, _this_firstChild, _this_lastChild;
154
- let node = this.ownerDocument.getMutableNode(this);
174
+ var _this_previousVisibleSibling, _this_firstVisibleChild, _this_lastVisibleChild;
175
+ let nextSibling = this.nextVisibleSibling;
176
+ let node = this.getMutableNode();
155
177
  node.index = this.index;
156
178
  node.level = this.level;
157
179
  node.parentKey = this.parentNode instanceof $681cc3c98f569e39$export$dc064fe9e59310fd ? this.parentNode.node.key : null;
158
- var _this_previousSibling_node_key;
159
- node.prevKey = (_this_previousSibling_node_key = (_this_previousSibling = this.previousSibling) === null || _this_previousSibling === void 0 ? void 0 : _this_previousSibling.node.key) !== null && _this_previousSibling_node_key !== void 0 ? _this_previousSibling_node_key : null;
160
- var _this_nextSibling_node_key;
161
- node.nextKey = (_this_nextSibling_node_key = (_this_nextSibling = this.nextSibling) === null || _this_nextSibling === void 0 ? void 0 : _this_nextSibling.node.key) !== null && _this_nextSibling_node_key !== void 0 ? _this_nextSibling_node_key : null;
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;
162
184
  node.hasChildNodes = !!this.firstChild;
163
- var _this_firstChild_node_key;
164
- node.firstChildKey = (_this_firstChild_node_key = (_this_firstChild = this.firstChild) === null || _this_firstChild === void 0 ? void 0 : _this_firstChild.node.key) !== null && _this_firstChild_node_key !== void 0 ? _this_firstChild_node_key : null;
165
- var _this_lastChild_node_key;
166
- node.lastChildKey = (_this_lastChild_node_key = (_this_lastChild = this.lastChild) === null || _this_lastChild === void 0 ? void 0 : _this_lastChild.node.key) !== null && _this_lastChild_node_key !== void 0 ? _this_lastChild_node_key : null;
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;
167
189
  // Update the colIndex of sibling nodes if this node has a colSpan.
168
- if ((node.colSpan != null || node.colIndex != null) && this.nextSibling) {
190
+ if ((node.colSpan != null || node.colIndex != null) && nextSibling) {
169
191
  var _node_colIndex, _node_colSpan;
170
192
  // This queues the next sibling for update, which means this happens recursively.
171
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);
172
- if (nextColIndex !== this.nextSibling.node.colIndex) {
173
- let siblingNode = this.ownerDocument.getMutableNode(this.nextSibling);
194
+ if (nextColIndex !== nextSibling.node.colIndex) {
195
+ let siblingNode = nextSibling.getMutableNode();
174
196
  siblingNode.colIndex = nextColIndex;
175
197
  }
176
198
  }
177
199
  }
178
200
  setProps(obj, ref, rendered, render) {
179
- let node = this.ownerDocument.getMutableNode(this);
180
- let { value: value, textValue: textValue, id: id, ...props } = obj;
201
+ let node = this.getMutableNode();
202
+ let { value: value1, textValue: textValue, id: id, ...props } = obj;
181
203
  props.ref = ref;
182
204
  node.props = props;
183
205
  node.rendered = rendered;
184
206
  node.render = render;
185
- node.value = value;
207
+ node.value = value1;
186
208
  node.textValue = textValue || (typeof props.children === 'string' ? props.children : '') || obj['aria-label'] || '';
187
209
  if (id != null && id !== node.key) {
188
210
  if (this.hasSetProps) throw new Error('Cannot change the id of an item');
189
211
  node.key = id;
190
212
  }
191
213
  if (props.colSpan != null) node.colSpan = props.colSpan;
192
- // If this is the first time props have been set, end the transaction started in the constructor
193
- // so this node can be emitted.
194
- if (!this.hasSetProps) {
195
- this.ownerDocument.addNode(this);
196
- this.ownerDocument.endTransaction();
197
- this.hasSetProps = true;
198
- }
214
+ this.hasSetProps = true;
199
215
  this.ownerDocument.queueUpdate();
200
216
  }
201
217
  get style() {
202
- return {};
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
+ };
203
244
  }
204
245
  hasAttribute() {}
205
246
  setAttribute() {}
@@ -207,12 +248,8 @@ class $681cc3c98f569e39$export$dc064fe9e59310fd extends $681cc3c98f569e39$export
207
248
  removeAttribute() {}
208
249
  constructor(type, ownerDocument){
209
250
  super(ownerDocument), this.nodeType = 8 // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions)
210
- , this._index = 0, this.hasSetProps = false;
251
+ , this.isMutated = true, this._index = 0, this.hasSetProps = false, this.isHidden = false;
211
252
  this.node = new (0, $23b9f4fcf0fe224b$export$d68d59712b04d9d1)(type, `react-aria-${++ownerDocument.nodeId}`);
212
- // Start a transaction so that no updates are emitted from the collection
213
- // until the props for this node are set. We don't know the real id for the
214
- // node until then, so we need to avoid emitting collections in an inconsistent state.
215
- this.ownerDocument.startTransaction();
216
253
  }
217
254
  }
218
255
  class $681cc3c98f569e39$export$b34a105447964f9f extends $681cc3c98f569e39$export$410b0c854570d131 {
@@ -222,77 +259,60 @@ class $681cc3c98f569e39$export$b34a105447964f9f extends $681cc3c98f569e39$export
222
259
  createElement(type) {
223
260
  return new $681cc3c98f569e39$export$dc064fe9e59310fd(type, this);
224
261
  }
225
- /**
226
- * Lazily gets a mutable instance of a Node. If the node has already
227
- * been cloned during this update cycle, it just returns the existing one.
228
- */ getMutableNode(element) {
229
- let node = element.node;
230
- if (!this.mutatedNodes.has(element)) {
231
- node = element.node.clone();
232
- this.mutatedNodes.add(element);
233
- element.node = node;
234
- }
235
- this.markDirty(element);
236
- return node;
237
- }
238
262
  getMutableCollection() {
239
- if (!this.isSSR && !this.collectionMutated) {
240
- this.collection = this.collection.clone();
241
- this.collectionMutated = true;
242
- }
243
- return this.collection;
263
+ if (!this.nextCollection) this.nextCollection = this.collection.clone();
264
+ return this.nextCollection;
244
265
  }
245
266
  markDirty(node) {
246
267
  this.dirtyNodes.add(node);
247
268
  }
248
- startTransaction() {
249
- this.transactionCount++;
250
- }
251
- endTransaction() {
252
- this.transactionCount--;
253
- }
254
269
  addNode(element) {
270
+ if (element.isHidden) return;
255
271
  let collection = this.getMutableCollection();
256
- if (!collection.getItem(element.node.key)) {
257
- collection.addNode(element.node);
258
- for (let child of element)this.addNode(child);
259
- }
260
- this.markDirty(element);
272
+ if (!collection.getItem(element.node.key)) for (let child of element)this.addNode(child);
273
+ collection.addNode(element.node);
261
274
  }
262
275
  removeNode(node) {
263
276
  for (let child of node)this.removeNode(child);
264
277
  let collection = this.getMutableCollection();
265
278
  collection.removeNode(node.node.key);
266
- this.markDirty(node);
267
279
  }
268
280
  /** Finalizes the collection update, updating all nodes and freezing the collection. */ getCollection() {
269
- if (this.transactionCount > 0) return this.collection;
270
- this.updateCollection();
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();
271
286
  // Reset queuedRender to false when getCollection is called during render.
272
- if (!this.inSubscription) this.queuedRender = false;
287
+ this.queuedRender = false;
288
+ this.updateCollection();
273
289
  return this.collection;
274
290
  }
275
291
  updateCollection() {
276
292
  // First, update the indices of dirty element children.
277
293
  for (let element of this.dirtyNodes)element.updateChildIndices();
278
294
  // Next, update dirty collection nodes.
279
- for (let element of this.dirtyNodes)if (element instanceof $681cc3c98f569e39$export$dc064fe9e59310fd && element.isConnected) element.updateNode();
295
+ for (let element of this.dirtyNodes)if (element instanceof $681cc3c98f569e39$export$dc064fe9e59310fd) {
296
+ if (element.isConnected && !element.isHidden) {
297
+ element.updateNode();
298
+ this.addNode(element);
299
+ } else this.removeNode(element);
300
+ element.isMutated = false;
301
+ }
280
302
  this.dirtyNodes.clear();
281
303
  // Finally, update the collection.
282
- if (this.mutatedNodes.size || this.collectionMutated) {
283
- var _this_firstChild, _this_lastChild;
284
- let collection = this.getMutableCollection();
285
- for (let element of this.mutatedNodes)if (element.isConnected) collection.addNode(element.node);
286
- this.mutatedNodes.clear();
287
- var _this_firstChild_node_key, _this_lastChild_node_key;
288
- 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);
304
+ if (this.nextCollection) {
305
+ var _this_firstVisibleChild, _this_lastVisibleChild;
306
+ var _this_firstVisibleChild_node_key, _this_lastVisibleChild_node_key;
307
+ 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);
308
+ if (!this.isSSR) {
309
+ this.collection = this.nextCollection;
310
+ this.nextCollection = null;
311
+ }
289
312
  }
290
- this.collectionMutated = false;
291
313
  }
292
314
  queueUpdate() {
293
- // Don't emit any updates if there is a transaction in progress.
294
- // queueUpdate should be called again after the transaction.
295
- if (this.dirtyNodes.size === 0 || this.transactionCount > 0 || this.queuedRender) return;
315
+ if (this.dirtyNodes.size === 0 || this.queuedRender) return;
296
316
  // Only trigger subscriptions once during an update, when the first item changes.
297
317
  // React's useSyncExternalStore will call getCollection immediately, to check whether the snapshot changed.
298
318
  // If so, React will queue a render to happen after the current commit to our fake DOM finishes.
@@ -318,9 +338,9 @@ class $681cc3c98f569e39$export$b34a105447964f9f extends $681cc3c98f569e39$export
318
338
  constructor(collection){
319
339
  // @ts-ignore
320
340
  super(null), this.nodeType = 11 // DOCUMENT_FRAGMENT_NODE
321
- , this.ownerDocument = this, this.dirtyNodes = new Set(), this.isSSR = false, this.nodeId = 0, this.nodesByProps = new WeakMap(), this.isMounted = true, this.mutatedNodes = new Set(), this.subscriptions = new Set(), this.transactionCount = 0, this.queuedRender = false, this.inSubscription = false;
341
+ , 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;
322
342
  this.collection = collection;
323
- this.collectionMutated = true;
343
+ this.nextCollection = collection;
324
344
  }
325
345
  }
326
346
 
@@ -70,7 +70,6 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
70
70
  this._minInvalidChildIndex = null;
71
71
  }
72
72
  appendChild(child) {
73
- this.ownerDocument.startTransaction();
74
73
  if (child.parentNode) child.parentNode.removeChild(child);
75
74
  if (this.firstChild == null) this.firstChild = child;
76
75
  if (this.lastChild) {
@@ -85,15 +84,10 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
85
84
  child.nextSibling = null;
86
85
  this.lastChild = child;
87
86
  this.ownerDocument.markDirty(this);
88
- if (child.hasSetProps) // Only add the node to the collection if we already received props for it.
89
- // Otherwise wait until then so we have the correct id for the node.
90
- this.ownerDocument.addNode(child);
91
- this.ownerDocument.endTransaction();
92
87
  this.ownerDocument.queueUpdate();
93
88
  }
94
89
  insertBefore(newNode, referenceNode) {
95
90
  if (referenceNode == null) return this.appendChild(newNode);
96
- this.ownerDocument.startTransaction();
97
91
  if (newNode.parentNode) newNode.parentNode.removeChild(newNode);
98
92
  newNode.nextSibling = referenceNode;
99
93
  newNode.previousSibling = referenceNode.previousSibling;
@@ -103,13 +97,10 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
103
97
  referenceNode.previousSibling = newNode;
104
98
  newNode.parentNode = referenceNode.parentNode;
105
99
  this.invalidateChildIndices(referenceNode);
106
- if (newNode.hasSetProps) this.ownerDocument.addNode(newNode);
107
- this.ownerDocument.endTransaction();
108
100
  this.ownerDocument.queueUpdate();
109
101
  }
110
102
  removeChild(child) {
111
103
  if (child.parentNode !== this || !this.ownerDocument.isMounted) return;
112
- this.ownerDocument.startTransaction();
113
104
  if (child.nextSibling) {
114
105
  this.invalidateChildIndices(child.nextSibling);
115
106
  child.nextSibling.previousSibling = child.previousSibling;
@@ -121,12 +112,31 @@ class $681cc3c98f569e39$export$410b0c854570d131 {
121
112
  child.nextSibling = null;
122
113
  child.previousSibling = null;
123
114
  child.index = 0;
124
- this.ownerDocument.removeNode(child);
125
- this.ownerDocument.endTransaction();
115
+ this.ownerDocument.markDirty(child);
126
116
  this.ownerDocument.queueUpdate();
127
117
  }
128
118
  addEventListener() {}
129
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
+ }
130
140
  constructor(ownerDocument){
131
141
  this._firstChild = null;
132
142
  this._lastChild = null;
@@ -149,57 +159,88 @@ class $681cc3c98f569e39$export$dc064fe9e59310fd extends $681cc3c98f569e39$export
149
159
  if (this.parentNode instanceof $681cc3c98f569e39$export$dc064fe9e59310fd) return this.parentNode.level + (this.node.type === 'item' ? 1 : 0);
150
160
  return 0;
151
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
+ }
152
173
  updateNode() {
153
- var _this_previousSibling, _this_nextSibling, _this_firstChild, _this_lastChild;
154
- let node = this.ownerDocument.getMutableNode(this);
174
+ var _this_previousVisibleSibling, _this_firstVisibleChild, _this_lastVisibleChild;
175
+ let nextSibling = this.nextVisibleSibling;
176
+ let node = this.getMutableNode();
155
177
  node.index = this.index;
156
178
  node.level = this.level;
157
179
  node.parentKey = this.parentNode instanceof $681cc3c98f569e39$export$dc064fe9e59310fd ? this.parentNode.node.key : null;
158
- var _this_previousSibling_node_key;
159
- node.prevKey = (_this_previousSibling_node_key = (_this_previousSibling = this.previousSibling) === null || _this_previousSibling === void 0 ? void 0 : _this_previousSibling.node.key) !== null && _this_previousSibling_node_key !== void 0 ? _this_previousSibling_node_key : null;
160
- var _this_nextSibling_node_key;
161
- node.nextKey = (_this_nextSibling_node_key = (_this_nextSibling = this.nextSibling) === null || _this_nextSibling === void 0 ? void 0 : _this_nextSibling.node.key) !== null && _this_nextSibling_node_key !== void 0 ? _this_nextSibling_node_key : null;
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;
162
184
  node.hasChildNodes = !!this.firstChild;
163
- var _this_firstChild_node_key;
164
- node.firstChildKey = (_this_firstChild_node_key = (_this_firstChild = this.firstChild) === null || _this_firstChild === void 0 ? void 0 : _this_firstChild.node.key) !== null && _this_firstChild_node_key !== void 0 ? _this_firstChild_node_key : null;
165
- var _this_lastChild_node_key;
166
- node.lastChildKey = (_this_lastChild_node_key = (_this_lastChild = this.lastChild) === null || _this_lastChild === void 0 ? void 0 : _this_lastChild.node.key) !== null && _this_lastChild_node_key !== void 0 ? _this_lastChild_node_key : null;
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;
167
189
  // Update the colIndex of sibling nodes if this node has a colSpan.
168
- if ((node.colSpan != null || node.colIndex != null) && this.nextSibling) {
190
+ if ((node.colSpan != null || node.colIndex != null) && nextSibling) {
169
191
  var _node_colIndex, _node_colSpan;
170
192
  // This queues the next sibling for update, which means this happens recursively.
171
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);
172
- if (nextColIndex !== this.nextSibling.node.colIndex) {
173
- let siblingNode = this.ownerDocument.getMutableNode(this.nextSibling);
194
+ if (nextColIndex !== nextSibling.node.colIndex) {
195
+ let siblingNode = nextSibling.getMutableNode();
174
196
  siblingNode.colIndex = nextColIndex;
175
197
  }
176
198
  }
177
199
  }
178
200
  setProps(obj, ref, rendered, render) {
179
- let node = this.ownerDocument.getMutableNode(this);
180
- let { value: value, textValue: textValue, id: id, ...props } = obj;
201
+ let node = this.getMutableNode();
202
+ let { value: value1, textValue: textValue, id: id, ...props } = obj;
181
203
  props.ref = ref;
182
204
  node.props = props;
183
205
  node.rendered = rendered;
184
206
  node.render = render;
185
- node.value = value;
207
+ node.value = value1;
186
208
  node.textValue = textValue || (typeof props.children === 'string' ? props.children : '') || obj['aria-label'] || '';
187
209
  if (id != null && id !== node.key) {
188
210
  if (this.hasSetProps) throw new Error('Cannot change the id of an item');
189
211
  node.key = id;
190
212
  }
191
213
  if (props.colSpan != null) node.colSpan = props.colSpan;
192
- // If this is the first time props have been set, end the transaction started in the constructor
193
- // so this node can be emitted.
194
- if (!this.hasSetProps) {
195
- this.ownerDocument.addNode(this);
196
- this.ownerDocument.endTransaction();
197
- this.hasSetProps = true;
198
- }
214
+ this.hasSetProps = true;
199
215
  this.ownerDocument.queueUpdate();
200
216
  }
201
217
  get style() {
202
- return {};
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
+ };
203
244
  }
204
245
  hasAttribute() {}
205
246
  setAttribute() {}
@@ -207,12 +248,8 @@ class $681cc3c98f569e39$export$dc064fe9e59310fd extends $681cc3c98f569e39$export
207
248
  removeAttribute() {}
208
249
  constructor(type, ownerDocument){
209
250
  super(ownerDocument), this.nodeType = 8 // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions)
210
- , this._index = 0, this.hasSetProps = false;
251
+ , this.isMutated = true, this._index = 0, this.hasSetProps = false, this.isHidden = false;
211
252
  this.node = new (0, $23b9f4fcf0fe224b$export$d68d59712b04d9d1)(type, `react-aria-${++ownerDocument.nodeId}`);
212
- // Start a transaction so that no updates are emitted from the collection
213
- // until the props for this node are set. We don't know the real id for the
214
- // node until then, so we need to avoid emitting collections in an inconsistent state.
215
- this.ownerDocument.startTransaction();
216
253
  }
217
254
  }
218
255
  class $681cc3c98f569e39$export$b34a105447964f9f extends $681cc3c98f569e39$export$410b0c854570d131 {
@@ -222,77 +259,60 @@ class $681cc3c98f569e39$export$b34a105447964f9f extends $681cc3c98f569e39$export
222
259
  createElement(type) {
223
260
  return new $681cc3c98f569e39$export$dc064fe9e59310fd(type, this);
224
261
  }
225
- /**
226
- * Lazily gets a mutable instance of a Node. If the node has already
227
- * been cloned during this update cycle, it just returns the existing one.
228
- */ getMutableNode(element) {
229
- let node = element.node;
230
- if (!this.mutatedNodes.has(element)) {
231
- node = element.node.clone();
232
- this.mutatedNodes.add(element);
233
- element.node = node;
234
- }
235
- this.markDirty(element);
236
- return node;
237
- }
238
262
  getMutableCollection() {
239
- if (!this.isSSR && !this.collectionMutated) {
240
- this.collection = this.collection.clone();
241
- this.collectionMutated = true;
242
- }
243
- return this.collection;
263
+ if (!this.nextCollection) this.nextCollection = this.collection.clone();
264
+ return this.nextCollection;
244
265
  }
245
266
  markDirty(node) {
246
267
  this.dirtyNodes.add(node);
247
268
  }
248
- startTransaction() {
249
- this.transactionCount++;
250
- }
251
- endTransaction() {
252
- this.transactionCount--;
253
- }
254
269
  addNode(element) {
270
+ if (element.isHidden) return;
255
271
  let collection = this.getMutableCollection();
256
- if (!collection.getItem(element.node.key)) {
257
- collection.addNode(element.node);
258
- for (let child of element)this.addNode(child);
259
- }
260
- this.markDirty(element);
272
+ if (!collection.getItem(element.node.key)) for (let child of element)this.addNode(child);
273
+ collection.addNode(element.node);
261
274
  }
262
275
  removeNode(node) {
263
276
  for (let child of node)this.removeNode(child);
264
277
  let collection = this.getMutableCollection();
265
278
  collection.removeNode(node.node.key);
266
- this.markDirty(node);
267
279
  }
268
280
  /** Finalizes the collection update, updating all nodes and freezing the collection. */ getCollection() {
269
- if (this.transactionCount > 0) return this.collection;
270
- this.updateCollection();
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();
271
286
  // Reset queuedRender to false when getCollection is called during render.
272
- if (!this.inSubscription) this.queuedRender = false;
287
+ this.queuedRender = false;
288
+ this.updateCollection();
273
289
  return this.collection;
274
290
  }
275
291
  updateCollection() {
276
292
  // First, update the indices of dirty element children.
277
293
  for (let element of this.dirtyNodes)element.updateChildIndices();
278
294
  // Next, update dirty collection nodes.
279
- for (let element of this.dirtyNodes)if (element instanceof $681cc3c98f569e39$export$dc064fe9e59310fd && element.isConnected) element.updateNode();
295
+ for (let element of this.dirtyNodes)if (element instanceof $681cc3c98f569e39$export$dc064fe9e59310fd) {
296
+ if (element.isConnected && !element.isHidden) {
297
+ element.updateNode();
298
+ this.addNode(element);
299
+ } else this.removeNode(element);
300
+ element.isMutated = false;
301
+ }
280
302
  this.dirtyNodes.clear();
281
303
  // Finally, update the collection.
282
- if (this.mutatedNodes.size || this.collectionMutated) {
283
- var _this_firstChild, _this_lastChild;
284
- let collection = this.getMutableCollection();
285
- for (let element of this.mutatedNodes)if (element.isConnected) collection.addNode(element.node);
286
- this.mutatedNodes.clear();
287
- var _this_firstChild_node_key, _this_lastChild_node_key;
288
- 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);
304
+ if (this.nextCollection) {
305
+ var _this_firstVisibleChild, _this_lastVisibleChild;
306
+ var _this_firstVisibleChild_node_key, _this_lastVisibleChild_node_key;
307
+ 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);
308
+ if (!this.isSSR) {
309
+ this.collection = this.nextCollection;
310
+ this.nextCollection = null;
311
+ }
289
312
  }
290
- this.collectionMutated = false;
291
313
  }
292
314
  queueUpdate() {
293
- // Don't emit any updates if there is a transaction in progress.
294
- // queueUpdate should be called again after the transaction.
295
- if (this.dirtyNodes.size === 0 || this.transactionCount > 0 || this.queuedRender) return;
315
+ if (this.dirtyNodes.size === 0 || this.queuedRender) return;
296
316
  // Only trigger subscriptions once during an update, when the first item changes.
297
317
  // React's useSyncExternalStore will call getCollection immediately, to check whether the snapshot changed.
298
318
  // If so, React will queue a render to happen after the current commit to our fake DOM finishes.
@@ -318,9 +338,9 @@ class $681cc3c98f569e39$export$b34a105447964f9f extends $681cc3c98f569e39$export
318
338
  constructor(collection){
319
339
  // @ts-ignore
320
340
  super(null), this.nodeType = 11 // DOCUMENT_FRAGMENT_NODE
321
- , this.ownerDocument = this, this.dirtyNodes = new Set(), this.isSSR = false, this.nodeId = 0, this.nodesByProps = new WeakMap(), this.isMounted = true, this.mutatedNodes = new Set(), this.subscriptions = new Set(), this.transactionCount = 0, this.queuedRender = false, this.inSubscription = false;
341
+ , 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;
322
342
  this.collection = collection;
323
- this.collectionMutated = true;
343
+ this.nextCollection = collection;
324
344
  }
325
345
  }
326
346