@react-stately/layout 3.4.6-nightly.3175 → 3.4.6-nightly.3184

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/main.js CHANGED
@@ -355,6 +355,302 @@ $parcel$export($67c493497dcda343$exports, "TableLayout", () => $67c493497dcda343
355
355
 
356
356
 
357
357
  class $67c493497dcda343$export$62444c3c724b1b20 extends $fe69e47e38ed0ac4$export$cacbb3924155d68e {
358
+ buildCollection() {
359
+ // If columns changed, clear layout cache.
360
+ if (!this.lastCollection || this.collection.columns.length !== this.lastCollection.columns.length || this.collection.columns.some((c, i)=>c.key !== this.lastCollection.columns[i].key
361
+ )) // Invalidate everything in this layout pass. Will be reset in ListLayout on the next pass.
362
+ this.invalidateEverything = true;
363
+ // Track whether we were previously loading. This is used to adjust the animations of async loading vs inserts.
364
+ let loadingState = this.collection.body.props.loadingState;
365
+ this.wasLoading = this.isLoading;
366
+ this.isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
367
+ let header = this.buildHeader();
368
+ let body = this.buildBody(0);
369
+ this.stickyColumnIndices = this.collection.columns.filter((c)=>c.props.isSelectionCell || this.collection.rowHeaderColumnKeys.has(c.key)
370
+ ).map((c)=>c.index
371
+ );
372
+ body.layoutInfo.rect.width = Math.max(header.layoutInfo.rect.width, body.layoutInfo.rect.width);
373
+ this.contentSize = new $cMJQZ$reactstatelyvirtualizer.Size(body.layoutInfo.rect.width, body.layoutInfo.rect.maxY);
374
+ return [
375
+ header,
376
+ body
377
+ ];
378
+ }
379
+ buildHeader() {
380
+ let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(0, 0, 0, 0);
381
+ let layoutInfo = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('header', 'header', rect);
382
+ let y = 0;
383
+ let width = 0;
384
+ let children = [];
385
+ for (let headerRow of this.collection.headerRows){
386
+ let layoutNode = this.buildChild(headerRow, 0, y);
387
+ layoutNode.layoutInfo.parentKey = 'header';
388
+ y = layoutNode.layoutInfo.rect.maxY;
389
+ width = Math.max(width, layoutNode.layoutInfo.rect.width);
390
+ children.push(layoutNode);
391
+ }
392
+ rect.width = width;
393
+ rect.height = y;
394
+ this.layoutInfos.set('header', layoutInfo);
395
+ return {
396
+ layoutInfo: layoutInfo,
397
+ children: children
398
+ };
399
+ }
400
+ buildHeaderRow(headerRow, x, y) {
401
+ let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(0, y, 0, 0);
402
+ let row = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('headerrow', headerRow.key, rect);
403
+ let height = 0;
404
+ let columns = [];
405
+ for (let cell of headerRow.childNodes){
406
+ let layoutNode = this.buildChild(cell, x, y);
407
+ layoutNode.layoutInfo.parentKey = row.key;
408
+ x = layoutNode.layoutInfo.rect.maxX;
409
+ height = Math.max(height, layoutNode.layoutInfo.rect.height);
410
+ columns.push(layoutNode);
411
+ }
412
+ this.setChildHeights(columns, height);
413
+ rect.height = height;
414
+ rect.width = x;
415
+ return {
416
+ layoutInfo: row,
417
+ children: columns
418
+ };
419
+ }
420
+ setChildHeights(children, height) {
421
+ for (let child of children)if (child.layoutInfo.rect.height !== height) {
422
+ // Need to copy the layout info before we mutate it.
423
+ child.layoutInfo = child.layoutInfo.copy();
424
+ this.layoutInfos.set(child.layoutInfo.key, child.layoutInfo);
425
+ child.layoutInfo.rect.height = height;
426
+ }
427
+ }
428
+ // used to get the column widths when rendering to the DOM
429
+ getColumnWidth_(node) {
430
+ var _colspan;
431
+ let colspan = (_colspan = node.colspan) !== null && _colspan !== void 0 ? _colspan : 1;
432
+ let width = 0;
433
+ for(let i = node.index; i < node.index + colspan; i++){
434
+ let column = this.collection.columns[i];
435
+ width += this.getColumnWidth(column.key);
436
+ }
437
+ return width;
438
+ }
439
+ getEstimatedHeight(node, width, height, estimatedHeight) {
440
+ let isEstimated = false;
441
+ // If no explicit height is available, use an estimated height.
442
+ if (height == null) {
443
+ // If a previous version of this layout info exists, reuse its height.
444
+ // Mark as estimated if the size of the overall collection view changed,
445
+ // or the content of the item changed.
446
+ let previousLayoutNode = this.layoutNodes.get(node.key);
447
+ if (previousLayoutNode) {
448
+ let curNode = this.collection.getItem(node.key);
449
+ let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;
450
+ height = previousLayoutNode.layoutInfo.rect.height;
451
+ isEstimated = curNode !== lastNode || width !== previousLayoutNode.layoutInfo.rect.width || previousLayoutNode.layoutInfo.estimatedSize;
452
+ } else {
453
+ height = estimatedHeight;
454
+ isEstimated = true;
455
+ }
456
+ }
457
+ return {
458
+ height: height,
459
+ isEstimated: isEstimated
460
+ };
461
+ }
462
+ buildColumn(node, x, y) {
463
+ var ref;
464
+ let width = this.getColumnWidth_(node);
465
+ let { height: height , isEstimated: isEstimated } = this.getEstimatedHeight(node, width, this.headingHeight, this.estimatedHeadingHeight);
466
+ let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(x, y, width, height);
467
+ let layoutInfo = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo(node.type, node.key, rect);
468
+ layoutInfo.isSticky = (ref = node.props) === null || ref === void 0 ? void 0 : ref.isSelectionCell;
469
+ layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
470
+ layoutInfo.estimatedSize = isEstimated;
471
+ return {
472
+ layoutInfo: layoutInfo
473
+ };
474
+ }
475
+ buildBody(y) {
476
+ let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(0, y, 0, 0);
477
+ let layoutInfo = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('rowgroup', 'body', rect);
478
+ let startY = y;
479
+ let width = 0;
480
+ let children = [];
481
+ for (let node of this.collection.body.childNodes){
482
+ let layoutNode = this.buildChild(node, 0, y);
483
+ layoutNode.layoutInfo.parentKey = 'body';
484
+ y = layoutNode.layoutInfo.rect.maxY;
485
+ width = Math.max(width, layoutNode.layoutInfo.rect.width);
486
+ children.push(layoutNode);
487
+ }
488
+ if (this.isLoading) {
489
+ let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(0, y, width || this.virtualizer.visibleRect.width, children.length === 0 ? this.virtualizer.visibleRect.height : 60);
490
+ let loader = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('loader', 'loader', rect);
491
+ loader.parentKey = 'body';
492
+ loader.isSticky = children.length === 0;
493
+ this.layoutInfos.set('loader', loader);
494
+ children.push({
495
+ layoutInfo: loader
496
+ });
497
+ y = loader.rect.maxY;
498
+ width = Math.max(width, rect.width);
499
+ } else if (children.length === 0) {
500
+ let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(0, y, this.virtualizer.visibleRect.width, this.virtualizer.visibleRect.height);
501
+ let empty = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('empty', 'empty', rect);
502
+ empty.parentKey = 'body';
503
+ empty.isSticky = true;
504
+ this.layoutInfos.set('empty', empty);
505
+ children.push({
506
+ layoutInfo: empty
507
+ });
508
+ y = empty.rect.maxY;
509
+ width = Math.max(width, rect.width);
510
+ }
511
+ rect.width = width;
512
+ rect.height = y - startY;
513
+ this.layoutInfos.set('body', layoutInfo);
514
+ return {
515
+ layoutInfo: layoutInfo,
516
+ children: children
517
+ };
518
+ }
519
+ buildNode(node, x, y) {
520
+ switch(node.type){
521
+ case 'headerrow':
522
+ return this.buildHeaderRow(node, x, y);
523
+ case 'item':
524
+ return this.buildRow(node, x, y);
525
+ case 'column':
526
+ case 'placeholder':
527
+ return this.buildColumn(node, x, y);
528
+ case 'cell':
529
+ return this.buildCell(node, x, y);
530
+ default:
531
+ throw new Error('Unknown node type ' + node.type);
532
+ }
533
+ }
534
+ buildRow(node, x, y) {
535
+ let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(x, y, 0, 0);
536
+ let layoutInfo = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('row', node.key, rect);
537
+ let children = [];
538
+ let height = 0;
539
+ for (let child of node.childNodes){
540
+ let layoutNode = this.buildChild(child, x, y);
541
+ x = layoutNode.layoutInfo.rect.maxX;
542
+ height = Math.max(height, layoutNode.layoutInfo.rect.height);
543
+ children.push(layoutNode);
544
+ }
545
+ this.setChildHeights(children, height);
546
+ rect.width = x;
547
+ rect.height = height + 1; // +1 for bottom border
548
+ return {
549
+ layoutInfo: layoutInfo,
550
+ children: children
551
+ };
552
+ }
553
+ buildCell(node, x, y) {
554
+ var ref;
555
+ let width = this.getColumnWidth_(node);
556
+ let { height: height , isEstimated: isEstimated } = this.getEstimatedHeight(node, width, this.rowHeight, this.estimatedRowHeight);
557
+ let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(x, y, width, height);
558
+ let layoutInfo = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo(node.type, node.key, rect);
559
+ layoutInfo.isSticky = (ref = node.props) === null || ref === void 0 ? void 0 : ref.isSelectionCell;
560
+ layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
561
+ layoutInfo.estimatedSize = isEstimated;
562
+ return {
563
+ layoutInfo: layoutInfo
564
+ };
565
+ }
566
+ getVisibleLayoutInfos(rect) {
567
+ let res = [];
568
+ for (let node of this.rootNodes){
569
+ res.push(node.layoutInfo);
570
+ this.addVisibleLayoutInfos(res, node, rect);
571
+ }
572
+ return res;
573
+ }
574
+ addVisibleLayoutInfos(res, node, rect) {
575
+ if (!node.children || node.children.length === 0) return;
576
+ switch(node.layoutInfo.type){
577
+ case 'header':
578
+ for (let child of node.children){
579
+ res.push(child.layoutInfo);
580
+ this.addVisibleLayoutInfos(res, child, rect);
581
+ }
582
+ break;
583
+ case 'rowgroup':
584
+ {
585
+ let firstVisibleRow = this.binarySearch(node.children, rect.topLeft, 'y');
586
+ let lastVisibleRow = this.binarySearch(node.children, rect.bottomRight, 'y');
587
+ for(let i = firstVisibleRow; i <= lastVisibleRow; i++){
588
+ res.push(node.children[i].layoutInfo);
589
+ this.addVisibleLayoutInfos(res, node.children[i], rect);
590
+ }
591
+ break;
592
+ }
593
+ case 'headerrow':
594
+ case 'row':
595
+ {
596
+ let firstVisibleCell = this.binarySearch(node.children, rect.topLeft, 'x');
597
+ let lastVisibleCell = this.binarySearch(node.children, rect.topRight, 'x');
598
+ let stickyIndex = 0;
599
+ for(let i = firstVisibleCell; i <= lastVisibleCell; i++){
600
+ // Sticky columns and row headers are always in the DOM. Interleave these
601
+ // with the visible range so that they are in the right order.
602
+ if (stickyIndex < this.stickyColumnIndices.length) {
603
+ let idx = this.stickyColumnIndices[stickyIndex];
604
+ while(idx < i){
605
+ res.push(node.children[idx].layoutInfo);
606
+ idx = this.stickyColumnIndices[stickyIndex++];
607
+ }
608
+ }
609
+ res.push(node.children[i].layoutInfo);
610
+ }
611
+ while(stickyIndex < this.stickyColumnIndices.length){
612
+ let idx = this.stickyColumnIndices[stickyIndex++];
613
+ res.push(node.children[idx].layoutInfo);
614
+ }
615
+ break;
616
+ }
617
+ default:
618
+ throw new Error('Unknown node type ' + node.layoutInfo.type);
619
+ }
620
+ }
621
+ binarySearch(items, point, axis) {
622
+ let low = 0;
623
+ let high = items.length - 1;
624
+ while(low <= high){
625
+ let mid = low + high >> 1;
626
+ let item = items[mid];
627
+ if (axis === 'x' && item.layoutInfo.rect.maxX < point.x || axis === 'y' && item.layoutInfo.rect.maxY < point.y) low = mid + 1;
628
+ else if (axis === 'x' && item.layoutInfo.rect.x > point.x || axis === 'y' && item.layoutInfo.rect.y > point.y) high = mid - 1;
629
+ else return mid;
630
+ }
631
+ return Math.max(0, Math.min(items.length - 1, low));
632
+ }
633
+ getInitialLayoutInfo(layoutInfo) {
634
+ let res = super.getInitialLayoutInfo(layoutInfo);
635
+ // If this insert was the result of async loading, remove the zoom effect and just keep the fade in.
636
+ if (this.wasLoading) res.transform = null;
637
+ return res;
638
+ }
639
+ constructor(options){
640
+ super(options);
641
+ this.wasLoading = false;
642
+ this.isLoading = false;
643
+ this.stickyColumnIndices = [];
644
+ }
645
+ }
646
+
647
+
648
+ var $8cf5b1c755e3d109$exports = {};
649
+
650
+ $parcel$export($8cf5b1c755e3d109$exports, "TableLayout_DEPRECATED", () => $8cf5b1c755e3d109$export$7e9c3f5c8fff54f);
651
+
652
+
653
+ class $8cf5b1c755e3d109$export$7e9c3f5c8fff54f extends $fe69e47e38ed0ac4$export$cacbb3924155d68e {
358
654
  buildCollection() {
359
655
  // If columns changed, clear layout cache.
360
656
  if (!this.lastCollection || this.collection.columns.length !== this.lastCollection.columns.length || this.collection.columns.some((c, i)=>c.key !== this.lastCollection.columns[i].key
@@ -400,7 +696,7 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends $fe69e47e38ed0ac4$export
400
696
  let props = column.props;
401
697
  let minWidth = props.minWidth != null ? this.parseWidth(props.minWidth) : 75;
402
698
  let maxWidth = props.maxWidth != null ? this.parseWidth(props.maxWidth) : Infinity;
403
- let width = Math.max(minWidth, Math.min(maxWidth, columnWidth));
699
+ let width = Math.floor(Math.max(minWidth, Math.min(maxWidth, columnWidth)));
404
700
  this.columnWidths.set(column.key, width);
405
701
  remainingSpace -= width;
406
702
  if (width !== columnWidth) columnWidth = remainingSpace / (this.collection.columns.length - this.columnWidths.size);
@@ -685,6 +981,7 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends $fe69e47e38ed0ac4$export
685
981
 
686
982
  $parcel$exportWildcard(module.exports, $fe69e47e38ed0ac4$exports);
687
983
  $parcel$exportWildcard(module.exports, $67c493497dcda343$exports);
984
+ $parcel$exportWildcard(module.exports, $8cf5b1c755e3d109$exports);
688
985
 
689
986
 
690
987
  //# sourceMappingURL=main.js.map