@josercl/form-maker 1.2.0 → 1.3.0

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 ADDED
@@ -0,0 +1,483 @@
1
+ import { defineComponent as g, computed as $, provide as E, inject as c, resolveComponent as j, openBlock as u, 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
+ const re = ["onSubmit"], oe = { key: 0 }, se = ["disabled"], ue = /* @__PURE__ */ g({
3
+ __name: "FormMaker",
4
+ props: {
5
+ loading: { type: Boolean, default: !1 },
6
+ hasActions: { type: Boolean, default: !0 },
7
+ modelValue: { default: () => ({}) },
8
+ fields: { default: () => [] },
9
+ hideDivider: { type: Boolean, default: !1 },
10
+ rowClass: { default: null },
11
+ columnClass: { default: null },
12
+ labelClass: { default: null },
13
+ inputGroupClass: { default: null },
14
+ inputWrapperClass: { default: null },
15
+ inputErrorClass: { default: null },
16
+ inputClass: { default: null },
17
+ errorClass: { default: null },
18
+ helpTextClass: { default: null },
19
+ submitButtonClass: { default: null },
20
+ submitButtonText: { default: "Submit" }
21
+ },
22
+ emits: ["submit", "update:modelValue"],
23
+ setup(s, { emit: a }) {
24
+ const e = s, l = () => a("submit"), r = $(() => e.fields.length > 0 ? e.fields.map((t) => {
25
+ let b = t;
26
+ return Array.isArray(t) || (b = [t]), b.map((C) => C.id ? C : {
27
+ ...C,
28
+ id: `formMaker_${(/* @__PURE__ */ new Date()).getTime()}_${C.name}`
29
+ });
30
+ }) : Object.keys(e.modelValue).map((t) => [
31
+ {
32
+ name: t,
33
+ label: t,
34
+ id: `formMaker_${t}`
35
+ }
36
+ ]));
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 n = e.rowClass || c("form-row"), o = e.columnClass || c("form-column"), v = e.submitButtonClass || c("submit-button"), p = (t) => {
39
+ const b = t.split(".");
40
+ let C = e.modelValue;
41
+ for (let y = 0; y < b.length - 1; y += 1) {
42
+ const _ = C[b[y]];
43
+ if (!_)
44
+ break;
45
+ C = _;
46
+ }
47
+ return C;
48
+ }, m = (t) => {
49
+ const b = t.split(".");
50
+ return b[b.length - 1];
51
+ };
52
+ return (t, b) => {
53
+ const C = j("form-maker-input");
54
+ return u(), i("form", {
55
+ class: "form-maker",
56
+ onSubmit: X(l, ["prevent"])
57
+ }, [
58
+ t.loading ? k(t.$slots, "loading", { key: 0 }, () => [
59
+ O(" Loading... ")
60
+ ]) : B("", !0),
61
+ k(t.$slots, "default", {}, () => [
62
+ (u(!0), i(M, null, A(r.value, (y, _) => (u(), i("div", {
63
+ class: T(f(n)),
64
+ key: `fieldRow_${_}`
65
+ }, [
66
+ (u(!0), i(M, null, A(y, (V, d) => (u(), i("div", {
67
+ class: T([f(o), V.columnClass]),
68
+ key: `field_${_}_${d}`
69
+ }, [
70
+ k(t.$slots, `${V.name}`, { field: V }, () => [
71
+ Y(C, F({
72
+ modelValue: p(V.name)[m(V.name)],
73
+ "onUpdate:modelValue": (G) => p(V.name)[m(V.name)] = G
74
+ }, V), null, 16, ["modelValue", "onUpdate:modelValue"])
75
+ ])
76
+ ], 2))), 128))
77
+ ], 2))), 128))
78
+ ]),
79
+ k(t.$slots, "extra"),
80
+ k(t.$slots, "divider", {}, () => [
81
+ t.hasActions && !t.hideDivider ? (u(), i("hr", oe)) : B("", !0)
82
+ ]),
83
+ t.hasActions ? k(t.$slots, "actions", { key: 1 }, () => [
84
+ k(t.$slots, "submit-button", {}, () => [
85
+ S("button", {
86
+ class: T(f(v)),
87
+ disabled: t.loading,
88
+ type: "submit"
89
+ }, w(t.submitButtonText), 11, se)
90
+ ]),
91
+ k(t.$slots, "extra-buttons")
92
+ ]) : B("", !0)
93
+ ], 40, re);
94
+ };
95
+ }
96
+ }), ne = /* @__PURE__ */ g({
97
+ __name: "RuleEvaluator",
98
+ props: {
99
+ rules: { default: () => [] },
100
+ modelValue: { default: void 0 }
101
+ },
102
+ emits: ["update:modelValue"],
103
+ setup(s, { emit: a }) {
104
+ const e = s;
105
+ return q(
106
+ e.modelValue,
107
+ (l) => {
108
+ var o;
109
+ let r = null;
110
+ const n = ((o = e.rules) == null ? void 0 : o.length) ?? 0;
111
+ for (let v = 0; v < n; v += 1) {
112
+ const p = e.rules[v];
113
+ if (!p.validator(l)) {
114
+ r = p.message;
115
+ break;
116
+ }
117
+ }
118
+ a("update:modelValue", r);
119
+ },
120
+ { immediate: !0 }
121
+ ), () => {
122
+ };
123
+ }
124
+ }), pe = () => {
125
+ const s = c("labelClass", null), a = c("inputClass", null), e = c("inputWrapperClass", null), l = c("inputGroupClass", null), r = c("inputErrorClass", null), n = c("errorClass", null), o = c("helpTextClass", null);
126
+ return {
127
+ labelClass: s,
128
+ inputClass: a,
129
+ inputWrapperClass: e,
130
+ inputGroupClass: l,
131
+ inputErrorClass: r,
132
+ errorClass: n,
133
+ helpTextClass: o
134
+ };
135
+ }, ie = (s, a) => {
136
+ const e = Z(a), l = x(null);
137
+ return q(
138
+ s,
139
+ (r, n) => {
140
+ if (l.value = null, r !== n)
141
+ for (let o = 0; o < e.length; o += 1) {
142
+ const v = e[o];
143
+ if (!v.validator(r)) {
144
+ l.value = v.message;
145
+ break;
146
+ }
147
+ }
148
+ },
149
+ { immediate: !0 }
150
+ ), l;
151
+ };
152
+ function D(s, a, e) {
153
+ const l = e ?? "modelValue";
154
+ return $({
155
+ get: () => s(),
156
+ set: (r) => a(`update:${l}`, r)
157
+ });
158
+ }
159
+ const me = /* @__PURE__ */ g({
160
+ inheritAttrs: !1,
161
+ __name: "FormMakerInput",
162
+ props: {
163
+ loading: { type: Boolean, default: !1 },
164
+ modelValue: {},
165
+ error: { default: void 0 },
166
+ helpText: { default: void 0 },
167
+ label: { default: void 0 },
168
+ type: { default: "text" },
169
+ rules: { default: () => [] }
170
+ },
171
+ emits: ["update:modelValue"],
172
+ setup(s, { emit: a }) {
173
+ const e = s, l = D(() => e.modelValue, a), {
174
+ labelClass: r,
175
+ inputClass: n,
176
+ inputWrapperClass: o,
177
+ inputGroupClass: v,
178
+ inputErrorClass: p,
179
+ errorClass: m,
180
+ helpTextClass: t
181
+ } = pe(), b = $(() => !!e.label), C = $(() => !!e.helpText), y = ie(l, e.rules), _ = $(() => !!e.error || !!y.value), V = $(() => e.error ? e.error : y.value);
182
+ return (d, G) => {
183
+ const J = j("form-maker-label"), K = j("form-maker-help"), Q = j("form-maker-error");
184
+ return u(), i("div", {
185
+ class: T([_.value && f(p), f(o)])
186
+ }, [
187
+ d.type !== "checkbox" ? k(d.$slots, "label", { key: 0 }, () => [
188
+ b.value ? (u(), I(J, {
189
+ key: 0,
190
+ id: d.id,
191
+ class: T(f(r))
192
+ }, {
193
+ default: W(() => [
194
+ O(w(d.label), 1)
195
+ ]),
196
+ _: 1
197
+ }, 8, ["id", "class"])) : B("", !0)
198
+ ]) : B("", !0),
199
+ k(d.$slots, "default", {}, () => [
200
+ S("div", {
201
+ class: T([f(v), _.value && f(p)])
202
+ }, [
203
+ k(d.$slots, "before"),
204
+ (u(), I(ee(`form-maker-input-${d.type}`), F({
205
+ modelValue: f(l),
206
+ "onUpdate:modelValue": G[0] || (G[0] = (U) => R(l) ? l.value = U : null)
207
+ }, { ...d.$props, ...d.$attrs }, {
208
+ class: [d.type !== "checkbox" && f(n), _.value && f(p)],
209
+ label: d.label
210
+ }), null, 16, ["modelValue", "class", "label"])),
211
+ k(d.$slots, "after")
212
+ ], 2)
213
+ ]),
214
+ k(d.$slots, "help", {}, () => [
215
+ C.value ? (u(), I(K, {
216
+ key: 0,
217
+ class: T(f(t))
218
+ }, {
219
+ default: W(() => [
220
+ O(w(d.helpText), 1)
221
+ ]),
222
+ _: 1
223
+ }, 8, ["class"])) : B("", !0)
224
+ ]),
225
+ k(d.$slots, "errors", {}, () => [
226
+ _.value ? (u(), I(Q, {
227
+ key: 0,
228
+ class: T(f(m))
229
+ }, {
230
+ default: W(() => [
231
+ O(w(V.value), 1)
232
+ ]),
233
+ _: 1
234
+ }, 8, ["class"])) : B("", !0),
235
+ d.rules.length ? (u(), I(ne, {
236
+ key: 1,
237
+ rules: d.rules,
238
+ value: d.modelValue,
239
+ modelValue: f(y),
240
+ "onUpdate:modelValue": G[1] || (G[1] = (U) => R(y) ? y.value = U : null)
241
+ }, null, 8, ["rules", "value", "modelValue"])) : B("", !0)
242
+ ])
243
+ ], 2);
244
+ };
245
+ }
246
+ }), de = ["checked", "value", "onClick"], fe = /* @__PURE__ */ g({
247
+ __name: "CheckboxInput",
248
+ props: {
249
+ options: { type: [Boolean, Array], default: () => [] }
250
+ },
251
+ emits: ["update:modelValue"],
252
+ setup(s, { emit: a }) {
253
+ const e = s, l = $(() => Array.isArray(e.options) && e.options.length === 0), r = $(() => e.modelValue), n = $(() => (Array.isArray(r.value) ? r.value : [r.value]).filter((m) => !!m)), o = $(() => l.value ? [
254
+ {
255
+ label: e.label,
256
+ value: !0
257
+ }
258
+ ] : e.options), v = (p) => {
259
+ let m = [...n.value];
260
+ m.indexOf(p) === -1 ? m.push(p) : m = m.filter((t) => t !== p), l.value ? a("update:modelValue", m.length > 0) : a("update:modelValue", m);
261
+ };
262
+ return (p, m) => (u(!0), i(M, null, A(o.value, (t, b) => (u(), i("div", {
263
+ key: `option_${b}`
264
+ }, [
265
+ S("label", null, [
266
+ S("input", F(p.$props, {
267
+ checked: n.value.indexOf(t.value) !== -1,
268
+ value: t.value,
269
+ type: "checkbox",
270
+ onClick: () => v(t.value)
271
+ }), null, 16, de),
272
+ O(" " + w(t.label), 1)
273
+ ])
274
+ ]))), 128));
275
+ }
276
+ }), ce = /* @__PURE__ */ g({
277
+ __name: "FileInput",
278
+ props: {
279
+ loading: { type: Boolean, default: !1 },
280
+ modelValue: {},
281
+ error: { default: void 0 },
282
+ helpText: { default: void 0 },
283
+ label: { default: void 0 },
284
+ type: {},
285
+ rules: { default: () => [] }
286
+ },
287
+ emits: ["update:modelValue"],
288
+ setup(s, { emit: a }) {
289
+ const e = (l) => {
290
+ if (l.target.files.length) {
291
+ const r = l.target.files[0];
292
+ a("update:modelValue", r);
293
+ }
294
+ };
295
+ return (l, r) => (u(), i("input", F(l.$props, {
296
+ type: "file",
297
+ onChange: e
298
+ }), null, 16));
299
+ }
300
+ });
301
+ function N(s, a) {
302
+ return z(s.as, a.attrs, a.slots);
303
+ }
304
+ N.props = {
305
+ as: {
306
+ type: String,
307
+ required: !1,
308
+ default: "div"
309
+ }
310
+ };
311
+ function H(s, { slots: a, attrs: e }) {
312
+ return z("label", { ...e, for: s.id }, a.default());
313
+ }
314
+ H.props = {
315
+ id: {
316
+ type: String,
317
+ default: null
318
+ }
319
+ };
320
+ const ve = H, ke = ["checked", "value", "onChange"], be = /* @__PURE__ */ g({
321
+ __name: "RadioInput",
322
+ props: {
323
+ options: { default: () => [] },
324
+ loading: { type: Boolean, default: !1 },
325
+ modelValue: {},
326
+ error: { default: void 0 },
327
+ helpText: { default: void 0 },
328
+ label: { default: void 0 },
329
+ type: {},
330
+ rules: { default: () => [] }
331
+ },
332
+ emits: ["update:modelValue"],
333
+ setup(s, { emit: a }) {
334
+ const e = (l) => {
335
+ a("update:modelValue", l);
336
+ };
337
+ return (l, r) => (u(!0), i(M, null, A(l.options, (n, o) => (u(), i("div", {
338
+ key: `option_${o}`
339
+ }, [
340
+ S("label", null, [
341
+ S("input", F(l.$props, {
342
+ checked: n.value === l.modelValue,
343
+ value: n.value,
344
+ type: "radio",
345
+ onChange: (v) => e(n.value)
346
+ }), null, 16, ke),
347
+ O(" " + w(n.label), 1)
348
+ ])
349
+ ]))), 128));
350
+ }
351
+ }), he = ["id", "disabled", "name", "placeholder"], Ce = ["label"], ye = ["value"], $e = ["value"], _e = /* @__PURE__ */ g({
352
+ __name: "SelectInput",
353
+ props: {
354
+ options: { default: () => [] },
355
+ optionGroups: { default: () => ({}) },
356
+ loading: { type: Boolean, default: !1 },
357
+ modelValue: {},
358
+ error: { default: void 0 },
359
+ helpText: { default: void 0 },
360
+ label: { default: void 0 },
361
+ type: {},
362
+ rules: { default: () => [] }
363
+ },
364
+ emits: ["update:modelValue"],
365
+ setup(s, { emit: a }) {
366
+ const e = s, l = D(() => e.modelValue, a), r = Object.keys(e.optionGroups).length > 0, n = $(() => e.options.map((o) => typeof o == "object" ? o : {
367
+ label: o,
368
+ value: o
369
+ }));
370
+ return (o, v) => L((u(), i("select", {
371
+ id: o.id,
372
+ "onUpdate:modelValue": v[0] || (v[0] = (p) => R(l) ? l.value = p : null),
373
+ disabled: o.disabled,
374
+ name: o.name,
375
+ placeholder: o.placeholder
376
+ }, [
377
+ r ? (u(!0), i(M, { key: 0 }, A(o.optionGroups, (p, m) => (u(), i("optgroup", {
378
+ key: `optGroup_${m}`,
379
+ label: m
380
+ }, [
381
+ (u(!0), i(M, null, A(p, (t) => (u(), i("option", {
382
+ key: `option_${t.value}`,
383
+ value: t.value
384
+ }, w(t.label), 9, ye))), 128))
385
+ ], 8, Ce))), 128)) : (u(!0), i(M, { key: 1 }, A(n.value, (p, m) => (u(), i("option", {
386
+ key: `option_${m}`,
387
+ value: p.value
388
+ }, w(p.label), 9, $e))), 128))
389
+ ], 8, he)), [
390
+ [le, f(l)]
391
+ ]);
392
+ }
393
+ }), Ve = ["id"], ge = /* @__PURE__ */ g({
394
+ __name: "TextAreaInput",
395
+ props: {
396
+ modelValue: {}
397
+ },
398
+ emits: ["update:modelValue"],
399
+ setup(s, { emit: a }) {
400
+ const e = s, l = D(() => e.modelValue, a);
401
+ return (r, n) => L((u(), i("textarea", F({
402
+ id: r.id,
403
+ "onUpdate:modelValue": n[0] || (n[0] = (o) => R(l) ? l.value = o : null)
404
+ }, { ...r.$props, ...r.$attrs }), null, 16, Ve)), [
405
+ [te, f(l)]
406
+ ]);
407
+ }
408
+ }), Be = ["type"], h = /* @__PURE__ */ g({
409
+ __name: "BasicInput",
410
+ props: {
411
+ loading: { type: Boolean, default: !1 },
412
+ modelValue: {},
413
+ error: { default: void 0 },
414
+ helpText: { default: void 0 },
415
+ label: { default: void 0 },
416
+ type: { default: "text" },
417
+ rules: { default: () => [] }
418
+ },
419
+ emits: ["update:modelValue"],
420
+ setup(s, { emit: a }) {
421
+ const e = s, l = D(() => e.modelValue, a);
422
+ return (r, n) => L((u(), i("input", F({
423
+ "onUpdate:modelValue": n[0] || (n[0] = (o) => R(l) ? l.value = o : null),
424
+ type: r.type
425
+ }, { ...r.$props, ...r.$attrs }), null, 16, Be)), [
426
+ [ae, f(l)]
427
+ ]);
428
+ }
429
+ }), P = {
430
+ classes: {
431
+ "form-row": "form-maker-row",
432
+ "form-column": "form-maker-column",
433
+ "form-label": "form-maker-label",
434
+ "input-group": "form-maker-input-group",
435
+ "input-wrapper": "form-maker-input-wrapper",
436
+ "input-error": "form-maker-input-error",
437
+ input: "form-maker-input",
438
+ error: "form-maker-error",
439
+ "help-text": "form-maker-help-text",
440
+ "submit-button": "form-maker-submit"
441
+ },
442
+ components: {
443
+ "form-maker-input-color": h,
444
+ "form-maker-input-date": h,
445
+ "form-maker-input-email": h,
446
+ "form-maker-input-month": h,
447
+ "form-maker-input-number": h,
448
+ "form-maker-input-password": h,
449
+ "form-maker-input-search": h,
450
+ "form-maker-input-tel": h,
451
+ "form-maker-input-time": h,
452
+ "form-maker-input-text": h,
453
+ "form-maker-input-url": h,
454
+ "form-maker-input-week": h,
455
+ "form-maker-input-range": h,
456
+ "form-maker-input-file": ce,
457
+ "form-maker-input-textarea": ge,
458
+ "form-maker-input-select": _e,
459
+ "form-maker-input-checkbox": fe,
460
+ "form-maker-input-radio": be,
461
+ "form-maker-label": ve,
462
+ "form-maker-help": N,
463
+ "form-maker-error": N
464
+ }
465
+ }, we = {
466
+ install: (s, a = {}) => {
467
+ const e = {
468
+ classes: { ...P.classes, ...a.classes },
469
+ components: {
470
+ ...P.components,
471
+ ...a.components
472
+ }
473
+ };
474
+ s.component("FormMaker", ue), s.component("FormMakerInput", me), Object.keys(e.classes).forEach((l) => {
475
+ s.provide(l, e.classes[l]);
476
+ }), Object.keys(e.components).forEach((l) => {
477
+ s.component(l, e.components[l]);
478
+ });
479
+ }
480
+ };
481
+ export {
482
+ we as default
483
+ };
@@ -0,0 +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])})}}});