@dxos/lit-grid 0.6.13 → 0.6.14-main.2b6a0f3

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 (56) hide show
  1. package/dist/src/dx-grid-axis-resize-handle.d.ts +16 -0
  2. package/dist/src/dx-grid-axis-resize-handle.d.ts.map +1 -0
  3. package/dist/src/dx-grid-axis-resize-handle.js +96 -0
  4. package/dist/src/dx-grid-axis-resize-handle.js.map +1 -0
  5. package/dist/src/dx-grid.d.ts +138 -0
  6. package/dist/src/dx-grid.d.ts.map +1 -0
  7. package/dist/src/dx-grid.js +1224 -0
  8. package/dist/src/dx-grid.js.map +1 -0
  9. package/dist/src/dx-grid.lit-stories.d.ts +42 -0
  10. package/dist/src/dx-grid.lit-stories.d.ts.map +1 -0
  11. package/dist/src/dx-grid.lit-stories.js +166 -0
  12. package/dist/src/dx-grid.lit-stories.js.map +1 -0
  13. package/dist/src/index.d.ts +3 -0
  14. package/dist/src/index.d.ts.map +1 -0
  15. package/dist/src/index.js +6 -0
  16. package/dist/src/index.js.map +1 -0
  17. package/dist/src/types.d.ts +119 -0
  18. package/dist/src/types.d.ts.map +1 -0
  19. package/dist/src/types.js +44 -0
  20. package/dist/src/types.js.map +1 -0
  21. package/dist/src/util.d.ts +9 -0
  22. package/dist/src/util.d.ts.map +1 -0
  23. package/dist/src/util.js +19 -0
  24. package/dist/src/util.js.map +1 -0
  25. package/dist/types/src/dx-grid-axis-resize-handle.d.ts +16 -0
  26. package/dist/types/src/dx-grid-axis-resize-handle.d.ts.map +1 -0
  27. package/dist/types/src/dx-grid-axis-resize-handle.js +96 -0
  28. package/dist/types/src/dx-grid-axis-resize-handle.js.map +1 -0
  29. package/dist/types/src/dx-grid.d.ts +112 -57
  30. package/dist/types/src/dx-grid.d.ts.map +1 -1
  31. package/dist/types/src/dx-grid.js +1224 -0
  32. package/dist/types/src/dx-grid.js.map +1 -0
  33. package/dist/types/src/dx-grid.lit-stories.d.ts +27 -2
  34. package/dist/types/src/dx-grid.lit-stories.d.ts.map +1 -1
  35. package/dist/types/src/dx-grid.lit-stories.js +166 -0
  36. package/dist/types/src/dx-grid.lit-stories.js.map +1 -0
  37. package/dist/types/src/index.js +6 -0
  38. package/dist/types/src/index.js.map +1 -0
  39. package/dist/types/src/types.d.ts +111 -1
  40. package/dist/types/src/types.d.ts.map +1 -1
  41. package/dist/types/src/types.js +44 -0
  42. package/dist/types/src/types.js.map +1 -0
  43. package/dist/types/src/util.d.ts +9 -0
  44. package/dist/types/src/util.d.ts.map +1 -0
  45. package/dist/types/src/util.js +19 -0
  46. package/dist/types/src/util.js.map +1 -0
  47. package/package.json +6 -6
  48. package/src/dx-grid-axis-resize-handle.ts +87 -0
  49. package/src/dx-grid.lit-stories.ts +148 -21
  50. package/src/dx-grid.pcss +68 -69
  51. package/src/dx-grid.ts +1116 -343
  52. package/src/types.ts +161 -1
  53. package/src/util.ts +28 -0
  54. package/dist/lib/browser/index.mjs +0 -578
  55. package/dist/lib/browser/index.mjs.map +0 -7
  56. package/dist/lib/browser/meta.json +0 -1
@@ -0,0 +1,1224 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
5
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
6
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
7
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
8
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
9
+ };
10
+ import { LitElement, html, nothing } from 'lit';
11
+ import { customElement, state, property } from 'lit/decorators.js';
12
+ import { ref, createRef } from 'lit/directives/ref.js';
13
+ import { styleMap } from 'lit/directives/style-map.js';
14
+ import { unsafeStatic, html as staticHtml } from 'lit/static-html.js';
15
+ // eslint-disable-next-line unused-imports/no-unused-imports
16
+ import './dx-grid-axis-resize-handle';
17
+ import { DxAxisResize, DxEditRequest, DxGridCellsSelect, } from './types';
18
+ import { separator, toCellIndex } from './util';
19
+ /**
20
+ * The size in pixels of the gap between cells
21
+ */
22
+ const gap = 1;
23
+ /**
24
+ * ResizeObserver notices even subpixel changes, only respond to changes of at least 1px.
25
+ */
26
+ const resizeTolerance = 1;
27
+ /**
28
+ * The amount of pixels the primary pointer has to move after PointerDown to engage in selection.
29
+ */
30
+ const selectTolerance = 4;
31
+ //
32
+ // `overscan` is the number of columns or rows to render outside of the viewport
33
+ //
34
+ const overscanCol = 1;
35
+ const overscanRow = 1;
36
+ //
37
+ // `defaultSize`, the final fallbacks
38
+ //
39
+ const defaultSizeRow = 32;
40
+ const defaultSizeCol = 180;
41
+ //
42
+ // `size`, when suffixed with ‘row’ or ‘col’, are limits on size applied when resizing
43
+ //
44
+ const sizeColMin = 32;
45
+ const sizeColMax = 1024;
46
+ const sizeRowMin = 32;
47
+ const sizeRowMax = 1024;
48
+ const shouldSelect = (pointer, { pageX, pageY }) => {
49
+ if ((pointer === null || pointer === void 0 ? void 0 : pointer.state) === 'maybeSelecting') {
50
+ return Math.hypot(Math.abs(pointer.pageX - pageX), Math.abs(pointer.pageY - pageY)) >= selectTolerance;
51
+ }
52
+ else {
53
+ return false;
54
+ }
55
+ };
56
+ const selectionProps = (selectionStart, selectionEnd) => {
57
+ const colMin = Math.min(selectionStart.col, selectionEnd.col);
58
+ const colMax = Math.max(selectionStart.col, selectionEnd.col);
59
+ const rowMin = Math.min(selectionStart.row, selectionEnd.row);
60
+ const rowMax = Math.max(selectionStart.row, selectionEnd.row);
61
+ const plane = selectionStart.plane;
62
+ const visible = colMin !== colMax || rowMin !== rowMax;
63
+ return { colMin, colMax, rowMin, rowMax, plane, visible };
64
+ };
65
+ const cellSelected = (col, row, plane, selection) => {
66
+ return (plane === selection.plane &&
67
+ col >= selection.colMin &&
68
+ col <= selection.colMax &&
69
+ row >= selection.rowMin &&
70
+ row <= selection.rowMax);
71
+ };
72
+ const closestAction = (target) => {
73
+ var _a, _b;
74
+ const actionEl = (_a = target === null || target === void 0 ? void 0 : target.closest('[data-dx-grid-action]')) !== null && _a !== void 0 ? _a : null;
75
+ return { actionEl, action: (_b = actionEl === null || actionEl === void 0 ? void 0 : actionEl.getAttribute('data-dx-grid-action')) !== null && _b !== void 0 ? _b : null };
76
+ };
77
+ export const closestCell = (target, actionEl) => {
78
+ var _a, _b, _c, _d;
79
+ let cellElement = actionEl;
80
+ if (!cellElement) {
81
+ const { action, actionEl } = closestAction(target);
82
+ if (action === 'cell') {
83
+ cellElement = actionEl;
84
+ }
85
+ }
86
+ if (cellElement) {
87
+ const col = parseInt((_a = cellElement.getAttribute('aria-colindex')) !== null && _a !== void 0 ? _a : 'never');
88
+ const row = parseInt((_b = cellElement.getAttribute('aria-rowindex')) !== null && _b !== void 0 ? _b : 'never');
89
+ const plane = ((_d = (_c = cellElement.closest('[data-dx-grid-plane]')) === null || _c === void 0 ? void 0 : _c.getAttribute('data-dx-grid-plane')) !== null && _d !== void 0 ? _d : 'grid');
90
+ return { plane, col, row };
91
+ }
92
+ else {
93
+ return null;
94
+ }
95
+ };
96
+ const resolveRowPlane = (plane) => {
97
+ switch (plane) {
98
+ case 'fixedStartStart':
99
+ case 'fixedStartEnd':
100
+ case 'frozenRowsStart':
101
+ return 'frozenRowsStart';
102
+ case 'fixedEndStart':
103
+ case 'fixedEndEnd':
104
+ case 'frozenRowsEnd':
105
+ return 'frozenRowsEnd';
106
+ default:
107
+ return 'grid';
108
+ }
109
+ };
110
+ const resolveColPlane = (plane) => {
111
+ switch (plane) {
112
+ case 'fixedStartStart':
113
+ case 'fixedEndStart':
114
+ case 'frozenColsStart':
115
+ return 'frozenColsStart';
116
+ case 'fixedStartEnd':
117
+ case 'fixedEndEnd':
118
+ case 'frozenColsEnd':
119
+ return 'frozenColsEnd';
120
+ default:
121
+ return 'grid';
122
+ }
123
+ };
124
+ const resolveFrozenPlane = (axis, cellPlane) => {
125
+ switch (cellPlane) {
126
+ case 'fixedStartStart':
127
+ return axis === 'col' ? 'frozenColsStart' : 'frozenRowsStart';
128
+ case 'fixedStartEnd':
129
+ return axis === 'col' ? 'frozenColsEnd' : 'frozenRowsStart';
130
+ case 'fixedEndStart':
131
+ return axis === 'col' ? 'frozenColsStart' : 'frozenRowsEnd';
132
+ case 'fixedEndEnd':
133
+ return axis === 'col' ? 'frozenColsEnd' : 'frozenRowsEnd';
134
+ case 'frozenColsStart':
135
+ case 'frozenColsEnd':
136
+ return axis === 'col' ? cellPlane : 'grid';
137
+ case 'frozenRowsStart':
138
+ case 'frozenRowsEnd':
139
+ return axis === 'row' ? cellPlane : 'grid';
140
+ default:
141
+ return cellPlane;
142
+ }
143
+ };
144
+ const isSameCell = (a, b) => a &&
145
+ b &&
146
+ a.plane === b.plane &&
147
+ Number.isFinite(a.col) &&
148
+ Number.isFinite(a.row) &&
149
+ a.col === b.col &&
150
+ a.row === b.row;
151
+ let DxGrid = class DxGrid extends LitElement {
152
+ constructor() {
153
+ var _a;
154
+ super();
155
+ this.gridId = 'default-grid-id';
156
+ this.rowDefault = {
157
+ grid: { size: defaultSizeRow },
158
+ };
159
+ this.columnDefault = {
160
+ grid: { size: defaultSizeCol },
161
+ };
162
+ this.rows = { grid: {} };
163
+ this.columns = { grid: {} };
164
+ this.initialCells = { grid: {} };
165
+ this.mode = 'browse';
166
+ this.limitColumns = Infinity;
167
+ this.limitRows = Infinity;
168
+ this.frozen = {};
169
+ this.overscroll = undefined;
170
+ this.activeRefs = '';
171
+ /**
172
+ * When this function is defined, it is used first to try to get a value for a cell, and otherwise will fall back
173
+ * to `cells`.
174
+ */
175
+ this.getCells = null;
176
+ this.cells = { grid: {} };
177
+ //
178
+ // `pos`, short for ‘position’, is the position in pixels of the viewport from the origin.
179
+ //
180
+ this.posInline = 0;
181
+ this.posBlock = 0;
182
+ //
183
+ // `size` (when not suffixed with ‘row’ or ‘col’, see above) is the size in pixels of the viewport.
184
+ //
185
+ this.sizeInline = 0;
186
+ this.sizeBlock = 0;
187
+ //
188
+ // `overscan` is the amount in pixels to offset the grid content due to the number of overscanned columns or rows.
189
+ //
190
+ this.overscanInline = 0;
191
+ this.overscanBlock = 0;
192
+ //
193
+ // `bin`, not short for anything, is the range in pixels within which virtualization does not need to reassess.
194
+ //
195
+ this.binInlineMin = 0;
196
+ this.binInlineMax = defaultSizeCol;
197
+ this.binBlockMin = 0;
198
+ this.binBlockMax = defaultSizeRow;
199
+ //
200
+ // `vis`, short for ‘visible’, is the range in numeric index of the columns or rows which should be rendered within
201
+ // the viewport. These start with naïve values that are updated before first contentful render.
202
+ //
203
+ this.visColMin = 0;
204
+ this.visColMax = 1;
205
+ this.visRowMin = 0;
206
+ this.visRowMax = 1;
207
+ //
208
+ // `template` is the rendered value of `grid-{axis}-template`.
209
+ //
210
+ this.templateGridColumns = '0';
211
+ this.templatefrozenColsStart = '';
212
+ this.templatefrozenColsEnd = '';
213
+ this.templateGridRows = '0';
214
+ this.templatefrozenRowsStart = '';
215
+ this.templatefrozenRowsEnd = '';
216
+ //
217
+ // Focus, selection, and resize states
218
+ //
219
+ this.pointer = null;
220
+ this.colSizes = { grid: {} };
221
+ this.rowSizes = { grid: {} };
222
+ this.focusActive = false;
223
+ this.focusedCell = { plane: 'grid', col: 0, row: 0 };
224
+ this.selectionStart = { plane: 'grid', col: 0, row: 0 };
225
+ this.selectionEnd = { plane: 'grid', col: 0, row: 0 };
226
+ //
227
+ // Limits
228
+ //
229
+ this.intrinsicInlineSize = Infinity;
230
+ this.intrinsicBlockSize = Infinity;
231
+ this.handlePointerDown = (event) => {
232
+ if (event.isPrimary) {
233
+ const { action, actionEl } = closestAction(event.target);
234
+ if (action && action === 'cell') {
235
+ if (event.shiftKey) {
236
+ // Prevent focus moving so the pointerup handler can move selectionEnd.
237
+ event.preventDefault();
238
+ }
239
+ else {
240
+ const cellCoords = closestCell(event.target, actionEl);
241
+ if (cellCoords) {
242
+ this.pointer = { state: 'maybeSelecting', pageX: event.pageX, pageY: event.pageY };
243
+ this.selectionStart = cellCoords;
244
+ this.selectionEnd = cellCoords;
245
+ this.dispatchSelectionChange();
246
+ }
247
+ if (this.mode === 'edit') {
248
+ // Prevent focus moving when editing.
249
+ event.preventDefault();
250
+ }
251
+ else {
252
+ if (this.focusActive && isSameCell(this.focusedCell, cellCoords)) {
253
+ this.dispatchEditRequest();
254
+ }
255
+ }
256
+ }
257
+ }
258
+ }
259
+ };
260
+ this.handlePointerUp = (event) => {
261
+ const cell = closestCell(event.target);
262
+ if (cell) {
263
+ this.setSelectionEnd(cell);
264
+ }
265
+ this.pointer = null;
266
+ };
267
+ this.handlePointerMove = (event) => {
268
+ var _a;
269
+ if (shouldSelect(this.pointer, event)) {
270
+ this.pointer = { state: 'selecting' };
271
+ }
272
+ else if (((_a = this.pointer) === null || _a === void 0 ? void 0 : _a.state) === 'selecting') {
273
+ const cell = closestCell(event.target);
274
+ if (cell &&
275
+ cell.plane === this.selectionStart.plane &&
276
+ (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
277
+ this.setSelectionEnd(cell);
278
+ }
279
+ }
280
+ };
281
+ //
282
+ // Resize & reposition handlers, observer, ref
283
+ //
284
+ this.observer = new ResizeObserver((entries) => {
285
+ var _a, _b, _c;
286
+ const { inlineSize, blockSize } = (_c = (_b = (_a = entries === null || entries === void 0 ? void 0 : entries[0]) === null || _a === void 0 ? void 0 : _a.contentBoxSize) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : {
287
+ inlineSize: 0,
288
+ blockSize: 0,
289
+ };
290
+ if (Math.abs(inlineSize - this.sizeInline) > resizeTolerance ||
291
+ Math.abs(blockSize - this.sizeBlock) > resizeTolerance) {
292
+ // console.info('[updating bounds]', 'resize', [inlineSize - this.sizeInline, blockSize - this.sizeBlock]);
293
+ this.sizeInline = inlineSize;
294
+ this.sizeBlock = blockSize;
295
+ this.updateVis();
296
+ queueMicrotask(() => this.updatePos());
297
+ }
298
+ });
299
+ this.viewportRef = createRef();
300
+ this.maybeUpdateVisInline = () => {
301
+ if (this.posInline < this.binInlineMin || this.posInline >= this.binInlineMax) {
302
+ this.updateVisInline();
303
+ }
304
+ };
305
+ this.maybeUpdateVisBlock = () => {
306
+ if (this.posBlock < this.binBlockMin || this.posBlock >= this.binBlockMax) {
307
+ this.updateVisBlock();
308
+ }
309
+ };
310
+ this.handleTopLevelWheel = (event) => {
311
+ if ((Number.isFinite(event.overscrollInline) && this.overscroll === 'inline' && event.overscrollInline === 0) ||
312
+ (Number.isFinite(event.overscrollBlock) && this.overscroll === 'block' && event.overscrollBlock === 0)) {
313
+ event.preventDefault();
314
+ event.stopPropagation();
315
+ }
316
+ };
317
+ this.handleWheel = (event) => {
318
+ if (this.mode === 'browse') {
319
+ const nextPosInline = this.posInline + event.deltaX;
320
+ const nextPosBlock = this.posBlock + event.deltaY;
321
+ const maxPosInline = this.maxPosInline();
322
+ const maxPosBlock = this.maxPosBlock();
323
+ this.updatePos(nextPosInline, nextPosBlock, maxPosInline, maxPosBlock);
324
+ event.overscrollInline =
325
+ nextPosInline <= 0 ? nextPosInline : nextPosInline > maxPosInline ? nextPosInline - maxPosInline : 0;
326
+ event.overscrollBlock =
327
+ nextPosBlock <= 0 ? nextPosBlock : nextPosBlock > maxPosBlock ? nextPosBlock - maxPosBlock : 0;
328
+ }
329
+ };
330
+ // Wheel, top-level and element-level
331
+ (_a = document.defaultView) === null || _a === void 0 ? void 0 : _a.addEventListener('wheel', this.handleTopLevelWheel, { passive: false });
332
+ this.addEventListener('wheel', this.handleWheel);
333
+ // Custom event(s)
334
+ this.addEventListener('dx-axis-resize-internal', this.handleAxisResizeInternal);
335
+ // Standard events
336
+ this.addEventListener('pointerdown', this.handlePointerDown);
337
+ this.addEventListener('pointermove', this.handlePointerMove);
338
+ this.addEventListener('pointerup', this.handlePointerUp);
339
+ this.addEventListener('pointerleave', this.handlePointerUp);
340
+ this.addEventListener('focus', this.handleFocus, { capture: true });
341
+ this.addEventListener('blur', this.handleBlur, { capture: true });
342
+ this.addEventListener('keydown', this.handleKeydown);
343
+ }
344
+ //
345
+ // Primary pointer and keyboard handlers
346
+ //
347
+ dispatchEditRequest(initialContent) {
348
+ this.snapPosToFocusedCell();
349
+ if (!this.cellReadonly(this.focusedCell.col, this.focusedCell.row, this.focusedCell.plane)) {
350
+ // Without deferring, the event dispatches before `focusedCellBox` can get updated bounds of the cell, hence:
351
+ queueMicrotask(() => this.dispatchEvent(new DxEditRequest({
352
+ cellIndex: toCellIndex(this.focusedCell),
353
+ cellBox: this.focusedCellBox(),
354
+ initialContent,
355
+ })));
356
+ }
357
+ }
358
+ dispatchSelectionChange() {
359
+ return this.dispatchEvent(new DxGridCellsSelect({
360
+ start: this.selectionStart,
361
+ end: this.selectionEnd,
362
+ }));
363
+ }
364
+ /**
365
+ * Increments focus among all theoretically possible cells in a plane, cycling as tab would but accounting for the
366
+ * theoretical bounds of the grid plane (handling infinite planes heuristically).
367
+ */
368
+ incrementFocusWithinPlane(reverse) {
369
+ const colPlane = resolveColPlane(this.focusedCell.plane);
370
+ const rowPlane = resolveRowPlane(this.focusedCell.plane);
371
+ const colMax = (colPlane === 'grid' ? this.limitColumns : this.frozen[colPlane]) - 1;
372
+ const rowMax = (rowPlane === 'grid' ? this.limitRows : this.frozen[rowPlane]) - 1;
373
+ if (reverse ? this.focusedCell.col - 1 < 0 : this.focusedCell.col + 1 > colMax) {
374
+ if (reverse ? this.focusedCell.row - 1 < 0 : this.focusedCell.row + 1 > rowMax) {
375
+ this.setFocusedCell({
376
+ plane: this.focusedCell.plane,
377
+ row: reverse && Number.isFinite(rowMax) ? rowMax : 0,
378
+ col: reverse && Number.isFinite(colMax) ? colMax : 0,
379
+ });
380
+ }
381
+ else {
382
+ this.setFocusedCell({
383
+ plane: this.focusedCell.plane,
384
+ row: this.focusedCell.row + (reverse ? -1 : 1),
385
+ col: reverse && Number.isFinite(colMax) ? colMax : 0,
386
+ });
387
+ }
388
+ }
389
+ else {
390
+ this.setFocusedCell({ ...this.focusedCell, col: this.focusedCell.col + (reverse ? -1 : 1) });
391
+ }
392
+ }
393
+ /**
394
+ * Increments focus in a specific direction without cycling.
395
+ */
396
+ moveFocusOrSelectionEndWithinPlane(deltaCol, deltaRow, selectionEnd) {
397
+ const current = selectionEnd ? this.selectionEnd : this.focusedCell;
398
+ const colPlane = resolveColPlane(current.plane);
399
+ const colMax = (colPlane === 'grid' ? this.limitColumns : this.frozen[colPlane]) - 1;
400
+ const nextCol = Math.max(0, Math.min(colMax, current.col + deltaCol));
401
+ const rowPlane = resolveRowPlane(current.plane);
402
+ const rowMax = (rowPlane === 'grid' ? this.limitRows : this.frozen[rowPlane]) - 1;
403
+ const nextRow = Math.max(0, Math.min(rowMax, current.row + deltaRow));
404
+ if (selectionEnd) {
405
+ this.setSelectionEnd({ ...this.selectionEnd, col: nextCol, row: nextRow });
406
+ }
407
+ else {
408
+ this.setFocusedCell({ ...this.focusedCell, row: nextRow, col: nextCol });
409
+ }
410
+ }
411
+ handleKeydown(event) {
412
+ if (this.focusActive && this.mode === 'browse') {
413
+ // Adjust state
414
+ switch (event.key) {
415
+ case 'ArrowDown':
416
+ event.preventDefault();
417
+ this.moveFocusOrSelectionEndWithinPlane(0, 1, event.shiftKey);
418
+ break;
419
+ case 'ArrowUp':
420
+ event.preventDefault();
421
+ this.moveFocusOrSelectionEndWithinPlane(0, -1, event.shiftKey);
422
+ break;
423
+ case 'ArrowRight':
424
+ event.preventDefault();
425
+ this.moveFocusOrSelectionEndWithinPlane(1, 0, event.shiftKey);
426
+ break;
427
+ case 'ArrowLeft':
428
+ event.preventDefault();
429
+ this.moveFocusOrSelectionEndWithinPlane(-1, 0, event.shiftKey);
430
+ break;
431
+ case 'Tab':
432
+ event.preventDefault();
433
+ this.incrementFocusWithinPlane(event.shiftKey);
434
+ break;
435
+ case 'Escape':
436
+ // Handle escape if selection is a superset of the focused cell.
437
+ if (this.selectionStart.col !== this.selectionEnd.col || this.selectionStart.row !== this.selectionEnd.row) {
438
+ event.preventDefault();
439
+ this.selectionStart = this.focusedCell;
440
+ this.selectionEnd = this.focusedCell;
441
+ this.dispatchSelectionChange();
442
+ }
443
+ break;
444
+ case 'Enter':
445
+ this.dispatchEditRequest();
446
+ break;
447
+ default:
448
+ if (event.key.length === 1 && event.key.match(/\P{Cc}/u) && !(event.metaKey || event.ctrlKey)) {
449
+ this.dispatchEditRequest(event.key);
450
+ }
451
+ break;
452
+ }
453
+ }
454
+ }
455
+ //
456
+ // Accessors
457
+ //
458
+ colSize(c, plane) {
459
+ var _a, _b, _c, _d, _e;
460
+ const resolvedPlane = resolveColPlane(plane);
461
+ return (_e = (_c = (_b = (_a = this.colSizes) === null || _a === void 0 ? void 0 : _a[resolvedPlane]) === null || _b === void 0 ? void 0 : _b[c]) !== null && _c !== void 0 ? _c : (_d = this.columnDefault[resolvedPlane]) === null || _d === void 0 ? void 0 : _d.size) !== null && _e !== void 0 ? _e : defaultSizeCol;
462
+ }
463
+ rowSize(r, plane) {
464
+ var _a, _b, _c, _d, _e;
465
+ const resolvedPlane = resolveRowPlane(plane);
466
+ return (_e = (_c = (_b = (_a = this.rowSizes) === null || _a === void 0 ? void 0 : _a[resolvedPlane]) === null || _b === void 0 ? void 0 : _b[r]) !== null && _c !== void 0 ? _c : (_d = this.rowDefault[resolvedPlane]) === null || _d === void 0 ? void 0 : _d.size) !== null && _e !== void 0 ? _e : defaultSizeRow;
467
+ }
468
+ cell(c, r, plane) {
469
+ var _a, _b, _c, _d, _e;
470
+ const index = `${c}${separator}${r}`;
471
+ return (_c = (_b = (_a = this.cells) === null || _a === void 0 ? void 0 : _a[plane]) === null || _b === void 0 ? void 0 : _b[index]) !== null && _c !== void 0 ? _c : (_e = (_d = this.initialCells) === null || _d === void 0 ? void 0 : _d[plane]) === null || _e === void 0 ? void 0 : _e[index];
472
+ }
473
+ cellActive(c, r, plane) {
474
+ return (this.focusActive && this.focusedCell.plane === plane && this.focusedCell.col === c && this.focusedCell.row === r);
475
+ }
476
+ setFocusedCell(nextCoords) {
477
+ if (this.focusedCell.plane !== nextCoords.plane ||
478
+ this.focusedCell.col !== nextCoords.col ||
479
+ this.focusedCell.row !== nextCoords.row) {
480
+ this.focusedCell = nextCoords;
481
+ this.selectionStart = nextCoords;
482
+ this.selectionEnd = nextCoords;
483
+ this.snapPosToFocusedCell();
484
+ this.dispatchSelectionChange();
485
+ }
486
+ }
487
+ setSelectionEnd(nextCoords) {
488
+ if (this.selectionEnd.plane !== nextCoords.plane ||
489
+ this.selectionEnd.col !== nextCoords.col ||
490
+ this.selectionEnd.row !== nextCoords.row) {
491
+ this.selectionEnd = nextCoords;
492
+ this.dispatchSelectionChange();
493
+ }
494
+ }
495
+ focusedCellBox() {
496
+ const cellElement = this.focusedCellElement();
497
+ const cellSize = {
498
+ inlineSize: this.colSize(this.focusedCell.col, this.focusedCell.plane),
499
+ blockSize: this.rowSize(this.focusedCell.row, this.focusedCell.plane),
500
+ };
501
+ if (!cellElement) {
502
+ return { insetInlineStart: NaN, insetBlockStart: NaN, ...cellSize };
503
+ }
504
+ const contentElement = cellElement.offsetParent;
505
+ // Note that storing `offset` in state causes performance issues, so instead the transform is parsed here.
506
+ const [_translate3d, inlineStr, blockStr] = contentElement.style.transform.split(/[()]|px,?\s?/);
507
+ const contentOffsetInline = parseFloat(inlineStr);
508
+ const contentOffsetBlock = parseFloat(blockStr);
509
+ const offsetParent = contentElement.offsetParent;
510
+ return {
511
+ insetInlineStart: cellElement.offsetLeft + contentOffsetInline + offsetParent.offsetLeft,
512
+ insetBlockStart: cellElement.offsetTop + contentOffsetBlock + offsetParent.offsetTop,
513
+ ...cellSize,
514
+ };
515
+ }
516
+ maxPosInline() {
517
+ return this.intrinsicInlineSize - this.sizeInline;
518
+ }
519
+ maxPosBlock() {
520
+ return this.intrinsicBlockSize - this.sizeBlock;
521
+ }
522
+ updatePosInline(inline, maxInline = this.maxPosInline()) {
523
+ this.posInline = Math.max(0, Math.min(maxInline, inline !== null && inline !== void 0 ? inline : this.posInline));
524
+ this.maybeUpdateVisInline();
525
+ }
526
+ updatePosBlock(block, maxBlock = this.maxPosBlock()) {
527
+ this.posBlock = Math.max(0, Math.min(maxBlock, block !== null && block !== void 0 ? block : this.posBlock));
528
+ this.maybeUpdateVisBlock();
529
+ }
530
+ updatePos(inline, block, maxInline, maxBlock) {
531
+ this.updatePosInline(inline, maxInline);
532
+ this.updatePosBlock(block, maxBlock);
533
+ }
534
+ updateVisInline() {
535
+ var _a, _b;
536
+ // todo: avoid starting from zero
537
+ let colIndex = 0;
538
+ let pxInline = this.colSize(colIndex, 'grid');
539
+ while (pxInline < this.posInline) {
540
+ colIndex += 1;
541
+ pxInline += this.colSize(colIndex, 'grid') + gap;
542
+ }
543
+ this.visColMin = colIndex - overscanCol;
544
+ this.binInlineMin = pxInline - this.colSize(colIndex, 'grid') - gap;
545
+ this.binInlineMax = pxInline + gap;
546
+ this.overscanInline =
547
+ [...Array(overscanCol)].reduce((acc, _, c0) => {
548
+ acc += this.colSize(this.visColMin + c0, 'grid');
549
+ return acc;
550
+ }, 0) +
551
+ gap * (overscanCol - 1);
552
+ while (pxInline < this.binInlineMax + this.sizeInline - gap * 2) {
553
+ colIndex += 1;
554
+ pxInline += this.colSize(colIndex, 'grid') + gap;
555
+ }
556
+ this.visColMax = Math.min(this.limitColumns, colIndex + overscanCol);
557
+ this.templateGridColumns = [...Array(this.visColMax - this.visColMin)]
558
+ .map((_, c0) => `${this.colSize(this.visColMin + c0, 'grid')}px`)
559
+ .join(' ');
560
+ this.templatefrozenColsStart = [...Array((_a = this.frozen.frozenColsStart) !== null && _a !== void 0 ? _a : 0)]
561
+ .map((_, c0) => `${this.colSize(c0, 'frozenColsStart')}px`)
562
+ .join(' ');
563
+ this.templatefrozenColsEnd = [...Array((_b = this.frozen.frozenColsEnd) !== null && _b !== void 0 ? _b : 0)]
564
+ .map((_, c0) => `${this.colSize(c0, 'frozenColsEnd')}px`)
565
+ .join(' ');
566
+ }
567
+ updateVisBlock() {
568
+ var _a, _b;
569
+ // todo: avoid starting from zero
570
+ let rowIndex = 0;
571
+ let pxBlock = this.rowSize(rowIndex, 'grid');
572
+ while (pxBlock < this.posBlock) {
573
+ rowIndex += 1;
574
+ pxBlock += this.rowSize(rowIndex, 'grid') + gap;
575
+ }
576
+ this.visRowMin = rowIndex - overscanRow;
577
+ this.binBlockMin = pxBlock - this.rowSize(rowIndex, 'grid') - gap;
578
+ this.binBlockMax = pxBlock + gap;
579
+ this.overscanBlock =
580
+ [...Array(overscanRow)].reduce((acc, _, r0) => {
581
+ acc += this.rowSize(this.visRowMin + r0, 'grid');
582
+ return acc;
583
+ }, 0) +
584
+ gap * (overscanRow - 1);
585
+ while (pxBlock < this.binBlockMax + this.sizeBlock - gap * 2) {
586
+ rowIndex += 1;
587
+ pxBlock += this.rowSize(rowIndex, 'grid') + gap;
588
+ }
589
+ this.visRowMax = Math.min(this.limitRows, rowIndex + overscanRow);
590
+ this.templateGridRows = [...Array(this.visRowMax - this.visRowMin)]
591
+ .map((_, r0) => `${this.rowSize(this.visRowMin + r0, 'grid')}px`)
592
+ .join(' ');
593
+ this.templatefrozenRowsStart = [...Array((_a = this.frozen.frozenRowsStart) !== null && _a !== void 0 ? _a : 0)]
594
+ .map((_, r0) => `${this.rowSize(r0, 'frozenRowsStart')}px`)
595
+ .join(' ');
596
+ this.templatefrozenRowsEnd = [...Array((_b = this.frozen.frozenRowsEnd) !== null && _b !== void 0 ? _b : 0)]
597
+ .map((_, r0) => `${this.rowSize(r0, 'frozenRowsEnd')}px`)
598
+ .join(' ');
599
+ }
600
+ updateVis() {
601
+ this.updateVisInline();
602
+ this.updateVisBlock();
603
+ }
604
+ updateCells(includeFixed) {
605
+ var _a, _b, _c, _d, _e, _f, _g, _h;
606
+ this.cells.grid = this.getCells({
607
+ start: { col: this.visColMin, row: this.visRowMin },
608
+ end: { col: this.visColMax, row: this.visRowMax },
609
+ }, 'grid');
610
+ Object.entries(this.frozen)
611
+ .filter(([_, limit]) => limit && limit > 0)
612
+ .forEach(([plane, limit]) => {
613
+ this.cells[plane] = this.getCells(plane.startsWith('frozenRows')
614
+ ? {
615
+ start: { col: this.visColMin, row: 0 },
616
+ end: { col: this.visColMax, row: limit },
617
+ }
618
+ : {
619
+ start: { col: 0, row: this.visRowMin },
620
+ end: { col: limit, row: this.visRowMax },
621
+ }, plane);
622
+ });
623
+ if (includeFixed) {
624
+ if (((_a = this.frozen.frozenColsStart) !== null && _a !== void 0 ? _a : 0) > 0 && ((_b = this.frozen.frozenRowsStart) !== null && _b !== void 0 ? _b : 0) > 0) {
625
+ this.cells.fixedStartStart = this.getCells({
626
+ start: { col: 0, row: 0 },
627
+ end: { col: this.frozen.frozenColsStart, row: this.frozen.frozenRowsStart },
628
+ }, 'fixedStartStart');
629
+ }
630
+ if (((_c = this.frozen.frozenColsEnd) !== null && _c !== void 0 ? _c : 0) > 0 && ((_d = this.frozen.frozenRowsStart) !== null && _d !== void 0 ? _d : 0) > 0) {
631
+ this.cells.fixedStartEnd = this.getCells({
632
+ start: { col: 0, row: 0 },
633
+ end: { col: this.frozen.frozenColsEnd, row: this.frozen.frozenRowsStart },
634
+ }, 'fixedStartEnd');
635
+ }
636
+ if (((_e = this.frozen.frozenColsStart) !== null && _e !== void 0 ? _e : 0) > 0 && ((_f = this.frozen.frozenRowsEnd) !== null && _f !== void 0 ? _f : 0) > 0) {
637
+ this.cells.fixedEndStart = this.getCells({
638
+ start: { col: 0, row: 0 },
639
+ end: { col: this.frozen.frozenColsStart, row: this.frozen.frozenRowsEnd },
640
+ }, 'fixedEndStart');
641
+ }
642
+ if (((_g = this.frozen.frozenColsEnd) !== null && _g !== void 0 ? _g : 0) > 0 && ((_h = this.frozen.frozenRowsEnd) !== null && _h !== void 0 ? _h : 0) > 0) {
643
+ this.cells.fixedEndEnd = this.getCells({
644
+ start: { col: 0, row: 0 },
645
+ end: { col: this.frozen.frozenColsEnd, row: this.frozen.frozenRowsEnd },
646
+ }, 'fixedEndEnd');
647
+ }
648
+ }
649
+ }
650
+ // Focus handlers
651
+ setFocus(coords, snap = true) {
652
+ this.setFocusedCell(coords);
653
+ this.focusActive = true;
654
+ if (snap) {
655
+ this.snapPosToFocusedCell();
656
+ }
657
+ }
658
+ handleFocus(event) {
659
+ const cellCoords = closestCell(event.target);
660
+ if (cellCoords) {
661
+ this.focusActive = true;
662
+ this.setFocusedCell(cellCoords);
663
+ }
664
+ }
665
+ handleBlur(event) {
666
+ // Only unset `focusActive` if focus is not moving to an element within the grid.
667
+ if (!event.relatedTarget || !event.relatedTarget.closest(`[data-grid="${this.gridId}"]`)) {
668
+ this.focusActive = false;
669
+ }
670
+ }
671
+ focusedCellQuery() {
672
+ return `[data-dx-grid-plane=${this.focusedCell.plane}] > [aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`;
673
+ }
674
+ focusedCellElement() {
675
+ var _a;
676
+ return (_a = this.viewportRef.value) === null || _a === void 0 ? void 0 : _a.querySelector(this.focusedCellQuery());
677
+ }
678
+ //
679
+ // `outOfVis` returns by how many rows/cols the focused cell is outside of the `vis` range for an axis, inset by a
680
+ // `delta`, otherwise zero if it is within that range.
681
+ //
682
+ focusedCellRowOutOfVis(minDelta = 0, maxDelta = minDelta) {
683
+ return this.focusedCell.row <= this.visRowMin + minDelta
684
+ ? this.focusedCell.row - (this.visRowMin + minDelta)
685
+ : this.focusedCell.row >= this.visRowMax - maxDelta
686
+ ? -(this.focusedCell.row - this.visRowMax - maxDelta)
687
+ : 0;
688
+ }
689
+ focusedCellColOutOfVis(minDelta = 0, maxDelta = minDelta) {
690
+ return this.focusedCell.col <= this.visColMin + minDelta
691
+ ? this.focusedCell.col - (this.visColMin + minDelta)
692
+ : this.focusedCell.col >= this.visColMax - maxDelta
693
+ ? -(this.focusedCell.col - this.visColMax - maxDelta)
694
+ : 0;
695
+ }
696
+ focusedCellOutOfVis(colDelta = 0, rowDelta = colDelta) {
697
+ switch (this.focusedCell.plane) {
698
+ case 'grid':
699
+ return { row: this.focusedCellRowOutOfVis(rowDelta), col: this.focusedCellColOutOfVis(colDelta) };
700
+ case 'frozenRowsStart':
701
+ case 'frozenRowsEnd':
702
+ return { col: this.focusedCellColOutOfVis(colDelta), row: 0 };
703
+ case 'frozenColsStart':
704
+ case 'frozenColsEnd':
705
+ return { col: 0, row: this.focusedCellRowOutOfVis(rowDelta) };
706
+ default:
707
+ return { col: 0, row: 0 };
708
+ }
709
+ }
710
+ /**
711
+ * Moves focus to the cell with actual focus, otherwise moves focus to the viewport.
712
+ */
713
+ refocus(increment, delta = 1) {
714
+ if (increment) {
715
+ switch (increment) {
716
+ case 'col': {
717
+ this.focusedCell.col += delta;
718
+ break;
719
+ }
720
+ case 'row': {
721
+ this.focusedCell.row += delta;
722
+ break;
723
+ }
724
+ }
725
+ this.snapPosToFocusedCell();
726
+ }
727
+ queueMicrotask(() => {
728
+ var _a;
729
+ const outOfVis = this.focusedCellOutOfVis();
730
+ const cellVisible = outOfVis.col === 0 && outOfVis.row === 0;
731
+ if (cellVisible) {
732
+ const cellElement = this.focusedCellElement();
733
+ if (cellElement && cellElement !== document.activeElement) {
734
+ cellElement.focus({ preventScroll: true });
735
+ }
736
+ }
737
+ else {
738
+ (_a = this.viewportRef.value) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
739
+ }
740
+ });
741
+ }
742
+ findPosInlineFromVisColMin(deltaCols) {
743
+ return [...Array(deltaCols)].reduce((acc, _, c0) => acc - this.colSize(this.visColMin - c0, 'grid') - gap, this.binInlineMin + gap);
744
+ }
745
+ findPosBlockFromVisRowMin(deltaRows) {
746
+ return [...Array(deltaRows)].reduce((acc, _, r0) => acc - this.rowSize(this.visRowMin - r0, 'grid') - gap, this.binBlockMin + gap);
747
+ }
748
+ /**
749
+ * Updates `pos` so that a cell in focus is fully within the viewport
750
+ */
751
+ snapPosToFocusedCell() {
752
+ const outOfVis = this.focusedCellOutOfVis(overscanCol, overscanRow);
753
+ if (outOfVis.col < 0) {
754
+ this.posInline = this.findPosInlineFromVisColMin(-outOfVis.col);
755
+ this.updateVisInline();
756
+ }
757
+ else if (outOfVis.col > 0) {
758
+ const sizeSumCol = [...Array(this.focusedCell.col - this.visColMin)].reduce((acc, _, c0) => {
759
+ acc += this.colSize(this.visColMin + overscanCol + c0, 'grid') + gap;
760
+ return acc;
761
+ }, 0);
762
+ this.posInline = Math.max(0, Math.min(this.intrinsicInlineSize - this.sizeInline, this.binInlineMin + sizeSumCol - this.sizeInline));
763
+ this.updateVisInline();
764
+ }
765
+ if (outOfVis.row < 0) {
766
+ this.posBlock = this.findPosBlockFromVisRowMin(-outOfVis.row);
767
+ this.updateVisBlock();
768
+ }
769
+ else if (outOfVis.row > 0) {
770
+ const sizeSumRow = [...Array(this.focusedCell.row - this.visRowMin)].reduce((acc, _, r0) => {
771
+ acc += this.rowSize(this.visRowMin + overscanRow + r0, 'grid') + gap;
772
+ return acc;
773
+ }, 0);
774
+ this.posBlock = Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, this.binBlockMin + sizeSumRow - this.sizeBlock));
775
+ this.updateVisBlock();
776
+ }
777
+ }
778
+ //
779
+ // Map scroll DOM methods to virtualized value.
780
+ //
781
+ get scrollLeft() {
782
+ return this.posInline;
783
+ }
784
+ set scrollLeft(nextValue) {
785
+ this.posInline = nextValue;
786
+ this.maybeUpdateVisInline();
787
+ }
788
+ get scrollTop() {
789
+ return this.posBlock;
790
+ }
791
+ set scrollTop(nextValue) {
792
+ this.posBlock = nextValue;
793
+ this.maybeUpdateVisBlock();
794
+ }
795
+ //
796
+ // Resize handlers
797
+ //
798
+ axisResizeable(plane, axis, index) {
799
+ var _a, _b, _c, _d, _e, _f, _g, _h;
800
+ return axis === 'col'
801
+ ? !!((_c = (_b = (_a = this.columns[plane]) === null || _a === void 0 ? void 0 : _a[index]) === null || _b === void 0 ? void 0 : _b.resizeable) !== null && _c !== void 0 ? _c : (_d = this.columnDefault[plane]) === null || _d === void 0 ? void 0 : _d.resizeable)
802
+ : !!((_g = (_f = (_e = this.rows[plane]) === null || _e === void 0 ? void 0 : _e[index]) === null || _f === void 0 ? void 0 : _f.resizeable) !== null && _g !== void 0 ? _g : (_h = this.rowDefault[plane]) === null || _h === void 0 ? void 0 : _h.resizeable);
803
+ }
804
+ handleAxisResizeInternal(event) {
805
+ event.stopPropagation();
806
+ const { plane, axis, delta, size, index, state } = event;
807
+ if (axis === 'col') {
808
+ const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, size + delta));
809
+ this.colSizes = { ...this.colSizes, [plane]: { ...this.colSizes[plane], [index]: nextSize } };
810
+ this.updateVisInline();
811
+ this.updateIntrinsicInlineSize();
812
+ }
813
+ else {
814
+ const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, size + delta));
815
+ this.rowSizes = { ...this.colSizes, [plane]: { ...this.rowSizes[plane], [index]: nextSize } };
816
+ this.updateVisBlock();
817
+ this.updateIntrinsicBlockSize();
818
+ }
819
+ if (state === 'dropped') {
820
+ this.dispatchEvent(new DxAxisResize({
821
+ plane,
822
+ axis,
823
+ index,
824
+ size: this[`${axis}Size`](index, plane),
825
+ }));
826
+ }
827
+ }
828
+ //
829
+ // Render and other lifecycle methods
830
+ //
831
+ renderFixed(plane, selection) {
832
+ const colPlane = resolveColPlane(plane);
833
+ const rowPlane = resolveRowPlane(plane);
834
+ const cols = this.frozen[colPlane];
835
+ const rows = this.frozen[rowPlane];
836
+ return (cols !== null && cols !== void 0 ? cols : 0) > 0 && (rows !== null && rows !== void 0 ? rows : 0) > 0
837
+ ? html `<div
838
+ role="none"
839
+ data-dx-grid-plane=${plane}
840
+ class="dx-grid__plane--fixed"
841
+ style=${styleMap({
842
+ 'grid-template-columns': this[`template${colPlane}`],
843
+ 'grid-template-rows': this[`template${rowPlane}`],
844
+ })}
845
+ >
846
+ ${[...Array(rows)].map((_, r) => {
847
+ return [...Array(cols)].map((_, c) => {
848
+ return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection));
849
+ });
850
+ })}
851
+ </div>`
852
+ : null;
853
+ }
854
+ renderFrozenRows(plane, visibleCols, offsetInline, selection) {
855
+ const rowPlane = resolveRowPlane(plane);
856
+ const rows = this.frozen[rowPlane];
857
+ return (rows !== null && rows !== void 0 ? rows : 0) > 0
858
+ ? html `<div role="none" class="dx-grid__plane--frozen-row">
859
+ <div
860
+ role="none"
861
+ data-dx-grid-plane=${plane}
862
+ class="dx-grid__plane--frozen-row__content"
863
+ style="transform:translate3d(${offsetInline}px,0,0);grid-template-columns:${this
864
+ .templateGridColumns};grid-template-rows:${this[`template${rowPlane}`]}"
865
+ >
866
+ ${[...Array(rows)].map((_, r) => {
867
+ return [...Array(visibleCols)].map((_, c0) => {
868
+ const c = this.visColMin + c0;
869
+ return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection), c0, r);
870
+ });
871
+ })}
872
+ </div>
873
+ </div>`
874
+ : null;
875
+ }
876
+ renderFrozenColumns(plane, visibleRows, offsetBlock, selection) {
877
+ const colPlane = resolveColPlane(plane);
878
+ const cols = this.frozen[colPlane];
879
+ return (cols !== null && cols !== void 0 ? cols : 0) > 0
880
+ ? html `<div role="none" class="dx-grid__plane--frozen-col">
881
+ <div
882
+ role="none"
883
+ data-dx-grid-plane=${plane}
884
+ class="dx-grid__plane--frozen-col__content"
885
+ style="transform:translate3d(0,${offsetBlock}px,0);grid-template-rows:${this
886
+ .templateGridRows};grid-template-columns:${this[`template${colPlane}`]}"
887
+ >
888
+ ${[...Array(visibleRows)].map((_, r0) => {
889
+ return [...Array(cols)].map((_, c) => {
890
+ const r = this.visRowMin + r0;
891
+ return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection), c, r0);
892
+ });
893
+ })}
894
+ </div>
895
+ </div>`
896
+ : null;
897
+ }
898
+ cellReadonly(col, row, plane) {
899
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
900
+ const colPlane = resolveColPlane(plane);
901
+ const rowPlane = resolveRowPlane(plane);
902
+ return (((_d = (_c = (_b = (_a = this.columns) === null || _a === void 0 ? void 0 : _a[colPlane]) === null || _b === void 0 ? void 0 : _b[col]) === null || _c === void 0 ? void 0 : _c.readonly) !== null && _d !== void 0 ? _d : (_f = (_e = this.columnDefault) === null || _e === void 0 ? void 0 : _e[colPlane]) === null || _f === void 0 ? void 0 : _f.readonly) ||
903
+ ((_k = (_j = (_h = (_g = this.rows) === null || _g === void 0 ? void 0 : _g[rowPlane]) === null || _h === void 0 ? void 0 : _h[row]) === null || _j === void 0 ? void 0 : _j.readonly) !== null && _k !== void 0 ? _k : (_m = (_l = this.rowDefault) === null || _l === void 0 ? void 0 : _l[rowPlane]) === null || _m === void 0 ? void 0 : _m.readonly));
904
+ }
905
+ renderCell(col, row, plane, selected, visCol = col, visRow = row) {
906
+ var _a, _b;
907
+ const cell = this.cell(col, row, plane);
908
+ const active = this.cellActive(col, row, plane);
909
+ const readonly = this.cellReadonly(col, row, plane);
910
+ const resizeIndex = (cell === null || cell === void 0 ? void 0 : cell.resizeHandle) ? (cell.resizeHandle === 'col' ? col : row) : undefined;
911
+ const resizePlane = (cell === null || cell === void 0 ? void 0 : cell.resizeHandle) ? resolveFrozenPlane(cell.resizeHandle, plane) : undefined;
912
+ const accessory = (cell === null || cell === void 0 ? void 0 : cell.accessoryHtml) ? staticHtml `${unsafeStatic(cell.accessoryHtml)}` : null;
913
+ return html `<div
914
+ role="gridcell"
915
+ tabindex="0"
916
+ ?inert=${col < 0 || row < 0}
917
+ aria-selected=${selected ? 'true' : nothing}
918
+ aria-readonly=${readonly ? 'true' : nothing}
919
+ class=${(_a = cell === null || cell === void 0 ? void 0 : cell.className) !== null && _a !== void 0 ? _a : nothing}
920
+ data-refs=${(_b = cell === null || cell === void 0 ? void 0 : cell.dataRefs) !== null && _b !== void 0 ? _b : nothing}
921
+ ?data-dx-active=${active}
922
+ data-dx-grid-action="cell"
923
+ aria-colindex=${col}
924
+ aria-rowindex=${row}
925
+ style="grid-column:${visCol + 1};grid-row:${visRow + 1}"
926
+ >
927
+ ${this.mode === 'edit' && active ? null : cell === null || cell === void 0 ? void 0 : cell.value}${this.mode === 'edit' && active
928
+ ? null
929
+ : accessory}${(cell === null || cell === void 0 ? void 0 : cell.resizeHandle) && this.axisResizeable(resizePlane, cell.resizeHandle, resizeIndex)
930
+ ? html `<dx-grid-axis-resize-handle
931
+ axis=${cell.resizeHandle}
932
+ plane=${resizePlane}
933
+ index=${resizeIndex}
934
+ size=${this[`${cell.resizeHandle}Size`](resizeIndex, plane)}
935
+ ></dx-grid-axis-resize-handle>`
936
+ : null}
937
+ </div>`;
938
+ }
939
+ render() {
940
+ const visibleCols = this.visColMax - this.visColMin;
941
+ const visibleRows = this.visRowMax - this.visRowMin;
942
+ const offsetInline = this.binInlineMin - this.posInline - this.overscanInline;
943
+ const offsetBlock = this.binBlockMin - this.posBlock - this.overscanBlock;
944
+ const selection = selectionProps(this.selectionStart, this.selectionEnd);
945
+ return html `<style>
946
+ ${this.activeRefs
947
+ .split(' ')
948
+ .filter((value) => value)
949
+ .map((activeRef) => `[data-refs~="${activeRef}"] { background: var(--dx-grid-commented-active, var(--dx-gridCommentedActive)) !important; }`)
950
+ .join('\n')}
951
+ </style>
952
+ <div
953
+ role="none"
954
+ class="dx-grid"
955
+ style=${styleMap({
956
+ 'grid-template-columns': `${this.templatefrozenColsStart ? 'min-content ' : ''}minmax(0, ${Number.isFinite(this.limitColumns) ? `${this.intrinsicInlineSize}px` : '1fr'})${this.templatefrozenColsEnd ? ' min-content' : ''}`,
957
+ 'grid-template-rows': `${this.templatefrozenRowsStart ? 'min-content ' : ''}minmax(0, ${Number.isFinite(this.limitRows) ? `${this.intrinsicBlockSize}px` : '1fr'})${this.templatefrozenRowsEnd ? ' min-content' : ''}`,
958
+ })}
959
+ data-grid=${this.gridId}
960
+ data-grid-mode=${this.mode}
961
+ ?data-grid-select=${selection.visible}
962
+ >
963
+ ${this.renderFixed('fixedStartStart', selection)}${this.renderFrozenRows('frozenRowsStart', visibleCols, offsetInline, selection)}${this.renderFixed('fixedStartEnd', selection)}${this.renderFrozenColumns('frozenColsStart', visibleRows, offsetBlock, selection)}
964
+ <div role="grid" class="dx-grid__plane--grid" tabindex="0" ${ref(this.viewportRef)}>
965
+ <div
966
+ role="none"
967
+ class="dx-grid__plane--grid__content"
968
+ data-dx-grid-plane="grid"
969
+ style="transform:translate3d(${offsetInline}px,${offsetBlock}px,0);grid-template-columns:${this
970
+ .templateGridColumns};grid-template-rows:${this.templateGridRows};"
971
+ >
972
+ ${[...Array(visibleRows)].map((_, r0) => {
973
+ return [...Array(visibleCols)].map((_, c0) => {
974
+ const c = c0 + this.visColMin;
975
+ const r = r0 + this.visRowMin;
976
+ return this.renderCell(c, r, 'grid', cellSelected(c, r, 'grid', selection), c0, r0);
977
+ });
978
+ })}
979
+ </div>
980
+ </div>
981
+ ${this.renderFrozenColumns('frozenColsEnd', visibleRows, offsetBlock, selection)}${this.renderFixed('fixedEndStart', selection)}${this.renderFrozenRows('frozenRowsEnd', visibleCols, offsetInline, selection)}${this.renderFixed('fixedEndEnd', selection)}
982
+ </div>`;
983
+ }
984
+ updateIntrinsicInlineSize() {
985
+ this.intrinsicInlineSize = Number.isFinite(this.limitColumns)
986
+ ? [...Array(this.limitColumns)].reduce((acc, _, c0) => acc + this.colSize(c0, 'grid'), 0) +
987
+ gap * (this.limitColumns - 1)
988
+ : Infinity;
989
+ }
990
+ updateIntrinsicBlockSize() {
991
+ this.intrinsicBlockSize = Number.isFinite(this.limitRows)
992
+ ? [...Array(this.limitRows)].reduce((acc, _, r0) => acc + this.rowSize(r0, 'grid'), 0) +
993
+ gap * (this.limitRows - 1)
994
+ : Infinity;
995
+ }
996
+ updateIntrinsicSizes() {
997
+ this.updateIntrinsicInlineSize();
998
+ this.updateIntrinsicBlockSize();
999
+ }
1000
+ computeColSizes() {
1001
+ var _a;
1002
+ this.colSizes = Object.entries((_a = this.columns) !== null && _a !== void 0 ? _a : {}).reduce((acc, [plane, planeColMeta]) => {
1003
+ acc[plane] = Object.entries(planeColMeta).reduce((planeAcc, [col, colMeta]) => {
1004
+ if (colMeta === null || colMeta === void 0 ? void 0 : colMeta.size) {
1005
+ planeAcc[col] = colMeta.size;
1006
+ }
1007
+ return planeAcc;
1008
+ }, {});
1009
+ return acc;
1010
+ }, { grid: {} });
1011
+ }
1012
+ computeRowSizes() {
1013
+ var _a;
1014
+ this.rowSizes = Object.entries((_a = this.rows) !== null && _a !== void 0 ? _a : {}).reduce((acc, [plane, planeRowMeta]) => {
1015
+ acc[plane] = Object.entries(planeRowMeta).reduce((planeAcc, [row, rowMeta]) => {
1016
+ if (rowMeta === null || rowMeta === void 0 ? void 0 : rowMeta.size) {
1017
+ planeAcc[row] = rowMeta.size;
1018
+ }
1019
+ return planeAcc;
1020
+ }, {});
1021
+ return acc;
1022
+ }, { grid: {} });
1023
+ }
1024
+ firstUpdated() {
1025
+ if (this.getCells) {
1026
+ this.updateCells(true);
1027
+ }
1028
+ this.observer.observe(this.viewportRef.value);
1029
+ this.computeColSizes();
1030
+ this.computeRowSizes();
1031
+ this.updateIntrinsicSizes();
1032
+ }
1033
+ willUpdate(changedProperties) {
1034
+ if (this.getCells &&
1035
+ (changedProperties.has('initialCells') ||
1036
+ changedProperties.has('visColMin') ||
1037
+ changedProperties.has('visColMax') ||
1038
+ changedProperties.has('visRowMin') ||
1039
+ changedProperties.has('visRowMax'))) {
1040
+ this.updateCells();
1041
+ }
1042
+ if (changedProperties.has('rowDefault') || changedProperties.has('rows') || changedProperties.has('limitRows')) {
1043
+ this.updateIntrinsicBlockSize();
1044
+ this.updatePosBlock();
1045
+ this.updateVisBlock();
1046
+ }
1047
+ if (changedProperties.has('colDefault') ||
1048
+ changedProperties.has('columns') ||
1049
+ changedProperties.has('limitColumns')) {
1050
+ this.updateIntrinsicInlineSize();
1051
+ this.updatePosInline();
1052
+ this.updateVisInline();
1053
+ }
1054
+ if (changedProperties.has('columns')) {
1055
+ this.computeColSizes();
1056
+ this.updateIntrinsicInlineSize();
1057
+ }
1058
+ if (changedProperties.has('rows')) {
1059
+ this.computeRowSizes();
1060
+ this.updateIntrinsicBlockSize();
1061
+ }
1062
+ }
1063
+ updated(changedProperties) {
1064
+ // Update the focused element if there is a change in bounds (otherwise Lit keeps focus on the relative element).
1065
+ if (this.focusActive &&
1066
+ (changedProperties.has('visRowMin') || changedProperties.has('visColMin') || changedProperties.has('focusedCell'))) {
1067
+ this.refocus();
1068
+ }
1069
+ }
1070
+ updateIfWithinBounds({ col, row }) {
1071
+ if (col >= this.visColMin && col <= this.visColMax && row >= this.visRowMin && row <= this.visRowMax) {
1072
+ this.requestUpdate();
1073
+ return true;
1074
+ }
1075
+ return false;
1076
+ }
1077
+ disconnectedCallback() {
1078
+ var _a;
1079
+ super.disconnectedCallback();
1080
+ if (this.viewportRef.value) {
1081
+ this.observer.unobserve(this.viewportRef.value);
1082
+ }
1083
+ (_a = document.defaultView) === null || _a === void 0 ? void 0 : _a.removeEventListener('wheel', this.handleTopLevelWheel);
1084
+ }
1085
+ createRenderRoot() {
1086
+ return this;
1087
+ }
1088
+ };
1089
+ __decorate([
1090
+ property({ type: String })
1091
+ ], DxGrid.prototype, "gridId", void 0);
1092
+ __decorate([
1093
+ property({ type: Object })
1094
+ ], DxGrid.prototype, "rowDefault", void 0);
1095
+ __decorate([
1096
+ property({ type: Object })
1097
+ ], DxGrid.prototype, "columnDefault", void 0);
1098
+ __decorate([
1099
+ property({ type: Object })
1100
+ ], DxGrid.prototype, "rows", void 0);
1101
+ __decorate([
1102
+ property({ type: Object })
1103
+ ], DxGrid.prototype, "columns", void 0);
1104
+ __decorate([
1105
+ property({ type: Object })
1106
+ ], DxGrid.prototype, "initialCells", void 0);
1107
+ __decorate([
1108
+ property({ type: String })
1109
+ ], DxGrid.prototype, "mode", void 0);
1110
+ __decorate([
1111
+ property({ type: Number })
1112
+ ], DxGrid.prototype, "limitColumns", void 0);
1113
+ __decorate([
1114
+ property({ type: Number })
1115
+ ], DxGrid.prototype, "limitRows", void 0);
1116
+ __decorate([
1117
+ property({ type: Object })
1118
+ ], DxGrid.prototype, "frozen", void 0);
1119
+ __decorate([
1120
+ property({ type: String })
1121
+ ], DxGrid.prototype, "overscroll", void 0);
1122
+ __decorate([
1123
+ property({ type: String })
1124
+ ], DxGrid.prototype, "activeRefs", void 0);
1125
+ __decorate([
1126
+ state()
1127
+ ], DxGrid.prototype, "cells", void 0);
1128
+ __decorate([
1129
+ state()
1130
+ ], DxGrid.prototype, "posInline", void 0);
1131
+ __decorate([
1132
+ state()
1133
+ ], DxGrid.prototype, "posBlock", void 0);
1134
+ __decorate([
1135
+ state()
1136
+ ], DxGrid.prototype, "sizeInline", void 0);
1137
+ __decorate([
1138
+ state()
1139
+ ], DxGrid.prototype, "sizeBlock", void 0);
1140
+ __decorate([
1141
+ state()
1142
+ ], DxGrid.prototype, "overscanInline", void 0);
1143
+ __decorate([
1144
+ state()
1145
+ ], DxGrid.prototype, "overscanBlock", void 0);
1146
+ __decorate([
1147
+ state()
1148
+ ], DxGrid.prototype, "binInlineMin", void 0);
1149
+ __decorate([
1150
+ state()
1151
+ ], DxGrid.prototype, "binInlineMax", void 0);
1152
+ __decorate([
1153
+ state()
1154
+ ], DxGrid.prototype, "binBlockMin", void 0);
1155
+ __decorate([
1156
+ state()
1157
+ ], DxGrid.prototype, "binBlockMax", void 0);
1158
+ __decorate([
1159
+ state()
1160
+ ], DxGrid.prototype, "visColMin", void 0);
1161
+ __decorate([
1162
+ state()
1163
+ ], DxGrid.prototype, "visColMax", void 0);
1164
+ __decorate([
1165
+ state()
1166
+ ], DxGrid.prototype, "visRowMin", void 0);
1167
+ __decorate([
1168
+ state()
1169
+ ], DxGrid.prototype, "visRowMax", void 0);
1170
+ __decorate([
1171
+ state()
1172
+ ], DxGrid.prototype, "templateGridColumns", void 0);
1173
+ __decorate([
1174
+ state()
1175
+ ], DxGrid.prototype, "templatefrozenColsStart", void 0);
1176
+ __decorate([
1177
+ state()
1178
+ ], DxGrid.prototype, "templatefrozenColsEnd", void 0);
1179
+ __decorate([
1180
+ state()
1181
+ ], DxGrid.prototype, "templateGridRows", void 0);
1182
+ __decorate([
1183
+ state()
1184
+ ], DxGrid.prototype, "templatefrozenRowsStart", void 0);
1185
+ __decorate([
1186
+ state()
1187
+ ], DxGrid.prototype, "templatefrozenRowsEnd", void 0);
1188
+ __decorate([
1189
+ state()
1190
+ ], DxGrid.prototype, "pointer", void 0);
1191
+ __decorate([
1192
+ state()
1193
+ ], DxGrid.prototype, "colSizes", void 0);
1194
+ __decorate([
1195
+ state()
1196
+ ], DxGrid.prototype, "rowSizes", void 0);
1197
+ __decorate([
1198
+ state()
1199
+ ], DxGrid.prototype, "focusActive", void 0);
1200
+ __decorate([
1201
+ state()
1202
+ ], DxGrid.prototype, "focusedCell", void 0);
1203
+ __decorate([
1204
+ state()
1205
+ ], DxGrid.prototype, "selectionStart", void 0);
1206
+ __decorate([
1207
+ state()
1208
+ ], DxGrid.prototype, "selectionEnd", void 0);
1209
+ __decorate([
1210
+ state()
1211
+ ], DxGrid.prototype, "intrinsicInlineSize", void 0);
1212
+ __decorate([
1213
+ state()
1214
+ ], DxGrid.prototype, "intrinsicBlockSize", void 0);
1215
+ __decorate([
1216
+ state()
1217
+ ], DxGrid.prototype, "observer", void 0);
1218
+ DxGrid = __decorate([
1219
+ customElement('dx-grid')
1220
+ ], DxGrid);
1221
+ export { DxGrid };
1222
+ export { rowToA1Notation, colToA1Notation } from './util';
1223
+ export const commentedClassName = 'dx-grid__cell--commented';
1224
+ //# sourceMappingURL=dx-grid.js.map