@react-stately/layout 3.5.1-nightly.3335 → 3.5.1-nightly.3346

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
@@ -654,343 +654,8 @@ class $67c493497dcda343$export$62444c3c724b1b20 extends $fe69e47e38ed0ac4$export
654
654
  }
655
655
 
656
656
 
657
- var $8cf5b1c755e3d109$exports = {};
658
-
659
- $parcel$export($8cf5b1c755e3d109$exports, "TableLayout_DEPRECATED", () => $8cf5b1c755e3d109$export$7e9c3f5c8fff54f);
660
-
661
-
662
- class $8cf5b1c755e3d109$export$7e9c3f5c8fff54f extends $fe69e47e38ed0ac4$export$cacbb3924155d68e {
663
- buildCollection() {
664
- // If columns changed, clear layout cache.
665
- if (!this.lastCollection || this.collection.columns.length !== this.lastCollection.columns.length || this.collection.columns.some((c, i)=>c.key !== this.lastCollection.columns[i].key
666
- )) // Invalidate everything in this layout pass. Will be reset in ListLayout on the next pass.
667
- this.invalidateEverything = true;
668
- // Track whether we were previously loading. This is used to adjust the animations of async loading vs inserts.
669
- let loadingState = this.collection.body.props.loadingState;
670
- this.wasLoading = this.isLoading;
671
- this.isLoading = loadingState === 'loading' || loadingState === 'loadingMore';
672
- this.buildColumnWidths();
673
- let header = this.buildHeader();
674
- let body = this.buildBody(0);
675
- body.layoutInfo.rect.width = Math.max(header.layoutInfo.rect.width, body.layoutInfo.rect.width);
676
- this.contentSize = new $cMJQZ$reactstatelyvirtualizer.Size(body.layoutInfo.rect.width, body.layoutInfo.rect.maxY);
677
- return [
678
- header,
679
- body
680
- ];
681
- }
682
- buildColumnWidths() {
683
- this.columnWidths = new Map();
684
- this.stickyColumnIndices = [];
685
- // Pass 1: set widths for all explicitly defined columns.
686
- let remainingColumns = new Set();
687
- let remainingSpace = this.virtualizer.visibleRect.width;
688
- for (let column of this.collection.columns){
689
- let props = column.props;
690
- var _width;
691
- let width = (_width = props.width) !== null && _width !== void 0 ? _width : this.getDefaultWidth(props);
692
- if (width != null) {
693
- let w = this.parseWidth(width);
694
- this.columnWidths.set(column.key, w);
695
- remainingSpace -= w;
696
- } else remainingColumns.add(column);
697
- // The selection cell and any other sticky columns always need to be visible.
698
- // In addition, row headers need to be in the DOM for accessibility labeling.
699
- if (column.props.isSelectionCell || this.collection.rowHeaderColumnKeys.has(column.key)) this.stickyColumnIndices.push(column.index);
700
- }
701
- // Pass 2: if there are remaining columns, then distribute the remaining space evenly.
702
- if (remainingColumns.size > 0) {
703
- let columnWidth = remainingSpace / (this.collection.columns.length - this.columnWidths.size);
704
- for (let column of remainingColumns){
705
- let props = column.props;
706
- let minWidth = props.minWidth != null ? this.parseWidth(props.minWidth) : 75;
707
- let maxWidth = props.maxWidth != null ? this.parseWidth(props.maxWidth) : Infinity;
708
- let width = Math.floor(Math.max(minWidth, Math.min(maxWidth, columnWidth)));
709
- this.columnWidths.set(column.key, width);
710
- remainingSpace -= width;
711
- if (width !== columnWidth) columnWidth = remainingSpace / (this.collection.columns.length - this.columnWidths.size);
712
- }
713
- }
714
- }
715
- parseWidth(width) {
716
- if (typeof width === 'string') {
717
- let match = width.match(/^(\d+)%$/);
718
- if (!match) throw new Error('Only percentages are supported as column widths');
719
- return this.virtualizer.visibleRect.width * (parseInt(match[1], 10) / 100);
720
- }
721
- return width;
722
- }
723
- buildHeader() {
724
- let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(0, 0, 0, 0);
725
- let layoutInfo = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('header', 'header', rect);
726
- let y = 0;
727
- let width = 0;
728
- let children = [];
729
- for (let headerRow of this.collection.headerRows){
730
- let layoutNode = this.buildChild(headerRow, 0, y);
731
- layoutNode.layoutInfo.parentKey = 'header';
732
- y = layoutNode.layoutInfo.rect.maxY;
733
- width = Math.max(width, layoutNode.layoutInfo.rect.width);
734
- children.push(layoutNode);
735
- }
736
- rect.width = width;
737
- rect.height = y;
738
- this.layoutInfos.set('header', layoutInfo);
739
- return {
740
- layoutInfo: layoutInfo,
741
- children: children
742
- };
743
- }
744
- buildHeaderRow(headerRow, x, y) {
745
- let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(0, y, 0, 0);
746
- let row = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('headerrow', headerRow.key, rect);
747
- let height = 0;
748
- let columns = [];
749
- for (let cell of headerRow.childNodes){
750
- let layoutNode = this.buildChild(cell, x, y);
751
- layoutNode.layoutInfo.parentKey = row.key;
752
- x = layoutNode.layoutInfo.rect.maxX;
753
- height = Math.max(height, layoutNode.layoutInfo.rect.height);
754
- columns.push(layoutNode);
755
- }
756
- this.setChildHeights(columns, height);
757
- rect.height = height;
758
- rect.width = x;
759
- return {
760
- layoutInfo: row,
761
- children: columns
762
- };
763
- }
764
- setChildHeights(children, height) {
765
- for (let child of children)if (child.layoutInfo.rect.height !== height) {
766
- // Need to copy the layout info before we mutate it.
767
- child.layoutInfo = child.layoutInfo.copy();
768
- this.layoutInfos.set(child.layoutInfo.key, child.layoutInfo);
769
- child.layoutInfo.rect.height = height;
770
- }
771
- }
772
- getColumnWidth(node) {
773
- var _colspan;
774
- let colspan = (_colspan = node.colspan) !== null && _colspan !== void 0 ? _colspan : 1;
775
- let width = 0;
776
- for(let i = 0; i < colspan; i++){
777
- let column = this.collection.columns[node.index + i];
778
- width += this.columnWidths.get(column.key);
779
- }
780
- return width;
781
- }
782
- getEstimatedHeight(node, width, height, estimatedHeight) {
783
- let isEstimated = false;
784
- // If no explicit height is available, use an estimated height.
785
- if (height == null) {
786
- // If a previous version of this layout info exists, reuse its height.
787
- // Mark as estimated if the size of the overall collection view changed,
788
- // or the content of the item changed.
789
- let previousLayoutNode = this.layoutNodes.get(node.key);
790
- if (previousLayoutNode) {
791
- let curNode = this.collection.getItem(node.key);
792
- let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;
793
- height = previousLayoutNode.layoutInfo.rect.height;
794
- isEstimated = curNode !== lastNode || width !== previousLayoutNode.layoutInfo.rect.width || previousLayoutNode.layoutInfo.estimatedSize;
795
- } else {
796
- height = estimatedHeight;
797
- isEstimated = true;
798
- }
799
- }
800
- return {
801
- height: height,
802
- isEstimated: isEstimated
803
- };
804
- }
805
- buildColumn(node, x, y) {
806
- var ref;
807
- let width = this.getColumnWidth(node);
808
- let { height: height , isEstimated: isEstimated } = this.getEstimatedHeight(node, width, this.headingHeight, this.estimatedHeadingHeight);
809
- let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(x, y, width, height);
810
- let layoutInfo = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo(node.type, node.key, rect);
811
- layoutInfo.isSticky = (ref = node.props) === null || ref === void 0 ? void 0 : ref.isSelectionCell;
812
- layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
813
- layoutInfo.estimatedSize = isEstimated;
814
- return {
815
- layoutInfo: layoutInfo
816
- };
817
- }
818
- buildBody(y) {
819
- let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(0, y, 0, 0);
820
- let layoutInfo = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('rowgroup', 'body', rect);
821
- let startY = y;
822
- let width = 0;
823
- let children = [];
824
- for (let node of this.collection.body.childNodes){
825
- let layoutNode = this.buildChild(node, 0, y);
826
- layoutNode.layoutInfo.parentKey = 'body';
827
- y = layoutNode.layoutInfo.rect.maxY;
828
- width = Math.max(width, layoutNode.layoutInfo.rect.width);
829
- children.push(layoutNode);
830
- }
831
- if (this.isLoading) {
832
- let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(0, y, width || this.virtualizer.visibleRect.width, children.length === 0 ? this.virtualizer.visibleRect.height : 60);
833
- let loader = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('loader', 'loader', rect);
834
- loader.parentKey = 'body';
835
- loader.isSticky = children.length === 0;
836
- this.layoutInfos.set('loader', loader);
837
- children.push({
838
- layoutInfo: loader
839
- });
840
- y = loader.rect.maxY;
841
- width = Math.max(width, rect.width);
842
- } else if (children.length === 0) {
843
- let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(0, y, this.virtualizer.visibleRect.width, this.virtualizer.visibleRect.height);
844
- let empty = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('empty', 'empty', rect);
845
- empty.parentKey = 'body';
846
- empty.isSticky = true;
847
- this.layoutInfos.set('empty', empty);
848
- children.push({
849
- layoutInfo: empty
850
- });
851
- y = empty.rect.maxY;
852
- width = Math.max(width, rect.width);
853
- }
854
- rect.width = width;
855
- rect.height = y - startY;
856
- this.layoutInfos.set('body', layoutInfo);
857
- return {
858
- layoutInfo: layoutInfo,
859
- children: children
860
- };
861
- }
862
- buildNode(node, x, y) {
863
- switch(node.type){
864
- case 'headerrow':
865
- return this.buildHeaderRow(node, x, y);
866
- case 'item':
867
- return this.buildRow(node, x, y);
868
- case 'column':
869
- case 'placeholder':
870
- return this.buildColumn(node, x, y);
871
- case 'cell':
872
- return this.buildCell(node, x, y);
873
- default:
874
- throw new Error('Unknown node type ' + node.type);
875
- }
876
- }
877
- buildRow(node, x, y) {
878
- let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(x, y, 0, 0);
879
- let layoutInfo = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo('row', node.key, rect);
880
- let children = [];
881
- let height = 0;
882
- for (let child of node.childNodes){
883
- let layoutNode = this.buildChild(child, x, y);
884
- x = layoutNode.layoutInfo.rect.maxX;
885
- height = Math.max(height, layoutNode.layoutInfo.rect.height);
886
- children.push(layoutNode);
887
- }
888
- this.setChildHeights(children, height);
889
- rect.width = x;
890
- rect.height = height + 1; // +1 for bottom border
891
- return {
892
- layoutInfo: layoutInfo,
893
- children: children
894
- };
895
- }
896
- buildCell(node, x, y) {
897
- var ref;
898
- let width = this.getColumnWidth(node);
899
- let { height: height , isEstimated: isEstimated } = this.getEstimatedHeight(node, width, this.rowHeight, this.estimatedRowHeight);
900
- let rect = new $cMJQZ$reactstatelyvirtualizer.Rect(x, y, width, height);
901
- let layoutInfo = new $cMJQZ$reactstatelyvirtualizer.LayoutInfo(node.type, node.key, rect);
902
- layoutInfo.isSticky = (ref = node.props) === null || ref === void 0 ? void 0 : ref.isSelectionCell;
903
- layoutInfo.zIndex = layoutInfo.isSticky ? 2 : 1;
904
- layoutInfo.estimatedSize = isEstimated;
905
- return {
906
- layoutInfo: layoutInfo
907
- };
908
- }
909
- getVisibleLayoutInfos(rect) {
910
- let res = [];
911
- for (let node of this.rootNodes){
912
- res.push(node.layoutInfo);
913
- this.addVisibleLayoutInfos(res, node, rect);
914
- }
915
- return res;
916
- }
917
- addVisibleLayoutInfos(res, node, rect) {
918
- if (!node.children || node.children.length === 0) return;
919
- switch(node.layoutInfo.type){
920
- case 'header':
921
- for (let child of node.children){
922
- res.push(child.layoutInfo);
923
- this.addVisibleLayoutInfos(res, child, rect);
924
- }
925
- break;
926
- case 'rowgroup':
927
- {
928
- let firstVisibleRow = this.binarySearch(node.children, rect.topLeft, 'y');
929
- let lastVisibleRow = this.binarySearch(node.children, rect.bottomRight, 'y');
930
- for(let i = firstVisibleRow; i <= lastVisibleRow; i++){
931
- res.push(node.children[i].layoutInfo);
932
- this.addVisibleLayoutInfos(res, node.children[i], rect);
933
- }
934
- break;
935
- }
936
- case 'headerrow':
937
- case 'row':
938
- {
939
- let firstVisibleCell = this.binarySearch(node.children, rect.topLeft, 'x');
940
- let lastVisibleCell = this.binarySearch(node.children, rect.topRight, 'x');
941
- let stickyIndex = 0;
942
- for(let i = firstVisibleCell; i <= lastVisibleCell; i++){
943
- // Sticky columns and row headers are always in the DOM. Interleave these
944
- // with the visible range so that they are in the right order.
945
- if (stickyIndex < this.stickyColumnIndices.length) {
946
- let idx = this.stickyColumnIndices[stickyIndex];
947
- while(idx < i){
948
- res.push(node.children[idx].layoutInfo);
949
- idx = this.stickyColumnIndices[stickyIndex++];
950
- }
951
- }
952
- res.push(node.children[i].layoutInfo);
953
- }
954
- while(stickyIndex < this.stickyColumnIndices.length){
955
- let idx = this.stickyColumnIndices[stickyIndex++];
956
- res.push(node.children[idx].layoutInfo);
957
- }
958
- break;
959
- }
960
- default:
961
- throw new Error('Unknown node type ' + node.layoutInfo.type);
962
- }
963
- }
964
- binarySearch(items, point, axis) {
965
- let low = 0;
966
- let high = items.length - 1;
967
- while(low <= high){
968
- let mid = low + high >> 1;
969
- let item = items[mid];
970
- if (axis === 'x' && item.layoutInfo.rect.maxX < point.x || axis === 'y' && item.layoutInfo.rect.maxY < point.y) low = mid + 1;
971
- else if (axis === 'x' && item.layoutInfo.rect.x > point.x || axis === 'y' && item.layoutInfo.rect.y > point.y) high = mid - 1;
972
- else return mid;
973
- }
974
- return Math.max(0, Math.min(items.length - 1, low));
975
- }
976
- getInitialLayoutInfo(layoutInfo) {
977
- let res = super.getInitialLayoutInfo(layoutInfo);
978
- // If this insert was the result of async loading, remove the zoom effect and just keep the fade in.
979
- if (this.wasLoading) res.transform = null;
980
- return res;
981
- }
982
- constructor(options){
983
- super(options);
984
- this.wasLoading = false;
985
- this.isLoading = false;
986
- this.getDefaultWidth = options.getDefaultWidth;
987
- }
988
- }
989
-
990
-
991
657
  $parcel$exportWildcard(module.exports, $fe69e47e38ed0ac4$exports);
992
658
  $parcel$exportWildcard(module.exports, $67c493497dcda343$exports);
993
- $parcel$exportWildcard(module.exports, $8cf5b1c755e3d109$exports);
994
659
 
995
660
 
996
661
  //# sourceMappingURL=main.js.map