@teamnovu/kit-vue-forms 0.0.4 → 0.0.5
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/components/Field.vue.d.ts +36 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +181 -161
- package/package.json +1 -1
- package/src/index.ts +2 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Form } from '../types/form.ts';
|
|
2
|
+
import { Paths, PickProps } from '../types/util.ts';
|
|
3
|
+
import { UseFieldOptions } from '../composables/useField.ts';
|
|
4
|
+
import { VNodeProps, AllowedComponentProps, ComponentCustomProps, PublicProps, ShallowUnwrapRef, Ref, VNode } from 'vue';
|
|
5
|
+
import { ValidationErrors, ErrorMessage } from '../index.js';
|
|
6
|
+
export interface FieldProps<TPath extends string, TData extends object> extends UseFieldOptions<PickProps<TData, TPath>, TPath> {
|
|
7
|
+
form: Form<TData>;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: <TPath extends Paths<TData>, TData extends object>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
10
|
+
props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>, never> & FieldProps<TPath, TData> & Partial<{}>> & PublicProps;
|
|
11
|
+
expose(exposed: ShallowUnwrapRef<{}>): void;
|
|
12
|
+
attrs: any;
|
|
13
|
+
slots: {
|
|
14
|
+
default?(_: {
|
|
15
|
+
data: Ref<PickProps<TData, TPath>, PickProps<TData, TPath>>;
|
|
16
|
+
path: Ref<TPath, TPath>;
|
|
17
|
+
initialValue: Readonly< Ref<PickProps<TData, TPath>, PickProps<TData, TPath>>>;
|
|
18
|
+
errors: Ref<ValidationErrors>;
|
|
19
|
+
touched: Ref<boolean>;
|
|
20
|
+
dirty: Ref<boolean>;
|
|
21
|
+
setData: (newData: PickProps<TData, TPath>) => void;
|
|
22
|
+
onBlur: () => void;
|
|
23
|
+
onFocus: () => void;
|
|
24
|
+
reset: () => void;
|
|
25
|
+
setErrors: (newErrors: ErrorMessage[]) => void;
|
|
26
|
+
clearErrors: () => void;
|
|
27
|
+
}): any;
|
|
28
|
+
};
|
|
29
|
+
emit: {};
|
|
30
|
+
}>) => VNode & {
|
|
31
|
+
__ctx?: Awaited<typeof __VLS_setup>;
|
|
32
|
+
};
|
|
33
|
+
export default _default;
|
|
34
|
+
type __VLS_PrettifyLocal<T> = {
|
|
35
|
+
[K in keyof T]: T[K];
|
|
36
|
+
} & {};
|
package/dist/index.d.ts
CHANGED
|
@@ -6,3 +6,4 @@ export type { ValidationStrategy, ValidationErrorMessage as ErrorMessage, Valida
|
|
|
6
6
|
export type { DeepPartial } from './utils/type-helpers';
|
|
7
7
|
export type { Form, FormField } from './types/form';
|
|
8
8
|
export type { SplitPath, Paths, PickProps } from './types/util';
|
|
9
|
+
export { default as Field } from './components/Field.vue';
|
package/dist/index.mjs
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var R = (
|
|
4
|
-
import { toValue as
|
|
1
|
+
var q = Object.defineProperty;
|
|
2
|
+
var x = (e, r, t) => r in e ? q(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
|
|
3
|
+
var R = (e, r, t) => x(e, typeof r != "symbol" ? r + "" : r, t);
|
|
4
|
+
import { toValue as K, toRaw as W, computed as d, unref as c, reactive as b, watch as F, toRefs as O, toRef as S, ref as A, isRef as _, getCurrentScope as I, onBeforeUnmount as J, defineComponent as T, renderSlot as B, normalizeProps as G, guardReactiveProps as L } from "vue";
|
|
5
5
|
import "zod";
|
|
6
|
-
function y(
|
|
7
|
-
const r =
|
|
8
|
-
return structuredClone(
|
|
6
|
+
function y(e) {
|
|
7
|
+
const r = K(e), t = W(r);
|
|
8
|
+
return structuredClone(t);
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
return
|
|
10
|
+
function N(e) {
|
|
11
|
+
return e === "" ? [] : e.split(/\s*\.\s*/).filter(Boolean);
|
|
12
12
|
}
|
|
13
|
-
function m(
|
|
14
|
-
return (Array.isArray(r) ? r :
|
|
13
|
+
function m(e, r) {
|
|
14
|
+
return (Array.isArray(r) ? r : N(r)).reduce(
|
|
15
15
|
(a, s) => a == null ? void 0 : a[s],
|
|
16
|
-
|
|
16
|
+
e
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const a = Array.isArray(r) ? r :
|
|
19
|
+
function U(e, r, t) {
|
|
20
|
+
const a = Array.isArray(r) ? r : N(r);
|
|
21
21
|
if (a.length === 0)
|
|
22
22
|
throw new Error("Path cannot be empty");
|
|
23
23
|
const s = a.at(-1), n = a.slice(0, -1).reduce(
|
|
24
24
|
(u, v) => u[v],
|
|
25
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
|
|
26
|
+
e
|
|
27
27
|
);
|
|
28
|
-
n[s] =
|
|
28
|
+
n[s] = t;
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const z = (e, r) => d({
|
|
31
31
|
get() {
|
|
32
|
-
return m(c(
|
|
32
|
+
return m(c(e), c(r));
|
|
33
33
|
},
|
|
34
|
-
set(
|
|
35
|
-
|
|
34
|
+
set(t) {
|
|
35
|
+
U(c(e), c(r), t);
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
function
|
|
39
|
-
return !
|
|
38
|
+
function E(e, r) {
|
|
39
|
+
return !e && !r ? "" : !e && r ? r : !r && e ? e : `${e}.${r}`;
|
|
40
40
|
}
|
|
41
|
-
function
|
|
41
|
+
function Z(e, r) {
|
|
42
42
|
if (!r)
|
|
43
|
-
return
|
|
44
|
-
const
|
|
45
|
-
Object.entries(
|
|
46
|
-
([s, n]) => [s.slice(
|
|
43
|
+
return e;
|
|
44
|
+
const t = `${r}.`, a = Object.fromEntries(
|
|
45
|
+
Object.entries(e.propertyErrors).filter(([s]) => s.startsWith(t)).map(
|
|
46
|
+
([s, n]) => [s.slice(t.length), n]
|
|
47
47
|
)
|
|
48
48
|
);
|
|
49
49
|
return {
|
|
50
|
-
general:
|
|
50
|
+
general: e.general,
|
|
51
51
|
// Keep general errors
|
|
52
52
|
propertyErrors: a
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
const r =
|
|
57
|
-
value:
|
|
58
|
-
path:
|
|
59
|
-
initialValue: d(() => Object.freeze(y(
|
|
60
|
-
errors: c(
|
|
55
|
+
function k(e) {
|
|
56
|
+
const r = b({
|
|
57
|
+
value: e.value,
|
|
58
|
+
path: e.path,
|
|
59
|
+
initialValue: d(() => Object.freeze(y(e.initialValue))),
|
|
60
|
+
errors: c(e.errors) || [],
|
|
61
61
|
touched: !1
|
|
62
62
|
});
|
|
63
|
-
|
|
63
|
+
F(() => c(e.errors), (f) => {
|
|
64
64
|
r.errors = f || [];
|
|
65
65
|
});
|
|
66
|
-
const
|
|
66
|
+
const t = d(() => JSON.stringify(r.value) !== JSON.stringify(r.initialValue)), a = (f) => {
|
|
67
67
|
r.value = f;
|
|
68
68
|
}, s = () => {
|
|
69
69
|
r.touched = !0;
|
|
@@ -74,14 +74,14 @@ function U(t) {
|
|
|
74
74
|
r.errors = f;
|
|
75
75
|
}, o = () => {
|
|
76
76
|
r.errors = [];
|
|
77
|
-
}, l =
|
|
77
|
+
}, l = O(r);
|
|
78
78
|
return {
|
|
79
79
|
data: l.value,
|
|
80
80
|
path: l.path,
|
|
81
81
|
initialValue: l.initialValue,
|
|
82
82
|
errors: l.errors,
|
|
83
83
|
touched: l.touched,
|
|
84
|
-
dirty:
|
|
84
|
+
dirty: t,
|
|
85
85
|
setData: a,
|
|
86
86
|
onBlur: s,
|
|
87
87
|
onFocus: n,
|
|
@@ -90,8 +90,8 @@ function U(t) {
|
|
|
90
90
|
clearErrors: o
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
function
|
|
94
|
-
const r = {},
|
|
93
|
+
function H(e) {
|
|
94
|
+
const r = {}, t = (u) => {
|
|
95
95
|
const v = c(u.path);
|
|
96
96
|
r[v] = u;
|
|
97
97
|
};
|
|
@@ -99,73 +99,73 @@ function Z(t) {
|
|
|
99
99
|
fields: r,
|
|
100
100
|
getField: (u) => r[u],
|
|
101
101
|
getFields: () => Object.values(r),
|
|
102
|
-
registerField:
|
|
102
|
+
registerField: t,
|
|
103
103
|
defineField: (u) => {
|
|
104
|
-
const v =
|
|
104
|
+
const v = k({
|
|
105
105
|
...u,
|
|
106
|
-
value:
|
|
107
|
-
initialValue: d(() => m(
|
|
106
|
+
value: z(S(e, "data"), u.path),
|
|
107
|
+
initialValue: d(() => m(e.initialData, c(u.path)))
|
|
108
108
|
});
|
|
109
|
-
return
|
|
109
|
+
return t(v), v;
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
112
|
}
|
|
113
|
-
function
|
|
114
|
-
const r = d(() =>
|
|
113
|
+
function Q(e) {
|
|
114
|
+
const r = d(() => e.getFields().some((a) => c(a.dirty))), t = d(() => e.getFields().some((a) => c(a.touched)));
|
|
115
115
|
return {
|
|
116
116
|
isDirty: r,
|
|
117
|
-
isTouched:
|
|
117
|
+
isTouched: t
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
|
-
function
|
|
121
|
-
return
|
|
122
|
-
(r,
|
|
120
|
+
function X(e) {
|
|
121
|
+
return e.filter(
|
|
122
|
+
(r, t, a) => a.indexOf(r) === t
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
|
-
function
|
|
126
|
-
return
|
|
127
|
-
if (!r && !
|
|
125
|
+
function C(...e) {
|
|
126
|
+
return e.slice(1).reduce((r, t) => {
|
|
127
|
+
if (!r && !t)
|
|
128
128
|
return;
|
|
129
|
-
const a = ((
|
|
130
|
-
if (!r && ((
|
|
131
|
-
return
|
|
129
|
+
const a = ((t == null ? void 0 : t.length) ?? 0) > 0;
|
|
130
|
+
if (!r && ((t == null ? void 0 : t.length) ?? 0) > 0)
|
|
131
|
+
return t;
|
|
132
132
|
if (!a)
|
|
133
133
|
return r;
|
|
134
|
-
const s = (r ?? []).concat(
|
|
135
|
-
return
|
|
136
|
-
},
|
|
134
|
+
const s = (r ?? []).concat(t);
|
|
135
|
+
return X(s);
|
|
136
|
+
}, e[0]);
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
return
|
|
140
|
-
const s =
|
|
138
|
+
function Y(...e) {
|
|
139
|
+
return e.map((t) => Object.keys(t)).flat().reduce((t, a) => {
|
|
140
|
+
const s = e.map((n) => n[a]).filter(Boolean);
|
|
141
141
|
return {
|
|
142
|
-
...
|
|
143
|
-
[a]:
|
|
142
|
+
...t,
|
|
143
|
+
[a]: C(...s)
|
|
144
144
|
};
|
|
145
145
|
}, {});
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
if (!
|
|
147
|
+
function D(...e) {
|
|
148
|
+
if (!e.length)
|
|
149
149
|
return {
|
|
150
150
|
general: [],
|
|
151
151
|
propertyErrors: {}
|
|
152
152
|
};
|
|
153
|
-
const r =
|
|
154
|
-
return
|
|
155
|
-
(
|
|
156
|
-
general:
|
|
157
|
-
propertyErrors:
|
|
153
|
+
const r = e[0];
|
|
154
|
+
return e.length === 1 ? r : e.slice(1).reduce(
|
|
155
|
+
(t, a) => ({
|
|
156
|
+
general: C(t.general, a.general),
|
|
157
|
+
propertyErrors: Y(t.propertyErrors ?? {}, a.propertyErrors ?? {})
|
|
158
158
|
}),
|
|
159
159
|
r
|
|
160
160
|
);
|
|
161
161
|
}
|
|
162
|
-
function
|
|
162
|
+
function j(e) {
|
|
163
163
|
var a;
|
|
164
|
-
const r = (((a =
|
|
165
|
-
return r ||
|
|
164
|
+
const r = (((a = e.general) == null ? void 0 : a.length) ?? 0) > 0, t = Object.entries(e.propertyErrors).filter(([, s]) => s == null ? void 0 : s.length).length > 0;
|
|
165
|
+
return r || t;
|
|
166
166
|
}
|
|
167
|
-
function
|
|
168
|
-
const r =
|
|
167
|
+
function rr(e) {
|
|
168
|
+
const r = e.issues.filter((a) => a.path.length === 0).map((a) => a.message), t = e.issues.filter((a) => a.path.length > 0).reduce((a, s) => {
|
|
169
169
|
const n = s.path.join(".");
|
|
170
170
|
return {
|
|
171
171
|
...a,
|
|
@@ -174,27 +174,27 @@ function H(t) {
|
|
|
174
174
|
}, {});
|
|
175
175
|
return {
|
|
176
176
|
general: r,
|
|
177
|
-
propertyErrors:
|
|
177
|
+
propertyErrors: t
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
-
const
|
|
180
|
+
const V = {
|
|
181
181
|
isValid: !0,
|
|
182
182
|
errors: {
|
|
183
183
|
general: [],
|
|
184
184
|
propertyErrors: {}
|
|
185
185
|
}
|
|
186
186
|
};
|
|
187
|
-
class
|
|
187
|
+
class er {
|
|
188
188
|
constructor(r) {
|
|
189
189
|
this.schema = r;
|
|
190
190
|
}
|
|
191
191
|
async validate(r) {
|
|
192
192
|
if (!this.schema)
|
|
193
|
-
return
|
|
194
|
-
const
|
|
195
|
-
if (
|
|
196
|
-
return
|
|
197
|
-
const a =
|
|
193
|
+
return V;
|
|
194
|
+
const t = await this.schema.safeParseAsync(r);
|
|
195
|
+
if (t.success)
|
|
196
|
+
return V;
|
|
197
|
+
const a = rr(t.error);
|
|
198
198
|
return {
|
|
199
199
|
isValid: !1,
|
|
200
200
|
errors: {
|
|
@@ -204,89 +204,89 @@ class Q {
|
|
|
204
204
|
};
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
|
-
class
|
|
207
|
+
class tr {
|
|
208
208
|
constructor(r) {
|
|
209
209
|
this.validateFn = r;
|
|
210
210
|
}
|
|
211
211
|
async validate(r) {
|
|
212
212
|
if (!this.validateFn)
|
|
213
|
-
return
|
|
213
|
+
return V;
|
|
214
214
|
try {
|
|
215
|
-
const
|
|
216
|
-
return
|
|
217
|
-
} catch (
|
|
215
|
+
const t = await this.validateFn(r);
|
|
216
|
+
return t.isValid ? V : t;
|
|
217
|
+
} catch (t) {
|
|
218
218
|
return {
|
|
219
219
|
isValid: !1,
|
|
220
220
|
errors: {
|
|
221
|
-
general: [
|
|
221
|
+
general: [t.message || "Validation error"],
|
|
222
222
|
propertyErrors: {}
|
|
223
223
|
}
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
|
-
class
|
|
229
|
-
constructor(r,
|
|
228
|
+
class ar {
|
|
229
|
+
constructor(r, t) {
|
|
230
230
|
R(this, "schemaValidator");
|
|
231
231
|
R(this, "functionValidator");
|
|
232
|
-
this.schema = r, this.validateFn =
|
|
232
|
+
this.schema = r, this.validateFn = t, this.schemaValidator = new er(this.schema), this.functionValidator = new tr(this.validateFn);
|
|
233
233
|
}
|
|
234
234
|
async validate(r) {
|
|
235
|
-
const [
|
|
235
|
+
const [t, a] = await Promise.all([
|
|
236
236
|
this.schemaValidator.validate(r),
|
|
237
237
|
this.functionValidator.validate(r)
|
|
238
238
|
]);
|
|
239
239
|
return {
|
|
240
|
-
isValid:
|
|
241
|
-
errors:
|
|
240
|
+
isValid: t.isValid && a.isValid,
|
|
241
|
+
errors: D(t.errors, a.errors)
|
|
242
242
|
};
|
|
243
243
|
}
|
|
244
244
|
}
|
|
245
|
-
function
|
|
246
|
-
return d(() => new
|
|
247
|
-
c(
|
|
248
|
-
c(
|
|
245
|
+
function P(e) {
|
|
246
|
+
return d(() => new ar(
|
|
247
|
+
c(e.schema),
|
|
248
|
+
c(e.validateFn)
|
|
249
249
|
));
|
|
250
250
|
}
|
|
251
|
-
function
|
|
252
|
-
const
|
|
253
|
-
validators: A([
|
|
251
|
+
function sr(e, r) {
|
|
252
|
+
const t = b({
|
|
253
|
+
validators: A([P(r)]),
|
|
254
254
|
isValidated: !1,
|
|
255
|
-
errors: c(r.errors) ??
|
|
255
|
+
errors: c(r.errors) ?? V.errors
|
|
256
256
|
});
|
|
257
|
-
|
|
257
|
+
F(() => c(r.errors), async () => {
|
|
258
258
|
const o = await s();
|
|
259
259
|
n(o.errors);
|
|
260
|
-
}, { immediate: !0 }),
|
|
261
|
-
[() =>
|
|
260
|
+
}, { immediate: !0 }), F(
|
|
261
|
+
[() => t.validators],
|
|
262
262
|
async (o) => {
|
|
263
|
-
if (
|
|
263
|
+
if (t.isValidated)
|
|
264
264
|
if (o) {
|
|
265
265
|
const l = await s();
|
|
266
|
-
|
|
266
|
+
t.errors = l.errors;
|
|
267
267
|
} else
|
|
268
|
-
|
|
268
|
+
t.errors = V.errors;
|
|
269
269
|
},
|
|
270
270
|
{ immediate: !0 }
|
|
271
|
-
),
|
|
272
|
-
|
|
271
|
+
), F(() => e.data, () => {
|
|
272
|
+
t.isValidated && u();
|
|
273
273
|
});
|
|
274
274
|
const a = (o) => {
|
|
275
|
-
const l =
|
|
276
|
-
return
|
|
277
|
-
|
|
275
|
+
const l = _(o) ? o : P(o);
|
|
276
|
+
return t.validators.push(l), I() && J(() => {
|
|
277
|
+
t.validators = t.validators.filter(
|
|
278
278
|
(f) => f !== l
|
|
279
279
|
);
|
|
280
280
|
}), l;
|
|
281
281
|
};
|
|
282
282
|
async function s() {
|
|
283
283
|
const o = await Promise.all(
|
|
284
|
-
|
|
285
|
-
), l = o.every((
|
|
286
|
-
let { errors: f } =
|
|
284
|
+
t.validators.filter((p) => c(p) !== void 0).map((p) => c(p).validate(e.data))
|
|
285
|
+
), l = o.every((p) => p.isValid);
|
|
286
|
+
let { errors: f } = V;
|
|
287
287
|
if (!l) {
|
|
288
|
-
const
|
|
289
|
-
f =
|
|
288
|
+
const p = o.map((w) => w.errors);
|
|
289
|
+
f = D(...p);
|
|
290
290
|
}
|
|
291
291
|
return {
|
|
292
292
|
errors: f,
|
|
@@ -294,37 +294,37 @@ function rr(t, r) {
|
|
|
294
294
|
};
|
|
295
295
|
}
|
|
296
296
|
const n = (o) => {
|
|
297
|
-
|
|
297
|
+
t.errors = D(c(r.errors) ?? V.errors, o);
|
|
298
298
|
}, u = async () => {
|
|
299
299
|
const o = await s();
|
|
300
|
-
return n(o.errors),
|
|
301
|
-
isValid: !
|
|
302
|
-
errors:
|
|
300
|
+
return n(o.errors), t.isValidated = !0, {
|
|
301
|
+
isValid: !j(o.errors),
|
|
302
|
+
errors: t.errors
|
|
303
303
|
};
|
|
304
|
-
}, v = d(() => !
|
|
304
|
+
}, v = d(() => !j(t.errors));
|
|
305
305
|
return {
|
|
306
|
-
...
|
|
306
|
+
...O(t),
|
|
307
307
|
validateForm: u,
|
|
308
308
|
defineValidator: a,
|
|
309
309
|
isValid: v
|
|
310
310
|
};
|
|
311
311
|
}
|
|
312
|
-
class
|
|
313
|
-
constructor(r,
|
|
314
|
-
this.path = r, this.validator =
|
|
312
|
+
class ir {
|
|
313
|
+
constructor(r, t) {
|
|
314
|
+
this.path = r, this.validator = t;
|
|
315
315
|
}
|
|
316
316
|
async validate(r) {
|
|
317
|
-
const
|
|
317
|
+
const t = m(r, this.path);
|
|
318
318
|
if (!this.validator)
|
|
319
|
-
return
|
|
320
|
-
const a = await this.validator.validate(
|
|
319
|
+
return V;
|
|
320
|
+
const a = await this.validator.validate(t);
|
|
321
321
|
return {
|
|
322
322
|
isValid: a.isValid,
|
|
323
323
|
errors: {
|
|
324
324
|
general: a.errors.general || [],
|
|
325
325
|
propertyErrors: a.errors.propertyErrors ? Object.fromEntries(
|
|
326
326
|
Object.entries(a.errors.propertyErrors).map(([s, n]) => [
|
|
327
|
-
|
|
327
|
+
E(this.path, s),
|
|
328
328
|
n
|
|
329
329
|
])
|
|
330
330
|
) : {}
|
|
@@ -332,30 +332,30 @@ class tr {
|
|
|
332
332
|
};
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
|
-
function
|
|
336
|
-
const a =
|
|
335
|
+
function nr(e, r, t) {
|
|
336
|
+
const a = z(e.data, r), s = d(() => m(e.initialData.value, r)), n = (i) => ({
|
|
337
337
|
...i,
|
|
338
338
|
path: d(() => c(i.path).replace(r + ".", "")),
|
|
339
339
|
setData: (h) => {
|
|
340
340
|
i.setData(h);
|
|
341
341
|
}
|
|
342
342
|
}), u = (i) => {
|
|
343
|
-
const h =
|
|
343
|
+
const h = E(r, i), g = e.getField(h);
|
|
344
344
|
if (g)
|
|
345
345
|
return n(g);
|
|
346
346
|
}, v = (i) => {
|
|
347
|
-
const h =
|
|
347
|
+
const h = E(r, i.path), g = e.defineField({
|
|
348
348
|
...i,
|
|
349
349
|
path: h
|
|
350
350
|
});
|
|
351
351
|
return n(g);
|
|
352
|
-
}, o = () =>
|
|
352
|
+
}, o = () => e.getFields().filter((i) => {
|
|
353
353
|
const h = i.path.value;
|
|
354
354
|
return h.startsWith(r + ".") || h === r;
|
|
355
|
-
}).map((i) => n(i)), l = () =>
|
|
355
|
+
}).map((i) => n(i)), l = () => e.getFields().filter((i) => {
|
|
356
356
|
const h = i.path.value;
|
|
357
357
|
return h.startsWith(r + ".") || h === r;
|
|
358
|
-
}), f = d(() => l().some((i) => i.dirty.value)),
|
|
358
|
+
}), f = d(() => l().some((i) => i.dirty.value)), p = d(() => l().some((i) => i.touched.value)), w = d(() => e.isValid.value), M = d(() => e.isValidated.value), $ = d(() => Z(c(e.errors), r));
|
|
359
359
|
return {
|
|
360
360
|
data: a,
|
|
361
361
|
initialData: s,
|
|
@@ -363,36 +363,36 @@ function er(t, r, e) {
|
|
|
363
363
|
getField: u,
|
|
364
364
|
getFields: o,
|
|
365
365
|
isDirty: f,
|
|
366
|
-
isTouched:
|
|
366
|
+
isTouched: p,
|
|
367
367
|
isValid: w,
|
|
368
|
-
isValidated:
|
|
369
|
-
errors:
|
|
368
|
+
isValidated: M,
|
|
369
|
+
errors: $,
|
|
370
370
|
defineValidator: (i) => {
|
|
371
|
-
const h =
|
|
372
|
-
() => new
|
|
371
|
+
const h = _(i) ? i : P(i), g = d(
|
|
372
|
+
() => new ir(r, c(h))
|
|
373
373
|
);
|
|
374
|
-
return
|
|
374
|
+
return e.defineValidator(g), h;
|
|
375
375
|
},
|
|
376
376
|
reset: () => l().forEach((i) => i.reset()),
|
|
377
|
-
validateForm: () =>
|
|
377
|
+
validateForm: () => e.validateForm(),
|
|
378
378
|
getSubForm: (i, h) => {
|
|
379
|
-
const g =
|
|
380
|
-
return
|
|
379
|
+
const g = E(r, i);
|
|
380
|
+
return e.getSubForm(
|
|
381
381
|
g,
|
|
382
382
|
h
|
|
383
383
|
);
|
|
384
384
|
}
|
|
385
385
|
};
|
|
386
386
|
}
|
|
387
|
-
function
|
|
388
|
-
const r = d(() => Object.freeze(y(
|
|
387
|
+
function vr(e) {
|
|
388
|
+
const r = d(() => Object.freeze(y(e.initialData))), t = A(y(r)), a = b({
|
|
389
389
|
initialData: r,
|
|
390
|
-
data:
|
|
391
|
-
}), s =
|
|
392
|
-
|
|
390
|
+
data: t
|
|
391
|
+
}), s = H(a), n = sr(a, e), u = Q(s), v = () => {
|
|
392
|
+
t.value = y(r), s.getFields().forEach((f) => f.reset());
|
|
393
393
|
};
|
|
394
|
-
function o(f,
|
|
395
|
-
return
|
|
394
|
+
function o(f, p) {
|
|
395
|
+
return nr(l, f);
|
|
396
396
|
}
|
|
397
397
|
const l = {
|
|
398
398
|
...s,
|
|
@@ -400,12 +400,32 @@ function ur(t) {
|
|
|
400
400
|
...u,
|
|
401
401
|
reset: v,
|
|
402
402
|
getSubForm: o,
|
|
403
|
-
initialData:
|
|
404
|
-
data:
|
|
403
|
+
initialData: S(a, "initialData"),
|
|
404
|
+
data: S(a, "data")
|
|
405
405
|
};
|
|
406
406
|
return l;
|
|
407
407
|
}
|
|
408
|
+
const pr = /* @__PURE__ */ T({
|
|
409
|
+
__name: "Field",
|
|
410
|
+
props: {
|
|
411
|
+
form: {},
|
|
412
|
+
value: {},
|
|
413
|
+
initialValue: {},
|
|
414
|
+
type: {},
|
|
415
|
+
required: {},
|
|
416
|
+
path: {},
|
|
417
|
+
errors: {}
|
|
418
|
+
},
|
|
419
|
+
setup(e) {
|
|
420
|
+
const r = e, t = r.form.defineField({
|
|
421
|
+
path: r.path,
|
|
422
|
+
required: r.required
|
|
423
|
+
});
|
|
424
|
+
return (a, s) => B(a.$slots, "default", G(L(c(t))));
|
|
425
|
+
}
|
|
426
|
+
});
|
|
408
427
|
export {
|
|
409
|
-
|
|
410
|
-
|
|
428
|
+
pr as Field,
|
|
429
|
+
k as useField,
|
|
430
|
+
vr as useForm
|
|
411
431
|
};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED