@revisium/schema-toolkit-ui 0.3.2 → 0.4.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/README.md +118 -1
- package/dist/index.cjs +6975 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1418 -54
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1418 -54
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +6916 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -141,9 +141,126 @@ const vm = new RowEditorVM(tableSchema, rowData, {
|
|
|
141
141
|
<RowEditor vm={vm} />
|
|
142
142
|
```
|
|
143
143
|
|
|
144
|
+
### Table editor
|
|
145
|
+
|
|
146
|
+
`TableEditor` renders a full table UI with inline cell editing, filtering, sorting, search, column management, row selection, and view persistence. It takes a `TableEditorCore` view model and a few external callbacks.
|
|
147
|
+
|
|
148
|
+
#### Data source
|
|
149
|
+
|
|
150
|
+
Implement `ITableDataSource` to connect the table to your backend:
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
import type { ITableDataSource } from '@revisium/schema-toolkit-ui';
|
|
154
|
+
|
|
155
|
+
const dataSource: ITableDataSource = {
|
|
156
|
+
async fetchMetadata() {
|
|
157
|
+
// Return { schema, columns, viewState, readonly }
|
|
158
|
+
},
|
|
159
|
+
async fetchRows(query) {
|
|
160
|
+
// query: { where, orderBy, search, first, after }
|
|
161
|
+
// Return { rows, totalCount, hasNextPage, endCursor }
|
|
162
|
+
},
|
|
163
|
+
async patchCells(patches) {
|
|
164
|
+
// patches: [{ rowId, field, value }]
|
|
165
|
+
// Return [{ rowId, field, ok, error? }]
|
|
166
|
+
},
|
|
167
|
+
async deleteRows(rowIds) {
|
|
168
|
+
// Return { ok, error? }
|
|
169
|
+
},
|
|
170
|
+
async saveView(viewState) {
|
|
171
|
+
// Persist column/filter/sort/search settings
|
|
172
|
+
// Return { ok, error? }
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### Creating the view model
|
|
178
|
+
|
|
179
|
+
Breadcrumbs and callbacks are passed through the view model options (same pattern as `RowEditorVM`):
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
import { TableEditorCore } from '@revisium/schema-toolkit-ui';
|
|
183
|
+
import type { TableEditorBreadcrumb, TableEditorCallbacks } from '@revisium/schema-toolkit-ui';
|
|
184
|
+
|
|
185
|
+
const breadcrumbs: TableEditorBreadcrumb[] = [
|
|
186
|
+
{ label: 'Database' },
|
|
187
|
+
{ label: 'invoices' },
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
const callbacks: TableEditorCallbacks = {
|
|
191
|
+
onBreadcrumbClick: (segment, index) => navigate('/tables'),
|
|
192
|
+
onCreateRow: () => createRow(),
|
|
193
|
+
onOpenRow: (rowId) => navigate(`/rows/${rowId}`),
|
|
194
|
+
onDuplicateRow: (rowId) => duplicateRow(rowId),
|
|
195
|
+
onSearchForeignKey: async (tableId, search) => { ... },
|
|
196
|
+
onCopyPath: (path) => navigator.clipboard.writeText(path),
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const core = new TableEditorCore(dataSource, {
|
|
200
|
+
tableId: 'invoices',
|
|
201
|
+
pageSize: 50, // optional, default 50
|
|
202
|
+
breadcrumbs,
|
|
203
|
+
callbacks,
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
`TableEditorCore` bootstraps automatically (fetches metadata, applies saved view state, loads the first page of rows).
|
|
208
|
+
|
|
209
|
+
#### Rendering
|
|
210
|
+
|
|
211
|
+
The component takes only the view model. All callbacks and breadcrumbs come from the view model:
|
|
212
|
+
|
|
213
|
+
```tsx
|
|
214
|
+
import { TableEditor } from '@revisium/schema-toolkit-ui';
|
|
215
|
+
|
|
216
|
+
<TableEditor viewModel={core} />
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
The component renders breadcrumbs with a "New row" button, a toolbar (search, filters, sorts), the virtualized table, and a status bar (row count, view settings badge) — all on a single header line.
|
|
220
|
+
|
|
221
|
+
In read-only mode, the "New row" button is hidden automatically.
|
|
222
|
+
|
|
223
|
+
#### Props
|
|
224
|
+
|
|
225
|
+
| Prop | Type | Description |
|
|
226
|
+
|------|------|-------------|
|
|
227
|
+
| `viewModel` | `TableEditorCore` | Required. The table view model |
|
|
228
|
+
| `useWindowScroll` | `boolean` | Use window scroll instead of container scroll |
|
|
229
|
+
|
|
230
|
+
#### Callbacks (`TableEditorCallbacks`)
|
|
231
|
+
|
|
232
|
+
All callbacks are optional and passed via `TableEditorOptions.callbacks`:
|
|
233
|
+
|
|
234
|
+
| Callback | Type | Description |
|
|
235
|
+
|----------|------|-------------|
|
|
236
|
+
| `onBreadcrumbClick` | `(segment, index) => void` | Navigate on breadcrumb click |
|
|
237
|
+
| `onCreateRow` | `() => void` | Create a new row (shows "+" button) |
|
|
238
|
+
| `onOpenRow` | `(rowId: string) => void` | Navigate to row detail view |
|
|
239
|
+
| `onDuplicateRow` | `(rowId: string) => void` | Duplicate a row |
|
|
240
|
+
| `onSearchForeignKey` | `SearchForeignKeySearchFn` | Foreign key search handler |
|
|
241
|
+
| `onCopyPath` | `(path: string) => void` | Copy JSON path to clipboard |
|
|
242
|
+
|
|
243
|
+
In read-only mode (`fetchMetadata` returns `readonly: true`), delete and duplicate actions are hidden automatically. Open row still works.
|
|
244
|
+
|
|
245
|
+
#### View model API
|
|
246
|
+
|
|
247
|
+
```tsx
|
|
248
|
+
core.rows // current RowVM[]
|
|
249
|
+
core.isBootstrapping // true during initial load
|
|
250
|
+
core.isLoadingMore // true during pagination
|
|
251
|
+
core.readonly // read-only flag from metadata
|
|
252
|
+
core.tableId // table identifier
|
|
253
|
+
|
|
254
|
+
core.loadMore() // load next page
|
|
255
|
+
core.deleteRows(ids) // delete rows by ID
|
|
256
|
+
core.getViewState() // serialize current view settings
|
|
257
|
+
core.applyViewState(s) // restore view settings
|
|
258
|
+
core.dispose() // cleanup
|
|
259
|
+
```
|
|
260
|
+
|
|
144
261
|
### Cleanup
|
|
145
262
|
|
|
146
|
-
Call `vm.dispose()` when the editor is unmounted.
|
|
263
|
+
Call `vm.dispose()` (or `core.dispose()` for `TableEditorCore`) when the editor is unmounted.
|
|
147
264
|
|
|
148
265
|
## License
|
|
149
266
|
|