@dxos/lit-grid 0.8.3 → 0.8.4-main.f9ba587
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/src/dx-grid.d.ts +1 -0
- package/dist/src/dx-grid.d.ts.map +1 -1
- package/dist/src/dx-grid.js +52 -8
- package/dist/src/dx-grid.js.map +1 -1
- package/dist/src/dx-grid.lit-stories.d.ts +1 -0
- package/dist/src/dx-grid.lit-stories.d.ts.map +1 -1
- package/dist/src/dx-grid.lit-stories.js +4 -2
- package/dist/src/dx-grid.lit-stories.js.map +1 -1
- package/dist/src/playwright/dx-grid.spec.d.ts.map +1 -0
- package/dist/src/{testing/playwright → playwright}/dx-grid.spec.js +3 -3
- package/dist/src/playwright/dx-grid.spec.js.map +1 -0
- package/dist/src/playwright/playwright.config.d.ts +3 -0
- package/dist/src/playwright/playwright.config.d.ts.map +1 -0
- package/dist/src/playwright/playwright.config.js +15 -0
- package/dist/src/playwright/playwright.config.js.map +1 -0
- package/dist/src/testing/{playwright/dx-grid-manager.d.ts → dx-grid-manager.d.ts} +1 -1
- package/dist/src/testing/dx-grid-manager.d.ts.map +1 -0
- package/dist/src/testing/dx-grid-manager.js.map +1 -0
- package/dist/src/testing/index.d.ts +1 -1
- package/dist/src/testing/index.d.ts.map +1 -1
- package/dist/src/testing/index.js +1 -1
- package/dist/src/testing/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/src/dx-grid-axis-resize-handle.pcss +1 -0
- package/src/dx-grid-multiselect-cell.pcss +2 -2
- package/src/dx-grid.lit-stories.ts +6 -2
- package/src/dx-grid.pcss +117 -15
- package/src/dx-grid.ts +68 -8
- package/src/{testing/playwright → playwright}/dx-grid.spec.ts +4 -4
- package/src/playwright/playwright.config.ts +17 -0
- package/src/testing/{playwright/dx-grid-manager.ts → dx-grid-manager.ts} +1 -1
- package/src/testing/index.ts +1 -1
- package/dist/src/testing/playwright/dx-grid-manager.d.ts.map +0 -1
- package/dist/src/testing/playwright/dx-grid-manager.js.map +0 -1
- package/dist/src/testing/playwright/dx-grid.spec.d.ts.map +0 -1
- package/dist/src/testing/playwright/dx-grid.spec.js.map +0 -1
- package/dist/types/src/defs.d.ts +0 -3
- package/dist/types/src/defs.d.ts.map +0 -1
- package/dist/types/src/defs.js +0 -6
- package/dist/types/src/defs.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 -100
- package/dist/types/src/dx-grid-axis-resize-handle.js.map +0 -1
- package/dist/types/src/dx-grid-multiselect-cell.d.ts +0 -13
- package/dist/types/src/dx-grid-multiselect-cell.d.ts.map +0 -1
- package/dist/types/src/dx-grid-multiselect-cell.js +0 -56
- package/dist/types/src/dx-grid-multiselect-cell.js.map +0 -1
- package/dist/types/src/dx-grid.d.ts +0 -170
- package/dist/types/src/dx-grid.d.ts.map +0 -1
- package/dist/types/src/dx-grid.js +0 -1347
- package/dist/types/src/dx-grid.js.map +0 -1
- package/dist/types/src/dx-grid.lit-stories.d.ts +0 -46
- package/dist/types/src/dx-grid.lit-stories.d.ts.map +0 -1
- package/dist/types/src/dx-grid.lit-stories.js +0 -179
- package/dist/types/src/dx-grid.lit-stories.js.map +0 -1
- package/dist/types/src/index.d.ts +0 -5
- package/dist/types/src/index.d.ts.map +0 -1
- package/dist/types/src/index.js +0 -8
- package/dist/types/src/index.js.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/index.js +0 -5
- package/dist/types/src/testing/index.js.map +0 -1
- package/dist/types/src/testing/playwright/dx-grid-manager.d.ts +0 -24
- package/dist/types/src/testing/playwright/dx-grid-manager.d.ts.map +0 -1
- package/dist/types/src/testing/playwright/dx-grid-manager.js +0 -79
- package/dist/types/src/testing/playwright/dx-grid-manager.js.map +0 -1
- package/dist/types/src/testing/playwright/dx-grid.spec.d.ts +0 -2
- package/dist/types/src/testing/playwright/dx-grid.spec.d.ts.map +0 -1
- package/dist/types/src/testing/playwright/dx-grid.spec.js +0 -92
- package/dist/types/src/testing/playwright/dx-grid.spec.js.map +0 -1
- package/dist/types/src/types.d.ts +0 -137
- package/dist/types/src/types.d.ts.map +0 -1
- package/dist/types/src/types.js +0 -46
- package/dist/types/src/types.js.map +0 -1
- package/dist/types/src/util.d.ts +0 -39
- package/dist/types/src/util.d.ts.map +0 -1
- package/dist/types/src/util.js +0 -165
- package/dist/types/src/util.js.map +0 -1
- package/dist/types/tsconfig.tsbuildinfo +0 -1
- package/src/testing/playwright/playwright.config.cts +0 -18
- /package/dist/src/{testing/playwright → playwright}/dx-grid.spec.d.ts +0 -0
- /package/dist/src/testing/{playwright/dx-grid-manager.js → dx-grid-manager.js} +0 -0
|
@@ -1,1347 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
5
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
6
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
7
|
-
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;
|
|
8
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
9
|
-
};
|
|
10
|
-
import { LitElement, html, nothing } from 'lit';
|
|
11
|
-
import { customElement, state, property } from 'lit/decorators.js';
|
|
12
|
-
import { ref, createRef } from 'lit/directives/ref.js';
|
|
13
|
-
import { styleMap } from 'lit/directives/style-map.js';
|
|
14
|
-
import { unsafeStatic, html as staticHtml } from 'lit/static-html.js';
|
|
15
|
-
import { defaultColSize, defaultRowSize } from './defs';
|
|
16
|
-
// eslint-disable-next-line unused-imports/no-unused-imports
|
|
17
|
-
import './dx-grid-axis-resize-handle';
|
|
18
|
-
import { DxAxisResize, DxEditRequest, DxGridCellsSelect, separator, } from './types';
|
|
19
|
-
import { toCellIndex, gap, resizeTolerance, sizeColMin, sizeColMax, sizeRowMin, sizeRowMax, shouldSelect, selectionProps, cellSelected, closestAction, closestCell, targetIsPlane, resolveRowPlane, resolveColPlane, resolveFrozenPlane, isSameCell, isReadonly, } from './util';
|
|
20
|
-
let DxGrid = class DxGrid extends LitElement {
|
|
21
|
-
constructor() {
|
|
22
|
-
var _a;
|
|
23
|
-
super();
|
|
24
|
-
this.gridId = 'default-grid-id';
|
|
25
|
-
this.rowDefault = {
|
|
26
|
-
grid: { size: defaultRowSize },
|
|
27
|
-
};
|
|
28
|
-
this.columnDefault = {
|
|
29
|
-
grid: { size: defaultColSize },
|
|
30
|
-
};
|
|
31
|
-
this.rows = { grid: {} };
|
|
32
|
-
this.columns = { grid: {} };
|
|
33
|
-
this.initialCells = { grid: {} };
|
|
34
|
-
this.mode = 'browse';
|
|
35
|
-
this.limitColumns = Infinity;
|
|
36
|
-
this.limitRows = Infinity;
|
|
37
|
-
this.frozen = {};
|
|
38
|
-
this.overscroll = undefined;
|
|
39
|
-
this.activeRefs = '';
|
|
40
|
-
/**
|
|
41
|
-
* When this function is defined, it is used first to try to get a value for a cell,
|
|
42
|
-
* and otherwise will fall back to `cells`.
|
|
43
|
-
*/
|
|
44
|
-
this.getCells = null;
|
|
45
|
-
this.cells = { grid: {} };
|
|
46
|
-
//
|
|
47
|
-
// `pos`, short for ‘position’, is the position in pixels of the viewport from the origin.
|
|
48
|
-
//
|
|
49
|
-
this.posInline = 0;
|
|
50
|
-
this.posBlock = 0;
|
|
51
|
-
//
|
|
52
|
-
// `size` (when not suffixed with ‘row’ or ‘col’, see above) is the size in pixels of the viewport.
|
|
53
|
-
//
|
|
54
|
-
this.sizeInline = 0;
|
|
55
|
-
this.sizeBlock = 0;
|
|
56
|
-
//
|
|
57
|
-
// `overscan` is the amount in pixels to offset the grid content due to the number of overscanned columns or rows.
|
|
58
|
-
//
|
|
59
|
-
this.visColMinStart = 0;
|
|
60
|
-
this.visRowMinStart = 0;
|
|
61
|
-
//
|
|
62
|
-
// `bin`, not short for anything, is the range in pixels within which virtualization does not need to reassess.
|
|
63
|
-
//
|
|
64
|
-
this.binInlineMin = 0;
|
|
65
|
-
this.binInlineMax = defaultColSize;
|
|
66
|
-
this.binBlockMin = 0;
|
|
67
|
-
this.binBlockMax = defaultRowSize;
|
|
68
|
-
//
|
|
69
|
-
// `vis`, short for ‘visible’, is the range in numeric index of the columns or rows which should be rendered within
|
|
70
|
-
// the viewport. These start with naïve values that are updated before first contentful render.
|
|
71
|
-
//
|
|
72
|
-
this.visColMin = 0;
|
|
73
|
-
this.visColMax = 1;
|
|
74
|
-
this.visRowMin = 0;
|
|
75
|
-
this.visRowMax = 1;
|
|
76
|
-
//
|
|
77
|
-
// `template` is the rendered value of `grid-{axis}-template`.
|
|
78
|
-
//
|
|
79
|
-
this.templateGridColumns = '0';
|
|
80
|
-
this.templatefrozenColsStart = '';
|
|
81
|
-
this.templatefrozenColsEnd = '';
|
|
82
|
-
this.templateGridRows = '0';
|
|
83
|
-
this.templatefrozenRowsStart = '';
|
|
84
|
-
this.templatefrozenRowsEnd = '';
|
|
85
|
-
//
|
|
86
|
-
// Focus, selection, and resize states
|
|
87
|
-
//
|
|
88
|
-
this.pointer = null;
|
|
89
|
-
this.colSizes = { grid: {} };
|
|
90
|
-
this.rowSizes = { grid: {} };
|
|
91
|
-
this.focusActive = false;
|
|
92
|
-
this.focusedCell = { plane: 'grid', col: 0, row: 0 };
|
|
93
|
-
this.selectionStart = { plane: 'grid', col: 0, row: 0 };
|
|
94
|
-
this.selectionEnd = { plane: 'grid', col: 0, row: 0 };
|
|
95
|
-
//
|
|
96
|
-
// Limits
|
|
97
|
-
//
|
|
98
|
-
this.intrinsicInlineSize = Infinity;
|
|
99
|
-
this.intrinsicBlockSize = Infinity;
|
|
100
|
-
this.totalIntrinsicInlineSize = Infinity;
|
|
101
|
-
this.totalIntrinsicBlockSize = Infinity;
|
|
102
|
-
this.handlePointerDown = (event) => {
|
|
103
|
-
if (this.mode === 'browse' && event.pointerType === 'touch') {
|
|
104
|
-
this.pointer = { state: 'panning', pageX: event.pageX, pageY: event.pageY };
|
|
105
|
-
}
|
|
106
|
-
else if (event.isPrimary) {
|
|
107
|
-
const { action, actionEl } = closestAction(event.target);
|
|
108
|
-
if (action && action === 'cell') {
|
|
109
|
-
if (event.shiftKey && this.mode === 'browse') {
|
|
110
|
-
// Prevent focus moving so the pointerup handler can move selectionEnd.
|
|
111
|
-
event.preventDefault();
|
|
112
|
-
this.pointer = { state: 'selecting' };
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
const cellCoords = closestCell(event.target, actionEl);
|
|
116
|
-
if (cellCoords &&
|
|
117
|
-
this.mode !== 'edit' &&
|
|
118
|
-
!this.cellReadonly(cellCoords.col, cellCoords.row, cellCoords.plane)) {
|
|
119
|
-
this.pointer = { state: 'maybeSelecting', pageX: event.pageX, pageY: event.pageY };
|
|
120
|
-
this.selectionStart = cellCoords;
|
|
121
|
-
this.selectionEnd = cellCoords;
|
|
122
|
-
this.dispatchSelectionChange();
|
|
123
|
-
}
|
|
124
|
-
if (this.mode === 'edit-select') {
|
|
125
|
-
// Prevent focus moving when editing while selection is possible
|
|
126
|
-
event.preventDefault();
|
|
127
|
-
}
|
|
128
|
-
else if (this.focusActive && isSameCell(this.focusedCell, cellCoords)) {
|
|
129
|
-
this.dispatchEditRequest();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
this.handlePointerUp = (event) => {
|
|
136
|
-
var _a;
|
|
137
|
-
if (((_a = this.pointer) === null || _a === void 0 ? void 0 : _a.state) === 'selecting') {
|
|
138
|
-
const cell = closestCell(event.target);
|
|
139
|
-
if (cell) {
|
|
140
|
-
this.setSelectionEnd(cell);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
// TODO(thure): If this was panning via touch, continue panning based on final velocity.
|
|
144
|
-
this.pointer = null;
|
|
145
|
-
};
|
|
146
|
-
this.handlePointerMove = (event) => {
|
|
147
|
-
var _a, _b;
|
|
148
|
-
if (((_a = this.pointer) === null || _a === void 0 ? void 0 : _a.state) === 'panning') {
|
|
149
|
-
const panEvent = event;
|
|
150
|
-
panEvent.deltaX = this.pointer.pageX - event.pageX;
|
|
151
|
-
panEvent.deltaY = this.pointer.pageY - event.pageY;
|
|
152
|
-
this.pointer.pageX = event.pageX;
|
|
153
|
-
this.pointer.pageY = event.pageY;
|
|
154
|
-
this.handleWheel(panEvent);
|
|
155
|
-
}
|
|
156
|
-
else if (shouldSelect(this.pointer, event)) {
|
|
157
|
-
this.pointer = { state: 'selecting' };
|
|
158
|
-
}
|
|
159
|
-
else if (((_b = this.pointer) === null || _b === void 0 ? void 0 : _b.state) === 'selecting') {
|
|
160
|
-
const cell = closestCell(event.target);
|
|
161
|
-
if (cell &&
|
|
162
|
-
cell.plane === this.selectionStart.plane &&
|
|
163
|
-
(cell.col !== this.selectionEnd.col || cell.row !== this.selectionEnd.row)) {
|
|
164
|
-
this.setSelectionEnd(cell);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
//
|
|
169
|
-
// Resize & reposition handlers, observer, ref
|
|
170
|
-
//
|
|
171
|
-
this.observer = new ResizeObserver((entries) => {
|
|
172
|
-
var _a, _b, _c;
|
|
173
|
-
const { inlineSize, blockSize } = (_c = (_b = (_a = entries === null || entries === void 0 ? void 0 : entries[0]) === null || _a === void 0 ? void 0 : _a.contentBoxSize) === null || _b === void 0 ? void 0 : _b[0]) !== null && _c !== void 0 ? _c : {
|
|
174
|
-
inlineSize: 0,
|
|
175
|
-
blockSize: 0,
|
|
176
|
-
};
|
|
177
|
-
if (Math.abs(inlineSize - this.sizeInline) > resizeTolerance ||
|
|
178
|
-
Math.abs(blockSize - this.sizeBlock) > resizeTolerance) {
|
|
179
|
-
// console.info('[updating bounds]', 'resize', [inlineSize - this.sizeInline, blockSize - this.sizeBlock]);
|
|
180
|
-
this.sizeInline = inlineSize;
|
|
181
|
-
this.sizeBlock = blockSize;
|
|
182
|
-
this.updateVis();
|
|
183
|
-
queueMicrotask(() => this.updatePos());
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
this.gridRef = createRef();
|
|
187
|
-
this.viewportRef = createRef();
|
|
188
|
-
this.maybeUpdateVisInline = () => {
|
|
189
|
-
if (this.posInline < this.binInlineMin || this.posInline >= this.binInlineMax) {
|
|
190
|
-
this.updateVisInline();
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
this.maybeUpdateVisBlock = () => {
|
|
194
|
-
if (this.posBlock < this.binBlockMin || this.posBlock >= this.binBlockMax) {
|
|
195
|
-
this.updateVisBlock();
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
this.handleTopLevelWheel = (event) => {
|
|
199
|
-
var _a;
|
|
200
|
-
if (event.gridId === ((_a = this.gridId) !== null && _a !== void 0 ? _a : 'never')) {
|
|
201
|
-
if (this.overscroll === 'trap' ||
|
|
202
|
-
(this.overscroll === 'inline' && event.overscrollInline === 0) ||
|
|
203
|
-
(this.overscroll === 'block' && event.overscrollBlock === 0)) {
|
|
204
|
-
event.preventDefault();
|
|
205
|
-
event.stopPropagation();
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
this.handleWheel = (event) => {
|
|
210
|
-
if (this.mode === 'browse') {
|
|
211
|
-
const nextPosInline = this.posInline + event.deltaX;
|
|
212
|
-
const nextPosBlock = this.posBlock + event.deltaY;
|
|
213
|
-
const maxPosInline = this.maxPosInline();
|
|
214
|
-
const maxPosBlock = this.maxPosBlock();
|
|
215
|
-
this.updatePos(nextPosInline, nextPosBlock, maxPosInline, maxPosBlock);
|
|
216
|
-
event.overscrollInline =
|
|
217
|
-
nextPosInline <= 0 ? nextPosInline : nextPosInline > maxPosInline ? nextPosInline - maxPosInline : 0;
|
|
218
|
-
event.overscrollBlock =
|
|
219
|
-
nextPosBlock <= 0 ? nextPosBlock : nextPosBlock > maxPosBlock ? nextPosBlock - maxPosBlock : 0;
|
|
220
|
-
event.gridId = this.gridId;
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
// Wheel, top-level and element-level
|
|
224
|
-
(_a = document.defaultView) === null || _a === void 0 ? void 0 : _a.addEventListener('wheel', this.handleTopLevelWheel, { passive: false });
|
|
225
|
-
this.addEventListener('wheel', this.handleWheel);
|
|
226
|
-
// Custom event(s)
|
|
227
|
-
this.addEventListener('dx-axis-resize-internal', this.handleAxisResizeInternal);
|
|
228
|
-
// Standard events
|
|
229
|
-
this.addEventListener('pointerdown', this.handlePointerDown);
|
|
230
|
-
this.addEventListener('pointermove', this.handlePointerMove);
|
|
231
|
-
this.addEventListener('pointerup', this.handlePointerUp);
|
|
232
|
-
this.addEventListener('pointerleave', this.handlePointerUp);
|
|
233
|
-
this.addEventListener('focus', this.handleFocus, { capture: true });
|
|
234
|
-
this.addEventListener('blur', this.handleBlur, { capture: true });
|
|
235
|
-
this.addEventListener('keydown', this.handleKeydown);
|
|
236
|
-
}
|
|
237
|
-
//
|
|
238
|
-
// Primary pointer and keyboard handlers
|
|
239
|
-
//
|
|
240
|
-
dispatchEditRequest(initialContent) {
|
|
241
|
-
this.snapPosToFocusedCell();
|
|
242
|
-
if (!this.cellReadonly(this.focusedCell.col, this.focusedCell.row, this.focusedCell.plane)) {
|
|
243
|
-
// Without deferring, the event dispatches before `focusedCellBox` can get updated bounds of the cell, hence:
|
|
244
|
-
queueMicrotask(() => {
|
|
245
|
-
const cellIndex = toCellIndex(this.focusedCell);
|
|
246
|
-
return this.dispatchEvent(new DxEditRequest({
|
|
247
|
-
cellIndex,
|
|
248
|
-
cellBox: this.focusedCellBox(),
|
|
249
|
-
cellElement: this.focusedCellElement(),
|
|
250
|
-
initialContent,
|
|
251
|
-
}));
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
dispatchSelectionChange() {
|
|
256
|
-
return this.dispatchEvent(new DxGridCellsSelect({
|
|
257
|
-
start: this.selectionStart,
|
|
258
|
-
end: this.selectionEnd,
|
|
259
|
-
}));
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Increments focus among all theoretically possible cells in a plane, cycling as tab would but accounting for the
|
|
263
|
-
* theoretical bounds of the grid plane (handling infinite planes heuristically).
|
|
264
|
-
*/
|
|
265
|
-
incrementFocusWithinPlane(event) {
|
|
266
|
-
const reverse = event.shiftKey;
|
|
267
|
-
const colPlane = resolveColPlane(this.focusedCell.plane);
|
|
268
|
-
const rowPlane = resolveRowPlane(this.focusedCell.plane);
|
|
269
|
-
const colMax = (colPlane === 'grid' ? this.limitColumns : this.frozen[colPlane]) - 1;
|
|
270
|
-
const rowMax = (rowPlane === 'grid' ? this.limitRows : this.frozen[rowPlane]) - 1;
|
|
271
|
-
if (reverse ? this.focusedCell.col - 1 < 0 : this.focusedCell.col + 1 > colMax) {
|
|
272
|
-
if (reverse ? this.focusedCell.row - 1 < 0 : this.focusedCell.row + 1 > rowMax) {
|
|
273
|
-
this.setFocusedCell({
|
|
274
|
-
plane: this.focusedCell.plane,
|
|
275
|
-
row: reverse && Number.isFinite(rowMax) ? rowMax : 0,
|
|
276
|
-
col: reverse && Number.isFinite(colMax) ? colMax : 0,
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
this.setFocusedCell({
|
|
281
|
-
plane: this.focusedCell.plane,
|
|
282
|
-
row: this.focusedCell.row + (reverse ? -1 : 1),
|
|
283
|
-
col: reverse && Number.isFinite(colMax) ? colMax : 0,
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
else {
|
|
288
|
-
this.setFocusedCell({ ...this.focusedCell, col: this.focusedCell.col + (reverse ? -1 : 1) });
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Increments focus in a specific direction without cycling.
|
|
293
|
-
*/
|
|
294
|
-
moveFocusOrSelectionEndWithinPlane(event) {
|
|
295
|
-
const current = event.shiftKey ? this.selectionEnd : this.focusedCell;
|
|
296
|
-
const deltaCol = event.key === 'ArrowLeft' ? -1 : event.key === 'ArrowRight' ? 1 : 0;
|
|
297
|
-
const deltaRow = event.key === 'ArrowUp' ? -1 : event.key === 'ArrowDown' ? 1 : 0;
|
|
298
|
-
const nextCol = this.clampCol(current, deltaCol);
|
|
299
|
-
const nextRow = this.clampRow(current, deltaRow);
|
|
300
|
-
if (event.shiftKey) {
|
|
301
|
-
this.setSelectionEnd({ ...this.selectionEnd, col: nextCol, row: nextRow });
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
this.setFocusedCell({ ...this.focusedCell, row: nextRow, col: nextCol });
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
moveFocusBetweenPlanes(event, plane) {
|
|
308
|
-
var _a, _b, _c, _d;
|
|
309
|
-
const planeElement = (_a = this.gridRef.value) === null || _a === void 0 ? void 0 : _a.querySelector(`[data-dx-grid-plane="${plane}"]`);
|
|
310
|
-
if (planeElement) {
|
|
311
|
-
const axis = event.key === 'ArrowUp' || event.key === 'ArrowDown' ? 'col' : 'row';
|
|
312
|
-
const delta = event.key === 'ArrowLeft' || event.key === 'ArrowUp' ? -1 : 1;
|
|
313
|
-
const planeAxis = planeElement === null || planeElement === void 0 ? void 0 : planeElement.getAttribute(`data-dx-grid-plane-${axis}`);
|
|
314
|
-
const adjacentPlanes = Array.from((_c = (_b = this.gridRef.value) === null || _b === void 0 ? void 0 : _b.querySelectorAll(`[data-dx-grid-plane-${axis}="${planeAxis}"]`)) !== null && _c !== void 0 ? _c : [planeElement]).filter((el) => !!el);
|
|
315
|
-
(_d = adjacentPlanes[(adjacentPlanes.length + adjacentPlanes.indexOf(planeElement) + delta) % adjacentPlanes.length]) === null || _d === void 0 ? void 0 : _d.focus({ preventScroll: true });
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
moveFocusIntoPlane(plane) {
|
|
319
|
-
var _a;
|
|
320
|
-
if (this.focusedCell.plane !== plane) {
|
|
321
|
-
const colPlane = resolveColPlane(plane);
|
|
322
|
-
const rowPlane = resolveRowPlane(plane);
|
|
323
|
-
this.focusedCell = {
|
|
324
|
-
plane,
|
|
325
|
-
col: colPlane === 'grid' ? this.visColMin : 0,
|
|
326
|
-
row: rowPlane === 'grid' ? this.visRowMin : 0,
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
(_a = this.focusedCellElement()) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
|
|
330
|
-
}
|
|
331
|
-
moveFocusToPlane() {
|
|
332
|
-
var _a;
|
|
333
|
-
(_a = this.focusedPlaneElement()) === null || _a === void 0 ? void 0 : _a.focus({ preventScroll: true });
|
|
334
|
-
}
|
|
335
|
-
handleKeydown(event) {
|
|
336
|
-
if (this.focusActive && this.mode === 'browse') {
|
|
337
|
-
const plane = targetIsPlane(event.target);
|
|
338
|
-
if (plane) {
|
|
339
|
-
switch (event.key) {
|
|
340
|
-
case 'ArrowDown':
|
|
341
|
-
case 'ArrowUp':
|
|
342
|
-
case 'ArrowRight':
|
|
343
|
-
case 'ArrowLeft':
|
|
344
|
-
event.preventDefault();
|
|
345
|
-
this.moveFocusBetweenPlanes(event, plane);
|
|
346
|
-
break;
|
|
347
|
-
case 'Enter':
|
|
348
|
-
event.preventDefault();
|
|
349
|
-
this.moveFocusIntoPlane(plane);
|
|
350
|
-
break;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
// Adjust cell-scope state
|
|
355
|
-
switch (event.key) {
|
|
356
|
-
case 'ArrowDown':
|
|
357
|
-
case 'ArrowUp':
|
|
358
|
-
case 'ArrowRight':
|
|
359
|
-
case 'ArrowLeft':
|
|
360
|
-
event.preventDefault();
|
|
361
|
-
this.moveFocusOrSelectionEndWithinPlane(event);
|
|
362
|
-
break;
|
|
363
|
-
case 'Tab':
|
|
364
|
-
event.preventDefault();
|
|
365
|
-
this.incrementFocusWithinPlane(event);
|
|
366
|
-
break;
|
|
367
|
-
case 'Escape':
|
|
368
|
-
// Handle escape if selection is a superset of the focused cell.
|
|
369
|
-
event.preventDefault();
|
|
370
|
-
if (this.selectionStart.col !== this.selectionEnd.col ||
|
|
371
|
-
this.selectionStart.row !== this.selectionEnd.row) {
|
|
372
|
-
this.selectionStart = this.focusedCell;
|
|
373
|
-
this.selectionEnd = this.focusedCell;
|
|
374
|
-
this.dispatchSelectionChange();
|
|
375
|
-
}
|
|
376
|
-
else {
|
|
377
|
-
this.moveFocusToPlane();
|
|
378
|
-
}
|
|
379
|
-
break;
|
|
380
|
-
case 'Enter':
|
|
381
|
-
event.preventDefault();
|
|
382
|
-
this.dispatchEditRequest();
|
|
383
|
-
break;
|
|
384
|
-
default:
|
|
385
|
-
if (event.key.length === 1 && event.key.match(/\P{Cc}/u) && !(event.metaKey || event.ctrlKey)) {
|
|
386
|
-
this.dispatchEditRequest(event.key);
|
|
387
|
-
}
|
|
388
|
-
break;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
//
|
|
394
|
-
// Accessors
|
|
395
|
-
//
|
|
396
|
-
colSize(c, plane) {
|
|
397
|
-
var _a, _b, _c, _d, _e;
|
|
398
|
-
const resolvedPlane = resolveColPlane(plane);
|
|
399
|
-
return (_e = (_c = (_b = (_a = this.colSizes) === null || _a === void 0 ? void 0 : _a[resolvedPlane]) === null || _b === void 0 ? void 0 : _b[c]) !== null && _c !== void 0 ? _c : (_d = this.columnDefault[resolvedPlane]) === null || _d === void 0 ? void 0 : _d.size) !== null && _e !== void 0 ? _e : defaultColSize;
|
|
400
|
-
}
|
|
401
|
-
rowSize(r, plane) {
|
|
402
|
-
var _a, _b, _c, _d, _e;
|
|
403
|
-
const resolvedPlane = resolveRowPlane(plane);
|
|
404
|
-
return (_e = (_c = (_b = (_a = this.rowSizes) === null || _a === void 0 ? void 0 : _a[resolvedPlane]) === null || _b === void 0 ? void 0 : _b[r]) !== null && _c !== void 0 ? _c : (_d = this.rowDefault[resolvedPlane]) === null || _d === void 0 ? void 0 : _d.size) !== null && _e !== void 0 ? _e : defaultRowSize;
|
|
405
|
-
}
|
|
406
|
-
cell(c, r, plane) {
|
|
407
|
-
var _a, _b, _c, _d, _e;
|
|
408
|
-
const index = `${c}${separator}${r}`;
|
|
409
|
-
return (_c = (_b = (_a = this.cells) === null || _a === void 0 ? void 0 : _a[plane]) === null || _b === void 0 ? void 0 : _b[index]) !== null && _c !== void 0 ? _c : (_e = (_d = this.initialCells) === null || _d === void 0 ? void 0 : _d[plane]) === null || _e === void 0 ? void 0 : _e[index];
|
|
410
|
-
}
|
|
411
|
-
cellActive(c, r, plane) {
|
|
412
|
-
return this.focusedCell.plane === plane && this.focusedCell.col === c && this.focusedCell.row === r;
|
|
413
|
-
}
|
|
414
|
-
setFocusedCell(nextCoords) {
|
|
415
|
-
if (this.focusedCell.plane !== nextCoords.plane ||
|
|
416
|
-
this.focusedCell.col !== nextCoords.col ||
|
|
417
|
-
this.focusedCell.row !== nextCoords.row) {
|
|
418
|
-
this.focusedCell = nextCoords;
|
|
419
|
-
this.selectionStart = nextCoords;
|
|
420
|
-
this.selectionEnd = nextCoords;
|
|
421
|
-
this.snapPosToFocusedCell();
|
|
422
|
-
this.dispatchSelectionChange();
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
// Internal utility for setting selection end.
|
|
426
|
-
setSelectionEnd(nextCoords) {
|
|
427
|
-
if (this.selectionEnd.plane !== nextCoords.plane ||
|
|
428
|
-
this.selectionEnd.col !== nextCoords.col ||
|
|
429
|
-
this.selectionEnd.row !== nextCoords.row) {
|
|
430
|
-
this.selectionEnd = nextCoords;
|
|
431
|
-
this.dispatchSelectionChange();
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
// Selection setter for consumers
|
|
435
|
-
setSelection(range) {
|
|
436
|
-
if (this.mode !== 'edit') {
|
|
437
|
-
this.selectionStart = range.start;
|
|
438
|
-
this.selectionEnd = range.end;
|
|
439
|
-
this.dispatchSelectionChange();
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
focusedCellBox() {
|
|
443
|
-
const cellElement = this.focusedCellElement();
|
|
444
|
-
const cellSize = {
|
|
445
|
-
inlineSize: this.colSize(this.focusedCell.col, this.focusedCell.plane),
|
|
446
|
-
blockSize: this.rowSize(this.focusedCell.row, this.focusedCell.plane),
|
|
447
|
-
};
|
|
448
|
-
if (!cellElement) {
|
|
449
|
-
return { insetInlineStart: NaN, insetBlockStart: NaN, ...cellSize };
|
|
450
|
-
}
|
|
451
|
-
const contentElement = cellElement.offsetParent;
|
|
452
|
-
// Note that storing `offset` in state causes performance issues, so instead the transform is parsed here.
|
|
453
|
-
const [_translate3d, inlineStr, blockStr] = contentElement.style.transform.split(/[()]|px,?\s?/);
|
|
454
|
-
const contentOffsetInline = parseFloat(inlineStr);
|
|
455
|
-
const contentOffsetBlock = parseFloat(blockStr);
|
|
456
|
-
const offsetParent = contentElement.offsetParent;
|
|
457
|
-
return {
|
|
458
|
-
insetInlineStart: cellElement.offsetLeft + contentOffsetInline + offsetParent.offsetLeft,
|
|
459
|
-
insetBlockStart: cellElement.offsetTop + contentOffsetBlock + offsetParent.offsetTop,
|
|
460
|
-
...cellSize,
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
maxPosInline() {
|
|
464
|
-
return this.intrinsicInlineSize - this.sizeInline;
|
|
465
|
-
}
|
|
466
|
-
maxPosBlock() {
|
|
467
|
-
return this.intrinsicBlockSize - this.sizeBlock;
|
|
468
|
-
}
|
|
469
|
-
updatePosInline(inline, maxInline = this.maxPosInline()) {
|
|
470
|
-
this.posInline = Math.max(0, Math.min(maxInline, inline !== null && inline !== void 0 ? inline : this.posInline));
|
|
471
|
-
this.maybeUpdateVisInline();
|
|
472
|
-
}
|
|
473
|
-
updatePosBlock(block, maxBlock = this.maxPosBlock()) {
|
|
474
|
-
this.posBlock = Math.max(0, Math.min(maxBlock, block !== null && block !== void 0 ? block : this.posBlock));
|
|
475
|
-
this.maybeUpdateVisBlock();
|
|
476
|
-
}
|
|
477
|
-
updatePos(inline, block, maxInline, maxBlock) {
|
|
478
|
-
this.updatePosInline(inline, maxInline);
|
|
479
|
-
this.updatePosBlock(block, maxBlock);
|
|
480
|
-
}
|
|
481
|
-
updateVisInline() {
|
|
482
|
-
var _a, _b;
|
|
483
|
-
// todo: avoid starting from zero
|
|
484
|
-
let axisCursor = 0;
|
|
485
|
-
let pxCursor = this.colSize(axisCursor, 'grid');
|
|
486
|
-
while (pxCursor < this.posInline) {
|
|
487
|
-
axisCursor += 1;
|
|
488
|
-
pxCursor += this.colSize(axisCursor, 'grid') + gap;
|
|
489
|
-
}
|
|
490
|
-
this.visColMin = axisCursor;
|
|
491
|
-
this.visColMinStart = pxCursor - this.colSize(axisCursor, 'grid') - gap;
|
|
492
|
-
const visColMinEnd = pxCursor;
|
|
493
|
-
while (pxCursor < this.posInline + this.sizeInline) {
|
|
494
|
-
axisCursor += 1;
|
|
495
|
-
pxCursor += this.colSize(axisCursor, 'grid') + gap;
|
|
496
|
-
}
|
|
497
|
-
this.visColMax = Math.min(this.limitColumns, axisCursor + 1);
|
|
498
|
-
const visColMaxStart = pxCursor - this.colSize(axisCursor, 'grid') - gap;
|
|
499
|
-
const visColMaxEnd = pxCursor;
|
|
500
|
-
const bifurcateStart = visColMaxStart - this.sizeInline;
|
|
501
|
-
const bifurcateEnd = visColMaxEnd - this.sizeInline;
|
|
502
|
-
const bounds = [this.visColMinStart, visColMinEnd, bifurcateStart, bifurcateEnd].sort((a, b) => a - b);
|
|
503
|
-
let boundsCursor = 1;
|
|
504
|
-
while (bounds[boundsCursor] < this.posInline && boundsCursor < 3) {
|
|
505
|
-
boundsCursor += 1;
|
|
506
|
-
}
|
|
507
|
-
this.binInlineMin = bounds[boundsCursor - 1];
|
|
508
|
-
this.binInlineMax = bounds[boundsCursor];
|
|
509
|
-
this.templateGridColumns = [...Array(this.visColMax - this.visColMin)]
|
|
510
|
-
.map((_, c0) => `${this.colSize(this.visColMin + c0, 'grid')}px`)
|
|
511
|
-
.join(' ');
|
|
512
|
-
this.templatefrozenColsStart = [...Array((_a = this.frozen.frozenColsStart) !== null && _a !== void 0 ? _a : 0)]
|
|
513
|
-
.map((_, c0) => `${this.colSize(c0, 'frozenColsStart')}px`)
|
|
514
|
-
.join(' ');
|
|
515
|
-
this.templatefrozenColsEnd = [...Array((_b = this.frozen.frozenColsEnd) !== null && _b !== void 0 ? _b : 0)]
|
|
516
|
-
.map((_, c0) => `${this.colSize(c0, 'frozenColsEnd')}px`)
|
|
517
|
-
.join(' ');
|
|
518
|
-
}
|
|
519
|
-
updateVisBlock() {
|
|
520
|
-
var _a, _b;
|
|
521
|
-
// todo: avoid starting from zero
|
|
522
|
-
let axisCursor = 0;
|
|
523
|
-
let pxCursor = this.rowSize(axisCursor, 'grid');
|
|
524
|
-
while (pxCursor < this.posBlock) {
|
|
525
|
-
axisCursor += 1;
|
|
526
|
-
pxCursor += this.rowSize(axisCursor, 'grid') + gap;
|
|
527
|
-
}
|
|
528
|
-
this.visRowMin = axisCursor;
|
|
529
|
-
this.visRowMinStart = pxCursor - this.rowSize(axisCursor, 'grid') - gap;
|
|
530
|
-
const visRowMinEnd = pxCursor;
|
|
531
|
-
while (pxCursor < this.posBlock + this.sizeBlock) {
|
|
532
|
-
axisCursor += 1;
|
|
533
|
-
pxCursor += this.rowSize(axisCursor, 'grid') + gap;
|
|
534
|
-
}
|
|
535
|
-
this.visRowMax = Math.min(this.limitRows, axisCursor + 1);
|
|
536
|
-
const visRowMaxStart = pxCursor - this.rowSize(axisCursor, 'grid') - gap;
|
|
537
|
-
const visRowMaxEnd = pxCursor;
|
|
538
|
-
const bifurcateStart = visRowMaxStart - this.sizeBlock;
|
|
539
|
-
const bifurcateEnd = visRowMaxEnd - this.sizeBlock;
|
|
540
|
-
const bounds = [this.visRowMinStart, visRowMinEnd, bifurcateStart, bifurcateEnd].sort((a, b) => a - b);
|
|
541
|
-
let boundsCursor = 1;
|
|
542
|
-
while (bounds[boundsCursor] < this.posBlock && boundsCursor < 3) {
|
|
543
|
-
boundsCursor += 1;
|
|
544
|
-
}
|
|
545
|
-
this.binBlockMin = bounds[boundsCursor - 1];
|
|
546
|
-
this.binBlockMax = bounds[boundsCursor];
|
|
547
|
-
this.templateGridRows = [...Array(this.visRowMax - this.visRowMin)]
|
|
548
|
-
.map((_, r0) => `${this.rowSize(this.visRowMin + r0, 'grid')}px`)
|
|
549
|
-
.join(' ');
|
|
550
|
-
this.templatefrozenRowsStart = [...Array((_a = this.frozen.frozenRowsStart) !== null && _a !== void 0 ? _a : 0)]
|
|
551
|
-
.map((_, r0) => `${this.rowSize(r0, 'frozenRowsStart')}px`)
|
|
552
|
-
.join(' ');
|
|
553
|
-
this.templatefrozenRowsEnd = [...Array((_b = this.frozen.frozenRowsEnd) !== null && _b !== void 0 ? _b : 0)]
|
|
554
|
-
.map((_, r0) => `${this.rowSize(r0, 'frozenRowsEnd')}px`)
|
|
555
|
-
.join(' ');
|
|
556
|
-
}
|
|
557
|
-
updateVis() {
|
|
558
|
-
this.updateVisInline();
|
|
559
|
-
this.updateVisBlock();
|
|
560
|
-
}
|
|
561
|
-
updateCells(includeFixed) {
|
|
562
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
563
|
-
this.cells.grid = this.getCells({
|
|
564
|
-
start: { col: this.visColMin, row: this.visRowMin },
|
|
565
|
-
end: { col: this.visColMax, row: this.visRowMax },
|
|
566
|
-
}, 'grid');
|
|
567
|
-
Object.entries(this.frozen)
|
|
568
|
-
.filter(([_, limit]) => limit && limit > 0)
|
|
569
|
-
.forEach(([plane, limit]) => {
|
|
570
|
-
this.cells[plane] = this.getCells(plane.startsWith('frozenRows')
|
|
571
|
-
? {
|
|
572
|
-
start: { col: this.visColMin, row: 0 },
|
|
573
|
-
end: { col: this.visColMax, row: limit },
|
|
574
|
-
}
|
|
575
|
-
: {
|
|
576
|
-
start: { col: 0, row: this.visRowMin },
|
|
577
|
-
end: { col: limit, row: this.visRowMax },
|
|
578
|
-
}, plane);
|
|
579
|
-
});
|
|
580
|
-
if (includeFixed) {
|
|
581
|
-
if (((_a = this.frozen.frozenColsStart) !== null && _a !== void 0 ? _a : 0) > 0 && ((_b = this.frozen.frozenRowsStart) !== null && _b !== void 0 ? _b : 0) > 0) {
|
|
582
|
-
this.cells.fixedStartStart = this.getCells({
|
|
583
|
-
start: { col: 0, row: 0 },
|
|
584
|
-
end: { col: this.frozen.frozenColsStart, row: this.frozen.frozenRowsStart },
|
|
585
|
-
}, 'fixedStartStart');
|
|
586
|
-
}
|
|
587
|
-
if (((_c = this.frozen.frozenColsEnd) !== null && _c !== void 0 ? _c : 0) > 0 && ((_d = this.frozen.frozenRowsStart) !== null && _d !== void 0 ? _d : 0) > 0) {
|
|
588
|
-
this.cells.fixedStartEnd = this.getCells({
|
|
589
|
-
start: { col: 0, row: 0 },
|
|
590
|
-
end: { col: this.frozen.frozenColsEnd, row: this.frozen.frozenRowsStart },
|
|
591
|
-
}, 'fixedStartEnd');
|
|
592
|
-
}
|
|
593
|
-
if (((_e = this.frozen.frozenColsStart) !== null && _e !== void 0 ? _e : 0) > 0 && ((_f = this.frozen.frozenRowsEnd) !== null && _f !== void 0 ? _f : 0) > 0) {
|
|
594
|
-
this.cells.fixedEndStart = this.getCells({
|
|
595
|
-
start: { col: 0, row: 0 },
|
|
596
|
-
end: { col: this.frozen.frozenColsStart, row: this.frozen.frozenRowsEnd },
|
|
597
|
-
}, 'fixedEndStart');
|
|
598
|
-
}
|
|
599
|
-
if (((_g = this.frozen.frozenColsEnd) !== null && _g !== void 0 ? _g : 0) > 0 && ((_h = this.frozen.frozenRowsEnd) !== null && _h !== void 0 ? _h : 0) > 0) {
|
|
600
|
-
this.cells.fixedEndEnd = this.getCells({
|
|
601
|
-
start: { col: 0, row: 0 },
|
|
602
|
-
end: { col: this.frozen.frozenColsEnd, row: this.frozen.frozenRowsEnd },
|
|
603
|
-
}, 'fixedEndEnd');
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
// Focus handlers
|
|
608
|
-
setFocus(coords, snap = true) {
|
|
609
|
-
this.setFocusedCell(coords);
|
|
610
|
-
this.focusActive = true;
|
|
611
|
-
if (snap) {
|
|
612
|
-
this.snapPosToFocusedCell();
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
handleFocus(event) {
|
|
616
|
-
const cellCoords = closestCell(event.target);
|
|
617
|
-
if (cellCoords || targetIsPlane(event.target)) {
|
|
618
|
-
this.focusActive = true;
|
|
619
|
-
if (cellCoords) {
|
|
620
|
-
this.setFocusedCell(cellCoords);
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
handleBlur(event) {
|
|
625
|
-
// Only unset `focusActive` if focus is moving to an element outside the grid.
|
|
626
|
-
if (event.relatedTarget && !event.relatedTarget.closest(`[data-grid="${this.gridId}"]`)) {
|
|
627
|
-
this.focusActive = false;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
focusedCellQuery() {
|
|
631
|
-
return `[data-dx-grid-plane=${this.focusedCell.plane}] [aria-colindex="${this.focusedCell.col}"][aria-rowindex="${this.focusedCell.row}"]`;
|
|
632
|
-
}
|
|
633
|
-
focusedPlaneQuery() {
|
|
634
|
-
return `[data-dx-grid-plane=${this.focusedCell.plane}]`;
|
|
635
|
-
}
|
|
636
|
-
focusedCellElement() {
|
|
637
|
-
var _a;
|
|
638
|
-
return (_a = this.gridRef.value) === null || _a === void 0 ? void 0 : _a.querySelector(this.focusedCellQuery());
|
|
639
|
-
}
|
|
640
|
-
focusedPlaneElement() {
|
|
641
|
-
var _a;
|
|
642
|
-
return (_a = this.gridRef.value) === null || _a === void 0 ? void 0 : _a.querySelector(this.focusedPlaneQuery());
|
|
643
|
-
}
|
|
644
|
-
//
|
|
645
|
-
// `outOfVis` returns by how many rows/cols the focused cell is outside of the `vis` range for an axis, inset by a
|
|
646
|
-
// `delta`, otherwise zero if it is within that range.
|
|
647
|
-
//
|
|
648
|
-
focusedCellRowOutOfVis() {
|
|
649
|
-
return this.focusedCell.row <= this.visRowMin
|
|
650
|
-
? this.focusedCell.row - this.visRowMin - 1
|
|
651
|
-
: this.focusedCell.row >= this.visRowMax - 1
|
|
652
|
-
? this.focusedCell.row + 2 - this.visRowMax
|
|
653
|
-
: 0;
|
|
654
|
-
}
|
|
655
|
-
focusedCellColOutOfVis() {
|
|
656
|
-
return this.focusedCell.col <= this.visColMin
|
|
657
|
-
? this.focusedCell.col - this.visColMin - 1
|
|
658
|
-
: this.focusedCell.col >= this.visColMax - 1
|
|
659
|
-
? this.focusedCell.col + 2 - this.visColMax
|
|
660
|
-
: 0;
|
|
661
|
-
}
|
|
662
|
-
focusedCellOutOfVis() {
|
|
663
|
-
switch (this.focusedCell.plane) {
|
|
664
|
-
case 'grid':
|
|
665
|
-
return { row: this.focusedCellRowOutOfVis(), col: this.focusedCellColOutOfVis() };
|
|
666
|
-
case 'frozenRowsStart':
|
|
667
|
-
case 'frozenRowsEnd':
|
|
668
|
-
return { col: this.focusedCellColOutOfVis(), row: 0 };
|
|
669
|
-
case 'frozenColsStart':
|
|
670
|
-
case 'frozenColsEnd':
|
|
671
|
-
return { col: 0, row: this.focusedCellRowOutOfVis() };
|
|
672
|
-
default:
|
|
673
|
-
return { col: 0, row: 0 };
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
clampCol(coords, deltaCol = 0) {
|
|
677
|
-
const colPlane = resolveColPlane(coords.plane);
|
|
678
|
-
const colMax = (colPlane === 'grid' ? this.limitColumns : this.frozen[colPlane]) - 1;
|
|
679
|
-
return Math.max(0, Math.min(colMax, coords.col + deltaCol));
|
|
680
|
-
}
|
|
681
|
-
clampRow(coords, deltaRow = 0) {
|
|
682
|
-
const rowPlane = resolveRowPlane(coords.plane);
|
|
683
|
-
const rowMax = (rowPlane === 'grid' ? this.limitRows : this.frozen[rowPlane]) - 1;
|
|
684
|
-
return Math.max(0, Math.min(rowMax, coords.row + deltaRow));
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* Moves focus to the cell with actual focus, otherwise moves focus to the viewport.
|
|
688
|
-
*/
|
|
689
|
-
refocus(increment = undefined, delta = 1) {
|
|
690
|
-
if (increment) {
|
|
691
|
-
switch (increment) {
|
|
692
|
-
case 'col': {
|
|
693
|
-
this.focusedCell.col = this.clampCol(this.focusedCell, delta);
|
|
694
|
-
break;
|
|
695
|
-
}
|
|
696
|
-
case 'row': {
|
|
697
|
-
this.focusedCell.row = this.clampRow(this.focusedCell, delta);
|
|
698
|
-
break;
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
this.snapPosToFocusedCell();
|
|
702
|
-
}
|
|
703
|
-
queueMicrotask(() => {
|
|
704
|
-
const cellElement = this.focusedCellElement();
|
|
705
|
-
if (cellElement) {
|
|
706
|
-
if (cellElement !== document.activeElement) {
|
|
707
|
-
cellElement.focus({ preventScroll: true });
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
else {
|
|
711
|
-
this.moveFocusToPlane();
|
|
712
|
-
}
|
|
713
|
-
});
|
|
714
|
-
}
|
|
715
|
-
clampPosInline(nextPos) {
|
|
716
|
-
return Math.max(0, Math.min(this.intrinsicInlineSize - this.sizeInline, nextPos));
|
|
717
|
-
}
|
|
718
|
-
clampPosBlock(nextPos) {
|
|
719
|
-
return Math.max(0, Math.min(this.intrinsicBlockSize - this.sizeBlock, nextPos));
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* Calculate the pixel offset for a given column in a plane.
|
|
723
|
-
* Sums all column sizes plus gaps up to the target column.
|
|
724
|
-
*/
|
|
725
|
-
inlineOffset(col, plane) {
|
|
726
|
-
return [...Array(col)].reduce((acc, _, c0) => {
|
|
727
|
-
return acc + this.colSize(c0, plane) + gap;
|
|
728
|
-
}, 0);
|
|
729
|
-
}
|
|
730
|
-
/**
|
|
731
|
-
* Calculate the pixel offset for a given row in a plane.
|
|
732
|
-
* Sums all row sizes plus gaps up to the target row.
|
|
733
|
-
*/
|
|
734
|
-
blockOffset(row, plane) {
|
|
735
|
-
return [...Array(row)].reduce((acc, _, r0) => {
|
|
736
|
-
return acc + this.rowSize(r0, plane) + gap;
|
|
737
|
-
}, 0);
|
|
738
|
-
}
|
|
739
|
-
/**
|
|
740
|
-
* Updates `pos` so that a cell in focus is fully within the viewport
|
|
741
|
-
*/
|
|
742
|
-
snapPosToFocusedCell() {
|
|
743
|
-
const outOfVis = this.focusedCellOutOfVis();
|
|
744
|
-
if (outOfVis.col < 0) {
|
|
745
|
-
// align viewport start edge with focused cell start edge
|
|
746
|
-
this.posInline = this.clampPosInline(this.inlineOffset(this.focusedCell.col, 'grid'));
|
|
747
|
-
this.updateVisInline();
|
|
748
|
-
}
|
|
749
|
-
else if (outOfVis.col > 0) {
|
|
750
|
-
// align viewport end edge with focused cell end edge
|
|
751
|
-
this.posInline = this.clampPosInline(this.inlineOffset(this.focusedCell.col + 1, 'grid') - this.sizeInline - gap);
|
|
752
|
-
this.updateVisInline();
|
|
753
|
-
}
|
|
754
|
-
if (outOfVis.row < 0) {
|
|
755
|
-
// align viewport start edge with focused cell start edge
|
|
756
|
-
this.posBlock = this.clampPosBlock(this.blockOffset(this.focusedCell.row, 'grid'));
|
|
757
|
-
this.updateVisBlock();
|
|
758
|
-
}
|
|
759
|
-
else if (outOfVis.row > 0) {
|
|
760
|
-
// align viewport end edge with focused cell end edge
|
|
761
|
-
this.posBlock = this.clampPosBlock(this.blockOffset(this.focusedCell.row + 1, 'grid') - this.sizeBlock - gap);
|
|
762
|
-
this.updateVisBlock();
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
scrollToCoord({ coords }) {
|
|
766
|
-
const plane = coords.plane;
|
|
767
|
-
const { row, col } = coords;
|
|
768
|
-
this.updatePosBlock(this.blockOffset(row, plane));
|
|
769
|
-
this.updatePosInline(this.inlineOffset(col, plane));
|
|
770
|
-
}
|
|
771
|
-
scrollToColumn(col) {
|
|
772
|
-
this.updatePosInline(this.inlineOffset(col, 'grid'));
|
|
773
|
-
}
|
|
774
|
-
scrollToRow(row) {
|
|
775
|
-
this.updatePosBlock(this.blockOffset(row, 'grid'));
|
|
776
|
-
}
|
|
777
|
-
scrollToEndRow() {
|
|
778
|
-
this.updatePosBlock(Infinity);
|
|
779
|
-
}
|
|
780
|
-
//
|
|
781
|
-
// Map scroll DOM methods to virtualized value.
|
|
782
|
-
//
|
|
783
|
-
get scrollLeft() {
|
|
784
|
-
return this.posInline;
|
|
785
|
-
}
|
|
786
|
-
set scrollLeft(nextValue) {
|
|
787
|
-
this.posInline = nextValue;
|
|
788
|
-
this.maybeUpdateVisInline();
|
|
789
|
-
}
|
|
790
|
-
get scrollTop() {
|
|
791
|
-
return this.posBlock;
|
|
792
|
-
}
|
|
793
|
-
set scrollTop(nextValue) {
|
|
794
|
-
this.posBlock = nextValue;
|
|
795
|
-
this.maybeUpdateVisBlock();
|
|
796
|
-
}
|
|
797
|
-
//
|
|
798
|
-
// Resize handlers
|
|
799
|
-
//
|
|
800
|
-
axisResizeable(plane, axis, index) {
|
|
801
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
802
|
-
return axis === 'col'
|
|
803
|
-
? !!((_c = (_b = (_a = this.columns[plane]) === null || _a === void 0 ? void 0 : _a[index]) === null || _b === void 0 ? void 0 : _b.resizeable) !== null && _c !== void 0 ? _c : (_d = this.columnDefault[plane]) === null || _d === void 0 ? void 0 : _d.resizeable)
|
|
804
|
-
: !!((_g = (_f = (_e = this.rows[plane]) === null || _e === void 0 ? void 0 : _e[index]) === null || _f === void 0 ? void 0 : _f.resizeable) !== null && _g !== void 0 ? _g : (_h = this.rowDefault[plane]) === null || _h === void 0 ? void 0 : _h.resizeable);
|
|
805
|
-
}
|
|
806
|
-
handleAxisResizeInternal(event) {
|
|
807
|
-
event.stopPropagation();
|
|
808
|
-
const { plane, axis, delta, size, index, state } = event;
|
|
809
|
-
if (axis === 'col') {
|
|
810
|
-
const nextSize = Math.max(sizeColMin, Math.min(sizeColMax, size + delta));
|
|
811
|
-
this.colSizes = { ...this.colSizes, [plane]: { ...this.colSizes[plane], [index]: nextSize } };
|
|
812
|
-
this.updateVisInline();
|
|
813
|
-
this.updateIntrinsicInlineSize();
|
|
814
|
-
}
|
|
815
|
-
else {
|
|
816
|
-
const nextSize = Math.max(sizeRowMin, Math.min(sizeRowMax, size + delta));
|
|
817
|
-
this.rowSizes = { ...this.colSizes, [plane]: { ...this.rowSizes[plane], [index]: nextSize } };
|
|
818
|
-
this.updateVisBlock();
|
|
819
|
-
this.updateIntrinsicBlockSize();
|
|
820
|
-
}
|
|
821
|
-
if (state === 'dropped') {
|
|
822
|
-
this.dispatchEvent(new DxAxisResize({
|
|
823
|
-
plane,
|
|
824
|
-
axis,
|
|
825
|
-
index,
|
|
826
|
-
size: this[`${axis}Size`](index, plane),
|
|
827
|
-
}));
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
//
|
|
831
|
-
// Render and other lifecycle methods
|
|
832
|
-
//
|
|
833
|
-
// TODO(thure): This is for rendering presentational objects superimposed onto the canonical grid (e.g. DnD drop line for #8108).
|
|
834
|
-
renderPresentationLayer(offsetInline, offsetBlock) {
|
|
835
|
-
var _a, _b, _c, _d, _e, _f;
|
|
836
|
-
const visibleCols = this.visColMax - this.visColMin;
|
|
837
|
-
const visibleRows = this.visRowMax - this.visRowMin;
|
|
838
|
-
return html `<div
|
|
839
|
-
role="none"
|
|
840
|
-
class="dx-grid-layer--presentation"
|
|
841
|
-
style=${styleMap({
|
|
842
|
-
gridTemplateColumns: [
|
|
843
|
-
...[...Array((_a = this.frozen.frozenColsStart) !== null && _a !== void 0 ? _a : 0)].map((_, c0) => `${this.colSize(c0, 'frozenColsStart')}px`),
|
|
844
|
-
...[...Array(visibleCols)].map((_, c0) => c0 === visibleCols - 1
|
|
845
|
-
? '1fr'
|
|
846
|
-
: `${this.colSize(this.visColMin + c0, 'grid') + (c0 === 0 ? offsetInline : 0)}px`),
|
|
847
|
-
...[...Array((_b = this.frozen.frozenColsEnd) !== null && _b !== void 0 ? _b : 0)].map((_, c0) => `${this.colSize(c0, 'frozenColsEnd')}px`),
|
|
848
|
-
].join(' '),
|
|
849
|
-
gridTemplateRows: [
|
|
850
|
-
...[...Array((_c = this.frozen.frozenRowsStart) !== null && _c !== void 0 ? _c : 0)].map((_, r0) => `${this.rowSize(r0, 'frozenRowsStart')}px`),
|
|
851
|
-
...[...Array(visibleRows)].map((_, r0) => r0 === visibleRows - 1
|
|
852
|
-
? '1fr'
|
|
853
|
-
: `${this.rowSize(this.visRowMin + r0, 'grid') + (r0 === 0 ? offsetBlock : 0)}px`),
|
|
854
|
-
...[...Array((_d = this.frozen.frozenRowsEnd) !== null && _d !== void 0 ? _d : 0)].map((_, r0) => `${this.rowSize(r0, 'frozenRowsEnd')}px`),
|
|
855
|
-
].join(' '),
|
|
856
|
-
})}
|
|
857
|
-
>
|
|
858
|
-
${
|
|
859
|
-
/* TODO(thure): These are debug cells, remove when rendering actual overlay content. */ [
|
|
860
|
-
...Array(((_e = this.frozen.frozenRowsStart) !== null && _e !== void 0 ? _e : 0) + visibleRows + ((_f = this.frozen.frozenRowsEnd) !== null && _f !== void 0 ? _f : 0)),
|
|
861
|
-
].map((_, r0) => {
|
|
862
|
-
var _a, _b;
|
|
863
|
-
return [...Array(((_a = this.frozen.frozenColsStart) !== null && _a !== void 0 ? _a : 0) + visibleCols + ((_b = this.frozen.frozenColsEnd) !== null && _b !== void 0 ? _b : 0))].map((_, c0) => html `<div
|
|
864
|
-
role="none"
|
|
865
|
-
class="dx-grid-layer--presentation__cell"
|
|
866
|
-
style="grid-column:${c0 + 1};grid-row:${r0 + 1}"
|
|
867
|
-
></div>`);
|
|
868
|
-
})}
|
|
869
|
-
</div>`;
|
|
870
|
-
}
|
|
871
|
-
renderFixed(plane, selection) {
|
|
872
|
-
const colPlane = resolveColPlane(plane);
|
|
873
|
-
const rowPlane = resolveRowPlane(plane);
|
|
874
|
-
const cols = this.frozen[colPlane];
|
|
875
|
-
const rows = this.frozen[rowPlane];
|
|
876
|
-
return (cols !== null && cols !== void 0 ? cols : 0) > 0 && (rows !== null && rows !== void 0 ? rows : 0) > 0
|
|
877
|
-
? html `<div
|
|
878
|
-
role="none"
|
|
879
|
-
tabindex="0"
|
|
880
|
-
data-dx-grid-plane=${plane}
|
|
881
|
-
data-dx-grid-plane-row=${plane === 'fixedStartStart' || plane === 'fixedStartEnd' ? 0 : 2}
|
|
882
|
-
data-dx-grid-plane-col=${plane === 'fixedStartStart' || plane === 'fixedEndStart' ? 0 : 2}
|
|
883
|
-
class="dx-grid__plane--fixed"
|
|
884
|
-
style=${styleMap({
|
|
885
|
-
'grid-template-columns': this[`template${colPlane}`],
|
|
886
|
-
'grid-template-rows': this[`template${rowPlane}`],
|
|
887
|
-
})}
|
|
888
|
-
>
|
|
889
|
-
${[...Array(rows)].map((_, r) => {
|
|
890
|
-
return [...Array(cols)].map((_, c) => {
|
|
891
|
-
return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection));
|
|
892
|
-
});
|
|
893
|
-
})}
|
|
894
|
-
</div>`
|
|
895
|
-
: null;
|
|
896
|
-
}
|
|
897
|
-
renderFrozenRows(plane, visibleCols, offsetInline, selection) {
|
|
898
|
-
const rowPlane = resolveRowPlane(plane);
|
|
899
|
-
const rows = this.frozen[rowPlane];
|
|
900
|
-
return (rows !== null && rows !== void 0 ? rows : 0) > 0
|
|
901
|
-
? html `<div
|
|
902
|
-
role="none"
|
|
903
|
-
class="dx-grid__plane--frozen-row"
|
|
904
|
-
tabindex="0"
|
|
905
|
-
data-dx-grid-plane=${plane}
|
|
906
|
-
data-dx-grid-plane-row=${plane === 'frozenRowsStart' ? 0 : 2}
|
|
907
|
-
data-dx-grid-plane-col="1"
|
|
908
|
-
>
|
|
909
|
-
<div
|
|
910
|
-
role="none"
|
|
911
|
-
class="dx-grid__plane--frozen-row__content"
|
|
912
|
-
style="transform:translate3d(${offsetInline}px,0,0);grid-template-columns:${this
|
|
913
|
-
.templateGridColumns};grid-template-rows:${this[`template${rowPlane}`]}"
|
|
914
|
-
>
|
|
915
|
-
${[...Array(rows)].map((_, r) => {
|
|
916
|
-
return [...Array(visibleCols)].map((_, c0) => {
|
|
917
|
-
const c = this.visColMin + c0;
|
|
918
|
-
return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection), c0, r);
|
|
919
|
-
});
|
|
920
|
-
})}
|
|
921
|
-
</div>
|
|
922
|
-
</div>`
|
|
923
|
-
: null;
|
|
924
|
-
}
|
|
925
|
-
renderFrozenColumns(plane, visibleRows, offsetBlock, selection) {
|
|
926
|
-
const colPlane = resolveColPlane(plane);
|
|
927
|
-
const cols = this.frozen[colPlane];
|
|
928
|
-
return (cols !== null && cols !== void 0 ? cols : 0) > 0
|
|
929
|
-
? html `<div
|
|
930
|
-
role="none"
|
|
931
|
-
class="dx-grid__plane--frozen-col"
|
|
932
|
-
tabindex="0"
|
|
933
|
-
data-dx-grid-plane=${plane}
|
|
934
|
-
data-dx-grid-plane-col=${plane === 'frozenColsStart' ? 0 : 2}
|
|
935
|
-
data-dx-grid-plane-row="1"
|
|
936
|
-
>
|
|
937
|
-
<div
|
|
938
|
-
role="none"
|
|
939
|
-
class="dx-grid__plane--frozen-col__content"
|
|
940
|
-
style="transform:translate3d(0,${offsetBlock}px,0);grid-template-rows:${this
|
|
941
|
-
.templateGridRows};grid-template-columns:${this[`template${colPlane}`]}"
|
|
942
|
-
>
|
|
943
|
-
${[...Array(visibleRows)].map((_, r0) => {
|
|
944
|
-
return [...Array(cols)].map((_, c) => {
|
|
945
|
-
const r = this.visRowMin + r0;
|
|
946
|
-
return this.renderCell(c, r, plane, cellSelected(c, r, plane, selection), c, r0);
|
|
947
|
-
});
|
|
948
|
-
})}
|
|
949
|
-
</div>
|
|
950
|
-
</div>`
|
|
951
|
-
: null;
|
|
952
|
-
}
|
|
953
|
-
cellReadonly(col, row, plane) {
|
|
954
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
955
|
-
const colPlane = resolveColPlane(plane);
|
|
956
|
-
const rowPlane = resolveRowPlane(plane);
|
|
957
|
-
// Check cell-specific setting first.
|
|
958
|
-
const cellReadonly = (_a = this.cell(col, row, plane)) === null || _a === void 0 ? void 0 : _a.readonly;
|
|
959
|
-
if (cellReadonly !== undefined) {
|
|
960
|
-
return isReadonly(cellReadonly);
|
|
961
|
-
}
|
|
962
|
-
// Check column/row defaults.
|
|
963
|
-
const colReadOnly = (_e = (_d = (_c = (_b = this.columns) === null || _b === void 0 ? void 0 : _b[colPlane]) === null || _c === void 0 ? void 0 : _c[col]) === null || _d === void 0 ? void 0 : _d.readonly) !== null && _e !== void 0 ? _e : (_g = (_f = this.columnDefault) === null || _f === void 0 ? void 0 : _f[colPlane]) === null || _g === void 0 ? void 0 : _g.readonly;
|
|
964
|
-
const rowReadOnly = (_l = (_k = (_j = (_h = this.rows) === null || _h === void 0 ? void 0 : _h[rowPlane]) === null || _j === void 0 ? void 0 : _j[row]) === null || _k === void 0 ? void 0 : _k.readonly) !== null && _l !== void 0 ? _l : (_o = (_m = this.rowDefault) === null || _m === void 0 ? void 0 : _m[rowPlane]) === null || _o === void 0 ? void 0 : _o.readonly;
|
|
965
|
-
return isReadonly(colReadOnly) || isReadonly(rowReadOnly);
|
|
966
|
-
}
|
|
967
|
-
/**
|
|
968
|
-
* Determines if the cell's text content should be selectable based on its readonly value.
|
|
969
|
-
* @returns true if the cells text content is selectable, false otherwise.
|
|
970
|
-
*/
|
|
971
|
-
cellTextSelectable(col, row, plane) {
|
|
972
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
973
|
-
const colPlane = resolveColPlane(plane);
|
|
974
|
-
const rowPlane = resolveRowPlane(plane);
|
|
975
|
-
// Check cell-specific setting first.
|
|
976
|
-
const cellReadonly = (_a = this.cell(col, row, plane)) === null || _a === void 0 ? void 0 : _a.readonly;
|
|
977
|
-
if (cellReadonly !== undefined) {
|
|
978
|
-
return cellReadonly === 'text-select';
|
|
979
|
-
}
|
|
980
|
-
// Check column/row defaults.
|
|
981
|
-
const colReadonly = (_e = (_d = (_c = (_b = this.columns) === null || _b === void 0 ? void 0 : _b[colPlane]) === null || _c === void 0 ? void 0 : _c[col]) === null || _d === void 0 ? void 0 : _d.readonly) !== null && _e !== void 0 ? _e : (_g = (_f = this.columnDefault) === null || _f === void 0 ? void 0 : _f[colPlane]) === null || _g === void 0 ? void 0 : _g.readonly;
|
|
982
|
-
const rowReadonly = (_l = (_k = (_j = (_h = this.rows) === null || _h === void 0 ? void 0 : _h[rowPlane]) === null || _j === void 0 ? void 0 : _j[row]) === null || _k === void 0 ? void 0 : _k.readonly) !== null && _l !== void 0 ? _l : (_o = (_m = this.rowDefault) === null || _m === void 0 ? void 0 : _m[rowPlane]) === null || _o === void 0 ? void 0 : _o.readonly;
|
|
983
|
-
return colReadonly === 'text-select' || rowReadonly === 'text-select';
|
|
984
|
-
}
|
|
985
|
-
renderCell(col, row, plane, selected, visCol = col, visRow = row) {
|
|
986
|
-
var _a, _b;
|
|
987
|
-
const cell = this.cell(col, row, plane);
|
|
988
|
-
const active = this.cellActive(col, row, plane);
|
|
989
|
-
const readonly = this.cellReadonly(col, row, plane);
|
|
990
|
-
const textSelectable = this.cellTextSelectable(col, row, plane);
|
|
991
|
-
const resizeIndex = (cell === null || cell === void 0 ? void 0 : cell.resizeHandle) ? (cell.resizeHandle === 'col' ? col : row) : undefined;
|
|
992
|
-
const resizePlane = (cell === null || cell === void 0 ? void 0 : cell.resizeHandle) ? resolveFrozenPlane(cell.resizeHandle, plane) : undefined;
|
|
993
|
-
const accessory = (cell === null || cell === void 0 ? void 0 : cell.accessoryHtml) ? staticHtml `${unsafeStatic(cell.accessoryHtml)}` : null;
|
|
994
|
-
return html `<div
|
|
995
|
-
role="gridcell"
|
|
996
|
-
tabindex="0"
|
|
997
|
-
aria-selected=${selected ? 'true' : nothing}
|
|
998
|
-
aria-readonly=${readonly ? 'true' : nothing}
|
|
999
|
-
class=${(_a = cell === null || cell === void 0 ? void 0 : cell.className) !== null && _a !== void 0 ? _a : nothing}
|
|
1000
|
-
data-refs=${(_b = cell === null || cell === void 0 ? void 0 : cell.dataRefs) !== null && _b !== void 0 ? _b : nothing}
|
|
1001
|
-
?data-dx-active=${active}
|
|
1002
|
-
data-text-selectable=${textSelectable ? 'true' : 'false'}
|
|
1003
|
-
data-dx-grid-action="cell"
|
|
1004
|
-
aria-colindex=${col}
|
|
1005
|
-
aria-rowindex=${row}
|
|
1006
|
-
style="grid-column:${visCol + 1};grid-row:${visRow + 1}"
|
|
1007
|
-
>
|
|
1008
|
-
${this.mode !== 'browse' && active ? null : cell === null || cell === void 0 ? void 0 : cell.value}${this.mode !== 'browse' && active
|
|
1009
|
-
? null
|
|
1010
|
-
: accessory}${(cell === null || cell === void 0 ? void 0 : cell.resizeHandle) &&
|
|
1011
|
-
this.mode === 'browse' &&
|
|
1012
|
-
this.axisResizeable(resizePlane, cell.resizeHandle, resizeIndex)
|
|
1013
|
-
? html `<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>`
|
|
1019
|
-
: null}
|
|
1020
|
-
</div>`;
|
|
1021
|
-
}
|
|
1022
|
-
render() {
|
|
1023
|
-
const visibleCols = this.visColMax - this.visColMin;
|
|
1024
|
-
const visibleRows = this.visRowMax - this.visRowMin;
|
|
1025
|
-
const offsetInline = this.visColMinStart - this.posInline + gap;
|
|
1026
|
-
const offsetBlock = this.visRowMinStart - this.posBlock + gap;
|
|
1027
|
-
const selection = selectionProps(this.selectionStart, this.selectionEnd);
|
|
1028
|
-
return html `<style>
|
|
1029
|
-
${this.activeRefs
|
|
1030
|
-
.split(' ')
|
|
1031
|
-
.filter((value) => value)
|
|
1032
|
-
.map(
|
|
1033
|
-
// TODO(burdon): Consistent camelCase?
|
|
1034
|
-
(activeRef) => `[data-refs~="${activeRef}"] { background: var(--dx-grid-commented-active, var(--dx-gridCommentedActive)) !important; }`)
|
|
1035
|
-
.join('\n')}
|
|
1036
|
-
</style>
|
|
1037
|
-
<div
|
|
1038
|
-
role="none"
|
|
1039
|
-
class="dx-grid"
|
|
1040
|
-
style=${styleMap({
|
|
1041
|
-
'grid-template-columns': `${this.templatefrozenColsStart ? 'min-content ' : ''}minmax(0, ${Number.isFinite(this.limitColumns) ? `${Math.max(0, this.intrinsicInlineSize)}px` : '1fr'})${this.templatefrozenColsEnd ? ' min-content' : ''}`,
|
|
1042
|
-
'grid-template-rows': `${this.templatefrozenRowsStart ? 'min-content ' : ''}minmax(0, ${Number.isFinite(this.limitRows) ? `${Math.max(0, this.intrinsicBlockSize)}px` : '1fr'})${this.templatefrozenRowsEnd ? ' min-content' : ''}`,
|
|
1043
|
-
'--dx-grid-content-inline-size': Number.isFinite(this.limitColumns)
|
|
1044
|
-
? `${Math.max(0, this.totalIntrinsicInlineSize)}px`
|
|
1045
|
-
: 'max-content',
|
|
1046
|
-
'--dx-grid-content-block-size': Number.isFinite(this.limitRows)
|
|
1047
|
-
? `${Math.max(0, this.totalIntrinsicBlockSize)}px`
|
|
1048
|
-
: 'max-content',
|
|
1049
|
-
})}
|
|
1050
|
-
data-grid=${this.gridId}
|
|
1051
|
-
data-grid-mode=${this.mode}
|
|
1052
|
-
?data-grid-select=${selection.visible}
|
|
1053
|
-
${ref(this.gridRef)}
|
|
1054
|
-
>
|
|
1055
|
-
${this.renderFixed('fixedStartStart', selection)}${this.renderFrozenRows('frozenRowsStart', visibleCols, offsetInline, selection)}${this.renderFixed('fixedStartEnd', selection)}${this.renderFrozenColumns('frozenColsStart', visibleRows, offsetBlock, selection)}
|
|
1056
|
-
<div
|
|
1057
|
-
role="grid"
|
|
1058
|
-
class="dx-grid__plane--grid"
|
|
1059
|
-
tabindex="0"
|
|
1060
|
-
data-dx-grid-plane="grid"
|
|
1061
|
-
data-dx-grid-plane-row="1"
|
|
1062
|
-
data-dx-grid-plane-col="1"
|
|
1063
|
-
${ref(this.viewportRef)}
|
|
1064
|
-
>
|
|
1065
|
-
<div
|
|
1066
|
-
role="none"
|
|
1067
|
-
class="dx-grid__plane--grid__content"
|
|
1068
|
-
style="transform:translate3d(${offsetInline}px,${offsetBlock}px,0);grid-template-columns:${this
|
|
1069
|
-
.templateGridColumns};grid-template-rows:${this.templateGridRows};"
|
|
1070
|
-
>
|
|
1071
|
-
${[...Array(visibleRows)].map((_, r0) => {
|
|
1072
|
-
return [...Array(visibleCols)].map((_, c0) => {
|
|
1073
|
-
const c = c0 + this.visColMin;
|
|
1074
|
-
const r = r0 + this.visRowMin;
|
|
1075
|
-
return this.renderCell(c, r, 'grid', cellSelected(c, r, 'grid', selection), c0, r0);
|
|
1076
|
-
});
|
|
1077
|
-
})}
|
|
1078
|
-
</div>
|
|
1079
|
-
</div>
|
|
1080
|
-
${this.renderFrozenColumns('frozenColsEnd', visibleRows, offsetBlock, selection)}${this.renderFixed('fixedEndStart', selection)}${this.renderFrozenRows('frozenRowsEnd', visibleCols, offsetInline, selection)}${this.renderFixed('fixedEndEnd', selection)}
|
|
1081
|
-
</div>`;
|
|
1082
|
-
}
|
|
1083
|
-
updateIntrinsicInlineSize() {
|
|
1084
|
-
this.intrinsicInlineSize = Number.isFinite(this.limitColumns)
|
|
1085
|
-
? [...Array(this.limitColumns)].reduce((acc, _, c0) => acc + this.colSize(c0, 'grid'), 0) +
|
|
1086
|
-
gap * (this.limitColumns - 1)
|
|
1087
|
-
: Infinity;
|
|
1088
|
-
this.totalIntrinsicInlineSize =
|
|
1089
|
-
this.intrinsicInlineSize +
|
|
1090
|
-
(Number.isFinite(this.frozen.frozenColsStart)
|
|
1091
|
-
? [...Array(this.frozen.frozenColsStart)].reduce((acc, _, c0) => acc + gap + this.colSize(c0, 'frozenColsStart'), 0)
|
|
1092
|
-
: 0) +
|
|
1093
|
-
(Number.isFinite(this.frozen.frozenColsEnd)
|
|
1094
|
-
? [...Array(this.frozen.frozenColsEnd)].reduce((acc, _, c0) => acc + gap + this.colSize(c0, 'frozenColsEnd'), 0)
|
|
1095
|
-
: 0);
|
|
1096
|
-
}
|
|
1097
|
-
updateIntrinsicBlockSize() {
|
|
1098
|
-
this.intrinsicBlockSize = Number.isFinite(this.limitRows)
|
|
1099
|
-
? [...Array(this.limitRows)].reduce((acc, _, r0) => acc + this.rowSize(r0, 'grid'), 0) +
|
|
1100
|
-
gap * (this.limitRows - 1)
|
|
1101
|
-
: Infinity;
|
|
1102
|
-
this.totalIntrinsicBlockSize =
|
|
1103
|
-
this.intrinsicBlockSize +
|
|
1104
|
-
(Number.isFinite(this.frozen.frozenRowsStart)
|
|
1105
|
-
? [...Array(this.frozen.frozenRowsStart)].reduce((acc, _, r0) => acc + gap + this.rowSize(r0, 'frozenRowsStart'), 0)
|
|
1106
|
-
: 0) +
|
|
1107
|
-
(Number.isFinite(this.frozen.frozenRowsEnd)
|
|
1108
|
-
? [...Array(this.frozen.frozenRowsEnd)].reduce((acc, _, r0) => acc + gap + this.rowSize(r0, 'frozenRowsEnd'), 0)
|
|
1109
|
-
: 0);
|
|
1110
|
-
}
|
|
1111
|
-
updateIntrinsicSizes() {
|
|
1112
|
-
this.updateIntrinsicInlineSize();
|
|
1113
|
-
this.updateIntrinsicBlockSize();
|
|
1114
|
-
}
|
|
1115
|
-
computeColSizes() {
|
|
1116
|
-
var _a;
|
|
1117
|
-
this.colSizes = Object.entries((_a = this.columns) !== null && _a !== void 0 ? _a : {}).reduce((acc, [plane, planeColMeta]) => {
|
|
1118
|
-
acc[plane] = Object.entries(planeColMeta).reduce((planeAcc, [col, colMeta]) => {
|
|
1119
|
-
if (colMeta === null || colMeta === void 0 ? void 0 : colMeta.size) {
|
|
1120
|
-
planeAcc[col] = colMeta.size;
|
|
1121
|
-
}
|
|
1122
|
-
return planeAcc;
|
|
1123
|
-
}, {});
|
|
1124
|
-
return acc;
|
|
1125
|
-
}, { grid: {} });
|
|
1126
|
-
}
|
|
1127
|
-
computeRowSizes() {
|
|
1128
|
-
var _a;
|
|
1129
|
-
this.rowSizes = Object.entries((_a = this.rows) !== null && _a !== void 0 ? _a : {}).reduce((acc, [plane, planeRowMeta]) => {
|
|
1130
|
-
acc[plane] = Object.entries(planeRowMeta).reduce((planeAcc, [row, rowMeta]) => {
|
|
1131
|
-
if (rowMeta === null || rowMeta === void 0 ? void 0 : rowMeta.size) {
|
|
1132
|
-
planeAcc[row] = rowMeta.size;
|
|
1133
|
-
}
|
|
1134
|
-
return planeAcc;
|
|
1135
|
-
}, {});
|
|
1136
|
-
return acc;
|
|
1137
|
-
}, { grid: {} });
|
|
1138
|
-
}
|
|
1139
|
-
firstUpdated() {
|
|
1140
|
-
if (this.getCells) {
|
|
1141
|
-
this.updateCells(true);
|
|
1142
|
-
}
|
|
1143
|
-
this.observer.observe(this.viewportRef.value);
|
|
1144
|
-
this.computeColSizes();
|
|
1145
|
-
this.computeRowSizes();
|
|
1146
|
-
this.updateIntrinsicSizes();
|
|
1147
|
-
}
|
|
1148
|
-
willUpdate(changedProperties) {
|
|
1149
|
-
if (changedProperties.has('rowDefault') || changedProperties.has('rows') || changedProperties.has('limitRows')) {
|
|
1150
|
-
this.computeRowSizes();
|
|
1151
|
-
this.updateIntrinsicBlockSize();
|
|
1152
|
-
this.updatePosBlock();
|
|
1153
|
-
this.updateVisBlock();
|
|
1154
|
-
}
|
|
1155
|
-
if (changedProperties.has('columnDefault') ||
|
|
1156
|
-
changedProperties.has('columns') ||
|
|
1157
|
-
changedProperties.has('limitColumns')) {
|
|
1158
|
-
this.computeColSizes();
|
|
1159
|
-
this.updateIntrinsicInlineSize();
|
|
1160
|
-
this.updatePosInline();
|
|
1161
|
-
this.updateVisInline();
|
|
1162
|
-
}
|
|
1163
|
-
if (this.getCells &&
|
|
1164
|
-
(changedProperties.has('initialCells') ||
|
|
1165
|
-
changedProperties.has('visColMin') ||
|
|
1166
|
-
changedProperties.has('visColMax') ||
|
|
1167
|
-
changedProperties.has('visRowMin') ||
|
|
1168
|
-
changedProperties.has('visRowMax') ||
|
|
1169
|
-
changedProperties.has('columns') ||
|
|
1170
|
-
changedProperties.has('rows') ||
|
|
1171
|
-
changedProperties.has('limitColumns') ||
|
|
1172
|
-
changedProperties.has('limitRows'))) {
|
|
1173
|
-
this.updateCells(true);
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
updated(changedProperties) {
|
|
1177
|
-
// Update the focused element if there is a change in bounds (otherwise Lit keeps focus on the relative element).
|
|
1178
|
-
if (this.focusActive &&
|
|
1179
|
-
(changedProperties.has('visColMin') ||
|
|
1180
|
-
changedProperties.has('visColMax') ||
|
|
1181
|
-
changedProperties.has('visRowMin') ||
|
|
1182
|
-
changedProperties.has('visRowMax') ||
|
|
1183
|
-
changedProperties.has('focusedCell'))) {
|
|
1184
|
-
this.refocus();
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
updateIfWithinBounds({ col, row }) {
|
|
1188
|
-
if (col >= this.visColMin && col <= this.visColMax && row >= this.visRowMin && row <= this.visRowMax) {
|
|
1189
|
-
this.requestUpdate();
|
|
1190
|
-
return true;
|
|
1191
|
-
}
|
|
1192
|
-
return false;
|
|
1193
|
-
}
|
|
1194
|
-
disconnectedCallback() {
|
|
1195
|
-
var _a;
|
|
1196
|
-
super.disconnectedCallback();
|
|
1197
|
-
if (this.viewportRef.value) {
|
|
1198
|
-
this.observer.unobserve(this.viewportRef.value);
|
|
1199
|
-
}
|
|
1200
|
-
(_a = document.defaultView) === null || _a === void 0 ? void 0 : _a.removeEventListener('wheel', this.handleTopLevelWheel);
|
|
1201
|
-
}
|
|
1202
|
-
createRenderRoot() {
|
|
1203
|
-
return this;
|
|
1204
|
-
}
|
|
1205
|
-
};
|
|
1206
|
-
__decorate([
|
|
1207
|
-
property({ type: String })
|
|
1208
|
-
], DxGrid.prototype, "gridId", void 0);
|
|
1209
|
-
__decorate([
|
|
1210
|
-
property({ type: Object })
|
|
1211
|
-
], DxGrid.prototype, "rowDefault", void 0);
|
|
1212
|
-
__decorate([
|
|
1213
|
-
property({ type: Object })
|
|
1214
|
-
], DxGrid.prototype, "columnDefault", void 0);
|
|
1215
|
-
__decorate([
|
|
1216
|
-
property({ type: Object })
|
|
1217
|
-
], DxGrid.prototype, "rows", void 0);
|
|
1218
|
-
__decorate([
|
|
1219
|
-
property({ type: Object })
|
|
1220
|
-
], DxGrid.prototype, "columns", void 0);
|
|
1221
|
-
__decorate([
|
|
1222
|
-
property({ type: Object })
|
|
1223
|
-
], DxGrid.prototype, "initialCells", void 0);
|
|
1224
|
-
__decorate([
|
|
1225
|
-
property({ type: String })
|
|
1226
|
-
], DxGrid.prototype, "mode", void 0);
|
|
1227
|
-
__decorate([
|
|
1228
|
-
property({ type: Number })
|
|
1229
|
-
], DxGrid.prototype, "limitColumns", void 0);
|
|
1230
|
-
__decorate([
|
|
1231
|
-
property({ type: Number })
|
|
1232
|
-
], DxGrid.prototype, "limitRows", void 0);
|
|
1233
|
-
__decorate([
|
|
1234
|
-
property({ type: Object })
|
|
1235
|
-
], DxGrid.prototype, "frozen", void 0);
|
|
1236
|
-
__decorate([
|
|
1237
|
-
property({ type: String })
|
|
1238
|
-
], DxGrid.prototype, "overscroll", void 0);
|
|
1239
|
-
__decorate([
|
|
1240
|
-
property({ type: String })
|
|
1241
|
-
], DxGrid.prototype, "activeRefs", void 0);
|
|
1242
|
-
__decorate([
|
|
1243
|
-
state()
|
|
1244
|
-
], DxGrid.prototype, "cells", void 0);
|
|
1245
|
-
__decorate([
|
|
1246
|
-
state()
|
|
1247
|
-
], DxGrid.prototype, "posInline", void 0);
|
|
1248
|
-
__decorate([
|
|
1249
|
-
state()
|
|
1250
|
-
], DxGrid.prototype, "posBlock", void 0);
|
|
1251
|
-
__decorate([
|
|
1252
|
-
state()
|
|
1253
|
-
], DxGrid.prototype, "sizeInline", void 0);
|
|
1254
|
-
__decorate([
|
|
1255
|
-
state()
|
|
1256
|
-
], DxGrid.prototype, "sizeBlock", void 0);
|
|
1257
|
-
__decorate([
|
|
1258
|
-
state()
|
|
1259
|
-
], DxGrid.prototype, "visColMinStart", void 0);
|
|
1260
|
-
__decorate([
|
|
1261
|
-
state()
|
|
1262
|
-
], DxGrid.prototype, "visRowMinStart", void 0);
|
|
1263
|
-
__decorate([
|
|
1264
|
-
state()
|
|
1265
|
-
], DxGrid.prototype, "binInlineMin", void 0);
|
|
1266
|
-
__decorate([
|
|
1267
|
-
state()
|
|
1268
|
-
], DxGrid.prototype, "binInlineMax", void 0);
|
|
1269
|
-
__decorate([
|
|
1270
|
-
state()
|
|
1271
|
-
], DxGrid.prototype, "binBlockMin", void 0);
|
|
1272
|
-
__decorate([
|
|
1273
|
-
state()
|
|
1274
|
-
], DxGrid.prototype, "binBlockMax", void 0);
|
|
1275
|
-
__decorate([
|
|
1276
|
-
state()
|
|
1277
|
-
], DxGrid.prototype, "visColMin", void 0);
|
|
1278
|
-
__decorate([
|
|
1279
|
-
state()
|
|
1280
|
-
], DxGrid.prototype, "visColMax", void 0);
|
|
1281
|
-
__decorate([
|
|
1282
|
-
state()
|
|
1283
|
-
], DxGrid.prototype, "visRowMin", void 0);
|
|
1284
|
-
__decorate([
|
|
1285
|
-
state()
|
|
1286
|
-
], DxGrid.prototype, "visRowMax", void 0);
|
|
1287
|
-
__decorate([
|
|
1288
|
-
state()
|
|
1289
|
-
], DxGrid.prototype, "templateGridColumns", void 0);
|
|
1290
|
-
__decorate([
|
|
1291
|
-
state()
|
|
1292
|
-
], DxGrid.prototype, "templatefrozenColsStart", void 0);
|
|
1293
|
-
__decorate([
|
|
1294
|
-
state()
|
|
1295
|
-
], DxGrid.prototype, "templatefrozenColsEnd", void 0);
|
|
1296
|
-
__decorate([
|
|
1297
|
-
state()
|
|
1298
|
-
], DxGrid.prototype, "templateGridRows", void 0);
|
|
1299
|
-
__decorate([
|
|
1300
|
-
state()
|
|
1301
|
-
], DxGrid.prototype, "templatefrozenRowsStart", void 0);
|
|
1302
|
-
__decorate([
|
|
1303
|
-
state()
|
|
1304
|
-
], DxGrid.prototype, "templatefrozenRowsEnd", void 0);
|
|
1305
|
-
__decorate([
|
|
1306
|
-
state()
|
|
1307
|
-
], DxGrid.prototype, "pointer", void 0);
|
|
1308
|
-
__decorate([
|
|
1309
|
-
state()
|
|
1310
|
-
], DxGrid.prototype, "colSizes", void 0);
|
|
1311
|
-
__decorate([
|
|
1312
|
-
state()
|
|
1313
|
-
], DxGrid.prototype, "rowSizes", void 0);
|
|
1314
|
-
__decorate([
|
|
1315
|
-
state()
|
|
1316
|
-
], DxGrid.prototype, "focusActive", void 0);
|
|
1317
|
-
__decorate([
|
|
1318
|
-
state()
|
|
1319
|
-
], DxGrid.prototype, "focusedCell", void 0);
|
|
1320
|
-
__decorate([
|
|
1321
|
-
state()
|
|
1322
|
-
], DxGrid.prototype, "selectionStart", void 0);
|
|
1323
|
-
__decorate([
|
|
1324
|
-
state()
|
|
1325
|
-
], DxGrid.prototype, "selectionEnd", void 0);
|
|
1326
|
-
__decorate([
|
|
1327
|
-
state()
|
|
1328
|
-
], DxGrid.prototype, "intrinsicInlineSize", void 0);
|
|
1329
|
-
__decorate([
|
|
1330
|
-
state()
|
|
1331
|
-
], DxGrid.prototype, "intrinsicBlockSize", void 0);
|
|
1332
|
-
__decorate([
|
|
1333
|
-
state()
|
|
1334
|
-
], DxGrid.prototype, "totalIntrinsicInlineSize", void 0);
|
|
1335
|
-
__decorate([
|
|
1336
|
-
state()
|
|
1337
|
-
], DxGrid.prototype, "totalIntrinsicBlockSize", void 0);
|
|
1338
|
-
__decorate([
|
|
1339
|
-
state()
|
|
1340
|
-
], DxGrid.prototype, "observer", void 0);
|
|
1341
|
-
DxGrid = __decorate([
|
|
1342
|
-
customElement('dx-grid')
|
|
1343
|
-
], DxGrid);
|
|
1344
|
-
export { DxGrid };
|
|
1345
|
-
export { rowToA1Notation, colToA1Notation, closestAction, closestCell, parseCellIndex, toPlaneCellIndex, cellQuery, } from './util';
|
|
1346
|
-
export const commentedClassName = 'dx-grid__cell--commented';
|
|
1347
|
-
//# sourceMappingURL=dx-grid.js.map
|