@react-stately/virtualizer 3.2.3-nightly.3407 → 3.2.3-nightly.3414

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/module.js CHANGED
@@ -319,6 +319,14 @@ function $fc36f9a046a9ce79$export$6897c284b6f9f4dc(object) {
319
319
  for(let key in object)res[object[key]] = key;
320
320
  return res;
321
321
  }
322
+ function $fc36f9a046a9ce79$export$a8d0d0c8d1c5df64(a, b) {
323
+ if (a === b) return true;
324
+ if (a.size !== b.size) return false;
325
+ for (let key of a){
326
+ if (!b.has(key)) return false;
327
+ }
328
+ return true;
329
+ }
322
330
 
323
331
 
324
332
 
@@ -475,23 +483,27 @@ class $38b9490c1cca8fc4$export$89be5a243e59c4b2 {
475
483
  */ getItem(key) {
476
484
  return this._collection ? this._collection.getItem(key) : null;
477
485
  }
478
- /**
479
- * Set the keys of keys for layoutInfos persisted by the virtualizer.
480
- * This is to prevent these views from being reused by the virtualizer.
481
- */ set persistedKeys(persistedKeys) {
482
- let setsNotEqual = false;
483
- if (this._persistedKeys.size !== persistedKeys.size) setsNotEqual = true;
484
- else {
485
- for (var existingKey of this._persistedKeys)if (!persistedKeys.has(existingKey)) {
486
- setsNotEqual = true;
487
- break;
488
- }
489
- }
490
- if (setsNotEqual) {
486
+ /** The set of persisted keys are always present in the DOM, even if not currently in view. */ get persistedKeys() {
487
+ return this._persistedKeys;
488
+ }
489
+ /** The set of persisted keys are always present in the DOM, even if not currently in view. */ set persistedKeys(persistedKeys) {
490
+ if (!$fc36f9a046a9ce79$export$a8d0d0c8d1c5df64(persistedKeys, this._persistedKeys)) {
491
491
  this._persistedKeys = persistedKeys;
492
492
  this.updateSubviews();
493
493
  }
494
494
  }
495
+ /** Returns whether the given key, or an ancestor, is persisted. */ isPersistedKey(key) {
496
+ // Quick check if the key is directly in the set of persisted keys.
497
+ if (this._persistedKeys.has(key)) return true;
498
+ // If not, check if the key is an ancestor of any of the persisted keys.
499
+ for (let k of this._persistedKeys)while(k != null){
500
+ let layoutInfo = this.layout.getLayoutInfo(k);
501
+ if (!layoutInfo) break;
502
+ k = layoutInfo.parentKey;
503
+ if (k === key) return true;
504
+ }
505
+ return false;
506
+ }
495
507
  /**
496
508
  * Get the collection view's layout.
497
509
  */ get layout() {
@@ -600,9 +612,12 @@ class $38b9490c1cca8fc4$export$89be5a243e59c4b2 {
600
612
  */ keyAtPoint(point) {
601
613
  let rect = new $60423f92c7f9ad87$export$c79fc6492f3af13d(point.x, point.y, 1, 1);
602
614
  let layoutInfos = this.layout.getVisibleLayoutInfos(rect);
603
- let layoutInfo = layoutInfos[0];
604
- if (!layoutInfo) return null;
605
- return layoutInfo.key;
615
+ // Layout may return multiple layout infos in the case of
616
+ // persisted keys, so find the first one that actually intersects.
617
+ for (let layoutInfo of layoutInfos){
618
+ if (layoutInfo.rect.intersects(rect)) return layoutInfo.key;
619
+ }
620
+ return null;
606
621
  }
607
622
  /**
608
623
  * Cleanup for when the Virtualizer will be unmounted.
@@ -789,20 +804,6 @@ class $38b9490c1cca8fc4$export$89be5a243e59c4b2 {
789
804
  }
790
805
  return map;
791
806
  }
792
- isPersistedKey(node) {
793
- let keyFound = this._persistedKeys.has(node.layoutInfo.key);
794
- // for components like Table, where we have rows with cells as children,
795
- // if the key isn't found at the top level (row in this example), check
796
- // the children of this node to see if a child is persisted. If a child
797
- // of this node is a persisted key we consider this node as "persistable."
798
- if (!keyFound && node.children && node.node.type !== 'section') {
799
- for (let child of node.children)if (this._persistedKeys.has(child.layoutInfo.key)) {
800
- keyFound = true;
801
- break;
802
- }
803
- }
804
- return keyFound;
805
- }
806
807
  updateSubviews(forceUpdate = false) {
807
808
  if (!this._collection) return;
808
809
  let visibleLayoutInfos = this.getVisibleLayoutInfos();