@mikestools/usetable 0.0.4 → 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/README.md +104 -116
- package/dist/index.d.ts +210 -274
- package/dist/usetable.js +1402 -802
- package/dist/usetable.umd.cjs +1 -1
- package/package.json +4 -2
- package/showcase/examples/BasicExample.vue +1 -1
package/README.md
CHANGED
|
@@ -13,20 +13,19 @@ A Vue 3 composable for HTML table manipulation with native DOM APIs. Two-layer a
|
|
|
13
13
|
|
|
14
14
|
### Core Features
|
|
15
15
|
|
|
16
|
-
| Feature | Description
|
|
17
|
-
|
|
18
|
-
| 📋 **Headers** | Set, update, add, remove header cells
|
|
19
|
-
| ➕ **Rows** | Add, remove, update
|
|
20
|
-
| 📊 **Columns** | Add, remove
|
|
21
|
-
| 🔲 **Cells** | Get, set individual cell values
|
|
22
|
-
| ☑️ **Selection** | Row and cell selection
|
|
23
|
-
| 🎯 **Focus** | Cell focus with keyboard navigation
|
|
24
|
-
| 📝 **Footer** | Footer row for totals/summaries
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
| 🔄 **Sync** | Sync with pre-existing DOM tables |
|
|
16
|
+
| Feature | Description |
|
|
17
|
+
|------------------|-----------------------------------------------|
|
|
18
|
+
| 📋 **Headers** | Set, update, add, remove header cells |
|
|
19
|
+
| ➕ **Rows** | Add, remove, update rows |
|
|
20
|
+
| 📊 **Columns** | Add, remove columns |
|
|
21
|
+
| 🔲 **Cells** | Get, set individual cell values |
|
|
22
|
+
| ☑️ **Selection** | Row and cell selection |
|
|
23
|
+
| 🎯 **Focus** | Cell focus with keyboard navigation |
|
|
24
|
+
| 📝 **Footer** | Footer row for totals/summaries |
|
|
25
|
+
| 🔔 **Events** | Data change callbacks |
|
|
26
|
+
| ⌨️ **Keyboard** | Arrow key cell navigation |
|
|
27
|
+
| ⚡ **Reactive** | Vue computed properties |
|
|
28
|
+
| 🔄 **Sync** | Sync with pre-existing DOM tables |
|
|
30
29
|
|
|
31
30
|
## Installation
|
|
32
31
|
|
|
@@ -121,8 +120,8 @@ function addEmployee() {
|
|
|
121
120
|
|
|
122
121
|
```typescript
|
|
123
122
|
function useTable(
|
|
124
|
-
elementRef:
|
|
125
|
-
initialData?:
|
|
123
|
+
elementRef: MaybeRef<HTMLTableElement | null>,
|
|
124
|
+
initialData?: TableData,
|
|
126
125
|
options?: UseTableOptions
|
|
127
126
|
): UseTableReturn
|
|
128
127
|
```
|
|
@@ -131,84 +130,90 @@ function useTable(
|
|
|
131
130
|
|
|
132
131
|
| Option | Type | Description |
|
|
133
132
|
|----------------|-------------------------|--------------------------------|
|
|
134
|
-
| `headers` | `readonly
|
|
133
|
+
| `headers` | `readonly string[]` | Initial header values |
|
|
135
134
|
| `caption` | `string` | Table caption text |
|
|
136
|
-
| `footer` | `
|
|
135
|
+
| `footer` | `RowData` | Initial footer values |
|
|
137
136
|
| `idGenerator` | `() => string` | Custom row ID generator |
|
|
138
137
|
|
|
139
138
|
#### Reactive State
|
|
140
139
|
|
|
141
|
-
| Property | Type
|
|
142
|
-
|
|
143
|
-
| `element` | `Readonly<Ref<HTMLTableElement>>`
|
|
144
|
-
| `headers` | `ComputedRef<readonly string[]>`
|
|
145
|
-
| `data` | `ComputedRef<readonly CellValue[][]>`
|
|
146
|
-
| `rowCount` | `ComputedRef<number>`
|
|
147
|
-
| `columnCount` | `ComputedRef<number>`
|
|
148
|
-
| `rowIds` | `ComputedRef<readonly string[]>`
|
|
149
|
-
| `footerData` | `ComputedRef<CellValue[] \|
|
|
150
|
-
| `captionText` | `ComputedRef<string \|
|
|
151
|
-
| `version` | `Ref<number
|
|
140
|
+
| Property | Type | Description |
|
|
141
|
+
|---------------|---------------------------------------------|--------------------------------|
|
|
142
|
+
| `element` | `Readonly<Ref<HTMLTableElement \| null>>` | The table element |
|
|
143
|
+
| `headers` | `ComputedRef<readonly string[]>` | Header values |
|
|
144
|
+
| `data` | `ComputedRef<readonly CellValue[][]>` | Body data as 2D array |
|
|
145
|
+
| `rowCount` | `ComputedRef<number>` | Number of body rows |
|
|
146
|
+
| `columnCount` | `ComputedRef<number>` | Number of columns |
|
|
147
|
+
| `rowIds` | `ComputedRef<readonly string[]>` | Array of row IDs |
|
|
148
|
+
| `footerData` | `ComputedRef<readonly CellValue[] \| null>` | Footer row values |
|
|
149
|
+
| `captionText` | `ComputedRef<string \| null>` | Caption text |
|
|
150
|
+
| `version` | `Readonly<Ref<number>>` | Version counter for reactivity |
|
|
152
151
|
|
|
153
152
|
#### Selection State
|
|
154
153
|
|
|
155
|
-
| Property | Type
|
|
156
|
-
|
|
157
|
-
| `selection.rows` | `Ref<
|
|
158
|
-
| `selection.cells` | `Ref<
|
|
154
|
+
| Property | Type | Description |
|
|
155
|
+
|-------------------|--------------------------------------|----------------------|
|
|
156
|
+
| `selection.rows` | `Readonly<Ref<ReadonlySet<number>>>` | Selected row indices |
|
|
157
|
+
| `selection.cells` | `Readonly<Ref<ReadonlySet<string>>>` | Selected cell keys |
|
|
159
158
|
|
|
160
159
|
#### Focus State
|
|
161
160
|
|
|
162
|
-
| Property | Type
|
|
163
|
-
|
|
164
|
-
| `focus.cell` | `Ref<
|
|
161
|
+
| Property | Type | Description |
|
|
162
|
+
|--------------|-----------------------------------------|-----------------------|
|
|
163
|
+
| `focus.cell` | `Readonly<Ref<CellPosition \| null>>` | Focused cell position |
|
|
165
164
|
|
|
166
165
|
### Methods
|
|
167
166
|
|
|
167
|
+
#### Structure Methods
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
createCaption(): HTMLTableCaptionElement | null
|
|
171
|
+
deleteCaption(): void
|
|
172
|
+
createTHead(): HTMLTableSectionElement | null
|
|
173
|
+
deleteTHead(): void
|
|
174
|
+
createTFoot(): HTMLTableSectionElement | null
|
|
175
|
+
deleteTFoot(): void
|
|
176
|
+
createTBody(): HTMLTableSectionElement | null
|
|
177
|
+
```
|
|
178
|
+
|
|
168
179
|
#### Header Methods
|
|
169
180
|
|
|
170
181
|
```typescript
|
|
171
|
-
setHeaders(headers: readonly
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
182
|
+
setHeaders(headers: readonly string[]): void
|
|
183
|
+
addHeader(text: string, index?: number): void
|
|
184
|
+
removeHeader(index: number): void
|
|
185
|
+
clearHeaders(): void
|
|
175
186
|
```
|
|
176
187
|
|
|
177
188
|
#### Row Methods
|
|
178
189
|
|
|
179
190
|
```typescript
|
|
180
|
-
addRow(data:
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
moveRow(fromIndex: number, toIndex: number): void
|
|
186
|
-
swapRows(index1: number, index2: number): void
|
|
191
|
+
addRow(data: RowData, index?: number): HTMLTableRowElement | null
|
|
192
|
+
addRowWithId(data: RowData, id: string, index?: number): HTMLTableRowElement | null
|
|
193
|
+
removeRow(index: number): RowData | null
|
|
194
|
+
removeRowById(id: string): RowData | null
|
|
195
|
+
updateRow(index: number, data: RowData): void
|
|
187
196
|
clearRows(): void
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
197
|
+
getRow(index: number): HTMLTableRowElement | null
|
|
198
|
+
getRowById(id: string): HTMLTableRowElement | null
|
|
199
|
+
getRowId(index: number): string | null
|
|
191
200
|
```
|
|
192
201
|
|
|
193
202
|
#### Column Methods
|
|
194
203
|
|
|
195
204
|
```typescript
|
|
196
|
-
addColumn(header
|
|
205
|
+
addColumn(header?: string, index?: number): void
|
|
197
206
|
removeColumn(index: number): void
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
getColumnData(columnIndex: number): readonly CellValue[]
|
|
201
|
-
setColumnData(columnIndex: number, data: readonly CellValue[]): void
|
|
207
|
+
getColumnData(index: number): readonly CellValue[]
|
|
208
|
+
setColumnData(index: number, data: readonly CellValue[]): void
|
|
202
209
|
```
|
|
203
210
|
|
|
204
211
|
#### Cell Methods
|
|
205
212
|
|
|
206
213
|
```typescript
|
|
207
|
-
getCell(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
setCellRange(startRow: number, startCol: number, data: readonly (readonly CellValue[])[]): void
|
|
211
|
-
getCellElement(rowIndex: number, columnIndex: number): HTMLTableCellElement | null
|
|
214
|
+
getCell(row: number, column: number): HTMLTableCellElement | null
|
|
215
|
+
getCellValue(row: number, column: number): CellValue
|
|
216
|
+
setCell(row: number, column: number, value: CellValue): void
|
|
212
217
|
```
|
|
213
218
|
|
|
214
219
|
#### Selection Methods
|
|
@@ -219,84 +224,66 @@ deselectRow(index: number): void
|
|
|
219
224
|
toggleRowSelection(index: number): void
|
|
220
225
|
selectAllRows(): void
|
|
221
226
|
deselectAllRows(): void
|
|
222
|
-
selectRowRange(startIndex: number, endIndex: number): void
|
|
223
227
|
isRowSelected(index: number): boolean
|
|
224
|
-
getSelectedRowIndices(): number[]
|
|
225
|
-
getSelectedRowData(): readonly CellValue[][]
|
|
228
|
+
getSelectedRowIndices(): readonly number[]
|
|
229
|
+
getSelectedRowData(): readonly (readonly CellValue[])[]
|
|
226
230
|
|
|
227
|
-
selectCell(
|
|
228
|
-
deselectCell(
|
|
229
|
-
toggleCellSelection(
|
|
230
|
-
isCellSelected(
|
|
231
|
+
selectCell(row: number, column: number): void
|
|
232
|
+
deselectCell(row: number, column: number): void
|
|
233
|
+
toggleCellSelection(row: number, column: number): void
|
|
234
|
+
isCellSelected(row: number, column: number): boolean
|
|
231
235
|
clearSelection(): void
|
|
232
236
|
```
|
|
233
237
|
|
|
234
238
|
#### Focus Methods
|
|
235
239
|
|
|
236
240
|
```typescript
|
|
237
|
-
focusCell(
|
|
241
|
+
focusCell(row: number, column: number): void
|
|
238
242
|
clearFocus(): void
|
|
239
|
-
getFocusedCell():
|
|
240
|
-
isCellFocused(
|
|
243
|
+
getFocusedCell(): CellPosition | null
|
|
244
|
+
isCellFocused(row: number, column: number): boolean
|
|
241
245
|
moveFocusUp(): boolean
|
|
242
246
|
moveFocusDown(): boolean
|
|
243
247
|
moveFocusLeft(): boolean
|
|
244
248
|
moveFocusRight(): boolean
|
|
245
|
-
|
|
246
|
-
moveFocusToLast(): void
|
|
249
|
+
enableKeyboardNavigation(): () => void // Returns cleanup function
|
|
247
250
|
```
|
|
248
251
|
|
|
249
252
|
#### Footer Methods
|
|
250
253
|
|
|
251
254
|
```typescript
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
getFooterCell(index: number): string | undefined
|
|
255
|
+
getFooter(): RowData | null
|
|
256
|
+
setFooter(data: RowData): void
|
|
255
257
|
clearFooter(): void
|
|
256
258
|
```
|
|
257
259
|
|
|
258
|
-
####
|
|
260
|
+
#### Caption Methods
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
getCaption(): string | null
|
|
264
|
+
setCaption(text: string): void
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
#### Bulk Operations
|
|
259
268
|
|
|
260
269
|
```typescript
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
): void
|
|
265
|
-
|
|
266
|
-
addRecord<T extends BaseRecord>(
|
|
267
|
-
record: T,
|
|
268
|
-
fields: readonly (keyof T | ((record: T) => CellValue))[],
|
|
269
|
-
index?: number
|
|
270
|
-
): string
|
|
271
|
-
|
|
272
|
-
getRecordData(id: string): readonly CellValue[] | undefined
|
|
273
|
-
updateRecordRow(id: string, data: readonly CellValue[]): boolean
|
|
274
|
-
removeRecord(id: string): boolean
|
|
275
|
-
hasRecord(id: string): boolean
|
|
276
|
-
selectRecords(ids: readonly string[]): void
|
|
277
|
-
getSelectedRecordIds(): string[]
|
|
270
|
+
getData(): TableData
|
|
271
|
+
setData(data: TableData): void
|
|
272
|
+
sync(): void // Trigger reactive update
|
|
278
273
|
```
|
|
279
274
|
|
|
280
275
|
#### Event Subscriptions
|
|
281
276
|
|
|
282
277
|
```typescript
|
|
283
|
-
onRowAdd(callback:
|
|
284
|
-
onRowRemove(callback:
|
|
285
|
-
|
|
286
|
-
onCellChange(callback: CellChangeCallback): () => void
|
|
287
|
-
onHeaderChange(callback: HeaderChangeCallback): () => void
|
|
288
|
-
onDataChange(callback: DataChangeCallback): () => void
|
|
289
|
-
onSelectionChange(callback: SelectionChangeCallback): () => void
|
|
290
|
-
onFocusChange(callback: FocusChangeCallback): () => void
|
|
278
|
+
onRowAdd(callback: (index: number, id: string | null) => void): () => void
|
|
279
|
+
onRowRemove(callback: (index: number, id: string | null) => void): () => void
|
|
280
|
+
onDataChange(callback: () => void): () => void
|
|
291
281
|
```
|
|
292
282
|
|
|
293
283
|
#### Lifecycle Methods
|
|
294
284
|
|
|
295
285
|
```typescript
|
|
296
|
-
|
|
297
|
-
sync(): void // Re-sync state from DOM
|
|
298
|
-
destroy(): void // Cleanup all resources
|
|
299
|
-
reset(): void // Clear all table content
|
|
286
|
+
destroy(): void // Cleanup all resources
|
|
300
287
|
```
|
|
301
288
|
|
|
302
289
|
### createTable
|
|
@@ -325,21 +312,22 @@ console.log(table.getRowCount()) // 3
|
|
|
325
312
|
// Cell value can be string, number, boolean, null, or DOM element
|
|
326
313
|
type CellValue = string | number | boolean | null | undefined | Node
|
|
327
314
|
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
315
|
+
// Row data is an array of cell values
|
|
316
|
+
type RowData = readonly CellValue[]
|
|
317
|
+
|
|
318
|
+
// Table data is a 2D array
|
|
319
|
+
type TableData = readonly RowData[]
|
|
320
|
+
|
|
321
|
+
// Cell position for focus/navigation
|
|
322
|
+
interface CellPosition {
|
|
323
|
+
readonly row: number
|
|
324
|
+
readonly column: number
|
|
332
325
|
}
|
|
333
326
|
|
|
334
327
|
// Callback types
|
|
335
|
-
type RowAddCallback = (data: readonly CellValue[], index: number, id: string |
|
|
336
|
-
type RowRemoveCallback = (data: readonly CellValue[], index: number, id: string |
|
|
337
|
-
type RowUpdateCallback = (data: readonly CellValue[], index: number) => void
|
|
338
|
-
type CellChangeCallback = (rowIndex: number, columnIndex: number, oldValue: CellValue, newValue: CellValue) => void
|
|
339
|
-
type HeaderChangeCallback = (headers: readonly string[]) => void
|
|
328
|
+
type RowAddCallback = (data: readonly CellValue[], index: number, id: string | null) => void
|
|
329
|
+
type RowRemoveCallback = (data: readonly CellValue[], index: number, id: string | null) => void
|
|
340
330
|
type DataChangeCallback = (data: readonly (readonly CellValue[])[]) => void
|
|
341
|
-
type SelectionChangeCallback = (rows: ReadonlySet<number>, cells: ReadonlySet<string>) => void
|
|
342
|
-
type FocusChangeCallback = (cell: { row: number; column: number } | null) => void
|
|
343
331
|
```
|
|
344
332
|
|
|
345
333
|
## Examples
|