@apia/table2-controller 5.0.0 → 5.0.3

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.
Files changed (90) hide show
  1. package/dist/data/TableController.d.ts +174 -0
  2. package/dist/data/TableController.d.ts.map +1 -0
  3. package/dist/data/TableController.js +348 -0
  4. package/dist/data/TableController.js.map +1 -0
  5. package/dist/data/body/TableBody.d.ts +16 -0
  6. package/dist/data/body/TableBody.d.ts.map +1 -0
  7. package/dist/data/body/TableBody.js +35 -0
  8. package/dist/data/body/TableBody.js.map +1 -0
  9. package/dist/data/filter/ComboFilter.d.ts +18 -0
  10. package/dist/data/filter/ComboFilter.d.ts.map +1 -0
  11. package/dist/data/filter/ComboFilter.js +32 -0
  12. package/dist/data/filter/ComboFilter.js.map +1 -0
  13. package/dist/data/filter/DateFilter.d.ts +7 -0
  14. package/dist/data/filter/DateFilter.d.ts.map +1 -0
  15. package/dist/data/filter/DateFilter.js +7 -0
  16. package/dist/data/filter/DateFilter.js.map +1 -0
  17. package/dist/data/filter/DateRangeFilter.d.ts +52 -0
  18. package/dist/data/filter/DateRangeFilter.d.ts.map +1 -0
  19. package/dist/data/filter/DateRangeFilter.js +208 -0
  20. package/dist/data/filter/DateRangeFilter.js.map +1 -0
  21. package/dist/data/filter/DateTimeRangeFilter.d.ts +23 -0
  22. package/dist/data/filter/DateTimeRangeFilter.d.ts.map +1 -0
  23. package/dist/data/filter/DateTimeRangeFilter.js +87 -0
  24. package/dist/data/filter/DateTimeRangeFilter.js.map +1 -0
  25. package/dist/data/filter/Filter.d.ts +49 -0
  26. package/dist/data/filter/Filter.d.ts.map +1 -0
  27. package/dist/data/filter/Filter.js +63 -0
  28. package/dist/data/filter/Filter.js.map +1 -0
  29. package/dist/data/head/Column.d.ts +23 -0
  30. package/dist/data/head/Column.d.ts.map +1 -0
  31. package/dist/data/head/Column.js +26 -0
  32. package/dist/data/head/Column.js.map +1 -0
  33. package/dist/data/head/Columns.d.ts +16 -0
  34. package/dist/data/head/Columns.d.ts.map +1 -0
  35. package/dist/data/head/Columns.js +57 -0
  36. package/dist/data/head/Columns.js.map +1 -0
  37. package/dist/data/head/Filters.d.ts +20 -0
  38. package/dist/data/head/Filters.d.ts.map +1 -0
  39. package/dist/data/head/Filters.js +132 -0
  40. package/dist/data/head/Filters.js.map +1 -0
  41. package/dist/data/head/NullFilter.js +25 -0
  42. package/dist/data/head/NullFilter.js.map +1 -0
  43. package/dist/data/head/TableHead.d.ts +26 -0
  44. package/dist/data/head/TableHead.d.ts.map +1 -0
  45. package/dist/data/head/TableHead.js +59 -0
  46. package/dist/data/head/TableHead.js.map +1 -0
  47. package/dist/data/plugins/FocusControllerPlugin/index.d.ts +26 -0
  48. package/dist/data/plugins/FocusControllerPlugin/index.d.ts.map +1 -0
  49. package/dist/data/plugins/FocusControllerPlugin/index.js +130 -0
  50. package/dist/data/plugins/FocusControllerPlugin/index.js.map +1 -0
  51. package/dist/data/plugins/FocusControllerPlugin/useFocusByClick.js +80 -0
  52. package/dist/data/plugins/FocusControllerPlugin/useFocusByClick.js.map +1 -0
  53. package/dist/data/plugins/FocusControllerPlugin/useFocusByKey.js +156 -0
  54. package/dist/data/plugins/FocusControllerPlugin/useFocusByKey.js.map +1 -0
  55. package/dist/data/plugins/TablePlugin.d.ts +30 -0
  56. package/dist/data/plugins/TablePlugin.d.ts.map +1 -0
  57. package/dist/data/plugins/TablePlugin.js +10 -0
  58. package/dist/data/plugins/TablePlugin.js.map +1 -0
  59. package/dist/data/plugins/WaiAriaPlugin.d.ts +42 -0
  60. package/dist/data/plugins/WaiAriaPlugin.d.ts.map +1 -0
  61. package/dist/data/plugins/WaiAriaPlugin.js +29 -0
  62. package/dist/data/plugins/WaiAriaPlugin.js.map +1 -0
  63. package/dist/data/primitive/AdditionalCell.d.ts +11 -0
  64. package/dist/data/primitive/AdditionalCell.d.ts.map +1 -0
  65. package/dist/data/primitive/AdditionalCell.js +38 -0
  66. package/dist/data/primitive/AdditionalCell.js.map +1 -0
  67. package/dist/data/primitive/AdditionalRow.d.ts +12 -0
  68. package/dist/data/primitive/AdditionalRow.d.ts.map +1 -0
  69. package/dist/data/primitive/AdditionalRow.js +16 -0
  70. package/dist/data/primitive/AdditionalRow.js.map +1 -0
  71. package/dist/data/primitive/Cell.d.ts +39 -0
  72. package/dist/data/primitive/Cell.d.ts.map +1 -0
  73. package/dist/data/primitive/Cell.js +41 -0
  74. package/dist/data/primitive/Cell.js.map +1 -0
  75. package/dist/data/primitive/Element.d.ts +18 -0
  76. package/dist/data/primitive/Element.d.ts.map +1 -0
  77. package/dist/data/primitive/Element.js +40 -0
  78. package/dist/data/primitive/Element.js.map +1 -0
  79. package/dist/data/primitive/Row.d.ts +58 -0
  80. package/dist/data/primitive/Row.d.ts.map +1 -0
  81. package/dist/data/primitive/Row.js +193 -0
  82. package/dist/data/primitive/Row.js.map +1 -0
  83. package/dist/data/primitive/RowsGroup.d.ts +29 -0
  84. package/dist/data/primitive/RowsGroup.d.ts.map +1 -0
  85. package/dist/data/primitive/RowsGroup.js +86 -0
  86. package/dist/data/primitive/RowsGroup.js.map +1 -0
  87. package/dist/index.d.ts +20 -433
  88. package/dist/index.js +20 -1300
  89. package/dist/index.js.map +1 -1
  90. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1,1301 +1,21 @@
1
- import { makeObservable, action, observable, computed } from 'mobx';
2
- import { arrayOrArray, EventEmitter, useMount, scrollParentIntoElement, disableChildrenFocus, getFocusSelector } from '@apia/util';
3
- import { useRef } from 'react';
4
-
5
- var __defProp$7 = Object.defineProperty;
6
- var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField$7 = (obj, key, value) => {
8
- __defNormalProp$7(obj, key + "" , value);
9
- return value;
10
- };
11
- const voidTable = {};
12
- class Element {
13
- constructor(state) {
14
- this.state = state;
15
- __publicField$7(this, "table", voidTable);
16
- makeObservable(this, {
17
- state: observable,
18
- setState: action
19
- });
20
- }
21
- getTable() {
22
- return this.table;
23
- }
24
- setTable(table) {
25
- this.table = table || voidTable;
26
- return this;
27
- }
28
- getState(prop) {
29
- return this.state[prop];
30
- }
31
- setState(prop, value) {
32
- if (typeof prop === "function") {
33
- this.state = prop(this.state);
34
- } else {
35
- this.state[prop] = value;
36
- }
37
- return this;
38
- }
39
- }
40
-
41
- var __defProp$6 = Object.defineProperty;
42
- var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
43
- var __publicField$6 = (obj, key, value) => {
44
- __defNormalProp$6(obj, key + "" , value);
45
- return value;
46
- };
47
- class Cell extends Element {
48
- constructor() {
49
- super(...arguments);
50
- __publicField$6(this, "parentRow", null);
51
- }
52
- getColumnName() {
53
- return this.getState("colName");
54
- }
55
- getIndex() {
56
- return this.getRow().getCellIndex(this);
57
- }
58
- getRow() {
59
- return this.parentRow;
60
- }
61
- setRow(row) {
62
- this.parentRow = row;
63
- return this;
64
- }
65
- /**
66
- *
67
- * @param doFocus - If true, the cell will be focused after being set as the focused cell.
68
- * If false, the cell will contain the tabIndex = 0 but will not be focused.
69
- */
70
- focus(doFocus = true) {
71
- this.table.setFocusedCell(this, doFocus);
72
- }
73
- updateState(state) {
74
- this.state = { ...this.state, ...state };
75
- }
76
- }
77
-
78
- var __defProp$5 = Object.defineProperty;
79
- var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
80
- var __publicField$5 = (obj, key, value) => {
81
- __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
82
- return value;
83
- };
84
- class Row extends Element {
85
- constructor(id, properties) {
86
- const { cells, isSelected, ...state } = properties || {};
87
- super({ id, ...state, cells: cells || [] });
88
- this.properties = properties;
89
- __publicField$5(this, "container", {});
90
- __publicField$5(this, "hiddenCells", /* @__PURE__ */ new Map());
91
- makeObservable(this, {
92
- isSelected: computed
93
- });
94
- }
95
- addCell(cell) {
96
- this.state.cells.push(cell);
97
- this.attachCell(cell);
98
- return this;
99
- }
100
- addCellAfter(anchor, newElement) {
101
- const index = this.state.cells.indexOf(anchor) + 1;
102
- if (index !== -1) {
103
- this.attachCell(newElement);
104
- this.state.cells.splice(index, 0, newElement);
105
- }
106
- }
107
- addCellBefore(anchor, newElement) {
108
- const index = this.state.cells.indexOf(anchor);
109
- if (index !== -1) {
110
- this.attachCell(newElement);
111
- this.state.cells.splice(index, 0, newElement);
112
- }
113
- }
114
- build(data) {
115
- this.hiddenCells.clear();
116
- for (let i = 0; i < data.cells.length; i++) {
117
- const cell = data.cells[i];
118
- const col = cell.colName ? this.table.head.getHeaderRow().getColumn(cell.colName) : this.table.head.getHeaderRow().getColumns()[i];
119
- const cellInstance = new Cell({
120
- ...cell,
121
- colName: col?.getState("colName")
122
- });
123
- if (col?.isVisible()) {
124
- const currentCell = this.state.cells[i - this.hiddenCells.size];
125
- if (!currentCell) {
126
- this.addCell(cellInstance);
127
- } else {
128
- currentCell.updateState({
129
- ...cell,
130
- colName: col?.getState("colName")
131
- });
132
- }
133
- } else {
134
- this.hiddenCells.set(col?.getColumnName(), cellInstance);
135
- }
136
- }
137
- this.cells.splice(data.cells.length - this.hiddenCells.size);
138
- }
139
- get cells() {
140
- const hasAdditionalColumn = !!this.table.getState("onRowExpand") || (this.table.head.getFiltersRow()?.getFiltersInTable()?.length || 0) > 0;
141
- let additionalCell = null;
142
- if (hasAdditionalColumn) {
143
- additionalCell = new AdditionalCell();
144
- additionalCell.setRow(this);
145
- additionalCell.setTable(this.table);
146
- }
147
- return [additionalCell, ...this.state.cells].filter(
148
- (f) => Boolean(f)
149
- );
150
- }
151
- get isSelected() {
152
- return this.table.isSelected(this);
153
- }
154
- getCellByColumnName(colName) {
155
- return this.cells.find((c) => c.getState("colName") === colName);
156
- }
157
- getCellByIndex(index) {
158
- return this.cells[index];
159
- }
160
- getCellIndex(cell) {
161
- return this.cells.indexOf(cell);
162
- }
163
- getContainer() {
164
- return this.container;
165
- }
166
- getFollowingRow() {
167
- const containerRows = [...this.container.getState("rows").values()];
168
- const index = containerRows.findIndex(
169
- (r) => r.getState("id") === this.state.id
170
- );
171
- return containerRows[index + 1] || null;
172
- }
173
- getHiddenCell(colName) {
174
- return this.hiddenCells.get(colName);
175
- }
176
- getIndex() {
177
- return this.getContainer().getRowIndex(this);
178
- }
179
- getPreviousRow() {
180
- const containerRows = [...this.container.getState("rows").values()];
181
- const index = containerRows.findIndex(
182
- (r) => r.getState("id") === this.state.id
183
- );
184
- return containerRows[index - 1] || null;
185
- }
186
- insertAfter(row) {
187
- this.getContainer()?.insertAfter(this, row);
188
- }
189
- insertBefore(row) {
190
- this.getContainer()?.insertBefore(this, row);
191
- }
192
- remove() {
193
- this.getContainer()?.removeRow(this);
194
- }
195
- replaceCellOnIndex(index, newCell) {
196
- const current = this.cells[index];
197
- if (!current) {
198
- throw new Error("IndexOutOfBounds - The provided index is out of bounds");
199
- }
200
- this.cells[index] = newCell;
201
- this.attachCell(newCell);
202
- this.detachCell(current);
203
- }
204
- scrollIntoView() {
205
- this.table.scrollRowIntoView(this);
206
- }
207
- setContainer(container) {
208
- this.container = container;
209
- return this;
210
- }
211
- setTable(table) {
212
- super.setTable(table);
213
- this.state.cells.forEach((c) => c.setTable(table));
214
- if (table && this.properties?.isSelected) {
215
- table.toggleRowSelection(this, true);
216
- }
217
- return this;
218
- }
219
- swap(withRow) {
220
- this.getContainer()?.swapRows(this, withRow);
221
- }
222
- toggleSelection(forceState) {
223
- this.table.toggleRowSelection(this, forceState);
224
- }
225
- attachCell(cell) {
226
- cell.setTable(this.table);
227
- cell.setRow(this);
228
- }
229
- detachCell(cell) {
230
- cell.setTable(null);
231
- cell.setRow(null);
232
- }
233
- }
234
-
235
- class AdditionalRow extends Row {
236
- constructor(id) {
237
- super(id);
238
- this.setState("isSelectable", false);
239
- }
240
- get cells() {
241
- return this.state.cells;
242
- }
243
- }
244
-
245
- class AdditionalRowContent extends Cell {
246
- constructor(content) {
247
- super({
248
- expanded: false,
249
- colName: "__additional",
250
- content
251
- });
252
- }
253
- getState(prop) {
254
- if (prop === "domProperties") {
255
- return {
256
- colSpan: this.table.head.getHeaderRow()?.getShownColumns().length || 0
257
- };
258
- }
259
- return super.getState(prop);
260
- }
261
- }
262
-
263
- class AdditionalCell extends Cell {
264
- constructor() {
265
- super({
266
- expanded: false,
267
- colName: "__additional",
268
- domProperties: {
269
- className: "additionalColumn",
270
- style: {
271
- width: "50px"
272
- }
273
- }
274
- });
275
- }
276
- async onToggle() {
277
- const currentIndex = this.getRow().getIndex();
278
- if (!(this.getTable().body.getRowByIndex(currentIndex + 1) instanceof AdditionalRow)) {
279
- const res = await this.table.onRowExpand(this.getRow());
280
- if (res !== false) {
281
- const newRow = new AdditionalRow(
282
- `${this.getRow()?.getState("id")}__additional`
283
- );
284
- this.getTable().body.insertAfter(this.getRow(), newRow);
285
- newRow.addCell(new AdditionalRowContent(res));
286
- this.state.expanded = true;
287
- }
288
- } else {
289
- this.getTable().body.getRowByIndex(currentIndex + 1).remove();
290
- this.state.expanded = false;
291
- }
292
- }
293
- }
294
-
295
- class RowsGroup extends Element {
296
- constructor(table, state) {
297
- super({ ...state, rows: [] });
298
- this.table = table;
299
- makeObservable(this, { swapRows: action, rows: computed });
300
- }
301
- get rows() {
302
- return this.state.rows;
303
- }
304
- addRow(row) {
305
- this.state.rows.push(row);
306
- row.setTable(this.table);
307
- row.setContainer(this);
308
- this.runAddRowPlugin(row);
309
- return this;
310
- }
311
- addRows(rows) {
312
- rows.forEach(this.addRow.bind(this));
313
- return this;
314
- }
315
- clear() {
316
- this.state.rows.forEach((row) => {
317
- row.setContainer(null);
318
- row.setTable(null);
319
- });
320
- return this.rows.splice(0, this.rows.length);
321
- }
322
- getRowById(id) {
323
- return this.state.rows.find((c) => c.getState("id") === id);
324
- }
325
- getRowByIndex(index) {
326
- return this.state.rows[index];
327
- }
328
- getRowIndex(row) {
329
- return this.state.rows.indexOf(row);
330
- }
331
- insertAfter(anchor, newElement) {
332
- if (anchor.getContainer() === this) {
333
- const index = this.state.rows.indexOf(anchor);
334
- this.state.rows.splice(index + 1, 0, newElement);
335
- newElement.setTable(this.table);
336
- newElement.setContainer(this);
337
- this.runAddRowPlugin(newElement);
338
- }
339
- }
340
- insertBefore(anchor, newElement) {
341
- if (anchor.getContainer() === this) {
342
- const index = this.state.rows.indexOf(anchor);
343
- this.state.rows.splice(index, 0, newElement);
344
- newElement.setTable(this.table);
345
- newElement.setContainer(this);
346
- this.runAddRowPlugin(newElement);
347
- }
348
- }
349
- removeRow(row) {
350
- if (row.getContainer() === this) {
351
- row.setContainer(null);
352
- this.state.rows = this.state.rows.filter((r) => r !== row);
353
- this.table.removeRow(row);
354
- }
355
- }
356
- swapRows(a, b) {
357
- if (a?.getContainer() === this && b?.getContainer() === this) {
358
- const aIndex = this.state.rows.findIndex(
359
- (r) => r.getState?.("id") === a.getState?.("id")
360
- );
361
- const bIndex = this.state.rows.findIndex(
362
- (r) => r.getState?.("id") === b.getState?.("id")
363
- );
364
- if (aIndex !== -1 && bIndex !== -1) {
365
- this.state.rows[aIndex] = b;
366
- this.state.rows[bIndex] = a;
367
- }
368
- }
369
- }
370
- runAddRowPlugin(newRow) {
371
- const plugins = this.getTable().getApplicablePlugins("onAddRow");
372
- plugins.forEach((c) => c(this, newRow));
373
- }
374
- }
375
-
376
- class TableBody extends RowsGroup {
377
- constructor(table) {
378
- super(table, { rows: [] });
379
- }
380
- build(data) {
381
- let i = 0;
382
- for (const row of data.rows) {
383
- let currentRow = this.rows[i++];
384
- if (currentRow instanceof AdditionalRow) {
385
- currentRow.remove();
386
- currentRow = void 0;
387
- }
388
- const bodyRow = currentRow ?? new Row(row.id);
389
- if (!currentRow) {
390
- this.addRow(bodyRow);
391
- }
392
- bodyRow.build(row);
393
- }
394
- this.rows.splice(data.rows.length);
395
- }
396
- }
397
-
398
- class Column extends Cell {
399
- asAdditional() {
400
- return !!this.state.asAdditional;
401
- }
402
- isHidden() {
403
- return !!this.state.isHidden;
404
- }
405
- /**
406
- * A visible column is that which is not additional nor hidden.
407
- */
408
- isVisible() {
409
- return !this.asAdditional() && !this.isHidden();
410
- }
411
- sort(order) {
412
- order = order ?? (this.getState("sortState") === "ASC" ? "DESC" : "ASC");
413
- this.setState("sortState", order);
414
- }
415
- }
416
-
417
- var __defProp$4 = Object.defineProperty;
418
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
419
- var __publicField$4 = (obj, key, value) => {
420
- __defNormalProp$4(obj, key + "" , value);
421
- return value;
422
- };
423
- class Columns extends Row {
424
- constructor() {
425
- super(...arguments);
426
- __publicField$4(this, "columns", /* @__PURE__ */ new Map());
427
- }
428
- buildColumnsRow(columns) {
429
- let i = 0;
430
- for (const column of columns) {
431
- if (!this.columns.has(column.colName)) {
432
- this.columns.set(column.colName, new Column(column));
433
- } else {
434
- this.columns.get(column.colName)?.updateState(column);
435
- }
436
- const currentColumn = this.columns.get(column.colName);
437
- if (currentColumn.isVisible()) {
438
- this.state.cells[i++] = currentColumn;
439
- this.attachCell(currentColumn);
440
- }
441
- }
442
- }
443
- getColumn(name) {
444
- return this.getCellByColumnName(name);
445
- }
446
- getColumns() {
447
- return Array.from(this.columns.values());
448
- }
449
- getAdditionalColumns() {
450
- return this.getColumns().filter((c) => c.asAdditional());
451
- }
452
- getShownColumns() {
453
- return this.cells ?? [];
454
- }
455
- }
456
-
457
- class Filter extends Cell {
458
- asAdditional() {
459
- return !!this.state.asAdditional || !this.getCorrespondingColumn();
460
- }
461
- constructor(state) {
462
- super(state);
463
- }
464
- clear() {
465
- this.setValue("");
466
- }
467
- getCorrespondingColumn() {
468
- return this.getRow().getContainer().getHeaderRow()?.getShownColumns().find((c) => c.getState("colName") === this.getState("colName"));
469
- }
470
- fire(ev) {
471
- this.table.emit(ev, this);
472
- }
473
- getRow() {
474
- return super.getRow();
475
- }
476
- getValue() {
477
- return this.state.value;
478
- }
479
- hasValue() {
480
- return !!this.getValue();
481
- }
482
- setValue(val) {
483
- this.state.value = val;
484
- this.table.emit("filterChange", this);
485
- }
486
- validate() {
487
- return this.state.isRequired ? this.hasValue() : true;
488
- }
489
- }
490
-
491
- class NullFilter extends Filter {
492
- constructor(colName) {
493
- super({ colName });
494
- }
495
- clear() {
496
- }
497
- fire(_) {
498
- }
499
- getValue() {
500
- return void 0;
501
- }
502
- hasValue() {
503
- return false;
504
- }
505
- setValue() {
506
- }
507
- validate() {
508
- return true;
509
- }
510
- }
511
-
512
- class DateFilter extends Filter {
513
- }
514
-
515
- var __defProp$3 = Object.defineProperty;
516
- var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
517
- var __publicField$3 = (obj, key, value) => {
518
- __defNormalProp$3(obj, key + "" , value);
519
- return value;
520
- };
521
- class Filters extends Row {
522
- constructor() {
523
- super(...arguments);
524
- __publicField$3(this, "filters", /* @__PURE__ */ new Map());
525
- }
526
- buildFilterFromDefinition(def) {
527
- switch (def.type) {
528
- case "DATE":
529
- return new DateFilter(def);
530
- default:
531
- return new Filter(def);
532
- }
533
- }
534
- buildFilters(filters) {
535
- let hasFiltersInRow = false;
536
- const columns = arrayOrArray(
537
- this.getContainer().getHeaderRow()?.getShownColumns()
538
- );
539
- for (const stored of this.filters.values()) {
540
- if (!filters.find((c) => c.name === stored.getState("name"))) {
541
- this.filters.delete(stored.getState("name"));
542
- }
543
- }
544
- for (let i = 0; i < columns.length; i++) {
545
- const column = columns[i];
546
- const filter = filters.find(
547
- (c) => c.columnName === column.getState("colName") && !c.asAdditional
548
- );
549
- if (filter) {
550
- const currentFilterCell = this.getCellByIndex(i);
551
- const filterCell = currentFilterCell ?? this.buildFilterFromDefinition({
552
- ...filter,
553
- colName: filter.columnName
554
- });
555
- this.filters.set(filter.name, filterCell);
556
- if (!currentFilterCell) {
557
- this.addCell(filterCell);
558
- } else {
559
- const { value, ...filterState } = filter;
560
- currentFilterCell.updateState(filterState);
561
- }
562
- hasFiltersInRow = true;
563
- filter.added = true;
564
- } else {
565
- if (!this.getCellByIndex(i)) {
566
- this.addCell(new NullFilter(column.getColumnName()));
567
- }
568
- }
569
- }
570
- for (const filter of filters) {
571
- if (!filter.added) {
572
- const filterCell = this.filters.get(filter.name) ?? this.buildFilterFromDefinition({
573
- ...filter,
574
- colName: filter.columnName
575
- });
576
- filterCell.setTable(this.table);
577
- this.filters.set(filter.name, filterCell);
578
- }
579
- }
580
- return hasFiltersInRow;
581
- }
582
- getAdditionalFilters() {
583
- return this.getFilters().filter(
584
- (c) => c.getState("asAdditional") || this.getContainer().getHeaderRow()?.columns.get(c.getState("colName"))?.asAdditional()
585
- );
586
- }
587
- getCells() {
588
- return this.cells.map((c) => c);
589
- }
590
- getContainer() {
591
- return this.container;
592
- }
593
- getFilter(name) {
594
- return this.filters.get(name);
595
- }
596
- getFilters() {
597
- return Array.from(this.filters.values());
598
- }
599
- getFiltersInTable() {
600
- return this.getFilters().filter((f) => {
601
- return !(f.getState("asAdditional") || this.getContainer().getHeaderRow()?.columns.get(f.getState("colName"))?.isVisible() === false);
602
- });
603
- }
604
- }
605
-
606
- var __defProp$2 = Object.defineProperty;
607
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
608
- var __publicField$2 = (obj, key, value) => {
609
- __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
610
- return value;
611
- };
612
- class TableHead extends RowsGroup {
613
- constructor(table) {
614
- super(table, { rows: [] });
615
- __publicField$2(this, "columnsRow", null);
616
- __publicField$2(this, "filtersRow", null);
617
- }
618
- getHeaderRow() {
619
- return this.rows[0] instanceof Columns ? this.rows[0] : void 0;
620
- }
621
- getFiltersRow() {
622
- return this.rows[1] instanceof Filters ? this.rows[1] : void 0;
623
- }
624
- build(data) {
625
- if (data.columns.length) {
626
- const currentHeaderRow = this.rows[0];
627
- if (currentHeaderRow && !(currentHeaderRow instanceof Columns)) {
628
- currentHeaderRow.remove();
629
- }
630
- this.columnsRow = currentHeaderRow ?? new Columns("header");
631
- this.columnsRow.setTable(this.table);
632
- this.columnsRow.setContainer(this);
633
- if (!currentHeaderRow) {
634
- this.addRow(this.columnsRow);
635
- }
636
- this.columnsRow.buildColumnsRow(data.columns);
637
- }
638
- if (data.filters.length) {
639
- const currentFiltersRow = this.getFiltersRow();
640
- this.filtersRow = currentFiltersRow ?? new Filters("filters");
641
- this.filtersRow.setTable(this.table);
642
- this.filtersRow.setContainer(this);
643
- const hasFilter = this.filtersRow.buildFilters(data.filters);
644
- if (hasFilter && !currentFiltersRow) {
645
- this.addRow(this.filtersRow);
646
- }
647
- }
648
- }
649
- }
650
-
651
- const defaultPlugins = () => [
652
- new WaiAriaPlugin(),
653
- new FocusControllerPlugin()
654
- ];
655
-
656
- var __defProp$1 = Object.defineProperty;
657
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
658
- var __publicField$1 = (obj, key, value) => {
659
- __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
660
- return value;
661
- };
662
- class TableController extends EventEmitter {
663
- constructor(props) {
664
- super();
665
- __publicField$1(this, "state", {
666
- allowEdition: true,
667
- allowResize: true,
668
- allowSelection: true,
669
- editionMode: false,
670
- focusedCell: null,
671
- plugins: [],
672
- isSelectionMultiple: true,
673
- selection: /* @__PURE__ */ new Set()
674
- });
675
- __publicField$1(this, "body", new TableBody(this));
676
- __publicField$1(this, "head", new TableHead(this));
677
- Object.assign(this.state, props || {});
678
- if (!props?.plugins) {
679
- this.state.plugins.push(...defaultPlugins());
680
- }
681
- makeObservable(this, {
682
- build: action,
683
- clearSelection: action,
684
- isEditionMode: computed,
685
- setFocusedCell: action,
686
- state: observable,
687
- toggleRowSelection: action,
688
- toggleEditionMode: action
689
- });
690
- }
691
- /**
692
- * Clears all data in the table, except for the events
693
- * listeners and recreates the structure based on the passed data.
694
- */
695
- build(data) {
696
- this.head.build(data);
697
- this.body.build(data);
698
- this.restoreFocus();
699
- }
700
- fromGenericTable(table) {
701
- this.setState("allowEdition", table.behavior.allowEdition);
702
- this.setState("allowSelection", table.behavior.allowSelection);
703
- this.setState("isSelectionMultiple", table.behavior.isMultipleSelection);
704
- const columns = arrayOrArray(table.columns);
705
- this.build({
706
- columns: columns.map((c) => {
707
- return {
708
- colName: c.name,
709
- asAdditional: c.showAsAdditional,
710
- sortable: c.isSortable,
711
- isHidden: c.isHidden,
712
- properties: c,
713
- content: c.title,
714
- className: c.className,
715
- sortState: c.sortType
716
- };
717
- }),
718
- filters: arrayOrArray(table.filters).map((f) => {
719
- return {
720
- name: f.name,
721
- title: f.title,
722
- tooltip: "no tooltip",
723
- type: f.type,
724
- isRequired: f.isRequired,
725
- properties: f,
726
- runAutomatically: f.runAutomatically,
727
- columnName: f.columnName,
728
- value: f.initialValue,
729
- asAdditional: f.asAdditional
730
- };
731
- }),
732
- rows: arrayOrArray(table.rows).map((row) => {
733
- const returnValue = {
734
- id: row.id,
735
- cells: arrayOrArray(row.cells).map((cell) => {
736
- const returnValue2 = {
737
- content: cell.text
738
- };
739
- return returnValue2;
740
- }),
741
- isExpandible: false,
742
- isSelectable: !row.isDisabled,
743
- isSelected: row.isSelected,
744
- domProperties: {},
745
- properties: row
746
- };
747
- return returnValue;
748
- })
749
- });
750
- }
751
- getColumn(name) {
752
- return this.head.getHeaderRow()?.getColumn(name);
753
- }
754
- getColumns() {
755
- return this.head.getHeaderRow()?.getColumns() || [];
756
- }
757
- getFilter(name) {
758
- return this.head.getFiltersRow()?.getFilter(name);
759
- }
760
- getFilters() {
761
- return this.head.getFiltersRow()?.getFilters() || [];
762
- }
763
- getRowById(id) {
764
- return this.head.getRowById(id) || this.body.getRowById(id);
765
- }
766
- hasAdditionalContent() {
767
- return !!this.head.getHeaderRow()?.getColumns().find((c) => c.asAdditional()) || this.getState("onRowExpand");
768
- }
769
- onRowExpand(row) {
770
- return this.getState("onRowExpand")?.(row) || this.head.getHeaderRow()?.getAdditionalColumns().map(
771
- (column) => `${column.getState("content")}: ${row.getHiddenCell(column.getColumnName())?.getState("content")}`
772
- ).join(", ");
773
- }
774
- /**
775
- * EDITION MODE
776
- */
777
- get isEditionMode() {
778
- return this.state.editionMode;
779
- }
780
- toggleEditionMode(force) {
781
- if (this.state.allowEdition) {
782
- this.state.editionMode = force ?? !this.state.editionMode;
783
- this.emit("editionMode", this.state.editionMode);
784
- }
785
- }
786
- /**
787
- * SELECTION
788
- */
789
- clearSelection() {
790
- this.state.selection.clear();
791
- }
792
- /**
793
- * Returns the selected rows.
794
- */
795
- getSelectedRows() {
796
- return [...this.state.selection];
797
- }
798
- isSelected(row) {
799
- return this.state.selection.has(row);
800
- }
801
- toggleColumnVisibility(colName, isVisible) {
802
- isVisible = isVisible ?? this.head.getHeaderRow()?.getColumn(colName).getState("isHidden");
803
- if (this.head.getHeaderRow()) {
804
- this.head.getHeaderRow()?.getColumn(colName).setState("isHidden", isVisible);
805
- } else {
806
- this.head.rows[0]?.cells?.find((c) => c.getState("colName") === colName)?.setState("isHidden", !isVisible);
807
- }
808
- }
809
- toggleFiltersRowVisibility() {
810
- this.head.getFiltersRow()?.setState("isHidden", !this.head.getFiltersRow()?.getState("isHidden"));
811
- }
812
- /**
813
- * Toggles the selection state of a given row.
814
- *
815
- * If the `isSelected` parameter is provided, it explicitly sets the selection
816
- * state of the row to the given value (`true` for selected, `false` for deselected).
817
- * If `isSelected` is not provided, the method will toggle the current selection state
818
- * of the row (i.e., select it if it's currently not selected, or deselect it if it is).
819
- *
820
- * @param row - The row to toggle selection for.
821
- * @param isSelected - Optional. A boolean indicating whether the row should be selected (`true`)
822
- * or deselected (`false`). If not provided, the selection state will be toggled.
823
- */
824
- toggleRowSelection(row, isSelected) {
825
- if (this.state.allowSelection) {
826
- isSelected = isSelected ?? !this.state.selection.has(row);
827
- if (isSelected) {
828
- if (row.getState("isSelectable") !== false) {
829
- this.state.selection.add(row);
830
- }
831
- } else {
832
- this.state.selection.delete(row);
833
- }
834
- this.emit("selectionChange", [...this.state.selection.values()]);
835
- }
836
- }
837
- restoreFocus() {
838
- if (!this.state.focusedCell || this.state.focusedCell.getTable() !== this) {
839
- this.state.focusedCell = this.body.getState("rows").values().next().value?.cells[0] || this.head.getState("rows").values().next().value?.cells[0] || null;
840
- }
841
- if (this.state.focusedCell) {
842
- this.emit("cellFocus", { cell: this.state.focusedCell, doFocus: false });
843
- }
844
- }
845
- removeRow(row) {
846
- if (row.getTable() === this) {
847
- row.setTable(null);
848
- this.head.removeRow(row);
849
- this.body.removeRow(row);
850
- if (this.state.selection.has(row)) {
851
- this.state.selection.delete(row);
852
- this.emit("selectionChange", [...this.state.selection.values()]);
853
- }
854
- if (this.state.focusedCell?.getRow() === row) {
855
- this.restoreFocus();
856
- }
857
- }
858
- }
859
- /**
860
- * FOCUS
861
- */
862
- /**
863
- * @returns The currently focused cell in the table.
864
- */
865
- getFocusedCell() {
866
- return this.state.focusedCell;
867
- }
868
- setFocusedCell(cell, doFocus = true) {
869
- this.state.focusedCell = cell;
870
- this.emit("cellFocus", { cell, doFocus });
871
- }
872
- setSelection(indices) {
873
- this.clearSelection();
874
- indices.forEach((index) => {
875
- const row = this.body.getRowByIndex(index);
876
- if (row) {
877
- this.toggleRowSelection(row, true);
878
- }
879
- });
880
- }
881
- scrollRowIntoView(row) {
882
- this.emit("scrollIntoRow", row);
883
- }
884
- /**
885
- * STATE
886
- */
887
- /**
888
- * Returns the current state of the `TableController` instance.
889
- *
890
- * @param prop - The property of the state to retrieve.
891
- */
892
- getState(prop) {
893
- return this.state[prop];
894
- }
895
- setState(prop, value) {
896
- if (typeof prop === "function") {
897
- this.state = prop(this.state);
898
- } else {
899
- this.state[prop] = value;
900
- }
901
- return this;
902
- }
903
- sortColumn(col, sortState) {
904
- this.getColumns().forEach((c) => {
905
- if (c.getColumnName() !== col.getColumnName()) {
906
- c.sort("NONE");
907
- }
908
- });
909
- col.sort(sortState);
910
- this.emit("columnSort", col);
911
- }
912
- /**
913
- * PLUGINS
914
- */
915
- getPluginOfType(clazz) {
916
- return this.state.plugins.find((plugin) => plugin instanceof clazz);
917
- }
918
- /**
919
- * Sets the plugins for the table.
920
- */
921
- setPlugins(cb) {
922
- this.state.plugins = cb(this.state.plugins);
923
- }
924
- getApplicablePlugins(method) {
925
- return this.state.plugins.filter((c) => c[method] !== void 0).map((c) => c[method].bind(c, this));
926
- }
927
- }
928
-
929
- function getRow(controller, rowElement) {
930
- const rowId = rowElement.dataset.rowid;
931
- const row = controller.getRowById(rowId);
932
- return row;
933
- }
934
- function selectBetweenRows(controller, rowA, rowB) {
935
- const relativePosition = rowA.compareDocumentPosition(rowB);
936
- let finished = false;
937
- if (relativePosition & Node.DOCUMENT_POSITION_FOLLOWING) {
938
- let current = rowA;
939
- if (rowA.closest("thead") && !rowB.closest("thead")) {
940
- current = rowA.closest("table")?.querySelector("tbody")?.firstElementChild;
941
- }
942
- while (!finished) {
943
- if (current) {
944
- getRow(controller, current)?.toggleSelection(true);
945
- finished = current === rowB;
946
- current = current.nextElementSibling;
947
- } else {
948
- finished = true;
949
- }
950
- }
951
- } else if (relativePosition & Node.DOCUMENT_POSITION_PRECEDING) {
952
- let current = rowA;
953
- while (!finished) {
954
- if (current) {
955
- getRow(controller, current)?.toggleSelection(true);
956
- finished = current === rowB;
957
- current = current.previousElementSibling;
958
- } else {
959
- finished = true;
960
- }
961
- }
962
- }
963
- }
964
- function useFocusByClick(controller) {
965
- const lastRow = useRef(null);
966
- return (ev) => {
967
- const { target } = ev;
968
- if (target instanceof HTMLElement) {
969
- const cellElement = target.closest("td[data-colname],th[data-colname]");
970
- const rowElement = target.closest("tr[data-rowid]");
971
- if (rowElement instanceof HTMLTableRowElement) {
972
- const row = getRow(controller, rowElement);
973
- if (row) {
974
- if (ev.shiftKey) {
975
- if (lastRow.current) {
976
- selectBetweenRows(controller, lastRow.current, rowElement);
977
- }
978
- } else if (ev.ctrlKey) {
979
- row?.toggleSelection();
980
- } else {
981
- controller.clearSelection();
982
- row?.toggleSelection(true);
983
- }
984
- lastRow.current = rowElement;
985
- if (cellElement instanceof HTMLTableCellElement) {
986
- const colName = cellElement.dataset.colname;
987
- const cell = row?.getCellByColumnName(colName);
988
- if (cell) {
989
- if (target.closest("thead")) {
990
- controller.emit("columnClick", cell);
991
- }
992
- cell?.focus(true);
993
- }
994
- }
995
- }
996
- }
997
- }
998
- };
999
- }
1000
-
1001
- const pageSize = 6;
1002
- function handleArrowKey(controller, ev) {
1003
- const { target } = ev;
1004
- if (target instanceof HTMLElement) {
1005
- const cellElement = target.closest("td[data-colname],th[data-colname]");
1006
- const rowElement = target.closest("tr[data-rowid]");
1007
- if (rowElement instanceof HTMLTableRowElement) {
1008
- if (cellElement instanceof HTMLTableCellElement) {
1009
- const colName = cellElement.dataset.colname;
1010
- let nextFocusedRow = rowElement;
1011
- let nextFocusedCell = cellElement;
1012
- switch (ev.code) {
1013
- case "ArrowUp": {
1014
- const test = rowElement?.previousElementSibling;
1015
- if (test) {
1016
- nextFocusedRow = test;
1017
- } else if (nextFocusedRow.closest("tbody")) {
1018
- const thead = nextFocusedRow.closest("table").querySelector("thead");
1019
- nextFocusedRow = thead.lastElementChild;
1020
- }
1021
- break;
1022
- }
1023
- case "ArrowDown": {
1024
- const test = rowElement?.nextElementSibling;
1025
- if (test) {
1026
- nextFocusedRow = test;
1027
- } else if (nextFocusedRow.closest("thead")) {
1028
- const tbody = nextFocusedRow.closest("table").querySelector("tbody");
1029
- nextFocusedRow = tbody.firstElementChild;
1030
- }
1031
- break;
1032
- }
1033
- case "ArrowLeft":
1034
- nextFocusedCell = cellElement.previousElementSibling;
1035
- break;
1036
- case "ArrowRight":
1037
- nextFocusedCell = cellElement.nextElementSibling;
1038
- break;
1039
- case "PageUp": {
1040
- let i = 0;
1041
- do {
1042
- const test = nextFocusedRow.previousElementSibling;
1043
- if (!test && nextFocusedRow.closest("tbody")) {
1044
- const thead = nextFocusedRow.closest("table").querySelector("thead");
1045
- nextFocusedRow = thead.lastElementChild;
1046
- } else if (test) {
1047
- nextFocusedRow = test;
1048
- }
1049
- } while (nextFocusedRow instanceof HTMLTableRowElement && ++i < pageSize);
1050
- break;
1051
- }
1052
- case "PageDown": {
1053
- let i = 0;
1054
- do {
1055
- const test = nextFocusedRow.nextElementSibling;
1056
- if (!test && nextFocusedRow.closest("thead")) {
1057
- const tbody = nextFocusedRow.closest("table").querySelector("tbody");
1058
- nextFocusedRow = tbody.firstElementChild;
1059
- } else if (test) {
1060
- nextFocusedRow = test;
1061
- }
1062
- } while (nextFocusedRow instanceof HTMLTableRowElement && ++i < pageSize);
1063
- break;
1064
- }
1065
- case "Home": {
1066
- if (ev.ctrlKey) {
1067
- nextFocusedRow = rowElement.closest("table")?.querySelector("thead tr");
1068
- } else {
1069
- nextFocusedCell = rowElement.firstElementChild;
1070
- }
1071
- break;
1072
- }
1073
- case "End":
1074
- if (ev.ctrlKey) {
1075
- nextFocusedRow = rowElement.closest("table").querySelector("tbody").lastElementChild;
1076
- } else {
1077
- nextFocusedCell = rowElement.lastChild;
1078
- }
1079
- }
1080
- if (nextFocusedCell !== cellElement && nextFocusedCell) {
1081
- getRow(controller, rowElement).getCellByColumnName(nextFocusedCell.dataset.colname).focus();
1082
- } else if (nextFocusedRow !== rowElement && nextFocusedRow) {
1083
- if (ev.shiftKey) {
1084
- selectBetweenRows(controller, rowElement, nextFocusedRow);
1085
- } else {
1086
- controller.clearSelection();
1087
- getRow(controller, nextFocusedRow)?.toggleSelection(true);
1088
- }
1089
- const cell = getRow(controller, nextFocusedRow).getCellByColumnName(colName) || getRow(controller, nextFocusedRow).getCellByIndex(0);
1090
- cell?.focus();
1091
- }
1092
- }
1093
- }
1094
- }
1095
- }
1096
- function useFocusByKey(controller) {
1097
- return (ev) => {
1098
- if (controller.isEditionMode) {
1099
- if (["Enter", "Escape"].includes(ev.code)) {
1100
- ev.preventDefault();
1101
- }
1102
- switch (ev.code) {
1103
- case "Enter":
1104
- controller.emit("keyEnter", null);
1105
- break;
1106
- case "Escape":
1107
- controller.toggleEditionMode(false);
1108
- }
1109
- } else {
1110
- if ([
1111
- "Escape",
1112
- "ArrowUp",
1113
- "ArrowDown",
1114
- "ArrowLeft",
1115
- "ArrowRight",
1116
- "PageUp",
1117
- "PageDown",
1118
- "Home",
1119
- "End"
1120
- ].includes(ev.code) || ev.code === "Enter" && controller.getState("allowEdition") || ev.code === "Space" && ev.ctrlKey) {
1121
- ev.preventDefault();
1122
- }
1123
- switch (ev.code) {
1124
- case "Enter":
1125
- controller.emit("keyEnter", null);
1126
- controller.toggleEditionMode();
1127
- break;
1128
- case "Space":
1129
- {
1130
- if (ev.ctrlKey) {
1131
- const row = ev.target?.closest("tr");
1132
- if (row instanceof HTMLElement) {
1133
- getRow(controller, row).toggleSelection();
1134
- }
1135
- }
1136
- }
1137
- break;
1138
- case "ArrowUp":
1139
- case "ArrowDown":
1140
- case "ArrowLeft":
1141
- case "ArrowRight":
1142
- case "Home":
1143
- case "End":
1144
- case "PageUp":
1145
- case "PageDown":
1146
- handleArrowKey(controller, ev);
1147
- break;
1148
- }
1149
- }
1150
- };
1151
- }
1152
-
1153
- var __defProp = Object.defineProperty;
1154
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1155
- var __publicField = (obj, key, value) => {
1156
- __defNormalProp(obj, key + "" , value);
1157
- return value;
1158
- };
1159
- function getCellElement(focusControllerRef, cell) {
1160
- return focusControllerRef.querySelector(
1161
- `tr[data-rowid="${cell.getRow().getState("id")}"] td[data-colname="${cell.getState("colName")}"], tr[data-rowid="${cell.getRow().getState("id")}"] th[data-colname="${cell.getState("colName")}"]`
1162
- );
1163
- }
1164
- function isVisible(el) {
1165
- if (!(el instanceof HTMLElement))
1166
- return false;
1167
- while (el) {
1168
- const style = getComputedStyle(el);
1169
- if (style.display === "none" || style.visibility === "hidden" || style.opacity === "0") {
1170
- return false;
1171
- }
1172
- el = el.parentElement;
1173
- }
1174
- return true;
1175
- }
1176
- function scrollIntoRow(row) {
1177
- if (row) {
1178
- scrollParentIntoElement(row, 150, 0, 0);
1179
- }
1180
- }
1181
- function restoreFocus(controller, tableElement, doFocus) {
1182
- const cell = controller.getFocusedCell();
1183
- if (cell) {
1184
- const cellElement = getCellElement(tableElement, cell);
1185
- if (cellElement) {
1186
- disableChildrenFocus(tableElement);
1187
- const widgets = cellElement.querySelectorAll(getFocusSelector());
1188
- const widget = [...widgets].find((c) => isVisible(c));
1189
- const focusableElement = widget || cellElement;
1190
- focusableElement.setAttribute("tabindex", "0");
1191
- restoreEditionMode(tableElement, cell.getTable().isEditionMode);
1192
- if (doFocus) {
1193
- focusableElement.focus();
1194
- }
1195
- }
1196
- }
1197
- }
1198
- function restoreEditionMode(focusController, editionMode) {
1199
- const focusable = focusController?.querySelector(
1200
- '[tabindex="0"]'
1201
- );
1202
- const cell = focusable?.closest("td, th");
1203
- if (cell instanceof HTMLElement) {
1204
- const widgets = cell.querySelectorAll(getFocusSelector());
1205
- widgets.forEach((widget) => {
1206
- widget.setAttribute("tabindex", editionMode ? "0" : "-1");
1207
- });
1208
- const firstFocusable = [...widgets].find((c) => isVisible(c)) || cell;
1209
- firstFocusable.setAttribute("tabindex", "0");
1210
- }
1211
- }
1212
- class FocusControllerPlugin {
1213
- constructor() {
1214
- __publicField(this, "rootElement", null);
1215
- }
1216
- scrollIntoView(rowId) {
1217
- const row = this.rootElement?.querySelector(
1218
- `tr[data-rowid="${rowId}"]`
1219
- );
1220
- if (row) {
1221
- scrollIntoRow(row);
1222
- }
1223
- }
1224
- useElementDomProps(controller, element, _context) {
1225
- if (element instanceof TableController) {
1226
- const disconnect = useRef(() => {
1227
- });
1228
- useMount(() => {
1229
- const uns1 = controller.on("cellFocus", (ev) => {
1230
- if (this.rootElement) {
1231
- restoreFocus(controller, this.rootElement, ev.doFocus);
1232
- }
1233
- });
1234
- const uns2 = controller.on("editionMode", (editionMode) => {
1235
- if (this.rootElement) {
1236
- restoreEditionMode(this.rootElement, editionMode);
1237
- }
1238
- });
1239
- const uns3 = controller.on("scrollIntoRow", (row) => {
1240
- this.scrollIntoView(row.getState("id"));
1241
- });
1242
- return () => {
1243
- uns1();
1244
- uns2();
1245
- uns3();
1246
- };
1247
- });
1248
- return {
1249
- className: "table__focus_controller",
1250
- onClick: useFocusByClick(controller),
1251
- onKeyDown: useFocusByKey(controller),
1252
- onBlur: (ev) => {
1253
- if (ev.relatedTarget instanceof HTMLElement && ev.relatedTarget.closest(".table__focus_controller") !== this.rootElement) {
1254
- controller.toggleEditionMode(false);
1255
- }
1256
- },
1257
- ref: (el) => {
1258
- this.rootElement = el;
1259
- if (el) {
1260
- const observer = new MutationObserver(() => {
1261
- restoreFocus(controller, this.rootElement, false);
1262
- });
1263
- disconnect.current?.();
1264
- observer.observe(el, { subtree: true, childList: true });
1265
- disconnect.current = () => {
1266
- observer.disconnect();
1267
- };
1268
- }
1269
- }
1270
- };
1271
- }
1272
- return {};
1273
- }
1274
- }
1275
-
1276
- class WaiAriaPlugin {
1277
- useElementDomProps(controller, element, context) {
1278
- if (element instanceof Row) {
1279
- const base = element.getContainer() === controller.head ? 0 : controller.head.rows.length;
1280
- return {
1281
- "aria-selected": element.isSelected,
1282
- "aria-rowindex": context + base + 1
1283
- };
1284
- } else if (element instanceof Cell) {
1285
- return {
1286
- "aria-colindex": context + 1
1287
- };
1288
- } else if (element instanceof TableController) {
1289
- return {
1290
- role: "treegrid",
1291
- "aria-multiselectable": controller.getState("allowSelection") && controller.getState("isSelectionMultiple") ? true : void 0,
1292
- "aria-colcount": controller.head.rows[0]?.cells.length || 0,
1293
- "aria-rowcount": controller.head.rows.length + controller.body.rows.length
1294
- };
1295
- }
1296
- return {};
1297
- }
1298
- }
1299
-
1300
- export { AdditionalCell, AdditionalRow, Cell, Column, Columns, DateFilter, Element, Filter, Filters, FocusControllerPlugin, Row, RowsGroup, TableBody, TableController, TableHead, WaiAriaPlugin, defaultPlugins };
1
+ export { AdditionalCell } from './data/primitive/AdditionalCell.js';
2
+ export { AdditionalRow } from './data/primitive/AdditionalRow.js';
3
+ export { Cell } from './data/primitive/Cell.js';
4
+ export { Row } from './data/primitive/Row.js';
5
+ export { TableController } from './data/TableController.js';
6
+ export { TableBody } from './data/body/TableBody.js';
7
+ export { defaultPlugins } from './data/plugins/TablePlugin.js';
8
+ export { FocusControllerPlugin } from './data/plugins/FocusControllerPlugin/index.js';
9
+ export { WaiAriaPlugin } from './data/plugins/WaiAriaPlugin.js';
10
+ export { Element } from './data/primitive/Element.js';
11
+ export { RowsGroup } from './data/primitive/RowsGroup.js';
12
+ export { Filter } from './data/filter/Filter.js';
13
+ export { DateFilter } from './data/filter/DateFilter.js';
14
+ export { TableHead } from './data/head/TableHead.js';
15
+ export { Column } from './data/head/Column.js';
16
+ export { Columns } from './data/head/Columns.js';
17
+ export { Filters } from './data/head/Filters.js';
18
+ export { DateRangeFilter } from './data/filter/DateRangeFilter.js';
19
+ export { DateTimeRangeFilter } from './data/filter/DateTimeRangeFilter.js';
20
+ export { ComboFilter } from './data/filter/ComboFilter.js';
1301
21
  //# sourceMappingURL=index.js.map