@josercl/form-maker 1.2.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 ADDED
@@ -0,0 +1,483 @@
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
+ 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: r }) {
24
+ const e = s, l = () => r("submit"), a = y(() => 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 u = 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 $ = 0; $ < b.length - 1; $ += 1) {
42
+ const _ = C[b[$]];
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 n(), 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
+ (n(!0), i(M, null, A(a.value, ($, _) => (n(), i("div", {
63
+ class: T(f(u)),
64
+ key: `fieldRow_${_}`
65
+ }, [
66
+ (n(!0), i(M, null, A($, (V, d) => (n(), 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 ? (n(), 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: r }) {
104
+ const e = s;
105
+ return q(
106
+ e.modelValue,
107
+ (l) => {
108
+ var o;
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
+ const p = e.rules[v];
113
+ if (!p.validator(l)) {
114
+ a = p.message;
115
+ break;
116
+ }
117
+ }
118
+ r("update:modelValue", a);
119
+ },
120
+ { immediate: !0 }
121
+ ), () => {
122
+ };
123
+ }
124
+ }), pe = () => {
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
+ return {
127
+ labelClass: s,
128
+ inputClass: r,
129
+ inputWrapperClass: e,
130
+ inputGroupClass: l,
131
+ inputErrorClass: a,
132
+ errorClass: u,
133
+ helpTextClass: o
134
+ };
135
+ }, ie = (s, r) => {
136
+ const e = Z(r), l = x(null);
137
+ return q(
138
+ s,
139
+ (a, u) => {
140
+ if (l.value = null, a !== u)
141
+ for (let o = 0; o < e.length; o += 1) {
142
+ const v = e[o];
143
+ if (!v.validator(a)) {
144
+ l.value = v.message;
145
+ break;
146
+ }
147
+ }
148
+ },
149
+ { immediate: !0 }
150
+ ), l;
151
+ };
152
+ function D(s, r, e) {
153
+ const l = e ?? "modelValue";
154
+ return y({
155
+ get: () => s(),
156
+ set: (a) => r(`update:${l}`, a)
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: r }) {
173
+ const e = s, l = D(() => e.modelValue, r), {
174
+ labelClass: a,
175
+ inputClass: u,
176
+ inputWrapperClass: o,
177
+ inputGroupClass: v,
178
+ inputErrorClass: p,
179
+ errorClass: m,
180
+ helpTextClass: t
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
+ return (d, G) => {
183
+ const J = j("form-maker-label"), K = j("form-maker-help"), Q = j("form-maker-error");
184
+ return n(), i("div", {
185
+ class: T([_.value && f(p), f(o)])
186
+ }, [
187
+ d.type !== "checkbox" ? k(d.$slots, "label", { key: 0 }, () => [
188
+ b.value ? (n(), I(J, {
189
+ key: 0,
190
+ id: d.id,
191
+ class: T(f(a))
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
+ (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,
207
+ modelValue: f(l),
208
+ "onUpdate:modelValue": G[0] || (G[0] = (U) => R(l) ? l.value = U : null)
209
+ }), null, 16, ["class", "label", "modelValue"])),
210
+ k(d.$slots, "after")
211
+ ], 2)
212
+ ]),
213
+ k(d.$slots, "help", {}, () => [
214
+ C.value ? (n(), I(K, {
215
+ key: 0,
216
+ class: T(f(t))
217
+ }, {
218
+ default: W(() => [
219
+ O(w(d.helpText), 1)
220
+ ]),
221
+ _: 1
222
+ }, 8, ["class"])) : B("", !0)
223
+ ]),
224
+ k(d.$slots, "errors", {}, () => [
225
+ _.value ? (n(), I(Q, {
226
+ key: 0,
227
+ class: T(f(m))
228
+ }, {
229
+ default: W(() => [
230
+ O(w(V.value), 1)
231
+ ]),
232
+ _: 1
233
+ }, 8, ["class"])) : B("", !0),
234
+ d.rules.length ? (n(), I(ne, {
235
+ key: 1,
236
+ rules: d.rules,
237
+ value: d.modelValue,
238
+ modelValue: f($),
239
+ "onUpdate:modelValue": G[1] || (G[1] = (U) => R($) ? $.value = U : null)
240
+ }, null, 8, ["rules", "value", "modelValue"])) : B("", !0)
241
+ ])
242
+ ], 2);
243
+ };
244
+ }
245
+ }), de = ["checked", "value", "onClick"], fe = /* @__PURE__ */ g({
246
+ __name: "CheckboxInput",
247
+ props: {
248
+ options: { type: [Boolean, Array], default: () => [] }
249
+ },
250
+ emits: ["update:modelValue"],
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 ? [
253
+ {
254
+ label: e.label,
255
+ value: !0
256
+ }
257
+ ] : e.options), v = (p) => {
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);
260
+ };
261
+ return (p, m) => (n(!0), i(M, null, A(o.value, (t, b) => (n(), i("div", {
262
+ key: `option_${b}`
263
+ }, [
264
+ S("label", null, [
265
+ S("input", F(p.$props, {
266
+ checked: u.value.indexOf(t.value) !== -1,
267
+ value: t.value,
268
+ type: "checkbox",
269
+ onClick: () => v(t.value)
270
+ }), null, 16, de),
271
+ O(" " + w(t.label), 1)
272
+ ])
273
+ ]))), 128));
274
+ }
275
+ }), ce = /* @__PURE__ */ g({
276
+ __name: "FileInput",
277
+ props: {
278
+ loading: { type: Boolean, default: !1 },
279
+ modelValue: {},
280
+ error: { default: void 0 },
281
+ helpText: { default: void 0 },
282
+ label: { default: void 0 },
283
+ type: {},
284
+ rules: { default: () => [] }
285
+ },
286
+ emits: ["update:modelValue"],
287
+ setup(s, { emit: r }) {
288
+ const e = (l) => {
289
+ const a = l.currentTarget;
290
+ if (a.files && a.files.length) {
291
+ const u = a.files[0];
292
+ r("update:modelValue", u);
293
+ }
294
+ };
295
+ return (l, a) => (n(), i("input", F(l.$props, {
296
+ type: "file",
297
+ onChange: e
298
+ }), null, 16));
299
+ }
300
+ });
301
+ function N(s, r) {
302
+ return z(`${s.as ?? "div"}`, r.attrs, r.slots);
303
+ }
304
+ N.props = {
305
+ as: {
306
+ type: String,
307
+ required: !1,
308
+ default: "div"
309
+ }
310
+ };
311
+ function H(s, { slots: r, attrs: e }) {
312
+ return z("label", { ...e, for: s.id }, r.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: {}
331
+ },
332
+ emits: ["update:modelValue"],
333
+ setup(s, { emit: r }) {
334
+ const e = (l) => {
335
+ r("update:modelValue", l);
336
+ };
337
+ return (l, a) => (n(!0), i(M, null, A(l.options, (u, o) => (n(), i("div", {
338
+ key: `option_${o}`
339
+ }, [
340
+ S("label", null, [
341
+ S("input", F(l.$props, {
342
+ checked: u.value === l.modelValue,
343
+ value: u.value,
344
+ type: "radio",
345
+ onChange: (v) => e(u.value)
346
+ }), null, 16, ke),
347
+ O(" " + w(u.label), 1)
348
+ ])
349
+ ]))), 128));
350
+ }
351
+ }), he = ["id", "disabled", "name", "placeholder"], Ce = ["label"], $e = ["value"], ye = ["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: 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
+ label: o,
368
+ value: o
369
+ }));
370
+ return (o, v) => L((n(), 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
+ a ? (n(!0), i(M, { key: 0 }, A(o.optionGroups, (p, m) => (n(), i("optgroup", {
378
+ key: `optGroup_${m}`,
379
+ label: m
380
+ }, [
381
+ (n(!0), i(M, null, A(p, (t) => (n(), i("option", {
382
+ key: `option_${t.value}`,
383
+ value: t.value
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
+ key: `option_${m}`,
387
+ value: p.value
388
+ }, w(p.label), 9, ye))), 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: 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
+ [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: 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
+ [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, r) => {
467
+ const e = {
468
+ classes: { ...P.classes, ...r.classes },
469
+ components: {
470
+ ...P.components,
471
+ ...r.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: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])})}}});