@dxos/lit-grid 0.6.12-main.5cc132e → 0.6.12-main.78ddbdf

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,7 +1,19 @@
1
1
  // packages/ui/lit-grid/src/dx-grid.ts
2
- import { LitElement, html } from "lit";
3
- import { customElement, state, property, eventOptions } from "lit/decorators.js";
4
- import { ref, createRef } from "lit/directives/ref.js";
2
+ import { LitElement as LitElement2, html as html2, nothing } from "lit";
3
+ import { customElement as customElement2, state, property as property2, eventOptions } from "lit/decorators.js";
4
+ import { ref as ref2, createRef } from "lit/directives/ref.js";
5
+
6
+ // packages/ui/lit-grid/src/dx-grid-axis-resize-handle.ts
7
+ import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
8
+ import { disableNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/disable-native-drag-preview";
9
+ import { preventUnhandled } from "@atlaskit/pragmatic-drag-and-drop/prevent-unhandled";
10
+ import { html, LitElement } from "lit";
11
+ import { customElement, property } from "lit/decorators.js";
12
+ import { ref } from "lit/directives/ref.js";
13
+
14
+ // packages/ui/lit-grid/src/util.ts
15
+ var separator = ",";
16
+ var toCellIndex = (cellCoords) => `${cellCoords.col}${separator}${cellCoords.row}`;
5
17
 
6
18
  // packages/ui/lit-grid/src/types.ts
7
19
  var DxAxisResize = class extends Event {
@@ -12,21 +24,129 @@ var DxAxisResize = class extends Event {
12
24
  this.size = props.size;
13
25
  }
14
26
  };
27
+ var DxAxisResizeInternal = class extends Event {
28
+ constructor(props) {
29
+ super("dx-axis-resize-internal", {
30
+ composed: true,
31
+ bubbles: true
32
+ });
33
+ this.axis = props.axis;
34
+ this.index = props.index;
35
+ this.size = props.size;
36
+ this.delta = props.delta;
37
+ this.state = props.state;
38
+ }
39
+ };
15
40
  var DxEditRequest = class extends Event {
16
41
  constructor(props) {
17
42
  super("dx-edit-request");
18
43
  this.cellIndex = props.cellIndex;
19
44
  this.cellBox = props.cellBox;
45
+ this.initialContent = props.initialContent;
46
+ }
47
+ };
48
+ var DxGridCellsSelect = class extends Event {
49
+ constructor({ start, end }) {
50
+ super("dx-grid-cells-select");
51
+ this.start = toCellIndex(start);
52
+ this.end = toCellIndex(end);
53
+ this.minCol = Math.min(start.col, end.col);
54
+ this.maxCol = Math.max(start.col, end.col);
55
+ this.minRow = Math.min(start.row, end.row);
56
+ this.maxRow = Math.max(start.row, end.row);
20
57
  }
21
58
  };
22
59
 
23
- // packages/ui/lit-grid/src/dx-grid.ts
60
+ // packages/ui/lit-grid/src/dx-grid-axis-resize-handle.ts
24
61
  function _ts_decorate(decorators, target, key, desc) {
25
62
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
26
63
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
27
64
  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;
28
65
  return c > 3 && r && Object.defineProperty(target, key, r), r;
29
66
  }
67
+ var DxGridAxisResizeHandle = class extends LitElement {
68
+ constructor() {
69
+ super(...arguments);
70
+ this.axis = "row";
71
+ this.index = "-1";
72
+ this.size = 128;
73
+ this.dragStartSize = 128;
74
+ this.cleanup = null;
75
+ }
76
+ render() {
77
+ return html`<button class="dx-grid__resize-handle" ${ref(this.mount)}>
78
+ <span class="sr-only">Resize</span>
79
+ </button>`;
80
+ }
81
+ dispatchResize(location, state2) {
82
+ const client = this.axis === "row" ? "clientY" : "clientX";
83
+ const event = new DxAxisResizeInternal({
84
+ axis: this.axis,
85
+ size: this.dragStartSize,
86
+ index: this.index,
87
+ delta: location.current.input[client] - location.initial.input[client],
88
+ state: state2
89
+ });
90
+ this.dispatchEvent(event);
91
+ }
92
+ mount(element) {
93
+ this.cleanup?.();
94
+ const host = this;
95
+ if (element) {
96
+ this.cleanup = draggable({
97
+ element,
98
+ onGenerateDragPreview: ({ nativeSetDragImage }) => {
99
+ disableNativeDragPreview({
100
+ nativeSetDragImage
101
+ });
102
+ preventUnhandled.start();
103
+ },
104
+ onDragStart() {
105
+ host.dragStartSize = host.size;
106
+ },
107
+ onDrag({ location }) {
108
+ host.dispatchResize(location, "dragging");
109
+ },
110
+ onDrop({ location }) {
111
+ host.dispatchResize(location, "dropped");
112
+ }
113
+ });
114
+ }
115
+ }
116
+ disconnectedCallback() {
117
+ super.disconnectedCallback();
118
+ this.cleanup?.();
119
+ }
120
+ createRenderRoot() {
121
+ return this;
122
+ }
123
+ };
124
+ _ts_decorate([
125
+ property({
126
+ type: String
127
+ })
128
+ ], DxGridAxisResizeHandle.prototype, "axis", void 0);
129
+ _ts_decorate([
130
+ property({
131
+ type: String
132
+ })
133
+ ], DxGridAxisResizeHandle.prototype, "index", void 0);
134
+ _ts_decorate([
135
+ property({
136
+ type: Number
137
+ })
138
+ ], DxGridAxisResizeHandle.prototype, "size", void 0);
139
+ DxGridAxisResizeHandle = _ts_decorate([
140
+ customElement("dx-grid-axis-resize-handle")
141
+ ], DxGridAxisResizeHandle);
142
+
143
+ // packages/ui/lit-grid/src/dx-grid.ts
144
+ function _ts_decorate2(decorators, target, key, desc) {
145
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
146
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
147
+ 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;
148
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
149
+ }
30
150
  var gap = 1;
31
151
  var resizeTolerance = 8;
32
152
  var overscanCol = 1;
@@ -35,7 +155,6 @@ var sizeColMin = 32;
35
155
  var sizeColMax = 1024;
36
156
  var sizeRowMin = 16;
37
157
  var sizeRowMax = 1024;
38
- var separator = ",";
39
158
  var colToA1Notation = (col) => {
40
159
  return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
41
160
  };
@@ -69,13 +188,13 @@ var closestCell = (target, actionEl) => {
69
188
  }
70
189
  };
71
190
  var isSameCell = (a, b) => a && b && Number.isFinite(a.col) && Number.isFinite(a.row) && a.col === b.col && a.row === b.row;
72
- var toCellIndex = (cellCoords) => `${cellCoords.col}${separator}${cellCoords.row}`;
73
191
  var localChId = (c0) => `ch--${c0}`;
74
192
  var localRhId = (r0) => `rh--${r0}`;
75
193
  var getPage = (axis, event) => axis === "col" ? event.pageX : event.pageY;
76
- var DxGrid = class extends LitElement {
194
+ var DxGrid = class extends LitElement2 {
77
195
  constructor() {
78
- super(...arguments);
196
+ super();
197
+ this.gridId = "default-grid-id";
79
198
  this.rowDefault = {
80
199
  size: 32
81
200
  };
@@ -84,8 +203,14 @@ var DxGrid = class extends LitElement {
84
203
  };
85
204
  this.rows = {};
86
205
  this.columns = {};
87
- this.cells = {};
206
+ this.initialCells = {};
88
207
  this.mode = "browse";
208
+ /**
209
+ * When this function is defined, it is used first to try to get a value for a cell, and otherwise will fall back
210
+ * to `cells`.
211
+ */
212
+ this.getCells = null;
213
+ this.cells = {};
89
214
  //
90
215
  // `pos`, short for ‘position’, is the position in pixels of the viewport from the origin.
91
216
  //
@@ -122,65 +247,76 @@ var DxGrid = class extends LitElement {
122
247
  this.templateColumns = `${this.colSize(0)}px`;
123
248
  this.templateRows = `${this.rowSize(0)}px`;
124
249
  //
125
- // Resize state
250
+ // Focus, selection, and resize states
126
251
  //
252
+ this.pointer = null;
127
253
  this.colSizes = {};
128
254
  this.rowSizes = {};
129
- this.resizing = null;
130
- //
131
- // Primary pointer and keyboard handlers
132
- //
255
+ this.focusActive = false;
256
+ this.focusedCell = {
257
+ col: 0,
258
+ row: 0
259
+ };
260
+ this.selectionStart = {
261
+ col: 0,
262
+ row: 0
263
+ };
264
+ this.selectionEnd = {
265
+ col: 0,
266
+ row: 0
267
+ };
133
268
  this.handlePointerDown = (event) => {
134
- const { action, actionEl } = closestAction(event.target);
135
- if (action) {
136
- if (action.startsWith("resize") && this.mode === "browse") {
137
- const [resize, index] = action.split(",");
138
- const [_, axis] = resize.split("-");
139
- this.resizing = {
140
- axis,
141
- size: axis === "col" ? this.colSize(index) : this.rowSize(index),
142
- page: getPage(axis, event),
143
- index
144
- };
145
- } else if (action === "cell") {
146
- const cellCoords = closestCell(event.target, actionEl);
147
- if (this.focusActive && isSameCell(this.focusedCell, cellCoords)) {
148
- this.dispatchEvent(new DxEditRequest({
149
- cellIndex: toCellIndex(cellCoords),
150
- cellBox: this.focusedCellBox()
151
- }));
269
+ if (event.isPrimary) {
270
+ const { action, actionEl } = closestAction(event.target);
271
+ if (action) {
272
+ if (action.startsWith("resize") && this.mode === "browse") {
273
+ const [resize, index] = action.split(",");
274
+ const [_, axis] = resize.split("-");
275
+ this.pointer = {
276
+ state: "resizing",
277
+ axis,
278
+ size: axis === "col" ? this.colSize(index) : this.rowSize(index),
279
+ page: getPage(axis, event),
280
+ index
281
+ };
282
+ } else if (action === "cell") {
283
+ const cellCoords = closestCell(event.target, actionEl);
284
+ if (cellCoords) {
285
+ this.pointer = {
286
+ state: "selecting"
287
+ };
288
+ this.selectionStart = cellCoords;
289
+ }
290
+ if (this.mode === "edit") {
291
+ event.preventDefault();
292
+ } else {
293
+ if (this.focusActive && isSameCell(this.focusedCell, cellCoords)) {
294
+ this.dispatchEditRequest();
295
+ }
296
+ }
152
297
  }
153
298
  }
154
299
  }
155
300
  };
156
- this.handlePointerUp = (_event) => {
157
- if (this.resizing) {
158
- const resizeEvent = new DxAxisResize({
159
- axis: this.resizing.axis,
160
- index: this.resizing.index,
161
- size: this[this.resizing.axis === "col" ? "colSize" : "rowSize"](this.resizing.index)
162
- });
163
- this.dispatchEvent(resizeEvent);
164
- this.resizing = null;
301
+ this.handlePointerUp = (event) => {
302
+ if (this.pointer?.state === "resizing") {
303
+ } else {
304
+ const cell = closestCell(event.target);
305
+ if (cell) {
306
+ this.selectionEnd = cell;
307
+ this.dispatchEvent(new DxGridCellsSelect({
308
+ start: this.selectionStart,
309
+ end: this.selectionEnd
310
+ }));
311
+ }
165
312
  }
313
+ this.pointer = null;
166
314
  };
167
315
  this.handlePointerMove = (event) => {
168
- if (this.resizing) {
169
- const delta = getPage(this.resizing.axis, event) - this.resizing.page;
170
- if (this.resizing.axis === "col") {
171
- const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, this.resizing.size + delta));
172
- this.colSizes = {
173
- ...this.colSizes,
174
- [this.resizing.index]: nextSize
175
- };
176
- this.updateVisInline();
177
- } else {
178
- const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, this.resizing.size + delta));
179
- this.rowSizes = {
180
- ...this.rowSizes,
181
- [this.resizing.index]: nextSize
182
- };
183
- this.updateVisBlock();
316
+ if (this.pointer?.state === "selecting") {
317
+ const cell = closestCell(event.target);
318
+ if (cell && (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
319
+ this.selectionEnd = cell;
184
320
  }
185
321
  }
186
322
  };
@@ -199,22 +335,43 @@ var DxGrid = class extends LitElement {
199
335
  }
200
336
  });
201
337
  this.viewportRef = createRef();
338
+ this.maybeUpdateVis = () => {
339
+ if (this.posInline >= this.binInlineMin && this.posInline < this.binInlineMax && this.posBlock >= this.binBlockMin && this.posBlock < this.binBlockMax) {
340
+ } else {
341
+ this.updateVis();
342
+ }
343
+ };
202
344
  this.handleWheel = ({ deltaX, deltaY }) => {
203
345
  if (this.mode === "browse") {
204
346
  this.posInline = Math.max(0, this.posInline + deltaX);
205
347
  this.posBlock = Math.max(0, this.posBlock + deltaY);
206
- if (this.posInline >= this.binInlineMin && this.posInline < this.binInlineMax && this.posBlock >= this.binBlockMin && this.posBlock < this.binBlockMax) {
207
- } else {
208
- this.updateVis();
209
- }
348
+ this.maybeUpdateVis();
210
349
  }
211
350
  };
212
- // Focus handlers
213
- this.focusedCell = {
214
- col: 0,
215
- row: 0
216
- };
217
- this.focusActive = false;
351
+ this.addEventListener("dx-axis-resize-internal", this.handleAxisResizeInternal);
352
+ this.addEventListener("wheel", this.handleWheel);
353
+ this.addEventListener("pointerdown", this.handlePointerDown);
354
+ this.addEventListener("pointermove", this.handlePointerMove);
355
+ this.addEventListener("pointerup", this.handlePointerUp);
356
+ this.addEventListener("pointerleave", this.handlePointerUp);
357
+ this.addEventListener("focus", this.handleFocus, {
358
+ capture: true
359
+ });
360
+ this.addEventListener("blur", this.handleBlur, {
361
+ capture: true
362
+ });
363
+ this.addEventListener("keydown", this.handleKeydown);
364
+ }
365
+ //
366
+ // Primary pointer and keyboard handlers
367
+ //
368
+ dispatchEditRequest(initialContent) {
369
+ this.snapPosToFocusedCell();
370
+ queueMicrotask(() => this.dispatchEvent(new DxEditRequest({
371
+ cellIndex: toCellIndex(this.focusedCell),
372
+ cellBox: this.focusedCellBox(),
373
+ initialContent
374
+ })));
218
375
  }
219
376
  handleKeydown(event) {
220
377
  if (this.focusActive && this.mode === "browse") {
@@ -246,10 +403,12 @@ var DxGrid = class extends LitElement {
246
403
  }
247
404
  switch (event.key) {
248
405
  case "Enter":
249
- this.dispatchEvent(new DxEditRequest({
250
- cellIndex: toCellIndex(this.focusedCell),
251
- cellBox: this.focusedCellBox()
252
- }));
406
+ this.dispatchEditRequest();
407
+ break;
408
+ default:
409
+ if (event.key.length === 1 && event.key.match(/\P{Cc}/u)) {
410
+ this.dispatchEditRequest(event.key);
411
+ }
253
412
  break;
254
413
  }
255
414
  switch (event.key) {
@@ -273,7 +432,8 @@ var DxGrid = class extends LitElement {
273
432
  return this.rowSizes?.[r] ?? this.rowDefault.size;
274
433
  }
275
434
  cell(c, r) {
276
- return this.cells[`${c}${separator}${r}`];
435
+ const index = `${c}${separator}${r}`;
436
+ return this.cells[index] ?? this.initialCells[index];
277
437
  }
278
438
  focusedCellBox() {
279
439
  const cellElement = this.focusedCellElement();
@@ -353,6 +513,7 @@ var DxGrid = class extends LitElement {
353
513
  this.updateVisInline();
354
514
  this.updateVisBlock();
355
515
  }
516
+ // Focus handlers
356
517
  handleFocus(event) {
357
518
  const cellCoords = closestCell(event.target);
358
519
  if (cellCoords) {
@@ -361,7 +522,7 @@ var DxGrid = class extends LitElement {
361
522
  }
362
523
  }
363
524
  handleBlur(event) {
364
- if (!event.relatedTarget || event.relatedTarget.closest(".dx-grid__viewport") !== this.viewportRef.value) {
525
+ if (!event.relatedTarget || !event.relatedTarget.closest(`[data-grid="${this.gridId}"]`)) {
365
526
  this.focusActive = false;
366
527
  }
367
528
  }
@@ -371,23 +532,26 @@ var DxGrid = class extends LitElement {
371
532
  /**
372
533
  * Moves focus to the cell with actual focus, otherwise moves focus to the viewport.
373
534
  */
374
- refocus(increment) {
535
+ refocus(increment, delta = 1) {
375
536
  switch (increment) {
376
- case "down":
537
+ case "row":
377
538
  this.focusedCell = {
378
539
  ...this.focusedCell,
379
- row: this.focusedCell.row + 1
540
+ row: this.focusedCell.row + delta
380
541
  };
381
542
  break;
382
- case "right":
543
+ case "col":
383
544
  this.focusedCell = {
384
545
  ...this.focusedCell,
385
- col: this.focusedCell.col + 1
546
+ col: this.focusedCell.col + delta
386
547
  };
387
548
  }
388
549
  (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({
389
550
  preventScroll: true
390
551
  });
552
+ if (increment) {
553
+ this.snapPosToFocusedCell();
554
+ }
391
555
  }
392
556
  /**
393
557
  * Updates `pos` so that a cell in focus is fully within the viewport
@@ -406,7 +570,7 @@ var DxGrid = class extends LitElement {
406
570
  acc += this.colSize(this.visColMin + overscanCol + c0) + gap;
407
571
  return acc;
408
572
  }, 0);
409
- this.posInline = this.binInlineMin + sizeSumCol + gap * 2 - this.sizeInline;
573
+ this.posInline = Math.max(0, this.binInlineMin + sizeSumCol + gap * 2 - this.sizeInline);
410
574
  this.updateVisInline();
411
575
  }
412
576
  if (this.focusedCell.row <= this.visRowMin + overscanRow) {
@@ -419,28 +583,76 @@ var DxGrid = class extends LitElement {
419
583
  acc += this.rowSize(this.visRowMin + overscanRow + r0) + gap;
420
584
  return acc;
421
585
  }, 0);
422
- this.posBlock = this.binBlockMin + sizeSumRow + gap * 2 - this.sizeBlock;
586
+ this.posBlock = Math.max(0, this.binBlockMin + sizeSumRow + gap * 2 - this.sizeBlock);
423
587
  this.updateVisBlock();
424
588
  }
425
589
  }
426
590
  }
427
591
  //
592
+ // Map scroll DOM methods to virtualized value.
593
+ //
594
+ get scrollLeft() {
595
+ return this.posInline;
596
+ }
597
+ set scrollLeft(nextValue) {
598
+ this.posInline = nextValue;
599
+ this.maybeUpdateVis();
600
+ }
601
+ get scrollTop() {
602
+ return this.posBlock;
603
+ }
604
+ set scrollTop(nextValue) {
605
+ this.posBlock = nextValue;
606
+ this.maybeUpdateVis();
607
+ }
608
+ //
609
+ // Resize handlers
610
+ //
611
+ handleAxisResizeInternal(event) {
612
+ event.stopPropagation();
613
+ const { axis, delta, size, index, type } = event;
614
+ if (axis === "col") {
615
+ const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, size + delta));
616
+ this.colSizes = {
617
+ ...this.colSizes,
618
+ [index]: nextSize
619
+ };
620
+ this.updateVisInline();
621
+ } else {
622
+ const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, size + delta));
623
+ this.rowSizes = {
624
+ ...this.rowSizes,
625
+ [index]: nextSize
626
+ };
627
+ this.updateVisBlock();
628
+ }
629
+ if (type === "dropped") {
630
+ this.dispatchEvent(new DxAxisResize({
631
+ axis,
632
+ index,
633
+ size: this[axis === "col" ? "colSize" : "rowSize"](index)
634
+ }));
635
+ }
636
+ }
637
+ //
428
638
  // Render and other lifecycle methods
429
639
  //
430
640
  render() {
431
641
  const visibleCols = this.visColMax - this.visColMin;
432
642
  const visibleRows = this.visRowMax - this.visRowMin;
433
- const offsetInline = gap + this.binInlineMin - this.posInline - this.overscanInline;
434
- const offsetBlock = gap + this.binBlockMin - this.posBlock - this.overscanBlock;
435
- return html`<div
643
+ const offsetInline = this.binInlineMin - this.posInline - this.overscanInline;
644
+ const offsetBlock = this.binBlockMin - this.posBlock - this.overscanBlock;
645
+ const selectColMin = Math.min(this.selectionStart.col, this.selectionEnd.col);
646
+ const selectColMax = Math.max(this.selectionStart.col, this.selectionEnd.col);
647
+ const selectRowMin = Math.min(this.selectionStart.row, this.selectionEnd.row);
648
+ const selectRowMax = Math.max(this.selectionStart.row, this.selectionEnd.row);
649
+ const selectVisible = selectColMin !== selectColMax || selectRowMin !== selectRowMax;
650
+ return html2`<div
436
651
  role="none"
437
652
  class="dx-grid"
438
- @pointerdown=${this.handlePointerDown}
439
- @pointerup=${this.handlePointerUp}
440
- @pointermove=${this.handlePointerMove}
441
- @focus=${this.handleFocus}
442
- @blur=${this.handleBlur}
443
- @keydown=${this.handleKeydown}
653
+ data-grid=${this.gridId}
654
+ data-grid-mode=${this.mode}
655
+ ?data-grid-select=${selectVisible}
444
656
  >
445
657
  <div role="none" class="dx-grid__corner"></div>
446
658
  <div role="none" class="dx-grid__columnheader">
@@ -453,15 +665,18 @@ var DxGrid = class extends LitElement {
453
665
  ...Array(visibleCols)
454
666
  ].map((_, c0) => {
455
667
  const c = this.visColMin + c0;
456
- return html`<div
668
+ return html2`<div
457
669
  role="columnheader"
458
670
  ?inert=${c < 0}
459
671
  style="block-size:${this.rowDefault.size}px;grid-column:${c0 + 1}/${c0 + 2};"
460
672
  >
461
673
  <span id=${localChId(c0)}>${colToA1Notation(c)}</span>
462
- ${(this.columns[c]?.resizeable ?? this.columnDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-col,${c}`}>
463
- <span class="sr-only">Resize</span>
464
- </button>`}
674
+ ${(this.columns[c]?.resizeable ?? this.columnDefault.resizeable) && html2`<dx-grid-axis-resize-handle
675
+ axis="col"
676
+ index=${c}
677
+ size=${this.colSize(c)}
678
+ @dxaxisresizeinternal=${this.handleAxisResizeInternal}
679
+ ></dx-grid-axis-resize-handle>`}
465
680
  </div>`;
466
681
  })}
467
682
  </div>
@@ -477,16 +692,18 @@ var DxGrid = class extends LitElement {
477
692
  ...Array(visibleRows)
478
693
  ].map((_, r0) => {
479
694
  const r = this.visRowMin + r0;
480
- return html`<div role="rowheader" ?inert=${r < 0} style="grid-row:${r0 + 1}/${r0 + 2}">
695
+ return html2`<div role="rowheader" ?inert=${r < 0} style="grid-row:${r0 + 1}/${r0 + 2}">
481
696
  <span id=${localRhId(r0)}>${rowToA1Notation(r)}</span>
482
- ${(this.rows[r]?.resizeable ?? this.rowDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-row,${r}`}>
483
- <span class="sr-only">Resize</span>
484
- </button>`}
697
+ ${(this.rows[r]?.resizeable ?? this.rowDefault.resizeable) && html2`<dx-grid-axis-resize-handle
698
+ axis="row"
699
+ index=${r}
700
+ size=${this.rowSize(r)}
701
+ ></dx-grid-axis-resize-handle>`}
485
702
  </div>`;
486
703
  })}
487
704
  </div>
488
705
  </div>
489
- <div role="grid" class="dx-grid__viewport" tabindex="0" @wheel=${this.handleWheel} ${ref(this.viewportRef)}>
706
+ <div role="grid" class="dx-grid__viewport" tabindex="0" @wheel=${this.handleWheel} ${ref2(this.viewportRef)}>
490
707
  <div
491
708
  role="none"
492
709
  class="dx-grid__content"
@@ -501,10 +718,14 @@ var DxGrid = class extends LitElement {
501
718
  const c = c0 + this.visColMin;
502
719
  const r = r0 + this.visRowMin;
503
720
  const cell = this.cell(c, r);
504
- return html`<div
721
+ const active = this.focusActive && this.focusedCell.col === c && this.focusedCell.row === r;
722
+ const selected = c >= selectColMin && c <= selectColMax && r >= selectRowMin && r <= selectRowMax;
723
+ return html2`<div
505
724
  role="gridcell"
506
725
  tabindex="0"
507
726
  ?inert=${c < 0 || r < 0}
727
+ ?aria-selected=${selected}
728
+ class=${cell || active ? (cell?.className ? cell.className + " " : "") + (active ? "dx-grid__cell--active" : "") : nothing}
508
729
  aria-rowindex=${r}
509
730
  aria-colindex=${c}
510
731
  data-dx-grid-action="cell"
@@ -527,6 +748,18 @@ var DxGrid = class extends LitElement {
527
748
  </div>`;
528
749
  }
529
750
  firstUpdated() {
751
+ if (this.getCells) {
752
+ this.cells = this.getCells({
753
+ start: {
754
+ col: this.visColMin,
755
+ row: this.visRowMin
756
+ },
757
+ end: {
758
+ col: this.visColMax,
759
+ row: this.visRowMax
760
+ }
761
+ });
762
+ }
530
763
  this.observer.observe(this.viewportRef.value);
531
764
  this.colSizes = Object.entries(this.columns).reduce((acc, [colId, colMeta]) => {
532
765
  if (colMeta?.size) {
@@ -541,6 +774,20 @@ var DxGrid = class extends LitElement {
541
774
  return acc;
542
775
  }, {});
543
776
  }
777
+ willUpdate(changedProperties) {
778
+ if (this.getCells && (changedProperties.has("initialCells") || changedProperties.has("visColMin") || changedProperties.has("visColMax") || changedProperties.has("visRowMin") || changedProperties.has("visRowMax"))) {
779
+ this.cells = this.getCells({
780
+ start: {
781
+ col: this.visColMin,
782
+ row: this.visRowMin
783
+ },
784
+ end: {
785
+ col: this.visColMax,
786
+ row: this.visRowMax
787
+ }
788
+ });
789
+ }
790
+ }
544
791
  updated(changedProperties) {
545
792
  if (this.focusActive && (changedProperties.has("visRowMin") || changedProperties.has("visColMin") || changedProperties.has("focusedCell"))) {
546
793
  this.refocus();
@@ -556,118 +803,134 @@ var DxGrid = class extends LitElement {
556
803
  return this;
557
804
  }
558
805
  };
559
- _ts_decorate([
560
- property({
806
+ _ts_decorate2([
807
+ property2({
808
+ type: String
809
+ })
810
+ ], DxGrid.prototype, "gridId", void 0);
811
+ _ts_decorate2([
812
+ property2({
561
813
  type: Object
562
814
  })
563
815
  ], DxGrid.prototype, "rowDefault", void 0);
564
- _ts_decorate([
565
- property({
816
+ _ts_decorate2([
817
+ property2({
566
818
  type: Object
567
819
  })
568
820
  ], DxGrid.prototype, "columnDefault", void 0);
569
- _ts_decorate([
570
- property({
821
+ _ts_decorate2([
822
+ property2({
571
823
  type: Object
572
824
  })
573
825
  ], DxGrid.prototype, "rows", void 0);
574
- _ts_decorate([
575
- property({
826
+ _ts_decorate2([
827
+ property2({
576
828
  type: Object
577
829
  })
578
830
  ], DxGrid.prototype, "columns", void 0);
579
- _ts_decorate([
580
- property({
831
+ _ts_decorate2([
832
+ property2({
581
833
  type: Object
582
834
  })
583
- ], DxGrid.prototype, "cells", void 0);
584
- _ts_decorate([
585
- property({
835
+ ], DxGrid.prototype, "initialCells", void 0);
836
+ _ts_decorate2([
837
+ property2({
586
838
  type: String
587
839
  })
588
840
  ], DxGrid.prototype, "mode", void 0);
589
- _ts_decorate([
841
+ _ts_decorate2([
842
+ state()
843
+ ], DxGrid.prototype, "cells", void 0);
844
+ _ts_decorate2([
590
845
  state()
591
846
  ], DxGrid.prototype, "posInline", void 0);
592
- _ts_decorate([
847
+ _ts_decorate2([
593
848
  state()
594
849
  ], DxGrid.prototype, "posBlock", void 0);
595
- _ts_decorate([
850
+ _ts_decorate2([
596
851
  state()
597
852
  ], DxGrid.prototype, "sizeInline", void 0);
598
- _ts_decorate([
853
+ _ts_decorate2([
599
854
  state()
600
855
  ], DxGrid.prototype, "sizeBlock", void 0);
601
- _ts_decorate([
856
+ _ts_decorate2([
602
857
  state()
603
858
  ], DxGrid.prototype, "overscanInline", void 0);
604
- _ts_decorate([
859
+ _ts_decorate2([
605
860
  state()
606
861
  ], DxGrid.prototype, "overscanBlock", void 0);
607
- _ts_decorate([
862
+ _ts_decorate2([
608
863
  state()
609
864
  ], DxGrid.prototype, "binInlineMin", void 0);
610
- _ts_decorate([
865
+ _ts_decorate2([
611
866
  state()
612
867
  ], DxGrid.prototype, "binInlineMax", void 0);
613
- _ts_decorate([
868
+ _ts_decorate2([
614
869
  state()
615
870
  ], DxGrid.prototype, "binBlockMin", void 0);
616
- _ts_decorate([
871
+ _ts_decorate2([
617
872
  state()
618
873
  ], DxGrid.prototype, "binBlockMax", void 0);
619
- _ts_decorate([
874
+ _ts_decorate2([
620
875
  state()
621
876
  ], DxGrid.prototype, "visColMin", void 0);
622
- _ts_decorate([
877
+ _ts_decorate2([
623
878
  state()
624
879
  ], DxGrid.prototype, "visColMax", void 0);
625
- _ts_decorate([
880
+ _ts_decorate2([
626
881
  state()
627
882
  ], DxGrid.prototype, "visRowMin", void 0);
628
- _ts_decorate([
883
+ _ts_decorate2([
629
884
  state()
630
885
  ], DxGrid.prototype, "visRowMax", void 0);
631
- _ts_decorate([
886
+ _ts_decorate2([
632
887
  state()
633
888
  ], DxGrid.prototype, "templateColumns", void 0);
634
- _ts_decorate([
889
+ _ts_decorate2([
635
890
  state()
636
891
  ], DxGrid.prototype, "templateRows", void 0);
637
- _ts_decorate([
892
+ _ts_decorate2([
893
+ state()
894
+ ], DxGrid.prototype, "pointer", void 0);
895
+ _ts_decorate2([
638
896
  state()
639
897
  ], DxGrid.prototype, "colSizes", void 0);
640
- _ts_decorate([
898
+ _ts_decorate2([
641
899
  state()
642
900
  ], DxGrid.prototype, "rowSizes", void 0);
643
- _ts_decorate([
644
- state()
645
- ], DxGrid.prototype, "resizing", void 0);
646
- _ts_decorate([
901
+ _ts_decorate2([
647
902
  state()
648
- ], DxGrid.prototype, "observer", void 0);
649
- _ts_decorate([
903
+ ], DxGrid.prototype, "focusActive", void 0);
904
+ _ts_decorate2([
650
905
  state()
651
906
  ], DxGrid.prototype, "focusedCell", void 0);
652
- _ts_decorate([
907
+ _ts_decorate2([
653
908
  state()
654
- ], DxGrid.prototype, "focusActive", void 0);
655
- _ts_decorate([
909
+ ], DxGrid.prototype, "selectionStart", void 0);
910
+ _ts_decorate2([
911
+ state()
912
+ ], DxGrid.prototype, "selectionEnd", void 0);
913
+ _ts_decorate2([
914
+ state()
915
+ ], DxGrid.prototype, "observer", void 0);
916
+ _ts_decorate2([
656
917
  eventOptions({
657
918
  capture: true
658
919
  })
659
920
  ], DxGrid.prototype, "handleFocus", null);
660
- _ts_decorate([
921
+ _ts_decorate2([
661
922
  eventOptions({
662
923
  capture: true
663
924
  })
664
925
  ], DxGrid.prototype, "handleBlur", null);
665
- DxGrid = _ts_decorate([
666
- customElement("dx-grid")
926
+ DxGrid = _ts_decorate2([
927
+ customElement2("dx-grid")
667
928
  ], DxGrid);
668
929
  export {
669
930
  DxAxisResize,
931
+ DxAxisResizeInternal,
670
932
  DxEditRequest,
671
- DxGrid
933
+ DxGrid,
934
+ DxGridCellsSelect
672
935
  };
673
936
  //# sourceMappingURL=index.mjs.map