@josercl/form-maker 1.3.0 → 1.3.1-beta1
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.js +94 -94
- package/dist/index.umd.cjs +1 -1
- package/lib/components/FormMakerInput.vue +5 -2
- package/lib/components/SimpleComponent.ts +1 -1
- package/lib/components/inputs/BasicInput.vue +4 -1
- package/lib/components/inputs/CheckboxInput.vue +1 -1
- package/lib/components/inputs/FileInput.vue +7 -4
- package/lib/components/inputs/RadioInput.vue +1 -1
- package/lib/components/inputs/SelectInput.vue +3 -1
- package/lib/components/inputs/TextAreaInput.vue +3 -1
- package/lib/{index.js → index.ts} +5 -3
- package/lib/model.d.ts +12 -2
- package/lib/shims-vue.d.ts +1 -0
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent as g, computed as
|
|
1
|
+
import { defineComponent as g, computed as y, provide as E, inject as c, resolveComponent as j, openBlock as n, createElementBlock as i, withModifiers as X, renderSlot as k, createTextVNode as O, createCommentVNode as B, Fragment as M, renderList as A, normalizeClass as T, unref as f, createVNode as Y, mergeProps as F, createElementVNode as S, toDisplayString as w, watch as q, toRaw as Z, ref as x, createBlock as I, withCtx as W, resolveDynamicComponent as ee, isRef as R, h as z, withDirectives as L, vModelSelect as le, vModelText as te, vModelDynamic as ae } from "vue";
|
|
2
2
|
const re = ["onSubmit"], oe = { key: 0 }, se = ["disabled"], ue = /* @__PURE__ */ g({
|
|
3
3
|
__name: "FormMaker",
|
|
4
4
|
props: {
|
|
@@ -20,8 +20,8 @@ const re = ["onSubmit"], oe = { key: 0 }, se = ["disabled"], ue = /* @__PURE__ *
|
|
|
20
20
|
submitButtonText: { default: "Submit" }
|
|
21
21
|
},
|
|
22
22
|
emits: ["submit", "update:modelValue"],
|
|
23
|
-
setup(s, { emit:
|
|
24
|
-
const e = s, l = () =>
|
|
23
|
+
setup(s, { emit: r }) {
|
|
24
|
+
const e = s, l = () => r("submit"), a = y(() => e.fields.length > 0 ? e.fields.map((t) => {
|
|
25
25
|
let b = t;
|
|
26
26
|
return Array.isArray(t) || (b = [t]), b.map((C) => C.id ? C : {
|
|
27
27
|
...C,
|
|
@@ -35,11 +35,11 @@ const re = ["onSubmit"], oe = { key: 0 }, se = ["disabled"], ue = /* @__PURE__ *
|
|
|
35
35
|
}
|
|
36
36
|
]));
|
|
37
37
|
E("labelClass", e.labelClass || c("form-label")), E("inputGroupClass", e.inputGroupClass || c("input-group")), E("inputWrapperClass", e.inputWrapperClass || c("input-wrapper")), E("inputErrorClass", e.inputErrorClass || c("input-error")), E("inputClass", e.inputClass || c("input")), E("errorClass", e.errorClass || c("error")), E("helpTextClass", e.helpTextClass || c("help-text"));
|
|
38
|
-
const
|
|
38
|
+
const u = e.rowClass || c("form-row"), o = e.columnClass || c("form-column"), v = e.submitButtonClass || c("submit-button"), p = (t) => {
|
|
39
39
|
const b = t.split(".");
|
|
40
40
|
let C = e.modelValue;
|
|
41
|
-
for (let
|
|
42
|
-
const _ = C[b[
|
|
41
|
+
for (let $ = 0; $ < b.length - 1; $ += 1) {
|
|
42
|
+
const _ = C[b[$]];
|
|
43
43
|
if (!_)
|
|
44
44
|
break;
|
|
45
45
|
C = _;
|
|
@@ -51,7 +51,7 @@ const re = ["onSubmit"], oe = { key: 0 }, se = ["disabled"], ue = /* @__PURE__ *
|
|
|
51
51
|
};
|
|
52
52
|
return (t, b) => {
|
|
53
53
|
const C = j("form-maker-input");
|
|
54
|
-
return
|
|
54
|
+
return n(), i("form", {
|
|
55
55
|
class: "form-maker",
|
|
56
56
|
onSubmit: X(l, ["prevent"])
|
|
57
57
|
}, [
|
|
@@ -59,11 +59,11 @@ const re = ["onSubmit"], oe = { key: 0 }, se = ["disabled"], ue = /* @__PURE__ *
|
|
|
59
59
|
O(" Loading... ")
|
|
60
60
|
]) : B("", !0),
|
|
61
61
|
k(t.$slots, "default", {}, () => [
|
|
62
|
-
(
|
|
63
|
-
class: T(f(
|
|
62
|
+
(n(!0), i(M, null, A(a.value, ($, _) => (n(), i("div", {
|
|
63
|
+
class: T(f(u)),
|
|
64
64
|
key: `fieldRow_${_}`
|
|
65
65
|
}, [
|
|
66
|
-
(
|
|
66
|
+
(n(!0), i(M, null, A($, (V, d) => (n(), i("div", {
|
|
67
67
|
class: T([f(o), V.columnClass]),
|
|
68
68
|
key: `field_${_}_${d}`
|
|
69
69
|
}, [
|
|
@@ -78,7 +78,7 @@ const re = ["onSubmit"], oe = { key: 0 }, se = ["disabled"], ue = /* @__PURE__ *
|
|
|
78
78
|
]),
|
|
79
79
|
k(t.$slots, "extra"),
|
|
80
80
|
k(t.$slots, "divider", {}, () => [
|
|
81
|
-
t.hasActions && !t.hideDivider ? (
|
|
81
|
+
t.hasActions && !t.hideDivider ? (n(), i("hr", oe)) : B("", !0)
|
|
82
82
|
]),
|
|
83
83
|
t.hasActions ? k(t.$slots, "actions", { key: 1 }, () => [
|
|
84
84
|
k(t.$slots, "submit-button", {}, () => [
|
|
@@ -100,47 +100,47 @@ const re = ["onSubmit"], oe = { key: 0 }, se = ["disabled"], ue = /* @__PURE__ *
|
|
|
100
100
|
modelValue: { default: void 0 }
|
|
101
101
|
},
|
|
102
102
|
emits: ["update:modelValue"],
|
|
103
|
-
setup(s, { emit:
|
|
103
|
+
setup(s, { emit: r }) {
|
|
104
104
|
const e = s;
|
|
105
105
|
return q(
|
|
106
106
|
e.modelValue,
|
|
107
107
|
(l) => {
|
|
108
108
|
var o;
|
|
109
|
-
let
|
|
110
|
-
const
|
|
111
|
-
for (let v = 0; v <
|
|
109
|
+
let a = null;
|
|
110
|
+
const u = ((o = e.rules) == null ? void 0 : o.length) ?? 0;
|
|
111
|
+
for (let v = 0; v < u; v += 1) {
|
|
112
112
|
const p = e.rules[v];
|
|
113
113
|
if (!p.validator(l)) {
|
|
114
|
-
|
|
114
|
+
a = p.message;
|
|
115
115
|
break;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
r("update:modelValue", a);
|
|
119
119
|
},
|
|
120
120
|
{ immediate: !0 }
|
|
121
121
|
), () => {
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
}), pe = () => {
|
|
125
|
-
const s = c("labelClass", null),
|
|
125
|
+
const s = c("labelClass", null), r = c("inputClass", null), e = c("inputWrapperClass", null), l = c("inputGroupClass", null), a = c("inputErrorClass", null), u = c("errorClass", null), o = c("helpTextClass", null);
|
|
126
126
|
return {
|
|
127
127
|
labelClass: s,
|
|
128
|
-
inputClass:
|
|
128
|
+
inputClass: r,
|
|
129
129
|
inputWrapperClass: e,
|
|
130
130
|
inputGroupClass: l,
|
|
131
|
-
inputErrorClass:
|
|
132
|
-
errorClass:
|
|
131
|
+
inputErrorClass: a,
|
|
132
|
+
errorClass: u,
|
|
133
133
|
helpTextClass: o
|
|
134
134
|
};
|
|
135
|
-
}, ie = (s,
|
|
136
|
-
const e = Z(
|
|
135
|
+
}, ie = (s, r) => {
|
|
136
|
+
const e = Z(r), l = x(null);
|
|
137
137
|
return q(
|
|
138
138
|
s,
|
|
139
|
-
(
|
|
140
|
-
if (l.value = null,
|
|
139
|
+
(a, u) => {
|
|
140
|
+
if (l.value = null, a !== u)
|
|
141
141
|
for (let o = 0; o < e.length; o += 1) {
|
|
142
142
|
const v = e[o];
|
|
143
|
-
if (!v.validator(
|
|
143
|
+
if (!v.validator(a)) {
|
|
144
144
|
l.value = v.message;
|
|
145
145
|
break;
|
|
146
146
|
}
|
|
@@ -149,11 +149,11 @@ const re = ["onSubmit"], oe = { key: 0 }, se = ["disabled"], ue = /* @__PURE__ *
|
|
|
149
149
|
{ immediate: !0 }
|
|
150
150
|
), l;
|
|
151
151
|
};
|
|
152
|
-
function D(s,
|
|
152
|
+
function D(s, r, e) {
|
|
153
153
|
const l = e ?? "modelValue";
|
|
154
|
-
return
|
|
154
|
+
return y({
|
|
155
155
|
get: () => s(),
|
|
156
|
-
set: (
|
|
156
|
+
set: (a) => r(`update:${l}`, a)
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
const me = /* @__PURE__ */ g({
|
|
@@ -169,26 +169,26 @@ const me = /* @__PURE__ */ g({
|
|
|
169
169
|
rules: { default: () => [] }
|
|
170
170
|
},
|
|
171
171
|
emits: ["update:modelValue"],
|
|
172
|
-
setup(s, { emit:
|
|
173
|
-
const e = s, l = D(() => e.modelValue,
|
|
174
|
-
labelClass:
|
|
175
|
-
inputClass:
|
|
172
|
+
setup(s, { emit: r }) {
|
|
173
|
+
const e = s, l = D(() => e.modelValue, r), {
|
|
174
|
+
labelClass: a,
|
|
175
|
+
inputClass: u,
|
|
176
176
|
inputWrapperClass: o,
|
|
177
177
|
inputGroupClass: v,
|
|
178
178
|
inputErrorClass: p,
|
|
179
179
|
errorClass: m,
|
|
180
180
|
helpTextClass: t
|
|
181
|
-
} = pe(), b =
|
|
181
|
+
} = pe(), b = y(() => !!e.label), C = y(() => !!e.helpText), $ = ie(l, e.rules), _ = y(() => !!e.error || !!$.value), V = y(() => e.error ? e.error : $.value);
|
|
182
182
|
return (d, G) => {
|
|
183
183
|
const J = j("form-maker-label"), K = j("form-maker-help"), Q = j("form-maker-error");
|
|
184
|
-
return
|
|
184
|
+
return n(), i("div", {
|
|
185
185
|
class: T([_.value && f(p), f(o)])
|
|
186
186
|
}, [
|
|
187
187
|
d.type !== "checkbox" ? k(d.$slots, "label", { key: 0 }, () => [
|
|
188
|
-
b.value ? (
|
|
188
|
+
b.value ? (n(), I(J, {
|
|
189
189
|
key: 0,
|
|
190
190
|
id: d.id,
|
|
191
|
-
class: T(f(
|
|
191
|
+
class: T(f(a))
|
|
192
192
|
}, {
|
|
193
193
|
default: W(() => [
|
|
194
194
|
O(w(d.label), 1)
|
|
@@ -201,18 +201,17 @@ const me = /* @__PURE__ */ g({
|
|
|
201
201
|
class: T([f(v), _.value && f(p)])
|
|
202
202
|
}, [
|
|
203
203
|
k(d.$slots, "before"),
|
|
204
|
-
(
|
|
204
|
+
(n(), I(ee(`form-maker-input-${d.type}`), F({ ...d.$props, ...d.$attrs }, {
|
|
205
|
+
class: [d.type !== "checkbox" && f(u), _.value && f(p)],
|
|
206
|
+
label: d.label,
|
|
205
207
|
modelValue: f(l),
|
|
206
208
|
"onUpdate:modelValue": G[0] || (G[0] = (U) => R(l) ? l.value = U : null)
|
|
207
|
-
},
|
|
208
|
-
class: [d.type !== "checkbox" && f(n), _.value && f(p)],
|
|
209
|
-
label: d.label
|
|
210
|
-
}), null, 16, ["modelValue", "class", "label"])),
|
|
209
|
+
}), null, 16, ["class", "label", "modelValue"])),
|
|
211
210
|
k(d.$slots, "after")
|
|
212
211
|
], 2)
|
|
213
212
|
]),
|
|
214
213
|
k(d.$slots, "help", {}, () => [
|
|
215
|
-
C.value ? (
|
|
214
|
+
C.value ? (n(), I(K, {
|
|
216
215
|
key: 0,
|
|
217
216
|
class: T(f(t))
|
|
218
217
|
}, {
|
|
@@ -223,7 +222,7 @@ const me = /* @__PURE__ */ g({
|
|
|
223
222
|
}, 8, ["class"])) : B("", !0)
|
|
224
223
|
]),
|
|
225
224
|
k(d.$slots, "errors", {}, () => [
|
|
226
|
-
_.value ? (
|
|
225
|
+
_.value ? (n(), I(Q, {
|
|
227
226
|
key: 0,
|
|
228
227
|
class: T(f(m))
|
|
229
228
|
}, {
|
|
@@ -232,12 +231,12 @@ const me = /* @__PURE__ */ g({
|
|
|
232
231
|
]),
|
|
233
232
|
_: 1
|
|
234
233
|
}, 8, ["class"])) : B("", !0),
|
|
235
|
-
d.rules.length ? (
|
|
234
|
+
d.rules.length ? (n(), I(ne, {
|
|
236
235
|
key: 1,
|
|
237
236
|
rules: d.rules,
|
|
238
237
|
value: d.modelValue,
|
|
239
|
-
modelValue: f(
|
|
240
|
-
"onUpdate:modelValue": G[1] || (G[1] = (U) => R(
|
|
238
|
+
modelValue: f($),
|
|
239
|
+
"onUpdate:modelValue": G[1] || (G[1] = (U) => R($) ? $.value = U : null)
|
|
241
240
|
}, null, 8, ["rules", "value", "modelValue"])) : B("", !0)
|
|
242
241
|
])
|
|
243
242
|
], 2);
|
|
@@ -249,22 +248,22 @@ const me = /* @__PURE__ */ g({
|
|
|
249
248
|
options: { type: [Boolean, Array], default: () => [] }
|
|
250
249
|
},
|
|
251
250
|
emits: ["update:modelValue"],
|
|
252
|
-
setup(s, { emit:
|
|
253
|
-
const e = s, l =
|
|
251
|
+
setup(s, { emit: r }) {
|
|
252
|
+
const e = s, l = y(() => Array.isArray(e.options) && e.options.length === 0), a = y(() => e.modelValue), u = y(() => (Array.isArray(a.value) ? a.value : [a.value]).filter((m) => !!m)), o = y(() => l.value ? [
|
|
254
253
|
{
|
|
255
254
|
label: e.label,
|
|
256
255
|
value: !0
|
|
257
256
|
}
|
|
258
257
|
] : e.options), v = (p) => {
|
|
259
|
-
let m = [...
|
|
260
|
-
m.indexOf(p) === -1 ? m.push(p) : m = m.filter((t) => t !== p), l.value ?
|
|
258
|
+
let m = [...u.value];
|
|
259
|
+
m.indexOf(p) === -1 ? m.push(p) : m = m.filter((t) => t !== p), l.value ? r("update:modelValue", m.length > 0) : r("update:modelValue", m);
|
|
261
260
|
};
|
|
262
|
-
return (p, m) => (
|
|
261
|
+
return (p, m) => (n(!0), i(M, null, A(o.value, (t, b) => (n(), i("div", {
|
|
263
262
|
key: `option_${b}`
|
|
264
263
|
}, [
|
|
265
264
|
S("label", null, [
|
|
266
265
|
S("input", F(p.$props, {
|
|
267
|
-
checked:
|
|
266
|
+
checked: u.value.indexOf(t.value) !== -1,
|
|
268
267
|
value: t.value,
|
|
269
268
|
type: "checkbox",
|
|
270
269
|
onClick: () => v(t.value)
|
|
@@ -285,21 +284,22 @@ const me = /* @__PURE__ */ g({
|
|
|
285
284
|
rules: { default: () => [] }
|
|
286
285
|
},
|
|
287
286
|
emits: ["update:modelValue"],
|
|
288
|
-
setup(s, { emit:
|
|
287
|
+
setup(s, { emit: r }) {
|
|
289
288
|
const e = (l) => {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
a
|
|
289
|
+
const a = l.currentTarget;
|
|
290
|
+
if (a.files && a.files.length) {
|
|
291
|
+
const u = a.files[0];
|
|
292
|
+
r("update:modelValue", u);
|
|
293
293
|
}
|
|
294
294
|
};
|
|
295
|
-
return (l,
|
|
295
|
+
return (l, a) => (n(), i("input", F(l.$props, {
|
|
296
296
|
type: "file",
|
|
297
297
|
onChange: e
|
|
298
298
|
}), null, 16));
|
|
299
299
|
}
|
|
300
300
|
});
|
|
301
|
-
function N(s,
|
|
302
|
-
return z(s.as
|
|
301
|
+
function N(s, r) {
|
|
302
|
+
return z(`${s.as ?? "div"}`, r.attrs, r.slots);
|
|
303
303
|
}
|
|
304
304
|
N.props = {
|
|
305
305
|
as: {
|
|
@@ -308,8 +308,8 @@ N.props = {
|
|
|
308
308
|
default: "div"
|
|
309
309
|
}
|
|
310
310
|
};
|
|
311
|
-
function H(s, { slots:
|
|
312
|
-
return z("label", { ...e, for: s.id },
|
|
311
|
+
function H(s, { slots: r, attrs: e }) {
|
|
312
|
+
return z("label", { ...e, for: s.id }, r.default());
|
|
313
313
|
}
|
|
314
314
|
H.props = {
|
|
315
315
|
id: {
|
|
@@ -327,28 +327,28 @@ const ve = H, ke = ["checked", "value", "onChange"], be = /* @__PURE__ */ g({
|
|
|
327
327
|
helpText: { default: void 0 },
|
|
328
328
|
label: { default: void 0 },
|
|
329
329
|
type: {},
|
|
330
|
-
rules: {
|
|
330
|
+
rules: {}
|
|
331
331
|
},
|
|
332
332
|
emits: ["update:modelValue"],
|
|
333
|
-
setup(s, { emit:
|
|
333
|
+
setup(s, { emit: r }) {
|
|
334
334
|
const e = (l) => {
|
|
335
|
-
|
|
335
|
+
r("update:modelValue", l);
|
|
336
336
|
};
|
|
337
|
-
return (l,
|
|
337
|
+
return (l, a) => (n(!0), i(M, null, A(l.options, (u, o) => (n(), i("div", {
|
|
338
338
|
key: `option_${o}`
|
|
339
339
|
}, [
|
|
340
340
|
S("label", null, [
|
|
341
341
|
S("input", F(l.$props, {
|
|
342
|
-
checked:
|
|
343
|
-
value:
|
|
342
|
+
checked: u.value === l.modelValue,
|
|
343
|
+
value: u.value,
|
|
344
344
|
type: "radio",
|
|
345
|
-
onChange: (v) => e(
|
|
345
|
+
onChange: (v) => e(u.value)
|
|
346
346
|
}), null, 16, ke),
|
|
347
|
-
O(" " + w(
|
|
347
|
+
O(" " + w(u.label), 1)
|
|
348
348
|
])
|
|
349
349
|
]))), 128));
|
|
350
350
|
}
|
|
351
|
-
}), he = ["id", "disabled", "name", "placeholder"], Ce = ["label"],
|
|
351
|
+
}), he = ["id", "disabled", "name", "placeholder"], Ce = ["label"], $e = ["value"], ye = ["value"], _e = /* @__PURE__ */ g({
|
|
352
352
|
__name: "SelectInput",
|
|
353
353
|
props: {
|
|
354
354
|
options: { default: () => [] },
|
|
@@ -362,30 +362,30 @@ const ve = H, ke = ["checked", "value", "onChange"], be = /* @__PURE__ */ g({
|
|
|
362
362
|
rules: { default: () => [] }
|
|
363
363
|
},
|
|
364
364
|
emits: ["update:modelValue"],
|
|
365
|
-
setup(s, { emit:
|
|
366
|
-
const e = s, l = D(() => e.modelValue,
|
|
365
|
+
setup(s, { emit: r }) {
|
|
366
|
+
const e = s, l = D(() => e.modelValue, r), a = Object.keys(e.optionGroups).length > 0, u = y(() => e.options.map((o) => typeof o == "object" ? o : {
|
|
367
367
|
label: o,
|
|
368
368
|
value: o
|
|
369
369
|
}));
|
|
370
|
-
return (o, v) => L((
|
|
370
|
+
return (o, v) => L((n(), i("select", {
|
|
371
371
|
id: o.id,
|
|
372
372
|
"onUpdate:modelValue": v[0] || (v[0] = (p) => R(l) ? l.value = p : null),
|
|
373
373
|
disabled: o.disabled,
|
|
374
374
|
name: o.name,
|
|
375
375
|
placeholder: o.placeholder
|
|
376
376
|
}, [
|
|
377
|
-
|
|
377
|
+
a ? (n(!0), i(M, { key: 0 }, A(o.optionGroups, (p, m) => (n(), i("optgroup", {
|
|
378
378
|
key: `optGroup_${m}`,
|
|
379
379
|
label: m
|
|
380
380
|
}, [
|
|
381
|
-
(
|
|
381
|
+
(n(!0), i(M, null, A(p, (t) => (n(), i("option", {
|
|
382
382
|
key: `option_${t.value}`,
|
|
383
383
|
value: t.value
|
|
384
|
-
}, w(t.label), 9,
|
|
385
|
-
], 8, Ce))), 128)) : (
|
|
384
|
+
}, w(t.label), 9, $e))), 128))
|
|
385
|
+
], 8, Ce))), 128)) : (n(!0), i(M, { key: 1 }, A(u.value, (p, m) => (n(), i("option", {
|
|
386
386
|
key: `option_${m}`,
|
|
387
387
|
value: p.value
|
|
388
|
-
}, w(p.label), 9,
|
|
388
|
+
}, w(p.label), 9, ye))), 128))
|
|
389
389
|
], 8, he)), [
|
|
390
390
|
[le, f(l)]
|
|
391
391
|
]);
|
|
@@ -396,12 +396,12 @@ const ve = H, ke = ["checked", "value", "onChange"], be = /* @__PURE__ */ g({
|
|
|
396
396
|
modelValue: {}
|
|
397
397
|
},
|
|
398
398
|
emits: ["update:modelValue"],
|
|
399
|
-
setup(s, { emit:
|
|
400
|
-
const e = s, l = D(() => e.modelValue,
|
|
401
|
-
return (
|
|
402
|
-
id:
|
|
403
|
-
"onUpdate:modelValue":
|
|
404
|
-
}, { ...
|
|
399
|
+
setup(s, { emit: r }) {
|
|
400
|
+
const e = s, l = D(() => e.modelValue, r);
|
|
401
|
+
return (a, u) => L((n(), i("textarea", F({
|
|
402
|
+
id: a.id,
|
|
403
|
+
"onUpdate:modelValue": u[0] || (u[0] = (o) => R(l) ? l.value = o : null)
|
|
404
|
+
}, { ...a.$props, ...a.$attrs }), null, 16, Ve)), [
|
|
405
405
|
[te, f(l)]
|
|
406
406
|
]);
|
|
407
407
|
}
|
|
@@ -417,12 +417,12 @@ const ve = H, ke = ["checked", "value", "onChange"], be = /* @__PURE__ */ g({
|
|
|
417
417
|
rules: { default: () => [] }
|
|
418
418
|
},
|
|
419
419
|
emits: ["update:modelValue"],
|
|
420
|
-
setup(s, { emit:
|
|
421
|
-
const e = s, l = D(() => e.modelValue,
|
|
422
|
-
return (
|
|
423
|
-
"onUpdate:modelValue":
|
|
424
|
-
type:
|
|
425
|
-
}, { ...
|
|
420
|
+
setup(s, { emit: r }) {
|
|
421
|
+
const e = s, l = D(() => e.modelValue, r);
|
|
422
|
+
return (a, u) => L((n(), i("input", F({
|
|
423
|
+
"onUpdate:modelValue": u[0] || (u[0] = (o) => R(l) ? l.value = o : null),
|
|
424
|
+
type: a.type
|
|
425
|
+
}, { ...a.$props, ...a.$attrs }), null, 16, Be)), [
|
|
426
426
|
[ae, f(l)]
|
|
427
427
|
]);
|
|
428
428
|
}
|
|
@@ -463,12 +463,12 @@ const ve = H, ke = ["checked", "value", "onChange"], be = /* @__PURE__ */ g({
|
|
|
463
463
|
"form-maker-error": N
|
|
464
464
|
}
|
|
465
465
|
}, we = {
|
|
466
|
-
install: (s,
|
|
466
|
+
install: (s, r) => {
|
|
467
467
|
const e = {
|
|
468
|
-
classes: { ...P.classes, ...
|
|
468
|
+
classes: { ...P.classes, ...r.classes },
|
|
469
469
|
components: {
|
|
470
470
|
...P.components,
|
|
471
|
-
...
|
|
471
|
+
...r.components
|
|
472
472
|
}
|
|
473
473
|
};
|
|
474
474
|
s.component("FormMaker", ue), s.component("FormMakerInput", me), Object.keys(e.classes).forEach((l) => {
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,V){typeof exports=="object"&&typeof module<"u"?module.exports=V(require("vue")):typeof define=="function"&&define.amd?define(["vue"],V):(e=typeof globalThis<"u"?globalThis:e||self,e.FormMaker=V(e.Vue))})(this,function(e){"use strict";const V=["onSubmit"],S={key:0},T=["disabled"],j=e.defineComponent({__name:"FormMaker",props:{loading:{type:Boolean,default:!1},hasActions:{type:Boolean,default:!0},modelValue:{default:()=>({})},fields:{default:()=>[]},hideDivider:{type:Boolean,default:!1},rowClass:{default:null},columnClass:{default:null},labelClass:{default:null},inputGroupClass:{default:null},inputWrapperClass:{default:null},inputErrorClass:{default:null},inputClass:{default:null},errorClass:{default:null},helpTextClass:{default:null},submitButtonClass:{default:null},submitButtonText:{default:"Submit"}},emits:["submit","update:modelValue"],setup(s,{emit:r}){const l=s,t=()=>r("submit"),n=e.computed(()=>l.fields.length>0?l.fields.map(o=>{let f=o;return Array.isArray(o)||(f=[o]),f.map(k=>k.id?k:{...k,id:`formMaker_${new Date().getTime()}_${k.name}`})}):Object.keys(l.modelValue).map(o=>[{name:o,label:o,id:`formMaker_${o}`}]));e.provide("labelClass",l.labelClass||e.inject("form-label")),e.provide("inputGroupClass",l.inputGroupClass||e.inject("input-group")),e.provide("inputWrapperClass",l.inputWrapperClass||e.inject("input-wrapper")),e.provide("inputErrorClass",l.inputErrorClass||e.inject("input-error")),e.provide("inputClass",l.inputClass||e.inject("input")),e.provide("errorClass",l.errorClass||e.inject("error")),e.provide("helpTextClass",l.helpTextClass||e.inject("help-text"));const i=l.rowClass||e.inject("form-row"),a=l.columnClass||e.inject("form-column"),c=l.submitButtonClass||e.inject("submit-button"),p=o=>{const f=o.split(".");let k=l.modelValue;for(let C=0;C<f.length-1;C+=1){const h=k[f[C]];if(!h)break;k=h}return k},m=o=>{const f=o.split(".");return f[f.length-1]};return(o,f)=>{const k=e.resolveComponent("form-maker-input");return e.openBlock(),e.createElementBlock("form",{class:"form-maker",onSubmit:e.withModifiers(t,["prevent"])},[o.loading?e.renderSlot(o.$slots,"loading",{key:0},()=>[e.createTextVNode(" Loading... ")]):e.createCommentVNode("",!0),e.renderSlot(o.$slots,"default",{},()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(n.value,(C,h)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(e.unref(i)),key:`fieldRow_${h}`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C,(b,d)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([e.unref(a),b.columnClass]),key:`field_${h}_${d}`},[e.renderSlot(o.$slots,`${b.name}`,{field:b},()=>[e.createVNode(k,e.mergeProps({modelValue:p(b.name)[m(b.name)],"onUpdate:modelValue":B=>p(b.name)[m(b.name)]=B},b),null,16,["modelValue","onUpdate:modelValue"])])],2))),128))],2))),128))]),e.renderSlot(o.$slots,"extra"),e.renderSlot(o.$slots,"divider",{},()=>[o.hasActions&&!o.hideDivider?(e.openBlock(),e.createElementBlock("hr",S)):e.createCommentVNode("",!0)]),o.hasActions?e.renderSlot(o.$slots,"actions",{key:1},()=>[e.renderSlot(o.$slots,"submit-button",{},()=>[e.createElementVNode("button",{class:e.normalizeClass(e.unref(c)),disabled:o.loading,type:"submit"},e.toDisplayString(o.submitButtonText),11,T)]),e.renderSlot(o.$slots,"extra-buttons")]):e.createCommentVNode("",!0)],40,V)}}}),w=e.defineComponent({__name:"RuleEvaluator",props:{rules:{default:()=>[]},modelValue:{default:void 0}},emits:["update:modelValue"],setup(s,{emit:r}){const l=s;return e.watch(l.modelValue,t=>{var a;let n=null;const i=((a=l.rules)==null?void 0:a.length)??0;for(let c=0;c<i;c+=1){const p=l.rules[c];if(!p.validator(t)){n=p.message;break}}r("update:modelValue",n)},{immediate:!0}),()=>{}}}),N=()=>{const s=e.inject("labelClass",null),r=e.inject("inputClass",null),l=e.inject("inputWrapperClass",null),t=e.inject("inputGroupClass",null),n=e.inject("inputErrorClass",null),i=e.inject("errorClass",null),a=e.inject("helpTextClass",null);return{labelClass:s,inputClass:r,inputWrapperClass:l,inputGroupClass:t,inputErrorClass:n,errorClass:i,helpTextClass:a}},F=(s,r)=>{const l=e.toRaw(r),t=e.ref(null);return e.watch(s,(n,i)=>{if(t.value=null,n!==i)for(let a=0;a<l.length;a+=1){const c=l[a];if(!c.validator(n)){t.value=c.message;break}}},{immediate:!0}),t};function y(s,r,l){const t=l??"modelValue";return e.computed({get:()=>s(),set:n=>r(`update:${t}`,n)})}const D=e.defineComponent({inheritAttrs:!1,__name:"FormMakerInput",props:{loading:{type:Boolean,default:!1},modelValue:{},error:{default:void 0},helpText:{default:void 0},label:{default:void 0},type:{default:"text"},rules:{default:()=>[]}},emits:["update:modelValue"],setup(s,{emit:r}){const l=s,t=y(()=>l.modelValue,r),{labelClass:n,inputClass:i,inputWrapperClass:a,inputGroupClass:c,inputErrorClass:p,errorClass:m,helpTextClass:o}=N(),f=e.computed(()=>!!l.label),k=e.computed(()=>!!l.helpText),C=F(t,l.rules),h=e.computed(()=>!!l.error||!!C.value),b=e.computed(()=>l.error?l.error:C.value);return(d,B)=>{const J=e.resolveComponent("form-maker-label"),K=e.resolveComponent("form-maker-help"),Q=e.resolveComponent("form-maker-error");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([h.value&&e.unref(p),e.unref(a)])},[d.type!=="checkbox"?e.renderSlot(d.$slots,"label",{key:0},()=>[f.value?(e.openBlock(),e.createBlock(J,{key:0,id:d.id,class:e.normalizeClass(e.unref(n))},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(d.label),1)]),_:1},8,["id","class"])):e.createCommentVNode("",!0)]):e.createCommentVNode("",!0),e.renderSlot(d.$slots,"default",{},()=>[e.createElementVNode("div",{class:e.normalizeClass([e.unref(c),h.value&&e.unref(p)])},[e.renderSlot(d.$slots,"before"),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(`form-maker-input-${d.type}`),e.mergeProps({modelValue:e.unref(t),"onUpdate:modelValue":B[0]||(B[0]=$=>e.isRef(t)?t.value=$:null)},{...d.$props,...d.$attrs},{class:[d.type!=="checkbox"&&e.unref(i),h.value&&e.unref(p)],label:d.label}),null,16,["modelValue","class","label"])),e.renderSlot(d.$slots,"after")],2)]),e.renderSlot(d.$slots,"help",{},()=>[k.value?(e.openBlock(),e.createBlock(K,{key:0,class:e.normalizeClass(e.unref(o))},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(d.helpText),1)]),_:1},8,["class"])):e.createCommentVNode("",!0)]),e.renderSlot(d.$slots,"errors",{},()=>[h.value?(e.openBlock(),e.createBlock(Q,{key:0,class:e.normalizeClass(e.unref(m))},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(b.value),1)]),_:1},8,["class"])):e.createCommentVNode("",!0),d.rules.length?(e.openBlock(),e.createBlock(w,{key:1,rules:d.rules,value:d.modelValue,modelValue:e.unref(C),"onUpdate:modelValue":B[1]||(B[1]=$=>e.isRef(C)?C.value=$:null)},null,8,["rules","value","modelValue"])):e.createCommentVNode("",!0)])],2)}}}),M=["checked","value","onClick"],A=e.defineComponent({__name:"CheckboxInput",props:{options:{type:[Boolean,Array],default:()=>[]}},emits:["update:modelValue"],setup(s,{emit:r}){const l=s,t=e.computed(()=>Array.isArray(l.options)&&l.options.length===0),n=e.computed(()=>l.modelValue),i=e.computed(()=>(Array.isArray(n.value)?n.value:[n.value]).filter(m=>!!m)),a=e.computed(()=>t.value?[{label:l.label,value:!0}]:l.options),c=p=>{let m=[...i.value];m.indexOf(p)===-1?m.push(p):m=m.filter(o=>o!==p),t.value?r("update:modelValue",m.length>0):r("update:modelValue",m)};return(p,m)=>(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.value,(o,f)=>(e.openBlock(),e.createElementBlock("div",{key:`option_${f}`},[e.createElementVNode("label",null,[e.createElementVNode("input",e.mergeProps(p.$props,{checked:i.value.indexOf(o.value)!==-1,value:o.value,type:"checkbox",onClick:()=>c(o.value)}),null,16,M),e.createTextVNode(" "+e.toDisplayString(o.label),1)])]))),128))}}),R=e.defineComponent({__name:"FileInput",props:{loading:{type:Boolean,default:!1},modelValue:{},error:{default:void 0},helpText:{default:void 0},label:{default:void 0},type:{},rules:{default:()=>[]}},emits:["update:modelValue"],setup(s,{emit:r}){const l=t=>{if(t.target.files.length){const n=t.target.files[0];r("update:modelValue",n)}};return(t,n)=>(e.openBlock(),e.createElementBlock("input",e.mergeProps(t.$props,{type:"file",onChange:l}),null,16))}});function g(s,r){return e.h(s.as,r.attrs,r.slots)}g.props={as:{type:String,required:!1,default:"div"}};function _(s,{slots:r,attrs:l}){return e.h("label",{...l,for:s.id},r.default())}_.props={id:{type:String,default:null}};const G=_,O=["checked","value","onChange"],L=e.defineComponent({__name:"RadioInput",props:{options:{default:()=>[]},loading:{type:Boolean,default:!1},modelValue:{},error:{default:void 0},helpText:{default:void 0},label:{default:void 0},type:{},rules:{default:()=>[]}},emits:["update:modelValue"],setup(s,{emit:r}){const l=t=>{r("update:modelValue",t)};return(t,n)=>(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.options,(i,a)=>(e.openBlock(),e.createElementBlock("div",{key:`option_${a}`},[e.createElementVNode("label",null,[e.createElementVNode("input",e.mergeProps(t.$props,{checked:i.value===t.modelValue,value:i.value,type:"radio",onChange:c=>l(i.value)}),null,16,O),e.createTextVNode(" "+e.toDisplayString(i.label),1)])]))),128))}}),I=["id","disabled","name","placeholder"],P=["label"],z=["value"],U=["value"],x=e.defineComponent({__name:"SelectInput",props:{options:{default:()=>[]},optionGroups:{default:()=>({})},loading:{type:Boolean,default:!1},modelValue:{},error:{default:void 0},helpText:{default:void 0},label:{default:void 0},type:{},rules:{default:()=>[]}},emits:["update:modelValue"],setup(s,{emit:r}){const l=s,t=y(()=>l.modelValue,r),n=Object.keys(l.optionGroups).length>0,i=e.computed(()=>l.options.map(a=>typeof a=="object"?a:{label:a,value:a}));return(a,c)=>e.withDirectives((e.openBlock(),e.createElementBlock("select",{id:a.id,"onUpdate:modelValue":c[0]||(c[0]=p=>e.isRef(t)?t.value=p:null),disabled:a.disabled,name:a.name,placeholder:a.placeholder},[n?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(a.optionGroups,(p,m)=>(e.openBlock(),e.createElementBlock("optgroup",{key:`optGroup_${m}`,label:m},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p,o=>(e.openBlock(),e.createElementBlock("option",{key:`option_${o.value}`,value:o.value},e.toDisplayString(o.label),9,z))),128))],8,P))),128)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(i.value,(p,m)=>(e.openBlock(),e.createElementBlock("option",{key:`option_${m}`,value:p.value},e.toDisplayString(p.label),9,U))),128))],8,I)),[[e.vModelSelect,e.unref(t)]])}}),W=["id"],q=e.defineComponent({__name:"TextAreaInput",props:{modelValue:{}},emits:["update:modelValue"],setup(s,{emit:r}){const l=s,t=y(()=>l.modelValue,r);return(n,i)=>e.withDirectives((e.openBlock(),e.createElementBlock("textarea",e.mergeProps({id:n.id,"onUpdate:modelValue":i[0]||(i[0]=a=>e.isRef(t)?t.value=a:null)},{...n.$props,...n.$attrs}),null,16,W)),[[e.vModelText,e.unref(t)]])}}),H=["type"],u=e.defineComponent({__name:"BasicInput",props:{loading:{type:Boolean,default:!1},modelValue:{},error:{default:void 0},helpText:{default:void 0},label:{default:void 0},type:{default:"text"},rules:{default:()=>[]}},emits:["update:modelValue"],setup(s,{emit:r}){const l=s,t=y(()=>l.modelValue,r);return(n,i)=>e.withDirectives((e.openBlock(),e.createElementBlock("input",e.mergeProps({"onUpdate:modelValue":i[0]||(i[0]=a=>e.isRef(t)?t.value=a:null),type:n.type},{...n.$props,...n.$attrs}),null,16,H)),[[e.vModelDynamic,e.unref(t)]])}}),E={classes:{"form-row":"form-maker-row","form-column":"form-maker-column","form-label":"form-maker-label","input-group":"form-maker-input-group","input-wrapper":"form-maker-input-wrapper","input-error":"form-maker-input-error",input:"form-maker-input",error:"form-maker-error","help-text":"form-maker-help-text","submit-button":"form-maker-submit"},components:{"form-maker-input-color":u,"form-maker-input-date":u,"form-maker-input-email":u,"form-maker-input-month":u,"form-maker-input-number":u,"form-maker-input-password":u,"form-maker-input-search":u,"form-maker-input-tel":u,"form-maker-input-time":u,"form-maker-input-text":u,"form-maker-input-url":u,"form-maker-input-week":u,"form-maker-input-range":u,"form-maker-input-file":R,"form-maker-input-textarea":q,"form-maker-input-select":x,"form-maker-input-checkbox":A,"form-maker-input-radio":L,"form-maker-label":G,"form-maker-help":g,"form-maker-error":g}};return{install:(s,r={})=>{const l={classes:{...E.classes,...r.classes},components:{...E.components,...r.components}};s.component("FormMaker",j),s.component("FormMakerInput",D),Object.keys(l.classes).forEach(t=>{s.provide(t,l.classes[t])}),Object.keys(l.components).forEach(t=>{s.component(t,l.components[t])})}}});
|
|
1
|
+
(function(e,V){typeof exports=="object"&&typeof module<"u"?module.exports=V(require("vue")):typeof define=="function"&&define.amd?define(["vue"],V):(e=typeof globalThis<"u"?globalThis:e||self,e.FormMaker=V(e.Vue))})(this,function(e){"use strict";const V=["onSubmit"],S={key:0},T=["disabled"],j=e.defineComponent({__name:"FormMaker",props:{loading:{type:Boolean,default:!1},hasActions:{type:Boolean,default:!0},modelValue:{default:()=>({})},fields:{default:()=>[]},hideDivider:{type:Boolean,default:!1},rowClass:{default:null},columnClass:{default:null},labelClass:{default:null},inputGroupClass:{default:null},inputWrapperClass:{default:null},inputErrorClass:{default:null},inputClass:{default:null},errorClass:{default:null},helpTextClass:{default:null},submitButtonClass:{default:null},submitButtonText:{default:"Submit"}},emits:["submit","update:modelValue"],setup(s,{emit:n}){const l=s,t=()=>n("submit"),r=e.computed(()=>l.fields.length>0?l.fields.map(o=>{let f=o;return Array.isArray(o)||(f=[o]),f.map(k=>k.id?k:{...k,id:`formMaker_${new Date().getTime()}_${k.name}`})}):Object.keys(l.modelValue).map(o=>[{name:o,label:o,id:`formMaker_${o}`}]));e.provide("labelClass",l.labelClass||e.inject("form-label")),e.provide("inputGroupClass",l.inputGroupClass||e.inject("input-group")),e.provide("inputWrapperClass",l.inputWrapperClass||e.inject("input-wrapper")),e.provide("inputErrorClass",l.inputErrorClass||e.inject("input-error")),e.provide("inputClass",l.inputClass||e.inject("input")),e.provide("errorClass",l.errorClass||e.inject("error")),e.provide("helpTextClass",l.helpTextClass||e.inject("help-text"));const i=l.rowClass||e.inject("form-row"),a=l.columnClass||e.inject("form-column"),c=l.submitButtonClass||e.inject("submit-button"),p=o=>{const f=o.split(".");let k=l.modelValue;for(let C=0;C<f.length-1;C+=1){const h=k[f[C]];if(!h)break;k=h}return k},m=o=>{const f=o.split(".");return f[f.length-1]};return(o,f)=>{const k=e.resolveComponent("form-maker-input");return e.openBlock(),e.createElementBlock("form",{class:"form-maker",onSubmit:e.withModifiers(t,["prevent"])},[o.loading?e.renderSlot(o.$slots,"loading",{key:0},()=>[e.createTextVNode(" Loading... ")]):e.createCommentVNode("",!0),e.renderSlot(o.$slots,"default",{},()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.value,(C,h)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(e.unref(i)),key:`fieldRow_${h}`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(C,(b,d)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([e.unref(a),b.columnClass]),key:`field_${h}_${d}`},[e.renderSlot(o.$slots,`${b.name}`,{field:b},()=>[e.createVNode(k,e.mergeProps({modelValue:p(b.name)[m(b.name)],"onUpdate:modelValue":B=>p(b.name)[m(b.name)]=B},b),null,16,["modelValue","onUpdate:modelValue"])])],2))),128))],2))),128))]),e.renderSlot(o.$slots,"extra"),e.renderSlot(o.$slots,"divider",{},()=>[o.hasActions&&!o.hideDivider?(e.openBlock(),e.createElementBlock("hr",S)):e.createCommentVNode("",!0)]),o.hasActions?e.renderSlot(o.$slots,"actions",{key:1},()=>[e.renderSlot(o.$slots,"submit-button",{},()=>[e.createElementVNode("button",{class:e.normalizeClass(e.unref(c)),disabled:o.loading,type:"submit"},e.toDisplayString(o.submitButtonText),11,T)]),e.renderSlot(o.$slots,"extra-buttons")]):e.createCommentVNode("",!0)],40,V)}}}),w=e.defineComponent({__name:"RuleEvaluator",props:{rules:{default:()=>[]},modelValue:{default:void 0}},emits:["update:modelValue"],setup(s,{emit:n}){const l=s;return e.watch(l.modelValue,t=>{var a;let r=null;const i=((a=l.rules)==null?void 0:a.length)??0;for(let c=0;c<i;c+=1){const p=l.rules[c];if(!p.validator(t)){r=p.message;break}}n("update:modelValue",r)},{immediate:!0}),()=>{}}}),N=()=>{const s=e.inject("labelClass",null),n=e.inject("inputClass",null),l=e.inject("inputWrapperClass",null),t=e.inject("inputGroupClass",null),r=e.inject("inputErrorClass",null),i=e.inject("errorClass",null),a=e.inject("helpTextClass",null);return{labelClass:s,inputClass:n,inputWrapperClass:l,inputGroupClass:t,inputErrorClass:r,errorClass:i,helpTextClass:a}},F=(s,n)=>{const l=e.toRaw(n),t=e.ref(null);return e.watch(s,(r,i)=>{if(t.value=null,r!==i)for(let a=0;a<l.length;a+=1){const c=l[a];if(!c.validator(r)){t.value=c.message;break}}},{immediate:!0}),t};function y(s,n,l){const t=l??"modelValue";return e.computed({get:()=>s(),set:r=>n(`update:${t}`,r)})}const D=e.defineComponent({inheritAttrs:!1,__name:"FormMakerInput",props:{loading:{type:Boolean,default:!1},modelValue:{},error:{default:void 0},helpText:{default:void 0},label:{default:void 0},type:{default:"text"},rules:{default:()=>[]}},emits:["update:modelValue"],setup(s,{emit:n}){const l=s,t=y(()=>l.modelValue,n),{labelClass:r,inputClass:i,inputWrapperClass:a,inputGroupClass:c,inputErrorClass:p,errorClass:m,helpTextClass:o}=N(),f=e.computed(()=>!!l.label),k=e.computed(()=>!!l.helpText),C=F(t,l.rules),h=e.computed(()=>!!l.error||!!C.value),b=e.computed(()=>l.error?l.error:C.value);return(d,B)=>{const J=e.resolveComponent("form-maker-label"),K=e.resolveComponent("form-maker-help"),Q=e.resolveComponent("form-maker-error");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass([h.value&&e.unref(p),e.unref(a)])},[d.type!=="checkbox"?e.renderSlot(d.$slots,"label",{key:0},()=>[f.value?(e.openBlock(),e.createBlock(J,{key:0,id:d.id,class:e.normalizeClass(e.unref(r))},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(d.label),1)]),_:1},8,["id","class"])):e.createCommentVNode("",!0)]):e.createCommentVNode("",!0),e.renderSlot(d.$slots,"default",{},()=>[e.createElementVNode("div",{class:e.normalizeClass([e.unref(c),h.value&&e.unref(p)])},[e.renderSlot(d.$slots,"before"),(e.openBlock(),e.createBlock(e.resolveDynamicComponent(`form-maker-input-${d.type}`),e.mergeProps({...d.$props,...d.$attrs},{class:[d.type!=="checkbox"&&e.unref(i),h.value&&e.unref(p)],label:d.label,modelValue:e.unref(t),"onUpdate:modelValue":B[0]||(B[0]=$=>e.isRef(t)?t.value=$:null)}),null,16,["class","label","modelValue"])),e.renderSlot(d.$slots,"after")],2)]),e.renderSlot(d.$slots,"help",{},()=>[k.value?(e.openBlock(),e.createBlock(K,{key:0,class:e.normalizeClass(e.unref(o))},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(d.helpText),1)]),_:1},8,["class"])):e.createCommentVNode("",!0)]),e.renderSlot(d.$slots,"errors",{},()=>[h.value?(e.openBlock(),e.createBlock(Q,{key:0,class:e.normalizeClass(e.unref(m))},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(b.value),1)]),_:1},8,["class"])):e.createCommentVNode("",!0),d.rules.length?(e.openBlock(),e.createBlock(w,{key:1,rules:d.rules,value:d.modelValue,modelValue:e.unref(C),"onUpdate:modelValue":B[1]||(B[1]=$=>e.isRef(C)?C.value=$:null)},null,8,["rules","value","modelValue"])):e.createCommentVNode("",!0)])],2)}}}),M=["checked","value","onClick"],A=e.defineComponent({__name:"CheckboxInput",props:{options:{type:[Boolean,Array],default:()=>[]}},emits:["update:modelValue"],setup(s,{emit:n}){const l=s,t=e.computed(()=>Array.isArray(l.options)&&l.options.length===0),r=e.computed(()=>l.modelValue),i=e.computed(()=>(Array.isArray(r.value)?r.value:[r.value]).filter(m=>!!m)),a=e.computed(()=>t.value?[{label:l.label,value:!0}]:l.options),c=p=>{let m=[...i.value];m.indexOf(p)===-1?m.push(p):m=m.filter(o=>o!==p),t.value?n("update:modelValue",m.length>0):n("update:modelValue",m)};return(p,m)=>(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.value,(o,f)=>(e.openBlock(),e.createElementBlock("div",{key:`option_${f}`},[e.createElementVNode("label",null,[e.createElementVNode("input",e.mergeProps(p.$props,{checked:i.value.indexOf(o.value)!==-1,value:o.value,type:"checkbox",onClick:()=>c(o.value)}),null,16,M),e.createTextVNode(" "+e.toDisplayString(o.label),1)])]))),128))}}),R=e.defineComponent({__name:"FileInput",props:{loading:{type:Boolean,default:!1},modelValue:{},error:{default:void 0},helpText:{default:void 0},label:{default:void 0},type:{},rules:{default:()=>[]}},emits:["update:modelValue"],setup(s,{emit:n}){const l=t=>{const r=t.currentTarget;if(r.files&&r.files.length){const i=r.files[0];n("update:modelValue",i)}};return(t,r)=>(e.openBlock(),e.createElementBlock("input",e.mergeProps(t.$props,{type:"file",onChange:l}),null,16))}});function g(s,n){return e.h(`${s.as??"div"}`,n.attrs,n.slots)}g.props={as:{type:String,required:!1,default:"div"}};function _(s,{slots:n,attrs:l}){return e.h("label",{...l,for:s.id},n.default())}_.props={id:{type:String,default:null}};const G=_,O=["checked","value","onChange"],L=e.defineComponent({__name:"RadioInput",props:{options:{default:()=>[]},loading:{type:Boolean,default:!1},modelValue:{},error:{default:void 0},helpText:{default:void 0},label:{default:void 0},type:{},rules:{}},emits:["update:modelValue"],setup(s,{emit:n}){const l=t=>{n("update:modelValue",t)};return(t,r)=>(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.options,(i,a)=>(e.openBlock(),e.createElementBlock("div",{key:`option_${a}`},[e.createElementVNode("label",null,[e.createElementVNode("input",e.mergeProps(t.$props,{checked:i.value===t.modelValue,value:i.value,type:"radio",onChange:c=>l(i.value)}),null,16,O),e.createTextVNode(" "+e.toDisplayString(i.label),1)])]))),128))}}),I=["id","disabled","name","placeholder"],P=["label"],z=["value"],U=["value"],x=e.defineComponent({__name:"SelectInput",props:{options:{default:()=>[]},optionGroups:{default:()=>({})},loading:{type:Boolean,default:!1},modelValue:{},error:{default:void 0},helpText:{default:void 0},label:{default:void 0},type:{},rules:{default:()=>[]}},emits:["update:modelValue"],setup(s,{emit:n}){const l=s,t=y(()=>l.modelValue,n),r=Object.keys(l.optionGroups).length>0,i=e.computed(()=>l.options.map(a=>typeof a=="object"?a:{label:a,value:a}));return(a,c)=>e.withDirectives((e.openBlock(),e.createElementBlock("select",{id:a.id,"onUpdate:modelValue":c[0]||(c[0]=p=>e.isRef(t)?t.value=p:null),disabled:a.disabled,name:a.name,placeholder:a.placeholder},[r?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(a.optionGroups,(p,m)=>(e.openBlock(),e.createElementBlock("optgroup",{key:`optGroup_${m}`,label:m},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(p,o=>(e.openBlock(),e.createElementBlock("option",{key:`option_${o.value}`,value:o.value},e.toDisplayString(o.label),9,z))),128))],8,P))),128)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(i.value,(p,m)=>(e.openBlock(),e.createElementBlock("option",{key:`option_${m}`,value:p.value},e.toDisplayString(p.label),9,U))),128))],8,I)),[[e.vModelSelect,e.unref(t)]])}}),W=["id"],q=e.defineComponent({__name:"TextAreaInput",props:{modelValue:{}},emits:["update:modelValue"],setup(s,{emit:n}){const l=s,t=y(()=>l.modelValue,n);return(r,i)=>e.withDirectives((e.openBlock(),e.createElementBlock("textarea",e.mergeProps({id:r.id,"onUpdate:modelValue":i[0]||(i[0]=a=>e.isRef(t)?t.value=a:null)},{...r.$props,...r.$attrs}),null,16,W)),[[e.vModelText,e.unref(t)]])}}),H=["type"],u=e.defineComponent({__name:"BasicInput",props:{loading:{type:Boolean,default:!1},modelValue:{},error:{default:void 0},helpText:{default:void 0},label:{default:void 0},type:{default:"text"},rules:{default:()=>[]}},emits:["update:modelValue"],setup(s,{emit:n}){const l=s,t=y(()=>l.modelValue,n);return(r,i)=>e.withDirectives((e.openBlock(),e.createElementBlock("input",e.mergeProps({"onUpdate:modelValue":i[0]||(i[0]=a=>e.isRef(t)?t.value=a:null),type:r.type},{...r.$props,...r.$attrs}),null,16,H)),[[e.vModelDynamic,e.unref(t)]])}}),E={classes:{"form-row":"form-maker-row","form-column":"form-maker-column","form-label":"form-maker-label","input-group":"form-maker-input-group","input-wrapper":"form-maker-input-wrapper","input-error":"form-maker-input-error",input:"form-maker-input",error:"form-maker-error","help-text":"form-maker-help-text","submit-button":"form-maker-submit"},components:{"form-maker-input-color":u,"form-maker-input-date":u,"form-maker-input-email":u,"form-maker-input-month":u,"form-maker-input-number":u,"form-maker-input-password":u,"form-maker-input-search":u,"form-maker-input-tel":u,"form-maker-input-time":u,"form-maker-input-text":u,"form-maker-input-url":u,"form-maker-input-week":u,"form-maker-input-range":u,"form-maker-input-file":R,"form-maker-input-textarea":q,"form-maker-input-select":x,"form-maker-input-checkbox":A,"form-maker-input-radio":L,"form-maker-label":G,"form-maker-help":g,"form-maker-error":g}};return{install:(s,n)=>{const l={classes:{...E.classes,...n.classes},components:{...E.components,...n.components}};s.component("FormMaker",j),s.component("FormMakerInput",D),Object.keys(l.classes).forEach(t=>{s.provide(t,l.classes[t])}),Object.keys(l.components).forEach(t=>{s.component(t,l.components[t])})}}});
|
|
@@ -21,7 +21,10 @@ const props = withDefaults(defineProps<FormMakerInputProps>(), {
|
|
|
21
21
|
rules: () => [],
|
|
22
22
|
type: 'text'
|
|
23
23
|
})
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
const emit = defineEmits<{
|
|
26
|
+
(event: 'update:modelValue' | string, val: any): void
|
|
27
|
+
}>();
|
|
25
28
|
|
|
26
29
|
const value = useVModel(() => props.modelValue, emit);
|
|
27
30
|
|
|
@@ -70,10 +73,10 @@ const realError = computed(() => {
|
|
|
70
73
|
<slot name="before" />
|
|
71
74
|
<component
|
|
72
75
|
:is="`form-maker-input-${type}`"
|
|
73
|
-
v-model="value"
|
|
74
76
|
v-bind="{ ...$props, ...$attrs}"
|
|
75
77
|
:class="[type !== 'checkbox' && inputClass, hasErrors && inputErrorClass]"
|
|
76
78
|
:label="label"
|
|
79
|
+
v-model="value"
|
|
77
80
|
/>
|
|
78
81
|
<slot name="after" />
|
|
79
82
|
</div>
|
|
@@ -13,7 +13,10 @@ const props = withDefaults(defineProps<FormMakerInputProps>(), {
|
|
|
13
13
|
rules: () => [],
|
|
14
14
|
type: 'text'
|
|
15
15
|
});
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
const emit = defineEmits<{
|
|
18
|
+
(event: 'update:modelValue' | string, val: any): void
|
|
19
|
+
}>();
|
|
17
20
|
|
|
18
21
|
const value = useVModel(() => props.modelValue, emit);
|
|
19
22
|
</script>
|
|
@@ -42,7 +42,7 @@ const fieldOptions: ComputedRef<SelectOption[]> = computed(() => {
|
|
|
42
42
|
];
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
-
const handleClick = clickVal => {
|
|
45
|
+
const handleClick = (clickVal: any) => {
|
|
46
46
|
let selOptions = [ ...selectedOptions.value ];
|
|
47
47
|
if (selOptions.indexOf(clickVal) === -1) {
|
|
48
48
|
selOptions.push(clickVal);
|
|
@@ -12,11 +12,14 @@ withDefaults(defineProps<FormMakerInputProps>(), {
|
|
|
12
12
|
placeholder: undefined,
|
|
13
13
|
rules: () => [],
|
|
14
14
|
});
|
|
15
|
-
const emit = defineEmits
|
|
15
|
+
const emit = defineEmits<{
|
|
16
|
+
(event: 'update:modelValue' | string, val: any): void
|
|
17
|
+
}>();
|
|
16
18
|
|
|
17
|
-
const handleFileSelect = event => {
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
const handleFileSelect = (event: Event) => {
|
|
20
|
+
const el = event.currentTarget as HTMLInputElement
|
|
21
|
+
if (el.files && el.files.length) {
|
|
22
|
+
const file = el.files[0];
|
|
20
23
|
emit('update:modelValue', file);
|
|
21
24
|
}
|
|
22
25
|
};
|
|
@@ -20,7 +20,9 @@ const props = withDefaults(defineProps<SelectInputProps>(), {
|
|
|
20
20
|
optionGroups: () => ({}),
|
|
21
21
|
rules: () => [],
|
|
22
22
|
});
|
|
23
|
-
const emit = defineEmits
|
|
23
|
+
const emit = defineEmits<{
|
|
24
|
+
(event: 'update:modelValue' | string, val: any): void
|
|
25
|
+
}>();
|
|
24
26
|
|
|
25
27
|
const value = useVModel(() => props.modelValue, emit);
|
|
26
28
|
|
|
@@ -11,7 +11,9 @@ const props = withDefaults(defineProps<TextAreaProps>(), {
|
|
|
11
11
|
id: undefined,
|
|
12
12
|
placeholder: undefined,
|
|
13
13
|
});
|
|
14
|
-
const emit = defineEmits
|
|
14
|
+
const emit = defineEmits<{
|
|
15
|
+
(event: 'update:modelValue' | string, val: any): void
|
|
16
|
+
}>();
|
|
15
17
|
|
|
16
18
|
const value = useVModel(() => props.modelValue, emit);
|
|
17
19
|
</script>
|
|
@@ -9,8 +9,10 @@ import RadioInput from './components/inputs/RadioInput.vue';
|
|
|
9
9
|
import SelectInput from './components/inputs/SelectInput.vue';
|
|
10
10
|
import TextAreaInput from './components/inputs/TextAreaInput.vue';
|
|
11
11
|
import BasicInput from './components/inputs/BasicInput.vue';
|
|
12
|
+
import type { FormMakerPluginOptions } from './model';
|
|
13
|
+
import type { App, Plugin } from 'vue';
|
|
12
14
|
|
|
13
|
-
const defaultOptions = {
|
|
15
|
+
const defaultOptions: FormMakerPluginOptions = {
|
|
14
16
|
classes: {
|
|
15
17
|
'form-row': 'form-maker-row',
|
|
16
18
|
'form-column': 'form-maker-column',
|
|
@@ -51,8 +53,8 @@ const defaultOptions = {
|
|
|
51
53
|
},
|
|
52
54
|
};
|
|
53
55
|
|
|
54
|
-
const FormMaker = {
|
|
55
|
-
install: (app, extraOptions
|
|
56
|
+
const FormMaker: Plugin = {
|
|
57
|
+
install: (app: App, extraOptions: FormMakerPluginOptions) => {
|
|
56
58
|
const options = {
|
|
57
59
|
classes: { ...defaultOptions.classes, ...extraOptions.classes },
|
|
58
60
|
components: {
|
package/lib/model.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import type {InputHTMLAttributes} from "vue";
|
|
1
|
+
import type {Component, FunctionalComponent, InputHTMLAttributes} from "vue";
|
|
2
|
+
|
|
3
|
+
declare module '@josercl/form-maker' {
|
|
4
|
+
import FormMaker from ".";
|
|
5
|
+
export default FormMaker
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface FormMakerPluginOptions {
|
|
9
|
+
classes?: Record<string, string>,
|
|
10
|
+
components?: Record<string, Component | FunctionalComponent | VNode>
|
|
11
|
+
}
|
|
2
12
|
|
|
3
13
|
export interface InputType {
|
|
4
14
|
id?: string | null
|
|
@@ -38,7 +48,7 @@ export interface FormMakerInputProps extends /* @vue-ignore */ InputHTMLAttribut
|
|
|
38
48
|
}
|
|
39
49
|
|
|
40
50
|
export interface SelectOption {
|
|
41
|
-
label: string
|
|
51
|
+
label: string | undefined
|
|
42
52
|
value: any
|
|
43
53
|
}
|
|
44
54
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module '*.vue'
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@josercl/form-maker",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1-beta1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Form generator using vue 3",
|
|
6
6
|
"author": "Jose Carrero <josercl@gmail.com>",
|
|
7
7
|
"main": "./dist/index.umd.cjs",
|
|
8
8
|
"module": "./dist/index.js",
|
|
9
|
+
"types": "./lib/model.d.ts",
|
|
9
10
|
"files": [
|
|
10
11
|
"dist",
|
|
11
12
|
"lib"
|