@react-aria/collections 3.0.0-nightly.5042 → 3.0.0-rc.1

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.
@@ -64,8 +64,21 @@ class $c20afee375f3b2d6$export$410b0c854570d131 {
64
64
  var _this_parentNode;
65
65
  return ((_this_parentNode = this.parentNode) === null || _this_parentNode === void 0 ? void 0 : _this_parentNode.isConnected) || false;
66
66
  }
67
+ invalidateChildIndices(child) {
68
+ if (this._minInvalidChildIndex == null || !this._minInvalidChildIndex.isConnected || child.index < this._minInvalidChildIndex.index) {
69
+ this._minInvalidChildIndex = child;
70
+ this.ownerDocument.markDirty(this);
71
+ }
72
+ }
73
+ updateChildIndices() {
74
+ let node = this._minInvalidChildIndex;
75
+ while(node){
76
+ node.index = node.previousSibling ? node.previousSibling.index + 1 : 0;
77
+ node = node.nextSibling;
78
+ }
79
+ this._minInvalidChildIndex = null;
80
+ }
67
81
  appendChild(child) {
68
- this.ownerDocument.startTransaction();
69
82
  if (child.parentNode) child.parentNode.removeChild(child);
70
83
  if (this.firstChild == null) this.firstChild = child;
71
84
  if (this.lastChild) {
@@ -80,41 +93,32 @@ class $c20afee375f3b2d6$export$410b0c854570d131 {
80
93
  child.nextSibling = null;
81
94
  this.lastChild = child;
82
95
  this.ownerDocument.markDirty(this);
83
- if (child.hasSetProps) // Only add the node to the collection if we already received props for it.
84
- // Otherwise wait until then so we have the correct id for the node.
85
- this.ownerDocument.addNode(child);
86
- this.ownerDocument.endTransaction();
87
- this.ownerDocument.queueUpdate();
96
+ if (this.isConnected) this.ownerDocument.queueUpdate();
88
97
  }
89
98
  insertBefore(newNode, referenceNode) {
90
99
  if (referenceNode == null) return this.appendChild(newNode);
91
- this.ownerDocument.startTransaction();
92
100
  if (newNode.parentNode) newNode.parentNode.removeChild(newNode);
93
101
  newNode.nextSibling = referenceNode;
94
102
  newNode.previousSibling = referenceNode.previousSibling;
95
- newNode.index = referenceNode.index;
103
+ // Ensure that the newNode's index is less than that of the reference node so that
104
+ // invalidateChildIndices will properly use the newNode as the _minInvalidChildIndex, thus making sure
105
+ // we will properly update the indexes of all sibiling nodes after the newNode. The value here doesn't matter
106
+ // since updateChildIndices should calculate the proper indexes.
107
+ newNode.index = referenceNode.index - 1;
96
108
  if (this.firstChild === referenceNode) this.firstChild = newNode;
97
109
  else if (referenceNode.previousSibling) referenceNode.previousSibling.nextSibling = newNode;
98
110
  referenceNode.previousSibling = newNode;
99
111
  newNode.parentNode = referenceNode.parentNode;
100
- let node = referenceNode;
101
- while(node){
102
- node.index++;
103
- node = node.nextSibling;
104
- }
105
- if (newNode.hasSetProps) this.ownerDocument.addNode(newNode);
106
- this.ownerDocument.endTransaction();
107
- this.ownerDocument.queueUpdate();
112
+ this.invalidateChildIndices(newNode);
113
+ if (this.isConnected) this.ownerDocument.queueUpdate();
108
114
  }
109
115
  removeChild(child) {
110
116
  if (child.parentNode !== this || !this.ownerDocument.isMounted) return;
111
- this.ownerDocument.startTransaction();
112
- let node = child.nextSibling;
113
- while(node){
114
- node.index--;
115
- node = node.nextSibling;
117
+ if (this._minInvalidChildIndex === child) this._minInvalidChildIndex = null;
118
+ if (child.nextSibling) {
119
+ this.invalidateChildIndices(child.nextSibling);
120
+ child.nextSibling.previousSibling = child.previousSibling;
116
121
  }
117
- if (child.nextSibling) child.nextSibling.previousSibling = child.previousSibling;
118
122
  if (child.previousSibling) child.previousSibling.nextSibling = child.nextSibling;
119
123
  if (this.firstChild === child) this.firstChild = child.nextSibling;
120
124
  if (this.lastChild === child) this.lastChild = child.previousSibling;
@@ -122,18 +126,38 @@ class $c20afee375f3b2d6$export$410b0c854570d131 {
122
126
  child.nextSibling = null;
123
127
  child.previousSibling = null;
124
128
  child.index = 0;
125
- this.ownerDocument.removeNode(child);
126
- this.ownerDocument.endTransaction();
127
- this.ownerDocument.queueUpdate();
129
+ this.ownerDocument.markDirty(child);
130
+ if (this.isConnected) this.ownerDocument.queueUpdate();
128
131
  }
129
132
  addEventListener() {}
130
133
  removeEventListener() {}
134
+ get previousVisibleSibling() {
135
+ let node = this.previousSibling;
136
+ while(node && node.isHidden)node = node.previousSibling;
137
+ return node;
138
+ }
139
+ get nextVisibleSibling() {
140
+ let node = this.nextSibling;
141
+ while(node && node.isHidden)node = node.nextSibling;
142
+ return node;
143
+ }
144
+ get firstVisibleChild() {
145
+ let node = this.firstChild;
146
+ while(node && node.isHidden)node = node.nextSibling;
147
+ return node;
148
+ }
149
+ get lastVisibleChild() {
150
+ let node = this.lastChild;
151
+ while(node && node.isHidden)node = node.previousSibling;
152
+ return node;
153
+ }
131
154
  constructor(ownerDocument){
132
155
  this._firstChild = null;
133
156
  this._lastChild = null;
134
157
  this._previousSibling = null;
135
158
  this._nextSibling = null;
136
159
  this._parentNode = null;
160
+ this._minInvalidChildIndex = null;
137
161
  this.ownerDocument = ownerDocument;
138
162
  }
139
163
  }
@@ -149,62 +173,97 @@ class $c20afee375f3b2d6$export$dc064fe9e59310fd extends $c20afee375f3b2d6$export
149
173
  if (this.parentNode instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd) return this.parentNode.level + (this.node.type === 'item' ? 1 : 0);
150
174
  return 0;
151
175
  }
176
+ /**
177
+ * Lazily gets a mutable instance of a Node. If the node has already
178
+ * been cloned during this update cycle, it just returns the existing one.
179
+ */ getMutableNode() {
180
+ if (!this.isMutated) {
181
+ this.node = this.node.clone();
182
+ this.isMutated = true;
183
+ }
184
+ this.ownerDocument.markDirty(this);
185
+ return this.node;
186
+ }
152
187
  updateNode() {
153
- var _this_previousSibling, _this_nextSibling, _this_firstChild, _this_lastChild;
154
- let node = this.ownerDocument.getMutableNode(this);
188
+ var _this_previousVisibleSibling, _this_firstVisibleChild, _this_lastVisibleChild;
189
+ let nextSibling = this.nextVisibleSibling;
190
+ let node = this.getMutableNode();
155
191
  node.index = this.index;
156
192
  node.level = this.level;
157
193
  node.parentKey = this.parentNode instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd ? this.parentNode.node.key : null;
158
- var _this_previousSibling_node_key;
159
- node.prevKey = (_this_previousSibling_node_key = (_this_previousSibling = this.previousSibling) === null || _this_previousSibling === void 0 ? void 0 : _this_previousSibling.node.key) !== null && _this_previousSibling_node_key !== void 0 ? _this_previousSibling_node_key : null;
160
- var _this_nextSibling_node_key;
161
- node.nextKey = (_this_nextSibling_node_key = (_this_nextSibling = this.nextSibling) === null || _this_nextSibling === void 0 ? void 0 : _this_nextSibling.node.key) !== null && _this_nextSibling_node_key !== void 0 ? _this_nextSibling_node_key : null;
194
+ var _this_previousVisibleSibling_node_key;
195
+ 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;
196
+ var _nextSibling_node_key;
197
+ 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
198
  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;
199
+ var _this_firstVisibleChild_node_key;
200
+ 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;
201
+ var _this_lastVisibleChild_node_key;
202
+ 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;
203
+ // Update the colIndex of sibling nodes if this node has a colSpan.
204
+ if ((node.colSpan != null || node.colIndex != null) && nextSibling) {
205
+ var _node_colIndex, _node_colSpan;
206
+ // This queues the next sibling for update, which means this happens recursively.
207
+ 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);
208
+ if (nextColIndex !== nextSibling.node.colIndex) {
209
+ let siblingNode = nextSibling.getMutableNode();
210
+ siblingNode.colIndex = nextColIndex;
211
+ }
212
+ }
167
213
  }
168
214
  setProps(obj, ref, rendered, render) {
169
- let node = this.ownerDocument.getMutableNode(this);
170
- let { value: value, textValue: textValue, id: id, ...props } = obj;
215
+ let node = this.getMutableNode();
216
+ let { value: value1, textValue: textValue, id: id, ...props } = obj;
171
217
  props.ref = ref;
172
218
  node.props = props;
173
219
  node.rendered = rendered;
174
220
  node.render = render;
175
- node.value = value;
221
+ node.value = value1;
176
222
  node.textValue = textValue || (typeof props.children === 'string' ? props.children : '') || obj['aria-label'] || '';
177
223
  if (id != null && id !== node.key) {
178
224
  if (this.hasSetProps) throw new Error('Cannot change the id of an item');
179
225
  node.key = id;
180
226
  }
181
- // If this is the first time props have been set, end the transaction started in the constructor
182
- // so this node can be emitted.
183
- if (!this.hasSetProps) {
184
- this.ownerDocument.addNode(this);
185
- this.ownerDocument.endTransaction();
186
- this.hasSetProps = true;
187
- }
188
- this.ownerDocument.queueUpdate();
227
+ if (props.colSpan != null) node.colSpan = props.colSpan;
228
+ this.hasSetProps = true;
229
+ if (this.isConnected) this.ownerDocument.queueUpdate();
189
230
  }
190
231
  get style() {
191
- return {};
232
+ // React sets display: none to hide elements during Suspense.
233
+ // We'll handle this by setting the element to hidden and invalidating
234
+ // its siblings/parent. Hidden elements remain in the Document, but
235
+ // are removed from the Collection.
236
+ let element = this;
237
+ return {
238
+ get display () {
239
+ return element.isHidden ? 'none' : '';
240
+ },
241
+ set display (value){
242
+ let isHidden = value === 'none';
243
+ if (element.isHidden !== isHidden) {
244
+ var _element_parentNode, _element_parentNode1;
245
+ // Mark parent node dirty if this element is currently the first or last visible child.
246
+ 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);
247
+ // Mark sibling visible elements dirty.
248
+ let prev = element.previousVisibleSibling;
249
+ let next = element.nextVisibleSibling;
250
+ if (prev) element.ownerDocument.markDirty(prev);
251
+ if (next) element.ownerDocument.markDirty(next);
252
+ // Mark self dirty.
253
+ element.isHidden = isHidden;
254
+ element.ownerDocument.markDirty(element);
255
+ }
256
+ }
257
+ };
192
258
  }
193
259
  hasAttribute() {}
194
260
  setAttribute() {}
195
261
  setAttributeNS() {}
196
262
  removeAttribute() {}
197
263
  constructor(type, ownerDocument){
198
- super(ownerDocument);
199
- this.nodeType = 8 // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions)
200
- ;
201
- this._index = 0;
202
- this.hasSetProps = false;
264
+ super(ownerDocument), this.nodeType = 8 // COMMENT_NODE (we'd use ELEMENT_NODE but React DevTools will fail to get its dimensions)
265
+ , this.isMutated = true, this._index = 0, this.hasSetProps = false, this.isHidden = false;
203
266
  this.node = new (0, $499e2959ba1abacc$exports.CollectionNode)(type, `react-aria-${++ownerDocument.nodeId}`);
204
- // Start a transaction so that no updates are emitted from the collection
205
- // until the props for this node are set. We don't know the real id for the
206
- // node until then, so we need to avoid emitting collections in an inconsistent state.
207
- this.ownerDocument.startTransaction();
208
267
  }
209
268
  }
210
269
  class $c20afee375f3b2d6$export$b34a105447964f9f extends $c20afee375f3b2d6$export$410b0c854570d131 {
@@ -214,72 +273,70 @@ class $c20afee375f3b2d6$export$b34a105447964f9f extends $c20afee375f3b2d6$export
214
273
  createElement(type) {
215
274
  return new $c20afee375f3b2d6$export$dc064fe9e59310fd(type, this);
216
275
  }
217
- /**
218
- * Lazily gets a mutable instance of a Node. If the node has already
219
- * been cloned during this update cycle, it just returns the existing one.
220
- */ getMutableNode(element) {
221
- let node = element.node;
222
- if (!this.mutatedNodes.has(element)) {
223
- node = element.node.clone();
224
- this.mutatedNodes.add(element);
225
- element.node = node;
226
- }
227
- this.markDirty(element);
228
- return node;
229
- }
230
276
  getMutableCollection() {
231
- if (!this.isSSR && !this.collectionMutated) {
232
- this.collection = this.collection.clone();
233
- this.collectionMutated = true;
234
- }
235
- return this.collection;
277
+ if (!this.nextCollection) this.nextCollection = this.collection.clone();
278
+ return this.nextCollection;
236
279
  }
237
280
  markDirty(node) {
238
281
  this.dirtyNodes.add(node);
239
282
  }
240
- startTransaction() {
241
- this.transactionCount++;
242
- }
243
- endTransaction() {
244
- this.transactionCount--;
245
- }
246
283
  addNode(element) {
284
+ if (element.isHidden) return;
247
285
  let collection = this.getMutableCollection();
248
- if (!collection.getItem(element.node.key)) {
249
- collection.addNode(element.node);
250
- for (let child of element)this.addNode(child);
251
- }
252
- this.markDirty(element);
286
+ if (!collection.getItem(element.node.key)) for (let child of element)this.addNode(child);
287
+ collection.addNode(element.node);
253
288
  }
254
289
  removeNode(node) {
255
290
  for (let child of node)this.removeNode(child);
256
291
  let collection = this.getMutableCollection();
257
292
  collection.removeNode(node.node.key);
258
- this.markDirty(node);
259
293
  }
260
294
  /** Finalizes the collection update, updating all nodes and freezing the collection. */ getCollection() {
261
- if (this.transactionCount > 0) return this.collection;
295
+ // If in a subscription update, return a clone of the existing collection.
296
+ // This ensures React will queue a render. React will call getCollection again
297
+ // during render, at which point all the updates will be complete and we can return
298
+ // the new collection.
299
+ if (this.inSubscription) return this.collection.clone();
300
+ // Reset queuedRender to false when getCollection is called during render.
301
+ this.queuedRender = false;
262
302
  this.updateCollection();
263
303
  return this.collection;
264
304
  }
265
305
  updateCollection() {
266
- for (let element of this.dirtyNodes)if (element instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd && element.isConnected) element.updateNode();
306
+ // First, remove disconnected nodes and update the indices of dirty element children.
307
+ for (let element of this.dirtyNodes)if (element instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd && (!element.isConnected || element.isHidden)) this.removeNode(element);
308
+ else element.updateChildIndices();
309
+ // Next, update dirty collection nodes.
310
+ for (let element of this.dirtyNodes)if (element instanceof $c20afee375f3b2d6$export$dc064fe9e59310fd) {
311
+ if (element.isConnected && !element.isHidden) {
312
+ element.updateNode();
313
+ this.addNode(element);
314
+ }
315
+ element.isMutated = false;
316
+ }
267
317
  this.dirtyNodes.clear();
268
- if (this.mutatedNodes.size || this.collectionMutated) {
269
- var _this_firstChild, _this_lastChild;
270
- let collection = this.getMutableCollection();
271
- for (let element of this.mutatedNodes)if (element.isConnected) collection.addNode(element.node);
272
- var _this_firstChild_node_key, _this_lastChild_node_key;
273
- collection.commit((_this_firstChild_node_key = (_this_firstChild = this.firstChild) === null || _this_firstChild === void 0 ? void 0 : _this_firstChild.node.key) !== null && _this_firstChild_node_key !== void 0 ? _this_firstChild_node_key : null, (_this_lastChild_node_key = (_this_lastChild = this.lastChild) === null || _this_lastChild === void 0 ? void 0 : _this_lastChild.node.key) !== null && _this_lastChild_node_key !== void 0 ? _this_lastChild_node_key : null, this.isSSR);
274
- this.mutatedNodes.clear();
318
+ // Finally, update the collection.
319
+ if (this.nextCollection) {
320
+ var _this_firstVisibleChild, _this_lastVisibleChild;
321
+ var _this_firstVisibleChild_node_key, _this_lastVisibleChild_node_key;
322
+ 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);
323
+ if (!this.isSSR) {
324
+ this.collection = this.nextCollection;
325
+ this.nextCollection = null;
326
+ }
275
327
  }
276
- this.collectionMutated = false;
277
328
  }
278
329
  queueUpdate() {
279
- // Don't emit any updates if there is a transaction in progress.
280
- // queueUpdate should be called again after the transaction.
281
- if (this.dirtyNodes.size === 0 || this.transactionCount > 0) return;
330
+ if (this.dirtyNodes.size === 0 || this.queuedRender) return;
331
+ // Only trigger subscriptions once during an update, when the first item changes.
332
+ // React's useSyncExternalStore will call getCollection immediately, to check whether the snapshot changed.
333
+ // If so, React will queue a render to happen after the current commit to our fake DOM finishes.
334
+ // We track whether getCollection is called in a subscription, and once it is called during render,
335
+ // we reset queuedRender back to false.
336
+ this.queuedRender = true;
337
+ this.inSubscription = true;
282
338
  for (let fn of this.subscriptions)fn();
339
+ this.inSubscription = false;
283
340
  }
284
341
  subscribe(fn) {
285
342
  this.subscriptions.add(fn);
@@ -295,20 +352,10 @@ class $c20afee375f3b2d6$export$b34a105447964f9f extends $c20afee375f3b2d6$export
295
352
  }
296
353
  constructor(collection){
297
354
  // @ts-ignore
298
- super(null);
299
- this.nodeType = 11 // DOCUMENT_FRAGMENT_NODE
300
- ;
301
- this.ownerDocument = this;
302
- this.dirtyNodes = new Set();
303
- this.isSSR = false;
304
- this.nodeId = 0;
305
- this.nodesByProps = new WeakMap();
306
- this.isMounted = true;
307
- this.mutatedNodes = new Set();
308
- this.subscriptions = new Set();
309
- this.transactionCount = 0;
355
+ super(null), this.nodeType = 11 // DOCUMENT_FRAGMENT_NODE
356
+ , 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;
310
357
  this.collection = collection;
311
- this.collectionMutated = true;
358
+ this.nextCollection = collection;
312
359
  }
313
360
  }
314
361
 
@@ -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,IAAI,CAAC,WAAW;IACzB;IAEA,IAAI,WAAW,UAAU,EAAE;QACzB,IAAI,CAAC,WAAW,GAAG;QACnB,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI;IACnC;IAEA,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,UAAU;IACxB;IAEA,IAAI,UAAU,SAAS,EAAE;QACvB,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI;IACnC;IAEA,IAAI,kBAAkB;QACpB,OAAO,IAAI,CAAC,gBAAgB;IAC9B;IAEA,IAAI,gBAAgB,eAAe,EAAE;QACnC,IAAI,CAAC,gBAAgB,GAAG;QACxB,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI;IACnC;IAEA,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,YAAY;IAC1B;IAEA,IAAI,YAAY,WAAW,EAAE;QAC3B,IAAI,CAAC,YAAY,GAAG;QACpB,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI;IACnC;IAEA,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,WAAW;IACzB;IAEA,IAAI,WAAW,UAAU,EAAE;QACzB,IAAI,CAAC,WAAW,GAAG;QACnB,IAAI,CAAC,aAAa,CA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AK,IAAI,MAAM,IAAI,CAAC,aAAa,CAC/B;IAEJ;IAEA,UAAU,EAAc,EAAE;QACxB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;QACvB,OAAO,IAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;IACzC;IAEA,gBAAgB;QACd,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,GAAG;YACb,IAAI,CAAC,UAAU,GAAG;YAClB,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,MAAM,GAAG;QAChB;IACF;IApIA,YAAY,UAAa,CAAE;QACzB,aAAa;QACb,KAAK,CAAC;aAfR,WAAW,GAAI,yBAAyB;;aACxC,gBAAgB,IAAI;aACpB,aAA+B,IAAI;aACnC,QAAQ;aACR,SAAS;aACT,eAAe,IAAI;aACnB,YAAY;aAGJ,eAAoC,IAAI;aACxC,gBAAiC,IAAI;aACrC,mBAAmB;QAKzB,IAAI,CAAC,UAAU,GAAG;QAClB,IAAI,CAAC,iBAAiB,GAAG;IAC3B;AAgIF","sources":["packages/@react-aria/collections/src/Document.ts"],"sourcesContent":["/*\n * Copyright 2024 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {BaseCollection, 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,MA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G,cAA/B,6CAAA,kCAAmC,MAAM,IAAI,CAAC,KAAK;YACxH,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE;gBACf,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,cAAc;gBACrC,IAAI,CAAC,cAAc,GAAG;YACxB;QACF;IACF;IAEA,cAAoB;QAClB,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,YAAY,EACjD;QAGF,iFAAiF;QACjF,2GAA2G;QAC3G,gGAAgG;QAChG,mGAAmG;QACnG,uCAAuC;QACvC,IAAI,CAAC,YAAY,GAAG;QACpB,IAAI,CAAC,cAAc,GAAG;QACtB,KAAK,IAAI,MAAM,IAAI,CAAC,aAAa,CAC/B;QAEF,IAAI,CAAC,cAAc,GAAG;IACxB;IAEA,UAAU,EAAc,EAAE;QACxB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC;QACvB,OAAO,IAAe,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC;IAClD;IAEA,gBAAsB;QACpB,IAAI,IAAI,CAAC,KAAK,EAAE;YACd,IAAI,CAAC,KAAK,GAAG;YACb,IAAI,CAAC,UAAU,GAAG;YAClB,IAAI,CAAC,SAAS,GAAG;YACjB,IAAI,CAAC,MAAM,GAAG;QAChB;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 || !this._minInvalidChildIndex.isConnected || child.index < this._minInvalidChildIndex.index) {\n this._minInvalidChildIndex = child;\n this.ownerDocument.markDirty(this);\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 if (this.isConnected) {\n this.ownerDocument.queueUpdate();\n }\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 // Ensure that the newNode's index is less than that of the reference node so that\n // invalidateChildIndices will properly use the newNode as the _minInvalidChildIndex, thus making sure\n // we will properly update the indexes of all sibiling nodes after the newNode. The value here doesn't matter\n // since updateChildIndices should calculate the proper indexes.\n newNode.index = referenceNode.index - 1;\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(newNode);\n if (this.isConnected) {\n this.ownerDocument.queueUpdate();\n }\n }\n\n removeChild(child: ElementNode<T>): void {\n if (child.parentNode !== this || !this.ownerDocument.isMounted) {\n return;\n }\n\n if (this._minInvalidChildIndex === child) {\n this._minInvalidChildIndex = null;\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 if (this.isConnected) {\n this.ownerDocument.queueUpdate();\n }\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 if (this.isConnected) {\n this.ownerDocument.queueUpdate();\n }\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"}