@ember-lattice/ember 0.0.0-stage → 1.0.0
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/CHANGELOG.md +18 -0
- package/LICENSE.md +21 -0
- package/NOTICE +30 -0
- package/README.md +139 -2
- package/addon-main.cjs +4 -0
- package/declarations/board/lattice-board.d.ts +122 -0
- package/declarations/board/lattice-board.d.ts.map +1 -0
- package/declarations/grid/alignment.d.ts +30 -0
- package/declarations/grid/alignment.d.ts.map +1 -0
- package/declarations/grid/auto-columns.d.ts +22 -0
- package/declarations/grid/auto-columns.d.ts.map +1 -0
- package/declarations/grid/cell-state.d.ts +17 -0
- package/declarations/grid/cell-state.d.ts.map +1 -0
- package/declarations/grid/clipboard.d.ts +7 -0
- package/declarations/grid/clipboard.d.ts.map +1 -0
- package/declarations/grid/keyboard.d.ts +24 -0
- package/declarations/grid/keyboard.d.ts.map +1 -0
- package/declarations/grid/lattice-grid.d.ts +741 -0
- package/declarations/grid/lattice-grid.d.ts.map +1 -0
- package/declarations/grid/row-number.d.ts +24 -0
- package/declarations/grid/row-number.d.ts.map +1 -0
- package/declarations/grid/selection.d.ts +24 -0
- package/declarations/grid/selection.d.ts.map +1 -0
- package/declarations/grid/state-host.d.ts +52 -0
- package/declarations/grid/state-host.d.ts.map +1 -0
- package/declarations/grid/types.d.ts +376 -0
- package/declarations/grid/types.d.ts.map +1 -0
- package/declarations/index.d.ts +19 -0
- package/declarations/index.d.ts.map +1 -0
- package/declarations/list/lattice-list.d.ts +184 -0
- package/declarations/list/lattice-list.d.ts.map +1 -0
- package/dist/index.js +4031 -0
- package/dist/index.js.map +1 -0
- package/package.json +92 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,4031 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { tracked, cached } from '@glimmer/tracking';
|
|
3
|
+
import { warn } from '@ember/debug';
|
|
4
|
+
import { getOwner } from '@ember/owner';
|
|
5
|
+
import { fn, hash } from '@ember/helper';
|
|
6
|
+
import { guidFor } from '@ember/object/internals';
|
|
7
|
+
import { on } from '@ember/modifier';
|
|
8
|
+
import { renderSettled } from '@ember/renderer';
|
|
9
|
+
import { waitForPromise } from '@ember/test-waiters';
|
|
10
|
+
import { htmlSafe } from '@ember/template';
|
|
11
|
+
import { modifier } from 'ember-modifier';
|
|
12
|
+
import is from '@sindresorhus/is';
|
|
13
|
+
import { ScaledScroll, VirtualizerState, sizerSize, bindScaledInput, VirtualScroll, defaultRangeExtractor } from '@ember-lattice/virtual';
|
|
14
|
+
import { g, i, n } from 'decorator-transforms/runtime';
|
|
15
|
+
import { latticeLocale, applyFlexWidths, autoSizeColumns } from '@ember-lattice/core';
|
|
16
|
+
import { precompileTemplate } from '@ember/template-compilation';
|
|
17
|
+
import { setComponentTemplate } from '@ember/component';
|
|
18
|
+
import { Checkbox } from '@ember-joinery/primitives';
|
|
19
|
+
import { registerDestructor } from '@ember/destroyable';
|
|
20
|
+
import { Typeahead, isTypeaheadKey, getNextMatch } from '@ember-joinery/primitives/typeahead';
|
|
21
|
+
import { isRTL } from '@ember-joinery/primitives/direction';
|
|
22
|
+
import { visuallyHidden } from '@ember-joinery/primitives/visually-hidden';
|
|
23
|
+
|
|
24
|
+
class CellState {
|
|
25
|
+
static {
|
|
26
|
+
g(this.prototype, "_values", [tracked], function () {
|
|
27
|
+
return {};
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
#_values = (i(this, "_values"), void 0);
|
|
31
|
+
get(key) {
|
|
32
|
+
return this._values[key];
|
|
33
|
+
}
|
|
34
|
+
set(key, value) {
|
|
35
|
+
this._values = {
|
|
36
|
+
...this._values,
|
|
37
|
+
[key]: value
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** `cell.state`: the cell states, keyed by row ID and column ID. */
|
|
43
|
+
class CellStateStore {
|
|
44
|
+
_states = new Map();
|
|
45
|
+
|
|
46
|
+
/** The state of a cell. The first read makes it; this is not a tracked write. */
|
|
47
|
+
for(rowId, columnId) {
|
|
48
|
+
const key = `${rowId}\u0000${columnId}`;
|
|
49
|
+
let state = this._states.get(key);
|
|
50
|
+
if (!state) this._states.set(key, state = new CellState());
|
|
51
|
+
return state;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// The clipboard text of a cell range (plan section 7): TSV for spreadsheets and text editors, and
|
|
56
|
+
// an HTML table for rich editors.
|
|
57
|
+
|
|
58
|
+
/** A cell with a tab, a line end or a quote gets quotes, as spreadsheets write it. */
|
|
59
|
+
const quote = text => /[\t\n\r"]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
|
|
60
|
+
const toTsv = rows => rows.map(row => row.map(quote).join('\t')).join('\n');
|
|
61
|
+
const escapeHtml = text => text.replace(/[&<>"]/g, c => `&#${c.charCodeAt(0)};`);
|
|
62
|
+
const toHtml = rows => `<table>${rows.map(row => `<tr>${row.map(cell => `<td>${escapeHtml(cell)}</td>`).join('')}</tr>`).join('')}</table>`;
|
|
63
|
+
const inRange = (range, row, col) => row >= range.minRowIndex && row <= range.maxRowIndex && col >= range.minColumnIndex && col <= range.maxColumnIndex;
|
|
64
|
+
|
|
65
|
+
/** The number of rows in a TSV text: line ends outside quotes; a last line end adds no row. */
|
|
66
|
+
function tsvRowCount(text) {
|
|
67
|
+
let rows = 1;
|
|
68
|
+
let quoted = false;
|
|
69
|
+
for (let i = 0; i < text.length; i++) {
|
|
70
|
+
const c = text[i];
|
|
71
|
+
if (c === '"') quoted = !quoted;else if (c === '\n' && !quoted && i < text.length - 1) rows++;
|
|
72
|
+
}
|
|
73
|
+
return text === '' ? 0 : rows;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// The APG grid keys that move the active cell (docs/m2-grid-contract.md, section 3).
|
|
77
|
+
|
|
78
|
+
/** A cell position, as 1-based `aria-rowindex` and `aria-colindex`. */
|
|
79
|
+
|
|
80
|
+
const clamp$1 = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
81
|
+
|
|
82
|
+
/** The next active cell for a key, or null when the key does not move the active cell. */
|
|
83
|
+
function moveCell(event, from, bounds) {
|
|
84
|
+
const {
|
|
85
|
+
firstRow,
|
|
86
|
+
lastRow,
|
|
87
|
+
colCount,
|
|
88
|
+
pageRows,
|
|
89
|
+
rtl
|
|
90
|
+
} = bounds;
|
|
91
|
+
const ctrl = event.ctrlKey || event.metaKey;
|
|
92
|
+
const to = (row, col) => ({
|
|
93
|
+
row: clamp$1(row, firstRow, lastRow),
|
|
94
|
+
col: clamp$1(col, 1, colCount)
|
|
95
|
+
});
|
|
96
|
+
// In RTL, the inline start is on the right: Left and Right swap.
|
|
97
|
+
const forward = rtl ? -1 : 1;
|
|
98
|
+
switch (event.key) {
|
|
99
|
+
case 'ArrowUp':
|
|
100
|
+
return to(from.row - 1, from.col);
|
|
101
|
+
case 'ArrowDown':
|
|
102
|
+
return to(from.row + 1, from.col);
|
|
103
|
+
case 'ArrowLeft':
|
|
104
|
+
return to(from.row, from.col - forward);
|
|
105
|
+
case 'ArrowRight':
|
|
106
|
+
return to(from.row, from.col + forward);
|
|
107
|
+
case 'Home':
|
|
108
|
+
return ctrl ? to(firstRow, 1) : to(from.row, 1);
|
|
109
|
+
case 'End':
|
|
110
|
+
return ctrl ? to(lastRow, colCount) : to(from.row, colCount);
|
|
111
|
+
case 'PageUp':
|
|
112
|
+
return to(from.row - Math.max(pageRows, 1), from.col);
|
|
113
|
+
case 'PageDown':
|
|
114
|
+
return to(from.row + Math.max(pageRows, 1), from.col);
|
|
115
|
+
default:
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// The Grid keys of a saved view: the scroll offset and the active cell. This class has the
|
|
121
|
+
// shape of `GridStateHost` in `@ember-lattice/state` (ADR 0011), with no import of that package.
|
|
122
|
+
// Make it before the grid renders, give it to `persistGridState` and to `@stateHost`.
|
|
123
|
+
|
|
124
|
+
/** The part of `LatticeGrid` that the host uses. */
|
|
125
|
+
|
|
126
|
+
/** The state of a grid that has not rendered, or that the user did not change. */
|
|
127
|
+
const INITIAL = {
|
|
128
|
+
scroll: {
|
|
129
|
+
top: 0,
|
|
130
|
+
left: 0
|
|
131
|
+
},
|
|
132
|
+
activeCell: null
|
|
133
|
+
};
|
|
134
|
+
class GridStateHandle {
|
|
135
|
+
grid = null;
|
|
136
|
+
pending = {};
|
|
137
|
+
listeners = new Set();
|
|
138
|
+
|
|
139
|
+
/** Before the grid renders, this is the state that waits for it. */
|
|
140
|
+
read() {
|
|
141
|
+
return this.grid ? this.grid.readState() : {
|
|
142
|
+
...INITIAL,
|
|
143
|
+
...this.pending
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Before the grid renders, the state waits; the grid applies it when it attaches. */
|
|
148
|
+
apply(state) {
|
|
149
|
+
if (this.grid) this.grid.applyState(state);else this.pending = {
|
|
150
|
+
...this.pending,
|
|
151
|
+
...state
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Makes a cell the active cell and scrolls it into view. The focus does not move. False: the
|
|
157
|
+
* grid has not rendered, or it has no such row (with a row model: no loaded row) or column.
|
|
158
|
+
*/
|
|
159
|
+
scrollToCell(rowId, columnId) {
|
|
160
|
+
return this.grid?.scrollToCell(rowId, columnId) ?? false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Sizes the columns to their widest rendered content: all columns, or the given columns. A
|
|
165
|
+
* column that is not rendered keeps its size. Before the grid renders, it does nothing.
|
|
166
|
+
*/
|
|
167
|
+
autoSizeColumns(columnIds) {
|
|
168
|
+
this.grid?.autoSizeColumns(columnIds);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Opens the editor of a cell, as F2 does: the cell becomes the active cell, scrolls into view,
|
|
173
|
+
* and the editor gets the focus. It works with any `editTrigger`, also `none`. False: the grid
|
|
174
|
+
* has not rendered, has no `@editing`, or has no such loaded row or column, or the cell cannot
|
|
175
|
+
* be edited.
|
|
176
|
+
*/
|
|
177
|
+
startEditing(rowId, columnId) {
|
|
178
|
+
return this.grid?.startEditing(rowId, columnId) ?? false;
|
|
179
|
+
}
|
|
180
|
+
subscribe(listener) {
|
|
181
|
+
this.listeners.add(listener);
|
|
182
|
+
return () => this.listeners.delete(listener);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** The grid calls this when it renders. The returned function detaches it. */
|
|
186
|
+
attach(grid) {
|
|
187
|
+
this.grid = grid;
|
|
188
|
+
const pending = this.pending;
|
|
189
|
+
this.pending = {};
|
|
190
|
+
if (Object.keys(pending).length > 0) grid.applyState(pending);
|
|
191
|
+
return () => {
|
|
192
|
+
if (this.grid !== grid) return;
|
|
193
|
+
// A grid that renders again with this handle gets the last state back.
|
|
194
|
+
this.pending = grid.readState();
|
|
195
|
+
this.grid = null;
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** The grid calls this when its scroll offset or its active cell changes. */
|
|
200
|
+
notify() {
|
|
201
|
+
for (const listener of this.listeners) listener();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Aligned grids (contract section 11): grids with one `GridAlignment` share the horizontal
|
|
206
|
+
// scroll, and the column sizes, order and visibility of the column IDs that they share. A totals
|
|
207
|
+
// grid under a main grid is the usual case.
|
|
208
|
+
|
|
209
|
+
/** The column state that aligned grids share. */
|
|
210
|
+
|
|
211
|
+
/** The part of `LatticeGrid` that an alignment uses. */
|
|
212
|
+
|
|
213
|
+
class GridAlignment {
|
|
214
|
+
grids = new Set();
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Adds a grid. A grid that joins takes the columns of the grids that are already there. The
|
|
218
|
+
* returned function removes it.
|
|
219
|
+
*/
|
|
220
|
+
join(grid) {
|
|
221
|
+
const first = [...this.grids][0];
|
|
222
|
+
this.grids.add(grid);
|
|
223
|
+
if (first) grid.alignColumns(first.alignedColumns());
|
|
224
|
+
return () => this.grids.delete(grid);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** A grid changed its columns: the other grids take the change. */
|
|
228
|
+
columnsChanged(from) {
|
|
229
|
+
if (!this.grids.has(from)) return;
|
|
230
|
+
const state = from.alignedColumns();
|
|
231
|
+
for (const grid of this.grids) if (grid !== from) grid.alignColumns(state);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** A grid scrolled: the other grids scroll to the same offset. */
|
|
235
|
+
scrolled(from, left) {
|
|
236
|
+
for (const grid of this.grids) if (grid !== from) grid.alignScroll(left);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Auto-generated columns (contract section 11): one column def for each key of the first rows.
|
|
241
|
+
|
|
242
|
+
/** A column def that `autoColumns` makes. */
|
|
243
|
+
|
|
244
|
+
/** `owner_name` and `ownerName` give `Owner name`. */
|
|
245
|
+
const headerOf = key => {
|
|
246
|
+
const words = key.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_-]+/g, ' ').trim().toLowerCase();
|
|
247
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Column defs from the keys of the first rows, in the order the keys come. The type of a key is
|
|
252
|
+
* from its first value that is not null or undefined.
|
|
253
|
+
*/
|
|
254
|
+
function autoColumns(rows, options = {}) {
|
|
255
|
+
const first = new Map();
|
|
256
|
+
for (const row of rows.slice(0, options.sample ?? 10)) {
|
|
257
|
+
if (!is.plainObject(row)) continue;
|
|
258
|
+
for (const [key, value] of Object.entries(row)) {
|
|
259
|
+
if (!first.has(key) || is.nullOrUndefined(first.get(key))) first.set(key, value);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return [...first].map(([key, value]) => {
|
|
263
|
+
const type = is.nullOrUndefined(value) ? undefined : options.types?.find(t => t.isValue?.(value) ?? false);
|
|
264
|
+
return {
|
|
265
|
+
id: key,
|
|
266
|
+
accessorKey: key,
|
|
267
|
+
header: headerOf(key),
|
|
268
|
+
...(type && {
|
|
269
|
+
meta: {
|
|
270
|
+
columnType: type
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// LatticeGrid: the Grid surface (docs/m2-grid-contract.md). Rows recycle in slots, full cells
|
|
278
|
+
// are keyed by row ID, and the active row is held (ADR 0002). Pinned cells are sticky in one
|
|
279
|
+
// scroll container (ADR 0004). Above the element height cap, the rows scroll scaled (ADR 0003).
|
|
280
|
+
const DEFAULT_ROW_HEIGHT = 32;
|
|
281
|
+
const DEFAULT_OVERSCAN$1 = 4;
|
|
282
|
+
const DEFAULT_COLUMN_SIZE = 150;
|
|
283
|
+
const MIN_COLUMN_SIZE = 20;
|
|
284
|
+
const MAX_COLUMN_SIZE = 2000;
|
|
285
|
+
const RESIZE_STEP = 10;
|
|
286
|
+
/** A header must move this far, in px, before a press becomes a reorder drag. */
|
|
287
|
+
const DRAG_THRESHOLD$1 = 4;
|
|
288
|
+
/** Above this row count, a full cell column gets a dev-mode warning (ADR 0002 cost). */
|
|
289
|
+
const FULL_CELL_ROW_LIMIT = 100_000;
|
|
290
|
+
/**
|
|
291
|
+
* One leaf column in a row. The list has all columns in their order, so a change of the column
|
|
292
|
+
* range never moves a cell element: it only adds or removes cells (focus stays on the cell).
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
/** The cells of a row and the spacer after the center range when no column is end-pinned. */
|
|
296
|
+
|
|
297
|
+
/** A header cell in a group row. */
|
|
298
|
+
|
|
299
|
+
/** A data row in a slot or in the held layer. */
|
|
300
|
+
|
|
301
|
+
/** The detail row of a master row (`@detailRow`): one cell across all columns. */
|
|
302
|
+
|
|
303
|
+
/** A row that is not loaded: skeleton cells, `aria-busy`, or `data-failed`. */
|
|
304
|
+
|
|
305
|
+
const asRowView = view => view.row ? view : undefined;
|
|
306
|
+
const asDetail = view => !view.row && 'master' in view ? view : undefined;
|
|
307
|
+
const asSkeleton = view => view.row || 'master' in view ? undefined : view;
|
|
308
|
+
/** The mounted grids by their `.lt-grid` element: a row drop finds the grid under the pointer. */
|
|
309
|
+
const GRIDS = new WeakMap();
|
|
310
|
+
const NO_DETAILS = new Map();
|
|
311
|
+
const expandedOf = expanded => expanded === undefined ? undefined : expanded ? 'true' : 'false';
|
|
312
|
+
const rowNumberOf = index => index + 1;
|
|
313
|
+
const isOpen = expanded => expanded === 'true';
|
|
314
|
+
const px$2 = n => `${n}px`;
|
|
315
|
+
const sizeOf = column => column.getSize?.() ?? DEFAULT_COLUMN_SIZE;
|
|
316
|
+
const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
317
|
+
const textOf = value => is.string(value) ? value : null;
|
|
318
|
+
/** The header text: the string `header` of the column def, or its result, or the column ID. */
|
|
319
|
+
function headerLabel(header) {
|
|
320
|
+
const def = header.column.columnDef.header;
|
|
321
|
+
if (is.function(def)) {
|
|
322
|
+
const result = Reflect.apply(def, undefined, [header.getContext()]);
|
|
323
|
+
return textOf(result) ?? header.column.id;
|
|
324
|
+
}
|
|
325
|
+
return textOf(def) ?? header.column.id;
|
|
326
|
+
}
|
|
327
|
+
const columnStyle = (size, pin, inset, align) => htmlSafe(`inline-size: ${px$2(size)}` + (pin ? `; inset-inline-${pin}: ${px$2(inset)}` : '') + (align ? `; text-align: ${align}` : ''));
|
|
328
|
+
const sortOf = column => {
|
|
329
|
+
if (!column.getCanSort?.()) return undefined;
|
|
330
|
+
const sorted = column.getIsSorted?.();
|
|
331
|
+
return sorted === 'asc' ? 'ascending' : sorted === 'desc' ? 'descending' : 'none';
|
|
332
|
+
};
|
|
333
|
+
const cellOf = (row, column) => {
|
|
334
|
+
const cell = row.getAllCellsByColumnId()[column.id];
|
|
335
|
+
if (!cell) throw new Error(`LatticeGrid: row ${row.id} has no cell for column ${column.id}`);
|
|
336
|
+
return cell;
|
|
337
|
+
};
|
|
338
|
+
/** A one-item list, so `{{#each}}` keys a full cell by its row ID. */
|
|
339
|
+
const keyed = id => [id];
|
|
340
|
+
const cellText = (row, column, locale) => formatValue(column, row.getValue(column.id), locale);
|
|
341
|
+
const formatValue = (column, value, locale) => {
|
|
342
|
+
const meta = column.columnDef.meta;
|
|
343
|
+
if (meta?.lattice?.format) return meta.lattice.format(value);
|
|
344
|
+
// A column type of `@ember-lattice/column-types` shows its value in the locale.
|
|
345
|
+
if (meta?.columnType) return meta.columnType.format(value, locale);
|
|
346
|
+
// A value that is not a primitive needs a `format` to show as text. NaN shows as no text.
|
|
347
|
+
if (is.string(value)) return value;
|
|
348
|
+
if (is.number(value) || is.boolean(value) || is.bigint(value)) return String(value);
|
|
349
|
+
return '';
|
|
350
|
+
};
|
|
351
|
+
/** The first cell of the total row shows the `grid.totalRow` text when its column has no total. */
|
|
352
|
+
const totalText = (row, slot, l) => {
|
|
353
|
+
const text = cellText(row, slot.column, l.locale);
|
|
354
|
+
return text === '' && slot.aria === 1 ? l.t('grid.totalRow') : text;
|
|
355
|
+
};
|
|
356
|
+
const selectedOf = row => {
|
|
357
|
+
if (!row.getIsSelected) return undefined;
|
|
358
|
+
return row.getIsSelected() ? 'true' : 'false';
|
|
359
|
+
};
|
|
360
|
+
const isPinned = pin => pin ? pin : undefined;
|
|
361
|
+
/**
|
|
362
|
+
* The width of the view before the grid measures its scroller: the window. With no width, the
|
|
363
|
+
* first render had no center columns, and the next render came a frame later. The row
|
|
364
|
+
* virtualizer does not get it: more rows in the first render made the first render 50% slower
|
|
365
|
+
* in the bench.
|
|
366
|
+
*/
|
|
367
|
+
const viewRect = () => ({
|
|
368
|
+
width: globalThis.innerWidth ?? 0,
|
|
369
|
+
height: globalThis.innerHeight ?? 0
|
|
370
|
+
});
|
|
371
|
+
/** The options of the column virtualizer: the center column sizes and the pinned widths. */
|
|
372
|
+
const colOptions = (sizes, startWidth, endWidth, rtl) => ({
|
|
373
|
+
horizontal: true,
|
|
374
|
+
count: sizes.length,
|
|
375
|
+
estimateSize: i => sizes[i] ?? DEFAULT_COLUMN_SIZE,
|
|
376
|
+
overscan: 1,
|
|
377
|
+
paddingStart: startWidth,
|
|
378
|
+
paddingEnd: endWidth,
|
|
379
|
+
scrollPaddingStart: startWidth,
|
|
380
|
+
scrollPaddingEnd: endWidth,
|
|
381
|
+
isRtl: rtl
|
|
382
|
+
});
|
|
383
|
+
/** A full cell is keyed by row ID (ADR 0002): a new component for each new row. */
|
|
384
|
+
const isFull = column => {
|
|
385
|
+
const lattice = column.columnDef.meta?.lattice;
|
|
386
|
+
return lattice?.cell !== undefined && lattice.cellKind !== 'cheap';
|
|
387
|
+
};
|
|
388
|
+
/** The fields of a center column outside the range. */
|
|
389
|
+
const HIDDEN = {
|
|
390
|
+
rendered: false,
|
|
391
|
+
gap: null,
|
|
392
|
+
pin: false,
|
|
393
|
+
style: htmlSafe(''),
|
|
394
|
+
component: null,
|
|
395
|
+
full: false,
|
|
396
|
+
headerSlot: null,
|
|
397
|
+
headerLabel: null,
|
|
398
|
+
rowNumber: false,
|
|
399
|
+
rowDrag: false,
|
|
400
|
+
describe: null,
|
|
401
|
+
invalid: null
|
|
402
|
+
};
|
|
403
|
+
/** The elements that a header slot or a floating filter can focus. */
|
|
404
|
+
const FOCUSABLE = 'button, input, select, textarea, [tabindex]';
|
|
405
|
+
/** The parts of a header cell that hold controls: the label component and the header slot. */
|
|
406
|
+
const WIDGETS = '.lt-header-label, .lt-header-slot';
|
|
407
|
+
const WIDGET_CONTROL = ':is(.lt-header-label, .lt-header-slot) :is(button, input, select, textarea, [tabindex])';
|
|
408
|
+
/** A cell of a row: a data cell, a row header (row numbers) or a column header. */
|
|
409
|
+
const CELL = '[role="gridcell"], [role="rowheader"], [role="columnheader"]';
|
|
410
|
+
/** A visually hidden live region: it stays in the accessibility tree. */
|
|
411
|
+
const LIVE_STYLE = htmlSafe('position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap');
|
|
412
|
+
/** With a side bar, the root puts the grid and the side bar in one line. */
|
|
413
|
+
const SPLIT_STYLE = htmlSafe('display: flex; align-items: stretch');
|
|
414
|
+
/**
|
|
415
|
+
* The assignment of rows to slots. A row keeps its slot while it is wanted. A new row takes a
|
|
416
|
+
* free slot. This is a cache of the last render, not tracked state.
|
|
417
|
+
*/
|
|
418
|
+
class SlotPool {
|
|
419
|
+
_size = 0;
|
|
420
|
+
_assigned = new Map();
|
|
421
|
+
/** The row index in each slot, or null for an empty slot. */
|
|
422
|
+
assign(indexes) {
|
|
423
|
+
// shortcut: the pool only grows; a smaller range leaves empty slots, not fewer elements.
|
|
424
|
+
this._size = Math.max(this._size, indexes.length);
|
|
425
|
+
const next = new Map();
|
|
426
|
+
const used = new Set();
|
|
427
|
+
for (const index of indexes) {
|
|
428
|
+
const slot = this._assigned.get(index);
|
|
429
|
+
if (slot !== undefined) {
|
|
430
|
+
next.set(index, slot);
|
|
431
|
+
used.add(slot);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
let free = 0;
|
|
435
|
+
for (const index of indexes) {
|
|
436
|
+
if (next.has(index)) continue;
|
|
437
|
+
while (used.has(free)) free++;
|
|
438
|
+
next.set(index, free);
|
|
439
|
+
used.add(free);
|
|
440
|
+
}
|
|
441
|
+
this._assigned = next;
|
|
442
|
+
const slots = Array.from({
|
|
443
|
+
length: this._size
|
|
444
|
+
}, () => null);
|
|
445
|
+
for (const [index, slot] of next) slots[slot] = index;
|
|
446
|
+
return slots;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
class LatticeRow extends Component {
|
|
450
|
+
get ariaRow() {
|
|
451
|
+
return this.args.grid.headerRowCount + this.args.view.index + 1;
|
|
452
|
+
}
|
|
453
|
+
/** The first cell of a group row holds the toggle and the group label. */
|
|
454
|
+
groupCell = aria => this.args.view.group !== undefined && aria === 1;
|
|
455
|
+
/** The first cell of a tree row with sub rows holds the toggle, then the value. */
|
|
456
|
+
treeCell = aria => this.args.view.treeToggle && aria === 1;
|
|
457
|
+
/** With `@detailRow`, the first cell of a master row holds the detail toggle. */
|
|
458
|
+
detailCell = aria => aria === 1 && this.args.grid.hasDetail(this.args.view.row);
|
|
459
|
+
toggleDetail = () => this.args.grid.toggleDetail(this.args.view.row);
|
|
460
|
+
toggle = () => this.args.grid.toggleGroup(this.args.view.index);
|
|
461
|
+
static {
|
|
462
|
+
setComponentTemplate(precompileTemplate("<div class=\"lt-row\" role=\"row\" aria-rowindex={{this.ariaRow}} aria-selected={{selectedOf @view.row}} aria-level={{@view.level}} aria-expanded={{@view.expanded}} data-row-id={{@view.id}} data-lt-slot={{@slot}} data-held={{if @view.held \"\"}} data-sticky={{if @view.sticky \"\"}} data-row-pinned={{@view.pinned}} data-index={{@view.index}} style={{@view.style}} {{@grid.measureRow @view.index @grid.measured}}>\n {{#if @view.fullWidth}}\n <div class=\"lt-cell lt-full-width-cell\" role=\"gridcell\" aria-colindex=\"1\" aria-colspan={{@grid.colCount}} tabindex={{@grid.rowTabIndex this.ariaRow}} style={{@grid.fullWidthStyle}}>\n {{#let @grid.fullWidthComponent as |FullWidth|}}\n {{#if FullWidth}}<FullWidth @row={{@view.row}} />{{/if}}\n {{/let}}\n </div>\n {{else}}\n {{#each @grid.layout.slots key=\"key\" as |slot|}}\n {{#if slot.rendered}}\n {{#if slot.gap}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{slot.gap}}></div>\n {{/if}}\n {{#let (@grid.spanOf @view.row slot) as |merge|}}\n {{#if merge.covered}}\n {{#if merge.spacer}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{merge.spacer}}></div>\n {{/if}}\n {{else}}\n <div class=\"lt-cell\" role={{if slot.rowNumber \"rowheader\" \"gridcell\"}} aria-colindex={{slot.aria}} aria-rowspan={{merge.rowSpan}} aria-colspan={{merge.colSpan}} aria-selected={{@grid.cellSelected @view.index slot.aria}} data-range-edge={{@grid.rangeEdge @view.index slot.aria}} data-column-id={{slot.column.id}} data-pinned={{isPinned slot.pin}} data-dirty={{if (@grid.isDirty @view.row slot.column) \"\"}} data-find-match={{@grid.findMatch @view.row slot.column}} data-note={{if (@grid.hasNote @view.row slot.column) \"\"}} aria-describedby={{@grid.describedBy @view.index slot @view.row}} aria-invalid={{@grid.invalidFor @view.row slot}} tabindex={{@grid.tabIndexFor this.ariaRow slot.aria}} style={{if merge merge.style slot.style}}>\n {{#if (this.groupCell slot.aria)}}\n <button type=\"button\" class=\"lt-group-toggle\" tabindex=\"-1\" aria-label={{if @view.group.expanded (@grid.l.t \"grid.collapse\") (@grid.l.t \"grid.expand\")}} {{on \"click\" this.toggle}}></button>\n <span class=\"lt-group-label\">{{@view.group.label}}</span>\n {{else}}\n {{#if (this.detailCell slot.aria)}}\n <button type=\"button\" class=\"lt-group-toggle lt-detail-toggle\" tabindex=\"-1\" aria-label={{@grid.l.t \"grid.details\"}} aria-expanded={{if (@grid.isDetailOpen @view.row) \"true\" \"false\"}} {{on \"click\" this.toggleDetail}}></button>\n {{/if}}\n {{#if slot.rowDrag}}\n <span class=\"lt-row-drag-handle\" aria-hidden=\"true\" {{on \"pointerdown\" (fn @grid.onRowDragStart @view.row @view.index)}}></span>\n {{/if}}\n {{#if (this.treeCell slot.aria)}}\n <button type=\"button\" class=\"lt-group-toggle\" tabindex=\"-1\" aria-label={{if (isOpen @view.expanded) (@grid.l.t \"grid.collapse\") (@grid.l.t \"grid.expand\")}} {{on \"click\" this.toggle}}></button>\n {{/if}}\n {{#if slot.rowNumber}}\n {{rowNumberOf @view.index}}\n {{else if slot.component}}\n {{#if slot.full}}\n {{#each (keyed @view.id) key=\"@identity\"}}\n <slot.component @cell={{cellOf @view.row slot.column}} @row={{@view.row}} @column={{slot.column}} @value={{@grid.valueFor @view.row slot.column}} @state={{@grid.stateFor @view.id slot.column}} />\n {{/each}}\n {{else}}\n <slot.component @cell={{cellOf @view.row slot.column}} @row={{@view.row}} @column={{slot.column}} @value={{@grid.valueFor @view.row slot.column}} @state={{@grid.stateFor @view.id slot.column}} />\n {{/if}}\n {{else}}\n {{@grid.textFor @view.row slot.column}}\n {{/if}}\n {{/if}}\n {{#if (@grid.isFillCorner @view.index slot.aria)}}\n <div class=\"lt-fill-handle\" aria-hidden=\"true\" {{on \"pointerdown\" @grid.onFillStart}}></div>\n {{/if}}\n </div>\n {{/if}}\n {{/let}}\n {{/if}}\n {{/each}}\n {{#if @grid.layout.tail}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{@grid.layout.tail}}></div>\n {{/if}}\n {{/if}}\n</div>", {
|
|
463
|
+
strictMode: true,
|
|
464
|
+
scope: () => ({
|
|
465
|
+
selectedOf,
|
|
466
|
+
isPinned,
|
|
467
|
+
on,
|
|
468
|
+
fn,
|
|
469
|
+
isOpen,
|
|
470
|
+
rowNumberOf,
|
|
471
|
+
keyed,
|
|
472
|
+
cellOf
|
|
473
|
+
})
|
|
474
|
+
}), this);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
/** The detail row of a master row: one cell across all columns, with the `@detailRow` component. */
|
|
478
|
+
class DetailRow extends Component {
|
|
479
|
+
get ariaRow() {
|
|
480
|
+
return this.args.grid.headerRowCount + this.args.view.index + 1;
|
|
481
|
+
}
|
|
482
|
+
static {
|
|
483
|
+
setComponentTemplate(precompileTemplate("<div class=\"lt-row lt-detail-row\" role=\"row\" aria-rowindex={{this.ariaRow}} data-row-id={{@view.id}} data-lt-slot={{@slot}} data-index={{@view.index}} data-held={{if @view.held \"\"}} style={{@view.style}} {{@grid.measureRow @view.index @grid.measured}}>\n <div class=\"lt-cell lt-full-width-cell\" role=\"gridcell\" aria-colindex=\"1\" aria-colspan={{@grid.colCount}} tabindex={{@grid.rowTabIndex this.ariaRow}} style={{@grid.fullWidthStyle}}>\n {{#let @grid.detailComponent as |Detail|}}\n {{#if Detail}}<Detail @row={{@view.master}} />{{/if}}\n {{/let}}\n </div>\n</div>", {
|
|
484
|
+
strictMode: true
|
|
485
|
+
}), this);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/** A row that is not loaded yet: empty cells with `data-loading`, so the theme can style them. */
|
|
489
|
+
class SkeletonRow extends Component {
|
|
490
|
+
get ariaRow() {
|
|
491
|
+
return this.args.grid.headerRowCount + this.args.view.index + 1;
|
|
492
|
+
}
|
|
493
|
+
static {
|
|
494
|
+
setComponentTemplate(precompileTemplate("<div class=\"lt-row\" role=\"row\" aria-rowindex={{this.ariaRow}} aria-busy={{if @view.failed undefined \"true\"}} aria-level={{@view.level}} data-failed={{if @view.failed \"\"}} data-lt-slot={{@slot}} data-held={{if @view.held \"\"}} style={{@view.style}}>\n {{#each @grid.layout.slots key=\"key\" as |slot|}}\n {{#if slot.rendered}}\n {{#if slot.gap}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{slot.gap}}></div>\n {{/if}}\n <div class=\"lt-cell\" role=\"gridcell\" aria-colindex={{slot.aria}} data-column-id={{slot.column.id}} data-pinned={{isPinned slot.pin}} data-loading tabindex={{@grid.tabIndexFor this.ariaRow slot.aria}} style={{slot.style}}></div>\n {{/if}}\n {{/each}}\n {{#if @grid.layout.tail}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{@grid.layout.tail}}></div>\n {{/if}}\n</div>", {
|
|
495
|
+
strictMode: true,
|
|
496
|
+
scope: () => ({
|
|
497
|
+
isPinned
|
|
498
|
+
})
|
|
499
|
+
}), this);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
class LatticeGrid extends Component {
|
|
503
|
+
/** A new `GridStateHost` for `persistGridState` and `@stateHost` (ADR 0011). */static stateHost = () => new GridStateHandle();
|
|
504
|
+
/** A new `GridAlignment`: give it to `@aligned` of each grid to align (contract section 11). */
|
|
505
|
+
static alignment = () => new GridAlignment();
|
|
506
|
+
cellState = new CellStateStore();
|
|
507
|
+
scale = new ScaledScroll({
|
|
508
|
+
totalSize: 0,
|
|
509
|
+
viewportSize: 0
|
|
510
|
+
});
|
|
511
|
+
/** The active cell, as `aria-rowindex` and `aria-colindex`. Null: the first data cell. */
|
|
512
|
+
static {
|
|
513
|
+
g(this.prototype, "_activeCell", [tracked], function () {
|
|
514
|
+
return null;
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
#_activeCell = (i(this, "_activeCell"), void 0);
|
|
518
|
+
static {
|
|
519
|
+
g(this.prototype, "dir", [tracked], function () {
|
|
520
|
+
return undefined;
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
#dir = (i(this, "dir"), void 0);
|
|
524
|
+
/** The text direction of the grid, read after it renders. Undefined before that. */
|
|
525
|
+
/** The locale text and the locale of this grid (ADR 0024): `@localeText`, then the owner. */get l() {
|
|
526
|
+
return latticeLocale(getOwner(this), this.args.localeText, this.args.locale);
|
|
527
|
+
}
|
|
528
|
+
static {
|
|
529
|
+
n(this.prototype, "l", [cached]);
|
|
530
|
+
}
|
|
531
|
+
get rtl() {
|
|
532
|
+
return this.dir === 'rtl';
|
|
533
|
+
}
|
|
534
|
+
get _active() {
|
|
535
|
+
return this._activeCell;
|
|
536
|
+
}
|
|
537
|
+
set _active(position) {
|
|
538
|
+
this._activeCell = position;
|
|
539
|
+
this.args.stateHost?.notify();
|
|
540
|
+
}
|
|
541
|
+
pool = new SlotPool();
|
|
542
|
+
_element = null;
|
|
543
|
+
_scroller = null;
|
|
544
|
+
_suppressClick = false;
|
|
545
|
+
rowState = new VirtualizerState({
|
|
546
|
+
count: this.rowCount,
|
|
547
|
+
estimateSize: () => this.rowHeight,
|
|
548
|
+
overscan: this.args.overscan ?? DEFAULT_OVERSCAN$1,
|
|
549
|
+
paddingStart: this.headerHeight,
|
|
550
|
+
scrollPaddingStart: this.headerHeight,
|
|
551
|
+
scrollScale: this.scale
|
|
552
|
+
});
|
|
553
|
+
colState = new VirtualizerState({
|
|
554
|
+
...colOptions(this.columns.centerSizes, this.columns.startWidth, this.columns.endWidth, false),
|
|
555
|
+
initialRect: viewRect()
|
|
556
|
+
});
|
|
557
|
+
/** The computed `--lt-row-height`, for the density presets when `@rowHeight` is not given. */
|
|
558
|
+
static {
|
|
559
|
+
g(this.prototype, "_cssRowHeight", [tracked], function () {
|
|
560
|
+
return null;
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
#_cssRowHeight = (i(this, "_cssRowHeight"), void 0);
|
|
564
|
+
get rowHeight() {
|
|
565
|
+
const height = this.args.rowHeight;
|
|
566
|
+
return is.number(height) ? height : this._cssRowHeight ?? DEFAULT_ROW_HEIGHT;
|
|
567
|
+
}
|
|
568
|
+
readRowHeight(grid) {
|
|
569
|
+
if (is.number(this.args.rowHeight)) return;
|
|
570
|
+
const value = parseFloat(getComputedStyle(grid).getPropertyValue('--lt-row-height'));
|
|
571
|
+
const next = Number.isFinite(value) && value > 0 ? value : null;
|
|
572
|
+
if (next !== this._cssRowHeight) this._cssRowHeight = next;
|
|
573
|
+
}
|
|
574
|
+
get rows() {
|
|
575
|
+
if (this.args.rowModel) return [];
|
|
576
|
+
const {
|
|
577
|
+
top,
|
|
578
|
+
center,
|
|
579
|
+
bottom
|
|
580
|
+
} = this.pinnedRows;
|
|
581
|
+
// shortcut: the external filter runs on the rows of the row model, after the engine groups
|
|
582
|
+
// them, so group rows keep their counts; a core filter step would filter before the groups.
|
|
583
|
+
const pass = this.args.externalFilter;
|
|
584
|
+
const rows = pass ? center().filter(row => pass(row)) : center();
|
|
585
|
+
return top.length + bottom.length > 0 ? [...top, ...rows, ...bottom] : rows;
|
|
586
|
+
}
|
|
587
|
+
/** The pinned rows of the engine row pinning, and a function for the other rows. */
|
|
588
|
+
static {
|
|
589
|
+
n(this.prototype, "rows", [cached]);
|
|
590
|
+
}
|
|
591
|
+
get pinnedRows() {
|
|
592
|
+
const table = this.args.table;
|
|
593
|
+
const none = [];
|
|
594
|
+
const top = this.args.rowModel ? none : table.getTopRows?.() ?? none;
|
|
595
|
+
const bottom = this.args.rowModel ? none : table.getBottomRows?.() ?? none;
|
|
596
|
+
const center = () => top.length + bottom.length > 0 && table.getCenterRows ? table.getCenterRows() : table.getRowModel().rows;
|
|
597
|
+
return {
|
|
598
|
+
top,
|
|
599
|
+
bottom,
|
|
600
|
+
center
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
/** The heights of the pinned top rows and bottom rows. */
|
|
604
|
+
static {
|
|
605
|
+
n(this.prototype, "pinnedRows", [cached]);
|
|
606
|
+
}
|
|
607
|
+
get pinnedTopHeight() {
|
|
608
|
+
return this.pinnedRows.top.length * this.rowHeight;
|
|
609
|
+
}
|
|
610
|
+
get pinnedBottomHeight() {
|
|
611
|
+
return this.pinnedRows.bottom.length * this.rowHeight;
|
|
612
|
+
}
|
|
613
|
+
/** True when rows float: sticky group rows or pinned rows read the view offsets from CSS. */
|
|
614
|
+
get floats() {
|
|
615
|
+
return this.clientTree || this.pinnedTopHeight + this.pinnedBottomHeight > 0;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* The view top and the view bottom, in body px, as CSS variables on the scroller. The floating
|
|
619
|
+
* rows read them, so a scroll moves them with no render (ADR 0018).
|
|
620
|
+
*/
|
|
621
|
+
writeViewVars(scroller) {
|
|
622
|
+
if (!this.floats) return;
|
|
623
|
+
const bottom = scroller.scrollTop + scroller.clientHeight - this.headerHeight - this.footerHeight;
|
|
624
|
+
scroller.style.setProperty('--lt-view-top', px$2(scroller.scrollTop));
|
|
625
|
+
scroller.style.setProperty('--lt-view-bottom', px$2(bottom));
|
|
626
|
+
}
|
|
627
|
+
/** The number of body rows: the rows of the row model, or of the table, and detail rows. */
|
|
628
|
+
get rowCount() {
|
|
629
|
+
return this.args.rowModel?.displayCount ?? this.display.rows.length;
|
|
630
|
+
}
|
|
631
|
+
/** The row at a 0-based index, or undefined when it is not loaded (or a detail row). */
|
|
632
|
+
rowAt(index) {
|
|
633
|
+
const model = this.args.rowModel;
|
|
634
|
+
return model ? model.rowAt(index) : this.display.rows[index];
|
|
635
|
+
}
|
|
636
|
+
// Row drag (ADR 0018) -------------------------------------------------------------------------
|
|
637
|
+
/** Moves a row in this grid: the app moves it in its data. The live region says the move. */
|
|
638
|
+
moveRow(row, fromIndex, toIndex) {
|
|
639
|
+
const onMove = this.args.onRowMove;
|
|
640
|
+
if (!onMove || toIndex === fromIndex || toIndex < 0 || toIndex >= this.rowCount) return false;
|
|
641
|
+
onMove({
|
|
642
|
+
row,
|
|
643
|
+
fromIndex,
|
|
644
|
+
toIndex
|
|
645
|
+
});
|
|
646
|
+
this.liveMessage = this.l.t('grid.rowMoved', {
|
|
647
|
+
from: fromIndex + 1,
|
|
648
|
+
to: toIndex + 1
|
|
649
|
+
});
|
|
650
|
+
return true;
|
|
651
|
+
}
|
|
652
|
+
/** Alt+ArrowUp and Alt+ArrowDown move the row of the active cell, and the active cell. */
|
|
653
|
+
moveKey(event, position) {
|
|
654
|
+
if (!event.altKey || !this.args.onRowMove) return false;
|
|
655
|
+
const step = event.key === 'ArrowUp' ? -1 : event.key === 'ArrowDown' ? 1 : 0;
|
|
656
|
+
const index = position.row - this.headerRowCount - 1;
|
|
657
|
+
const row = this.rowAt(index);
|
|
658
|
+
if (step === 0 || !row) return false;
|
|
659
|
+
event.preventDefault();
|
|
660
|
+
if (this.moveRow(row, index, index + step)) this.activate({
|
|
661
|
+
...position,
|
|
662
|
+
row: position.row + step
|
|
663
|
+
});
|
|
664
|
+
return true;
|
|
665
|
+
}
|
|
666
|
+
/** A press on a drag handle: the drop row is under the pointer, in this grid or in another. */
|
|
667
|
+
onRowDragStart = (row, fromIndex, event) => {
|
|
668
|
+
if (event.button !== 0) return;
|
|
669
|
+
// No range selection and no text selection from the handle.
|
|
670
|
+
event.preventDefault();
|
|
671
|
+
event.stopPropagation();
|
|
672
|
+
const doc = this._element?.ownerDocument ?? document;
|
|
673
|
+
this._element?.setAttribute('data-row-dragging', '');
|
|
674
|
+
const end = e => {
|
|
675
|
+
if (e.pointerId !== event.pointerId) return;
|
|
676
|
+
doc.removeEventListener('pointerup', end);
|
|
677
|
+
doc.removeEventListener('pointercancel', end);
|
|
678
|
+
this._element?.removeAttribute('data-row-dragging');
|
|
679
|
+
if (e.type === 'pointercancel') return;
|
|
680
|
+
const target = doc.elementFromPoint(e.clientX, e.clientY)?.closest('.lt-body .lt-row');
|
|
681
|
+
const grid = target?.closest('.lt-grid');
|
|
682
|
+
const owner = grid ? GRIDS.get(grid) : undefined;
|
|
683
|
+
if (!target || !owner) return;
|
|
684
|
+
const toIndex = Number(target.getAttribute('aria-rowindex')) - owner.headerRowCount - 1;
|
|
685
|
+
if (owner === this) this.moveRow(row, fromIndex, toIndex);else owner.args.onRowDrop?.({
|
|
686
|
+
row,
|
|
687
|
+
source: this.args.label,
|
|
688
|
+
toIndex
|
|
689
|
+
});
|
|
690
|
+
};
|
|
691
|
+
doc.addEventListener('pointerup', end);
|
|
692
|
+
doc.addEventListener('pointercancel', end);
|
|
693
|
+
};
|
|
694
|
+
// Cell spanning (ADR 0018) ------------------------------------------------------------------
|
|
695
|
+
/** True when the table has the engine cell spanning feature (client rows only). */
|
|
696
|
+
get spanning() {
|
|
697
|
+
return !this.args.rowModel && this.args.table.getCellSpanIndex !== undefined;
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* The span of a cell, or undefined for a cell of one row and one column. A cell that a cell
|
|
701
|
+
* above covers leaves a spacer of the width of its column span; a cell that a cell before it covers leaves
|
|
702
|
+
* nothing, because the spanning cell is as wide as all its columns.
|
|
703
|
+
*/
|
|
704
|
+
spanOf = (row, slot) => {
|
|
705
|
+
if (!this.spanning) return undefined;
|
|
706
|
+
const cell = row.getAllCellsByColumnId()[slot.column.id];
|
|
707
|
+
const rowSpan = cell?.getRowSpan?.() ?? 1;
|
|
708
|
+
const colSpan = cell?.getColSpan?.() ?? 1;
|
|
709
|
+
if (rowSpan === 1 && colSpan === 1) return undefined;
|
|
710
|
+
if (colSpan === 0) return {
|
|
711
|
+
covered: true,
|
|
712
|
+
spacer: null
|
|
713
|
+
};
|
|
714
|
+
// shortcut: a column span assumes its columns are side by side (not split by pinning or by the column range).
|
|
715
|
+
const width = this.columns.all.slice(slot.aria - 1, slot.aria - 1 + colSpan).reduce((n, c) => n + sizeOf(c), 0);
|
|
716
|
+
// A cell under a merge of many columns leaves a spacer as wide as the merge.
|
|
717
|
+
if (rowSpan === 0) return {
|
|
718
|
+
covered: true,
|
|
719
|
+
spacer: htmlSafe(`inline-size: ${px$2(width)}`)
|
|
720
|
+
};
|
|
721
|
+
const height = rowSpan > 1 ? `; block-size: ${px$2(rowSpan * this.rowHeight)}; align-self: flex-start` : '';
|
|
722
|
+
return {
|
|
723
|
+
covered: false,
|
|
724
|
+
spacer: null,
|
|
725
|
+
rowSpan: rowSpan > 1 ? rowSpan : undefined,
|
|
726
|
+
colSpan: colSpan > 1 ? colSpan : undefined,
|
|
727
|
+
style: htmlSafe(`${String(slot.style)}; inline-size: ${px$2(width)}${height}`)
|
|
728
|
+
};
|
|
729
|
+
};
|
|
730
|
+
/** The first row of each row span that covers a row: it stays rendered with its merged cell. */
|
|
731
|
+
spanAnchors(index) {
|
|
732
|
+
if (!this.spanning || index === undefined) return [];
|
|
733
|
+
const anchors = [];
|
|
734
|
+
for (const spans of Object.values(this.args.table.getCellSpanIndex?.().rowSpans ?? {})) {
|
|
735
|
+
let at = index;
|
|
736
|
+
while (at > 0 && spans[at] === 0) at--;
|
|
737
|
+
if (at !== index) anchors.push(at);
|
|
738
|
+
}
|
|
739
|
+
return anchors;
|
|
740
|
+
}
|
|
741
|
+
/** A row with a cell that spans rows paints over the rows under it. */
|
|
742
|
+
spansDown(row) {
|
|
743
|
+
if (!this.spanning) return false;
|
|
744
|
+
const cells = row.getAllCellsByColumnId();
|
|
745
|
+
return Object.values(cells).some(cell => (cell.getRowSpan?.() ?? 1) > 1);
|
|
746
|
+
}
|
|
747
|
+
// Master/detail and full-width rows (ADR 0018) ----------------------------------------------
|
|
748
|
+
/** The IDs of the master rows with an open detail row. */
|
|
749
|
+
static {
|
|
750
|
+
g(this.prototype, "_details", [tracked], function () {
|
|
751
|
+
return new Set();
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
#_details = (i(this, "_details"), void 0);
|
|
755
|
+
hasDetail = row => this.args.detailRow !== undefined && (this.args.hasDetail?.(row) ?? true);
|
|
756
|
+
isDetailOpen = row => this._details.has(this.rowIdOf(row));
|
|
757
|
+
toggleDetail = row => {
|
|
758
|
+
const next = new Set(this._details);
|
|
759
|
+
const id = this.rowIdOf(row);
|
|
760
|
+
if (!next.delete(id)) next.add(id);
|
|
761
|
+
this._details = next;
|
|
762
|
+
};
|
|
763
|
+
/** The client rows with a detail row after each open master row (a detail row is undefined). */
|
|
764
|
+
get display() {
|
|
765
|
+
const rows = this.rows;
|
|
766
|
+
if (!this.args.detailRow || this._details.size === 0) return {
|
|
767
|
+
rows,
|
|
768
|
+
details: NO_DETAILS
|
|
769
|
+
};
|
|
770
|
+
// shortcut: a copy of the rows while a detail row is open; splice the detail rows in if 1M rows are slow.
|
|
771
|
+
const out = [];
|
|
772
|
+
const details = new Map();
|
|
773
|
+
for (const row of rows) {
|
|
774
|
+
out.push(row);
|
|
775
|
+
if (this._details.has(this.rowIdOf(row))) {
|
|
776
|
+
details.set(out.length, row);
|
|
777
|
+
out.push(undefined);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return {
|
|
781
|
+
rows: out,
|
|
782
|
+
details
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
static {
|
|
786
|
+
n(this.prototype, "display", [cached]);
|
|
787
|
+
}
|
|
788
|
+
get fullWidthComponent() {
|
|
789
|
+
return this.args.fullWidthRow;
|
|
790
|
+
}
|
|
791
|
+
get detailComponent() {
|
|
792
|
+
return this.args.detailRow;
|
|
793
|
+
}
|
|
794
|
+
/** A full-width cell spans the rows: it is as wide as all columns. */
|
|
795
|
+
get fullWidthStyle() {
|
|
796
|
+
return htmlSafe(`inline-size: ${px$2(this.totalWidth)}`);
|
|
797
|
+
}
|
|
798
|
+
/** The tab stop of a full-width cell: it is the active cell for any column of its row. */
|
|
799
|
+
rowTabIndex = ariaRow => this.activeCell.row === ariaRow ? 0 : -1;
|
|
800
|
+
/** True when rows have measured heights: `@rowHeight="auto"`, or an open detail row. */
|
|
801
|
+
get measured() {
|
|
802
|
+
return this.args.rowHeight === 'auto' || this.display.details.size > 0;
|
|
803
|
+
}
|
|
804
|
+
/** The key of a row for the measured sizes: its row ID, so a size stays with its row. */
|
|
805
|
+
keyAt = index => {
|
|
806
|
+
const master = this.display.details.get(index);
|
|
807
|
+
if (master) return `detail:${this.rowIdOf(master)}`;
|
|
808
|
+
const row = this.rowAt(index);
|
|
809
|
+
return row ? this.rowIdOf(row) : `index:${index}`;
|
|
810
|
+
};
|
|
811
|
+
/** The virtual start of a row: measured, or the fixed row height. */
|
|
812
|
+
startOf(index) {
|
|
813
|
+
if (!this.measured) return this.headerHeight + index * this.rowHeight;
|
|
814
|
+
return this.rowState.virtualizer.measurementsCache[index]?.start ?? this.headerHeight;
|
|
815
|
+
}
|
|
816
|
+
/** Measures a row element (ResizeObserver, through the virtualizer), as `LatticeList` does. */
|
|
817
|
+
measureRow = modifier((element, [index, measured]) => {
|
|
818
|
+
if (!measured) return;
|
|
819
|
+
const virtualizer = this.rowState.virtualizer;
|
|
820
|
+
// Before `syncRows` runs, the virtualizer can still have the old keys.
|
|
821
|
+
const run = () => {
|
|
822
|
+
if (element.isConnected && virtualizer.options.getItemKey(index) === this.keyAt(index)) {
|
|
823
|
+
virtualizer.measureElement(element);
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
queueMicrotask(run);
|
|
827
|
+
return () => virtualizer.measureElement(null);
|
|
828
|
+
});
|
|
829
|
+
toggleGroup = index => {
|
|
830
|
+
const model = this.args.rowModel;
|
|
831
|
+
if (model) model.toggleGroup?.(index);else this.rowAt(index)?.toggleExpanded?.();
|
|
832
|
+
};
|
|
833
|
+
/** True for a row that Enter opens and closes: a group row, or a tree row with sub rows. */
|
|
834
|
+
isToggleRow(index) {
|
|
835
|
+
const model = this.args.rowModel;
|
|
836
|
+
if (model) return model.groupAt?.(index) !== undefined;
|
|
837
|
+
return this.rowAt(index)?.getCanExpand?.() ?? false;
|
|
838
|
+
}
|
|
839
|
+
/** Client rows have levels when the table has the engine expanding feature (ADR 0018). */
|
|
840
|
+
get clientTree() {
|
|
841
|
+
return !this.args.rowModel && this.args.table.toggleAllRowsExpanded !== undefined;
|
|
842
|
+
}
|
|
843
|
+
/** The group of a client group row: the label is the group value and the leaf row count. */
|
|
844
|
+
clientGroup(row, level) {
|
|
845
|
+
if (!row.getIsGrouped?.()) return undefined;
|
|
846
|
+
const column = this.columns.all.find(c => c.id === row.groupingColumnId);
|
|
847
|
+
const value = column ? formatValue(column, row.groupingValue, this.l.locale) : textOf(row.groupingValue);
|
|
848
|
+
const count = row.getLeafRows?.().length ?? 0;
|
|
849
|
+
return {
|
|
850
|
+
level,
|
|
851
|
+
expanded: row.getIsExpanded?.() ?? false,
|
|
852
|
+
label: this.l.t('grid.groupLabel', {
|
|
853
|
+
value: String(value),
|
|
854
|
+
count
|
|
855
|
+
})
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
get headerGroups() {
|
|
859
|
+
return this.args.table.getHeaderGroups();
|
|
860
|
+
}
|
|
861
|
+
/** The header rows: the group rows, the leaf header row and the floating filter row. */
|
|
862
|
+
static {
|
|
863
|
+
n(this.prototype, "headerGroups", [cached]);
|
|
864
|
+
}
|
|
865
|
+
get headerRowCount() {
|
|
866
|
+
return this.leafHeaderRow + (this.args.floatingFilter ? 1 : 0);
|
|
867
|
+
}
|
|
868
|
+
/** The `aria-rowindex` of the floating filter row, or 0 when there is none. */
|
|
869
|
+
get floatingRow() {
|
|
870
|
+
return this.args.floatingFilter ? this.leafHeaderRow + 1 : 0;
|
|
871
|
+
}
|
|
872
|
+
get headerHeight() {
|
|
873
|
+
return this.headerRowCount * this.rowHeight;
|
|
874
|
+
}
|
|
875
|
+
get columns() {
|
|
876
|
+
const table = this.args.table;
|
|
877
|
+
const end = table.getEndVisibleLeafColumns?.() ?? [];
|
|
878
|
+
const allCenter = table.getCenterVisibleLeafColumns?.() ?? table.getVisibleLeafColumns?.() ?? table.getAllLeafColumns();
|
|
879
|
+
// The row number column is pinned at the start, before the pinned columns (ADR 0018).
|
|
880
|
+
const isNumber = c => c.columnDef.meta?.lattice?.rowNumber === true;
|
|
881
|
+
const start = [...allCenter.filter(isNumber), ...(table.getStartVisibleLeafColumns?.() ?? [])];
|
|
882
|
+
const center = allCenter.some(isNumber) ? allCenter.filter(c => !isNumber(c)) : allCenter;
|
|
883
|
+
const width = list => list.reduce((n, c) => n + sizeOf(c), 0);
|
|
884
|
+
const centerSizes = center.map(sizeOf);
|
|
885
|
+
const centerStarts = [];
|
|
886
|
+
let at = 0;
|
|
887
|
+
for (const size of centerSizes) {
|
|
888
|
+
centerStarts.push(at);
|
|
889
|
+
at += size;
|
|
890
|
+
}
|
|
891
|
+
return {
|
|
892
|
+
start,
|
|
893
|
+
center,
|
|
894
|
+
end,
|
|
895
|
+
all: [...start, ...center, ...end],
|
|
896
|
+
centerSizes,
|
|
897
|
+
centerStarts,
|
|
898
|
+
startWidth: width(start),
|
|
899
|
+
centerWidth: at,
|
|
900
|
+
endWidth: width(end)
|
|
901
|
+
};
|
|
902
|
+
}
|
|
903
|
+
static {
|
|
904
|
+
n(this.prototype, "columns", [cached]);
|
|
905
|
+
}
|
|
906
|
+
get totalWidth() {
|
|
907
|
+
const {
|
|
908
|
+
startWidth,
|
|
909
|
+
centerWidth,
|
|
910
|
+
endWidth
|
|
911
|
+
} = this.columns;
|
|
912
|
+
return startWidth + centerWidth + endWidth;
|
|
913
|
+
}
|
|
914
|
+
get colCount() {
|
|
915
|
+
return this.columns.all.length;
|
|
916
|
+
}
|
|
917
|
+
/** The active cell, kept inside the grid when rows or columns go away. */
|
|
918
|
+
get activeCell() {
|
|
919
|
+
const firstData = this.headerRowCount + 1;
|
|
920
|
+
const lastRow = this.headerRowCount + this.rowCount;
|
|
921
|
+
const active = this._active ?? {
|
|
922
|
+
row: Math.min(firstData, lastRow),
|
|
923
|
+
col: 1
|
|
924
|
+
};
|
|
925
|
+
return {
|
|
926
|
+
row: clamp(active.row, this.leafHeaderRow, lastRow),
|
|
927
|
+
col: clamp(active.col, 1, Math.max(this.colCount, 1))
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
/** The 0-based data row of the active cell, or -1 when it is a header cell. */
|
|
931
|
+
get activeIndex() {
|
|
932
|
+
return this.activeCell.row - this.headerRowCount - 1;
|
|
933
|
+
}
|
|
934
|
+
tabIndexFor = (ariaRow, ariaCol) => {
|
|
935
|
+
const active = this.activeCell;
|
|
936
|
+
return active.row === ariaRow && active.col === ariaCol ? 0 : -1;
|
|
937
|
+
};
|
|
938
|
+
rowIdOf = row => this.args.getRowId?.(row) ?? row.id;
|
|
939
|
+
valueFor = (row, column) => {
|
|
940
|
+
const pending = this.args.editing?.pendingValue(row.id, column.id);
|
|
941
|
+
return pending ? pending.value : row.getValue(column.id);
|
|
942
|
+
};
|
|
943
|
+
/** The text of a cheap cell: a staged or saving value of `@editing` first. */
|
|
944
|
+
textFor = (row, column) => {
|
|
945
|
+
const pending = this.args.editing?.pendingValue(row.id, column.id);
|
|
946
|
+
const locale = this.l.locale;
|
|
947
|
+
return pending ? formatValue(column, pending.value, locale) : cellText(row, column, locale);
|
|
948
|
+
};
|
|
949
|
+
isDirty = (row, column) => this.args.editing?.isDirty(row.id, column.id) ?? false;
|
|
950
|
+
stateFor = (rowId, column) => this.cellState.for(rowId, column.id);
|
|
951
|
+
findMatch = (row, column) => this.args.find?.matchAt(row.id, column.id);
|
|
952
|
+
get density() {
|
|
953
|
+
return this.args.density ?? 'normal';
|
|
954
|
+
}
|
|
955
|
+
contains = element => this._element?.contains(element) ?? false;
|
|
956
|
+
/** The cells of one row, in visual order: start-pinned, the center range, end-pinned. */
|
|
957
|
+
get layout() {
|
|
958
|
+
const {
|
|
959
|
+
start,
|
|
960
|
+
center,
|
|
961
|
+
end,
|
|
962
|
+
centerSizes,
|
|
963
|
+
centerStarts,
|
|
964
|
+
centerWidth
|
|
965
|
+
} = this.columns;
|
|
966
|
+
const slots = [];
|
|
967
|
+
const spacer = size => size > 0 ? htmlSafe(`inline-size: ${px$2(size)}`) : null;
|
|
968
|
+
const cell = (column, aria, pin, inset, gap = null) => {
|
|
969
|
+
const lattice = column.columnDef.meta?.lattice;
|
|
970
|
+
const component = lattice?.cell ?? null;
|
|
971
|
+
const size = sizeOf(column);
|
|
972
|
+
return {
|
|
973
|
+
key: column.id,
|
|
974
|
+
column,
|
|
975
|
+
rendered: true,
|
|
976
|
+
gap,
|
|
977
|
+
aria,
|
|
978
|
+
pin,
|
|
979
|
+
size,
|
|
980
|
+
style: columnStyle(size, pin, inset, lattice?.align),
|
|
981
|
+
component,
|
|
982
|
+
full: isFull(column),
|
|
983
|
+
headerSlot: lattice?.header ?? null,
|
|
984
|
+
headerLabel: lattice?.headerLabel ?? null,
|
|
985
|
+
rowNumber: lattice?.rowNumber === true,
|
|
986
|
+
rowDrag: lattice?.rowDrag === true,
|
|
987
|
+
describe: lattice?.cellDescription ?? null,
|
|
988
|
+
invalid: lattice?.cellInvalid ?? null
|
|
989
|
+
};
|
|
990
|
+
};
|
|
991
|
+
let inset = 0;
|
|
992
|
+
start.forEach((column, i) => {
|
|
993
|
+
slots.push(cell(column, i + 1, 'start', inset));
|
|
994
|
+
inset += sizeOf(column);
|
|
995
|
+
});
|
|
996
|
+
// The center range, and the active column, so the one tab stop stays in the DOM.
|
|
997
|
+
const indexes = new Set(this.colState.virtualItems.map(item => item.index));
|
|
998
|
+
// The edited column also stays, so the editor can follow its cell.
|
|
999
|
+
for (const col of [this.activeCell.col, this._editPosition?.col ?? 0]) {
|
|
1000
|
+
const i = col - start.length - 1;
|
|
1001
|
+
if (i >= 0 && i < center.length) indexes.add(i);
|
|
1002
|
+
}
|
|
1003
|
+
let at = 0;
|
|
1004
|
+
center.forEach((column, i) => {
|
|
1005
|
+
const aria = start.length + i + 1;
|
|
1006
|
+
if (!indexes.has(i)) {
|
|
1007
|
+
slots.push({
|
|
1008
|
+
...HIDDEN,
|
|
1009
|
+
key: column.id,
|
|
1010
|
+
column,
|
|
1011
|
+
aria,
|
|
1012
|
+
size: centerSizes[i] ?? 0
|
|
1013
|
+
});
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
const begin = centerStarts[i] ?? 0;
|
|
1017
|
+
slots.push(cell(column, aria, false, 0, spacer(begin - at)));
|
|
1018
|
+
at = begin + (centerSizes[i] ?? 0);
|
|
1019
|
+
});
|
|
1020
|
+
let rest = spacer(centerWidth - at);
|
|
1021
|
+
let after = end.reduce((n, c) => n + sizeOf(c), 0);
|
|
1022
|
+
end.forEach((column, i) => {
|
|
1023
|
+
after -= sizeOf(column);
|
|
1024
|
+
slots.push(cell(column, start.length + center.length + i + 1, 'end', after, rest));
|
|
1025
|
+
rest = null;
|
|
1026
|
+
});
|
|
1027
|
+
return {
|
|
1028
|
+
slots,
|
|
1029
|
+
tail: rest
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
/** The leaf header cells, in the same layout as the rows. */
|
|
1033
|
+
static {
|
|
1034
|
+
n(this.prototype, "layout", [cached]);
|
|
1035
|
+
}
|
|
1036
|
+
get leafHeaders() {
|
|
1037
|
+
const last = this.headerGroups[this.headerGroups.length - 1];
|
|
1038
|
+
return new Map((last?.headers ?? []).map(header => [header.column.id, header]));
|
|
1039
|
+
}
|
|
1040
|
+
/** The group header rows, above the leaf header row. They are not virtualized. */
|
|
1041
|
+
static {
|
|
1042
|
+
n(this.prototype, "leafHeaders", [cached]);
|
|
1043
|
+
}
|
|
1044
|
+
get groupRows() {
|
|
1045
|
+
const all = this.columns.all;
|
|
1046
|
+
return this.headerGroups.slice(0, -1).map((group, depth) => {
|
|
1047
|
+
let at = 0;
|
|
1048
|
+
const cells = [];
|
|
1049
|
+
for (const header of group.headers) {
|
|
1050
|
+
const leaves = all.slice(at, at + header.colSpan);
|
|
1051
|
+
const first = leaves[0];
|
|
1052
|
+
const size = leaves.reduce((n, c) => n + sizeOf(c), 0);
|
|
1053
|
+
const pin = first?.getIsPinned?.() ?? false;
|
|
1054
|
+
const inset = first && pin ? this.insetOf(first, pin) : 0;
|
|
1055
|
+
cells.push({
|
|
1056
|
+
key: header.id,
|
|
1057
|
+
header,
|
|
1058
|
+
label: header.isPlaceholder ? '' : headerLabel(header),
|
|
1059
|
+
aria: at + 1,
|
|
1060
|
+
colSpan: header.colSpan,
|
|
1061
|
+
pin,
|
|
1062
|
+
style: columnStyle(size, pin, inset)
|
|
1063
|
+
});
|
|
1064
|
+
at += header.colSpan;
|
|
1065
|
+
}
|
|
1066
|
+
return {
|
|
1067
|
+
key: group.id,
|
|
1068
|
+
aria: depth + 1,
|
|
1069
|
+
cells
|
|
1070
|
+
};
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
/** The sticky inset of a pinned column: the sizes of the pinned columns nearer the edge. */
|
|
1074
|
+
static {
|
|
1075
|
+
n(this.prototype, "groupRows", [cached]);
|
|
1076
|
+
}
|
|
1077
|
+
insetOf(column, pin) {
|
|
1078
|
+
const list = pin === 'start' ? this.columns.start : this.columns.end;
|
|
1079
|
+
const i = list.findIndex(c => c.id === column.id);
|
|
1080
|
+
const nearer = pin === 'start' ? list.slice(0, Math.max(i, 0)) : list.slice(i + 1);
|
|
1081
|
+
return nearer.reduce((n, c) => n + sizeOf(c), 0);
|
|
1082
|
+
}
|
|
1083
|
+
headerLabelFor = column => {
|
|
1084
|
+
const header = this.leafHeaders.get(column.id);
|
|
1085
|
+
return header ? headerLabel(header) : column.id;
|
|
1086
|
+
};
|
|
1087
|
+
/** The `aria-rowindex` of the leaf header row: the last row of column headers. */
|
|
1088
|
+
get leafHeaderRow() {
|
|
1089
|
+
return Math.max(this.headerGroups.length, 1);
|
|
1090
|
+
}
|
|
1091
|
+
/** The size of the sizer element: the rows, scaled above the cap (ADR 0003). */
|
|
1092
|
+
get sizerStyle() {
|
|
1093
|
+
return htmlSafe(`block-size: ${px$2(this.bodyHeight)}; inline-size: ${px$2(this.totalWidth)}`);
|
|
1094
|
+
}
|
|
1095
|
+
get bodyHeight() {
|
|
1096
|
+
const height = sizerSize({
|
|
1097
|
+
totalSize: this.rowState.totalSize,
|
|
1098
|
+
viewportSize: 0
|
|
1099
|
+
});
|
|
1100
|
+
return Math.max(height - this.headerHeight, 0);
|
|
1101
|
+
}
|
|
1102
|
+
get bodyStyle() {
|
|
1103
|
+
return htmlSafe(`block-size: ${px$2(this.bodyHeight)}; inline-size: ${px$2(this.totalWidth)}`);
|
|
1104
|
+
}
|
|
1105
|
+
get rowWidthStyle() {
|
|
1106
|
+
return htmlSafe(`inline-size: ${px$2(this.totalWidth)}`);
|
|
1107
|
+
}
|
|
1108
|
+
view(index, start, shift, held) {
|
|
1109
|
+
if (index >= this.rowCount) return null;
|
|
1110
|
+
// The real position in the body: the virtual start, moved by the scaled shift (ADR 0003).
|
|
1111
|
+
const top = clamp(start + shift - this.headerHeight, 0, Math.max(this.bodyHeight - this.rowHeight, 0));
|
|
1112
|
+
const measured = this.measured ? `; block-size: auto; min-block-size: ${px$2(this.rowHeight)}` : '';
|
|
1113
|
+
let style = htmlSafe(`transform: translateY(${px$2(top)}); inline-size: ${px$2(this.totalWidth)}${measured}`);
|
|
1114
|
+
const master = this.display.details.get(index);
|
|
1115
|
+
if (master && !this.args.rowModel) {
|
|
1116
|
+
const id = `detail:${this.rowIdOf(master)}`;
|
|
1117
|
+
return {
|
|
1118
|
+
row: undefined,
|
|
1119
|
+
master,
|
|
1120
|
+
id,
|
|
1121
|
+
index,
|
|
1122
|
+
held,
|
|
1123
|
+
style
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
const model = this.args.rowModel;
|
|
1127
|
+
const level = model?.tree ? model.levelAt?.(index) : undefined;
|
|
1128
|
+
const row = this.rowAt(index);
|
|
1129
|
+
if (!row) {
|
|
1130
|
+
const failed = model?.failedAt?.(index) ?? false;
|
|
1131
|
+
return {
|
|
1132
|
+
row: undefined,
|
|
1133
|
+
id: `loading-${index}`,
|
|
1134
|
+
index,
|
|
1135
|
+
held,
|
|
1136
|
+
failed,
|
|
1137
|
+
style,
|
|
1138
|
+
level
|
|
1139
|
+
};
|
|
1140
|
+
}
|
|
1141
|
+
if (model) {
|
|
1142
|
+
const group = model.groupAt?.(index);
|
|
1143
|
+
const expanded = expandedOf(group?.expanded);
|
|
1144
|
+
return {
|
|
1145
|
+
row,
|
|
1146
|
+
id: this.rowIdOf(row),
|
|
1147
|
+
index,
|
|
1148
|
+
held,
|
|
1149
|
+
style,
|
|
1150
|
+
level,
|
|
1151
|
+
group,
|
|
1152
|
+
expanded,
|
|
1153
|
+
treeToggle: false,
|
|
1154
|
+
sticky: false,
|
|
1155
|
+
pinned: undefined,
|
|
1156
|
+
fullWidth: this.args.isFullWidthRow?.(row) ?? false
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
const clientLevel = this.clientTree ? (row.depth ?? 0) + 1 : undefined;
|
|
1160
|
+
const group = clientLevel === undefined ? undefined : this.clientGroup(row, clientLevel);
|
|
1161
|
+
const canExpand = clientLevel !== undefined && (row.getCanExpand?.() ?? false);
|
|
1162
|
+
const expanded = expandedOf(canExpand ? row.getIsExpanded?.() ?? false : undefined);
|
|
1163
|
+
const treeToggle = canExpand && !group;
|
|
1164
|
+
const sticky = expanded === 'true';
|
|
1165
|
+
if (sticky && clientLevel !== undefined) style = this.stickyStyle(index, top, clientLevel);
|
|
1166
|
+
const pinned = this.pinnedAt(index);
|
|
1167
|
+
if (pinned) style = this.pinnedStyle(index, top, pinned);
|
|
1168
|
+
if (this.spansDown(row)) style = htmlSafe(`${String(style)}; z-index: 1`);
|
|
1169
|
+
return {
|
|
1170
|
+
row,
|
|
1171
|
+
id: this.rowIdOf(row),
|
|
1172
|
+
index,
|
|
1173
|
+
held,
|
|
1174
|
+
style,
|
|
1175
|
+
level: clientLevel,
|
|
1176
|
+
group,
|
|
1177
|
+
expanded,
|
|
1178
|
+
treeToggle,
|
|
1179
|
+
sticky,
|
|
1180
|
+
pinned,
|
|
1181
|
+
fullWidth: this.args.isFullWidthRow?.(row) ?? false
|
|
1182
|
+
};
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* An open group row sticks under the header, one row height lower for each level, while its
|
|
1186
|
+
* rows scroll. The last row of its group pushes it up. `--lt-view-top` is the scroll offset in
|
|
1187
|
+
* body px: a scroll listener sets it, so a scroll moves the row with no render (ADR 0018).
|
|
1188
|
+
*/
|
|
1189
|
+
stickyStyle(index, top, level) {
|
|
1190
|
+
const last = this.groupEnds.get(index) ?? index;
|
|
1191
|
+
const end = top + (last - index) * this.rowHeight;
|
|
1192
|
+
const offset = (level - 1) * this.rowHeight + this.pinnedTopHeight;
|
|
1193
|
+
const stuck = `calc(var(--lt-view-top, 0px) + ${px$2(offset)})`;
|
|
1194
|
+
return htmlSafe(`transform: translateY(clamp(${px$2(top)}, ${stuck}, ${px$2(end)})); z-index: 1; ` + `inline-size: ${px$2(this.totalWidth)}`);
|
|
1195
|
+
}
|
|
1196
|
+
/**
|
|
1197
|
+
* The last row of the group of each client row: the row before the next row that is not deeper.
|
|
1198
|
+
* One pass over the rows when they change, so a scroll reads it with no scan (ADR 0018).
|
|
1199
|
+
*/
|
|
1200
|
+
get groupEnds() {
|
|
1201
|
+
const ends = new Map();
|
|
1202
|
+
const open = [];
|
|
1203
|
+
const rows = this.display.rows;
|
|
1204
|
+
const close = (index, depth) => {
|
|
1205
|
+
for (let top = open.at(-1); top && top.depth >= depth; top = open.at(-1)) {
|
|
1206
|
+
ends.set(top.index, index - 1);
|
|
1207
|
+
open.pop();
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
rows.forEach((row, index) => {
|
|
1211
|
+
// A detail row ends all groups, as a row of depth -1.
|
|
1212
|
+
const depth = row ? row.depth ?? 0 : -1;
|
|
1213
|
+
close(index, depth);
|
|
1214
|
+
if (row) open.push({
|
|
1215
|
+
index,
|
|
1216
|
+
depth
|
|
1217
|
+
});
|
|
1218
|
+
});
|
|
1219
|
+
close(rows.length, -Infinity);
|
|
1220
|
+
return ends;
|
|
1221
|
+
}
|
|
1222
|
+
/** `top` or `bottom` for a pinned row: the first rows and the last rows of the list. */
|
|
1223
|
+
static {
|
|
1224
|
+
n(this.prototype, "groupEnds", [cached]);
|
|
1225
|
+
}
|
|
1226
|
+
pinnedAt(index) {
|
|
1227
|
+
const {
|
|
1228
|
+
top,
|
|
1229
|
+
bottom
|
|
1230
|
+
} = this.pinnedRows;
|
|
1231
|
+
if (index < top.length) return 'top';
|
|
1232
|
+
if (index >= this.rowCount - bottom.length) return 'bottom';
|
|
1233
|
+
return undefined;
|
|
1234
|
+
}
|
|
1235
|
+
/** A pinned row floats at the top or the bottom of the view, as a sticky row does. */
|
|
1236
|
+
pinnedStyle(index, top, pinned) {
|
|
1237
|
+
const at = pinned === 'top' ? `max(${px$2(top)}, calc(var(--lt-view-top, 0px) + ${px$2(index * this.rowHeight)}))` : `min(${px$2(top)}, calc(var(--lt-view-bottom, 0px) - ${px$2((this.rowCount - index) * this.rowHeight)}))`;
|
|
1238
|
+
return htmlSafe(`transform: translateY(${at}); z-index: 2; inline-size: ${px$2(this.totalWidth)}`);
|
|
1239
|
+
}
|
|
1240
|
+
/** The index of each client row by its row ID, to find the parent rows of a row. */
|
|
1241
|
+
get clientIndexes() {
|
|
1242
|
+
const map = new Map();
|
|
1243
|
+
this.display.rows.forEach((row, i) => row && map.set(row.id, i));
|
|
1244
|
+
return map;
|
|
1245
|
+
}
|
|
1246
|
+
/** The open parent rows of the rows in range: they stick at the top, so they stay rendered. */
|
|
1247
|
+
static {
|
|
1248
|
+
n(this.prototype, "clientIndexes", [cached]);
|
|
1249
|
+
}
|
|
1250
|
+
parentsOf(indexes) {
|
|
1251
|
+
if (!this.clientTree) return [];
|
|
1252
|
+
const parents = new Set();
|
|
1253
|
+
for (const index of indexes) {
|
|
1254
|
+
let parent = this.rowAt(index)?.getParentRow?.();
|
|
1255
|
+
while (parent) {
|
|
1256
|
+
const at = this.clientIndexes.get(parent.id);
|
|
1257
|
+
if (at === undefined || parents.has(at)) break;
|
|
1258
|
+
parents.add(at);
|
|
1259
|
+
parent = parent.getParentRow?.();
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
return [...parents];
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* The row slots. A row keeps its slot while it is in range, so the slot element and its
|
|
1266
|
+
* cells stay. A row that comes into range takes a free slot. The active row keeps its slot
|
|
1267
|
+
* also when it leaves the range: this is the held row (ADR 0002), with its DOM focus.
|
|
1268
|
+
*/
|
|
1269
|
+
get slots() {
|
|
1270
|
+
const items = this.rowState.virtualItems;
|
|
1271
|
+
const shift = this.scale.shift;
|
|
1272
|
+
const active = this.activeIndex;
|
|
1273
|
+
const wanted = new Map(items.map(item => [item.index, item.start]));
|
|
1274
|
+
// The active row and the edited row keep their slots outside the range (ADR 0002).
|
|
1275
|
+
const edited = this.editPosition ? this.editPosition.row - this.headerRowCount - 1 : -1;
|
|
1276
|
+
const {
|
|
1277
|
+
top,
|
|
1278
|
+
bottom
|
|
1279
|
+
} = this.pinnedRows;
|
|
1280
|
+
const pinned = [...top.map((_, i) => i), ...bottom.map((_, i) => this.rowCount - bottom.length + i)];
|
|
1281
|
+
const anchors = this.spanAnchors(items[0]?.index);
|
|
1282
|
+
for (const held of [active, edited, ...pinned, ...anchors, ...this.parentsOf(wanted.keys())]) {
|
|
1283
|
+
if (held >= 0 && !wanted.has(held)) wanted.set(held, this.startOf(held));
|
|
1284
|
+
}
|
|
1285
|
+
return this.pool.assign([...wanted.keys()]).map(index => index === null ? null : this.view(index, wanted.get(index) ?? 0, shift, index === active || index === edited));
|
|
1286
|
+
}
|
|
1287
|
+
// Modifiers -------------------------------------------------------------------------------
|
|
1288
|
+
static {
|
|
1289
|
+
n(this.prototype, "slots", [cached]);
|
|
1290
|
+
}
|
|
1291
|
+
setup = modifier(scroller => {
|
|
1292
|
+
this._scroller = scroller;
|
|
1293
|
+
this._element = scroller.parentElement;
|
|
1294
|
+
if (this._element) GRIDS.set(this._element, this);
|
|
1295
|
+
const unbind = bindScaledInput(scroller, this.scale);
|
|
1296
|
+
const grid = scroller.parentElement;
|
|
1297
|
+
const host = this.args.stateHost;
|
|
1298
|
+
let detach;
|
|
1299
|
+
// The modifier installs in the render transaction, and `syncRows` and `syncCols` already
|
|
1300
|
+
// read `rtl` and the row height. A tracked write must wait until the transaction ends.
|
|
1301
|
+
void waitForPromise(Promise.resolve().then(() => {
|
|
1302
|
+
if (this._scroller !== scroller) return;
|
|
1303
|
+
// `.lt-grid` has the `dir` of `...attributes`; the root copies it for the overlay.
|
|
1304
|
+
const dir = grid && getComputedStyle(grid).direction === 'rtl' ? 'rtl' : 'ltr';
|
|
1305
|
+
if (dir !== this.dir) this.dir = dir;
|
|
1306
|
+
if (grid) this.readRowHeight(grid);
|
|
1307
|
+
detach = host?.attach(this);
|
|
1308
|
+
}));
|
|
1309
|
+
// Flex columns follow the width of the scroller.
|
|
1310
|
+
const resize = new ResizeObserver(() => this.scheduleFlex());
|
|
1311
|
+
resize.observe(scroller);
|
|
1312
|
+
const onScroll = () => {
|
|
1313
|
+
host?.notify();
|
|
1314
|
+
this.writeViewVars(scroller);
|
|
1315
|
+
if (this.args.aligned) this.scrolledAligned(scroller);
|
|
1316
|
+
};
|
|
1317
|
+
scroller.addEventListener('scroll', onScroll, {
|
|
1318
|
+
passive: true
|
|
1319
|
+
});
|
|
1320
|
+
let observer = null;
|
|
1321
|
+
if (grid) {
|
|
1322
|
+
// A new density preset changes the row height.
|
|
1323
|
+
observer = new MutationObserver(() => this.readRowHeight(grid));
|
|
1324
|
+
observer.observe(grid, {
|
|
1325
|
+
attributes: true,
|
|
1326
|
+
attributeFilter: ['data-lt-density', 'class']
|
|
1327
|
+
});
|
|
1328
|
+
}
|
|
1329
|
+
return () => {
|
|
1330
|
+
scroller.removeEventListener('scroll', onScroll);
|
|
1331
|
+
resize.disconnect();
|
|
1332
|
+
detach?.();
|
|
1333
|
+
observer?.disconnect();
|
|
1334
|
+
unbind();
|
|
1335
|
+
this._scroller = null;
|
|
1336
|
+
this._element = null;
|
|
1337
|
+
};
|
|
1338
|
+
});
|
|
1339
|
+
/** Give the row virtualizer the current row count and sizes. It runs after render. */
|
|
1340
|
+
syncRows = modifier((_el, [count, rowHeight, overscan, headerHeight, footerHeight, pinTop, pinBottom, measured]) => {
|
|
1341
|
+
// A detail row is estimated larger than a row: it is measured after it renders.
|
|
1342
|
+
const details = this.display.details;
|
|
1343
|
+
this.rowState.setOptions({
|
|
1344
|
+
count,
|
|
1345
|
+
estimateSize: i => details.has(i) ? rowHeight * 4 : rowHeight,
|
|
1346
|
+
...(measured && {
|
|
1347
|
+
getItemKey: this.keyAt
|
|
1348
|
+
}),
|
|
1349
|
+
overscan,
|
|
1350
|
+
paddingStart: headerHeight,
|
|
1351
|
+
// The pinned top rows and the sticky header cover the start of the view.
|
|
1352
|
+
scrollPaddingStart: headerHeight + pinTop,
|
|
1353
|
+
// The sticky total row covers the end of the view: a scroll to a row keeps it above.
|
|
1354
|
+
scrollPaddingEnd: footerHeight + pinBottom,
|
|
1355
|
+
scrollScale: this.scale
|
|
1356
|
+
});
|
|
1357
|
+
this.rowState.virtualizer.measure();
|
|
1358
|
+
this.warnFullCells(count);
|
|
1359
|
+
if (this._scroller) this.writeViewVars(this._scroller);
|
|
1360
|
+
});
|
|
1361
|
+
/** Tell the row model the rows in view, and the query, after each render. */
|
|
1362
|
+
syncModel = modifier((_el, [model, start, end, query]) => {
|
|
1363
|
+
model?.setRange(start, end);
|
|
1364
|
+
});
|
|
1365
|
+
/** The first row in view and the row after the last, for `syncModel`. */
|
|
1366
|
+
get range() {
|
|
1367
|
+
const items = this.rowState.virtualItems;
|
|
1368
|
+
const first = items[0]?.index ?? 0;
|
|
1369
|
+
const last = items[items.length - 1]?.index ?? -1;
|
|
1370
|
+
return [first, last + 1];
|
|
1371
|
+
}
|
|
1372
|
+
_warned = false;
|
|
1373
|
+
/**
|
|
1374
|
+
* In development, warn once when a full cell column is on a grid of more than 100,000 rows.
|
|
1375
|
+
* Each new row in view then makes new components, which is slow (ADR 0002). `warn` is a no-op
|
|
1376
|
+
* in production builds.
|
|
1377
|
+
*/
|
|
1378
|
+
warnFullCells(count) {
|
|
1379
|
+
if (this._warned || count <= FULL_CELL_ROW_LIMIT) return;
|
|
1380
|
+
const full = this.columns.all.filter(isFull).map(column => column.id);
|
|
1381
|
+
if (full.length === 0) return;
|
|
1382
|
+
this._warned = true;
|
|
1383
|
+
warn(`LatticeGrid: the columns ${full.join(', ')} have full cell components on a grid of ` + `${count} rows. A full cell makes a new component for each row that scrolls into view. ` + `Use cellKind: 'cheap' for a cell with no local state.`, false, {
|
|
1384
|
+
id: 'ember-lattice.full-cells'
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
/** Give the column virtualizer the center column sizes and the pinned widths. */
|
|
1388
|
+
syncCols = modifier((_el, [sizes, startWidth, endWidth, rtl]) => {
|
|
1389
|
+
this.colState.setOptions({
|
|
1390
|
+
...colOptions(sizes, startWidth, endWidth, rtl),
|
|
1391
|
+
initialRect: viewRect()
|
|
1392
|
+
});
|
|
1393
|
+
this.colState.virtualizer.measure();
|
|
1394
|
+
// A new size, visibility or order of a column changes the free width of the flex columns.
|
|
1395
|
+
this.scheduleFlex();
|
|
1396
|
+
});
|
|
1397
|
+
// Focus and keys ----------------------------------------------------------------------------
|
|
1398
|
+
positionOf(target) {
|
|
1399
|
+
if (!(target instanceof Element)) return null;
|
|
1400
|
+
const cell = target.closest(CELL);
|
|
1401
|
+
const row = cell?.closest('[role="row"]');
|
|
1402
|
+
// A cell of a nested grid (in a detail row) is not a cell of this grid.
|
|
1403
|
+
if (!cell || !row || cell.closest('.lt-grid') !== this._element) return null;
|
|
1404
|
+
return {
|
|
1405
|
+
row: Number(row.getAttribute('aria-rowindex')),
|
|
1406
|
+
col: Number(cell.getAttribute('aria-colindex'))
|
|
1407
|
+
};
|
|
1408
|
+
}
|
|
1409
|
+
onFocusIn = event => {
|
|
1410
|
+
const position = this.positionOf(event.target);
|
|
1411
|
+
if (!position || position.row < this.leafHeaderRow) return;
|
|
1412
|
+
const active = this.activeCell;
|
|
1413
|
+
if (active.row !== position.row || active.col !== position.col) this._active = position;
|
|
1414
|
+
if (position.row > this.headerRowCount) {
|
|
1415
|
+
this.showTooltip(position);
|
|
1416
|
+
this.showNote(position);
|
|
1417
|
+
}
|
|
1418
|
+
};
|
|
1419
|
+
cellElement(position) {
|
|
1420
|
+
// Only the rows of this grid: a detail row can hold a nested grid.
|
|
1421
|
+
const row = `:scope > .lt-scroller > .lt-sizer > * > .lt-row[aria-rowindex="${position.row}"]`;
|
|
1422
|
+
return this._element?.querySelector(`${row} > [aria-colindex="${position.col}"]`) ?? this._element?.querySelector(`${row} > .lt-full-width-cell`) ?? null;
|
|
1423
|
+
}
|
|
1424
|
+
focusActive = () => {
|
|
1425
|
+
this.cellElement(this.activeCell)?.focus();
|
|
1426
|
+
};
|
|
1427
|
+
/** Make a cell the active cell, scroll it into view, and focus it after the render. */
|
|
1428
|
+
activate(position, focus = true) {
|
|
1429
|
+
this._active = position;
|
|
1430
|
+
const index = position.row - this.headerRowCount - 1;
|
|
1431
|
+
if (index >= 0) this.rowState.virtualizer.scrollToIndex(index, {
|
|
1432
|
+
align: 'auto'
|
|
1433
|
+
});
|
|
1434
|
+
const centerIndex = position.col - this.columns.start.length - 1;
|
|
1435
|
+
if (centerIndex >= 0 && centerIndex < this.columns.center.length) {
|
|
1436
|
+
this.colState.virtualizer.scrollToIndex(centerIndex, {
|
|
1437
|
+
align: 'auto'
|
|
1438
|
+
});
|
|
1439
|
+
}
|
|
1440
|
+
if (focus) void waitForPromise(renderSettled().then(this.focusActive));
|
|
1441
|
+
}
|
|
1442
|
+
get pageRows() {
|
|
1443
|
+
const height = this._scroller?.clientHeight ?? 0;
|
|
1444
|
+
return Math.max(Math.floor((height - this.headerHeight) / this.rowHeight), 1);
|
|
1445
|
+
}
|
|
1446
|
+
onKeyDown = event => {
|
|
1447
|
+
this._keyMenu = false;
|
|
1448
|
+
const position = this.positionOf(event.target);
|
|
1449
|
+
if (!position) return;
|
|
1450
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
1451
|
+
const onCell = target?.matches(CELL) ?? false;
|
|
1452
|
+
const isHeader = position.row <= this.headerRowCount;
|
|
1453
|
+
const ctrl = event.ctrlKey || event.metaKey;
|
|
1454
|
+
if (event.key === 'Escape' && this.tooltip) this.tooltip = null;
|
|
1455
|
+
if (!onCell && event.key === 'Escape') {
|
|
1456
|
+
this.leaveWidget(event);
|
|
1457
|
+
return;
|
|
1458
|
+
}
|
|
1459
|
+
if (onCell && !isHeader && this.menuKey(event)) {
|
|
1460
|
+
event.preventDefault();
|
|
1461
|
+
this.openContextMenu(position, true);
|
|
1462
|
+
return;
|
|
1463
|
+
}
|
|
1464
|
+
if (onCell && isHeader && (event.key === 'F2' || position.row === this.floatingRow)) {
|
|
1465
|
+
// F2 (and Enter on a floating filter cell) moves the focus into the cell's control.
|
|
1466
|
+
if (event.key === 'F2' || event.key === 'Enter') {
|
|
1467
|
+
event.preventDefault();
|
|
1468
|
+
this.enterWidget(position);
|
|
1469
|
+
return;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
if (onCell && !isHeader && this.moveKey(event, position)) return;
|
|
1473
|
+
if (onCell && !isHeader && this.editKey(event, position)) return;
|
|
1474
|
+
if (onCell && !isHeader && this.rangeKey(event)) return;
|
|
1475
|
+
if (event.key === 'Enter' && onCell) {
|
|
1476
|
+
event.preventDefault();
|
|
1477
|
+
if (isHeader) this.toggleSort(position, event);else this.activateCell(position);
|
|
1478
|
+
return;
|
|
1479
|
+
}
|
|
1480
|
+
if (event.key === ' ' && onCell && !isHeader) {
|
|
1481
|
+
const row = this.rowAt(position.row - this.headerRowCount - 1);
|
|
1482
|
+
if (row?.toggleSelected && row.getCanSelect?.() !== false) {
|
|
1483
|
+
event.preventDefault();
|
|
1484
|
+
row.toggleSelected(event.shiftKey ? true : !row.getIsSelected?.());
|
|
1485
|
+
}
|
|
1486
|
+
return;
|
|
1487
|
+
}
|
|
1488
|
+
if (ctrl && event.key.toLowerCase() === 'a' && onCell) {
|
|
1489
|
+
const table = this.args.table;
|
|
1490
|
+
if (table.toggleAllRowsSelected && this.multiSelect) {
|
|
1491
|
+
event.preventDefault();
|
|
1492
|
+
table.toggleAllRowsSelected(true);
|
|
1493
|
+
}
|
|
1494
|
+
return;
|
|
1495
|
+
}
|
|
1496
|
+
if (!onCell) return;
|
|
1497
|
+
const next = moveCell(event, this.activeCell, {
|
|
1498
|
+
firstRow: this.leafHeaderRow,
|
|
1499
|
+
lastRow: this.headerRowCount + this.rowCount,
|
|
1500
|
+
colCount: this.colCount,
|
|
1501
|
+
pageRows: this.pageRows,
|
|
1502
|
+
rtl: this.rtl
|
|
1503
|
+
});
|
|
1504
|
+
if (!next) return;
|
|
1505
|
+
event.preventDefault();
|
|
1506
|
+
this.activate(next);
|
|
1507
|
+
this.focusSelection(next);
|
|
1508
|
+
};
|
|
1509
|
+
/** Shift+F10 and the ContextMenu key (APG). */
|
|
1510
|
+
menuKey(event) {
|
|
1511
|
+
return event.key === 'F10' && event.shiftKey || event.key === 'ContextMenu';
|
|
1512
|
+
}
|
|
1513
|
+
/** F2 or Enter: focus the first control in a header slot or a floating filter cell. */
|
|
1514
|
+
enterWidget(position) {
|
|
1515
|
+
const cell = this.cellElement(position);
|
|
1516
|
+
const inCell = position.row === this.floatingRow ? FOCUSABLE : WIDGET_CONTROL;
|
|
1517
|
+
cell?.querySelector(inCell)?.focus();
|
|
1518
|
+
}
|
|
1519
|
+
/** Escape in a header slot or a floating filter: the focus goes back to its cell. */
|
|
1520
|
+
leaveWidget(event) {
|
|
1521
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
1522
|
+
if (event.defaultPrevented || !target?.closest(`${WIDGETS}, .lt-floating-cell`)) return;
|
|
1523
|
+
// A menu or a dialog in the slot handles its own Escape.
|
|
1524
|
+
if (target.closest('[role="menu"], [role="dialog"]')) return;
|
|
1525
|
+
const cell = target.closest(CELL);
|
|
1526
|
+
if (!cell) return;
|
|
1527
|
+
event.preventDefault();
|
|
1528
|
+
cell.focus();
|
|
1529
|
+
}
|
|
1530
|
+
// Context menu ------------------------------------------------------------------------------
|
|
1531
|
+
/** The cell of the open context menu, for the `contextMenu` block. */
|
|
1532
|
+
static {
|
|
1533
|
+
g(this.prototype, "contextTarget", [tracked], function () {
|
|
1534
|
+
return null;
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
#contextTarget = (i(this, "contextTarget"), void 0);
|
|
1538
|
+
/** True after a key opened the menu: the `contextmenu` event of the same key is ignored. */_keyMenu = false;
|
|
1539
|
+
openContextMenu(position, keyboard, x = 0, y = 0) {
|
|
1540
|
+
const row = this.rowAt(position.row - this.headerRowCount - 1);
|
|
1541
|
+
const column = this.columnAt(position.col);
|
|
1542
|
+
if (!row || !column) return false;
|
|
1543
|
+
if (keyboard) {
|
|
1544
|
+
this._keyMenu = true;
|
|
1545
|
+
const box = this.cellElement(position)?.getBoundingClientRect();
|
|
1546
|
+
x = box?.left ?? 0;
|
|
1547
|
+
y = box?.bottom ?? 0;
|
|
1548
|
+
} else if (this.activeCell.row !== position.row || this.activeCell.col !== position.col) {
|
|
1549
|
+
this._active = position;
|
|
1550
|
+
this.focusSelection(position);
|
|
1551
|
+
}
|
|
1552
|
+
const target = {
|
|
1553
|
+
row,
|
|
1554
|
+
column,
|
|
1555
|
+
x,
|
|
1556
|
+
y,
|
|
1557
|
+
keyboard
|
|
1558
|
+
};
|
|
1559
|
+
this.contextTarget = target;
|
|
1560
|
+
this.args.onCellContextMenu?.(target);
|
|
1561
|
+
return true;
|
|
1562
|
+
}
|
|
1563
|
+
/** A right click on a body cell. With no hook and no block, the browser menu opens. */ /** True when the grid has a context menu: the `contextMenu` block or `@onCellContextMenu`. */
|
|
1564
|
+
get _hasMenu() {
|
|
1565
|
+
return this._menuBlock || this.args.onCellContextMenu !== undefined;
|
|
1566
|
+
}
|
|
1567
|
+
_menuBlock = false;
|
|
1568
|
+
/** The template tells the grid when it has a `contextMenu` block. */
|
|
1569
|
+
noteMenuBlock = modifier((_el, [hasBlock]) => {
|
|
1570
|
+
this._menuBlock = hasBlock;
|
|
1571
|
+
});
|
|
1572
|
+
onContextMenu = (hasMenu, event) => {
|
|
1573
|
+
// Android sends `contextmenu` during a long press: the press timer must not open a second menu.
|
|
1574
|
+
this._stopPress?.();
|
|
1575
|
+
if (this._keyMenu) {
|
|
1576
|
+
this._keyMenu = false;
|
|
1577
|
+
event.preventDefault();
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
if (!hasMenu && !this.args.onCellContextMenu) return;
|
|
1581
|
+
const position = this.positionOf(event.target);
|
|
1582
|
+
if (!position || position.row <= this.headerRowCount) return;
|
|
1583
|
+
// The focus goes to the cell now, before the menu opens, as a press of a real pointer does.
|
|
1584
|
+
this.cellElement(position)?.focus();
|
|
1585
|
+
if (this.openContextMenu(position, false, event.clientX, event.clientY)) event.preventDefault();
|
|
1586
|
+
};
|
|
1587
|
+
closeMenu = () => {
|
|
1588
|
+
this.contextTarget = null;
|
|
1589
|
+
};
|
|
1590
|
+
/** The selection as TSV, for a menu "Copy". With headers: the header labels come first. */
|
|
1591
|
+
copyText = (withHeaders = false) => this.selection.map(range => {
|
|
1592
|
+
const rows = this.cellsOf(range).map(row => row.map(c => this.textFor(c.row, c.column)));
|
|
1593
|
+
if (!withHeaders) return toTsv(rows);
|
|
1594
|
+
const columns = this.columns.all.slice(range.minColumnIndex, range.maxColumnIndex + 1);
|
|
1595
|
+
return toTsv([columns.map(this.headerLabelFor), ...rows]);
|
|
1596
|
+
}).join('\n');
|
|
1597
|
+
/** Pastes TSV at the start corner of the last range, through `@editing` (one undo step). */
|
|
1598
|
+
pasteText = async text => {
|
|
1599
|
+
const editing = this.args.editing;
|
|
1600
|
+
const origin = this.selection[this.selection.length - 1];
|
|
1601
|
+
if (!editing || !origin) return;
|
|
1602
|
+
const {
|
|
1603
|
+
minRowIndex: row,
|
|
1604
|
+
minColumnIndex: col
|
|
1605
|
+
} = origin;
|
|
1606
|
+
// With `@rowModel`, a paste that reaches a row that is not loaded is refused as a whole.
|
|
1607
|
+
const last = Math.min(row + tsvRowCount(text), this.rowCount);
|
|
1608
|
+
for (let i = row; i < last; i++) {
|
|
1609
|
+
if (!this.rowAt(i)) {
|
|
1610
|
+
this.liveMessage = this.l.t('grid.pasteRefused');
|
|
1611
|
+
return;
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
await editing.paste(text, (r, c) => this.cellRefAt(row + r, col + c));
|
|
1615
|
+
};
|
|
1616
|
+
// Live region -------------------------------------------------------------------------------
|
|
1617
|
+
/** The last grid message (a sort, a refused paste), for the live region. */
|
|
1618
|
+
static {
|
|
1619
|
+
g(this.prototype, "liveMessage", [tracked], function () {
|
|
1620
|
+
return '';
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
#liveMessage = (i(this, "liveMessage"), void 0);
|
|
1624
|
+
get countMessage() {
|
|
1625
|
+
const count = this.args.rowModel ? this.args.rowModel.rowCount : this.rowCount;
|
|
1626
|
+
return count === null ? '' : this.l.plural('grid.rowCount', count);
|
|
1627
|
+
}
|
|
1628
|
+
announceSort(column) {
|
|
1629
|
+
const label = this.headerLabelFor(column);
|
|
1630
|
+
const sorted = column.getIsSorted?.();
|
|
1631
|
+
const key = sorted === 'asc' ? 'grid.sortedAscending' : 'grid.sortedDescending';
|
|
1632
|
+
this.liveMessage = this.l.t(sorted ? key : 'grid.sortRemoved', {
|
|
1633
|
+
column: label
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
// Scroll to a cell --------------------------------------------------------------------------
|
|
1637
|
+
/** The index of a row by its ID (with a row model: of a loaded row), or -1. */
|
|
1638
|
+
indexOfRow(rowId) {
|
|
1639
|
+
// shortcut: a linear search of the rows (with a row model, only the loaded rows); index the IDs if this is slow.
|
|
1640
|
+
for (let i = 0; i < this.rowCount; i++) {
|
|
1641
|
+
const row = this.rowAt(i);
|
|
1642
|
+
if (row && this.rowIdOf(row) === rowId) return i;
|
|
1643
|
+
}
|
|
1644
|
+
return -1;
|
|
1645
|
+
}
|
|
1646
|
+
scrollToCell(rowId, columnId) {
|
|
1647
|
+
const col = this.columns.all.findIndex(c => c.id === columnId);
|
|
1648
|
+
const index = col < 0 ? -1 : this.indexOfRow(rowId);
|
|
1649
|
+
if (index < 0) return false;
|
|
1650
|
+
this.activate({
|
|
1651
|
+
row: this.headerRowCount + index + 1,
|
|
1652
|
+
col: col + 1
|
|
1653
|
+
}, false);
|
|
1654
|
+
return true;
|
|
1655
|
+
}
|
|
1656
|
+
/** Opens the editor of a cell, as F2 does (`GridStateHandle.startEditing`). */
|
|
1657
|
+
startEditing(rowId, columnId) {
|
|
1658
|
+
const editing = this.args.editing;
|
|
1659
|
+
const col = this.columns.all.findIndex(c => c.id === columnId);
|
|
1660
|
+
const index = col < 0 ? -1 : this.indexOfRow(rowId);
|
|
1661
|
+
const cell = index < 0 ? undefined : this.cellRefAt(index, col);
|
|
1662
|
+
if (!editing || !cell || this.isToggleRow(index) || !editing.canEdit(cell)) return false;
|
|
1663
|
+
this.startEdit({
|
|
1664
|
+
row: this.headerRowCount + index + 1,
|
|
1665
|
+
col: col + 1
|
|
1666
|
+
}, cell);
|
|
1667
|
+
return true;
|
|
1668
|
+
}
|
|
1669
|
+
columnAt(ariaCol) {
|
|
1670
|
+
return this.columns.all[ariaCol - 1];
|
|
1671
|
+
}
|
|
1672
|
+
activateCell(position) {
|
|
1673
|
+
const index = position.row - this.headerRowCount - 1;
|
|
1674
|
+
if (this.isToggleRow(index)) {
|
|
1675
|
+
this.toggleGroup(index);
|
|
1676
|
+
return;
|
|
1677
|
+
}
|
|
1678
|
+
const row = this.rowAt(index);
|
|
1679
|
+
const column = this.columnAt(position.col);
|
|
1680
|
+
if (row && column) this.args.onCellActivate?.({
|
|
1681
|
+
row,
|
|
1682
|
+
column
|
|
1683
|
+
});
|
|
1684
|
+
}
|
|
1685
|
+
onDoubleClick = event => {
|
|
1686
|
+
const position = this.positionOf(event.target);
|
|
1687
|
+
if (!position || position.row <= this.headerRowCount) return;
|
|
1688
|
+
if (this.pointerEdit(event, position, 'doubleClick')) return;
|
|
1689
|
+
// With the `singleClick` trigger, the first click of the double click opened the editor.
|
|
1690
|
+
if (!this.args.editing?.active) this.activateCell(position);
|
|
1691
|
+
};
|
|
1692
|
+
/** A click opens the editor of a column with the `singleClick` trigger. */
|
|
1693
|
+
onClick = event => {
|
|
1694
|
+
const position = this.positionOf(event.target);
|
|
1695
|
+
if (position && position.row > this.headerRowCount) this.pointerEdit(event, position, 'singleClick');
|
|
1696
|
+
};
|
|
1697
|
+
/**
|
|
1698
|
+
* Opens the editor for a pointer action, when it is the trigger of the column. A click with a
|
|
1699
|
+
* modifier key (a range) or on a button or a link in the cell does not open it. A click on a
|
|
1700
|
+
* display input (the stars of a rating) opens it. True: the editor opens.
|
|
1701
|
+
*/
|
|
1702
|
+
pointerEdit(event, position, trigger) {
|
|
1703
|
+
const editing = this.args.editing;
|
|
1704
|
+
if (!editing || event.shiftKey || event.ctrlKey || event.metaKey || event.altKey) return false;
|
|
1705
|
+
const target = event.target;
|
|
1706
|
+
if (target instanceof Element && target.closest('button, a[href]')) {
|
|
1707
|
+
return false;
|
|
1708
|
+
}
|
|
1709
|
+
// A group row toggles; it has no editor.
|
|
1710
|
+
const index = position.row - this.headerRowCount - 1;
|
|
1711
|
+
if (this.isToggleRow(index)) return false;
|
|
1712
|
+
const cell = this.cellRefAt(index, position.col - 1);
|
|
1713
|
+
if (!cell || !editing.canEdit(cell)) return false;
|
|
1714
|
+
const own = cell.column.columnDef.meta?.lattice?.editTrigger;
|
|
1715
|
+
if ((own ?? this.args.editTrigger ?? 'doubleClick') !== trigger) return false;
|
|
1716
|
+
// The press on the cell saved the open edit first. A value that is not valid keeps it open.
|
|
1717
|
+
const saved = this._pressCommit ?? Promise.resolve(true);
|
|
1718
|
+
void waitForPromise(saved.then(ok => {
|
|
1719
|
+
if (ok && !editing.active && !editing.activeRow) this.startEdit(position, cell);
|
|
1720
|
+
}));
|
|
1721
|
+
return true;
|
|
1722
|
+
}
|
|
1723
|
+
get selectable() {
|
|
1724
|
+
return this.rowAt(0)?.toggleSelected !== undefined;
|
|
1725
|
+
}
|
|
1726
|
+
get multiSelect() {
|
|
1727
|
+
return this.selectable && (this.rowAt(0)?.getCanMultiSelect?.() ?? false);
|
|
1728
|
+
}
|
|
1729
|
+
get multiselectable() {
|
|
1730
|
+
return this.multiSelect || this.cellSelectable;
|
|
1731
|
+
}
|
|
1732
|
+
// Ranges (the engine cell selection) ------------------------------------------------------
|
|
1733
|
+
/** True when the table has the cell selection feature: ranges of cells. */
|
|
1734
|
+
get cellSelectable() {
|
|
1735
|
+
return this.args.table.getCellSelectionBounds !== undefined;
|
|
1736
|
+
}
|
|
1737
|
+
/** Client rows use the engine ranges. With `@rowModel`, the grid owns one range. */
|
|
1738
|
+
get engineRanges() {
|
|
1739
|
+
return this.cellSelectable && !this.args.rowModel;
|
|
1740
|
+
}
|
|
1741
|
+
/** The grid range with `@rowModel`: two corners as 0-based row and column indexes. */
|
|
1742
|
+
static {
|
|
1743
|
+
g(this.prototype, "_range", [tracked], function () {
|
|
1744
|
+
return null;
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
#_range = (i(this, "_range"), void 0);
|
|
1748
|
+
/** The cell ranges, or the active cell as a range when there is no range. */get selection() {
|
|
1749
|
+
const ranges = this.engineRanges ? this.args.table.getCellSelectionBounds?.() ?? [] : [];
|
|
1750
|
+
if (ranges.length > 0) return [...ranges];
|
|
1751
|
+
const own = this.args.rowModel ? this._range : null;
|
|
1752
|
+
if (own) {
|
|
1753
|
+
const [r1, c1] = own.anchor;
|
|
1754
|
+
const [r2, c2] = own.focus;
|
|
1755
|
+
return [{
|
|
1756
|
+
minRowIndex: Math.min(r1, r2),
|
|
1757
|
+
maxRowIndex: Math.max(r1, r2),
|
|
1758
|
+
minColumnIndex: Math.min(c1, c2),
|
|
1759
|
+
maxColumnIndex: Math.max(c1, c2)
|
|
1760
|
+
}];
|
|
1761
|
+
}
|
|
1762
|
+
const index = this.activeIndex;
|
|
1763
|
+
const col = this.activeCell.col - 1;
|
|
1764
|
+
if (index < 0) return [];
|
|
1765
|
+
return [{
|
|
1766
|
+
minRowIndex: index,
|
|
1767
|
+
maxRowIndex: index,
|
|
1768
|
+
minColumnIndex: col,
|
|
1769
|
+
maxColumnIndex: col
|
|
1770
|
+
}];
|
|
1771
|
+
}
|
|
1772
|
+
/** `aria-selected` of a cell: in a range (or the active cell when there is no range). */
|
|
1773
|
+
static {
|
|
1774
|
+
n(this.prototype, "selection", [cached]);
|
|
1775
|
+
}
|
|
1776
|
+
cellSelected = (index, ariaCol) => {
|
|
1777
|
+
if (!this.cellSelectable) return undefined;
|
|
1778
|
+
return this.selection.some(range => inRange(range, index, ariaCol - 1)) ? 'true' : 'false';
|
|
1779
|
+
};
|
|
1780
|
+
/** The logical edges of the ranges that a cell sits on, for the range borders of the theme. */
|
|
1781
|
+
rangeEdge = (index, ariaCol) => {
|
|
1782
|
+
if (!this.cellSelectable) return undefined;
|
|
1783
|
+
const col = ariaCol - 1;
|
|
1784
|
+
const edges = new Set();
|
|
1785
|
+
for (const range of this.selection) {
|
|
1786
|
+
if (!inRange(range, index, col)) continue;
|
|
1787
|
+
if (index === range.minRowIndex) edges.add('block-start');
|
|
1788
|
+
if (index === range.maxRowIndex) edges.add('block-end');
|
|
1789
|
+
if (col === range.minColumnIndex) edges.add('inline-start');
|
|
1790
|
+
if (col === range.maxColumnIndex) edges.add('inline-end');
|
|
1791
|
+
}
|
|
1792
|
+
const order = ['block-start', 'block-end', 'inline-start', 'inline-end'];
|
|
1793
|
+
return edges.size > 0 ? order.filter(edge => edges.has(edge)).join(' ') : undefined;
|
|
1794
|
+
};
|
|
1795
|
+
/** The fill handle is on the end corner of the last range. */
|
|
1796
|
+
isFillCorner = (index, ariaCol) => {
|
|
1797
|
+
// shortcut: no fill handle with `@rowModel`; the fill grows an engine range.
|
|
1798
|
+
if (!this.args.editing || !this.engineRanges) return false;
|
|
1799
|
+
const range = this.selection[this.selection.length - 1];
|
|
1800
|
+
return range?.maxRowIndex === index && range.maxColumnIndex === ariaCol - 1;
|
|
1801
|
+
};
|
|
1802
|
+
/** The cell at 0-based display indexes, or undefined outside the loaded rows. */
|
|
1803
|
+
cellRefAt(index, col) {
|
|
1804
|
+
const row = index >= 0 ? this.rowAt(index) : undefined;
|
|
1805
|
+
const column = this.columns.all[col];
|
|
1806
|
+
return row && column ? {
|
|
1807
|
+
row,
|
|
1808
|
+
column
|
|
1809
|
+
} : undefined;
|
|
1810
|
+
}
|
|
1811
|
+
/** The cells of a range, row by row. */
|
|
1812
|
+
cellsOf(range) {
|
|
1813
|
+
const rows = [];
|
|
1814
|
+
// shortcut: a range of all rows makes one array of all its cells; stream it if copies of 1M rows are slow.
|
|
1815
|
+
for (let i = range.minRowIndex; i <= range.maxRowIndex; i++) {
|
|
1816
|
+
const row = [];
|
|
1817
|
+
for (let c = range.minColumnIndex; c <= range.maxColumnIndex; c++) {
|
|
1818
|
+
const cell = this.cellRefAt(i, c);
|
|
1819
|
+
if (cell) row.push(cell);
|
|
1820
|
+
}
|
|
1821
|
+
rows.push(row);
|
|
1822
|
+
}
|
|
1823
|
+
return rows;
|
|
1824
|
+
}
|
|
1825
|
+
/** Makes the cell at a position the one-cell range: a move with no Shift. */
|
|
1826
|
+
focusSelection(position) {
|
|
1827
|
+
this._range = null;
|
|
1828
|
+
if (!this.engineRanges) return;
|
|
1829
|
+
const cell = this.cellRefAt(position.row - this.headerRowCount - 1, position.col - 1);
|
|
1830
|
+
if (cell) this.args.table.setFocusedCell?.(cell.row.id, cell.column.id);
|
|
1831
|
+
}
|
|
1832
|
+
/** Shift+arrows extend the last range; Ctrl+A selects all cells. */
|
|
1833
|
+
rangeKey(event) {
|
|
1834
|
+
const table = this.args.table;
|
|
1835
|
+
if (!this.cellSelectable) return false;
|
|
1836
|
+
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'a') {
|
|
1837
|
+
event.preventDefault();
|
|
1838
|
+
if (this.engineRanges) table.selectAllCells?.();else this._range = {
|
|
1839
|
+
anchor: [0, 0],
|
|
1840
|
+
focus: [this.rowCount - 1, this.colCount - 1]
|
|
1841
|
+
};
|
|
1842
|
+
return true;
|
|
1843
|
+
}
|
|
1844
|
+
const forward = this.rtl ? 'left' : 'right';
|
|
1845
|
+
const back = this.rtl ? 'right' : 'left';
|
|
1846
|
+
const directions = {
|
|
1847
|
+
ArrowUp: 'up',
|
|
1848
|
+
ArrowDown: 'down',
|
|
1849
|
+
ArrowLeft: back,
|
|
1850
|
+
ArrowRight: forward
|
|
1851
|
+
};
|
|
1852
|
+
const direction = event.shiftKey && !event.ctrlKey ? directions[event.key] : undefined;
|
|
1853
|
+
if (!direction) return false;
|
|
1854
|
+
event.preventDefault();
|
|
1855
|
+
if (!this.engineRanges) {
|
|
1856
|
+
this.extendOwnRange(direction);
|
|
1857
|
+
return true;
|
|
1858
|
+
}
|
|
1859
|
+
if (!table.getFocusedCell?.()) this.focusSelection(this.activeCell);
|
|
1860
|
+
table.extendCellSelection?.(direction);
|
|
1861
|
+
return true;
|
|
1862
|
+
}
|
|
1863
|
+
/** Moves the focus corner of the grid range (`@rowModel`), from the active cell at first. */
|
|
1864
|
+
extendOwnRange(direction) {
|
|
1865
|
+
const start = [this.activeIndex, this.activeCell.col - 1];
|
|
1866
|
+
const range = this._range ?? {
|
|
1867
|
+
anchor: start,
|
|
1868
|
+
focus: start
|
|
1869
|
+
};
|
|
1870
|
+
const [row, col] = range.focus;
|
|
1871
|
+
const step = {
|
|
1872
|
+
up: [-1, 0],
|
|
1873
|
+
down: [1, 0],
|
|
1874
|
+
left: [0, -1],
|
|
1875
|
+
right: [0, 1]
|
|
1876
|
+
}[direction] ?? [0, 0];
|
|
1877
|
+
const focus = [clamp(row + (step[0] ?? 0), 0, this.rowCount - 1), clamp(col + (step[1] ?? 0), 0, this.colCount - 1)];
|
|
1878
|
+
this._range = {
|
|
1879
|
+
anchor: range.anchor,
|
|
1880
|
+
focus
|
|
1881
|
+
};
|
|
1882
|
+
}
|
|
1883
|
+
/** The engine cell under a mouse event, for a press (a range start) or a drag. */
|
|
1884
|
+
engineCell(target) {
|
|
1885
|
+
if (!this.engineRanges) return undefined;
|
|
1886
|
+
const position = this.positionOf(target);
|
|
1887
|
+
if (!position || position.row <= this.headerRowCount) return undefined;
|
|
1888
|
+
const cell = this.cellRefAt(position.row - this.headerRowCount - 1, position.col - 1);
|
|
1889
|
+
return cell?.row.getAllCellsByColumnId()[cell.column.id];
|
|
1890
|
+
}
|
|
1891
|
+
/** A press starts a range; Shift extends the last range, Ctrl adds a range (the engine). */
|
|
1892
|
+
onMouseDown = event => {
|
|
1893
|
+
this._keyMenu = false;
|
|
1894
|
+
if (event.button !== 0) return;
|
|
1895
|
+
// shortcut: a press ends the grid range (`@rowModel`); Shift+click does not extend it yet.
|
|
1896
|
+
if (this.onBodyCell(event.target)) this._range = null;
|
|
1897
|
+
// A press on a cell outside the editor ends the edit with a commit, as in a spreadsheet.
|
|
1898
|
+
const editing = this.args.editing;
|
|
1899
|
+
this._pressCommit = null;
|
|
1900
|
+
if (editing?.active && this.onBodyCell(event.target)) {
|
|
1901
|
+
this._pressCommit = this.commitOnce(editing);
|
|
1902
|
+
// A value that is not valid keeps the edit open: the focus goes back into the editor after
|
|
1903
|
+
// the press moves it to the cell.
|
|
1904
|
+
const refocus = this._pressCommit.then(async ok => {
|
|
1905
|
+
if (ok || !editing.active) return;
|
|
1906
|
+
await new Promise(resolve => setTimeout(resolve));
|
|
1907
|
+
this.focusEditor(this.editorId);
|
|
1908
|
+
});
|
|
1909
|
+
void waitForPromise(refocus);
|
|
1910
|
+
}
|
|
1911
|
+
this.engineCell(event.target)?.getSelectionStartHandler?.(this._element?.ownerDocument)(event);
|
|
1912
|
+
};
|
|
1913
|
+
onMouseOver = event => {
|
|
1914
|
+
this.engineCell(event.target)?.getSelectionExtendHandler?.()(event);
|
|
1915
|
+
const position = this.positionOf(event.target);
|
|
1916
|
+
if (position && position.row > this.headerRowCount) {
|
|
1917
|
+
this.showTooltip(position);
|
|
1918
|
+
this.showNote(position);
|
|
1919
|
+
}
|
|
1920
|
+
};
|
|
1921
|
+
onMouseOut = event => {
|
|
1922
|
+
const from = this.positionOf(event.target);
|
|
1923
|
+
const to = this.positionOf(event.relatedTarget);
|
|
1924
|
+
if (from && (from.row !== to?.row || from.col !== to.col)) {
|
|
1925
|
+
this.hideTooltip(from);
|
|
1926
|
+
this.hideNote(from);
|
|
1927
|
+
}
|
|
1928
|
+
};
|
|
1929
|
+
onFocusOut = event => {
|
|
1930
|
+
const position = this.positionOf(event.target);
|
|
1931
|
+
if (position) {
|
|
1932
|
+
this.hideTooltip(position);
|
|
1933
|
+
this.hideNote(position);
|
|
1934
|
+
}
|
|
1935
|
+
};
|
|
1936
|
+
// Overlays (ADR 0018) -------------------------------------------------------------------------
|
|
1937
|
+
/** The loading message, or "No rows" for an empty grid. Outside `role=grid`, as a status. */
|
|
1938
|
+
get overlayMessage() {
|
|
1939
|
+
if (this.args.loading) return this.l.t('grid.loading');
|
|
1940
|
+
// A row model with no known count is still in its first load: no "No rows" yet.
|
|
1941
|
+
const count = this.args.rowModel ? this.args.rowModel.rowCount : this.rowCount;
|
|
1942
|
+
return count === 0 ? this.l.t('grid.noRows') : '';
|
|
1943
|
+
}
|
|
1944
|
+
// Tooltips (ADR 0018) -------------------------------------------------------------------------
|
|
1945
|
+
tooltipId = `${guidFor(this)}-tooltip`;
|
|
1946
|
+
/** The cell of the tooltip, its text and its place in the viewport. */
|
|
1947
|
+
static {
|
|
1948
|
+
g(this.prototype, "tooltip", [tracked], function () {
|
|
1949
|
+
return null;
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
#tooltip = (i(this, "tooltip"), void 0);
|
|
1953
|
+
/**
|
|
1954
|
+
* The `aria-describedby` of a cell: its own description (`meta.lattice.cellDescription`), then
|
|
1955
|
+
* the open tooltip and the open note.
|
|
1956
|
+
*/
|
|
1957
|
+
describedBy = (index, slot, row) => {
|
|
1958
|
+
const own = slot.describe?.(row, slot.column) ? this.descriptionId(index, slot.aria) : false;
|
|
1959
|
+
const tip = this.tooltip;
|
|
1960
|
+
const note = this.note;
|
|
1961
|
+
// Each cell calls this on each render: no work when nothing is open.
|
|
1962
|
+
if (!tip && !note) return own || undefined;
|
|
1963
|
+
const at = this.headerRowCount + index + 1;
|
|
1964
|
+
const on = open => open?.row === at && open.col === slot.aria;
|
|
1965
|
+
const ids = [own, on(tip) && this.tooltipId, on(note) && this.noteId].filter(Boolean);
|
|
1966
|
+
return ids.length > 0 ? ids.join(' ') : undefined;
|
|
1967
|
+
};
|
|
1968
|
+
/** `aria-invalid` of a cell, from `meta.lattice.cellInvalid`. */
|
|
1969
|
+
invalidFor = (row, slot) => slot.invalid?.(row, slot.column) ? 'true' : undefined;
|
|
1970
|
+
descriptionId = (index, ariaCol) => `${guidFor(this)}-description-${index}-${ariaCol}`;
|
|
1971
|
+
/** The descriptions of the rendered cells, in a hidden list outside `role=grid`. */
|
|
1972
|
+
get cellDescriptions() {
|
|
1973
|
+
const described = this.layout.slots.filter(slot => slot.rendered && slot.describe);
|
|
1974
|
+
if (described.length === 0) return [];
|
|
1975
|
+
const list = [];
|
|
1976
|
+
for (const slot of this.slots) {
|
|
1977
|
+
const view = slot ? asRowView(slot) : undefined;
|
|
1978
|
+
const row = view?.row;
|
|
1979
|
+
if (!view || !row) continue;
|
|
1980
|
+
for (const slot of described) {
|
|
1981
|
+
const text = slot.describe?.(row, slot.column);
|
|
1982
|
+
if (text) list.push({
|
|
1983
|
+
id: this.descriptionId(view.index, slot.aria),
|
|
1984
|
+
text
|
|
1985
|
+
});
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
return list;
|
|
1989
|
+
}
|
|
1990
|
+
// Notes (contract section 11) -----------------------------------------------------------------
|
|
1991
|
+
static {
|
|
1992
|
+
n(this.prototype, "cellDescriptions", [cached]);
|
|
1993
|
+
}
|
|
1994
|
+
noteId = `${guidFor(this)}-note`;
|
|
1995
|
+
/** The cell of the open note and its text. */
|
|
1996
|
+
static {
|
|
1997
|
+
g(this.prototype, "note", [tracked], function () {
|
|
1998
|
+
return null;
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
2001
|
+
#note = (i(this, "note"), void 0);
|
|
2002
|
+
hasNote = (row, column) => {
|
|
2003
|
+
const notes = this.args.notes;
|
|
2004
|
+
return notes !== undefined && notes.noteAt(row.id, column.id) !== undefined;
|
|
2005
|
+
};
|
|
2006
|
+
showNote(position) {
|
|
2007
|
+
const notes = this.args.notes;
|
|
2008
|
+
if (!notes) return;
|
|
2009
|
+
const row = this.rowAt(position.row - this.headerRowCount - 1);
|
|
2010
|
+
const column = this.columnAt(position.col);
|
|
2011
|
+
const text = row && column ? notes.noteAt(row.id, column.id) : undefined;
|
|
2012
|
+
const old = this.note;
|
|
2013
|
+
if (old && old.row === position.row && old.col === position.col && old.text === text) return;
|
|
2014
|
+
// A tracked write renders all cells again: write only a change.
|
|
2015
|
+
if (text) this.note = {
|
|
2016
|
+
row: position.row,
|
|
2017
|
+
col: position.col,
|
|
2018
|
+
text
|
|
2019
|
+
};else if (old) this.note = null;
|
|
2020
|
+
}
|
|
2021
|
+
hideNote(position) {
|
|
2022
|
+
const note = this.note;
|
|
2023
|
+
if (note && note.row === position.row && note.col === position.col) this.note = null;
|
|
2024
|
+
}
|
|
2025
|
+
/**
|
|
2026
|
+
* Puts the note under its cell, by measurement as in `placeEditor`, and again on each scroll.
|
|
2027
|
+
* When the tooltip of the same cell is open, the note goes under the tooltip, so they do not
|
|
2028
|
+
* overlap. When the cell is not rendered, the note hides.
|
|
2029
|
+
*/
|
|
2030
|
+
placeNote = modifier((box, [note, tip]) => {
|
|
2031
|
+
const scroller = this._scroller;
|
|
2032
|
+
const place = () => {
|
|
2033
|
+
const cell = note && this.cellElement(note);
|
|
2034
|
+
box.hidden = !cell;
|
|
2035
|
+
if (!cell) return;
|
|
2036
|
+
const sameCell = tip !== null && note !== null && tip.row === note.row && tip.col === note.col;
|
|
2037
|
+
const anchor = sameCell && box.parentElement?.querySelector(':scope > .lt-tooltip') || cell;
|
|
2038
|
+
Object.assign(box.style, {
|
|
2039
|
+
position: 'absolute',
|
|
2040
|
+
top: '0px',
|
|
2041
|
+
left: '0px',
|
|
2042
|
+
zIndex: '10'
|
|
2043
|
+
});
|
|
2044
|
+
const at = box.getBoundingClientRect();
|
|
2045
|
+
const scale = box.offsetWidth > 0 ? at.width / box.offsetWidth : 1;
|
|
2046
|
+
const to = anchor.getBoundingClientRect();
|
|
2047
|
+
box.style.top = px$2((to.bottom - at.top) / (scale || 1));
|
|
2048
|
+
box.style.left = px$2((to.left - at.left) / (scale || 1));
|
|
2049
|
+
};
|
|
2050
|
+
place();
|
|
2051
|
+
scroller?.addEventListener('scroll', place, {
|
|
2052
|
+
passive: true
|
|
2053
|
+
});
|
|
2054
|
+
return () => scroller?.removeEventListener('scroll', place);
|
|
2055
|
+
});
|
|
2056
|
+
showTooltip(position) {
|
|
2057
|
+
const row = this.rowAt(position.row - this.headerRowCount - 1);
|
|
2058
|
+
const column = this.columnAt(position.col);
|
|
2059
|
+
const tip = column?.columnDef.meta?.lattice?.tooltip;
|
|
2060
|
+
const text = row && tip ? tip(this.valueFor(row, column), row) : undefined;
|
|
2061
|
+
if (!text) {
|
|
2062
|
+
// A tracked write renders all cells again: write only a change.
|
|
2063
|
+
if (this.tooltip) this.tooltip = null;
|
|
2064
|
+
return;
|
|
2065
|
+
}
|
|
2066
|
+
const old = this.tooltip;
|
|
2067
|
+
if (old && old.row === position.row && old.col === position.col && old.text === text) return;
|
|
2068
|
+
const box = this.cellElement(position)?.getBoundingClientRect();
|
|
2069
|
+
const style = htmlSafe(`position: fixed; top: ${px$2(box?.bottom ?? 0)}; left: ${px$2(box?.left ?? 0)}; z-index: 10`);
|
|
2070
|
+
this.tooltip = {
|
|
2071
|
+
row: position.row,
|
|
2072
|
+
col: position.col,
|
|
2073
|
+
text,
|
|
2074
|
+
style
|
|
2075
|
+
};
|
|
2076
|
+
}
|
|
2077
|
+
hideTooltip(position) {
|
|
2078
|
+
const tip = this.tooltip;
|
|
2079
|
+
if (tip && tip.row === position.row && tip.col === position.col) this.tooltip = null;
|
|
2080
|
+
}
|
|
2081
|
+
// Touch (ADR 0018) ----------------------------------------------------------------------------
|
|
2082
|
+
/** A touch press that stays this long, in ms, opens the context menu. */
|
|
2083
|
+
static LONG_PRESS = 500;
|
|
2084
|
+
/** A long press on a body cell opens the context menu, as a right click does. */
|
|
2085
|
+
onPointerDown = event => {
|
|
2086
|
+
if (event.pointerType !== 'touch' || !this._hasMenu) return;
|
|
2087
|
+
const position = this.positionOf(event.target);
|
|
2088
|
+
if (!position || position.row <= this.headerRowCount) return;
|
|
2089
|
+
const doc = this._element?.ownerDocument ?? document;
|
|
2090
|
+
const {
|
|
2091
|
+
clientX: x,
|
|
2092
|
+
clientY: y,
|
|
2093
|
+
pointerId
|
|
2094
|
+
} = event;
|
|
2095
|
+
this._stopPress?.();
|
|
2096
|
+
const stop = () => {
|
|
2097
|
+
this._stopPress = null;
|
|
2098
|
+
clearTimeout(timer);
|
|
2099
|
+
doc.removeEventListener('pointermove', move, true);
|
|
2100
|
+
doc.removeEventListener('pointerup', stop, true);
|
|
2101
|
+
doc.removeEventListener('pointercancel', stop, true);
|
|
2102
|
+
};
|
|
2103
|
+
// A press that moves is a scroll: it does not open the menu.
|
|
2104
|
+
const move = e => {
|
|
2105
|
+
if (e.pointerId === pointerId && Math.hypot(e.clientX - x, e.clientY - y) > 10) stop();
|
|
2106
|
+
};
|
|
2107
|
+
const timer = setTimeout(() => {
|
|
2108
|
+
stop();
|
|
2109
|
+
this.cellElement(position)?.focus();
|
|
2110
|
+
// The browser can send its own `contextmenu` after a long press: it is ignored.
|
|
2111
|
+
if (this.openContextMenu(position, false, x, y)) this._keyMenu = true;
|
|
2112
|
+
}, LatticeGrid.LONG_PRESS);
|
|
2113
|
+
this._stopPress = stop;
|
|
2114
|
+
doc.addEventListener('pointermove', move, true);
|
|
2115
|
+
doc.addEventListener('pointerup', stop, true);
|
|
2116
|
+
doc.addEventListener('pointercancel', stop, true);
|
|
2117
|
+
};
|
|
2118
|
+
/** Ends the long press that runs: a `contextmenu` event (Android) opens the menu in its place. */
|
|
2119
|
+
_stopPress = null;
|
|
2120
|
+
// Clipboard ---------------------------------------------------------------------------------
|
|
2121
|
+
onBodyCell(target) {
|
|
2122
|
+
const position = this.positionOf(target);
|
|
2123
|
+
return position !== null && position.row > this.headerRowCount;
|
|
2124
|
+
}
|
|
2125
|
+
/** Puts the ranges on the clipboard as TSV and HTML. False: not a copy from a body cell. */
|
|
2126
|
+
writeClipboard(event) {
|
|
2127
|
+
const data = event.clipboardData;
|
|
2128
|
+
if (!data || !this.onBodyCell(event.target)) return false;
|
|
2129
|
+
// shortcut: many ranges copy one after the other; a spreadsheet refuses a copy of many ranges.
|
|
2130
|
+
const blocks = this.selection.map(range => this.cellsOf(range).map(row => row.map(cell => this.textFor(cell.row, cell.column))));
|
|
2131
|
+
data.setData('text/plain', blocks.map(toTsv).join('\n'));
|
|
2132
|
+
data.setData('text/html', blocks.map(toHtml).join(''));
|
|
2133
|
+
event.preventDefault();
|
|
2134
|
+
return true;
|
|
2135
|
+
}
|
|
2136
|
+
onCopy = event => {
|
|
2137
|
+
this.writeClipboard(event);
|
|
2138
|
+
};
|
|
2139
|
+
/** A copy, then a clear of the cells through `@editing` (one undo step). */
|
|
2140
|
+
onCut = event => {
|
|
2141
|
+
const editing = this.args.editing;
|
|
2142
|
+
if (!editing || !this.writeClipboard(event)) return;
|
|
2143
|
+
const cells = this.selection.flatMap(range => this.cellsOf(range).flat());
|
|
2144
|
+
void waitForPromise(editing.clear(cells));
|
|
2145
|
+
};
|
|
2146
|
+
/** Pastes TSV at the start corner of the last range, through `@editing` (one undo step). */
|
|
2147
|
+
onPaste = event => {
|
|
2148
|
+
const text = event.clipboardData?.getData('text/plain');
|
|
2149
|
+
if (!this.args.editing || !text || !this.onBodyCell(event.target)) return;
|
|
2150
|
+
event.preventDefault();
|
|
2151
|
+
void waitForPromise(this.pasteText(text));
|
|
2152
|
+
};
|
|
2153
|
+
// Fill handle -------------------------------------------------------------------------------
|
|
2154
|
+
/** A drag of the fill handle: down or to the inline end, whichever is farther. */
|
|
2155
|
+
onFillStart = event => {
|
|
2156
|
+
const editing = this.args.editing;
|
|
2157
|
+
const source = this.selection[this.selection.length - 1];
|
|
2158
|
+
if (event.button !== 0 || !editing || !source) return;
|
|
2159
|
+
event.preventDefault();
|
|
2160
|
+
event.stopPropagation();
|
|
2161
|
+
const doc = this._element?.ownerDocument ?? document;
|
|
2162
|
+
let down = 0;
|
|
2163
|
+
let right = 0;
|
|
2164
|
+
const track = e => {
|
|
2165
|
+
const position = this.positionOf(doc.elementFromPoint(e.clientX, e.clientY));
|
|
2166
|
+
if (!position) return;
|
|
2167
|
+
const rows = position.row - this.headerRowCount - 1 - source.maxRowIndex;
|
|
2168
|
+
const cols = position.col - 1 - source.maxColumnIndex;
|
|
2169
|
+
down = rows >= cols ? Math.max(rows, 0) : 0;
|
|
2170
|
+
right = rows >= cols ? 0 : Math.max(cols, 0);
|
|
2171
|
+
};
|
|
2172
|
+
const move = e => {
|
|
2173
|
+
if (e.pointerId === event.pointerId) track(e);
|
|
2174
|
+
};
|
|
2175
|
+
const end = e => {
|
|
2176
|
+
if (e.pointerId !== event.pointerId) return;
|
|
2177
|
+
doc.removeEventListener('pointermove', move);
|
|
2178
|
+
doc.removeEventListener('pointerup', end);
|
|
2179
|
+
doc.removeEventListener('pointercancel', end);
|
|
2180
|
+
if (e.type === 'pointercancel') return;
|
|
2181
|
+
track(e);
|
|
2182
|
+
if (down > 0 || right > 0) void waitForPromise(this.fill(editing, source, down, right));
|
|
2183
|
+
};
|
|
2184
|
+
doc.addEventListener('pointermove', move);
|
|
2185
|
+
doc.addEventListener('pointerup', end);
|
|
2186
|
+
doc.addEventListener('pointercancel', end);
|
|
2187
|
+
};
|
|
2188
|
+
async fill(editing, range, down, right) {
|
|
2189
|
+
const {
|
|
2190
|
+
minRowIndex,
|
|
2191
|
+
maxRowIndex,
|
|
2192
|
+
minColumnIndex,
|
|
2193
|
+
maxColumnIndex
|
|
2194
|
+
} = range;
|
|
2195
|
+
const span = (from, to) => Array.from({
|
|
2196
|
+
length: to - from + 1
|
|
2197
|
+
}, (_, i) => from + i);
|
|
2198
|
+
const at = (r, c) => this.cellRefAt(r, c);
|
|
2199
|
+
const real = cells => cells.filter(c => c !== undefined);
|
|
2200
|
+
const lines = down > 0 ? span(minColumnIndex, maxColumnIndex).map(c => ({
|
|
2201
|
+
source: real(span(minRowIndex, maxRowIndex).map(r => at(r, c))),
|
|
2202
|
+
target: real(span(1, down).map(k => at(maxRowIndex + k, c)))
|
|
2203
|
+
})) : span(minRowIndex, maxRowIndex).map(r => ({
|
|
2204
|
+
source: real(span(minColumnIndex, maxColumnIndex).map(c => at(r, c))),
|
|
2205
|
+
target: real(span(1, right).map(k => at(r, maxColumnIndex + k)))
|
|
2206
|
+
}));
|
|
2207
|
+
await editing.fill(lines);
|
|
2208
|
+
// The range grows over the filled cells.
|
|
2209
|
+
const first = at(minRowIndex, minColumnIndex);
|
|
2210
|
+
const last = at(Math.min(maxRowIndex + down, this.rowCount - 1), Math.min(maxColumnIndex + right, this.colCount - 1));
|
|
2211
|
+
if (first && last) {
|
|
2212
|
+
this.args.table.selectCellRange?.({
|
|
2213
|
+
anchorRowId: first.row.id,
|
|
2214
|
+
anchorColumnId: first.column.id,
|
|
2215
|
+
focusRowId: last.row.id,
|
|
2216
|
+
focusColumnId: last.column.id
|
|
2217
|
+
});
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2220
|
+
/**
|
|
2221
|
+
* Ctrl+D copies the top row of the range into the rows under it, and Ctrl+R copies the first
|
|
2222
|
+
* column into the columns at its inline end, as spreadsheets do. In one row (or one column),
|
|
2223
|
+
* the source is the row above (or the column at the inline start). It is one undo step, through
|
|
2224
|
+
* the same `fill` as the fill handle. A row number cell is never a source or a target.
|
|
2225
|
+
*/
|
|
2226
|
+
async fillKey(editing, range, way) {
|
|
2227
|
+
const {
|
|
2228
|
+
minRowIndex,
|
|
2229
|
+
maxRowIndex,
|
|
2230
|
+
minColumnIndex,
|
|
2231
|
+
maxColumnIndex
|
|
2232
|
+
} = range;
|
|
2233
|
+
const span = (from, to) => Array.from({
|
|
2234
|
+
length: Math.max(0, to - from + 1)
|
|
2235
|
+
}, (_, i) => from + i);
|
|
2236
|
+
const at = (r, c) => {
|
|
2237
|
+
const cell = this.cellRefAt(r, c);
|
|
2238
|
+
return cell?.column.columnDef.meta?.lattice?.rowNumber === true ? undefined : cell;
|
|
2239
|
+
};
|
|
2240
|
+
const real = cells => cells.filter(c => c !== undefined);
|
|
2241
|
+
const lines = way === 'down' ? span(minColumnIndex, maxColumnIndex).map(c => {
|
|
2242
|
+
const from = minRowIndex === maxRowIndex ? minRowIndex - 1 : minRowIndex;
|
|
2243
|
+
return {
|
|
2244
|
+
source: real([at(from, c)]),
|
|
2245
|
+
target: real(span(from + 1, maxRowIndex).map(r => at(r, c)))
|
|
2246
|
+
};
|
|
2247
|
+
}) : span(minRowIndex, maxRowIndex).map(r => {
|
|
2248
|
+
const from = minColumnIndex === maxColumnIndex ? minColumnIndex - 1 : minColumnIndex;
|
|
2249
|
+
return {
|
|
2250
|
+
source: real([at(r, from)]),
|
|
2251
|
+
target: real(span(from + 1, maxColumnIndex).map(c => at(r, c)))
|
|
2252
|
+
};
|
|
2253
|
+
});
|
|
2254
|
+
const filled = lines.filter(line => line.source.length > 0 && line.target.length > 0);
|
|
2255
|
+
if (filled.length > 0) await editing.fill(filled);
|
|
2256
|
+
}
|
|
2257
|
+
// Cell edit (`@editing`) --------------------------------------------------------------------
|
|
2258
|
+
editorId = `${guidFor(this)}-editor`;
|
|
2259
|
+
/** The cell in edit, as `aria-rowindex` and `aria-colindex`. It can differ from the active cell. */
|
|
2260
|
+
static {
|
|
2261
|
+
g(this.prototype, "_editPosition", [tracked], function () {
|
|
2262
|
+
return null;
|
|
2263
|
+
});
|
|
2264
|
+
}
|
|
2265
|
+
#_editPosition = (i(this, "_editPosition"), void 0);
|
|
2266
|
+
get editPosition() {
|
|
2267
|
+
const editing = this.args.editing;
|
|
2268
|
+
return editing?.active || editing?.activeRow ? this._editPosition : null;
|
|
2269
|
+
}
|
|
2270
|
+
/** The edit mode of the edited column: `popup` puts the editor under the cell. */
|
|
2271
|
+
get editMode() {
|
|
2272
|
+
return this.args.editing?.active?.column.columnDef.meta?.lattice?.editMode ?? 'cell';
|
|
2273
|
+
}
|
|
2274
|
+
/** The fields of a full-row edit: the rendered columns that `@editing` can edit. */
|
|
2275
|
+
get rowEditFields() {
|
|
2276
|
+
const editing = this.args.editing;
|
|
2277
|
+
const row = editing?.activeRow;
|
|
2278
|
+
if (!editing || !row) return [];
|
|
2279
|
+
return this.layout.slots.filter(slot => slot.rendered && editing.canEdit({
|
|
2280
|
+
row,
|
|
2281
|
+
column: slot.column
|
|
2282
|
+
})).map(slot => ({
|
|
2283
|
+
column: slot.column,
|
|
2284
|
+
id: `${this.editorId}-${slot.column.id}`,
|
|
2285
|
+
label: this.headerLabelFor(slot.column)
|
|
2286
|
+
}));
|
|
2287
|
+
}
|
|
2288
|
+
/** The 1-based number of the edited row, for the name of the row editor. */
|
|
2289
|
+
get editRowNumber() {
|
|
2290
|
+
return this._editPosition ? this._editPosition.row - this.headerRowCount : 0;
|
|
2291
|
+
}
|
|
2292
|
+
get editInvalid() {
|
|
2293
|
+
return (this.args.editing?.errors.length ?? 0) > 0;
|
|
2294
|
+
}
|
|
2295
|
+
/** Enter or F2 opens the editor; a typed key opens it with the key; Ctrl+Z and Ctrl+Y. */
|
|
2296
|
+
editKey(event, position) {
|
|
2297
|
+
const editing = this.args.editing;
|
|
2298
|
+
if (!editing) return false;
|
|
2299
|
+
const ctrl = event.ctrlKey || event.metaKey;
|
|
2300
|
+
const key = event.key.toLowerCase();
|
|
2301
|
+
if (ctrl && (key === 'z' || key === 'y')) {
|
|
2302
|
+
event.preventDefault();
|
|
2303
|
+
void waitForPromise(key === 'y' || event.shiftKey ? editing.redo() : editing.undo());
|
|
2304
|
+
return true;
|
|
2305
|
+
}
|
|
2306
|
+
if (ctrl && !event.shiftKey && !event.altKey && (key === 'd' || key === 'r')) {
|
|
2307
|
+
const range = this.selection[this.selection.length - 1];
|
|
2308
|
+
// shortcut: no keyboard fill with `@rowModel`, as no fill handle; the fill reads loaded rows.
|
|
2309
|
+
if (!this.engineRanges || !range) return false;
|
|
2310
|
+
// The browser binds these keys to a bookmark and a reload.
|
|
2311
|
+
event.preventDefault();
|
|
2312
|
+
void waitForPromise(this.fillKey(editing, range, key === 'd' ? 'down' : 'right'));
|
|
2313
|
+
return true;
|
|
2314
|
+
}
|
|
2315
|
+
const index = position.row - this.headerRowCount - 1;
|
|
2316
|
+
// Enter on a group row toggles it; a group row has no editor.
|
|
2317
|
+
if (this.isToggleRow(index)) return false;
|
|
2318
|
+
const cell = this.cellRefAt(index, position.col - 1);
|
|
2319
|
+
if (!cell || !editing.canEdit(cell)) return false;
|
|
2320
|
+
// Space stays the row selection key.
|
|
2321
|
+
const typed = event.key.length === 1 && event.key !== ' ' && !ctrl && !event.altKey;
|
|
2322
|
+
if (event.key !== 'Enter' && event.key !== 'F2' && !typed) return false;
|
|
2323
|
+
event.preventDefault();
|
|
2324
|
+
this.startEdit(position, cell, typed ? event.key : undefined);
|
|
2325
|
+
return true;
|
|
2326
|
+
}
|
|
2327
|
+
/** Opens the editor on the cell (or the row editor), then moves the focus into it. */
|
|
2328
|
+
startEdit(position, cell, text) {
|
|
2329
|
+
const editing = this.args.editing;
|
|
2330
|
+
if (!editing) return;
|
|
2331
|
+
this._editPosition = position;
|
|
2332
|
+
// A pointer edit can start on a cell that is not the active cell yet.
|
|
2333
|
+
this.activate(position, false);
|
|
2334
|
+
let focusId = this.editorId;
|
|
2335
|
+
if (editing.mode === 'row' && editing.beginRow) {
|
|
2336
|
+
// Full-row edit: one editor for each column; the focus goes to the field of the cell.
|
|
2337
|
+
editing.beginRow(cell.row, this.columns.all);
|
|
2338
|
+
focusId = `${this.editorId}-${cell.column.id}`;
|
|
2339
|
+
} else {
|
|
2340
|
+
editing.begin(cell, text);
|
|
2341
|
+
}
|
|
2342
|
+
void waitForPromise(renderSettled().then(() => this.focusEditor(focusId)));
|
|
2343
|
+
}
|
|
2344
|
+
/**
|
|
2345
|
+
* Focuses the element with the editor ID. When that element cannot take the focus (a
|
|
2346
|
+
* fieldset, the root of a calendar), the focus goes to its checked or current item, else to
|
|
2347
|
+
* its first control.
|
|
2348
|
+
*/
|
|
2349
|
+
focusEditor(id) {
|
|
2350
|
+
const doc = this._element?.ownerDocument;
|
|
2351
|
+
const element = doc?.getElementById(id);
|
|
2352
|
+
if (!element || element.contains(doc?.activeElement ?? null)) return;
|
|
2353
|
+
element.focus();
|
|
2354
|
+
if (element.contains(doc?.activeElement ?? null)) return;
|
|
2355
|
+
const inner = element.querySelector(':checked, [tabindex="0"]') ?? element.querySelector(FOCUSABLE);
|
|
2356
|
+
inner?.focus();
|
|
2357
|
+
}
|
|
2358
|
+
/** The commit of a press or a focus change: only one at a time, and only while in edit. */
|
|
2359
|
+
_pressCommit = null;
|
|
2360
|
+
commitOnce(editing) {
|
|
2361
|
+
// The edit machine is strict: a second commit while the first validates would throw.
|
|
2362
|
+
if (editing.state !== 'editing') return Promise.resolve(false);
|
|
2363
|
+
return editing.commit();
|
|
2364
|
+
}
|
|
2365
|
+
/** With `@stopEditingWhenCellsLoseFocus`: the focus goes outside the overlay, so the edit saves. */
|
|
2366
|
+
onEditorFocusOut = event => {
|
|
2367
|
+
const editing = this.args.editing;
|
|
2368
|
+
if (!this.args.stopEditingWhenCellsLoseFocus || !editing?.active) return;
|
|
2369
|
+
const to = event.relatedTarget;
|
|
2370
|
+
const overlay = event.currentTarget;
|
|
2371
|
+
if (!(to instanceof Node) || overlay.contains(to)) return;
|
|
2372
|
+
void waitForPromise(this.commitOnce(editing));
|
|
2373
|
+
};
|
|
2374
|
+
/** With `@stopEditingWhenCellsLoseFocus`: a press outside the grid saves the edit. */
|
|
2375
|
+
saveOnOutsidePress = modifier((root, [enabled]) => {
|
|
2376
|
+
if (!enabled) return;
|
|
2377
|
+
const doc = root.ownerDocument;
|
|
2378
|
+
const press = event => {
|
|
2379
|
+
const editing = this.args.editing;
|
|
2380
|
+
if (!editing?.active || event.target instanceof Node && root.contains(event.target)) return;
|
|
2381
|
+
void waitForPromise(this.commitOnce(editing));
|
|
2382
|
+
};
|
|
2383
|
+
doc.addEventListener('pointerdown', press, true);
|
|
2384
|
+
return () => doc.removeEventListener('pointerdown', press, true);
|
|
2385
|
+
});
|
|
2386
|
+
/** Escape cancels; Enter commits and moves down; Tab commits and moves to the inline end. */
|
|
2387
|
+
onEditorKeyDown = event => {
|
|
2388
|
+
const editing = this.args.editing;
|
|
2389
|
+
// A key that the control used (a list in the editor closes on Escape) is not the grid key.
|
|
2390
|
+
if (!editing?.active && !editing?.activeRow || event.defaultPrevented) return;
|
|
2391
|
+
const edited = this.editPosition ?? this.activeCell;
|
|
2392
|
+
if (editing.activeRow) {
|
|
2393
|
+
// Full-row edit: Tab moves between the fields; Enter saves the row and moves down.
|
|
2394
|
+
if (event.key !== 'Enter') return;
|
|
2395
|
+
event.preventDefault();
|
|
2396
|
+
void waitForPromise(this.commitRowAndMove(editing, edited, event.shiftKey ? -1 : 1));
|
|
2397
|
+
return;
|
|
2398
|
+
}
|
|
2399
|
+
const back = event.shiftKey ? -1 : 1;
|
|
2400
|
+
const step = event.key === 'Enter' ? [back, 0] : event.key === 'Tab' ? [0, back] : null;
|
|
2401
|
+
if (!step) return;
|
|
2402
|
+
const move = () => this.commitAndMove(editing, edited, step[0] ?? 0, step[1] ?? 0);
|
|
2403
|
+
if (event.key === 'Enter' && event.target instanceof HTMLButtonElement) {
|
|
2404
|
+
// Enter clicks the button (a calendar day) after this event: save after that click.
|
|
2405
|
+
void waitForPromise(new Promise(resolve => setTimeout(resolve)).then(move));
|
|
2406
|
+
return;
|
|
2407
|
+
}
|
|
2408
|
+
event.preventDefault();
|
|
2409
|
+
void waitForPromise(move());
|
|
2410
|
+
};
|
|
2411
|
+
/**
|
|
2412
|
+
* Escape cancels the edit. It runs in the capture phase: a control can stop the key in the
|
|
2413
|
+
* bubble phase (a closed combobox clears its text). A layer in the editor that Escape closes
|
|
2414
|
+
* (a list, a popover) cancels the key first, and then the edit stays open.
|
|
2415
|
+
*/
|
|
2416
|
+
onEditorEscape = event => {
|
|
2417
|
+
const editing = this.args.editing;
|
|
2418
|
+
if (event.key !== 'Escape' || event.defaultPrevented) return;
|
|
2419
|
+
if (!editing?.active && !editing?.activeRow) return;
|
|
2420
|
+
event.preventDefault();
|
|
2421
|
+
const edited = this.editPosition ?? this.activeCell;
|
|
2422
|
+
editing.cancel();
|
|
2423
|
+
this.activate(edited);
|
|
2424
|
+
};
|
|
2425
|
+
async commitRowAndMove(editing, {
|
|
2426
|
+
row,
|
|
2427
|
+
col
|
|
2428
|
+
}, rows) {
|
|
2429
|
+
if (!(await editing.commitRow?.())) return;
|
|
2430
|
+
const next = {
|
|
2431
|
+
row: clamp(row + rows, this.headerRowCount + 1, this.headerRowCount + this.rowCount),
|
|
2432
|
+
col
|
|
2433
|
+
};
|
|
2434
|
+
this.activate(next);
|
|
2435
|
+
this.focusSelection(next);
|
|
2436
|
+
}
|
|
2437
|
+
async commitAndMove(editing, {
|
|
2438
|
+
row,
|
|
2439
|
+
col
|
|
2440
|
+
}, rows, cols) {
|
|
2441
|
+
if (!(await editing.commit())) return;
|
|
2442
|
+
const next = {
|
|
2443
|
+
row: clamp(row + rows, this.headerRowCount + 1, this.headerRowCount + this.rowCount),
|
|
2444
|
+
col: clamp(col + cols, 1, this.colCount)
|
|
2445
|
+
};
|
|
2446
|
+
this.activate(next);
|
|
2447
|
+
this.focusSelection(next);
|
|
2448
|
+
}
|
|
2449
|
+
/**
|
|
2450
|
+
* Puts the editor on the edited cell. It measures where the editor lands and moves it by the
|
|
2451
|
+
* difference, so it works in any containing block and with a scaled page. It does this again
|
|
2452
|
+
* on each scroll, so the editor follows its cell. The edited row is held (ADR 0002, amendment 1):
|
|
2453
|
+
* when the cell leaves the view, the editor is clipped, not hidden, so its control keeps focus.
|
|
2454
|
+
*/
|
|
2455
|
+
placeEditor = modifier((editor, [position]) => {
|
|
2456
|
+
const scroller = this._scroller;
|
|
2457
|
+
const place = () => {
|
|
2458
|
+
const cell = position && this.cellElement(position);
|
|
2459
|
+
const view = scroller?.getBoundingClientRect();
|
|
2460
|
+
if (!cell || !view) return;
|
|
2461
|
+
// A popup editor can be larger than the cell (a calendar): the cell size is its minimum.
|
|
2462
|
+
const popup = editor.dataset['ltEditMode'] === 'popup';
|
|
2463
|
+
Object.assign(editor.style, {
|
|
2464
|
+
position: 'absolute',
|
|
2465
|
+
top: '0px',
|
|
2466
|
+
left: '0px',
|
|
2467
|
+
width: popup ? 'max-content' : px$2(cell.offsetWidth),
|
|
2468
|
+
minWidth: popup ? px$2(cell.offsetWidth) : '',
|
|
2469
|
+
minHeight: px$2(cell.offsetHeight)
|
|
2470
|
+
});
|
|
2471
|
+
editor.style.setProperty('--lt-editor-block-size', px$2(cell.offsetHeight));
|
|
2472
|
+
const box = cell.getBoundingClientRect();
|
|
2473
|
+
const at = editor.getBoundingClientRect();
|
|
2474
|
+
const scale = editor.offsetWidth > 0 ? at.width / editor.offsetWidth : 1;
|
|
2475
|
+
// The sticky header and the total row cover the ends of the view.
|
|
2476
|
+
const ratio = scroller && scroller.offsetHeight > 0 ? view.height / scroller.offsetHeight : 1;
|
|
2477
|
+
const top = view.top + this.headerHeight * ratio;
|
|
2478
|
+
const bottom = view.bottom - this.footerHeight * ratio;
|
|
2479
|
+
// A popup editor opens under the cell, so the cell stays in view. When it does not fit
|
|
2480
|
+
// under the cell, it opens over the cell; when it fits neither, it moves up into the view.
|
|
2481
|
+
const under = box.bottom + at.height <= bottom;
|
|
2482
|
+
const over = box.top - at.height >= top;
|
|
2483
|
+
const y = !popup ? box.top : under ? box.bottom : over ? box.top - at.height : Math.max(top, bottom - at.height);
|
|
2484
|
+
editor.style.top = px$2((y - at.top) / (scale || 1));
|
|
2485
|
+
editor.style.left = px$2((box.left - at.left) / (scale || 1));
|
|
2486
|
+
const out = box.bottom <= top || box.top >= bottom || box.right <= view.left || box.left >= view.right;
|
|
2487
|
+
editor.toggleAttribute('data-lt-offscreen', out);
|
|
2488
|
+
editor.style.clipPath = out ? 'inset(50%)' : '';
|
|
2489
|
+
};
|
|
2490
|
+
place();
|
|
2491
|
+
scroller?.addEventListener('scroll', place, {
|
|
2492
|
+
passive: true
|
|
2493
|
+
});
|
|
2494
|
+
return () => scroller?.removeEventListener('scroll', place);
|
|
2495
|
+
});
|
|
2496
|
+
/**
|
|
2497
|
+
* Puts the row editor over the edited row, and each field over its cell, by measurement as in
|
|
2498
|
+
* `placeEditor`. It does this again on each scroll.
|
|
2499
|
+
*/
|
|
2500
|
+
placeRowEditor = modifier((box, [position]) => {
|
|
2501
|
+
const scroller = this._scroller;
|
|
2502
|
+
const place = () => {
|
|
2503
|
+
// Only a row of this grid: a detail row can hold a nested grid with the same indexes.
|
|
2504
|
+
const row = position && this._element?.querySelector(`:scope > .lt-scroller > .lt-sizer > .lt-body > .lt-row[aria-rowindex="${position.row}"]`);
|
|
2505
|
+
const view = scroller?.getBoundingClientRect();
|
|
2506
|
+
if (!row || !view || !scroller) return;
|
|
2507
|
+
Object.assign(box.style, {
|
|
2508
|
+
position: 'absolute',
|
|
2509
|
+
top: '0px',
|
|
2510
|
+
left: '0px',
|
|
2511
|
+
width: px$2(scroller.clientWidth),
|
|
2512
|
+
minHeight: px$2(row.offsetHeight)
|
|
2513
|
+
});
|
|
2514
|
+
const at = box.getBoundingClientRect();
|
|
2515
|
+
const scale = box.offsetWidth > 0 ? at.width / box.offsetWidth : 1;
|
|
2516
|
+
const rowBox = row.getBoundingClientRect();
|
|
2517
|
+
box.style.top = px$2((rowBox.top - at.top) / (scale || 1));
|
|
2518
|
+
box.style.left = px$2((view.left - at.left) / (scale || 1));
|
|
2519
|
+
for (const field of box.querySelectorAll('[data-column-id]')) {
|
|
2520
|
+
const id = field.dataset['columnId'] ?? '';
|
|
2521
|
+
const cell = row.querySelector(`:scope > [data-column-id="${CSS.escape(id)}"]`);
|
|
2522
|
+
if (!cell) continue;
|
|
2523
|
+
const cellBox = cell.getBoundingClientRect();
|
|
2524
|
+
Object.assign(field.style, {
|
|
2525
|
+
position: 'absolute',
|
|
2526
|
+
top: '0px',
|
|
2527
|
+
left: px$2((cellBox.left - view.left) / (scale || 1)),
|
|
2528
|
+
width: px$2(cell.offsetWidth),
|
|
2529
|
+
height: px$2(cell.offsetHeight)
|
|
2530
|
+
});
|
|
2531
|
+
}
|
|
2532
|
+
};
|
|
2533
|
+
place();
|
|
2534
|
+
scroller?.addEventListener('scroll', place, {
|
|
2535
|
+
passive: true
|
|
2536
|
+
});
|
|
2537
|
+
return () => scroller?.removeEventListener('scroll', place);
|
|
2538
|
+
});
|
|
2539
|
+
// Saved state (ADR 0011) -------------------------------------------------------------------
|
|
2540
|
+
/** The scroll offset (virtual px, ADR 0003) and the active cell that the user chose. */
|
|
2541
|
+
readState() {
|
|
2542
|
+
const active = this._active ? this.activeCell : null;
|
|
2543
|
+
const row = active ? this.rowAt(active.row - this.headerRowCount - 1) : undefined;
|
|
2544
|
+
const column = active ? this.columnAt(active.col) : undefined;
|
|
2545
|
+
return {
|
|
2546
|
+
scroll: {
|
|
2547
|
+
top: this.rowState.virtualizer.scrollOffset ?? 0,
|
|
2548
|
+
left: this.colState.virtualizer.scrollOffset ?? 0
|
|
2549
|
+
},
|
|
2550
|
+
activeCell: row && column ? {
|
|
2551
|
+
rowId: this.rowIdOf(row),
|
|
2552
|
+
columnId: column.id
|
|
2553
|
+
} : null
|
|
2554
|
+
};
|
|
2555
|
+
}
|
|
2556
|
+
applyState(state) {
|
|
2557
|
+
if (state.scroll) {
|
|
2558
|
+
this.rowState.virtualizer.scrollToOffset(state.scroll.top);
|
|
2559
|
+
this.colState.virtualizer.scrollToOffset(state.scroll.left);
|
|
2560
|
+
}
|
|
2561
|
+
if (state.activeCell === undefined) return;
|
|
2562
|
+
const ref = state.activeCell;
|
|
2563
|
+
const col = ref ? this.columns.all.findIndex(c => c.id === ref.columnId) : -1;
|
|
2564
|
+
const index = ref && col >= 0 ? this.indexOfRow(ref.rowId) : -1;
|
|
2565
|
+
this._active = index < 0 ? null : {
|
|
2566
|
+
row: this.headerRowCount + index + 1,
|
|
2567
|
+
col: col + 1
|
|
2568
|
+
};
|
|
2569
|
+
}
|
|
2570
|
+
// Sorting -------------------------------------------------------------------------------------
|
|
2571
|
+
toggleSort(position, event) {
|
|
2572
|
+
const column = this.columnAt(position.col);
|
|
2573
|
+
if (column) this.sortBy(column, event);
|
|
2574
|
+
}
|
|
2575
|
+
sortBy(column, event) {
|
|
2576
|
+
if (!column.getCanSort?.()) return;
|
|
2577
|
+
column.getToggleSortingHandler?.()?.(event);
|
|
2578
|
+
this.announceSort(column);
|
|
2579
|
+
}
|
|
2580
|
+
/** True for an event from a header slot or a control in the label: no sort and no drag. */
|
|
2581
|
+
inSlot = event => event.target instanceof Element && (event.target.closest('.lt-header-slot') !== null || event.target.closest(WIDGET_CONTROL) !== null);
|
|
2582
|
+
onHeaderClick = (column, event) => {
|
|
2583
|
+
if (this._suppressClick) {
|
|
2584
|
+
this._suppressClick = false;
|
|
2585
|
+
return;
|
|
2586
|
+
}
|
|
2587
|
+
if (!this.inSlot(event)) this.sortBy(column, event);
|
|
2588
|
+
};
|
|
2589
|
+
// Resize --------------------------------------------------------------------------------------
|
|
2590
|
+
/** A separator needs the column resizing feature, and `enableResizing` not false. */
|
|
2591
|
+
canResize = column => this.args.table.setColumnSizing !== undefined && column.getSize !== undefined && column.getCanResize?.() === true;
|
|
2592
|
+
resize(column, size) {
|
|
2593
|
+
// A resize takes a flex column out of flex, so the next flex pass keeps its size.
|
|
2594
|
+
this._fixedFlex.add(column.id);
|
|
2595
|
+
const next = Math.round(clamp(size, MIN_COLUMN_SIZE, MAX_COLUMN_SIZE));
|
|
2596
|
+
this.args.table.setColumnSizing?.(old => ({
|
|
2597
|
+
...old,
|
|
2598
|
+
[column.id]: next
|
|
2599
|
+
}));
|
|
2600
|
+
}
|
|
2601
|
+
onResizeKey = (column, event) => {
|
|
2602
|
+
const forward = this.rtl ? -1 : 1;
|
|
2603
|
+
const step = event.key === 'ArrowRight' ? forward : event.key === 'ArrowLeft' ? -forward : 0;
|
|
2604
|
+
if (step === 0) return;
|
|
2605
|
+
event.preventDefault();
|
|
2606
|
+
event.stopPropagation();
|
|
2607
|
+
this.resize(column, sizeOf(column) + step * RESIZE_STEP);
|
|
2608
|
+
};
|
|
2609
|
+
onResizeStart = (column, event) => {
|
|
2610
|
+
if (event.button !== 0) return;
|
|
2611
|
+
event.preventDefault();
|
|
2612
|
+
event.stopPropagation();
|
|
2613
|
+
const handle = event.currentTarget;
|
|
2614
|
+
if (!(handle instanceof HTMLElement)) return;
|
|
2615
|
+
const cell = handle.parentElement ?? handle;
|
|
2616
|
+
// Pointer px to CSS px: a transform on the page (a zoom, a scale) changes the ratio.
|
|
2617
|
+
const ratio = cell.offsetWidth > 0 ? cell.getBoundingClientRect().width / cell.offsetWidth : 1;
|
|
2618
|
+
const startX = event.clientX;
|
|
2619
|
+
const startSize = sizeOf(column);
|
|
2620
|
+
const direction = this.rtl ? -1 : 1;
|
|
2621
|
+
const doc = handle.ownerDocument;
|
|
2622
|
+
const move = e => {
|
|
2623
|
+
if (e.pointerId !== event.pointerId) return;
|
|
2624
|
+
this.resize(column, startSize + direction * (e.clientX - startX) / (ratio || 1));
|
|
2625
|
+
};
|
|
2626
|
+
const end = e => {
|
|
2627
|
+
if (e.pointerId !== event.pointerId) return;
|
|
2628
|
+
doc.removeEventListener('pointermove', move);
|
|
2629
|
+
doc.removeEventListener('pointerup', end);
|
|
2630
|
+
doc.removeEventListener('pointercancel', end);
|
|
2631
|
+
try {
|
|
2632
|
+
if (handle.hasPointerCapture(event.pointerId)) handle.releasePointerCapture(event.pointerId);
|
|
2633
|
+
} catch {
|
|
2634
|
+
// An event that a test makes has no pointer to capture.
|
|
2635
|
+
}
|
|
2636
|
+
};
|
|
2637
|
+
doc.addEventListener('pointermove', move);
|
|
2638
|
+
doc.addEventListener('pointerup', end);
|
|
2639
|
+
doc.addEventListener('pointercancel', end);
|
|
2640
|
+
try {
|
|
2641
|
+
handle.setPointerCapture(event.pointerId);
|
|
2642
|
+
} catch {
|
|
2643
|
+
// An event that a test makes has no pointer to capture.
|
|
2644
|
+
}
|
|
2645
|
+
};
|
|
2646
|
+
stopClick = event => event.stopPropagation();
|
|
2647
|
+
/** A double click on the separator sizes the column to its content. */
|
|
2648
|
+
onResizeDoubleClick = (column, event) => {
|
|
2649
|
+
event.stopPropagation();
|
|
2650
|
+
this.autoSizeColumns([column.id]);
|
|
2651
|
+
};
|
|
2652
|
+
// Flex widths and auto-size (contract section 11, ADR 0019) ---------------------------------
|
|
2653
|
+
/** The flex columns that a resize or an auto-size took out of flex. */
|
|
2654
|
+
_fixedFlex = new Set();
|
|
2655
|
+
/** The width and the fixed sizes of the last flex pass: the same input needs no pass. */
|
|
2656
|
+
_flexKey = '';
|
|
2657
|
+
_flexFrame = 0;
|
|
2658
|
+
isFlex = column => (column.columnDef.flex ?? 0) > 0 && !this._fixedFlex.has(column.id);
|
|
2659
|
+
/** The table as core `applyFlexWidths` and `autoSizeColumns` read it. */
|
|
2660
|
+
get sizingTable() {
|
|
2661
|
+
const table = this.args.table;
|
|
2662
|
+
const sized = c => ({
|
|
2663
|
+
id: c.id,
|
|
2664
|
+
columnDef: {
|
|
2665
|
+
flex: this.isFlex(c) ? c.columnDef.flex : 0,
|
|
2666
|
+
minSize: c.columnDef.minSize ?? MIN_COLUMN_SIZE,
|
|
2667
|
+
maxSize: c.columnDef.maxSize ?? MAX_COLUMN_SIZE
|
|
2668
|
+
},
|
|
2669
|
+
getSize: () => sizeOf(c)
|
|
2670
|
+
});
|
|
2671
|
+
return {
|
|
2672
|
+
getAllLeafColumns: () => table.getAllLeafColumns().map(sized),
|
|
2673
|
+
getVisibleLeafColumns: () => this.columns.all.map(sized),
|
|
2674
|
+
setColumnSizing: updater => table.setColumnSizing?.(updater)
|
|
2675
|
+
};
|
|
2676
|
+
}
|
|
2677
|
+
/** Runs a flex pass in the next frame: a size write in a ResizeObserver callback can loop. */
|
|
2678
|
+
scheduleFlex() {
|
|
2679
|
+
if (this._flexFrame !== 0 || !this.columns.all.some(this.isFlex)) return;
|
|
2680
|
+
void waitForPromise(new Promise(done => {
|
|
2681
|
+
this._flexFrame = requestAnimationFrame(() => {
|
|
2682
|
+
this._flexFrame = 0;
|
|
2683
|
+
this.applyFlex();
|
|
2684
|
+
done();
|
|
2685
|
+
});
|
|
2686
|
+
}));
|
|
2687
|
+
}
|
|
2688
|
+
applyFlex() {
|
|
2689
|
+
const scroller = this._scroller;
|
|
2690
|
+
const all = this.columns.all;
|
|
2691
|
+
if (!scroller || !this.args.table.setColumnSizing || !all.some(this.isFlex)) return;
|
|
2692
|
+
const width = scroller.clientWidth;
|
|
2693
|
+
const key = `${width}:${all.map(c => this.isFlex(c) ? c.id : sizeOf(c)).join()}`;
|
|
2694
|
+
if (width <= 0 || key === this._flexKey) return;
|
|
2695
|
+
this._flexKey = key;
|
|
2696
|
+
applyFlexWidths(this.sizingTable, width);
|
|
2697
|
+
}
|
|
2698
|
+
/**
|
|
2699
|
+
* The grid API of the header slots and the floating filters (`@grid`). With no IDs, it sizes
|
|
2700
|
+
* the columns that have a separator: a column that cannot resize keeps its size.
|
|
2701
|
+
*/
|
|
2702
|
+
headerApi = {
|
|
2703
|
+
autoSizeColumns: columnIds => this.autoSizeColumns(columnIds ?? this.columns.all.filter(c => this.canResize(c)).map(c => c.id))
|
|
2704
|
+
};
|
|
2705
|
+
/** Sizes columns to their widest rendered content (`GridStateHandle.autoSizeColumns`). */
|
|
2706
|
+
autoSizeColumns(columnIds) {
|
|
2707
|
+
if (!this.args.table.setColumnSizing) return;
|
|
2708
|
+
const sizes = autoSizeColumns(this.sizingTable, c => this.measureColumn(c.id), columnIds);
|
|
2709
|
+
for (const id of Object.keys(sizes)) this._fixedFlex.add(id);
|
|
2710
|
+
}
|
|
2711
|
+
/**
|
|
2712
|
+
* The width of the widest rendered content of a column, in CSS px: the header label and slot,
|
|
2713
|
+
* and the body and total cells. Undefined when no cell of the column is rendered.
|
|
2714
|
+
*/
|
|
2715
|
+
measureColumn(id) {
|
|
2716
|
+
// shortcut: only the rendered rows and columns; a column outside the column range keeps its size.
|
|
2717
|
+
const cells = this._element?.querySelectorAll(`:scope > .lt-scroller > .lt-sizer > * > .lt-row:not(.lt-floating-row) > [data-column-id="${CSS.escape(id)}"]`);
|
|
2718
|
+
if (!cells || cells.length === 0) return undefined;
|
|
2719
|
+
const range = document.createRange();
|
|
2720
|
+
const widthOf = (node, scale) => {
|
|
2721
|
+
range.selectNodeContents(node);
|
|
2722
|
+
return range.getBoundingClientRect().width / scale;
|
|
2723
|
+
};
|
|
2724
|
+
let widest = 0;
|
|
2725
|
+
for (const cell of cells) {
|
|
2726
|
+
const scale = cell.offsetWidth > 0 ? cell.getBoundingClientRect().width / cell.offsetWidth : 1;
|
|
2727
|
+
const style = getComputedStyle(cell);
|
|
2728
|
+
const frame = parseFloat(style.paddingInlineStart) + parseFloat(style.paddingInlineEnd) + parseFloat(style.borderInlineEndWidth);
|
|
2729
|
+
const parts = cell.classList.contains('lt-header-cell') ? [...cell.querySelectorAll(':scope > .lt-header-label, :scope > .lt-header-slot')] : [cell];
|
|
2730
|
+
const content = parts.reduce((n, part) => n + widthOf(part, scale || 1), 0);
|
|
2731
|
+
// One px more: a text width with a fraction must not round down to an ellipsis.
|
|
2732
|
+
widest = Math.max(widest, content + frame + 1);
|
|
2733
|
+
}
|
|
2734
|
+
return widest;
|
|
2735
|
+
}
|
|
2736
|
+
// Auto-generated columns (contract section 11) ------------------------------------------------
|
|
2737
|
+
/** True when the table has no columns and has rows: the grid makes columns from the rows. */
|
|
2738
|
+
get wantsAutoColumns() {
|
|
2739
|
+
const table = this.args.table;
|
|
2740
|
+
return !this.args.rowModel && table.getAllLeafColumns().length === 0 && table.getRowModel().rows.length > 0;
|
|
2741
|
+
}
|
|
2742
|
+
/** Sets the auto columns after the render in which the first rows show. */
|
|
2743
|
+
syncAutoColumns = modifier((_el, [wanted]) => {
|
|
2744
|
+
if (wanted) void waitForPromise(Promise.resolve().then(() => this.setAutoColumns()));
|
|
2745
|
+
});
|
|
2746
|
+
/** A table with no columns gets a column for each key of its first rows. */
|
|
2747
|
+
setAutoColumns() {
|
|
2748
|
+
const table = this.args.table;
|
|
2749
|
+
if (this.args.rowModel || table.getAllLeafColumns().length > 0) return;
|
|
2750
|
+
// `setOptions` is not in `GridTable`: its updater type is the table options of the app.
|
|
2751
|
+
const setOptions = Reflect.get(table, 'setOptions');
|
|
2752
|
+
if (!is.function(setOptions)) return;
|
|
2753
|
+
const columns = autoColumns(table.getRowModel().rows.map(row => row.original));
|
|
2754
|
+
if (columns.length === 0) return;
|
|
2755
|
+
Reflect.apply(setOptions, table, [old => ({
|
|
2756
|
+
...old,
|
|
2757
|
+
columns
|
|
2758
|
+
})]);
|
|
2759
|
+
}
|
|
2760
|
+
// Aligned grids (contract section 11) ---------------------------------------------------------
|
|
2761
|
+
_alignment = null;
|
|
2762
|
+
_leaveAlignment = null;
|
|
2763
|
+
/** The column state that aligned grids share: a change of it runs `syncAligned`. */
|
|
2764
|
+
get alignedKey() {
|
|
2765
|
+
return JSON.stringify(this.alignedColumns());
|
|
2766
|
+
}
|
|
2767
|
+
alignedColumns() {
|
|
2768
|
+
const table = this.args.table;
|
|
2769
|
+
const leaves = table.getAllLeafColumns();
|
|
2770
|
+
return {
|
|
2771
|
+
sizes: Object.fromEntries(leaves.map(c => [c.id, sizeOf(c)])),
|
|
2772
|
+
order: this.columns.all.map(c => c.id),
|
|
2773
|
+
visible: Object.fromEntries(leaves.map(c => [c.id, c.getIsVisible?.() ?? true]))
|
|
2774
|
+
};
|
|
2775
|
+
}
|
|
2776
|
+
alignColumns(state) {
|
|
2777
|
+
const table = this.args.table;
|
|
2778
|
+
const leaves = table.getAllLeafColumns();
|
|
2779
|
+
const sizes = {};
|
|
2780
|
+
const visible = {};
|
|
2781
|
+
for (const c of leaves) {
|
|
2782
|
+
const size = state.sizes[c.id];
|
|
2783
|
+
if (size !== undefined && size !== sizeOf(c)) sizes[c.id] = size;
|
|
2784
|
+
const shown = state.visible[c.id];
|
|
2785
|
+
if (shown !== undefined && shown !== (c.getIsVisible?.() ?? true)) visible[c.id] = shown;
|
|
2786
|
+
}
|
|
2787
|
+
// The order is the visible order: the column order state is an engine atom, and a read of
|
|
2788
|
+
// it in a render can dirty it. Hidden columns keep their place at the end.
|
|
2789
|
+
const ids = new Set(leaves.map(c => c.id));
|
|
2790
|
+
const own = this.columns.all.map(c => c.id);
|
|
2791
|
+
const shared = state.order.filter(id => ids.has(id));
|
|
2792
|
+
const ownShared = own.filter(id => shared.includes(id));
|
|
2793
|
+
const sameOrder = ownShared.every((id, i) => shared[i] === id);
|
|
2794
|
+
const order = [...shared, ...leaves.map(c => c.id).filter(id => !shared.includes(id))];
|
|
2795
|
+
// `syncAligned` calls this after the render, so it can write.
|
|
2796
|
+
if (Object.keys(sizes).length > 0) table.setColumnSizing?.(old => ({
|
|
2797
|
+
...old,
|
|
2798
|
+
...sizes
|
|
2799
|
+
}));
|
|
2800
|
+
if (Object.keys(visible).length > 0) {
|
|
2801
|
+
table.setColumnVisibility?.(old => ({
|
|
2802
|
+
...old,
|
|
2803
|
+
...visible
|
|
2804
|
+
}));
|
|
2805
|
+
}
|
|
2806
|
+
if (!sameOrder) table.setColumnOrder?.(order);
|
|
2807
|
+
}
|
|
2808
|
+
/** The offset that an aligned grid set: the scroll event of it is not sent back. */
|
|
2809
|
+
_alignedLeft = null;
|
|
2810
|
+
alignScroll(left) {
|
|
2811
|
+
const scroller = this._scroller;
|
|
2812
|
+
// Less than 1 px: a scaled page rounds `scrollLeft`, so an exact compare sends it back and forth.
|
|
2813
|
+
if (!scroller || Math.abs(scroller.scrollLeft - left) < 1) return;
|
|
2814
|
+
scroller.scrollLeft = left;
|
|
2815
|
+
// Keep the offset that the browser applied: a narrower grid clamps it, and that scroll event
|
|
2816
|
+
// must not go back.
|
|
2817
|
+
this._alignedLeft = scroller.scrollLeft;
|
|
2818
|
+
}
|
|
2819
|
+
/** Sends a horizontal scroll to the aligned grids, but not one that came from them. */
|
|
2820
|
+
scrolledAligned(scroller) {
|
|
2821
|
+
const left = scroller.scrollLeft;
|
|
2822
|
+
// The offset stays until the user moves this grid: a vertical scroll or a second event of
|
|
2823
|
+
// the same offset is not sent back.
|
|
2824
|
+
const echo = this._alignedLeft !== null && Math.abs(left - this._alignedLeft) < 1;
|
|
2825
|
+
if (echo) return;
|
|
2826
|
+
this._alignedLeft = null;
|
|
2827
|
+
this.args.aligned?.scrolled(this, left);
|
|
2828
|
+
}
|
|
2829
|
+
/**
|
|
2830
|
+
* Joins `@aligned` on the first run; later runs send a column change to the other grids. The
|
|
2831
|
+
* work waits until the render ends: it reads and writes the other tables, and a modifier
|
|
2832
|
+
* tracks what it reads.
|
|
2833
|
+
*/
|
|
2834
|
+
syncAligned = modifier((_el, [alignment, key]) => {
|
|
2835
|
+
void waitForPromise(Promise.resolve().then(() => {
|
|
2836
|
+
if (alignment === this._alignment) {
|
|
2837
|
+
alignment?.columnsChanged(this);
|
|
2838
|
+
return;
|
|
2839
|
+
}
|
|
2840
|
+
this._leaveAlignment?.();
|
|
2841
|
+
this._alignment = alignment ?? null;
|
|
2842
|
+
this._leaveAlignment = alignment ? alignment.join(this) : null;
|
|
2843
|
+
}));
|
|
2844
|
+
});
|
|
2845
|
+
willDestroy() {
|
|
2846
|
+
super.willDestroy();
|
|
2847
|
+
// A flex frame that is still to run finds no scroller and does nothing.
|
|
2848
|
+
this._leaveAlignment?.();
|
|
2849
|
+
}
|
|
2850
|
+
// Reorder -------------------------------------------------------------------------------------
|
|
2851
|
+
onHeaderPointerDown = (column, event) => {
|
|
2852
|
+
const table = this.args.table;
|
|
2853
|
+
this._suppressClick = false;
|
|
2854
|
+
if (event.button !== 0 || !table.setColumnOrder || this.inSlot(event)) return;
|
|
2855
|
+
const header = event.currentTarget;
|
|
2856
|
+
if (!(header instanceof HTMLElement)) return;
|
|
2857
|
+
const doc = header.ownerDocument;
|
|
2858
|
+
const startX = event.clientX;
|
|
2859
|
+
let dragging = false;
|
|
2860
|
+
const move = e => {
|
|
2861
|
+
if (e.pointerId !== event.pointerId) return;
|
|
2862
|
+
if (!dragging && Math.abs(e.clientX - startX) >= DRAG_THRESHOLD$1) {
|
|
2863
|
+
dragging = true;
|
|
2864
|
+
header.setAttribute('data-dragging', '');
|
|
2865
|
+
}
|
|
2866
|
+
};
|
|
2867
|
+
const end = e => {
|
|
2868
|
+
if (e.pointerId !== event.pointerId) return;
|
|
2869
|
+
doc.removeEventListener('pointermove', move);
|
|
2870
|
+
doc.removeEventListener('pointerup', end);
|
|
2871
|
+
doc.removeEventListener('pointercancel', end);
|
|
2872
|
+
header.removeAttribute('data-dragging');
|
|
2873
|
+
if (!dragging || e.type === 'pointercancel') return;
|
|
2874
|
+
// The click after a drag must not sort. The next press clears this.
|
|
2875
|
+
this._suppressClick = true;
|
|
2876
|
+
const target = doc.elementFromPoint(e.clientX, e.clientY)?.closest('.lt-header-cell[data-column-id]');
|
|
2877
|
+
const targetId = target && this.contains(target) ? target.dataset['columnId'] : undefined;
|
|
2878
|
+
if (targetId && targetId !== column.id) this.moveColumn(column.id, targetId);
|
|
2879
|
+
};
|
|
2880
|
+
doc.addEventListener('pointermove', move);
|
|
2881
|
+
doc.addEventListener('pointerup', end);
|
|
2882
|
+
doc.addEventListener('pointercancel', end);
|
|
2883
|
+
};
|
|
2884
|
+
moveColumn(sourceId, targetId) {
|
|
2885
|
+
const ids = this.args.table.getAllLeafColumns().map(c => c.id);
|
|
2886
|
+
const from = ids.indexOf(sourceId);
|
|
2887
|
+
const to = ids.indexOf(targetId);
|
|
2888
|
+
if (from < 0 || to < 0) return;
|
|
2889
|
+
ids.splice(from, 1);
|
|
2890
|
+
ids.splice(to, 0, sourceId);
|
|
2891
|
+
this.args.table.setColumnOrder?.(ids);
|
|
2892
|
+
}
|
|
2893
|
+
static {
|
|
2894
|
+
setComponentTemplate(precompileTemplate("<div class=\"lt-grid-root\" dir={{this.dir}} style={{if (has-block \"sideBar\") SPLIT_STYLE}} {{this.saveOnOutsidePress @stopEditingWhenCellsLoseFocus}}>\n <div class=\"lt-grid\" role={{this.role}} aria-label={{@label}} aria-rowcount={{this.ariaRowCount}} aria-colcount={{this.colCount}} aria-multiselectable={{if this.multiselectable \"true\"}} aria-busy={{if @loading \"true\"}} data-lt-density={{this.density}} data-lt-borders=\"rows\" style={{this.gridStyle (has-block \"sideBar\")}} ...attributes {{on \"focusin\" this.onFocusIn}} {{on \"keydown\" this.onKeyDown}} {{on \"dblclick\" this.onDoubleClick}} {{on \"click\" this.onClick}} {{on \"mousedown\" this.onMouseDown}} {{on \"mouseover\" this.onMouseOver}} {{on \"mouseout\" this.onMouseOut}} {{on \"focusout\" this.onFocusOut}} {{on \"pointerdown\" this.onPointerDown}} {{on \"copy\" this.onCopy}} {{on \"cut\" this.onCut}} {{on \"paste\" this.onPaste}} {{on \"contextmenu\" (fn this.onContextMenu (has-block \"contextMenu\"))}} {{this.noteMenuBlock (has-block \"contextMenu\")}}>\n <div class=\"lt-scroller\" {{this.setup}} {{VirtualScroll this.rowState}} {{VirtualScroll this.colState}} {{this.syncRows this.rowCount this.rowHeight this.overscan this.headerHeight this.footerHeight this.pinnedTopHeight this.pinnedBottomHeight this.measured this.display}} {{this.syncModel @rowModel this.rangeStart this.rangeEnd @rowModel.queryKey}} {{this.syncAligned @aligned (if @aligned this.alignedKey)}} {{this.syncAutoColumns this.wantsAutoColumns}} {{this.syncCols this.columns.centerSizes this.columns.startWidth this.columns.endWidth this.rtl}}>\n <div class=\"lt-sizer\" style={{this.sizerStyle}}>\n <div class=\"lt-header\" role=\"rowgroup\">\n {{#each this.groupRows key=\"key\" as |group|}}\n <div class=\"lt-row lt-header-row\" role=\"row\" aria-rowindex={{group.aria}} style={{this.rowWidthStyle}}>\n {{#each group.cells key=\"key\" as |cell|}}\n {{#if cell.header.isPlaceholder}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{cell.style}}></div>\n {{else}}\n <div class=\"lt-header-cell lt-group-header\" role=\"columnheader\" aria-colindex={{cell.aria}} aria-colspan={{cell.colSpan}} data-column-id={{cell.header.column.id}} data-pinned={{isPinned cell.pin}} tabindex=\"-1\" style={{cell.style}}>\n <span class=\"lt-header-label\">{{cell.label}}</span>\n </div>\n {{/if}}\n {{/each}}\n </div>\n {{/each}}\n <div class=\"lt-row lt-header-row\" role=\"row\" aria-rowindex={{this.leafHeaderRow}} style={{this.rowWidthStyle}}>\n {{#each this.layout.slots key=\"key\" as |slot|}}\n {{#if slot.rendered}}\n {{#if slot.gap}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{slot.gap}}></div>\n {{/if}}\n <div class=\"lt-header-cell\" role=\"columnheader\" aria-colindex={{slot.aria}} aria-sort={{sortOf slot.column}} data-column-id={{slot.column.id}} data-pinned={{isPinned slot.pin}} aria-label={{if slot.headerSlot (this.headerLabelFor slot.column)}} tabindex={{this.tabIndexFor this.leafHeaderRow slot.aria}} style={{slot.style}} {{on \"click\" (fn this.onHeaderClick slot.column)}} {{on \"pointerdown\" (fn this.onHeaderPointerDown slot.column)}}>\n <span class=\"lt-header-label\">\n {{~#if slot.headerLabel~}}\n <slot.headerLabel @column={{slot.column}} @label={{this.headerLabelFor slot.column}} />\n {{~else~}}\n {{this.headerLabelFor slot.column}}\n {{~/if~}}\n </span>\n {{#if slot.headerSlot}}\n <span class=\"lt-header-slot\"><slot.headerSlot @column={{slot.column}} @grid={{this.headerApi}} /></span>\n {{/if}}\n {{#if (this.canResize slot.column)}}\n <div class=\"lt-resize-handle\" role=\"separator\" aria-orientation=\"vertical\" aria-valuenow={{slot.size}} aria-valuemin={{MIN_COLUMN_SIZE}} aria-valuemax={{MAX_COLUMN_SIZE}} aria-label={{this.l.t \"grid.resizeColumn\" column=(this.headerLabelFor slot.column)}} tabindex=\"-1\" {{on \"pointerdown\" (fn this.onResizeStart slot.column)}} {{on \"keydown\" (fn this.onResizeKey slot.column)}} {{on \"click\" this.stopClick}} {{on \"dblclick\" (fn this.onResizeDoubleClick slot.column)}}></div>\n {{/if}}\n </div>\n {{/if}}\n {{/each}}\n {{#if this.layout.tail}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{this.layout.tail}}></div>\n {{/if}}\n </div>\n {{#if @floatingFilter}}\n <div class=\"lt-row lt-header-row lt-floating-row\" role=\"row\" aria-rowindex={{this.floatingRow}} style={{this.rowWidthStyle}}>\n {{#each this.layout.slots key=\"key\" as |slot|}}\n {{#if slot.rendered}}\n {{#if slot.gap}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{slot.gap}}></div>\n {{/if}}\n <div class=\"lt-header-cell lt-floating-cell\" role=\"gridcell\" aria-colindex={{slot.aria}} data-column-id={{slot.column.id}} data-pinned={{isPinned slot.pin}} tabindex={{this.tabIndexFor this.floatingRow slot.aria}} style={{slot.style}}>\n <@floatingFilter @column={{slot.column}} @grid={{this.headerApi}} />\n </div>\n {{/if}}\n {{/each}}\n {{#if this.layout.tail}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{this.layout.tail}}></div>\n {{/if}}\n </div>\n {{/if}}\n </div>\n <div class=\"lt-body\" role=\"rowgroup\" style={{this.bodyStyle}}>\n {{#each this.slots key=\"@index\" as |view index|}}\n {{#if view}}\n {{#let (asRowView view) (asSkeleton view) (asDetail view) as |rowView skeleton detail|}}\n {{#if rowView}}\n <LatticeRow @grid={{this}} @view={{rowView}} @slot={{index}} />\n {{else if detail}}\n <DetailRow @grid={{this}} @view={{detail}} @slot={{index}} />\n {{else if skeleton}}\n <SkeletonRow @grid={{this}} @view={{skeleton}} @slot={{index}} />\n {{/if}}\n {{/let}}\n {{/if}}\n {{/each}}\n </div>\n {{#if @rowModel.totalRow}}\n <div class=\"lt-footer\" role=\"rowgroup\" style={{this.footerStyle}}>\n <div class=\"lt-row lt-total-row\" role=\"row\" aria-rowindex={{this.totalAriaRow}} style={{this.rowWidthStyle}}>\n {{#each this.layout.slots key=\"key\" as |slot|}}\n {{#if slot.rendered}}\n {{#if slot.gap}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{slot.gap}}></div>\n {{/if}}\n <div class=\"lt-cell\" role=\"gridcell\" aria-colindex={{slot.aria}} data-column-id={{slot.column.id}} data-pinned={{isPinned slot.pin}} style={{slot.style}}>{{totalText @rowModel.totalRow slot this.l}}</div>\n {{/if}}\n {{/each}}\n {{#if this.layout.tail}}\n <div class=\"lt-spacer\" aria-hidden=\"true\" style={{this.layout.tail}}></div>\n {{/if}}\n </div>\n </div>\n {{/if}}\n </div>\n </div>\n </div>\n {{#if (has-block \"sideBar\")}}\n <div class=\"lt-side-bar-region\">{{yield to=\"sideBar\"}}</div>\n {{/if}}\n {{#if this.overlayMessage}}\n <div class=\"lt-overlay-message\" role=\"status\" aria-label={{this.l.t \"grid.status\"}}>{{this.overlayMessage}}</div>\n {{/if}}\n {{#if this.tooltip}}\n <div class=\"lt-tooltip\" role=\"tooltip\" id={{this.tooltipId}} style={{this.tooltip.style}}>{{this.tooltip.text}}</div>\n {{/if}}\n {{#if this.note}}\n <div class=\"lt-note\" role=\"note\" id={{this.noteId}} {{this.placeNote this.note this.tooltip}}>{{this.note.text}}</div>\n {{/if}}\n {{#if this.cellDescriptions.length}}\n <div class=\"lt-cell-descriptions\" hidden>\n {{#each this.cellDescriptions as |description|}}\n <span id={{description.id}}>{{description.text}}</span>\n {{/each}}\n </div>\n {{/if}}\n <div class=\"lt-live\" role=\"status\" aria-label={{this.l.t \"grid.messages\"}} style={{LIVE_STYLE}}>\n <span data-live=\"message\">{{this.liveMessage}}</span>\n <span data-live=\"edit\">{{@editing.message}}</span>\n <span data-live=\"count\">{{this.countMessage}}</span>\n </div>\n {{!-- The keys of the editor do not reach role=grid: the overlay is outside it. --}}\n <div class=\"lt-overlay\" {{on \"keydown\" this.onEditorEscape capture=true}} {{on \"keydown\" this.onEditorKeyDown}} {{on \"focusout\" this.onEditorFocusOut}}>\n {{yield (hash target=this.contextTarget selection=this.selection close=this.closeMenu copyText=this.copyText pasteText=this.pasteText) to=\"contextMenu\"}}\n {{#if @editing}}\n {{#if @editing.active}}\n <div class=\"lt-editor\" data-lt-edit-state={{@editing.state}} data-lt-edit-mode={{this.editMode}} {{this.placeEditor this.editPosition}}>\n <@editing.Editor @cell={{@editing.active}} @id={{this.editorId}} @label={{this.headerLabelFor @editing.active.column}} @value={{@editing.draft}} @onChange={{@editing.setDraft}} @invalid={{this.editInvalid}} />\n {{#each @editing.errors as |error|}}\n <div class=\"lt-editor-error\" role=\"alert\">{{error}}</div>\n {{/each}}\n </div>\n {{/if}}\n {{#let @editing.RowEditor @editing.activeRow as |RowEditor row|}}\n {{#if RowEditor}}\n {{#if row}}\n <div class=\"lt-row-editor\" role=\"group\" aria-label={{this.l.t \"grid.editRow\" row=this.editRowNumber}} data-lt-edit-state={{@editing.state}} {{this.placeRowEditor this.editPosition}}>\n <RowEditor @row={{row}} @fields={{this.rowEditFields}} @values={{this.rowDraft}} @onChange={{this.setRowValue}} />\n {{#each @editing.errors as |error|}}\n <div class=\"lt-editor-error\" role=\"alert\">{{error}}</div>\n {{/each}}\n </div>\n {{/if}}\n {{/if}}\n {{/let}}\n {{/if}}\n </div>\n</div>", {
|
|
2895
|
+
strictMode: true,
|
|
2896
|
+
scope: () => ({
|
|
2897
|
+
SPLIT_STYLE,
|
|
2898
|
+
on,
|
|
2899
|
+
fn,
|
|
2900
|
+
VirtualScroll,
|
|
2901
|
+
isPinned,
|
|
2902
|
+
sortOf,
|
|
2903
|
+
MIN_COLUMN_SIZE,
|
|
2904
|
+
MAX_COLUMN_SIZE,
|
|
2905
|
+
asRowView,
|
|
2906
|
+
asSkeleton,
|
|
2907
|
+
asDetail,
|
|
2908
|
+
LatticeRow,
|
|
2909
|
+
DetailRow,
|
|
2910
|
+
SkeletonRow,
|
|
2911
|
+
totalText,
|
|
2912
|
+
LIVE_STYLE,
|
|
2913
|
+
hash
|
|
2914
|
+
})
|
|
2915
|
+
}), this);
|
|
2916
|
+
}
|
|
2917
|
+
get rowDraft() {
|
|
2918
|
+
return this.args.editing?.rowDraft ?? {};
|
|
2919
|
+
}
|
|
2920
|
+
setRowValue = (columnId, value) => this.args.editing?.setRowValue?.(columnId, value);
|
|
2921
|
+
get rangeStart() {
|
|
2922
|
+
return this.range[0];
|
|
2923
|
+
}
|
|
2924
|
+
get rangeEnd() {
|
|
2925
|
+
return this.range[1];
|
|
2926
|
+
}
|
|
2927
|
+
/** All rows plus the header rows, or -1 when the row model does not know the count (ARIA). */
|
|
2928
|
+
get ariaRowCount() {
|
|
2929
|
+
const model = this.args.rowModel;
|
|
2930
|
+
if (model && model.rowCount === null) return -1;
|
|
2931
|
+
return this.rowCount + this.headerRowCount + (model?.totalRow ? 1 : 0);
|
|
2932
|
+
}
|
|
2933
|
+
get footerHeight() {
|
|
2934
|
+
return this.args.rowModel?.totalRow ? this.rowHeight : 0;
|
|
2935
|
+
}
|
|
2936
|
+
/** The grand total row is after the last row. */
|
|
2937
|
+
get totalAriaRow() {
|
|
2938
|
+
return this.headerRowCount + this.rowCount + 1;
|
|
2939
|
+
}
|
|
2940
|
+
/** The total row stays at the bottom of the view while the rows scroll. */
|
|
2941
|
+
get footerStyle() {
|
|
2942
|
+
return htmlSafe(`position: sticky; inset-block-end: 0; z-index: 2; inline-size: ${px$2(this.totalWidth)}`);
|
|
2943
|
+
}
|
|
2944
|
+
get role() {
|
|
2945
|
+
return this.args.rowModel?.tree || this.clientTree ? 'treegrid' : 'grid';
|
|
2946
|
+
}
|
|
2947
|
+
get overscan() {
|
|
2948
|
+
return this.args.overscan ?? DEFAULT_OVERSCAN$1;
|
|
2949
|
+
}
|
|
2950
|
+
/** The row height when `@rowHeight` is given, and the flex size beside a side bar. */
|
|
2951
|
+
gridStyle = split => {
|
|
2952
|
+
const height = this.args.rowHeight;
|
|
2953
|
+
const style = (is.number(height) ? `--lt-row-height: ${px$2(height)}; ` : '') + (split ? 'flex: 1 1 auto; min-inline-size: 0' : '');
|
|
2954
|
+
return style === '' ? undefined : htmlSafe(style);
|
|
2955
|
+
};
|
|
2956
|
+
}
|
|
2957
|
+
|
|
2958
|
+
// The row selection column: a Joinery `Checkbox` in each row.
|
|
2959
|
+
class SelectCell extends Component {
|
|
2960
|
+
get checked() {
|
|
2961
|
+
return this.args.row.getIsSelected?.() ?? false;
|
|
2962
|
+
}
|
|
2963
|
+
get disabled() {
|
|
2964
|
+
return this.args.row.getCanSelect?.() === false;
|
|
2965
|
+
}
|
|
2966
|
+
/** A grid slot has a fixed signature, so it reads only the owner text (ADR 0024). */
|
|
2967
|
+
get label() {
|
|
2968
|
+
return latticeLocale(getOwner(this)).t('grid.selectRow');
|
|
2969
|
+
}
|
|
2970
|
+
onChange = checked => this.args.row.toggleSelected?.(checked === true);
|
|
2971
|
+
/** The cell is the tab stop: after a click, give it the focus, so the arrow keys work. */
|
|
2972
|
+
focusCell = event => {
|
|
2973
|
+
if (!(event.currentTarget instanceof Element)) return;
|
|
2974
|
+
const cell = event.currentTarget.closest('[role="gridcell"]');
|
|
2975
|
+
if (cell instanceof HTMLElement) cell.focus();
|
|
2976
|
+
};
|
|
2977
|
+
static {
|
|
2978
|
+
setComponentTemplate(precompileTemplate("{{!-- The cell is the tab stop: the checkbox is not. --}}\n<Checkbox class=\"lt-select\" @checked={{this.checked}} @disabled={{this.disabled}} @onCheckedChange={{this.onChange}} aria-label={{this.label}} tabindex=\"-1\" {{on \"click\" this.focusCell}} as |c|>\n <c.Indicator>\u2713</c.Indicator>\n</Checkbox>", {
|
|
2979
|
+
strictMode: true,
|
|
2980
|
+
scope: () => ({
|
|
2981
|
+
Checkbox,
|
|
2982
|
+
on
|
|
2983
|
+
})
|
|
2984
|
+
}), this);
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
/** The column def of the selection column. */
|
|
2988
|
+
|
|
2989
|
+
/**
|
|
2990
|
+
* A column def for row selection. Put it in the `columns` of the table. The table needs the
|
|
2991
|
+
* `rowSelectionFeature`.
|
|
2992
|
+
* The default header is the locale text of `locale` (`latticeLocale(owner)`), or English.
|
|
2993
|
+
*/
|
|
2994
|
+
function selectionColumn(options = {}) {
|
|
2995
|
+
return {
|
|
2996
|
+
id: '__lattice_select',
|
|
2997
|
+
header: options.header ?? (options.locale ?? latticeLocale(undefined)).t('grid.selectedHeader'),
|
|
2998
|
+
size: options.size ?? 40,
|
|
2999
|
+
enableSorting: false,
|
|
3000
|
+
enableResizing: false,
|
|
3001
|
+
// The checkbox has no local state: it reads the row, so it can reuse a row slot.
|
|
3002
|
+
meta: {
|
|
3003
|
+
lattice: {
|
|
3004
|
+
cell: SelectCell,
|
|
3005
|
+
cellKind: 'cheap',
|
|
3006
|
+
align: 'center'
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
};
|
|
3010
|
+
}
|
|
3011
|
+
|
|
3012
|
+
// The row number column: the display position of each row, pinned at the inline start.
|
|
3013
|
+
|
|
3014
|
+
/** The column def of the row number column. */
|
|
3015
|
+
|
|
3016
|
+
/**
|
|
3017
|
+
* A column def for row numbers. Put it in the `columns` of the table. The grid pins it at the
|
|
3018
|
+
* inline start and shows the 1-based display position of each row (ADR 0018).
|
|
3019
|
+
* The default header is the locale text of `locale` (`latticeLocale(owner)`), or English.
|
|
3020
|
+
*/
|
|
3021
|
+
function rowNumberColumn(options = {}) {
|
|
3022
|
+
return {
|
|
3023
|
+
id: '__lattice_row_number',
|
|
3024
|
+
header: options.header ?? (options.locale ?? latticeLocale(undefined)).t('grid.rowNumberHeader'),
|
|
3025
|
+
size: options.size ?? 56,
|
|
3026
|
+
enableSorting: false,
|
|
3027
|
+
enableResizing: false,
|
|
3028
|
+
meta: {
|
|
3029
|
+
lattice: {
|
|
3030
|
+
rowNumber: true,
|
|
3031
|
+
cellKind: 'cheap',
|
|
3032
|
+
align: 'end'
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3037
|
+
|
|
3038
|
+
// LatticeList: the List surface (docs/m3-list-board-contract.md, section 1). Items are measured
|
|
3039
|
+
// after render. Each item is keyed by its ID, so it keeps its element while it is in range, and
|
|
3040
|
+
// the active item stays rendered (held) when it leaves the range (ADR 0002, amendment 1).
|
|
3041
|
+
const DEFAULT_ESTIMATE = 48;
|
|
3042
|
+
const DEFAULT_OVERSCAN = 4;
|
|
3043
|
+
const DEFAULT_MIN_CARD_WIDTH = 240;
|
|
3044
|
+
const ITEM_ROLE = {
|
|
3045
|
+
list: 'listitem',
|
|
3046
|
+
feed: 'article',
|
|
3047
|
+
listbox: 'option'
|
|
3048
|
+
};
|
|
3049
|
+
const px$1 = n => `${n}px`;
|
|
3050
|
+
const inc = n => n + 1;
|
|
3051
|
+
class LatticeList extends Component {
|
|
3052
|
+
static {
|
|
3053
|
+
g(this.prototype, "_activeId", [tracked], function () {
|
|
3054
|
+
return null;
|
|
3055
|
+
});
|
|
3056
|
+
}
|
|
3057
|
+
#_activeId = (i(this, "_activeId"), void 0);
|
|
3058
|
+
/** The ID of the item with the focus, or the listbox tab stop. It stays rendered. */
|
|
3059
|
+
state = new VirtualizerState(this.options(this.ids, this.estimate, -1, this.lanes));
|
|
3060
|
+
/** The width of the scroller, for the `cards` layout. */
|
|
3061
|
+
static {
|
|
3062
|
+
g(this.prototype, "_width", [tracked], function () {
|
|
3063
|
+
return 0;
|
|
3064
|
+
});
|
|
3065
|
+
}
|
|
3066
|
+
#_width = (i(this, "_width"), void 0);
|
|
3067
|
+
static {
|
|
3068
|
+
g(this.prototype, "loadingStart", [tracked], function () {
|
|
3069
|
+
return false;
|
|
3070
|
+
});
|
|
3071
|
+
}
|
|
3072
|
+
#loadingStart = (i(this, "loadingStart"), void 0);
|
|
3073
|
+
/** A load call is in progress at this edge. */
|
|
3074
|
+
static {
|
|
3075
|
+
g(this.prototype, "loadingEnd", [tracked], function () {
|
|
3076
|
+
return false;
|
|
3077
|
+
});
|
|
3078
|
+
}
|
|
3079
|
+
#loadingEnd = (i(this, "loadingEnd"), void 0);
|
|
3080
|
+
typeahead = new Typeahead();
|
|
3081
|
+
_edgeCheckQueued = false;
|
|
3082
|
+
/** False until a chat list has reached the bottom once: no load before that. */
|
|
3083
|
+
_ready = this.args.anchor !== 'end';
|
|
3084
|
+
_root = null;
|
|
3085
|
+
/** An item to focus when its element renders. */
|
|
3086
|
+
_focusId = null;
|
|
3087
|
+
constructor(owner, args) {
|
|
3088
|
+
super(owner, args);
|
|
3089
|
+
registerDestructor(this, () => this.typeahead.dispose());
|
|
3090
|
+
}
|
|
3091
|
+
/** The locale text of this component (ADR 0024): `@localeText`, then the owner text. */
|
|
3092
|
+
get l() {
|
|
3093
|
+
return latticeLocale(getOwner(this), this.args.localeText);
|
|
3094
|
+
}
|
|
3095
|
+
static {
|
|
3096
|
+
n(this.prototype, "l", [cached]);
|
|
3097
|
+
}
|
|
3098
|
+
get role() {
|
|
3099
|
+
return this.args.role ?? 'list';
|
|
3100
|
+
}
|
|
3101
|
+
get itemRole() {
|
|
3102
|
+
return ITEM_ROLE[this.role];
|
|
3103
|
+
}
|
|
3104
|
+
get estimate() {
|
|
3105
|
+
return this.args.estimateSize ?? DEFAULT_ESTIMATE;
|
|
3106
|
+
}
|
|
3107
|
+
get layout() {
|
|
3108
|
+
return this.args.layout ?? 'rows';
|
|
3109
|
+
}
|
|
3110
|
+
get isCards() {
|
|
3111
|
+
return this.layout === 'cards';
|
|
3112
|
+
}
|
|
3113
|
+
get lanes() {
|
|
3114
|
+
if (this.layout === 'cards') {
|
|
3115
|
+
const min = this.args.minCardWidth ?? DEFAULT_MIN_CARD_WIDTH;
|
|
3116
|
+
return Math.max(1, Math.floor(this._width / min));
|
|
3117
|
+
}
|
|
3118
|
+
return Math.max(1, Math.floor(this.args.lanes ?? 1));
|
|
3119
|
+
}
|
|
3120
|
+
get overscan() {
|
|
3121
|
+
return this.args.overscan ?? DEFAULT_OVERSCAN;
|
|
3122
|
+
}
|
|
3123
|
+
get items() {
|
|
3124
|
+
return this.args.items ?? this.args.table?.getRowModel().rows ?? [];
|
|
3125
|
+
}
|
|
3126
|
+
static {
|
|
3127
|
+
n(this.prototype, "items", [cached]);
|
|
3128
|
+
}
|
|
3129
|
+
idOf(item) {
|
|
3130
|
+
if (this.args.getItemId) return this.args.getItemId(item);
|
|
3131
|
+
if (is.object(item)) {
|
|
3132
|
+
const id = Reflect.get(item, 'id');
|
|
3133
|
+
if (is.string(id)) return id;
|
|
3134
|
+
}
|
|
3135
|
+
throw new Error('LatticeList: give @getItemId, or items with a string `id`.');
|
|
3136
|
+
}
|
|
3137
|
+
get ids() {
|
|
3138
|
+
return this.items.map(item => this.idOf(item));
|
|
3139
|
+
}
|
|
3140
|
+
static {
|
|
3141
|
+
n(this.prototype, "ids", [cached]);
|
|
3142
|
+
}
|
|
3143
|
+
get indexById() {
|
|
3144
|
+
return new Map(this.ids.map((id, index) => [id, index]));
|
|
3145
|
+
}
|
|
3146
|
+
/** The listbox tab stop: the active option, else the first option. */
|
|
3147
|
+
static {
|
|
3148
|
+
n(this.prototype, "indexById", [cached]);
|
|
3149
|
+
}
|
|
3150
|
+
get tabStopId() {
|
|
3151
|
+
const active = this._activeId;
|
|
3152
|
+
return active !== null && this.indexById.has(active) ? active : this.ids[0];
|
|
3153
|
+
}
|
|
3154
|
+
/** The index of the item that stays rendered out of range (the focus or the tab stop), or -1. */
|
|
3155
|
+
get heldIndex() {
|
|
3156
|
+
const id = this.role === 'listbox' ? this.tabStopId : this._activeId;
|
|
3157
|
+
return id === null || id === undefined ? -1 : this.indexById.get(id) ?? -1;
|
|
3158
|
+
}
|
|
3159
|
+
get multiselect() {
|
|
3160
|
+
return this.role === 'listbox' && this.args.multiselect === true;
|
|
3161
|
+
}
|
|
3162
|
+
tabIndexFor = id => {
|
|
3163
|
+
if (this.role === 'feed') return 0;
|
|
3164
|
+
if (this.role === 'listbox') return id === this.tabStopId ? 0 : -1;
|
|
3165
|
+
return undefined;
|
|
3166
|
+
};
|
|
3167
|
+
selectedFor = id => {
|
|
3168
|
+
if (this.role !== 'listbox') return undefined;
|
|
3169
|
+
return this.args.selection?.has(id) ? 'true' : 'false';
|
|
3170
|
+
};
|
|
3171
|
+
options(ids, estimate, held, lanes) {
|
|
3172
|
+
return {
|
|
3173
|
+
count: ids.length,
|
|
3174
|
+
estimateSize: () => estimate,
|
|
3175
|
+
// A new function on each change: the virtualizer finds the keys of a prepend with it.
|
|
3176
|
+
getItemKey: index => ids[index] ?? index,
|
|
3177
|
+
overscan: this.overscan,
|
|
3178
|
+
lanes,
|
|
3179
|
+
// The shortest lane by the measured heights, not by the estimates.
|
|
3180
|
+
laneAssignmentMode: 'measured',
|
|
3181
|
+
// The key anchor of the core: a prepend keeps the view still.
|
|
3182
|
+
anchorTo: 'end',
|
|
3183
|
+
// A chat stays at the bottom when items arrive, unless the user has scrolled up.
|
|
3184
|
+
followOnAppend: this.args.anchor === 'end',
|
|
3185
|
+
scrollEndThreshold: 2,
|
|
3186
|
+
// Not during render: the check runs in a microtask, and a load call writes tracked state.
|
|
3187
|
+
onChange: () => this.queueEdgeCheck(),
|
|
3188
|
+
rangeExtractor: range => {
|
|
3189
|
+
const indexes = defaultRangeExtractor(range);
|
|
3190
|
+
if (held < 0 || held >= range.count || indexes.includes(held)) return indexes;
|
|
3191
|
+
return [...indexes, held].sort((a, b) => a - b);
|
|
3192
|
+
}
|
|
3193
|
+
};
|
|
3194
|
+
}
|
|
3195
|
+
get views() {
|
|
3196
|
+
const virtualizer = this.state.virtualizer;
|
|
3197
|
+
const items = this.state.virtualItems;
|
|
3198
|
+
const range = virtualizer.range;
|
|
3199
|
+
const active = this.role === 'listbox' ? this.tabStopId : this._activeId;
|
|
3200
|
+
const lanes = this.lanes;
|
|
3201
|
+
const views = [];
|
|
3202
|
+
for (const virtual of items) {
|
|
3203
|
+
// The key, not the index: the first render after a change to the items still has the
|
|
3204
|
+
// old layout, and its indexes point to other items.
|
|
3205
|
+
const id = String(virtual.key);
|
|
3206
|
+
const index = this.indexById.get(id);
|
|
3207
|
+
if (index === undefined) continue;
|
|
3208
|
+
const reach = this.overscan * lanes;
|
|
3209
|
+
const outside = range !== null && (virtual.index < range.startIndex - reach || virtual.index > range.endIndex + reach);
|
|
3210
|
+
views.push({
|
|
3211
|
+
id,
|
|
3212
|
+
item: this.items[index],
|
|
3213
|
+
index,
|
|
3214
|
+
held: id === active && outside,
|
|
3215
|
+
lane: lanes > 1 ? virtual.lane : undefined,
|
|
3216
|
+
style: htmlSafe(`transform: translateY(${px$1(virtual.start)})` + (lanes > 1 ? `; inline-size: calc(100% / ${lanes}); inset-inline-start: calc(100% * ${virtual.lane} / ${lanes})` : ''))
|
|
3217
|
+
});
|
|
3218
|
+
}
|
|
3219
|
+
return views;
|
|
3220
|
+
}
|
|
3221
|
+
static {
|
|
3222
|
+
n(this.prototype, "views", [cached]);
|
|
3223
|
+
}
|
|
3224
|
+
get busy() {
|
|
3225
|
+
return this.loadingStart || this.loadingEnd;
|
|
3226
|
+
}
|
|
3227
|
+
// Load more and load previous ---------------------------------------------------------------
|
|
3228
|
+
queueEdgeCheck() {
|
|
3229
|
+
if (this._edgeCheckQueued) return;
|
|
3230
|
+
this._edgeCheckQueued = true;
|
|
3231
|
+
queueMicrotask(() => {
|
|
3232
|
+
this._edgeCheckQueued = false;
|
|
3233
|
+
if (!this.isDestroying) this.checkEdges();
|
|
3234
|
+
});
|
|
3235
|
+
}
|
|
3236
|
+
/**
|
|
3237
|
+
* Call a load function when its edge is in the rendered range. It runs only on a range change,
|
|
3238
|
+
* so a load that adds no items is not called again until the range changes.
|
|
3239
|
+
*/
|
|
3240
|
+
checkEdges() {
|
|
3241
|
+
if (!this._ready) {
|
|
3242
|
+
if (!this.state.virtualizer.isAtEnd()) return;
|
|
3243
|
+
this._ready = true;
|
|
3244
|
+
}
|
|
3245
|
+
const range = this.state.virtualizer.range;
|
|
3246
|
+
const count = this.ids.length;
|
|
3247
|
+
const reach = this.overscan;
|
|
3248
|
+
if (count === 0 || range && range.endIndex + reach >= count - 1) this.load('end');
|
|
3249
|
+
if (count > 0 && range && range.startIndex - reach <= 0) this.load('start');
|
|
3250
|
+
}
|
|
3251
|
+
load(edge) {
|
|
3252
|
+
const fn = edge === 'end' ? this.args.onLoadMore : this.args.onLoadPrevious;
|
|
3253
|
+
const loading = edge === 'end' ? this.loadingEnd : this.loadingStart;
|
|
3254
|
+
if (!fn || loading) return;
|
|
3255
|
+
this.setLoading(edge, true);
|
|
3256
|
+
void Promise.resolve(fn()).finally(() => {
|
|
3257
|
+
if (!this.isDestroying) this.setLoading(edge, false);
|
|
3258
|
+
});
|
|
3259
|
+
}
|
|
3260
|
+
setLoading(edge, value) {
|
|
3261
|
+
if (edge === 'end') this.loadingEnd = value;else this.loadingStart = value;
|
|
3262
|
+
}
|
|
3263
|
+
get sizerStyle() {
|
|
3264
|
+
return htmlSafe(`block-size: ${px$1(this.state.totalSize)}`);
|
|
3265
|
+
}
|
|
3266
|
+
// Modifiers -------------------------------------------------------------------------------
|
|
3267
|
+
/** Give the virtualizer the current items. It runs after render, never during it. */
|
|
3268
|
+
sync = modifier((_el, [ids, estimate, held, lanes]) => {
|
|
3269
|
+
this.state.setOptions(this.options(ids, estimate, held, lanes));
|
|
3270
|
+
});
|
|
3271
|
+
/** The `cards` layout: read the width of the scroller when it changes. */
|
|
3272
|
+
observeWidth = modifier((scroller, [cards]) => {
|
|
3273
|
+
if (!cards) return;
|
|
3274
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
3275
|
+
const width = entry?.contentRect.width ?? 0;
|
|
3276
|
+
if (width !== this._width) this._width = width;
|
|
3277
|
+
});
|
|
3278
|
+
observer.observe(scroller);
|
|
3279
|
+
return () => observer.disconnect();
|
|
3280
|
+
});
|
|
3281
|
+
/** A chat list starts at the bottom. */
|
|
3282
|
+
startAtEnd = modifier(() => {
|
|
3283
|
+
if (this.args.anchor === 'end') this.state.virtualizer.scrollToEnd();
|
|
3284
|
+
});
|
|
3285
|
+
/** Measure an item element (ResizeObserver, through the virtualizer). */ // The index is an argument so that the modifier runs again when the item moves.
|
|
3286
|
+
measure = modifier((el, [id]) => {
|
|
3287
|
+
const virtualizer = this.state.virtualizer;
|
|
3288
|
+
const run = () => {
|
|
3289
|
+
if (!el.isConnected) return;
|
|
3290
|
+
const index = Number(el.dataset['index']);
|
|
3291
|
+
// Before the sync modifier runs, the virtualizer can still have the old keys.
|
|
3292
|
+
if (virtualizer.options.getItemKey(index) === id) virtualizer.measureElement(el);
|
|
3293
|
+
};
|
|
3294
|
+
if (virtualizer.options.getItemKey(Number(el.dataset['index'])) === id) run();else queueMicrotask(run);
|
|
3295
|
+
if (this.role === 'feed') this.labelArticle(el, id);
|
|
3296
|
+
if (this._focusId === id) {
|
|
3297
|
+
this._focusId = null;
|
|
3298
|
+
el.focus({
|
|
3299
|
+
preventScroll: true
|
|
3300
|
+
});
|
|
3301
|
+
}
|
|
3302
|
+
return () => virtualizer.measureElement(null);
|
|
3303
|
+
});
|
|
3304
|
+
/**
|
|
3305
|
+
* A feed article is labelled by its title, when the item marks one with `data-lt-item-title`.
|
|
3306
|
+
* shortcut: read when the item renders; a title that the item adds later is not seen.
|
|
3307
|
+
*/
|
|
3308
|
+
labelArticle(el, id) {
|
|
3309
|
+
const title = el.querySelector('[data-lt-item-title]');
|
|
3310
|
+
if (!title) return el.removeAttribute('aria-labelledby');
|
|
3311
|
+
if (!title.id) title.id = `${guidFor(this)}-title-${id}`;
|
|
3312
|
+
el.setAttribute('aria-labelledby', title.id);
|
|
3313
|
+
}
|
|
3314
|
+
// Focus -----------------------------------------------------------------------------------
|
|
3315
|
+
setup = modifier(root => {
|
|
3316
|
+
this._root = root;
|
|
3317
|
+
const doc = root.ownerDocument;
|
|
3318
|
+
const onPointerDown = () => this._pointerDownAt = performance.now();
|
|
3319
|
+
doc.addEventListener('pointerdown', onPointerDown, {
|
|
3320
|
+
capture: true
|
|
3321
|
+
});
|
|
3322
|
+
return () => {
|
|
3323
|
+
doc.removeEventListener('pointerdown', onPointerDown, {
|
|
3324
|
+
capture: true
|
|
3325
|
+
});
|
|
3326
|
+
this._root = null;
|
|
3327
|
+
};
|
|
3328
|
+
});
|
|
3329
|
+
/** The time of the last pointer press on the page, to tell a click-out from a DOM move. */
|
|
3330
|
+
_pointerDownAt = -Infinity;
|
|
3331
|
+
/**
|
|
3332
|
+
* A keyed `{{#each}}` moves the focused item in the DOM when the items before it change, and
|
|
3333
|
+
* the browser then blurs it with no `relatedTarget`. After the render, give the focus back to
|
|
3334
|
+
* the active item. A blur from a pointer press, or to outside the page, is a real blur.
|
|
3335
|
+
* shortcut: as in the Grid, a script call of `blur()` on an item also gets the focus back.
|
|
3336
|
+
*/
|
|
3337
|
+
onFocusOut = event => {
|
|
3338
|
+
const to = event.relatedTarget;
|
|
3339
|
+
// The focus left the list: a list or feed item is no longer held. The listbox keeps its tab stop.
|
|
3340
|
+
if (to instanceof Node && !this._root?.contains(to) && this.role !== 'listbox') {
|
|
3341
|
+
this._activeId = null;
|
|
3342
|
+
}
|
|
3343
|
+
if (to !== null) return;
|
|
3344
|
+
const pressed = performance.now() - this._pointerDownAt < 500;
|
|
3345
|
+
const id = this._activeId;
|
|
3346
|
+
const lost = event.target;
|
|
3347
|
+
queueMicrotask(() => {
|
|
3348
|
+
const active = document.activeElement;
|
|
3349
|
+
if (pressed || id === null || !document.hasFocus()) return;
|
|
3350
|
+
if (active && active !== document.body) return;
|
|
3351
|
+
// The element that lost the focus (a control in the item) if it is still in the list.
|
|
3352
|
+
const target = lost instanceof HTMLElement && lost.isConnected && this._root?.contains(lost) ? lost : this.itemElement(id);
|
|
3353
|
+
target?.focus({
|
|
3354
|
+
preventScroll: true
|
|
3355
|
+
});
|
|
3356
|
+
});
|
|
3357
|
+
};
|
|
3358
|
+
itemElement(id) {
|
|
3359
|
+
return this._root?.querySelector(`.lt-list-item[data-item-id="${CSS.escape(id)}"]`) ?? null;
|
|
3360
|
+
}
|
|
3361
|
+
itemOf(target) {
|
|
3362
|
+
if (!(target instanceof Element)) return null;
|
|
3363
|
+
const el = target.closest('.lt-list-item');
|
|
3364
|
+
const index = this.indexById.get(el?.dataset['itemId'] ?? '');
|
|
3365
|
+
if (!el || index === undefined || !this._root?.contains(el)) return null;
|
|
3366
|
+
return {
|
|
3367
|
+
el,
|
|
3368
|
+
index
|
|
3369
|
+
};
|
|
3370
|
+
}
|
|
3371
|
+
/** Make an item active, scroll it into view, and focus it after the render. */
|
|
3372
|
+
activate(index) {
|
|
3373
|
+
const id = this.ids[index];
|
|
3374
|
+
if (id === undefined) return;
|
|
3375
|
+
this._activeId = id;
|
|
3376
|
+
this.state.virtualizer.scrollToIndex(index, {
|
|
3377
|
+
align: 'auto'
|
|
3378
|
+
});
|
|
3379
|
+
const el = this.itemElement(id);
|
|
3380
|
+
// An item out of range renders after this (it is held); the item modifier focuses it then.
|
|
3381
|
+
if (el) el.focus({
|
|
3382
|
+
preventScroll: true
|
|
3383
|
+
});else this._focusId = id;
|
|
3384
|
+
}
|
|
3385
|
+
select(id, mode) {
|
|
3386
|
+
let next;
|
|
3387
|
+
if (mode === 'only') {
|
|
3388
|
+
next = new Set([id]);
|
|
3389
|
+
} else {
|
|
3390
|
+
next = new Set(this.args.selection);
|
|
3391
|
+
if (mode === 'toggle' && next.has(id)) next.delete(id);else next.add(id);
|
|
3392
|
+
}
|
|
3393
|
+
this.args.onSelectionChange?.(next);
|
|
3394
|
+
}
|
|
3395
|
+
onKeyDown = event => {
|
|
3396
|
+
const found = this.itemOf(event.target);
|
|
3397
|
+
if (!found || found.el !== event.target) return;
|
|
3398
|
+
if (this.role === 'listbox') this.listboxKey(event, found.index);
|
|
3399
|
+
if (this.role === 'feed') this.feedKey(event, found.index);
|
|
3400
|
+
};
|
|
3401
|
+
/** The APG feed keys: PageDown and PageUp move to the next and the previous article. */
|
|
3402
|
+
feedKey(event, index) {
|
|
3403
|
+
const step = event.key === 'PageDown' ? 1 : event.key === 'PageUp' ? -1 : 0;
|
|
3404
|
+
const next = index + step;
|
|
3405
|
+
if (step === 0 || next < 0 || next >= this.ids.length) return;
|
|
3406
|
+
event.preventDefault();
|
|
3407
|
+
this.activate(next);
|
|
3408
|
+
}
|
|
3409
|
+
/** The APG listbox keys. */
|
|
3410
|
+
listboxKey(event, index) {
|
|
3411
|
+
const id = this.ids[index] ?? '';
|
|
3412
|
+
const last = this.ids.length - 1;
|
|
3413
|
+
const ctrl = event.ctrlKey || event.metaKey;
|
|
3414
|
+
if (ctrl && event.key.toLowerCase() === 'a' && this.multiselect) {
|
|
3415
|
+
event.preventDefault();
|
|
3416
|
+
this.args.onSelectionChange?.(new Set(this.ids));
|
|
3417
|
+
return;
|
|
3418
|
+
}
|
|
3419
|
+
if (event.key === ' ' && !this.typeahead.isTyping) {
|
|
3420
|
+
event.preventDefault();
|
|
3421
|
+
this.select(id, this.multiselect ? 'toggle' : 'only');
|
|
3422
|
+
return;
|
|
3423
|
+
}
|
|
3424
|
+
if (isTypeaheadKey(event)) {
|
|
3425
|
+
event.preventDefault();
|
|
3426
|
+
this.typeaheadKey(event.key, this.itemElement(id) ?? undefined);
|
|
3427
|
+
return;
|
|
3428
|
+
}
|
|
3429
|
+
const next = event.key === 'ArrowDown' ? Math.min(index + 1, last) : event.key === 'ArrowUp' ? Math.max(index - 1, 0) : event.key === 'Home' ? 0 : event.key === 'End' ? last : null;
|
|
3430
|
+
if (next === null) return;
|
|
3431
|
+
event.preventDefault();
|
|
3432
|
+
this.activate(next);
|
|
3433
|
+
const nextId = this.ids[next];
|
|
3434
|
+
if (event.shiftKey && this.multiselect && nextId !== undefined) this.select(nextId, 'add');
|
|
3435
|
+
}
|
|
3436
|
+
/**
|
|
3437
|
+
* shortcut: typeahead searches the rendered options only (their text is in the DOM); add an
|
|
3438
|
+
* item text argument if a search must reach items out of range.
|
|
3439
|
+
*/
|
|
3440
|
+
typeaheadKey(key, current) {
|
|
3441
|
+
const options = [...(this._root?.querySelectorAll('.lt-list-item') ?? [])].sort((a, b) => Number(a.dataset['index']) - Number(b.dataset['index']));
|
|
3442
|
+
const match = getNextMatch(options, this.typeahead.type(key), current, el => el.textContent?.trim() ?? '');
|
|
3443
|
+
const index = this.indexById.get(match?.dataset['itemId'] ?? '');
|
|
3444
|
+
if (index !== undefined) this.activate(index);
|
|
3445
|
+
}
|
|
3446
|
+
onClick = event => {
|
|
3447
|
+
if (this.role !== 'listbox') return;
|
|
3448
|
+
const found = this.itemOf(event.target);
|
|
3449
|
+
const id = found ? this.ids[found.index] : undefined;
|
|
3450
|
+
if (!found || id === undefined) return;
|
|
3451
|
+
this.activate(found.index);
|
|
3452
|
+
this.select(id, this.multiselect ? 'toggle' : 'only');
|
|
3453
|
+
};
|
|
3454
|
+
onFocusIn = event => {
|
|
3455
|
+
const target = event.target;
|
|
3456
|
+
if (!(target instanceof Element)) return;
|
|
3457
|
+
const id = target.closest('.lt-list-item')?.dataset['itemId'];
|
|
3458
|
+
if (id !== undefined && id !== this._activeId) this._activeId = id;
|
|
3459
|
+
};
|
|
3460
|
+
static {
|
|
3461
|
+
setComponentTemplate(precompileTemplate("<div class=\"lt-list-root\" {{this.setup}} {{on \"focusin\" this.onFocusIn}} {{on \"focusout\" this.onFocusOut}} {{on \"keydown\" this.onKeyDown}} {{on \"click\" this.onClick}}>\n <div class=\"lt-list\" role={{this.role}} aria-label={{@label}} aria-multiselectable={{if this.multiselect \"true\"}} aria-busy={{if this.busy \"true\"}} data-lt-layout={{this.layout}} ...attributes>\n <div class=\"lt-list-scroller\" {{VirtualScroll this.state}} {{this.startAtEnd}} {{this.sync this.ids this.estimate this.heldIndex this.lanes}} {{this.observeWidth this.isCards}}>\n <div class=\"lt-list-sizer\" style={{this.sizerStyle}}>\n {{#each this.views key=\"id\" as |view|}}\n <div class=\"lt-list-item\" role={{this.itemRole}} aria-posinset={{inc view.index}} aria-setsize={{this.ids.length}} aria-selected={{this.selectedFor view.id}} tabindex={{this.tabIndexFor view.id}} data-item-id={{view.id}} data-index={{view.index}} data-held={{if view.held \"\"}} data-lane={{view.lane}} style={{view.style}} {{this.measure view.id view.index}}>\n {{yield view.item view.index}}\n </div>\n {{/each}}\n </div>\n </div>\n </div>\n {{!-- The loading row is outside the role element: role=status is not an allowed child of a list. --}}\n {{#if this.loadingStart}}\n <div class=\"lt-list-loading\" role=\"status\" data-edge=\"start\">{{this.l.t \"list.loading\"}}</div>\n {{/if}}\n {{#if this.loadingEnd}}\n <div class=\"lt-list-loading\" role=\"status\" data-edge=\"end\">{{this.l.t \"list.loading\"}}</div>\n {{/if}}\n</div>", {
|
|
3462
|
+
strictMode: true,
|
|
3463
|
+
scope: () => ({
|
|
3464
|
+
on,
|
|
3465
|
+
VirtualScroll,
|
|
3466
|
+
inc
|
|
3467
|
+
})
|
|
3468
|
+
}), this);
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
|
|
3472
|
+
// LatticeBoard: the Board surface (docs/m3-list-board-contract.md, section 2). Each lane is a
|
|
3473
|
+
// LatticeList listbox. A move is an edit: the board calls @onMove and does not change @items.
|
|
3474
|
+
// While the move promise is in progress, the card shows its new place (an override).
|
|
3475
|
+
/** A press must move this far, in px, before it becomes a drag. */const DRAG_THRESHOLD = 4;
|
|
3476
|
+
/** The pointer scrolls a lane when it is this near (client px) to the top or the bottom edge. */
|
|
3477
|
+
const SCROLL_EDGE = 32;
|
|
3478
|
+
/** The most px that a lane scrolls in one frame. */
|
|
3479
|
+
const SCROLL_STEP = 12;
|
|
3480
|
+
const STEPS = {
|
|
3481
|
+
ArrowUp: -1,
|
|
3482
|
+
ArrowDown: 1
|
|
3483
|
+
};
|
|
3484
|
+
const SIDES = {
|
|
3485
|
+
ArrowLeft: -1,
|
|
3486
|
+
ArrowRight: 1
|
|
3487
|
+
};
|
|
3488
|
+
const px = n => `${Math.round(n * 100) / 100}px`;
|
|
3489
|
+
const sameLane = (a, b) => Object.is(a, b);
|
|
3490
|
+
/** The rendered options of a lane, in index order. */
|
|
3491
|
+
const optionsIn = (lane, skip) => [...lane.querySelectorAll('.lt-list-item')].filter(el => el.dataset['itemId'] !== skip).sort((a, b) => Number(a.dataset['index']) - Number(b.dataset['index']));
|
|
3492
|
+
class LatticeBoard extends Component {
|
|
3493
|
+
static {
|
|
3494
|
+
g(this.prototype, "overrides", [tracked], function () {
|
|
3495
|
+
return new Map();
|
|
3496
|
+
});
|
|
3497
|
+
}
|
|
3498
|
+
#overrides = (i(this, "overrides"), void 0);
|
|
3499
|
+
/** The cards out of their data place: picked up, or with a move in progress. */
|
|
3500
|
+
static {
|
|
3501
|
+
g(this.prototype, "held", [tracked], function () {
|
|
3502
|
+
return null;
|
|
3503
|
+
});
|
|
3504
|
+
}
|
|
3505
|
+
#held = (i(this, "held"), void 0);
|
|
3506
|
+
static {
|
|
3507
|
+
g(this.prototype, "drag", [tracked], function () {
|
|
3508
|
+
return null;
|
|
3509
|
+
});
|
|
3510
|
+
}
|
|
3511
|
+
#drag = (i(this, "drag"), void 0);
|
|
3512
|
+
static {
|
|
3513
|
+
g(this.prototype, "message", [tracked], function () {
|
|
3514
|
+
return '';
|
|
3515
|
+
});
|
|
3516
|
+
}
|
|
3517
|
+
#message = (i(this, "message"), void 0);
|
|
3518
|
+
_root = null;
|
|
3519
|
+
/** A card to focus when it renders, and while it is picked up. */
|
|
3520
|
+
_focusId = null;
|
|
3521
|
+
_suppressClick = false;
|
|
3522
|
+
_endDrag = null;
|
|
3523
|
+
constructor(owner, args) {
|
|
3524
|
+
super(owner, args);
|
|
3525
|
+
registerDestructor(this, () => this._endDrag?.());
|
|
3526
|
+
}
|
|
3527
|
+
get boardId() {
|
|
3528
|
+
return guidFor(this);
|
|
3529
|
+
}
|
|
3530
|
+
get itemById() {
|
|
3531
|
+
return new Map(this.args.items.map(item => [this.args.getItemId(item), item]));
|
|
3532
|
+
}
|
|
3533
|
+
/** The items of each lane, from the data only. */
|
|
3534
|
+
static {
|
|
3535
|
+
n(this.prototype, "itemById", [cached]);
|
|
3536
|
+
}
|
|
3537
|
+
get baseLanes() {
|
|
3538
|
+
const lanes = new Map(this.args.lanes.map(key => [key, []]));
|
|
3539
|
+
for (const item of this.args.items) lanes.get(this.args.laneOf(item))?.push(item);
|
|
3540
|
+
return lanes;
|
|
3541
|
+
}
|
|
3542
|
+
/** The items of each lane, with the overrides. A lane with no override keeps its array. */
|
|
3543
|
+
static {
|
|
3544
|
+
n(this.prototype, "baseLanes", [cached]);
|
|
3545
|
+
}
|
|
3546
|
+
get laneItems() {
|
|
3547
|
+
const lanes = new Map(this.baseLanes);
|
|
3548
|
+
for (const [id, {
|
|
3549
|
+
place
|
|
3550
|
+
}] of this.overrides) {
|
|
3551
|
+
const item = this.itemById.get(id);
|
|
3552
|
+
if (item === undefined || !lanes.has(place.lane)) continue;
|
|
3553
|
+
for (const [key, items] of lanes) {
|
|
3554
|
+
if (items.includes(item)) lanes.set(key, items.filter(i => i !== item));
|
|
3555
|
+
}
|
|
3556
|
+
const target = [...(lanes.get(place.lane) ?? [])];
|
|
3557
|
+
target.splice(Math.min(place.index, target.length), 0, item);
|
|
3558
|
+
lanes.set(place.lane, target);
|
|
3559
|
+
}
|
|
3560
|
+
return lanes;
|
|
3561
|
+
}
|
|
3562
|
+
static {
|
|
3563
|
+
n(this.prototype, "laneItems", [cached]);
|
|
3564
|
+
}
|
|
3565
|
+
get laneViews() {
|
|
3566
|
+
const lanes = this.laneItems;
|
|
3567
|
+
return this.args.lanes.map((key, i) => ({
|
|
3568
|
+
key,
|
|
3569
|
+
dataLane: String(key),
|
|
3570
|
+
label: this.args.laneLabel(key),
|
|
3571
|
+
titleId: `${this.boardId}-lane-${i}`,
|
|
3572
|
+
items: lanes.get(key) ?? []
|
|
3573
|
+
}));
|
|
3574
|
+
}
|
|
3575
|
+
static {
|
|
3576
|
+
n(this.prototype, "laneViews", [cached]);
|
|
3577
|
+
}
|
|
3578
|
+
idOf = item => this.args.getItemId(item);
|
|
3579
|
+
get headingLevel() {
|
|
3580
|
+
return this.args.headingLevel ?? 3;
|
|
3581
|
+
}
|
|
3582
|
+
get heldId() {
|
|
3583
|
+
return this.held?.id;
|
|
3584
|
+
}
|
|
3585
|
+
/** The style of the drop line in a lane, or undefined. It reads only the drag. */
|
|
3586
|
+
lineFor = lane => {
|
|
3587
|
+
const drag = this.drag;
|
|
3588
|
+
if (drag === null || drag.to === null || !sameLane(drag.to.lane, lane)) return undefined;
|
|
3589
|
+
return htmlSafe(`inset-block-start: ${px(drag.line)}`);
|
|
3590
|
+
};
|
|
3591
|
+
get previewStyle() {
|
|
3592
|
+
const drag = this.drag;
|
|
3593
|
+
if (drag === null) return htmlSafe('');
|
|
3594
|
+
return htmlSafe(`position: absolute; left: 0; top: 0; pointer-events: none; inline-size: ${px(drag.width)}; ` + `transform: translate(${px(drag.x)}, ${px(drag.y)})`);
|
|
3595
|
+
}
|
|
3596
|
+
// Places and announcements ------------------------------------------------------------------
|
|
3597
|
+
/** The locale text of this component (ADR 0024): `@localeText`, then the owner text. */
|
|
3598
|
+
get l() {
|
|
3599
|
+
return latticeLocale(getOwner(this), this.args.localeText);
|
|
3600
|
+
}
|
|
3601
|
+
static {
|
|
3602
|
+
n(this.prototype, "l", [cached]);
|
|
3603
|
+
}
|
|
3604
|
+
placeOf(id) {
|
|
3605
|
+
const item = this.itemById.get(id);
|
|
3606
|
+
if (item === undefined) return null;
|
|
3607
|
+
for (const [lane, items] of this.laneItems) {
|
|
3608
|
+
const index = items.indexOf(item);
|
|
3609
|
+
if (index >= 0) return {
|
|
3610
|
+
lane,
|
|
3611
|
+
index
|
|
3612
|
+
};
|
|
3613
|
+
}
|
|
3614
|
+
return null;
|
|
3615
|
+
}
|
|
3616
|
+
countIn(lane) {
|
|
3617
|
+
return this.laneItems.get(lane)?.length ?? 0;
|
|
3618
|
+
}
|
|
3619
|
+
/** The params of a place in a message: the lane label, the position and the card count. */
|
|
3620
|
+
where(place) {
|
|
3621
|
+
const lane = this.args.laneLabel(place.lane);
|
|
3622
|
+
return {
|
|
3623
|
+
lane,
|
|
3624
|
+
position: place.index + 1,
|
|
3625
|
+
total: this.countIn(place.lane)
|
|
3626
|
+
};
|
|
3627
|
+
}
|
|
3628
|
+
setOverride(id, place) {
|
|
3629
|
+
const next = new Map(this.overrides);
|
|
3630
|
+
const token = {};
|
|
3631
|
+
if (place === null) next.delete(id);else next.set(id, {
|
|
3632
|
+
place,
|
|
3633
|
+
token
|
|
3634
|
+
});
|
|
3635
|
+
this.overrides = next;
|
|
3636
|
+
return token;
|
|
3637
|
+
}
|
|
3638
|
+
/** Drop a card: call @onMove, and show the new place while its promise is in progress. */
|
|
3639
|
+
commit(card, to) {
|
|
3640
|
+
const token = this.setOverride(card.id, to);
|
|
3641
|
+
this.message = this.l.t('board.dropped', {
|
|
3642
|
+
card: card.name,
|
|
3643
|
+
...this.where(to)
|
|
3644
|
+
});
|
|
3645
|
+
if (sameLane(to.lane, card.from.lane) && to.index === card.from.index) {
|
|
3646
|
+
this.setOverride(card.id, null);
|
|
3647
|
+
return;
|
|
3648
|
+
}
|
|
3649
|
+
const settle = failed => {
|
|
3650
|
+
if (this.isDestroying || this.overrides.get(card.id)?.token !== token) return;
|
|
3651
|
+
this.setOverride(card.id, null);
|
|
3652
|
+
if (failed) {
|
|
3653
|
+
this.message = this.l.t('board.moveFailed', {
|
|
3654
|
+
card: card.name,
|
|
3655
|
+
lane: this.args.laneLabel(card.from.lane)
|
|
3656
|
+
});
|
|
3657
|
+
}
|
|
3658
|
+
};
|
|
3659
|
+
let result;
|
|
3660
|
+
try {
|
|
3661
|
+
result = this.args.onMove?.(card.item, to.lane, to.index, card.from.lane);
|
|
3662
|
+
} catch (error) {
|
|
3663
|
+
// A throw is a failure, as a reject is. The app still gets its error.
|
|
3664
|
+
settle(true);
|
|
3665
|
+
throw error;
|
|
3666
|
+
}
|
|
3667
|
+
// Not a test waiter: a test must see the card in its new place while the promise waits.
|
|
3668
|
+
if (is.promise(result)) result.then(() => settle(false), () => settle(true));else settle(false);
|
|
3669
|
+
}
|
|
3670
|
+
// Modifiers ---------------------------------------------------------------------------------
|
|
3671
|
+
setup = modifier(root => {
|
|
3672
|
+
this._root = root;
|
|
3673
|
+
const doc = root.ownerDocument;
|
|
3674
|
+
doc.addEventListener('pointerdown', this.onDocumentPointerDown, {
|
|
3675
|
+
capture: true
|
|
3676
|
+
});
|
|
3677
|
+
return () => {
|
|
3678
|
+
doc.removeEventListener('pointerdown', this.onDocumentPointerDown, {
|
|
3679
|
+
capture: true
|
|
3680
|
+
});
|
|
3681
|
+
this._root = null;
|
|
3682
|
+
};
|
|
3683
|
+
});
|
|
3684
|
+
/** On each card: mark the picked-up card, and give it the focus when it renders or moves. */ // The held ID and the index are arguments so that the modifier runs again when they change.
|
|
3685
|
+
card = modifier((el, [id, heldId]) => {
|
|
3686
|
+
const option = el.closest('.lt-list-item');
|
|
3687
|
+
if (option === null) return;
|
|
3688
|
+
option.toggleAttribute('data-picked-up', id === heldId);
|
|
3689
|
+
// When the picked-up card leaves the DOM, it can come back in another lane, or not at all.
|
|
3690
|
+
const teardown = id === heldId ? () => this.checkHeld() : undefined;
|
|
3691
|
+
if (id !== this._focusId) return teardown;
|
|
3692
|
+
if (heldId !== id) this._focusId = null;
|
|
3693
|
+
// After the render: a focus fires `focusin`, and the lane list writes tracked state there.
|
|
3694
|
+
queueMicrotask(() => {
|
|
3695
|
+
if (!option.isConnected) return;
|
|
3696
|
+
option.focus({
|
|
3697
|
+
preventScroll: true
|
|
3698
|
+
});
|
|
3699
|
+
option.scrollIntoView({
|
|
3700
|
+
block: 'nearest',
|
|
3701
|
+
inline: 'nearest'
|
|
3702
|
+
});
|
|
3703
|
+
});
|
|
3704
|
+
return teardown;
|
|
3705
|
+
});
|
|
3706
|
+
// Keyboard ----------------------------------------------------------------------------------
|
|
3707
|
+
/** The option of a board card that is the event target, or null. */
|
|
3708
|
+
cardOf(target) {
|
|
3709
|
+
if (!(target instanceof HTMLElement) || !target.classList.contains('lt-list-item')) return null;
|
|
3710
|
+
const lane = target.closest('.lt-board-lane');
|
|
3711
|
+
return lane !== null && lane.parentElement === this._root ? target : null;
|
|
3712
|
+
}
|
|
3713
|
+
laneElement(lane) {
|
|
3714
|
+
const index = this.args.lanes.indexOf(lane);
|
|
3715
|
+
return this._root?.querySelectorAll(':scope > .lt-board-lane')[index] ?? null;
|
|
3716
|
+
}
|
|
3717
|
+
// In the capture phase: the lane listbox must not see Space (select) or the arrows of a move.
|
|
3718
|
+
onKeyDown = event => {
|
|
3719
|
+
const option = this.cardOf(event.target);
|
|
3720
|
+
const id = option?.dataset['itemId'];
|
|
3721
|
+
if (option === null || id === undefined || this.drag !== null) return;
|
|
3722
|
+
const held = this.held;
|
|
3723
|
+
if (held === null) {
|
|
3724
|
+
if (event.key !== ' ') return;
|
|
3725
|
+
this.stop(event);
|
|
3726
|
+
this.pickUp(id, option);
|
|
3727
|
+
return;
|
|
3728
|
+
}
|
|
3729
|
+
if (held.id !== id) return;
|
|
3730
|
+
const step = STEPS[event.key];
|
|
3731
|
+
const side = SIDES[event.key];
|
|
3732
|
+
if (event.key === ' ' || event.key === 'Enter') {
|
|
3733
|
+
this.stop(event);
|
|
3734
|
+
this.held = null;
|
|
3735
|
+
this.commit(held, this.placeOf(id) ?? held.from);
|
|
3736
|
+
} else if (event.key === 'Escape') {
|
|
3737
|
+
this.stop(event);
|
|
3738
|
+
this.cancel(held);
|
|
3739
|
+
} else if (step !== undefined) {
|
|
3740
|
+
this.stop(event);
|
|
3741
|
+
this.moveInLane(held, step);
|
|
3742
|
+
} else if (side !== undefined) {
|
|
3743
|
+
this.stop(event);
|
|
3744
|
+
this.moveToLane(held, option, isRTL(option) ? -side : side);
|
|
3745
|
+
}
|
|
3746
|
+
};
|
|
3747
|
+
/** Put a picked-up card back in its old place. */
|
|
3748
|
+
cancel(held) {
|
|
3749
|
+
this.held = null;
|
|
3750
|
+
this.setOverride(held.id, null);
|
|
3751
|
+
this.message = this.itemById.has(held.id) ? this.l.t('board.moveCanceled', {
|
|
3752
|
+
card: held.name,
|
|
3753
|
+
...this.where(held.from)
|
|
3754
|
+
}) : this.l.t('board.moveCanceledRemoved', {
|
|
3755
|
+
card: held.name
|
|
3756
|
+
});
|
|
3757
|
+
}
|
|
3758
|
+
/** Cancel a keyboard move when the user goes out of the board: the card keeps no focus. */
|
|
3759
|
+
leave(target) {
|
|
3760
|
+
const held = this.held;
|
|
3761
|
+
const root = this._root;
|
|
3762
|
+
if (held === null || root === null || !(target instanceof Node) || root.contains(target)) return;
|
|
3763
|
+
this._focusId = null;
|
|
3764
|
+
this.cancel(held);
|
|
3765
|
+
}
|
|
3766
|
+
// The focus goes to an element out of the board (Tab). A focusout with no `relatedTarget`
|
|
3767
|
+
// also comes when the lane moves the card in the DOM, so it does not cancel.
|
|
3768
|
+
onFocusOut = event => this.leave(event.relatedTarget);
|
|
3769
|
+
// A press out of the board, also on content that cannot have the focus.
|
|
3770
|
+
onDocumentPointerDown = event => this.leave(event.target);
|
|
3771
|
+
/** After the render: cancel the keyboard move if the picked-up card is not rendered. */
|
|
3772
|
+
checkHeld() {
|
|
3773
|
+
const check = new Promise(resolve => setTimeout(() => {
|
|
3774
|
+
resolve();
|
|
3775
|
+
const held = this.held;
|
|
3776
|
+
const root = this._root;
|
|
3777
|
+
if (held === null || this.isDestroying || root === null) return;
|
|
3778
|
+
if (root.querySelector(`.lt-list-item[data-item-id="${CSS.escape(held.id)}"]`)) return;
|
|
3779
|
+
this._focusId = null;
|
|
3780
|
+
this.cancel(held);
|
|
3781
|
+
}));
|
|
3782
|
+
void waitForPromise(check);
|
|
3783
|
+
}
|
|
3784
|
+
stop(event) {
|
|
3785
|
+
event.preventDefault();
|
|
3786
|
+
event.stopPropagation();
|
|
3787
|
+
}
|
|
3788
|
+
pickUp(id, option) {
|
|
3789
|
+
const item = this.itemById.get(id);
|
|
3790
|
+
const from = this.placeOf(id);
|
|
3791
|
+
if (item === undefined || from === null) return;
|
|
3792
|
+
const name = this.nameOf(item, option);
|
|
3793
|
+
this.held = {
|
|
3794
|
+
id,
|
|
3795
|
+
item,
|
|
3796
|
+
name,
|
|
3797
|
+
from
|
|
3798
|
+
};
|
|
3799
|
+
this._focusId = id;
|
|
3800
|
+
this.message = this.l.t('board.pickedUp', {
|
|
3801
|
+
card: name
|
|
3802
|
+
});
|
|
3803
|
+
}
|
|
3804
|
+
moveInLane(held, step) {
|
|
3805
|
+
const place = this.placeOf(held.id);
|
|
3806
|
+
if (place === null) return;
|
|
3807
|
+
const index = Math.max(0, Math.min(place.index + step, this.countIn(place.lane) - 1));
|
|
3808
|
+
if (index !== place.index) this.moveTo(held, {
|
|
3809
|
+
lane: place.lane,
|
|
3810
|
+
index
|
|
3811
|
+
});
|
|
3812
|
+
}
|
|
3813
|
+
/** Move to the next or the previous lane, at the height of the card in the view. */
|
|
3814
|
+
moveToLane(held, option, side) {
|
|
3815
|
+
const place = this.placeOf(held.id);
|
|
3816
|
+
const lane = place === null ? undefined : this.args.lanes[this.args.lanes.indexOf(place.lane) + side];
|
|
3817
|
+
const laneEl = lane === undefined ? null : this.laneElement(lane);
|
|
3818
|
+
if (lane === undefined || laneEl === null) return;
|
|
3819
|
+
const top = option.getBoundingClientRect().top;
|
|
3820
|
+
const options = optionsIn(laneEl, held.id);
|
|
3821
|
+
const next = options.find(el => {
|
|
3822
|
+
const box = el.getBoundingClientRect();
|
|
3823
|
+
return box.top + box.height / 2 > top;
|
|
3824
|
+
});
|
|
3825
|
+
const last = options.at(-1);
|
|
3826
|
+
const index = next !== undefined ? Number(next.dataset['index']) : last !== undefined ? Number(last.dataset['index']) + 1 : 0;
|
|
3827
|
+
this.moveTo(held, {
|
|
3828
|
+
lane,
|
|
3829
|
+
index
|
|
3830
|
+
});
|
|
3831
|
+
}
|
|
3832
|
+
moveTo(held, place) {
|
|
3833
|
+
this.setOverride(held.id, place);
|
|
3834
|
+
this.message = this.l.t('board.moved', {
|
|
3835
|
+
card: held.name,
|
|
3836
|
+
...this.where(place)
|
|
3837
|
+
});
|
|
3838
|
+
}
|
|
3839
|
+
// Pointer -----------------------------------------------------------------------------------
|
|
3840
|
+
onPointerDown = event => {
|
|
3841
|
+
this._suppressClick = false;
|
|
3842
|
+
if (event.button !== 0 || this.held !== null || this._endDrag !== null) return;
|
|
3843
|
+
const option = event.target instanceof Element ? this.cardOf(event.target.closest('.lt-list-item')) : null;
|
|
3844
|
+
const id = option?.dataset['itemId'];
|
|
3845
|
+
const root = this._root;
|
|
3846
|
+
if (option === null || id === undefined || root === null) return;
|
|
3847
|
+
const doc = root.ownerDocument;
|
|
3848
|
+
const startX = event.clientX;
|
|
3849
|
+
const startY = event.clientY;
|
|
3850
|
+
let card = null;
|
|
3851
|
+
let grab = {
|
|
3852
|
+
x: 0,
|
|
3853
|
+
y: 0,
|
|
3854
|
+
width: 0
|
|
3855
|
+
};
|
|
3856
|
+
let last = {
|
|
3857
|
+
x: startX,
|
|
3858
|
+
y: startY
|
|
3859
|
+
};
|
|
3860
|
+
let frame = 0;
|
|
3861
|
+
const scrollLoop = () => {
|
|
3862
|
+
frame = 0;
|
|
3863
|
+
if (this.drag === null) return;
|
|
3864
|
+
const lane = this.drag.to === null ? null : this.laneElement(this.drag.to.lane);
|
|
3865
|
+
const scroller = lane?.querySelector('.lt-list-scroller');
|
|
3866
|
+
const box = scroller?.getBoundingClientRect();
|
|
3867
|
+
if (!scroller || box === undefined) return;
|
|
3868
|
+
const speed = last.y < box.top + SCROLL_EDGE ? -SCROLL_STEP * (1 - (last.y - box.top) / SCROLL_EDGE) : last.y > box.bottom - SCROLL_EDGE ? SCROLL_STEP * (1 - (box.bottom - last.y) / SCROLL_EDGE) : 0;
|
|
3869
|
+
if (speed === 0) return;
|
|
3870
|
+
scroller.scrollTop += speed;
|
|
3871
|
+
this.track(card, grab, last.x, last.y);
|
|
3872
|
+
frame = requestAnimationFrame(scrollLoop);
|
|
3873
|
+
};
|
|
3874
|
+
const move = e => {
|
|
3875
|
+
if (e.pointerId !== event.pointerId) return;
|
|
3876
|
+
last = {
|
|
3877
|
+
x: e.clientX,
|
|
3878
|
+
y: e.clientY
|
|
3879
|
+
};
|
|
3880
|
+
if (card === null) {
|
|
3881
|
+
if (Math.hypot(e.clientX - startX, e.clientY - startY) < DRAG_THRESHOLD) return;
|
|
3882
|
+
card = this.startDrag(id, option);
|
|
3883
|
+
if (card === null) return end(e);
|
|
3884
|
+
const box = option.getBoundingClientRect();
|
|
3885
|
+
const ratio = this.ratio();
|
|
3886
|
+
grab = {
|
|
3887
|
+
x: (startX - box.left) / ratio,
|
|
3888
|
+
y: (startY - box.top) / ratio,
|
|
3889
|
+
width: box.width / ratio
|
|
3890
|
+
};
|
|
3891
|
+
try {
|
|
3892
|
+
option.setPointerCapture(event.pointerId);
|
|
3893
|
+
} catch {
|
|
3894
|
+
// An event that a test makes has no pointer to capture.
|
|
3895
|
+
}
|
|
3896
|
+
}
|
|
3897
|
+
this.track(card, grab, e.clientX, e.clientY);
|
|
3898
|
+
if (frame === 0) frame = requestAnimationFrame(scrollLoop);
|
|
3899
|
+
};
|
|
3900
|
+
const end = e => {
|
|
3901
|
+
if (e !== null && e.pointerId !== event.pointerId) return;
|
|
3902
|
+
const drag = this.drag;
|
|
3903
|
+
cleanup();
|
|
3904
|
+
if (card === null) return;
|
|
3905
|
+
// The click after a drag must not select the card. The next press clears this.
|
|
3906
|
+
this._suppressClick = true;
|
|
3907
|
+
if (e?.type === 'pointerup' && drag !== null && drag.to !== null) this.commit(card, drag.to);
|
|
3908
|
+
};
|
|
3909
|
+
const onKey = e => {
|
|
3910
|
+
if (e.key !== 'Escape' || card === null) return;
|
|
3911
|
+
this.stop(e);
|
|
3912
|
+
this.message = this.l.t('board.moveCanceled', {
|
|
3913
|
+
card: card.name,
|
|
3914
|
+
...this.where(card.from)
|
|
3915
|
+
});
|
|
3916
|
+
card = null;
|
|
3917
|
+
cleanup();
|
|
3918
|
+
};
|
|
3919
|
+
const onUp = e => end(e);
|
|
3920
|
+
const cleanup = () => {
|
|
3921
|
+
doc.removeEventListener('pointermove', move);
|
|
3922
|
+
doc.removeEventListener('pointerup', onUp);
|
|
3923
|
+
doc.removeEventListener('pointercancel', onUp);
|
|
3924
|
+
doc.removeEventListener('keydown', onKey, {
|
|
3925
|
+
capture: true
|
|
3926
|
+
});
|
|
3927
|
+
if (frame !== 0) cancelAnimationFrame(frame);
|
|
3928
|
+
frame = 0;
|
|
3929
|
+
try {
|
|
3930
|
+
if (option.hasPointerCapture(event.pointerId)) option.releasePointerCapture(event.pointerId);
|
|
3931
|
+
} catch {
|
|
3932
|
+
// As above.
|
|
3933
|
+
}
|
|
3934
|
+
this._endDrag = null;
|
|
3935
|
+
if (!this.isDestroying && this.drag !== null) this.drag = null;
|
|
3936
|
+
};
|
|
3937
|
+
doc.addEventListener('pointermove', move);
|
|
3938
|
+
doc.addEventListener('pointerup', onUp);
|
|
3939
|
+
doc.addEventListener('pointercancel', onUp);
|
|
3940
|
+
doc.addEventListener('keydown', onKey, {
|
|
3941
|
+
capture: true
|
|
3942
|
+
});
|
|
3943
|
+
this._endDrag = cleanup;
|
|
3944
|
+
};
|
|
3945
|
+
startDrag(id, option) {
|
|
3946
|
+
const item = this.itemById.get(id);
|
|
3947
|
+
const from = this.placeOf(id);
|
|
3948
|
+
if (item === undefined || from === null) return null;
|
|
3949
|
+
return {
|
|
3950
|
+
id,
|
|
3951
|
+
item,
|
|
3952
|
+
name: this.nameOf(item, option),
|
|
3953
|
+
from
|
|
3954
|
+
};
|
|
3955
|
+
}
|
|
3956
|
+
nameOf(item, option) {
|
|
3957
|
+
return this.args.cardLabel?.(item) ?? option.textContent?.trim() ?? '';
|
|
3958
|
+
}
|
|
3959
|
+
/** Client px to board px: a transform on the page (the test container scale) changes it. */
|
|
3960
|
+
ratio() {
|
|
3961
|
+
const root = this._root;
|
|
3962
|
+
if (root === null || root.offsetWidth === 0) return 1;
|
|
3963
|
+
return root.getBoundingClientRect().width / root.offsetWidth || 1;
|
|
3964
|
+
}
|
|
3965
|
+
/** Update the preview and the drop place for a pointer at (x, y), in client px. */
|
|
3966
|
+
track(card, grab, x, y) {
|
|
3967
|
+
const root = this._root;
|
|
3968
|
+
if (card === null || root === null) return;
|
|
3969
|
+
const ratio = this.ratio();
|
|
3970
|
+
const board = root.getBoundingClientRect();
|
|
3971
|
+
let to = null;
|
|
3972
|
+
let line = 0;
|
|
3973
|
+
const laneEls = root.querySelectorAll(':scope > .lt-board-lane');
|
|
3974
|
+
for (const [i, lane] of this.args.lanes.entries()) {
|
|
3975
|
+
const laneEl = laneEls[i];
|
|
3976
|
+
const box = laneEl?.getBoundingClientRect();
|
|
3977
|
+
if (laneEl === undefined || box === undefined || x < box.left || x >= box.right) continue;
|
|
3978
|
+
const scroller = laneEl.querySelector('.lt-list-scroller');
|
|
3979
|
+
const view = scroller?.getBoundingClientRect() ?? box;
|
|
3980
|
+
const options = optionsIn(laneEl, card.id);
|
|
3981
|
+
const next = options.find(el => {
|
|
3982
|
+
const r = el.getBoundingClientRect();
|
|
3983
|
+
return r.top + r.height / 2 > y;
|
|
3984
|
+
});
|
|
3985
|
+
const prev = options.at(-1);
|
|
3986
|
+
let index = 0;
|
|
3987
|
+
let at = view.top;
|
|
3988
|
+
if (next !== undefined) {
|
|
3989
|
+
index = Number(next.dataset['index']);
|
|
3990
|
+
at = next.getBoundingClientRect().top;
|
|
3991
|
+
} else if (prev !== undefined) {
|
|
3992
|
+
index = Number(prev.dataset['index']) + 1;
|
|
3993
|
+
at = prev.getBoundingClientRect().bottom;
|
|
3994
|
+
}
|
|
3995
|
+
// The index after the card leaves its own lane.
|
|
3996
|
+
if (sameLane(lane, card.from.lane) && card.from.index < index) index -= 1;
|
|
3997
|
+
to = {
|
|
3998
|
+
lane,
|
|
3999
|
+
index
|
|
4000
|
+
};
|
|
4001
|
+
line = (Math.max(view.top, Math.min(at, view.bottom)) - box.top) / ratio;
|
|
4002
|
+
}
|
|
4003
|
+
this.drag = {
|
|
4004
|
+
...card,
|
|
4005
|
+
to,
|
|
4006
|
+
line,
|
|
4007
|
+
x: (x - board.left) / ratio - grab.x,
|
|
4008
|
+
y: (y - board.top) / ratio - grab.y,
|
|
4009
|
+
width: grab.width
|
|
4010
|
+
};
|
|
4011
|
+
}
|
|
4012
|
+
// In the capture phase: the click after a drag must not reach the lane listbox.
|
|
4013
|
+
onClick = event => {
|
|
4014
|
+
if (!this._suppressClick) return;
|
|
4015
|
+
this._suppressClick = false;
|
|
4016
|
+
this.stop(event);
|
|
4017
|
+
};
|
|
4018
|
+
static {
|
|
4019
|
+
setComponentTemplate(precompileTemplate("<div class=\"lt-board\" role=\"region\" aria-label={{@label}} {{this.setup}} {{on \"keydown\" this.onKeyDown capture=true}} {{on \"click\" this.onClick capture=true}} {{on \"pointerdown\" this.onPointerDown}} {{on \"focusout\" this.onFocusOut}} ...attributes>\n {{#each this.laneViews key=\"dataLane\" as |lane|}}\n <div class=\"lt-board-lane\" role=\"group\" aria-labelledby={{lane.titleId}} data-lane={{lane.dataLane}}>\n {{!-- Glimmer has no dynamic tag, so the title is a heading by role at any level. --}}\n <div class=\"lt-board-lane-title\" id={{lane.titleId}} role=\"heading\" aria-level={{this.headingLevel}}>\n {{lane.label}}\n <span class=\"lt-board-lane-count\">{{lane.items.length}}</span>\n </div>\n <LatticeList @items={{lane.items}} @label={{lane.label}} @role=\"listbox\" @getItemId={{@getItemId}} @estimateSize={{@estimateSize}} @localeText={{@localeText}} as |item index|>\n {{!-- A touch pan on a card starts a drag: the browser does not scroll. --}}\n <div class=\"lt-board-card\" style=\"touch-action: none\" {{this.card (this.idOf item) this.heldId index}}>\n {{yield item}}\n </div>\n </LatticeList>\n {{#let (this.lineFor lane.key) as |line|}}\n {{#if line}}\n <div class=\"lt-board-drop-line\" style={{line}}></div>\n {{/if}}\n {{/let}}\n </div>\n {{/each}}\n <div class=\"lt-board-live\" aria-live=\"assertive\" {{visuallyHidden}}>{{this.message}}</div>\n {{#if this.drag}}\n <div class=\"lt-board-drag-preview\" aria-hidden=\"true\" style={{this.previewStyle}}>\n {{yield this.drag.item}}\n </div>\n {{/if}}\n</div>", {
|
|
4020
|
+
strictMode: true,
|
|
4021
|
+
scope: () => ({
|
|
4022
|
+
on,
|
|
4023
|
+
LatticeList,
|
|
4024
|
+
visuallyHidden
|
|
4025
|
+
})
|
|
4026
|
+
}), this);
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
|
|
4030
|
+
export { CellState, CellStateStore, GridAlignment, GridStateHandle, LatticeBoard, LatticeGrid, LatticeList, autoColumns, rowNumberColumn, selectionColumn };
|
|
4031
|
+
//# sourceMappingURL=index.js.map
|