@flowgram.ai/form 0.1.0-alpha.3 → 0.1.0-alpha.30

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/index.d.mts CHANGED
@@ -1,11 +1,20 @@
1
- import * as React from 'react';
1
+ import * as React$1 from 'react';
2
2
  import React__default from 'react';
3
3
  import * as _flowgram_ai_utils from '@flowgram.ai/utils';
4
4
  import { MaybePromise, Disposable, Emitter, DisposableCollection } from '@flowgram.ai/utils';
5
5
  import { ReactiveState } from '@flowgram.ai/reactive';
6
6
 
7
+ /**
8
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
9
+ * SPDX-License-Identifier: MIT
10
+ */
7
11
  type Context = any;
8
12
 
13
+ /**
14
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
15
+ * SPDX-License-Identifier: MIT
16
+ */
17
+
9
18
  declare enum FeedbackLevel {
10
19
  Error = "error",
11
20
  Warning = "warning"
@@ -26,7 +35,7 @@ interface Feedback<FeedbackLevel> {
26
35
  /**
27
36
  * Feedback message
28
37
  */
29
- message: string;
38
+ message: string | React.ReactNode;
30
39
  }
31
40
  type FieldError = Feedback<FeedbackLevel.Error>;
32
41
  type FieldWarning = Feedback<FeedbackLevel.Warning>;
@@ -58,6 +67,10 @@ declare enum ValidateTrigger {
58
67
  }
59
68
  type FormValidateReturn = (FieldError | FieldWarning)[];
60
69
 
70
+ /**
71
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
72
+ * SPDX-License-Identifier: MIT
73
+ */
61
74
  declare class Path {
62
75
  protected _path: string[];
63
76
  constructor(path: string | string[]);
@@ -82,11 +95,15 @@ declare class Path {
82
95
  replaceParent(parent: Path, newParent: Path): Path;
83
96
  }
84
97
 
98
+ /**
99
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
100
+ * SPDX-License-Identifier: MIT
101
+ */
102
+
85
103
  declare class Store<TValues = FieldValue> {
86
104
  protected _values: TValues;
87
105
  get values(): TValues;
88
106
  set values(v: TValues);
89
- setInitialValues<TValue = FieldValue>(values: TValues): void;
90
107
  setIn<TValue = FieldValue>(path: Path, value: TValue): void;
91
108
  getIn<TValue = FieldValue>(path: Path): TValue;
92
109
  dispose(): void;
@@ -148,6 +165,7 @@ declare class FieldModel<TValue extends FieldValue = FieldValue> implements Disp
148
165
  updateState(s: Partial<FieldModel>): void;
149
166
  dispose(): void;
150
167
  onDispose(fn: () => void): void;
168
+ get disposed(): boolean;
151
169
  }
152
170
 
153
171
  declare class FieldArrayModel<TValue = FieldValue> extends FieldModel<Array<TValue>> {
@@ -173,13 +191,26 @@ declare class FieldArrayModel<TValue = FieldValue> extends FieldModel<Array<TVal
173
191
  map<T>(cb: (f: FieldModel, index: number, arr: FieldModel[]) => T): T[];
174
192
  append(value?: TValue): FieldModel<any>;
175
193
  /**
176
- * 删除数组项,该操作会删除数组项的值并销毁数组项的Field模型
194
+ * Delete the element in given index and delete the corresponding FieldModel as well
177
195
  * @param index
178
196
  */
179
197
  delete(index: number): void;
180
198
  _splice(start: number, deleteCount?: number): void;
181
199
  swap(from: number, to: number): void;
182
200
  move(from: number, to: number): void;
201
+ protected insertAt(index: number, value: TValue): void;
202
+ /**
203
+ * get element path at given index
204
+ * @param index
205
+ * @protected
206
+ */
207
+ protected getPathAt(index: number): Path;
208
+ /**
209
+ * find all fields including child and grandchild fields at given index.
210
+ * @param index
211
+ * @protected
212
+ */
213
+ protected findAllFieldsAt(index: number): FieldModel<any>[];
183
214
  }
184
215
 
185
216
  declare class FormModel<TValues = any> implements Disposable {
@@ -233,13 +264,20 @@ declare class FormModel<TValues = any> implements Disposable {
233
264
  getValueIn<TValue>(name: FieldName): TValue;
234
265
  setValueIn<TValue>(name: FieldName, value: TValue): void;
235
266
  setInitValueIn<TValue = any>(name: FieldName, value: TValue): void;
267
+ validateDisabled: boolean;
236
268
  clearValueIn(name: FieldName): void;
237
- validateIn(name: FieldName): Promise<string | FormErrorOptions | FormWarningOptions | undefined>;
269
+ validateIn(name: FieldName): Promise<(string | FormErrorOptions | FormWarningOptions | undefined)[] | undefined>;
270
+ protected getValidateOptions(): Record<string, Validate> | undefined;
238
271
  validate(): Promise<FormValidateReturn>;
239
272
  alignStateWithFieldMap(): void;
240
273
  dispose(): void;
241
274
  }
242
275
 
276
+ /**
277
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
278
+ * SPDX-License-Identifier: MIT
279
+ */
280
+
243
281
  interface FormState {
244
282
  /**
245
283
  * If the form data is valid
@@ -282,7 +320,7 @@ interface FormOptions<TValues = any> {
282
320
  /**
283
321
  * 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.
284
322
  */
285
- validate?: Record<string, Validate>;
323
+ validate?: Record<string, Validate> | ((value: TValues, ctx: Context) => Record<string, Validate>);
286
324
  /**
287
325
  * Custom context. It will be accessible via form instance or in validate function.
288
326
  */
@@ -312,6 +350,10 @@ interface Form$1<TValues = any> {
312
350
  * @param name path
313
351
  */
314
352
  setValueIn<TValue>(name: FieldName, value: TValue): void;
353
+ /**
354
+ * Trigger validate for the whole form.
355
+ */
356
+ validate: () => Promise<FormValidateReturn>;
315
357
  }
316
358
  interface FormRenderProps<TValues> {
317
359
  /**
@@ -330,7 +372,7 @@ interface CreateFormReturn<TValues> {
330
372
  control: FormControl<TValues>;
331
373
  }
332
374
  interface OnFormValuesChangeOptions {
333
- action?: 'array-append' | 'array-splice';
375
+ action?: 'array-append' | 'array-splice' | 'array-swap';
334
376
  indexes?: number[];
335
377
  }
336
378
  interface OnFormValuesChangePayload {
@@ -351,6 +393,11 @@ interface OnFormValuesUpdatedPayload {
351
393
  options?: OnFormValuesChangeOptions;
352
394
  }
353
395
 
396
+ /**
397
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
398
+ * SPDX-License-Identifier: MIT
399
+ */
400
+
354
401
  type FieldValue = any;
355
402
  type FieldName = string;
356
403
  type CustomElement = Partial<HTMLElement> & {
@@ -404,17 +451,23 @@ interface FieldArray$1<TFieldValue extends FieldValue = FieldValue> extends Fiel
404
451
  * Same as native Array.map, the first param of the callback function is the child field of this FieldArray.
405
452
  * @param cb callback function
406
453
  */
407
- map: <T = any>(cb: (f: Field$1, index: number) => T) => T[];
454
+ map: <T = any>(cb: (f: Field$1<TFieldValue>, index: number) => T) => T[];
408
455
  /**
409
456
  * Append a value at the end of the array, it will create a new Field for this value as well.
410
457
  * @param value the value to append
411
458
  */
412
459
  append: (value: TFieldValue) => Field$1<TFieldValue>;
413
460
  /**
461
+ * @deprecated use remove instead
414
462
  * Delete the value and the related field at certain index of the array.
415
463
  * @param index the index of the element to delete
416
464
  */
417
465
  delete: (index: number) => void;
466
+ /**
467
+ * Delete the value and the related field at certain index of the array.
468
+ * @param index the index of the element to delete
469
+ */
470
+ remove: (index: number) => void;
418
471
  /**
419
472
  * Move an array element from one position to another.
420
473
  * @param from from position
@@ -505,11 +558,16 @@ interface FieldModelState extends Omit<FieldState, 'errors' | 'warnings'> {
505
558
  warnings?: Warnings;
506
559
  }
507
560
 
561
+ /**
562
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
563
+ * SPDX-License-Identifier: MIT
564
+ */
565
+
508
566
  type FieldProps<TValue> = FieldOptions<TValue> & {
509
567
  /**
510
568
  * A React element or a render prop
511
569
  */
512
- children?: ((props: FieldRenderProps<TValue>) => React.ReactElement) | React.ReactElement;
570
+ children?: ((props: FieldRenderProps<TValue>) => React$1.ReactElement) | React$1.ReactElement;
513
571
  /**
514
572
  * 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
515
573
  */
@@ -518,7 +576,12 @@ type FieldProps<TValue> = FieldOptions<TValue> & {
518
576
  /**
519
577
  * 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
520
578
  */
521
- declare function Field<TValue>({ name, defaultValue, render, children, deps, }: FieldProps<TValue>): React.ReactElement;
579
+ declare function Field<TValue>({ name, defaultValue, render, children, deps, }: FieldProps<TValue>): React$1.ReactElement;
580
+
581
+ /**
582
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
583
+ * SPDX-License-Identifier: MIT
584
+ */
522
585
 
523
586
  type FormProps<TValues> = FormOptions & {
524
587
  /**
@@ -542,22 +605,37 @@ type FormProps<TValues> = FormOptions & {
542
605
  */
543
606
  declare function Form<TValues>(props: FormProps<TValues>): React__default.JSX.Element;
544
607
 
608
+ /**
609
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
610
+ * SPDX-License-Identifier: MIT
611
+ */
612
+
545
613
  /**
546
614
  * Get Form instance. It should be use in a child component of <Form />
547
615
  */
548
616
  declare function useForm(): Form$1;
549
617
 
618
+ /**
619
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
620
+ * SPDX-License-Identifier: MIT
621
+ */
622
+
550
623
  /**
551
624
  * Listen to the field data change and refresh the React component.
552
625
  * @param name the field's uniq name (path)
553
626
  */
554
627
  declare function useWatch<TValue = FieldValue>(name: FieldName): TValue;
555
628
 
629
+ /**
630
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
631
+ * SPDX-License-Identifier: MIT
632
+ */
633
+
556
634
  type FieldArrayProps<TValue> = FieldArrayOptions<TValue> & {
557
635
  /**
558
636
  * A React element or a render prop
559
637
  */
560
- children?: ((props: FieldArrayRenderProps<TValue>) => React.ReactElement) | React.ReactElement;
638
+ children?: ((props: FieldArrayRenderProps<TValue>) => React$1.ReactElement) | React$1.ReactElement;
561
639
  /**
562
640
  * 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
563
641
  */
@@ -566,7 +644,12 @@ type FieldArrayProps<TValue> = FieldArrayOptions<TValue> & {
566
644
  /**
567
645
  * 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
568
646
  */
569
- declare function FieldArray<TValue extends FieldValue>({ name, defaultValue, deps, render, children, }: FieldArrayProps<TValue>): React.ReactElement;
647
+ declare function FieldArray<TValue extends FieldValue>({ name, defaultValue, deps, render, children, }: FieldArrayProps<TValue>): React$1.ReactElement;
648
+
649
+ /**
650
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
651
+ * SPDX-License-Identifier: MIT
652
+ */
570
653
 
571
654
  /**
572
655
  * @deprecated
@@ -580,6 +663,11 @@ declare function useFormState(control?: FormControl<any> | Form$1): FormState;
580
663
  declare function useFormErrors(control?: FormControl<any> | Form$1): Errors | undefined;
581
664
  declare function useFormWarnings(control?: FormControl<any> | Form$1): Warnings | undefined;
582
665
 
666
+ /**
667
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
668
+ * SPDX-License-Identifier: MIT
669
+ */
670
+
583
671
  /**
584
672
  * Get validate method of a field with given name. the returned function could possibly do nothing if the field is not found.
585
673
  * The reason could be that the field is not rendered yet or the name given is wrong.
@@ -587,17 +675,32 @@ declare function useFormWarnings(control?: FormControl<any> | Form$1): Warnings
587
675
  */
588
676
  declare function useFieldValidate(name?: FieldName): () => void;
589
677
 
678
+ /**
679
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
680
+ * SPDX-License-Identifier: MIT
681
+ */
682
+
590
683
  /**
591
684
  * Get the current Field. It should be used in a child component of <Field />, otherwise it throws an error
592
685
  */
593
686
  declare function useCurrentField<TFieldValue = FieldValue, TField extends Field$1<TFieldValue> | FieldArray$1<TFieldValue> = Field$1<TFieldValue>>(): Field$1<TFieldValue> | FieldArray$1<TFieldValue>;
594
687
 
688
+ /**
689
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
690
+ * SPDX-License-Identifier: MIT
691
+ */
692
+
595
693
  /**
596
694
  * Get the current field state. It should be used in a child component of <Field />, otherwise it throws an error
597
695
  */
598
696
  declare function useCurrentFieldState(): FieldState;
599
697
 
600
- type CreateFormOptions = FormOptions & {
698
+ /**
699
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
700
+ * SPDX-License-Identifier: MIT
701
+ */
702
+
703
+ type CreateFormOptions<T = any> = FormOptions<T> & {
601
704
  /**
602
705
  * 为 true 时,createForm 不会对form 初始化, 用户需要手动调用 control.init()
603
706
  * 该配置主要为了解决,用户需要去监听一些form 的初始化事件,那么他需要再配置完监听后再初始化。
@@ -605,8 +708,12 @@ type CreateFormOptions = FormOptions & {
605
708
  **/
606
709
  disableAutoInit?: boolean;
607
710
  };
608
- declare function createForm<TValues>(options?: CreateFormOptions): CreateFormReturn<TValues>;
711
+ declare function createForm<TValues>(options?: CreateFormOptions<TValues>): CreateFormReturn<TValues>;
609
712
 
713
+ /**
714
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
715
+ * SPDX-License-Identifier: MIT
716
+ */
610
717
  declare namespace Glob {
611
718
  const DIVIDER = ".";
612
719
  const ALL = "*";
@@ -663,9 +770,19 @@ declare function toFieldState(modelState: FieldModelState): {
663
770
  readonly warnings: FieldWarning[] | undefined;
664
771
  };
665
772
 
773
+ /**
774
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
775
+ * SPDX-License-Identifier: MIT
776
+ */
777
+
666
778
  declare function toFieldArray<TValue>(model: FieldArrayModel<TValue>): FieldArray$1<TValue>;
667
779
 
780
+ /**
781
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
782
+ * SPDX-License-Identifier: MIT
783
+ */
784
+
668
785
  declare function toForm<TValue>(model: FormModel): Form$1<TValue>;
669
786
  declare function toFormState(modelState: FormModelState): FormState;
670
787
 
671
- export { type Errors, 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 };
788
+ 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 };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,20 @@
1
- import * as React from 'react';
1
+ import * as React$1 from 'react';
2
2
  import React__default from 'react';
3
3
  import * as _flowgram_ai_utils from '@flowgram.ai/utils';
4
4
  import { MaybePromise, Disposable, Emitter, DisposableCollection } from '@flowgram.ai/utils';
5
5
  import { ReactiveState } from '@flowgram.ai/reactive';
6
6
 
7
+ /**
8
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
9
+ * SPDX-License-Identifier: MIT
10
+ */
7
11
  type Context = any;
8
12
 
13
+ /**
14
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
15
+ * SPDX-License-Identifier: MIT
16
+ */
17
+
9
18
  declare enum FeedbackLevel {
10
19
  Error = "error",
11
20
  Warning = "warning"
@@ -26,7 +35,7 @@ interface Feedback<FeedbackLevel> {
26
35
  /**
27
36
  * Feedback message
28
37
  */
29
- message: string;
38
+ message: string | React.ReactNode;
30
39
  }
31
40
  type FieldError = Feedback<FeedbackLevel.Error>;
32
41
  type FieldWarning = Feedback<FeedbackLevel.Warning>;
@@ -58,6 +67,10 @@ declare enum ValidateTrigger {
58
67
  }
59
68
  type FormValidateReturn = (FieldError | FieldWarning)[];
60
69
 
70
+ /**
71
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
72
+ * SPDX-License-Identifier: MIT
73
+ */
61
74
  declare class Path {
62
75
  protected _path: string[];
63
76
  constructor(path: string | string[]);
@@ -82,11 +95,15 @@ declare class Path {
82
95
  replaceParent(parent: Path, newParent: Path): Path;
83
96
  }
84
97
 
98
+ /**
99
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
100
+ * SPDX-License-Identifier: MIT
101
+ */
102
+
85
103
  declare class Store<TValues = FieldValue> {
86
104
  protected _values: TValues;
87
105
  get values(): TValues;
88
106
  set values(v: TValues);
89
- setInitialValues<TValue = FieldValue>(values: TValues): void;
90
107
  setIn<TValue = FieldValue>(path: Path, value: TValue): void;
91
108
  getIn<TValue = FieldValue>(path: Path): TValue;
92
109
  dispose(): void;
@@ -148,6 +165,7 @@ declare class FieldModel<TValue extends FieldValue = FieldValue> implements Disp
148
165
  updateState(s: Partial<FieldModel>): void;
149
166
  dispose(): void;
150
167
  onDispose(fn: () => void): void;
168
+ get disposed(): boolean;
151
169
  }
152
170
 
153
171
  declare class FieldArrayModel<TValue = FieldValue> extends FieldModel<Array<TValue>> {
@@ -173,13 +191,26 @@ declare class FieldArrayModel<TValue = FieldValue> extends FieldModel<Array<TVal
173
191
  map<T>(cb: (f: FieldModel, index: number, arr: FieldModel[]) => T): T[];
174
192
  append(value?: TValue): FieldModel<any>;
175
193
  /**
176
- * 删除数组项,该操作会删除数组项的值并销毁数组项的Field模型
194
+ * Delete the element in given index and delete the corresponding FieldModel as well
177
195
  * @param index
178
196
  */
179
197
  delete(index: number): void;
180
198
  _splice(start: number, deleteCount?: number): void;
181
199
  swap(from: number, to: number): void;
182
200
  move(from: number, to: number): void;
201
+ protected insertAt(index: number, value: TValue): void;
202
+ /**
203
+ * get element path at given index
204
+ * @param index
205
+ * @protected
206
+ */
207
+ protected getPathAt(index: number): Path;
208
+ /**
209
+ * find all fields including child and grandchild fields at given index.
210
+ * @param index
211
+ * @protected
212
+ */
213
+ protected findAllFieldsAt(index: number): FieldModel<any>[];
183
214
  }
184
215
 
185
216
  declare class FormModel<TValues = any> implements Disposable {
@@ -233,13 +264,20 @@ declare class FormModel<TValues = any> implements Disposable {
233
264
  getValueIn<TValue>(name: FieldName): TValue;
234
265
  setValueIn<TValue>(name: FieldName, value: TValue): void;
235
266
  setInitValueIn<TValue = any>(name: FieldName, value: TValue): void;
267
+ validateDisabled: boolean;
236
268
  clearValueIn(name: FieldName): void;
237
- validateIn(name: FieldName): Promise<string | FormErrorOptions | FormWarningOptions | undefined>;
269
+ validateIn(name: FieldName): Promise<(string | FormErrorOptions | FormWarningOptions | undefined)[] | undefined>;
270
+ protected getValidateOptions(): Record<string, Validate> | undefined;
238
271
  validate(): Promise<FormValidateReturn>;
239
272
  alignStateWithFieldMap(): void;
240
273
  dispose(): void;
241
274
  }
242
275
 
276
+ /**
277
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
278
+ * SPDX-License-Identifier: MIT
279
+ */
280
+
243
281
  interface FormState {
244
282
  /**
245
283
  * If the form data is valid
@@ -282,7 +320,7 @@ interface FormOptions<TValues = any> {
282
320
  /**
283
321
  * 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.
284
322
  */
285
- validate?: Record<string, Validate>;
323
+ validate?: Record<string, Validate> | ((value: TValues, ctx: Context) => Record<string, Validate>);
286
324
  /**
287
325
  * Custom context. It will be accessible via form instance or in validate function.
288
326
  */
@@ -312,6 +350,10 @@ interface Form$1<TValues = any> {
312
350
  * @param name path
313
351
  */
314
352
  setValueIn<TValue>(name: FieldName, value: TValue): void;
353
+ /**
354
+ * Trigger validate for the whole form.
355
+ */
356
+ validate: () => Promise<FormValidateReturn>;
315
357
  }
316
358
  interface FormRenderProps<TValues> {
317
359
  /**
@@ -330,7 +372,7 @@ interface CreateFormReturn<TValues> {
330
372
  control: FormControl<TValues>;
331
373
  }
332
374
  interface OnFormValuesChangeOptions {
333
- action?: 'array-append' | 'array-splice';
375
+ action?: 'array-append' | 'array-splice' | 'array-swap';
334
376
  indexes?: number[];
335
377
  }
336
378
  interface OnFormValuesChangePayload {
@@ -351,6 +393,11 @@ interface OnFormValuesUpdatedPayload {
351
393
  options?: OnFormValuesChangeOptions;
352
394
  }
353
395
 
396
+ /**
397
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
398
+ * SPDX-License-Identifier: MIT
399
+ */
400
+
354
401
  type FieldValue = any;
355
402
  type FieldName = string;
356
403
  type CustomElement = Partial<HTMLElement> & {
@@ -404,17 +451,23 @@ interface FieldArray$1<TFieldValue extends FieldValue = FieldValue> extends Fiel
404
451
  * Same as native Array.map, the first param of the callback function is the child field of this FieldArray.
405
452
  * @param cb callback function
406
453
  */
407
- map: <T = any>(cb: (f: Field$1, index: number) => T) => T[];
454
+ map: <T = any>(cb: (f: Field$1<TFieldValue>, index: number) => T) => T[];
408
455
  /**
409
456
  * Append a value at the end of the array, it will create a new Field for this value as well.
410
457
  * @param value the value to append
411
458
  */
412
459
  append: (value: TFieldValue) => Field$1<TFieldValue>;
413
460
  /**
461
+ * @deprecated use remove instead
414
462
  * Delete the value and the related field at certain index of the array.
415
463
  * @param index the index of the element to delete
416
464
  */
417
465
  delete: (index: number) => void;
466
+ /**
467
+ * Delete the value and the related field at certain index of the array.
468
+ * @param index the index of the element to delete
469
+ */
470
+ remove: (index: number) => void;
418
471
  /**
419
472
  * Move an array element from one position to another.
420
473
  * @param from from position
@@ -505,11 +558,16 @@ interface FieldModelState extends Omit<FieldState, 'errors' | 'warnings'> {
505
558
  warnings?: Warnings;
506
559
  }
507
560
 
561
+ /**
562
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
563
+ * SPDX-License-Identifier: MIT
564
+ */
565
+
508
566
  type FieldProps<TValue> = FieldOptions<TValue> & {
509
567
  /**
510
568
  * A React element or a render prop
511
569
  */
512
- children?: ((props: FieldRenderProps<TValue>) => React.ReactElement) | React.ReactElement;
570
+ children?: ((props: FieldRenderProps<TValue>) => React$1.ReactElement) | React$1.ReactElement;
513
571
  /**
514
572
  * 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
515
573
  */
@@ -518,7 +576,12 @@ type FieldProps<TValue> = FieldOptions<TValue> & {
518
576
  /**
519
577
  * 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
520
578
  */
521
- declare function Field<TValue>({ name, defaultValue, render, children, deps, }: FieldProps<TValue>): React.ReactElement;
579
+ declare function Field<TValue>({ name, defaultValue, render, children, deps, }: FieldProps<TValue>): React$1.ReactElement;
580
+
581
+ /**
582
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
583
+ * SPDX-License-Identifier: MIT
584
+ */
522
585
 
523
586
  type FormProps<TValues> = FormOptions & {
524
587
  /**
@@ -542,22 +605,37 @@ type FormProps<TValues> = FormOptions & {
542
605
  */
543
606
  declare function Form<TValues>(props: FormProps<TValues>): React__default.JSX.Element;
544
607
 
608
+ /**
609
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
610
+ * SPDX-License-Identifier: MIT
611
+ */
612
+
545
613
  /**
546
614
  * Get Form instance. It should be use in a child component of <Form />
547
615
  */
548
616
  declare function useForm(): Form$1;
549
617
 
618
+ /**
619
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
620
+ * SPDX-License-Identifier: MIT
621
+ */
622
+
550
623
  /**
551
624
  * Listen to the field data change and refresh the React component.
552
625
  * @param name the field's uniq name (path)
553
626
  */
554
627
  declare function useWatch<TValue = FieldValue>(name: FieldName): TValue;
555
628
 
629
+ /**
630
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
631
+ * SPDX-License-Identifier: MIT
632
+ */
633
+
556
634
  type FieldArrayProps<TValue> = FieldArrayOptions<TValue> & {
557
635
  /**
558
636
  * A React element or a render prop
559
637
  */
560
- children?: ((props: FieldArrayRenderProps<TValue>) => React.ReactElement) | React.ReactElement;
638
+ children?: ((props: FieldArrayRenderProps<TValue>) => React$1.ReactElement) | React$1.ReactElement;
561
639
  /**
562
640
  * 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
563
641
  */
@@ -566,7 +644,12 @@ type FieldArrayProps<TValue> = FieldArrayOptions<TValue> & {
566
644
  /**
567
645
  * 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
568
646
  */
569
- declare function FieldArray<TValue extends FieldValue>({ name, defaultValue, deps, render, children, }: FieldArrayProps<TValue>): React.ReactElement;
647
+ declare function FieldArray<TValue extends FieldValue>({ name, defaultValue, deps, render, children, }: FieldArrayProps<TValue>): React$1.ReactElement;
648
+
649
+ /**
650
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
651
+ * SPDX-License-Identifier: MIT
652
+ */
570
653
 
571
654
  /**
572
655
  * @deprecated
@@ -580,6 +663,11 @@ declare function useFormState(control?: FormControl<any> | Form$1): FormState;
580
663
  declare function useFormErrors(control?: FormControl<any> | Form$1): Errors | undefined;
581
664
  declare function useFormWarnings(control?: FormControl<any> | Form$1): Warnings | undefined;
582
665
 
666
+ /**
667
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
668
+ * SPDX-License-Identifier: MIT
669
+ */
670
+
583
671
  /**
584
672
  * Get validate method of a field with given name. the returned function could possibly do nothing if the field is not found.
585
673
  * The reason could be that the field is not rendered yet or the name given is wrong.
@@ -587,17 +675,32 @@ declare function useFormWarnings(control?: FormControl<any> | Form$1): Warnings
587
675
  */
588
676
  declare function useFieldValidate(name?: FieldName): () => void;
589
677
 
678
+ /**
679
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
680
+ * SPDX-License-Identifier: MIT
681
+ */
682
+
590
683
  /**
591
684
  * Get the current Field. It should be used in a child component of <Field />, otherwise it throws an error
592
685
  */
593
686
  declare function useCurrentField<TFieldValue = FieldValue, TField extends Field$1<TFieldValue> | FieldArray$1<TFieldValue> = Field$1<TFieldValue>>(): Field$1<TFieldValue> | FieldArray$1<TFieldValue>;
594
687
 
688
+ /**
689
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
690
+ * SPDX-License-Identifier: MIT
691
+ */
692
+
595
693
  /**
596
694
  * Get the current field state. It should be used in a child component of <Field />, otherwise it throws an error
597
695
  */
598
696
  declare function useCurrentFieldState(): FieldState;
599
697
 
600
- type CreateFormOptions = FormOptions & {
698
+ /**
699
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
700
+ * SPDX-License-Identifier: MIT
701
+ */
702
+
703
+ type CreateFormOptions<T = any> = FormOptions<T> & {
601
704
  /**
602
705
  * 为 true 时,createForm 不会对form 初始化, 用户需要手动调用 control.init()
603
706
  * 该配置主要为了解决,用户需要去监听一些form 的初始化事件,那么他需要再配置完监听后再初始化。
@@ -605,8 +708,12 @@ type CreateFormOptions = FormOptions & {
605
708
  **/
606
709
  disableAutoInit?: boolean;
607
710
  };
608
- declare function createForm<TValues>(options?: CreateFormOptions): CreateFormReturn<TValues>;
711
+ declare function createForm<TValues>(options?: CreateFormOptions<TValues>): CreateFormReturn<TValues>;
609
712
 
713
+ /**
714
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
715
+ * SPDX-License-Identifier: MIT
716
+ */
610
717
  declare namespace Glob {
611
718
  const DIVIDER = ".";
612
719
  const ALL = "*";
@@ -663,9 +770,19 @@ declare function toFieldState(modelState: FieldModelState): {
663
770
  readonly warnings: FieldWarning[] | undefined;
664
771
  };
665
772
 
773
+ /**
774
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
775
+ * SPDX-License-Identifier: MIT
776
+ */
777
+
666
778
  declare function toFieldArray<TValue>(model: FieldArrayModel<TValue>): FieldArray$1<TValue>;
667
779
 
780
+ /**
781
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
782
+ * SPDX-License-Identifier: MIT
783
+ */
784
+
668
785
  declare function toForm<TValue>(model: FormModel): Form$1<TValue>;
669
786
  declare function toFormState(modelState: FormModelState): FormState;
670
787
 
671
- export { type Errors, 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 };
788
+ 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 };