@react-stately/layout 3.5.0 → 3.5.1-nightly.3287

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