@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
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { FormState as FormState$1, FormController as FormController$1, PluginFormControllerOptions } from './index.js';
|
|
2
|
+
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The form contract as Cervio exposes it (`GET …/forms/{form}/write-schema?include=layout`,
|
|
6
|
+
* `POST …/validate-draft`). The engine reads it; it never invents rules of its own.
|
|
7
|
+
*/
|
|
8
|
+
interface FormInfo {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
label: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* How a value is chosen. `none`: a free value, its input follows `field_type`
|
|
15
|
+
* (text, number, date, …); the others pick among choices.
|
|
16
|
+
*/
|
|
17
|
+
type FormInputMode = 'none' | 'boolean' | 'fixed_list' | 'remote_options' | 'relation' | (string & {});
|
|
18
|
+
interface FormOption {
|
|
19
|
+
value: string;
|
|
20
|
+
label: string;
|
|
21
|
+
}
|
|
22
|
+
interface FormFieldInput {
|
|
23
|
+
mode: FormInputMode;
|
|
24
|
+
/** Choices of a small fixed list, inline. Larger lists: `controller.fieldOptions()`. */
|
|
25
|
+
options?: FormOption[];
|
|
26
|
+
relation_entity_id?: string;
|
|
27
|
+
/** A relation holding several linked records (`uuid[]`). */
|
|
28
|
+
multi_select?: boolean;
|
|
29
|
+
storage?: string;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
}
|
|
32
|
+
interface FormFieldSchema {
|
|
33
|
+
name: string;
|
|
34
|
+
label: string;
|
|
35
|
+
field_type: string;
|
|
36
|
+
/** What the value looks like: `string`, `number`, `boolean`, `uuid`, `uuid[]`, … */
|
|
37
|
+
value_shape?: string;
|
|
38
|
+
required: boolean;
|
|
39
|
+
readonly: boolean;
|
|
40
|
+
order: number;
|
|
41
|
+
input: FormFieldInput;
|
|
42
|
+
/** Cervio fills it on save (`default` when empty, `computed` always). */
|
|
43
|
+
server_filled?: 'default' | 'computed';
|
|
44
|
+
client_may_omit?: boolean;
|
|
45
|
+
/** Conditional rules exist: visibility, required, readonly may change with the values. */
|
|
46
|
+
rules?: {
|
|
47
|
+
has_conditional_rules?: boolean;
|
|
48
|
+
[key: string]: unknown;
|
|
49
|
+
};
|
|
50
|
+
/** Help text of the field on this form. */
|
|
51
|
+
instructions?: string | null;
|
|
52
|
+
[key: string]: unknown;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Blocks carry the `id` Cervio uses in `hidden_blocks`; steps carry their own. A field
|
|
56
|
+
* node's `id` keys its entry in `field_display` (a field placed twice has two).
|
|
57
|
+
*/
|
|
58
|
+
type FormLayoutNode = {
|
|
59
|
+
type: 'field';
|
|
60
|
+
id?: string;
|
|
61
|
+
field: string;
|
|
62
|
+
width?: 'half' | 'full' | 1 | 2 | 3 | 4;
|
|
63
|
+
hide_label?: true;
|
|
64
|
+
instructions?: string;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'group';
|
|
67
|
+
id?: string;
|
|
68
|
+
title: string | null;
|
|
69
|
+
collapsible?: true;
|
|
70
|
+
default_expanded?: boolean;
|
|
71
|
+
conditional?: true;
|
|
72
|
+
children: FormLayoutNode[];
|
|
73
|
+
} | {
|
|
74
|
+
type: 'columns';
|
|
75
|
+
id?: string;
|
|
76
|
+
columns: FormLayoutNode[][];
|
|
77
|
+
conditional?: true;
|
|
78
|
+
} | {
|
|
79
|
+
type: 'tabs';
|
|
80
|
+
id?: string;
|
|
81
|
+
tabs: Array<{
|
|
82
|
+
label: string;
|
|
83
|
+
children: FormLayoutNode[];
|
|
84
|
+
}>;
|
|
85
|
+
conditional?: true;
|
|
86
|
+
} | {
|
|
87
|
+
type: 'steps';
|
|
88
|
+
id?: string;
|
|
89
|
+
steps: Array<{
|
|
90
|
+
id?: string;
|
|
91
|
+
label: string;
|
|
92
|
+
conditional?: true;
|
|
93
|
+
/** The step has a rule for "Next": while it fails, the step is in `blockedSteps`. */
|
|
94
|
+
advance_rule?: true;
|
|
95
|
+
/** Message to show while the rule blocks "Next". */
|
|
96
|
+
advance_message?: string;
|
|
97
|
+
children: FormLayoutNode[];
|
|
98
|
+
}>;
|
|
99
|
+
conditional?: true;
|
|
100
|
+
} | {
|
|
101
|
+
type: 'divider';
|
|
102
|
+
id?: string;
|
|
103
|
+
conditional?: true;
|
|
104
|
+
} | {
|
|
105
|
+
type: 'text';
|
|
106
|
+
id?: string;
|
|
107
|
+
content: string;
|
|
108
|
+
conditional?: true;
|
|
109
|
+
}
|
|
110
|
+
/** Notice box; `{{field}}` in title and content stands for the field value. */
|
|
111
|
+
| {
|
|
112
|
+
type: 'alert';
|
|
113
|
+
id?: string;
|
|
114
|
+
tone: 'info' | 'warning' | 'error' | 'success';
|
|
115
|
+
title: string | null;
|
|
116
|
+
content: string;
|
|
117
|
+
conditional?: true;
|
|
118
|
+
} | {
|
|
119
|
+
type: 'block';
|
|
120
|
+
id?: string;
|
|
121
|
+
block: string;
|
|
122
|
+
};
|
|
123
|
+
interface FormLayout$1 {
|
|
124
|
+
version: 1;
|
|
125
|
+
children: FormLayoutNode[];
|
|
126
|
+
}
|
|
127
|
+
interface FormSchema {
|
|
128
|
+
form: FormInfo;
|
|
129
|
+
fields: FormFieldSchema[];
|
|
130
|
+
document_slots?: unknown[];
|
|
131
|
+
/** Present on hosts that support `include=layout`; otherwise the engine builds a flat one. */
|
|
132
|
+
layout?: FormLayout$1;
|
|
133
|
+
/** Content locale of labels, options and layout texts (hosts with `include=layout`). */
|
|
134
|
+
locale?: string;
|
|
135
|
+
}
|
|
136
|
+
interface FieldState {
|
|
137
|
+
visible: boolean;
|
|
138
|
+
required: boolean;
|
|
139
|
+
readonly: boolean;
|
|
140
|
+
}
|
|
141
|
+
/** How Cervio shows one field of the layout for the current values. */
|
|
142
|
+
interface FieldDisplay {
|
|
143
|
+
/** The field name. */
|
|
144
|
+
field: string;
|
|
145
|
+
display_type: string | null;
|
|
146
|
+
/** `fixed`: the choices are in `options`; `remote`: ask the options endpoint with the draft. */
|
|
147
|
+
options_source: 'fixed' | 'remote' | null;
|
|
148
|
+
options?: FormOption[];
|
|
149
|
+
}
|
|
150
|
+
type FormValues = Record<string, unknown>;
|
|
151
|
+
interface FormState {
|
|
152
|
+
status: 'loading' | 'ready' | 'error';
|
|
153
|
+
error: Error | null;
|
|
154
|
+
schema: FormSchema | null;
|
|
155
|
+
/** The host's layout, or a flat one in field order on older hosts. */
|
|
156
|
+
layout: FormLayout$1 | null;
|
|
157
|
+
/** Fields by name. */
|
|
158
|
+
fields: Record<string, FormFieldSchema>;
|
|
159
|
+
mode: 'create' | 'edit';
|
|
160
|
+
recordId: string | null;
|
|
161
|
+
updatedAt: string | null;
|
|
162
|
+
values: FormValues;
|
|
163
|
+
/** Fields the user changed since the load or the last save. */
|
|
164
|
+
dirty: string[];
|
|
165
|
+
/** Fields the user left at least once (errors show there first). */
|
|
166
|
+
touched: string[];
|
|
167
|
+
/** Visible / required / readonly per field, as Cervio last evaluated them. */
|
|
168
|
+
fieldState: Record<string, FieldState>;
|
|
169
|
+
/** Errors to show: on touched fields, or all after a save attempt. */
|
|
170
|
+
errors: Record<string, string>;
|
|
171
|
+
/** Every error of the last evaluation, shown or not. */
|
|
172
|
+
draftErrors: Record<string, string>;
|
|
173
|
+
/** A rules evaluation is pending or running. */
|
|
174
|
+
validating: boolean;
|
|
175
|
+
saving: boolean;
|
|
176
|
+
/** Last failed save that is not a field error. */
|
|
177
|
+
saveError: Error | null;
|
|
178
|
+
/** The record changed on the server since it was read. */
|
|
179
|
+
conflict: boolean;
|
|
180
|
+
/** A save was attempted: every error is shown. */
|
|
181
|
+
submitted: boolean;
|
|
182
|
+
/** Labels of linked records, by field and id. */
|
|
183
|
+
relationLabels: Record<string, Record<string, string>>;
|
|
184
|
+
/** Ids of the layout blocks and steps Cervio hides for the current values. */
|
|
185
|
+
hiddenBlocks: string[];
|
|
186
|
+
/** Ids of the steps whose "Next" rule fails for the current values. */
|
|
187
|
+
blockedSteps: string[];
|
|
188
|
+
/**
|
|
189
|
+
* How Cervio shows each field node of the layout for the current values (e.g. fewer
|
|
190
|
+
* choices), by node id. Read it with `fieldDisplayFor`.
|
|
191
|
+
*/
|
|
192
|
+
fieldDisplay: Record<string, FieldDisplay>;
|
|
193
|
+
}
|
|
194
|
+
interface SaveResult {
|
|
195
|
+
id: string;
|
|
196
|
+
created: boolean;
|
|
197
|
+
}
|
|
198
|
+
interface FormController {
|
|
199
|
+
readonly ready: Promise<void>;
|
|
200
|
+
getState(): FormState;
|
|
201
|
+
subscribe(listener: (state: FormState) => void): () => void;
|
|
202
|
+
setValue(field: string, value: unknown): void;
|
|
203
|
+
setValues(values: FormValues): void;
|
|
204
|
+
/** The user left the field: show its error from now on. */
|
|
205
|
+
touch(field: string): void;
|
|
206
|
+
/** Ask Cervio for the rules now; true when the draft has no errors. */
|
|
207
|
+
validate(): Promise<boolean>;
|
|
208
|
+
/** Validate and save; null when there are errors or the save failed (see state). */
|
|
209
|
+
save(): Promise<SaveResult | null>;
|
|
210
|
+
/** Back to the values last loaded or saved. */
|
|
211
|
+
reset(): void;
|
|
212
|
+
/** Read the record again (e.g. after a conflict). */
|
|
213
|
+
reload(): Promise<void>;
|
|
214
|
+
/**
|
|
215
|
+
* Choices of a list field: the ones Cervio shows for the current values, else the
|
|
216
|
+
* inline ones, else from the host. `nodeId`: the layout node, for a field placed twice.
|
|
217
|
+
*/
|
|
218
|
+
fieldOptions(field: string, nodeId?: string): Promise<FormOption[]>;
|
|
219
|
+
/** Linked records matching `search` the user can pick. */
|
|
220
|
+
relationOptions(field: string, search: string, limit?: number): Promise<Array<{
|
|
221
|
+
id: string;
|
|
222
|
+
label: string;
|
|
223
|
+
}>>;
|
|
224
|
+
destroy(): void;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** Default UI strings of the form pieces; pass `labels` to override any of them. */
|
|
228
|
+
interface FormLabels {
|
|
229
|
+
save: string;
|
|
230
|
+
saving: string;
|
|
231
|
+
cancel: string;
|
|
232
|
+
saved: string;
|
|
233
|
+
unsaved: (n: number) => string;
|
|
234
|
+
checking: string;
|
|
235
|
+
search: string;
|
|
236
|
+
noResults: string;
|
|
237
|
+
loading: string;
|
|
238
|
+
choose: string;
|
|
239
|
+
remove: string;
|
|
240
|
+
yes: string;
|
|
241
|
+
no: string;
|
|
242
|
+
conflict: string;
|
|
243
|
+
reload: string;
|
|
244
|
+
fixErrors: string;
|
|
245
|
+
error: string;
|
|
246
|
+
next: string;
|
|
247
|
+
back: string;
|
|
248
|
+
/** "Next" blocked by the step rule, when Cervio has no message for it. */
|
|
249
|
+
stepBlocked: string;
|
|
250
|
+
}
|
|
251
|
+
declare function formLabels(locale: string | undefined, overrides?: Partial<FormLabels>): FormLabels;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Field: one field of a Cervio form with the Cervio look. Label, input for the
|
|
255
|
+
* field's type, required mark and error, all from the controller: whether it
|
|
256
|
+
* shows, is required or read-only is what Cervio last evaluated.
|
|
257
|
+
*
|
|
258
|
+
* `renderInput` replaces only the input (keep label and error); skip this piece
|
|
259
|
+
* entirely to draw your own and call `controller.setValue` / `touch`.
|
|
260
|
+
*/
|
|
261
|
+
|
|
262
|
+
interface FieldInputContext {
|
|
263
|
+
field: FormFieldSchema;
|
|
264
|
+
value: unknown;
|
|
265
|
+
setValue: (value: unknown) => void;
|
|
266
|
+
touch: () => void;
|
|
267
|
+
readonly: boolean;
|
|
268
|
+
required: boolean;
|
|
269
|
+
invalid: boolean;
|
|
270
|
+
id: string;
|
|
271
|
+
state: FormState;
|
|
272
|
+
/** The layout node drawn, when the field comes from `FormLayout`. */
|
|
273
|
+
nodeId?: string;
|
|
274
|
+
}
|
|
275
|
+
interface FieldProps {
|
|
276
|
+
controller: FormController;
|
|
277
|
+
name: string;
|
|
278
|
+
/** The layout node this field is drawn for (set by `FormLayout`; a field placed twice has two). */
|
|
279
|
+
nodeId?: string;
|
|
280
|
+
/** Label instead of the form's one. */
|
|
281
|
+
label?: string;
|
|
282
|
+
hideLabel?: boolean;
|
|
283
|
+
/** Text under the input; default: the field's instructions on the Cervio form. */
|
|
284
|
+
hint?: ReactNode;
|
|
285
|
+
locale?: string;
|
|
286
|
+
labels?: Partial<FormLabels>;
|
|
287
|
+
unstyled?: boolean;
|
|
288
|
+
className?: string;
|
|
289
|
+
style?: CSSProperties;
|
|
290
|
+
/** Draw the input yourself; label, required mark and error stay. */
|
|
291
|
+
renderInput?: (ctx: FieldInputContext) => ReactNode;
|
|
292
|
+
/** Render even when Cervio says the field is hidden (default false). */
|
|
293
|
+
showHidden?: boolean;
|
|
294
|
+
}
|
|
295
|
+
declare function Field(props: FieldProps): ReactNode;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* FormLayout: the fields placed as the form was designed in Cervio (groups,
|
|
299
|
+
* columns, tabs, steps, dividers, text). Fields, blocks and steps Cervio hides
|
|
300
|
+
* for the current values are skipped; a tab or step holding an error is marked;
|
|
301
|
+
* field instructions show under the input.
|
|
302
|
+
*
|
|
303
|
+
* `renderField` draws one field your way (return undefined for the default);
|
|
304
|
+
* `only` limits the layout to some fields (e.g. one step of your own wizard).
|
|
305
|
+
*/
|
|
306
|
+
|
|
307
|
+
interface FormLayoutProps {
|
|
308
|
+
controller: FormController;
|
|
309
|
+
locale?: string;
|
|
310
|
+
labels?: Partial<FormLabels>;
|
|
311
|
+
unstyled?: boolean;
|
|
312
|
+
className?: string;
|
|
313
|
+
style?: CSSProperties;
|
|
314
|
+
/** Draw a field yourself; return undefined to keep the default `Field`. */
|
|
315
|
+
renderField?: (name: string, node: Extract<FormLayoutNode, {
|
|
316
|
+
type: 'field';
|
|
317
|
+
}>) => ReactNode | undefined;
|
|
318
|
+
/** Draw only these fields (containers left empty are skipped). */
|
|
319
|
+
only?: string[];
|
|
320
|
+
/** Steps blocks: draw all steps at once instead of a wizard. */
|
|
321
|
+
flattenSteps?: boolean;
|
|
322
|
+
}
|
|
323
|
+
/** Field names under a node. */
|
|
324
|
+
declare function layoutFields(nodes: FormLayoutNode[]): string[];
|
|
325
|
+
declare function FormLayout(props: FormLayoutProps): ReactNode;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* FormActions: Save and Discard with the form's status (unsaved changes,
|
|
329
|
+
* checking, saving, saved), the list of errors after a failed save, and the
|
|
330
|
+
* conflict notice with Reload when someone saved the record in the meantime.
|
|
331
|
+
*/
|
|
332
|
+
|
|
333
|
+
interface FormActionsProps {
|
|
334
|
+
controller: FormController;
|
|
335
|
+
locale?: string;
|
|
336
|
+
labels?: Partial<FormLabels>;
|
|
337
|
+
unstyled?: boolean;
|
|
338
|
+
className?: string;
|
|
339
|
+
style?: CSSProperties;
|
|
340
|
+
/** Called after a successful save. */
|
|
341
|
+
onSaved?: (result: SaveResult) => void;
|
|
342
|
+
/** Hide the Discard button. */
|
|
343
|
+
hideCancel?: boolean;
|
|
344
|
+
}
|
|
345
|
+
declare function FormActions(props: FormActionsProps): ReactNode;
|
|
346
|
+
|
|
347
|
+
/** Current state of a form controller; re-renders on every change. */
|
|
348
|
+
declare function useFormState(controller: FormController): FormState;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Default look of the form pieces, on the Cervio theme tokens the host pushes
|
|
352
|
+
* into the plugin document (`--background`, `--foreground`, `--border`,
|
|
353
|
+
* `--muted`, `--primary`, `--destructive`, …), with fallbacks outside Cervio.
|
|
354
|
+
* Same measures as the Cervio forms: 36px inputs, 13px text, 8px radius.
|
|
355
|
+
*
|
|
356
|
+
* The tokens sit on `:root`, so a `Field` used on its own looks the same.
|
|
357
|
+
* Injected once per document (`<style data-cervio-form>`). Every class starts
|
|
358
|
+
* with `cf-`; override them, or pass `unstyled` and style the pieces yourself.
|
|
359
|
+
*/
|
|
360
|
+
declare const CERVIO_FORM_CSS = "\n:root{--cf-accent:var(--primary,#2f5fd0);--cf-border:var(--border,#e2e5ea);--cf-input:var(--input,var(--cf-border));--cf-muted:var(--muted,#f3f4f6);--cf-muted-fg:var(--muted-foreground,#6b7280);--cf-bg:var(--background,#fff);--cf-fg:var(--foreground,#111827);--cf-danger:var(--destructive,#dc2626);--cf-warning:var(--warning,#d97706);--cf-success:var(--success,#16a34a);--cf-radius:8px}\n.cf-root{color:var(--cf-fg);font-size:13px;display:flex;flex-direction:column;gap:14px;min-width:0}\n.cf-field{display:flex;flex-direction:column;gap:6px;min-width:0}\n.cf-label{font-size:12.5px;font-weight:500;color:var(--cf-fg);display:flex;gap:4px;align-items:baseline}\n.cf-req{color:var(--cf-danger)}\n.cf-control{width:100%;min-height:36px;border:1px solid var(--cf-input);border-radius:var(--cf-radius);background:var(--cf-bg);color:inherit;padding:6px 10px;font:inherit;box-sizing:border-box}\ntextarea.cf-control{min-height:72px;resize:vertical}\n.cf-control:focus-visible,.cf-btn:focus-visible,.cf-tab:focus-visible,.cf-option:focus-visible{outline:2px solid var(--cf-accent);outline-offset:1px}\n.cf-control:disabled,.cf-control[aria-readonly=true]{background:var(--cf-muted);color:var(--cf-muted-fg);cursor:default}\n.cf-field[data-invalid=true] .cf-control{border-color:var(--cf-danger)}\n.cf-error{color:var(--cf-danger);font-size:12px}\n.cf-hint{color:var(--cf-muted-fg);font-size:12px}\n.cf-check{display:inline-flex;gap:8px;align-items:center;min-height:36px;cursor:pointer}\n.cf-check input{accent-color:var(--cf-accent);width:16px;height:16px}\n.cf-readonly{min-height:36px;display:flex;align-items:center;color:var(--cf-fg);padding:0 2px}\n.cf-combo{position:relative}\n.cf-list{position:absolute;z-index:40;top:calc(100% + 4px);left:0;right:0;max-height:240px;overflow:auto;background:var(--popover,var(--cf-bg));color:var(--popover-foreground,var(--cf-fg));border:1px solid var(--cf-border);border-radius:var(--cf-radius);box-shadow:0 8px 24px rgb(0 0 0 / .12);padding:4px;display:grid}\n.cf-option{all:unset;padding:7px 8px;border-radius:6px;cursor:pointer;display:flex;justify-content:space-between;gap:8px}\n.cf-option:hover,.cf-option[data-active=true]{background:var(--cf-muted)}\n.cf-option[aria-selected=true]{font-weight:600}\n.cf-empty{padding:8px;color:var(--cf-muted-fg)}\n.cf-chips{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:6px}\n.cf-chip{display:inline-flex;align-items:center;gap:6px;border-radius:999px;background:var(--cf-muted);padding:2px 4px 2px 10px;font-size:12px}\n.cf-chip button{all:unset;cursor:pointer;width:18px;height:18px;border-radius:50%;text-align:center;line-height:18px;color:var(--cf-muted-fg)}\n.cf-chip button:hover{background:var(--cf-border);color:var(--cf-fg)}\n.cf-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px 16px}\n.cf-grid>.cf-full{grid-column:1 / -1}\n.cf-columns{display:grid;gap:14px 16px}\n.cf-col{display:flex;flex-direction:column;gap:14px;min-width:0}\n@media (max-width:640px){.cf-grid,.cf-columns{grid-template-columns:1fr !important}}\n.cf-group{border:1px solid var(--cf-border);border-radius:10px;padding:14px;display:flex;flex-direction:column;gap:14px}\n.cf-group-title{all:unset;font-weight:600;font-size:13.5px;display:flex;gap:8px;align-items:center}\nbutton.cf-group-title{cursor:pointer}\n.cf-divider{border:0;border-top:1px solid var(--cf-border);margin:2px 0}\n.cf-text{color:var(--cf-muted-fg);white-space:pre-wrap;line-height:1.5}\n.cf-alert{--cf-tone:var(--cf-accent);border:1px solid color-mix(in srgb,var(--cf-tone) 35%,transparent);background:color-mix(in srgb,var(--cf-tone) 8%,var(--cf-bg));border-radius:var(--cf-radius);padding:10px 12px;display:flex;flex-direction:column;gap:2px;white-space:pre-wrap;line-height:1.5}\n.cf-alert[data-tone=warning]{--cf-tone:var(--cf-warning)}\n.cf-alert[data-tone=error]{--cf-tone:var(--cf-danger)}\n.cf-alert[data-tone=success]{--cf-tone:var(--cf-success)}\n.cf-alert-title{font-weight:600}\n.cf-tabs{display:flex;gap:4px;border-bottom:1px solid var(--cf-border);margin-bottom:4px;flex-wrap:wrap}\n.cf-tab{all:unset;padding:7px 12px;cursor:pointer;color:var(--cf-muted-fg);border-bottom:2px solid transparent;margin-bottom:-1px}\n.cf-tab[aria-selected=true]{color:var(--cf-fg);border-bottom-color:var(--cf-accent);font-weight:600}\n.cf-tab[data-invalid=true]::after{content:\" \u2022\";color:var(--cf-danger)}\n.cf-actions{display:flex;flex-wrap:wrap;gap:8px;align-items:center;justify-content:flex-end}\n.cf-status{margin-right:auto;color:var(--cf-muted-fg);font-size:12px}\n.cf-btn{height:34px;border:1px solid var(--cf-border);border-radius:var(--cf-radius);background:var(--cf-bg);color:inherit;padding:0 14px;font:inherit;cursor:pointer;display:inline-flex;align-items:center;gap:6px}\n.cf-btn:hover:not(:disabled){background:var(--cf-muted)}\n.cf-btn:disabled{opacity:.55;cursor:default}\n.cf-btn[data-variant=primary]{background:var(--cf-accent);border-color:var(--cf-accent);color:var(--primary-foreground,#fff)}\n.cf-btn[data-variant=primary]:hover:not(:disabled){filter:brightness(1.08)}\n.cf-alert{border:1px solid color-mix(in srgb,var(--cf-danger) 35%,transparent);background:color-mix(in srgb,var(--cf-danger) 8%,transparent);color:var(--cf-fg);border-radius:var(--cf-radius);padding:10px 12px;display:flex;gap:10px;align-items:center;justify-content:space-between;flex-wrap:wrap}\n.cf-summary{margin:0;padding-left:18px;color:var(--cf-danger);font-size:12.5px}\n.cf-block{border:1px dashed var(--cf-border);border-radius:var(--cf-radius);padding:10px 12px;color:var(--cf-muted-fg);font-size:12px}\n";
|
|
361
|
+
declare function ensureCervioFormStyles(doc?: Document | undefined): void;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* `useCervioForm`: a Cervio form as React state. One controller per entity, form
|
|
365
|
+
* and record, torn down on unmount; re-renders on every state change.
|
|
366
|
+
*
|
|
367
|
+
* ```tsx
|
|
368
|
+
* const f = useCervioForm({ entity: 'contratti', form: 'scheda_contratto' })
|
|
369
|
+
* return <><FormLayout controller={f.controller} /><FormActions controller={f.controller} /></>
|
|
370
|
+
* ```
|
|
371
|
+
*
|
|
372
|
+
* Or draw your own inputs: `f.values`, `f.fieldState`, `f.errors`, `f.setValue`.
|
|
373
|
+
*/
|
|
374
|
+
|
|
375
|
+
type UseCervioForm = FormState$1 & Omit<FormController$1, 'getState' | 'subscribe' | 'destroy'> & {
|
|
376
|
+
controller: FormController$1;
|
|
377
|
+
};
|
|
378
|
+
declare function useCervioForm(opts: PluginFormControllerOptions): UseCervioForm;
|
|
379
|
+
|
|
380
|
+
export { CERVIO_FORM_CSS, Field, FormActions, FormLayout, ensureCervioFormStyles, formLabels, layoutFields, useCervioForm, useFormState };
|
|
381
|
+
export type { FieldInputContext, FieldProps, FieldState, FormActionsProps, FormController, FormFieldSchema, FormLabels, FormLayout$1 as FormLayoutDoc, FormLayoutNode, FormLayoutProps, FormSchema, FormState, FormValues, SaveResult, UseCervioForm };
|