@cervio/plugin-sdk 2.2.0 → 2.3.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 +62 -0
- package/dist/forms/index.d.ts +360 -0
- package/dist/forms/index.js +416 -0
- package/dist/forms/react.d.ts +381 -0
- package/dist/forms/react.js +1159 -0
- package/dist/index.d.ts +12 -1
- package/dist/views/index.d.ts +450 -0
- package/dist/views/index.js +570 -0
- package/dist/views/react.d.ts +406 -0
- package/dist/views/react.js +1368 -0
- package/package.json +22 -2
package/README.md
CHANGED
|
@@ -116,6 +116,68 @@ markReady() // Cervio times the plugin open up to here; no-op outside Cervio
|
|
|
116
116
|
access token), for use outside the iframe (e.g. server-side scripts against a
|
|
117
117
|
Cervio org).
|
|
118
118
|
|
|
119
|
+
## Views (`./views`, `./views/react`)
|
|
120
|
+
|
|
121
|
+
The view is Cervio's, the presentation is the plugin's. Underneath, the view
|
|
122
|
+
engine (bundled in this package, nothing else to install) is the skeleton of a Cervio view:
|
|
123
|
+
definition, permissions, filters, text search, sorting, grouping, paging and the
|
|
124
|
+
saved column layout, all through Cervio's own API. On top, the plugin draws it
|
|
125
|
+
as it likes: a table, cards, a kanban.
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import { useCervioView } from '@cervio/plugin-sdk/views/react'
|
|
129
|
+
|
|
130
|
+
const v = useCervioView({ view: viewId })
|
|
131
|
+
v.setFilter('stato', { type: 'text', operator: 'equals', values: ['aperto'] })
|
|
132
|
+
v.setFilter('cliente', { type: 'relation', operator: 'equals', values: [clienteId] })
|
|
133
|
+
v.setSearch('AB 123')
|
|
134
|
+
v.toggleSort('importo') // asc, desc, off; saved like the Cervio grid
|
|
135
|
+
v.setGrouping(['stato']) // v.groups: [{ label, count, rows }]
|
|
136
|
+
v.setColumnSize('targa', 180) // layout saved for this plugin only (plugin:<plugin_key>)
|
|
137
|
+
// v.rows (sorted), v.groups, v.visibleColumns, v.total, v.hasMore, v.loadMore()
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Without React: `createPluginViewController({ view })` from `@cervio/plugin-sdk/views`
|
|
141
|
+
(`subscribe` + `getState`). Declare in the manifest `cervio_apis`:
|
|
142
|
+
`GET /api/v1/views`, `POST /api/v1/views`, `GET /api/v1/me/view-prefs`,
|
|
143
|
+
`PUT /api/v1/me/view-prefs`. Needs a Cervio host with the view API
|
|
144
|
+
(`GET /api/v1/views/{viewId}`); older hosts answer 404.
|
|
145
|
+
|
|
146
|
+
Optional pieces with the Cervio look are exported by the same entry. They only draw: every action goes to the skeleton.
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
import { DataGrid, FilterBar, GroupByMenu, SearchBox, useCervioView } from '@cervio/plugin-sdk/views/react'
|
|
150
|
+
|
|
151
|
+
const { controller } = useCervioView({ view: viewId })
|
|
152
|
+
<SearchBox controller={controller} />
|
|
153
|
+
<FilterBar controller={controller} fields={['stato', 'cliente', 'urgente']} />
|
|
154
|
+
<GroupByMenu controller={controller} />
|
|
155
|
+
<DataGrid controller={controller} /> // or your own cards / kanban from v.rows / v.groups
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Forms (`./forms`, `./forms/react`)
|
|
159
|
+
|
|
160
|
+
A Cervio form inside the plugin: the form is Cervio's (fields, layout,
|
|
161
|
+
permissions, rules, validation, save), the plugin decides how to present it.
|
|
162
|
+
Rules are evaluated by Cervio after each change, never in the plugin.
|
|
163
|
+
|
|
164
|
+
```tsx
|
|
165
|
+
import { useCervioForm, FormLayout, FormActions } from '@cervio/plugin-sdk/forms/react'
|
|
166
|
+
|
|
167
|
+
const f = useCervioForm({ entity: 'contratti', form: 'scheda_contratto', recordId })
|
|
168
|
+
return (
|
|
169
|
+
<>
|
|
170
|
+
<FormLayout controller={f.controller} />
|
|
171
|
+
<FormActions controller={f.controller} />
|
|
172
|
+
</>
|
|
173
|
+
)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Labels, choices and texts come in the user's language, as in Cervio (pass
|
|
177
|
+
`locale` to choose another). Draw your own inputs with `f.values`, `f.fieldState`,
|
|
178
|
+
`f.errors` and `f.setValue`, or mix them with the `Field` piece. Declare in `cervio_apis`: `GET`, `POST` and
|
|
179
|
+
`PATCH` on `/api/v1/entities`. The form engine and pieces are bundled in this package.
|
|
180
|
+
|
|
119
181
|
## Theme
|
|
120
182
|
|
|
121
183
|
```ts
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The form contract as Cervio exposes it (`GET …/forms/{form}/write-schema?include=layout`,
|
|
3
|
+
* `POST …/validate-draft`). The engine reads it; it never invents rules of its own.
|
|
4
|
+
*/
|
|
5
|
+
interface FormInfo {
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
label: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* How a value is chosen. `none`: a free value, its input follows `field_type`
|
|
12
|
+
* (text, number, date, …); the others pick among choices.
|
|
13
|
+
*/
|
|
14
|
+
type FormInputMode = 'none' | 'boolean' | 'fixed_list' | 'remote_options' | 'relation' | (string & {});
|
|
15
|
+
interface FormOption {
|
|
16
|
+
value: string;
|
|
17
|
+
label: string;
|
|
18
|
+
}
|
|
19
|
+
interface FormFieldInput {
|
|
20
|
+
mode: FormInputMode;
|
|
21
|
+
/** Choices of a small fixed list, inline. Larger lists: `controller.fieldOptions()`. */
|
|
22
|
+
options?: FormOption[];
|
|
23
|
+
relation_entity_id?: string;
|
|
24
|
+
/** A relation holding several linked records (`uuid[]`). */
|
|
25
|
+
multi_select?: boolean;
|
|
26
|
+
storage?: string;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
interface FormFieldSchema {
|
|
30
|
+
name: string;
|
|
31
|
+
label: string;
|
|
32
|
+
field_type: string;
|
|
33
|
+
/** What the value looks like: `string`, `number`, `boolean`, `uuid`, `uuid[]`, … */
|
|
34
|
+
value_shape?: string;
|
|
35
|
+
required: boolean;
|
|
36
|
+
readonly: boolean;
|
|
37
|
+
order: number;
|
|
38
|
+
input: FormFieldInput;
|
|
39
|
+
/** Cervio fills it on save (`default` when empty, `computed` always). */
|
|
40
|
+
server_filled?: 'default' | 'computed';
|
|
41
|
+
client_may_omit?: boolean;
|
|
42
|
+
/** Conditional rules exist: visibility, required, readonly may change with the values. */
|
|
43
|
+
rules?: {
|
|
44
|
+
has_conditional_rules?: boolean;
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
};
|
|
47
|
+
/** Help text of the field on this form. */
|
|
48
|
+
instructions?: string | null;
|
|
49
|
+
[key: string]: unknown;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Blocks carry the `id` Cervio uses in `hidden_blocks`; steps carry their own. A field
|
|
53
|
+
* node's `id` keys its entry in `field_display` (a field placed twice has two).
|
|
54
|
+
*/
|
|
55
|
+
type FormLayoutNode = {
|
|
56
|
+
type: 'field';
|
|
57
|
+
id?: string;
|
|
58
|
+
field: string;
|
|
59
|
+
width?: 'half' | 'full' | 1 | 2 | 3 | 4;
|
|
60
|
+
hide_label?: true;
|
|
61
|
+
instructions?: string;
|
|
62
|
+
} | {
|
|
63
|
+
type: 'group';
|
|
64
|
+
id?: string;
|
|
65
|
+
title: string | null;
|
|
66
|
+
collapsible?: true;
|
|
67
|
+
default_expanded?: boolean;
|
|
68
|
+
conditional?: true;
|
|
69
|
+
children: FormLayoutNode[];
|
|
70
|
+
} | {
|
|
71
|
+
type: 'columns';
|
|
72
|
+
id?: string;
|
|
73
|
+
columns: FormLayoutNode[][];
|
|
74
|
+
conditional?: true;
|
|
75
|
+
} | {
|
|
76
|
+
type: 'tabs';
|
|
77
|
+
id?: string;
|
|
78
|
+
tabs: Array<{
|
|
79
|
+
label: string;
|
|
80
|
+
children: FormLayoutNode[];
|
|
81
|
+
}>;
|
|
82
|
+
conditional?: true;
|
|
83
|
+
} | {
|
|
84
|
+
type: 'steps';
|
|
85
|
+
id?: string;
|
|
86
|
+
steps: Array<{
|
|
87
|
+
id?: string;
|
|
88
|
+
label: string;
|
|
89
|
+
conditional?: true;
|
|
90
|
+
/** The step has a rule for "Next": while it fails, the step is in `blockedSteps`. */
|
|
91
|
+
advance_rule?: true;
|
|
92
|
+
/** Message to show while the rule blocks "Next". */
|
|
93
|
+
advance_message?: string;
|
|
94
|
+
children: FormLayoutNode[];
|
|
95
|
+
}>;
|
|
96
|
+
conditional?: true;
|
|
97
|
+
} | {
|
|
98
|
+
type: 'divider';
|
|
99
|
+
id?: string;
|
|
100
|
+
conditional?: true;
|
|
101
|
+
} | {
|
|
102
|
+
type: 'text';
|
|
103
|
+
id?: string;
|
|
104
|
+
content: string;
|
|
105
|
+
conditional?: true;
|
|
106
|
+
}
|
|
107
|
+
/** Notice box; `{{field}}` in title and content stands for the field value. */
|
|
108
|
+
| {
|
|
109
|
+
type: 'alert';
|
|
110
|
+
id?: string;
|
|
111
|
+
tone: 'info' | 'warning' | 'error' | 'success';
|
|
112
|
+
title: string | null;
|
|
113
|
+
content: string;
|
|
114
|
+
conditional?: true;
|
|
115
|
+
} | {
|
|
116
|
+
type: 'block';
|
|
117
|
+
id?: string;
|
|
118
|
+
block: string;
|
|
119
|
+
};
|
|
120
|
+
interface FormLayout {
|
|
121
|
+
version: 1;
|
|
122
|
+
children: FormLayoutNode[];
|
|
123
|
+
}
|
|
124
|
+
interface FormSchema {
|
|
125
|
+
form: FormInfo;
|
|
126
|
+
fields: FormFieldSchema[];
|
|
127
|
+
document_slots?: unknown[];
|
|
128
|
+
/** Present on hosts that support `include=layout`; otherwise the engine builds a flat one. */
|
|
129
|
+
layout?: FormLayout;
|
|
130
|
+
/** Content locale of labels, options and layout texts (hosts with `include=layout`). */
|
|
131
|
+
locale?: string;
|
|
132
|
+
}
|
|
133
|
+
interface FieldState {
|
|
134
|
+
visible: boolean;
|
|
135
|
+
required: boolean;
|
|
136
|
+
readonly: boolean;
|
|
137
|
+
}
|
|
138
|
+
interface FormFieldError {
|
|
139
|
+
field: string;
|
|
140
|
+
code: string;
|
|
141
|
+
message: string;
|
|
142
|
+
}
|
|
143
|
+
/** How Cervio shows one field of the layout for the current values. */
|
|
144
|
+
interface FieldDisplay {
|
|
145
|
+
/** The field name. */
|
|
146
|
+
field: string;
|
|
147
|
+
display_type: string | null;
|
|
148
|
+
/** `fixed`: the choices are in `options`; `remote`: ask the options endpoint with the draft. */
|
|
149
|
+
options_source: 'fixed' | 'remote' | null;
|
|
150
|
+
options?: FormOption[];
|
|
151
|
+
}
|
|
152
|
+
interface DraftResult {
|
|
153
|
+
ok: boolean;
|
|
154
|
+
resolved_data?: Record<string, unknown>;
|
|
155
|
+
server_filled?: Record<string, 'default' | 'computed'>;
|
|
156
|
+
field_state?: Record<string, FieldState>;
|
|
157
|
+
errors?: FormFieldError[];
|
|
158
|
+
/** Ids of the layout blocks and steps Cervio hides for these values (`include=layout_state`). */
|
|
159
|
+
hidden_blocks?: string[];
|
|
160
|
+
/** Ids of the steps whose "Next" rule fails for these values. */
|
|
161
|
+
blocked_steps?: string[];
|
|
162
|
+
/** Visualization of each field node of the layout, by node `id` (`include=layout_state`). */
|
|
163
|
+
field_display?: Record<string, FieldDisplay>;
|
|
164
|
+
}
|
|
165
|
+
interface FormRecord {
|
|
166
|
+
id: string;
|
|
167
|
+
data: Record<string, unknown>;
|
|
168
|
+
updated_at?: string;
|
|
169
|
+
}
|
|
170
|
+
type FormValues = Record<string, unknown>;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* How the engine reaches Cervio. The default works for any `fetch`: inside a
|
|
174
|
+
* plugin pass the SDK's relayed fetch, in Cervio the session one, in Node a token.
|
|
175
|
+
* Every call is one Cervio already serves to integrations and MCP.
|
|
176
|
+
*/
|
|
177
|
+
|
|
178
|
+
interface FormTransport {
|
|
179
|
+
getSchema(entityId: string, form: string, signal?: AbortSignal): Promise<FormSchema>;
|
|
180
|
+
/** Dry run of the form rules (defaults, computed, visibility, required, validation); saves nothing. */
|
|
181
|
+
validateDraft(entityId: string, form: string, data: FormValues, recordId?: string | null, signal?: AbortSignal): Promise<DraftResult>;
|
|
182
|
+
getRecord(entityId: string, recordId: string, signal?: AbortSignal): Promise<FormRecord>;
|
|
183
|
+
createRecord(entityId: string, form: string, data: FormValues): Promise<{
|
|
184
|
+
id: string;
|
|
185
|
+
}>;
|
|
186
|
+
updateRecord(entityId: string, form: string, recordId: string, data: FormValues, expectedUpdatedAt?: string): Promise<void>;
|
|
187
|
+
/** Choices of a list field; `data` for sources that depend on other fields. */
|
|
188
|
+
fieldOptions(entityId: string, form: string, field: string, data?: FormValues): Promise<{
|
|
189
|
+
options: FormOption[];
|
|
190
|
+
}>;
|
|
191
|
+
/** Linked records the user can pick; a record id as `q` returns that record. */
|
|
192
|
+
relationOptions(entityId: string, form: string, field: string, q: string, limit?: number): Promise<{
|
|
193
|
+
records: Array<{
|
|
194
|
+
id: string;
|
|
195
|
+
label: string;
|
|
196
|
+
}>;
|
|
197
|
+
}>;
|
|
198
|
+
}
|
|
199
|
+
declare class FormApiError extends Error {
|
|
200
|
+
readonly status: number;
|
|
201
|
+
readonly code: string;
|
|
202
|
+
/** The field a validation error is about, when Cervio names it. */
|
|
203
|
+
readonly field?: string | undefined;
|
|
204
|
+
constructor(status: number, code: string, message: string,
|
|
205
|
+
/** The field a validation error is about, when Cervio names it. */
|
|
206
|
+
field?: string | undefined);
|
|
207
|
+
}
|
|
208
|
+
interface FetchTransportOptions {
|
|
209
|
+
/** Origin of the Cervio host (e.g. `https://acme.cervio.app`); '' for same-origin. */
|
|
210
|
+
baseUrl?: string;
|
|
211
|
+
fetchImpl?: typeof fetch;
|
|
212
|
+
headers?: Record<string, string>;
|
|
213
|
+
credentials?: RequestCredentials;
|
|
214
|
+
/** Content locale of labels, options and texts (e.g. `en`); default: the user's. */
|
|
215
|
+
locale?: string;
|
|
216
|
+
}
|
|
217
|
+
declare function createFetchTransport(opts?: FetchTransportOptions): FormTransport;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Form controller: the state of one record in one Cervio form, without UI.
|
|
221
|
+
*
|
|
222
|
+
* - The form is Cervio's: fields, layout, permissions, rules and validation come
|
|
223
|
+
* from the host. The engine evaluates no formula of its own: after each change
|
|
224
|
+
* it asks Cervio for a dry run (`validate-draft`) and applies what comes back
|
|
225
|
+
* (visible / required / readonly per field, computed values, errors).
|
|
226
|
+
* - Save writes through the records API with the form's name, so Cervio checks
|
|
227
|
+
* the same mask as in its own UI. An edit sends only the changed fields and
|
|
228
|
+
* the `updated_at` it read: if someone saved in between, the save fails with
|
|
229
|
+
* `conflict` instead of overwriting.
|
|
230
|
+
*
|
|
231
|
+
* Framework-agnostic: `subscribe` + `getState` fit React's `useSyncExternalStore`.
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
interface FormControllerOptions {
|
|
235
|
+
/** Entity id or technical name (e.g. `contratti`). */
|
|
236
|
+
entity: string;
|
|
237
|
+
/** Form name (e.g. `scheda_contratto`). */
|
|
238
|
+
form: string;
|
|
239
|
+
/** Record to edit; omitted to create one. */
|
|
240
|
+
recordId?: string | null;
|
|
241
|
+
/** Values to start a new record with (ignored when editing). */
|
|
242
|
+
initialValues?: FormValues;
|
|
243
|
+
transport: FormTransport;
|
|
244
|
+
/** Wait after the last change before asking Cervio for the rules (ms). Default 300. */
|
|
245
|
+
validateDebounceMs?: number;
|
|
246
|
+
/** Error shown on an empty required field. Default: Cervio's own, `Campo obbligatorio`. */
|
|
247
|
+
requiredMessage?: string;
|
|
248
|
+
}
|
|
249
|
+
interface FormState {
|
|
250
|
+
status: 'loading' | 'ready' | 'error';
|
|
251
|
+
error: Error | null;
|
|
252
|
+
schema: FormSchema | null;
|
|
253
|
+
/** The host's layout, or a flat one in field order on older hosts. */
|
|
254
|
+
layout: FormLayout | null;
|
|
255
|
+
/** Fields by name. */
|
|
256
|
+
fields: Record<string, FormFieldSchema>;
|
|
257
|
+
mode: 'create' | 'edit';
|
|
258
|
+
recordId: string | null;
|
|
259
|
+
updatedAt: string | null;
|
|
260
|
+
values: FormValues;
|
|
261
|
+
/** Fields the user changed since the load or the last save. */
|
|
262
|
+
dirty: string[];
|
|
263
|
+
/** Fields the user left at least once (errors show there first). */
|
|
264
|
+
touched: string[];
|
|
265
|
+
/** Visible / required / readonly per field, as Cervio last evaluated them. */
|
|
266
|
+
fieldState: Record<string, FieldState>;
|
|
267
|
+
/** Errors to show: on touched fields, or all after a save attempt. */
|
|
268
|
+
errors: Record<string, string>;
|
|
269
|
+
/** Every error of the last evaluation, shown or not. */
|
|
270
|
+
draftErrors: Record<string, string>;
|
|
271
|
+
/** A rules evaluation is pending or running. */
|
|
272
|
+
validating: boolean;
|
|
273
|
+
saving: boolean;
|
|
274
|
+
/** Last failed save that is not a field error. */
|
|
275
|
+
saveError: Error | null;
|
|
276
|
+
/** The record changed on the server since it was read. */
|
|
277
|
+
conflict: boolean;
|
|
278
|
+
/** A save was attempted: every error is shown. */
|
|
279
|
+
submitted: boolean;
|
|
280
|
+
/** Labels of linked records, by field and id. */
|
|
281
|
+
relationLabels: Record<string, Record<string, string>>;
|
|
282
|
+
/** Ids of the layout blocks and steps Cervio hides for the current values. */
|
|
283
|
+
hiddenBlocks: string[];
|
|
284
|
+
/** Ids of the steps whose "Next" rule fails for the current values. */
|
|
285
|
+
blockedSteps: string[];
|
|
286
|
+
/**
|
|
287
|
+
* How Cervio shows each field node of the layout for the current values (e.g. fewer
|
|
288
|
+
* choices), by node id. Read it with `fieldDisplayFor`.
|
|
289
|
+
*/
|
|
290
|
+
fieldDisplay: Record<string, FieldDisplay>;
|
|
291
|
+
}
|
|
292
|
+
interface SaveResult {
|
|
293
|
+
id: string;
|
|
294
|
+
created: boolean;
|
|
295
|
+
}
|
|
296
|
+
interface FormController {
|
|
297
|
+
readonly ready: Promise<void>;
|
|
298
|
+
getState(): FormState;
|
|
299
|
+
subscribe(listener: (state: FormState) => void): () => void;
|
|
300
|
+
setValue(field: string, value: unknown): void;
|
|
301
|
+
setValues(values: FormValues): void;
|
|
302
|
+
/** The user left the field: show its error from now on. */
|
|
303
|
+
touch(field: string): void;
|
|
304
|
+
/** Ask Cervio for the rules now; true when the draft has no errors. */
|
|
305
|
+
validate(): Promise<boolean>;
|
|
306
|
+
/** Validate and save; null when there are errors or the save failed (see state). */
|
|
307
|
+
save(): Promise<SaveResult | null>;
|
|
308
|
+
/** Back to the values last loaded or saved. */
|
|
309
|
+
reset(): void;
|
|
310
|
+
/** Read the record again (e.g. after a conflict). */
|
|
311
|
+
reload(): Promise<void>;
|
|
312
|
+
/**
|
|
313
|
+
* Choices of a list field: the ones Cervio shows for the current values, else the
|
|
314
|
+
* inline ones, else from the host. `nodeId`: the layout node, for a field placed twice.
|
|
315
|
+
*/
|
|
316
|
+
fieldOptions(field: string, nodeId?: string): Promise<FormOption[]>;
|
|
317
|
+
/** Linked records matching `search` the user can pick. */
|
|
318
|
+
relationOptions(field: string, search: string, limit?: number): Promise<Array<{
|
|
319
|
+
id: string;
|
|
320
|
+
label: string;
|
|
321
|
+
}>>;
|
|
322
|
+
destroy(): void;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* How Cervio shows `field` now: the entry of layout node `nodeId` when given, else the
|
|
326
|
+
* first node of that field. Undefined on hosts without the layout state.
|
|
327
|
+
*/
|
|
328
|
+
declare function fieldDisplayFor(state: Pick<FormState, 'fieldDisplay'>, field: string, nodeId?: string): FieldDisplay | undefined;
|
|
329
|
+
/** A layout in field order, for hosts that do not send one. */
|
|
330
|
+
declare function flatLayout(fields: FormFieldSchema[]): FormLayout;
|
|
331
|
+
declare function createFormController(opts: FormControllerOptions): FormController;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* `@cervio/plugin-sdk/forms`: Cervio forms inside a plugin, without UI.
|
|
335
|
+
*
|
|
336
|
+
* Re-exports the engine of `@cervio/form-core` and adds
|
|
337
|
+
* `createPluginFormController`, wired for the plugin sandbox: the API goes
|
|
338
|
+
* through the host relay. Declare in the manifest `cervio_apis`:
|
|
339
|
+
* `GET /api/v1/entities` (form contract, records, options),
|
|
340
|
+
* `POST /api/v1/entities` (draft check, create) and, to edit,
|
|
341
|
+
* `PATCH /api/v1/entities`.
|
|
342
|
+
*
|
|
343
|
+
* The form is Cervio's: fields, layout, permissions, rules and validation come
|
|
344
|
+
* from the host, evaluated by its own engine. The plugin only decides how to
|
|
345
|
+
* present it. React users: `useCervioForm` from `@cervio/plugin-sdk/forms/react`.
|
|
346
|
+
*/
|
|
347
|
+
|
|
348
|
+
type PluginFormControllerOptions = Omit<FormControllerOptions, 'transport'> & {
|
|
349
|
+
/** Default: the host origin from the plugin context. */
|
|
350
|
+
baseUrl?: string;
|
|
351
|
+
/** Content locale of labels and texts; default: the user's, from the plugin context. */
|
|
352
|
+
locale?: string;
|
|
353
|
+
fetchImpl?: typeof fetch;
|
|
354
|
+
/** Replace the HTTP transport entirely (tests, custom backends). */
|
|
355
|
+
transport?: FormTransport;
|
|
356
|
+
};
|
|
357
|
+
declare function createPluginFormController(opts: PluginFormControllerOptions): FormController;
|
|
358
|
+
|
|
359
|
+
export { FormApiError, createFetchTransport, createFormController, createPluginFormController, fieldDisplayFor, flatLayout };
|
|
360
|
+
export type { DraftResult, FetchTransportOptions, FieldDisplay, FieldState, FormController, FormControllerOptions, FormFieldError, FormFieldInput, FormFieldSchema, FormInfo, FormInputMode, FormLayout, FormLayoutNode, FormOption, FormRecord, FormSchema, FormState, FormTransport, FormValues, PluginFormControllerOptions, SaveResult };
|