@dxos/lit-grid 0.6.12-main.f9d0246 → 0.6.12-staging.0b4bb48

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,19 +1,7 @@
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, 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}`;
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";
17
5
 
18
6
  // packages/ui/lit-grid/src/types.ts
19
7
  var DxAxisResize = class extends Event {
@@ -24,124 +12,9 @@ var DxAxisResize = class extends Event {
24
12
  this.size = props.size;
25
13
  }
26
14
  };
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
- };
40
- var DxEditRequest = class extends Event {
41
- constructor(props) {
42
- super("dx-edit-request");
43
- this.cellIndex = props.cellIndex;
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);
57
- }
58
- };
59
-
60
- // packages/ui/lit-grid/src/dx-grid-axis-resize-handle.ts
61
- function _ts_decorate(decorators, target, key, desc) {
62
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
63
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
65
- return c > 3 && r && Object.defineProperty(target, key, r), r;
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
15
 
143
16
  // packages/ui/lit-grid/src/dx-grid.ts
144
- function _ts_decorate2(decorators, target, key, desc) {
17
+ function _ts_decorate(decorators, target, key, desc) {
145
18
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
146
19
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
147
20
  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;
@@ -155,46 +28,19 @@ var sizeColMin = 32;
155
28
  var sizeColMax = 1024;
156
29
  var sizeRowMin = 16;
157
30
  var sizeRowMax = 1024;
31
+ var separator = ",";
158
32
  var colToA1Notation = (col) => {
159
33
  return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
160
34
  };
161
35
  var rowToA1Notation = (row) => {
162
36
  return `${row + 1}`;
163
37
  };
164
- var closestAction = (target) => {
165
- const actionEl = target?.closest("[data-dx-grid-action]") ?? null;
166
- return {
167
- actionEl,
168
- action: actionEl?.getAttribute("data-dx-grid-action") ?? null
169
- };
170
- };
171
- var closestCell = (target, actionEl) => {
172
- let cellElement = actionEl;
173
- if (!cellElement) {
174
- const { action, actionEl: actionEl2 } = closestAction(target);
175
- if (action === "cell") {
176
- cellElement = actionEl2;
177
- }
178
- }
179
- if (cellElement) {
180
- const col = parseInt(cellElement.getAttribute("aria-colindex") ?? "never");
181
- const row = parseInt(cellElement.getAttribute("aria-rowindex") ?? "never");
182
- return {
183
- col,
184
- row
185
- };
186
- } else {
187
- return null;
188
- }
189
- };
190
- var isSameCell = (a, b) => a && b && Number.isFinite(a.col) && Number.isFinite(a.row) && a.col === b.col && a.row === b.row;
191
38
  var localChId = (c0) => `ch--${c0}`;
192
39
  var localRhId = (r0) => `rh--${r0}`;
193
40
  var getPage = (axis, event) => axis === "col" ? event.pageX : event.pageY;
194
- var DxGrid = class extends LitElement2 {
41
+ var DxGrid = class extends LitElement {
195
42
  constructor() {
196
- super();
197
- this.gridId = "default-grid-id";
43
+ super(...arguments);
198
44
  this.rowDefault = {
199
45
  size: 32
200
46
  };
@@ -203,13 +49,6 @@ var DxGrid = class extends LitElement2 {
203
49
  };
204
50
  this.rows = {};
205
51
  this.columns = {};
206
- this.initialCells = {};
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
52
  this.cells = {};
214
53
  //
215
54
  // `pos`, short for ‘position’, is the position in pixels of the viewport from the origin.
@@ -247,76 +86,55 @@ var DxGrid = class extends LitElement2 {
247
86
  this.templateColumns = `${this.colSize(0)}px`;
248
87
  this.templateRows = `${this.rowSize(0)}px`;
249
88
  //
250
- // Focus, selection, and resize states
89
+ // Resize state and handlers
251
90
  //
252
- this.pointer = null;
253
91
  this.colSizes = {};
254
92
  this.rowSizes = {};
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
- };
93
+ this.resizing = null;
268
94
  this.handlePointerDown = (event) => {
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
- }
297
- }
95
+ const actionEl = event.target?.closest("[data-dx-grid-action]");
96
+ const action = actionEl?.getAttribute("data-dx-grid-action");
97
+ if (action) {
98
+ if (action.startsWith("resize")) {
99
+ const [resize, index] = action.split(",");
100
+ const [_, axis] = resize.split("-");
101
+ this.resizing = {
102
+ axis,
103
+ size: axis === "col" ? this.colSize(index) : this.rowSize(index),
104
+ page: getPage(axis, event),
105
+ index
106
+ };
298
107
  }
299
108
  }
300
109
  };
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
- }
110
+ this.handlePointerUp = (_event) => {
111
+ if (this.resizing) {
112
+ const resizeEvent = new DxAxisResize({
113
+ axis: this.resizing.axis,
114
+ index: this.resizing.index,
115
+ size: this[this.resizing.axis === "col" ? "colSize" : "rowSize"](this.resizing.index)
116
+ });
117
+ this.dispatchEvent(resizeEvent);
118
+ this.resizing = null;
312
119
  }
313
- this.pointer = null;
314
120
  };
315
121
  this.handlePointerMove = (event) => {
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;
122
+ if (this.resizing) {
123
+ const delta = getPage(this.resizing.axis, event) - this.resizing.page;
124
+ if (this.resizing.axis === "col") {
125
+ const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, this.resizing.size + delta));
126
+ this.colSizes = {
127
+ ...this.colSizes,
128
+ [this.resizing.index]: nextSize
129
+ };
130
+ this.updateVisInline();
131
+ } else {
132
+ const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, this.resizing.size + delta));
133
+ this.rowSizes = {
134
+ ...this.rowSizes,
135
+ [this.resizing.index]: nextSize
136
+ };
137
+ this.updateVisBlock();
320
138
  }
321
139
  }
322
140
  };
@@ -335,92 +153,20 @@ var DxGrid = class extends LitElement2 {
335
153
  }
336
154
  });
337
155
  this.viewportRef = createRef();
338
- this.maybeUpdateVis = () => {
156
+ this.handleWheel = ({ deltaX, deltaY }) => {
157
+ this.posInline = Math.max(0, this.posInline + deltaX);
158
+ this.posBlock = Math.max(0, this.posBlock + deltaY);
339
159
  if (this.posInline >= this.binInlineMin && this.posInline < this.binInlineMax && this.posBlock >= this.binBlockMin && this.posBlock < this.binBlockMax) {
340
160
  } else {
341
161
  this.updateVis();
342
162
  }
343
163
  };
344
- this.handleWheel = ({ deltaX, deltaY }) => {
345
- if (this.mode === "browse") {
346
- this.posInline = Math.max(0, this.posInline + deltaX);
347
- this.posBlock = Math.max(0, this.posBlock + deltaY);
348
- this.maybeUpdateVis();
349
- }
164
+ // Focus handlers
165
+ this.focusedCell = {
166
+ col: 0,
167
+ row: 0
350
168
  };
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
- })));
375
- }
376
- handleKeydown(event) {
377
- if (this.focusActive && this.mode === "browse") {
378
- switch (event.key) {
379
- case "ArrowDown":
380
- this.focusedCell = {
381
- ...this.focusedCell,
382
- row: this.focusedCell.row + 1
383
- };
384
- break;
385
- case "ArrowUp":
386
- this.focusedCell = {
387
- ...this.focusedCell,
388
- row: Math.max(0, this.focusedCell.row - 1)
389
- };
390
- break;
391
- case "ArrowRight":
392
- this.focusedCell = {
393
- ...this.focusedCell,
394
- col: this.focusedCell.col + 1
395
- };
396
- break;
397
- case "ArrowLeft":
398
- this.focusedCell = {
399
- ...this.focusedCell,
400
- col: Math.max(0, this.focusedCell.col - 1)
401
- };
402
- break;
403
- }
404
- switch (event.key) {
405
- case "Enter":
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
- }
412
- break;
413
- }
414
- switch (event.key) {
415
- case "ArrowDown":
416
- case "ArrowUp":
417
- case "ArrowRight":
418
- case "ArrowLeft":
419
- event.preventDefault();
420
- this.snapPosToFocusedCell();
421
- break;
422
- }
423
- }
169
+ this.focusActive = false;
424
170
  }
425
171
  //
426
172
  // Accessors
@@ -431,33 +177,8 @@ var DxGrid = class extends LitElement2 {
431
177
  rowSize(r) {
432
178
  return this.rowSizes?.[r] ?? this.rowDefault.size;
433
179
  }
434
- cell(c, r) {
435
- const index = `${c}${separator}${r}`;
436
- return this.cells[index] ?? this.initialCells[index];
437
- }
438
- focusedCellBox() {
439
- const cellElement = this.focusedCellElement();
440
- const cellSize = {
441
- inlineSize: this.colSize(this.focusedCell.col),
442
- blockSize: this.rowSize(this.focusedCell.row)
443
- };
444
- if (!cellElement) {
445
- return {
446
- insetInlineStart: NaN,
447
- insetBlockStart: NaN,
448
- ...cellSize
449
- };
450
- }
451
- const contentElement = cellElement.offsetParent;
452
- const [_translate3d, inlineStr, blockStr] = contentElement.style.transform.split(/[()]|px,?\s?/);
453
- const contentOffsetInline = parseFloat(inlineStr);
454
- const contentOffsetBlock = parseFloat(blockStr);
455
- const offsetParent = contentElement.offsetParent;
456
- return {
457
- insetInlineStart: cellElement.offsetLeft + contentOffsetInline + offsetParent.offsetLeft,
458
- insetBlockStart: cellElement.offsetTop + contentOffsetBlock + offsetParent.offsetTop,
459
- ...cellSize
460
- };
180
+ getCell(c, r) {
181
+ return this.cells[`${c}${separator}${r}`];
461
182
  }
462
183
  updateVisInline() {
463
184
  let colIndex = 0;
@@ -513,45 +234,31 @@ var DxGrid = class extends LitElement2 {
513
234
  this.updateVisInline();
514
235
  this.updateVisBlock();
515
236
  }
516
- // Focus handlers
517
237
  handleFocus(event) {
518
- const cellCoords = closestCell(event.target);
519
- if (cellCoords) {
520
- this.focusedCell = cellCoords;
238
+ const target = event.target;
239
+ const action = target.getAttribute("data-dx-grid-action");
240
+ if (action === "cell") {
241
+ const c = parseInt(target.getAttribute("aria-colindex") ?? "never");
242
+ const r = parseInt(target.getAttribute("aria-rowindex") ?? "never");
243
+ this.focusedCell = {
244
+ col: c,
245
+ row: r
246
+ };
521
247
  this.focusActive = true;
522
248
  }
523
249
  }
524
250
  handleBlur(event) {
525
- if (!event.relatedTarget || !event.relatedTarget.closest(`[data-grid="${this.gridId}"]`)) {
251
+ if (!event.relatedTarget || event.relatedTarget.closest(".dx-grid__viewport") !== this.viewportRef.value) {
526
252
  this.focusActive = false;
527
253
  }
528
254
  }
529
- focusedCellElement() {
530
- return this.viewportRef.value?.querySelector(`[aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`);
531
- }
532
255
  /**
533
256
  * Moves focus to the cell with actual focus, otherwise moves focus to the viewport.
534
257
  */
535
- refocus(increment, delta = 1) {
536
- switch (increment) {
537
- case "row":
538
- this.focusedCell = {
539
- ...this.focusedCell,
540
- row: this.focusedCell.row + delta
541
- };
542
- break;
543
- case "col":
544
- this.focusedCell = {
545
- ...this.focusedCell,
546
- col: this.focusedCell.col + delta
547
- };
548
- }
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({
258
+ refocus() {
259
+ (this.focusedCell.row < this.visRowMin || this.focusedCell.row > this.visRowMax || this.focusedCell.col < this.visColMin || this.focusedCell.col > this.visColMax ? this.viewportRef.value : this.viewportRef.value?.querySelector(`[aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`))?.focus({
550
260
  preventScroll: true
551
261
  });
552
- if (increment) {
553
- this.snapPosToFocusedCell();
554
- }
555
262
  }
556
263
  /**
557
264
  * Updates `pos` so that a cell in focus is fully within the viewport
@@ -570,7 +277,7 @@ var DxGrid = class extends LitElement2 {
570
277
  acc += this.colSize(this.visColMin + overscanCol + c0) + gap;
571
278
  return acc;
572
279
  }, 0);
573
- this.posInline = Math.max(0, this.binInlineMin + sizeSumCol + gap * 2 - this.sizeInline);
280
+ this.posInline = this.binInlineMin + sizeSumCol + gap * 2 - this.sizeInline;
574
281
  this.updateVisInline();
575
282
  }
576
283
  if (this.focusedCell.row <= this.visRowMin + overscanRow) {
@@ -583,55 +290,49 @@ var DxGrid = class extends LitElement2 {
583
290
  acc += this.rowSize(this.visRowMin + overscanRow + r0) + gap;
584
291
  return acc;
585
292
  }, 0);
586
- this.posBlock = Math.max(0, this.binBlockMin + sizeSumRow + gap * 2 - this.sizeBlock);
293
+ this.posBlock = this.binBlockMin + sizeSumRow + gap * 2 - this.sizeBlock;
587
294
  this.updateVisBlock();
588
295
  }
589
296
  }
590
297
  }
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
- }));
298
+ // Keyboard interactions
299
+ handleKeydown(event) {
300
+ if (this.focusActive) {
301
+ switch (event.key) {
302
+ case "ArrowDown":
303
+ this.focusedCell = {
304
+ ...this.focusedCell,
305
+ row: this.focusedCell.row + 1
306
+ };
307
+ break;
308
+ case "ArrowUp":
309
+ this.focusedCell = {
310
+ ...this.focusedCell,
311
+ row: Math.max(0, this.focusedCell.row - 1)
312
+ };
313
+ break;
314
+ case "ArrowRight":
315
+ this.focusedCell = {
316
+ ...this.focusedCell,
317
+ col: this.focusedCell.col + 1
318
+ };
319
+ break;
320
+ case "ArrowLeft":
321
+ this.focusedCell = {
322
+ ...this.focusedCell,
323
+ col: Math.max(0, this.focusedCell.col - 1)
324
+ };
325
+ break;
326
+ }
327
+ switch (event.key) {
328
+ case "ArrowDown":
329
+ case "ArrowUp":
330
+ case "ArrowRight":
331
+ case "ArrowLeft":
332
+ event.preventDefault();
333
+ this.snapPosToFocusedCell();
334
+ break;
335
+ }
635
336
  }
636
337
  }
637
338
  //
@@ -640,19 +341,17 @@ var DxGrid = class extends LitElement2 {
640
341
  render() {
641
342
  const visibleCols = this.visColMax - this.visColMin;
642
343
  const visibleRows = this.visRowMax - this.visRowMin;
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
344
+ const offsetInline = gap + this.binInlineMin - this.posInline - this.overscanInline;
345
+ const offsetBlock = gap + this.binBlockMin - this.posBlock - this.overscanBlock;
346
+ return html`<div
651
347
  role="none"
652
348
  class="dx-grid"
653
- data-grid=${this.gridId}
654
- data-grid-mode=${this.mode}
655
- ?data-grid-select=${selectVisible}
349
+ @pointerdown=${this.handlePointerDown}
350
+ @pointerup=${this.handlePointerUp}
351
+ @pointermove=${this.handlePointerMove}
352
+ @focus=${this.handleFocus}
353
+ @blur=${this.handleBlur}
354
+ @keydown=${this.handleKeydown}
656
355
  >
657
356
  <div role="none" class="dx-grid__corner"></div>
658
357
  <div role="none" class="dx-grid__columnheader">
@@ -665,18 +364,15 @@ var DxGrid = class extends LitElement2 {
665
364
  ...Array(visibleCols)
666
365
  ].map((_, c0) => {
667
366
  const c = this.visColMin + c0;
668
- return html2`<div
367
+ return html`<div
669
368
  role="columnheader"
670
369
  ?inert=${c < 0}
671
370
  style="block-size:${this.rowDefault.size}px;grid-column:${c0 + 1}/${c0 + 2};"
672
371
  >
673
372
  <span id=${localChId(c0)}>${colToA1Notation(c)}</span>
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>`}
373
+ ${(this.columns[c]?.resizeable ?? this.columnDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-col,${c}`}>
374
+ <span class="sr-only">Resize</span>
375
+ </button>`}
680
376
  </div>`;
681
377
  })}
682
378
  </div>
@@ -692,18 +388,16 @@ var DxGrid = class extends LitElement2 {
692
388
  ...Array(visibleRows)
693
389
  ].map((_, r0) => {
694
390
  const r = this.visRowMin + r0;
695
- return html2`<div role="rowheader" ?inert=${r < 0} style="grid-row:${r0 + 1}/${r0 + 2}">
391
+ return html`<div role="rowheader" ?inert=${r < 0} style="grid-row:${r0 + 1}/${r0 + 2}">
696
392
  <span id=${localRhId(r0)}>${rowToA1Notation(r)}</span>
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>`}
393
+ ${(this.rows[r]?.resizeable ?? this.rowDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-row,${r}`}>
394
+ <span class="sr-only">Resize</span>
395
+ </button>`}
702
396
  </div>`;
703
397
  })}
704
398
  </div>
705
399
  </div>
706
- <div role="grid" class="dx-grid__viewport" tabindex="0" @wheel=${this.handleWheel} ${ref2(this.viewportRef)}>
400
+ <div role="grid" class="dx-grid__viewport" tabindex="0" @wheel=${this.handleWheel} ${ref(this.viewportRef)}>
707
401
  <div
708
402
  role="none"
709
403
  class="dx-grid__content"
@@ -717,15 +411,11 @@ var DxGrid = class extends LitElement2 {
717
411
  ].map((_2, r0) => {
718
412
  const c = c0 + this.visColMin;
719
413
  const r = r0 + this.visRowMin;
720
- const cell = this.cell(c, r);
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
414
+ const cell = this.getCell(c, r);
415
+ return html`<div
724
416
  role="gridcell"
725
417
  tabindex="0"
726
418
  ?inert=${c < 0 || r < 0}
727
- ?aria-selected=${selected}
728
- class=${cell || active ? (cell?.className ? cell.className + " " : "") + (active ? "dx-grid__cell--active" : "") : nothing}
729
419
  aria-rowindex=${r}
730
420
  aria-colindex=${c}
731
421
  data-dx-grid-action="cell"
@@ -748,18 +438,6 @@ var DxGrid = class extends LitElement2 {
748
438
  </div>`;
749
439
  }
750
440
  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
- }
763
441
  this.observer.observe(this.viewportRef.value);
764
442
  this.colSizes = Object.entries(this.columns).reduce((acc, [colId, colMeta]) => {
765
443
  if (colMeta?.size) {
@@ -774,20 +452,6 @@ var DxGrid = class extends LitElement2 {
774
452
  return acc;
775
453
  }, {});
776
454
  }
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
- }
791
455
  updated(changedProperties) {
792
456
  if (this.focusActive && (changedProperties.has("visRowMin") || changedProperties.has("visColMin") || changedProperties.has("focusedCell"))) {
793
457
  this.refocus();
@@ -803,134 +467,112 @@ var DxGrid = class extends LitElement2 {
803
467
  return this;
804
468
  }
805
469
  };
806
- _ts_decorate2([
807
- property2({
808
- type: String
809
- })
810
- ], DxGrid.prototype, "gridId", void 0);
811
- _ts_decorate2([
812
- property2({
470
+ _ts_decorate([
471
+ property({
813
472
  type: Object
814
473
  })
815
474
  ], DxGrid.prototype, "rowDefault", void 0);
816
- _ts_decorate2([
817
- property2({
475
+ _ts_decorate([
476
+ property({
818
477
  type: Object
819
478
  })
820
479
  ], DxGrid.prototype, "columnDefault", void 0);
821
- _ts_decorate2([
822
- property2({
480
+ _ts_decorate([
481
+ property({
823
482
  type: Object
824
483
  })
825
484
  ], DxGrid.prototype, "rows", void 0);
826
- _ts_decorate2([
827
- property2({
485
+ _ts_decorate([
486
+ property({
828
487
  type: Object
829
488
  })
830
489
  ], DxGrid.prototype, "columns", void 0);
831
- _ts_decorate2([
832
- property2({
490
+ _ts_decorate([
491
+ property({
833
492
  type: Object
834
493
  })
835
- ], DxGrid.prototype, "initialCells", void 0);
836
- _ts_decorate2([
837
- property2({
838
- type: String
839
- })
840
- ], DxGrid.prototype, "mode", void 0);
841
- _ts_decorate2([
842
- state()
843
494
  ], DxGrid.prototype, "cells", void 0);
844
- _ts_decorate2([
495
+ _ts_decorate([
845
496
  state()
846
497
  ], DxGrid.prototype, "posInline", void 0);
847
- _ts_decorate2([
498
+ _ts_decorate([
848
499
  state()
849
500
  ], DxGrid.prototype, "posBlock", void 0);
850
- _ts_decorate2([
501
+ _ts_decorate([
851
502
  state()
852
503
  ], DxGrid.prototype, "sizeInline", void 0);
853
- _ts_decorate2([
504
+ _ts_decorate([
854
505
  state()
855
506
  ], DxGrid.prototype, "sizeBlock", void 0);
856
- _ts_decorate2([
507
+ _ts_decorate([
857
508
  state()
858
509
  ], DxGrid.prototype, "overscanInline", void 0);
859
- _ts_decorate2([
510
+ _ts_decorate([
860
511
  state()
861
512
  ], DxGrid.prototype, "overscanBlock", void 0);
862
- _ts_decorate2([
513
+ _ts_decorate([
863
514
  state()
864
515
  ], DxGrid.prototype, "binInlineMin", void 0);
865
- _ts_decorate2([
516
+ _ts_decorate([
866
517
  state()
867
518
  ], DxGrid.prototype, "binInlineMax", void 0);
868
- _ts_decorate2([
519
+ _ts_decorate([
869
520
  state()
870
521
  ], DxGrid.prototype, "binBlockMin", void 0);
871
- _ts_decorate2([
522
+ _ts_decorate([
872
523
  state()
873
524
  ], DxGrid.prototype, "binBlockMax", void 0);
874
- _ts_decorate2([
525
+ _ts_decorate([
875
526
  state()
876
527
  ], DxGrid.prototype, "visColMin", void 0);
877
- _ts_decorate2([
528
+ _ts_decorate([
878
529
  state()
879
530
  ], DxGrid.prototype, "visColMax", void 0);
880
- _ts_decorate2([
531
+ _ts_decorate([
881
532
  state()
882
533
  ], DxGrid.prototype, "visRowMin", void 0);
883
- _ts_decorate2([
534
+ _ts_decorate([
884
535
  state()
885
536
  ], DxGrid.prototype, "visRowMax", void 0);
886
- _ts_decorate2([
537
+ _ts_decorate([
887
538
  state()
888
539
  ], DxGrid.prototype, "templateColumns", void 0);
889
- _ts_decorate2([
540
+ _ts_decorate([
890
541
  state()
891
542
  ], DxGrid.prototype, "templateRows", void 0);
892
- _ts_decorate2([
893
- state()
894
- ], DxGrid.prototype, "pointer", void 0);
895
- _ts_decorate2([
543
+ _ts_decorate([
896
544
  state()
897
545
  ], DxGrid.prototype, "colSizes", void 0);
898
- _ts_decorate2([
546
+ _ts_decorate([
899
547
  state()
900
548
  ], DxGrid.prototype, "rowSizes", void 0);
901
- _ts_decorate2([
902
- state()
903
- ], DxGrid.prototype, "focusActive", void 0);
904
- _ts_decorate2([
549
+ _ts_decorate([
905
550
  state()
906
- ], DxGrid.prototype, "focusedCell", void 0);
907
- _ts_decorate2([
551
+ ], DxGrid.prototype, "resizing", void 0);
552
+ _ts_decorate([
908
553
  state()
909
- ], DxGrid.prototype, "selectionStart", void 0);
910
- _ts_decorate2([
554
+ ], DxGrid.prototype, "observer", void 0);
555
+ _ts_decorate([
911
556
  state()
912
- ], DxGrid.prototype, "selectionEnd", void 0);
913
- _ts_decorate2([
557
+ ], DxGrid.prototype, "focusedCell", void 0);
558
+ _ts_decorate([
914
559
  state()
915
- ], DxGrid.prototype, "observer", void 0);
916
- _ts_decorate2([
560
+ ], DxGrid.prototype, "focusActive", void 0);
561
+ _ts_decorate([
917
562
  eventOptions({
918
563
  capture: true
919
564
  })
920
565
  ], DxGrid.prototype, "handleFocus", null);
921
- _ts_decorate2([
566
+ _ts_decorate([
922
567
  eventOptions({
923
568
  capture: true
924
569
  })
925
570
  ], DxGrid.prototype, "handleBlur", null);
926
- DxGrid = _ts_decorate2([
927
- customElement2("dx-grid")
571
+ DxGrid = _ts_decorate([
572
+ customElement("dx-grid")
928
573
  ], DxGrid);
929
574
  export {
930
575
  DxAxisResize,
931
- DxAxisResizeInternal,
932
- DxEditRequest,
933
- DxGrid,
934
- DxGridCellsSelect
576
+ DxGrid
935
577
  };
936
578
  //# sourceMappingURL=index.mjs.map