vft 0.0.358 → 0.0.359
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/es/components/super-form/use/use-form-events.js +43 -41
- package/es/package.json.d.ts +1 -1
- package/es/package.json.js +1 -1
- package/lib/components/super-form/use/use-form-events.cjs +1 -1
- package/lib/package.json.cjs +1 -1
- package/lib/package.json.d.ts +1 -1
- package/package.json +4 -4
- package/web-types.json +1 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { isDef as
|
|
2
|
-
import { formatToDate as
|
|
1
|
+
import { isDef as J, isFunction as j, isString as A, isObject as V, isArray as I, deepMerge as nt, findDifferentValuesForObj as rt, isNullOrUndefined as Q, isEmpty as st, isEmptyObject as lt } from "@vft/utils";
|
|
2
|
+
import { formatToDate as W } from "@vft/utils/date";
|
|
3
3
|
import { get as ot, cloneDeep as m, uniqBy as at, isEqual as ct, set as X } from "lodash-es";
|
|
4
|
-
import {
|
|
5
|
-
import { isInput as ft, FormCompEnum as
|
|
4
|
+
import { nextTick as x, unref as n, toRaw as S } from "vue";
|
|
5
|
+
import { isInput as ft, FormCompEnum as _, isDatePicker as ut } from "../component-map.js";
|
|
6
6
|
import { handleInputNumberValue as dt } from "./helper.js";
|
|
7
|
-
function
|
|
7
|
+
function T(h, y) {
|
|
8
8
|
const { show: o, ifShow: c } = h;
|
|
9
9
|
let p = !0, f = !0;
|
|
10
10
|
return typeof o == "boolean" ? p = o : typeof o == "function" && (p = o({
|
|
@@ -62,7 +62,7 @@ function Et({
|
|
|
62
62
|
formElRef: f,
|
|
63
63
|
schemaRef: F,
|
|
64
64
|
handleFormValues: B,
|
|
65
|
-
initValues:
|
|
65
|
+
initValues: q
|
|
66
66
|
}) {
|
|
67
67
|
async function Y(t) {
|
|
68
68
|
const { resetFunc: e, submitOnReset: s } = n(y);
|
|
@@ -74,10 +74,10 @@ function Et({
|
|
|
74
74
|
Object.keys(o).forEach((a) => {
|
|
75
75
|
const l = n(c).find((u) => u.field === a), i = m(p.value[a]);
|
|
76
76
|
o[a] = ft(l?.type) ? i || "" : i;
|
|
77
|
-
}),
|
|
77
|
+
}), x(() => D()), h("reset", S(o)), s && await z();
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
-
async function
|
|
80
|
+
async function N(t, e = !0) {
|
|
81
81
|
const s = n(c).map((i) => i.field).filter(Boolean), r = ".", a = s.filter(
|
|
82
82
|
(i) => String(i).indexOf(r) >= 0
|
|
83
83
|
), l = [];
|
|
@@ -86,20 +86,20 @@ function Et({
|
|
|
86
86
|
let b = ot(t, i);
|
|
87
87
|
const C = Reflect.has(t, i);
|
|
88
88
|
b = dt(u?.type, b);
|
|
89
|
-
const { componentProps:
|
|
90
|
-
let w =
|
|
91
|
-
typeof
|
|
92
|
-
const
|
|
93
|
-
if (C ||
|
|
94
|
-
const d =
|
|
89
|
+
const { componentProps: G } = u || {};
|
|
90
|
+
let w = G;
|
|
91
|
+
typeof G == "function" && (w = w({ formModel: n(o) }));
|
|
92
|
+
const H = ht(i, t) || pt(i, t);
|
|
93
|
+
if (C || H) {
|
|
94
|
+
const d = H || b;
|
|
95
95
|
if (M(i))
|
|
96
96
|
if (Array.isArray(d)) {
|
|
97
97
|
const v = [];
|
|
98
98
|
for (const E of d)
|
|
99
|
-
v.push(E ?
|
|
99
|
+
v.push(E ? W(E) : null);
|
|
100
100
|
n(o)[i] = v;
|
|
101
101
|
} else
|
|
102
|
-
n(o)[i] = d ? w?.valueFormat ? d :
|
|
102
|
+
n(o)[i] = d ? w?.valueFormat ? d : W(d) : null;
|
|
103
103
|
else
|
|
104
104
|
n(o)[i] = d;
|
|
105
105
|
w?.onChange && w?.onChange(d), l.push(i);
|
|
@@ -107,15 +107,15 @@ function Et({
|
|
|
107
107
|
a.forEach((d) => {
|
|
108
108
|
try {
|
|
109
109
|
const v = d.split(".").reduce((E, it) => E[it], t);
|
|
110
|
-
|
|
110
|
+
J(v) && (n(o)[d] = n(v), l.push(d));
|
|
111
111
|
} catch {
|
|
112
|
-
|
|
112
|
+
J(p.value[d]) && (n(o)[d] = m(
|
|
113
113
|
n(p.value[d])
|
|
114
114
|
));
|
|
115
115
|
}
|
|
116
116
|
});
|
|
117
|
-
}), e &&
|
|
118
|
-
await
|
|
117
|
+
}), e && x(async () => {
|
|
118
|
+
await P(l).catch((i) => {
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
121
|
}
|
|
@@ -146,7 +146,7 @@ function Et({
|
|
|
146
146
|
async function R(t) {
|
|
147
147
|
let e = [];
|
|
148
148
|
if (V(t) && e.push(t), I(t) && (e = [...t]), !e.every(
|
|
149
|
-
(r) => r.type ===
|
|
149
|
+
(r) => r.type === _.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"
|
|
@@ -155,10 +155,10 @@ function Et({
|
|
|
155
155
|
}
|
|
156
156
|
F.value = e;
|
|
157
157
|
}
|
|
158
|
-
async function
|
|
158
|
+
async function $(t) {
|
|
159
159
|
let e = [];
|
|
160
160
|
if (V(t) && e.push(t), I(t) && (e = [...t]), !e.every(
|
|
161
|
-
(l) => l.type ===
|
|
161
|
+
(l) => l.type === _.DIVIDER || Reflect.has(l, "field") && l.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"
|
|
@@ -184,42 +184,44 @@ function Et({
|
|
|
184
184
|
V(t) && r.push(t), I(t) && (r = [...t]);
|
|
185
185
|
const a = {}, l = g();
|
|
186
186
|
r.forEach((i) => {
|
|
187
|
-
i.type !==
|
|
188
|
-
}), lt(a) ||
|
|
187
|
+
i.type !== _.DIVIDER && Reflect.has(i, "field") && i.field && !Q(i.defaultValue) && (!(i.field in l) || Q(l[i.field]) || st(l[i.field])) && (a[i.field] = i.defaultValue);
|
|
188
|
+
}), lt(a) || N(a, s);
|
|
189
189
|
}
|
|
190
190
|
function g(t = !1) {
|
|
191
191
|
if (!n(f)) return {};
|
|
192
|
-
const s = B(
|
|
192
|
+
const s = B(S(n(o)));
|
|
193
193
|
if (t)
|
|
194
194
|
return s;
|
|
195
|
-
const r = n(c).filter((l) =>
|
|
195
|
+
const r = n(c).filter((l) => T(l, n(o))).map((l) => l.field).filter(Boolean), a = {};
|
|
196
196
|
return r.forEach((l) => {
|
|
197
197
|
l in s && (a[l] = s[l]);
|
|
198
198
|
}), a;
|
|
199
199
|
}
|
|
200
200
|
function k(t) {
|
|
201
|
-
return n(f) ?
|
|
201
|
+
return n(f) ? S(n(o))[t] : {};
|
|
202
202
|
}
|
|
203
203
|
function M(t) {
|
|
204
204
|
return n(c).some((e) => e.field === t ? ut(e.type) : !1);
|
|
205
205
|
}
|
|
206
|
-
async function $(t) {
|
|
207
|
-
return t || (t = n(c).filter((s) => _(s, n(o))).map((s) => s.field).filter(Boolean)), n(f)?.validateField(t);
|
|
208
|
-
}
|
|
209
206
|
async function P(t) {
|
|
210
|
-
return t || (t = n(c).filter((s) =>
|
|
207
|
+
return t || (t = n(c).filter((s) => T(s, n(o))).map((s) => s.field).filter(Boolean)), n(f)?.validateField(t);
|
|
208
|
+
}
|
|
209
|
+
async function U(t) {
|
|
210
|
+
return t || (t = n(c).filter((s) => T(s, n(o))).map((s) => s.field).filter(Boolean)), await n(f)?.validate(t, () => {
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
213
|
async function D(t) {
|
|
214
214
|
await n(f)?.clearValidate(t);
|
|
215
215
|
}
|
|
216
216
|
async function tt(t, e) {
|
|
217
|
-
await D(t), await
|
|
217
|
+
await D(t), await x(async () => {
|
|
218
|
+
await $([{ field: t, itemProps: { error: e } }]);
|
|
219
|
+
});
|
|
218
220
|
}
|
|
219
221
|
async function et(t, e) {
|
|
220
222
|
await n(f)?.scrollToField(t, e);
|
|
221
223
|
}
|
|
222
|
-
async function
|
|
224
|
+
async function z(t) {
|
|
223
225
|
const { autoCleanErrorMessage: e, watchDataIsChange: s } = n(y);
|
|
224
226
|
t && t.preventDefault(), e && await D();
|
|
225
227
|
const { submitFunc: r, beforeSubmitFunc: a } = n(y);
|
|
@@ -229,11 +231,11 @@ function Et({
|
|
|
229
231
|
}
|
|
230
232
|
if (n(f))
|
|
231
233
|
try {
|
|
232
|
-
if (!await
|
|
234
|
+
if (!await U())
|
|
233
235
|
return;
|
|
234
236
|
const u = g();
|
|
235
237
|
if (s) {
|
|
236
|
-
const b = ct(
|
|
238
|
+
const b = ct(q.value, u), C = rt(q.value, u);
|
|
237
239
|
h("submit", u, !b, C);
|
|
238
240
|
} else
|
|
239
241
|
h("submit", u);
|
|
@@ -244,17 +246,17 @@ function Et({
|
|
|
244
246
|
}
|
|
245
247
|
}
|
|
246
248
|
return {
|
|
247
|
-
handleSubmit:
|
|
249
|
+
handleSubmit: z,
|
|
248
250
|
clearValidate: D,
|
|
249
|
-
validate:
|
|
250
|
-
validateField:
|
|
251
|
+
validate: U,
|
|
252
|
+
validateField: P,
|
|
251
253
|
getFieldsValue: g,
|
|
252
|
-
updateSchema:
|
|
254
|
+
updateSchema: $,
|
|
253
255
|
resetSchema: R,
|
|
254
256
|
appendSchemaByField: K,
|
|
255
257
|
removeSchemaByField: Z,
|
|
256
258
|
resetFields: Y,
|
|
257
|
-
setFieldsValue:
|
|
259
|
+
setFieldsValue: N,
|
|
258
260
|
scrollToField: et,
|
|
259
261
|
getFieldValue: k,
|
|
260
262
|
setFormItemError: tt
|
package/es/package.json.d.ts
CHANGED
package/es/package.json.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@vft/utils"),U=require("@vft/utils/date"),b=require("lodash-es"),i=require("vue"),V=require("../component-map.cjs"),L=require("./helper.cjs");function C(p,F){const{show:l,ifShow:o}=p;let y=!0,c=!0;return typeof l=="boolean"?y=l:typeof l=="function"&&(y=l({field:p.field,model:F,values:{...F},schema:p})),typeof o=="boolean"?c=o:typeof o=="function"&&(c=o({field:p.field,model:F,values:{...F},schema:p})),y&&c}function K(p,F={}){const l=/^\[(.+)\]$/;if(l.test(p)){const o=p.match(l);if(o&&o[1]){const y=o[1].split(",");if(!y.length)return;const c=[];return y.forEach((v,g)=>{b.set(c,g,F[v.trim()])}),c.filter(Boolean).length?c:void 0}}}function R(p,F={}){const l=/^\{(.+)\}$/;if(l.test(p)){const o=p.match(l);if(o&&o[1]){const y=o[1].split(",");if(!y.length)return;const c={};return y.forEach(v=>{b.set(c,v.trim(),F[v.trim()])}),Object.values(c).filter(Boolean).length?c:void 0}}}function k({emit:p,getProps:F,formModel:l,getSchema:o,defaultValueRef:y,formElRef:c,schemaRef:v,handleFormValues:g,initValues:S}){async function $(e){const{resetFunc:n,submitOnReset:s}=i.unref(F);n&&a.isFunction(n)&&await n();const r=i.unref(c);if(r){if(e?.length)return r.resetFields(e);Object.keys(l).forEach(f=>{const u=i.unref(o).find(d=>d.field===f),t=b.cloneDeep(y.value[f]);l[f]=V.isInput(u?.type)?t||"":t}),i.nextTick(()=>O()),p("reset",i.toRaw(l)),s&&await _()}}async function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@vft/utils"),U=require("@vft/utils/date"),b=require("lodash-es"),i=require("vue"),V=require("../component-map.cjs"),L=require("./helper.cjs");function C(p,F){const{show:l,ifShow:o}=p;let y=!0,c=!0;return typeof l=="boolean"?y=l:typeof l=="function"&&(y=l({field:p.field,model:F,values:{...F},schema:p})),typeof o=="boolean"?c=o:typeof o=="function"&&(c=o({field:p.field,model:F,values:{...F},schema:p})),y&&c}function K(p,F={}){const l=/^\[(.+)\]$/;if(l.test(p)){const o=p.match(l);if(o&&o[1]){const y=o[1].split(",");if(!y.length)return;const c=[];return y.forEach((v,g)=>{b.set(c,g,F[v.trim()])}),c.filter(Boolean).length?c:void 0}}}function R(p,F={}){const l=/^\{(.+)\}$/;if(l.test(p)){const o=p.match(l);if(o&&o[1]){const y=o[1].split(",");if(!y.length)return;const c={};return y.forEach(v=>{b.set(c,v.trim(),F[v.trim()])}),Object.values(c).filter(Boolean).length?c:void 0}}}function k({emit:p,getProps:F,formModel:l,getSchema:o,defaultValueRef:y,formElRef:c,schemaRef:v,handleFormValues:g,initValues:S}){async function $(e){const{resetFunc:n,submitOnReset:s}=i.unref(F);n&&a.isFunction(n)&&await n();const r=i.unref(c);if(r){if(e?.length)return r.resetFields(e);Object.keys(l).forEach(f=>{const u=i.unref(o).find(d=>d.field===f),t=b.cloneDeep(y.value[f]);l[f]=V.isInput(u?.type)?t||"":t}),i.nextTick(()=>O()),p("reset",i.toRaw(l)),s&&await _()}}async function T(e,n=!0){const s=i.unref(o).map(t=>t.field).filter(Boolean),r=".",f=s.filter(t=>String(t).indexOf(r)>=0),u=[];s.forEach(t=>{const d=i.unref(o).find(h=>h.field===t);let w=b.get(e,t);const B=Reflect.has(e,t);w=L.handleInputNumberValue(d?.type,w);const{componentProps:N}=d||{};let E=N;typeof N=="function"&&(E=E({formModel:i.unref(l)}));const P=K(t,e)||R(t,e);if(B||P){const h=P||w;if(W(t))if(Array.isArray(h)){const D=[];for(const I of h)D.push(I?U.formatToDate(I):null);i.unref(l)[t]=D}else i.unref(l)[t]=h?E?.valueFormat?h:U.formatToDate(h):null;else i.unref(l)[t]=h;E?.onChange&&E?.onChange(h),u.push(t)}else f.forEach(h=>{try{const D=h.split(".").reduce((I,Z)=>I[Z],e);a.isDef(D)&&(i.unref(l)[h]=i.unref(D),u.push(h))}catch{a.isDef(y.value[h])&&(i.unref(l)[h]=b.cloneDeep(i.unref(y.value[h])))}})}),n&&i.nextTick(async()=>{await q(u).catch(t=>{})})}async function z(e){const n=b.cloneDeep(i.unref(o));if(!e)return;let s=a.isString(e)?[e]:e;a.isString(e)&&(s=[e]);for(const r of s)G(r,n);v.value=n}function G(e,n){if(a.isString(e)){const s=n.findIndex(r=>r.field===e);s!==-1&&(delete l[e],n.splice(s,1))}}async function H(e,n,s=!1){const r=b.cloneDeep(i.unref(o)),f=r.findIndex(t=>t.field===n),u=a.isObject(e)?[e]:e;if(!n||f===-1||s){s?r.unshift(...u):r.push(...u),v.value=r,j(e);return}f!==-1&&r.splice(f+1,0,...u),j(e),v.value=r}async function J(e){let n=[];if(a.isObject(e)&&n.push(e),a.isArray(e)&&(n=[...e]),!n.every(r=>r.type===V.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=n}async function m(e){let n=[];if(a.isObject(e)&&n.push(e),a.isArray(e)&&(n=[...e]),!n.every(u=>u.type===V.FormCompEnum.DIVIDER||Reflect.has(u,"field")&&u.field)){console.error("All children of the form Schema array that need to be updated must contain the `field` field");return}const r=[],f=[];i.unref(o).forEach(u=>{let t;if(n.forEach(d=>{u.field===d.field&&(t=d),d.defaultValue&&d.field&&r.push(d.field)}),t!==void 0&&u.field===t.field){const d=a.deepMerge(u,t);f.push(d)}else f.push(u)}),j(f,r),v.value=b.uniqBy(f,"field")}function j(e,n,s=!0){if(a.isArray(n)&&n?.length===0)return;let r=[];a.isObject(e)&&r.push(e),a.isArray(e)&&(r=[...e]);const f={},u=A();r.forEach(t=>{t.type!==V.FormCompEnum.DIVIDER&&Reflect.has(t,"field")&&t.field&&!a.isNullOrUndefined(t.defaultValue)&&(!(t.field in u)||a.isNullOrUndefined(u[t.field])||a.isEmpty(u[t.field]))&&(f[t.field]=t.defaultValue)}),a.isEmptyObject(f)||T(f,s)}function A(e=!1){if(!i.unref(c))return{};const s=g(i.toRaw(i.unref(l)));if(e)return s;const r=i.unref(o).filter(u=>C(u,i.unref(l))).map(u=>u.field).filter(Boolean),f={};return r.forEach(u=>{u in s&&(f[u]=s[u])}),f}function Q(e){return i.unref(c)?i.toRaw(i.unref(l))[e]:{}}function W(e){return i.unref(o).some(n=>n.field===e?V.isDatePicker(n.type):!1)}async function q(e){return e||(e=i.unref(o).filter(s=>C(s,i.unref(l))).map(s=>s.field).filter(Boolean)),i.unref(c)?.validateField(e)}async function x(e){return e||(e=i.unref(o).filter(s=>C(s,i.unref(l))).map(s=>s.field).filter(Boolean)),await i.unref(c)?.validate(e,()=>{})}async function O(e){await i.unref(c)?.clearValidate(e)}async function X(e,n){await O(e),await i.nextTick(async()=>{await m([{field:e,itemProps:{error:n}}])})}async function Y(e,n){await i.unref(c)?.scrollToField(e,n)}async function _(e){const{autoCleanErrorMessage:n,watchDataIsChange:s}=i.unref(F);e&&e.preventDefault(),n&&await O();const{submitFunc:r,beforeSubmitFunc:f}=i.unref(F);if(f&&a.isFunction(f)&&await f(),r&&a.isFunction(r)){await r();return}if(i.unref(c))try{if(!await x())return;const d=A();if(s){const w=b.isEqual(S.value,d),B=a.findDifferentValuesForObj(S.value,d);p("submit",d,!w,B)}else p("submit",d)}catch(t){if(t?.outOfDate===!1&&t?.errorFields)return;throw new Error(t.message)}}return{handleSubmit:_,clearValidate:O,validate:x,validateField:q,getFieldsValue:A,updateSchema:m,resetSchema:J,appendSchemaByField:H,removeSchemaByField:z,resetFields:$,setFieldsValue:T,scrollToField:Y,getFieldValue:Q,setFormItemError:X}}exports.useFormEvents=k;
|
package/lib/package.json.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.0.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.0.359";exports.version=e;
|
package/lib/package.json.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vft",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.359",
|
|
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/constants": "0.0.72",
|
|
59
|
-
"@vft/store": "0.0.54",
|
|
60
58
|
"@vft/router": "0.0.65",
|
|
59
|
+
"@vft/use": "0.0.76",
|
|
61
60
|
"@vft/utils": "0.0.128",
|
|
62
61
|
"@vft/directives": "0.0.33",
|
|
63
|
-
"@vft/
|
|
62
|
+
"@vft/store": "0.0.54",
|
|
63
|
+
"@vft/constants": "0.0.72"
|
|
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.
|
|
1
|
+
{"$schema":"http://json.schemastore.org/web-types","framework":"vue","name":"vft","version":"0.0.359","js-types-syntax":"typescript","description-markup":"markdown","contributions":{"html":{}}}
|