@dxos/lit-grid 0.6.12 → 0.6.13-main.09887cd

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