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

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