@dou-ui/form-builder 0.0.0-stage → 0.1.0-alpha.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 +10 -2
- package/dist/builder/canvas.js +695 -0
- package/dist/builder/canvas.js.map +1 -0
- package/dist/builder/completion.js +49 -0
- package/dist/builder/completion.js.map +1 -0
- package/dist/builder/condition-editor.js +6 -0
- package/dist/builder/condition-editor.js.map +1 -0
- package/dist/builder/condition-editor.vue_vue_type_script_setup_true_lang.js +410 -0
- package/dist/builder/condition-editor.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/builder/condition.js +159 -0
- package/dist/builder/condition.js.map +1 -0
- package/dist/builder/context.js +477 -0
- package/dist/builder/context.js.map +1 -0
- package/dist/builder/core/commands.js +373 -0
- package/dist/builder/core/commands.js.map +1 -0
- package/dist/builder/core/history.js +76 -0
- package/dist/builder/core/history.js.map +1 -0
- package/dist/builder/core/transaction.js +298 -0
- package/dist/builder/core/transaction.js.map +1 -0
- package/dist/builder/drag.js +466 -0
- package/dist/builder/drag.js.map +1 -0
- package/dist/builder/expression-box.js +19 -0
- package/dist/builder/expression-box.js.map +1 -0
- package/dist/builder/expression-input.js +6 -0
- package/dist/builder/expression-input.js.map +1 -0
- package/dist/builder/expression-input.vue_vue_type_script_setup_true_lang.js +117 -0
- package/dist/builder/expression-input.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/builder/extension.js +47 -0
- package/dist/builder/extension.js.map +1 -0
- package/dist/builder/form-builder.js +6 -0
- package/dist/builder/form-builder.js.map +1 -0
- package/dist/builder/form-builder.vue_vue_type_script_setup_true_lang.js +450 -0
- package/dist/builder/form-builder.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/builder/index.js +22 -0
- package/dist/builder/index.js.map +1 -0
- package/dist/builder/inspector.js +6 -0
- package/dist/builder/inspector.js.map +1 -0
- package/dist/builder/inspector.vue_vue_type_script_setup_true_lang.js +442 -0
- package/dist/builder/inspector.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/builder/json-dialog.js +6 -0
- package/dist/builder/json-dialog.js.map +1 -0
- package/dist/builder/json-dialog.vue_vue_type_script_setup_true_lang.js +281 -0
- package/dist/builder/json-dialog.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/builder/locale.js +1271 -0
- package/dist/builder/locale.js.map +1 -0
- package/dist/builder/logic-fields.js +18 -0
- package/dist/builder/logic-fields.js.map +1 -0
- package/dist/builder/logic.js +332 -0
- package/dist/builder/logic.js.map +1 -0
- package/dist/builder/menu.js +92 -0
- package/dist/builder/menu.js.map +1 -0
- package/dist/builder/outline-row.js +6 -0
- package/dist/builder/outline-row.js.map +1 -0
- package/dist/builder/outline-row.vue_vue_type_script_setup_true_lang.js +88 -0
- package/dist/builder/outline-row.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/builder/outline.js +6 -0
- package/dist/builder/outline.js.map +1 -0
- package/dist/builder/outline.vue_vue_type_script_setup_true_lang.js +111 -0
- package/dist/builder/outline.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/builder/palette.js +6 -0
- package/dist/builder/palette.js.map +1 -0
- package/dist/builder/palette.vue_vue_type_script_setup_true_lang.js +96 -0
- package/dist/builder/palette.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/builder/preview.js +6 -0
- package/dist/builder/preview.js.map +1 -0
- package/dist/builder/preview.vue_vue_type_script_setup_true_lang.js +111 -0
- package/dist/builder/preview.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/builder/settings-binding.js +57 -0
- package/dist/builder/settings-binding.js.map +1 -0
- package/dist/builder/settings.js +487 -0
- package/dist/builder/settings.js.map +1 -0
- package/dist/builder/span-field.js +104 -0
- package/dist/builder/span-field.js.map +1 -0
- package/dist/code/expression-input.js +6 -0
- package/dist/code/expression-input.js.map +1 -0
- package/dist/code/expression-input.vue_vue_type_script_setup_true_lang.js +88 -0
- package/dist/code/expression-input.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/code/extension.js +202 -0
- package/dist/code/extension.js.map +1 -0
- package/dist/code/index.js +19 -0
- package/dist/code/index.js.map +1 -0
- package/dist/code/language.js +43 -0
- package/dist/code/language.js.map +1 -0
- package/dist/collaboration/index.js +382 -0
- package/dist/collaboration/index.js.map +1 -0
- package/dist/collaboration/order.js +88 -0
- package/dist/collaboration/order.js.map +1 -0
- package/dist/core/check.js +314 -0
- package/dist/core/check.js.map +1 -0
- package/dist/core/document.js +112 -0
- package/dist/core/document.js.map +1 -0
- package/dist/core/expression.js +854 -0
- package/dist/core/expression.js.map +1 -0
- package/dist/core/formulas.js +242 -0
- package/dist/core/formulas.js.map +1 -0
- package/dist/core/rules.js +83 -0
- package/dist/core/rules.js.map +1 -0
- package/dist/core/values.js +80 -0
- package/dist/core/values.js.map +1 -0
- package/dist/fields/builtin.js +167 -0
- package/dist/fields/builtin.js.map +1 -0
- package/dist/fields/components.js +155 -0
- package/dist/fields/components.js.map +1 -0
- package/dist/fields/define.js +44 -0
- package/dist/fields/define.js.map +1 -0
- package/dist/fields/format.js +125 -0
- package/dist/fields/format.js.map +1 -0
- package/dist/fields/options.js +54 -0
- package/dist/fields/options.js.map +1 -0
- package/dist/index.js +20 -0
- package/dist/locale.js +161 -0
- package/dist/locale.js.map +1 -0
- package/dist/renderer/containers.js +430 -0
- package/dist/renderer/containers.js.map +1 -0
- package/dist/renderer/context.js +21 -0
- package/dist/renderer/context.js.map +1 -0
- package/dist/renderer/form-renderer.js +6 -0
- package/dist/renderer/form-renderer.js.map +1 -0
- package/dist/renderer/form-renderer.vue_vue_type_script_setup_true_lang.js +272 -0
- package/dist/renderer/form-renderer.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/renderer/index.js +19 -0
- package/dist/renderer/index.js.map +1 -0
- package/dist/renderer/node-view.js +385 -0
- package/dist/renderer/node-view.js.map +1 -0
- package/dist/style.css +1 -0
- package/dist/style.d.ts +1 -0
- package/dist/style.js +27 -0
- package/dist/types/builder/canvas.d.ts +5 -0
- package/dist/types/builder/completion.d.ts +35 -0
- package/dist/types/builder/condition-editor.vue.d.ts +17 -0
- package/dist/types/builder/condition.d.ts +37 -0
- package/dist/types/builder/context.d.ts +149 -0
- package/dist/types/builder/core/commands.d.ts +74 -0
- package/dist/types/builder/core/history.d.ts +23 -0
- package/dist/types/builder/core/transaction.d.ts +108 -0
- package/dist/types/builder/drag.d.ts +52 -0
- package/dist/types/builder/expression-box.d.ts +8 -0
- package/dist/types/builder/expression-input.vue.d.ts +29 -0
- package/dist/types/builder/extension.d.ts +149 -0
- package/dist/types/builder/form-builder.vue.d.ts +24 -0
- package/dist/types/builder/index.d.ts +76 -0
- package/dist/types/builder/inspector.vue.d.ts +3 -0
- package/dist/types/builder/json-dialog.vue.d.ts +10 -0
- package/dist/types/builder/locale.d.ts +195 -0
- package/dist/types/builder/logic-fields.d.ts +2 -0
- package/dist/types/builder/logic.d.ts +57 -0
- package/dist/types/builder/menu.d.ts +23 -0
- package/dist/types/builder/outline-row.vue.d.ts +19 -0
- package/dist/types/builder/outline.vue.d.ts +3 -0
- package/dist/types/builder/palette.vue.d.ts +3 -0
- package/dist/types/builder/preview.vue.d.ts +3 -0
- package/dist/types/builder/settings-binding.d.ts +23 -0
- package/dist/types/builder/settings.d.ts +49 -0
- package/dist/types/builder/span-field.d.ts +4 -0
- package/dist/types/builder/types.d.ts +59 -0
- package/dist/types/code/expression-input.vue.d.ts +23 -0
- package/dist/types/code/extension.d.ts +45 -0
- package/dist/types/code/index.d.ts +12 -0
- package/dist/types/code/language.d.ts +6 -0
- package/dist/types/collaboration/index.d.ts +64 -0
- package/dist/types/collaboration/order.d.ts +20 -0
- package/dist/types/core/check.d.ts +68 -0
- package/dist/types/core/document.d.ts +36 -0
- package/dist/types/core/expression.d.ts +175 -0
- package/dist/types/core/formulas.d.ts +44 -0
- package/dist/types/core/rules.d.ts +23 -0
- package/dist/types/core/types.d.ts +211 -0
- package/dist/types/core/values.d.ts +22 -0
- package/dist/types/fields/builtin.d.ts +9 -0
- package/dist/types/fields/components.d.ts +177 -0
- package/dist/types/fields/define.d.ts +93 -0
- package/dist/types/fields/format.d.ts +76 -0
- package/dist/types/fields/options.d.ts +11 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/locale.d.ts +45 -0
- package/dist/types/renderer/containers.d.ts +20 -0
- package/dist/types/renderer/context.d.ts +186 -0
- package/dist/types/renderer/form-renderer.vue.d.ts +25 -0
- package/dist/types/renderer/index.d.ts +81 -0
- package/dist/types/renderer/node-view.d.ts +56 -0
- package/package.json +88 -4
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { FormFunction } from './expression';
|
|
2
|
+
import type { FormDocument, FormFieldNode, FormListNode, FormNode } from './types';
|
|
3
|
+
import type { FormFieldType } from '../fields/define';
|
|
4
|
+
/** The value a field starts with: its own default, else its type's empty value. */
|
|
5
|
+
export declare function startValue(type: FormFieldType, node: FormFieldNode): unknown;
|
|
6
|
+
/** A new item of a list, every field at its starting value. */
|
|
7
|
+
export declare function emptyItem(list: FormListNode, types: Map<string, FormFieldType>): Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Give every field of `nodes` that `target` has no value for its starting
|
|
10
|
+
* value, the items of lists included. Values already there stay.
|
|
11
|
+
*/
|
|
12
|
+
export declare function fillValues(nodes: readonly FormNode[], target: Record<string, unknown>, types: Map<string, FormFieldType>): void;
|
|
13
|
+
export interface VisibleValuesOptions {
|
|
14
|
+
/** Functions the expressions can call besides the built-in ones. */
|
|
15
|
+
functions?: Record<string, FormFunction>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A copy of the values without the ones of hidden fields: a field, group,
|
|
19
|
+
* page or list whose `visibleWhen` is false leaves out everything it
|
|
20
|
+
* holds, item by item inside lists. This is what the renderer submits.
|
|
21
|
+
*/
|
|
22
|
+
export declare function visibleValues(document: FormDocument, model: Record<string, unknown>, options?: VisibleValuesOptions): Record<string, unknown>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { FormFieldType } from './define';
|
|
2
|
+
/**
|
|
3
|
+
* The field types every renderer and builder knows. Each one is named
|
|
4
|
+
* after the component it renders, in kebab case without the `Dou`
|
|
5
|
+
* prefix: `input-number` renders `DouInputNumber`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const builtinFields: FormFieldType<any>[];
|
|
8
|
+
/** The built-in types, then `extra` on top: a type of the same name replaces the built-in one. */
|
|
9
|
+
export declare function resolveFields(extra?: readonly FormFieldType<any>[]): Map<string, FormFieldType<import("./define").FormFieldProps>>;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import type { PropType } from 'vue';
|
|
2
|
+
import type { CheckboxValue, RadioValue, Tone } from 'dou-ui';
|
|
3
|
+
/** A choice as written in a document: a plain value is both value and label. */
|
|
4
|
+
export type FormOption = string | number | {
|
|
5
|
+
value: string | number | boolean;
|
|
6
|
+
label?: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export declare function normalizeOptions(options: readonly FormOption[] | undefined): {
|
|
10
|
+
value: string | number | boolean;
|
|
11
|
+
label: string;
|
|
12
|
+
disabled: boolean | undefined;
|
|
13
|
+
}[];
|
|
14
|
+
/** One choice out of a few, all in view. */
|
|
15
|
+
export declare const RadioField: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
16
|
+
modelValue: {
|
|
17
|
+
type: PropType<RadioValue>;
|
|
18
|
+
default: undefined;
|
|
19
|
+
};
|
|
20
|
+
options: {
|
|
21
|
+
type: PropType<FormOption[]>;
|
|
22
|
+
default: () => never[];
|
|
23
|
+
};
|
|
24
|
+
direction: {
|
|
25
|
+
type: PropType<"horizontal" | "vertical">;
|
|
26
|
+
default: string;
|
|
27
|
+
};
|
|
28
|
+
disabled: BooleanConstructor;
|
|
29
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
30
|
+
[key: string]: any;
|
|
31
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
32
|
+
'update:modelValue': (_value: RadioValue) => true;
|
|
33
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
34
|
+
modelValue: {
|
|
35
|
+
type: PropType<RadioValue>;
|
|
36
|
+
default: undefined;
|
|
37
|
+
};
|
|
38
|
+
options: {
|
|
39
|
+
type: PropType<FormOption[]>;
|
|
40
|
+
default: () => never[];
|
|
41
|
+
};
|
|
42
|
+
direction: {
|
|
43
|
+
type: PropType<"horizontal" | "vertical">;
|
|
44
|
+
default: string;
|
|
45
|
+
};
|
|
46
|
+
disabled: BooleanConstructor;
|
|
47
|
+
}>> & Readonly<{
|
|
48
|
+
"onUpdate:modelValue"?: ((_value: RadioValue) => any) | undefined;
|
|
49
|
+
}>, {
|
|
50
|
+
modelValue: RadioValue;
|
|
51
|
+
options: FormOption[];
|
|
52
|
+
direction: "vertical" | "horizontal";
|
|
53
|
+
disabled: boolean;
|
|
54
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
55
|
+
/** Any number of choices out of a few, all in view. */
|
|
56
|
+
export declare const CheckboxGroupField: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
57
|
+
modelValue: {
|
|
58
|
+
type: PropType<CheckboxValue[]>;
|
|
59
|
+
default: undefined;
|
|
60
|
+
};
|
|
61
|
+
options: {
|
|
62
|
+
type: PropType<FormOption[]>;
|
|
63
|
+
default: () => never[];
|
|
64
|
+
};
|
|
65
|
+
direction: {
|
|
66
|
+
type: PropType<"horizontal" | "vertical">;
|
|
67
|
+
default: string;
|
|
68
|
+
};
|
|
69
|
+
disabled: BooleanConstructor;
|
|
70
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
71
|
+
[key: string]: any;
|
|
72
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
73
|
+
'update:modelValue': (_value: CheckboxValue[]) => true;
|
|
74
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
75
|
+
modelValue: {
|
|
76
|
+
type: PropType<CheckboxValue[]>;
|
|
77
|
+
default: undefined;
|
|
78
|
+
};
|
|
79
|
+
options: {
|
|
80
|
+
type: PropType<FormOption[]>;
|
|
81
|
+
default: () => never[];
|
|
82
|
+
};
|
|
83
|
+
direction: {
|
|
84
|
+
type: PropType<"horizontal" | "vertical">;
|
|
85
|
+
default: string;
|
|
86
|
+
};
|
|
87
|
+
disabled: BooleanConstructor;
|
|
88
|
+
}>> & Readonly<{
|
|
89
|
+
"onUpdate:modelValue"?: ((_value: CheckboxValue[]) => any) | undefined;
|
|
90
|
+
}>, {
|
|
91
|
+
modelValue: CheckboxValue[];
|
|
92
|
+
options: FormOption[];
|
|
93
|
+
direction: "vertical" | "horizontal";
|
|
94
|
+
disabled: boolean;
|
|
95
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
96
|
+
/** A single box, e.g. to agree to terms; its text sits beside it. */
|
|
97
|
+
export declare const CheckboxField: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
98
|
+
modelValue: {
|
|
99
|
+
type: BooleanConstructor;
|
|
100
|
+
default: boolean;
|
|
101
|
+
};
|
|
102
|
+
text: StringConstructor;
|
|
103
|
+
disabled: BooleanConstructor;
|
|
104
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
105
|
+
[key: string]: any;
|
|
106
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
107
|
+
'update:modelValue': (_value: boolean) => true;
|
|
108
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
109
|
+
modelValue: {
|
|
110
|
+
type: BooleanConstructor;
|
|
111
|
+
default: boolean;
|
|
112
|
+
};
|
|
113
|
+
text: StringConstructor;
|
|
114
|
+
disabled: BooleanConstructor;
|
|
115
|
+
}>> & Readonly<{
|
|
116
|
+
"onUpdate:modelValue"?: ((_value: boolean) => any) | undefined;
|
|
117
|
+
}>, {
|
|
118
|
+
modelValue: boolean;
|
|
119
|
+
disabled: boolean;
|
|
120
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
121
|
+
/** A heading or a paragraph between fields. */
|
|
122
|
+
export declare const TextField: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
123
|
+
content: {
|
|
124
|
+
type: StringConstructor;
|
|
125
|
+
default: string;
|
|
126
|
+
};
|
|
127
|
+
/** `title` for a heading, `body` for a paragraph, `caption` for small print. */
|
|
128
|
+
variant: {
|
|
129
|
+
type: PropType<"title" | "body" | "caption">;
|
|
130
|
+
default: string;
|
|
131
|
+
};
|
|
132
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
133
|
+
[key: string]: any;
|
|
134
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
135
|
+
content: {
|
|
136
|
+
type: StringConstructor;
|
|
137
|
+
default: string;
|
|
138
|
+
};
|
|
139
|
+
/** `title` for a heading, `body` for a paragraph, `caption` for small print. */
|
|
140
|
+
variant: {
|
|
141
|
+
type: PropType<"title" | "body" | "caption">;
|
|
142
|
+
default: string;
|
|
143
|
+
};
|
|
144
|
+
}>> & Readonly<{}>, {
|
|
145
|
+
content: string;
|
|
146
|
+
variant: "body" | "caption" | "title";
|
|
147
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
148
|
+
export declare const DividerField: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
149
|
+
text: StringConstructor;
|
|
150
|
+
dashed: BooleanConstructor;
|
|
151
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
152
|
+
[key: string]: any;
|
|
153
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
154
|
+
text: StringConstructor;
|
|
155
|
+
dashed: BooleanConstructor;
|
|
156
|
+
}>> & Readonly<{}>, {
|
|
157
|
+
dashed: boolean;
|
|
158
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
159
|
+
export declare const AlertField: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
160
|
+
tone: {
|
|
161
|
+
type: PropType<Tone>;
|
|
162
|
+
default: string;
|
|
163
|
+
};
|
|
164
|
+
title: StringConstructor;
|
|
165
|
+
content: StringConstructor;
|
|
166
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
167
|
+
[key: string]: any;
|
|
168
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
169
|
+
tone: {
|
|
170
|
+
type: PropType<Tone>;
|
|
171
|
+
default: string;
|
|
172
|
+
};
|
|
173
|
+
title: StringConstructor;
|
|
174
|
+
content: StringConstructor;
|
|
175
|
+
}>> & Readonly<{}>, {
|
|
176
|
+
tone: Tone;
|
|
177
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Component, InjectionKey } from 'vue';
|
|
2
|
+
import type { FormFieldNode, FormNode } from '../core/types';
|
|
3
|
+
import type { FormFormatContext } from './format';
|
|
4
|
+
export type FormFieldProps = Record<string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* What a field type is: how it renders, what it starts with, and which
|
|
7
|
+
* settings it takes. The renderer and the builder share the same list.
|
|
8
|
+
*/
|
|
9
|
+
export interface FormFieldType<P extends FormFieldProps = FormFieldProps> {
|
|
10
|
+
/** The name nodes refer to it by in `type`. A type of the same name as a built-in one replaces it. */
|
|
11
|
+
type: string;
|
|
12
|
+
/** Shown to people building the form. */
|
|
13
|
+
label?: string;
|
|
14
|
+
/**
|
|
15
|
+
* - `value`: holds a value at the node's `name`, wrapped in a form item
|
|
16
|
+
* with its label, help and checks.
|
|
17
|
+
* - `display`: only shows something, such as text or a divider.
|
|
18
|
+
*/
|
|
19
|
+
kind?: 'value' | 'display';
|
|
20
|
+
/** Settings a node starts with, below its own `props`. */
|
|
21
|
+
defaultProps?: Partial<P>;
|
|
22
|
+
/**
|
|
23
|
+
* The type's empty value, which a field starts with when its node sets
|
|
24
|
+
* no `default`, e.g. `[]` for a list of choices. Defaults to `null`.
|
|
25
|
+
*/
|
|
26
|
+
empty?: (props: P) => unknown;
|
|
27
|
+
/**
|
|
28
|
+
* Renders the field. A `value` field gets `modelValue`, listens to
|
|
29
|
+
* `update:modelValue`, and receives the settings as props (after
|
|
30
|
+
* `toProps`). Call `useFormField()` inside it for the node itself.
|
|
31
|
+
*/
|
|
32
|
+
component: Component;
|
|
33
|
+
/**
|
|
34
|
+
* The prop that takes the list of options, for a type whose options can
|
|
35
|
+
* come from a source (a node's `source`), e.g. `options` or `data`.
|
|
36
|
+
*/
|
|
37
|
+
optionsProp?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Narrows a value to what new options offer, e.g. drops a city once the
|
|
40
|
+
* province changes. Called when a source loads different options; the
|
|
41
|
+
* value stays as it is when the type has none.
|
|
42
|
+
*/
|
|
43
|
+
fitValue?: (value: unknown, options: readonly unknown[]) => unknown;
|
|
44
|
+
/**
|
|
45
|
+
* The value as text, for a renderer that is `readonly`. Gets the
|
|
46
|
+
* settings (with options loaded from a source). Not called for an empty
|
|
47
|
+
* value, which shows as the renderer's `noValue` text. Defaults to the
|
|
48
|
+
* labels of the chosen options for a type with `optionsProp`, else to
|
|
49
|
+
* the value as plain text: lists joined, booleans as yes and no.
|
|
50
|
+
*/
|
|
51
|
+
format?: (value: unknown, props: P, context: FormFormatContext) => string;
|
|
52
|
+
/**
|
|
53
|
+
* Shows the value in a `readonly` renderer instead of `format`'s text,
|
|
54
|
+
* e.g. a swatch for a color. Gets `modelValue` and the same props as
|
|
55
|
+
* `component`, and `readonly` when it takes one.
|
|
56
|
+
*/
|
|
57
|
+
readonlyComponent?: Component;
|
|
58
|
+
/** Turns the settings into the component's props, when they differ. */
|
|
59
|
+
toProps?: (props: P, node: FormFieldNode) => Record<string, unknown>;
|
|
60
|
+
/** The builder's palette: the type's icon, e.g. one of `@dou-ui/icons`. */
|
|
61
|
+
icon?: Component;
|
|
62
|
+
/**
|
|
63
|
+
* The palette group the type is listed in: `input`, `choice`, `more`
|
|
64
|
+
* (the default), `display`, or a name of your own, shown as it is.
|
|
65
|
+
*/
|
|
66
|
+
group?: string;
|
|
67
|
+
/**
|
|
68
|
+
* The settings the builder's inspector shows for the type, as nodes of
|
|
69
|
+
* a form whose values are the node's `props`: a field named
|
|
70
|
+
* `placeholder` edits `props.placeholder`, and expressions read the
|
|
71
|
+
* other settings as `values`. A setting left at its `default` is not
|
|
72
|
+
* written to the node.
|
|
73
|
+
*/
|
|
74
|
+
settings?: FormNode[];
|
|
75
|
+
}
|
|
76
|
+
/** Declare a field type. Gives the spec its types and leaves it as is otherwise. */
|
|
77
|
+
export declare function defineFormField<P extends FormFieldProps = FormFieldProps>(spec: FormFieldType<P>): FormFieldType<P>;
|
|
78
|
+
/** Settings of a node: its type's `defaultProps` with its own `props` on top. */
|
|
79
|
+
export declare function fieldProps(type: FormFieldType | undefined, node: FormFieldNode): FormFieldProps;
|
|
80
|
+
export interface FormFieldContext {
|
|
81
|
+
/** The node being rendered. */
|
|
82
|
+
node: FormFieldNode;
|
|
83
|
+
/** Its type. */
|
|
84
|
+
type: FormFieldType;
|
|
85
|
+
/** Its settings, with the type's `defaultProps` filled in. */
|
|
86
|
+
props: FormFieldProps;
|
|
87
|
+
}
|
|
88
|
+
export declare const formFieldKey: InjectionKey<() => FormFieldContext>;
|
|
89
|
+
/**
|
|
90
|
+
* Inside a field type's component: the node it renders, its type and
|
|
91
|
+
* settings. The properties stay current when the node changes.
|
|
92
|
+
*/
|
|
93
|
+
export declare function useFormField(): Readonly<FormFieldContext>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { PropType } from 'vue';
|
|
2
|
+
import type { Locale } from 'dou-ui';
|
|
3
|
+
import type { FormFieldNode } from '../core/types';
|
|
4
|
+
import type { FormRendererMessages } from '../locale';
|
|
5
|
+
/** What a field type's `format` gets besides the value and the settings. */
|
|
6
|
+
export interface FormFormatContext {
|
|
7
|
+
/** The node being shown. */
|
|
8
|
+
node: FormFieldNode;
|
|
9
|
+
/** The renderer's texts, e.g. `yes` and `no`. */
|
|
10
|
+
messages: FormRendererMessages;
|
|
11
|
+
/** DouUI's current locale, e.g. for its date patterns. */
|
|
12
|
+
locale: Locale;
|
|
13
|
+
}
|
|
14
|
+
/** Plain text of any value: lists joined, `true` and `false` as yes and no. */
|
|
15
|
+
export declare function formatValue(value: unknown, context: FormFormatContext): string;
|
|
16
|
+
/** The labels of the chosen options, from the setting that holds them (`options` by default). */
|
|
17
|
+
export declare const formatOptions: (prop?: string) => (value: unknown, props: Record<string, unknown>, context: FormFormatContext) => string;
|
|
18
|
+
/**
|
|
19
|
+
* A path through levels of options as their labels, or a list of such
|
|
20
|
+
* paths; only the last label with `showLastOnly`, as the cascader shows it.
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatPath(value: unknown, props: Record<string, unknown>, context: FormFormatContext): string;
|
|
23
|
+
/** A switch or a single box: yes or no, by its `checkedValue` when it has one. */
|
|
24
|
+
export declare function formatToggle(value: unknown, props: Record<string, unknown>, context: FormFormatContext): string;
|
|
25
|
+
/** Text typed into an input, hidden for a password. */
|
|
26
|
+
export declare function formatText(value: unknown, props: Record<string, unknown>): string;
|
|
27
|
+
/** A number, with `precision` decimals when it sets them. */
|
|
28
|
+
export declare function formatNumber(value: unknown, props: Record<string, unknown>): string;
|
|
29
|
+
/** One number or time, or both ends of a range. */
|
|
30
|
+
export declare function formatRange(value: unknown, _props: Record<string, unknown>, context: FormFormatContext): string;
|
|
31
|
+
/** A date written the way the date picker writes it (`displayFormat`, else the locale's); a range as both ends. */
|
|
32
|
+
export declare function formatDate(value: unknown, props: Record<string, unknown>, context: FormFormatContext): string;
|
|
33
|
+
/** A color, with a swatch before its text. */
|
|
34
|
+
export declare const ColorValue: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
35
|
+
modelValue: {
|
|
36
|
+
type: PropType<string | null>;
|
|
37
|
+
default: null;
|
|
38
|
+
};
|
|
39
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
40
|
+
[key: string]: any;
|
|
41
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
42
|
+
modelValue: {
|
|
43
|
+
type: PropType<string | null>;
|
|
44
|
+
default: null;
|
|
45
|
+
};
|
|
46
|
+
}>> & Readonly<{}>, {
|
|
47
|
+
modelValue: string | null;
|
|
48
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
49
|
+
/** Uploaded files, each a link when it has a `url`. */
|
|
50
|
+
export declare const FilesValue: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
51
|
+
modelValue: {
|
|
52
|
+
type: PropType<{
|
|
53
|
+
uid?: string;
|
|
54
|
+
name: string;
|
|
55
|
+
url?: string;
|
|
56
|
+
}[]>;
|
|
57
|
+
default: () => never[];
|
|
58
|
+
};
|
|
59
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
62
|
+
modelValue: {
|
|
63
|
+
type: PropType<{
|
|
64
|
+
uid?: string;
|
|
65
|
+
name: string;
|
|
66
|
+
url?: string;
|
|
67
|
+
}[]>;
|
|
68
|
+
default: () => never[];
|
|
69
|
+
};
|
|
70
|
+
}>> & Readonly<{}>, {
|
|
71
|
+
modelValue: {
|
|
72
|
+
uid?: string;
|
|
73
|
+
name: string;
|
|
74
|
+
url?: string;
|
|
75
|
+
}[];
|
|
76
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value narrowed to what the options offer: a single value the options
|
|
3
|
+
* lack becomes `null`, and a list keeps only the items they have. The
|
|
4
|
+
* same value comes back when nothing is lost.
|
|
5
|
+
*/
|
|
6
|
+
export declare function fitToOptions(value: unknown, options: readonly unknown[]): unknown;
|
|
7
|
+
/**
|
|
8
|
+
* Like `fitToOptions`, for a value that is a path through levels of
|
|
9
|
+
* options, or a list of such paths.
|
|
10
|
+
*/
|
|
11
|
+
export declare function fitPathToOptions(value: unknown, options: readonly unknown[]): unknown;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter } from 'vue';
|
|
2
|
+
import type { ExpressionProblem } from './core/expression';
|
|
3
|
+
import type { DocumentProblem } from './core/check';
|
|
4
|
+
export interface FormRendererMessages {
|
|
5
|
+
/** Buttons of `steps`. */
|
|
6
|
+
prev: string;
|
|
7
|
+
next: string;
|
|
8
|
+
/** Names the page of `steps` that shows, read out when Back or Next goes to it: `{index}`, `{count}`, `{title}`. */
|
|
9
|
+
step: string;
|
|
10
|
+
/** The add button of a list, unless the list sets `addText`. */
|
|
11
|
+
add: string;
|
|
12
|
+
/** The remove button of a list item, read out: `{index}` counts from 1. */
|
|
13
|
+
remove: string;
|
|
14
|
+
/** The drag handle of a list item, read out: `{index}`. */
|
|
15
|
+
move: string;
|
|
16
|
+
/** Names a list item: `{index}`. */
|
|
17
|
+
item: string;
|
|
18
|
+
/** Shown in a list without items. */
|
|
19
|
+
empty: string;
|
|
20
|
+
/** Read out after the title of a tab whose fields have errors. */
|
|
21
|
+
invalid: string;
|
|
22
|
+
/** What a `readonly` renderer shows for a field without a value. */
|
|
23
|
+
noValue: string;
|
|
24
|
+
/** A `readonly` renderer's text for `true`, e.g. a switch that is on. */
|
|
25
|
+
yes: string;
|
|
26
|
+
/** A `readonly` renderer's text for `false`. */
|
|
27
|
+
no: string;
|
|
28
|
+
/** Between the items of a list of values in a `readonly` renderer. */
|
|
29
|
+
separator: string;
|
|
30
|
+
/** Between both ends of a range of dates, times or numbers in a `readonly` renderer. */
|
|
31
|
+
rangeSeparator: string;
|
|
32
|
+
/** What an editor shows for each problem of an expression; `{text}` is the source at fault. */
|
|
33
|
+
expression: Record<ExpressionProblem['code'], string>;
|
|
34
|
+
/** What an editor shows for each problem of a document; `{text}` is the id, name or type at fault. */
|
|
35
|
+
document: Record<DocumentProblem['code'], string>;
|
|
36
|
+
}
|
|
37
|
+
export declare const formRendererLocales: Record<string, FormRendererMessages>;
|
|
38
|
+
/** Texts to change; the `expression` and `document` groups are merged, so only the ones given are replaced. */
|
|
39
|
+
export type FormRendererMessagesOverride = {
|
|
40
|
+
[K in keyof FormRendererMessages]?: FormRendererMessages[K] extends string ? string : Partial<FormRendererMessages[K]>;
|
|
41
|
+
};
|
|
42
|
+
/** The form builder's texts, picked by the name of DouUI's current locale. */
|
|
43
|
+
export declare function useFormRendererMessages(override?: MaybeRefOrGetter<FormRendererMessagesOverride | undefined>): import("vue").ComputedRef<FormRendererMessages>;
|
|
44
|
+
/** Fills `{name}` placeholders. */
|
|
45
|
+
export declare const formatMessage: (text: string, params: Record<string, string | number>) => string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FormNode } from '../core/types';
|
|
2
|
+
import type { NodeScope, RendererContext } from './context';
|
|
3
|
+
import type { Condition, NodeKit, NodeProps } from './context';
|
|
4
|
+
type Flag = {
|
|
5
|
+
readonly value: boolean;
|
|
6
|
+
};
|
|
7
|
+
/** Whether a field at `path` sits among `nodes`, inside a list item included. */
|
|
8
|
+
export declare function holdsPath(nodes: readonly FormNode[], path: string, prefix?: string): boolean;
|
|
9
|
+
/** The paths of every field among `nodes`, the fields of each list item included. */
|
|
10
|
+
export declare function valuePaths(nodes: readonly FormNode[], model: unknown, prefix?: string): string[];
|
|
11
|
+
export declare function tabsView(kit: NodeKit, props: NodeProps, renderer: RendererContext, scope: NodeScope, disabled: Flag, condition: Condition): () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function stepsView(kit: NodeKit, props: NodeProps, renderer: RendererContext, scope: NodeScope, disabled: Flag, condition: Condition): () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function listView(kit: NodeKit, props: NodeProps, renderer: RendererContext, scope: NodeScope, disabled: Flag): () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
}>;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { Component, InjectionKey, VNode } from 'vue';
|
|
2
|
+
import type { FormErrors, FormModel, FormRules, FormValidateResult } from 'dou-ui';
|
|
3
|
+
import type { FormRendererMessages, FormRendererMessagesOverride } from '../locale';
|
|
4
|
+
import type { FormFieldType } from '../fields/define';
|
|
5
|
+
import type { FormDocument, FormNode, FormValidator } from '../core/types';
|
|
6
|
+
import type { FormFunction } from '../core/expression';
|
|
7
|
+
export interface FormRendererProps {
|
|
8
|
+
/** The form to render: its fields, groups and layout, as plain data. */
|
|
9
|
+
form: FormDocument;
|
|
10
|
+
/**
|
|
11
|
+
* The object the fields write to, changed in place. Pass a reactive
|
|
12
|
+
* object to read the values as they change; fields missing from it are
|
|
13
|
+
* filled with their defaults. Defaults to an object of the renderer's own.
|
|
14
|
+
*/
|
|
15
|
+
model?: FormModel;
|
|
16
|
+
/** Field types besides the built-in ones; one of the same name replaces the built-in type. */
|
|
17
|
+
fields?: FormFieldType<any>[];
|
|
18
|
+
/** More rules by field name, e.g. checks that need code. Added to the document's own. */
|
|
19
|
+
rules?: FormRules;
|
|
20
|
+
/** Disable every field. */
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Show the values as text instead of fields, e.g. on a detail page or an
|
|
24
|
+
* approval. Lists show their items without the buttons, steps show every
|
|
25
|
+
* page one after another, and the model is never written to.
|
|
26
|
+
*/
|
|
27
|
+
readonly?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Functions the document's expressions can call besides the built-in
|
|
30
|
+
* ones, e.g. `{ tax: (price) => price * 0.06 }`. They get plain values
|
|
31
|
+
* and should not change them; one of the same name replaces a built-in function.
|
|
32
|
+
*/
|
|
33
|
+
functions?: Record<string, FormFunction>;
|
|
34
|
+
/**
|
|
35
|
+
* Where options come from, by the name a node's `source` gives. A source
|
|
36
|
+
* gets the result of the node's `arg` expression and returns the
|
|
37
|
+
* options, or a promise of them. Results are kept for each name and
|
|
38
|
+
* `arg`, so fields asking the same thing share one call. `reloadSource`
|
|
39
|
+
* forgets them, e.g. after the options changed on the server.
|
|
40
|
+
*/
|
|
41
|
+
sources?: Record<string, FormOptionsLoader>;
|
|
42
|
+
/**
|
|
43
|
+
* Checks that need code, by the name a rule's `validator` gives, e.g. one
|
|
44
|
+
* asking the server whether a user name is taken. A validator may return
|
|
45
|
+
* a promise; only the result of the latest check of a field is shown.
|
|
46
|
+
*/
|
|
47
|
+
validators?: Record<string, FormValidator>;
|
|
48
|
+
/**
|
|
49
|
+
* Submit the values of hidden fields too. By default `submit` hands over
|
|
50
|
+
* a copy of the values without them (see `visibleValues`), so a field
|
|
51
|
+
* that was filled in and then hidden is not sent.
|
|
52
|
+
*/
|
|
53
|
+
keepHidden?: boolean;
|
|
54
|
+
/** Replaces texts of the locale, e.g. the step buttons. */
|
|
55
|
+
messages?: FormRendererMessagesOverride;
|
|
56
|
+
}
|
|
57
|
+
/** Loads the options of a field, given the result of its `source.arg`. */
|
|
58
|
+
export type FormOptionsLoader = (arg: any) => unknown[] | Promise<unknown[]>;
|
|
59
|
+
export interface FormRendererEmits {
|
|
60
|
+
/** A field changed its value: its `name`, and the value it now holds. */
|
|
61
|
+
change: [name: string, value: unknown];
|
|
62
|
+
/**
|
|
63
|
+
* The form was submitted and every field passed: a copy of the values,
|
|
64
|
+
* without the ones of hidden fields unless `keepHidden` is set.
|
|
65
|
+
*/
|
|
66
|
+
submit: [values: FormModel];
|
|
67
|
+
/** The form was submitted and some fields failed. */
|
|
68
|
+
invalid: [errors: Record<string, string>];
|
|
69
|
+
/** The form was reset to its starting values. */
|
|
70
|
+
reset: [];
|
|
71
|
+
}
|
|
72
|
+
export interface FormRendererSlots {
|
|
73
|
+
/**
|
|
74
|
+
* After the fields, e.g. the submit and reset buttons. In a form that is
|
|
75
|
+
* a series of steps, on the last step beside the back button.
|
|
76
|
+
*/
|
|
77
|
+
default?: () => unknown;
|
|
78
|
+
}
|
|
79
|
+
export interface FormRendererExpose {
|
|
80
|
+
/** The object the fields write to. */
|
|
81
|
+
readonly model: FormModel;
|
|
82
|
+
/** Check the given fields, or every field. Never rejects. */
|
|
83
|
+
validate: (names?: string | string[]) => Promise<FormValidateResult>;
|
|
84
|
+
/**
|
|
85
|
+
* Restore the given fields, or every field, to their starting values and
|
|
86
|
+
* clear their errors. Resetting every field also goes back to the first step.
|
|
87
|
+
*/
|
|
88
|
+
resetFields: (names?: string | string[]) => void;
|
|
89
|
+
/** Clear the errors of the given fields, or every field. */
|
|
90
|
+
clearValidate: (names?: string | string[]) => void;
|
|
91
|
+
/**
|
|
92
|
+
* Show errors by field path, e.g. ones a server returned after submit.
|
|
93
|
+
* Each stays until the field's value changes or it is checked again; an
|
|
94
|
+
* empty or `undefined` message clears the field's error. Tabs and steps
|
|
95
|
+
* mark the pages with errors. Returns the paths with a message that no
|
|
96
|
+
* field shows, e.g. a hidden field's, to list them above the form.
|
|
97
|
+
*/
|
|
98
|
+
setErrors: (errors: Partial<FormErrors>) => string[];
|
|
99
|
+
/** Scroll a field into view and focus it. */
|
|
100
|
+
scrollToField: (name: string) => void;
|
|
101
|
+
/** Forget the options loaded from a source, or from every source, and load them again. */
|
|
102
|
+
reloadSource: (name?: string) => void;
|
|
103
|
+
/** A copy of the values as `submit` hands them over, without hidden fields unless `keepHidden` is set. */
|
|
104
|
+
getValues: () => FormModel;
|
|
105
|
+
}
|
|
106
|
+
/** What every node of a renderer reads. */
|
|
107
|
+
export interface RendererContext {
|
|
108
|
+
model: () => FormModel;
|
|
109
|
+
fields: () => Map<string, FormFieldType>;
|
|
110
|
+
/** Pixel width of the label column in the horizontal layout, else `undefined`. */
|
|
111
|
+
labelWidth: () => number | undefined;
|
|
112
|
+
/** Tell the renderer a field wrote a value. */
|
|
113
|
+
changed: (name: string, value: unknown) => void;
|
|
114
|
+
/** The functions expressions can call besides the built-in ones. */
|
|
115
|
+
functions: () => Record<string, FormFunction> | undefined;
|
|
116
|
+
/** The validators rules can name. */
|
|
117
|
+
validators: () => Record<string, FormValidator> | undefined;
|
|
118
|
+
/** Whether values show as text. */
|
|
119
|
+
readonly: () => boolean;
|
|
120
|
+
/** The ids of the formula fields on a circle, which are not worked out. */
|
|
121
|
+
blockedFormulas: () => ReadonlySet<string>;
|
|
122
|
+
/**
|
|
123
|
+
* In a read-only form, a copy of the values with every formula worked
|
|
124
|
+
* out, which formula fields show; nothing writes the model itself.
|
|
125
|
+
*/
|
|
126
|
+
settled: () => FormModel;
|
|
127
|
+
/** Whether the controls are read-only, as in a read-only builder's settings. */
|
|
128
|
+
controlsReadonly: () => boolean;
|
|
129
|
+
/** The options from a source, shared by every field asking the same thing. */
|
|
130
|
+
load: (name: string, arg: unknown) => Promise<unknown[]>;
|
|
131
|
+
/** Bumped by `reloadSource`, so fields reading it load again. */
|
|
132
|
+
sourceVersion: (name: string) => number;
|
|
133
|
+
messages: () => FormRendererMessages;
|
|
134
|
+
validate: (names: string[]) => Promise<FormValidateResult>;
|
|
135
|
+
scrollToField: (name: string) => void;
|
|
136
|
+
/**
|
|
137
|
+
* Add something that can bring a field into view, e.g. tabs selecting
|
|
138
|
+
* the page it is on. It says whether it holds the field.
|
|
139
|
+
*/
|
|
140
|
+
addRevealer: (reveal: (path: string) => boolean) => () => void;
|
|
141
|
+
/** Follow the error a form item shows, so tabs can mark the pages with errors. */
|
|
142
|
+
trackError: (path: () => string | undefined, error: () => string | undefined) => () => void;
|
|
143
|
+
/** The paths of the fields that show an error now. */
|
|
144
|
+
errorPaths: () => string[];
|
|
145
|
+
/** The default slot, for the steps that show it on their last step. */
|
|
146
|
+
footer: () => unknown;
|
|
147
|
+
/** The id of the steps that show the default slot, if the form is a series of steps. */
|
|
148
|
+
footerOwner: () => string | undefined;
|
|
149
|
+
/** Counts the times the whole form was reset, so steps go back to the first one. */
|
|
150
|
+
resets: () => number;
|
|
151
|
+
}
|
|
152
|
+
/** Where a node sits: inside a list item, its fields' paths start with the item's. */
|
|
153
|
+
export interface NodeScope {
|
|
154
|
+
/** Put before the names of fields, e.g. `guests.2.`. */
|
|
155
|
+
prefix: () => string;
|
|
156
|
+
/** The item, read as `item` by expressions. */
|
|
157
|
+
item: () => unknown;
|
|
158
|
+
}
|
|
159
|
+
export declare const scopeKey: InjectionKey<NodeScope>;
|
|
160
|
+
export declare const rendererKey: InjectionKey<RendererContext>;
|
|
161
|
+
/**
|
|
162
|
+
* Internal: renderers inside make their controls read-only (the form's
|
|
163
|
+
* own `readonly`) instead of showing values as text, e.g. the settings of
|
|
164
|
+
* a read-only builder.
|
|
165
|
+
*/
|
|
166
|
+
export declare const controlsReadonlyKey: InjectionKey<() => boolean>;
|
|
167
|
+
/** Whether the groups around a node are disabled. */
|
|
168
|
+
export declare const disabledKey: InjectionKey<() => boolean>;
|
|
169
|
+
/** The scope of nodes outside lists. */
|
|
170
|
+
export declare const rootScope: NodeScope;
|
|
171
|
+
/** The full path of a name in a scope. */
|
|
172
|
+
export declare const pathIn: (scope: NodeScope, name: string) => string;
|
|
173
|
+
/** The props of a node's view. */
|
|
174
|
+
export type NodeProps = {
|
|
175
|
+
node: FormNode;
|
|
176
|
+
columns: number;
|
|
177
|
+
inset: number;
|
|
178
|
+
asPage: boolean;
|
|
179
|
+
};
|
|
180
|
+
/** Runs an expression of a node (the viewed one by default); `fallback` when it is unset or does not parse. */
|
|
181
|
+
export type Condition = (source: string | undefined, fallback: boolean, node?: FormNode) => boolean;
|
|
182
|
+
/** What container views draw their children with, handed in to keep the modules apart. */
|
|
183
|
+
export interface NodeKit {
|
|
184
|
+
view: Component;
|
|
185
|
+
renderNodes: (nodes: readonly FormNode[], columns: number, inset?: number) => VNode[];
|
|
186
|
+
}
|