@revisium/schema-toolkit-ui 0.3.3 → 0.5.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 +143 -2
- package/dist/index.cjs +7324 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1505 -55
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1505 -55
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +7265 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -97,7 +97,7 @@ const vm = new RowEditorVM(tableSchema, existingRowData, {
|
|
|
97
97
|
refSchemas: { ... },
|
|
98
98
|
callbacks: {
|
|
99
99
|
onSearchForeignKey: async (tableId, search) => { ... },
|
|
100
|
-
onUploadFile: async (fileId, file) => { ... },
|
|
100
|
+
onUploadFile: async ({ rowId, fileId, file }) => { ... },
|
|
101
101
|
onOpenFile: (url) => window.open(url, '_blank', 'noopener,noreferrer'),
|
|
102
102
|
onNavigateToForeignKey: (tableId, rowId) => { ... },
|
|
103
103
|
},
|
|
@@ -141,9 +141,150 @@ 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
|
+
| `onUploadFile` | `(params: { rowId: string; fileId: string; file: File }) => Promise<Record<string, unknown> \| null>` | Upload a file for a file field |
|
|
242
|
+
| `onOpenFile` | `(url: string) => void` | Open/preview a file URL |
|
|
243
|
+
| `onCopyPath` | `(path: string) => void` | Copy JSON path to clipboard |
|
|
244
|
+
|
|
245
|
+
In read-only mode (`fetchMetadata` returns `readonly: true`), delete and duplicate actions are hidden automatically. Open row still works.
|
|
246
|
+
|
|
247
|
+
#### File columns
|
|
248
|
+
|
|
249
|
+
File fields (`$ref` to the File schema) are automatically resolved into:
|
|
250
|
+
- A **parent file column** (`FilterFieldType.File`) that displays the `fileName` and supports inline editing of the file name
|
|
251
|
+
- **Sub-field columns** (e.g., `avatar.status`, `avatar.url`) for each primitive property of the file object
|
|
252
|
+
|
|
253
|
+
Sub-field columns are hidden by default but can be added via the "+" column button. File columns are excluded from filters and sorts.
|
|
254
|
+
|
|
255
|
+
To enable file upload/preview in the table, pass `onUploadFile` and `onOpenFile` in `TableEditorCallbacks`. The file cell shows upload and preview buttons on hover when these callbacks are provided. File schemas must be passed through `fetchMetadata` as `refSchemas` in the `TableMetadata` return value:
|
|
256
|
+
|
|
257
|
+
```tsx
|
|
258
|
+
async fetchMetadata() {
|
|
259
|
+
return {
|
|
260
|
+
schema,
|
|
261
|
+
columns,
|
|
262
|
+
viewState,
|
|
263
|
+
readonly: false,
|
|
264
|
+
refSchemas: { [SystemSchemaIds.File]: fileSchema },
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### View model API
|
|
270
|
+
|
|
271
|
+
```tsx
|
|
272
|
+
core.rows // current RowVM[]
|
|
273
|
+
core.isBootstrapping // true during initial load
|
|
274
|
+
core.isLoadingMore // true during pagination
|
|
275
|
+
core.readonly // read-only flag from metadata
|
|
276
|
+
core.tableId // table identifier
|
|
277
|
+
|
|
278
|
+
core.loadMore() // load next page
|
|
279
|
+
core.deleteRows(ids) // delete rows by ID
|
|
280
|
+
core.getViewState() // serialize current view settings
|
|
281
|
+
core.applyViewState(s) // restore view settings
|
|
282
|
+
core.dispose() // cleanup
|
|
283
|
+
```
|
|
284
|
+
|
|
144
285
|
### Cleanup
|
|
145
286
|
|
|
146
|
-
Call `vm.dispose()` when the editor is unmounted.
|
|
287
|
+
Call `vm.dispose()` (or `core.dispose()` for `TableEditorCore`) when the editor is unmounted.
|
|
147
288
|
|
|
148
289
|
## License
|
|
149
290
|
|