vft 0.0.339 → 0.0.340

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