vft 0.0.340 → 0.0.343

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.
Files changed (30) hide show
  1. package/es/components/button/index.d.ts +9 -9
  2. package/es/components/form/form-item.vue.d.ts +1 -1
  3. package/es/components/form/form.vue.d.ts +1 -1
  4. package/es/components/form/form.vue2.js +10 -10
  5. package/es/components/form/index.d.ts +33 -33
  6. package/es/components/popconfirm/index.d.ts +15 -15
  7. package/es/components/popconfirm/popconfirm.vue.d.ts +1 -1
  8. package/es/components/super-form/index.d.ts +3 -3
  9. package/es/components/super-form/super-form.vue.d.ts +1 -1
  10. package/es/components/super-form/types.d.ts +1 -1
  11. package/es/components/super-form/use/use-form-events.d.ts +1 -1
  12. package/es/components/super-form/use/use-form-events.js +136 -126
  13. package/es/package.json.d.ts +1 -1
  14. package/es/package.json.js +1 -1
  15. package/lib/components/button/index.d.ts +9 -9
  16. package/lib/components/form/form-item.vue.d.ts +1 -1
  17. package/lib/components/form/form.vue.d.ts +1 -1
  18. package/lib/components/form/form.vue2.cjs +1 -1
  19. package/lib/components/form/index.d.ts +33 -33
  20. package/lib/components/popconfirm/index.d.ts +15 -15
  21. package/lib/components/popconfirm/popconfirm.vue.d.ts +1 -1
  22. package/lib/components/super-form/index.d.ts +3 -3
  23. package/lib/components/super-form/super-form.vue.d.ts +1 -1
  24. package/lib/components/super-form/types.d.ts +1 -1
  25. package/lib/components/super-form/use/use-form-events.cjs +1 -1
  26. package/lib/components/super-form/use/use-form-events.d.ts +1 -1
  27. package/lib/package.json.cjs +1 -1
  28. package/lib/package.json.d.ts +1 -1
  29. package/package.json +2 -2
  30. package/web-types.json +1 -1
@@ -1,227 +1,237 @@
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";
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";
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";
1
+ import { isDef as H, isFunction as m, isString as A, isObject as E, isArray as V, deepMerge as it, findDifferentValuesForObj as nt, isNullOrUndefined as J, isEmpty as lt, isEmptyObject as st } from "@vft/utils";
2
+ import { formatToDate as P } from "@vft/utils/date";
3
+ import { get as rt, cloneDeep as I, uniqBy as ot, isEqual as at, set as W } from "lodash-es";
4
+ import { unref as n, toRaw as x, nextTick as Q } from "vue";
5
+ import { isInput as ft, FormCompEnum as S, isDatePicker as ct } from "../component-map.js";
6
6
  import { handleInputNumberValue as ut } from "./helper.js";
7
- function Q(h, y) {
8
- const { show: r, ifShow: c } = h;
9
- let p = !0, a = !0;
10
- return typeof r == "boolean" ? p = r : typeof r == "function" && (p = r({
7
+ function _(h, v) {
8
+ const { show: o, ifShow: f } = h;
9
+ let p = !0, c = !0;
10
+ return typeof o == "boolean" ? p = o : typeof o == "function" && (p = o({
11
11
  field: h.field,
12
- model: y,
12
+ model: v,
13
13
  values: {
14
- ...y
14
+ ...v
15
15
  },
16
16
  schema: h
17
- })), typeof c == "boolean" ? a = c : typeof c == "function" && (a = c({
17
+ })), typeof f == "boolean" ? c = f : typeof f == "function" && (c = f({
18
18
  field: h.field,
19
- model: y,
19
+ model: v,
20
20
  values: {
21
- ...y
21
+ ...v
22
22
  },
23
23
  schema: h
24
- })), p && a;
24
+ })), p && c;
25
25
  }
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(",");
26
+ function dt(h, v = {}) {
27
+ const o = /^\[(.+)\]$/;
28
+ if (o.test(h)) {
29
+ const f = h.match(o);
30
+ if (f && f[1]) {
31
+ const p = f[1].split(",");
32
32
  if (!p.length)
33
33
  return;
34
- const a = [];
35
- return p.forEach((v, D) => {
36
- W(a, D, y[v.trim()]);
37
- }), a.filter(Boolean).length ? a : void 0;
34
+ const c = [];
35
+ return p.forEach((y, B) => {
36
+ W(c, B, v[y.trim()]);
37
+ }), c.filter(Boolean).length ? c : void 0;
38
38
  }
39
39
  }
40
40
  }
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(",");
41
+ function ht(h, v = {}) {
42
+ const o = /^\{(.+)\}$/;
43
+ if (o.test(h)) {
44
+ const f = h.match(o);
45
+ if (f && f[1]) {
46
+ const p = f[1].split(",");
47
47
  if (!p.length)
48
48
  return;
49
- const a = {};
50
- return p.forEach((v) => {
51
- W(a, v.trim(), y[v.trim()]);
52
- }), Object.values(a).filter(Boolean).length ? a : void 0;
49
+ const c = {};
50
+ return p.forEach((y) => {
51
+ W(c, y.trim(), v[y.trim()]);
52
+ }), Object.values(c).filter(Boolean).length ? c : void 0;
53
53
  }
54
54
  }
55
55
  }
56
- function Dt({
56
+ function wt({
57
57
  emit: h,
58
- getProps: y,
59
- formModel: r,
60
- getSchema: c,
58
+ getProps: v,
59
+ formModel: o,
60
+ getSchema: f,
61
61
  defaultValueRef: p,
62
- formElRef: a,
63
- schemaRef: v,
64
- handleFormValues: D,
65
- initValues: _
62
+ formElRef: c,
63
+ schemaRef: y,
64
+ handleFormValues: B,
65
+ initValues: T
66
66
  }) {
67
67
  async function X(t) {
68
- const { resetFunc: i, submitOnReset: s } = n(y);
69
- i && j(i) && await i();
70
- const l = n(a);
68
+ const { resetFunc: i, submitOnReset: s } = n(v);
69
+ i && m(i) && await i();
70
+ const l = n(c);
71
71
  if (l) {
72
72
  if (t?.length)
73
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 $();
74
+ Object.keys(o).forEach((a) => {
75
+ const r = n(f).find((u) => u.field === a), e = I(p.value[a]);
76
+ o[a] = ft(r?.type) ? e || "" : e;
77
+ }), Q(() => C()), h("reset", x(o)), s && await U();
78
78
  }
79
79
  }
80
- async function m(t, i = !0) {
81
- const s = n(c).map((e) => e.field).filter(Boolean), l = ".", f = s.filter(
80
+ async function q(t, i = !0) {
81
+ const s = n(f).map((e) => e.field).filter(Boolean), l = ".", a = s.filter(
82
82
  (e) => String(e).indexOf(l) >= 0
83
- ), o = [];
83
+ ), r = [];
84
84
  s.forEach((e) => {
85
- const u = n(c).find((d) => d.field === e);
85
+ const u = n(f).find((d) => d.field === e);
86
86
  let b = rt(t, e);
87
- const C = Reflect.has(t, e);
87
+ const j = Reflect.has(t, e);
88
88
  b = ut(u?.type, b);
89
- const { componentProps: U } = u || {};
90
- let w = U;
91
- typeof U == "function" && (w = w({ formModel: n(r) }));
92
- const z = dt(e, t) || ht(e, t);
93
- if (C || z) {
94
- const d = z || b;
89
+ const { componentProps: z } = u || {};
90
+ let D = z;
91
+ typeof z == "function" && (D = D({ formModel: n(o) }));
92
+ const G = dt(e, t) || ht(e, t);
93
+ if (j || G) {
94
+ const d = G || b;
95
95
  if (M(e))
96
96
  if (Array.isArray(d)) {
97
97
  const F = [];
98
- for (const E of d)
99
- F.push(E ? J(E) : null);
100
- n(r)[e] = F;
98
+ for (const w of d)
99
+ F.push(w ? P(w) : null);
100
+ n(o)[e] = F;
101
101
  } else
102
- n(r)[e] = d ? w?.valueFormat ? d : J(d) : null;
102
+ n(o)[e] = d ? D?.valueFormat ? d : P(d) : null;
103
103
  else
104
- n(r)[e] = d;
105
- w?.onChange && w?.onChange(d), o.push(e);
104
+ n(o)[e] = d;
105
+ D?.onChange && D?.onChange(d), r.push(e);
106
106
  } else
107
- f.forEach((d) => {
107
+ a.forEach((d) => {
108
108
  try {
109
- const F = d.split(".").reduce((E, et) => E[et], t);
110
- G(F) && (n(r)[d] = n(F), o.push(d));
109
+ const F = d.split(".").reduce((w, et) => w[et], t);
110
+ H(F) && (n(o)[d] = n(F), r.push(d));
111
111
  } catch {
112
- G(p.value[d]) && (n(r)[d] = O(
112
+ H(p.value[d]) && (n(o)[d] = I(
113
113
  n(p.value[d])
114
114
  ));
115
115
  }
116
116
  });
117
- }), i && P(async () => {
118
- await q(o).catch((e) => {
117
+ }), i && Q(async () => {
118
+ await N(r).catch((e) => {
119
119
  });
120
120
  });
121
121
  }
122
122
  async function Y(t) {
123
- const i = O(n(c));
123
+ const i = I(n(f));
124
124
  if (!t)
125
125
  return;
126
126
  let s = A(t) ? [t] : t;
127
127
  A(t) && (s = [t]);
128
128
  for (const l of s)
129
129
  Z(l, i);
130
- v.value = i;
130
+ y.value = i;
131
131
  }
132
132
  function Z(t, i) {
133
133
  if (A(t)) {
134
134
  const s = i.findIndex((l) => l.field === t);
135
- s !== -1 && (delete r[t], i.splice(s, 1));
135
+ s !== -1 && (delete o[t], i.splice(s, 1));
136
136
  }
137
137
  }
138
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);
139
+ const l = I(n(f)), a = l.findIndex((e) => e.field === i), r = E(t) ? [t] : t;
140
+ if (!i || a === -1 || s) {
141
+ s ? l.unshift(...r) : l.push(...r), y.value = l, O(t);
142
142
  return;
143
143
  }
144
- f !== -1 && l.splice(f + 1, 0, ...o), g(t), v.value = l;
144
+ a !== -1 && l.splice(a + 1, 0, ...r), O(t), y.value = l;
145
145
  }
146
146
  async function K(t) {
147
147
  let i = [];
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
148
+ if (E(t) && i.push(t), V(t) && (i = [...t]), !i.every(
149
+ (l) => l.type === S.DIVIDER || Reflect.has(l, "field") && l.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"
153
153
  );
154
154
  return;
155
155
  }
156
- v.value = i;
156
+ y.value = i;
157
157
  }
158
158
  async function R(t) {
159
159
  let i = [];
160
- if (V(t) && i.push(t), I(t) && (i = [...t]), !i.every(
161
- (o) => o.type === x.DIVIDER || Reflect.has(o, "field") && o.field
160
+ if (E(t) && i.push(t), V(t) && (i = [...t]), !i.every(
161
+ (r) => r.type === S.DIVIDER || Reflect.has(r, "field") && r.field
162
162
  )) {
163
163
  console.error(
164
164
  "All children of the form Schema array that need to be updated must contain the `field` field"
165
165
  );
166
166
  return;
167
167
  }
168
- const l = [], f = [];
169
- n(c).forEach((o) => {
168
+ const l = [], a = [];
169
+ n(f).forEach((r) => {
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);
173
- }), e !== void 0 && o.field === e.field) {
174
- const u = it(o, e);
175
- f.push(u);
172
+ r.field === u.field && (e = u), u.defaultValue && u.field && l.push(u.field);
173
+ }), e !== void 0 && r.field === e.field) {
174
+ const u = it(r, e);
175
+ a.push(u);
176
176
  } else
177
- f.push(o);
178
- }), g(f, l), v.value = ot(f, "field");
177
+ a.push(r);
178
+ }), O(a, l), y.value = ot(a, "field");
179
179
  }
180
- function g(t, i, s = !0) {
181
- if (I(i) && i?.length === 0)
180
+ function O(t, i, s = !0) {
181
+ if (V(i) && i?.length === 0)
182
182
  return;
183
183
  let l = [];
184
- V(t) && l.push(t), I(t) && (l = [...t]);
185
- const f = {}, o = T();
184
+ E(t) && l.push(t), V(t) && (l = [...t]);
185
+ const a = {}, r = g();
186
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);
187
+ e.type !== S.DIVIDER && Reflect.has(e, "field") && e.field && !J(e.defaultValue) && (!(e.field in r) || J(r[e.field]) || lt(r[e.field])) && (a[e.field] = e.defaultValue);
188
+ }), st(a) || q(a, s);
189
189
  }
190
- function T() {
191
- return n(a) ? D(S(n(r))) : {};
190
+ function g(t = fasle) {
191
+ if (!n(c)) return {};
192
+ const s = B(x(n(o)));
193
+ if (t)
194
+ return s;
195
+ const l = n(f).filter((r) => _(r, n(o))).map((r) => r.field).filter(Boolean), a = {};
196
+ return l.forEach((r) => {
197
+ r in s && (a[r] = s[r]);
198
+ }), a;
192
199
  }
193
200
  function k(t) {
194
- return n(a) ? S(n(r))[t] : {};
201
+ return n(c) ? x(n(o))[t] : {};
195
202
  }
196
203
  function M(t) {
197
- return n(c).some((i) => i.field === t ? at(i.type) : !1);
198
- }
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);
204
+ return n(f).some((i) => i.field === t ? ct(i.type) : !1);
201
205
  }
202
206
  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);
207
+ return t || (t = n(f).filter((s) => _(s, n(o))).map((s) => s.field).filter(Boolean)), n(c)?.validateField(t);
208
+ }
209
+ async function $(t) {
210
+ return t || (t = n(f).filter((s) => _(s, n(o))).map((s) => s.field).filter(Boolean)), await n(c)?.validate(() => {
211
+ }, t);
204
212
  }
205
- async function B(t) {
206
- await n(a)?.clearValidate(t);
213
+ async function C(t) {
214
+ await n(c)?.clearValidate(t);
207
215
  }
208
216
  async function tt(t, i) {
209
- await n(a)?.scrollToField(t, i);
217
+ await n(c)?.scrollToField(t, i);
210
218
  }
211
- async function $(t) {
212
- const { autoCleanErrorMessage: i, watchDataIsChange: s } = n(y);
213
- t && t.preventDefault(), i && await B();
214
- const { submitFunc: l, beforeSubmitFunc: f } = n(y);
215
- if (f && j(f) && await f(), l && j(l)) {
219
+ async function U(t) {
220
+ const { autoCleanErrorMessage: i, watchDataIsChange: s } = n(v);
221
+ t && t.preventDefault(), i && await C();
222
+ const { submitFunc: l, beforeSubmitFunc: a } = n(v);
223
+ if (a && m(a) && await a(), l && m(l)) {
216
224
  await l();
217
225
  return;
218
226
  }
219
- if (n(a))
227
+ if (n(c))
220
228
  try {
221
- const e = await N(), u = D(e);
229
+ if (!await $())
230
+ return;
231
+ const u = g();
222
232
  if (s) {
223
- const b = ct(_.value, u), C = nt(_.value, u);
224
- h("submit", u, !b, C);
233
+ const b = at(T.value, u), j = nt(T.value, u);
234
+ h("submit", u, !b, j);
225
235
  } else
226
236
  h("submit", u);
227
237
  } catch (e) {
@@ -231,21 +241,21 @@ function Dt({
231
241
  }
232
242
  }
233
243
  return {
234
- handleSubmit: $,
235
- clearValidate: B,
236
- validate: N,
237
- validateField: q,
238
- getFieldsValue: T,
244
+ handleSubmit: U,
245
+ clearValidate: C,
246
+ validate: $,
247
+ validateField: N,
248
+ getFieldsValue: g,
239
249
  updateSchema: R,
240
250
  resetSchema: K,
241
251
  appendSchemaByField: L,
242
252
  removeSchemaByField: Y,
243
253
  resetFields: X,
244
- setFieldsValue: m,
254
+ setFieldsValue: q,
245
255
  scrollToField: tt,
246
256
  getFieldValue: k
247
257
  };
248
258
  }
249
259
  export {
250
- Dt as useFormEvents
260
+ wt as useFormEvents
251
261
  };
@@ -1,6 +1,6 @@
1
1
  declare const _default: {
2
2
  "name": "vft",
3
- "version": "0.0.340",
3
+ "version": "0.0.343",
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.343";
2
2
  export {
3
3
  o as version
4
4
  };
@@ -24,12 +24,12 @@ export declare const VftButton: import("vft/es/utils").SFCWithInstall<{
24
24
  size: {
25
25
  type: import("vue").PropType<import("../types").ComponentSize>;
26
26
  };
27
- icon: {
28
- type: import("vue").PropType<string | import("vft/es/vft").IconProps>;
29
- };
30
27
  dark: {
31
28
  type: import("vue").PropType<boolean>;
32
29
  };
30
+ icon: {
31
+ type: import("vue").PropType<string | import("vft/es/vft").IconProps>;
32
+ };
33
33
  loading: {
34
34
  type: import("vue").PropType<boolean>;
35
35
  };
@@ -114,12 +114,12 @@ export declare const VftButton: import("vft/es/utils").SFCWithInstall<{
114
114
  size: {
115
115
  type: import("vue").PropType<import("../types").ComponentSize>;
116
116
  };
117
- icon: {
118
- type: import("vue").PropType<string | import("vft/es/vft").IconProps>;
119
- };
120
117
  dark: {
121
118
  type: import("vue").PropType<boolean>;
122
119
  };
120
+ icon: {
121
+ type: import("vue").PropType<string | import("vft/es/vft").IconProps>;
122
+ };
123
123
  loading: {
124
124
  type: import("vue").PropType<boolean>;
125
125
  };
@@ -199,12 +199,12 @@ export declare const VftButton: import("vft/es/utils").SFCWithInstall<{
199
199
  size: {
200
200
  type: import("vue").PropType<import("../types").ComponentSize>;
201
201
  };
202
- icon: {
203
- type: import("vue").PropType<string | import("vft/es/vft").IconProps>;
204
- };
205
202
  dark: {
206
203
  type: import("vue").PropType<boolean>;
207
204
  };
205
+ icon: {
206
+ type: import("vue").PropType<string | import("vft/es/vft").IconProps>;
207
+ };
208
208
  loading: {
209
209
  type: import("vue").PropType<boolean>;
210
210
  };
@@ -32,10 +32,10 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
32
32
  }>>> & Readonly<{
33
33
  "onUpdate:error"?: ((val: string) => any) | undefined;
34
34
  }>, {
35
- required: boolean;
36
35
  labelWidth: string | number;
37
36
  inlineMessage: string | boolean;
38
37
  showMessage: boolean;
38
+ required: boolean;
39
39
  hideLabel: boolean;
40
40
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
41
41
  declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
@@ -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;