@dxos/lit-grid 0.8.2-staging.7ac8446 → 0.8.2-staging.8c95c61

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 (47) hide show
  1. package/dist/src/defs.d.ts +2 -2
  2. package/dist/src/defs.d.ts.map +1 -1
  3. package/dist/src/defs.js +2 -5
  4. package/dist/src/defs.js.map +1 -1
  5. package/dist/src/dx-grid-axis-resize-handle.d.ts.map +1 -1
  6. package/dist/src/dx-grid-multiselect-cell.d.ts.map +1 -1
  7. package/dist/src/dx-grid.d.ts.map +1 -1
  8. package/dist/src/dx-grid.js +16 -12
  9. package/dist/src/dx-grid.js.map +1 -1
  10. package/dist/src/dx-grid.lit-stories.js +4 -4
  11. package/dist/src/testing/playwright/dx-grid-manager.d.ts.map +1 -1
  12. package/dist/src/types.d.ts +2 -1
  13. package/dist/src/types.d.ts.map +1 -1
  14. package/dist/src/types.js +1 -0
  15. package/dist/src/types.js.map +1 -1
  16. package/dist/src/util.d.ts.map +1 -1
  17. package/dist/src/util.js +3 -3
  18. package/dist/src/util.js.map +1 -1
  19. package/dist/tsconfig.tsbuildinfo +1 -1
  20. package/dist/types/src/defs.d.ts +2 -2
  21. package/dist/types/src/defs.d.ts.map +1 -1
  22. package/dist/types/src/defs.js +2 -5
  23. package/dist/types/src/defs.js.map +1 -1
  24. package/dist/types/src/dx-grid-axis-resize-handle.d.ts.map +1 -1
  25. package/dist/types/src/dx-grid-multiselect-cell.d.ts.map +1 -1
  26. package/dist/types/src/dx-grid.d.ts.map +1 -1
  27. package/dist/types/src/dx-grid.js +16 -12
  28. package/dist/types/src/dx-grid.js.map +1 -1
  29. package/dist/types/src/dx-grid.lit-stories.js +4 -4
  30. package/dist/types/src/testing/playwright/dx-grid-manager.d.ts.map +1 -1
  31. package/dist/types/src/types.d.ts +2 -1
  32. package/dist/types/src/types.d.ts.map +1 -1
  33. package/dist/types/src/types.js +1 -0
  34. package/dist/types/src/types.js.map +1 -1
  35. package/dist/types/src/util.d.ts.map +1 -1
  36. package/dist/types/src/util.js +3 -3
  37. package/dist/types/src/util.js.map +1 -1
  38. package/dist/types/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +2 -2
  40. package/src/defs.ts +2 -6
  41. package/src/dx-grid-axis-resize-handle.ts +4 -4
  42. package/src/dx-grid-multiselect-cell.ts +1 -1
  43. package/src/dx-grid.lit-stories.ts +4 -4
  44. package/src/dx-grid.ts +68 -66
  45. package/src/testing/playwright/dx-grid-manager.ts +11 -11
  46. package/src/types.ts +3 -1
  47. package/src/util.ts +4 -4
package/src/dx-grid.ts CHANGED
@@ -8,7 +8,7 @@ import { ref, createRef, type Ref } from 'lit/directives/ref.js';
8
8
  import { styleMap } from 'lit/directives/style-map.js';
9
9
  import { unsafeStatic, html as staticHtml } from 'lit/static-html.js';
10
10
 
11
- import { defaultSizeCol, defaultSizeRow } from './defs';
11
+ import { defaultColSize, defaultRowSize } from './defs';
12
12
  // eslint-disable-next-line unused-imports/no-unused-imports
13
13
  import './dx-grid-axis-resize-handle';
14
14
  import {
@@ -85,12 +85,12 @@ export class DxGrid extends LitElement {
85
85
 
86
86
  @property({ type: Object })
87
87
  rowDefault: DxGridPlaneRecord<DxGridFrozenRowsPlane, DxGridAxisMetaProps> = {
88
- grid: { size: defaultSizeRow },
88
+ grid: { size: defaultRowSize },
89
89
  };
90
90
 
91
91
  @property({ type: Object })
92
92
  columnDefault: DxGridPlaneRecord<DxGridFrozenColsPlane, DxGridAxisMetaProps> = {
93
- grid: { size: defaultSizeCol },
93
+ grid: { size: defaultColSize },
94
94
  };
95
95
 
96
96
  @property({ type: Object })
@@ -167,13 +167,13 @@ export class DxGrid extends LitElement {
167
167
  private binInlineMin = 0;
168
168
 
169
169
  @state()
170
- private binInlineMax = defaultSizeCol;
170
+ private binInlineMax = defaultColSize;
171
171
 
172
172
  @state()
173
173
  private binBlockMin = 0;
174
174
 
175
175
  @state()
176
- private binBlockMax = defaultSizeRow;
176
+ private binBlockMax = defaultRowSize;
177
177
 
178
178
  //
179
179
  // `vis`, short for ‘visible’, is the range in numeric index of the columns or rows which should be rendered within
@@ -258,23 +258,25 @@ export class DxGrid extends LitElement {
258
258
  // Primary pointer and keyboard handlers
259
259
  //
260
260
 
261
- private dispatchEditRequest(initialContent?: string) {
261
+ private dispatchEditRequest(initialContent?: string): void {
262
262
  this.snapPosToFocusedCell();
263
263
  if (!this.cellReadonly(this.focusedCell.col, this.focusedCell.row, this.focusedCell.plane)) {
264
264
  // Without deferring, the event dispatches before `focusedCellBox` can get updated bounds of the cell, hence:
265
- queueMicrotask(() =>
266
- this.dispatchEvent(
265
+ queueMicrotask(() => {
266
+ const cellIndex = toCellIndex(this.focusedCell);
267
+ return this.dispatchEvent(
267
268
  new DxEditRequest({
268
- cellIndex: toCellIndex(this.focusedCell),
269
+ cellIndex,
269
270
  cellBox: this.focusedCellBox(),
271
+ cellElement: this.focusedCellElement(),
270
272
  initialContent,
271
273
  }),
272
- ),
273
- );
274
+ );
275
+ });
274
276
  }
275
277
  }
276
278
 
277
- private dispatchSelectionChange() {
279
+ private dispatchSelectionChange(): boolean {
278
280
  return this.dispatchEvent(
279
281
  new DxGridCellsSelect({
280
282
  start: this.selectionStart,
@@ -353,7 +355,7 @@ export class DxGrid extends LitElement {
353
355
  * Increments focus among all theoretically possible cells in a plane, cycling as tab would but accounting for the
354
356
  * theoretical bounds of the grid plane (handling infinite planes heuristically).
355
357
  */
356
- private incrementFocusWithinPlane(event: KeyboardEvent) {
358
+ private incrementFocusWithinPlane(event: KeyboardEvent): void {
357
359
  const reverse = event.shiftKey;
358
360
  const colPlane = resolveColPlane(this.focusedCell.plane);
359
361
  const rowPlane = resolveRowPlane(this.focusedCell.plane);
@@ -381,7 +383,7 @@ export class DxGrid extends LitElement {
381
383
  /**
382
384
  * Increments focus in a specific direction without cycling.
383
385
  */
384
- private moveFocusOrSelectionEndWithinPlane(event: KeyboardEvent) {
386
+ private moveFocusOrSelectionEndWithinPlane(event: KeyboardEvent): void {
385
387
  const current = event.shiftKey ? this.selectionEnd : this.focusedCell;
386
388
  const deltaCol = event.key === 'ArrowLeft' ? -1 : event.key === 'ArrowRight' ? 1 : 0;
387
389
  const deltaRow = event.key === 'ArrowUp' ? -1 : event.key === 'ArrowDown' ? 1 : 0;
@@ -396,7 +398,7 @@ export class DxGrid extends LitElement {
396
398
  }
397
399
  }
398
400
 
399
- private moveFocusBetweenPlanes(event: KeyboardEvent, plane: DxGridPlane) {
401
+ private moveFocusBetweenPlanes(event: KeyboardEvent, plane: DxGridPlane): void {
400
402
  const planeElement = this.gridRef.value?.querySelector(`[data-dx-grid-plane="${plane}"]`) as HTMLElement | null;
401
403
  if (planeElement) {
402
404
  const axis = event.key === 'ArrowUp' || event.key === 'ArrowDown' ? 'col' : 'row';
@@ -413,7 +415,7 @@ export class DxGrid extends LitElement {
413
415
  }
414
416
  }
415
417
 
416
- private moveFocusIntoPlane(plane: DxGridPlane) {
418
+ private moveFocusIntoPlane(plane: DxGridPlane): void {
417
419
  if (this.focusedCell.plane !== plane) {
418
420
  const colPlane = resolveColPlane(plane);
419
421
  const rowPlane = resolveRowPlane(plane);
@@ -426,11 +428,11 @@ export class DxGrid extends LitElement {
426
428
  this.focusedCellElement()?.focus({ preventScroll: true });
427
429
  }
428
430
 
429
- private moveFocusToPlane() {
431
+ private moveFocusToPlane(): void {
430
432
  this.focusedPlaneElement()?.focus({ preventScroll: true });
431
433
  }
432
434
 
433
- private handleKeydown(event: KeyboardEvent) {
435
+ private handleKeydown(event: KeyboardEvent): void {
434
436
  if (this.focusActive && this.mode === 'browse') {
435
437
  const plane = targetIsPlane(event.target);
436
438
  if (plane) {
@@ -493,14 +495,14 @@ export class DxGrid extends LitElement {
493
495
  // Accessors
494
496
  //
495
497
 
496
- private colSize(c: number | string, plane: DxGridPlane) {
498
+ private colSize(c: number | string, plane: DxGridPlane): number {
497
499
  const resolvedPlane = resolveColPlane(plane);
498
- return this.colSizes?.[resolvedPlane]?.[c] ?? this.columnDefault[resolvedPlane]?.size ?? defaultSizeCol;
500
+ return this.colSizes?.[resolvedPlane]?.[c] ?? this.columnDefault[resolvedPlane]?.size ?? defaultColSize;
499
501
  }
500
502
 
501
- private rowSize(r: number | string, plane: DxGridPlane) {
503
+ private rowSize(r: number | string, plane: DxGridPlane): number {
502
504
  const resolvedPlane = resolveRowPlane(plane);
503
- return this.rowSizes?.[resolvedPlane]?.[r] ?? this.rowDefault[resolvedPlane]?.size ?? defaultSizeRow;
505
+ return this.rowSizes?.[resolvedPlane]?.[r] ?? this.rowDefault[resolvedPlane]?.size ?? defaultRowSize;
504
506
  }
505
507
 
506
508
  private cell(c: number | string, r: number | string, plane: DxGridPlane): DxGridCellValue | undefined {
@@ -512,7 +514,7 @@ export class DxGrid extends LitElement {
512
514
  return this.focusedCell.plane === plane && this.focusedCell.col === c && this.focusedCell.row === r;
513
515
  }
514
516
 
515
- private setFocusedCell(nextCoords: DxGridPosition) {
517
+ private setFocusedCell(nextCoords: DxGridPosition): void {
516
518
  if (
517
519
  this.focusedCell.plane !== nextCoords.plane ||
518
520
  this.focusedCell.col !== nextCoords.col ||
@@ -528,7 +530,7 @@ export class DxGrid extends LitElement {
528
530
 
529
531
  // Internal utility for setting selection end.
530
532
 
531
- private setSelectionEnd(nextCoords: DxGridPosition) {
533
+ private setSelectionEnd(nextCoords: DxGridPosition): void {
532
534
  if (
533
535
  this.selectionEnd.plane !== nextCoords.plane ||
534
536
  this.selectionEnd.col !== nextCoords.col ||
@@ -541,7 +543,7 @@ export class DxGrid extends LitElement {
541
543
 
542
544
  // Selection setter for consumers
543
545
 
544
- setSelection(range: DxGridRange) {
546
+ setSelection(range: DxGridRange): void {
545
547
  if (this.mode !== 'edit') {
546
548
  this.selectionStart = range.start;
547
549
  this.selectionEnd = range.end;
@@ -608,25 +610,25 @@ export class DxGrid extends LitElement {
608
610
  }
609
611
  };
610
612
 
611
- private maxPosInline() {
613
+ private maxPosInline(): number {
612
614
  return this.intrinsicInlineSize - this.sizeInline;
613
615
  }
614
616
 
615
- private maxPosBlock() {
617
+ private maxPosBlock(): number {
616
618
  return this.intrinsicBlockSize - this.sizeBlock;
617
619
  }
618
620
 
619
- private updatePosInline(inline?: number, maxInline: number = this.maxPosInline()) {
621
+ private updatePosInline(inline?: number, maxInline: number = this.maxPosInline()): void {
620
622
  this.posInline = Math.max(0, Math.min(maxInline, inline ?? this.posInline));
621
623
  this.maybeUpdateVisInline();
622
624
  }
623
625
 
624
- private updatePosBlock(block?: number, maxBlock: number = this.maxPosBlock()) {
626
+ private updatePosBlock(block?: number, maxBlock: number = this.maxPosBlock()): void {
625
627
  this.posBlock = Math.max(0, Math.min(maxBlock, block ?? this.posBlock));
626
628
  this.maybeUpdateVisBlock();
627
629
  }
628
630
 
629
- private updatePos(inline?: number, block?: number, maxInline?: number, maxBlock?: number) {
631
+ private updatePos(inline?: number, block?: number, maxInline?: number, maxBlock?: number): void {
630
632
  this.updatePosInline(inline, maxInline);
631
633
  this.updatePosBlock(block, maxBlock);
632
634
  }
@@ -659,7 +661,7 @@ export class DxGrid extends LitElement {
659
661
  }
660
662
  };
661
663
 
662
- private updateVisInline() {
664
+ private updateVisInline(): void {
663
665
  // todo: avoid starting from zero
664
666
  let axisCursor = 0;
665
667
  let pxCursor = this.colSize(axisCursor, 'grid');
@@ -708,7 +710,7 @@ export class DxGrid extends LitElement {
708
710
  .join(' ');
709
711
  }
710
712
 
711
- private updateVisBlock() {
713
+ private updateVisBlock(): void {
712
714
  // todo: avoid starting from zero
713
715
  let axisCursor = 0;
714
716
  let pxCursor = this.rowSize(axisCursor, 'grid');
@@ -757,12 +759,12 @@ export class DxGrid extends LitElement {
757
759
  .join(' ');
758
760
  }
759
761
 
760
- private updateVis() {
762
+ private updateVis(): void {
761
763
  this.updateVisInline();
762
764
  this.updateVisBlock();
763
765
  }
764
766
 
765
- public updateCells(includeFixed?: boolean) {
767
+ public updateCells(includeFixed?: boolean): void {
766
768
  this.cells.grid = this.getCells!(
767
769
  {
768
770
  start: { col: this.visColMin, row: this.visRowMin },
@@ -828,7 +830,7 @@ export class DxGrid extends LitElement {
828
830
 
829
831
  // Focus handlers
830
832
 
831
- setFocus(coords: DxGridPosition, snap = true) {
833
+ setFocus(coords: DxGridPosition, snap = true): void {
832
834
  this.setFocusedCell(coords);
833
835
  this.focusActive = true;
834
836
  if (snap) {
@@ -836,7 +838,7 @@ export class DxGrid extends LitElement {
836
838
  }
837
839
  }
838
840
 
839
- private handleFocus(event: FocusEvent) {
841
+ private handleFocus(event: FocusEvent): void {
840
842
  const cellCoords = closestCell(event.target);
841
843
  if (cellCoords || targetIsPlane(event.target)) {
842
844
  this.focusActive = true;
@@ -846,26 +848,26 @@ export class DxGrid extends LitElement {
846
848
  }
847
849
  }
848
850
 
849
- private handleBlur(event: FocusEvent) {
851
+ private handleBlur(event: FocusEvent): void {
850
852
  // Only unset `focusActive` if focus is moving to an element outside the grid.
851
853
  if (event.relatedTarget && !(event.relatedTarget as HTMLElement).closest(`[data-grid="${this.gridId}"]`)) {
852
854
  this.focusActive = false;
853
855
  }
854
856
  }
855
857
 
856
- private focusedCellQuery() {
858
+ private focusedCellQuery(): string {
857
859
  return `[data-dx-grid-plane=${this.focusedCell.plane}] [aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`;
858
860
  }
859
861
 
860
- private focusedPlaneQuery() {
862
+ private focusedPlaneQuery(): string {
861
863
  return `[data-dx-grid-plane=${this.focusedCell.plane}]`;
862
864
  }
863
865
 
864
- private focusedCellElement() {
866
+ private focusedCellElement(): HTMLElement | null {
865
867
  return this.gridRef.value?.querySelector(this.focusedCellQuery()) as HTMLElement | null;
866
868
  }
867
869
 
868
- private focusedPlaneElement() {
870
+ private focusedPlaneElement(): HTMLElement | null {
869
871
  return this.gridRef.value?.querySelector(this.focusedPlaneQuery()) as HTMLElement | null;
870
872
  }
871
873
 
@@ -874,7 +876,7 @@ export class DxGrid extends LitElement {
874
876
  // `delta`, otherwise zero if it is within that range.
875
877
  //
876
878
 
877
- private focusedCellRowOutOfVis() {
879
+ private focusedCellRowOutOfVis(): number {
878
880
  return this.focusedCell.row <= this.visRowMin
879
881
  ? this.focusedCell.row - this.visRowMin - 1
880
882
  : this.focusedCell.row >= this.visRowMax - 1
@@ -882,7 +884,7 @@ export class DxGrid extends LitElement {
882
884
  : 0;
883
885
  }
884
886
 
885
- private focusedCellColOutOfVis() {
887
+ private focusedCellColOutOfVis(): number {
886
888
  return this.focusedCell.col <= this.visColMin
887
889
  ? this.focusedCell.col - this.visColMin - 1
888
890
  : this.focusedCell.col >= this.visColMax - 1
@@ -905,13 +907,13 @@ export class DxGrid extends LitElement {
905
907
  }
906
908
  }
907
909
 
908
- private clampCol(coords: DxGridPosition, deltaCol = 0) {
910
+ private clampCol(coords: DxGridPosition, deltaCol = 0): number {
909
911
  const colPlane = resolveColPlane(coords.plane);
910
912
  const colMax = (colPlane === 'grid' ? this.limitColumns : this.frozen[colPlane]!) - 1;
911
913
  return Math.max(0, Math.min(colMax, coords.col + deltaCol));
912
914
  }
913
915
 
914
- private clampRow(coords: DxGridPosition, deltaRow = 0) {
916
+ private clampRow(coords: DxGridPosition, deltaRow = 0): number {
915
917
  const rowPlane = resolveRowPlane(coords.plane);
916
918
  const rowMax = (rowPlane === 'grid' ? this.limitRows : this.frozen[rowPlane]!) - 1;
917
919
  return Math.max(0, Math.min(rowMax, coords.row + deltaRow));
@@ -920,7 +922,7 @@ export class DxGrid extends LitElement {
920
922
  /**
921
923
  * Moves focus to the cell with actual focus, otherwise moves focus to the viewport.
922
924
  */
923
- refocus(increment: 'col' | 'row' | undefined = undefined, delta: 1 | -1 | 0 = 1) {
925
+ refocus(increment: 'col' | 'row' | undefined = undefined, delta: 1 | -1 | 0 = 1): void {
924
926
  if (increment) {
925
927
  switch (increment) {
926
928
  case 'col': {
@@ -947,11 +949,11 @@ export class DxGrid extends LitElement {
947
949
  });
948
950
  }
949
951
 
950
- private clampPosInline(nextPos: number) {
952
+ private clampPosInline(nextPos: number): number {
951
953
  return Math.max(0, Math.min(this.intrinsicInlineSize - this.sizeInline, nextPos));
952
954
  }
953
955
 
954
- private clampPosBlock(nextPos: number) {
956
+ private clampPosBlock(nextPos: number): number {
955
957
  return Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, nextPos));
956
958
  }
957
959
 
@@ -978,7 +980,7 @@ export class DxGrid extends LitElement {
978
980
  /**
979
981
  * Updates `pos` so that a cell in focus is fully within the viewport
980
982
  */
981
- snapPosToFocusedCell() {
983
+ snapPosToFocusedCell(): void {
982
984
  const outOfVis = this.focusedCellOutOfVis();
983
985
  if (outOfVis.col < 0) {
984
986
  // align viewport start edge with focused cell start edge
@@ -1001,7 +1003,7 @@ export class DxGrid extends LitElement {
1001
1003
  }
1002
1004
  }
1003
1005
 
1004
- scrollToCoord({ coords }: { coords: DxGridPosition }) {
1006
+ scrollToCoord({ coords }: { coords: DxGridPosition }): void {
1005
1007
  const plane = coords.plane;
1006
1008
  const { row, col } = coords;
1007
1009
 
@@ -1009,15 +1011,15 @@ export class DxGrid extends LitElement {
1009
1011
  this.updatePosInline(this.inlineOffset(col, plane));
1010
1012
  }
1011
1013
 
1012
- scrollToColumn(col: number) {
1014
+ scrollToColumn(col: number): void {
1013
1015
  this.updatePosInline(this.inlineOffset(col, 'grid'));
1014
1016
  }
1015
1017
 
1016
- scrollToRow(row: number) {
1018
+ scrollToRow(row: number): void {
1017
1019
  this.updatePosBlock(this.blockOffset(row, 'grid'));
1018
1020
  }
1019
1021
 
1020
- scrollToEndRow() {
1022
+ scrollToEndRow(): void {
1021
1023
  this.updatePosBlock(Infinity);
1022
1024
  }
1023
1025
 
@@ -1047,13 +1049,13 @@ export class DxGrid extends LitElement {
1047
1049
  // Resize handlers
1048
1050
  //
1049
1051
 
1050
- private axisResizeable(plane: 'grid' | DxGridFrozenPlane, axis: DxGridAxis, index: number | string) {
1052
+ private axisResizeable(plane: 'grid' | DxGridFrozenPlane, axis: DxGridAxis, index: number | string): boolean {
1051
1053
  return axis === 'col'
1052
1054
  ? !!(this.columns[plane]?.[index]?.resizeable ?? this.columnDefault[plane as DxGridFrozenColsPlane]?.resizeable)
1053
1055
  : !!(this.rows[plane]?.[index]?.resizeable ?? this.rowDefault[plane as DxGridFrozenRowsPlane]?.resizeable);
1054
1056
  }
1055
1057
 
1056
- private handleAxisResizeInternal(event: DxAxisResizeInternal) {
1058
+ private handleAxisResizeInternal(event: DxAxisResizeInternal): void {
1057
1059
  event.stopPropagation();
1058
1060
  const { plane, axis, delta, size, index, state } = event;
1059
1061
  if (axis === 'col') {
@@ -1223,7 +1225,7 @@ export class DxGrid extends LitElement {
1223
1225
  : null;
1224
1226
  }
1225
1227
 
1226
- private cellReadonly(col: number, row: number, plane: DxGridPlane) {
1228
+ private cellReadonly(col: number, row: number, plane: DxGridPlane): boolean {
1227
1229
  const colPlane = resolveColPlane(plane);
1228
1230
  const rowPlane = resolveRowPlane(plane);
1229
1231
 
@@ -1382,7 +1384,7 @@ export class DxGrid extends LitElement {
1382
1384
  </div>`;
1383
1385
  }
1384
1386
 
1385
- private updateIntrinsicInlineSize() {
1387
+ private updateIntrinsicInlineSize(): void {
1386
1388
  this.intrinsicInlineSize = Number.isFinite(this.limitColumns)
1387
1389
  ? [...Array(this.limitColumns)].reduce((acc, _, c0) => acc + this.colSize(c0, 'grid'), 0) +
1388
1390
  gap * (this.limitColumns - 1)
@@ -1400,7 +1402,7 @@ export class DxGrid extends LitElement {
1400
1402
  : 0);
1401
1403
  }
1402
1404
 
1403
- private updateIntrinsicBlockSize() {
1405
+ private updateIntrinsicBlockSize(): void {
1404
1406
  this.intrinsicBlockSize = Number.isFinite(this.limitRows)
1405
1407
  ? [...Array(this.limitRows)].reduce((acc, _, r0) => acc + this.rowSize(r0, 'grid'), 0) +
1406
1408
  gap * (this.limitRows - 1)
@@ -1418,12 +1420,12 @@ export class DxGrid extends LitElement {
1418
1420
  : 0);
1419
1421
  }
1420
1422
 
1421
- private updateIntrinsicSizes() {
1423
+ private updateIntrinsicSizes(): void {
1422
1424
  this.updateIntrinsicInlineSize();
1423
1425
  this.updateIntrinsicBlockSize();
1424
1426
  }
1425
1427
 
1426
- private computeColSizes() {
1428
+ private computeColSizes(): void {
1427
1429
  this.colSizes = Object.entries(this.columns ?? {}).reduce(
1428
1430
  (acc: DxGridAxisSizes, [plane, planeColMeta]) => {
1429
1431
  acc[plane as 'grid' | DxGridFrozenPlane] = Object.entries(planeColMeta).reduce(
@@ -1441,7 +1443,7 @@ export class DxGrid extends LitElement {
1441
1443
  );
1442
1444
  }
1443
1445
 
1444
- private computeRowSizes() {
1446
+ private computeRowSizes(): void {
1445
1447
  this.rowSizes = Object.entries(this.rows ?? {}).reduce(
1446
1448
  (acc: DxGridAxisSizes, [plane, planeRowMeta]) => {
1447
1449
  acc[plane as 'grid' | DxGridFrozenPlane] = Object.entries(planeRowMeta).reduce(
@@ -1459,7 +1461,7 @@ export class DxGrid extends LitElement {
1459
1461
  );
1460
1462
  }
1461
1463
 
1462
- override firstUpdated() {
1464
+ override firstUpdated(): void {
1463
1465
  if (this.getCells) {
1464
1466
  this.updateCells(true);
1465
1467
  }
@@ -1469,7 +1471,7 @@ export class DxGrid extends LitElement {
1469
1471
  this.updateIntrinsicSizes();
1470
1472
  }
1471
1473
 
1472
- override willUpdate(changedProperties: Map<string, any>) {
1474
+ override willUpdate(changedProperties: Map<string, any>): void {
1473
1475
  if (changedProperties.has('rowDefault') || changedProperties.has('rows') || changedProperties.has('limitRows')) {
1474
1476
  this.computeRowSizes();
1475
1477
  this.updateIntrinsicBlockSize();
@@ -1504,7 +1506,7 @@ export class DxGrid extends LitElement {
1504
1506
  }
1505
1507
  }
1506
1508
 
1507
- override updated(changedProperties: Map<string, any>) {
1509
+ override updated(changedProperties: Map<string, any>): void {
1508
1510
  // Update the focused element if there is a change in bounds (otherwise Lit keeps focus on the relative element).
1509
1511
  if (
1510
1512
  this.focusActive &&
@@ -1526,7 +1528,7 @@ export class DxGrid extends LitElement {
1526
1528
  return false;
1527
1529
  }
1528
1530
 
1529
- override disconnectedCallback() {
1531
+ override disconnectedCallback(): void {
1530
1532
  super.disconnectedCallback();
1531
1533
  if (this.viewportRef.value) {
1532
1534
  this.observer.unobserve(this.viewportRef.value);
@@ -1534,7 +1536,7 @@ export class DxGrid extends LitElement {
1534
1536
  document.defaultView?.removeEventListener('wheel', this.handleTopLevelWheel);
1535
1537
  }
1536
1538
 
1537
- override createRenderRoot() {
1539
+ override createRenderRoot(): this {
1538
1540
  return this;
1539
1541
  }
1540
1542
  }
@@ -19,29 +19,29 @@ export class DxGridManager {
19
19
  grid: Locator;
20
20
  page: Page;
21
21
 
22
- async ready() {
22
+ async ready(): Promise<void> {
23
23
  return this.grid.locator('.dx-grid').waitFor({ state: 'visible' });
24
24
  }
25
25
 
26
- planes() {
26
+ planes(): Locator {
27
27
  return this.grid.locator('.dx-grid [data-dx-grid-plane]');
28
28
  }
29
29
 
30
- cellsWithinPlane(plane: string) {
30
+ cellsWithinPlane(plane: string): Locator {
31
31
  return this.grid.locator(`.dx-grid [data-dx-grid-plane="${plane}"]`).getByRole('gridcell');
32
32
  }
33
33
 
34
- cell(col: number, row: number, plane: string) {
34
+ cell(col: number, row: number, plane: string): Locator {
35
35
  return this.grid.locator(
36
36
  `.dx-grid [data-dx-grid-plane="${plane}"] [aria-colindex="${col}"][aria-rowindex="${row}"]`,
37
37
  );
38
38
  }
39
39
 
40
- mode() {
40
+ mode(): Promise<string | null> {
41
41
  return this.grid.locator('.dx-grid').getAttribute('data-grid-mode');
42
42
  }
43
43
 
44
- panByWheel(deltaX: number, deltaY: number) {
44
+ panByWheel(deltaX: number, deltaY: number): Promise<void> {
45
45
  return this.grid.locator('.dx-grid [data-dx-grid-plane="grid"]').dispatchEvent('wheel', { deltaX, deltaY });
46
46
  }
47
47
 
@@ -49,7 +49,7 @@ export class DxGridManager {
49
49
  start: DxGridPlanePosition,
50
50
  end: DxGridPlanePosition,
51
51
  iterator: (col: number, row: number) => Promise<void>,
52
- ) {
52
+ ): Promise<void> {
53
53
  const nCols = 1 + end.col - start.col;
54
54
  const nRows = 1 + end.row - start.row;
55
55
 
@@ -64,13 +64,13 @@ export class DxGridManager {
64
64
  );
65
65
  }
66
66
 
67
- async expectSelectionResult(start: DxGridPlanePosition, end: DxGridPlanePosition) {
67
+ async expectSelectionResult(start: DxGridPlanePosition, end: DxGridPlanePosition): Promise<void> {
68
68
  return this.forCellsInRange(start, end, (col, row) =>
69
69
  expect(this.cell(col, row, 'grid')).toHaveAttribute('aria-selected', 'true'),
70
70
  );
71
71
  }
72
72
 
73
- async expectVirtualizationResult(cols: number, rows: number, minColIndex = 0, minRowIndex = 0) {
73
+ async expectVirtualizationResult(cols: number, rows: number, minColIndex = 0, minRowIndex = 0): Promise<void> {
74
74
  await this.cell(minColIndex, minRowIndex, 'grid').waitFor({ state: 'visible' });
75
75
  // Top planes
76
76
  await expect(this.cellsWithinPlane('fixedStartStart')).toHaveCount(4);
@@ -86,11 +86,11 @@ export class DxGridManager {
86
86
  await expect(this.cellsWithinPlane('fixedEndEnd')).toHaveCount(1);
87
87
  }
88
88
 
89
- async expectFocus(locator: Locator) {
89
+ async expectFocus(locator: Locator): Promise<void> {
90
90
  return expect(await locator.evaluate((node) => document.activeElement === node)).toBeTruthy();
91
91
  }
92
92
 
93
- listenForSelect() {
93
+ listenForSelect(): Promise<void> {
94
94
  return this.grid.evaluate(() => {
95
95
  document.querySelector('dx-grid')!.addEventListener('dx-grid-cells-select', (event) => {
96
96
  (window as any).DX_GRID_EVENT = event;
package/src/types.ts CHANGED
@@ -153,16 +153,18 @@ export class DxAxisResizeInternal extends Event {
153
153
  }
154
154
  }
155
155
 
156
- export type DxEditRequestProps = Pick<DxEditRequest, 'cellIndex' | 'cellBox' | 'initialContent'>;
156
+ export type DxEditRequestProps = Pick<DxEditRequest, 'cellIndex' | 'cellBox' | 'cellElement' | 'initialContent'>;
157
157
 
158
158
  export class DxEditRequest extends Event {
159
159
  public readonly cellIndex: DxGridCellIndex;
160
160
  public readonly cellBox: Record<'insetInlineStart' | 'insetBlockStart' | 'inlineSize' | 'blockSize', number>;
161
+ public readonly cellElement: HTMLElement | null;
161
162
  public readonly initialContent?: string;
162
163
  constructor(props: DxEditRequestProps) {
163
164
  super('dx-edit-request');
164
165
  this.cellIndex = props.cellIndex;
165
166
  this.cellBox = props.cellBox;
167
+ this.cellElement = props.cellElement;
166
168
  this.initialContent = props.initialContent;
167
169
  }
168
170
  }
package/src/util.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { defaultSizeRow } from './defs';
5
+ import { defaultRowSize } from './defs';
6
6
  import {
7
7
  type DxGridPlaneCellIndex,
8
8
  type DxGridCellIndex,
@@ -16,8 +16,8 @@ import {
16
16
  type DxGridFrozenPlane,
17
17
  type DxGridAxis,
18
18
  type DxGridPlanePosition,
19
- separator,
20
19
  type DxGridReadonlyValue,
20
+ separator,
21
21
  } from './types';
22
22
 
23
23
  export const toPlaneCellIndex = (cellCoords: Partial<DxGridPosition> & DxGridPlanePosition): DxGridPlaneCellIndex =>
@@ -80,9 +80,9 @@ export const selectTolerance = 4;
80
80
  //
81
81
  // `size`, when suffixed with ‘row’ or ‘col’, are limits on size applied when resizing
82
82
  //
83
- export const sizeColMin = defaultSizeRow;
83
+ export const sizeColMin = defaultRowSize;
84
84
  export const sizeColMax = 1024;
85
- export const sizeRowMin = defaultSizeRow;
85
+ export const sizeRowMin = defaultRowSize;
86
86
  export const sizeRowMax = 1024;
87
87
 
88
88
  export const shouldSelect = (pointer: DxGridPointer, { pageX, pageY }: PointerEvent) => {