@liteforge/table 0.1.0
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/LICENSE +21 -0
- package/README.md +318 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.d.ts +16 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/styles.js +345 -0
- package/dist/styles.js.map +1 -0
- package/dist/table.d.ts +9 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +737 -0
- package/dist/table.js.map +1 -0
- package/dist/types.d.ts +165 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SchildW3rk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
# @liteforge/table
|
|
2
|
+
|
|
3
|
+
Signals-based data table with sorting, filtering, pagination, and selection for LiteForge.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @liteforge/table @liteforge/core @liteforge/runtime
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependencies: `@liteforge/core >= 0.1.0`, `@liteforge/runtime >= 0.1.0`
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
`@liteforge/table` provides a full-featured, reactive data table component. All state is signal-based for automatic reactivity.
|
|
16
|
+
|
|
17
|
+
## Basic Usage
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { createTable } from '@liteforge/table'
|
|
21
|
+
|
|
22
|
+
const table = createTable({
|
|
23
|
+
data: () => users,
|
|
24
|
+
columns: [
|
|
25
|
+
{ key: 'id', header: 'ID', width: 60 },
|
|
26
|
+
{ key: 'name', header: 'Name', sortable: true },
|
|
27
|
+
{ key: 'email', header: 'Email', sortable: true }
|
|
28
|
+
]
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// In JSX
|
|
32
|
+
<table.Root />
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
### createTable
|
|
38
|
+
|
|
39
|
+
Creates a reactive table instance.
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { createTable } from '@liteforge/table'
|
|
43
|
+
|
|
44
|
+
const table = createTable<User>({
|
|
45
|
+
// Data source (signal or getter)
|
|
46
|
+
data: () => usersQuery.data() ?? [],
|
|
47
|
+
|
|
48
|
+
// Column definitions
|
|
49
|
+
columns: [
|
|
50
|
+
{ key: 'id', header: 'ID', width: 60, sortable: true },
|
|
51
|
+
{ key: 'name', header: 'Name', sortable: true, filterable: true },
|
|
52
|
+
{ key: 'email', header: 'Email', sortable: true },
|
|
53
|
+
{ key: 'company.name', header: 'Company', sortable: true }, // Nested access
|
|
54
|
+
{
|
|
55
|
+
key: 'website',
|
|
56
|
+
header: 'Website',
|
|
57
|
+
cell: (value) => <a href={`https://${value}`}>{value}</a>
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: '_actions', // Virtual column (no data field)
|
|
61
|
+
header: '',
|
|
62
|
+
cell: (_, row) => (
|
|
63
|
+
<button onclick={() => editUser(row)}>Edit</button>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
|
|
68
|
+
// Features
|
|
69
|
+
search: {
|
|
70
|
+
enabled: true,
|
|
71
|
+
columns: ['name', 'email'],
|
|
72
|
+
placeholder: 'Search users...'
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
filters: {
|
|
76
|
+
'company.name': { type: 'select' }
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
pagination: {
|
|
80
|
+
pageSize: 20,
|
|
81
|
+
pageSizes: [10, 20, 50, 100]
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
selection: {
|
|
85
|
+
enabled: true,
|
|
86
|
+
mode: 'multi' // 'single' | 'multi'
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
columnToggle: true,
|
|
90
|
+
|
|
91
|
+
// Callbacks
|
|
92
|
+
onRowClick: (row) => navigate(`/users/${row.id}`),
|
|
93
|
+
rowClass: (row) => row.active ? '' : 'row-inactive'
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Column Definition
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
interface ColumnDef<T> {
|
|
101
|
+
key: string // Data field or '_prefix' for virtual
|
|
102
|
+
header: string // Column header text
|
|
103
|
+
width?: number | string // Column width
|
|
104
|
+
sortable?: boolean // Enable sorting
|
|
105
|
+
filterable?: boolean // Enable filtering
|
|
106
|
+
visible?: boolean // Initial visibility (default: true)
|
|
107
|
+
cell?: (value, row) => Node // Custom cell renderer
|
|
108
|
+
headerCell?: () => Node // Custom header renderer
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Table State
|
|
113
|
+
|
|
114
|
+
All state properties are signals:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
// Sorting
|
|
118
|
+
table.sorting() // { key: string, direction: 'asc' | 'desc' } | null
|
|
119
|
+
table.sort('name', 'asc') // Set sort
|
|
120
|
+
table.clearSort() // Remove sort
|
|
121
|
+
|
|
122
|
+
// Search
|
|
123
|
+
table.searchQuery() // Current search text
|
|
124
|
+
table.setSearch('query') // Set search text
|
|
125
|
+
|
|
126
|
+
// Filters
|
|
127
|
+
table.filters() // { 'company.name': 'Acme', ... }
|
|
128
|
+
table.setFilter('status', 'active')
|
|
129
|
+
table.clearFilter('status')
|
|
130
|
+
table.clearAllFilters()
|
|
131
|
+
|
|
132
|
+
// Pagination
|
|
133
|
+
table.page() // Current page (0-indexed)
|
|
134
|
+
table.setPage(2)
|
|
135
|
+
table.nextPage()
|
|
136
|
+
table.prevPage()
|
|
137
|
+
table.pageSize() // Items per page
|
|
138
|
+
table.setPageSize(50)
|
|
139
|
+
table.totalPages() // Total number of pages
|
|
140
|
+
table.totalRows() // Total rows before pagination
|
|
141
|
+
|
|
142
|
+
// Selection
|
|
143
|
+
table.selected() // Selected rows
|
|
144
|
+
table.selectedCount() // Number of selected rows
|
|
145
|
+
table.selectAll()
|
|
146
|
+
table.deselectAll()
|
|
147
|
+
table.toggleRow(row)
|
|
148
|
+
table.isSelected(row) // Check if row is selected
|
|
149
|
+
|
|
150
|
+
// Columns
|
|
151
|
+
table.visibleColumns() // Array of visible column keys
|
|
152
|
+
table.showColumn('email')
|
|
153
|
+
table.hideColumn('email')
|
|
154
|
+
table.toggleColumn('email')
|
|
155
|
+
|
|
156
|
+
// Processed data
|
|
157
|
+
table.rows() // Current visible rows (filtered + sorted + paginated)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Filter Types
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
const table = createTable({
|
|
164
|
+
data: () => users,
|
|
165
|
+
columns: [...],
|
|
166
|
+
filters: {
|
|
167
|
+
// Text filter (with debounce)
|
|
168
|
+
name: { type: 'text', debounce: 300 },
|
|
169
|
+
|
|
170
|
+
// Select filter (options auto-generated from data)
|
|
171
|
+
status: { type: 'select' },
|
|
172
|
+
|
|
173
|
+
// Select with custom options
|
|
174
|
+
role: {
|
|
175
|
+
type: 'select',
|
|
176
|
+
options: [
|
|
177
|
+
{ value: 'admin', label: 'Administrator' },
|
|
178
|
+
{ value: 'user', label: 'User' }
|
|
179
|
+
]
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
// Boolean filter
|
|
183
|
+
active: { type: 'boolean' },
|
|
184
|
+
|
|
185
|
+
// Number range filter
|
|
186
|
+
age: { type: 'number-range', min: 0, max: 120 }
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Styling
|
|
192
|
+
|
|
193
|
+
The table provides three styling layers:
|
|
194
|
+
|
|
195
|
+
**1. BEM classes (always present):**
|
|
196
|
+
```css
|
|
197
|
+
.lf-table
|
|
198
|
+
.lf-table-header
|
|
199
|
+
.lf-table-row
|
|
200
|
+
.lf-table-cell
|
|
201
|
+
.lf-table-pagination
|
|
202
|
+
/* etc. */
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**2. CSS Variables (override defaults):**
|
|
206
|
+
```css
|
|
207
|
+
:root {
|
|
208
|
+
--lf-table-border-color: #e5e7eb;
|
|
209
|
+
--lf-table-header-bg: #f9fafb;
|
|
210
|
+
--lf-table-row-hover: #f3f4f6;
|
|
211
|
+
--lf-table-selected-bg: #eff6ff;
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**3. Custom classes (Tailwind, etc.):**
|
|
216
|
+
```ts
|
|
217
|
+
const table = createTable({
|
|
218
|
+
data: () => users,
|
|
219
|
+
columns: [...],
|
|
220
|
+
classes: {
|
|
221
|
+
root: 'rounded-lg shadow',
|
|
222
|
+
header: 'bg-gray-100',
|
|
223
|
+
row: 'hover:bg-gray-50',
|
|
224
|
+
cell: 'px-4 py-2'
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**4. Unstyled mode:**
|
|
230
|
+
```ts
|
|
231
|
+
const table = createTable({
|
|
232
|
+
data: () => users,
|
|
233
|
+
columns: [...],
|
|
234
|
+
unstyled: true // No default styles injected
|
|
235
|
+
})
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## Usage in Components
|
|
239
|
+
|
|
240
|
+
```tsx
|
|
241
|
+
import { createComponent } from '@liteforge/runtime'
|
|
242
|
+
import { createQuery } from '@liteforge/query'
|
|
243
|
+
import { createTable } from '@liteforge/table'
|
|
244
|
+
|
|
245
|
+
const UserTable = createComponent({
|
|
246
|
+
component: () => {
|
|
247
|
+
const users = createQuery({
|
|
248
|
+
key: 'users',
|
|
249
|
+
fn: () => fetch('/api/users').then(r => r.json())
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
const table = createTable({
|
|
253
|
+
data: () => users.data() ?? [],
|
|
254
|
+
columns: [
|
|
255
|
+
{ key: 'name', header: 'Name', sortable: true },
|
|
256
|
+
{ key: 'email', header: 'Email', sortable: true },
|
|
257
|
+
{ key: 'role', header: 'Role', filterable: true },
|
|
258
|
+
{
|
|
259
|
+
key: '_actions',
|
|
260
|
+
header: '',
|
|
261
|
+
cell: (_, row) => (
|
|
262
|
+
<div>
|
|
263
|
+
<button onclick={() => editUser(row)}>Edit</button>
|
|
264
|
+
<button onclick={() => deleteUser(row.id)}>Delete</button>
|
|
265
|
+
</div>
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
],
|
|
269
|
+
search: { enabled: true, columns: ['name', 'email'] },
|
|
270
|
+
pagination: { pageSize: 25 },
|
|
271
|
+
selection: { enabled: true, mode: 'multi' }
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
const handleBulkDelete = () => {
|
|
275
|
+
const ids = table.selected().map(u => u.id)
|
|
276
|
+
deleteUsers(ids)
|
|
277
|
+
table.deselectAll()
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return (
|
|
281
|
+
<div>
|
|
282
|
+
<Show when={() => table.selectedCount() > 0}>
|
|
283
|
+
<button onclick={handleBulkDelete}>
|
|
284
|
+
Delete {() => table.selectedCount()} selected
|
|
285
|
+
</button>
|
|
286
|
+
</Show>
|
|
287
|
+
|
|
288
|
+
<table.Root />
|
|
289
|
+
</div>
|
|
290
|
+
)
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Types
|
|
296
|
+
|
|
297
|
+
```ts
|
|
298
|
+
import type {
|
|
299
|
+
TableOptions,
|
|
300
|
+
TableResult,
|
|
301
|
+
ColumnDef,
|
|
302
|
+
TableClasses,
|
|
303
|
+
FilterDef,
|
|
304
|
+
TextFilterDef,
|
|
305
|
+
SelectFilterDef,
|
|
306
|
+
BooleanFilterDef,
|
|
307
|
+
NumberRangeFilterDef,
|
|
308
|
+
SortState,
|
|
309
|
+
SortDirection,
|
|
310
|
+
SearchOptions,
|
|
311
|
+
PaginationOptions,
|
|
312
|
+
SelectionOptions
|
|
313
|
+
} from '@liteforge/table'
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## License
|
|
317
|
+
|
|
318
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @liteforge/table
|
|
3
|
+
*
|
|
4
|
+
* Signals-based data table with sorting, filtering, pagination, and selection.
|
|
5
|
+
*/
|
|
6
|
+
export { createTable } from './table.js';
|
|
7
|
+
export type { TableOptions, TableResult, ColumnDef, TableClasses, FilterDef, TextFilterDef, SelectFilterDef, BooleanFilterDef, NumberRangeFilterDef, SortState, SortDirection, SearchOptions, PaginationOptions, SelectionOptions, } from './types.js';
|
|
8
|
+
export { injectDefaultStyles, resetStylesInjection } from './styles.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,YAAY,EAEV,YAAY,EACZ,WAAW,EACX,SAAS,EACT,YAAY,EAGZ,SAAS,EACT,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EAGpB,SAAS,EACT,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @liteforge/table
|
|
3
|
+
*
|
|
4
|
+
* Signals-based data table with sorting, filtering, pagination, and selection.
|
|
5
|
+
*/
|
|
6
|
+
export { createTable } from './table.js';
|
|
7
|
+
export { injectDefaultStyles, resetStylesInjection } from './styles.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAwBxC,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @liteforge/table - Default CSS Theme
|
|
3
|
+
*
|
|
4
|
+
* Minimal, clean default styles using CSS variables.
|
|
5
|
+
* Injected once when the first table renders (unless unstyled: true).
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Inject default styles into the document head.
|
|
9
|
+
* Called automatically when the first table is created (unless unstyled: true).
|
|
10
|
+
*/
|
|
11
|
+
export declare function injectDefaultStyles(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Reset styles injection flag (for testing)
|
|
14
|
+
*/
|
|
15
|
+
export declare function resetStylesInjection(): void;
|
|
16
|
+
//# sourceMappingURL=styles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6TH;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAU1C;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAM3C"}
|