@flowgram.ai/form 0.1.0-alpha.10

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.
@@ -0,0 +1,785 @@
1
+ import * as React$1 from 'react';
2
+ import React__default from 'react';
3
+ import * as _flowgram_ai_utils from '@flowgram.ai/utils';
4
+ import { MaybePromise, Disposable, Emitter, DisposableCollection } from '@flowgram.ai/utils';
5
+ import { ReactiveState } from '@flowgram.ai/reactive';
6
+
7
+ /**
8
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
9
+ * SPDX-License-Identifier: MIT
10
+ */
11
+ type Context = any;
12
+
13
+ /**
14
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
15
+ * SPDX-License-Identifier: MIT
16
+ */
17
+
18
+ declare enum FeedbackLevel {
19
+ Error = "error",
20
+ Warning = "warning"
21
+ }
22
+ interface Feedback<FeedbackLevel> {
23
+ /**
24
+ * The data path (or field path) that generate this feedback
25
+ */
26
+ name: string;
27
+ /**
28
+ * The type of the feedback
29
+ */
30
+ type?: string;
31
+ /**
32
+ * Feedback level
33
+ */
34
+ level: FeedbackLevel;
35
+ /**
36
+ * Feedback message
37
+ */
38
+ message: string | React.ReactNode;
39
+ }
40
+ type FieldError = Feedback<FeedbackLevel.Error>;
41
+ type FieldWarning = Feedback<FeedbackLevel.Warning>;
42
+ type FormErrorOptions = Omit<FieldError, 'name'>;
43
+ type FormWarningOptions = Omit<FieldWarning, 'name'>;
44
+ type Validate<TFieldValue = any, TFormValues = any> = (props: {
45
+ /**
46
+ * Value of the data to validate
47
+ */
48
+ value: TFieldValue;
49
+ /**
50
+ * Complete form values
51
+ */
52
+ formValues: TFormValues;
53
+ /**
54
+ * The path of the data we are validating
55
+ */
56
+ name: FieldName;
57
+ /**
58
+ * The custom context set when init form
59
+ */
60
+ context: Context;
61
+ }) => MaybePromise<string> | MaybePromise<FormErrorOptions> | MaybePromise<FormWarningOptions> | MaybePromise<undefined>;
62
+ type Errors = Record<FieldName, FieldError[]>;
63
+ type Warnings = Record<FieldName, FieldWarning[]>;
64
+ declare enum ValidateTrigger {
65
+ onChange = "onChange",
66
+ onBlur = "onBlur"
67
+ }
68
+ type FormValidateReturn = (FieldError | FieldWarning)[];
69
+
70
+ /**
71
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
72
+ * SPDX-License-Identifier: MIT
73
+ */
74
+ declare class Path {
75
+ protected _path: string[];
76
+ constructor(path: string | string[]);
77
+ get parent(): Path | undefined;
78
+ toString(): string;
79
+ get value(): string[];
80
+ /**
81
+ * 仅计直系child
82
+ * @param path
83
+ */
84
+ isChild(path: string): boolean;
85
+ /**
86
+ * 比较两个数组path大小
87
+ * 返回小于0则path1<path2, 大于0 则path1>path2, 等于0则相等
88
+ * @param path1
89
+ * @param path2
90
+ */
91
+ static compareArrayPath(path1: Path, path2: Path): number | void;
92
+ isChildOrGrandChild(path: string): boolean;
93
+ getArrayIndex(parent: Path): number;
94
+ concat(name: number | string): Path;
95
+ replaceParent(parent: Path, newParent: Path): Path;
96
+ }
97
+
98
+ /**
99
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
100
+ * SPDX-License-Identifier: MIT
101
+ */
102
+
103
+ declare class Store<TValues = FieldValue> {
104
+ protected _values: TValues;
105
+ get values(): TValues;
106
+ set values(v: TValues);
107
+ setIn<TValue = FieldValue>(path: Path, value: TValue): void;
108
+ getIn<TValue = FieldValue>(path: Path): TValue;
109
+ dispose(): void;
110
+ }
111
+
112
+ interface OnValueChangePayload<TValue> {
113
+ value: TValue | undefined;
114
+ prevValue: TValue | undefined;
115
+ formValues: any;
116
+ prevFormValues: any;
117
+ }
118
+ declare class FieldModel<TValue extends FieldValue = FieldValue> implements Disposable {
119
+ readonly onValueChangeEmitter: Emitter<OnValueChangePayload<TValue>>;
120
+ readonly form: FormModel;
121
+ readonly id: string;
122
+ readonly onValueChange: _flowgram_ai_utils.Event<OnValueChangePayload<TValue>>;
123
+ protected toDispose: DisposableCollection;
124
+ protected _ref?: Ref;
125
+ protected _path: Path;
126
+ protected _state: ReactiveState<FieldModelState>;
127
+ /**
128
+ * @deprecated
129
+ * 原用于直接给field 设置validate 逻辑,现将该逻辑放到form._options.validate 中设置,该字段暂时弃用
130
+ */
131
+ originalValidate?: Validate;
132
+ protected _renderCount: number;
133
+ constructor(path: Path, form: FormModel);
134
+ protected _mount: boolean;
135
+ get renderCount(): number;
136
+ set renderCount(n: number);
137
+ private initState;
138
+ get path(): Path;
139
+ get name(): FieldName;
140
+ set name(name: FieldName);
141
+ get ref(): Ref | undefined;
142
+ set ref(ref: Ref | undefined);
143
+ get state(): FieldModelState;
144
+ get reactiveState(): ReactiveState<FieldModelState>;
145
+ get value(): TValue | undefined;
146
+ set value(value: TValue | undefined);
147
+ updateNameForLeafState(newName: string): void;
148
+ /**
149
+ * @deprecated
150
+ * @param validate
151
+ * @param from
152
+ */
153
+ updateValidate(validate: Validate | undefined, from?: 'ui'): void;
154
+ bubbleState(): void;
155
+ clearState(): void;
156
+ get children(): FieldModel[];
157
+ get parent(): FieldModel | undefined;
158
+ clear(): void;
159
+ validate(): Promise<void>;
160
+ validateSelf(): Promise<void>;
161
+ protected _runAsyncValidate(): Promise<{
162
+ errors?: FieldError[];
163
+ warnings?: FieldWarning[];
164
+ }>;
165
+ updateState(s: Partial<FieldModel>): void;
166
+ dispose(): void;
167
+ onDispose(fn: () => void): void;
168
+ }
169
+
170
+ declare class FieldArrayModel<TValue = FieldValue> extends FieldModel<Array<TValue>> {
171
+ protected onAppendEmitter: Emitter<{
172
+ index: number;
173
+ value: TValue | undefined;
174
+ arrayValue: Array<TValue>;
175
+ }>;
176
+ readonly onAppend: _flowgram_ai_utils.Event<{
177
+ index: number;
178
+ value: TValue | undefined;
179
+ arrayValue: Array<TValue>;
180
+ }>;
181
+ protected onDeleteEmitter: Emitter<{
182
+ arrayValue: Array<TValue> | undefined;
183
+ index: number;
184
+ }>;
185
+ readonly onDelete: _flowgram_ai_utils.Event<{
186
+ arrayValue: Array<TValue> | undefined;
187
+ index: number;
188
+ }>;
189
+ get children(): FieldModel<any>[];
190
+ map<T>(cb: (f: FieldModel, index: number, arr: FieldModel[]) => T): T[];
191
+ append(value?: TValue): FieldModel<any>;
192
+ /**
193
+ * Delete the element in given index and delete the corresponding FieldModel as well
194
+ * @param index
195
+ */
196
+ delete(index: number): void;
197
+ _splice(start: number, deleteCount?: number): void;
198
+ swap(from: number, to: number): void;
199
+ move(from: number, to: number): void;
200
+ protected insertAt(index: number, value: TValue): void;
201
+ /**
202
+ * get element path at given index
203
+ * @param index
204
+ * @protected
205
+ */
206
+ protected getPathAt(index: number): Path;
207
+ /**
208
+ * find all fields including child and grandchild fields at given index.
209
+ * @param index
210
+ * @protected
211
+ */
212
+ protected findAllFieldsAt(index: number): FieldModel<any>[];
213
+ }
214
+
215
+ declare class FormModel<TValues = any> implements Disposable {
216
+ protected _fieldMap: Map<string, FieldModel>;
217
+ readonly store: Store<any>;
218
+ protected _options: FormOptions;
219
+ protected onFieldModelCreateEmitter: Emitter<FieldModel<any>>;
220
+ readonly onFieldModelCreate: _flowgram_ai_utils.Event<FieldModel<any>>;
221
+ readonly onFormValuesChangeEmitter: Emitter<OnFormValuesChangePayload>;
222
+ readonly onFormValuesChange: _flowgram_ai_utils.Event<OnFormValuesChangePayload>;
223
+ readonly onFormValuesInitEmitter: Emitter<OnFormValuesInitPayload>;
224
+ readonly onFormValuesInit: _flowgram_ai_utils.Event<OnFormValuesInitPayload>;
225
+ readonly onFormValuesUpdatedEmitter: Emitter<OnFormValuesUpdatedPayload>;
226
+ readonly onFormValuesUpdated: _flowgram_ai_utils.Event<OnFormValuesUpdatedPayload>;
227
+ readonly onValidateEmitter: Emitter<FormModelState>;
228
+ readonly onValidate: _flowgram_ai_utils.Event<FormModelState>;
229
+ protected _state: ReactiveState<FormModelState>;
230
+ protected _initialized: boolean;
231
+ set fieldMap(map: Map<string, FieldModel<any>>);
232
+ /**
233
+ * 表单初始值,初始化设置后不可修改
234
+ * @protected
235
+ */
236
+ get fieldMap(): Map<string, FieldModel<any>>;
237
+ get context(): any;
238
+ get initialValues(): any;
239
+ get values(): any;
240
+ set values(v: any);
241
+ get validationTrigger(): ValidateTrigger | undefined;
242
+ get state(): FormModelState;
243
+ get reactiveState(): ReactiveState<FormModelState>;
244
+ get fields(): FieldModel[];
245
+ updateState(state: Partial<FormState>): void;
246
+ get initialized(): boolean;
247
+ fireOnFormValuesChange(payload: OnFormValuesChangePayload): void;
248
+ fireOnFormValuesInit(payload: OnFormValuesInitPayload): void;
249
+ init(options: FormOptions<TValues>): void;
250
+ createField<TValue = FieldValue>(name: FieldName, isArray?: boolean): FieldModel<TValue>;
251
+ createFieldArray<TValue = FieldValue>(name: FieldName, value?: Array<TValue>): FieldArrayModel<TValue>;
252
+ /**
253
+ * 销毁Field 模型和子模型,但不会删除field的值
254
+ * @param name
255
+ */
256
+ disposeField(name: string): void;
257
+ /**
258
+ * 删除field, 会删除值和 Field 模型, 以及对应的子模型
259
+ * @param name
260
+ */
261
+ deleteField(name: string): void;
262
+ getField<TFieldModel extends FieldModel | FieldArrayModel = FieldModel>(name: FieldName): TFieldModel | undefined;
263
+ getValueIn<TValue>(name: FieldName): TValue;
264
+ setValueIn<TValue>(name: FieldName, value: TValue): void;
265
+ setInitValueIn<TValue = any>(name: FieldName, value: TValue): void;
266
+ clearValueIn(name: FieldName): void;
267
+ validateIn(name: FieldName): Promise<(string | FormErrorOptions | FormWarningOptions | undefined)[] | undefined>;
268
+ validate(): Promise<FormValidateReturn>;
269
+ alignStateWithFieldMap(): void;
270
+ dispose(): void;
271
+ }
272
+
273
+ /**
274
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
275
+ * SPDX-License-Identifier: MIT
276
+ */
277
+
278
+ interface FormState {
279
+ /**
280
+ * If the form data is valid
281
+ */
282
+ invalid: boolean;
283
+ /**
284
+ * If the form data is different from the intialValues
285
+ */
286
+ isDirty: boolean;
287
+ /**
288
+ * If the form fields have been touched
289
+ */
290
+ isTouched: boolean;
291
+ /**
292
+ * If the form is during validation
293
+ */
294
+ isValidating: boolean;
295
+ /**
296
+ * Form errors
297
+ */
298
+ errors?: Errors;
299
+ /**
300
+ * Form warnings
301
+ */
302
+ warnings?: Warnings;
303
+ }
304
+ interface FormModelState extends Omit<FormState, 'errors' | 'warnings'> {
305
+ errors?: Errors;
306
+ warnings?: Warnings;
307
+ }
308
+ interface FormOptions<TValues = any> {
309
+ /**
310
+ * InitialValues of the form.
311
+ */
312
+ initialValues?: TValues;
313
+ /**
314
+ * When should the validation trigger, for example onChange or onBlur.
315
+ */
316
+ validateTrigger?: ValidateTrigger;
317
+ /**
318
+ * 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.
319
+ */
320
+ validate?: Record<string, Validate>;
321
+ /**
322
+ * Custom context. It will be accessible via form instance or in validate function.
323
+ */
324
+ context?: Context;
325
+ }
326
+ interface Form$1<TValues = any> {
327
+ /**
328
+ * The initialValues of the form.
329
+ */
330
+ initialValues: TValues;
331
+ /**
332
+ * Form values. Returns a deep copy of the data in the store.
333
+ */
334
+ values: TValues;
335
+ /**
336
+ * Form state
337
+ */
338
+ state: FormState;
339
+ /**
340
+ * Get value in certain path
341
+ * @param name path
342
+ */
343
+ getValueIn<TValue = FieldValue>(name: FieldName): TValue;
344
+ /**
345
+ * Set value in certain path.
346
+ * It will trigger the re-rendering of the Field Component if a Field is related to this path
347
+ * @param name path
348
+ */
349
+ setValueIn<TValue>(name: FieldName, value: TValue): void;
350
+ /**
351
+ * Trigger validate for the whole form.
352
+ */
353
+ validate: () => Promise<FormValidateReturn>;
354
+ }
355
+ interface FormRenderProps<TValues> {
356
+ /**
357
+ * Form instance.
358
+ */
359
+ form: Form$1<TValues>;
360
+ }
361
+ interface FormControl<TValues> {
362
+ _formModel: FormModel<TValues>;
363
+ getField: <TValue = FieldValue, TField extends Field$1<TValue> | FieldArray$1<TValue> = Field$1<TValue>>(name: FieldName) => Field$1<TValue> | FieldArray$1<TValue> | undefined;
364
+ /** 手动初始化form */
365
+ init: () => void;
366
+ }
367
+ interface CreateFormReturn<TValues> {
368
+ form: Form$1<TValues>;
369
+ control: FormControl<TValues>;
370
+ }
371
+ interface OnFormValuesChangeOptions {
372
+ action?: 'array-append' | 'array-splice' | 'array-swap';
373
+ indexes?: number[];
374
+ }
375
+ interface OnFormValuesChangePayload {
376
+ values: FieldValue;
377
+ prevValues: FieldValue;
378
+ name: FieldName;
379
+ options?: OnFormValuesChangeOptions;
380
+ }
381
+ interface OnFormValuesInitPayload {
382
+ values: FieldValue;
383
+ prevValues: FieldValue;
384
+ name: FieldName;
385
+ }
386
+ interface OnFormValuesUpdatedPayload {
387
+ values: FieldValue;
388
+ prevValues: FieldValue;
389
+ name: FieldName;
390
+ options?: OnFormValuesChangeOptions;
391
+ }
392
+
393
+ /**
394
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
395
+ * SPDX-License-Identifier: MIT
396
+ */
397
+
398
+ type FieldValue = any;
399
+ type FieldName = string;
400
+ type CustomElement = Partial<HTMLElement> & {
401
+ name: FieldName;
402
+ type?: string;
403
+ value?: any;
404
+ disabled?: boolean;
405
+ checked?: boolean;
406
+ options?: HTMLOptionsCollection;
407
+ files?: FileList | null;
408
+ focus?: () => void;
409
+ };
410
+ type FieldElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement | CustomElement;
411
+ type Ref = FieldElement;
412
+ /**
413
+ * Field render model, it's only available when Field is rendered
414
+ */
415
+ interface Field$1<TFieldValue extends FieldValue = FieldValue, E = React__default.ChangeEvent<any> | TFieldValue> {
416
+ /**
417
+ * Uniq key for the Field, you can use it for the child react component's uniq key.
418
+ */
419
+ key: string;
420
+ /**
421
+ * A function which sends the input's value to Field.
422
+ * It should be assigned to the onChange prop of the input component
423
+ * @param e It can be the new value of the field or the event sent by original dom input or checkbox component.
424
+ */
425
+ onChange: (e: E) => void;
426
+ /**
427
+ * The current value of Field
428
+ */
429
+ value: TFieldValue;
430
+ /**
431
+ * Field's name (path)
432
+ */
433
+ name: FieldName;
434
+ /**
435
+ * A function which sends the input's onFocus event to Field. It should be assigned to the input's onFocus prop.
436
+ */
437
+ onFocus?: () => void;
438
+ /**
439
+ * A function which sends the input's onBlur event to Field. It should be assigned to the input's onBlur prop.
440
+ */
441
+ onBlur?: () => void;
442
+ }
443
+ /**
444
+ * FieldArray render model, it's only available when FieldArray is rendered
445
+ */
446
+ interface FieldArray$1<TFieldValue extends FieldValue = FieldValue> extends Field$1<Array<TFieldValue> | undefined, Array<TFieldValue> | undefined> {
447
+ /**
448
+ * Same as native Array.map, the first param of the callback function is the child field of this FieldArray.
449
+ * @param cb callback function
450
+ */
451
+ map: <T = any>(cb: (f: Field$1<TFieldValue>, index: number) => T) => T[];
452
+ /**
453
+ * Append a value at the end of the array, it will create a new Field for this value as well.
454
+ * @param value the value to append
455
+ */
456
+ append: (value: TFieldValue) => Field$1<TFieldValue>;
457
+ /**
458
+ * @deprecated use remove instead
459
+ * Delete the value and the related field at certain index of the array.
460
+ * @param index the index of the element to delete
461
+ */
462
+ delete: (index: number) => void;
463
+ /**
464
+ * Delete the value and the related field at certain index of the array.
465
+ * @param index the index of the element to delete
466
+ */
467
+ remove: (index: number) => void;
468
+ /**
469
+ * Move an array element from one position to another.
470
+ * @param from from position
471
+ * @param to to position
472
+ */
473
+ move: (from: number, to: number) => void;
474
+ /**
475
+ * Swap the position of two elements of the array.
476
+ * @param from
477
+ * @param to
478
+ */
479
+ swap: (from: number, to: number) => void;
480
+ }
481
+ interface FieldOptions<TValue, TFormValues = any> {
482
+ /**
483
+ * Field's name(path), it should be uniq within a form instance.
484
+ * Two Fields Rendered with the same name will link to the same part of data and field status such as errors is shared.
485
+ */
486
+ name: FieldName;
487
+ /**
488
+ * Default value of the field. Please notice that Field is a render model, so this default value will only be set when
489
+ * the field is rendered. If you want to give a default value before field rendering, please set it in the Form's defaultValue.
490
+ */
491
+ defaultValue?: TValue;
492
+ /**
493
+ * This is a render prop. A function that returns a React element and provides the ability to attach events and value into the component.
494
+ * This simplifies integrating with external controlled components with non-standard prop names. Provides field、fieldState and formState, to the child component.
495
+ * @param props
496
+ */
497
+ render?: (props: FieldRenderProps<TValue>) => React__default.ReactElement;
498
+ }
499
+ interface FieldRenderProps<TValue> {
500
+ field: Field$1<TValue>;
501
+ fieldState: Readonly<FieldState>;
502
+ formState: Readonly<FormState>;
503
+ }
504
+ interface FieldArrayOptions<TValue> {
505
+ /**
506
+ * Field's name(path), it should be uniq within a form instance.
507
+ * Two Fields Rendered with the same name will link to the same part of data and field status such as errors is shared.
508
+ */
509
+ name: FieldName;
510
+ /**
511
+ * Default value of the field. Please notice that Field is a render model, so this default value will only be set when
512
+ * the field is rendered. If you want to give a default value before field rendering, please set it in the Form's initialValues.
513
+ */
514
+ defaultValue?: TValue[];
515
+ /**
516
+ * This is a render prop. A function that returns a React element and provides the ability to attach events and value into the component.
517
+ * This simplifies integrating with external controlled components with non-standard prop names. Provides field、fieldState and formState, to the child component.
518
+ * @param props
519
+ */
520
+ render?: (props: FieldArrayRenderProps<TValue>) => React__default.ReactElement;
521
+ }
522
+ interface FieldArrayRenderProps<TValue> {
523
+ field: FieldArray$1<TValue>;
524
+ fieldState: Readonly<FieldState>;
525
+ formState: Readonly<FormState>;
526
+ }
527
+ interface FieldState {
528
+ /**
529
+ * If field value is invalid
530
+ */
531
+ invalid: boolean;
532
+ /**
533
+ * If field input component is touched by user
534
+ */
535
+ isTouched: boolean;
536
+ /**
537
+ * If field current value is different from the initialValue.
538
+ */
539
+ isDirty: boolean;
540
+ /**
541
+ * If field is validating.
542
+ */
543
+ isValidating: boolean;
544
+ /**
545
+ * Field errors, empty array means there is no errors.
546
+ */
547
+ errors?: FieldError[];
548
+ /**
549
+ * Field warnings, empty array means there is no warnings.
550
+ */
551
+ warnings?: FieldWarning[];
552
+ }
553
+ interface FieldModelState extends Omit<FieldState, 'errors' | 'warnings'> {
554
+ errors?: Errors;
555
+ warnings?: Warnings;
556
+ }
557
+
558
+ /**
559
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
560
+ * SPDX-License-Identifier: MIT
561
+ */
562
+
563
+ type FieldProps<TValue> = FieldOptions<TValue> & {
564
+ /**
565
+ * A React element or a render prop
566
+ */
567
+ children?: ((props: FieldRenderProps<TValue>) => React$1.ReactElement) | React$1.ReactElement;
568
+ /**
569
+ * Dependencies of the current field. If a field name is given in deps, current field will re-render if the given field name data is updated
570
+ */
571
+ deps?: FieldName[];
572
+ };
573
+ /**
574
+ * HOC That declare a field, an Field model will be created it's rendered. Multiple Field rendering with a same name will link to the same model, which means they shared data、 status and methods
575
+ */
576
+ declare function Field<TValue>({ name, defaultValue, render, children, deps, }: FieldProps<TValue>): React$1.ReactElement;
577
+
578
+ /**
579
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
580
+ * SPDX-License-Identifier: MIT
581
+ */
582
+
583
+ type FormProps<TValues> = FormOptions & {
584
+ /**
585
+ * React children or child render prop
586
+ */
587
+ children?: ((props: FormRenderProps<TValues>) => React__default.ReactNode) | React__default.ReactNode;
588
+ /**
589
+ * If this prop is set to true, Form instance will be kept event thought<Form /> is destroyed.
590
+ * This means you can still use some form's api such as Form.validate and Form.setValueIn to handle pure data logic.
591
+ * @default false
592
+ */
593
+ keepModelOnUnMount?: boolean;
594
+ /**
595
+ * provide form instance from outside. if control is given Form will use the form instance in the control instead of creating one.
596
+ */
597
+ control?: FormControl<TValues>;
598
+ };
599
+ /**
600
+ * Hoc That init and provide Form instance. You can also provide form instance from outside by using control prop
601
+ * @param props
602
+ */
603
+ declare function Form<TValues>(props: FormProps<TValues>): React__default.JSX.Element;
604
+
605
+ /**
606
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
607
+ * SPDX-License-Identifier: MIT
608
+ */
609
+
610
+ /**
611
+ * Get Form instance. It should be use in a child component of <Form />
612
+ */
613
+ declare function useForm(): Form$1;
614
+
615
+ /**
616
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
617
+ * SPDX-License-Identifier: MIT
618
+ */
619
+
620
+ /**
621
+ * Listen to the field data change and refresh the React component.
622
+ * @param name the field's uniq name (path)
623
+ */
624
+ declare function useWatch<TValue = FieldValue>(name: FieldName): TValue;
625
+
626
+ /**
627
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
628
+ * SPDX-License-Identifier: MIT
629
+ */
630
+
631
+ type FieldArrayProps<TValue> = FieldArrayOptions<TValue> & {
632
+ /**
633
+ * A React element or a render prop
634
+ */
635
+ children?: ((props: FieldArrayRenderProps<TValue>) => React$1.ReactElement) | React$1.ReactElement;
636
+ /**
637
+ * Dependencies of the current field. If a field name is given in deps, current field will re-render if the given field name data is updated
638
+ */
639
+ deps?: FieldName[];
640
+ };
641
+ /**
642
+ * HOC That declare an array field, an FieldArray model will be created when it's rendered. Multiple FieldArray rendering with a same name will link to the same model, which means they shared data、 status and methods
643
+ */
644
+ declare function FieldArray<TValue extends FieldValue>({ name, defaultValue, deps, render, children, }: FieldArrayProps<TValue>): React$1.ReactElement;
645
+
646
+ /**
647
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
648
+ * SPDX-License-Identifier: MIT
649
+ */
650
+
651
+ /**
652
+ * @deprecated
653
+ * `useField` is deprecated because its return relies on React render. if the Field is not rendered, the return would be
654
+ * undefined. If you simply want to monitor the change of the value of a certain path, please use `useWatch(fieldName)`
655
+ * @param name
656
+ */
657
+ declare function useField<TFieldValue = FieldValue, TField extends Field$1<TFieldValue> | FieldArray$1<TFieldValue> = Field$1<TFieldValue>>(name?: FieldName): TField | undefined;
658
+
659
+ declare function useFormState(control?: FormControl<any> | Form$1): FormState;
660
+ declare function useFormErrors(control?: FormControl<any> | Form$1): Errors | undefined;
661
+ declare function useFormWarnings(control?: FormControl<any> | Form$1): Warnings | undefined;
662
+
663
+ /**
664
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
665
+ * SPDX-License-Identifier: MIT
666
+ */
667
+
668
+ /**
669
+ * Get validate method of a field with given name. the returned function could possibly do nothing if the field is not found.
670
+ * The reason could be that the field is not rendered yet or the name given is wrong.
671
+ * @param name
672
+ */
673
+ declare function useFieldValidate(name?: FieldName): () => void;
674
+
675
+ /**
676
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
677
+ * SPDX-License-Identifier: MIT
678
+ */
679
+
680
+ /**
681
+ * Get the current Field. It should be used in a child component of <Field />, otherwise it throws an error
682
+ */
683
+ declare function useCurrentField<TFieldValue = FieldValue, TField extends Field$1<TFieldValue> | FieldArray$1<TFieldValue> = Field$1<TFieldValue>>(): Field$1<TFieldValue> | FieldArray$1<TFieldValue>;
684
+
685
+ /**
686
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
687
+ * SPDX-License-Identifier: MIT
688
+ */
689
+
690
+ /**
691
+ * Get the current field state. It should be used in a child component of <Field />, otherwise it throws an error
692
+ */
693
+ declare function useCurrentFieldState(): FieldState;
694
+
695
+ /**
696
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
697
+ * SPDX-License-Identifier: MIT
698
+ */
699
+
700
+ type CreateFormOptions<T = any> = FormOptions<T> & {
701
+ /**
702
+ * 为 true 时,createForm 不会对form 初始化, 用户需要手动调用 control.init()
703
+ * 该配置主要为了解决,用户需要去监听一些form 的初始化事件,那么他需要再配置完监听后再初始化。
704
+ * 该配置默认为 false
705
+ **/
706
+ disableAutoInit?: boolean;
707
+ };
708
+ declare function createForm<TValues>(options?: CreateFormOptions<TValues>): CreateFormReturn<TValues>;
709
+
710
+ /**
711
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
712
+ * SPDX-License-Identifier: MIT
713
+ */
714
+ declare namespace Glob {
715
+ const DIVIDER = ".";
716
+ const ALL = "*";
717
+ function isMatch(pattern: string, path: string): boolean;
718
+ /**
719
+ * 判断pattern 是否match pattern 或其parent
720
+ * @param pattern
721
+ * @param path
722
+ */
723
+ function isMatchOrParent(pattern: string, path: string): boolean;
724
+ /**
725
+ * 从 path 中提取出匹配pattern 的 parent path,包括是 path 自身
726
+ * 该方法默认 isMatchOrParent(pattern, path) 为 true, 不做为false 的错误处理。
727
+ * @param pattern
728
+ * @param path
729
+ */
730
+ function getParentPathByPattern(pattern: string, path: string): string;
731
+ /**
732
+ * 找到 obj 在给与 paths 下所有子path
733
+ * @param paths
734
+ * @param obj
735
+ * @private
736
+ */
737
+ function getSubPaths(paths: string[], obj: any): string[];
738
+ /**
739
+ * 将带有通配符的 path pattern 分割。如 a.b.*.c.*.d, 会被分割成['a.b','*','c','*','d']
740
+ * @param pattern
741
+ * @private
742
+ */
743
+ function splitPattern(pattern: string): string[];
744
+ /**
745
+ * Find all paths matched pattern in object. If withEmptyValue is true, it will include
746
+ * paths whoes value is undefined.
747
+ * @param obj
748
+ * @param pattern
749
+ * @param withEmptyValue
750
+ */
751
+ function findMatchPaths(obj: any, pattern: string, withEmptyValue?: boolean): string[];
752
+ /**
753
+ * Find all paths matched pattern in object, including paths whoes value is undefined.
754
+ * @param obj
755
+ * @param pattern
756
+ */
757
+ function findMatchPathsWithEmptyValue(obj: any, pattern: string): string[];
758
+ }
759
+
760
+ declare function toField<TValue>(model: FieldModel): Field$1<TValue>;
761
+ declare function toFieldState(modelState: FieldModelState): {
762
+ readonly isTouched: boolean;
763
+ readonly invalid: boolean;
764
+ readonly isDirty: boolean;
765
+ readonly isValidating: boolean;
766
+ readonly errors: FieldError[] | undefined;
767
+ readonly warnings: FieldWarning[] | undefined;
768
+ };
769
+
770
+ /**
771
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
772
+ * SPDX-License-Identifier: MIT
773
+ */
774
+
775
+ declare function toFieldArray<TValue>(model: FieldArrayModel<TValue>): FieldArray$1<TValue>;
776
+
777
+ /**
778
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
779
+ * SPDX-License-Identifier: MIT
780
+ */
781
+
782
+ declare function toForm<TValue>(model: FormModel): Form$1<TValue>;
783
+ declare function toFormState(modelState: FormModelState): FormState;
784
+
785
+ export { type CreateFormOptions, type Errors, FeedbackLevel, Field, FieldArray, FieldArrayModel, type FieldArrayProps, type FieldArrayRenderProps, type FieldError, FieldModel, type FieldName, type FieldProps, type FieldRenderProps, type FieldState, type FieldValue, type FieldWarning, Form, type FormControl, FormModel, type FormProps, type FormRenderProps, type FormState, type FormValidateReturn, Glob, type Field$1 as IField, type FieldArray$1 as IFieldArray, type Form$1 as IForm, Path, type Validate, ValidateTrigger, type Warnings, createForm, toField, toFieldArray, toFieldState, toForm, toFormState, useCurrentField, useCurrentFieldState, useField, useFieldValidate, useForm, useFormErrors, useFormState, useFormWarnings, useWatch };