@dxos/lit-grid 0.6.11-staging.e6894a4 → 0.6.12-main.15a606f
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.
- package/dist/lib/browser/index.mjs +285 -109
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/dx-grid.d.ts +41 -58
- package/dist/types/src/dx-grid.d.ts.map +1 -1
- package/dist/types/src/dx-grid.lit-stories.d.ts +4 -1
- package/dist/types/src/dx-grid.lit-stories.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +51 -0
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +7 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/package.json +4 -3
- package/src/dx-grid.lit-stories.ts +10 -7
- package/src/dx-grid.pcss +27 -3
- package/src/dx-grid.ts +280 -154
- package/src/types.ts +69 -0
- package/src/util.ts +12 -0
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// packages/ui/lit-grid/src/dx-grid.ts
|
|
2
|
-
import { LitElement, html } from "lit";
|
|
2
|
+
import { LitElement, html, nothing } from "lit";
|
|
3
3
|
import { customElement, state, property, eventOptions } from "lit/decorators.js";
|
|
4
4
|
import { ref, createRef } from "lit/directives/ref.js";
|
|
5
5
|
|
|
6
|
+
// packages/ui/lit-grid/src/util.ts
|
|
7
|
+
var separator = ",";
|
|
8
|
+
var toCellIndex = (cellCoords) => `${cellCoords.col}${separator}${cellCoords.row}`;
|
|
9
|
+
|
|
6
10
|
// packages/ui/lit-grid/src/types.ts
|
|
7
11
|
var DxAxisResize = class extends Event {
|
|
8
12
|
constructor(props) {
|
|
@@ -12,16 +16,31 @@ var DxAxisResize = class extends Event {
|
|
|
12
16
|
this.size = props.size;
|
|
13
17
|
}
|
|
14
18
|
};
|
|
19
|
+
var DxEditRequest = class extends Event {
|
|
20
|
+
constructor(props) {
|
|
21
|
+
super("dx-edit-request");
|
|
22
|
+
this.cellIndex = props.cellIndex;
|
|
23
|
+
this.cellBox = props.cellBox;
|
|
24
|
+
this.initialContent = props.initialContent;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var DxGridCellsSelect = class extends Event {
|
|
28
|
+
constructor({ start, end }) {
|
|
29
|
+
super("dx-grid-cells-select");
|
|
30
|
+
this.start = toCellIndex(start);
|
|
31
|
+
this.end = toCellIndex(end);
|
|
32
|
+
this.minCol = Math.min(start.col, end.col);
|
|
33
|
+
this.maxCol = Math.max(start.col, end.col);
|
|
34
|
+
this.minRow = Math.min(start.row, end.row);
|
|
35
|
+
this.maxRow = Math.max(start.row, end.row);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
15
38
|
|
|
16
39
|
// packages/ui/lit-grid/src/dx-grid.ts
|
|
17
40
|
function _ts_decorate(decorators, target, key, desc) {
|
|
18
41
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
20
|
-
|
|
21
|
-
else
|
|
22
|
-
for (var i = decorators.length - 1; i >= 0; i--)
|
|
23
|
-
if (d = decorators[i])
|
|
24
|
-
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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;
|
|
25
44
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
26
45
|
}
|
|
27
46
|
var gap = 1;
|
|
@@ -32,19 +51,46 @@ var sizeColMin = 32;
|
|
|
32
51
|
var sizeColMax = 1024;
|
|
33
52
|
var sizeRowMin = 16;
|
|
34
53
|
var sizeRowMax = 1024;
|
|
35
|
-
var separator = ",";
|
|
36
54
|
var colToA1Notation = (col) => {
|
|
37
55
|
return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
|
|
38
56
|
};
|
|
39
57
|
var rowToA1Notation = (row) => {
|
|
40
58
|
return `${row + 1}`;
|
|
41
59
|
};
|
|
60
|
+
var closestAction = (target) => {
|
|
61
|
+
const actionEl = target?.closest("[data-dx-grid-action]") ?? null;
|
|
62
|
+
return {
|
|
63
|
+
actionEl,
|
|
64
|
+
action: actionEl?.getAttribute("data-dx-grid-action") ?? null
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
var closestCell = (target, actionEl) => {
|
|
68
|
+
let cellElement = actionEl;
|
|
69
|
+
if (!cellElement) {
|
|
70
|
+
const { action, actionEl: actionEl2 } = closestAction(target);
|
|
71
|
+
if (action === "cell") {
|
|
72
|
+
cellElement = actionEl2;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (cellElement) {
|
|
76
|
+
const col = parseInt(cellElement.getAttribute("aria-colindex") ?? "never");
|
|
77
|
+
const row = parseInt(cellElement.getAttribute("aria-rowindex") ?? "never");
|
|
78
|
+
return {
|
|
79
|
+
col,
|
|
80
|
+
row
|
|
81
|
+
};
|
|
82
|
+
} else {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var isSameCell = (a, b) => a && b && Number.isFinite(a.col) && Number.isFinite(a.row) && a.col === b.col && a.row === b.row;
|
|
42
87
|
var localChId = (c0) => `ch--${c0}`;
|
|
43
88
|
var localRhId = (r0) => `rh--${r0}`;
|
|
44
89
|
var getPage = (axis, event) => axis === "col" ? event.pageX : event.pageY;
|
|
45
90
|
var DxGrid = class extends LitElement {
|
|
46
91
|
constructor() {
|
|
47
92
|
super(...arguments);
|
|
93
|
+
this.gridId = "default-grid-id";
|
|
48
94
|
this.rowDefault = {
|
|
49
95
|
size: 32
|
|
50
96
|
};
|
|
@@ -54,6 +100,7 @@ var DxGrid = class extends LitElement {
|
|
|
54
100
|
this.rows = {};
|
|
55
101
|
this.columns = {};
|
|
56
102
|
this.cells = {};
|
|
103
|
+
this.mode = "browse";
|
|
57
104
|
//
|
|
58
105
|
// `pos`, short for ‘position’, is the position in pixels of the viewport from the origin.
|
|
59
106
|
//
|
|
@@ -90,56 +137,100 @@ var DxGrid = class extends LitElement {
|
|
|
90
137
|
this.templateColumns = `${this.colSize(0)}px`;
|
|
91
138
|
this.templateRows = `${this.rowSize(0)}px`;
|
|
92
139
|
//
|
|
93
|
-
//
|
|
140
|
+
// Focus, selection, and resize states
|
|
94
141
|
//
|
|
142
|
+
this.pointer = null;
|
|
95
143
|
this.colSizes = {};
|
|
96
144
|
this.rowSizes = {};
|
|
97
|
-
this.
|
|
145
|
+
this.focusActive = false;
|
|
146
|
+
this.focusedCell = {
|
|
147
|
+
col: 0,
|
|
148
|
+
row: 0
|
|
149
|
+
};
|
|
150
|
+
this.selectionStart = {
|
|
151
|
+
col: 0,
|
|
152
|
+
row: 0
|
|
153
|
+
};
|
|
154
|
+
this.selectionEnd = {
|
|
155
|
+
col: 0,
|
|
156
|
+
row: 0
|
|
157
|
+
};
|
|
98
158
|
this.handlePointerDown = (event) => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
159
|
+
if (event.isPrimary) {
|
|
160
|
+
const { action, actionEl } = closestAction(event.target);
|
|
161
|
+
if (action) {
|
|
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") {
|
|
173
|
+
const cellCoords = closestCell(event.target, actionEl);
|
|
174
|
+
if (cellCoords) {
|
|
175
|
+
this.pointer = {
|
|
176
|
+
state: "selecting"
|
|
177
|
+
};
|
|
178
|
+
this.selectionStart = cellCoords;
|
|
179
|
+
}
|
|
180
|
+
if (this.mode === "edit") {
|
|
181
|
+
event.preventDefault();
|
|
182
|
+
} else {
|
|
183
|
+
if (this.focusActive && isSameCell(this.focusedCell, cellCoords)) {
|
|
184
|
+
this.dispatchEditRequest();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
111
188
|
}
|
|
112
189
|
}
|
|
113
190
|
};
|
|
114
|
-
this.handlePointerUp = (
|
|
115
|
-
if (this.resizing) {
|
|
191
|
+
this.handlePointerUp = (event) => {
|
|
192
|
+
if (this.pointer?.state === "resizing") {
|
|
116
193
|
const resizeEvent = new DxAxisResize({
|
|
117
|
-
axis: this.
|
|
118
|
-
index: this.
|
|
119
|
-
size: this[this.
|
|
194
|
+
axis: this.pointer.axis,
|
|
195
|
+
index: this.pointer.index,
|
|
196
|
+
size: this[this.pointer.axis === "col" ? "colSize" : "rowSize"](this.pointer.index)
|
|
120
197
|
});
|
|
121
198
|
this.dispatchEvent(resizeEvent);
|
|
122
|
-
|
|
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
|
+
}
|
|
123
208
|
}
|
|
209
|
+
this.pointer = null;
|
|
124
210
|
};
|
|
125
211
|
this.handlePointerMove = (event) => {
|
|
126
|
-
if (this.resizing) {
|
|
127
|
-
const delta = getPage(this.
|
|
128
|
-
if (this.
|
|
129
|
-
const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, this.
|
|
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));
|
|
130
216
|
this.colSizes = {
|
|
131
217
|
...this.colSizes,
|
|
132
|
-
[this.
|
|
218
|
+
[this.pointer.index]: nextSize
|
|
133
219
|
};
|
|
134
220
|
this.updateVisInline();
|
|
135
221
|
} else {
|
|
136
|
-
const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, this.
|
|
222
|
+
const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, this.pointer.size + delta));
|
|
137
223
|
this.rowSizes = {
|
|
138
224
|
...this.rowSizes,
|
|
139
|
-
[this.
|
|
225
|
+
[this.pointer.index]: nextSize
|
|
140
226
|
};
|
|
141
227
|
this.updateVisBlock();
|
|
142
228
|
}
|
|
229
|
+
} else if (this.pointer?.state === "selecting") {
|
|
230
|
+
const cell = closestCell(event.target);
|
|
231
|
+
if (cell && (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
|
|
232
|
+
this.selectionEnd = cell;
|
|
233
|
+
}
|
|
143
234
|
}
|
|
144
235
|
};
|
|
145
236
|
//
|
|
@@ -158,19 +249,75 @@ var DxGrid = class extends LitElement {
|
|
|
158
249
|
});
|
|
159
250
|
this.viewportRef = createRef();
|
|
160
251
|
this.handleWheel = ({ deltaX, deltaY }) => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
252
|
+
if (this.mode === "browse") {
|
|
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
|
+
}
|
|
166
259
|
}
|
|
167
260
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
this.
|
|
261
|
+
}
|
|
262
|
+
//
|
|
263
|
+
// Primary pointer and keyboard handlers
|
|
264
|
+
//
|
|
265
|
+
dispatchEditRequest(initialContent) {
|
|
266
|
+
this.snapPosToFocusedCell();
|
|
267
|
+
queueMicrotask(() => this.dispatchEvent(new DxEditRequest({
|
|
268
|
+
cellIndex: toCellIndex(this.focusedCell),
|
|
269
|
+
cellBox: this.focusedCellBox(),
|
|
270
|
+
initialContent
|
|
271
|
+
})));
|
|
272
|
+
}
|
|
273
|
+
handleKeydown(event) {
|
|
274
|
+
if (this.focusActive && this.mode === "browse") {
|
|
275
|
+
switch (event.key) {
|
|
276
|
+
case "ArrowDown":
|
|
277
|
+
this.focusedCell = {
|
|
278
|
+
...this.focusedCell,
|
|
279
|
+
row: this.focusedCell.row + 1
|
|
280
|
+
};
|
|
281
|
+
break;
|
|
282
|
+
case "ArrowUp":
|
|
283
|
+
this.focusedCell = {
|
|
284
|
+
...this.focusedCell,
|
|
285
|
+
row: Math.max(0, this.focusedCell.row - 1)
|
|
286
|
+
};
|
|
287
|
+
break;
|
|
288
|
+
case "ArrowRight":
|
|
289
|
+
this.focusedCell = {
|
|
290
|
+
...this.focusedCell,
|
|
291
|
+
col: this.focusedCell.col + 1
|
|
292
|
+
};
|
|
293
|
+
break;
|
|
294
|
+
case "ArrowLeft":
|
|
295
|
+
this.focusedCell = {
|
|
296
|
+
...this.focusedCell,
|
|
297
|
+
col: Math.max(0, this.focusedCell.col - 1)
|
|
298
|
+
};
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
switch (event.key) {
|
|
302
|
+
case "Enter":
|
|
303
|
+
this.dispatchEditRequest();
|
|
304
|
+
break;
|
|
305
|
+
default:
|
|
306
|
+
if (event.key.length === 1 && event.key.match(/\P{Cc}/u)) {
|
|
307
|
+
this.dispatchEditRequest(event.key);
|
|
308
|
+
}
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
switch (event.key) {
|
|
312
|
+
case "ArrowDown":
|
|
313
|
+
case "ArrowUp":
|
|
314
|
+
case "ArrowRight":
|
|
315
|
+
case "ArrowLeft":
|
|
316
|
+
event.preventDefault();
|
|
317
|
+
this.snapPosToFocusedCell();
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
174
321
|
}
|
|
175
322
|
//
|
|
176
323
|
// Accessors
|
|
@@ -181,9 +328,33 @@ var DxGrid = class extends LitElement {
|
|
|
181
328
|
rowSize(r) {
|
|
182
329
|
return this.rowSizes?.[r] ?? this.rowDefault.size;
|
|
183
330
|
}
|
|
184
|
-
|
|
331
|
+
cell(c, r) {
|
|
185
332
|
return this.cells[`${c}${separator}${r}`];
|
|
186
333
|
}
|
|
334
|
+
focusedCellBox() {
|
|
335
|
+
const cellElement = this.focusedCellElement();
|
|
336
|
+
const cellSize = {
|
|
337
|
+
inlineSize: this.colSize(this.focusedCell.col),
|
|
338
|
+
blockSize: this.rowSize(this.focusedCell.row)
|
|
339
|
+
};
|
|
340
|
+
if (!cellElement) {
|
|
341
|
+
return {
|
|
342
|
+
insetInlineStart: NaN,
|
|
343
|
+
insetBlockStart: NaN,
|
|
344
|
+
...cellSize
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
const contentElement = cellElement.offsetParent;
|
|
348
|
+
const [_translate3d, inlineStr, blockStr] = contentElement.style.transform.split(/[()]|px,?\s?/);
|
|
349
|
+
const contentOffsetInline = parseFloat(inlineStr);
|
|
350
|
+
const contentOffsetBlock = parseFloat(blockStr);
|
|
351
|
+
const offsetParent = contentElement.offsetParent;
|
|
352
|
+
return {
|
|
353
|
+
insetInlineStart: cellElement.offsetLeft + contentOffsetInline + offsetParent.offsetLeft,
|
|
354
|
+
insetBlockStart: cellElement.offsetTop + contentOffsetBlock + offsetParent.offsetTop,
|
|
355
|
+
...cellSize
|
|
356
|
+
};
|
|
357
|
+
}
|
|
187
358
|
updateVisInline() {
|
|
188
359
|
let colIndex = 0;
|
|
189
360
|
let pxInline = this.colSize(colIndex);
|
|
@@ -238,31 +409,45 @@ var DxGrid = class extends LitElement {
|
|
|
238
409
|
this.updateVisInline();
|
|
239
410
|
this.updateVisBlock();
|
|
240
411
|
}
|
|
412
|
+
// Focus handlers
|
|
241
413
|
handleFocus(event) {
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const c = parseInt(target.getAttribute("aria-colindex") ?? "never");
|
|
246
|
-
const r = parseInt(target.getAttribute("aria-rowindex") ?? "never");
|
|
247
|
-
this.focusedCell = {
|
|
248
|
-
col: c,
|
|
249
|
-
row: r
|
|
250
|
-
};
|
|
414
|
+
const cellCoords = closestCell(event.target);
|
|
415
|
+
if (cellCoords) {
|
|
416
|
+
this.focusedCell = cellCoords;
|
|
251
417
|
this.focusActive = true;
|
|
252
418
|
}
|
|
253
419
|
}
|
|
254
420
|
handleBlur(event) {
|
|
255
|
-
if (!event.relatedTarget || event.relatedTarget.closest(
|
|
421
|
+
if (!event.relatedTarget || !event.relatedTarget.closest(`[data-grid="${this.gridId}"]`)) {
|
|
256
422
|
this.focusActive = false;
|
|
257
423
|
}
|
|
258
424
|
}
|
|
425
|
+
focusedCellElement() {
|
|
426
|
+
return this.viewportRef.value?.querySelector(`[aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`);
|
|
427
|
+
}
|
|
259
428
|
/**
|
|
260
429
|
* Moves focus to the cell with actual focus, otherwise moves focus to the viewport.
|
|
261
430
|
*/
|
|
262
|
-
refocus() {
|
|
263
|
-
|
|
431
|
+
refocus(increment, delta = 1) {
|
|
432
|
+
switch (increment) {
|
|
433
|
+
case "row":
|
|
434
|
+
this.focusedCell = {
|
|
435
|
+
...this.focusedCell,
|
|
436
|
+
row: this.focusedCell.row + delta
|
|
437
|
+
};
|
|
438
|
+
break;
|
|
439
|
+
case "col":
|
|
440
|
+
this.focusedCell = {
|
|
441
|
+
...this.focusedCell,
|
|
442
|
+
col: this.focusedCell.col + delta
|
|
443
|
+
};
|
|
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({
|
|
264
446
|
preventScroll: true
|
|
265
447
|
});
|
|
448
|
+
if (increment) {
|
|
449
|
+
this.snapPosToFocusedCell();
|
|
450
|
+
}
|
|
266
451
|
}
|
|
267
452
|
/**
|
|
268
453
|
* Updates `pos` so that a cell in focus is fully within the viewport
|
|
@@ -281,7 +466,7 @@ var DxGrid = class extends LitElement {
|
|
|
281
466
|
acc += this.colSize(this.visColMin + overscanCol + c0) + gap;
|
|
282
467
|
return acc;
|
|
283
468
|
}, 0);
|
|
284
|
-
this.posInline = this.binInlineMin + sizeSumCol + gap * 2 - this.sizeInline;
|
|
469
|
+
this.posInline = Math.max(0, this.binInlineMin + sizeSumCol + gap * 2 - this.sizeInline);
|
|
285
470
|
this.updateVisInline();
|
|
286
471
|
}
|
|
287
472
|
if (this.focusedCell.row <= this.visRowMin + overscanRow) {
|
|
@@ -294,65 +479,34 @@ var DxGrid = class extends LitElement {
|
|
|
294
479
|
acc += this.rowSize(this.visRowMin + overscanRow + r0) + gap;
|
|
295
480
|
return acc;
|
|
296
481
|
}, 0);
|
|
297
|
-
this.posBlock = this.binBlockMin + sizeSumRow + gap * 2 - this.sizeBlock;
|
|
482
|
+
this.posBlock = Math.max(0, this.binBlockMin + sizeSumRow + gap * 2 - this.sizeBlock);
|
|
298
483
|
this.updateVisBlock();
|
|
299
484
|
}
|
|
300
485
|
}
|
|
301
486
|
}
|
|
302
|
-
// Keyboard interactions
|
|
303
|
-
handleKeydown(event) {
|
|
304
|
-
if (this.focusActive) {
|
|
305
|
-
switch (event.key) {
|
|
306
|
-
case "ArrowDown":
|
|
307
|
-
this.focusedCell = {
|
|
308
|
-
...this.focusedCell,
|
|
309
|
-
row: this.focusedCell.row + 1
|
|
310
|
-
};
|
|
311
|
-
break;
|
|
312
|
-
case "ArrowUp":
|
|
313
|
-
this.focusedCell = {
|
|
314
|
-
...this.focusedCell,
|
|
315
|
-
row: Math.max(0, this.focusedCell.row - 1)
|
|
316
|
-
};
|
|
317
|
-
break;
|
|
318
|
-
case "ArrowRight":
|
|
319
|
-
this.focusedCell = {
|
|
320
|
-
...this.focusedCell,
|
|
321
|
-
col: this.focusedCell.col + 1
|
|
322
|
-
};
|
|
323
|
-
break;
|
|
324
|
-
case "ArrowLeft":
|
|
325
|
-
this.focusedCell = {
|
|
326
|
-
...this.focusedCell,
|
|
327
|
-
col: Math.max(0, this.focusedCell.col - 1)
|
|
328
|
-
};
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
331
|
-
switch (event.key) {
|
|
332
|
-
case "ArrowDown":
|
|
333
|
-
case "ArrowUp":
|
|
334
|
-
case "ArrowRight":
|
|
335
|
-
case "ArrowLeft":
|
|
336
|
-
event.preventDefault();
|
|
337
|
-
this.snapPosToFocusedCell();
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
487
|
//
|
|
343
488
|
// Render and other lifecycle methods
|
|
344
489
|
//
|
|
345
490
|
render() {
|
|
346
491
|
const visibleCols = this.visColMax - this.visColMin;
|
|
347
492
|
const visibleRows = this.visRowMax - this.visRowMin;
|
|
348
|
-
const offsetInline =
|
|
349
|
-
const offsetBlock =
|
|
493
|
+
const offsetInline = this.binInlineMin - this.posInline - this.overscanInline;
|
|
494
|
+
const offsetBlock = this.binBlockMin - this.posBlock - this.overscanBlock;
|
|
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;
|
|
350
500
|
return html`<div
|
|
351
501
|
role="none"
|
|
352
502
|
class="dx-grid"
|
|
503
|
+
data-grid=${this.gridId}
|
|
504
|
+
data-grid-mode=${this.mode}
|
|
505
|
+
?data-grid-select=${selectVisible}
|
|
353
506
|
@pointerdown=${this.handlePointerDown}
|
|
354
507
|
@pointerup=${this.handlePointerUp}
|
|
355
508
|
@pointermove=${this.handlePointerMove}
|
|
509
|
+
@pointerleave=${this.handlePointerUp}
|
|
356
510
|
@focus=${this.handleFocus}
|
|
357
511
|
@blur=${this.handleBlur}
|
|
358
512
|
@keydown=${this.handleKeydown}
|
|
@@ -415,11 +569,15 @@ var DxGrid = class extends LitElement {
|
|
|
415
569
|
].map((_2, r0) => {
|
|
416
570
|
const c = c0 + this.visColMin;
|
|
417
571
|
const r = r0 + this.visRowMin;
|
|
418
|
-
const cell = this.
|
|
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;
|
|
419
575
|
return html`<div
|
|
420
576
|
role="gridcell"
|
|
421
577
|
tabindex="0"
|
|
422
578
|
?inert=${c < 0 || r < 0}
|
|
579
|
+
?aria-selected=${selected}
|
|
580
|
+
class=${cell || active ? (cell?.className ? cell.className + " " : "") + (active ? "dx-grid__cell--active" : "") : nothing}
|
|
423
581
|
aria-rowindex=${r}
|
|
424
582
|
aria-colindex=${c}
|
|
425
583
|
data-dx-grid-action="cell"
|
|
@@ -471,6 +629,11 @@ var DxGrid = class extends LitElement {
|
|
|
471
629
|
return this;
|
|
472
630
|
}
|
|
473
631
|
};
|
|
632
|
+
_ts_decorate([
|
|
633
|
+
property({
|
|
634
|
+
type: String
|
|
635
|
+
})
|
|
636
|
+
], DxGrid.prototype, "gridId", void 0);
|
|
474
637
|
_ts_decorate([
|
|
475
638
|
property({
|
|
476
639
|
type: Object
|
|
@@ -496,6 +659,11 @@ _ts_decorate([
|
|
|
496
659
|
type: Object
|
|
497
660
|
})
|
|
498
661
|
], DxGrid.prototype, "cells", void 0);
|
|
662
|
+
_ts_decorate([
|
|
663
|
+
property({
|
|
664
|
+
type: String
|
|
665
|
+
})
|
|
666
|
+
], DxGrid.prototype, "mode", void 0);
|
|
499
667
|
_ts_decorate([
|
|
500
668
|
state()
|
|
501
669
|
], DxGrid.prototype, "posInline", void 0);
|
|
@@ -544,6 +712,9 @@ _ts_decorate([
|
|
|
544
712
|
_ts_decorate([
|
|
545
713
|
state()
|
|
546
714
|
], DxGrid.prototype, "templateRows", void 0);
|
|
715
|
+
_ts_decorate([
|
|
716
|
+
state()
|
|
717
|
+
], DxGrid.prototype, "pointer", void 0);
|
|
547
718
|
_ts_decorate([
|
|
548
719
|
state()
|
|
549
720
|
], DxGrid.prototype, "colSizes", void 0);
|
|
@@ -552,16 +723,19 @@ _ts_decorate([
|
|
|
552
723
|
], DxGrid.prototype, "rowSizes", void 0);
|
|
553
724
|
_ts_decorate([
|
|
554
725
|
state()
|
|
555
|
-
], DxGrid.prototype, "
|
|
726
|
+
], DxGrid.prototype, "focusActive", void 0);
|
|
556
727
|
_ts_decorate([
|
|
557
728
|
state()
|
|
558
|
-
], DxGrid.prototype, "
|
|
729
|
+
], DxGrid.prototype, "focusedCell", void 0);
|
|
559
730
|
_ts_decorate([
|
|
560
731
|
state()
|
|
561
|
-
], DxGrid.prototype, "
|
|
732
|
+
], DxGrid.prototype, "selectionStart", void 0);
|
|
562
733
|
_ts_decorate([
|
|
563
734
|
state()
|
|
564
|
-
], DxGrid.prototype, "
|
|
735
|
+
], DxGrid.prototype, "selectionEnd", void 0);
|
|
736
|
+
_ts_decorate([
|
|
737
|
+
state()
|
|
738
|
+
], DxGrid.prototype, "observer", void 0);
|
|
565
739
|
_ts_decorate([
|
|
566
740
|
eventOptions({
|
|
567
741
|
capture: true
|
|
@@ -577,6 +751,8 @@ DxGrid = _ts_decorate([
|
|
|
577
751
|
], DxGrid);
|
|
578
752
|
export {
|
|
579
753
|
DxAxisResize,
|
|
580
|
-
|
|
754
|
+
DxEditRequest,
|
|
755
|
+
DxGrid,
|
|
756
|
+
DxGridCellsSelect
|
|
581
757
|
};
|
|
582
758
|
//# sourceMappingURL=index.mjs.map
|