@flowgram.ai/node 0.1.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/dist/esm/index.js +576 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +321 -0
- package/dist/index.d.ts +321 -0
- package/dist/index.js +619 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { FormModel, OnFormValuesChangePayload, FormModelValid, FormFeedback, FormManager, IFormItem, FormItem, IFormMeta, NodeFormContext } from '@flowgram.ai/form-core';
|
|
4
|
+
import { FieldName as FieldName$1, FieldValue as FieldValue$1, Errors, Warnings } from '@flowgram.ai/form/src/types';
|
|
5
|
+
import { FormValidateReturn, FormControl, FormModel as FormModel$1, FieldValue, IFieldArray, IField, FieldName, Validate as Validate$1, FormRenderProps, ValidateTrigger, FormState } from '@flowgram.ai/form';
|
|
6
|
+
import * as _flowgram_ai_document from '@flowgram.ai/document';
|
|
7
|
+
import { FlowNodeEntity } from '@flowgram.ai/document';
|
|
8
|
+
import * as _flowgram_ai_utils from '@flowgram.ai/utils';
|
|
9
|
+
import { Disposable, Emitter, DisposableCollection, Event } from '@flowgram.ai/utils';
|
|
10
|
+
|
|
11
|
+
declare class FormModelV2 extends FormModel implements Disposable {
|
|
12
|
+
protected effectMap: Record<string, EffectOptions[]>;
|
|
13
|
+
protected effectReturnMap: Map<DataEvent, Record<string, EffectReturn>>;
|
|
14
|
+
protected plugins: FormPlugin[];
|
|
15
|
+
protected node: FlowNodeEntity;
|
|
16
|
+
protected formFeedbacks: FormValidateReturn | undefined;
|
|
17
|
+
protected onInitializedEmitter: Emitter<FormModel>;
|
|
18
|
+
protected onValidateEmitter: Emitter<FormModel>;
|
|
19
|
+
readonly onValidate: _flowgram_ai_utils.Event<FormModel>;
|
|
20
|
+
readonly onInitialized: _flowgram_ai_utils.Event<FormModel>;
|
|
21
|
+
protected onDisposeEmitter: Emitter<void>;
|
|
22
|
+
readonly onDispose: _flowgram_ai_utils.Event<void>;
|
|
23
|
+
protected toDispose: DisposableCollection;
|
|
24
|
+
protected onFormValuesChangeEmitter: Emitter<OnFormValuesChangePayload>;
|
|
25
|
+
readonly onFormValuesChange: _flowgram_ai_utils.Event<OnFormValuesChangePayload>;
|
|
26
|
+
protected onValidChangeEmitter: Emitter<FormModelValid>;
|
|
27
|
+
readonly onValidChange: _flowgram_ai_utils.Event<FormModelValid>;
|
|
28
|
+
protected onFeedbacksChangeEmitter: Emitter<FormFeedback[]>;
|
|
29
|
+
readonly onFeedbacksChange: _flowgram_ai_utils.Event<FormFeedback[]>;
|
|
30
|
+
constructor(node: FlowNodeEntity);
|
|
31
|
+
protected _valid: FormModelValid;
|
|
32
|
+
get valid(): FormModelValid;
|
|
33
|
+
private set valid(value);
|
|
34
|
+
get flowNodeEntity(): FlowNodeEntity;
|
|
35
|
+
get formManager(): FormManager;
|
|
36
|
+
protected _formControl?: FormControl<any>;
|
|
37
|
+
get formControl(): FormControl<any> | undefined;
|
|
38
|
+
get formMeta(): any;
|
|
39
|
+
protected _feedbacks: FormFeedback[];
|
|
40
|
+
get feedbacks(): FormFeedback[];
|
|
41
|
+
private set feedbacks(value);
|
|
42
|
+
get formItemPathMap(): Map<string, IFormItem>;
|
|
43
|
+
protected _initialized: boolean;
|
|
44
|
+
get initialized(): boolean;
|
|
45
|
+
get nodeContext(): {
|
|
46
|
+
node: FlowNodeEntity;
|
|
47
|
+
playgroundContext: unknown;
|
|
48
|
+
};
|
|
49
|
+
get nativeFormModel(): FormModel$1 | undefined;
|
|
50
|
+
render(): React.JSX.Element;
|
|
51
|
+
initPlugins(plugins: FormPlugin[]): void;
|
|
52
|
+
init(formMeta: FormMeta, rawInitialValues?: any): void;
|
|
53
|
+
toJSON(): any;
|
|
54
|
+
clearValid(): void;
|
|
55
|
+
validate(): Promise<boolean>;
|
|
56
|
+
getValues<T = any>(): T | undefined;
|
|
57
|
+
getField<TValue = FieldValue, TField extends IFieldArray<TValue> | IField<TValue> = IField<TValue>>(name: FieldName): TField | undefined;
|
|
58
|
+
getValueIn<TValue>(name: FieldName): TValue | undefined;
|
|
59
|
+
setValueIn(name: FieldName, value: any): void;
|
|
60
|
+
/**
|
|
61
|
+
* 监听表单某个路径下的值变化
|
|
62
|
+
* @param name 路径
|
|
63
|
+
* @param callback 回调函数
|
|
64
|
+
*/
|
|
65
|
+
onFormValueChangeIn<TValue = FieldValue, TFormValue = FieldValue>(name: FieldName, callback: (payload: onFormValueChangeInPayload<TValue, TFormValue>) => void): void;
|
|
66
|
+
/**
|
|
67
|
+
* @deprecated 该方法用于兼容 V1 版本 FormModel接口,如果确定是FormModelV2 请使用 FormModel.getValueIn
|
|
68
|
+
* @param path glob path
|
|
69
|
+
*/
|
|
70
|
+
getFormItemValueByPath(globPath: string): any;
|
|
71
|
+
validateWithFeedbacks(): Promise<FormFeedback[]>;
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated 该方法用于兼容 V1 版本 FormModel接口,如果确定是FormModelV2, 请使用FormModel.getValueIn 和 FormModel.setValueIn
|
|
74
|
+
* @param path glob path
|
|
75
|
+
*/
|
|
76
|
+
getFormItemByPath(path: string): FormItem | undefined;
|
|
77
|
+
dispose(): void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface FormPluginConfig<Opts = any> {
|
|
81
|
+
/**
|
|
82
|
+
* FormModel 初始化时执行
|
|
83
|
+
* @param ctx
|
|
84
|
+
*/
|
|
85
|
+
onInit?: (ctx: FormPluginCtx, opts: Opts) => void;
|
|
86
|
+
/**
|
|
87
|
+
* 同 FormMeta 中的effects 会与 FormMeta 中的effects 合并
|
|
88
|
+
*/
|
|
89
|
+
effect?: Record<string, EffectOptions[]>;
|
|
90
|
+
/**
|
|
91
|
+
* FormModel 销毁时执行
|
|
92
|
+
* @param ctx
|
|
93
|
+
*/
|
|
94
|
+
onDispose?: (ctx: FormPluginCtx, opts: Opts) => void;
|
|
95
|
+
}
|
|
96
|
+
declare class FormPlugin<Opts = any> implements Disposable {
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly pluginId: string;
|
|
99
|
+
readonly config: FormPluginConfig;
|
|
100
|
+
readonly opts?: Opts;
|
|
101
|
+
protected _formModel: FormModelV2;
|
|
102
|
+
constructor(name: string, config: FormPluginConfig, opts?: Opts);
|
|
103
|
+
get formModel(): FormModelV2;
|
|
104
|
+
get ctx(): {
|
|
105
|
+
formModel: FormModelV2;
|
|
106
|
+
node: _flowgram_ai_document.FlowNodeEntity;
|
|
107
|
+
playgroundContext: unknown;
|
|
108
|
+
};
|
|
109
|
+
init(formModel: FormModelV2): void;
|
|
110
|
+
dispose(): void;
|
|
111
|
+
}
|
|
112
|
+
declare function defineFormPluginCreator<Opts>(name: string, config: FormPluginConfig): (opts: Opts) => FormPlugin<Opts>;
|
|
113
|
+
|
|
114
|
+
interface Node {
|
|
115
|
+
}
|
|
116
|
+
interface Flow {
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* NodeContext contains
|
|
120
|
+
* - node: the Editor's node entity.
|
|
121
|
+
* - playgroundContext: the Editor's playgroundContext injected when initiate the Editor.
|
|
122
|
+
*/
|
|
123
|
+
type NodeContext = NodeFormContext;
|
|
124
|
+
type Validate<TFieldValue = any, TFormValues = any> = (props: {
|
|
125
|
+
value: TFieldValue;
|
|
126
|
+
formValues: TFormValues;
|
|
127
|
+
context: NodeContext;
|
|
128
|
+
name: FieldName$1;
|
|
129
|
+
}) => ReturnType<Validate$1<TFieldValue, TFormValues>>;
|
|
130
|
+
declare enum DataEvent {
|
|
131
|
+
onValueChange = "onValueChange",
|
|
132
|
+
/**
|
|
133
|
+
* When value Init,it triggers when
|
|
134
|
+
* - defaultValue is configured in formMeta, it will trigger when form is initializing.
|
|
135
|
+
* - defaultValue is configured in Field, it will trigger when this Field is initializing if no initial value is set to this field.
|
|
136
|
+
*/
|
|
137
|
+
onValueInit = "onValueInit",
|
|
138
|
+
/**
|
|
139
|
+
* When Value Init or change
|
|
140
|
+
*/
|
|
141
|
+
onValueInitOrChange = "onValueInitOrChange",
|
|
142
|
+
onArrayAppend = "onArrayAppend",
|
|
143
|
+
onArrayDelete = "onArrayDelete"
|
|
144
|
+
}
|
|
145
|
+
type EffectReturn = () => void;
|
|
146
|
+
type Effect<TFieldValue = any, TFormValues = any> = (props: {
|
|
147
|
+
name: FieldName$1;
|
|
148
|
+
value: TFieldValue;
|
|
149
|
+
prevValue?: TFieldValue;
|
|
150
|
+
formValues: TFormValues;
|
|
151
|
+
context: NodeContext;
|
|
152
|
+
}) => void | EffectReturn;
|
|
153
|
+
type ArrayAppendEffect<TFieldValue = any, TFormValues = any> = (props: {
|
|
154
|
+
index: number;
|
|
155
|
+
value: TFieldValue;
|
|
156
|
+
arrayValues: Array<TFieldValue>;
|
|
157
|
+
formValues: TFormValues;
|
|
158
|
+
context: NodeContext;
|
|
159
|
+
}) => void | EffectReturn;
|
|
160
|
+
type ArrayDeleteEffect<TFieldValue = any, TFormValues = any> = (props: {
|
|
161
|
+
index: number;
|
|
162
|
+
arrayValue: Array<TFieldValue>;
|
|
163
|
+
formValues: TFormValues;
|
|
164
|
+
context: NodeContext;
|
|
165
|
+
}) => void | EffectReturn;
|
|
166
|
+
type EffectOptions = {
|
|
167
|
+
effect: Effect;
|
|
168
|
+
event: DataEvent;
|
|
169
|
+
} | {
|
|
170
|
+
effect: ArrayAppendEffect;
|
|
171
|
+
event: DataEvent;
|
|
172
|
+
} | {
|
|
173
|
+
effect: ArrayDeleteEffect;
|
|
174
|
+
event: DataEvent;
|
|
175
|
+
};
|
|
176
|
+
interface FormMeta<TValues = any> {
|
|
177
|
+
/**
|
|
178
|
+
* The render method of the node form content. <Form /> is already integrated, so you don't need to wrap your components with <Form />
|
|
179
|
+
* @param props
|
|
180
|
+
*/
|
|
181
|
+
render: (props: FormRenderProps<any>) => React.ReactElement;
|
|
182
|
+
/**
|
|
183
|
+
* When to trigger the validation.
|
|
184
|
+
*/
|
|
185
|
+
validateTrigger?: ValidateTrigger;
|
|
186
|
+
/**
|
|
187
|
+
* Form data's validation rules. It's a key value map, where the key is a pattern of data's path (or field name), the value is a validate function.
|
|
188
|
+
*/
|
|
189
|
+
validate?: Record<FieldName$1, Validate>;
|
|
190
|
+
/**
|
|
191
|
+
* Form data's effects. It's a key value map, where the key is a pattern of data's path (or field name), the value is an array of effect configuration.
|
|
192
|
+
*/
|
|
193
|
+
effect?: Record<FieldName$1, EffectOptions[]>;
|
|
194
|
+
/**
|
|
195
|
+
* Form data's complete default value. it will not be sent to formatOnInit, but used directly as form's value when needed.
|
|
196
|
+
*/
|
|
197
|
+
defaultValues?: TValues | ((contest: NodeContext) => TValues);
|
|
198
|
+
/**
|
|
199
|
+
* This function is to format the value when initiate the form, the returned value will be used as the initial value of the form.
|
|
200
|
+
* @param value value input to node as initialValue.
|
|
201
|
+
* @param context
|
|
202
|
+
*/
|
|
203
|
+
formatOnInit?: (value: any, context: NodeContext) => any;
|
|
204
|
+
/**
|
|
205
|
+
* This function is to format the value when FormModel.toJSON is called, the returned value will be used as the final value to be saved .
|
|
206
|
+
* @param value value sent by form before format.
|
|
207
|
+
* @param context
|
|
208
|
+
*/
|
|
209
|
+
formatOnSubmit?: (value: any, context: NodeContext) => any;
|
|
210
|
+
/**
|
|
211
|
+
* Form's plugins
|
|
212
|
+
*/
|
|
213
|
+
plugins?: FormPlugin[];
|
|
214
|
+
}
|
|
215
|
+
declare function isFormModelV2(fm: FormModel | FormModelV2): fm is FormModelV2;
|
|
216
|
+
declare function isFormMetaV2(formMeta: IFormMeta | FormMeta): boolean;
|
|
217
|
+
type FormPluginCtx = {
|
|
218
|
+
formModel: FormModelV2;
|
|
219
|
+
} & NodeContext;
|
|
220
|
+
interface onFormValueChangeInPayload<TValue = FieldValue$1, TFormValues = FieldValue$1> {
|
|
221
|
+
value: TValue;
|
|
222
|
+
prevValue: TValue;
|
|
223
|
+
formValues: TFormValues;
|
|
224
|
+
prevFormValues: TFormValues;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
declare function isFormV2(node: FlowNodeEntity): boolean;
|
|
228
|
+
declare function createEffectOptions<T>(event: DataEvent, effect: T): {
|
|
229
|
+
effect: T;
|
|
230
|
+
event: DataEvent;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Listen to Form's values and refresh the React component.
|
|
235
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
236
|
+
* @param node
|
|
237
|
+
*/
|
|
238
|
+
declare function useWatchFormValues<T = any>(node: FlowNodeEntity): T | undefined;
|
|
239
|
+
/**
|
|
240
|
+
* Listen to Form's value in a certain path and refresh the React component.
|
|
241
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
242
|
+
* @param node
|
|
243
|
+
*/
|
|
244
|
+
declare function useWatchFormValueIn<T = any>(node: FlowNodeEntity, name: string): T | undefined;
|
|
245
|
+
/**
|
|
246
|
+
* Listen to FormModel's initialization and refresh React component.
|
|
247
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
248
|
+
* @param node
|
|
249
|
+
*/
|
|
250
|
+
declare function useInitializedFormModel(node: FlowNodeEntity): FormModelV2;
|
|
251
|
+
/**
|
|
252
|
+
* Get Form's state, Form State is a proxy, it will refresh the React component when the value you accessed changed
|
|
253
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
254
|
+
* @param node
|
|
255
|
+
*/
|
|
256
|
+
declare function useWatchFormState(node: FlowNodeEntity): FormState | undefined;
|
|
257
|
+
/**
|
|
258
|
+
* Get Form's errors, Form errors is a proxy, it will refresh the React component when the value you accessed changed
|
|
259
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
260
|
+
* @param node
|
|
261
|
+
*/
|
|
262
|
+
declare function useWatchFormErrors(node: FlowNodeEntity): Errors | undefined;
|
|
263
|
+
/**
|
|
264
|
+
* Get Form's warnings, Form warnings is a proxy, it will refresh the React component when the value you accessed changed
|
|
265
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
266
|
+
* @param node
|
|
267
|
+
*/
|
|
268
|
+
declare function useWatchFormWarnings(node: FlowNodeEntity): Warnings | undefined;
|
|
269
|
+
|
|
270
|
+
interface NodeFormProps<TValues> {
|
|
271
|
+
/**
|
|
272
|
+
* The initialValues of the form.
|
|
273
|
+
*/
|
|
274
|
+
initialValues: TValues;
|
|
275
|
+
/**
|
|
276
|
+
* Form values. Returns a deep copy of the data in the store.
|
|
277
|
+
*/
|
|
278
|
+
values: TValues;
|
|
279
|
+
/**
|
|
280
|
+
* Form state
|
|
281
|
+
*/
|
|
282
|
+
state: FormState;
|
|
283
|
+
/**
|
|
284
|
+
* Get value in certain path
|
|
285
|
+
* @param name path
|
|
286
|
+
*/
|
|
287
|
+
getValueIn<TValue = FieldValue>(name: FieldName): TValue;
|
|
288
|
+
/**
|
|
289
|
+
* Set value in certain path.
|
|
290
|
+
* It will trigger the re-rendering of the Field Component if a Field is related to this path
|
|
291
|
+
* @param name path
|
|
292
|
+
*/
|
|
293
|
+
setValueIn<TValue>(name: FieldName, value: TValue): void;
|
|
294
|
+
/**
|
|
295
|
+
* Render form
|
|
296
|
+
*/
|
|
297
|
+
render: () => React__default.ReactNode;
|
|
298
|
+
/**
|
|
299
|
+
* Form value change event
|
|
300
|
+
*/
|
|
301
|
+
onFormValuesChange: Event<OnFormValuesChangePayload>;
|
|
302
|
+
/**
|
|
303
|
+
* Trigger form validate
|
|
304
|
+
*/
|
|
305
|
+
validate: () => Promise<boolean>;
|
|
306
|
+
/**
|
|
307
|
+
* Form validate event
|
|
308
|
+
*/
|
|
309
|
+
onValidate: Event<FormState>;
|
|
310
|
+
/**
|
|
311
|
+
* Form field value change event
|
|
312
|
+
*/
|
|
313
|
+
onFormValueChangeIn<TValue = FieldValue, TFormValue = FieldValue>(name: FieldName, callback: (payload: onFormValueChangeInPayload<TValue, TFormValue>) => void): void;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Only support FormModelV2
|
|
317
|
+
* @param node
|
|
318
|
+
*/
|
|
319
|
+
declare function getNodeForm<TValues = FieldValue>(node: FlowNodeEntity): NodeFormProps<TValues> | undefined;
|
|
320
|
+
|
|
321
|
+
export { type ArrayAppendEffect, type ArrayDeleteEffect, DataEvent, type Effect, type EffectOptions, type EffectReturn, type Flow, type FormMeta, FormModelV2, FormPlugin, type FormPluginConfig, type FormPluginCtx, type Node, type NodeFormProps, type Validate, createEffectOptions, defineFormPluginCreator, getNodeForm, isFormMetaV2, isFormModelV2, isFormV2, type onFormValueChangeInPayload, useInitializedFormModel, useWatchFormErrors, useWatchFormState, useWatchFormValueIn, useWatchFormValues, useWatchFormWarnings };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { FormModel, OnFormValuesChangePayload, FormModelValid, FormFeedback, FormManager, IFormItem, FormItem, IFormMeta, NodeFormContext } from '@flowgram.ai/form-core';
|
|
4
|
+
import { FieldName as FieldName$1, FieldValue as FieldValue$1, Errors, Warnings } from '@flowgram.ai/form/src/types';
|
|
5
|
+
import { FormValidateReturn, FormControl, FormModel as FormModel$1, FieldValue, IFieldArray, IField, FieldName, Validate as Validate$1, FormRenderProps, ValidateTrigger, FormState } from '@flowgram.ai/form';
|
|
6
|
+
import * as _flowgram_ai_document from '@flowgram.ai/document';
|
|
7
|
+
import { FlowNodeEntity } from '@flowgram.ai/document';
|
|
8
|
+
import * as _flowgram_ai_utils from '@flowgram.ai/utils';
|
|
9
|
+
import { Disposable, Emitter, DisposableCollection, Event } from '@flowgram.ai/utils';
|
|
10
|
+
|
|
11
|
+
declare class FormModelV2 extends FormModel implements Disposable {
|
|
12
|
+
protected effectMap: Record<string, EffectOptions[]>;
|
|
13
|
+
protected effectReturnMap: Map<DataEvent, Record<string, EffectReturn>>;
|
|
14
|
+
protected plugins: FormPlugin[];
|
|
15
|
+
protected node: FlowNodeEntity;
|
|
16
|
+
protected formFeedbacks: FormValidateReturn | undefined;
|
|
17
|
+
protected onInitializedEmitter: Emitter<FormModel>;
|
|
18
|
+
protected onValidateEmitter: Emitter<FormModel>;
|
|
19
|
+
readonly onValidate: _flowgram_ai_utils.Event<FormModel>;
|
|
20
|
+
readonly onInitialized: _flowgram_ai_utils.Event<FormModel>;
|
|
21
|
+
protected onDisposeEmitter: Emitter<void>;
|
|
22
|
+
readonly onDispose: _flowgram_ai_utils.Event<void>;
|
|
23
|
+
protected toDispose: DisposableCollection;
|
|
24
|
+
protected onFormValuesChangeEmitter: Emitter<OnFormValuesChangePayload>;
|
|
25
|
+
readonly onFormValuesChange: _flowgram_ai_utils.Event<OnFormValuesChangePayload>;
|
|
26
|
+
protected onValidChangeEmitter: Emitter<FormModelValid>;
|
|
27
|
+
readonly onValidChange: _flowgram_ai_utils.Event<FormModelValid>;
|
|
28
|
+
protected onFeedbacksChangeEmitter: Emitter<FormFeedback[]>;
|
|
29
|
+
readonly onFeedbacksChange: _flowgram_ai_utils.Event<FormFeedback[]>;
|
|
30
|
+
constructor(node: FlowNodeEntity);
|
|
31
|
+
protected _valid: FormModelValid;
|
|
32
|
+
get valid(): FormModelValid;
|
|
33
|
+
private set valid(value);
|
|
34
|
+
get flowNodeEntity(): FlowNodeEntity;
|
|
35
|
+
get formManager(): FormManager;
|
|
36
|
+
protected _formControl?: FormControl<any>;
|
|
37
|
+
get formControl(): FormControl<any> | undefined;
|
|
38
|
+
get formMeta(): any;
|
|
39
|
+
protected _feedbacks: FormFeedback[];
|
|
40
|
+
get feedbacks(): FormFeedback[];
|
|
41
|
+
private set feedbacks(value);
|
|
42
|
+
get formItemPathMap(): Map<string, IFormItem>;
|
|
43
|
+
protected _initialized: boolean;
|
|
44
|
+
get initialized(): boolean;
|
|
45
|
+
get nodeContext(): {
|
|
46
|
+
node: FlowNodeEntity;
|
|
47
|
+
playgroundContext: unknown;
|
|
48
|
+
};
|
|
49
|
+
get nativeFormModel(): FormModel$1 | undefined;
|
|
50
|
+
render(): React.JSX.Element;
|
|
51
|
+
initPlugins(plugins: FormPlugin[]): void;
|
|
52
|
+
init(formMeta: FormMeta, rawInitialValues?: any): void;
|
|
53
|
+
toJSON(): any;
|
|
54
|
+
clearValid(): void;
|
|
55
|
+
validate(): Promise<boolean>;
|
|
56
|
+
getValues<T = any>(): T | undefined;
|
|
57
|
+
getField<TValue = FieldValue, TField extends IFieldArray<TValue> | IField<TValue> = IField<TValue>>(name: FieldName): TField | undefined;
|
|
58
|
+
getValueIn<TValue>(name: FieldName): TValue | undefined;
|
|
59
|
+
setValueIn(name: FieldName, value: any): void;
|
|
60
|
+
/**
|
|
61
|
+
* 监听表单某个路径下的值变化
|
|
62
|
+
* @param name 路径
|
|
63
|
+
* @param callback 回调函数
|
|
64
|
+
*/
|
|
65
|
+
onFormValueChangeIn<TValue = FieldValue, TFormValue = FieldValue>(name: FieldName, callback: (payload: onFormValueChangeInPayload<TValue, TFormValue>) => void): void;
|
|
66
|
+
/**
|
|
67
|
+
* @deprecated 该方法用于兼容 V1 版本 FormModel接口,如果确定是FormModelV2 请使用 FormModel.getValueIn
|
|
68
|
+
* @param path glob path
|
|
69
|
+
*/
|
|
70
|
+
getFormItemValueByPath(globPath: string): any;
|
|
71
|
+
validateWithFeedbacks(): Promise<FormFeedback[]>;
|
|
72
|
+
/**
|
|
73
|
+
* @deprecated 该方法用于兼容 V1 版本 FormModel接口,如果确定是FormModelV2, 请使用FormModel.getValueIn 和 FormModel.setValueIn
|
|
74
|
+
* @param path glob path
|
|
75
|
+
*/
|
|
76
|
+
getFormItemByPath(path: string): FormItem | undefined;
|
|
77
|
+
dispose(): void;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface FormPluginConfig<Opts = any> {
|
|
81
|
+
/**
|
|
82
|
+
* FormModel 初始化时执行
|
|
83
|
+
* @param ctx
|
|
84
|
+
*/
|
|
85
|
+
onInit?: (ctx: FormPluginCtx, opts: Opts) => void;
|
|
86
|
+
/**
|
|
87
|
+
* 同 FormMeta 中的effects 会与 FormMeta 中的effects 合并
|
|
88
|
+
*/
|
|
89
|
+
effect?: Record<string, EffectOptions[]>;
|
|
90
|
+
/**
|
|
91
|
+
* FormModel 销毁时执行
|
|
92
|
+
* @param ctx
|
|
93
|
+
*/
|
|
94
|
+
onDispose?: (ctx: FormPluginCtx, opts: Opts) => void;
|
|
95
|
+
}
|
|
96
|
+
declare class FormPlugin<Opts = any> implements Disposable {
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly pluginId: string;
|
|
99
|
+
readonly config: FormPluginConfig;
|
|
100
|
+
readonly opts?: Opts;
|
|
101
|
+
protected _formModel: FormModelV2;
|
|
102
|
+
constructor(name: string, config: FormPluginConfig, opts?: Opts);
|
|
103
|
+
get formModel(): FormModelV2;
|
|
104
|
+
get ctx(): {
|
|
105
|
+
formModel: FormModelV2;
|
|
106
|
+
node: _flowgram_ai_document.FlowNodeEntity;
|
|
107
|
+
playgroundContext: unknown;
|
|
108
|
+
};
|
|
109
|
+
init(formModel: FormModelV2): void;
|
|
110
|
+
dispose(): void;
|
|
111
|
+
}
|
|
112
|
+
declare function defineFormPluginCreator<Opts>(name: string, config: FormPluginConfig): (opts: Opts) => FormPlugin<Opts>;
|
|
113
|
+
|
|
114
|
+
interface Node {
|
|
115
|
+
}
|
|
116
|
+
interface Flow {
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* NodeContext contains
|
|
120
|
+
* - node: the Editor's node entity.
|
|
121
|
+
* - playgroundContext: the Editor's playgroundContext injected when initiate the Editor.
|
|
122
|
+
*/
|
|
123
|
+
type NodeContext = NodeFormContext;
|
|
124
|
+
type Validate<TFieldValue = any, TFormValues = any> = (props: {
|
|
125
|
+
value: TFieldValue;
|
|
126
|
+
formValues: TFormValues;
|
|
127
|
+
context: NodeContext;
|
|
128
|
+
name: FieldName$1;
|
|
129
|
+
}) => ReturnType<Validate$1<TFieldValue, TFormValues>>;
|
|
130
|
+
declare enum DataEvent {
|
|
131
|
+
onValueChange = "onValueChange",
|
|
132
|
+
/**
|
|
133
|
+
* When value Init,it triggers when
|
|
134
|
+
* - defaultValue is configured in formMeta, it will trigger when form is initializing.
|
|
135
|
+
* - defaultValue is configured in Field, it will trigger when this Field is initializing if no initial value is set to this field.
|
|
136
|
+
*/
|
|
137
|
+
onValueInit = "onValueInit",
|
|
138
|
+
/**
|
|
139
|
+
* When Value Init or change
|
|
140
|
+
*/
|
|
141
|
+
onValueInitOrChange = "onValueInitOrChange",
|
|
142
|
+
onArrayAppend = "onArrayAppend",
|
|
143
|
+
onArrayDelete = "onArrayDelete"
|
|
144
|
+
}
|
|
145
|
+
type EffectReturn = () => void;
|
|
146
|
+
type Effect<TFieldValue = any, TFormValues = any> = (props: {
|
|
147
|
+
name: FieldName$1;
|
|
148
|
+
value: TFieldValue;
|
|
149
|
+
prevValue?: TFieldValue;
|
|
150
|
+
formValues: TFormValues;
|
|
151
|
+
context: NodeContext;
|
|
152
|
+
}) => void | EffectReturn;
|
|
153
|
+
type ArrayAppendEffect<TFieldValue = any, TFormValues = any> = (props: {
|
|
154
|
+
index: number;
|
|
155
|
+
value: TFieldValue;
|
|
156
|
+
arrayValues: Array<TFieldValue>;
|
|
157
|
+
formValues: TFormValues;
|
|
158
|
+
context: NodeContext;
|
|
159
|
+
}) => void | EffectReturn;
|
|
160
|
+
type ArrayDeleteEffect<TFieldValue = any, TFormValues = any> = (props: {
|
|
161
|
+
index: number;
|
|
162
|
+
arrayValue: Array<TFieldValue>;
|
|
163
|
+
formValues: TFormValues;
|
|
164
|
+
context: NodeContext;
|
|
165
|
+
}) => void | EffectReturn;
|
|
166
|
+
type EffectOptions = {
|
|
167
|
+
effect: Effect;
|
|
168
|
+
event: DataEvent;
|
|
169
|
+
} | {
|
|
170
|
+
effect: ArrayAppendEffect;
|
|
171
|
+
event: DataEvent;
|
|
172
|
+
} | {
|
|
173
|
+
effect: ArrayDeleteEffect;
|
|
174
|
+
event: DataEvent;
|
|
175
|
+
};
|
|
176
|
+
interface FormMeta<TValues = any> {
|
|
177
|
+
/**
|
|
178
|
+
* The render method of the node form content. <Form /> is already integrated, so you don't need to wrap your components with <Form />
|
|
179
|
+
* @param props
|
|
180
|
+
*/
|
|
181
|
+
render: (props: FormRenderProps<any>) => React.ReactElement;
|
|
182
|
+
/**
|
|
183
|
+
* When to trigger the validation.
|
|
184
|
+
*/
|
|
185
|
+
validateTrigger?: ValidateTrigger;
|
|
186
|
+
/**
|
|
187
|
+
* Form data's validation rules. It's a key value map, where the key is a pattern of data's path (or field name), the value is a validate function.
|
|
188
|
+
*/
|
|
189
|
+
validate?: Record<FieldName$1, Validate>;
|
|
190
|
+
/**
|
|
191
|
+
* Form data's effects. It's a key value map, where the key is a pattern of data's path (or field name), the value is an array of effect configuration.
|
|
192
|
+
*/
|
|
193
|
+
effect?: Record<FieldName$1, EffectOptions[]>;
|
|
194
|
+
/**
|
|
195
|
+
* Form data's complete default value. it will not be sent to formatOnInit, but used directly as form's value when needed.
|
|
196
|
+
*/
|
|
197
|
+
defaultValues?: TValues | ((contest: NodeContext) => TValues);
|
|
198
|
+
/**
|
|
199
|
+
* This function is to format the value when initiate the form, the returned value will be used as the initial value of the form.
|
|
200
|
+
* @param value value input to node as initialValue.
|
|
201
|
+
* @param context
|
|
202
|
+
*/
|
|
203
|
+
formatOnInit?: (value: any, context: NodeContext) => any;
|
|
204
|
+
/**
|
|
205
|
+
* This function is to format the value when FormModel.toJSON is called, the returned value will be used as the final value to be saved .
|
|
206
|
+
* @param value value sent by form before format.
|
|
207
|
+
* @param context
|
|
208
|
+
*/
|
|
209
|
+
formatOnSubmit?: (value: any, context: NodeContext) => any;
|
|
210
|
+
/**
|
|
211
|
+
* Form's plugins
|
|
212
|
+
*/
|
|
213
|
+
plugins?: FormPlugin[];
|
|
214
|
+
}
|
|
215
|
+
declare function isFormModelV2(fm: FormModel | FormModelV2): fm is FormModelV2;
|
|
216
|
+
declare function isFormMetaV2(formMeta: IFormMeta | FormMeta): boolean;
|
|
217
|
+
type FormPluginCtx = {
|
|
218
|
+
formModel: FormModelV2;
|
|
219
|
+
} & NodeContext;
|
|
220
|
+
interface onFormValueChangeInPayload<TValue = FieldValue$1, TFormValues = FieldValue$1> {
|
|
221
|
+
value: TValue;
|
|
222
|
+
prevValue: TValue;
|
|
223
|
+
formValues: TFormValues;
|
|
224
|
+
prevFormValues: TFormValues;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
declare function isFormV2(node: FlowNodeEntity): boolean;
|
|
228
|
+
declare function createEffectOptions<T>(event: DataEvent, effect: T): {
|
|
229
|
+
effect: T;
|
|
230
|
+
event: DataEvent;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Listen to Form's values and refresh the React component.
|
|
235
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
236
|
+
* @param node
|
|
237
|
+
*/
|
|
238
|
+
declare function useWatchFormValues<T = any>(node: FlowNodeEntity): T | undefined;
|
|
239
|
+
/**
|
|
240
|
+
* Listen to Form's value in a certain path and refresh the React component.
|
|
241
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
242
|
+
* @param node
|
|
243
|
+
*/
|
|
244
|
+
declare function useWatchFormValueIn<T = any>(node: FlowNodeEntity, name: string): T | undefined;
|
|
245
|
+
/**
|
|
246
|
+
* Listen to FormModel's initialization and refresh React component.
|
|
247
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
248
|
+
* @param node
|
|
249
|
+
*/
|
|
250
|
+
declare function useInitializedFormModel(node: FlowNodeEntity): FormModelV2;
|
|
251
|
+
/**
|
|
252
|
+
* Get Form's state, Form State is a proxy, it will refresh the React component when the value you accessed changed
|
|
253
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
254
|
+
* @param node
|
|
255
|
+
*/
|
|
256
|
+
declare function useWatchFormState(node: FlowNodeEntity): FormState | undefined;
|
|
257
|
+
/**
|
|
258
|
+
* Get Form's errors, Form errors is a proxy, it will refresh the React component when the value you accessed changed
|
|
259
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
260
|
+
* @param node
|
|
261
|
+
*/
|
|
262
|
+
declare function useWatchFormErrors(node: FlowNodeEntity): Errors | undefined;
|
|
263
|
+
/**
|
|
264
|
+
* Get Form's warnings, Form warnings is a proxy, it will refresh the React component when the value you accessed changed
|
|
265
|
+
* By providing related node, you can use this hook outside the Form Component.
|
|
266
|
+
* @param node
|
|
267
|
+
*/
|
|
268
|
+
declare function useWatchFormWarnings(node: FlowNodeEntity): Warnings | undefined;
|
|
269
|
+
|
|
270
|
+
interface NodeFormProps<TValues> {
|
|
271
|
+
/**
|
|
272
|
+
* The initialValues of the form.
|
|
273
|
+
*/
|
|
274
|
+
initialValues: TValues;
|
|
275
|
+
/**
|
|
276
|
+
* Form values. Returns a deep copy of the data in the store.
|
|
277
|
+
*/
|
|
278
|
+
values: TValues;
|
|
279
|
+
/**
|
|
280
|
+
* Form state
|
|
281
|
+
*/
|
|
282
|
+
state: FormState;
|
|
283
|
+
/**
|
|
284
|
+
* Get value in certain path
|
|
285
|
+
* @param name path
|
|
286
|
+
*/
|
|
287
|
+
getValueIn<TValue = FieldValue>(name: FieldName): TValue;
|
|
288
|
+
/**
|
|
289
|
+
* Set value in certain path.
|
|
290
|
+
* It will trigger the re-rendering of the Field Component if a Field is related to this path
|
|
291
|
+
* @param name path
|
|
292
|
+
*/
|
|
293
|
+
setValueIn<TValue>(name: FieldName, value: TValue): void;
|
|
294
|
+
/**
|
|
295
|
+
* Render form
|
|
296
|
+
*/
|
|
297
|
+
render: () => React__default.ReactNode;
|
|
298
|
+
/**
|
|
299
|
+
* Form value change event
|
|
300
|
+
*/
|
|
301
|
+
onFormValuesChange: Event<OnFormValuesChangePayload>;
|
|
302
|
+
/**
|
|
303
|
+
* Trigger form validate
|
|
304
|
+
*/
|
|
305
|
+
validate: () => Promise<boolean>;
|
|
306
|
+
/**
|
|
307
|
+
* Form validate event
|
|
308
|
+
*/
|
|
309
|
+
onValidate: Event<FormState>;
|
|
310
|
+
/**
|
|
311
|
+
* Form field value change event
|
|
312
|
+
*/
|
|
313
|
+
onFormValueChangeIn<TValue = FieldValue, TFormValue = FieldValue>(name: FieldName, callback: (payload: onFormValueChangeInPayload<TValue, TFormValue>) => void): void;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Only support FormModelV2
|
|
317
|
+
* @param node
|
|
318
|
+
*/
|
|
319
|
+
declare function getNodeForm<TValues = FieldValue>(node: FlowNodeEntity): NodeFormProps<TValues> | undefined;
|
|
320
|
+
|
|
321
|
+
export { type ArrayAppendEffect, type ArrayDeleteEffect, DataEvent, type Effect, type EffectOptions, type EffectReturn, type Flow, type FormMeta, FormModelV2, FormPlugin, type FormPluginConfig, type FormPluginCtx, type Node, type NodeFormProps, type Validate, createEffectOptions, defineFormPluginCreator, getNodeForm, isFormMetaV2, isFormModelV2, isFormV2, type onFormValueChangeInPayload, useInitializedFormModel, useWatchFormErrors, useWatchFormState, useWatchFormValueIn, useWatchFormValues, useWatchFormWarnings };
|