@dxos/lit-grid 0.6.12-main.89e9959 → 0.6.12-main.c1d977f

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.
@@ -447,10 +447,14 @@ var DxGrid = class extends LitElement2 {
447
447
  }
448
448
  });
449
449
  this.viewportRef = createRef();
450
- this.maybeUpdateVis = () => {
451
- if (this.posInline >= this.binInlineMin && this.posInline < this.binInlineMax && this.posBlock >= this.binBlockMin && this.posBlock < this.binBlockMax) {
452
- } else {
453
- this.updateVis();
450
+ this.maybeUpdateVisInline = () => {
451
+ if (this.posInline < this.binInlineMin || this.posInline >= this.binInlineMax) {
452
+ this.updateVisInline();
453
+ }
454
+ };
455
+ this.maybeUpdateVisBlock = () => {
456
+ if (this.posBlock < this.binBlockMin || this.posBlock >= this.binBlockMax) {
457
+ this.updateVisBlock();
454
458
  }
455
459
  };
456
460
  this.handleWheel = ({ deltaX, deltaY }) => {
@@ -576,10 +580,17 @@ var DxGrid = class extends LitElement2 {
576
580
  ...cellSize
577
581
  };
578
582
  }
579
- updatePos(inline, block) {
583
+ updatePosInline(inline) {
580
584
  this.posInline = Math.max(0, Math.min(this.intrinsicInlineSize - this.sizeInline, inline ?? this.posInline));
585
+ this.maybeUpdateVisInline();
586
+ }
587
+ updatePosBlock(block) {
581
588
  this.posBlock = Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, block ?? this.posBlock));
582
- this.maybeUpdateVis();
589
+ this.maybeUpdateVisBlock();
590
+ }
591
+ updatePos(inline, block) {
592
+ this.updatePosInline(inline);
593
+ this.updatePosBlock(block);
583
594
  }
584
595
  updateVisInline() {
585
596
  let colIndex = 0;
@@ -597,7 +608,7 @@ var DxGrid = class extends LitElement2 {
597
608
  acc += this.colSize(this.visColMin + c0, "grid");
598
609
  return acc;
599
610
  }, 0) + gap * (overscanCol - 1);
600
- while (pxInline < this.binInlineMax + this.sizeInline + gap) {
611
+ while (pxInline < this.binInlineMax + this.sizeInline - gap * 2) {
601
612
  colIndex += 1;
602
613
  pxInline += this.colSize(colIndex, "grid") + gap;
603
614
  }
@@ -628,7 +639,7 @@ var DxGrid = class extends LitElement2 {
628
639
  acc += this.rowSize(this.visRowMin + r0, "grid");
629
640
  return acc;
630
641
  }, 0) + gap * (overscanRow - 1);
631
- while (pxBlock < this.binBlockMax + this.sizeBlock) {
642
+ while (pxBlock < this.binBlockMax + this.sizeBlock - gap * 2) {
632
643
  rowIndex += 1;
633
644
  pxBlock += this.rowSize(rowIndex, "grid") + gap;
634
645
  }
@@ -746,24 +757,40 @@ var DxGrid = class extends LitElement2 {
746
757
  focusedCellElement() {
747
758
  return this.viewportRef.value?.querySelector(`[data-dx-grid-plane=${this.focusedCell.plane}] > [aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`);
748
759
  }
760
+ //
761
+ // `outOfVis` returns by how many rows/cols the focused cell is outside of the `vis` range for an axis, inset by a
762
+ // `delta`, otherwise zero if it is within that range.
763
+ //
749
764
  focusedCellRowOutOfVis(minDelta = 0, maxDelta = minDelta) {
750
- return this.focusedCell.row < this.visRowMin + minDelta || this.focusedCell.row > this.visRowMax - maxDelta;
765
+ return this.focusedCell.row <= this.visRowMin + minDelta ? this.focusedCell.row - (this.visRowMin + minDelta) : this.focusedCell.row >= this.visRowMax - maxDelta ? -(this.focusedCell.row - this.visRowMax - maxDelta) : 0;
751
766
  }
752
767
  focusedCellColOutOfVis(minDelta = 0, maxDelta = minDelta) {
753
- return this.focusedCell.col < this.visColMin + minDelta || this.focusedCell.col > this.visColMax - maxDelta;
768
+ return this.focusedCell.col <= this.visColMin + minDelta ? this.focusedCell.col - (this.visColMin + minDelta) : this.focusedCell.col >= this.visColMax - maxDelta ? -(this.focusedCell.col - this.visColMax - maxDelta) : 0;
754
769
  }
755
770
  focusedCellOutOfVis(colDelta = 0, rowDelta = colDelta) {
756
771
  switch (this.focusedCell.plane) {
757
772
  case "grid":
758
- return this.focusedCellRowOutOfVis(rowDelta) || this.focusedCellColOutOfVis(colDelta);
773
+ return {
774
+ row: this.focusedCellRowOutOfVis(rowDelta),
775
+ col: this.focusedCellColOutOfVis(colDelta)
776
+ };
759
777
  case "frozenRowsStart":
760
778
  case "frozenRowsEnd":
761
- return this.focusedCellColOutOfVis(colDelta);
779
+ return {
780
+ col: this.focusedCellColOutOfVis(colDelta),
781
+ row: 0
782
+ };
762
783
  case "frozenColsStart":
763
784
  case "frozenColsEnd":
764
- return this.focusedCellRowOutOfVis(rowDelta);
785
+ return {
786
+ col: 0,
787
+ row: this.focusedCellRowOutOfVis(rowDelta)
788
+ };
765
789
  default:
766
- return false;
790
+ return {
791
+ col: 0,
792
+ row: 0
793
+ };
767
794
  }
768
795
  }
769
796
  /**
@@ -786,41 +813,53 @@ var DxGrid = class extends LitElement2 {
786
813
  if (increment) {
787
814
  this.snapPosToFocusedCell();
788
815
  }
789
- queueMicrotask(() => (this.focusedCellOutOfVis() ? this.viewportRef.value : this.focusedCellElement())?.focus({
790
- preventScroll: true
791
- }));
816
+ queueMicrotask(() => {
817
+ const outOfVis = this.focusedCellOutOfVis(overscanCol, overscanRow);
818
+ (outOfVis.col !== 0 || outOfVis.row !== 0 ? this.viewportRef.value : this.focusedCellElement())?.focus({
819
+ preventScroll: true
820
+ });
821
+ });
822
+ }
823
+ findPosInlineFromVisColMin(deltaCols) {
824
+ return [
825
+ ...Array(deltaCols)
826
+ ].reduce((acc, _, c0) => acc - this.colSize(this.visColMin - c0, "grid") - gap, this.binInlineMin + gap);
827
+ }
828
+ findPosBlockFromVisRowMin(deltaRows) {
829
+ return [
830
+ ...Array(deltaRows)
831
+ ].reduce((acc, _, r0) => acc - this.rowSize(this.visRowMin - r0, "grid") - gap, this.binBlockMin + gap);
792
832
  }
793
833
  /**
794
834
  * Updates `pos` so that a cell in focus is fully within the viewport
795
835
  */
796
836
  snapPosToFocusedCell() {
797
- if (this.focusedCellOutOfVis(overscanCol + 1, overscanRow + 1)) {
798
- if (this.focusedCell.col <= this.visColMin + overscanCol) {
799
- this.posInline = this.binInlineMin;
800
- this.updateVisInline();
801
- } else if (this.focusedCell.col >= this.visColMax - overscanCol - 1) {
802
- const sizeSumCol = [
803
- ...Array(this.focusedCell.col - this.visColMin)
804
- ].reduce((acc, _, c0) => {
805
- acc += this.colSize(this.visColMin + overscanCol + c0, "grid") + gap;
806
- return acc;
807
- }, 0);
808
- this.posInline = Math.max(0, Math.min(this.intrinsicInlineSize - this.sizeInline, this.binInlineMin + sizeSumCol - this.sizeInline));
809
- this.updateVisInline();
810
- }
811
- if (this.focusedCell.row <= this.visRowMin + overscanRow) {
812
- this.posBlock = this.binBlockMin;
813
- this.updateVisBlock();
814
- } else if (this.focusedCell.row >= this.visRowMax - overscanRow - 1) {
815
- const sizeSumRow = [
816
- ...Array(this.focusedCell.row - this.visRowMin)
817
- ].reduce((acc, _, r0) => {
818
- acc += this.rowSize(this.visRowMin + overscanRow + r0, "grid") + gap;
819
- return acc;
820
- }, 0);
821
- this.posBlock = Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, this.binBlockMin + sizeSumRow - this.sizeBlock));
822
- this.updateVisBlock();
823
- }
837
+ const outOfVis = this.focusedCellOutOfVis(overscanCol, overscanRow);
838
+ if (outOfVis.col < 0) {
839
+ this.posInline = this.findPosInlineFromVisColMin(-outOfVis.col);
840
+ this.updateVisInline();
841
+ } else if (outOfVis.col > 0) {
842
+ const sizeSumCol = [
843
+ ...Array(this.focusedCell.col - this.visColMin)
844
+ ].reduce((acc, _, c0) => {
845
+ acc += this.colSize(this.visColMin + overscanCol + c0, "grid") + gap;
846
+ return acc;
847
+ }, 0);
848
+ this.posInline = Math.max(0, Math.min(this.intrinsicInlineSize - this.sizeInline, this.binInlineMin + sizeSumCol - this.sizeInline));
849
+ this.updateVisInline();
850
+ }
851
+ if (outOfVis.row < 0) {
852
+ this.posBlock = this.findPosBlockFromVisRowMin(-outOfVis.row);
853
+ this.updateVisBlock();
854
+ } else if (outOfVis.row > 0) {
855
+ const sizeSumRow = [
856
+ ...Array(this.focusedCell.row - this.visRowMin)
857
+ ].reduce((acc, _, r0) => {
858
+ acc += this.rowSize(this.visRowMin + overscanRow + r0, "grid") + gap;
859
+ return acc;
860
+ }, 0);
861
+ this.posBlock = Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, this.binBlockMin + sizeSumRow - this.sizeBlock));
862
+ this.updateVisBlock();
824
863
  }
825
864
  }
826
865
  //
@@ -831,14 +870,14 @@ var DxGrid = class extends LitElement2 {
831
870
  }
832
871
  set scrollLeft(nextValue) {
833
872
  this.posInline = nextValue;
834
- this.maybeUpdateVis();
873
+ this.maybeUpdateVisInline();
835
874
  }
836
875
  get scrollTop() {
837
876
  return this.posBlock;
838
877
  }
839
878
  set scrollTop(nextValue) {
840
879
  this.posBlock = nextValue;
841
- this.maybeUpdateVis();
880
+ this.maybeUpdateVisBlock();
842
881
  }
843
882
  //
844
883
  // Resize handlers
@@ -848,7 +887,7 @@ var DxGrid = class extends LitElement2 {
848
887
  }
849
888
  handleAxisResizeInternal(event) {
850
889
  event.stopPropagation();
851
- const { plane, axis, delta, size, index, type } = event;
890
+ const { plane, axis, delta, size, index, state: state2 } = event;
852
891
  if (axis === "col") {
853
892
  const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, size + delta));
854
893
  this.colSizes = {
@@ -872,7 +911,7 @@ var DxGrid = class extends LitElement2 {
872
911
  this.updateVisBlock();
873
912
  this.updateIntrinsicBlockSize();
874
913
  }
875
- if (type === "dropped") {
914
+ if (state2 === "dropped") {
876
915
  this.dispatchEvent(new DxAxisResize({
877
916
  plane,
878
917
  axis,
@@ -1067,12 +1106,29 @@ var DxGrid = class extends LitElement2 {
1067
1106
  if (this.getCells && (changedProperties.has("initialCells") || changedProperties.has("visColMin") || changedProperties.has("visColMax") || changedProperties.has("visRowMin") || changedProperties.has("visRowMax"))) {
1068
1107
  this.updateCells();
1069
1108
  }
1109
+ if (changedProperties.has("rowDefault") || changedProperties.has("rows") || changedProperties.has("limitRows")) {
1110
+ this.updateIntrinsicBlockSize();
1111
+ this.updatePosBlock();
1112
+ this.updateVisBlock();
1113
+ }
1114
+ if (changedProperties.has("colDefault") || changedProperties.has("columns") || changedProperties.has("limitColumns")) {
1115
+ this.updateIntrinsicInlineSize();
1116
+ this.updatePosInline();
1117
+ this.updateVisInline();
1118
+ }
1070
1119
  }
1071
1120
  updated(changedProperties) {
1072
1121
  if (this.focusActive && (changedProperties.has("visRowMin") || changedProperties.has("visColMin") || changedProperties.has("focusedCell"))) {
1073
1122
  this.refocus();
1074
1123
  }
1075
1124
  }
1125
+ updateIfWithinBounds({ col, row }) {
1126
+ if (col >= this.visColMin && col <= this.visColMax && row >= this.visRowMin && row <= this.visRowMax) {
1127
+ this.requestUpdate();
1128
+ return true;
1129
+ }
1130
+ return false;
1131
+ }
1076
1132
  disconnectedCallback() {
1077
1133
  super.disconnectedCallback();
1078
1134
  if (this.viewportRef.value) {