vft 0.0.340 → 0.0.342

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.
@@ -7,7 +7,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
7
7
  /**
8
8
  * @description Validate the whole form. Receives a callback or returns `Promise`.
9
9
  */
10
- validate: (callback?: FormValidateCallback) => FormValidationResult;
10
+ validate: (callback?: FormValidateCallback, props?: Arrayable<FormItemProp>) => FormValidationResult;
11
11
  /**
12
12
  * @description Validate specified fields.
13
13
  */
@@ -61,32 +61,32 @@ const H = b({
61
61
  if (l.length === 0) return [];
62
62
  const t = f(l, e);
63
63
  return t.length ? t : (n(i.b(), "please pass correct props!"), []);
64
- }, h = async (e) => c(void 0, e), R = async (e = []) => {
64
+ }, h = async (e, t) => c(t || void 0, e), R = async (e = []) => {
65
65
  if (!k.value) return !1;
66
66
  const t = P(e);
67
67
  if (t.length === 0) return !0;
68
68
  let r = {};
69
- for (const s of t)
69
+ for (const a of t)
70
70
  try {
71
- await s.validate(""), s.validateState === "error" && s.resetField();
72
- } catch (a) {
71
+ await a.validate(""), a.validateState === "error" && a.resetField();
72
+ } catch (s) {
73
73
  r = {
74
74
  ...r,
75
- ...a
75
+ ...s
76
76
  };
77
77
  }
78
78
  return Object.keys(r).length === 0 ? !0 : Promise.reject(r);
79
79
  }, c = async (e = [], t) => {
80
80
  let r = !1;
81
- const s = !K(t);
81
+ const a = !K(t);
82
82
  try {
83
83
  return r = await R(e), r === !0 && await t?.(r), o.model;
84
- } catch (a) {
85
- if (a instanceof Error) throw a;
86
- const v = a;
84
+ } catch (s) {
85
+ if (s instanceof Error) throw s;
86
+ const v = s;
87
87
  return o.scrollToError && d.value && d.value.querySelector(
88
88
  `.${i.b()}-item.is-error`
89
- )?.scrollIntoView(o.scrollIntoViewOptions), !r && await t?.(!1, v), s && Promise.reject(v);
89
+ )?.scrollIntoView(o.scrollIntoViewOptions), console.error(s), !r && await t?.(!1, v), a && Promise.reject(v);
90
90
  }
91
91
  }, S = (e) => {
92
92
  const t = u(e);
@@ -53,7 +53,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
53
53
  }>> & Readonly<{
54
54
  onValidate?: ((...args: any[]) => any) | undefined;
55
55
  }>, {
56
- validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
56
+ validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
57
57
  validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
58
58
  resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
59
59
  clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
@@ -119,7 +119,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
119
119
  }>> & Readonly<{
120
120
  onValidate?: ((...args: any[]) => any) | undefined;
121
121
  }>, {
122
- validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
122
+ validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
123
123
  validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
124
124
  resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
125
125
  clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
@@ -180,7 +180,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
180
180
  }>> & Readonly<{
181
181
  onValidate?: ((...args: any[]) => any) | undefined;
182
182
  }>, {
183
- validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
183
+ validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
184
184
  validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
185
185
  resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
186
186
  clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
@@ -79,7 +79,7 @@ export interface FormActionType {
79
79
  /** 验证指定字段 */
80
80
  validateField: (nameList?: NamePath[]) => Promise<any>;
81
81
  /** 验证表单 */
82
- validate: (nameList?: NamePath[]) => Promise<any>;
82
+ validate: (callback?: Function, nameList?: NamePath[]) => Promise<any>;
83
83
  /** 滚动到指定字段 */
84
84
  scrollToField: (name: NamePath, options?: ScrollOptions) => Promise<void>;
85
85
  /** 设置表单项错误信息 */
@@ -1,20 +1,20 @@
1
- import { isDef as G, isFunction as j, isString as A, isObject as V, isArray as I, deepMerge as it, findDifferentValuesForObj as nt, isNullOrUndefined as H, isEmpty as lt, isEmptyObject as st } from "@vft/utils";
1
+ import { isDef as G, isFunction as j, isString as A, isObject as V, isArray as I, deepMerge as it, findDifferentValuesForObj as nt, isNullOrUndefined as H, isEmpty as rt, isEmptyObject as lt } from "@vft/utils";
2
2
  import { formatToDate as J } from "@vft/utils/date";
3
- import { get as rt, cloneDeep as O, uniqBy as ot, isEqual as ct, set as W } from "lodash-es";
3
+ import { get as st, cloneDeep as O, uniqBy as ot, isEqual as ft, set as W } from "lodash-es";
4
4
  import { unref as n, toRaw as S, nextTick as P } from "vue";
5
- import { isInput as ft, FormCompEnum as x, isDatePicker as at } from "../component-map.js";
5
+ import { isInput as ct, FormCompEnum as x, isDatePicker as at } from "../component-map.js";
6
6
  import { handleInputNumberValue as ut } from "./helper.js";
7
7
  function Q(h, y) {
8
- const { show: r, ifShow: c } = h;
8
+ const { show: s, ifShow: f } = h;
9
9
  let p = !0, a = !0;
10
- return typeof r == "boolean" ? p = r : typeof r == "function" && (p = r({
10
+ return typeof s == "boolean" ? p = s : typeof s == "function" && (p = s({
11
11
  field: h.field,
12
12
  model: y,
13
13
  values: {
14
14
  ...y
15
15
  },
16
16
  schema: h
17
- })), typeof c == "boolean" ? a = c : typeof c == "function" && (a = c({
17
+ })), typeof f == "boolean" ? a = f : typeof f == "function" && (a = f({
18
18
  field: h.field,
19
19
  model: y,
20
20
  values: {
@@ -24,11 +24,11 @@ function Q(h, y) {
24
24
  })), p && a;
25
25
  }
26
26
  function dt(h, y = {}) {
27
- const r = /^\[(.+)\]$/;
28
- if (r.test(h)) {
29
- const c = h.match(r);
30
- if (c && c[1]) {
31
- const p = c[1].split(",");
27
+ const s = /^\[(.+)\]$/;
28
+ if (s.test(h)) {
29
+ const f = h.match(s);
30
+ if (f && f[1]) {
31
+ const p = f[1].split(",");
32
32
  if (!p.length)
33
33
  return;
34
34
  const a = [];
@@ -39,11 +39,11 @@ function dt(h, y = {}) {
39
39
  }
40
40
  }
41
41
  function ht(h, y = {}) {
42
- const r = /^\{(.+)\}$/;
43
- if (r.test(h)) {
44
- const c = h.match(r);
45
- if (c && c[1]) {
46
- const p = c[1].split(",");
42
+ const s = /^\{(.+)\}$/;
43
+ if (s.test(h)) {
44
+ const f = h.match(s);
45
+ if (f && f[1]) {
46
+ const p = f[1].split(",");
47
47
  if (!p.length)
48
48
  return;
49
49
  const a = {};
@@ -56,8 +56,8 @@ function ht(h, y = {}) {
56
56
  function Dt({
57
57
  emit: h,
58
58
  getProps: y,
59
- formModel: r,
60
- getSchema: c,
59
+ formModel: s,
60
+ getSchema: f,
61
61
  defaultValueRef: p,
62
62
  formElRef: a,
63
63
  schemaRef: v,
@@ -65,30 +65,30 @@ function Dt({
65
65
  initValues: _
66
66
  }) {
67
67
  async function X(t) {
68
- const { resetFunc: i, submitOnReset: s } = n(y);
68
+ const { resetFunc: i, submitOnReset: l } = n(y);
69
69
  i && j(i) && await i();
70
- const l = n(a);
71
- if (l) {
70
+ const r = n(a);
71
+ if (r) {
72
72
  if (t?.length)
73
- return l.resetFields(t);
74
- Object.keys(r).forEach((f) => {
75
- const o = n(c).find((u) => u.field === f), e = O(p.value[f]);
76
- r[f] = ft(o?.type) ? e || "" : e;
77
- }), P(() => B()), h("reset", S(r)), s && await $();
73
+ return r.resetFields(t);
74
+ Object.keys(s).forEach((c) => {
75
+ const o = n(f).find((u) => u.field === c), e = O(p.value[c]);
76
+ s[c] = ct(o?.type) ? e || "" : e;
77
+ }), P(() => B()), h("reset", S(s)), l && await $();
78
78
  }
79
79
  }
80
80
  async function m(t, i = !0) {
81
- const s = n(c).map((e) => e.field).filter(Boolean), l = ".", f = s.filter(
82
- (e) => String(e).indexOf(l) >= 0
81
+ const l = n(f).map((e) => e.field).filter(Boolean), r = ".", c = l.filter(
82
+ (e) => String(e).indexOf(r) >= 0
83
83
  ), o = [];
84
- s.forEach((e) => {
85
- const u = n(c).find((d) => d.field === e);
86
- let b = rt(t, e);
84
+ l.forEach((e) => {
85
+ const u = n(f).find((d) => d.field === e);
86
+ let b = st(t, e);
87
87
  const C = Reflect.has(t, e);
88
88
  b = ut(u?.type, b);
89
89
  const { componentProps: U } = u || {};
90
90
  let w = U;
91
- typeof U == "function" && (w = w({ formModel: n(r) }));
91
+ typeof U == "function" && (w = w({ formModel: n(s) }));
92
92
  const z = dt(e, t) || ht(e, t);
93
93
  if (C || z) {
94
94
  const d = z || b;
@@ -97,19 +97,19 @@ function Dt({
97
97
  const F = [];
98
98
  for (const E of d)
99
99
  F.push(E ? J(E) : null);
100
- n(r)[e] = F;
100
+ n(s)[e] = F;
101
101
  } else
102
- n(r)[e] = d ? w?.valueFormat ? d : J(d) : null;
102
+ n(s)[e] = d ? w?.valueFormat ? d : J(d) : null;
103
103
  else
104
- n(r)[e] = d;
104
+ n(s)[e] = d;
105
105
  w?.onChange && w?.onChange(d), o.push(e);
106
106
  } else
107
- f.forEach((d) => {
107
+ c.forEach((d) => {
108
108
  try {
109
109
  const F = d.split(".").reduce((E, et) => E[et], t);
110
- G(F) && (n(r)[d] = n(F), o.push(d));
110
+ G(F) && (n(s)[d] = n(F), o.push(d));
111
111
  } catch {
112
- G(p.value[d]) && (n(r)[d] = O(
112
+ G(p.value[d]) && (n(s)[d] = O(
113
113
  n(p.value[d])
114
114
  ));
115
115
  }
@@ -120,33 +120,33 @@ function Dt({
120
120
  });
121
121
  }
122
122
  async function Y(t) {
123
- const i = O(n(c));
123
+ const i = O(n(f));
124
124
  if (!t)
125
125
  return;
126
- let s = A(t) ? [t] : t;
127
- A(t) && (s = [t]);
128
- for (const l of s)
129
- Z(l, i);
126
+ let l = A(t) ? [t] : t;
127
+ A(t) && (l = [t]);
128
+ for (const r of l)
129
+ Z(r, i);
130
130
  v.value = i;
131
131
  }
132
132
  function Z(t, i) {
133
133
  if (A(t)) {
134
- const s = i.findIndex((l) => l.field === t);
135
- s !== -1 && (delete r[t], i.splice(s, 1));
134
+ const l = i.findIndex((r) => r.field === t);
135
+ l !== -1 && (delete s[t], i.splice(l, 1));
136
136
  }
137
137
  }
138
- async function L(t, i, s = !1) {
139
- const l = O(n(c)), f = l.findIndex((e) => e.field === i), o = V(t) ? [t] : t;
140
- if (!i || f === -1 || s) {
141
- s ? l.unshift(...o) : l.push(...o), v.value = l, g(t);
138
+ async function L(t, i, l = !1) {
139
+ const r = O(n(f)), c = r.findIndex((e) => e.field === i), o = V(t) ? [t] : t;
140
+ if (!i || c === -1 || l) {
141
+ l ? r.unshift(...o) : r.push(...o), v.value = r, g(t);
142
142
  return;
143
143
  }
144
- f !== -1 && l.splice(f + 1, 0, ...o), g(t), v.value = l;
144
+ c !== -1 && r.splice(c + 1, 0, ...o), g(t), v.value = r;
145
145
  }
146
146
  async function K(t) {
147
147
  let i = [];
148
148
  if (V(t) && i.push(t), I(t) && (i = [...t]), !i.every(
149
- (l) => l.type === x.DIVIDER || Reflect.has(l, "field") && l.field
149
+ (r) => r.type === x.DIVIDER || Reflect.has(r, "field") && r.field
150
150
  )) {
151
151
  console.error(
152
152
  "All children of the form Schema array that need to be updated must contain the `field` field"
@@ -165,42 +165,43 @@ function Dt({
165
165
  );
166
166
  return;
167
167
  }
168
- const l = [], f = [];
169
- n(c).forEach((o) => {
168
+ const r = [], c = [];
169
+ n(f).forEach((o) => {
170
170
  let e;
171
171
  if (i.forEach((u) => {
172
- o.field === u.field && (e = u), u.defaultValue && u.field && l.push(u.field);
172
+ o.field === u.field && (e = u), u.defaultValue && u.field && r.push(u.field);
173
173
  }), e !== void 0 && o.field === e.field) {
174
174
  const u = it(o, e);
175
- f.push(u);
175
+ c.push(u);
176
176
  } else
177
- f.push(o);
178
- }), g(f, l), v.value = ot(f, "field");
177
+ c.push(o);
178
+ }), g(c, r), v.value = ot(c, "field");
179
179
  }
180
- function g(t, i, s = !0) {
180
+ function g(t, i, l = !0) {
181
181
  if (I(i) && i?.length === 0)
182
182
  return;
183
- let l = [];
184
- V(t) && l.push(t), I(t) && (l = [...t]);
185
- const f = {}, o = T();
186
- l.forEach((e) => {
187
- e.type !== x.DIVIDER && Reflect.has(e, "field") && e.field && !H(e.defaultValue) && (!(e.field in o) || H(o[e.field]) || lt(o[e.field])) && (f[e.field] = e.defaultValue);
188
- }), st(f) || m(f, s);
183
+ let r = [];
184
+ V(t) && r.push(t), I(t) && (r = [...t]);
185
+ const c = {}, o = T();
186
+ r.forEach((e) => {
187
+ e.type !== x.DIVIDER && Reflect.has(e, "field") && e.field && !H(e.defaultValue) && (!(e.field in o) || H(o[e.field]) || rt(o[e.field])) && (c[e.field] = e.defaultValue);
188
+ }), lt(c) || m(c, l);
189
189
  }
190
190
  function T() {
191
- return n(a) ? D(S(n(r))) : {};
191
+ return n(a) ? D(S(n(s))) : {};
192
192
  }
193
193
  function k(t) {
194
- return n(a) ? S(n(r))[t] : {};
194
+ return n(a) ? S(n(s))[t] : {};
195
195
  }
196
196
  function M(t) {
197
- return n(c).some((i) => i.field === t ? at(i.type) : !1);
197
+ return n(f).some((i) => i.field === t ? at(i.type) : !1);
198
198
  }
199
199
  async function q(t) {
200
- return t || (t = n(c).filter((s) => Q(s, n(r))).map((s) => s.field).filter(Boolean)), n(a)?.validateField(t);
200
+ return t || (t = n(f).filter((l) => Q(l, n(s))).map((l) => l.field).filter(Boolean)), n(a)?.validateField(t);
201
201
  }
202
202
  async function N(t) {
203
- return t || (t = n(c).filter((s) => Q(s, n(r))).map((s) => s.field).filter(Boolean)), await n(a)?.validate(t);
203
+ return t || (t = n(f).filter((l) => Q(l, n(s))).map((l) => l.field).filter(Boolean)), await n(a)?.validate(() => {
204
+ }, t);
204
205
  }
205
206
  async function B(t) {
206
207
  await n(a)?.clearValidate(t);
@@ -209,18 +210,21 @@ function Dt({
209
210
  await n(a)?.scrollToField(t, i);
210
211
  }
211
212
  async function $(t) {
212
- const { autoCleanErrorMessage: i, watchDataIsChange: s } = n(y);
213
+ const { autoCleanErrorMessage: i, watchDataIsChange: l } = n(y);
213
214
  t && t.preventDefault(), i && await B();
214
- const { submitFunc: l, beforeSubmitFunc: f } = n(y);
215
- if (f && j(f) && await f(), l && j(l)) {
216
- await l();
215
+ const { submitFunc: r, beforeSubmitFunc: c } = n(y);
216
+ if (c && j(c) && await c(), r && j(r)) {
217
+ await r();
217
218
  return;
218
219
  }
219
220
  if (n(a))
220
221
  try {
221
- const e = await N(), u = D(e);
222
- if (s) {
223
- const b = ct(_.value, u), C = nt(_.value, u);
222
+ const e = await N();
223
+ if (!e)
224
+ return;
225
+ const u = D(e);
226
+ if (l) {
227
+ const b = ft(_.value, u), C = nt(_.value, u);
224
228
  h("submit", u, !b, C);
225
229
  } else
226
230
  h("submit", u);
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
2
  "name": "vft",
3
- "version": "0.0.340",
3
+ "version": "0.0.342",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "es/index.js",
@@ -1,4 +1,4 @@
1
- const o = "0.0.340";
1
+ const o = "0.0.342";
2
2
  export {
3
3
  o as version
4
4
  };
@@ -7,7 +7,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
7
7
  /**
8
8
  * @description Validate the whole form. Receives a callback or returns `Promise`.
9
9
  */
10
- validate: (callback?: FormValidateCallback) => FormValidationResult;
10
+ validate: (callback?: FormValidateCallback, props?: Arrayable<FormItemProp>) => FormValidationResult;
11
11
  /**
12
12
  * @description Validate specified fields.
13
13
  */
@@ -1 +1 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("vue");require("@vueuse/core");const E=require("@vft/utils"),d=require("../../utils/error.cjs");require("../config-provider/hooks/use-global-config.cjs");require("lodash-es");const k=require("../../hooks/use-namespace/index.cjs");require("../../hooks/use-model-toggle/index.cjs");require("@popperjs/core");require("../../hooks/use-z-index/index.cjs");const R=require("./constants.cjs"),W=require("./hooks/use-form-common-props.cjs"),u=require("./utils.cjs"),x=r.defineComponent({name:"vft-form"}),M=r.defineComponent({...x,props:{size:{},disabled:{type:Boolean},model:{},rules:{},labelPosition:{default:"right"},requireAsteriskPosition:{default:"left"},labelWidth:{default:""},labelSuffix:{default:""},inline:{type:Boolean},inlineMessage:{type:Boolean},statusIcon:{type:Boolean},showMessage:{type:Boolean,default:!0},validateOnRuleChange:{type:Boolean,default:!0},hideRequiredAsterisk:{type:Boolean,default:!1},scrollToError:{type:Boolean},scrollIntoViewOptions:{type:Boolean,default:!0}},emits:["validate"],setup(o,{expose:y,emit:q}){const g=q,p=r.getCurrentInstance(),c=r.ref(),l=r.reactive([]),w=W.useFormSize(),s=k.useNamespace("form"),B=r.computed(()=>[s.b(),s.m(w.value||"default"),{[s.m(`label-${o.labelPosition}`)]:o.labelPosition,[s.m("inline")]:o.inline}]),m=e=>u.filterFields(l,[e])[0],V=e=>{l.push(e)},C=e=>{e.prop&&l.splice(l.indexOf(e),1)},h=(e=[])=>{if(!o.model){d.debugWarn(s.b(),"model is required for resetFields to work.");return}u.filterFields(l,e).forEach(t=>t.resetField())},v=(e=[])=>{u.filterFields(l,e).forEach(t=>t.clearValidate())},I=r.computed(()=>{const e=!!o.model;return e||d.debugWarn(s.b(),"model is required for validate to work."),e}),O=e=>{if(l.length===0)return[];const t=u.filterFields(l,e);return t.length?t:(d.debugWarn(s.b(),"please pass correct props!"),[])},F=async e=>f(void 0,e),P=async(e=[])=>{if(!I.value)return!1;const t=O(e);if(t.length===0)return!0;let i={};for(const n of t)try{await n.validate(""),n.validateState==="error"&&n.resetField()}catch(a){i={...i,...a}}return Object.keys(i).length===0?!0:Promise.reject(i)},f=async(e=[],t)=>{let i=!1;const n=!E.isFunction(t);try{return i=await P(e),i===!0&&await t?.(i),o.model}catch(a){if(a instanceof Error)throw a;const b=a;return o.scrollToError&&c.value&&c.value.querySelector(`.${s.b()}-item.is-error`)?.scrollIntoView(o.scrollIntoViewOptions),!i&&await t?.(!1,b),n&&Promise.reject(b)}},S=e=>{const t=m(e);t&&t.$el?.scrollIntoView(o.scrollIntoViewOptions)};return r.watch(()=>o.rules,()=>{o.validateOnRuleChange&&F().catch(e=>d.debugWarn(e))},{deep:!0,flush:"post"}),r.provide(R.formContextKey,r.reactive({...r.toRefs(p.props),emit:g,resetFields:h,clearValidate:v,validateField:f,getField:m,addField:V,removeField:C,...u.useFormLabelWidth()})),y({validate:F,validateField:f,resetFields:h,clearValidate:v,scrollToField:S}),(e,t)=>(r.openBlock(),r.createElementBlock("form",{ref_key:"formRef",ref:c,class:r.normalizeClass(B.value)},[r.renderSlot(e.$slots,"default")],2))}});exports.default=M;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("vue");require("@vueuse/core");const E=require("@vft/utils"),d=require("../../utils/error.cjs");require("../config-provider/hooks/use-global-config.cjs");require("lodash-es");const k=require("../../hooks/use-namespace/index.cjs");require("../../hooks/use-model-toggle/index.cjs");require("@popperjs/core");require("../../hooks/use-z-index/index.cjs");const R=require("./constants.cjs"),W=require("./hooks/use-form-common-props.cjs"),u=require("./utils.cjs"),x=r.defineComponent({name:"vft-form"}),M=r.defineComponent({...x,props:{size:{},disabled:{type:Boolean},model:{},rules:{},labelPosition:{default:"right"},requireAsteriskPosition:{default:"left"},labelWidth:{default:""},labelSuffix:{default:""},inline:{type:Boolean},inlineMessage:{type:Boolean},statusIcon:{type:Boolean},showMessage:{type:Boolean,default:!0},validateOnRuleChange:{type:Boolean,default:!0},hideRequiredAsterisk:{type:Boolean,default:!1},scrollToError:{type:Boolean},scrollIntoViewOptions:{type:Boolean,default:!0}},emits:["validate"],setup(o,{expose:y,emit:q}){const g=q,p=r.getCurrentInstance(),c=r.ref(),l=r.reactive([]),w=W.useFormSize(),s=k.useNamespace("form"),B=r.computed(()=>[s.b(),s.m(w.value||"default"),{[s.m(`label-${o.labelPosition}`)]:o.labelPosition,[s.m("inline")]:o.inline}]),m=e=>u.filterFields(l,[e])[0],V=e=>{l.push(e)},C=e=>{e.prop&&l.splice(l.indexOf(e),1)},h=(e=[])=>{if(!o.model){d.debugWarn(s.b(),"model is required for resetFields to work.");return}u.filterFields(l,e).forEach(t=>t.resetField())},v=(e=[])=>{u.filterFields(l,e).forEach(t=>t.clearValidate())},I=r.computed(()=>{const e=!!o.model;return e||d.debugWarn(s.b(),"model is required for validate to work."),e}),O=e=>{if(l.length===0)return[];const t=u.filterFields(l,e);return t.length?t:(d.debugWarn(s.b(),"please pass correct props!"),[])},F=async(e,t)=>f(t||void 0,e),P=async(e=[])=>{if(!I.value)return!1;const t=O(e);if(t.length===0)return!0;let i={};for(const a of t)try{await a.validate(""),a.validateState==="error"&&a.resetField()}catch(n){i={...i,...n}}return Object.keys(i).length===0?!0:Promise.reject(i)},f=async(e=[],t)=>{let i=!1;const a=!E.isFunction(t);try{return i=await P(e),i===!0&&await t?.(i),o.model}catch(n){if(n instanceof Error)throw n;const b=n;return o.scrollToError&&c.value&&c.value.querySelector(`.${s.b()}-item.is-error`)?.scrollIntoView(o.scrollIntoViewOptions),console.error(n),!i&&await t?.(!1,b),a&&Promise.reject(b)}},S=e=>{const t=m(e);t&&t.$el?.scrollIntoView(o.scrollIntoViewOptions)};return r.watch(()=>o.rules,()=>{o.validateOnRuleChange&&F().catch(e=>d.debugWarn(e))},{deep:!0,flush:"post"}),r.provide(R.formContextKey,r.reactive({...r.toRefs(p.props),emit:g,resetFields:h,clearValidate:v,validateField:f,getField:m,addField:V,removeField:C,...u.useFormLabelWidth()})),y({validate:F,validateField:f,resetFields:h,clearValidate:v,scrollToField:S}),(e,t)=>(r.openBlock(),r.createElementBlock("form",{ref_key:"formRef",ref:c,class:r.normalizeClass(B.value)},[r.renderSlot(e.$slots,"default")],2))}});exports.default=M;
@@ -53,7 +53,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
53
53
  }>> & Readonly<{
54
54
  onValidate?: ((...args: any[]) => any) | undefined;
55
55
  }>, {
56
- validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
56
+ validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
57
57
  validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
58
58
  resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
59
59
  clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
@@ -119,7 +119,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
119
119
  }>> & Readonly<{
120
120
  onValidate?: ((...args: any[]) => any) | undefined;
121
121
  }>, {
122
- validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
122
+ validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
123
123
  validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
124
124
  resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
125
125
  clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
@@ -180,7 +180,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
180
180
  }>> & Readonly<{
181
181
  onValidate?: ((...args: any[]) => any) | undefined;
182
182
  }>, {
183
- validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
183
+ validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
184
184
  validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
185
185
  resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
186
186
  clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
@@ -79,7 +79,7 @@ export interface FormActionType {
79
79
  /** 验证指定字段 */
80
80
  validateField: (nameList?: NamePath[]) => Promise<any>;
81
81
  /** 验证表单 */
82
- validate: (nameList?: NamePath[]) => Promise<any>;
82
+ validate: (callback?: Function, nameList?: NamePath[]) => Promise<any>;
83
83
  /** 滚动到指定字段 */
84
84
  scrollToField: (name: NamePath, options?: ScrollOptions) => Promise<void>;
85
85
  /** 设置表单项错误信息 */
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@vft/utils"),N=require("@vft/utils/date"),b=require("lodash-es"),i=require("vue"),O=require("../component-map.cjs"),Z=require("./helper.cjs");function U(p,F){const{show:u,ifShow:l}=p;let y=!0,a=!0;return typeof u=="boolean"?y=u:typeof u=="function"&&(y=u({field:p.field,model:F,values:{...F},schema:p})),typeof l=="boolean"?a=l:typeof l=="function"&&(a=l({field:p.field,model:F,values:{...F},schema:p})),y&&a}function L(p,F={}){const u=/^\[(.+)\]$/;if(u.test(p)){const l=p.match(u);if(l&&l[1]){const y=l[1].split(",");if(!y.length)return;const a=[];return y.forEach((v,V)=>{b.set(a,V,F[v.trim()])}),a.filter(Boolean).length?a:void 0}}}function K(p,F={}){const u=/^\{(.+)\}$/;if(u.test(p)){const l=p.match(u);if(l&&l[1]){const y=l[1].split(",");if(!y.length)return;const a={};return y.forEach(v=>{b.set(a,v.trim(),F[v.trim()])}),Object.values(a).filter(Boolean).length?a:void 0}}}function R({emit:p,getProps:F,formModel:u,getSchema:l,defaultValueRef:y,formElRef:a,schemaRef:v,handleFormValues:V,initValues:A}){async function $(e){const{resetFunc:t,submitOnReset:s}=i.unref(F);t&&c.isFunction(t)&&await t();const r=i.unref(a);if(r){if(e?.length)return r.resetFields(e);Object.keys(u).forEach(o=>{const f=i.unref(l).find(d=>d.field===o),n=b.cloneDeep(y.value[o]);u[o]=O.isInput(f?.type)?n||"":n}),i.nextTick(()=>j()),p("reset",i.toRaw(u)),s&&await x()}}async function C(e,t=!0){const s=i.unref(l).map(n=>n.field).filter(Boolean),r=".",o=s.filter(n=>String(n).indexOf(r)>=0),f=[];s.forEach(n=>{const d=i.unref(l).find(h=>h.field===n);let E=b.get(e,n);const S=Reflect.has(e,n);E=Z.handleInputNumberValue(d?.type,E);const{componentProps:_}=d||{};let w=_;typeof _=="function"&&(w=w({formModel:i.unref(u)}));const m=L(n,e)||K(n,e);if(S||m){const h=m||E;if(W(n))if(Array.isArray(h)){const D=[];for(const g of h)D.push(g?N.formatToDate(g):null);i.unref(u)[n]=D}else i.unref(u)[n]=h?w?.valueFormat?h:N.formatToDate(h):null;else i.unref(u)[n]=h;w?.onChange&&w?.onChange(h),f.push(n)}else o.forEach(h=>{try{const D=h.split(".").reduce((g,Y)=>g[Y],e);c.isDef(D)&&(i.unref(u)[h]=i.unref(D),f.push(h))}catch{c.isDef(y.value[h])&&(i.unref(u)[h]=b.cloneDeep(i.unref(y.value[h])))}})}),t&&i.nextTick(async()=>{await q(f).catch(n=>{})})}async function P(e){const t=b.cloneDeep(i.unref(l));if(!e)return;let s=c.isString(e)?[e]:e;c.isString(e)&&(s=[e]);for(const r of s)z(r,t);v.value=t}function z(e,t){if(c.isString(e)){const s=t.findIndex(r=>r.field===e);s!==-1&&(delete u[e],t.splice(s,1))}}async function G(e,t,s=!1){const r=b.cloneDeep(i.unref(l)),o=r.findIndex(n=>n.field===t),f=c.isObject(e)?[e]:e;if(!t||o===-1||s){s?r.unshift(...f):r.push(...f),v.value=r,I(e);return}o!==-1&&r.splice(o+1,0,...f),I(e),v.value=r}async function H(e){let t=[];if(c.isObject(e)&&t.push(e),c.isArray(e)&&(t=[...e]),!t.every(r=>r.type===O.FormCompEnum.DIVIDER||Reflect.has(r,"field")&&r.field)){console.error("All children of the form Schema array that need to be updated must contain the `field` field");return}v.value=t}async function J(e){let t=[];if(c.isObject(e)&&t.push(e),c.isArray(e)&&(t=[...e]),!t.every(f=>f.type===O.FormCompEnum.DIVIDER||Reflect.has(f,"field")&&f.field)){console.error("All children of the form Schema array that need to be updated must contain the `field` field");return}const r=[],o=[];i.unref(l).forEach(f=>{let n;if(t.forEach(d=>{f.field===d.field&&(n=d),d.defaultValue&&d.field&&r.push(d.field)}),n!==void 0&&f.field===n.field){const d=c.deepMerge(f,n);o.push(d)}else o.push(f)}),I(o,r),v.value=b.uniqBy(o,"field")}function I(e,t,s=!0){if(c.isArray(t)&&t?.length===0)return;let r=[];c.isObject(e)&&r.push(e),c.isArray(e)&&(r=[...e]);const o={},f=B();r.forEach(n=>{n.type!==O.FormCompEnum.DIVIDER&&Reflect.has(n,"field")&&n.field&&!c.isNullOrUndefined(n.defaultValue)&&(!(n.field in f)||c.isNullOrUndefined(f[n.field])||c.isEmpty(f[n.field]))&&(o[n.field]=n.defaultValue)}),c.isEmptyObject(o)||C(o,s)}function B(){return i.unref(a)?V(i.toRaw(i.unref(u))):{}}function Q(e){return i.unref(a)?i.toRaw(i.unref(u))[e]:{}}function W(e){return i.unref(l).some(t=>t.field===e?O.isDatePicker(t.type):!1)}async function q(e){return e||(e=i.unref(l).filter(s=>U(s,i.unref(u))).map(s=>s.field).filter(Boolean)),i.unref(a)?.validateField(e)}async function T(e){return e||(e=i.unref(l).filter(s=>U(s,i.unref(u))).map(s=>s.field).filter(Boolean)),await i.unref(a)?.validate(e)}async function j(e){await i.unref(a)?.clearValidate(e)}async function X(e,t){await i.unref(a)?.scrollToField(e,t)}async function x(e){const{autoCleanErrorMessage:t,watchDataIsChange:s}=i.unref(F);e&&e.preventDefault(),t&&await j();const{submitFunc:r,beforeSubmitFunc:o}=i.unref(F);if(o&&c.isFunction(o)&&await o(),r&&c.isFunction(r)){await r();return}if(i.unref(a))try{const n=await T(),d=V(n);if(s){const E=b.isEqual(A.value,d),S=c.findDifferentValuesForObj(A.value,d);p("submit",d,!E,S)}else p("submit",d)}catch(n){if(n?.outOfDate===!1&&n?.errorFields)return;throw new Error(n.message)}}return{handleSubmit:x,clearValidate:j,validate:T,validateField:q,getFieldsValue:B,updateSchema:J,resetSchema:H,appendSchemaByField:G,removeSchemaByField:P,resetFields:$,setFieldsValue:C,scrollToField:X,getFieldValue:Q}}exports.useFormEvents=R;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@vft/utils"),N=require("@vft/utils/date"),b=require("lodash-es"),i=require("vue"),O=require("../component-map.cjs"),Z=require("./helper.cjs");function U(p,F){const{show:u,ifShow:l}=p;let y=!0,a=!0;return typeof u=="boolean"?y=u:typeof u=="function"&&(y=u({field:p.field,model:F,values:{...F},schema:p})),typeof l=="boolean"?a=l:typeof l=="function"&&(a=l({field:p.field,model:F,values:{...F},schema:p})),y&&a}function L(p,F={}){const u=/^\[(.+)\]$/;if(u.test(p)){const l=p.match(u);if(l&&l[1]){const y=l[1].split(",");if(!y.length)return;const a=[];return y.forEach((v,V)=>{b.set(a,V,F[v.trim()])}),a.filter(Boolean).length?a:void 0}}}function K(p,F={}){const u=/^\{(.+)\}$/;if(u.test(p)){const l=p.match(u);if(l&&l[1]){const y=l[1].split(",");if(!y.length)return;const a={};return y.forEach(v=>{b.set(a,v.trim(),F[v.trim()])}),Object.values(a).filter(Boolean).length?a:void 0}}}function R({emit:p,getProps:F,formModel:u,getSchema:l,defaultValueRef:y,formElRef:a,schemaRef:v,handleFormValues:V,initValues:A}){async function $(e){const{resetFunc:t,submitOnReset:s}=i.unref(F);t&&c.isFunction(t)&&await t();const r=i.unref(a);if(r){if(e?.length)return r.resetFields(e);Object.keys(u).forEach(o=>{const f=i.unref(l).find(d=>d.field===o),n=b.cloneDeep(y.value[o]);u[o]=O.isInput(f?.type)?n||"":n}),i.nextTick(()=>j()),p("reset",i.toRaw(u)),s&&await x()}}async function C(e,t=!0){const s=i.unref(l).map(n=>n.field).filter(Boolean),r=".",o=s.filter(n=>String(n).indexOf(r)>=0),f=[];s.forEach(n=>{const d=i.unref(l).find(h=>h.field===n);let E=b.get(e,n);const S=Reflect.has(e,n);E=Z.handleInputNumberValue(d?.type,E);const{componentProps:_}=d||{};let w=_;typeof _=="function"&&(w=w({formModel:i.unref(u)}));const m=L(n,e)||K(n,e);if(S||m){const h=m||E;if(W(n))if(Array.isArray(h)){const D=[];for(const g of h)D.push(g?N.formatToDate(g):null);i.unref(u)[n]=D}else i.unref(u)[n]=h?w?.valueFormat?h:N.formatToDate(h):null;else i.unref(u)[n]=h;w?.onChange&&w?.onChange(h),f.push(n)}else o.forEach(h=>{try{const D=h.split(".").reduce((g,Y)=>g[Y],e);c.isDef(D)&&(i.unref(u)[h]=i.unref(D),f.push(h))}catch{c.isDef(y.value[h])&&(i.unref(u)[h]=b.cloneDeep(i.unref(y.value[h])))}})}),t&&i.nextTick(async()=>{await q(f).catch(n=>{})})}async function P(e){const t=b.cloneDeep(i.unref(l));if(!e)return;let s=c.isString(e)?[e]:e;c.isString(e)&&(s=[e]);for(const r of s)z(r,t);v.value=t}function z(e,t){if(c.isString(e)){const s=t.findIndex(r=>r.field===e);s!==-1&&(delete u[e],t.splice(s,1))}}async function G(e,t,s=!1){const r=b.cloneDeep(i.unref(l)),o=r.findIndex(n=>n.field===t),f=c.isObject(e)?[e]:e;if(!t||o===-1||s){s?r.unshift(...f):r.push(...f),v.value=r,I(e);return}o!==-1&&r.splice(o+1,0,...f),I(e),v.value=r}async function H(e){let t=[];if(c.isObject(e)&&t.push(e),c.isArray(e)&&(t=[...e]),!t.every(r=>r.type===O.FormCompEnum.DIVIDER||Reflect.has(r,"field")&&r.field)){console.error("All children of the form Schema array that need to be updated must contain the `field` field");return}v.value=t}async function J(e){let t=[];if(c.isObject(e)&&t.push(e),c.isArray(e)&&(t=[...e]),!t.every(f=>f.type===O.FormCompEnum.DIVIDER||Reflect.has(f,"field")&&f.field)){console.error("All children of the form Schema array that need to be updated must contain the `field` field");return}const r=[],o=[];i.unref(l).forEach(f=>{let n;if(t.forEach(d=>{f.field===d.field&&(n=d),d.defaultValue&&d.field&&r.push(d.field)}),n!==void 0&&f.field===n.field){const d=c.deepMerge(f,n);o.push(d)}else o.push(f)}),I(o,r),v.value=b.uniqBy(o,"field")}function I(e,t,s=!0){if(c.isArray(t)&&t?.length===0)return;let r=[];c.isObject(e)&&r.push(e),c.isArray(e)&&(r=[...e]);const o={},f=B();r.forEach(n=>{n.type!==O.FormCompEnum.DIVIDER&&Reflect.has(n,"field")&&n.field&&!c.isNullOrUndefined(n.defaultValue)&&(!(n.field in f)||c.isNullOrUndefined(f[n.field])||c.isEmpty(f[n.field]))&&(o[n.field]=n.defaultValue)}),c.isEmptyObject(o)||C(o,s)}function B(){return i.unref(a)?V(i.toRaw(i.unref(u))):{}}function Q(e){return i.unref(a)?i.toRaw(i.unref(u))[e]:{}}function W(e){return i.unref(l).some(t=>t.field===e?O.isDatePicker(t.type):!1)}async function q(e){return e||(e=i.unref(l).filter(s=>U(s,i.unref(u))).map(s=>s.field).filter(Boolean)),i.unref(a)?.validateField(e)}async function T(e){return e||(e=i.unref(l).filter(s=>U(s,i.unref(u))).map(s=>s.field).filter(Boolean)),await i.unref(a)?.validate(()=>{},e)}async function j(e){await i.unref(a)?.clearValidate(e)}async function X(e,t){await i.unref(a)?.scrollToField(e,t)}async function x(e){const{autoCleanErrorMessage:t,watchDataIsChange:s}=i.unref(F);e&&e.preventDefault(),t&&await j();const{submitFunc:r,beforeSubmitFunc:o}=i.unref(F);if(o&&c.isFunction(o)&&await o(),r&&c.isFunction(r)){await r();return}if(i.unref(a))try{const n=await T();if(!n)return;const d=V(n);if(s){const E=b.isEqual(A.value,d),S=c.findDifferentValuesForObj(A.value,d);p("submit",d,!E,S)}else p("submit",d)}catch(n){if(n?.outOfDate===!1&&n?.errorFields)return;throw new Error(n.message)}}return{handleSubmit:x,clearValidate:j,validate:T,validateField:q,getFieldsValue:B,updateSchema:J,resetSchema:H,appendSchemaByField:G,removeSchemaByField:P,resetFields:$,setFieldsValue:C,scrollToField:X,getFieldValue:Q}}exports.useFormEvents=R;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.0.340";exports.version=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.0.342";exports.version=e;
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
2
  "name": "vft",
3
- "version": "0.0.340",
3
+ "version": "0.0.342",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "es/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vft",
3
- "version": "0.0.340",
3
+ "version": "0.0.342",
4
4
  "license": "MIT",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "es/index.js",
@@ -56,10 +56,10 @@
56
56
  "sortablejs": "1.15.0",
57
57
  "photoswipe": "5.4.4",
58
58
  "@vft/router": "0.0.65",
59
- "@vft/constants": "0.0.72",
60
59
  "@vft/store": "0.0.54",
61
- "@vft/use": "0.0.76",
60
+ "@vft/constants": "0.0.72",
62
61
  "@vft/utils": "0.0.128",
62
+ "@vft/use": "0.0.76",
63
63
  "@vft/directives": "0.0.33"
64
64
  },
65
65
  "vetur": {
package/web-types.json CHANGED
@@ -1 +1 @@
1
- {"$schema":"http://json.schemastore.org/web-types","framework":"vue","name":"vft","version":"0.0.340","js-types-syntax":"typescript","description-markup":"markdown","contributions":{"html":{}}}
1
+ {"$schema":"http://json.schemastore.org/web-types","framework":"vue","name":"vft","version":"0.0.342","js-types-syntax":"typescript","description-markup":"markdown","contributions":{"html":{}}}