@dxos/lit-grid 0.6.11 → 0.6.12-main.2d19bf1

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