@dxos/lit-grid 0.6.12-main.c1d977f → 0.6.12-main.c974201

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.
@@ -1,51 +1,21 @@
1
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";
2
+ import { LitElement, html, nothing } from "lit";
3
+ import { customElement, state, property, eventOptions } from "lit/decorators.js";
4
+ import { ref, createRef } from "lit/directives/ref.js";
14
5
 
15
6
  // packages/ui/lit-grid/src/util.ts
16
7
  var separator = ",";
17
8
  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
9
 
25
10
  // packages/ui/lit-grid/src/types.ts
26
11
  var DxAxisResize = class extends Event {
27
12
  constructor(props) {
28
13
  super("dx-axis-resize");
29
14
  this.axis = props.axis;
30
- this.plane = props.plane;
31
15
  this.index = props.index;
32
16
  this.size = props.size;
33
17
  }
34
18
  };
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
19
  var DxEditRequest = class extends Event {
50
20
  constructor(props) {
51
21
  super("dx-edit-request");
@@ -66,137 +36,26 @@ var DxGridCellsSelect = class extends Event {
66
36
  }
67
37
  };
68
38
 
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
39
  // packages/ui/lit-grid/src/dx-grid.ts
160
- function _ts_decorate2(decorators, target, key, desc) {
40
+ function _ts_decorate(decorators, target, key, desc) {
161
41
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
162
42
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
163
43
  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
44
  return c > 3 && r && Object.defineProperty(target, key, r), r;
165
45
  }
166
46
  var gap = 1;
167
- var resizeTolerance = 1;
168
- var selectTolerance = 4;
47
+ var resizeTolerance = 8;
169
48
  var overscanCol = 1;
170
49
  var overscanRow = 1;
171
50
  var sizeColMin = 32;
172
51
  var sizeColMax = 1024;
173
52
  var sizeRowMin = 16;
174
53
  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
- };
54
+ var colToA1Notation = (col) => {
55
+ return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
197
56
  };
198
- var cellSelected = (col, row, plane, selection) => {
199
- return plane === selection.plane && col >= selection.colMin && col <= selection.colMax && row >= selection.rowMin && row <= selection.rowMax;
57
+ var rowToA1Notation = (row) => {
58
+ return `${row + 1}`;
200
59
  };
201
60
  var closestAction = (target) => {
202
61
  const actionEl = target?.closest("[data-dx-grid-action]") ?? null;
@@ -216,9 +75,7 @@ var closestCell = (target, actionEl) => {
216
75
  if (cellElement) {
217
76
  const col = parseInt(cellElement.getAttribute("aria-colindex") ?? "never");
218
77
  const row = parseInt(cellElement.getAttribute("aria-rowindex") ?? "never");
219
- const plane = cellElement.closest("[data-dx-grid-plane]")?.getAttribute("data-dx-grid-plane") ?? "grid";
220
78
  return {
221
- plane,
222
79
  col,
223
80
  row
224
81
  };
@@ -226,92 +83,24 @@ var closestCell = (target, actionEl) => {
226
83
  return null;
227
84
  }
228
85
  };
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 {
86
+ var isSameCell = (a, b) => a && b && Number.isFinite(a.col) && Number.isFinite(a.row) && a.col === b.col && a.row === b.row;
87
+ var localChId = (c0) => `ch--${c0}`;
88
+ var localRhId = (r0) => `rh--${r0}`;
89
+ var getPage = (axis, event) => axis === "col" ? event.pageX : event.pageY;
90
+ var DxGrid = class extends LitElement {
281
91
  constructor() {
282
- super();
92
+ super(...arguments);
283
93
  this.gridId = "default-grid-id";
284
94
  this.rowDefault = {
285
- grid: {
286
- size: defaultRowSize
287
- }
95
+ size: 32
288
96
  };
289
97
  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: {}
98
+ size: 180
302
99
  };
100
+ this.rows = {};
101
+ this.columns = {};
102
+ this.cells = {};
303
103
  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
104
  //
316
105
  // `pos`, short for ‘position’, is the position in pixels of the viewport from the origin.
317
106
  //
@@ -331,9 +120,9 @@ var DxGrid = class extends LitElement2 {
331
120
  // `bin`, not short for anything, is the range in pixels within which virtualization does not need to reassess.
332
121
  //
333
122
  this.binInlineMin = 0;
334
- this.binInlineMax = defaultColSize;
123
+ this.binInlineMax = this.colSize(0);
335
124
  this.binBlockMin = 0;
336
- this.binBlockMax = defaultRowSize;
125
+ this.binBlockMax = this.rowSize(0);
337
126
  //
338
127
  // `vis`, short for ‘visible’, is the range in numeric index of the columns or rows which should be rendered within
339
128
  // the viewport. These start with naïve values that are updated before first contentful render.
@@ -345,57 +134,48 @@ var DxGrid = class extends LitElement2 {
345
134
  //
346
135
  // `template` is the rendered value of `grid-{axis}-template`.
347
136
  //
348
- this.templateGridColumns = "0";
349
- this.templatefrozenColsStart = "";
350
- this.templatefrozenColsEnd = "";
351
- this.templateGridRows = "0";
352
- this.templatefrozenRowsStart = "";
353
- this.templatefrozenRowsEnd = "";
137
+ this.templateColumns = `${this.colSize(0)}px`;
138
+ this.templateRows = `${this.rowSize(0)}px`;
354
139
  //
355
140
  // Focus, selection, and resize states
356
141
  //
357
142
  this.pointer = null;
358
- this.colSizes = {
359
- grid: {}
360
- };
361
- this.rowSizes = {
362
- grid: {}
363
- };
143
+ this.colSizes = {};
144
+ this.rowSizes = {};
364
145
  this.focusActive = false;
365
146
  this.focusedCell = {
366
- plane: "grid",
367
147
  col: 0,
368
148
  row: 0
369
149
  };
370
150
  this.selectionStart = {
371
- plane: "grid",
372
151
  col: 0,
373
152
  row: 0
374
153
  };
375
154
  this.selectionEnd = {
376
- plane: "grid",
377
155
  col: 0,
378
156
  row: 0
379
157
  };
380
- //
381
- // Limits
382
- //
383
- this.intrinsicInlineSize = Infinity;
384
- this.intrinsicBlockSize = Infinity;
385
158
  this.handlePointerDown = (event) => {
386
159
  if (event.isPrimary) {
387
160
  const { action, actionEl } = closestAction(event.target);
388
161
  if (action) {
389
- if (action === "cell") {
162
+ if (action.startsWith("resize") && this.mode === "browse") {
163
+ const [resize, index] = action.split(",");
164
+ const [_, axis] = resize.split("-");
165
+ this.pointer = {
166
+ state: "resizing",
167
+ axis,
168
+ size: axis === "col" ? this.colSize(index) : this.rowSize(index),
169
+ page: getPage(axis, event),
170
+ index
171
+ };
172
+ } else if (action === "cell") {
390
173
  const cellCoords = closestCell(event.target, actionEl);
391
174
  if (cellCoords) {
392
175
  this.pointer = {
393
- state: "maybeSelecting",
394
- pageX: event.pageX,
395
- pageY: event.pageY
176
+ state: "selecting"
396
177
  };
397
178
  this.selectionStart = cellCoords;
398
- this.selectionEnd = cellCoords;
399
179
  }
400
180
  if (this.mode === "edit") {
401
181
  event.preventDefault();
@@ -409,24 +189,46 @@ var DxGrid = class extends LitElement2 {
409
189
  }
410
190
  };
411
191
  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
- }));
192
+ if (this.pointer?.state === "resizing") {
193
+ const resizeEvent = new DxAxisResize({
194
+ axis: this.pointer.axis,
195
+ index: this.pointer.index,
196
+ size: this[this.pointer.axis === "col" ? "colSize" : "rowSize"](this.pointer.index)
197
+ });
198
+ this.dispatchEvent(resizeEvent);
199
+ } else {
200
+ const cell = closestCell(event.target);
201
+ if (cell) {
202
+ this.selectionEnd = cell;
203
+ this.dispatchEvent(new DxGridCellsSelect({
204
+ start: this.selectionStart,
205
+ end: this.selectionEnd
206
+ }));
207
+ }
419
208
  }
420
209
  this.pointer = null;
421
210
  };
422
211
  this.handlePointerMove = (event) => {
423
- if (shouldSelect(this.pointer, event)) {
424
- this.pointer = {
425
- state: "selecting"
426
- };
212
+ if (this.pointer?.state === "resizing") {
213
+ const delta = getPage(this.pointer.axis, event) - this.pointer.page;
214
+ if (this.pointer.axis === "col") {
215
+ const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, this.pointer.size + delta));
216
+ this.colSizes = {
217
+ ...this.colSizes,
218
+ [this.pointer.index]: nextSize
219
+ };
220
+ this.updateVisInline();
221
+ } else {
222
+ const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, this.pointer.size + delta));
223
+ this.rowSizes = {
224
+ ...this.rowSizes,
225
+ [this.pointer.index]: nextSize
226
+ };
227
+ this.updateVisBlock();
228
+ }
427
229
  } else if (this.pointer?.state === "selecting") {
428
230
  const cell = closestCell(event.target);
429
- if (cell && cell.plane === this.selectionStart.plane && (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
231
+ if (cell && (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
430
232
  this.selectionEnd = cell;
431
233
  }
432
234
  }
@@ -443,40 +245,19 @@ var DxGrid = class extends LitElement2 {
443
245
  this.sizeInline = inlineSize;
444
246
  this.sizeBlock = blockSize;
445
247
  this.updateVis();
446
- queueMicrotask(() => this.updatePos());
447
248
  }
448
249
  });
449
250
  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
251
  this.handleWheel = ({ deltaX, deltaY }) => {
461
252
  if (this.mode === "browse") {
462
- this.updatePos(this.posInline + deltaX, this.posBlock + deltaY);
253
+ this.posInline = Math.max(0, this.posInline + deltaX);
254
+ this.posBlock = Math.max(0, this.posBlock + deltaY);
255
+ if (this.posInline >= this.binInlineMin && this.posInline < this.binInlineMax && this.posBlock >= this.binBlockMin && this.posBlock < this.binBlockMax) {
256
+ } else {
257
+ this.updateVis();
258
+ }
463
259
  }
464
260
  };
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
261
  }
481
262
  //
482
263
  // Primary pointer and keyboard handlers
@@ -495,7 +276,7 @@ var DxGrid = class extends LitElement2 {
495
276
  case "ArrowDown":
496
277
  this.focusedCell = {
497
278
  ...this.focusedCell,
498
- row: Math.min(this.limitRows - 1, this.focusedCell.row + 1)
279
+ row: this.focusedCell.row + 1
499
280
  };
500
281
  break;
501
282
  case "ArrowUp":
@@ -507,7 +288,7 @@ var DxGrid = class extends LitElement2 {
507
288
  case "ArrowRight":
508
289
  this.focusedCell = {
509
290
  ...this.focusedCell,
510
- col: Math.min(this.limitColumns - 1, this.focusedCell.col + 1)
291
+ col: this.focusedCell.col + 1
511
292
  };
512
293
  break;
513
294
  case "ArrowLeft":
@@ -541,26 +322,20 @@ var DxGrid = class extends LitElement2 {
541
322
  //
542
323
  // Accessors
543
324
  //
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;
325
+ colSize(c) {
326
+ return this.colSizes?.[c] ?? this.columnDefault.size;
551
327
  }
552
- cell(c, r, plane) {
553
- const index = `${c}${separator}${r}`;
554
- return this.cells?.[plane]?.[index] ?? this.initialCells?.[plane]?.[index];
328
+ rowSize(r) {
329
+ return this.rowSizes?.[r] ?? this.rowDefault.size;
555
330
  }
556
- cellActive(c, r, plane) {
557
- return this.focusActive && this.focusedCell.plane === plane && this.focusedCell.col === c && this.focusedCell.row === r;
331
+ cell(c, r) {
332
+ return this.cells[`${c}${separator}${r}`];
558
333
  }
559
334
  focusedCellBox() {
560
335
  const cellElement = this.focusedCellElement();
561
336
  const cellSize = {
562
- inlineSize: this.colSize(this.focusedCell.col, this.focusedCell.plane),
563
- blockSize: this.rowSize(this.focusedCell.row, this.focusedCell.plane)
337
+ inlineSize: this.colSize(this.focusedCell.col),
338
+ blockSize: this.rowSize(this.focusedCell.row)
564
339
  };
565
340
  if (!cellElement) {
566
341
  return {
@@ -580,167 +355,60 @@ var DxGrid = class extends LitElement2 {
580
355
  ...cellSize
581
356
  };
582
357
  }
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
358
  updateVisInline() {
596
359
  let colIndex = 0;
597
- let pxInline = this.colSize(colIndex, "grid");
360
+ let pxInline = this.colSize(colIndex);
598
361
  while (pxInline < this.posInline) {
599
362
  colIndex += 1;
600
- pxInline += this.colSize(colIndex, "grid") + gap;
363
+ pxInline += this.colSize(colIndex) + gap;
601
364
  }
602
365
  this.visColMin = colIndex - overscanCol;
603
- this.binInlineMin = pxInline - this.colSize(colIndex, "grid") - gap;
366
+ this.binInlineMin = pxInline - this.colSize(colIndex) - gap;
604
367
  this.binInlineMax = pxInline + gap;
605
368
  this.overscanInline = [
606
369
  ...Array(overscanCol)
607
370
  ].reduce((acc, _, c0) => {
608
- acc += this.colSize(this.visColMin + c0, "grid");
371
+ acc += this.colSize(this.visColMin + c0);
609
372
  return acc;
610
373
  }, 0) + gap * (overscanCol - 1);
611
- while (pxInline < this.binInlineMax + this.sizeInline - gap * 2) {
374
+ while (pxInline < this.binInlineMax + this.sizeInline + gap) {
612
375
  colIndex += 1;
613
- pxInline += this.colSize(colIndex, "grid") + gap;
376
+ pxInline += this.colSize(colIndex) + gap;
614
377
  }
615
- this.visColMax = Math.min(this.limitColumns, colIndex + overscanCol);
616
- this.templateGridColumns = [
378
+ this.visColMax = colIndex + overscanCol;
379
+ this.templateColumns = [
617
380
  ...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(" ");
381
+ ].map((_, c0) => `${this.colSize(this.visColMin + c0)}px`).join(" ");
625
382
  }
626
383
  updateVisBlock() {
627
384
  let rowIndex = 0;
628
- let pxBlock = this.rowSize(rowIndex, "grid");
385
+ let pxBlock = this.rowSize(rowIndex);
629
386
  while (pxBlock < this.posBlock) {
630
387
  rowIndex += 1;
631
- pxBlock += this.rowSize(rowIndex, "grid") + gap;
388
+ pxBlock += this.rowSize(rowIndex) + gap;
632
389
  }
633
390
  this.visRowMin = rowIndex - overscanRow;
634
- this.binBlockMin = pxBlock - this.rowSize(rowIndex, "grid") - gap;
391
+ this.binBlockMin = pxBlock - this.rowSize(rowIndex) - gap;
635
392
  this.binBlockMax = pxBlock + gap;
636
393
  this.overscanBlock = [
637
394
  ...Array(overscanRow)
638
395
  ].reduce((acc, _, r0) => {
639
- acc += this.rowSize(this.visRowMin + r0, "grid");
396
+ acc += this.rowSize(this.visRowMin + r0);
640
397
  return acc;
641
398
  }, 0) + gap * (overscanRow - 1);
642
- while (pxBlock < this.binBlockMax + this.sizeBlock - gap * 2) {
399
+ while (pxBlock < this.binBlockMax + this.sizeBlock) {
643
400
  rowIndex += 1;
644
- pxBlock += this.rowSize(rowIndex, "grid") + gap;
401
+ pxBlock += this.rowSize(rowIndex) + gap;
645
402
  }
646
- this.visRowMax = Math.min(this.limitRows, rowIndex + overscanRow);
647
- this.templateGridRows = [
403
+ this.visRowMax = rowIndex + overscanRow;
404
+ this.templateRows = [
648
405
  ...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(" ");
406
+ ].map((_, r0) => `${this.rowSize(this.visRowMin + r0)}px`).join(" ");
656
407
  }
657
408
  updateVis() {
658
409
  this.updateVisInline();
659
410
  this.updateVisBlock();
660
411
  }
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
412
  // Focus handlers
745
413
  handleFocus(event) {
746
414
  const cellCoords = closestCell(event.target);
@@ -755,43 +423,7 @@ var DxGrid = class extends LitElement2 {
755
423
  }
756
424
  }
757
425
  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
- }
426
+ return this.viewportRef.value?.querySelector(`[aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`);
795
427
  }
796
428
  /**
797
429
  * Moves focus to the cell with actual focus, otherwise moves focus to the viewport.
@@ -810,238 +442,124 @@ var DxGrid = class extends LitElement2 {
810
442
  col: this.focusedCell.col + delta
811
443
  };
812
444
  }
445
+ (this.focusedCell.row < this.visRowMin || this.focusedCell.row > this.visRowMax || this.focusedCell.col < this.visColMin || this.focusedCell.col > this.visColMax ? this.viewportRef.value : this.focusedCellElement())?.focus({
446
+ preventScroll: true
447
+ });
813
448
  if (increment) {
814
449
  this.snapPosToFocusedCell();
815
450
  }
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
451
  }
833
452
  /**
834
453
  * Updates `pos` so that a cell in focus is fully within the viewport
835
454
  */
836
455
  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();
456
+ if (this.focusedCell.col < this.visColMin || this.focusedCell.col > this.visColMax || this.focusedCell.row < this.visRowMin || this.focusedCell.row > this.visRowMax) {
457
+ } else if (this.focusedCell.col > this.visColMin + overscanCol && this.focusedCell.col < this.visColMax - overscanCol - 1 && this.focusedCell.row > this.visRowMin + overscanRow && this.focusedCell.row < this.visRowMax - overscanRow - 1) {
902
458
  } 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
- }));
459
+ if (this.focusedCell.col <= this.visColMin + overscanCol) {
460
+ this.posInline = this.binInlineMin;
461
+ this.updateVisInline();
462
+ } else if (this.focusedCell.col >= this.visColMax - overscanCol - 1) {
463
+ const sizeSumCol = [
464
+ ...Array(this.focusedCell.col - this.visColMin)
465
+ ].reduce((acc, _, c0) => {
466
+ acc += this.colSize(this.visColMin + overscanCol + c0) + gap;
467
+ return acc;
468
+ }, 0);
469
+ this.posInline = Math.max(0, this.binInlineMin + sizeSumCol + gap * 2 - this.sizeInline);
470
+ this.updateVisInline();
471
+ }
472
+ if (this.focusedCell.row <= this.visRowMin + overscanRow) {
473
+ this.posBlock = this.binBlockMin;
474
+ this.updateVisBlock();
475
+ } else if (this.focusedCell.row >= this.visRowMax - overscanRow - 1) {
476
+ const sizeSumRow = [
477
+ ...Array(this.focusedCell.row - this.visRowMin)
478
+ ].reduce((acc, _, r0) => {
479
+ acc += this.rowSize(this.visRowMin + overscanRow + r0) + gap;
480
+ return acc;
481
+ }, 0);
482
+ this.posBlock = Math.max(0, this.binBlockMin + sizeSumRow + gap * 2 - this.sizeBlock);
483
+ this.updateVisBlock();
484
+ }
921
485
  }
922
486
  }
923
487
  //
924
488
  // Render and other lifecycle methods
925
489
  //
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
490
  render() {
1022
491
  const visibleCols = this.visColMax - this.visColMin;
1023
492
  const visibleRows = this.visRowMax - this.visRowMin;
1024
493
  const offsetInline = this.binInlineMin - this.posInline - this.overscanInline;
1025
494
  const offsetBlock = this.binBlockMin - this.posBlock - this.overscanBlock;
1026
- const selection = selectionProps(this.selectionStart, this.selectionEnd);
1027
- return html2`<div
495
+ const selectColMin = Math.min(this.selectionStart.col, this.selectionEnd.col);
496
+ const selectColMax = Math.max(this.selectionStart.col, this.selectionEnd.col);
497
+ const selectRowMin = Math.min(this.selectionStart.row, this.selectionEnd.row);
498
+ const selectRowMax = Math.max(this.selectionStart.row, this.selectionEnd.row);
499
+ const selectVisible = selectColMin !== selectColMax || selectRowMin !== selectRowMax;
500
+ return html`<div
1028
501
  role="none"
1029
502
  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
503
  data-grid=${this.gridId}
1035
504
  data-grid-mode=${this.mode}
1036
- ?data-grid-select=${selection.visible}
505
+ ?data-grid-select=${selectVisible}
506
+ @pointerdown=${this.handlePointerDown}
507
+ @pointerup=${this.handlePointerUp}
508
+ @pointermove=${this.handlePointerMove}
509
+ @pointerleave=${this.handlePointerUp}
510
+ @focus=${this.handleFocus}
511
+ @blur=${this.handleBlur}
512
+ @keydown=${this.handleKeydown}
1037
513
  >
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)}>
514
+ <div role="none" class="dx-grid__corner"></div>
515
+ <div role="none" class="dx-grid__columnheader">
1040
516
  <div
1041
517
  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};"
518
+ class="dx-grid__columnheader__content"
519
+ style="transform:translate3d(${offsetInline}px,0,0);grid-template-columns:${this.templateColumns};"
520
+ >
521
+ ${[
522
+ ...Array(visibleCols)
523
+ ].map((_, c0) => {
524
+ const c = this.visColMin + c0;
525
+ return html`<div
526
+ role="columnheader"
527
+ ?inert=${c < 0}
528
+ style="block-size:${this.rowDefault.size}px;grid-column:${c0 + 1}/${c0 + 2};"
529
+ >
530
+ <span id=${localChId(c0)}>${colToA1Notation(c)}</span>
531
+ ${(this.columns[c]?.resizeable ?? this.columnDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-col,${c}`}>
532
+ <span class="sr-only">Resize</span>
533
+ </button>`}
534
+ </div>`;
535
+ })}
536
+ </div>
537
+ </div>
538
+ <div role="none" class="dx-grid__corner"></div>
539
+ <div role="none" class="dx-grid__rowheader">
540
+ <div
541
+ role="none"
542
+ class="dx-grid__rowheader__content"
543
+ style="transform:translate3d(0,${offsetBlock}px,0);grid-template-rows:${this.templateRows};"
544
+ >
545
+ ${[
546
+ ...Array(visibleRows)
547
+ ].map((_, r0) => {
548
+ const r = this.visRowMin + r0;
549
+ return html`<div role="rowheader" ?inert=${r < 0} style="grid-row:${r0 + 1}/${r0 + 2}">
550
+ <span id=${localRhId(r0)}>${rowToA1Notation(r)}</span>
551
+ ${(this.rows[r]?.resizeable ?? this.rowDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-row,${r}`}>
552
+ <span class="sr-only">Resize</span>
553
+ </button>`}
554
+ </div>`;
555
+ })}
556
+ </div>
557
+ </div>
558
+ <div role="grid" class="dx-grid__viewport" tabindex="0" @wheel=${this.handleWheel} ${ref(this.viewportRef)}>
559
+ <div
560
+ role="none"
561
+ class="dx-grid__content"
562
+ style="transform:translate3d(${offsetInline}px,${offsetBlock}px,0);grid-template-columns:${this.templateColumns};grid-template-rows:${this.templateRows};"
1045
563
  >
1046
564
  ${[
1047
565
  ...Array(visibleCols)
@@ -1051,84 +569,56 @@ var DxGrid = class extends LitElement2 {
1051
569
  ].map((_2, r0) => {
1052
570
  const c = c0 + this.visColMin;
1053
571
  const r = r0 + this.visRowMin;
1054
- return this.renderCell(c, r, "grid", cellSelected(c, r, "grid", selection), c0, r0);
572
+ const cell = this.cell(c, r);
573
+ const active = this.focusActive && this.focusedCell.col === c && this.focusedCell.row === r;
574
+ const selected = c >= selectColMin && c <= selectColMax && r >= selectRowMin && r <= selectRowMax;
575
+ return html`<div
576
+ role="gridcell"
577
+ tabindex="0"
578
+ ?inert=${c < 0 || r < 0}
579
+ ?aria-selected=${selected}
580
+ class=${cell || active ? (cell?.className ? cell.className + " " : "") + (active ? "dx-grid__cell--active" : "") : nothing}
581
+ aria-rowindex=${r}
582
+ aria-colindex=${c}
583
+ data-dx-grid-action="cell"
584
+ style="grid-column:${c0 + 1};grid-row:${r0 + 1}"
585
+ >
586
+ ${cell?.value}
587
+ </div>`;
1055
588
  });
1056
589
  })}
1057
590
  </div>
1058
591
  </div>
1059
- ${this.renderFrozenColumns("frozenColsEnd", visibleRows, offsetBlock, selection)}${this.renderFixed("fixedEndStart", selection)}${this.renderFrozenRows("frozenRowsEnd", visibleCols, offsetInline, selection)}${this.renderFixed("fixedEndEnd", selection)}
592
+ <div role="none" class="dx-grid__scrollbar" aria-orientation="vertical">
593
+ <div role="none" class="dx-grid__scrollbar__thumb"></div>
594
+ </div>
595
+ <div role="none" class="dx-grid__corner"></div>
596
+ <div role="none" class="dx-grid__scrollbar" aria-orientation="horizontal">
597
+ <div role="none" class="dx-grid__scrollbar__thumb"></div>
598
+ </div>
599
+ <div role="none" class="dx-grid__corner"></div>
1060
600
  </div>`;
1061
601
  }
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
602
  firstUpdated() {
1077
- if (this.getCells) {
1078
- this.updateCells(true);
1079
- }
1080
603
  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
- }, {});
604
+ this.colSizes = Object.entries(this.columns).reduce((acc, [colId, colMeta]) => {
605
+ if (colMeta?.size) {
606
+ acc[colId] = colMeta.size;
607
+ }
1088
608
  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
- }, {});
609
+ }, {});
610
+ this.rowSizes = Object.entries(this.rows).reduce((acc, [rowId, rowMeta]) => {
611
+ if (rowMeta?.size) {
612
+ acc[rowId] = rowMeta.size;
613
+ }
1099
614
  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
- }
615
+ }, {});
1119
616
  }
1120
617
  updated(changedProperties) {
1121
618
  if (this.focusActive && (changedProperties.has("visRowMin") || changedProperties.has("visColMin") || changedProperties.has("focusedCell"))) {
1122
619
  this.refocus();
1123
620
  }
1124
621
  }
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
622
  disconnectedCallback() {
1133
623
  super.disconnectedCallback();
1134
624
  if (this.viewportRef.value) {
@@ -1139,159 +629,130 @@ var DxGrid = class extends LitElement2 {
1139
629
  return this;
1140
630
  }
1141
631
  };
1142
- _ts_decorate2([
1143
- property2({
632
+ _ts_decorate([
633
+ property({
1144
634
  type: String
1145
635
  })
1146
636
  ], DxGrid.prototype, "gridId", void 0);
1147
- _ts_decorate2([
1148
- property2({
637
+ _ts_decorate([
638
+ property({
1149
639
  type: Object
1150
640
  })
1151
641
  ], DxGrid.prototype, "rowDefault", void 0);
1152
- _ts_decorate2([
1153
- property2({
642
+ _ts_decorate([
643
+ property({
1154
644
  type: Object
1155
645
  })
1156
646
  ], DxGrid.prototype, "columnDefault", void 0);
1157
- _ts_decorate2([
1158
- property2({
647
+ _ts_decorate([
648
+ property({
1159
649
  type: Object
1160
650
  })
1161
651
  ], DxGrid.prototype, "rows", void 0);
1162
- _ts_decorate2([
1163
- property2({
652
+ _ts_decorate([
653
+ property({
1164
654
  type: Object
1165
655
  })
1166
656
  ], DxGrid.prototype, "columns", void 0);
1167
- _ts_decorate2([
1168
- property2({
657
+ _ts_decorate([
658
+ property({
1169
659
  type: Object
1170
660
  })
1171
- ], DxGrid.prototype, "initialCells", void 0);
1172
- _ts_decorate2([
1173
- property2({
661
+ ], DxGrid.prototype, "cells", void 0);
662
+ _ts_decorate([
663
+ property({
1174
664
  type: String
1175
665
  })
1176
666
  ], 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([
667
+ _ts_decorate([
1196
668
  state()
1197
669
  ], DxGrid.prototype, "posInline", void 0);
1198
- _ts_decorate2([
670
+ _ts_decorate([
1199
671
  state()
1200
672
  ], DxGrid.prototype, "posBlock", void 0);
1201
- _ts_decorate2([
673
+ _ts_decorate([
1202
674
  state()
1203
675
  ], DxGrid.prototype, "sizeInline", void 0);
1204
- _ts_decorate2([
676
+ _ts_decorate([
1205
677
  state()
1206
678
  ], DxGrid.prototype, "sizeBlock", void 0);
1207
- _ts_decorate2([
679
+ _ts_decorate([
1208
680
  state()
1209
681
  ], DxGrid.prototype, "overscanInline", void 0);
1210
- _ts_decorate2([
682
+ _ts_decorate([
1211
683
  state()
1212
684
  ], DxGrid.prototype, "overscanBlock", void 0);
1213
- _ts_decorate2([
685
+ _ts_decorate([
1214
686
  state()
1215
687
  ], DxGrid.prototype, "binInlineMin", void 0);
1216
- _ts_decorate2([
688
+ _ts_decorate([
1217
689
  state()
1218
690
  ], DxGrid.prototype, "binInlineMax", void 0);
1219
- _ts_decorate2([
691
+ _ts_decorate([
1220
692
  state()
1221
693
  ], DxGrid.prototype, "binBlockMin", void 0);
1222
- _ts_decorate2([
694
+ _ts_decorate([
1223
695
  state()
1224
696
  ], DxGrid.prototype, "binBlockMax", void 0);
1225
- _ts_decorate2([
697
+ _ts_decorate([
1226
698
  state()
1227
699
  ], DxGrid.prototype, "visColMin", void 0);
1228
- _ts_decorate2([
700
+ _ts_decorate([
1229
701
  state()
1230
702
  ], DxGrid.prototype, "visColMax", void 0);
1231
- _ts_decorate2([
703
+ _ts_decorate([
1232
704
  state()
1233
705
  ], DxGrid.prototype, "visRowMin", void 0);
1234
- _ts_decorate2([
706
+ _ts_decorate([
1235
707
  state()
1236
708
  ], 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([
709
+ _ts_decorate([
1250
710
  state()
1251
- ], DxGrid.prototype, "templatefrozenRowsStart", void 0);
1252
- _ts_decorate2([
711
+ ], DxGrid.prototype, "templateColumns", void 0);
712
+ _ts_decorate([
1253
713
  state()
1254
- ], DxGrid.prototype, "templatefrozenRowsEnd", void 0);
1255
- _ts_decorate2([
714
+ ], DxGrid.prototype, "templateRows", void 0);
715
+ _ts_decorate([
1256
716
  state()
1257
717
  ], DxGrid.prototype, "pointer", void 0);
1258
- _ts_decorate2([
718
+ _ts_decorate([
1259
719
  state()
1260
720
  ], DxGrid.prototype, "colSizes", void 0);
1261
- _ts_decorate2([
721
+ _ts_decorate([
1262
722
  state()
1263
723
  ], DxGrid.prototype, "rowSizes", void 0);
1264
- _ts_decorate2([
724
+ _ts_decorate([
1265
725
  state()
1266
726
  ], DxGrid.prototype, "focusActive", void 0);
1267
- _ts_decorate2([
727
+ _ts_decorate([
1268
728
  state()
1269
729
  ], DxGrid.prototype, "focusedCell", void 0);
1270
- _ts_decorate2([
730
+ _ts_decorate([
1271
731
  state()
1272
732
  ], DxGrid.prototype, "selectionStart", void 0);
1273
- _ts_decorate2([
733
+ _ts_decorate([
1274
734
  state()
1275
735
  ], 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([
736
+ _ts_decorate([
1283
737
  state()
1284
738
  ], DxGrid.prototype, "observer", void 0);
1285
- DxGrid = _ts_decorate2([
1286
- customElement2("dx-grid")
739
+ _ts_decorate([
740
+ eventOptions({
741
+ capture: true
742
+ })
743
+ ], DxGrid.prototype, "handleFocus", null);
744
+ _ts_decorate([
745
+ eventOptions({
746
+ capture: true
747
+ })
748
+ ], DxGrid.prototype, "handleBlur", null);
749
+ DxGrid = _ts_decorate([
750
+ customElement("dx-grid")
1287
751
  ], DxGrid);
1288
752
  export {
1289
753
  DxAxisResize,
1290
- DxAxisResizeInternal,
1291
754
  DxEditRequest,
1292
755
  DxGrid,
1293
- DxGridCellsSelect,
1294
- colToA1Notation,
1295
- rowToA1Notation
756
+ DxGridCellsSelect
1296
757
  };
1297
758
  //# sourceMappingURL=index.mjs.map