@tailng-ui/primitives 0.14.0 → 0.15.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/package.json +3 -2
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/lib/form/datepicker/__tests__/tng-datepicker.test-helpers.d.ts +25 -0
- package/src/lib/form/datepicker/__tests__/tng-datepicker.test-helpers.d.ts.map +1 -0
- package/src/lib/form/datepicker/__tests__/tng-datepicker.test-helpers.js +105 -0
- package/src/lib/form/datepicker/__tests__/tng-datepicker.test-helpers.js.map +1 -0
- package/src/lib/form/datepicker/datepicker.adapters.d.ts +5 -0
- package/src/lib/form/datepicker/datepicker.adapters.d.ts.map +1 -0
- package/src/lib/form/datepicker/datepicker.adapters.js +194 -0
- package/src/lib/form/datepicker/datepicker.adapters.js.map +1 -0
- package/src/lib/form/datepicker/datepicker.state.d.ts +10 -0
- package/src/lib/form/datepicker/datepicker.state.d.ts.map +1 -0
- package/src/lib/form/datepicker/datepicker.state.js +97 -0
- package/src/lib/form/datepicker/datepicker.state.js.map +1 -0
- package/src/lib/form/datepicker/datepicker.types.d.ts +269 -0
- package/src/lib/form/datepicker/datepicker.types.d.ts.map +1 -0
- package/src/lib/form/datepicker/datepicker.types.js +1 -0
- package/src/lib/form/datepicker/datepicker.types.js.map +1 -0
- package/src/lib/form/datepicker/datepicker.utils.d.ts +75 -0
- package/src/lib/form/datepicker/datepicker.utils.d.ts.map +1 -0
- package/src/lib/form/datepicker/datepicker.utils.js +238 -0
- package/src/lib/form/datepicker/datepicker.utils.js.map +1 -0
- package/src/lib/form/datepicker/index.d.ts +3 -0
- package/src/lib/form/datepicker/index.d.ts.map +1 -0
- package/src/lib/form/datepicker/index.js +3 -0
- package/src/lib/form/datepicker/index.js.map +1 -0
- package/src/lib/form/datepicker/tng-datepicker.d.ts +5 -0
- package/src/lib/form/datepicker/tng-datepicker.d.ts.map +1 -0
- package/src/lib/form/datepicker/tng-datepicker.js +1948 -0
- package/src/lib/form/datepicker/tng-datepicker.js.map +1 -0
- package/src/lib/form/datepicker/tng-datepicker.overlay.d.ts +60 -0
- package/src/lib/form/datepicker/tng-datepicker.overlay.d.ts.map +1 -0
- package/src/lib/form/datepicker/tng-datepicker.overlay.js +275 -0
- package/src/lib/form/datepicker/tng-datepicker.overlay.js.map +1 -0
- package/src/lib/layout/grid/__tests__/tng-grid.test-harness.d.ts +32 -0
- package/src/lib/layout/grid/__tests__/tng-grid.test-harness.d.ts.map +1 -0
- package/src/lib/layout/grid/__tests__/tng-grid.test-harness.js +312 -0
- package/src/lib/layout/grid/__tests__/tng-grid.test-harness.js.map +1 -0
- package/src/lib/layout/grid/tng-grid.d.ts +144 -2
- package/src/lib/layout/grid/tng-grid.d.ts.map +1 -1
- package/src/lib/layout/grid/tng-grid.js +669 -2
- package/src/lib/layout/grid/tng-grid.js.map +1 -1
- package/src/lib/layout/tree/__tests__/tng-tree.test-harness.d.ts.map +1 -1
- package/src/lib/layout/tree/__tests__/tng-tree.test-harness.js +0 -1
- package/src/lib/layout/tree/__tests__/tng-tree.test-harness.js.map +1 -1
- package/src/lib/navigation/tabs/tng-tabs.d.ts +13 -6
- package/src/lib/navigation/tabs/tng-tabs.d.ts.map +1 -1
- package/src/lib/navigation/tabs/tng-tabs.js +77 -35
- package/src/lib/navigation/tabs/tng-tabs.js.map +1 -1
|
@@ -1,9 +1,436 @@
|
|
|
1
|
-
import { Directive, HostBinding } from '@angular/core';
|
|
1
|
+
import { Directive, ElementRef, HostBinding, HostListener, Input, booleanAttribute, inject, input, output, } from '@angular/core';
|
|
2
|
+
import { resolveGridNavigationKeyAction, resolveNavigableGridCell, } from '@tailng-ui/cdk';
|
|
2
3
|
import * as i0 from "@angular/core";
|
|
4
|
+
function coerceFiniteNumber(value) {
|
|
5
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
if (typeof value === 'string' && value.trim().length > 0) {
|
|
9
|
+
const parsed = Number(value);
|
|
10
|
+
if (Number.isFinite(parsed)) {
|
|
11
|
+
return parsed;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
function normalizeIndex(value) {
|
|
17
|
+
return Math.max(0, Math.trunc(coerceFiniteNumber(value) ?? 0));
|
|
18
|
+
}
|
|
19
|
+
function normalizeOptionalIndex(value) {
|
|
20
|
+
if (value === undefined) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
if (value === null || value === '') {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const numberValue = coerceFiniteNumber(value);
|
|
27
|
+
if (numberValue === null) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return Math.max(0, Math.trunc(numberValue));
|
|
31
|
+
}
|
|
32
|
+
function normalizeCount(value) {
|
|
33
|
+
if (value === undefined || value === null || value === '') {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const numberValue = coerceFiniteNumber(value);
|
|
37
|
+
if (numberValue === null) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return Math.max(1, Math.trunc(numberValue));
|
|
41
|
+
}
|
|
42
|
+
function normalizeSpan(value) {
|
|
43
|
+
return Math.max(1, Math.trunc(coerceFiniteNumber(value) ?? 1));
|
|
44
|
+
}
|
|
45
|
+
function normalizeDirection(value) {
|
|
46
|
+
return value === 'rtl' ? 'rtl' : 'ltr';
|
|
47
|
+
}
|
|
48
|
+
function normalizeSelectionMode(value) {
|
|
49
|
+
return value === 'single' ? 'single' : 'none';
|
|
50
|
+
}
|
|
51
|
+
function normalizeCellRole(value) {
|
|
52
|
+
if (value === 'rowheader' || value === 'columnheader') {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
return 'gridcell';
|
|
56
|
+
}
|
|
57
|
+
function normalizeGridValueInput(value) {
|
|
58
|
+
if (value === undefined) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
if (value === null) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (typeof value === 'object' && value !== null && 'row' in value && 'col' in value) {
|
|
65
|
+
const row = normalizeOptionalIndex(value.row);
|
|
66
|
+
const col = normalizeOptionalIndex(value.col);
|
|
67
|
+
if (row === undefined || row === null || col === undefined || col === null) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return Object.freeze({ col, row });
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
function createCellKey(value) {
|
|
75
|
+
return `${value.row}:${value.col}`;
|
|
76
|
+
}
|
|
77
|
+
function compareCellValues(a, b) {
|
|
78
|
+
if (a.row !== b.row) {
|
|
79
|
+
return a.row - b.row;
|
|
80
|
+
}
|
|
81
|
+
return a.col - b.col;
|
|
82
|
+
}
|
|
83
|
+
function positionsEqual(a, b) {
|
|
84
|
+
if (a === null || b === null) {
|
|
85
|
+
return a === b;
|
|
86
|
+
}
|
|
87
|
+
return a.row === b.row && a.col === b.col;
|
|
88
|
+
}
|
|
89
|
+
function focusChangeEvent(current, previous, trigger) {
|
|
90
|
+
return Object.freeze({
|
|
91
|
+
col: current.col,
|
|
92
|
+
previousCol: previous?.col ?? null,
|
|
93
|
+
previousRow: previous?.row ?? null,
|
|
94
|
+
row: current.row,
|
|
95
|
+
trigger,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
3
98
|
export class TngGrid {
|
|
99
|
+
hostRef = inject(ElementRef);
|
|
100
|
+
cells = new Set();
|
|
101
|
+
cellByKey = new Map();
|
|
102
|
+
uncontrolledFocus = null;
|
|
103
|
+
uncontrolledSelection = null;
|
|
104
|
+
selectionInitialized = false;
|
|
105
|
+
ariaLabelValue = null;
|
|
106
|
+
ariaColcountValue = null;
|
|
107
|
+
ariaRowcountValue = null;
|
|
108
|
+
domFocusedKey = null;
|
|
109
|
+
focusVisibleKey = null;
|
|
110
|
+
lastActivatedKey = null;
|
|
111
|
+
pendingFocusTrigger = null;
|
|
112
|
+
dir = input('ltr', { ...(ngDevMode ? { debugName: "dir" } : {}), transform: normalizeDirection });
|
|
113
|
+
focusCol = input(undefined, { ...(ngDevMode ? { debugName: "focusCol" } : {}), transform: normalizeOptionalIndex });
|
|
114
|
+
focusRow = input(undefined, { ...(ngDevMode ? { debugName: "focusRow" } : {}), transform: normalizeOptionalIndex });
|
|
115
|
+
selectionMode = input('none', { ...(ngDevMode ? { debugName: "selectionMode" } : {}), transform: normalizeSelectionMode });
|
|
116
|
+
value = input(undefined, { ...(ngDevMode ? { debugName: "value" } : {}), transform: normalizeGridValueInput });
|
|
117
|
+
defaultValue = input(undefined, { ...(ngDevMode ? { debugName: "defaultValue" } : {}), transform: normalizeGridValueInput });
|
|
118
|
+
wrap = input(false, { ...(ngDevMode ? { debugName: "wrap" } : {}), transform: booleanAttribute });
|
|
119
|
+
focusRowChange = output();
|
|
120
|
+
focusColChange = output();
|
|
121
|
+
focusChange = output();
|
|
122
|
+
valueChange = output();
|
|
123
|
+
cellActivate = output();
|
|
124
|
+
set ariaLabel(value) {
|
|
125
|
+
this.ariaLabelValue = value;
|
|
126
|
+
}
|
|
127
|
+
set ariaColcount(value) {
|
|
128
|
+
this.ariaColcountValue = normalizeCount(value);
|
|
129
|
+
}
|
|
130
|
+
set ariaRowcount(value) {
|
|
131
|
+
this.ariaRowcountValue = normalizeCount(value);
|
|
132
|
+
}
|
|
4
133
|
dataSlot = 'grid';
|
|
134
|
+
role = 'grid';
|
|
135
|
+
get ariaLabelAttr() {
|
|
136
|
+
return this.ariaLabelValue;
|
|
137
|
+
}
|
|
138
|
+
get ariaColcountAttr() {
|
|
139
|
+
const explicitCount = this.ariaColcountValue;
|
|
140
|
+
if (explicitCount !== null) {
|
|
141
|
+
return String(explicitCount);
|
|
142
|
+
}
|
|
143
|
+
const computedCount = this.getComputedBounds().colCount;
|
|
144
|
+
return this.cells.size > 0 ? String(computedCount) : null;
|
|
145
|
+
}
|
|
146
|
+
get ariaRowcountAttr() {
|
|
147
|
+
const explicitCount = this.ariaRowcountValue;
|
|
148
|
+
if (explicitCount !== null) {
|
|
149
|
+
return String(explicitCount);
|
|
150
|
+
}
|
|
151
|
+
const computedCount = this.getComputedBounds().rowCount;
|
|
152
|
+
return this.cells.size > 0 ? String(computedCount) : null;
|
|
153
|
+
}
|
|
154
|
+
ngOnDestroy() {
|
|
155
|
+
this.cells.clear();
|
|
156
|
+
this.cellByKey.clear();
|
|
157
|
+
}
|
|
158
|
+
registerCell(cell) {
|
|
159
|
+
this.cells.add(cell);
|
|
160
|
+
this.cellByKey.set(cell.cellKey(), cell);
|
|
161
|
+
this.ensureUncontrolledSelectionInitialized();
|
|
162
|
+
this.ensureFallbackFocus();
|
|
163
|
+
}
|
|
164
|
+
unregisterCell(cell) {
|
|
165
|
+
this.cells.delete(cell);
|
|
166
|
+
this.cellByKey.delete(cell.cellKey());
|
|
167
|
+
if (this.lastActivatedKey === cell.cellKey()) {
|
|
168
|
+
this.lastActivatedKey = null;
|
|
169
|
+
}
|
|
170
|
+
if (this.focusVisibleKey === cell.cellKey()) {
|
|
171
|
+
this.focusVisibleKey = null;
|
|
172
|
+
}
|
|
173
|
+
if (this.domFocusedKey === cell.cellKey()) {
|
|
174
|
+
this.domFocusedKey = null;
|
|
175
|
+
}
|
|
176
|
+
if (!this.isFocusControlled()
|
|
177
|
+
&& this.uncontrolledFocus !== null
|
|
178
|
+
&& createCellKey(this.uncontrolledFocus) === cell.cellKey()) {
|
|
179
|
+
this.uncontrolledFocus = null;
|
|
180
|
+
}
|
|
181
|
+
if (!this.isSelectionControlled()
|
|
182
|
+
&& this.uncontrolledSelection !== null
|
|
183
|
+
&& createCellKey(this.uncontrolledSelection) === cell.cellKey()) {
|
|
184
|
+
this.uncontrolledSelection = null;
|
|
185
|
+
}
|
|
186
|
+
this.ensureFallbackFocus();
|
|
187
|
+
}
|
|
188
|
+
isCellActivated(cell) {
|
|
189
|
+
return this.lastActivatedKey === cell.cellKey();
|
|
190
|
+
}
|
|
191
|
+
isCellDisabled(cell) {
|
|
192
|
+
return cell.disabled();
|
|
193
|
+
}
|
|
194
|
+
isCellFocusVisible(cell) {
|
|
195
|
+
return this.focusVisibleKey === cell.cellKey();
|
|
196
|
+
}
|
|
197
|
+
isCellFocused(cell) {
|
|
198
|
+
return this.domFocusedKey === cell.cellKey();
|
|
199
|
+
}
|
|
200
|
+
isCellTabStop(cell) {
|
|
201
|
+
const active = this.getActiveCell();
|
|
202
|
+
return active !== null && active.cellKey() === cell.cellKey();
|
|
203
|
+
}
|
|
204
|
+
isCellSelected(cell) {
|
|
205
|
+
const explicitSelected = cell.selected();
|
|
206
|
+
if (explicitSelected !== null) {
|
|
207
|
+
return explicitSelected;
|
|
208
|
+
}
|
|
209
|
+
const selectedValue = this.getSelectedValue();
|
|
210
|
+
return selectedValue !== null && cell.matchesValue(selectedValue);
|
|
211
|
+
}
|
|
212
|
+
getCellTabIndex(cell) {
|
|
213
|
+
if (this.isCellDisabled(cell)) {
|
|
214
|
+
return '-1';
|
|
215
|
+
}
|
|
216
|
+
return this.isCellTabStop(cell) ? '0' : '-1';
|
|
217
|
+
}
|
|
218
|
+
onCellClicked(cell) {
|
|
219
|
+
if (this.isCellDisabled(cell)) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (this.selectionMode() === 'single') {
|
|
223
|
+
this.requestSelection(cell.getValue());
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
onCellFocused(cell) {
|
|
227
|
+
if (this.isCellDisabled(cell)) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
const trigger = this.pendingFocusTrigger ?? 'programmatic';
|
|
231
|
+
this.pendingFocusTrigger = null;
|
|
232
|
+
this.domFocusedKey = cell.cellKey();
|
|
233
|
+
this.requestFocus(cell.getValue(), trigger);
|
|
234
|
+
this.focusVisibleKey = trigger === 'keyboard' || cell.isFocusVisible()
|
|
235
|
+
? cell.cellKey()
|
|
236
|
+
: null;
|
|
237
|
+
}
|
|
238
|
+
onCellPointerDown(cell) {
|
|
239
|
+
if (this.isCellDisabled(cell)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
this.pendingFocusTrigger = 'pointer';
|
|
243
|
+
this.focusVisibleKey = null;
|
|
244
|
+
}
|
|
245
|
+
onCellSelectionRequest(cell, trigger) {
|
|
246
|
+
if (this.isCellDisabled(cell)) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
this.lastActivatedKey = cell.cellKey();
|
|
250
|
+
if (this.selectionMode() === 'single') {
|
|
251
|
+
this.requestSelection(cell.getValue());
|
|
252
|
+
}
|
|
253
|
+
this.cellActivate.emit(Object.freeze({
|
|
254
|
+
col: cell.colIndex(),
|
|
255
|
+
row: cell.rowIndex(),
|
|
256
|
+
trigger,
|
|
257
|
+
}));
|
|
258
|
+
}
|
|
259
|
+
onFocusOut(event) {
|
|
260
|
+
const nextTarget = event.relatedTarget;
|
|
261
|
+
if (nextTarget instanceof Node && this.hostRef.nativeElement.contains(nextTarget)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
this.domFocusedKey = null;
|
|
265
|
+
this.focusVisibleKey = null;
|
|
266
|
+
this.pendingFocusTrigger = null;
|
|
267
|
+
}
|
|
268
|
+
onKeyDown(event) {
|
|
269
|
+
const activeCell = this.getActiveCell();
|
|
270
|
+
if (activeCell === null || this.isCellDisabled(activeCell)) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const action = resolveGridNavigationKeyAction(event, {
|
|
274
|
+
direction: this.dir(),
|
|
275
|
+
});
|
|
276
|
+
if (action === null) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (action.preventDefault) {
|
|
280
|
+
event.preventDefault();
|
|
281
|
+
}
|
|
282
|
+
if (action.type === 'exit') {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (action.type === 'activate') {
|
|
286
|
+
this.onCellSelectionRequest(activeCell, 'keyboard');
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
this.moveFocus(activeCell, action.type);
|
|
290
|
+
}
|
|
291
|
+
ensureFallbackFocus() {
|
|
292
|
+
if (this.isFocusControlled()) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const currentFocus = this.uncontrolledFocus;
|
|
296
|
+
if (currentFocus !== null) {
|
|
297
|
+
const currentCell = this.cellByKey.get(createCellKey(currentFocus));
|
|
298
|
+
if (currentCell !== undefined && !this.isCellDisabled(currentCell)) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
const fallback = this.getFirstEnabledCell();
|
|
303
|
+
this.uncontrolledFocus = fallback?.getValue() ?? null;
|
|
304
|
+
}
|
|
305
|
+
ensureUncontrolledSelectionInitialized() {
|
|
306
|
+
if (this.selectionInitialized || this.isSelectionControlled()) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
this.selectionInitialized = true;
|
|
310
|
+
this.uncontrolledSelection = this.defaultValue() ?? null;
|
|
311
|
+
}
|
|
312
|
+
getActiveCell() {
|
|
313
|
+
const focusValue = this.getFocusValue();
|
|
314
|
+
if (focusValue === null) {
|
|
315
|
+
return this.getFirstEnabledCell();
|
|
316
|
+
}
|
|
317
|
+
return this.cellByKey.get(createCellKey(focusValue)) ?? this.getFirstEnabledCell();
|
|
318
|
+
}
|
|
319
|
+
getComputedBounds() {
|
|
320
|
+
const explicitColcount = this.ariaColcountValue;
|
|
321
|
+
const explicitRowcount = this.ariaRowcountValue;
|
|
322
|
+
if (explicitColcount !== null && explicitRowcount !== null) {
|
|
323
|
+
return Object.freeze({
|
|
324
|
+
colCount: explicitColcount,
|
|
325
|
+
rowCount: explicitRowcount,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
let maxCol = 0;
|
|
329
|
+
let maxRow = 0;
|
|
330
|
+
for (const cell of this.cells) {
|
|
331
|
+
maxCol = Math.max(maxCol, cell.colIndex());
|
|
332
|
+
maxRow = Math.max(maxRow, cell.rowIndex());
|
|
333
|
+
}
|
|
334
|
+
return Object.freeze({
|
|
335
|
+
colCount: explicitColcount ?? maxCol + 1,
|
|
336
|
+
rowCount: explicitRowcount ?? maxRow + 1,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
getFirstEnabledCell() {
|
|
340
|
+
const enabledCells = this.getEnabledCells();
|
|
341
|
+
return enabledCells[0] ?? null;
|
|
342
|
+
}
|
|
343
|
+
getEnabledCells() {
|
|
344
|
+
return [...this.cells]
|
|
345
|
+
.filter((cell) => !this.isCellDisabled(cell))
|
|
346
|
+
.sort((a, b) => compareCellValues(a.getValue(), b.getValue()));
|
|
347
|
+
}
|
|
348
|
+
getFocusValue() {
|
|
349
|
+
if (this.isFocusControlled()) {
|
|
350
|
+
const row = this.focusRow();
|
|
351
|
+
const col = this.focusCol();
|
|
352
|
+
if (row === null || col === null || row === undefined || col === undefined) {
|
|
353
|
+
return this.getFirstEnabledCell()?.getValue() ?? null;
|
|
354
|
+
}
|
|
355
|
+
const controlled = Object.freeze({ col, row });
|
|
356
|
+
const controlledCell = this.cellByKey.get(createCellKey(controlled));
|
|
357
|
+
if (controlledCell !== undefined && !this.isCellDisabled(controlledCell)) {
|
|
358
|
+
return controlled;
|
|
359
|
+
}
|
|
360
|
+
return this.getFirstEnabledCell()?.getValue() ?? null;
|
|
361
|
+
}
|
|
362
|
+
if (this.uncontrolledFocus !== null) {
|
|
363
|
+
const activeCell = this.cellByKey.get(createCellKey(this.uncontrolledFocus));
|
|
364
|
+
if (activeCell !== undefined && !this.isCellDisabled(activeCell)) {
|
|
365
|
+
return this.uncontrolledFocus;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return this.getFirstEnabledCell()?.getValue() ?? null;
|
|
369
|
+
}
|
|
370
|
+
getNavigableCells() {
|
|
371
|
+
return [...this.cells].map((cell) => ({
|
|
372
|
+
col: cell.colIndex(),
|
|
373
|
+
disabled: this.isCellDisabled(cell),
|
|
374
|
+
row: cell.rowIndex(),
|
|
375
|
+
}));
|
|
376
|
+
}
|
|
377
|
+
getSelectedValue() {
|
|
378
|
+
if (this.selectionMode() === 'none') {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
if (this.isSelectionControlled()) {
|
|
382
|
+
return this.value() ?? null;
|
|
383
|
+
}
|
|
384
|
+
return this.uncontrolledSelection;
|
|
385
|
+
}
|
|
386
|
+
isFocusControlled() {
|
|
387
|
+
return this.focusRow() !== undefined && this.focusCol() !== undefined;
|
|
388
|
+
}
|
|
389
|
+
isSelectionControlled() {
|
|
390
|
+
return this.value() !== undefined;
|
|
391
|
+
}
|
|
392
|
+
moveFocus(activeCell, actionType) {
|
|
393
|
+
const nextValue = resolveNavigableGridCell(activeCell.getValue(), actionType, {
|
|
394
|
+
bounds: this.getComputedBounds(),
|
|
395
|
+
cells: this.getNavigableCells(),
|
|
396
|
+
wrap: this.wrap(),
|
|
397
|
+
});
|
|
398
|
+
if (nextValue === null) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const nextCell = this.cellByKey.get(createCellKey(nextValue));
|
|
402
|
+
if (nextCell === undefined || this.isCellDisabled(nextCell)) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
this.pendingFocusTrigger = 'keyboard';
|
|
406
|
+
this.requestFocus(nextValue, 'keyboard');
|
|
407
|
+
this.focusVisibleKey = nextCell.cellKey();
|
|
408
|
+
nextCell.focusHost();
|
|
409
|
+
}
|
|
410
|
+
requestFocus(value, trigger) {
|
|
411
|
+
const previous = this.getFocusValue();
|
|
412
|
+
if (positionsEqual(previous, value)) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
if (!this.isFocusControlled()) {
|
|
416
|
+
this.uncontrolledFocus = value;
|
|
417
|
+
}
|
|
418
|
+
this.focusRowChange.emit(value.row);
|
|
419
|
+
this.focusColChange.emit(value.col);
|
|
420
|
+
this.focusChange.emit(focusChangeEvent(value, previous, trigger));
|
|
421
|
+
}
|
|
422
|
+
requestSelection(value) {
|
|
423
|
+
const previous = this.getSelectedValue();
|
|
424
|
+
if (positionsEqual(previous, value)) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
if (!this.isSelectionControlled()) {
|
|
428
|
+
this.uncontrolledSelection = value;
|
|
429
|
+
}
|
|
430
|
+
this.valueChange.emit(value);
|
|
431
|
+
}
|
|
5
432
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngGrid, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
6
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "
|
|
433
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: TngGrid, isStandalone: true, selector: "[tngGrid]", inputs: { dir: { classPropertyName: "dir", publicName: "dir", isSignal: true, isRequired: false, transformFunction: null }, focusCol: { classPropertyName: "focusCol", publicName: "focusCol", isSignal: true, isRequired: false, transformFunction: null }, focusRow: { classPropertyName: "focusRow", publicName: "focusRow", isSignal: true, isRequired: false, transformFunction: null }, selectionMode: { classPropertyName: "selectionMode", publicName: "selectionMode", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, defaultValue: { classPropertyName: "defaultValue", publicName: "defaultValue", isSignal: true, isRequired: false, transformFunction: null }, wrap: { classPropertyName: "wrap", publicName: "wrap", isSignal: true, isRequired: false, transformFunction: null }, ariaLabel: { classPropertyName: "ariaLabel", publicName: "ariaLabel", isSignal: false, isRequired: false, transformFunction: null }, ariaColcount: { classPropertyName: "ariaColcount", publicName: "ariaColcount", isSignal: false, isRequired: false, transformFunction: null }, ariaRowcount: { classPropertyName: "ariaRowcount", publicName: "ariaRowcount", isSignal: false, isRequired: false, transformFunction: null } }, outputs: { focusRowChange: "focusRowChange", focusColChange: "focusColChange", focusChange: "focusChange", valueChange: "valueChange", cellActivate: "cellActivate" }, host: { listeners: { "focusout": "onFocusOut($event)", "keydown": "onKeyDown($event)" }, properties: { "attr.data-slot": "this.dataSlot", "attr.role": "this.role", "attr.aria-label": "this.ariaLabelAttr", "attr.aria-colcount": "this.ariaColcountAttr", "attr.aria-rowcount": "this.ariaRowcountAttr" } }, exportAs: ["tngGrid"], ngImport: i0 });
|
|
7
434
|
}
|
|
8
435
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngGrid, decorators: [{
|
|
9
436
|
type: Directive,
|
|
@@ -11,8 +438,248 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
|
|
|
11
438
|
selector: '[tngGrid]',
|
|
12
439
|
exportAs: 'tngGrid',
|
|
13
440
|
}]
|
|
441
|
+
}], propDecorators: { dir: [{ type: i0.Input, args: [{ isSignal: true, alias: "dir", required: false }] }], focusCol: [{ type: i0.Input, args: [{ isSignal: true, alias: "focusCol", required: false }] }], focusRow: [{ type: i0.Input, args: [{ isSignal: true, alias: "focusRow", required: false }] }], selectionMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectionMode", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }], defaultValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "defaultValue", required: false }] }], wrap: [{ type: i0.Input, args: [{ isSignal: true, alias: "wrap", required: false }] }], focusRowChange: [{ type: i0.Output, args: ["focusRowChange"] }], focusColChange: [{ type: i0.Output, args: ["focusColChange"] }], focusChange: [{ type: i0.Output, args: ["focusChange"] }], valueChange: [{ type: i0.Output, args: ["valueChange"] }], cellActivate: [{ type: i0.Output, args: ["cellActivate"] }], ariaLabel: [{
|
|
442
|
+
type: Input
|
|
443
|
+
}], ariaColcount: [{
|
|
444
|
+
type: Input
|
|
445
|
+
}], ariaRowcount: [{
|
|
446
|
+
type: Input
|
|
447
|
+
}], dataSlot: [{
|
|
448
|
+
type: HostBinding,
|
|
449
|
+
args: ['attr.data-slot']
|
|
450
|
+
}], role: [{
|
|
451
|
+
type: HostBinding,
|
|
452
|
+
args: ['attr.role']
|
|
453
|
+
}], ariaLabelAttr: [{
|
|
454
|
+
type: HostBinding,
|
|
455
|
+
args: ['attr.aria-label']
|
|
456
|
+
}], ariaColcountAttr: [{
|
|
457
|
+
type: HostBinding,
|
|
458
|
+
args: ['attr.aria-colcount']
|
|
459
|
+
}], ariaRowcountAttr: [{
|
|
460
|
+
type: HostBinding,
|
|
461
|
+
args: ['attr.aria-rowcount']
|
|
462
|
+
}], onFocusOut: [{
|
|
463
|
+
type: HostListener,
|
|
464
|
+
args: ['focusout', ['$event']]
|
|
465
|
+
}], onKeyDown: [{
|
|
466
|
+
type: HostListener,
|
|
467
|
+
args: ['keydown', ['$event']]
|
|
468
|
+
}] } });
|
|
469
|
+
export class TngGridRow {
|
|
470
|
+
dataSlot = 'grid-row';
|
|
471
|
+
role = 'row';
|
|
472
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngGridRow, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
473
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.1.1", type: TngGridRow, isStandalone: true, selector: "[tngGridRow]", host: { properties: { "attr.data-slot": "this.dataSlot", "attr.role": "this.role" } }, exportAs: ["tngGridRow"], ngImport: i0 });
|
|
474
|
+
}
|
|
475
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngGridRow, decorators: [{
|
|
476
|
+
type: Directive,
|
|
477
|
+
args: [{
|
|
478
|
+
selector: '[tngGridRow]',
|
|
479
|
+
exportAs: 'tngGridRow',
|
|
480
|
+
}]
|
|
14
481
|
}], propDecorators: { dataSlot: [{
|
|
15
482
|
type: HostBinding,
|
|
16
483
|
args: ['attr.data-slot']
|
|
484
|
+
}], role: [{
|
|
485
|
+
type: HostBinding,
|
|
486
|
+
args: ['attr.role']
|
|
487
|
+
}] } });
|
|
488
|
+
export class TngGridCell {
|
|
489
|
+
hostRef = inject(ElementRef);
|
|
490
|
+
grid = inject(TngGrid);
|
|
491
|
+
rowIndex = input.required({ ...(ngDevMode ? { debugName: "rowIndex" } : {}), transform: normalizeIndex });
|
|
492
|
+
colIndex = input.required({ ...(ngDevMode ? { debugName: "colIndex" } : {}), transform: normalizeIndex });
|
|
493
|
+
rowSpan = input(1, { ...(ngDevMode ? { debugName: "rowSpan" } : {}), transform: normalizeSpan });
|
|
494
|
+
colSpan = input(1, { ...(ngDevMode ? { debugName: "colSpan" } : {}), transform: normalizeSpan });
|
|
495
|
+
disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : {}), transform: booleanAttribute });
|
|
496
|
+
selected = input(null, { ...(ngDevMode ? { debugName: "selected" } : {}), transform: (value) => {
|
|
497
|
+
if (value === undefined || value === null) {
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
return booleanAttribute(value);
|
|
501
|
+
} });
|
|
502
|
+
cellRole = input('gridcell', { ...(ngDevMode ? { debugName: "cellRole" } : {}), transform: normalizeCellRole });
|
|
503
|
+
dataSlot = 'gridcell';
|
|
504
|
+
get roleAttr() {
|
|
505
|
+
return this.cellRole();
|
|
506
|
+
}
|
|
507
|
+
get tabIndexAttr() {
|
|
508
|
+
return this.grid.getCellTabIndex(this);
|
|
509
|
+
}
|
|
510
|
+
get ariaRowIndexAttr() {
|
|
511
|
+
return String(this.rowIndex() + 1);
|
|
512
|
+
}
|
|
513
|
+
get ariaColIndexAttr() {
|
|
514
|
+
return String(this.colIndex() + 1);
|
|
515
|
+
}
|
|
516
|
+
get ariaRowSpanAttr() {
|
|
517
|
+
return this.rowSpan() > 1 ? String(this.rowSpan()) : null;
|
|
518
|
+
}
|
|
519
|
+
get ariaColSpanAttr() {
|
|
520
|
+
return this.colSpan() > 1 ? String(this.colSpan()) : null;
|
|
521
|
+
}
|
|
522
|
+
get ariaDisabledAttr() {
|
|
523
|
+
return this.grid.isCellDisabled(this) ? 'true' : null;
|
|
524
|
+
}
|
|
525
|
+
get ariaSelectedAttr() {
|
|
526
|
+
if (this.cellRole() !== 'gridcell' && this.selected() === null) {
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
if (this.cellRole() !== 'gridcell' && this.selected() !== null) {
|
|
530
|
+
return this.selected() ? 'true' : 'false';
|
|
531
|
+
}
|
|
532
|
+
if (this.grid.selectionMode() === 'none' && this.selected() === null) {
|
|
533
|
+
return null;
|
|
534
|
+
}
|
|
535
|
+
return this.grid.isCellSelected(this) ? 'true' : 'false';
|
|
536
|
+
}
|
|
537
|
+
get dataRowIndexAttr() {
|
|
538
|
+
return String(this.rowIndex());
|
|
539
|
+
}
|
|
540
|
+
get dataColIndexAttr() {
|
|
541
|
+
return String(this.colIndex());
|
|
542
|
+
}
|
|
543
|
+
get dataRowSpanAttr() {
|
|
544
|
+
return this.rowSpan() > 1 ? String(this.rowSpan()) : null;
|
|
545
|
+
}
|
|
546
|
+
get dataColSpanAttr() {
|
|
547
|
+
return this.colSpan() > 1 ? String(this.colSpan()) : null;
|
|
548
|
+
}
|
|
549
|
+
get dataDisabledAttr() {
|
|
550
|
+
return this.grid.isCellDisabled(this) ? '' : null;
|
|
551
|
+
}
|
|
552
|
+
get dataSelectedAttr() {
|
|
553
|
+
return this.grid.isCellSelected(this) ? '' : null;
|
|
554
|
+
}
|
|
555
|
+
get dataFocusedAttr() {
|
|
556
|
+
return this.grid.isCellFocused(this) ? '' : null;
|
|
557
|
+
}
|
|
558
|
+
get dataFocusVisibleAttr() {
|
|
559
|
+
return this.grid.isCellFocusVisible(this) ? '' : null;
|
|
560
|
+
}
|
|
561
|
+
get dataActivatedAttr() {
|
|
562
|
+
return this.grid.isCellActivated(this) ? '' : null;
|
|
563
|
+
}
|
|
564
|
+
ngOnInit() {
|
|
565
|
+
this.grid.registerCell(this);
|
|
566
|
+
}
|
|
567
|
+
ngOnDestroy() {
|
|
568
|
+
this.grid.unregisterCell(this);
|
|
569
|
+
}
|
|
570
|
+
cellKey() {
|
|
571
|
+
return createCellKey(this.getValue());
|
|
572
|
+
}
|
|
573
|
+
focusHost() {
|
|
574
|
+
this.hostRef.nativeElement.focus();
|
|
575
|
+
}
|
|
576
|
+
getHostElement() {
|
|
577
|
+
return this.hostRef.nativeElement;
|
|
578
|
+
}
|
|
579
|
+
getValue() {
|
|
580
|
+
return Object.freeze({
|
|
581
|
+
col: this.colIndex(),
|
|
582
|
+
row: this.rowIndex(),
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
isFocusVisible() {
|
|
586
|
+
return this.hostRef.nativeElement.matches(':focus-visible');
|
|
587
|
+
}
|
|
588
|
+
matchesValue(value) {
|
|
589
|
+
return this.rowIndex() === value.row && this.colIndex() === value.col;
|
|
590
|
+
}
|
|
591
|
+
onClick() {
|
|
592
|
+
if (this.grid.isCellDisabled(this)) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
this.grid.onCellClicked(this);
|
|
596
|
+
}
|
|
597
|
+
onDoubleClick() {
|
|
598
|
+
if (this.grid.isCellDisabled(this)) {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
this.grid.onCellSelectionRequest(this, 'pointer');
|
|
602
|
+
}
|
|
603
|
+
onFocus() {
|
|
604
|
+
this.grid.onCellFocused(this);
|
|
605
|
+
}
|
|
606
|
+
onPointerDown() {
|
|
607
|
+
this.grid.onCellPointerDown(this);
|
|
608
|
+
}
|
|
609
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngGridCell, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
610
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.1.1", type: TngGridCell, isStandalone: true, selector: "[tngGridCell]", inputs: { rowIndex: { classPropertyName: "rowIndex", publicName: "rowIndex", isSignal: true, isRequired: true, transformFunction: null }, colIndex: { classPropertyName: "colIndex", publicName: "colIndex", isSignal: true, isRequired: true, transformFunction: null }, rowSpan: { classPropertyName: "rowSpan", publicName: "rowSpan", isSignal: true, isRequired: false, transformFunction: null }, colSpan: { classPropertyName: "colSpan", publicName: "colSpan", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, selected: { classPropertyName: "selected", publicName: "selected", isSignal: true, isRequired: false, transformFunction: null }, cellRole: { classPropertyName: "cellRole", publicName: "cellRole", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "click": "onClick()", "dblclick": "onDoubleClick()", "focus": "onFocus()", "pointerdown": "onPointerDown()" }, properties: { "attr.data-slot": "this.dataSlot", "attr.role": "this.roleAttr", "attr.tabindex": "this.tabIndexAttr", "attr.aria-rowindex": "this.ariaRowIndexAttr", "attr.aria-colindex": "this.ariaColIndexAttr", "attr.aria-rowspan": "this.ariaRowSpanAttr", "attr.aria-colspan": "this.ariaColSpanAttr", "attr.aria-disabled": "this.ariaDisabledAttr", "attr.aria-selected": "this.ariaSelectedAttr", "attr.data-row-index": "this.dataRowIndexAttr", "attr.data-col-index": "this.dataColIndexAttr", "attr.data-row-span": "this.dataRowSpanAttr", "attr.data-col-span": "this.dataColSpanAttr", "attr.data-disabled": "this.dataDisabledAttr", "attr.data-selected": "this.dataSelectedAttr", "attr.data-focused": "this.dataFocusedAttr", "attr.data-focus-visible": "this.dataFocusVisibleAttr", "attr.data-activated": "this.dataActivatedAttr" } }, exportAs: ["tngGridCell"], ngImport: i0 });
|
|
611
|
+
}
|
|
612
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: TngGridCell, decorators: [{
|
|
613
|
+
type: Directive,
|
|
614
|
+
args: [{
|
|
615
|
+
selector: '[tngGridCell]',
|
|
616
|
+
exportAs: 'tngGridCell',
|
|
617
|
+
}]
|
|
618
|
+
}], propDecorators: { rowIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowIndex", required: true }] }], colIndex: [{ type: i0.Input, args: [{ isSignal: true, alias: "colIndex", required: true }] }], rowSpan: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowSpan", required: false }] }], colSpan: [{ type: i0.Input, args: [{ isSignal: true, alias: "colSpan", required: false }] }], disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], selected: [{ type: i0.Input, args: [{ isSignal: true, alias: "selected", required: false }] }], cellRole: [{ type: i0.Input, args: [{ isSignal: true, alias: "cellRole", required: false }] }], dataSlot: [{
|
|
619
|
+
type: HostBinding,
|
|
620
|
+
args: ['attr.data-slot']
|
|
621
|
+
}], roleAttr: [{
|
|
622
|
+
type: HostBinding,
|
|
623
|
+
args: ['attr.role']
|
|
624
|
+
}], tabIndexAttr: [{
|
|
625
|
+
type: HostBinding,
|
|
626
|
+
args: ['attr.tabindex']
|
|
627
|
+
}], ariaRowIndexAttr: [{
|
|
628
|
+
type: HostBinding,
|
|
629
|
+
args: ['attr.aria-rowindex']
|
|
630
|
+
}], ariaColIndexAttr: [{
|
|
631
|
+
type: HostBinding,
|
|
632
|
+
args: ['attr.aria-colindex']
|
|
633
|
+
}], ariaRowSpanAttr: [{
|
|
634
|
+
type: HostBinding,
|
|
635
|
+
args: ['attr.aria-rowspan']
|
|
636
|
+
}], ariaColSpanAttr: [{
|
|
637
|
+
type: HostBinding,
|
|
638
|
+
args: ['attr.aria-colspan']
|
|
639
|
+
}], ariaDisabledAttr: [{
|
|
640
|
+
type: HostBinding,
|
|
641
|
+
args: ['attr.aria-disabled']
|
|
642
|
+
}], ariaSelectedAttr: [{
|
|
643
|
+
type: HostBinding,
|
|
644
|
+
args: ['attr.aria-selected']
|
|
645
|
+
}], dataRowIndexAttr: [{
|
|
646
|
+
type: HostBinding,
|
|
647
|
+
args: ['attr.data-row-index']
|
|
648
|
+
}], dataColIndexAttr: [{
|
|
649
|
+
type: HostBinding,
|
|
650
|
+
args: ['attr.data-col-index']
|
|
651
|
+
}], dataRowSpanAttr: [{
|
|
652
|
+
type: HostBinding,
|
|
653
|
+
args: ['attr.data-row-span']
|
|
654
|
+
}], dataColSpanAttr: [{
|
|
655
|
+
type: HostBinding,
|
|
656
|
+
args: ['attr.data-col-span']
|
|
657
|
+
}], dataDisabledAttr: [{
|
|
658
|
+
type: HostBinding,
|
|
659
|
+
args: ['attr.data-disabled']
|
|
660
|
+
}], dataSelectedAttr: [{
|
|
661
|
+
type: HostBinding,
|
|
662
|
+
args: ['attr.data-selected']
|
|
663
|
+
}], dataFocusedAttr: [{
|
|
664
|
+
type: HostBinding,
|
|
665
|
+
args: ['attr.data-focused']
|
|
666
|
+
}], dataFocusVisibleAttr: [{
|
|
667
|
+
type: HostBinding,
|
|
668
|
+
args: ['attr.data-focus-visible']
|
|
669
|
+
}], dataActivatedAttr: [{
|
|
670
|
+
type: HostBinding,
|
|
671
|
+
args: ['attr.data-activated']
|
|
672
|
+
}], onClick: [{
|
|
673
|
+
type: HostListener,
|
|
674
|
+
args: ['click']
|
|
675
|
+
}], onDoubleClick: [{
|
|
676
|
+
type: HostListener,
|
|
677
|
+
args: ['dblclick']
|
|
678
|
+
}], onFocus: [{
|
|
679
|
+
type: HostListener,
|
|
680
|
+
args: ['focus']
|
|
681
|
+
}], onPointerDown: [{
|
|
682
|
+
type: HostListener,
|
|
683
|
+
args: ['pointerdown']
|
|
17
684
|
}] } });
|
|
18
685
|
//# sourceMappingURL=tng-grid.js.map
|