@dxos/lit-grid 0.6.12-main.78ddbdf → 0.6.12-main.7907542
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 +609 -248
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/dx-grid-axis-resize-handle.d.ts +2 -1
- package/dist/types/src/dx-grid-axis-resize-handle.d.ts.map +1 -1
- package/dist/types/src/dx-grid.d.ts +40 -7
- package/dist/types/src/dx-grid.d.ts.map +1 -1
- package/dist/types/src/dx-grid.lit-stories.d.ts +23 -1
- package/dist/types/src/dx-grid.lit-stories.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +45 -13
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +4 -2
- package/dist/types/src/util.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/dx-grid-axis-resize-handle.ts +6 -2
- package/src/dx-grid.lit-stories.ts +140 -16
- package/src/dx-grid.pcss +37 -62
- package/src/dx-grid.ts +650 -279
- package/src/types.ts +55 -11
- package/src/util.ts +18 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// packages/ui/lit-grid/src/dx-grid.ts
|
|
2
2
|
import { LitElement as LitElement2, html as html2, nothing } from "lit";
|
|
3
|
-
import { customElement as customElement2, state, property as property2
|
|
3
|
+
import { customElement as customElement2, state, property as property2 } from "lit/decorators.js";
|
|
4
4
|
import { ref as ref2, createRef } from "lit/directives/ref.js";
|
|
5
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
5
6
|
|
|
6
7
|
// packages/ui/lit-grid/src/dx-grid-axis-resize-handle.ts
|
|
7
8
|
import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
@@ -14,12 +15,19 @@ import { ref } from "lit/directives/ref.js";
|
|
|
14
15
|
// packages/ui/lit-grid/src/util.ts
|
|
15
16
|
var separator = ",";
|
|
16
17
|
var toCellIndex = (cellCoords) => `${cellCoords.col}${separator}${cellCoords.row}`;
|
|
18
|
+
var colToA1Notation = (col) => {
|
|
19
|
+
return (col >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(col / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + col % 26);
|
|
20
|
+
};
|
|
21
|
+
var rowToA1Notation = (row) => {
|
|
22
|
+
return `${row + 1}`;
|
|
23
|
+
};
|
|
17
24
|
|
|
18
25
|
// packages/ui/lit-grid/src/types.ts
|
|
19
26
|
var DxAxisResize = class extends Event {
|
|
20
27
|
constructor(props) {
|
|
21
28
|
super("dx-axis-resize");
|
|
22
29
|
this.axis = props.axis;
|
|
30
|
+
this.plane = props.plane;
|
|
23
31
|
this.index = props.index;
|
|
24
32
|
this.size = props.size;
|
|
25
33
|
}
|
|
@@ -31,6 +39,7 @@ var DxAxisResizeInternal = class extends Event {
|
|
|
31
39
|
bubbles: true
|
|
32
40
|
});
|
|
33
41
|
this.axis = props.axis;
|
|
42
|
+
this.plane = props.plane;
|
|
34
43
|
this.index = props.index;
|
|
35
44
|
this.size = props.size;
|
|
36
45
|
this.delta = props.delta;
|
|
@@ -68,13 +77,14 @@ var DxGridAxisResizeHandle = class extends LitElement {
|
|
|
68
77
|
constructor() {
|
|
69
78
|
super(...arguments);
|
|
70
79
|
this.axis = "row";
|
|
80
|
+
this.plane = "grid";
|
|
71
81
|
this.index = "-1";
|
|
72
82
|
this.size = 128;
|
|
73
83
|
this.dragStartSize = 128;
|
|
74
84
|
this.cleanup = null;
|
|
75
85
|
}
|
|
76
86
|
render() {
|
|
77
|
-
return html`<button class="dx-grid__resize-handle" ${ref(this.mount)}>
|
|
87
|
+
return html`<button class="dx-grid__resize-handle" data-dx-grid-axis=${this.axis} ${ref(this.mount)}>
|
|
78
88
|
<span class="sr-only">Resize</span>
|
|
79
89
|
</button>`;
|
|
80
90
|
}
|
|
@@ -82,6 +92,7 @@ var DxGridAxisResizeHandle = class extends LitElement {
|
|
|
82
92
|
const client = this.axis === "row" ? "clientY" : "clientX";
|
|
83
93
|
const event = new DxAxisResizeInternal({
|
|
84
94
|
axis: this.axis,
|
|
95
|
+
plane: this.plane,
|
|
85
96
|
size: this.dragStartSize,
|
|
86
97
|
index: this.index,
|
|
87
98
|
delta: location.current.input[client] - location.initial.input[client],
|
|
@@ -126,6 +137,11 @@ _ts_decorate([
|
|
|
126
137
|
type: String
|
|
127
138
|
})
|
|
128
139
|
], DxGridAxisResizeHandle.prototype, "axis", void 0);
|
|
140
|
+
_ts_decorate([
|
|
141
|
+
property({
|
|
142
|
+
type: String
|
|
143
|
+
})
|
|
144
|
+
], DxGridAxisResizeHandle.prototype, "plane", void 0);
|
|
129
145
|
_ts_decorate([
|
|
130
146
|
property({
|
|
131
147
|
type: String
|
|
@@ -148,18 +164,39 @@ function _ts_decorate2(decorators, target, key, desc) {
|
|
|
148
164
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
149
165
|
}
|
|
150
166
|
var gap = 1;
|
|
151
|
-
var resizeTolerance =
|
|
167
|
+
var resizeTolerance = 1;
|
|
168
|
+
var selectTolerance = 4;
|
|
152
169
|
var overscanCol = 1;
|
|
153
170
|
var overscanRow = 1;
|
|
154
171
|
var sizeColMin = 32;
|
|
155
172
|
var sizeColMax = 1024;
|
|
156
173
|
var sizeRowMin = 16;
|
|
157
174
|
var sizeRowMax = 1024;
|
|
158
|
-
var
|
|
159
|
-
|
|
175
|
+
var shouldSelect = (pointer, { pageX, pageY }) => {
|
|
176
|
+
if (pointer?.state === "maybeSelecting") {
|
|
177
|
+
return Math.hypot(Math.abs(pointer.pageX - pageX), Math.abs(pointer.pageY - pageY)) >= selectTolerance;
|
|
178
|
+
} else {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
160
181
|
};
|
|
161
|
-
var
|
|
162
|
-
|
|
182
|
+
var selectionProps = (selectionStart, selectionEnd) => {
|
|
183
|
+
const colMin = Math.min(selectionStart.col, selectionEnd.col);
|
|
184
|
+
const colMax = Math.max(selectionStart.col, selectionEnd.col);
|
|
185
|
+
const rowMin = Math.min(selectionStart.row, selectionEnd.row);
|
|
186
|
+
const rowMax = Math.max(selectionStart.row, selectionEnd.row);
|
|
187
|
+
const plane = selectionStart.plane;
|
|
188
|
+
const visible = colMin !== colMax || rowMin !== rowMax;
|
|
189
|
+
return {
|
|
190
|
+
colMin,
|
|
191
|
+
colMax,
|
|
192
|
+
rowMin,
|
|
193
|
+
rowMax,
|
|
194
|
+
plane,
|
|
195
|
+
visible
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
var cellSelected = (col, row, plane, selection) => {
|
|
199
|
+
return plane === selection.plane && col >= selection.colMin && col <= selection.colMax && row >= selection.rowMin && row <= selection.rowMax;
|
|
163
200
|
};
|
|
164
201
|
var closestAction = (target) => {
|
|
165
202
|
const actionEl = target?.closest("[data-dx-grid-action]") ?? null;
|
|
@@ -179,7 +216,9 @@ var closestCell = (target, actionEl) => {
|
|
|
179
216
|
if (cellElement) {
|
|
180
217
|
const col = parseInt(cellElement.getAttribute("aria-colindex") ?? "never");
|
|
181
218
|
const row = parseInt(cellElement.getAttribute("aria-rowindex") ?? "never");
|
|
219
|
+
const plane = cellElement.closest("[data-dx-grid-plane]")?.getAttribute("data-dx-grid-plane") ?? "grid";
|
|
182
220
|
return {
|
|
221
|
+
plane,
|
|
183
222
|
col,
|
|
184
223
|
row
|
|
185
224
|
};
|
|
@@ -187,30 +226,92 @@ var closestCell = (target, actionEl) => {
|
|
|
187
226
|
return null;
|
|
188
227
|
}
|
|
189
228
|
};
|
|
190
|
-
var
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
229
|
+
var resolveRowPlane = (plane) => {
|
|
230
|
+
switch (plane) {
|
|
231
|
+
case "fixedStartStart":
|
|
232
|
+
case "fixedStartEnd":
|
|
233
|
+
case "frozenRowsStart":
|
|
234
|
+
return "frozenRowsStart";
|
|
235
|
+
case "fixedEndStart":
|
|
236
|
+
case "fixedEndEnd":
|
|
237
|
+
case "frozenRowsEnd":
|
|
238
|
+
return "frozenRowsEnd";
|
|
239
|
+
default:
|
|
240
|
+
return "grid";
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
var resolveColPlane = (plane) => {
|
|
244
|
+
switch (plane) {
|
|
245
|
+
case "fixedStartStart":
|
|
246
|
+
case "fixedEndStart":
|
|
247
|
+
case "frozenColsStart":
|
|
248
|
+
return "frozenColsStart";
|
|
249
|
+
case "fixedStartEnd":
|
|
250
|
+
case "fixedEndEnd":
|
|
251
|
+
case "frozenColsEnd":
|
|
252
|
+
return "frozenColsEnd";
|
|
253
|
+
default:
|
|
254
|
+
return "grid";
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
var resolveResizePlane = (resizeAxis, cellPlane) => {
|
|
258
|
+
switch (cellPlane) {
|
|
259
|
+
case "fixedStartStart":
|
|
260
|
+
return resizeAxis === "col" ? "frozenColsStart" : "frozenRowsStart";
|
|
261
|
+
case "fixedStartEnd":
|
|
262
|
+
return resizeAxis === "col" ? "frozenColsEnd" : "frozenRowsStart";
|
|
263
|
+
case "fixedEndStart":
|
|
264
|
+
return resizeAxis === "col" ? "frozenColsStart" : "frozenRowsEnd";
|
|
265
|
+
case "fixedEndEnd":
|
|
266
|
+
return resizeAxis === "col" ? "frozenColsEnd" : "frozenRowsEnd";
|
|
267
|
+
case "frozenColsStart":
|
|
268
|
+
case "frozenColsEnd":
|
|
269
|
+
return resizeAxis === "col" ? cellPlane : "grid";
|
|
270
|
+
case "frozenRowsStart":
|
|
271
|
+
case "frozenRowsEnd":
|
|
272
|
+
return resizeAxis === "row" ? cellPlane : "grid";
|
|
273
|
+
default:
|
|
274
|
+
return cellPlane;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
var isSameCell = (a, b) => a && b && a.plane === b.plane && Number.isFinite(a.col) && Number.isFinite(a.row) && a.col === b.col && a.row === b.row;
|
|
278
|
+
var defaultRowSize = 32;
|
|
279
|
+
var defaultColSize = 180;
|
|
194
280
|
var DxGrid = class extends LitElement2 {
|
|
195
281
|
constructor() {
|
|
196
282
|
super();
|
|
197
283
|
this.gridId = "default-grid-id";
|
|
198
284
|
this.rowDefault = {
|
|
199
|
-
|
|
285
|
+
grid: {
|
|
286
|
+
size: defaultRowSize
|
|
287
|
+
}
|
|
200
288
|
};
|
|
201
289
|
this.columnDefault = {
|
|
202
|
-
|
|
290
|
+
grid: {
|
|
291
|
+
size: defaultColSize
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
this.rows = {
|
|
295
|
+
grid: {}
|
|
296
|
+
};
|
|
297
|
+
this.columns = {
|
|
298
|
+
grid: {}
|
|
299
|
+
};
|
|
300
|
+
this.initialCells = {
|
|
301
|
+
grid: {}
|
|
203
302
|
};
|
|
204
|
-
this.rows = {};
|
|
205
|
-
this.columns = {};
|
|
206
|
-
this.initialCells = {};
|
|
207
303
|
this.mode = "browse";
|
|
304
|
+
this.limitColumns = Infinity;
|
|
305
|
+
this.limitRows = Infinity;
|
|
306
|
+
this.frozen = {};
|
|
208
307
|
/**
|
|
209
308
|
* When this function is defined, it is used first to try to get a value for a cell, and otherwise will fall back
|
|
210
309
|
* to `cells`.
|
|
211
310
|
*/
|
|
212
311
|
this.getCells = null;
|
|
213
|
-
this.cells = {
|
|
312
|
+
this.cells = {
|
|
313
|
+
grid: {}
|
|
314
|
+
};
|
|
214
315
|
//
|
|
215
316
|
// `pos`, short for ‘position’, is the position in pixels of the viewport from the origin.
|
|
216
317
|
//
|
|
@@ -230,9 +331,9 @@ var DxGrid = class extends LitElement2 {
|
|
|
230
331
|
// `bin`, not short for anything, is the range in pixels within which virtualization does not need to reassess.
|
|
231
332
|
//
|
|
232
333
|
this.binInlineMin = 0;
|
|
233
|
-
this.binInlineMax =
|
|
334
|
+
this.binInlineMax = defaultColSize;
|
|
234
335
|
this.binBlockMin = 0;
|
|
235
|
-
this.binBlockMax =
|
|
336
|
+
this.binBlockMax = defaultRowSize;
|
|
236
337
|
//
|
|
237
338
|
// `vis`, short for ‘visible’, is the range in numeric index of the columns or rows which should be rendered within
|
|
238
339
|
// the viewport. These start with naïve values that are updated before first contentful render.
|
|
@@ -244,48 +345,57 @@ var DxGrid = class extends LitElement2 {
|
|
|
244
345
|
//
|
|
245
346
|
// `template` is the rendered value of `grid-{axis}-template`.
|
|
246
347
|
//
|
|
247
|
-
this.
|
|
248
|
-
this.
|
|
348
|
+
this.templateGridColumns = "0";
|
|
349
|
+
this.templatefrozenColsStart = "";
|
|
350
|
+
this.templatefrozenColsEnd = "";
|
|
351
|
+
this.templateGridRows = "0";
|
|
352
|
+
this.templatefrozenRowsStart = "";
|
|
353
|
+
this.templatefrozenRowsEnd = "";
|
|
249
354
|
//
|
|
250
355
|
// Focus, selection, and resize states
|
|
251
356
|
//
|
|
252
357
|
this.pointer = null;
|
|
253
|
-
this.colSizes = {
|
|
254
|
-
|
|
358
|
+
this.colSizes = {
|
|
359
|
+
grid: {}
|
|
360
|
+
};
|
|
361
|
+
this.rowSizes = {
|
|
362
|
+
grid: {}
|
|
363
|
+
};
|
|
255
364
|
this.focusActive = false;
|
|
256
365
|
this.focusedCell = {
|
|
366
|
+
plane: "grid",
|
|
257
367
|
col: 0,
|
|
258
368
|
row: 0
|
|
259
369
|
};
|
|
260
370
|
this.selectionStart = {
|
|
371
|
+
plane: "grid",
|
|
261
372
|
col: 0,
|
|
262
373
|
row: 0
|
|
263
374
|
};
|
|
264
375
|
this.selectionEnd = {
|
|
376
|
+
plane: "grid",
|
|
265
377
|
col: 0,
|
|
266
378
|
row: 0
|
|
267
379
|
};
|
|
380
|
+
//
|
|
381
|
+
// Limits
|
|
382
|
+
//
|
|
383
|
+
this.intrinsicInlineSize = Infinity;
|
|
384
|
+
this.intrinsicBlockSize = Infinity;
|
|
268
385
|
this.handlePointerDown = (event) => {
|
|
269
386
|
if (event.isPrimary) {
|
|
270
387
|
const { action, actionEl } = closestAction(event.target);
|
|
271
388
|
if (action) {
|
|
272
|
-
if (action
|
|
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") {
|
|
389
|
+
if (action === "cell") {
|
|
283
390
|
const cellCoords = closestCell(event.target, actionEl);
|
|
284
391
|
if (cellCoords) {
|
|
285
392
|
this.pointer = {
|
|
286
|
-
state: "
|
|
393
|
+
state: "maybeSelecting",
|
|
394
|
+
pageX: event.pageX,
|
|
395
|
+
pageY: event.pageY
|
|
287
396
|
};
|
|
288
397
|
this.selectionStart = cellCoords;
|
|
398
|
+
this.selectionEnd = cellCoords;
|
|
289
399
|
}
|
|
290
400
|
if (this.mode === "edit") {
|
|
291
401
|
event.preventDefault();
|
|
@@ -299,23 +409,24 @@ var DxGrid = class extends LitElement2 {
|
|
|
299
409
|
}
|
|
300
410
|
};
|
|
301
411
|
this.handlePointerUp = (event) => {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
this.
|
|
307
|
-
this.
|
|
308
|
-
|
|
309
|
-
end: this.selectionEnd
|
|
310
|
-
}));
|
|
311
|
-
}
|
|
412
|
+
const cell = closestCell(event.target);
|
|
413
|
+
if (cell) {
|
|
414
|
+
this.selectionEnd = cell;
|
|
415
|
+
this.dispatchEvent(new DxGridCellsSelect({
|
|
416
|
+
start: this.selectionStart,
|
|
417
|
+
end: this.selectionEnd
|
|
418
|
+
}));
|
|
312
419
|
}
|
|
313
420
|
this.pointer = null;
|
|
314
421
|
};
|
|
315
422
|
this.handlePointerMove = (event) => {
|
|
316
|
-
if (this.pointer
|
|
423
|
+
if (shouldSelect(this.pointer, event)) {
|
|
424
|
+
this.pointer = {
|
|
425
|
+
state: "selecting"
|
|
426
|
+
};
|
|
427
|
+
} else if (this.pointer?.state === "selecting") {
|
|
317
428
|
const cell = closestCell(event.target);
|
|
318
|
-
if (cell && (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
|
|
429
|
+
if (cell && cell.plane === this.selectionStart.plane && (cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
|
|
319
430
|
this.selectionEnd = cell;
|
|
320
431
|
}
|
|
321
432
|
}
|
|
@@ -332,24 +443,29 @@ var DxGrid = class extends LitElement2 {
|
|
|
332
443
|
this.sizeInline = inlineSize;
|
|
333
444
|
this.sizeBlock = blockSize;
|
|
334
445
|
this.updateVis();
|
|
446
|
+
queueMicrotask(() => this.updatePos());
|
|
335
447
|
}
|
|
336
448
|
});
|
|
337
449
|
this.viewportRef = createRef();
|
|
338
|
-
this.
|
|
339
|
-
if (this.posInline
|
|
340
|
-
|
|
341
|
-
|
|
450
|
+
this.maybeUpdateVisInline = () => {
|
|
451
|
+
if (this.posInline < this.binInlineMin || this.posInline >= this.binInlineMax) {
|
|
452
|
+
this.updateVisInline();
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
this.maybeUpdateVisBlock = () => {
|
|
456
|
+
if (this.posBlock < this.binBlockMin || this.posBlock >= this.binBlockMax) {
|
|
457
|
+
this.updateVisBlock();
|
|
342
458
|
}
|
|
343
459
|
};
|
|
344
460
|
this.handleWheel = ({ deltaX, deltaY }) => {
|
|
345
461
|
if (this.mode === "browse") {
|
|
346
|
-
this.posInline
|
|
347
|
-
this.posBlock = Math.max(0, this.posBlock + deltaY);
|
|
348
|
-
this.maybeUpdateVis();
|
|
462
|
+
this.updatePos(this.posInline + deltaX, this.posBlock + deltaY);
|
|
349
463
|
}
|
|
350
464
|
};
|
|
351
465
|
this.addEventListener("dx-axis-resize-internal", this.handleAxisResizeInternal);
|
|
352
|
-
this.addEventListener("wheel", this.handleWheel
|
|
466
|
+
this.addEventListener("wheel", this.handleWheel, {
|
|
467
|
+
passive: true
|
|
468
|
+
});
|
|
353
469
|
this.addEventListener("pointerdown", this.handlePointerDown);
|
|
354
470
|
this.addEventListener("pointermove", this.handlePointerMove);
|
|
355
471
|
this.addEventListener("pointerup", this.handlePointerUp);
|
|
@@ -379,7 +495,7 @@ var DxGrid = class extends LitElement2 {
|
|
|
379
495
|
case "ArrowDown":
|
|
380
496
|
this.focusedCell = {
|
|
381
497
|
...this.focusedCell,
|
|
382
|
-
row: this.focusedCell.row + 1
|
|
498
|
+
row: Math.min(this.limitRows - 1, this.focusedCell.row + 1)
|
|
383
499
|
};
|
|
384
500
|
break;
|
|
385
501
|
case "ArrowUp":
|
|
@@ -391,7 +507,7 @@ var DxGrid = class extends LitElement2 {
|
|
|
391
507
|
case "ArrowRight":
|
|
392
508
|
this.focusedCell = {
|
|
393
509
|
...this.focusedCell,
|
|
394
|
-
col: this.focusedCell.col + 1
|
|
510
|
+
col: Math.min(this.limitColumns - 1, this.focusedCell.col + 1)
|
|
395
511
|
};
|
|
396
512
|
break;
|
|
397
513
|
case "ArrowLeft":
|
|
@@ -425,21 +541,26 @@ var DxGrid = class extends LitElement2 {
|
|
|
425
541
|
//
|
|
426
542
|
// Accessors
|
|
427
543
|
//
|
|
428
|
-
colSize(c) {
|
|
429
|
-
|
|
544
|
+
colSize(c, plane) {
|
|
545
|
+
const resolvedPlane = resolveColPlane(plane);
|
|
546
|
+
return this.colSizes?.[resolvedPlane]?.[c] ?? this.columnDefault[resolvedPlane]?.size ?? defaultColSize;
|
|
430
547
|
}
|
|
431
|
-
rowSize(r) {
|
|
432
|
-
|
|
548
|
+
rowSize(r, plane) {
|
|
549
|
+
const resolvedPlane = resolveRowPlane(plane);
|
|
550
|
+
return this.rowSizes?.[resolvedPlane]?.[r] ?? this.rowDefault[resolvedPlane]?.size ?? defaultRowSize;
|
|
433
551
|
}
|
|
434
|
-
cell(c, r) {
|
|
552
|
+
cell(c, r, plane) {
|
|
435
553
|
const index = `${c}${separator}${r}`;
|
|
436
|
-
return this.cells[index] ?? this.initialCells[index];
|
|
554
|
+
return this.cells?.[plane]?.[index] ?? this.initialCells?.[plane]?.[index];
|
|
555
|
+
}
|
|
556
|
+
cellActive(c, r, plane) {
|
|
557
|
+
return this.focusActive && this.focusedCell.plane === plane && this.focusedCell.col === c && this.focusedCell.row === r;
|
|
437
558
|
}
|
|
438
559
|
focusedCellBox() {
|
|
439
560
|
const cellElement = this.focusedCellElement();
|
|
440
561
|
const cellSize = {
|
|
441
|
-
inlineSize: this.colSize(this.focusedCell.col),
|
|
442
|
-
blockSize: this.rowSize(this.focusedCell.row)
|
|
562
|
+
inlineSize: this.colSize(this.focusedCell.col, this.focusedCell.plane),
|
|
563
|
+
blockSize: this.rowSize(this.focusedCell.row, this.focusedCell.plane)
|
|
443
564
|
};
|
|
444
565
|
if (!cellElement) {
|
|
445
566
|
return {
|
|
@@ -459,60 +580,167 @@ var DxGrid = class extends LitElement2 {
|
|
|
459
580
|
...cellSize
|
|
460
581
|
};
|
|
461
582
|
}
|
|
583
|
+
updatePosInline(inline) {
|
|
584
|
+
this.posInline = Math.max(0, Math.min(this.intrinsicInlineSize - this.sizeInline, inline ?? this.posInline));
|
|
585
|
+
this.maybeUpdateVisInline();
|
|
586
|
+
}
|
|
587
|
+
updatePosBlock(block) {
|
|
588
|
+
this.posBlock = Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, block ?? this.posBlock));
|
|
589
|
+
this.maybeUpdateVisBlock();
|
|
590
|
+
}
|
|
591
|
+
updatePos(inline, block) {
|
|
592
|
+
this.updatePosInline(inline);
|
|
593
|
+
this.updatePosBlock(block);
|
|
594
|
+
}
|
|
462
595
|
updateVisInline() {
|
|
463
596
|
let colIndex = 0;
|
|
464
|
-
let pxInline = this.colSize(colIndex);
|
|
597
|
+
let pxInline = this.colSize(colIndex, "grid");
|
|
465
598
|
while (pxInline < this.posInline) {
|
|
466
599
|
colIndex += 1;
|
|
467
|
-
pxInline += this.colSize(colIndex) + gap;
|
|
600
|
+
pxInline += this.colSize(colIndex, "grid") + gap;
|
|
468
601
|
}
|
|
469
602
|
this.visColMin = colIndex - overscanCol;
|
|
470
|
-
this.binInlineMin = pxInline - this.colSize(colIndex) - gap;
|
|
603
|
+
this.binInlineMin = pxInline - this.colSize(colIndex, "grid") - gap;
|
|
471
604
|
this.binInlineMax = pxInline + gap;
|
|
472
605
|
this.overscanInline = [
|
|
473
606
|
...Array(overscanCol)
|
|
474
607
|
].reduce((acc, _, c0) => {
|
|
475
|
-
acc += this.colSize(this.visColMin + c0);
|
|
608
|
+
acc += this.colSize(this.visColMin + c0, "grid");
|
|
476
609
|
return acc;
|
|
477
610
|
}, 0) + gap * (overscanCol - 1);
|
|
478
|
-
while (pxInline < this.binInlineMax + this.sizeInline
|
|
611
|
+
while (pxInline < this.binInlineMax + this.sizeInline - gap * 2) {
|
|
479
612
|
colIndex += 1;
|
|
480
|
-
pxInline += this.colSize(colIndex) + gap;
|
|
613
|
+
pxInline += this.colSize(colIndex, "grid") + gap;
|
|
481
614
|
}
|
|
482
|
-
this.visColMax = colIndex + overscanCol;
|
|
483
|
-
this.
|
|
615
|
+
this.visColMax = Math.min(this.limitColumns, colIndex + overscanCol);
|
|
616
|
+
this.templateGridColumns = [
|
|
484
617
|
...Array(this.visColMax - this.visColMin)
|
|
485
|
-
].map((_, c0) => `${this.colSize(this.visColMin + c0)}px`).join(" ");
|
|
618
|
+
].map((_, c0) => `${this.colSize(this.visColMin + c0, "grid")}px`).join(" ");
|
|
619
|
+
this.templatefrozenColsStart = [
|
|
620
|
+
...Array(this.frozen.frozenColsStart ?? 0)
|
|
621
|
+
].map((_, c0) => `${this.colSize(c0, "frozenColsStart")}px`).join(" ");
|
|
622
|
+
this.templatefrozenColsEnd = [
|
|
623
|
+
...Array(this.frozen.frozenColsEnd ?? 0)
|
|
624
|
+
].map((_, c0) => `${this.colSize(c0, "frozenColsEnd")}px`).join(" ");
|
|
486
625
|
}
|
|
487
626
|
updateVisBlock() {
|
|
488
627
|
let rowIndex = 0;
|
|
489
|
-
let pxBlock = this.rowSize(rowIndex);
|
|
628
|
+
let pxBlock = this.rowSize(rowIndex, "grid");
|
|
490
629
|
while (pxBlock < this.posBlock) {
|
|
491
630
|
rowIndex += 1;
|
|
492
|
-
pxBlock += this.rowSize(rowIndex) + gap;
|
|
631
|
+
pxBlock += this.rowSize(rowIndex, "grid") + gap;
|
|
493
632
|
}
|
|
494
633
|
this.visRowMin = rowIndex - overscanRow;
|
|
495
|
-
this.binBlockMin = pxBlock - this.rowSize(rowIndex) - gap;
|
|
634
|
+
this.binBlockMin = pxBlock - this.rowSize(rowIndex, "grid") - gap;
|
|
496
635
|
this.binBlockMax = pxBlock + gap;
|
|
497
636
|
this.overscanBlock = [
|
|
498
637
|
...Array(overscanRow)
|
|
499
638
|
].reduce((acc, _, r0) => {
|
|
500
|
-
acc += this.rowSize(this.visRowMin + r0);
|
|
639
|
+
acc += this.rowSize(this.visRowMin + r0, "grid");
|
|
501
640
|
return acc;
|
|
502
641
|
}, 0) + gap * (overscanRow - 1);
|
|
503
|
-
while (pxBlock < this.binBlockMax + this.sizeBlock) {
|
|
642
|
+
while (pxBlock < this.binBlockMax + this.sizeBlock - gap * 2) {
|
|
504
643
|
rowIndex += 1;
|
|
505
|
-
pxBlock += this.rowSize(rowIndex) + gap;
|
|
644
|
+
pxBlock += this.rowSize(rowIndex, "grid") + gap;
|
|
506
645
|
}
|
|
507
|
-
this.visRowMax = rowIndex + overscanRow;
|
|
508
|
-
this.
|
|
646
|
+
this.visRowMax = Math.min(this.limitRows, rowIndex + overscanRow);
|
|
647
|
+
this.templateGridRows = [
|
|
509
648
|
...Array(this.visRowMax - this.visRowMin)
|
|
510
|
-
].map((_, r0) => `${this.rowSize(this.visRowMin + r0)}px`).join(" ");
|
|
649
|
+
].map((_, r0) => `${this.rowSize(this.visRowMin + r0, "grid")}px`).join(" ");
|
|
650
|
+
this.templatefrozenRowsStart = [
|
|
651
|
+
...Array(this.frozen.frozenRowsStart ?? 0)
|
|
652
|
+
].map((_, r0) => `${this.rowSize(r0, "frozenRowsStart")}px`).join(" ");
|
|
653
|
+
this.templatefrozenRowsEnd = [
|
|
654
|
+
...Array(this.frozen.frozenRowsEnd ?? 0)
|
|
655
|
+
].map((_, r0) => `${this.rowSize(r0, "frozenRowsEnd")}px`).join(" ");
|
|
511
656
|
}
|
|
512
657
|
updateVis() {
|
|
513
658
|
this.updateVisInline();
|
|
514
659
|
this.updateVisBlock();
|
|
515
660
|
}
|
|
661
|
+
updateCells(includeFixed) {
|
|
662
|
+
this.cells.grid = this.getCells({
|
|
663
|
+
start: {
|
|
664
|
+
col: this.visColMin,
|
|
665
|
+
row: this.visRowMin
|
|
666
|
+
},
|
|
667
|
+
end: {
|
|
668
|
+
col: this.visColMax,
|
|
669
|
+
row: this.visRowMax
|
|
670
|
+
}
|
|
671
|
+
}, "grid");
|
|
672
|
+
Object.entries(this.frozen).filter(([_, limit]) => limit && limit > 0).forEach(([plane, limit]) => {
|
|
673
|
+
this.cells[plane] = this.getCells(plane.startsWith("frozenRows") ? {
|
|
674
|
+
start: {
|
|
675
|
+
col: this.visColMin,
|
|
676
|
+
row: 0
|
|
677
|
+
},
|
|
678
|
+
end: {
|
|
679
|
+
col: this.visColMax,
|
|
680
|
+
row: limit
|
|
681
|
+
}
|
|
682
|
+
} : {
|
|
683
|
+
start: {
|
|
684
|
+
col: 0,
|
|
685
|
+
row: this.visRowMin
|
|
686
|
+
},
|
|
687
|
+
end: {
|
|
688
|
+
col: limit,
|
|
689
|
+
row: this.visRowMax
|
|
690
|
+
}
|
|
691
|
+
}, plane);
|
|
692
|
+
});
|
|
693
|
+
if (includeFixed) {
|
|
694
|
+
if ((this.frozen.frozenColsStart ?? 0) > 0 && (this.frozen.frozenRowsStart ?? 0) > 0) {
|
|
695
|
+
this.cells.fixedStartStart = this.getCells({
|
|
696
|
+
start: {
|
|
697
|
+
col: 0,
|
|
698
|
+
row: 0
|
|
699
|
+
},
|
|
700
|
+
end: {
|
|
701
|
+
col: this.frozen.frozenColsStart,
|
|
702
|
+
row: this.frozen.frozenRowsStart
|
|
703
|
+
}
|
|
704
|
+
}, "fixedStartStart");
|
|
705
|
+
}
|
|
706
|
+
if ((this.frozen.frozenColsEnd ?? 0) > 0 && (this.frozen.frozenRowsStart ?? 0) > 0) {
|
|
707
|
+
this.cells.fixedStartEnd = this.getCells({
|
|
708
|
+
start: {
|
|
709
|
+
col: 0,
|
|
710
|
+
row: 0
|
|
711
|
+
},
|
|
712
|
+
end: {
|
|
713
|
+
col: this.frozen.frozenColsEnd,
|
|
714
|
+
row: this.frozen.frozenRowsStart
|
|
715
|
+
}
|
|
716
|
+
}, "fixedStartEnd");
|
|
717
|
+
}
|
|
718
|
+
if ((this.frozen.frozenColsStart ?? 0) > 0 && (this.frozen.frozenRowsEnd ?? 0) > 0) {
|
|
719
|
+
this.cells.fixedEndStart = this.getCells({
|
|
720
|
+
start: {
|
|
721
|
+
col: 0,
|
|
722
|
+
row: 0
|
|
723
|
+
},
|
|
724
|
+
end: {
|
|
725
|
+
col: this.frozen.frozenColsStart,
|
|
726
|
+
row: this.frozen.frozenRowsEnd
|
|
727
|
+
}
|
|
728
|
+
}, "fixedEndStart");
|
|
729
|
+
}
|
|
730
|
+
if ((this.frozen.frozenColsEnd ?? 0) > 0 && (this.frozen.frozenRowsEnd ?? 0) > 0) {
|
|
731
|
+
this.cells.fixedEndEnd = this.getCells({
|
|
732
|
+
start: {
|
|
733
|
+
col: 0,
|
|
734
|
+
row: 0
|
|
735
|
+
},
|
|
736
|
+
end: {
|
|
737
|
+
col: this.frozen.frozenColsEnd,
|
|
738
|
+
row: this.frozen.frozenRowsEnd
|
|
739
|
+
}
|
|
740
|
+
}, "fixedEndEnd");
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
}
|
|
516
744
|
// Focus handlers
|
|
517
745
|
handleFocus(event) {
|
|
518
746
|
const cellCoords = closestCell(event.target);
|
|
@@ -527,7 +755,43 @@ var DxGrid = class extends LitElement2 {
|
|
|
527
755
|
}
|
|
528
756
|
}
|
|
529
757
|
focusedCellElement() {
|
|
530
|
-
return this.viewportRef.value?.querySelector(`[aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`);
|
|
758
|
+
return this.viewportRef.value?.querySelector(`[data-dx-grid-plane=${this.focusedCell.plane}] > [aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`);
|
|
759
|
+
}
|
|
760
|
+
//
|
|
761
|
+
// `outOfVis` returns by how many rows/cols the focused cell is outside of the `vis` range for an axis, inset by a
|
|
762
|
+
// `delta`, otherwise zero if it is within that range.
|
|
763
|
+
//
|
|
764
|
+
focusedCellRowOutOfVis(minDelta = 0, maxDelta = minDelta) {
|
|
765
|
+
return this.focusedCell.row <= this.visRowMin + minDelta ? this.focusedCell.row - (this.visRowMin + minDelta) : this.focusedCell.row >= this.visRowMax - maxDelta ? -(this.focusedCell.row - this.visRowMax - maxDelta) : 0;
|
|
766
|
+
}
|
|
767
|
+
focusedCellColOutOfVis(minDelta = 0, maxDelta = minDelta) {
|
|
768
|
+
return this.focusedCell.col <= this.visColMin + minDelta ? this.focusedCell.col - (this.visColMin + minDelta) : this.focusedCell.col >= this.visColMax - maxDelta ? -(this.focusedCell.col - this.visColMax - maxDelta) : 0;
|
|
769
|
+
}
|
|
770
|
+
focusedCellOutOfVis(colDelta = 0, rowDelta = colDelta) {
|
|
771
|
+
switch (this.focusedCell.plane) {
|
|
772
|
+
case "grid":
|
|
773
|
+
return {
|
|
774
|
+
row: this.focusedCellRowOutOfVis(rowDelta),
|
|
775
|
+
col: this.focusedCellColOutOfVis(colDelta)
|
|
776
|
+
};
|
|
777
|
+
case "frozenRowsStart":
|
|
778
|
+
case "frozenRowsEnd":
|
|
779
|
+
return {
|
|
780
|
+
col: this.focusedCellColOutOfVis(colDelta),
|
|
781
|
+
row: 0
|
|
782
|
+
};
|
|
783
|
+
case "frozenColsStart":
|
|
784
|
+
case "frozenColsEnd":
|
|
785
|
+
return {
|
|
786
|
+
col: 0,
|
|
787
|
+
row: this.focusedCellRowOutOfVis(rowDelta)
|
|
788
|
+
};
|
|
789
|
+
default:
|
|
790
|
+
return {
|
|
791
|
+
col: 0,
|
|
792
|
+
row: 0
|
|
793
|
+
};
|
|
794
|
+
}
|
|
531
795
|
}
|
|
532
796
|
/**
|
|
533
797
|
* Moves focus to the cell with actual focus, otherwise moves focus to the viewport.
|
|
@@ -546,46 +810,56 @@ var DxGrid = class extends LitElement2 {
|
|
|
546
810
|
col: this.focusedCell.col + delta
|
|
547
811
|
};
|
|
548
812
|
}
|
|
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({
|
|
550
|
-
preventScroll: true
|
|
551
|
-
});
|
|
552
813
|
if (increment) {
|
|
553
814
|
this.snapPosToFocusedCell();
|
|
554
815
|
}
|
|
816
|
+
queueMicrotask(() => {
|
|
817
|
+
const outOfVis = this.focusedCellOutOfVis(overscanCol, overscanRow);
|
|
818
|
+
(outOfVis.col !== 0 || outOfVis.row !== 0 ? this.viewportRef.value : this.focusedCellElement())?.focus({
|
|
819
|
+
preventScroll: true
|
|
820
|
+
});
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
findPosInlineFromVisColMin(deltaCols) {
|
|
824
|
+
return [
|
|
825
|
+
...Array(deltaCols)
|
|
826
|
+
].reduce((acc, _, c0) => acc - this.colSize(this.visColMin - c0, "grid") - gap, this.binInlineMin + gap);
|
|
827
|
+
}
|
|
828
|
+
findPosBlockFromVisRowMin(deltaRows) {
|
|
829
|
+
return [
|
|
830
|
+
...Array(deltaRows)
|
|
831
|
+
].reduce((acc, _, r0) => acc - this.rowSize(this.visRowMin - r0, "grid") - gap, this.binBlockMin + gap);
|
|
555
832
|
}
|
|
556
833
|
/**
|
|
557
834
|
* Updates `pos` so that a cell in focus is fully within the viewport
|
|
558
835
|
*/
|
|
559
836
|
snapPosToFocusedCell() {
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
this.posBlock = Math.max(0, this.binBlockMin + sizeSumRow + gap * 2 - this.sizeBlock);
|
|
587
|
-
this.updateVisBlock();
|
|
588
|
-
}
|
|
837
|
+
const outOfVis = this.focusedCellOutOfVis(overscanCol, overscanRow);
|
|
838
|
+
if (outOfVis.col < 0) {
|
|
839
|
+
this.posInline = this.findPosInlineFromVisColMin(-outOfVis.col);
|
|
840
|
+
this.updateVisInline();
|
|
841
|
+
} else if (outOfVis.col > 0) {
|
|
842
|
+
const sizeSumCol = [
|
|
843
|
+
...Array(this.focusedCell.col - this.visColMin)
|
|
844
|
+
].reduce((acc, _, c0) => {
|
|
845
|
+
acc += this.colSize(this.visColMin + overscanCol + c0, "grid") + gap;
|
|
846
|
+
return acc;
|
|
847
|
+
}, 0);
|
|
848
|
+
this.posInline = Math.max(0, Math.min(this.intrinsicInlineSize - this.sizeInline, this.binInlineMin + sizeSumCol - this.sizeInline));
|
|
849
|
+
this.updateVisInline();
|
|
850
|
+
}
|
|
851
|
+
if (outOfVis.row < 0) {
|
|
852
|
+
this.posBlock = this.findPosBlockFromVisRowMin(-outOfVis.row);
|
|
853
|
+
this.updateVisBlock();
|
|
854
|
+
} else if (outOfVis.row > 0) {
|
|
855
|
+
const sizeSumRow = [
|
|
856
|
+
...Array(this.focusedCell.row - this.visRowMin)
|
|
857
|
+
].reduce((acc, _, r0) => {
|
|
858
|
+
acc += this.rowSize(this.visRowMin + overscanRow + r0, "grid") + gap;
|
|
859
|
+
return acc;
|
|
860
|
+
}, 0);
|
|
861
|
+
this.posBlock = Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, this.binBlockMin + sizeSumRow - this.sizeBlock));
|
|
862
|
+
this.updateVisBlock();
|
|
589
863
|
}
|
|
590
864
|
}
|
|
591
865
|
//
|
|
@@ -596,118 +870,178 @@ var DxGrid = class extends LitElement2 {
|
|
|
596
870
|
}
|
|
597
871
|
set scrollLeft(nextValue) {
|
|
598
872
|
this.posInline = nextValue;
|
|
599
|
-
this.
|
|
873
|
+
this.maybeUpdateVisInline();
|
|
600
874
|
}
|
|
601
875
|
get scrollTop() {
|
|
602
876
|
return this.posBlock;
|
|
603
877
|
}
|
|
604
878
|
set scrollTop(nextValue) {
|
|
605
879
|
this.posBlock = nextValue;
|
|
606
|
-
this.
|
|
880
|
+
this.maybeUpdateVisBlock();
|
|
607
881
|
}
|
|
608
882
|
//
|
|
609
883
|
// Resize handlers
|
|
610
884
|
//
|
|
885
|
+
axisResizeable(plane, axis, index) {
|
|
886
|
+
return axis === "col" ? !!(this.columns[plane]?.[index]?.resizeable ?? this.columnDefault[plane]?.resizeable) : !!(this.rows[plane]?.[index]?.resizeable ?? this.rowDefault[plane]?.resizeable);
|
|
887
|
+
}
|
|
611
888
|
handleAxisResizeInternal(event) {
|
|
612
889
|
event.stopPropagation();
|
|
613
|
-
const { axis, delta, size, index,
|
|
890
|
+
const { plane, axis, delta, size, index, state: state2 } = event;
|
|
614
891
|
if (axis === "col") {
|
|
615
892
|
const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, size + delta));
|
|
616
893
|
this.colSizes = {
|
|
617
894
|
...this.colSizes,
|
|
618
|
-
[
|
|
895
|
+
[plane]: {
|
|
896
|
+
...this.colSizes[plane],
|
|
897
|
+
[index]: nextSize
|
|
898
|
+
}
|
|
619
899
|
};
|
|
620
900
|
this.updateVisInline();
|
|
901
|
+
this.updateIntrinsicInlineSize();
|
|
621
902
|
} else {
|
|
622
903
|
const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, size + delta));
|
|
623
904
|
this.rowSizes = {
|
|
624
|
-
...this.
|
|
625
|
-
[
|
|
905
|
+
...this.colSizes,
|
|
906
|
+
[plane]: {
|
|
907
|
+
...this.rowSizes[plane],
|
|
908
|
+
[index]: nextSize
|
|
909
|
+
}
|
|
626
910
|
};
|
|
627
911
|
this.updateVisBlock();
|
|
912
|
+
this.updateIntrinsicBlockSize();
|
|
628
913
|
}
|
|
629
|
-
if (
|
|
914
|
+
if (state2 === "dropped") {
|
|
630
915
|
this.dispatchEvent(new DxAxisResize({
|
|
916
|
+
plane,
|
|
631
917
|
axis,
|
|
632
918
|
index,
|
|
633
|
-
size: this[axis
|
|
919
|
+
size: this[`${axis}Size`](index, plane)
|
|
634
920
|
}));
|
|
635
921
|
}
|
|
636
922
|
}
|
|
637
923
|
//
|
|
638
924
|
// Render and other lifecycle methods
|
|
639
925
|
//
|
|
926
|
+
renderFixed(plane, selection) {
|
|
927
|
+
const colPlane = resolveColPlane(plane);
|
|
928
|
+
const rowPlane = resolveRowPlane(plane);
|
|
929
|
+
const cols = this.frozen[colPlane];
|
|
930
|
+
const rows = this.frozen[rowPlane];
|
|
931
|
+
return (cols ?? 0) > 0 && (rows ?? 0) > 0 ? html2`<div
|
|
932
|
+
role="none"
|
|
933
|
+
data-dx-grid-plane=${plane}
|
|
934
|
+
class="dx-grid__plane--fixed"
|
|
935
|
+
style=${styleMap({
|
|
936
|
+
"grid-template-columns": this[`template${colPlane}`],
|
|
937
|
+
"grid-template-rows": this[`template${rowPlane}`]
|
|
938
|
+
})}
|
|
939
|
+
>
|
|
940
|
+
${[
|
|
941
|
+
...Array(cols)
|
|
942
|
+
].map((_, c) => {
|
|
943
|
+
return [
|
|
944
|
+
...Array(rows)
|
|
945
|
+
].map((_2, r) => {
|
|
946
|
+
return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection));
|
|
947
|
+
});
|
|
948
|
+
})}
|
|
949
|
+
</div>` : null;
|
|
950
|
+
}
|
|
951
|
+
renderFrozenRows(plane, visibleCols, offsetInline, selection) {
|
|
952
|
+
const rowPlane = resolveRowPlane(plane);
|
|
953
|
+
const rows = this.frozen[rowPlane];
|
|
954
|
+
return (rows ?? 0) > 0 ? html2`<div role="none" class="dx-grid__plane--frozen-row">
|
|
955
|
+
<div
|
|
956
|
+
role="none"
|
|
957
|
+
data-dx-grid-plane=${plane}
|
|
958
|
+
class="dx-grid__plane--frozen-row__content"
|
|
959
|
+
style="transform:translate3d(${offsetInline}px,0,0);grid-template-columns:${this.templateGridColumns};grid-template-rows:${this[`template${rowPlane}`]}"
|
|
960
|
+
>
|
|
961
|
+
${[
|
|
962
|
+
...Array(visibleCols)
|
|
963
|
+
].map((_, c0) => {
|
|
964
|
+
return [
|
|
965
|
+
...Array(rows)
|
|
966
|
+
].map((_2, r) => {
|
|
967
|
+
const c = this.visColMin + c0;
|
|
968
|
+
return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection), c0, r);
|
|
969
|
+
});
|
|
970
|
+
})}
|
|
971
|
+
</div>
|
|
972
|
+
</div>` : null;
|
|
973
|
+
}
|
|
974
|
+
renderFrozenColumns(plane, visibleRows, offsetBlock, selection) {
|
|
975
|
+
const colPlane = resolveColPlane(plane);
|
|
976
|
+
const cols = this.frozen[colPlane];
|
|
977
|
+
return (cols ?? 0) > 0 ? html2`<div role="none" class="dx-grid__plane--frozen-col">
|
|
978
|
+
<div
|
|
979
|
+
role="none"
|
|
980
|
+
data-dx-grid-plane=${plane}
|
|
981
|
+
class="dx-grid__plane--frozen-col__content"
|
|
982
|
+
style="transform:translate3d(0,${offsetBlock}px,0);grid-template-rows:${this.templateGridRows};grid-template-columns:${this[`template${colPlane}`]}"
|
|
983
|
+
>
|
|
984
|
+
${[
|
|
985
|
+
...Array(cols)
|
|
986
|
+
].map((_, c) => {
|
|
987
|
+
return [
|
|
988
|
+
...Array(visibleRows)
|
|
989
|
+
].map((_2, r0) => {
|
|
990
|
+
const r = this.visRowMin + r0;
|
|
991
|
+
return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection), c, r0);
|
|
992
|
+
});
|
|
993
|
+
})}
|
|
994
|
+
</div>
|
|
995
|
+
</div>` : null;
|
|
996
|
+
}
|
|
997
|
+
renderCell(col, row, plane, selected, visCol = col, visRow = row) {
|
|
998
|
+
const cell = this.cell(col, row, plane);
|
|
999
|
+
const active = this.cellActive(col, row, plane);
|
|
1000
|
+
const resizeIndex = cell?.resizeHandle ? cell.resizeHandle === "col" ? col : row : void 0;
|
|
1001
|
+
const resizePlane = cell?.resizeHandle ? resolveResizePlane(cell.resizeHandle, plane) : void 0;
|
|
1002
|
+
return html2`<div
|
|
1003
|
+
role="gridcell"
|
|
1004
|
+
tabindex="0"
|
|
1005
|
+
?inert=${col < 0 || row < 0}
|
|
1006
|
+
?aria-selected=${selected}
|
|
1007
|
+
class=${cell || active ? (cell?.className ? cell.className + " " : "") + (active ? "dx-grid__cell--active" : "") : nothing}
|
|
1008
|
+
aria-colindex=${col}
|
|
1009
|
+
aria-rowindex=${row}
|
|
1010
|
+
data-dx-grid-action="cell"
|
|
1011
|
+
style="grid-column:${visCol + 1};grid-row:${visRow + 1}"
|
|
1012
|
+
>
|
|
1013
|
+
${cell?.value}${cell?.resizeHandle && this.axisResizeable(resizePlane, cell.resizeHandle, resizeIndex) ? html2`<dx-grid-axis-resize-handle
|
|
1014
|
+
axis=${cell.resizeHandle}
|
|
1015
|
+
plane=${resizePlane}
|
|
1016
|
+
index=${resizeIndex}
|
|
1017
|
+
size=${this[`${cell.resizeHandle}Size`](resizeIndex, plane)}
|
|
1018
|
+
></dx-grid-axis-resize-handle>` : null}
|
|
1019
|
+
</div>`;
|
|
1020
|
+
}
|
|
640
1021
|
render() {
|
|
641
1022
|
const visibleCols = this.visColMax - this.visColMin;
|
|
642
1023
|
const visibleRows = this.visRowMax - this.visRowMin;
|
|
643
1024
|
const offsetInline = this.binInlineMin - this.posInline - this.overscanInline;
|
|
644
1025
|
const offsetBlock = this.binBlockMin - this.posBlock - this.overscanBlock;
|
|
645
|
-
const
|
|
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;
|
|
1026
|
+
const selection = selectionProps(this.selectionStart, this.selectionEnd);
|
|
650
1027
|
return html2`<div
|
|
651
1028
|
role="none"
|
|
652
1029
|
class="dx-grid"
|
|
1030
|
+
style=${styleMap({
|
|
1031
|
+
"grid-template-columns": `${this.templatefrozenColsStart ? "min-content " : ""}minmax(0, ${Number.isFinite(this.limitColumns) ? `${this.intrinsicInlineSize}px` : "1fr"})${this.templatefrozenColsEnd ? " min-content" : ""}`,
|
|
1032
|
+
"grid-template-rows": `${this.templatefrozenRowsStart ? "min-content " : ""}minmax(0, ${Number.isFinite(this.limitRows) ? `${this.intrinsicBlockSize}px` : "1fr"})${this.templatefrozenRowsEnd ? " min-content" : ""}`
|
|
1033
|
+
})}
|
|
653
1034
|
data-grid=${this.gridId}
|
|
654
1035
|
data-grid-mode=${this.mode}
|
|
655
|
-
?data-grid-select=${
|
|
1036
|
+
?data-grid-select=${selection.visible}
|
|
656
1037
|
>
|
|
657
|
-
|
|
658
|
-
<div role="
|
|
1038
|
+
${this.renderFixed("fixedStartStart", selection)}${this.renderFrozenRows("frozenRowsStart", visibleCols, offsetInline, selection)}${this.renderFixed("fixedStartEnd", selection)}${this.renderFrozenColumns("frozenColsStart", visibleRows, offsetBlock, selection)}
|
|
1039
|
+
<div role="grid" class="dx-grid__plane--grid" tabindex="0" ${ref2(this.viewportRef)}>
|
|
659
1040
|
<div
|
|
660
1041
|
role="none"
|
|
661
|
-
class="dx-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
${[
|
|
665
|
-
...Array(visibleCols)
|
|
666
|
-
].map((_, c0) => {
|
|
667
|
-
const c = this.visColMin + c0;
|
|
668
|
-
return html2`<div
|
|
669
|
-
role="columnheader"
|
|
670
|
-
?inert=${c < 0}
|
|
671
|
-
style="block-size:${this.rowDefault.size}px;grid-column:${c0 + 1}/${c0 + 2};"
|
|
672
|
-
>
|
|
673
|
-
<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>`}
|
|
680
|
-
</div>`;
|
|
681
|
-
})}
|
|
682
|
-
</div>
|
|
683
|
-
</div>
|
|
684
|
-
<div role="none" class="dx-grid__corner"></div>
|
|
685
|
-
<div role="none" class="dx-grid__rowheader">
|
|
686
|
-
<div
|
|
687
|
-
role="none"
|
|
688
|
-
class="dx-grid__rowheader__content"
|
|
689
|
-
style="transform:translate3d(0,${offsetBlock}px,0);grid-template-rows:${this.templateRows};"
|
|
690
|
-
>
|
|
691
|
-
${[
|
|
692
|
-
...Array(visibleRows)
|
|
693
|
-
].map((_, r0) => {
|
|
694
|
-
const r = this.visRowMin + r0;
|
|
695
|
-
return html2`<div role="rowheader" ?inert=${r < 0} style="grid-row:${r0 + 1}/${r0 + 2}">
|
|
696
|
-
<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>`}
|
|
702
|
-
</div>`;
|
|
703
|
-
})}
|
|
704
|
-
</div>
|
|
705
|
-
</div>
|
|
706
|
-
<div role="grid" class="dx-grid__viewport" tabindex="0" @wheel=${this.handleWheel} ${ref2(this.viewportRef)}>
|
|
707
|
-
<div
|
|
708
|
-
role="none"
|
|
709
|
-
class="dx-grid__content"
|
|
710
|
-
style="transform:translate3d(${offsetInline}px,${offsetBlock}px,0);grid-template-columns:${this.templateColumns};grid-template-rows:${this.templateRows};"
|
|
1042
|
+
class="dx-grid__plane--grid__content"
|
|
1043
|
+
data-dx-grid-plane="grid"
|
|
1044
|
+
style="transform:translate3d(${offsetInline}px,${offsetBlock}px,0);grid-template-columns:${this.templateGridColumns};grid-template-rows:${this.templateGridRows};"
|
|
711
1045
|
>
|
|
712
1046
|
${[
|
|
713
1047
|
...Array(visibleCols)
|
|
@@ -717,75 +1051,70 @@ var DxGrid = class extends LitElement2 {
|
|
|
717
1051
|
].map((_2, r0) => {
|
|
718
1052
|
const c = c0 + this.visColMin;
|
|
719
1053
|
const r = r0 + this.visRowMin;
|
|
720
|
-
|
|
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
|
|
724
|
-
role="gridcell"
|
|
725
|
-
tabindex="0"
|
|
726
|
-
?inert=${c < 0 || r < 0}
|
|
727
|
-
?aria-selected=${selected}
|
|
728
|
-
class=${cell || active ? (cell?.className ? cell.className + " " : "") + (active ? "dx-grid__cell--active" : "") : nothing}
|
|
729
|
-
aria-rowindex=${r}
|
|
730
|
-
aria-colindex=${c}
|
|
731
|
-
data-dx-grid-action="cell"
|
|
732
|
-
style="grid-column:${c0 + 1};grid-row:${r0 + 1}"
|
|
733
|
-
>
|
|
734
|
-
${cell?.value}
|
|
735
|
-
</div>`;
|
|
1054
|
+
return this.renderCell(c, r, "grid", cellSelected(c, r, "grid", selection), c0, r0);
|
|
736
1055
|
});
|
|
737
1056
|
})}
|
|
738
1057
|
</div>
|
|
739
1058
|
</div>
|
|
740
|
-
|
|
741
|
-
<div role="none" class="dx-grid__scrollbar__thumb"></div>
|
|
742
|
-
</div>
|
|
743
|
-
<div role="none" class="dx-grid__corner"></div>
|
|
744
|
-
<div role="none" class="dx-grid__scrollbar" aria-orientation="horizontal">
|
|
745
|
-
<div role="none" class="dx-grid__scrollbar__thumb"></div>
|
|
746
|
-
</div>
|
|
747
|
-
<div role="none" class="dx-grid__corner"></div>
|
|
1059
|
+
${this.renderFrozenColumns("frozenColsEnd", visibleRows, offsetBlock, selection)}${this.renderFixed("fixedEndStart", selection)}${this.renderFrozenRows("frozenRowsEnd", visibleCols, offsetInline, selection)}${this.renderFixed("fixedEndEnd", selection)}
|
|
748
1060
|
</div>`;
|
|
749
1061
|
}
|
|
1062
|
+
updateIntrinsicInlineSize() {
|
|
1063
|
+
this.intrinsicInlineSize = Number.isFinite(this.limitColumns) ? [
|
|
1064
|
+
...Array(this.limitColumns)
|
|
1065
|
+
].reduce((acc, _, c0) => acc + this.colSize(c0, "grid"), 0) + gap * (this.limitColumns - 1) : Infinity;
|
|
1066
|
+
}
|
|
1067
|
+
updateIntrinsicBlockSize() {
|
|
1068
|
+
this.intrinsicBlockSize = Number.isFinite(this.limitRows) ? [
|
|
1069
|
+
...Array(this.limitRows)
|
|
1070
|
+
].reduce((acc, _, r0) => acc + this.rowSize(r0, "grid"), 0) + gap * (this.limitRows - 1) : Infinity;
|
|
1071
|
+
}
|
|
1072
|
+
updateIntrinsicSizes() {
|
|
1073
|
+
this.updateIntrinsicInlineSize();
|
|
1074
|
+
this.updateIntrinsicBlockSize();
|
|
1075
|
+
}
|
|
750
1076
|
firstUpdated() {
|
|
751
1077
|
if (this.getCells) {
|
|
752
|
-
this.
|
|
753
|
-
start: {
|
|
754
|
-
col: this.visColMin,
|
|
755
|
-
row: this.visRowMin
|
|
756
|
-
},
|
|
757
|
-
end: {
|
|
758
|
-
col: this.visColMax,
|
|
759
|
-
row: this.visRowMax
|
|
760
|
-
}
|
|
761
|
-
});
|
|
1078
|
+
this.updateCells(true);
|
|
762
1079
|
}
|
|
763
1080
|
this.observer.observe(this.viewportRef.value);
|
|
764
|
-
this.colSizes = Object.entries(this.columns).reduce((acc, [
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
1081
|
+
this.colSizes = Object.entries(this.columns).reduce((acc, [plane, planeColMeta]) => {
|
|
1082
|
+
acc[plane] = Object.entries(planeColMeta).reduce((planeAcc, [col, colMeta]) => {
|
|
1083
|
+
if (colMeta?.size) {
|
|
1084
|
+
planeAcc[col] = colMeta.size;
|
|
1085
|
+
}
|
|
1086
|
+
return planeAcc;
|
|
1087
|
+
}, {});
|
|
768
1088
|
return acc;
|
|
769
|
-
}, {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
1089
|
+
}, {
|
|
1090
|
+
grid: {}
|
|
1091
|
+
});
|
|
1092
|
+
this.rowSizes = Object.entries(this.rows).reduce((acc, [plane, planeRowMeta]) => {
|
|
1093
|
+
acc[plane] = Object.entries(planeRowMeta).reduce((planeAcc, [row, rowMeta]) => {
|
|
1094
|
+
if (rowMeta?.size) {
|
|
1095
|
+
planeAcc[row] = rowMeta.size;
|
|
1096
|
+
}
|
|
1097
|
+
return planeAcc;
|
|
1098
|
+
}, {});
|
|
774
1099
|
return acc;
|
|
775
|
-
}, {
|
|
1100
|
+
}, {
|
|
1101
|
+
grid: {}
|
|
1102
|
+
});
|
|
1103
|
+
this.updateIntrinsicSizes();
|
|
776
1104
|
}
|
|
777
1105
|
willUpdate(changedProperties) {
|
|
778
1106
|
if (this.getCells && (changedProperties.has("initialCells") || changedProperties.has("visColMin") || changedProperties.has("visColMax") || changedProperties.has("visRowMin") || changedProperties.has("visRowMax"))) {
|
|
779
|
-
this.
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
1107
|
+
this.updateCells();
|
|
1108
|
+
}
|
|
1109
|
+
if (changedProperties.has("rowDefault") || changedProperties.has("rows") || changedProperties.has("limitRows")) {
|
|
1110
|
+
this.updateIntrinsicBlockSize();
|
|
1111
|
+
this.updatePosBlock();
|
|
1112
|
+
this.updateVisBlock();
|
|
1113
|
+
}
|
|
1114
|
+
if (changedProperties.has("colDefault") || changedProperties.has("columns") || changedProperties.has("limitColumns")) {
|
|
1115
|
+
this.updateIntrinsicInlineSize();
|
|
1116
|
+
this.updatePosInline();
|
|
1117
|
+
this.updateVisInline();
|
|
789
1118
|
}
|
|
790
1119
|
}
|
|
791
1120
|
updated(changedProperties) {
|
|
@@ -793,6 +1122,13 @@ var DxGrid = class extends LitElement2 {
|
|
|
793
1122
|
this.refocus();
|
|
794
1123
|
}
|
|
795
1124
|
}
|
|
1125
|
+
updateIfWithinBounds({ col, row }) {
|
|
1126
|
+
if (col >= this.visColMin && col <= this.visColMax && row >= this.visRowMin && row <= this.visRowMax) {
|
|
1127
|
+
this.requestUpdate();
|
|
1128
|
+
return true;
|
|
1129
|
+
}
|
|
1130
|
+
return false;
|
|
1131
|
+
}
|
|
796
1132
|
disconnectedCallback() {
|
|
797
1133
|
super.disconnectedCallback();
|
|
798
1134
|
if (this.viewportRef.value) {
|
|
@@ -838,6 +1174,21 @@ _ts_decorate2([
|
|
|
838
1174
|
type: String
|
|
839
1175
|
})
|
|
840
1176
|
], DxGrid.prototype, "mode", void 0);
|
|
1177
|
+
_ts_decorate2([
|
|
1178
|
+
property2({
|
|
1179
|
+
type: Number
|
|
1180
|
+
})
|
|
1181
|
+
], DxGrid.prototype, "limitColumns", void 0);
|
|
1182
|
+
_ts_decorate2([
|
|
1183
|
+
property2({
|
|
1184
|
+
type: Number
|
|
1185
|
+
})
|
|
1186
|
+
], DxGrid.prototype, "limitRows", void 0);
|
|
1187
|
+
_ts_decorate2([
|
|
1188
|
+
property2({
|
|
1189
|
+
type: Object
|
|
1190
|
+
})
|
|
1191
|
+
], DxGrid.prototype, "frozen", void 0);
|
|
841
1192
|
_ts_decorate2([
|
|
842
1193
|
state()
|
|
843
1194
|
], DxGrid.prototype, "cells", void 0);
|
|
@@ -885,10 +1236,22 @@ _ts_decorate2([
|
|
|
885
1236
|
], DxGrid.prototype, "visRowMax", void 0);
|
|
886
1237
|
_ts_decorate2([
|
|
887
1238
|
state()
|
|
888
|
-
], DxGrid.prototype, "
|
|
1239
|
+
], DxGrid.prototype, "templateGridColumns", void 0);
|
|
1240
|
+
_ts_decorate2([
|
|
1241
|
+
state()
|
|
1242
|
+
], DxGrid.prototype, "templatefrozenColsStart", void 0);
|
|
889
1243
|
_ts_decorate2([
|
|
890
1244
|
state()
|
|
891
|
-
], DxGrid.prototype, "
|
|
1245
|
+
], DxGrid.prototype, "templatefrozenColsEnd", void 0);
|
|
1246
|
+
_ts_decorate2([
|
|
1247
|
+
state()
|
|
1248
|
+
], DxGrid.prototype, "templateGridRows", void 0);
|
|
1249
|
+
_ts_decorate2([
|
|
1250
|
+
state()
|
|
1251
|
+
], DxGrid.prototype, "templatefrozenRowsStart", void 0);
|
|
1252
|
+
_ts_decorate2([
|
|
1253
|
+
state()
|
|
1254
|
+
], DxGrid.prototype, "templatefrozenRowsEnd", void 0);
|
|
892
1255
|
_ts_decorate2([
|
|
893
1256
|
state()
|
|
894
1257
|
], DxGrid.prototype, "pointer", void 0);
|
|
@@ -912,17 +1275,13 @@ _ts_decorate2([
|
|
|
912
1275
|
], DxGrid.prototype, "selectionEnd", void 0);
|
|
913
1276
|
_ts_decorate2([
|
|
914
1277
|
state()
|
|
915
|
-
], DxGrid.prototype, "
|
|
1278
|
+
], DxGrid.prototype, "intrinsicInlineSize", void 0);
|
|
916
1279
|
_ts_decorate2([
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
})
|
|
920
|
-
], DxGrid.prototype, "handleFocus", null);
|
|
1280
|
+
state()
|
|
1281
|
+
], DxGrid.prototype, "intrinsicBlockSize", void 0);
|
|
921
1282
|
_ts_decorate2([
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
})
|
|
925
|
-
], DxGrid.prototype, "handleBlur", null);
|
|
1283
|
+
state()
|
|
1284
|
+
], DxGrid.prototype, "observer", void 0);
|
|
926
1285
|
DxGrid = _ts_decorate2([
|
|
927
1286
|
customElement2("dx-grid")
|
|
928
1287
|
], DxGrid);
|
|
@@ -931,6 +1290,8 @@ export {
|
|
|
931
1290
|
DxAxisResizeInternal,
|
|
932
1291
|
DxEditRequest,
|
|
933
1292
|
DxGrid,
|
|
934
|
-
DxGridCellsSelect
|
|
1293
|
+
DxGridCellsSelect,
|
|
1294
|
+
colToA1Notation,
|
|
1295
|
+
rowToA1Notation
|
|
935
1296
|
};
|
|
936
1297
|
//# sourceMappingURL=index.mjs.map
|