@mikestools/usetable 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { ComputedRef } from 'vue';
2
+ import { ElementInstance } from '@mikestools/useelement';
3
+ import { MaybeRef } from 'vue';
2
4
  import { Ref } from 'vue';
3
5
 
4
6
  /**
5
7
  * Base record interface - all records must have an id.
6
- * This is the foundation for the shared reactive data schema.
7
8
  */
8
9
  export declare interface BaseRecord {
9
10
  /** Unique identifier - required on all records */
@@ -11,71 +12,92 @@ export declare interface BaseRecord {
11
12
  }
12
13
 
13
14
  /**
14
- * Cell change record for tracking modifications.
15
+ * Cell change record for dirty tracking.
15
16
  */
16
17
  export declare interface CellChange {
18
+ /** Row index */
17
19
  readonly row: number;
20
+ /** Column index */
18
21
  readonly column: number;
19
- readonly oldValue: CellValue;
20
- readonly newValue: CellValue;
22
+ /** Previous value */
23
+ readonly oldValue: unknown;
24
+ /** New value */
25
+ readonly newValue: unknown;
21
26
  }
22
27
 
28
+ /**
29
+ * Callback for cell change events
30
+ */
23
31
  export declare type CellChangeCallback = (row: number, column: number, oldValue: CellValue, newValue: CellValue) => void;
24
32
 
25
33
  /**
26
- * Cell position for navigation and selection.
34
+ * Cell position for focus/navigation.
27
35
  */
28
36
  export declare interface CellPosition {
37
+ /** Row index */
29
38
  readonly row: number;
39
+ /** Column index */
30
40
  readonly column: number;
31
41
  }
32
42
 
33
43
  /**
34
- * Cell value can be a string, number, or DOM element.
44
+ * Cell value types - can be primitive or DOM node
35
45
  */
36
- export declare type CellValue = string | number | boolean | null | undefined | HTMLElement | Node;
46
+ export declare type CellValue = string | number | boolean | null | undefined | Node;
37
47
 
38
48
  /**
39
- * Create a table instance for manipulating an HTML table element.
49
+ * Create a table instance wrapping HTMLTableElement.
40
50
  *
41
- * Uses native table DOM APIs exclusively - no querySelector/querySelectorAll.
42
- * DOM-first architecture where the HTML table is the source of truth.
51
+ * Built on top of createElement, adds table-specific APIs using native methods:
52
+ * - element.caption, tHead, tFoot, tBodies (native properties)
53
+ * - element.insertRow(), deleteRow() (native methods)
54
+ * - element.rows (native HTMLCollection)
55
+ * - row.cells, row.insertCell(), row.deleteCell()
43
56
  *
44
57
  * @param element - The HTML table element
45
- * @param initialData - Optional initial body data
58
+ * @param initialData - Initial body data
46
59
  * @param options - Configuration options
47
- * @returns TableInstance for table manipulation
60
+ * @returns TableInstance with full table manipulation API
48
61
  *
49
62
  * @example
50
63
  * ```ts
51
64
  * const table = document.createElement('table')
52
- * const instance = createTable(table, [['Alice', 30], ['Bob', 25]], {
65
+ * const instance = createTable(table, [
66
+ * ['Alice', 30],
67
+ * ['Bob', 25]
68
+ * ], {
53
69
  * headers: ['Name', 'Age'],
54
70
  * caption: 'Users'
55
71
  * })
56
72
  *
73
+ * // Native table methods
74
+ * const row = instance.insertTableRow() // Uses native insertRow
75
+ *
76
+ * // High-level convenience
57
77
  * instance.addRow(['Carol', 35])
58
78
  * instance.setCell(0, 1, 31)
59
- * console.log(instance. getData())
60
79
  * ```
61
80
  */
62
81
  export declare function createTable(element: HTMLTableElement, initialData?: TableData, options?: CreateTableOptions): TableInstance;
63
82
 
64
83
  /**
65
- * Options for creating a table.
84
+ * Options for createTable
66
85
  */
67
86
  export declare interface CreateTableOptions {
68
87
  /** Initial headers */
69
88
  readonly headers?: readonly string[];
70
- /** Initial footer data */
71
- readonly footer?: RowData;
72
- /** Caption text */
89
+ /** Table caption */
73
90
  readonly caption?: string;
74
- /** ID generator for records */
91
+ /** Initial footer row */
92
+ readonly footer?: RowData;
93
+ /** ID generator for rows */
75
94
  readonly idGenerator?: IdGenerator;
76
95
  }
77
96
 
78
- export declare type DataChangeCallback = (data: CellValue[][]) => void;
97
+ /**
98
+ * Callback for data change events
99
+ */
100
+ export declare type DataChangeCallback = (data: readonly (readonly CellValue[])[]) => void;
79
101
 
80
102
  /**
81
103
  * Ensure a record has an ID, generating one if missing.
@@ -90,7 +112,7 @@ export declare function ensureId<T extends Record<string, unknown>>(record: T, g
90
112
  export declare function findById<T extends BaseRecord>(records: readonly T[], id: string): T | undefined;
91
113
 
92
114
  /**
93
- * Focus state.
115
+ * Focus state for cells.
94
116
  */
95
117
  export declare interface FocusState {
96
118
  /** Currently focused cell position */
@@ -102,6 +124,9 @@ export declare interface FocusState {
102
124
  */
103
125
  export declare function generateId(): string;
104
126
 
127
+ /**
128
+ * Callback for header change events
129
+ */
105
130
  export declare type HeaderChangeCallback = (headers: readonly string[]) => void;
106
131
 
107
132
  /**
@@ -126,21 +151,27 @@ export declare function indexById<T extends BaseRecord>(records: readonly T[], i
126
151
  export declare function isValidId(value: unknown): value is string;
127
152
 
128
153
  /**
129
- * Event callback types.
154
+ * Callback for row add events
130
155
  */
131
- export declare type RowAddCallback = (rowData: CellValue[], rowIndex: number, rowId: string | undefined) => void;
156
+ export declare type RowAddCallback = (data: readonly CellValue[], index: number, id: string | null) => void;
132
157
 
133
158
  /**
134
- * Row data is an array of cell values.
159
+ * Row data is an array of cell values
135
160
  */
136
161
  export declare type RowData = readonly CellValue[];
137
162
 
138
- export declare type RowRemoveCallback = (rowData: CellValue[], rowIndex: number, rowId: string | undefined) => void;
163
+ /**
164
+ * Callback for row remove events
165
+ */
166
+ export declare type RowRemoveCallback = (data: readonly CellValue[], index: number, id: string | null) => void;
139
167
 
140
- export declare type RowUpdateCallback = (rowIndex: number, oldData: CellValue[], newData: CellValue[], rowId: string | undefined) => void;
168
+ /**
169
+ * Callback for row update events
170
+ */
171
+ export declare type RowUpdateCallback = (index: number, oldData: readonly CellValue[], newData: readonly CellValue[], id: string | null) => void;
141
172
 
142
173
  /**
143
- * Selection state.
174
+ * Selection state for rows.
144
175
  */
145
176
  export declare interface SelectionState {
146
177
  /** Selected row indices */
@@ -157,228 +188,149 @@ export declare function stripGeneratedId<T extends {
157
188
  }>(record: T): Omit<T, 'id'> | T;
158
189
 
159
190
  /**
160
- * Table data is a 2D array of cell values.
191
+ * Table data is a 2D array
161
192
  */
162
193
  export declare type TableData = readonly RowData[];
163
194
 
164
195
  /**
165
- * Return type for createTable.
196
+ * Table instance - extends ElementInstance with table-specific APIs
166
197
  */
167
- export declare interface TableInstance {
168
- /** The table element */
169
- readonly element: HTMLTableElement;
170
- /** Get caption element */
171
- getCaption(): HTMLTableCaptionElement | null;
172
- /** Get thead element */
173
- getTHead(): HTMLTableSectionElement | null;
174
- /** Get tfoot element */
175
- getTFoot(): HTMLTableSectionElement | null;
176
- /** Get all tbody elements */
177
- getTBodies(): HTMLCollectionOf<HTMLTableSectionElement>;
178
- /** Get primary tbody (first one, created if needed) */
179
- getPrimaryTBody(): HTMLTableSectionElement;
180
- /** Get all rows in tbody sections */
181
- getBodyRows(): readonly HTMLTableRowElement[];
182
- /** Get row by index (body rows only) */
183
- getRow(index: number): HTMLTableRowElement | undefined;
184
- /** Get row by ID */
185
- getRowById(id: string): HTMLTableRowElement | undefined;
186
- /** Get cell at position */
187
- getCell(row: number, column: number): HTMLTableCellElement | undefined;
188
- /** Get cell by row ID and column index */
189
- getCellByRowId(rowId: string, column: number): HTMLTableCellElement | undefined;
190
- /** Get current headers */
191
- getHeaders(): string[];
192
- /** Get header at index */
193
- getHeader(index: number): string | undefined;
194
- /** Get body data as 2D array */
195
- getData(): CellValue[][];
196
- /** Get row data by index */
197
- getRowData(index: number): CellValue[] | undefined;
198
- /** Get row data by ID */
199
- getRowDataById(id: string): CellValue[] | undefined;
200
- /** Get cell value */
201
- getCellValue(row: number, column: number): CellValue;
202
- /** Get column data */
203
- getColumnData(index: number): CellValue[];
204
- /** Get footer data */
205
- getFooterData(): CellValue[] | undefined;
206
- /** Get row count (body rows only) */
207
- getRowCount(): number;
208
- /** Get column count (based on headers or first row) */
209
- getColumnCount(): number;
210
- /** Get row ID by index */
211
- getRowId(index: number): string | undefined;
212
- /** Get row index by ID */
213
- getRowIndex(id: string): number;
214
- /** Get all row IDs */
215
- getAllRowIds(): string[];
216
- /** Create or get caption */
198
+ export declare interface TableInstance extends ElementInstance<HTMLTableElement> {
199
+ /** Get/set caption element */
200
+ getTableCaption(): HTMLTableCaptionElement | null;
201
+ setTableCaption(caption: HTMLTableCaptionElement | null): void;
202
+ /** Create and return caption (or return existing) */
217
203
  createCaption(): HTMLTableCaptionElement;
218
- /** Delete caption */
204
+ /** Delete caption if exists */
219
205
  deleteCaption(): void;
220
- /** Create or get thead */
206
+ /** Get/set thead element */
207
+ getTHead(): HTMLTableSectionElement | null;
208
+ setTHead(thead: HTMLTableSectionElement | null): void;
209
+ /** Create and return thead (or return existing) */
221
210
  createTHead(): HTMLTableSectionElement;
222
- /** Delete thead */
211
+ /** Delete thead if exists */
223
212
  deleteTHead(): void;
224
- /** Create or get tfoot */
213
+ /** Get/set tfoot element */
214
+ getTFoot(): HTMLTableSectionElement | null;
215
+ setTFoot(tfoot: HTMLTableSectionElement | null): void;
216
+ /** Create and return tfoot (or return existing) */
225
217
  createTFoot(): HTMLTableSectionElement;
226
- /** Delete tfoot */
218
+ /** Delete tfoot if exists */
227
219
  deleteTFoot(): void;
228
- /** Create a new tbody */
220
+ /** Get tBodies collection */
221
+ getTBodies(): HTMLCollectionOf<HTMLTableSectionElement>;
222
+ /** Create and insert new tbody */
229
223
  createTBody(): HTMLTableSectionElement;
230
- /** Get rows from a specific section (thead, tbody, or tfoot) */
231
- getSectionRows(section: HTMLTableSectionElement): HTMLCollectionOf<HTMLTableRowElement>;
232
- /** Insert a row in a specific section at the given index */
233
- insertSectionRow(section: HTMLTableSectionElement, data: RowData, index?: number, id?: string): HTMLTableRowElement;
234
- /** Delete a row from a specific section at the given index */
235
- deleteSectionRow(section: HTMLTableSectionElement, index: number): CellValue[] | undefined;
236
- /** Get row count for a specific section */
237
- getSectionRowCount(section: HTMLTableSectionElement): number;
238
- /** Add row to thead */
239
- addHeadRow(data: RowData, index?: number): HTMLTableRowElement;
240
- /** Remove row from thead */
241
- removeHeadRow(index: number): CellValue[] | undefined;
242
- /** Get head row count */
243
- getHeadRowCount(): number;
244
- /** Add row to tfoot */
245
- addFootRow(data: RowData, index?: number): HTMLTableRowElement;
246
- /** Remove row from tfoot */
247
- removeFootRow(index: number): CellValue[] | undefined;
248
- /** Get foot row count */
249
- getFootRowCount(): number;
250
- /** Add row to specific tbody */
251
- addBodyRow(data: RowData, tbodyIndex?: number, rowIndex?: number, id?: string): HTMLTableRowElement;
252
- /** Remove row from specific tbody */
253
- removeBodyRow(rowIndex: number, tbodyIndex?: number): CellValue[] | undefined;
254
- /** Get body row count for a specific tbody */
255
- getBodyRowCount(tbodyIndex?: number): number;
256
- /** Set all headers */
224
+ /** Get rows collection (all rows in table) */
225
+ getTableRows(): HTMLCollectionOf<HTMLTableRowElement>;
226
+ /** Insert row at index (-1 = end) */
227
+ insertTableRow(index?: number): HTMLTableRowElement;
228
+ /** Delete row at index */
229
+ deleteTableRow(index: number): void;
230
+ /** Get header texts from thead */
231
+ getHeaders(): readonly string[];
232
+ /** Set headers (creates/updates thead) */
257
233
  setHeaders(headers: readonly string[]): void;
258
- /** Set single header */
259
- setHeader(index: number, text: string): void;
260
- /** Add header column */
234
+ /** Add single header at index */
261
235
  addHeader(text: string, index?: number): void;
262
- /** Remove header column */
236
+ /** Remove header at index */
263
237
  removeHeader(index: number): void;
264
- /** Add a row with data */
265
- addRow(data: RowData, index?: number, id?: string): HTMLTableRowElement;
266
- /** Remove row by index */
267
- removeRow(index: number): CellValue[] | undefined;
268
- /** Remove row by ID */
269
- removeRowById(id: string): CellValue[] | undefined;
270
- /** Update entire row */
238
+ /** Clear all headers */
239
+ clearHeaders(): void;
240
+ /** Get count of body rows */
241
+ getRowCount(): number;
242
+ /** Get all body rows */
243
+ getBodyRows(): readonly HTMLTableRowElement[];
244
+ /** Get row at index */
245
+ getRow(index: number): HTMLTableRowElement | null;
246
+ /** Add row with data */
247
+ addRow(data: RowData, index?: number): HTMLTableRowElement;
248
+ /** Remove row at index, return data */
249
+ removeRow(index: number): RowData | null;
250
+ /** Update row data */
271
251
  updateRow(index: number, data: RowData): void;
272
- /** Update row by ID */
273
- updateRowById(id: string, data: RowData): void;
274
- /** Move row from one index to another */
275
- moveRow(fromIndex: number, toIndex: number): void;
276
- /** Swap two rows */
277
- swapRows(indexA: number, indexB: number): void;
278
252
  /** Clear all body rows */
279
253
  clearRows(): void;
280
- /** Add a column */
281
- addColumn(header: string, defaultValue?: CellValue, index?: number): void;
282
- /** Remove a column */
254
+ /** Get row by data-id */
255
+ getRowById(id: string): HTMLTableRowElement | null;
256
+ /** Get ID of row at index */
257
+ getRowId(index: number): string | null;
258
+ /** Add row with specific ID */
259
+ addRowWithId(data: RowData, id: string, index?: number): HTMLTableRowElement;
260
+ /** Remove row by ID */
261
+ removeRowById(id: string): RowData | null;
262
+ /** Get cell at row, col */
263
+ getCell(row: number, col: number): HTMLTableCellElement | null;
264
+ /** Get cell value */
265
+ getCellValue(row: number, col: number): CellValue;
266
+ /** Set cell value */
267
+ setCell(row: number, col: number, value: CellValue): void;
268
+ /** Get column count */
269
+ getColumnCount(): number;
270
+ /** Add column (header + cells) */
271
+ addColumn(header?: string, index?: number): void;
272
+ /** Remove column */
283
273
  removeColumn(index: number): void;
284
- /** Move column */
285
- moveColumn(fromIndex: number, toIndex: number): void;
286
- /** Swap two columns */
287
- swapColumns(indexA: number, indexB: number): void;
274
+ /** Get column data */
275
+ getColumnData(index: number): readonly CellValue[];
288
276
  /** Set column data */
289
277
  setColumnData(index: number, data: readonly CellValue[]): void;
290
- /** Set cell value */
291
- setCell(row: number, column: number, value: CellValue): void;
292
- /** Set cell by row ID */
293
- setCellByRowId(rowId: string, column: number, value: CellValue): void;
294
- /** Set cell range */
295
- setCellRange(startRow: number, startColumn: number, data: TableData): void;
278
+ /** Get all body data */
279
+ getTableData(): TableData;
280
+ /** Set all body data */
281
+ setTableData(data: TableData): void;
282
+ /** Get footer row data */
283
+ getFooter(): RowData | null;
296
284
  /** Set footer row */
297
285
  setFooter(data: RowData): void;
298
- /** Set footer cell */
299
- setFooterCell(index: number, value: CellValue): void;
300
- /** Get footer cell */
301
- getFooterCell(index: number): CellValue;
302
286
  /** Clear footer */
303
287
  clearFooter(): void;
304
- /** Set caption text */
305
- setCaption(text: string): void;
306
288
  /** Get caption text */
307
- getCaptionText(): string | undefined;
308
- /** Set all data (replaces body rows) */
309
- setData(data: TableData): void;
310
- /** Reset table (clear all content) */
311
- reset(): void;
312
- /** Sync internal state with DOM (if external changes made) */
313
- sync(): void;
314
- /** Set records with column mapping */
315
- setRecords<T extends BaseRecord>(records: readonly T[], fields: readonly (keyof T | ((record: T) => CellValue))[]): void;
316
- /** Get record by ID */
317
- getRecordData(id: string): CellValue[] | undefined;
318
- /** Add a record */
319
- addRecord<T extends BaseRecord>(record: T | Omit<T, 'id'>, fields: readonly (keyof T | ((record: T) => CellValue))[], index?: number): string;
320
- /** Update a record by ID */
321
- updateRecordRow(id: string, data: RowData): boolean;
322
- /** Remove a record by ID */
323
- removeRecord(id: string): boolean;
324
- /** Check if record exists */
325
- hasRecord(id: string): boolean;
326
- /** Set the ID generator function */
327
- setIdGenerator(generator: IdGenerator): void;
328
- /** Generate a new ID */
329
- generateId(): string;
330
- /** Subscribe to row add events */
331
- onRowAdd(callback: RowAddCallback): () => void;
332
- /** Subscribe to row remove events */
333
- onRowRemove(callback: RowRemoveCallback): () => void;
334
- /** Subscribe to row update events */
335
- onRowUpdate(callback: RowUpdateCallback): () => void;
336
- /** Subscribe to cell change events */
337
- onCellChange(callback: CellChangeCallback): () => void;
338
- /** Subscribe to header change events */
339
- onHeaderChange(callback: HeaderChangeCallback): () => void;
340
- /** Subscribe to data change events */
341
- onDataChange(callback: DataChangeCallback): () => void;
342
- /** Destroy and clean up */
343
- destroy(): void;
289
+ getCaptionText(): string | null;
290
+ /** Set caption text */
291
+ setCaptionText(text: string): void;
292
+ /** Move row from one index to another */
293
+ moveRow(fromIndex: number, toIndex: number): void;
294
+ /** Swap two rows */
295
+ swapRows(index1: number, index2: number): void;
296
+ /** Subscribe to row add */
297
+ onRowAdd(callback: (index: number, id: string | null) => void): () => void;
298
+ /** Subscribe to row remove */
299
+ onRowRemove(callback: (index: number, id: string | null) => void): () => void;
300
+ /** Subscribe to data change */
301
+ onDataChange(callback: () => void): () => void;
344
302
  }
345
303
 
346
304
  /**
347
305
  * Vue 3 composable for HTML table manipulation.
348
306
  *
349
- * Wraps createTable with Vue reactivity and state management.
350
- * Uses native table DOM APIs - no querySelector/querySelectorAll.
307
+ * Wraps createTable with reactive state and Vue-specific integration.
308
+ * Follows the DOM-first architecture where the HTML table element is the source of truth.
351
309
  *
352
310
  * @param elementRef - Ref to the HTML table element
353
- * @param initialData - Optional initial body data
311
+ * @param initialData - Initial body data
354
312
  * @param options - Configuration options
355
- * @returns UseTableReturn for reactive table manipulation
313
+ * @returns UseTableReturn with reactive state and methods
356
314
  *
357
315
  * @example
358
316
  * ```vue
359
- * <script setup lang="ts">
317
+ * <script setup>
360
318
  * import { ref, onMounted } from 'vue'
361
319
  * import { useTable } from '@mikestools/usetable'
362
320
  *
363
- * const tableRef = ref<HTMLTableElement>()
321
+ * const tableRef = ref<HTMLTableElement | null>(null)
364
322
  *
365
- * onMounted(() => {
366
- * if (! tableRef.value) return
367
- *
368
- * const table = useTable(ref(tableRef.value), [
369
- * ['Alice', 30],
370
- * ['Bob', 25]
371
- * ], {
372
- * headers: ['Name', 'Age']
373
- * })
374
- *
375
- * // Reactive access
376
- * console. log(table.data. value)
377
- * console.log(table.rowCount. value)
378
- *
379
- * // Mutations
380
- * table.addRow(['Carol', 35])
381
- * table.setCell(0, 1, 31)
323
+ * const {
324
+ * data,
325
+ * headers,
326
+ * rowCount,
327
+ * addRow,
328
+ * setCell
329
+ * } = useTable(tableRef, [
330
+ * ['Alice', 30],
331
+ * ['Bob', 25]
332
+ * ], {
333
+ * headers: ['Name', 'Age']
382
334
  * })
383
335
  * </script>
384
336
  *
@@ -387,7 +339,7 @@ export declare interface TableInstance {
387
339
  * </template>
388
340
  * ```
389
341
  */
390
- export declare function useTable(elementRef: Ref<HTMLTableElement>, initialData?: TableData, options?: UseTableOptions): UseTableReturn;
342
+ export declare function useTable(elementRef: MaybeRef<HTMLTableElement | null>, initialData?: TableData, options?: UseTableOptions): UseTableReturn;
391
343
 
392
344
  /**
393
345
  * Options for useTable composable.
@@ -398,10 +350,12 @@ export declare type UseTableOptions = CreateTableOptions;
398
350
  * Return type for useTable composable.
399
351
  */
400
352
  export declare interface UseTableReturn {
401
- /** Underlying table instance */
402
- readonly instance: TableInstance;
403
- /** The table element */
404
- readonly element: Readonly<Ref<HTMLTableElement>>;
353
+ /** Underlying table instance (for advanced usage) */
354
+ readonly instance: Readonly<Ref<TableInstance | null>>;
355
+ /** Whether the table is initialized */
356
+ readonly isInitialized: ComputedRef<boolean>;
357
+ /** The table element reference */
358
+ readonly element: Readonly<Ref<HTMLTableElement | null>>;
405
359
  /** Reactive headers */
406
360
  readonly headers: ComputedRef<readonly string[]>;
407
361
  /** Reactive body data */
@@ -413,9 +367,9 @@ export declare interface UseTableReturn {
413
367
  /** Reactive row IDs */
414
368
  readonly rowIds: ComputedRef<readonly string[]>;
415
369
  /** Reactive footer data */
416
- readonly footerData: ComputedRef<readonly CellValue[] | undefined>;
370
+ readonly footerData: ComputedRef<readonly CellValue[] | null>;
417
371
  /** Reactive caption text */
418
- readonly captionText: ComputedRef<string | undefined>;
372
+ readonly captionText: ComputedRef<string | null>;
419
373
  /** Version counter for reactivity (incremented on changes) */
420
374
  readonly version: Readonly<Ref<number>>;
421
375
  /** Selection state */
@@ -423,117 +377,77 @@ export declare interface UseTableReturn {
423
377
  /** Focus state */
424
378
  readonly focus: FocusState;
425
379
  /** Create or get caption */
426
- createCaption(): HTMLTableCaptionElement;
380
+ createCaption(): HTMLTableCaptionElement | null;
427
381
  /** Delete caption */
428
382
  deleteCaption(): void;
429
383
  /** Create or get thead */
430
- createTHead(): HTMLTableSectionElement;
384
+ createTHead(): HTMLTableSectionElement | null;
431
385
  /** Delete thead */
432
386
  deleteTHead(): void;
433
387
  /** Create or get tfoot */
434
- createTFoot(): HTMLTableSectionElement;
388
+ createTFoot(): HTMLTableSectionElement | null;
435
389
  /** Delete tfoot */
436
390
  deleteTFoot(): void;
437
391
  /** Create a new tbody */
438
- createTBody(): HTMLTableSectionElement;
439
- /** Get rows from a specific section (thead, tbody, or tfoot) */
440
- getSectionRows(section: HTMLTableSectionElement): HTMLCollectionOf<HTMLTableRowElement>;
441
- /** Insert a row in a specific section at the given index */
442
- insertSectionRow(section: HTMLTableSectionElement, data: RowData, index?: number, id?: string): HTMLTableRowElement;
443
- /** Delete a row from a specific section at the given index */
444
- deleteSectionRow(section: HTMLTableSectionElement, index: number): CellValue[] | undefined;
445
- /** Get row count for a specific section */
446
- getSectionRowCount(section: HTMLTableSectionElement): number;
447
- /** Add row to thead */
448
- addHeadRow(data: RowData, index?: number): HTMLTableRowElement;
449
- /** Remove row from thead */
450
- removeHeadRow(index: number): CellValue[] | undefined;
451
- /** Get head row count */
452
- getHeadRowCount(): number;
453
- /** Add row to tfoot */
454
- addFootRow(data: RowData, index?: number): HTMLTableRowElement;
455
- /** Remove row from tfoot */
456
- removeFootRow(index: number): CellValue[] | undefined;
457
- /** Get foot row count */
458
- getFootRowCount(): number;
459
- /** Add row to specific tbody */
460
- addBodyRow(data: RowData, tbodyIndex?: number, rowIndex?: number, id?: string): HTMLTableRowElement;
461
- /** Remove row from specific tbody */
462
- removeBodyRow(rowIndex: number, tbodyIndex?: number): CellValue[] | undefined;
463
- /** Get body row count for a specific tbody */
464
- getBodyRowCount(tbodyIndex?: number): number;
392
+ createTBody(): HTMLTableSectionElement | null;
465
393
  /** Set all headers */
466
394
  setHeaders(headers: readonly string[]): void;
467
- /** Set single header */
468
- setHeader(index: number, text: string): void;
469
395
  /** Add header column */
470
396
  addHeader(text: string, index?: number): void;
471
397
  /** Remove header column */
472
398
  removeHeader(index: number): void;
399
+ /** Clear all headers */
400
+ clearHeaders(): void;
473
401
  /** Add a row with data */
474
- addRow(data: RowData, index?: number, id?: string): HTMLTableRowElement;
402
+ addRow(data: RowData, index?: number): HTMLTableRowElement | null;
403
+ /** Add a row with specific ID */
404
+ addRowWithId(data: RowData, id: string, index?: number): HTMLTableRowElement | null;
475
405
  /** Remove row by index */
476
- removeRow(index: number): CellValue[] | undefined;
406
+ removeRow(index: number): RowData | null;
477
407
  /** Remove row by ID */
478
- removeRowById(id: string): CellValue[] | undefined;
408
+ removeRowById(id: string): RowData | null;
479
409
  /** Update entire row */
480
410
  updateRow(index: number, data: RowData): void;
481
- /** Update row by ID */
482
- updateRowById(id: string, data: RowData): void;
411
+ /** Clear all body rows */
412
+ clearRows(): void;
413
+ /** Get row by index */
414
+ getRow(index: number): HTMLTableRowElement | null;
415
+ /** Get row by ID */
416
+ getRowById(id: string): HTMLTableRowElement | null;
417
+ /** Get row ID by index */
418
+ getRowId(index: number): string | null;
483
419
  /** Move row from one index to another */
484
420
  moveRow(fromIndex: number, toIndex: number): void;
485
421
  /** Swap two rows */
486
- swapRows(indexA: number, indexB: number): void;
487
- /** Clear all body rows */
488
- clearRows(): void;
422
+ swapRows(index1: number, index2: number): void;
489
423
  /** Add a column */
490
- addColumn(header: string, defaultValue?: CellValue, index?: number): void;
424
+ addColumn(header?: string, index?: number): void;
491
425
  /** Remove a column */
492
426
  removeColumn(index: number): void;
493
- /** Move column */
494
- moveColumn(fromIndex: number, toIndex: number): void;
495
- /** Swap two columns */
496
- swapColumns(indexA: number, indexB: number): void;
427
+ /** Get column data */
428
+ getColumnData(index: number): readonly CellValue[];
497
429
  /** Set column data */
498
430
  setColumnData(index: number, data: readonly CellValue[]): void;
431
+ /** Get cell element */
432
+ getCell(row: number, column: number): HTMLTableCellElement | null;
499
433
  /** Get cell value */
500
- getCell(row: number, column: number): CellValue;
434
+ getCellValue(row: number, column: number): CellValue;
501
435
  /** Set cell value */
502
436
  setCell(row: number, column: number, value: CellValue): void;
503
- /** Set cell by row ID */
504
- setCellByRowId(rowId: string, column: number, value: CellValue): void;
505
- /** Set cell range */
506
- setCellRange(startRow: number, startColumn: number, data: TableData): void;
507
- /** Get cell element */
508
- getCellElement(row: number, column: number): HTMLTableCellElement | undefined;
509
- /** Get row data by index */
510
- getRowData(index: number): CellValue[] | undefined;
511
- /** Get row data by ID */
512
- getRowDataById(id: string): CellValue[] | undefined;
513
- /** Get row element */
514
- getRowElement(index: number): HTMLTableRowElement | undefined;
515
- /** Get row by ID */
516
- getRowById(id: string): HTMLTableRowElement | undefined;
517
- /** Get row ID by index */
518
- getRowId(index: number): string | undefined;
519
- /** Get row index by ID */
520
- getRowIndex(id: string): number;
521
- /** Get column data */
522
- getColumnData(index: number): CellValue[];
437
+ /** Get footer data */
438
+ getFooter(): RowData | null;
523
439
  /** Set footer row */
524
440
  setFooter(data: RowData): void;
525
- /** Set footer cell */
526
- setFooterCell(index: number, value: CellValue): void;
527
- /** Get footer cell */
528
- getFooterCell(index: number): CellValue;
529
441
  /** Clear footer */
530
442
  clearFooter(): void;
443
+ /** Get caption text */
444
+ getCaption(): string | null;
531
445
  /** Set caption text */
532
446
  setCaption(text: string): void;
447
+ /** Get all table data */
448
+ getData(): TableData;
533
449
  /** Set all data (replaces body rows) */
534
450
  setData(data: TableData): void;
535
- /** Reset table (clear all content) */
536
- reset(): void;
537
451
  /** Sync internal state with DOM */
538
452
  sync(): void;
539
453
  /** Select a row by index */
@@ -546,14 +460,16 @@ export declare interface UseTableReturn {
546
460
  selectAllRows(): void;
547
461
  /** Deselect all rows */
548
462
  deselectAllRows(): void;
549
- /** Select row range */
550
- selectRowRange(startIndex: number, endIndex: number): void;
551
463
  /** Check if row is selected */
552
464
  isRowSelected(index: number): boolean;
553
465
  /** Get selected row indices */
554
466
  getSelectedRowIndices(): readonly number[];
555
467
  /** Get selected row data */
556
468
  getSelectedRowData(): readonly (readonly CellValue[])[];
469
+ /** Select a range of rows (from anchor to target) */
470
+ selectRowRange(fromIndex: number, toIndex: number): void;
471
+ /** Select row with modifier key awareness (Ctrl/Cmd, Shift) */
472
+ selectRowWithModifiers(index: number, ctrlKey: boolean, shiftKey: boolean): void;
557
473
  /** Select a cell */
558
474
  selectCell(row: number, column: number): void;
559
475
  /** Deselect a cell */
@@ -580,51 +496,19 @@ export declare interface UseTableReturn {
580
496
  moveFocusLeft(): boolean;
581
497
  /** Move focus right */
582
498
  moveFocusRight(): boolean;
583
- /** Move focus to first cell */
584
- moveFocusToFirst(): void;
585
- /** Move focus to last cell */
586
- moveFocusToLast(): void;
587
499
  /** Enable keyboard navigation (returns cleanup function) */
588
500
  enableKeyboardNavigation(): () => void;
589
- /** Set records with column mapping */
590
- setRecords<T extends BaseRecord>(records: readonly T[], fields: readonly (keyof T | ((record: T) => CellValue))[]): void;
591
- /** Get record data by ID */
592
- getRecordData(id: string): CellValue[] | undefined;
593
- /** Add a record */
594
- addRecord<T extends BaseRecord>(record: T | Omit<T, 'id'>, fields: readonly (keyof T | ((record: T) => CellValue))[], index?: number): string;
595
- /** Update a record row by ID */
596
- updateRecordRow(id: string, data: RowData): boolean;
597
- /** Remove a record by ID */
598
- removeRecord(id: string): boolean;
599
- /** Check if record exists */
600
- hasRecord(id: string): boolean;
601
- /** Get selected record IDs */
602
- getSelectedRecordIds(): readonly string[];
603
- /** Select records by IDs */
604
- selectRecords(ids: readonly string[]): void;
605
- /** Deselect records by IDs */
606
- deselectRecords(ids: readonly string[]): void;
607
- /** Set the ID generator function */
608
- setIdGenerator(generator: IdGenerator): void;
609
- /** Generate a new ID */
610
- generateId(): string;
611
501
  /** Subscribe to row add events */
612
- onRowAdd(callback: RowAddCallback): () => void;
502
+ onRowAdd(callback: (index: number, id: string | null) => void): () => void;
613
503
  /** Subscribe to row remove events */
614
- onRowRemove(callback: RowRemoveCallback): () => void;
615
- /** Subscribe to row update events */
616
- onRowUpdate(callback: RowUpdateCallback): () => void;
617
- /** Subscribe to cell change events */
618
- onCellChange(callback: CellChangeCallback): () => void;
619
- /** Subscribe to header change events */
620
- onHeaderChange(callback: HeaderChangeCallback): () => void;
504
+ onRowRemove(callback: (index: number, id: string | null) => void): () => void;
621
505
  /** Subscribe to data change events */
622
- onDataChange(callback: DataChangeCallback): () => void;
506
+ onDataChange(callback: () => void): () => void;
623
507
  /** Subscribe to selection change events */
624
- onSelectionChange(callback: (selectedRows: ReadonlySet<number>, selectedCells: ReadonlySet<string>) => void): () => void;
508
+ onSelectionChange(callback: (rows: ReadonlySet<number>, cells: ReadonlySet<string>) => void): () => void;
625
509
  /** Subscribe to focus change events */
626
510
  onFocusChange(callback: (cell: CellPosition | null) => void): () => void;
627
- /** Destroy and clean up */
511
+ /** Destroy and cleanup */
628
512
  destroy(): void;
629
513
  }
630
514