@foormjs/vue 0.0.2 → 0.0.3
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/index.d.ts +17 -1
- package/dist/index.js +140 -132
- package/dist/index.umd.cjs +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -64,13 +64,16 @@ export declare const OoField: <TFormData, TFormContext>(__VLS_props: any, __VLS_
|
|
|
64
64
|
emit: any;
|
|
65
65
|
}>) => any;
|
|
66
66
|
|
|
67
|
-
export declare const
|
|
67
|
+
export declare const OoForm: <TFormData extends object, TFormContext extends object>(__VLS_props: any, __VLS_ctx?: {
|
|
68
68
|
attrs: any;
|
|
69
69
|
emit: any;
|
|
70
70
|
slots: Partial<Record<`field:${any}`, (_: any) => any>> & {
|
|
71
71
|
"form.header"?(_: {
|
|
72
72
|
clearErrors: any;
|
|
73
73
|
reset: any;
|
|
74
|
+
title: any;
|
|
75
|
+
formContext: any;
|
|
76
|
+
disabled: any;
|
|
74
77
|
}): any;
|
|
75
78
|
"form.before"?(_: {
|
|
76
79
|
clearErrors: any;
|
|
@@ -79,15 +82,20 @@ export declare const OoFoorm: <TFormData extends object, TFormContext extends ob
|
|
|
79
82
|
"form.after"?(_: {
|
|
80
83
|
clearErrors: any;
|
|
81
84
|
reset: any;
|
|
85
|
+
disabled: any;
|
|
86
|
+
formContext: any;
|
|
82
87
|
}): any;
|
|
83
88
|
"form.submit"?(_: {
|
|
84
89
|
disabled: any;
|
|
85
90
|
clearErrors: any;
|
|
86
91
|
reset: any;
|
|
92
|
+
formContext: any;
|
|
87
93
|
}): any;
|
|
88
94
|
"form.footer"?(_: {
|
|
95
|
+
disabled: any;
|
|
89
96
|
clearErrors: any;
|
|
90
97
|
reset: any;
|
|
98
|
+
formContext: any;
|
|
91
99
|
}): any;
|
|
92
100
|
};
|
|
93
101
|
}, __VLS_expose?: (exposed: any) => void, __VLS_setup?: Promise<{
|
|
@@ -98,6 +106,9 @@ export declare const OoFoorm: <TFormData extends object, TFormContext extends ob
|
|
|
98
106
|
"form.header"?(_: {
|
|
99
107
|
clearErrors: any;
|
|
100
108
|
reset: any;
|
|
109
|
+
title: any;
|
|
110
|
+
formContext: any;
|
|
111
|
+
disabled: any;
|
|
101
112
|
}): any;
|
|
102
113
|
"form.before"?(_: {
|
|
103
114
|
clearErrors: any;
|
|
@@ -106,15 +117,20 @@ export declare const OoFoorm: <TFormData extends object, TFormContext extends ob
|
|
|
106
117
|
"form.after"?(_: {
|
|
107
118
|
clearErrors: any;
|
|
108
119
|
reset: any;
|
|
120
|
+
disabled: any;
|
|
121
|
+
formContext: any;
|
|
109
122
|
}): any;
|
|
110
123
|
"form.submit"?(_: {
|
|
111
124
|
disabled: any;
|
|
112
125
|
clearErrors: any;
|
|
113
126
|
reset: any;
|
|
127
|
+
formContext: any;
|
|
114
128
|
}): any;
|
|
115
129
|
"form.footer"?(_: {
|
|
130
|
+
disabled: any;
|
|
116
131
|
clearErrors: any;
|
|
117
132
|
reset: any;
|
|
133
|
+
formContext: any;
|
|
118
134
|
}): any;
|
|
119
135
|
};
|
|
120
136
|
emit: any;
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { defineComponent as q, mergeModels as I, useModel as L, inject as O, ref as k, computed as
|
|
2
|
-
function
|
|
1
|
+
import { defineComponent as q, mergeModels as I, useModel as L, inject as O, ref as k, computed as i, watch as R, onUnmounted as T, getCurrentInstance as N, renderSlot as _, unref as x, provide as W, openBlock as p, createElementBlock as V, withModifiers as G, nextTick as J, createBlock as B, withCtx as w, toDisplayString as h, createCommentVNode as j, Fragment as K, renderList as Q, normalizeProps as A, guardReactiveProps as M, resolveDynamicComponent as F, mergeProps as H, normalizeClass as X, createElementVNode as $, withDirectives as Y, vModelDynamic as Z } from "vue";
|
|
2
|
+
function C(n, r) {
|
|
3
3
|
return U(n) ? n(r) : n;
|
|
4
4
|
}
|
|
5
5
|
function S(n, r) {
|
|
6
6
|
if (typeof n == "object" && n !== null) {
|
|
7
7
|
const o = {};
|
|
8
|
-
for (const [t,
|
|
9
|
-
o[t] =
|
|
8
|
+
for (const [t, m] of Object.entries(n))
|
|
9
|
+
o[t] = C(m, r);
|
|
10
10
|
return o;
|
|
11
11
|
}
|
|
12
12
|
return U(n) ? n(r) : n;
|
|
@@ -24,70 +24,70 @@ const ee = /* @__PURE__ */ q({
|
|
|
24
24
|
}),
|
|
25
25
|
emits: ["update:modelValue"],
|
|
26
26
|
setup(n) {
|
|
27
|
-
const r = n, o = L(n, "modelValue"), t = O("vuiless"),
|
|
27
|
+
const r = n, o = L(n, "modelValue"), t = O("vuiless"), m = k(), d = k(!1), b = k(!1), v = i(() => {
|
|
28
28
|
var a;
|
|
29
29
|
if ((a = t == null ? void 0 : t.value) != null && a.firstValidation)
|
|
30
30
|
switch (t.value.firstValidation) {
|
|
31
31
|
case "on-change":
|
|
32
32
|
return t.value.firstSubmitHappened || d.value;
|
|
33
33
|
case "touched-on-blur":
|
|
34
|
-
return t.value.firstSubmitHappened ||
|
|
34
|
+
return t.value.firstSubmitHappened || b.value && d.value;
|
|
35
35
|
case "on-blur":
|
|
36
|
-
return t.value.firstSubmitHappened ||
|
|
36
|
+
return t.value.firstSubmitHappened || b.value;
|
|
37
37
|
case "on-submit":
|
|
38
38
|
return t.value.firstSubmitHappened;
|
|
39
39
|
case "none":
|
|
40
40
|
return !1;
|
|
41
41
|
}
|
|
42
42
|
return !1;
|
|
43
|
-
}),
|
|
44
|
-
if (
|
|
45
|
-
return
|
|
43
|
+
}), y = i(() => {
|
|
44
|
+
if (v.value || m.value)
|
|
45
|
+
return l();
|
|
46
46
|
});
|
|
47
47
|
R([o], () => {
|
|
48
|
-
|
|
48
|
+
m.value = void 0, d.value = !0;
|
|
49
49
|
}), T(() => {
|
|
50
50
|
var a;
|
|
51
51
|
(a = t == null ? void 0 : t.value) == null || a.unregister(N());
|
|
52
52
|
}), t != null && t.value && t.value.register(N(), {
|
|
53
|
-
validate: () => (
|
|
53
|
+
validate: () => (m.value = l(), m.value || !0),
|
|
54
54
|
clearErrors: () => {
|
|
55
|
-
d.value = !1,
|
|
55
|
+
d.value = !1, b.value = !1, m.value = void 0;
|
|
56
56
|
},
|
|
57
57
|
reset: () => {
|
|
58
58
|
o.value = "";
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
-
function
|
|
62
|
-
var a, e,
|
|
61
|
+
function l() {
|
|
62
|
+
var a, e, f;
|
|
63
63
|
if ((a = r.rules) != null && a.length)
|
|
64
64
|
for (const g of r.rules) {
|
|
65
|
-
const
|
|
65
|
+
const u = g(
|
|
66
66
|
o.value,
|
|
67
67
|
(e = t == null ? void 0 : t.value) == null ? void 0 : e.formData,
|
|
68
|
-
(
|
|
68
|
+
(f = t == null ? void 0 : t.value) == null ? void 0 : f.formContext
|
|
69
69
|
);
|
|
70
|
-
if (
|
|
71
|
-
return
|
|
70
|
+
if (u !== !0)
|
|
71
|
+
return u || "Wrong value";
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
|
|
74
|
+
function c() {
|
|
75
|
+
b.value = !0;
|
|
76
76
|
}
|
|
77
|
-
const
|
|
78
|
-
v:
|
|
77
|
+
const s = {
|
|
78
|
+
v: i({
|
|
79
79
|
get: () => o.value,
|
|
80
80
|
set: (a) => o.value = a
|
|
81
81
|
})
|
|
82
82
|
};
|
|
83
83
|
return (a, e) => {
|
|
84
|
-
var
|
|
85
|
-
return
|
|
86
|
-
onBlur:
|
|
87
|
-
error:
|
|
88
|
-
formData: (
|
|
84
|
+
var f, g;
|
|
85
|
+
return _(a.$slots, "default", {
|
|
86
|
+
onBlur: c,
|
|
87
|
+
error: y.value,
|
|
88
|
+
formData: (f = x(t)) == null ? void 0 : f.formData,
|
|
89
89
|
formContext: (g = x(t)) == null ? void 0 : g.formContext,
|
|
90
|
-
model:
|
|
90
|
+
model: s.v
|
|
91
91
|
});
|
|
92
92
|
};
|
|
93
93
|
}
|
|
@@ -100,41 +100,41 @@ const ee = /* @__PURE__ */ q({
|
|
|
100
100
|
},
|
|
101
101
|
emits: ["submit"],
|
|
102
102
|
setup(n, { emit: r }) {
|
|
103
|
-
const o = n, t = r,
|
|
103
|
+
const o = n, t = r, m = /* @__PURE__ */ new Map(), d = k(!1), b = i(() => ({
|
|
104
104
|
firstSubmitHappened: d.value,
|
|
105
105
|
firstValidation: o.firstValidation,
|
|
106
|
-
register: (
|
|
107
|
-
|
|
106
|
+
register: (c, s) => {
|
|
107
|
+
m.set(c, s);
|
|
108
108
|
},
|
|
109
|
-
unregister: (
|
|
109
|
+
unregister: (c) => m.delete(c),
|
|
110
110
|
formData: o.formData,
|
|
111
111
|
formContext: o.formContext
|
|
112
112
|
}));
|
|
113
|
-
W("vuiless",
|
|
114
|
-
function
|
|
113
|
+
W("vuiless", b);
|
|
114
|
+
function v() {
|
|
115
115
|
d.value = !1;
|
|
116
|
-
for (const { clearErrors:
|
|
117
|
-
|
|
116
|
+
for (const { clearErrors: c } of m.values())
|
|
117
|
+
c();
|
|
118
118
|
}
|
|
119
|
-
async function
|
|
120
|
-
for (const { reset:
|
|
121
|
-
|
|
122
|
-
await J(),
|
|
119
|
+
async function y() {
|
|
120
|
+
for (const { reset: c } of m.values())
|
|
121
|
+
c();
|
|
122
|
+
await J(), v();
|
|
123
123
|
}
|
|
124
|
-
function
|
|
124
|
+
function l() {
|
|
125
125
|
d.value = !0;
|
|
126
|
-
let
|
|
126
|
+
let c = !1;
|
|
127
127
|
if (o.firstValidation !== "none")
|
|
128
|
-
for (const { validate:
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
for (const { validate: s } of m.values())
|
|
129
|
+
s() !== !0 && (c = !0);
|
|
130
|
+
c || t("submit", o.formData);
|
|
131
131
|
}
|
|
132
|
-
return (
|
|
133
|
-
onSubmit: G(
|
|
132
|
+
return (c, s) => (p(), V("form", {
|
|
133
|
+
onSubmit: G(l, ["prevent"])
|
|
134
134
|
}, [
|
|
135
|
-
|
|
136
|
-
clearErrors:
|
|
137
|
-
reset:
|
|
135
|
+
_(c.$slots, "default", {
|
|
136
|
+
clearErrors: v,
|
|
137
|
+
reset: y
|
|
138
138
|
})
|
|
139
139
|
], 32));
|
|
140
140
|
}
|
|
@@ -165,79 +165,79 @@ const ee = /* @__PURE__ */ q({
|
|
|
165
165
|
setup(n) {
|
|
166
166
|
const r = n, o = O(
|
|
167
167
|
"vuiless"
|
|
168
|
-
), t =
|
|
168
|
+
), t = i(
|
|
169
169
|
() => ({
|
|
170
170
|
v: o.value.formData[r.field],
|
|
171
171
|
data: o == null ? void 0 : o.value.formData,
|
|
172
172
|
context: o == null ? void 0 : o.value.formContext,
|
|
173
173
|
entry: r
|
|
174
174
|
})
|
|
175
|
-
),
|
|
176
|
-
const
|
|
177
|
-
return typeof
|
|
178
|
-
[
|
|
179
|
-
disabled:
|
|
175
|
+
), m = i(() => C(r.label, t.value)), d = i(() => C(r.description, t.value)), b = i(() => C(r.hint, t.value)), v = i(() => C(r.placeholder, t.value)), y = i(() => C(r.optional, t.value)), l = i(() => C(r.disabled, t.value)), c = i(() => C(r.hidden, t.value)), s = i(() => C(r.options, t.value)), a = i(() => {
|
|
176
|
+
const u = S(r.classes, t.value);
|
|
177
|
+
return typeof u == "string" ? {
|
|
178
|
+
[u]: !0,
|
|
179
|
+
disabled: l.value,
|
|
180
180
|
// error: !validation.value.passed,
|
|
181
|
-
required: !
|
|
181
|
+
required: !y.value
|
|
182
182
|
} : {
|
|
183
|
-
...
|
|
184
|
-
disabled:
|
|
183
|
+
...u || {},
|
|
184
|
+
disabled: l.value,
|
|
185
185
|
// error: !validation.value.passed,
|
|
186
|
-
required: !
|
|
186
|
+
required: !y.value
|
|
187
187
|
};
|
|
188
|
-
}), e =
|
|
188
|
+
}), e = i(
|
|
189
189
|
() => S(r.styles, t.value)
|
|
190
|
-
),
|
|
191
|
-
var
|
|
192
|
-
return (
|
|
193
|
-
(E) => (
|
|
194
|
-
v:
|
|
190
|
+
), f = i(() => S(r.attrs, t.value)), g = i(() => {
|
|
191
|
+
var u;
|
|
192
|
+
return (u = r.validators) == null ? void 0 : u.map(
|
|
193
|
+
(E) => (D, P, z) => E({
|
|
194
|
+
v: D,
|
|
195
195
|
data: P,
|
|
196
196
|
context: z,
|
|
197
197
|
entry: r
|
|
198
198
|
})
|
|
199
199
|
);
|
|
200
200
|
});
|
|
201
|
-
return (
|
|
201
|
+
return (u, E) => (p(), B(x(ee), {
|
|
202
202
|
modelValue: x(o).formData[r.field],
|
|
203
|
-
"onUpdate:modelValue": E[0] || (E[0] = (
|
|
203
|
+
"onUpdate:modelValue": E[0] || (E[0] = (D) => x(o).formData[r.field] = D),
|
|
204
204
|
rules: g.value
|
|
205
205
|
}, {
|
|
206
|
-
default: w((
|
|
207
|
-
|
|
208
|
-
onBlur:
|
|
209
|
-
error:
|
|
210
|
-
model:
|
|
206
|
+
default: w((D) => [
|
|
207
|
+
_(u.$slots, "default", {
|
|
208
|
+
onBlur: D.onBlur,
|
|
209
|
+
error: D.error,
|
|
210
|
+
model: D.model,
|
|
211
211
|
formData: x(o).formData,
|
|
212
212
|
formContext: x(o).formContext,
|
|
213
|
-
label:
|
|
213
|
+
label: m.value,
|
|
214
214
|
description: d.value,
|
|
215
|
-
hint:
|
|
216
|
-
placeholder:
|
|
215
|
+
hint: b.value,
|
|
216
|
+
placeholder: v.value,
|
|
217
217
|
classes: {
|
|
218
218
|
...a.value,
|
|
219
|
-
error: !!
|
|
219
|
+
error: !!D.error
|
|
220
220
|
},
|
|
221
221
|
styles: e.value,
|
|
222
|
-
optional:
|
|
223
|
-
disabled:
|
|
224
|
-
hidden:
|
|
225
|
-
type:
|
|
226
|
-
altAction:
|
|
227
|
-
component:
|
|
228
|
-
vName:
|
|
229
|
-
field:
|
|
230
|
-
options:
|
|
231
|
-
length:
|
|
232
|
-
required: !
|
|
233
|
-
autocomplete:
|
|
234
|
-
attrs:
|
|
222
|
+
optional: y.value,
|
|
223
|
+
disabled: l.value,
|
|
224
|
+
hidden: c.value,
|
|
225
|
+
type: u.type,
|
|
226
|
+
altAction: u.altAction,
|
|
227
|
+
component: u.component,
|
|
228
|
+
vName: u.name,
|
|
229
|
+
field: u.field,
|
|
230
|
+
options: s.value,
|
|
231
|
+
length: u.length,
|
|
232
|
+
required: !y.value,
|
|
233
|
+
autocomplete: u.autocomplete,
|
|
234
|
+
attrs: f.value
|
|
235
235
|
})
|
|
236
236
|
]),
|
|
237
237
|
_: 3
|
|
238
238
|
}, 8, ["modelValue", "rules"]));
|
|
239
239
|
}
|
|
240
|
-
}), re = { key: 0 }, ae = { key: 1 }, ne = { key: 0 }, le = ["onUpdate:modelValue", "onBlur", "placeholder", "autocomplete", "name", "type"], se = { class: "oo-error-slot" }, ue = { key: 4 }, ie = { key: 5 }, ce = ["disabled"],
|
|
240
|
+
}), re = { key: 0 }, ae = { key: 1 }, ne = { key: 0 }, le = ["onUpdate:modelValue", "onBlur", "placeholder", "autocomplete", "name", "type"], se = { class: "oo-error-slot" }, ue = { key: 4 }, ie = { key: 5 }, ce = ["disabled"], pe = /* @__PURE__ */ q({
|
|
241
241
|
__name: "oo-form",
|
|
242
242
|
props: {
|
|
243
243
|
form: {},
|
|
@@ -249,39 +249,42 @@ const ee = /* @__PURE__ */ q({
|
|
|
249
249
|
},
|
|
250
250
|
emits: ["submit"],
|
|
251
251
|
setup(n, { emit: r }) {
|
|
252
|
-
const o = n, t =
|
|
252
|
+
const o = n, t = i(() => o.form.executable()), m = i(
|
|
253
253
|
() => ({
|
|
254
254
|
v: void 0,
|
|
255
|
-
data:
|
|
255
|
+
data: b.value,
|
|
256
256
|
context: o.formContext,
|
|
257
257
|
entry: o
|
|
258
258
|
})
|
|
259
|
-
), d = k({}),
|
|
260
|
-
() =>
|
|
261
|
-
),
|
|
262
|
-
return (
|
|
263
|
-
"first-validation":
|
|
264
|
-
onSubmit:
|
|
265
|
-
"form-data":
|
|
266
|
-
"form-context":
|
|
259
|
+
), d = k({}), b = i(() => o.formData || d.value), v = i(
|
|
260
|
+
() => C(t.value.submit.disabled, m.value)
|
|
261
|
+
), y = r;
|
|
262
|
+
return (l, c) => (p(), B(x(te), {
|
|
263
|
+
"first-validation": l.firstValidation,
|
|
264
|
+
onSubmit: c[0] || (c[0] = (s) => y("submit", s)),
|
|
265
|
+
"form-data": b.value,
|
|
266
|
+
"form-context": l.formContext
|
|
267
267
|
}, {
|
|
268
|
-
default: w((
|
|
269
|
-
|
|
270
|
-
clearErrors:
|
|
271
|
-
reset:
|
|
268
|
+
default: w((s) => [
|
|
269
|
+
_(l.$slots, "form.header", {
|
|
270
|
+
clearErrors: s.clearErrors,
|
|
271
|
+
reset: s.reset,
|
|
272
|
+
title: t.value.title,
|
|
273
|
+
formContext: l.formContext,
|
|
274
|
+
disabled: v.value
|
|
272
275
|
}, () => [
|
|
273
|
-
t.value.title ? (
|
|
276
|
+
t.value.title ? (p(), V("h2", re, h(t.value.title), 1)) : j("", !0)
|
|
274
277
|
]),
|
|
275
|
-
|
|
276
|
-
clearErrors:
|
|
277
|
-
reset:
|
|
278
|
+
_(l.$slots, "form.before", {
|
|
279
|
+
clearErrors: s.clearErrors,
|
|
280
|
+
reset: s.reset
|
|
278
281
|
}),
|
|
279
|
-
(
|
|
282
|
+
(p(!0), V(K, null, Q(t.value.entries, (a) => (p(), B(oe, A(M(a)), {
|
|
280
283
|
default: w((e) => [
|
|
281
|
-
|
|
282
|
-
var
|
|
284
|
+
_(l.$slots, `field:${e.type}`, A(M(e)), () => {
|
|
285
|
+
var f, g, u;
|
|
283
286
|
return [
|
|
284
|
-
a.component && ((
|
|
287
|
+
a.component && ((f = o.components) != null && f[a.component]) ? (p(), B(F(o.components[a.component]), H({
|
|
285
288
|
key: 0,
|
|
286
289
|
"on-blur": e.onBlur,
|
|
287
290
|
error: e.error,
|
|
@@ -305,7 +308,7 @@ const ee = /* @__PURE__ */ q({
|
|
|
305
308
|
options: e.options,
|
|
306
309
|
length: e.length,
|
|
307
310
|
autocomplete: e.autocomplete
|
|
308
|
-
}, e.attrs), null, 16, ["on-blur", "error", "model", "form-data", "form-context", "label", "description", "hint", "placeholder", "class", "style", "optional", "required", "disabled", "hidden", "type", "alt-action", "name", "field", "options", "length", "autocomplete"])) : a.component && !((g = o.components) != null && g[a.component]) ? (
|
|
311
|
+
}, e.attrs), null, 16, ["on-blur", "error", "model", "form-data", "form-context", "label", "description", "hint", "placeholder", "class", "style", "optional", "required", "disabled", "hidden", "type", "alt-action", "name", "field", "options", "length", "autocomplete"])) : a.component && !((g = o.components) != null && g[a.component]) ? (p(), V("div", ae, " [" + h(e.label) + '] Component "' + h(e.component) + '" not supplied ', 1)) : (u = o.types) != null && u[a.type] ? (p(), B(F(o.types[a.type]), H({
|
|
309
312
|
key: 2,
|
|
310
313
|
"on-blur": e.onBlur,
|
|
311
314
|
error: e.error,
|
|
@@ -329,12 +332,12 @@ const ee = /* @__PURE__ */ q({
|
|
|
329
332
|
options: e.options,
|
|
330
333
|
length: e.length,
|
|
331
334
|
autocomplete: e.autocomplete
|
|
332
|
-
}, e.attrs), null, 16, ["on-blur", "error", "model", "form-data", "form-context", "label", "description", "hint", "placeholder", "class", "style", "optional", "required", "disabled", "hidden", "type", "alt-action", "name", "field", "options", "length", "autocomplete"])) : ["text", "password", "number"].includes(e.type) ? (
|
|
335
|
+
}, e.attrs), null, 16, ["on-blur", "error", "model", "form-data", "form-context", "label", "description", "hint", "placeholder", "class", "style", "optional", "required", "disabled", "hidden", "type", "alt-action", "name", "field", "options", "length", "autocomplete"])) : ["text", "password", "number"].includes(e.type) ? (p(), V("div", {
|
|
333
336
|
key: 3,
|
|
334
337
|
class: X(["oo-default-field", e.classes])
|
|
335
338
|
}, [
|
|
336
|
-
$("label", null,
|
|
337
|
-
e.description ? (
|
|
339
|
+
$("label", null, h(e.label), 1),
|
|
340
|
+
e.description ? (p(), V("span", ne, h(e.description), 1)) : j("", !0),
|
|
338
341
|
Y($("input", {
|
|
339
342
|
"onUpdate:modelValue": (E) => e.model.value = E,
|
|
340
343
|
onBlur: e.onBlur,
|
|
@@ -345,27 +348,32 @@ const ee = /* @__PURE__ */ q({
|
|
|
345
348
|
}, null, 40, le), [
|
|
346
349
|
[Z, e.model.value]
|
|
347
350
|
]),
|
|
348
|
-
$("div", se,
|
|
349
|
-
], 2)) : e.type === "paragraph" ? (
|
|
351
|
+
$("div", se, h(e.error || e.hint), 1)
|
|
352
|
+
], 2)) : e.type === "paragraph" ? (p(), V("p", ue, h(e.description), 1)) : (p(), V("div", ie, " [" + h(e.label) + '] Not supported field type "' + h(e.type) + '" ' + h(e.component), 1))
|
|
350
353
|
];
|
|
351
354
|
})
|
|
352
355
|
]),
|
|
353
356
|
_: 2
|
|
354
357
|
}, 1040))), 256)),
|
|
355
|
-
|
|
356
|
-
clearErrors:
|
|
357
|
-
reset:
|
|
358
|
+
_(l.$slots, "form.after", {
|
|
359
|
+
clearErrors: s.clearErrors,
|
|
360
|
+
reset: s.reset,
|
|
361
|
+
disabled: v.value,
|
|
362
|
+
formContext: l.formContext
|
|
358
363
|
}),
|
|
359
|
-
|
|
360
|
-
disabled:
|
|
361
|
-
clearErrors:
|
|
362
|
-
reset:
|
|
364
|
+
_(l.$slots, "form.submit", {
|
|
365
|
+
disabled: v.value,
|
|
366
|
+
clearErrors: s.clearErrors,
|
|
367
|
+
reset: s.reset,
|
|
368
|
+
formContext: l.formContext
|
|
363
369
|
}, () => [
|
|
364
|
-
$("button", { disabled:
|
|
370
|
+
$("button", { disabled: v.value }, h(t.value.submit.text), 9, ce)
|
|
365
371
|
]),
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
372
|
+
_(l.$slots, "form.footer", {
|
|
373
|
+
disabled: v.value,
|
|
374
|
+
clearErrors: s.clearErrors,
|
|
375
|
+
reset: s.reset,
|
|
376
|
+
formContext: l.formContext
|
|
369
377
|
})
|
|
370
378
|
]),
|
|
371
379
|
_: 3
|
|
@@ -374,5 +382,5 @@ const ee = /* @__PURE__ */ q({
|
|
|
374
382
|
});
|
|
375
383
|
export {
|
|
376
384
|
oe as OoField,
|
|
377
|
-
|
|
385
|
+
pe as OoForm
|
|
378
386
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(B,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(B=typeof globalThis<"u"?globalThis:B||self,e(B.index={},B.Vue))})(this,function(B,e){"use strict";function
|
|
1
|
+
(function(B,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(B=typeof globalThis<"u"?globalThis:B||self,e(B.index={},B.Vue))})(this,function(B,e){"use strict";function b(l,n){return S(l)?l(n):l}function D(l,n){if(typeof l=="object"&&l!==null){const r={};for(const[o,m]of Object.entries(l))r[o]=b(m,n);return r}return S(l)?l(n):l}function S(l){return typeof l=="function"}const E=e.defineComponent({__name:"VuilessField",props:e.mergeModels({rules:{}},{modelValue:{},modelModifiers:{}}),emits:["update:modelValue"],setup(l){const n=l,r=e.useModel(l,"modelValue"),o=e.inject("vuiless"),m=e.ref(),d=e.ref(!1),f=e.ref(!1),u=e.computed(()=>{var a;if((a=o==null?void 0:o.value)!=null&&a.firstValidation)switch(o.value.firstValidation){case"on-change":return o.value.firstSubmitHappened||d.value;case"touched-on-blur":return o.value.firstSubmitHappened||f.value&&d.value;case"on-blur":return o.value.firstSubmitHappened||f.value;case"on-submit":return o.value.firstSubmitHappened;case"none":return!1}return!1}),y=e.computed(()=>{if(u.value||m.value)return s()});e.watch([r],()=>{m.value=void 0,d.value=!0}),e.onUnmounted(()=>{var a;(a=o==null?void 0:o.value)==null||a.unregister(e.getCurrentInstance())}),o!=null&&o.value&&o.value.register(e.getCurrentInstance(),{validate:()=>(m.value=s(),m.value||!0),clearErrors:()=>{d.value=!1,f.value=!1,m.value=void 0},reset:()=>{r.value=""}});function s(){var a,t,h;if((a=n.rules)!=null&&a.length)for(const g of n.rules){const c=g(r.value,(t=o==null?void 0:o.value)==null?void 0:t.formData,(h=o==null?void 0:o.value)==null?void 0:h.formContext);if(c!==!0)return c||"Wrong value"}}function p(){f.value=!0}const i={v:e.computed({get:()=>r.value,set:a=>r.value=a})};return(a,t)=>{var h,g;return e.renderSlot(a.$slots,"default",{onBlur:p,error:y.value,formData:(h=e.unref(o))==null?void 0:h.formData,formContext:(g=e.unref(o))==null?void 0:g.formContext,model:i.v})}}}),x=e.defineComponent({__name:"VuilessForm",props:{formData:{},formContext:{},firstValidation:{default:"on-change"}},emits:["submit"],setup(l,{emit:n}){const r=l,o=n,m=new Map,d=e.ref(!1),f=e.computed(()=>({firstSubmitHappened:d.value,firstValidation:r.firstValidation,register:(p,i)=>{m.set(p,i)},unregister:p=>m.delete(p),formData:r.formData,formContext:r.formContext}));e.provide("vuiless",f);function u(){d.value=!1;for(const{clearErrors:p}of m.values())p()}async function y(){for(const{reset:p}of m.values())p();await e.nextTick(),u()}function s(){d.value=!0;let p=!1;if(r.firstValidation!=="none")for(const{validate:i}of m.values())i()!==!0&&(p=!0);p||o("submit",r.formData)}return(p,i)=>(e.openBlock(),e.createElementBlock("form",{onSubmit:e.withModifiers(s,["prevent"])},[e.renderSlot(p.$slots,"default",{clearErrors:u,reset:y})],32))}}),V=e.defineComponent({__name:"oo-field",props:{field:{},altAction:{},label:{},description:{},hint:{},placeholder:{},classes:{},styles:{},type:{},component:{},autocomplete:{},name:{},value:{},options:{},attrs:{},optional:{type:Boolean},disabled:{type:Boolean},hidden:{type:Boolean},length:{},validators:{}},setup(l){const n=l,r=e.inject("vuiless"),o=e.computed(()=>({v:r.value.formData[n.field],data:r==null?void 0:r.value.formData,context:r==null?void 0:r.value.formContext,entry:n})),m=e.computed(()=>b(n.label,o.value)),d=e.computed(()=>b(n.description,o.value)),f=e.computed(()=>b(n.hint,o.value)),u=e.computed(()=>b(n.placeholder,o.value)),y=e.computed(()=>b(n.optional,o.value)),s=e.computed(()=>b(n.disabled,o.value)),p=e.computed(()=>b(n.hidden,o.value)),i=e.computed(()=>b(n.options,o.value)),a=e.computed(()=>{const c=D(n.classes,o.value);return typeof c=="string"?{[c]:!0,disabled:s.value,required:!y.value}:{...c||{},disabled:s.value,required:!y.value}}),t=e.computed(()=>D(n.styles,o.value)),h=e.computed(()=>D(n.attrs,o.value)),g=e.computed(()=>{var c;return(c=n.validators)==null?void 0:c.map(k=>(C,A,F)=>k({v:C,data:A,context:F,entry:n}))});return(c,k)=>(e.openBlock(),e.createBlock(e.unref(E),{modelValue:e.unref(r).formData[n.field],"onUpdate:modelValue":k[0]||(k[0]=C=>e.unref(r).formData[n.field]=C),rules:g.value},{default:e.withCtx(C=>[e.renderSlot(c.$slots,"default",{onBlur:C.onBlur,error:C.error,model:C.model,formData:e.unref(r).formData,formContext:e.unref(r).formContext,label:m.value,description:d.value,hint:f.value,placeholder:u.value,classes:{...a.value,error:!!C.error},styles:t.value,optional:y.value,disabled:s.value,hidden:p.value,type:c.type,altAction:c.altAction,component:c.component,vName:c.name,field:c.field,options:i.value,length:c.length,required:!y.value,autocomplete:c.autocomplete,attrs:h.value})]),_:3},8,["modelValue","rules"]))}}),_={key:0},N={key:1},$={key:0},q=["onUpdate:modelValue","onBlur","placeholder","autocomplete","name","type"],w={class:"oo-error-slot"},j={key:4},v={key:5},M=["disabled"],P=e.defineComponent({__name:"oo-form",props:{form:{},formData:{},formContext:{},firstValidation:{},components:{},types:{}},emits:["submit"],setup(l,{emit:n}){const r=l,o=e.computed(()=>r.form.executable()),m=e.computed(()=>({v:void 0,data:f.value,context:r.formContext,entry:r})),d=e.ref({}),f=e.computed(()=>r.formData||d.value),u=e.computed(()=>b(o.value.submit.disabled,m.value)),y=n;return(s,p)=>(e.openBlock(),e.createBlock(e.unref(x),{"first-validation":s.firstValidation,onSubmit:p[0]||(p[0]=i=>y("submit",i)),"form-data":f.value,"form-context":s.formContext},{default:e.withCtx(i=>[e.renderSlot(s.$slots,"form.header",{clearErrors:i.clearErrors,reset:i.reset,title:o.value.title,formContext:s.formContext,disabled:u.value},()=>[o.value.title?(e.openBlock(),e.createElementBlock("h2",_,e.toDisplayString(o.value.title),1)):e.createCommentVNode("",!0)]),e.renderSlot(s.$slots,"form.before",{clearErrors:i.clearErrors,reset:i.reset}),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.value.entries,a=>(e.openBlock(),e.createBlock(V,e.normalizeProps(e.guardReactiveProps(a)),{default:e.withCtx(t=>[e.renderSlot(s.$slots,`field:${t.type}`,e.normalizeProps(e.guardReactiveProps(t)),()=>{var h,g,c;return[a.component&&((h=r.components)!=null&&h[a.component])?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(r.components[a.component]),e.mergeProps({key:0,"on-blur":t.onBlur,error:t.error,model:t.model,"form-data":t.formData,"form-context":t.formContext,label:t.label,description:t.description,hint:t.hint,placeholder:t.placeholder,class:t.classes,style:t.styles,optional:t.optional,required:!t.required,disabled:t.disabled,hidden:t.hidden,type:t.type,"alt-action":t.altAction,name:t.vName,field:t,options:t.options,length:t.length,autocomplete:t.autocomplete},t.attrs),null,16,["on-blur","error","model","form-data","form-context","label","description","hint","placeholder","class","style","optional","required","disabled","hidden","type","alt-action","name","field","options","length","autocomplete"])):a.component&&!((g=r.components)!=null&&g[a.component])?(e.openBlock(),e.createElementBlock("div",N," ["+e.toDisplayString(t.label)+'] Component "'+e.toDisplayString(t.component)+'" not supplied ',1)):(c=r.types)!=null&&c[a.type]?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(r.types[a.type]),e.mergeProps({key:2,"on-blur":t.onBlur,error:t.error,model:t.model,"form-data":t.formData,"form-context":t.formContext,label:t.label,description:t.description,hint:t.hint,placeholder:t.placeholder,class:t.classes,style:t.styles,optional:t.optional,required:!t.required,disabled:t.disabled,hidden:t.hidden,type:t.type,"alt-action":t.altAction,name:t.vName,field:t,options:t.options,length:t.length,autocomplete:t.autocomplete},t.attrs),null,16,["on-blur","error","model","form-data","form-context","label","description","hint","placeholder","class","style","optional","required","disabled","hidden","type","alt-action","name","field","options","length","autocomplete"])):["text","password","number"].includes(t.type)?(e.openBlock(),e.createElementBlock("div",{key:3,class:e.normalizeClass(["oo-default-field",t.classes])},[e.createElementVNode("label",null,e.toDisplayString(t.label),1),t.description?(e.openBlock(),e.createElementBlock("span",$,e.toDisplayString(t.description),1)):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":k=>t.model.value=k,onBlur:t.onBlur,placeholder:t.placeholder,autocomplete:t.autocomplete,name:t.vName,type:t.type},null,40,q),[[e.vModelDynamic,t.model.value]]),e.createElementVNode("div",w,e.toDisplayString(t.error||t.hint),1)],2)):t.type==="paragraph"?(e.openBlock(),e.createElementBlock("p",j,e.toDisplayString(t.description),1)):(e.openBlock(),e.createElementBlock("div",v," ["+e.toDisplayString(t.label)+'] Not supported field type "'+e.toDisplayString(t.type)+'" '+e.toDisplayString(t.component),1))]})]),_:2},1040))),256)),e.renderSlot(s.$slots,"form.after",{clearErrors:i.clearErrors,reset:i.reset,disabled:u.value,formContext:s.formContext}),e.renderSlot(s.$slots,"form.submit",{disabled:u.value,clearErrors:i.clearErrors,reset:i.reset,formContext:s.formContext},()=>[e.createElementVNode("button",{disabled:u.value},e.toDisplayString(o.value.submit.text),9,M)]),e.renderSlot(s.$slots,"form.footer",{disabled:u.value,clearErrors:i.clearErrors,reset:i.reset,formContext:s.formContext})]),_:3},8,["first-validation","form-data","form-context"]))}});B.OoField=V,B.OoForm=P,Object.defineProperty(B,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foormjs/vue",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "@foormjs/vue",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"type-check": "vue-tsc --build --force"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"foorm": "0.0.
|
|
50
|
+
"foorm": "0.0.3",
|
|
51
51
|
"vue": "^3.3.9",
|
|
52
52
|
"vuiless-forms": "^0.0.3"
|
|
53
53
|
},
|