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

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/src/dx-grid.ts CHANGED
@@ -3,26 +3,38 @@
3
3
  //
4
4
 
5
5
  import { LitElement, html, nothing } from 'lit';
6
- import { customElement, state, property, eventOptions } from 'lit/decorators.js';
6
+ import { customElement, state, property } from 'lit/decorators.js';
7
7
  import { ref, createRef, type Ref } from 'lit/directives/ref.js';
8
+ import { styleMap } from 'lit/directives/style-map.js';
8
9
 
9
10
  // eslint-disable-next-line unused-imports/no-unused-imports
10
11
  import './dx-grid-axis-resize-handle';
11
12
  import {
12
13
  type AxisMeta,
14
+ type AxisSizes,
13
15
  type CellIndex,
16
+ type DxGridCellValue,
14
17
  DxAxisResize,
15
18
  type DxAxisResizeInternal,
16
19
  DxEditRequest,
17
- type DxGridAxis,
18
20
  type DxGridAxisMeta,
19
21
  type DxGridCells,
20
22
  DxGridCellsSelect,
23
+ type DxGridFixedPlane,
24
+ type DxGridFrozenAxes,
25
+ type DxGridFrozenColsPlane,
26
+ type DxGridFrozenPlane,
27
+ type DxGridFrozenRowsPlane,
21
28
  type DxGridMode,
29
+ type DxGridPlane,
30
+ type DxGridPlaneCells,
31
+ type DxGridPlaneRange,
32
+ type DxGridPlaneRecord,
22
33
  type DxGridPointer,
23
34
  type DxGridPosition,
24
35
  type DxGridPositionNullable,
25
- type DxGridRange,
36
+ type DxGridAxis,
37
+ type DxGridSelectionProps,
26
38
  } from './types';
27
39
  import { separator, toCellIndex } from './util';
28
40
 
@@ -32,10 +44,14 @@ import { separator, toCellIndex } from './util';
32
44
  const gap = 1;
33
45
 
34
46
  /**
35
- * This should be about the width of the `1` numeral so resize is triggered as the row header column’s intrinsic size
36
- * changes when scrolling vertically.
47
+ * ResizeObserver notices even subpixel changes, only respond to changes of at least 1px.
48
+ */
49
+ const resizeTolerance = 1;
50
+
51
+ /**
52
+ * The amount of pixels the primary pointer has to move after PointerDown to engage in selection.
37
53
  */
38
- const resizeTolerance = 8;
54
+ const selectTolerance = 4;
39
55
 
40
56
  //
41
57
  // `overscan` is the number of columns or rows to render outside of the viewport
@@ -51,19 +67,32 @@ const sizeColMax = 1024;
51
67
  const sizeRowMin = 16;
52
68
  const sizeRowMax = 1024;
53
69
 
54
- //
55
- // A1 notation is the fallback for numbering columns and rows.
56
- //
70
+ const shouldSelect = (pointer: DxGridPointer, { pageX, pageY }: PointerEvent) => {
71
+ if (pointer?.state === 'maybeSelecting') {
72
+ return Math.hypot(Math.abs(pointer.pageX - pageX), Math.abs(pointer.pageY - pageY)) >= selectTolerance;
73
+ } else {
74
+ return false;
75
+ }
76
+ };
57
77
 
58
- const colToA1Notation = (col: number): string => {
59
- return (
60
- (col >= 26 ? String.fromCharCode('A'.charCodeAt(0) + Math.floor(col / 26) - 1) : '') +
61
- String.fromCharCode('A'.charCodeAt(0) + (col % 26))
62
- );
78
+ const selectionProps = (selectionStart: DxGridPosition, selectionEnd: DxGridPosition): DxGridSelectionProps => {
79
+ const colMin = Math.min(selectionStart.col, selectionEnd.col);
80
+ const colMax = Math.max(selectionStart.col, selectionEnd.col);
81
+ const rowMin = Math.min(selectionStart.row, selectionEnd.row);
82
+ const rowMax = Math.max(selectionStart.row, selectionEnd.row);
83
+ const plane = selectionStart.plane;
84
+ const visible = colMin !== colMax || rowMin !== rowMax;
85
+ return { colMin, colMax, rowMin, rowMax, plane, visible };
63
86
  };
64
87
 
65
- const rowToA1Notation = (row: number): string => {
66
- return `${row + 1}`;
88
+ const cellSelected = (col: number, row: number, plane: DxGridPlane, selection: DxGridSelectionProps): boolean => {
89
+ return (
90
+ plane === selection.plane &&
91
+ col >= selection.colMin &&
92
+ col <= selection.colMax &&
93
+ row >= selection.rowMin &&
94
+ row <= selection.rowMax
95
+ );
67
96
  };
68
97
 
69
98
  const closestAction = (target: EventTarget | null): { action: string | null; actionEl: HTMLElement | null } => {
@@ -82,26 +111,84 @@ const closestCell = (target: EventTarget | null, actionEl?: HTMLElement | null):
82
111
  if (cellElement) {
83
112
  const col = parseInt(cellElement.getAttribute('aria-colindex') ?? 'never');
84
113
  const row = parseInt(cellElement.getAttribute('aria-rowindex') ?? 'never');
85
- return { col, row };
114
+ const plane = (cellElement.closest('[data-dx-grid-plane]')?.getAttribute('data-dx-grid-plane') ??
115
+ 'grid') as DxGridPlane;
116
+ return { plane, col, row };
86
117
  } else {
87
118
  return null;
88
119
  }
89
120
  };
90
121
 
122
+ const resolveRowPlane = (plane: DxGridPlane): 'grid' | DxGridFrozenRowsPlane => {
123
+ switch (plane) {
124
+ case 'fixedStartStart':
125
+ case 'fixedStartEnd':
126
+ case 'frozenRowsStart':
127
+ return 'frozenRowsStart';
128
+ case 'fixedEndStart':
129
+ case 'fixedEndEnd':
130
+ case 'frozenRowsEnd':
131
+ return 'frozenRowsEnd';
132
+ default:
133
+ return 'grid';
134
+ }
135
+ };
136
+
137
+ const resolveColPlane = (plane: DxGridPlane): 'grid' | DxGridFrozenColsPlane => {
138
+ switch (plane) {
139
+ case 'fixedStartStart':
140
+ case 'fixedEndStart':
141
+ case 'frozenColsStart':
142
+ return 'frozenColsStart';
143
+ case 'fixedStartEnd':
144
+ case 'fixedEndEnd':
145
+ case 'frozenColsEnd':
146
+ return 'frozenColsEnd';
147
+ default:
148
+ return 'grid';
149
+ }
150
+ };
151
+
152
+ const resolveResizePlane = (resizeAxis: DxGridAxis, cellPlane: DxGridPlane): 'grid' | DxGridFrozenPlane => {
153
+ switch (cellPlane) {
154
+ case 'fixedStartStart':
155
+ return resizeAxis === 'col' ? 'frozenColsStart' : 'frozenRowsStart';
156
+ case 'fixedStartEnd':
157
+ return resizeAxis === 'col' ? 'frozenColsEnd' : 'frozenRowsStart';
158
+ case 'fixedEndStart':
159
+ return resizeAxis === 'col' ? 'frozenColsStart' : 'frozenRowsEnd';
160
+ case 'fixedEndEnd':
161
+ return resizeAxis === 'col' ? 'frozenColsEnd' : 'frozenRowsEnd';
162
+ case 'frozenColsStart':
163
+ case 'frozenColsEnd':
164
+ return resizeAxis === 'col' ? cellPlane : 'grid';
165
+ case 'frozenRowsStart':
166
+ case 'frozenRowsEnd':
167
+ return resizeAxis === 'row' ? cellPlane : 'grid';
168
+ default:
169
+ return cellPlane;
170
+ }
171
+ };
172
+
91
173
  const isSameCell = (a: DxGridPositionNullable, b: DxGridPositionNullable) =>
92
- a && b && Number.isFinite(a.col) && Number.isFinite(a.row) && a.col === b.col && a.row === b.row;
174
+ a &&
175
+ b &&
176
+ a.plane === b.plane &&
177
+ Number.isFinite(a.col) &&
178
+ Number.isFinite(a.row) &&
179
+ a.col === b.col &&
180
+ a.row === b.row;
93
181
 
94
- const localChId = (c0: number) => `ch--${c0}`;
95
- const localRhId = (r0: number) => `rh--${r0}`;
182
+ const defaultRowSize = 32;
96
183
 
97
- const getPage = (axis: string, event: PointerEvent) => (axis === 'col' ? event.pageX : event.pageY);
184
+ const defaultColSize = 180;
98
185
 
99
186
  @customElement('dx-grid')
100
187
  export class DxGrid extends LitElement {
101
188
  constructor() {
102
189
  super();
103
190
  this.addEventListener('dx-axis-resize-internal', this.handleAxisResizeInternal as EventListener);
104
- this.addEventListener('wheel', this.handleWheel);
191
+ this.addEventListener('wheel', this.handleWheel, { passive: true });
105
192
  this.addEventListener('pointerdown', this.handlePointerDown);
106
193
  this.addEventListener('pointermove', this.handlePointerMove);
107
194
  this.addEventListener('pointerup', this.handlePointerUp);
@@ -115,31 +202,44 @@ export class DxGrid extends LitElement {
115
202
  gridId: string = 'default-grid-id';
116
203
 
117
204
  @property({ type: Object })
118
- rowDefault: AxisMeta = { size: 32 };
205
+ rowDefault: DxGridPlaneRecord<DxGridFrozenRowsPlane, AxisMeta> = {
206
+ grid: { size: defaultRowSize },
207
+ };
119
208
 
120
209
  @property({ type: Object })
121
- columnDefault: AxisMeta = { size: 180 };
210
+ columnDefault: DxGridPlaneRecord<DxGridFrozenColsPlane, AxisMeta> = {
211
+ grid: { size: defaultColSize },
212
+ };
122
213
 
123
214
  @property({ type: Object })
124
- rows: DxGridAxisMeta = {};
215
+ rows: DxGridAxisMeta = { grid: {} };
125
216
 
126
217
  @property({ type: Object })
127
- columns: DxGridAxisMeta = {};
218
+ columns: DxGridAxisMeta = { grid: {} };
128
219
 
129
220
  @property({ type: Object })
130
- initialCells: DxGridCells = {};
221
+ initialCells: DxGridCells = { grid: {} };
131
222
 
132
223
  @property({ type: String })
133
224
  mode: DxGridMode = 'browse';
134
225
 
226
+ @property({ type: Number })
227
+ limitColumns: number = Infinity;
228
+
229
+ @property({ type: Number })
230
+ limitRows: number = Infinity;
231
+
232
+ @property({ type: Object })
233
+ frozen: DxGridFrozenAxes = {};
234
+
135
235
  /**
136
236
  * When this function is defined, it is used first to try to get a value for a cell, and otherwise will fall back
137
237
  * to `cells`.
138
238
  */
139
- getCells: ((nextRange: DxGridRange) => DxGridCells) | null = null;
239
+ getCells: ((nextRange: DxGridPlaneRange, plane: DxGridPlane) => DxGridPlaneCells) | null = null;
140
240
 
141
241
  @state()
142
- private cells: DxGridCells = {};
242
+ private cells: DxGridCells = { grid: {} };
143
243
 
144
244
  //
145
245
  // `pos`, short for ‘position’, is the position in pixels of the viewport from the origin.
@@ -179,13 +279,13 @@ export class DxGrid extends LitElement {
179
279
  private binInlineMin = 0;
180
280
 
181
281
  @state()
182
- private binInlineMax = this.colSize(0);
282
+ private binInlineMax = defaultColSize;
183
283
 
184
284
  @state()
185
285
  private binBlockMin = 0;
186
286
 
187
287
  @state()
188
- private binBlockMax = this.rowSize(0);
288
+ private binBlockMax = defaultRowSize;
189
289
 
190
290
  //
191
291
  // `vis`, short for ‘visible’, is the range in numeric index of the columns or rows which should be rendered within
@@ -208,10 +308,22 @@ export class DxGrid extends LitElement {
208
308
  // `template` is the rendered value of `grid-{axis}-template`.
209
309
  //
210
310
  @state()
211
- private templateColumns = `${this.colSize(0)}px`;
311
+ private templateGridColumns = '0';
312
+
313
+ @state()
314
+ private templatefrozenColsStart = '';
315
+
316
+ @state()
317
+ private templatefrozenColsEnd = '';
318
+
319
+ @state()
320
+ private templateGridRows = '0';
212
321
 
213
322
  @state()
214
- private templateRows = `${this.rowSize(0)}px`;
323
+ private templatefrozenRowsStart = '';
324
+
325
+ @state()
326
+ private templatefrozenRowsEnd = '';
215
327
 
216
328
  //
217
329
  // Focus, selection, and resize states
@@ -221,22 +333,32 @@ export class DxGrid extends LitElement {
221
333
  private pointer: DxGridPointer = null;
222
334
 
223
335
  @state()
224
- private colSizes: Record<string, number> = {};
336
+ private colSizes: AxisSizes = { grid: {} };
225
337
 
226
338
  @state()
227
- private rowSizes: Record<string, number> = {};
339
+ private rowSizes: AxisSizes = { grid: {} };
228
340
 
229
341
  @state()
230
342
  private focusActive: boolean = false;
231
343
 
232
344
  @state()
233
- private focusedCell: DxGridPosition = { col: 0, row: 0 };
345
+ private focusedCell: DxGridPosition = { plane: 'grid', col: 0, row: 0 };
234
346
 
235
347
  @state()
236
- private selectionStart: DxGridPosition = { col: 0, row: 0 };
348
+ private selectionStart: DxGridPosition = { plane: 'grid', col: 0, row: 0 };
237
349
 
238
350
  @state()
239
- private selectionEnd: DxGridPosition = { col: 0, row: 0 };
351
+ private selectionEnd: DxGridPosition = { plane: 'grid', col: 0, row: 0 };
352
+
353
+ //
354
+ // Limits
355
+ //
356
+
357
+ @state()
358
+ private intrinsicInlineSize: number = Infinity;
359
+
360
+ @state()
361
+ private intrinsicBlockSize: number = Infinity;
240
362
 
241
363
  //
242
364
  // Primary pointer and keyboard handlers
@@ -260,21 +382,12 @@ export class DxGrid extends LitElement {
260
382
  if (event.isPrimary) {
261
383
  const { action, actionEl } = closestAction(event.target);
262
384
  if (action) {
263
- if (action.startsWith('resize') && this.mode === 'browse') {
264
- const [resize, index] = action.split(',');
265
- const [_, axis] = resize.split('-');
266
- this.pointer = {
267
- state: 'resizing',
268
- axis: axis as DxGridAxis,
269
- size: axis === 'col' ? this.colSize(index) : this.rowSize(index),
270
- page: getPage(axis, event),
271
- index,
272
- };
273
- } else if (action === 'cell') {
385
+ if (action === 'cell') {
274
386
  const cellCoords = closestCell(event.target, actionEl);
275
387
  if (cellCoords) {
276
- this.pointer = { state: 'selecting' };
388
+ this.pointer = { state: 'maybeSelecting', pageX: event.pageX, pageY: event.pageY };
277
389
  this.selectionStart = cellCoords;
390
+ this.selectionEnd = cellCoords;
278
391
  }
279
392
  if (this.mode === 'edit') {
280
393
  event.preventDefault();
@@ -289,27 +402,29 @@ export class DxGrid extends LitElement {
289
402
  };
290
403
 
291
404
  private handlePointerUp = (event: PointerEvent) => {
292
- if (this.pointer?.state === 'resizing') {
293
- // do nothing, todo: remove
294
- } else {
295
- const cell = closestCell(event.target);
296
- if (cell) {
297
- this.selectionEnd = cell;
298
- this.dispatchEvent(
299
- new DxGridCellsSelect({
300
- start: this.selectionStart,
301
- end: this.selectionEnd,
302
- }),
303
- );
304
- }
405
+ const cell = closestCell(event.target);
406
+ if (cell) {
407
+ this.selectionEnd = cell;
408
+ this.dispatchEvent(
409
+ new DxGridCellsSelect({
410
+ start: this.selectionStart,
411
+ end: this.selectionEnd,
412
+ }),
413
+ );
305
414
  }
306
415
  this.pointer = null;
307
416
  };
308
417
 
309
418
  private handlePointerMove = (event: PointerEvent) => {
310
- if (this.pointer?.state === 'selecting') {
419
+ if (shouldSelect(this.pointer, event)) {
420
+ this.pointer = { state: 'selecting' };
421
+ } else if (this.pointer?.state === 'selecting') {
311
422
  const cell = closestCell(event.target);
312
- if (cell && (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
423
+ if (
424
+ cell &&
425
+ cell.plane === this.selectionStart.plane &&
426
+ (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)
427
+ ) {
313
428
  this.selectionEnd = cell;
314
429
  }
315
430
  }
@@ -320,13 +435,13 @@ export class DxGrid extends LitElement {
320
435
  // Adjust state
321
436
  switch (event.key) {
322
437
  case 'ArrowDown':
323
- this.focusedCell = { ...this.focusedCell, row: this.focusedCell.row + 1 };
438
+ this.focusedCell = { ...this.focusedCell, row: Math.min(this.limitRows - 1, this.focusedCell.row + 1) };
324
439
  break;
325
440
  case 'ArrowUp':
326
441
  this.focusedCell = { ...this.focusedCell, row: Math.max(0, this.focusedCell.row - 1) };
327
442
  break;
328
443
  case 'ArrowRight':
329
- this.focusedCell = { ...this.focusedCell, col: this.focusedCell.col + 1 };
444
+ this.focusedCell = { ...this.focusedCell, col: Math.min(this.limitColumns - 1, this.focusedCell.col + 1) };
330
445
  break;
331
446
  case 'ArrowLeft':
332
447
  this.focusedCell = { ...this.focusedCell, col: Math.max(0, this.focusedCell.col - 1) };
@@ -360,22 +475,33 @@ export class DxGrid extends LitElement {
360
475
  // Accessors
361
476
  //
362
477
 
363
- private colSize(c: number | string) {
364
- return this.colSizes?.[c] ?? this.columnDefault.size;
478
+ private colSize(c: number | string, plane: DxGridPlane) {
479
+ const resolvedPlane = resolveColPlane(plane);
480
+ return this.colSizes?.[resolvedPlane]?.[c] ?? this.columnDefault[resolvedPlane]?.size ?? defaultColSize;
365
481
  }
366
482
 
367
- private rowSize(r: number | string) {
368
- return this.rowSizes?.[r] ?? this.rowDefault.size;
483
+ private rowSize(r: number | string, plane: DxGridPlane) {
484
+ const resolvedPlane = resolveRowPlane(plane);
485
+ return this.rowSizes?.[resolvedPlane]?.[r] ?? this.rowDefault[resolvedPlane]?.size ?? defaultRowSize;
369
486
  }
370
487
 
371
- private cell(c: number | string, r: number | string) {
488
+ private cell(c: number | string, r: number | string, plane: DxGridPlane): DxGridCellValue | undefined {
372
489
  const index: CellIndex = `${c}${separator}${r}`;
373
- return this.cells[index] ?? this.initialCells[index];
490
+ return this.cells?.[plane]?.[index] ?? this.initialCells?.[plane]?.[index];
491
+ }
492
+
493
+ private cellActive(c: number | string, r: number | string, plane: DxGridPlane): boolean {
494
+ return (
495
+ this.focusActive && this.focusedCell.plane === plane && this.focusedCell.col === c && this.focusedCell.row === r
496
+ );
374
497
  }
375
498
 
376
499
  private focusedCellBox(): DxEditRequest['cellBox'] {
377
500
  const cellElement = this.focusedCellElement();
378
- const cellSize = { inlineSize: this.colSize(this.focusedCell.col), blockSize: this.rowSize(this.focusedCell.row) };
501
+ const cellSize = {
502
+ inlineSize: this.colSize(this.focusedCell.col, this.focusedCell.plane),
503
+ blockSize: this.rowSize(this.focusedCell.row, this.focusedCell.plane),
504
+ };
379
505
  if (!cellElement) {
380
506
  return { insetInlineStart: NaN, insetBlockStart: NaN, ...cellSize };
381
507
  }
@@ -410,6 +536,7 @@ export class DxGrid extends LitElement {
410
536
  this.sizeInline = inlineSize;
411
537
  this.sizeBlock = blockSize;
412
538
  this.updateVis();
539
+ queueMicrotask(() => this.updatePos());
413
540
  }
414
541
  });
415
542
 
@@ -434,79 +561,99 @@ export class DxGrid extends LitElement {
434
561
  }
435
562
  };
436
563
 
437
- private handleWheel = ({ deltaX, deltaY }: WheelEvent) => {
564
+ private updatePos(inline?: number, block?: number) {
565
+ this.posInline = Math.max(0, Math.min(this.intrinsicInlineSize - this.sizeInline, inline ?? this.posInline));
566
+ this.posBlock = Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, block ?? this.posBlock));
567
+ this.maybeUpdateVis();
568
+ }
569
+
570
+ private handleWheel = ({ deltaX, deltaY }: Pick<WheelEvent, 'deltaX' | 'deltaY'>) => {
438
571
  if (this.mode === 'browse') {
439
- this.posInline = Math.max(0, this.posInline + deltaX);
440
- this.posBlock = Math.max(0, this.posBlock + deltaY);
441
- this.maybeUpdateVis();
572
+ this.updatePos(this.posInline + deltaX, this.posBlock + deltaY);
442
573
  }
443
574
  };
444
575
 
445
576
  private updateVisInline() {
446
577
  // todo: avoid starting from zero
447
578
  let colIndex = 0;
448
- let pxInline = this.colSize(colIndex);
579
+ let pxInline = this.colSize(colIndex, 'grid');
449
580
 
450
581
  while (pxInline < this.posInline) {
451
582
  colIndex += 1;
452
- pxInline += this.colSize(colIndex) + gap;
583
+ pxInline += this.colSize(colIndex, 'grid') + gap;
453
584
  }
454
585
 
455
586
  this.visColMin = colIndex - overscanCol;
456
587
 
457
- this.binInlineMin = pxInline - this.colSize(colIndex) - gap;
588
+ this.binInlineMin = pxInline - this.colSize(colIndex, 'grid') - gap;
458
589
  this.binInlineMax = pxInline + gap;
459
590
 
460
591
  this.overscanInline =
461
592
  [...Array(overscanCol)].reduce((acc, _, c0) => {
462
- acc += this.colSize(this.visColMin + c0);
593
+ acc += this.colSize(this.visColMin + c0, 'grid');
463
594
  return acc;
464
595
  }, 0) +
465
596
  gap * (overscanCol - 1);
466
597
 
467
598
  while (pxInline < this.binInlineMax + this.sizeInline + gap) {
468
599
  colIndex += 1;
469
- pxInline += this.colSize(colIndex) + gap;
600
+ pxInline += this.colSize(colIndex, 'grid') + gap;
470
601
  }
471
602
 
472
- this.visColMax = colIndex + overscanCol;
603
+ this.visColMax = Math.min(this.limitColumns, colIndex + overscanCol);
473
604
 
474
- this.templateColumns = [...Array(this.visColMax - this.visColMin)]
475
- .map((_, c0) => `${this.colSize(this.visColMin + c0)}px`)
605
+ this.templateGridColumns = [...Array(this.visColMax - this.visColMin)]
606
+ .map((_, c0) => `${this.colSize(this.visColMin + c0, 'grid')}px`)
607
+ .join(' ');
608
+
609
+ this.templatefrozenColsStart = [...Array(this.frozen.frozenColsStart ?? 0)]
610
+ .map((_, c0) => `${this.colSize(c0, 'frozenColsStart')}px`)
611
+ .join(' ');
612
+
613
+ this.templatefrozenColsEnd = [...Array(this.frozen.frozenColsEnd ?? 0)]
614
+ .map((_, c0) => `${this.colSize(c0, 'frozenColsEnd')}px`)
476
615
  .join(' ');
477
616
  }
478
617
 
479
618
  private updateVisBlock() {
480
619
  // todo: avoid starting from zero
481
620
  let rowIndex = 0;
482
- let pxBlock = this.rowSize(rowIndex);
621
+ let pxBlock = this.rowSize(rowIndex, 'grid');
483
622
 
484
623
  while (pxBlock < this.posBlock) {
485
624
  rowIndex += 1;
486
- pxBlock += this.rowSize(rowIndex) + gap;
625
+ pxBlock += this.rowSize(rowIndex, 'grid') + gap;
487
626
  }
488
627
 
489
628
  this.visRowMin = rowIndex - overscanRow;
490
629
 
491
- this.binBlockMin = pxBlock - this.rowSize(rowIndex) - gap;
630
+ this.binBlockMin = pxBlock - this.rowSize(rowIndex, 'grid') - gap;
492
631
  this.binBlockMax = pxBlock + gap;
493
632
 
494
633
  this.overscanBlock =
495
634
  [...Array(overscanRow)].reduce((acc, _, r0) => {
496
- acc += this.rowSize(this.visRowMin + r0);
635
+ acc += this.rowSize(this.visRowMin + r0, 'grid');
497
636
  return acc;
498
637
  }, 0) +
499
638
  gap * (overscanRow - 1);
500
639
 
501
640
  while (pxBlock < this.binBlockMax + this.sizeBlock) {
502
641
  rowIndex += 1;
503
- pxBlock += this.rowSize(rowIndex) + gap;
642
+ pxBlock += this.rowSize(rowIndex, 'grid') + gap;
504
643
  }
505
644
 
506
- this.visRowMax = rowIndex + overscanRow;
645
+ this.visRowMax = Math.min(this.limitRows, rowIndex + overscanRow);
646
+
647
+ this.templateGridRows = [...Array(this.visRowMax - this.visRowMin)]
648
+ .map((_, r0) => `${this.rowSize(this.visRowMin + r0, 'grid')}px`)
649
+ .join(' ');
650
+
651
+ this.templatefrozenRowsStart = [...Array(this.frozen.frozenRowsStart ?? 0)]
652
+ .map((_, r0) => `${this.rowSize(r0, 'frozenRowsStart')}px`)
653
+ .join(' ');
507
654
 
508
- this.templateRows = [...Array(this.visRowMax - this.visRowMin)]
509
- .map((_, r0) => `${this.rowSize(this.visRowMin + r0)}px`)
655
+ this.templatefrozenRowsEnd = [...Array(this.frozen.frozenRowsEnd ?? 0)]
656
+ .map((_, r0) => `${this.rowSize(r0, 'frozenRowsEnd')}px`)
510
657
  .join(' ');
511
658
  }
512
659
 
@@ -515,9 +662,72 @@ export class DxGrid extends LitElement {
515
662
  this.updateVisBlock();
516
663
  }
517
664
 
665
+ private updateCells(includeFixed?: boolean) {
666
+ this.cells.grid = this.getCells!(
667
+ {
668
+ start: { col: this.visColMin, row: this.visRowMin },
669
+ end: { col: this.visColMax, row: this.visRowMax },
670
+ },
671
+ 'grid',
672
+ );
673
+ Object.entries(this.frozen)
674
+ .filter(([_, limit]) => limit && limit > 0)
675
+ .forEach(([plane, limit]) => {
676
+ this.cells[plane as DxGridFrozenPlane] = this.getCells!(
677
+ plane.startsWith('frozenRows')
678
+ ? {
679
+ start: { col: this.visColMin, row: 0 },
680
+ end: { col: this.visColMax, row: limit },
681
+ }
682
+ : {
683
+ start: { col: 0, row: this.visRowMin },
684
+ end: { col: limit, row: this.visRowMax },
685
+ },
686
+ plane as DxGridFrozenPlane,
687
+ );
688
+ });
689
+ if (includeFixed) {
690
+ if ((this.frozen.frozenColsStart ?? 0) > 0 && (this.frozen.frozenRowsStart ?? 0) > 0) {
691
+ this.cells.fixedStartStart = this.getCells!(
692
+ {
693
+ start: { col: 0, row: 0 },
694
+ end: { col: this.frozen.frozenColsStart!, row: this.frozen.frozenRowsStart! },
695
+ },
696
+ 'fixedStartStart',
697
+ );
698
+ }
699
+ if ((this.frozen.frozenColsEnd ?? 0) > 0 && (this.frozen.frozenRowsStart ?? 0) > 0) {
700
+ this.cells.fixedStartEnd = this.getCells!(
701
+ {
702
+ start: { col: 0, row: 0 },
703
+ end: { col: this.frozen.frozenColsEnd!, row: this.frozen.frozenRowsStart! },
704
+ },
705
+ 'fixedStartEnd',
706
+ );
707
+ }
708
+ if ((this.frozen.frozenColsStart ?? 0) > 0 && (this.frozen.frozenRowsEnd ?? 0) > 0) {
709
+ this.cells.fixedEndStart = this.getCells!(
710
+ {
711
+ start: { col: 0, row: 0 },
712
+ end: { col: this.frozen.frozenColsStart!, row: this.frozen.frozenRowsEnd! },
713
+ },
714
+ 'fixedEndStart',
715
+ );
716
+ }
717
+ if ((this.frozen.frozenColsEnd ?? 0) > 0 && (this.frozen.frozenRowsEnd ?? 0) > 0) {
718
+ this.cells.fixedEndEnd = this.getCells!(
719
+ {
720
+ start: { col: 0, row: 0 },
721
+ end: { col: this.frozen.frozenColsEnd!, row: this.frozen.frozenRowsEnd! },
722
+ },
723
+ 'fixedEndEnd',
724
+ );
725
+ }
726
+ }
727
+ }
728
+
518
729
  // Focus handlers
519
730
 
520
- @eventOptions({ capture: true })
521
731
  private handleFocus(event: FocusEvent) {
522
732
  const cellCoords = closestCell(event.target);
523
733
  if (cellCoords) {
@@ -526,7 +736,6 @@ export class DxGrid extends LitElement {
526
736
  }
527
737
  }
528
738
 
529
- @eventOptions({ capture: true })
530
739
  private handleBlur(event: FocusEvent) {
531
740
  // Only unset `focusActive` if focus is not moving to an element within the grid.
532
741
  if (!event.relatedTarget || !(event.relatedTarget as HTMLElement).closest(`[data-grid="${this.gridId}"]`)) {
@@ -536,10 +745,33 @@ export class DxGrid extends LitElement {
536
745
 
537
746
  private focusedCellElement() {
538
747
  return this.viewportRef.value?.querySelector(
539
- `[aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`,
748
+ `[data-dx-grid-plane=${this.focusedCell.plane}] > [aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`,
540
749
  ) as HTMLElement | null;
541
750
  }
542
751
 
752
+ private focusedCellRowOutOfVis(minDelta = 0, maxDelta = minDelta) {
753
+ return this.focusedCell.row < this.visRowMin + minDelta || this.focusedCell.row > this.visRowMax - maxDelta;
754
+ }
755
+
756
+ private focusedCellColOutOfVis(minDelta = 0, maxDelta = minDelta) {
757
+ return this.focusedCell.col < this.visColMin + minDelta || this.focusedCell.col > this.visColMax - maxDelta;
758
+ }
759
+
760
+ private focusedCellOutOfVis(colDelta = 0, rowDelta = colDelta) {
761
+ switch (this.focusedCell.plane) {
762
+ case 'grid':
763
+ return this.focusedCellRowOutOfVis(rowDelta) || this.focusedCellColOutOfVis(colDelta);
764
+ case 'frozenRowsStart':
765
+ case 'frozenRowsEnd':
766
+ return this.focusedCellColOutOfVis(colDelta);
767
+ case 'frozenColsStart':
768
+ case 'frozenColsEnd':
769
+ return this.focusedCellRowOutOfVis(rowDelta);
770
+ default:
771
+ return false;
772
+ }
773
+ }
774
+
543
775
  /**
544
776
  * Moves focus to the cell with actual focus, otherwise moves focus to the viewport.
545
777
  */
@@ -551,51 +783,31 @@ export class DxGrid extends LitElement {
551
783
  case 'col':
552
784
  this.focusedCell = { ...this.focusedCell, col: this.focusedCell.col + delta };
553
785
  }
554
- (this.focusedCell.row < this.visRowMin ||
555
- this.focusedCell.row > this.visRowMax ||
556
- this.focusedCell.col < this.visColMin ||
557
- this.focusedCell.col > this.visColMax
558
- ? this.viewportRef.value
559
- : this.focusedCellElement()
560
- )?.focus({ preventScroll: true });
561
786
  if (increment) {
562
787
  this.snapPosToFocusedCell();
563
788
  }
789
+ queueMicrotask(() =>
790
+ (this.focusedCellOutOfVis() ? this.viewportRef.value : this.focusedCellElement())?.focus({ preventScroll: true }),
791
+ );
564
792
  }
565
793
 
566
794
  /**
567
795
  * Updates `pos` so that a cell in focus is fully within the viewport
568
796
  */
569
797
  snapPosToFocusedCell() {
570
- if (
571
- this.focusedCell.col < this.visColMin ||
572
- this.focusedCell.col > this.visColMax ||
573
- this.focusedCell.row < this.visRowMin ||
574
- this.focusedCell.row > this.visRowMax
575
- ) {
576
- // console.warn('Snapping position to a focused cell that is not already mounted is unsupported.');
577
- } else if (
578
- this.focusedCell.col > this.visColMin + overscanCol &&
579
- this.focusedCell.col < this.visColMax - overscanCol - 1 &&
580
- this.focusedCell.row > this.visRowMin + overscanRow &&
581
- this.focusedCell.row < this.visRowMax - overscanRow - 1
582
- ) {
583
- // console.log(
584
- // '[within bounds]',
585
- // this.focusedCell,
586
- // [this.visColMin, this.visColMax, overscanCol],
587
- // [this.visRowMin, this.visRowMax, overscanRow],
588
- // );
589
- } else {
798
+ if (this.focusedCellOutOfVis(overscanCol + 1, overscanRow + 1)) {
590
799
  if (this.focusedCell.col <= this.visColMin + overscanCol) {
591
800
  this.posInline = this.binInlineMin;
592
801
  this.updateVisInline();
593
802
  } else if (this.focusedCell.col >= this.visColMax - overscanCol - 1) {
594
803
  const sizeSumCol = [...Array(this.focusedCell.col - this.visColMin)].reduce((acc, _, c0) => {
595
- acc += this.colSize(this.visColMin + overscanCol + c0) + gap;
804
+ acc += this.colSize(this.visColMin + overscanCol + c0, 'grid') + gap;
596
805
  return acc;
597
806
  }, 0);
598
- this.posInline = Math.max(0, this.binInlineMin + sizeSumCol + gap * 2 - this.sizeInline);
807
+ this.posInline = Math.max(
808
+ 0,
809
+ Math.min(this.intrinsicInlineSize - this.sizeInline, this.binInlineMin + sizeSumCol - this.sizeInline),
810
+ );
599
811
  this.updateVisInline();
600
812
  }
601
813
 
@@ -604,10 +816,13 @@ export class DxGrid extends LitElement {
604
816
  this.updateVisBlock();
605
817
  } else if (this.focusedCell.row >= this.visRowMax - overscanRow - 1) {
606
818
  const sizeSumRow = [...Array(this.focusedCell.row - this.visRowMin)].reduce((acc, _, r0) => {
607
- acc += this.rowSize(this.visRowMin + overscanRow + r0) + gap;
819
+ acc += this.rowSize(this.visRowMin + overscanRow + r0, 'grid') + gap;
608
820
  return acc;
609
821
  }, 0);
610
- this.posBlock = Math.max(0, this.binBlockMin + sizeSumRow + gap * 2 - this.sizeBlock);
822
+ this.posBlock = Math.max(
823
+ 0,
824
+ Math.min(this.intrinsicBlockSize - this.sizeBlock, this.binBlockMin + sizeSumRow - this.sizeBlock),
825
+ );
611
826
  this.updateVisBlock();
612
827
  }
613
828
  }
@@ -638,24 +853,34 @@ export class DxGrid extends LitElement {
638
853
  //
639
854
  // Resize handlers
640
855
  //
856
+
857
+ private axisResizeable(plane: 'grid' | DxGridFrozenPlane, axis: DxGridAxis, index: number | string) {
858
+ return axis === 'col'
859
+ ? !!(this.columns[plane]?.[index]?.resizeable ?? this.columnDefault[plane as DxGridFrozenColsPlane]?.resizeable)
860
+ : !!(this.rows[plane]?.[index]?.resizeable ?? this.rowDefault[plane as DxGridFrozenRowsPlane]?.resizeable);
861
+ }
862
+
641
863
  private handleAxisResizeInternal(event: DxAxisResizeInternal) {
642
864
  event.stopPropagation();
643
- const { axis, delta, size, index, type } = event;
865
+ const { plane, axis, delta, size, index, type } = event;
644
866
  if (axis === 'col') {
645
867
  const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, size + delta));
646
- this.colSizes = { ...this.colSizes, [index]: nextSize };
868
+ this.colSizes = { ...this.colSizes, [plane]: { ...this.colSizes[plane], [index]: nextSize } };
647
869
  this.updateVisInline();
870
+ this.updateIntrinsicInlineSize();
648
871
  } else {
649
872
  const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, size + delta));
650
- this.rowSizes = { ...this.rowSizes, [index]: nextSize };
873
+ this.rowSizes = { ...this.colSizes, [plane]: { ...this.rowSizes[plane], [index]: nextSize } };
651
874
  this.updateVisBlock();
875
+ this.updateIntrinsicBlockSize();
652
876
  }
653
877
  if (type === 'dropped') {
654
878
  this.dispatchEvent(
655
879
  new DxAxisResize({
880
+ plane,
656
881
  axis,
657
882
  index,
658
- size: this[axis === 'col' ? 'colSize' : 'rowSize'](index),
883
+ size: this[`${axis}Size`](index, plane),
659
884
  }),
660
885
  );
661
886
  }
@@ -665,136 +890,230 @@ export class DxGrid extends LitElement {
665
890
  // Render and other lifecycle methods
666
891
  //
667
892
 
893
+ private renderFixed(plane: DxGridFixedPlane, selection: DxGridSelectionProps) {
894
+ const colPlane = resolveColPlane(plane) as DxGridFrozenPlane;
895
+ const rowPlane = resolveRowPlane(plane) as DxGridFrozenPlane;
896
+ const cols = this.frozen[colPlane];
897
+ const rows = this.frozen[rowPlane];
898
+ return (cols ?? 0) > 0 && (rows ?? 0) > 0
899
+ ? html`<div
900
+ role="none"
901
+ data-dx-grid-plane=${plane}
902
+ class="dx-grid__plane--fixed"
903
+ style=${styleMap({
904
+ 'grid-template-columns': this[`template${colPlane}`],
905
+ 'grid-template-rows': this[`template${rowPlane}`],
906
+ })}
907
+ >
908
+ ${[...Array(cols)].map((_, c) => {
909
+ return [...Array(rows)].map((_, r) => {
910
+ return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection));
911
+ });
912
+ })}
913
+ </div>`
914
+ : null;
915
+ }
916
+
917
+ private renderFrozenRows(
918
+ plane: DxGridFrozenRowsPlane,
919
+ visibleCols: number,
920
+ offsetInline: number,
921
+ selection: DxGridSelectionProps,
922
+ ) {
923
+ const rowPlane = resolveRowPlane(plane) as DxGridFrozenPlane;
924
+ const rows = this.frozen[rowPlane];
925
+ return (rows ?? 0) > 0
926
+ ? html`<div role="none" class="dx-grid__plane--frozen-row">
927
+ <div
928
+ role="none"
929
+ data-dx-grid-plane=${plane}
930
+ class="dx-grid__plane--frozen-row__content"
931
+ style="transform:translate3d(${offsetInline}px,0,0);grid-template-columns:${this
932
+ .templateGridColumns};grid-template-rows:${this[`template${rowPlane}`]}"
933
+ >
934
+ ${[...Array(visibleCols)].map((_, c0) => {
935
+ return [...Array(rows)].map((_, r) => {
936
+ const c = this.visColMin + c0;
937
+ return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection), c0, r);
938
+ });
939
+ })}
940
+ </div>
941
+ </div>`
942
+ : null;
943
+ }
944
+
945
+ private renderFrozenColumns(
946
+ plane: DxGridFrozenColsPlane,
947
+ visibleRows: number,
948
+ offsetBlock: number,
949
+ selection: DxGridSelectionProps,
950
+ ) {
951
+ const colPlane = resolveColPlane(plane) as DxGridFrozenPlane;
952
+ const cols = this.frozen[colPlane];
953
+ return (cols ?? 0) > 0
954
+ ? html`<div role="none" class="dx-grid__plane--frozen-col">
955
+ <div
956
+ role="none"
957
+ data-dx-grid-plane=${plane}
958
+ class="dx-grid__plane--frozen-col__content"
959
+ style="transform:translate3d(0,${offsetBlock}px,0);grid-template-rows:${this
960
+ .templateGridRows};grid-template-columns:${this[`template${colPlane}`]}"
961
+ >
962
+ ${[...Array(cols)].map((_, c) => {
963
+ return [...Array(visibleRows)].map((_, r0) => {
964
+ const r = this.visRowMin + r0;
965
+ return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection), c, r0);
966
+ });
967
+ })}
968
+ </div>
969
+ </div>`
970
+ : null;
971
+ }
972
+
973
+ private renderCell(col: number, row: number, plane: DxGridPlane, selected?: boolean, visCol = col, visRow = row) {
974
+ const cell = this.cell(col, row, plane);
975
+ const active = this.cellActive(col, row, plane);
976
+ const resizeIndex = cell?.resizeHandle ? (cell.resizeHandle === 'col' ? col : row) : undefined;
977
+ const resizePlane = cell?.resizeHandle ? resolveResizePlane(cell.resizeHandle, plane) : undefined;
978
+ return html`<div
979
+ role="gridcell"
980
+ tabindex="0"
981
+ ?inert=${col < 0 || row < 0}
982
+ ?aria-selected=${selected}
983
+ class=${cell || active
984
+ ? (cell?.className ? cell.className + ' ' : '') + (active ? 'dx-grid__cell--active' : '')
985
+ : nothing}
986
+ aria-colindex=${col}
987
+ aria-rowindex=${row}
988
+ data-dx-grid-action="cell"
989
+ style="grid-column:${visCol + 1};grid-row:${visRow + 1}"
990
+ >
991
+ ${cell?.value}${cell?.resizeHandle && this.axisResizeable(resizePlane!, cell.resizeHandle, resizeIndex!)
992
+ ? html`<dx-grid-axis-resize-handle
993
+ axis=${cell.resizeHandle}
994
+ plane=${resizePlane}
995
+ index=${resizeIndex}
996
+ size=${this[`${cell.resizeHandle}Size`](resizeIndex!, plane)}
997
+ ></dx-grid-axis-resize-handle>`
998
+ : null}
999
+ </div>`;
1000
+ }
1001
+
668
1002
  override render() {
669
1003
  const visibleCols = this.visColMax - this.visColMin;
670
1004
  const visibleRows = this.visRowMax - this.visRowMin;
671
1005
  const offsetInline = this.binInlineMin - this.posInline - this.overscanInline;
672
1006
  const offsetBlock = this.binBlockMin - this.posBlock - this.overscanBlock;
673
-
674
- const selectColMin = Math.min(this.selectionStart.col, this.selectionEnd.col);
675
- const selectColMax = Math.max(this.selectionStart.col, this.selectionEnd.col);
676
- const selectRowMin = Math.min(this.selectionStart.row, this.selectionEnd.row);
677
- const selectRowMax = Math.max(this.selectionStart.row, this.selectionEnd.row);
678
- const selectVisible = selectColMin !== selectColMax || selectRowMin !== selectRowMax;
1007
+ const selection = selectionProps(this.selectionStart, this.selectionEnd);
679
1008
 
680
1009
  return html`<div
681
1010
  role="none"
682
1011
  class="dx-grid"
1012
+ style=${styleMap({
1013
+ 'grid-template-columns': `${this.templatefrozenColsStart ? 'min-content ' : ''}minmax(0, ${
1014
+ Number.isFinite(this.limitColumns) ? `${this.intrinsicInlineSize}px` : '1fr'
1015
+ })${this.templatefrozenColsEnd ? ' min-content' : ''}`,
1016
+ 'grid-template-rows': `${this.templatefrozenRowsStart ? 'min-content ' : ''}minmax(0, ${
1017
+ Number.isFinite(this.limitRows) ? `${this.intrinsicBlockSize}px` : '1fr'
1018
+ })${this.templatefrozenRowsEnd ? ' min-content' : ''}`,
1019
+ })}
683
1020
  data-grid=${this.gridId}
684
1021
  data-grid-mode=${this.mode}
685
- ?data-grid-select=${selectVisible}
1022
+ ?data-grid-select=${selection.visible}
686
1023
  >
687
- <div role="none" class="dx-grid__corner"></div>
688
- <div role="none" class="dx-grid__columnheader">
689
- <div
690
- role="none"
691
- class="dx-grid__columnheader__content"
692
- style="transform:translate3d(${offsetInline}px,0,0);grid-template-columns:${this.templateColumns};"
693
- >
694
- ${[...Array(visibleCols)].map((_, c0) => {
695
- const c = this.visColMin + c0;
696
- return html`<div
697
- role="columnheader"
698
- ?inert=${c < 0}
699
- style="block-size:${this.rowDefault.size}px;grid-column:${c0 + 1}/${c0 + 2};"
700
- >
701
- <span id=${localChId(c0)}>${colToA1Notation(c)}</span>
702
- ${(this.columns[c]?.resizeable ?? this.columnDefault.resizeable) &&
703
- html`<dx-grid-axis-resize-handle
704
- axis="col"
705
- index=${c}
706
- size=${this.colSize(c)}
707
- @dxaxisresizeinternal=${this.handleAxisResizeInternal}
708
- ></dx-grid-axis-resize-handle>`}
709
- </div>`;
710
- })}
711
- </div>
712
- </div>
713
- <div role="none" class="dx-grid__corner"></div>
714
- <div role="none" class="dx-grid__rowheader">
715
- <div
716
- role="none"
717
- class="dx-grid__rowheader__content"
718
- style="transform:translate3d(0,${offsetBlock}px,0);grid-template-rows:${this.templateRows};"
719
- >
720
- ${[...Array(visibleRows)].map((_, r0) => {
721
- const r = this.visRowMin + r0;
722
- return html`<div role="rowheader" ?inert=${r < 0} style="grid-row:${r0 + 1}/${r0 + 2}">
723
- <span id=${localRhId(r0)}>${rowToA1Notation(r)}</span>
724
- ${(this.rows[r]?.resizeable ?? this.rowDefault.resizeable) &&
725
- html`<dx-grid-axis-resize-handle
726
- axis="row"
727
- index=${r}
728
- size=${this.rowSize(r)}
729
- ></dx-grid-axis-resize-handle>`}
730
- </div>`;
731
- })}
732
- </div>
733
- </div>
734
- <div role="grid" class="dx-grid__viewport" tabindex="0" @wheel=${this.handleWheel} ${ref(this.viewportRef)}>
1024
+ ${this.renderFixed('fixedStartStart', selection)}${this.renderFrozenRows(
1025
+ 'frozenRowsStart',
1026
+ visibleCols,
1027
+ offsetInline,
1028
+ selection,
1029
+ )}${this.renderFixed('fixedStartEnd', selection)}${this.renderFrozenColumns(
1030
+ 'frozenColsStart',
1031
+ visibleRows,
1032
+ offsetBlock,
1033
+ selection,
1034
+ )}
1035
+ <div role="grid" class="dx-grid__plane--grid" tabindex="0" ${ref(this.viewportRef)}>
735
1036
  <div
736
1037
  role="none"
737
- class="dx-grid__content"
1038
+ class="dx-grid__plane--grid__content"
1039
+ data-dx-grid-plane="grid"
738
1040
  style="transform:translate3d(${offsetInline}px,${offsetBlock}px,0);grid-template-columns:${this
739
- .templateColumns};grid-template-rows:${this.templateRows};"
1041
+ .templateGridColumns};grid-template-rows:${this.templateGridRows};"
740
1042
  >
741
1043
  ${[...Array(visibleCols)].map((_, c0) => {
742
1044
  return [...Array(visibleRows)].map((_, r0) => {
743
1045
  const c = c0 + this.visColMin;
744
1046
  const r = r0 + this.visRowMin;
745
- const cell = this.cell(c, r);
746
- const active = this.focusActive && this.focusedCell.col === c && this.focusedCell.row === r;
747
- const selected = c >= selectColMin && c <= selectColMax && r >= selectRowMin && r <= selectRowMax;
748
- return html`<div
749
- role="gridcell"
750
- tabindex="0"
751
- ?inert=${c < 0 || r < 0}
752
- ?aria-selected=${selected}
753
- class=${cell || active
754
- ? (cell?.className ? cell.className + ' ' : '') + (active ? 'dx-grid__cell--active' : '')
755
- : nothing}
756
- aria-rowindex=${r}
757
- aria-colindex=${c}
758
- data-dx-grid-action="cell"
759
- style="grid-column:${c0 + 1};grid-row:${r0 + 1}"
760
- >
761
- ${cell?.value}
762
- </div>`;
1047
+ return this.renderCell(c, r, 'grid', cellSelected(c, r, 'grid', selection), c0, r0);
763
1048
  });
764
1049
  })}
765
1050
  </div>
766
1051
  </div>
767
- <div role="none" class="dx-grid__scrollbar" aria-orientation="vertical">
768
- <div role="none" class="dx-grid__scrollbar__thumb"></div>
769
- </div>
770
- <div role="none" class="dx-grid__corner"></div>
771
- <div role="none" class="dx-grid__scrollbar" aria-orientation="horizontal">
772
- <div role="none" class="dx-grid__scrollbar__thumb"></div>
773
- </div>
774
- <div role="none" class="dx-grid__corner"></div>
1052
+ ${this.renderFrozenColumns('frozenColsEnd', visibleRows, offsetBlock, selection)}${this.renderFixed(
1053
+ 'fixedEndStart',
1054
+ selection,
1055
+ )}${this.renderFrozenRows('frozenRowsEnd', visibleCols, offsetInline, selection)}${this.renderFixed(
1056
+ 'fixedEndEnd',
1057
+ selection,
1058
+ )}
775
1059
  </div>`;
776
1060
  }
777
1061
 
1062
+ private updateIntrinsicInlineSize() {
1063
+ this.intrinsicInlineSize = Number.isFinite(this.limitColumns)
1064
+ ? [...Array(this.limitColumns)].reduce((acc, _, c0) => acc + this.colSize(c0, 'grid'), 0) +
1065
+ gap * (this.limitColumns - 1)
1066
+ : Infinity;
1067
+ }
1068
+
1069
+ private updateIntrinsicBlockSize() {
1070
+ this.intrinsicBlockSize = Number.isFinite(this.limitRows)
1071
+ ? [...Array(this.limitRows)].reduce((acc, _, r0) => acc + this.rowSize(r0, 'grid'), 0) +
1072
+ gap * (this.limitRows - 1)
1073
+ : Infinity;
1074
+ }
1075
+
1076
+ private updateIntrinsicSizes() {
1077
+ this.updateIntrinsicInlineSize();
1078
+ this.updateIntrinsicBlockSize();
1079
+ }
1080
+
778
1081
  override firstUpdated() {
779
1082
  if (this.getCells) {
780
- this.cells = this.getCells({
781
- start: { col: this.visColMin, row: this.visRowMin },
782
- end: { col: this.visColMax, row: this.visRowMax },
783
- });
1083
+ this.updateCells(true);
784
1084
  }
785
1085
  this.observer.observe(this.viewportRef.value!);
786
- this.colSizes = Object.entries(this.columns).reduce((acc: Record<string, number>, [colId, colMeta]) => {
787
- if (colMeta?.size) {
788
- acc[colId] = colMeta.size;
789
- }
790
- return acc;
791
- }, {});
792
- this.rowSizes = Object.entries(this.rows).reduce((acc: Record<string, number>, [rowId, rowMeta]) => {
793
- if (rowMeta?.size) {
794
- acc[rowId] = rowMeta.size;
795
- }
796
- return acc;
797
- }, {});
1086
+ this.colSizes = Object.entries(this.columns).reduce(
1087
+ (acc: AxisSizes, [plane, planeColMeta]) => {
1088
+ acc[plane as 'grid' | DxGridFrozenPlane] = Object.entries(planeColMeta).reduce(
1089
+ (planeAcc: Record<string, number>, [col, colMeta]) => {
1090
+ if (colMeta?.size) {
1091
+ planeAcc[col] = colMeta.size;
1092
+ }
1093
+ return planeAcc;
1094
+ },
1095
+ {},
1096
+ );
1097
+ return acc;
1098
+ },
1099
+ { grid: {} },
1100
+ );
1101
+ this.rowSizes = Object.entries(this.rows).reduce(
1102
+ (acc: AxisSizes, [plane, planeRowMeta]) => {
1103
+ acc[plane as 'grid' | DxGridFrozenPlane] = Object.entries(planeRowMeta).reduce(
1104
+ (planeAcc: Record<string, number>, [row, rowMeta]) => {
1105
+ if (rowMeta?.size) {
1106
+ planeAcc[row] = rowMeta.size;
1107
+ }
1108
+ return planeAcc;
1109
+ },
1110
+ {},
1111
+ );
1112
+ return acc;
1113
+ },
1114
+ { grid: {} },
1115
+ );
1116
+ this.updateIntrinsicSizes();
798
1117
  }
799
1118
 
800
1119
  override willUpdate(changedProperties: Map<string, any>) {
@@ -806,10 +1125,7 @@ export class DxGrid extends LitElement {
806
1125
  changedProperties.has('visRowMin') ||
807
1126
  changedProperties.has('visRowMax'))
808
1127
  ) {
809
- this.cells = this.getCells({
810
- start: { col: this.visColMin, row: this.visRowMin },
811
- end: { col: this.visColMax, row: this.visRowMax },
812
- });
1128
+ this.updateCells();
813
1129
  }
814
1130
  }
815
1131
 
@@ -825,8 +1141,6 @@ export class DxGrid extends LitElement {
825
1141
 
826
1142
  override disconnectedCallback() {
827
1143
  super.disconnectedCallback();
828
- // console.log('[disconnected]', this.viewportRef.value);
829
- // TODO(thure): Will this even work?
830
1144
  if (this.viewportRef.value) {
831
1145
  this.observer.unobserve(this.viewportRef.value);
832
1146
  }
@@ -836,3 +1150,5 @@ export class DxGrid extends LitElement {
836
1150
  return this;
837
1151
  }
838
1152
  }
1153
+
1154
+ export { rowToA1Notation, colToA1Notation } from './util';