@dxos/lit-grid 0.7.2 → 0.7.3-main.2dd075e

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.
Files changed (34) hide show
  1. package/dist/src/dx-grid.d.ts +16 -1
  2. package/dist/src/dx-grid.d.ts.map +1 -1
  3. package/dist/src/dx-grid.js +37 -15
  4. package/dist/src/dx-grid.js.map +1 -1
  5. package/dist/src/testing/playwright/dx-grid-manager.d.ts +1 -0
  6. package/dist/src/testing/playwright/dx-grid-manager.d.ts.map +1 -1
  7. package/dist/src/testing/playwright/dx-grid-manager.js +3 -0
  8. package/dist/src/testing/playwright/dx-grid-manager.js.map +1 -1
  9. package/dist/src/types.d.ts +1 -1
  10. package/dist/src/types.d.ts.map +1 -1
  11. package/dist/src/util.d.ts +3 -0
  12. package/dist/src/util.d.ts.map +1 -1
  13. package/dist/src/util.js +18 -0
  14. package/dist/src/util.js.map +1 -1
  15. package/dist/types/src/dx-grid.d.ts +16 -1
  16. package/dist/types/src/dx-grid.d.ts.map +1 -1
  17. package/dist/types/src/dx-grid.js +37 -15
  18. package/dist/types/src/dx-grid.js.map +1 -1
  19. package/dist/types/src/testing/playwright/dx-grid-manager.d.ts +1 -0
  20. package/dist/types/src/testing/playwright/dx-grid-manager.d.ts.map +1 -1
  21. package/dist/types/src/testing/playwright/dx-grid-manager.js +3 -0
  22. package/dist/types/src/testing/playwright/dx-grid-manager.js.map +1 -1
  23. package/dist/types/src/types.d.ts +1 -1
  24. package/dist/types/src/types.d.ts.map +1 -1
  25. package/dist/types/src/util.d.ts +3 -0
  26. package/dist/types/src/util.d.ts.map +1 -1
  27. package/dist/types/src/util.js +18 -0
  28. package/dist/types/src/util.js.map +1 -1
  29. package/package.json +2 -2
  30. package/src/dx-grid.pcss +3 -2
  31. package/src/dx-grid.ts +51 -23
  32. package/src/testing/playwright/dx-grid-manager.ts +4 -0
  33. package/src/types.ts +1 -1
  34. package/src/util.ts +21 -0
package/src/dx-grid.ts CHANGED
@@ -41,7 +41,7 @@ import {
41
41
  separator,
42
42
  } from './types';
43
43
  import {
44
- toPlaneCellIndex,
44
+ toCellIndex,
45
45
  gap,
46
46
  resizeTolerance,
47
47
  sizeColMin,
@@ -264,7 +264,7 @@ export class DxGrid extends LitElement {
264
264
  queueMicrotask(() =>
265
265
  this.dispatchEvent(
266
266
  new DxEditRequest({
267
- cellIndex: toPlaneCellIndex(this.focusedCell),
267
+ cellIndex: toCellIndex(this.focusedCell),
268
268
  cellBox: this.focusedCellBox(),
269
269
  initialContent,
270
270
  }),
@@ -954,6 +954,26 @@ export class DxGrid extends LitElement {
954
954
  return Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, nextPos));
955
955
  }
956
956
 
957
+ /**
958
+ * Calculate the pixel offset for a given column in a plane.
959
+ * Sums all column sizes plus gaps up to the target column.
960
+ */
961
+ private inlineOffset(col: number, plane: DxGridPlane): number {
962
+ return [...Array(col)].reduce((acc, _, c0) => {
963
+ return acc + this.colSize(c0, plane) + gap;
964
+ }, 0);
965
+ }
966
+
967
+ /**
968
+ * Calculate the pixel offset for a given row in a plane.
969
+ * Sums all row sizes plus gaps up to the target row.
970
+ */
971
+ private blockOffset(row: number, plane: DxGridPlane): number {
972
+ return [...Array(row)].reduce((acc, _, r0) => {
973
+ return acc + this.rowSize(r0, plane) + gap;
974
+ }, 0);
975
+ }
976
+
957
977
  /**
958
978
  * Updates `pos` so that a cell in focus is fully within the viewport
959
979
  */
@@ -961,41 +981,41 @@ export class DxGrid extends LitElement {
961
981
  const outOfVis = this.focusedCellOutOfVis();
962
982
  if (outOfVis.col < 0) {
963
983
  // align viewport start edge with focused cell start edge
964
- this.posInline = this.clampPosInline(
965
- [...Array(this.focusedCell.col)].reduce((acc, _, c0) => {
966
- return acc + this.colSize(c0, 'grid') + gap;
967
- }, 0),
968
- );
984
+ this.posInline = this.clampPosInline(this.inlineOffset(this.focusedCell.col, 'grid'));
969
985
  this.updateVisInline();
970
986
  } else if (outOfVis.col > 0) {
971
987
  // align viewport end edge with focused cell end edge
972
- this.posInline = this.clampPosInline(
973
- [...Array(this.focusedCell.col + 1)].reduce((acc, _, c0) => {
974
- return acc + this.colSize(c0, 'grid') + gap;
975
- }, -this.sizeInline) - gap,
976
- );
988
+ this.posInline = this.clampPosInline(this.inlineOffset(this.focusedCell.col + 1, 'grid') - this.sizeInline - gap);
977
989
  this.updateVisInline();
978
990
  }
979
991
 
980
992
  if (outOfVis.row < 0) {
981
993
  // align viewport start edge with focused cell start edge
982
- this.posBlock = this.clampPosBlock(
983
- [...Array(this.focusedCell.row)].reduce((acc, _, r0) => {
984
- return acc + this.rowSize(r0, 'grid') + gap;
985
- }, 0),
986
- );
994
+ this.posBlock = this.clampPosBlock(this.blockOffset(this.focusedCell.row, 'grid'));
987
995
  this.updateVisBlock();
988
996
  } else if (outOfVis.row > 0) {
989
997
  // align viewport end edge with focused cell end edge
990
- this.posBlock = this.clampPosBlock(
991
- [...Array(this.focusedCell.row + 1)].reduce((acc, _, r0) => {
992
- return acc + this.rowSize(r0, 'grid') + gap;
993
- }, -this.sizeBlock) - gap,
994
- );
998
+ this.posBlock = this.clampPosBlock(this.blockOffset(this.focusedCell.row + 1, 'grid') - this.sizeBlock - gap);
995
999
  this.updateVisBlock();
996
1000
  }
997
1001
  }
998
1002
 
1003
+ scrollToCoord({ coords }: { coords: DxGridPosition }) {
1004
+ const plane = coords.plane;
1005
+ const { row, col } = coords;
1006
+
1007
+ this.updatePosBlock(this.blockOffset(row, plane));
1008
+ this.updatePosInline(this.inlineOffset(col, plane));
1009
+ }
1010
+
1011
+ scrollToColumn(col: number) {
1012
+ this.updatePosInline(this.inlineOffset(col, 'grid'));
1013
+ }
1014
+
1015
+ scrollToRow(row: number) {
1016
+ this.updatePosBlock(this.blockOffset(row, 'grid'));
1017
+ }
1018
+
999
1019
  //
1000
1020
  // Map scroll DOM methods to virtualized value.
1001
1021
  //
@@ -1490,6 +1510,14 @@ export class DxGrid extends LitElement {
1490
1510
  }
1491
1511
  }
1492
1512
 
1493
- export { rowToA1Notation, colToA1Notation, closestAction, closestCell } from './util';
1513
+ export {
1514
+ rowToA1Notation,
1515
+ colToA1Notation,
1516
+ closestAction,
1517
+ closestCell,
1518
+ parseCellIndex,
1519
+ toPlaneCellIndex,
1520
+ cellQuery,
1521
+ } from './util';
1494
1522
 
1495
1523
  export const commentedClassName = 'dx-grid__cell--commented';
@@ -37,6 +37,10 @@ export class DxGridManager {
37
37
  );
38
38
  }
39
39
 
40
+ mode() {
41
+ return this.grid.locator('.dx-grid').getAttribute('data-grid-mode');
42
+ }
43
+
40
44
  panByWheel(deltaX: number, deltaY: number) {
41
45
  return this.grid.locator('.dx-grid [data-dx-grid-plane="grid"]').dispatchEvent('wheel', { deltaX, deltaY });
42
46
  }
package/src/types.ts CHANGED
@@ -154,7 +154,7 @@ export class DxAxisResizeInternal extends Event {
154
154
  export type DxEditRequestProps = Pick<DxEditRequest, 'cellIndex' | 'cellBox' | 'initialContent'>;
155
155
 
156
156
  export class DxEditRequest extends Event {
157
- public readonly cellIndex: DxGridPlaneCellIndex;
157
+ public readonly cellIndex: DxGridCellIndex;
158
158
  public readonly cellBox: Record<'insetInlineStart' | 'insetBlockStart' | 'inlineSize' | 'blockSize', number>;
159
159
  public readonly initialContent?: string;
160
160
  constructor(props: DxEditRequestProps) {
package/src/util.ts CHANGED
@@ -22,6 +22,27 @@ import {
22
22
  export const toPlaneCellIndex = (cellCoords: Partial<DxGridPosition> & DxGridPlanePosition): DxGridPlaneCellIndex =>
23
23
  `${cellCoords.col}${separator}${cellCoords.row}`;
24
24
 
25
+ export function parseCellIndex(index: DxGridCellIndex): DxGridPosition;
26
+ export function parseCellIndex(index: DxGridPlaneCellIndex): DxGridPlanePosition;
27
+ // eslint-disable-next-line @stayradiated/prefer-arrow-functions/prefer-arrow-functions
28
+ export function parseCellIndex(index: DxGridPlaneCellIndex | DxGridCellIndex): DxGridPlanePosition | DxGridPosition {
29
+ const coords = index.split(separator);
30
+ if (coords.length === 3) {
31
+ return {
32
+ plane: coords[0] as DxGridPlane,
33
+ col: parseInt(coords[1]),
34
+ row: parseInt(coords[2]),
35
+ } satisfies DxGridPosition;
36
+ } else {
37
+ return { col: parseInt(coords[0]), row: parseInt(coords[1]) } satisfies DxGridPlanePosition;
38
+ }
39
+ }
40
+
41
+ export const cellQuery = (index: DxGridCellIndex, gridId: string) => {
42
+ const { plane, col, row } = parseCellIndex(index);
43
+ return `[data-grid="${gridId}"] [data-dx-grid-plane="${plane}"] [aria-colindex="${col}"][aria-rowindex="${row}"]`;
44
+ };
45
+
25
46
  export const toCellIndex = (cellCoords: DxGridPosition): DxGridCellIndex =>
26
47
  `${cellCoords.plane}${separator}${cellCoords.col}${separator}${cellCoords.row}`;
27
48