@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
package/dist/columns.d.ts CHANGED
@@ -2,74 +2,278 @@ import type { DisplayBodyCell } from './bodyCells.js';
2
2
  import type { TableState } from './createViewModel.js';
3
3
  import type { DataLabel, DisplayLabel, HeaderLabel } from './types/Label.js';
4
4
  import type { AnyPlugins, PluginColumnConfigs } from './types/TablePlugin.js';
5
+ /**
6
+ * Initialization options for a Column.
7
+ *
8
+ * @template Item - The type of data items in the table.
9
+ * @template Plugins - The plugins configuration type.
10
+ */
5
11
  export interface ColumnInit<Item, Plugins extends AnyPlugins = AnyPlugins> {
12
+ /** The header label or render function. */
6
13
  header: HeaderLabel<Item, Plugins>;
14
+ /** Optional footer label or render function. */
7
15
  footer?: HeaderLabel<Item, Plugins>;
16
+ /** The height of the column in header rows (for grouping). */
8
17
  height: number;
18
+ /** Plugin-specific column configuration. */
9
19
  plugins?: PluginColumnConfigs<Plugins>;
10
20
  }
21
+ /**
22
+ * Base class for all column types in the table.
23
+ * Provides type guards for determining the specific column type.
24
+ *
25
+ * @template Item - The type of data items in the table.
26
+ * @template Plugins - The plugins configuration type.
27
+ */
11
28
  export declare class Column<Item, Plugins extends AnyPlugins = AnyPlugins> {
29
+ /** The header label or render function. */
12
30
  header: HeaderLabel<Item, Plugins>;
31
+ /** Optional footer label or render function. */
13
32
  footer?: HeaderLabel<Item, Plugins>;
33
+ /** The height of the column in header rows. */
14
34
  height: number;
35
+ /** Plugin-specific column configuration. */
15
36
  plugins?: PluginColumnConfigs<Plugins>;
37
+ /**
38
+ * Creates a new Column instance.
39
+ *
40
+ * @param init - The column initialization options.
41
+ */
16
42
  constructor({ header, footer, height, plugins }: ColumnInit<Item, Plugins>);
43
+ /**
44
+ * Type guard to check if this column is a FlatColumn (DataColumn or DisplayColumn).
45
+ *
46
+ * @returns True if this is a FlatColumn.
47
+ */
17
48
  isFlat(): this is FlatColumn<Item, Plugins>;
49
+ /**
50
+ * Type guard to check if this column is a DataColumn.
51
+ *
52
+ * @returns True if this is a DataColumn.
53
+ */
18
54
  isData(): this is DataColumn<Item, Plugins>;
55
+ /**
56
+ * Type guard to check if this column is a DisplayColumn.
57
+ *
58
+ * @returns True if this is a DisplayColumn.
59
+ */
19
60
  isDisplay(): this is DisplayColumn<Item, Plugins>;
61
+ /**
62
+ * Type guard to check if this column is a GroupColumn.
63
+ *
64
+ * @returns True if this is a GroupColumn.
65
+ */
20
66
  isGroup(): this is GroupColumn<Item, Plugins>;
21
67
  }
68
+ /**
69
+ * Initialization options for a FlatColumn.
70
+ * Height is always 1 for flat columns.
71
+ *
72
+ * @template Item - The type of data items in the table.
73
+ * @template Plugins - The plugins configuration type.
74
+ * @template Id - The column ID type.
75
+ */
22
76
  export type FlatColumnInit<Item, Plugins extends AnyPlugins = AnyPlugins, Id extends string = any> = Omit<ColumnInit<Item, Plugins>, 'height'> & {
77
+ /** Optional unique identifier for the column. Defaults to the header string. */
23
78
  id?: Id;
24
79
  };
80
+ /**
81
+ * A column that occupies a single row in the header (not a group).
82
+ * Base class for DataColumn and DisplayColumn.
83
+ *
84
+ * @template Item - The type of data items in the table.
85
+ * @template Plugins - The plugins configuration type.
86
+ * @template Id - The column ID type.
87
+ */
25
88
  export declare class FlatColumn<Item, Plugins extends AnyPlugins = AnyPlugins, Id extends string = any> extends Column<Item, Plugins> {
26
89
  __flat: boolean;
90
+ /** The unique identifier for this column. */
27
91
  id: Id;
92
+ /**
93
+ * Creates a new FlatColumn instance.
94
+ *
95
+ * @param init - The column initialization options.
96
+ */
28
97
  constructor({ header, footer, plugins, id }: FlatColumnInit<Item, Plugins>);
29
98
  }
99
+ /**
100
+ * Full initialization type for a DataColumn.
101
+ * Supports three accessor patterns: key only, key with ID, or function with ID.
102
+ *
103
+ * @template Item - The type of data items in the table.
104
+ * @template Plugins - The plugins configuration type.
105
+ * @template Id - The column ID type.
106
+ * @template Value - The type of the cell value.
107
+ */
30
108
  export type DataColumnInit<Item, Plugins extends AnyPlugins = AnyPlugins, Id extends string = string, Value = unknown> = DataColumnInitBase<Item, Plugins, Value> & ((Id extends keyof Item ? DataColumnInitKey<Item, Id> : never) | DataColumnInitIdAndKey<Item, Id, keyof Item> | DataColumnInitFnAndId<Item, Id, Value>);
109
+ /**
110
+ * Base initialization options for a DataColumn.
111
+ *
112
+ * @template Item - The type of data items in the table.
113
+ * @template Plugins - The plugins configuration type.
114
+ * @template Value - The type of the cell value.
115
+ */
31
116
  export type DataColumnInitBase<Item, Plugins extends AnyPlugins = AnyPlugins, Value = unknown> = Omit<ColumnInit<Item, Plugins>, 'height'> & {
117
+ /** Optional custom cell renderer. */
32
118
  cell?: DataLabel<Item, Plugins, Value>;
33
119
  };
120
+ /**
121
+ * DataColumn init when using an accessor key that matches Item property.
122
+ *
123
+ * @template Item - The type of data items.
124
+ * @template Id - The key of Item to access.
125
+ */
34
126
  export type DataColumnInitKey<Item, Id extends keyof Item> = {
127
+ /** The property key to access on each item. */
35
128
  accessor: Id;
129
+ /** Optional ID override. Defaults to accessor key. */
36
130
  id?: Id;
37
131
  };
132
+ /**
133
+ * DataColumn init when using an accessor key with a custom ID.
134
+ *
135
+ * @template Item - The type of data items.
136
+ * @template Id - The column ID type.
137
+ * @template Key - The key of Item to access.
138
+ */
38
139
  export type DataColumnInitIdAndKey<Item, Id extends string, Key extends keyof Item> = {
140
+ /** The property key to access on each item. */
39
141
  accessor: Key;
142
+ /** Optional custom ID for the column. */
40
143
  id?: Id;
41
144
  };
145
+ /**
146
+ * DataColumn init when using an accessor function.
147
+ *
148
+ * @template Item - The type of data items.
149
+ * @template Id - The column ID type.
150
+ * @template Value - The return type of the accessor function.
151
+ */
42
152
  export type DataColumnInitFnAndId<Item, Id extends string, Value> = {
153
+ /** Function to extract the value from each item, or a property key. */
43
154
  accessor: keyof Item | ((item: Item) => Value);
155
+ /** Optional custom ID for the column. */
44
156
  id?: Id;
45
157
  };
158
+ /**
159
+ * A column that displays data from the table items.
160
+ * Uses an accessor (key or function) to extract values from each row.
161
+ *
162
+ * @template Item - The type of data items in the table.
163
+ * @template Plugins - The plugins configuration type.
164
+ * @template Id - The column ID type.
165
+ * @template Value - The type of the cell value.
166
+ */
46
167
  export declare class DataColumn<Item, Plugins extends AnyPlugins = AnyPlugins, Id extends string = any, Value = any> extends FlatColumn<Item, Plugins, Id> {
47
168
  __data: boolean;
169
+ /** Optional custom cell renderer. */
48
170
  cell?: DataLabel<Item, Plugins, Value>;
171
+ /** The property key used to access values (if using key accessor). */
49
172
  accessorKey?: keyof Item;
173
+ /** The function used to extract values (if using function accessor). */
50
174
  accessorFn?: (item: Item) => Value;
175
+ /**
176
+ * Creates a new DataColumn instance.
177
+ *
178
+ * @param init - The column initialization options.
179
+ * @throws Error if no id, accessor key, or header is provided.
180
+ */
51
181
  constructor({ header, footer, plugins, cell, accessor, id }: DataColumnInit<Item, Plugins, Id, Value>);
182
+ /**
183
+ * Extracts the value from a data item using the configured accessor.
184
+ *
185
+ * @param item - The data item to extract the value from.
186
+ * @returns The extracted value, or undefined if no accessor is configured.
187
+ */
52
188
  getValue(item: Item): any;
53
189
  }
190
+ /**
191
+ * Function type for getting custom data from a DisplayColumn cell.
192
+ *
193
+ * @template Item - The type of data items in the table.
194
+ * @template Plugins - The plugins configuration type.
195
+ */
54
196
  export type DisplayColumnDataGetter<Item, Plugins extends AnyPlugins = AnyPlugins> = (cell: DisplayBodyCell<Item>, state?: TableState<Item, Plugins>) => unknown;
197
+ /**
198
+ * Initialization options for a DisplayColumn.
199
+ *
200
+ * @template Item - The type of data items in the table.
201
+ * @template Plugins - The plugins configuration type.
202
+ * @template Id - The column ID type.
203
+ */
55
204
  export type DisplayColumnInit<Item, Plugins extends AnyPlugins = AnyPlugins, Id extends string = any> = FlatColumnInit<Item, Plugins, Id> & {
205
+ /** The cell renderer function. */
56
206
  cell: DisplayLabel<Item, Plugins>;
207
+ /** Optional function to provide custom data to the cell. */
57
208
  data?: DisplayColumnDataGetter<Item, Plugins>;
58
209
  };
210
+ /**
211
+ * A column for displaying non-data content like actions, checkboxes, or custom UI.
212
+ * Unlike DataColumn, it doesn't extract values from the data items automatically.
213
+ *
214
+ * @template Item - The type of data items in the table.
215
+ * @template Plugins - The plugins configuration type.
216
+ * @template Id - The column ID type.
217
+ */
59
218
  export declare class DisplayColumn<Item, Plugins extends AnyPlugins = AnyPlugins, Id extends string = any> extends FlatColumn<Item, Plugins, Id> {
60
219
  __display: boolean;
220
+ /** The cell renderer function. */
61
221
  cell: DisplayLabel<Item, Plugins>;
222
+ /** Optional function to provide custom data to the cell. */
62
223
  data?: DisplayColumnDataGetter<Item, Plugins>;
224
+ /**
225
+ * Creates a new DisplayColumn instance.
226
+ *
227
+ * @param init - The column initialization options.
228
+ */
63
229
  constructor({ header, footer, plugins, id, cell, data }: DisplayColumnInit<Item, Plugins, Id>);
64
230
  }
231
+ /**
232
+ * Initialization options for a GroupColumn.
233
+ *
234
+ * @template Item - The type of data items in the table.
235
+ * @template Plugins - The plugins configuration type.
236
+ */
65
237
  export type GroupColumnInit<Item, Plugins extends AnyPlugins = AnyPlugins> = Omit<ColumnInit<Item, Plugins>, 'height'> & {
238
+ /** The child columns contained within this group. */
66
239
  columns: Column<Item, Plugins>[];
67
240
  };
241
+ /**
242
+ * A column that groups other columns under a shared header.
243
+ * Creates a hierarchical header structure.
244
+ *
245
+ * @template Item - The type of data items in the table.
246
+ * @template Plugins - The plugins configuration type.
247
+ */
68
248
  export declare class GroupColumn<Item, Plugins extends AnyPlugins = AnyPlugins> extends Column<Item, Plugins> {
69
249
  __group: boolean;
250
+ /** The child columns contained within this group. */
70
251
  columns: Column<Item, Plugins>[];
252
+ /** The IDs of all flat columns within this group (recursively). */
71
253
  ids: string[];
254
+ /**
255
+ * Creates a new GroupColumn instance.
256
+ * Height is calculated as max child height + 1.
257
+ *
258
+ * @param init - The column initialization options.
259
+ */
72
260
  constructor({ header, footer, columns, plugins }: GroupColumnInit<Item, Plugins>);
73
261
  }
262
+ /**
263
+ * Extracts all flat column IDs from an array of columns (including nested groups).
264
+ *
265
+ * @template Item - The type of data items in the table.
266
+ * @template Plugins - The plugins configuration type.
267
+ * @param columns - The array of columns to extract IDs from.
268
+ * @returns An array of column ID strings.
269
+ */
74
270
  export declare const getFlatColumnIds: <Item, Plugins extends AnyPlugins = AnyPlugins>(columns: Column<Item, Plugins>[]) => string[];
271
+ /**
272
+ * Extracts all FlatColumns from an array of columns (including nested groups).
273
+ *
274
+ * @template Item - The type of data items in the table.
275
+ * @template Plugins - The plugins configuration type.
276
+ * @param columns - The array of columns to flatten.
277
+ * @returns An array of FlatColumn instances.
278
+ */
75
279
  export declare const getFlatColumns: <Item, Plugins extends AnyPlugins = AnyPlugins>(columns: Column<Item, Plugins>[]) => FlatColumn<Item, Plugins>[];
package/dist/columns.js CHANGED
@@ -1,47 +1,115 @@
1
+ /**
2
+ * Base class for all column types in the table.
3
+ * Provides type guards for determining the specific column type.
4
+ *
5
+ * @template Item - The type of data items in the table.
6
+ * @template Plugins - The plugins configuration type.
7
+ */
1
8
  export class Column {
9
+ /** The header label or render function. */
2
10
  header;
11
+ /** Optional footer label or render function. */
3
12
  footer;
13
+ /** The height of the column in header rows. */
4
14
  height;
15
+ /** Plugin-specific column configuration. */
5
16
  plugins;
17
+ /**
18
+ * Creates a new Column instance.
19
+ *
20
+ * @param init - The column initialization options.
21
+ */
6
22
  constructor({ header, footer, height, plugins }) {
7
23
  this.header = header;
8
24
  this.footer = footer;
9
25
  this.height = height;
10
26
  this.plugins = plugins;
11
27
  }
28
+ /**
29
+ * Type guard to check if this column is a FlatColumn (DataColumn or DisplayColumn).
30
+ *
31
+ * @returns True if this is a FlatColumn.
32
+ */
12
33
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
13
34
  isFlat() {
14
35
  return '__flat' in this;
15
36
  }
37
+ /**
38
+ * Type guard to check if this column is a DataColumn.
39
+ *
40
+ * @returns True if this is a DataColumn.
41
+ */
16
42
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
17
43
  isData() {
18
44
  return '__data' in this;
19
45
  }
46
+ /**
47
+ * Type guard to check if this column is a DisplayColumn.
48
+ *
49
+ * @returns True if this is a DisplayColumn.
50
+ */
20
51
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
21
52
  isDisplay() {
22
53
  return '__display' in this;
23
54
  }
55
+ /**
56
+ * Type guard to check if this column is a GroupColumn.
57
+ *
58
+ * @returns True if this is a GroupColumn.
59
+ */
24
60
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
25
61
  isGroup() {
26
62
  return '__group' in this;
27
63
  }
28
64
  }
65
+ /**
66
+ * A column that occupies a single row in the header (not a group).
67
+ * Base class for DataColumn and DisplayColumn.
68
+ *
69
+ * @template Item - The type of data items in the table.
70
+ * @template Plugins - The plugins configuration type.
71
+ * @template Id - The column ID type.
72
+ */
29
73
  export class FlatColumn extends Column {
30
74
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
31
75
  __flat = true;
76
+ /** The unique identifier for this column. */
32
77
  id;
78
+ /**
79
+ * Creates a new FlatColumn instance.
80
+ *
81
+ * @param init - The column initialization options.
82
+ */
33
83
  constructor({ header, footer, plugins, id }) {
34
84
  super({ header, footer, plugins, height: 1 });
35
85
  this.id = id ?? String(header);
36
86
  }
37
87
  }
88
+ /**
89
+ * A column that displays data from the table items.
90
+ * Uses an accessor (key or function) to extract values from each row.
91
+ *
92
+ * @template Item - The type of data items in the table.
93
+ * @template Plugins - The plugins configuration type.
94
+ * @template Id - The column ID type.
95
+ * @template Value - The type of the cell value.
96
+ */
38
97
  export class DataColumn extends FlatColumn {
39
98
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
40
99
  __data = true;
100
+ /** Optional custom cell renderer. */
41
101
  cell;
102
+ /** The property key used to access values (if using key accessor). */
42
103
  accessorKey;
104
+ /** The function used to extract values (if using function accessor). */
43
105
  /* trunk-ignore(eslint/no-unused-vars) */
44
106
  accessorFn;
107
+ /**
108
+ * Creates a new DataColumn instance.
109
+ *
110
+ * @param init - The column initialization options.
111
+ * @throws Error if no id, accessor key, or header is provided.
112
+ */
45
113
  constructor({ header, footer, plugins, cell, accessor, id }) {
46
114
  super({ header, footer, plugins, id: 'Initialization not complete' });
47
115
  this.cell = cell;
@@ -57,6 +125,12 @@ export class DataColumn extends FlatColumn {
57
125
  const accessorKeyId = typeof this.accessorKey === 'string' ? this.accessorKey : null;
58
126
  this.id = (id ?? accessorKeyId ?? String(header));
59
127
  }
128
+ /**
129
+ * Extracts the value from a data item using the configured accessor.
130
+ *
131
+ * @param item - The data item to extract the value from.
132
+ * @returns The extracted value, or undefined if no accessor is configured.
133
+ */
60
134
  /* trunk-ignore(eslint/@typescript-eslint/no-explicit-any) */
61
135
  getValue(item) {
62
136
  if (this.accessorFn !== undefined) {
@@ -68,22 +142,52 @@ export class DataColumn extends FlatColumn {
68
142
  return undefined;
69
143
  }
70
144
  }
145
+ /**
146
+ * A column for displaying non-data content like actions, checkboxes, or custom UI.
147
+ * Unlike DataColumn, it doesn't extract values from the data items automatically.
148
+ *
149
+ * @template Item - The type of data items in the table.
150
+ * @template Plugins - The plugins configuration type.
151
+ * @template Id - The column ID type.
152
+ */
71
153
  export class DisplayColumn extends FlatColumn {
72
154
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
73
155
  __display = true;
156
+ /** The cell renderer function. */
74
157
  cell;
158
+ /** Optional function to provide custom data to the cell. */
75
159
  data;
160
+ /**
161
+ * Creates a new DisplayColumn instance.
162
+ *
163
+ * @param init - The column initialization options.
164
+ */
76
165
  constructor({ header, footer, plugins, id, cell, data }) {
77
166
  super({ header, footer, plugins, id });
78
167
  this.cell = cell;
79
168
  this.data = data;
80
169
  }
81
170
  }
171
+ /**
172
+ * A column that groups other columns under a shared header.
173
+ * Creates a hierarchical header structure.
174
+ *
175
+ * @template Item - The type of data items in the table.
176
+ * @template Plugins - The plugins configuration type.
177
+ */
82
178
  export class GroupColumn extends Column {
83
179
  // TODO Workaround for https://github.com/vitejs/vite/issues/9528
84
180
  __group = true;
181
+ /** The child columns contained within this group. */
85
182
  columns;
183
+ /** The IDs of all flat columns within this group (recursively). */
86
184
  ids;
185
+ /**
186
+ * Creates a new GroupColumn instance.
187
+ * Height is calculated as max child height + 1.
188
+ *
189
+ * @param init - The column initialization options.
190
+ */
87
191
  constructor({ header, footer, columns, plugins }) {
88
192
  const height = Math.max(...columns.map((c) => c.height)) + 1;
89
193
  super({ header, footer, height, plugins });
@@ -91,7 +195,23 @@ export class GroupColumn extends Column {
91
195
  this.ids = getFlatColumnIds(columns);
92
196
  }
93
197
  }
198
+ /**
199
+ * Extracts all flat column IDs from an array of columns (including nested groups).
200
+ *
201
+ * @template Item - The type of data items in the table.
202
+ * @template Plugins - The plugins configuration type.
203
+ * @param columns - The array of columns to extract IDs from.
204
+ * @returns An array of column ID strings.
205
+ */
94
206
  export const getFlatColumnIds = (columns) => columns.flatMap((c) => (c.isFlat() ? [c.id] : c.isGroup() ? c.ids : []));
207
+ /**
208
+ * Extracts all FlatColumns from an array of columns (including nested groups).
209
+ *
210
+ * @template Item - The type of data items in the table.
211
+ * @template Plugins - The plugins configuration type.
212
+ * @param columns - The array of columns to flatten.
213
+ * @returns An array of FlatColumn instances.
214
+ */
95
215
  export const getFlatColumns = (columns) => {
96
216
  return columns.flatMap((c) => (c.isFlat() ? [c] : c.isGroup() ? getFlatColumns(c.columns) : []));
97
217
  };
@@ -1 +1,5 @@
1
+ /**
2
+ * Non-breaking space character (U+00A0).
3
+ * Used as a placeholder in empty header cells to maintain proper rendering.
4
+ */
1
5
  export declare const NBSP = " ";
package/dist/constants.js CHANGED
@@ -1 +1,5 @@
1
+ /**
2
+ * Non-breaking space character (U+00A0).
3
+ * Used as a placeholder in empty header cells to maintain proper rendering.
4
+ */
1
5
  export const NBSP = ' ';
@@ -2,16 +2,123 @@ import { DataColumn, DisplayColumn, GroupColumn, type Column, type DataColumnIni
2
2
  import { type CreateViewModelOptions, type TableViewModel } from './createViewModel.js';
3
3
  import type { AnyPlugins } from './types/TablePlugin.js';
4
4
  import type { ReadOrWritable } from './utils/store.js';
5
+ /**
6
+ * Core table class that provides methods for defining columns and creating view models.
7
+ * Use the `createTable` factory function to instantiate.
8
+ *
9
+ * @template Item - The type of data items in the table.
10
+ * @template Plugins - The plugins configuration type.
11
+ * @example
12
+ * ```typescript
13
+ * const table = createTable(data, { sort: addSortBy(), filter: addTableFilter() })
14
+ * const columns = table.createColumns([
15
+ * table.column({ accessor: 'name', header: 'Name' }),
16
+ * table.column({ accessor: 'age', header: 'Age' })
17
+ * ])
18
+ * const viewModel = table.createViewModel(columns)
19
+ * ```
20
+ */
5
21
  export declare class Table<Item, Plugins extends AnyPlugins = AnyPlugins> {
22
+ /** The data source, either a Readable or Writable Svelte store. */
6
23
  data: ReadOrWritable<Item[]>;
24
+ /** The plugins configuration object. */
7
25
  plugins: Plugins;
26
+ /**
27
+ * Creates a new Table instance.
28
+ *
29
+ * @param data - A Svelte store containing the table data.
30
+ * @param plugins - The plugins to use with this table.
31
+ */
8
32
  constructor(data: ReadOrWritable<Item[]>, plugins: Plugins);
33
+ /**
34
+ * Validates and returns the column definitions.
35
+ * Throws an error if duplicate column IDs are detected.
36
+ *
37
+ * @param columns - Array of column definitions.
38
+ * @returns The same columns array if validation passes.
39
+ * @throws Error if duplicate column IDs are found.
40
+ */
9
41
  createColumns(columns: Column<Item, Plugins>[]): Column<Item, Plugins>[];
42
+ /**
43
+ * Creates a data column that displays values from the data items.
44
+ * Supports three initialization patterns:
45
+ * - `accessorKey` only: Uses a property key from Item
46
+ * - `accessorKey` and `id`: Uses a property key with a custom ID
47
+ * - `accessorFn` and `id`: Uses a function to extract values
48
+ *
49
+ * @param def - The column definition object.
50
+ * @returns A new DataColumn instance.
51
+ * @example
52
+ * ```typescript
53
+ * table.column({ accessor: 'name', header: 'Name' })
54
+ * table.column({ accessor: (item) => item.firstName + ' ' + item.lastName, header: 'Full Name', id: 'fullName' })
55
+ * ```
56
+ */
10
57
  column<Id extends Exclude<keyof Item, symbol>>(def: DataColumnInitBase<Item, Plugins, Item[Id]> & DataColumnInitKey<Item, Id>): DataColumn<Item, Plugins, `${Id}`, Item[Id]>;
11
58
  column<Id extends string, Key extends keyof Item>(def: DataColumnInitBase<Item, Plugins, Item[Key]> & DataColumnInitIdAndKey<Item, Id, Key>): DataColumn<Item, Plugins, Id, Item[Key]>;
12
59
  column<Id extends string, Value>(def: DataColumnInitBase<Item, Plugins, Value> & DataColumnInitFnAndId<Item, Id, Value>): DataColumn<Item, Plugins, Id, Value>;
60
+ /**
61
+ * Creates a group column that contains other columns.
62
+ * Used for creating hierarchical column headers.
63
+ *
64
+ * @param def - The group column definition.
65
+ * @returns A new GroupColumn instance.
66
+ * @example
67
+ * ```typescript
68
+ * table.group({
69
+ * header: 'Personal Info',
70
+ * columns: [
71
+ * table.column({ accessor: 'firstName', header: 'First Name' }),
72
+ * table.column({ accessor: 'lastName', header: 'Last Name' })
73
+ * ]
74
+ * })
75
+ * ```
76
+ */
13
77
  group(def: GroupColumnInit<Item, Plugins>): GroupColumn<Item, Plugins>;
78
+ /**
79
+ * Creates a display column for non-data content like actions or selection checkboxes.
80
+ *
81
+ * @param def - The display column definition.
82
+ * @returns A new DisplayColumn instance.
83
+ * @example
84
+ * ```typescript
85
+ * table.display({
86
+ * id: 'actions',
87
+ * header: '',
88
+ * cell: ({ row }) => createRender(ActionButtons, { row })
89
+ * })
90
+ * ```
91
+ */
14
92
  display(def: DisplayColumnInit<Item, Plugins>): DisplayColumn<Item, Plugins>;
93
+ /**
94
+ * Creates a reactive view model from the table and columns.
95
+ * The view model provides all the data needed to render the table.
96
+ *
97
+ * @param columns - The column definitions.
98
+ * @param options - Optional configuration for the view model.
99
+ * @returns A TableViewModel with reactive stores for rendering.
100
+ */
15
101
  createViewModel(columns: Column<Item, Plugins>[], options?: CreateViewModelOptions<Item>): TableViewModel<Item, Plugins>;
16
102
  }
103
+ /**
104
+ * Factory function to create a new Table instance.
105
+ * This is the main entry point for using svelte-headless-table.
106
+ *
107
+ * @template Item - The type of data items in the table.
108
+ * @template Plugins - The plugins configuration type.
109
+ * @param data - A Svelte store containing the table data.
110
+ * @param plugins - Optional plugins configuration object.
111
+ * @returns A new Table instance.
112
+ * @example
113
+ * ```typescript
114
+ * import { createTable } from 'svelte-headless-table'
115
+ * import { addSortBy, addPagination } from 'svelte-headless-table/plugins'
116
+ *
117
+ * const data = writable([{ name: 'Alice', age: 30 }, { name: 'Bob', age: 25 }])
118
+ * const table = createTable(data, {
119
+ * sort: addSortBy(),
120
+ * page: addPagination({ initialPageSize: 10 })
121
+ * })
122
+ * ```
123
+ */
17
124
  export declare const createTable: <Item, Plugins extends AnyPlugins = AnyPlugins>(data: ReadOrWritable<Item[]>, plugins?: Plugins) => Table<Item, Plugins>;