@humanspeak/svelte-headless-table 6.0.1 → 6.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 (78) hide show
  1. package/README.md +2 -2
  2. package/dist/bodyCells.d.ts +116 -0
  3. package/dist/bodyCells.js +80 -0
  4. package/dist/bodyRows.d.ts +92 -0
  5. package/dist/bodyRows.js +55 -0
  6. package/dist/columns.d.ts +204 -0
  7. package/dist/columns.js +120 -0
  8. package/dist/constants.d.ts +4 -0
  9. package/dist/constants.js +4 -0
  10. package/dist/createTable.d.ts +107 -0
  11. package/dist/createTable.js +92 -0
  12. package/dist/createViewModel.d.ts +105 -2
  13. package/dist/createViewModel.js +55 -1
  14. package/dist/headerCells.d.ts +210 -0
  15. package/dist/headerCells.js +151 -0
  16. package/dist/headerRows.d.ts +72 -0
  17. package/dist/headerRows.js +60 -0
  18. package/dist/plugins/addColumnFilters.d.ts +101 -0
  19. package/dist/plugins/addColumnFilters.js +55 -0
  20. package/dist/plugins/addColumnOrder.d.ts +30 -0
  21. package/dist/plugins/addColumnOrder.js +21 -0
  22. package/dist/plugins/addDataExport.d.ts +51 -0
  23. package/dist/plugins/addDataExport.js +30 -0
  24. package/dist/plugins/addExpandedRows.d.ts +43 -2
  25. package/dist/plugins/addExpandedRows.js +48 -2
  26. package/dist/plugins/addFlatten.d.ts +48 -3
  27. package/dist/plugins/addFlatten.js +28 -0
  28. package/dist/plugins/addGridLayout.d.ts +13 -0
  29. package/dist/plugins/addGridLayout.js +13 -0
  30. package/dist/plugins/addGroupBy.d.ts +80 -4
  31. package/dist/plugins/addGroupBy.js +48 -4
  32. package/dist/plugins/addHiddenColumns.d.ts +27 -0
  33. package/dist/plugins/addHiddenColumns.js +19 -0
  34. package/dist/plugins/addPagination.d.ts +54 -0
  35. package/dist/plugins/addPagination.js +29 -0
  36. package/dist/plugins/addResizedColumns.d.ts +58 -4
  37. package/dist/plugins/addResizedColumns.js +33 -0
  38. package/dist/plugins/addSelectedRows.d.ts +60 -2
  39. package/dist/plugins/addSelectedRows.js +67 -2
  40. package/dist/plugins/addSortBy.d.ts +83 -6
  41. package/dist/plugins/addSortBy.js +65 -24
  42. package/dist/plugins/addSubRows.d.ts +39 -1
  43. package/dist/plugins/addSubRows.js +25 -0
  44. package/dist/plugins/addTableFilter.d.ts +87 -3
  45. package/dist/plugins/addTableFilter.js +90 -40
  46. package/dist/plugins/cacheConfig.d.ts +7 -0
  47. package/dist/plugins/cacheConfig.js +11 -0
  48. package/dist/tableComponent.d.ts +41 -0
  49. package/dist/tableComponent.js +37 -0
  50. package/dist/types/Action.d.ts +16 -2
  51. package/dist/types/Entries.d.ts +6 -0
  52. package/dist/types/KeyPath.d.ts +20 -0
  53. package/dist/types/Label.d.ts +26 -3
  54. package/dist/types/Matrix.d.ts +6 -0
  55. package/dist/types/TablePlugin.d.ts +140 -10
  56. package/dist/utils/array.d.ts +24 -0
  57. package/dist/utils/array.js +24 -0
  58. package/dist/utils/attributes.d.ts +31 -0
  59. package/dist/utils/attributes.js +31 -0
  60. package/dist/utils/clone.d.ts +19 -0
  61. package/dist/utils/clone.js +13 -0
  62. package/dist/utils/compare.d.ts +29 -0
  63. package/dist/utils/compare.js +29 -0
  64. package/dist/utils/counter.d.ts +12 -0
  65. package/dist/utils/counter.js +12 -0
  66. package/dist/utils/css.d.ts +11 -0
  67. package/dist/utils/css.js +11 -0
  68. package/dist/utils/event.d.ts +14 -0
  69. package/dist/utils/event.js +14 -0
  70. package/dist/utils/filter.d.ts +47 -0
  71. package/dist/utils/filter.js +47 -0
  72. package/dist/utils/math.d.ts +22 -0
  73. package/dist/utils/math.js +22 -0
  74. package/dist/utils/matrix.d.ts +24 -0
  75. package/dist/utils/matrix.js +24 -0
  76. package/dist/utils/store.d.ts +116 -9
  77. package/dist/utils/store.js +63 -0
  78. package/package.json +31 -30
@@ -1,16 +1,37 @@
1
1
  import { NBSP } from './constants.js';
2
2
  import { TableComponent } from './tableComponent.js';
3
3
  import { derived } from 'svelte/store';
4
+ /**
5
+ * Abstract base class representing a cell in the table header.
6
+ * Extended by FlatHeaderCell, DataHeaderCell, GroupHeaderCell, etc.
7
+ *
8
+ * @template Item - The type of data items in the table.
9
+ * @template Plugins - The plugins used by the table.
10
+ */
4
11
  export class HeaderCell extends TableComponent {
12
+ /** Label content or render function for the header. */
5
13
  label;
14
+ /** Number of columns this cell spans. */
6
15
  colspan;
16
+ /** Starting column index. */
7
17
  colstart;
18
+ /**
19
+ * Creates a new HeaderCell.
20
+ *
21
+ * @param init - Initialization options.
22
+ */
8
23
  constructor({ id, label, colspan, colstart }) {
9
24
  super({ id });
10
25
  this.label = label;
11
26
  this.colspan = colspan;
12
27
  this.colstart = colstart;
13
28
  }
29
+ /**
30
+ * Renders the header cell content.
31
+ *
32
+ * @returns The render configuration for displaying this cell.
33
+ * @throws Error if state reference is missing when using a function label.
34
+ */
14
35
  render() {
15
36
  if (this.label instanceof Function) {
16
37
  if (this.state === undefined) {
@@ -20,6 +41,11 @@ export class HeaderCell extends TableComponent {
20
41
  }
21
42
  return this.label;
22
43
  }
44
+ /**
45
+ * Gets the HTML attributes for this header cell.
46
+ *
47
+ * @returns A readable store of cell attributes.
48
+ */
23
49
  attrs() {
24
50
  return derived(super.attrs(), ($baseAttrs) => {
25
51
  return {
@@ -29,33 +55,75 @@ export class HeaderCell extends TableComponent {
29
55
  };
30
56
  });
31
57
  }
58
+ /**
59
+ * Type guard to check if this is a flat header cell.
60
+ *
61
+ * @returns True if this is a FlatHeaderCell.
62
+ */
32
63
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
33
64
  isFlat() {
34
65
  return '__flat' in this;
35
66
  }
67
+ /**
68
+ * Type guard to check if this is a data header cell.
69
+ *
70
+ * @returns True if this is a DataHeaderCell.
71
+ */
36
72
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
37
73
  isData() {
38
74
  return '__data' in this;
39
75
  }
76
+ /**
77
+ * Type guard to check if this is a flat display header cell.
78
+ *
79
+ * @returns True if this is a FlatDisplayHeaderCell.
80
+ */
40
81
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
41
82
  isFlatDisplay() {
42
83
  return '__flat' in this && '__display' in this;
43
84
  }
85
+ /**
86
+ * Type guard to check if this is a group header cell.
87
+ *
88
+ * @returns True if this is a GroupHeaderCell.
89
+ */
44
90
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
45
91
  isGroup() {
46
92
  return '__group' in this;
47
93
  }
94
+ /**
95
+ * Type guard to check if this is a group display header cell.
96
+ *
97
+ * @returns True if this is a GroupDisplayHeaderCell.
98
+ */
48
99
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
49
100
  isGroupDisplay() {
50
101
  return '__group' in this && '__display' in this;
51
102
  }
52
103
  }
104
+ /**
105
+ * A flat (non-grouped) header cell that spans a single column.
106
+ * Base class for DataHeaderCell and FlatDisplayHeaderCell.
107
+ *
108
+ * @template Item - The type of data items in the table.
109
+ * @template Plugins - The plugins used by the table.
110
+ */
53
111
  export class FlatHeaderCell extends HeaderCell {
54
112
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
55
113
  __flat = true;
114
+ /**
115
+ * Creates a new FlatHeaderCell.
116
+ *
117
+ * @param init - Initialization options.
118
+ */
56
119
  constructor({ id, label, colstart }) {
57
120
  super({ id, label, colspan: 1, colstart });
58
121
  }
122
+ /**
123
+ * Creates a copy of this header cell.
124
+ *
125
+ * @returns A cloned FlatHeaderCell.
126
+ */
59
127
  clone() {
60
128
  return new FlatHeaderCell({
61
129
  id: this.id,
@@ -64,17 +132,36 @@ export class FlatHeaderCell extends HeaderCell {
64
132
  });
65
133
  }
66
134
  }
135
+ /**
136
+ * A header cell for a data column that displays values from the data source.
137
+ * Contains accessor information for retrieving cell values.
138
+ *
139
+ * @template Item - The type of data items in the table.
140
+ * @template Plugins - The plugins used by the table.
141
+ */
67
142
  export class DataHeaderCell extends FlatHeaderCell {
68
143
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
69
144
  __data = true;
145
+ /** The key used to access data from the item. */
70
146
  accessorKey;
147
+ /** Function to extract data from the item. */
71
148
  /* trunk-ignore(eslint/no-unused-vars) */
72
149
  accessorFn;
150
+ /**
151
+ * Creates a new DataHeaderCell.
152
+ *
153
+ * @param init - Initialization options.
154
+ */
73
155
  constructor({ id, label, accessorKey, accessorFn, colstart }) {
74
156
  super({ id, label, colstart });
75
157
  this.accessorKey = accessorKey;
76
158
  this.accessorFn = accessorFn;
77
159
  }
160
+ /**
161
+ * Creates a copy of this header cell.
162
+ *
163
+ * @returns A cloned DataHeaderCell.
164
+ */
78
165
  clone() {
79
166
  return new DataHeaderCell({
80
167
  id: this.id,
@@ -85,12 +172,29 @@ export class DataHeaderCell extends FlatHeaderCell {
85
172
  });
86
173
  }
87
174
  }
175
+ /**
176
+ * A flat header cell for display-only columns (e.g., action columns).
177
+ * Does not contain data accessor information.
178
+ *
179
+ * @template Item - The type of data items in the table.
180
+ * @template Plugins - The plugins used by the table.
181
+ */
88
182
  export class FlatDisplayHeaderCell extends FlatHeaderCell {
89
183
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
90
184
  __display = true;
185
+ /**
186
+ * Creates a new FlatDisplayHeaderCell.
187
+ *
188
+ * @param init - Initialization options.
189
+ */
91
190
  constructor({ id, label = NBSP, colstart }) {
92
191
  super({ id, label, colstart });
93
192
  }
193
+ /**
194
+ * Creates a copy of this header cell.
195
+ *
196
+ * @returns A cloned FlatDisplayHeaderCell.
197
+ */
94
198
  clone() {
95
199
  return new FlatDisplayHeaderCell({
96
200
  id: this.id,
@@ -99,26 +203,56 @@ export class FlatDisplayHeaderCell extends FlatHeaderCell {
99
203
  });
100
204
  }
101
205
  }
206
+ /**
207
+ * A header cell that spans multiple columns, used for column grouping.
208
+ * Contains information about which columns are part of the group.
209
+ *
210
+ * @template Item - The type of data items in the table.
211
+ * @template Plugins - The plugins used by the table.
212
+ */
102
213
  export class GroupHeaderCell extends HeaderCell {
103
214
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
104
215
  __group = true;
216
+ /** Current column IDs covered by this group. */
105
217
  ids;
218
+ /** Combined ID string for all columns in the original group. */
106
219
  allId;
220
+ /** All column IDs in the original group definition. */
107
221
  allIds;
222
+ /**
223
+ * Creates a new GroupHeaderCell.
224
+ *
225
+ * @param init - Initialization options.
226
+ */
108
227
  constructor({ label, ids, allIds, colspan, colstart }) {
109
228
  super({ id: `[${ids.join(',')}]`, label, colspan, colstart });
110
229
  this.ids = ids;
111
230
  this.allId = `[${allIds.join(',')}]`;
112
231
  this.allIds = allIds;
113
232
  }
233
+ /**
234
+ * Sets the column IDs covered by this group and updates the cell ID.
235
+ *
236
+ * @param ids - The new array of column IDs.
237
+ */
114
238
  setIds(ids) {
115
239
  this.ids = ids;
116
240
  this.id = `[${this.ids.join(',')}]`;
117
241
  }
242
+ /**
243
+ * Adds a column ID to this group and updates the cell ID.
244
+ *
245
+ * @param id - The column ID to add.
246
+ */
118
247
  pushId(id) {
119
248
  this.ids = [...this.ids, id];
120
249
  this.id = `[${this.ids.join(',')}]`;
121
250
  }
251
+ /**
252
+ * Creates a copy of this header cell.
253
+ *
254
+ * @returns A cloned GroupHeaderCell.
255
+ */
122
256
  clone() {
123
257
  return new GroupHeaderCell({
124
258
  label: this.label,
@@ -129,12 +263,29 @@ export class GroupHeaderCell extends HeaderCell {
129
263
  });
130
264
  }
131
265
  }
266
+ /**
267
+ * A group header cell for display purposes (e.g., empty group headers).
268
+ * Used to fill gaps in the header row matrix.
269
+ *
270
+ * @template Item - The type of data items in the table.
271
+ * @template Plugins - The plugins used by the table.
272
+ */
132
273
  export class GroupDisplayHeaderCell extends GroupHeaderCell {
133
274
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
134
275
  __display = true;
276
+ /**
277
+ * Creates a new GroupDisplayHeaderCell.
278
+ *
279
+ * @param init - Initialization options.
280
+ */
135
281
  constructor({ label = NBSP, ids, allIds, colspan = 1, colstart }) {
136
282
  super({ label, ids, allIds, colspan, colstart });
137
283
  }
284
+ /**
285
+ * Creates a copy of this header cell.
286
+ *
287
+ * @returns A cloned GroupDisplayHeaderCell.
288
+ */
138
289
  clone() {
139
290
  return new GroupDisplayHeaderCell({
140
291
  label: this.label,
@@ -3,24 +3,96 @@ import { type HeaderCell } from './headerCells.js';
3
3
  import { TableComponent } from './tableComponent.js';
4
4
  import type { Matrix } from './types/Matrix.js';
5
5
  import type { AnyPlugins } from './types/TablePlugin.js';
6
+ /**
7
+ * HTML attributes for a header row element.
8
+ *
9
+ * @template Item - The type of data items in the table.
10
+ * @template Plugins - The plugins used by the table.
11
+ */
6
12
  export type HeaderRowAttributes<Item, Plugins extends AnyPlugins = AnyPlugins> = {
7
13
  role: 'row';
8
14
  };
15
+ /**
16
+ * Initialization options for creating a HeaderRow.
17
+ *
18
+ * @template Item - The type of data items in the table.
19
+ * @template Plugins - The plugins used by the table.
20
+ */
9
21
  export interface HeaderRowInit<Item, Plugins extends AnyPlugins = AnyPlugins> {
10
22
  id: string;
11
23
  cells: HeaderCell<Item, Plugins>[];
12
24
  }
25
+ /**
26
+ * Represents a row in the table header.
27
+ * Contains header cells for column labels and group headers.
28
+ *
29
+ * @template Item - The type of data items in the table.
30
+ * @template Plugins - The plugins used by the table.
31
+ */
13
32
  export declare class HeaderRow<Item, Plugins extends AnyPlugins = AnyPlugins> extends TableComponent<Item, Plugins, 'thead.tr'> {
33
+ /** The header cells in this row. */
14
34
  cells: HeaderCell<Item, Plugins>[];
35
+ /**
36
+ * Creates a new HeaderRow.
37
+ *
38
+ * @param init - Initialization options.
39
+ */
15
40
  constructor({ id, cells }: HeaderRowInit<Item, Plugins>);
41
+ /**
42
+ * Gets the HTML attributes for this header row.
43
+ *
44
+ * @returns A readable store of row attributes.
45
+ */
16
46
  attrs(): import("svelte/store").Readable<{
17
47
  role: "row";
18
48
  }>;
49
+ /**
50
+ * Creates a copy of this header row.
51
+ *
52
+ * @returns A cloned HeaderRow.
53
+ */
19
54
  clone(): HeaderRow<Item, Plugins>;
20
55
  }
56
+ /**
57
+ * Converts an array of columns into header rows for rendering.
58
+ * Handles nested column groups by creating multiple header rows.
59
+ *
60
+ * @template Item - The type of data items in the table.
61
+ * @template Plugins - The plugins used by the table.
62
+ * @param columns - The column definitions.
63
+ * @param flatColumnIds - Optional array of column IDs for ordering.
64
+ * @returns An array of HeaderRow objects.
65
+ */
21
66
  export declare const getHeaderRows: <Item, Plugins extends AnyPlugins = AnyPlugins>(columns: Column<Item, Plugins>[], flatColumnIds?: string[]) => HeaderRow<Item, Plugins>[];
67
+ /**
68
+ * Creates a matrix of header cells from column definitions.
69
+ * Each row in the matrix represents a header row, with cells positioned
70
+ * according to their column spans.
71
+ *
72
+ * @template Item - The type of data items in the table.
73
+ * @template Plugins - The plugins used by the table.
74
+ * @param columns - The column definitions.
75
+ * @returns A matrix of HeaderCell objects.
76
+ */
22
77
  export declare const getHeaderRowMatrix: <Item, Plugins extends AnyPlugins = AnyPlugins>(columns: Column<Item, Plugins>[]) => Matrix<HeaderCell<Item, Plugins>>;
78
+ /**
79
+ * Reorders a column matrix according to the specified column ID order.
80
+ *
81
+ * @template Item - The type of data items in the table.
82
+ * @template Plugins - The plugins used by the table.
83
+ * @param columnMatrix - The original column matrix.
84
+ * @param flatColumnIds - The desired order of column IDs.
85
+ * @returns A reordered column matrix.
86
+ */
23
87
  export declare const getOrderedColumnMatrix: <Item, Plugins extends AnyPlugins = AnyPlugins>(columnMatrix: Matrix<HeaderCell<Item, Plugins>>, flatColumnIds: string[]) => Matrix<HeaderCell<Item, Plugins>>;
88
+ /**
89
+ * Converts a row matrix into an array of HeaderRow objects.
90
+ *
91
+ * @template Item - The type of data items in the table.
92
+ * @template Plugins - The plugins used by the table.
93
+ * @param rowMatrix - The matrix of header cells organized by rows.
94
+ * @returns An array of HeaderRow objects.
95
+ */
24
96
  export declare const headerRowsForRowMatrix: <Item, Plugins extends AnyPlugins = AnyPlugins>(rowMatrix: Matrix<HeaderCell<Item, Plugins>>) => HeaderRow<Item, Plugins>[];
25
97
  /**
26
98
  * Multi-colspan cells will appear as multiple adjacent cells on the same row.
@@ -3,12 +3,30 @@ import { TableComponent } from './tableComponent.js';
3
3
  import { sum } from './utils/math.js';
4
4
  import { getNullMatrix, getTransposed } from './utils/matrix.js';
5
5
  import { derived } from 'svelte/store';
6
+ /**
7
+ * Represents a row in the table header.
8
+ * Contains header cells for column labels and group headers.
9
+ *
10
+ * @template Item - The type of data items in the table.
11
+ * @template Plugins - The plugins used by the table.
12
+ */
6
13
  export class HeaderRow extends TableComponent {
14
+ /** The header cells in this row. */
7
15
  cells;
16
+ /**
17
+ * Creates a new HeaderRow.
18
+ *
19
+ * @param init - Initialization options.
20
+ */
8
21
  constructor({ id, cells }) {
9
22
  super({ id });
10
23
  this.cells = cells;
11
24
  }
25
+ /**
26
+ * Gets the HTML attributes for this header row.
27
+ *
28
+ * @returns A readable store of row attributes.
29
+ */
12
30
  attrs() {
13
31
  return derived(super.attrs(), ($baseAttrs) => {
14
32
  return {
@@ -17,6 +35,11 @@ export class HeaderRow extends TableComponent {
17
35
  };
18
36
  });
19
37
  }
38
+ /**
39
+ * Creates a copy of this header row.
40
+ *
41
+ * @returns A cloned HeaderRow.
42
+ */
20
43
  clone() {
21
44
  return new HeaderRow({
22
45
  id: this.id,
@@ -24,6 +47,16 @@ export class HeaderRow extends TableComponent {
24
47
  });
25
48
  }
26
49
  }
50
+ /**
51
+ * Converts an array of columns into header rows for rendering.
52
+ * Handles nested column groups by creating multiple header rows.
53
+ *
54
+ * @template Item - The type of data items in the table.
55
+ * @template Plugins - The plugins used by the table.
56
+ * @param columns - The column definitions.
57
+ * @param flatColumnIds - Optional array of column IDs for ordering.
58
+ * @returns An array of HeaderRow objects.
59
+ */
27
60
  export const getHeaderRows = (columns, flatColumnIds = []) => {
28
61
  const rowMatrix = getHeaderRowMatrix(columns);
29
62
  // Perform all column operations on the transposed columnMatrix. This helps
@@ -34,6 +67,16 @@ export const getHeaderRows = (columns, flatColumnIds = []) => {
34
67
  populateGroupHeaderCellIds(columnMatrix);
35
68
  return headerRowsForRowMatrix(getTransposed(columnMatrix));
36
69
  };
70
+ /**
71
+ * Creates a matrix of header cells from column definitions.
72
+ * Each row in the matrix represents a header row, with cells positioned
73
+ * according to their column spans.
74
+ *
75
+ * @template Item - The type of data items in the table.
76
+ * @template Plugins - The plugins used by the table.
77
+ * @param columns - The column definitions.
78
+ * @returns A matrix of HeaderCell objects.
79
+ */
37
80
  export const getHeaderRowMatrix = (columns) => {
38
81
  const maxColspan = sum(columns.map((c) => (c.isGroup() ? c.ids.length : 1)));
39
82
  const maxHeight = Math.max(...columns.map((c) => c.height));
@@ -96,6 +139,15 @@ const loadHeaderRowMatrix = (rowMatrix, column, rowOffset, cellOffset) => {
96
139
  return;
97
140
  }
98
141
  };
142
+ /**
143
+ * Reorders a column matrix according to the specified column ID order.
144
+ *
145
+ * @template Item - The type of data items in the table.
146
+ * @template Plugins - The plugins used by the table.
147
+ * @param columnMatrix - The original column matrix.
148
+ * @param flatColumnIds - The desired order of column IDs.
149
+ * @returns A reordered column matrix.
150
+ */
99
151
  export const getOrderedColumnMatrix = (columnMatrix, flatColumnIds) => {
100
152
  if (flatColumnIds.length === 0) {
101
153
  return columnMatrix;
@@ -134,6 +186,14 @@ const populateGroupHeaderCellIds = (columnMatrix) => {
134
186
  });
135
187
  });
136
188
  };
189
+ /**
190
+ * Converts a row matrix into an array of HeaderRow objects.
191
+ *
192
+ * @template Item - The type of data items in the table.
193
+ * @template Plugins - The plugins used by the table.
194
+ * @param rowMatrix - The matrix of header cells organized by rows.
195
+ * @returns An array of HeaderRow objects.
196
+ */
137
197
  export const headerRowsForRowMatrix = (rowMatrix) => {
138
198
  return rowMatrix.map((rowCells, rowIdx) => {
139
199
  return new HeaderRow({ id: rowIdx.toString(), cells: getMergedRow(rowCells) });
@@ -3,37 +3,138 @@ import { type Readable, type Writable } from 'svelte/store';
3
3
  import type { BodyRow } from '../bodyRows.js';
4
4
  import type { PluginInitTableState } from '../createViewModel.js';
5
5
  import type { NewTablePropSet, TablePlugin } from '../types/TablePlugin.js';
6
+ /**
7
+ * Configuration options for the addColumnFilters plugin.
8
+ */
6
9
  export interface ColumnFiltersConfig {
10
+ /** If true, filtering is handled server-side and all rows are returned. */
7
11
  serverSide?: boolean;
8
12
  }
13
+ /**
14
+ * State exposed by the addColumnFilters plugin.
15
+ *
16
+ * @template Item - The type of data items in the table.
17
+ */
9
18
  export interface ColumnFiltersState<Item> {
19
+ /** Writable store containing filter values keyed by column ID. */
10
20
  filterValues: Writable<Record<string, unknown>>;
21
+ /** Readable store containing rows before filtering was applied. */
11
22
  preFilteredRows: Readable<BodyRow<Item>[]>;
12
23
  }
24
+ /**
25
+ * Per-column configuration options for column filters.
26
+ *
27
+ * @template Item - The type of data items in the table.
28
+ * @template FilterValue - The type of the filter value.
29
+ */
13
30
  export interface ColumnFiltersColumnOptions<Item, FilterValue = any> {
31
+ /** The filter function to use for this column. */
14
32
  fn: ColumnFilterFn<FilterValue>;
33
+ /** Initial filter value for this column. */
15
34
  initialFilterValue?: FilterValue;
35
+ /** Optional render function for custom filter UI. */
16
36
  render?: (props: ColumnRenderConfigPropArgs<Item, FilterValue>) => RenderConfig;
17
37
  }
38
+ /**
39
+ * Props passed to the column filter render function.
40
+ *
41
+ * @template Item - The type of data items.
42
+ * @template FilterValue - The type of the filter value.
43
+ * @template Value - The type of cell values.
44
+ */
18
45
  interface ColumnRenderConfigPropArgs<Item, FilterValue = any, Value = any> extends PluginInitTableState<Item> {
46
+ /** The column ID. */
19
47
  id: string;
48
+ /** Writable store for the filter value. */
20
49
  filterValue: Writable<FilterValue>;
50
+ /** Readable store of all current column values (after filtering). */
21
51
  values: Readable<Value[]>;
52
+ /** Readable store of rows before filtering. */
22
53
  preFilteredRows: Readable<BodyRow<Item>[]>;
54
+ /** Readable store of all column values before filtering. */
23
55
  preFilteredValues: Readable<Value[]>;
24
56
  }
57
+ /**
58
+ * Function type for column filter implementations.
59
+ *
60
+ * @template FilterValue - The type of the filter value.
61
+ * @template Value - The type of cell values.
62
+ */
25
63
  export type ColumnFilterFn<FilterValue = any, Value = any> = (props: ColumnFilterFnProps<FilterValue, Value>) => boolean;
64
+ /**
65
+ * Props passed to a ColumnFilterFn.
66
+ *
67
+ * @template FilterValue - The type of the filter value.
68
+ * @template Value - The type of cell values.
69
+ */
26
70
  export type ColumnFilterFnProps<FilterValue = any, Value = any> = {
71
+ /** The current filter value for this column. */
27
72
  filterValue: FilterValue;
73
+ /** The cell value being tested. */
28
74
  value: Value;
29
75
  };
76
+ /**
77
+ * Props added to header cells by the column filters plugin.
78
+ */
30
79
  export type ColumnFiltersPropSet = NewTablePropSet<{
31
80
  'thead.tr.th': {
81
+ /** The rendered filter component. */
32
82
  render?: RenderConfig;
33
83
  } | undefined;
34
84
  }>;
85
+ /**
86
+ * Creates a column filters plugin that enables per-column filtering with custom filter functions.
87
+ *
88
+ * @template Item - The type of data items in the table.
89
+ * @param config - Configuration options.
90
+ * @returns A TablePlugin that provides column filtering functionality.
91
+ * @example
92
+ * ```typescript
93
+ * const table = createTable(data, {
94
+ * colFilter: addColumnFilters()
95
+ * })
96
+ *
97
+ * // Configure per-column in column definitions:
98
+ * table.column({
99
+ * accessor: 'status',
100
+ * header: 'Status',
101
+ * plugins: {
102
+ * colFilter: {
103
+ * fn: matchFilter,
104
+ * initialFilterValue: undefined
105
+ * }
106
+ * }
107
+ * })
108
+ * ```
109
+ */
35
110
  export declare const addColumnFilters: <Item>({ serverSide }?: ColumnFiltersConfig) => TablePlugin<Item, ColumnFiltersState<Item>, ColumnFiltersColumnOptions<Item>, ColumnFiltersPropSet>;
111
+ /**
112
+ * A filter function that matches exact values.
113
+ * Returns true if filterValue is undefined or equals the cell value.
114
+ *
115
+ * @param props - The filter props containing filterValue and value.
116
+ * @returns True if the value matches the filter.
117
+ */
36
118
  export declare const matchFilter: ColumnFilterFn<unknown, unknown>;
119
+ /**
120
+ * A filter function that matches text by prefix (case-insensitive).
121
+ * Returns true if filterValue is empty or value starts with filterValue.
122
+ *
123
+ * @param props - The filter props containing filterValue and value.
124
+ * @returns True if the value starts with the filter text.
125
+ */
37
126
  export declare const textPrefixFilter: ColumnFilterFn<string, string>;
127
+ /**
128
+ * A filter function that matches numbers within a range.
129
+ * The range is [min, max] inclusive. Use null for unbounded.
130
+ *
131
+ * @param props - The filter props with a [min, max] filterValue and numeric value.
132
+ * @returns True if the value is within the specified range.
133
+ * @example
134
+ * ```typescript
135
+ * numberRangeFilter({ filterValue: [10, 50], value: 25 }) // true
136
+ * numberRangeFilter({ filterValue: [null, 100], value: 50 }) // true (no min)
137
+ * ```
138
+ */
38
139
  export declare const numberRangeFilter: ColumnFilterFn<[number | null, number | null], number>;
39
140
  export {};