@flowgram.ai/form 0.1.17 → 0.1.21

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.ts CHANGED
@@ -247,7 +247,7 @@ declare class FormModel<TValues = any> implements Disposable {
247
247
  setValueIn<TValue>(name: FieldName, value: TValue): void;
248
248
  setInitValueIn<TValue = any>(name: FieldName, value: TValue): void;
249
249
  clearValueIn(name: FieldName): void;
250
- validateIn(name: FieldName): Promise<string | FormErrorOptions | FormWarningOptions | undefined>;
250
+ validateIn(name: FieldName): Promise<(string | FormErrorOptions | FormWarningOptions | undefined)[] | undefined>;
251
251
  validate(): Promise<FormValidateReturn>;
252
252
  alignStateWithFieldMap(): void;
253
253
  dispose(): void;
@@ -620,7 +620,7 @@ declare function useCurrentField<TFieldValue = FieldValue, TField extends Field$
620
620
  */
621
621
  declare function useCurrentFieldState(): FieldState;
622
622
 
623
- type CreateFormOptions = FormOptions & {
623
+ type CreateFormOptions<T = any> = FormOptions<T> & {
624
624
  /**
625
625
  * 为 true 时,createForm 不会对form 初始化, 用户需要手动调用 control.init()
626
626
  * 该配置主要为了解决,用户需要去监听一些form 的初始化事件,那么他需要再配置完监听后再初始化。
@@ -628,7 +628,7 @@ type CreateFormOptions = FormOptions & {
628
628
  **/
629
629
  disableAutoInit?: boolean;
630
630
  };
631
- declare function createForm<TValues>(options?: CreateFormOptions): CreateFormReturn<TValues>;
631
+ declare function createForm<TValues>(options?: CreateFormOptions<TValues>): CreateFormReturn<TValues>;
632
632
 
633
633
  declare namespace Glob {
634
634
  const DIVIDER = ".";
@@ -691,4 +691,4 @@ declare function toFieldArray<TValue>(model: FieldArrayModel<TValue>): FieldArra
691
691
  declare function toForm<TValue>(model: FormModel): Form$1<TValue>;
692
692
  declare function toFormState(modelState: FormModelState): FormState;
693
693
 
694
- 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 };
694
+ export { type CreateFormOptions, 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 };
package/dist/index.js CHANGED
@@ -253,18 +253,15 @@ var Glob;
253
253
  }
254
254
  Glob2.findMatchPaths = findMatchPaths;
255
255
  function findMatchPathsWithEmptyValue(obj, pattern) {
256
+ if (!pattern.includes("*")) {
257
+ return [pattern];
258
+ }
256
259
  return findMatchPaths(obj, pattern, true);
257
260
  }
258
261
  Glob2.findMatchPathsWithEmptyValue = findMatchPathsWithEmptyValue;
259
262
  })(Glob || (Glob = {}));
260
263
 
261
264
  // src/types/validate.ts
262
- function isFieldWarning(f) {
263
- if (f.level === "warning" /* Warning */) {
264
- return true;
265
- }
266
- return false;
267
- }
268
265
  var ValidateTrigger = /* @__PURE__ */ ((ValidateTrigger2) => {
269
266
  ValidateTrigger2["onChange"] = "onChange";
270
267
  ValidateTrigger2["onBlur"] = "onBlur";
@@ -983,21 +980,19 @@ var FieldModel = class {
983
980
  this.form.onValidateEmitter.fire(this.form.state);
984
981
  }
985
982
  async _runAsyncValidate() {
986
- const errors = [];
987
- const warnings = [];
988
- const result = await this.form.validateIn(this.name);
989
- if (!result) {
983
+ let errors = [];
984
+ let warnings = [];
985
+ const results = await this.form.validateIn(this.name);
986
+ if (!results?.length) {
990
987
  return {};
991
988
  } else {
992
- const feedback = toFeedback(result, this.name);
993
- if (!feedback) {
989
+ const feedbacks = results.map((result) => toFeedback(result, this.name)).filter(Boolean);
990
+ if (!feedbacks?.length) {
994
991
  return {};
995
992
  }
996
- if (isFieldWarning(feedback)) {
997
- warnings.push(feedback);
998
- } else {
999
- errors.push(feedback);
1000
- }
993
+ const groupedFeedbacks = (0, import_lodash7.groupBy)(feedbacks, "level");
994
+ warnings = warnings.concat(groupedFeedbacks["warning" /* Warning */]);
995
+ errors = errors.concat(groupedFeedbacks["error" /* Error */]);
1001
996
  }
1002
997
  return { errors, warnings };
1003
998
  }
@@ -1416,10 +1411,10 @@ var FormModel = class {
1416
1411
  if (!this._options.validate) {
1417
1412
  return;
1418
1413
  }
1419
- const validateKey = Object.keys(this._options.validate).find(
1414
+ const validateKeys = Object.keys(this._options.validate).filter(
1420
1415
  (pattern) => Glob.isMatch(pattern, name)
1421
1416
  );
1422
- if (validateKey) {
1417
+ const validatePromises = validateKeys.map(async (validateKey) => {
1423
1418
  const validate = this._options.validate[validateKey];
1424
1419
  return validate({
1425
1420
  value: this.getValueIn(name),
@@ -1427,7 +1422,8 @@ var FormModel = class {
1427
1422
  context: this.context,
1428
1423
  name
1429
1424
  });
1430
- }
1425
+ });
1426
+ return Promise.all(validatePromises);
1431
1427
  }
1432
1428
  async validate() {
1433
1429
  if (!this._options.validate) {