@dxos/lit-grid 0.6.12-main.ac23639 → 0.6.12-main.c4a728f
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 +794 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/types/src/dx-grid.d.ts +6 -47
- package/dist/types/src/dx-grid.d.ts.map +1 -1
- package/dist/types/src/dx-grid.lit-stories.d.ts +1 -23
- package/dist/types/src/dx-grid.lit-stories.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +13 -57
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +2 -4
- package/dist/types/src/util.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/dx-grid.lit-stories.ts +16 -140
- package/src/dx-grid.pcss +67 -43
- package/src/dx-grid.ts +287 -708
- package/src/types.ts +11 -72
- package/src/util.ts +2 -18
- package/dist/src/dx-grid-axis-resize-handle.d.ts +0 -16
- package/dist/src/dx-grid-axis-resize-handle.d.ts.map +0 -1
- package/dist/src/dx-grid-axis-resize-handle.js +0 -96
- package/dist/src/dx-grid-axis-resize-handle.js.map +0 -1
- package/dist/src/dx-grid.d.ts +0 -114
- package/dist/src/dx-grid.d.ts.map +0 -1
- package/dist/src/dx-grid.js +0 -1047
- package/dist/src/dx-grid.js.map +0 -1
- package/dist/src/dx-grid.lit-stories.d.ts +0 -42
- package/dist/src/dx-grid.lit-stories.d.ts.map +0 -1
- package/dist/src/dx-grid.lit-stories.js +0 -166
- package/dist/src/dx-grid.lit-stories.js.map +0 -1
- package/dist/src/index.d.ts +0 -3
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js +0 -6
- package/dist/src/index.js.map +0 -1
- package/dist/src/types.d.ts +0 -106
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -44
- package/dist/src/types.js.map +0 -1
- package/dist/src/util.d.ts +0 -9
- package/dist/src/util.d.ts.map +0 -1
- package/dist/src/util.js +0 -19
- package/dist/src/util.js.map +0 -1
- package/dist/types/src/dx-grid-axis-resize-handle.d.ts +0 -16
- package/dist/types/src/dx-grid-axis-resize-handle.d.ts.map +0 -1
- package/dist/types/src/dx-grid-axis-resize-handle.js +0 -96
- package/dist/types/src/dx-grid-axis-resize-handle.js.map +0 -1
- package/dist/types/src/dx-grid.js +0 -1047
- package/dist/types/src/dx-grid.js.map +0 -1
- package/dist/types/src/dx-grid.lit-stories.js +0 -166
- package/dist/types/src/dx-grid.lit-stories.js.map +0 -1
- package/dist/types/src/index.js +0 -6
- package/dist/types/src/index.js.map +0 -1
- package/dist/types/src/types.js +0 -44
- package/dist/types/src/types.js.map +0 -1
- package/dist/types/src/util.js +0 -19
- package/dist/types/src/util.js.map +0 -1
- package/src/dx-grid-axis-resize-handle.ts +0 -87
|
@@ -0,0 +1,794 @@
|
|
|
1
|
+
// packages/ui/lit-grid/src/dx-grid.ts
|
|
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";
|
|
5
|
+
|
|
6
|
+
// packages/ui/lit-grid/src/util.ts
|
|
7
|
+
var separator = ",";
|
|
8
|
+
var toCellIndex = (cellCoords) => `${cellCoords.col}${separator}${cellCoords.row}`;
|
|
9
|
+
|
|
10
|
+
// packages/ui/lit-grid/src/types.ts
|
|
11
|
+
var DxAxisResize = class extends Event {
|
|
12
|
+
constructor(props) {
|
|
13
|
+
super("dx-axis-resize");
|
|
14
|
+
this.axis = props.axis;
|
|
15
|
+
this.index = props.index;
|
|
16
|
+
this.size = props.size;
|
|
17
|
+
}
|
|
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
|
+
};
|
|
38
|
+
|
|
39
|
+
// packages/ui/lit-grid/src/dx-grid.ts
|
|
40
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
41
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
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;
|
|
44
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
45
|
+
}
|
|
46
|
+
var gap = 1;
|
|
47
|
+
var resizeTolerance = 8;
|
|
48
|
+
var overscanCol = 1;
|
|
49
|
+
var overscanRow = 1;
|
|
50
|
+
var sizeColMin = 32;
|
|
51
|
+
var sizeColMax = 1024;
|
|
52
|
+
var sizeRowMin = 16;
|
|
53
|
+
var sizeRowMax = 1024;
|
|
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);
|
|
56
|
+
};
|
|
57
|
+
var rowToA1Notation = (row) => {
|
|
58
|
+
return `${row + 1}`;
|
|
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;
|
|
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 {
|
|
91
|
+
constructor() {
|
|
92
|
+
super(...arguments);
|
|
93
|
+
this.gridId = "default-grid-id";
|
|
94
|
+
this.rowDefault = {
|
|
95
|
+
size: 32
|
|
96
|
+
};
|
|
97
|
+
this.columnDefault = {
|
|
98
|
+
size: 180
|
|
99
|
+
};
|
|
100
|
+
this.rows = {};
|
|
101
|
+
this.columns = {};
|
|
102
|
+
this.initialCells = {};
|
|
103
|
+
this.mode = "browse";
|
|
104
|
+
/**
|
|
105
|
+
* When this function is defined, it is used first to try to get a value for a cell, and otherwise will fall back
|
|
106
|
+
* to `cells`.
|
|
107
|
+
*/
|
|
108
|
+
this.getCells = null;
|
|
109
|
+
this.cells = {};
|
|
110
|
+
//
|
|
111
|
+
// `pos`, short for ‘position’, is the position in pixels of the viewport from the origin.
|
|
112
|
+
//
|
|
113
|
+
this.posInline = 0;
|
|
114
|
+
this.posBlock = 0;
|
|
115
|
+
//
|
|
116
|
+
// `size` (when not suffixed with ‘row’ or ‘col’, see above) is the size in pixels of the viewport.
|
|
117
|
+
//
|
|
118
|
+
this.sizeInline = 0;
|
|
119
|
+
this.sizeBlock = 0;
|
|
120
|
+
//
|
|
121
|
+
// `overscan` is the amount in pixels to offset the grid content due to the number of overscanned columns or rows.
|
|
122
|
+
//
|
|
123
|
+
this.overscanInline = 0;
|
|
124
|
+
this.overscanBlock = 0;
|
|
125
|
+
//
|
|
126
|
+
// `bin`, not short for anything, is the range in pixels within which virtualization does not need to reassess.
|
|
127
|
+
//
|
|
128
|
+
this.binInlineMin = 0;
|
|
129
|
+
this.binInlineMax = this.colSize(0);
|
|
130
|
+
this.binBlockMin = 0;
|
|
131
|
+
this.binBlockMax = this.rowSize(0);
|
|
132
|
+
//
|
|
133
|
+
// `vis`, short for ‘visible’, is the range in numeric index of the columns or rows which should be rendered within
|
|
134
|
+
// the viewport. These start with naïve values that are updated before first contentful render.
|
|
135
|
+
//
|
|
136
|
+
this.visColMin = 0;
|
|
137
|
+
this.visColMax = 1;
|
|
138
|
+
this.visRowMin = 0;
|
|
139
|
+
this.visRowMax = 1;
|
|
140
|
+
//
|
|
141
|
+
// `template` is the rendered value of `grid-{axis}-template`.
|
|
142
|
+
//
|
|
143
|
+
this.templateColumns = `${this.colSize(0)}px`;
|
|
144
|
+
this.templateRows = `${this.rowSize(0)}px`;
|
|
145
|
+
//
|
|
146
|
+
// Focus, selection, and resize states
|
|
147
|
+
//
|
|
148
|
+
this.pointer = null;
|
|
149
|
+
this.colSizes = {};
|
|
150
|
+
this.rowSizes = {};
|
|
151
|
+
this.focusActive = false;
|
|
152
|
+
this.focusedCell = {
|
|
153
|
+
col: 0,
|
|
154
|
+
row: 0
|
|
155
|
+
};
|
|
156
|
+
this.selectionStart = {
|
|
157
|
+
col: 0,
|
|
158
|
+
row: 0
|
|
159
|
+
};
|
|
160
|
+
this.selectionEnd = {
|
|
161
|
+
col: 0,
|
|
162
|
+
row: 0
|
|
163
|
+
};
|
|
164
|
+
this.handlePointerDown = (event) => {
|
|
165
|
+
if (event.isPrimary) {
|
|
166
|
+
const { action, actionEl } = closestAction(event.target);
|
|
167
|
+
if (action) {
|
|
168
|
+
if (action.startsWith("resize") && this.mode === "browse") {
|
|
169
|
+
const [resize, index] = action.split(",");
|
|
170
|
+
const [_, axis] = resize.split("-");
|
|
171
|
+
this.pointer = {
|
|
172
|
+
state: "resizing",
|
|
173
|
+
axis,
|
|
174
|
+
size: axis === "col" ? this.colSize(index) : this.rowSize(index),
|
|
175
|
+
page: getPage(axis, event),
|
|
176
|
+
index
|
|
177
|
+
};
|
|
178
|
+
} else if (action === "cell") {
|
|
179
|
+
const cellCoords = closestCell(event.target, actionEl);
|
|
180
|
+
if (cellCoords) {
|
|
181
|
+
this.pointer = {
|
|
182
|
+
state: "selecting"
|
|
183
|
+
};
|
|
184
|
+
this.selectionStart = cellCoords;
|
|
185
|
+
}
|
|
186
|
+
if (this.mode === "edit") {
|
|
187
|
+
event.preventDefault();
|
|
188
|
+
} else {
|
|
189
|
+
if (this.focusActive && isSameCell(this.focusedCell, cellCoords)) {
|
|
190
|
+
this.dispatchEditRequest();
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
this.handlePointerUp = (event) => {
|
|
198
|
+
if (this.pointer?.state === "resizing") {
|
|
199
|
+
const resizeEvent = new DxAxisResize({
|
|
200
|
+
axis: this.pointer.axis,
|
|
201
|
+
index: this.pointer.index,
|
|
202
|
+
size: this[this.pointer.axis === "col" ? "colSize" : "rowSize"](this.pointer.index)
|
|
203
|
+
});
|
|
204
|
+
this.dispatchEvent(resizeEvent);
|
|
205
|
+
} else {
|
|
206
|
+
const cell = closestCell(event.target);
|
|
207
|
+
if (cell) {
|
|
208
|
+
this.selectionEnd = cell;
|
|
209
|
+
this.dispatchEvent(new DxGridCellsSelect({
|
|
210
|
+
start: this.selectionStart,
|
|
211
|
+
end: this.selectionEnd
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
this.pointer = null;
|
|
216
|
+
};
|
|
217
|
+
this.handlePointerMove = (event) => {
|
|
218
|
+
if (this.pointer?.state === "resizing") {
|
|
219
|
+
const delta = getPage(this.pointer.axis, event) - this.pointer.page;
|
|
220
|
+
if (this.pointer.axis === "col") {
|
|
221
|
+
const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, this.pointer.size + delta));
|
|
222
|
+
this.colSizes = {
|
|
223
|
+
...this.colSizes,
|
|
224
|
+
[this.pointer.index]: nextSize
|
|
225
|
+
};
|
|
226
|
+
this.updateVisInline();
|
|
227
|
+
} else {
|
|
228
|
+
const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, this.pointer.size + delta));
|
|
229
|
+
this.rowSizes = {
|
|
230
|
+
...this.rowSizes,
|
|
231
|
+
[this.pointer.index]: nextSize
|
|
232
|
+
};
|
|
233
|
+
this.updateVisBlock();
|
|
234
|
+
}
|
|
235
|
+
} else if (this.pointer?.state === "selecting") {
|
|
236
|
+
const cell = closestCell(event.target);
|
|
237
|
+
if (cell && (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
|
|
238
|
+
this.selectionEnd = cell;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
//
|
|
243
|
+
// Resize & reposition handlers, observer, ref
|
|
244
|
+
//
|
|
245
|
+
this.observer = new ResizeObserver((entries) => {
|
|
246
|
+
const { inlineSize, blockSize } = entries?.[0]?.contentBoxSize?.[0] ?? {
|
|
247
|
+
inlineSize: 0,
|
|
248
|
+
blockSize: 0
|
|
249
|
+
};
|
|
250
|
+
if (Math.abs(inlineSize - this.sizeInline) > resizeTolerance || Math.abs(blockSize - this.sizeBlock) > resizeTolerance) {
|
|
251
|
+
this.sizeInline = inlineSize;
|
|
252
|
+
this.sizeBlock = blockSize;
|
|
253
|
+
this.updateVis();
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
this.viewportRef = createRef();
|
|
257
|
+
this.handleWheel = ({ deltaX, deltaY }) => {
|
|
258
|
+
if (this.mode === "browse") {
|
|
259
|
+
this.posInline = Math.max(0, this.posInline + deltaX);
|
|
260
|
+
this.posBlock = Math.max(0, this.posBlock + deltaY);
|
|
261
|
+
if (this.posInline >= this.binInlineMin && this.posInline < this.binInlineMax && this.posBlock >= this.binBlockMin && this.posBlock < this.binBlockMax) {
|
|
262
|
+
} else {
|
|
263
|
+
this.updateVis();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
//
|
|
269
|
+
// Primary pointer and keyboard handlers
|
|
270
|
+
//
|
|
271
|
+
dispatchEditRequest(initialContent) {
|
|
272
|
+
this.snapPosToFocusedCell();
|
|
273
|
+
queueMicrotask(() => this.dispatchEvent(new DxEditRequest({
|
|
274
|
+
cellIndex: toCellIndex(this.focusedCell),
|
|
275
|
+
cellBox: this.focusedCellBox(),
|
|
276
|
+
initialContent
|
|
277
|
+
})));
|
|
278
|
+
}
|
|
279
|
+
handleKeydown(event) {
|
|
280
|
+
if (this.focusActive && this.mode === "browse") {
|
|
281
|
+
switch (event.key) {
|
|
282
|
+
case "ArrowDown":
|
|
283
|
+
this.focusedCell = {
|
|
284
|
+
...this.focusedCell,
|
|
285
|
+
row: this.focusedCell.row + 1
|
|
286
|
+
};
|
|
287
|
+
break;
|
|
288
|
+
case "ArrowUp":
|
|
289
|
+
this.focusedCell = {
|
|
290
|
+
...this.focusedCell,
|
|
291
|
+
row: Math.max(0, this.focusedCell.row - 1)
|
|
292
|
+
};
|
|
293
|
+
break;
|
|
294
|
+
case "ArrowRight":
|
|
295
|
+
this.focusedCell = {
|
|
296
|
+
...this.focusedCell,
|
|
297
|
+
col: this.focusedCell.col + 1
|
|
298
|
+
};
|
|
299
|
+
break;
|
|
300
|
+
case "ArrowLeft":
|
|
301
|
+
this.focusedCell = {
|
|
302
|
+
...this.focusedCell,
|
|
303
|
+
col: Math.max(0, this.focusedCell.col - 1)
|
|
304
|
+
};
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
switch (event.key) {
|
|
308
|
+
case "Enter":
|
|
309
|
+
this.dispatchEditRequest();
|
|
310
|
+
break;
|
|
311
|
+
default:
|
|
312
|
+
if (event.key.length === 1 && event.key.match(/\P{Cc}/u)) {
|
|
313
|
+
this.dispatchEditRequest(event.key);
|
|
314
|
+
}
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
switch (event.key) {
|
|
318
|
+
case "ArrowDown":
|
|
319
|
+
case "ArrowUp":
|
|
320
|
+
case "ArrowRight":
|
|
321
|
+
case "ArrowLeft":
|
|
322
|
+
event.preventDefault();
|
|
323
|
+
this.snapPosToFocusedCell();
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
//
|
|
329
|
+
// Accessors
|
|
330
|
+
//
|
|
331
|
+
colSize(c) {
|
|
332
|
+
return this.colSizes?.[c] ?? this.columnDefault.size;
|
|
333
|
+
}
|
|
334
|
+
rowSize(r) {
|
|
335
|
+
return this.rowSizes?.[r] ?? this.rowDefault.size;
|
|
336
|
+
}
|
|
337
|
+
cell(c, r) {
|
|
338
|
+
const index = `${c}${separator}${r}`;
|
|
339
|
+
return this.cells[index] ?? this.initialCells[index];
|
|
340
|
+
}
|
|
341
|
+
focusedCellBox() {
|
|
342
|
+
const cellElement = this.focusedCellElement();
|
|
343
|
+
const cellSize = {
|
|
344
|
+
inlineSize: this.colSize(this.focusedCell.col),
|
|
345
|
+
blockSize: this.rowSize(this.focusedCell.row)
|
|
346
|
+
};
|
|
347
|
+
if (!cellElement) {
|
|
348
|
+
return {
|
|
349
|
+
insetInlineStart: NaN,
|
|
350
|
+
insetBlockStart: NaN,
|
|
351
|
+
...cellSize
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
const contentElement = cellElement.offsetParent;
|
|
355
|
+
const [_translate3d, inlineStr, blockStr] = contentElement.style.transform.split(/[()]|px,?\s?/);
|
|
356
|
+
const contentOffsetInline = parseFloat(inlineStr);
|
|
357
|
+
const contentOffsetBlock = parseFloat(blockStr);
|
|
358
|
+
const offsetParent = contentElement.offsetParent;
|
|
359
|
+
return {
|
|
360
|
+
insetInlineStart: cellElement.offsetLeft + contentOffsetInline + offsetParent.offsetLeft,
|
|
361
|
+
insetBlockStart: cellElement.offsetTop + contentOffsetBlock + offsetParent.offsetTop,
|
|
362
|
+
...cellSize
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
updateVisInline() {
|
|
366
|
+
let colIndex = 0;
|
|
367
|
+
let pxInline = this.colSize(colIndex);
|
|
368
|
+
while (pxInline < this.posInline) {
|
|
369
|
+
colIndex += 1;
|
|
370
|
+
pxInline += this.colSize(colIndex) + gap;
|
|
371
|
+
}
|
|
372
|
+
this.visColMin = colIndex - overscanCol;
|
|
373
|
+
this.binInlineMin = pxInline - this.colSize(colIndex) - gap;
|
|
374
|
+
this.binInlineMax = pxInline + gap;
|
|
375
|
+
this.overscanInline = [
|
|
376
|
+
...Array(overscanCol)
|
|
377
|
+
].reduce((acc, _, c0) => {
|
|
378
|
+
acc += this.colSize(this.visColMin + c0);
|
|
379
|
+
return acc;
|
|
380
|
+
}, 0) + gap * (overscanCol - 1);
|
|
381
|
+
while (pxInline < this.binInlineMax + this.sizeInline + gap) {
|
|
382
|
+
colIndex += 1;
|
|
383
|
+
pxInline += this.colSize(colIndex) + gap;
|
|
384
|
+
}
|
|
385
|
+
this.visColMax = colIndex + overscanCol;
|
|
386
|
+
this.templateColumns = [
|
|
387
|
+
...Array(this.visColMax - this.visColMin)
|
|
388
|
+
].map((_, c0) => `${this.colSize(this.visColMin + c0)}px`).join(" ");
|
|
389
|
+
}
|
|
390
|
+
updateVisBlock() {
|
|
391
|
+
let rowIndex = 0;
|
|
392
|
+
let pxBlock = this.rowSize(rowIndex);
|
|
393
|
+
while (pxBlock < this.posBlock) {
|
|
394
|
+
rowIndex += 1;
|
|
395
|
+
pxBlock += this.rowSize(rowIndex) + gap;
|
|
396
|
+
}
|
|
397
|
+
this.visRowMin = rowIndex - overscanRow;
|
|
398
|
+
this.binBlockMin = pxBlock - this.rowSize(rowIndex) - gap;
|
|
399
|
+
this.binBlockMax = pxBlock + gap;
|
|
400
|
+
this.overscanBlock = [
|
|
401
|
+
...Array(overscanRow)
|
|
402
|
+
].reduce((acc, _, r0) => {
|
|
403
|
+
acc += this.rowSize(this.visRowMin + r0);
|
|
404
|
+
return acc;
|
|
405
|
+
}, 0) + gap * (overscanRow - 1);
|
|
406
|
+
while (pxBlock < this.binBlockMax + this.sizeBlock) {
|
|
407
|
+
rowIndex += 1;
|
|
408
|
+
pxBlock += this.rowSize(rowIndex) + gap;
|
|
409
|
+
}
|
|
410
|
+
this.visRowMax = rowIndex + overscanRow;
|
|
411
|
+
this.templateRows = [
|
|
412
|
+
...Array(this.visRowMax - this.visRowMin)
|
|
413
|
+
].map((_, r0) => `${this.rowSize(this.visRowMin + r0)}px`).join(" ");
|
|
414
|
+
}
|
|
415
|
+
updateVis() {
|
|
416
|
+
this.updateVisInline();
|
|
417
|
+
this.updateVisBlock();
|
|
418
|
+
}
|
|
419
|
+
// Focus handlers
|
|
420
|
+
handleFocus(event) {
|
|
421
|
+
const cellCoords = closestCell(event.target);
|
|
422
|
+
if (cellCoords) {
|
|
423
|
+
this.focusedCell = cellCoords;
|
|
424
|
+
this.focusActive = true;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
handleBlur(event) {
|
|
428
|
+
if (!event.relatedTarget || !event.relatedTarget.closest(`[data-grid="${this.gridId}"]`)) {
|
|
429
|
+
this.focusActive = false;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
focusedCellElement() {
|
|
433
|
+
return this.viewportRef.value?.querySelector(`[aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Moves focus to the cell with actual focus, otherwise moves focus to the viewport.
|
|
437
|
+
*/
|
|
438
|
+
refocus(increment, delta = 1) {
|
|
439
|
+
switch (increment) {
|
|
440
|
+
case "row":
|
|
441
|
+
this.focusedCell = {
|
|
442
|
+
...this.focusedCell,
|
|
443
|
+
row: this.focusedCell.row + delta
|
|
444
|
+
};
|
|
445
|
+
break;
|
|
446
|
+
case "col":
|
|
447
|
+
this.focusedCell = {
|
|
448
|
+
...this.focusedCell,
|
|
449
|
+
col: this.focusedCell.col + delta
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
(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({
|
|
453
|
+
preventScroll: true
|
|
454
|
+
});
|
|
455
|
+
if (increment) {
|
|
456
|
+
this.snapPosToFocusedCell();
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Updates `pos` so that a cell in focus is fully within the viewport
|
|
461
|
+
*/
|
|
462
|
+
snapPosToFocusedCell() {
|
|
463
|
+
if (this.focusedCell.col < this.visColMin || this.focusedCell.col > this.visColMax || this.focusedCell.row < this.visRowMin || this.focusedCell.row > this.visRowMax) {
|
|
464
|
+
} 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) {
|
|
465
|
+
} else {
|
|
466
|
+
if (this.focusedCell.col <= this.visColMin + overscanCol) {
|
|
467
|
+
this.posInline = this.binInlineMin;
|
|
468
|
+
this.updateVisInline();
|
|
469
|
+
} else if (this.focusedCell.col >= this.visColMax - overscanCol - 1) {
|
|
470
|
+
const sizeSumCol = [
|
|
471
|
+
...Array(this.focusedCell.col - this.visColMin)
|
|
472
|
+
].reduce((acc, _, c0) => {
|
|
473
|
+
acc += this.colSize(this.visColMin + overscanCol + c0) + gap;
|
|
474
|
+
return acc;
|
|
475
|
+
}, 0);
|
|
476
|
+
this.posInline = Math.max(0, this.binInlineMin + sizeSumCol + gap * 2 - this.sizeInline);
|
|
477
|
+
this.updateVisInline();
|
|
478
|
+
}
|
|
479
|
+
if (this.focusedCell.row <= this.visRowMin + overscanRow) {
|
|
480
|
+
this.posBlock = this.binBlockMin;
|
|
481
|
+
this.updateVisBlock();
|
|
482
|
+
} else if (this.focusedCell.row >= this.visRowMax - overscanRow - 1) {
|
|
483
|
+
const sizeSumRow = [
|
|
484
|
+
...Array(this.focusedCell.row - this.visRowMin)
|
|
485
|
+
].reduce((acc, _, r0) => {
|
|
486
|
+
acc += this.rowSize(this.visRowMin + overscanRow + r0) + gap;
|
|
487
|
+
return acc;
|
|
488
|
+
}, 0);
|
|
489
|
+
this.posBlock = Math.max(0, this.binBlockMin + sizeSumRow + gap * 2 - this.sizeBlock);
|
|
490
|
+
this.updateVisBlock();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
//
|
|
495
|
+
// Render and other lifecycle methods
|
|
496
|
+
//
|
|
497
|
+
render() {
|
|
498
|
+
const visibleCols = this.visColMax - this.visColMin;
|
|
499
|
+
const visibleRows = this.visRowMax - this.visRowMin;
|
|
500
|
+
const offsetInline = this.binInlineMin - this.posInline - this.overscanInline;
|
|
501
|
+
const offsetBlock = this.binBlockMin - this.posBlock - this.overscanBlock;
|
|
502
|
+
const selectColMin = Math.min(this.selectionStart.col, this.selectionEnd.col);
|
|
503
|
+
const selectColMax = Math.max(this.selectionStart.col, this.selectionEnd.col);
|
|
504
|
+
const selectRowMin = Math.min(this.selectionStart.row, this.selectionEnd.row);
|
|
505
|
+
const selectRowMax = Math.max(this.selectionStart.row, this.selectionEnd.row);
|
|
506
|
+
const selectVisible = selectColMin !== selectColMax || selectRowMin !== selectRowMax;
|
|
507
|
+
return html`<div
|
|
508
|
+
role="none"
|
|
509
|
+
class="dx-grid"
|
|
510
|
+
data-grid=${this.gridId}
|
|
511
|
+
data-grid-mode=${this.mode}
|
|
512
|
+
?data-grid-select=${selectVisible}
|
|
513
|
+
@pointerdown=${this.handlePointerDown}
|
|
514
|
+
@pointerup=${this.handlePointerUp}
|
|
515
|
+
@pointermove=${this.handlePointerMove}
|
|
516
|
+
@pointerleave=${this.handlePointerUp}
|
|
517
|
+
@focus=${this.handleFocus}
|
|
518
|
+
@blur=${this.handleBlur}
|
|
519
|
+
@keydown=${this.handleKeydown}
|
|
520
|
+
>
|
|
521
|
+
<div role="none" class="dx-grid__corner"></div>
|
|
522
|
+
<div role="none" class="dx-grid__columnheader">
|
|
523
|
+
<div
|
|
524
|
+
role="none"
|
|
525
|
+
class="dx-grid__columnheader__content"
|
|
526
|
+
style="transform:translate3d(${offsetInline}px,0,0);grid-template-columns:${this.templateColumns};"
|
|
527
|
+
>
|
|
528
|
+
${[
|
|
529
|
+
...Array(visibleCols)
|
|
530
|
+
].map((_, c0) => {
|
|
531
|
+
const c = this.visColMin + c0;
|
|
532
|
+
return html`<div
|
|
533
|
+
role="columnheader"
|
|
534
|
+
?inert=${c < 0}
|
|
535
|
+
style="block-size:${this.rowDefault.size}px;grid-column:${c0 + 1}/${c0 + 2};"
|
|
536
|
+
>
|
|
537
|
+
<span id=${localChId(c0)}>${colToA1Notation(c)}</span>
|
|
538
|
+
${(this.columns[c]?.resizeable ?? this.columnDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-col,${c}`}>
|
|
539
|
+
<span class="sr-only">Resize</span>
|
|
540
|
+
</button>`}
|
|
541
|
+
</div>`;
|
|
542
|
+
})}
|
|
543
|
+
</div>
|
|
544
|
+
</div>
|
|
545
|
+
<div role="none" class="dx-grid__corner"></div>
|
|
546
|
+
<div role="none" class="dx-grid__rowheader">
|
|
547
|
+
<div
|
|
548
|
+
role="none"
|
|
549
|
+
class="dx-grid__rowheader__content"
|
|
550
|
+
style="transform:translate3d(0,${offsetBlock}px,0);grid-template-rows:${this.templateRows};"
|
|
551
|
+
>
|
|
552
|
+
${[
|
|
553
|
+
...Array(visibleRows)
|
|
554
|
+
].map((_, r0) => {
|
|
555
|
+
const r = this.visRowMin + r0;
|
|
556
|
+
return html`<div role="rowheader" ?inert=${r < 0} style="grid-row:${r0 + 1}/${r0 + 2}">
|
|
557
|
+
<span id=${localRhId(r0)}>${rowToA1Notation(r)}</span>
|
|
558
|
+
${(this.rows[r]?.resizeable ?? this.rowDefault.resizeable) && html`<button class="dx-grid__resize-handle" data-dx-grid-action=${`resize-row,${r}`}>
|
|
559
|
+
<span class="sr-only">Resize</span>
|
|
560
|
+
</button>`}
|
|
561
|
+
</div>`;
|
|
562
|
+
})}
|
|
563
|
+
</div>
|
|
564
|
+
</div>
|
|
565
|
+
<div role="grid" class="dx-grid__viewport" tabindex="0" @wheel=${this.handleWheel} ${ref(this.viewportRef)}>
|
|
566
|
+
<div
|
|
567
|
+
role="none"
|
|
568
|
+
class="dx-grid__content"
|
|
569
|
+
style="transform:translate3d(${offsetInline}px,${offsetBlock}px,0);grid-template-columns:${this.templateColumns};grid-template-rows:${this.templateRows};"
|
|
570
|
+
>
|
|
571
|
+
${[
|
|
572
|
+
...Array(visibleCols)
|
|
573
|
+
].map((_, c0) => {
|
|
574
|
+
return [
|
|
575
|
+
...Array(visibleRows)
|
|
576
|
+
].map((_2, r0) => {
|
|
577
|
+
const c = c0 + this.visColMin;
|
|
578
|
+
const r = r0 + this.visRowMin;
|
|
579
|
+
const cell = this.cell(c, r);
|
|
580
|
+
const active = this.focusActive && this.focusedCell.col === c && this.focusedCell.row === r;
|
|
581
|
+
const selected = c >= selectColMin && c <= selectColMax && r >= selectRowMin && r <= selectRowMax;
|
|
582
|
+
return html`<div
|
|
583
|
+
role="gridcell"
|
|
584
|
+
tabindex="0"
|
|
585
|
+
?inert=${c < 0 || r < 0}
|
|
586
|
+
?aria-selected=${selected}
|
|
587
|
+
class=${cell || active ? (cell?.className ? cell.className + " " : "") + (active ? "dx-grid__cell--active" : "") : nothing}
|
|
588
|
+
aria-rowindex=${r}
|
|
589
|
+
aria-colindex=${c}
|
|
590
|
+
data-dx-grid-action="cell"
|
|
591
|
+
style="grid-column:${c0 + 1};grid-row:${r0 + 1}"
|
|
592
|
+
>
|
|
593
|
+
${cell?.value}
|
|
594
|
+
</div>`;
|
|
595
|
+
});
|
|
596
|
+
})}
|
|
597
|
+
</div>
|
|
598
|
+
</div>
|
|
599
|
+
<div role="none" class="dx-grid__scrollbar" aria-orientation="vertical">
|
|
600
|
+
<div role="none" class="dx-grid__scrollbar__thumb"></div>
|
|
601
|
+
</div>
|
|
602
|
+
<div role="none" class="dx-grid__corner"></div>
|
|
603
|
+
<div role="none" class="dx-grid__scrollbar" aria-orientation="horizontal">
|
|
604
|
+
<div role="none" class="dx-grid__scrollbar__thumb"></div>
|
|
605
|
+
</div>
|
|
606
|
+
<div role="none" class="dx-grid__corner"></div>
|
|
607
|
+
</div>`;
|
|
608
|
+
}
|
|
609
|
+
firstUpdated() {
|
|
610
|
+
if (this.getCells) {
|
|
611
|
+
this.cells = this.getCells({
|
|
612
|
+
start: {
|
|
613
|
+
col: this.visColMin,
|
|
614
|
+
row: this.visRowMin
|
|
615
|
+
},
|
|
616
|
+
end: {
|
|
617
|
+
col: this.visColMax,
|
|
618
|
+
row: this.visRowMax
|
|
619
|
+
}
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
this.observer.observe(this.viewportRef.value);
|
|
623
|
+
this.colSizes = Object.entries(this.columns).reduce((acc, [colId, colMeta]) => {
|
|
624
|
+
if (colMeta?.size) {
|
|
625
|
+
acc[colId] = colMeta.size;
|
|
626
|
+
}
|
|
627
|
+
return acc;
|
|
628
|
+
}, {});
|
|
629
|
+
this.rowSizes = Object.entries(this.rows).reduce((acc, [rowId, rowMeta]) => {
|
|
630
|
+
if (rowMeta?.size) {
|
|
631
|
+
acc[rowId] = rowMeta.size;
|
|
632
|
+
}
|
|
633
|
+
return acc;
|
|
634
|
+
}, {});
|
|
635
|
+
}
|
|
636
|
+
willUpdate(changedProperties) {
|
|
637
|
+
if (this.getCells && (changedProperties.has("initialCells") || changedProperties.has("visColMin") || changedProperties.has("visColMax") || changedProperties.has("visRowMin") || changedProperties.has("visRowMax"))) {
|
|
638
|
+
this.cells = this.getCells({
|
|
639
|
+
start: {
|
|
640
|
+
col: this.visColMin,
|
|
641
|
+
row: this.visRowMin
|
|
642
|
+
},
|
|
643
|
+
end: {
|
|
644
|
+
col: this.visColMax,
|
|
645
|
+
row: this.visRowMax
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
updated(changedProperties) {
|
|
651
|
+
if (this.focusActive && (changedProperties.has("visRowMin") || changedProperties.has("visColMin") || changedProperties.has("focusedCell"))) {
|
|
652
|
+
this.refocus();
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
disconnectedCallback() {
|
|
656
|
+
super.disconnectedCallback();
|
|
657
|
+
if (this.viewportRef.value) {
|
|
658
|
+
this.observer.unobserve(this.viewportRef.value);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
createRenderRoot() {
|
|
662
|
+
return this;
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
_ts_decorate([
|
|
666
|
+
property({
|
|
667
|
+
type: String
|
|
668
|
+
})
|
|
669
|
+
], DxGrid.prototype, "gridId", void 0);
|
|
670
|
+
_ts_decorate([
|
|
671
|
+
property({
|
|
672
|
+
type: Object
|
|
673
|
+
})
|
|
674
|
+
], DxGrid.prototype, "rowDefault", void 0);
|
|
675
|
+
_ts_decorate([
|
|
676
|
+
property({
|
|
677
|
+
type: Object
|
|
678
|
+
})
|
|
679
|
+
], DxGrid.prototype, "columnDefault", void 0);
|
|
680
|
+
_ts_decorate([
|
|
681
|
+
property({
|
|
682
|
+
type: Object
|
|
683
|
+
})
|
|
684
|
+
], DxGrid.prototype, "rows", void 0);
|
|
685
|
+
_ts_decorate([
|
|
686
|
+
property({
|
|
687
|
+
type: Object
|
|
688
|
+
})
|
|
689
|
+
], DxGrid.prototype, "columns", void 0);
|
|
690
|
+
_ts_decorate([
|
|
691
|
+
property({
|
|
692
|
+
type: Object
|
|
693
|
+
})
|
|
694
|
+
], DxGrid.prototype, "initialCells", void 0);
|
|
695
|
+
_ts_decorate([
|
|
696
|
+
property({
|
|
697
|
+
type: String
|
|
698
|
+
})
|
|
699
|
+
], DxGrid.prototype, "mode", void 0);
|
|
700
|
+
_ts_decorate([
|
|
701
|
+
state()
|
|
702
|
+
], DxGrid.prototype, "cells", void 0);
|
|
703
|
+
_ts_decorate([
|
|
704
|
+
state()
|
|
705
|
+
], DxGrid.prototype, "posInline", void 0);
|
|
706
|
+
_ts_decorate([
|
|
707
|
+
state()
|
|
708
|
+
], DxGrid.prototype, "posBlock", void 0);
|
|
709
|
+
_ts_decorate([
|
|
710
|
+
state()
|
|
711
|
+
], DxGrid.prototype, "sizeInline", void 0);
|
|
712
|
+
_ts_decorate([
|
|
713
|
+
state()
|
|
714
|
+
], DxGrid.prototype, "sizeBlock", void 0);
|
|
715
|
+
_ts_decorate([
|
|
716
|
+
state()
|
|
717
|
+
], DxGrid.prototype, "overscanInline", void 0);
|
|
718
|
+
_ts_decorate([
|
|
719
|
+
state()
|
|
720
|
+
], DxGrid.prototype, "overscanBlock", void 0);
|
|
721
|
+
_ts_decorate([
|
|
722
|
+
state()
|
|
723
|
+
], DxGrid.prototype, "binInlineMin", void 0);
|
|
724
|
+
_ts_decorate([
|
|
725
|
+
state()
|
|
726
|
+
], DxGrid.prototype, "binInlineMax", void 0);
|
|
727
|
+
_ts_decorate([
|
|
728
|
+
state()
|
|
729
|
+
], DxGrid.prototype, "binBlockMin", void 0);
|
|
730
|
+
_ts_decorate([
|
|
731
|
+
state()
|
|
732
|
+
], DxGrid.prototype, "binBlockMax", void 0);
|
|
733
|
+
_ts_decorate([
|
|
734
|
+
state()
|
|
735
|
+
], DxGrid.prototype, "visColMin", void 0);
|
|
736
|
+
_ts_decorate([
|
|
737
|
+
state()
|
|
738
|
+
], DxGrid.prototype, "visColMax", void 0);
|
|
739
|
+
_ts_decorate([
|
|
740
|
+
state()
|
|
741
|
+
], DxGrid.prototype, "visRowMin", void 0);
|
|
742
|
+
_ts_decorate([
|
|
743
|
+
state()
|
|
744
|
+
], DxGrid.prototype, "visRowMax", void 0);
|
|
745
|
+
_ts_decorate([
|
|
746
|
+
state()
|
|
747
|
+
], DxGrid.prototype, "templateColumns", void 0);
|
|
748
|
+
_ts_decorate([
|
|
749
|
+
state()
|
|
750
|
+
], DxGrid.prototype, "templateRows", void 0);
|
|
751
|
+
_ts_decorate([
|
|
752
|
+
state()
|
|
753
|
+
], DxGrid.prototype, "pointer", void 0);
|
|
754
|
+
_ts_decorate([
|
|
755
|
+
state()
|
|
756
|
+
], DxGrid.prototype, "colSizes", void 0);
|
|
757
|
+
_ts_decorate([
|
|
758
|
+
state()
|
|
759
|
+
], DxGrid.prototype, "rowSizes", void 0);
|
|
760
|
+
_ts_decorate([
|
|
761
|
+
state()
|
|
762
|
+
], DxGrid.prototype, "focusActive", void 0);
|
|
763
|
+
_ts_decorate([
|
|
764
|
+
state()
|
|
765
|
+
], DxGrid.prototype, "focusedCell", void 0);
|
|
766
|
+
_ts_decorate([
|
|
767
|
+
state()
|
|
768
|
+
], DxGrid.prototype, "selectionStart", void 0);
|
|
769
|
+
_ts_decorate([
|
|
770
|
+
state()
|
|
771
|
+
], DxGrid.prototype, "selectionEnd", void 0);
|
|
772
|
+
_ts_decorate([
|
|
773
|
+
state()
|
|
774
|
+
], DxGrid.prototype, "observer", void 0);
|
|
775
|
+
_ts_decorate([
|
|
776
|
+
eventOptions({
|
|
777
|
+
capture: true
|
|
778
|
+
})
|
|
779
|
+
], DxGrid.prototype, "handleFocus", null);
|
|
780
|
+
_ts_decorate([
|
|
781
|
+
eventOptions({
|
|
782
|
+
capture: true
|
|
783
|
+
})
|
|
784
|
+
], DxGrid.prototype, "handleBlur", null);
|
|
785
|
+
DxGrid = _ts_decorate([
|
|
786
|
+
customElement("dx-grid")
|
|
787
|
+
], DxGrid);
|
|
788
|
+
export {
|
|
789
|
+
DxAxisResize,
|
|
790
|
+
DxEditRequest,
|
|
791
|
+
DxGrid,
|
|
792
|
+
DxGridCellsSelect
|
|
793
|
+
};
|
|
794
|
+
//# sourceMappingURL=index.mjs.map
|