vuesp-components 1.3.7 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/composables/index.es.js +97 -55
- package/dist/composables/types.d.ts +3 -1
- package/dist/composables/types.d.ts.map +1 -1
- package/dist/composables/useForms.d.ts.map +1 -1
- package/dist/index.es.js +212 -212
- package/dist/types/types.d.ts +1 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1,71 +1,113 @@
|
|
|
1
|
-
import { reactive as
|
|
2
|
-
function
|
|
3
|
-
const { validationSchema:
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { ref as z, reactive as y, watch as B, computed as k } from "vue";
|
|
2
|
+
function I(w) {
|
|
3
|
+
const { validationSchema: l, initialValues: m = {} } = w, d = typeof l == "function", v = z(
|
|
4
|
+
d ? l(m) : l
|
|
5
|
+
), F = (t) => {
|
|
6
|
+
v.value = t;
|
|
7
|
+
const e = Object.keys(t), o = Object.keys(c);
|
|
8
|
+
e.forEach((s) => {
|
|
9
|
+
s in c || (c[s] = m[s] ?? "", a[s] = [], u[s] = !1, i[s] = !1);
|
|
10
|
+
}), o.forEach((s) => {
|
|
11
|
+
e.includes(s) || (delete c[s], delete a[s], delete u[s], delete i[s]);
|
|
12
|
+
}), O();
|
|
13
|
+
}, c = y({}), a = y({}), u = y({}), i = y({}), f = /* @__PURE__ */ new Map(), V = () => {
|
|
14
|
+
Object.keys(v.value).forEach((t) => {
|
|
15
|
+
c[t] = m[t] ?? "", a[t] = [], u[t] = !1, i[t] = !1;
|
|
6
16
|
});
|
|
7
|
-
}, v = (t,
|
|
8
|
-
const
|
|
9
|
-
for (const
|
|
10
|
-
const
|
|
11
|
-
|
|
17
|
+
}, h = () => d ? l(c) : v.value, b = (t, e) => {
|
|
18
|
+
const s = h()[t] || [], n = [];
|
|
19
|
+
for (const r of s) {
|
|
20
|
+
const p = r(e, c);
|
|
21
|
+
p !== !0 && n.push(p);
|
|
12
22
|
}
|
|
13
|
-
return
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
return a[t] = n, n.length === 0;
|
|
24
|
+
}, E = (t, e) => {
|
|
25
|
+
const o = h();
|
|
26
|
+
if (!o[t]) return;
|
|
27
|
+
b(t, e);
|
|
28
|
+
const s = f.get(t);
|
|
29
|
+
s && s.forEach((n) => {
|
|
30
|
+
o[n] && b(n, c[n]);
|
|
31
|
+
});
|
|
32
|
+
}, O = () => {
|
|
33
|
+
f.clear();
|
|
34
|
+
const t = h();
|
|
35
|
+
Object.keys(t).forEach((e) => {
|
|
36
|
+
(t[e] || []).forEach((s) => {
|
|
37
|
+
if (typeof s == "function" && s.name === "sameAs") {
|
|
38
|
+
const n = s.toString().match(/['"](.*?)['"]/);
|
|
39
|
+
if (n) {
|
|
40
|
+
const r = n[1];
|
|
41
|
+
f.has(r) || f.set(r, /* @__PURE__ */ new Set()), f.get(r).add(e);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
}, S = () => {
|
|
47
|
+
const t = h();
|
|
48
|
+
let e = !0;
|
|
49
|
+
return Object.keys(t).forEach((o) => {
|
|
50
|
+
b(o, c[o]) || (e = !1);
|
|
51
|
+
}), e;
|
|
52
|
+
}, D = (t, e = {}) => {
|
|
53
|
+
h()[t] || console.warn(`Field "${t}" not found in current validationSchema`);
|
|
54
|
+
const s = k({
|
|
55
|
+
get: () => c[t],
|
|
56
|
+
set: (r) => {
|
|
57
|
+
c[t] = r, i[t] = !0, E(t, r);
|
|
27
58
|
}
|
|
28
|
-
}),
|
|
29
|
-
var
|
|
30
|
-
const
|
|
31
|
-
errors:
|
|
59
|
+
}), n = k(() => {
|
|
60
|
+
var j;
|
|
61
|
+
const r = {
|
|
62
|
+
errors: a[t] || [],
|
|
32
63
|
touched: u[t] || !1,
|
|
33
|
-
dirty:
|
|
34
|
-
},
|
|
35
|
-
message: (
|
|
36
|
-
onInput: (
|
|
37
|
-
const
|
|
38
|
-
|
|
64
|
+
dirty: i[t] || !1
|
|
65
|
+
}, p = {
|
|
66
|
+
message: (j = a[t]) == null ? void 0 : j[0],
|
|
67
|
+
onInput: (g) => {
|
|
68
|
+
const K = g.target;
|
|
69
|
+
s.value = K.value;
|
|
39
70
|
},
|
|
40
71
|
onBlur: () => {
|
|
41
|
-
u[t] = !0,
|
|
72
|
+
u[t] = !0, E(t, c[t]);
|
|
42
73
|
}
|
|
43
74
|
};
|
|
44
|
-
if (
|
|
45
|
-
const
|
|
46
|
-
return { ...
|
|
75
|
+
if (e.props) {
|
|
76
|
+
const g = e.props(r);
|
|
77
|
+
return { ...p, ...g };
|
|
47
78
|
}
|
|
48
|
-
return
|
|
79
|
+
return p;
|
|
49
80
|
});
|
|
50
|
-
return [
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
81
|
+
return [s, n];
|
|
82
|
+
}, x = (t) => async (e) => {
|
|
83
|
+
e && e.preventDefault();
|
|
84
|
+
const o = h();
|
|
85
|
+
Object.keys(o).forEach((n) => {
|
|
86
|
+
u[n] = !0;
|
|
87
|
+
}), S() && await t(c);
|
|
88
|
+
}, A = () => {
|
|
89
|
+
const t = h();
|
|
90
|
+
Object.keys(t).forEach((e) => {
|
|
91
|
+
c[e] = m[e] || "", a[e] = [], u[e] = !1, i[e] = !1;
|
|
58
92
|
});
|
|
59
93
|
};
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
94
|
+
return V(), O(), d && B(
|
|
95
|
+
() => c,
|
|
96
|
+
() => {
|
|
97
|
+
const t = l(c), e = v.value, o = Object.keys(t), s = Object.keys(e);
|
|
98
|
+
(o.length !== s.length || o.some((n) => !s.includes(n))) && F(t);
|
|
99
|
+
},
|
|
100
|
+
{ deep: !0 }
|
|
101
|
+
), {
|
|
102
|
+
values: c,
|
|
103
|
+
errors: a,
|
|
104
|
+
defineField: D,
|
|
105
|
+
handleSubmit: x,
|
|
106
|
+
resetForm: A,
|
|
107
|
+
validate: S,
|
|
108
|
+
updateSchema: F
|
|
67
109
|
};
|
|
68
110
|
}
|
|
69
111
|
export {
|
|
70
|
-
|
|
112
|
+
I as useForm
|
|
71
113
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Ref, ComputedRef } from 'vue';
|
|
2
2
|
export type Validator = (value: string, values?: Record<string, unknown>) => true | string;
|
|
3
3
|
export type ValidationSchema = Record<string, Validator[]>;
|
|
4
|
+
export type ValidationSchemaFn = (values: Record<string, unknown>) => ValidationSchema;
|
|
4
5
|
export interface FieldState {
|
|
5
6
|
value: string | number;
|
|
6
7
|
errors: string[];
|
|
@@ -22,7 +23,7 @@ export interface FieldContext {
|
|
|
22
23
|
dirty: boolean;
|
|
23
24
|
}
|
|
24
25
|
export interface UseFormOptions {
|
|
25
|
-
validationSchema: ValidationSchema;
|
|
26
|
+
validationSchema: ValidationSchema | ValidationSchemaFn;
|
|
26
27
|
initialValues?: Record<string, unknown>;
|
|
27
28
|
}
|
|
28
29
|
export interface UseFormReturn {
|
|
@@ -32,5 +33,6 @@ export interface UseFormReturn {
|
|
|
32
33
|
handleSubmit: (callback: (values: Record<string, unknown>) => void | Promise<void>) => (event?: Event) => Promise<void>;
|
|
33
34
|
resetForm: () => void;
|
|
34
35
|
validate: () => boolean;
|
|
36
|
+
updateSchema: (newSchema: ValidationSchema) => void;
|
|
35
37
|
}
|
|
36
38
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/composables/types.ts"],"names":[],"mappings":"AAAA,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":"useForms.d.ts","sourceRoot":"","sources":["../../src/composables/useForms.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EAKd,MAAM,qBAAqB,CAAC;AAG7B,wBAAgB,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa,CAuO9D"}
|