@stachelock/ui 0.6.13 → 0.6.15
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/BaseInformationInput-DmtT4C7P.js +4 -0
- package/dist/BaseInformationInput.vue_vue_type_script_setup_true_lang-B-qW4F69.js +154 -0
- package/dist/{DynamicForm.vue_vue_type_script_setup_true_lang-BR8Pq7Kw.js → DynamicForm.vue_vue_type_script_setup_true_lang-D8QXRuSo.js} +1 -1
- package/dist/DynamicFormField.vue_vue_type_script_setup_true_lang-DVoVGq7g.js +216 -0
- package/dist/NamesInput-DHs3Gie7.js +4 -0
- package/dist/NamesInput.vue_vue_type_script_setup_true_lang-BO54mB4C.js +195 -0
- package/dist/forms/DynamicForm.js +1 -1
- package/dist/forms/DynamicFormField.js +1 -1
- package/dist/index.js +1345 -1677
- package/dist/src/components/inputs/DatepickerInput.d.ts +2 -2
- package/dist/src/components/inputs/PhoneInput.d.ts +1 -1
- package/dist/src/components/inputs/RichTextInput.d.ts +1 -1
- package/dist/src/types/form.d.ts +27 -1
- package/package.json +1 -1
- package/dist/DynamicFormField.vue_vue_type_script_setup_true_lang-BCVmqg_n.js +0 -152
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { defineComponent as L, defineAsyncComponent as s, ref as q, computed as i, onMounted as $, watch as b, createElementBlock as m, openBlock as u, withModifiers as A, unref as h, createElementVNode as N, Fragment as R, renderList as G, normalizeClass as H, createBlock as J, resolveDynamicComponent as K, mergeProps as Q } from "vue";
|
|
2
|
+
import { useForm as W } from "vee-validate";
|
|
3
|
+
import { object as X } from "yup";
|
|
4
|
+
import Y from "lodash-es/debounce";
|
|
5
|
+
const Z = { class: "sl-flex sl-flex-col md:sl-flex-row sl-gap-4" }, oe = /* @__PURE__ */ L({
|
|
6
|
+
__name: "BaseInformationInput",
|
|
7
|
+
props: {
|
|
8
|
+
value: {
|
|
9
|
+
type: Object,
|
|
10
|
+
default: () => ({})
|
|
11
|
+
},
|
|
12
|
+
name: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: !0
|
|
15
|
+
},
|
|
16
|
+
rules: {
|
|
17
|
+
type: [Function, Object],
|
|
18
|
+
default: () => ({})
|
|
19
|
+
},
|
|
20
|
+
schema: {
|
|
21
|
+
type: Object,
|
|
22
|
+
required: !0
|
|
23
|
+
},
|
|
24
|
+
enableVerification: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
default: !1
|
|
27
|
+
},
|
|
28
|
+
use: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: "profile"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
emits: ["update:value", "update:media", "update:validity", "clear:media"],
|
|
34
|
+
setup(y, { expose: I, emit: S }) {
|
|
35
|
+
const g = s(() => import("./inputs/TextInput.js")), x = s(() => import("./inputs/EmailInput.js")), F = s(() => import("./inputs/PhoneInput.js")), V = s(() => import("./inputs/ImageDropzoneInput.js")), a = y, r = S;
|
|
36
|
+
let l = !1, c = !0;
|
|
37
|
+
const n = q({}), U = (e) => {
|
|
38
|
+
switch (e) {
|
|
39
|
+
case "EmailInput":
|
|
40
|
+
return x;
|
|
41
|
+
case "PhoneInput":
|
|
42
|
+
return F;
|
|
43
|
+
case "ImageDropzoneInput":
|
|
44
|
+
return V;
|
|
45
|
+
case "TextInput":
|
|
46
|
+
default:
|
|
47
|
+
return g;
|
|
48
|
+
}
|
|
49
|
+
}, _ = (e) => {
|
|
50
|
+
const t = {
|
|
51
|
+
label: e.label,
|
|
52
|
+
placeholder: e.placeholder,
|
|
53
|
+
rules: e.rules,
|
|
54
|
+
tertiaryLabel: e.tertiaryLabel,
|
|
55
|
+
validateOnMount: e.validateOnMount
|
|
56
|
+
};
|
|
57
|
+
switch (e.as) {
|
|
58
|
+
case "EmailInput":
|
|
59
|
+
return {
|
|
60
|
+
...t,
|
|
61
|
+
enableVerification: a.enableVerification || e.enableVerification
|
|
62
|
+
};
|
|
63
|
+
case "PhoneInput":
|
|
64
|
+
return {
|
|
65
|
+
...t,
|
|
66
|
+
enableVerification: a.enableVerification || e.enableVerification
|
|
67
|
+
};
|
|
68
|
+
case "ImageDropzoneInput":
|
|
69
|
+
return {
|
|
70
|
+
...t,
|
|
71
|
+
presetType: e.presetType,
|
|
72
|
+
acceptedFormats: e.acceptedFormats,
|
|
73
|
+
maximumFileSize: e.maximumFileSize
|
|
74
|
+
};
|
|
75
|
+
default:
|
|
76
|
+
return t;
|
|
77
|
+
}
|
|
78
|
+
}, E = i(() => [...a.schema.fields].sort((e, t) => (e.position ?? 0) - (t.position ?? 0))), p = i(() => X(
|
|
79
|
+
a.schema.fields.reduce((e, t) => (t.name && t.rules && (e[t.name] = t.rules), e), {})
|
|
80
|
+
)), { handleSubmit: C, errors: O, validate: P } = W({
|
|
81
|
+
validationSchema: p.value
|
|
82
|
+
}), d = i(() => {
|
|
83
|
+
const e = {};
|
|
84
|
+
return a.schema.fields.forEach((t) => {
|
|
85
|
+
t.name === "profile_image" ? e[t.name] = a.value && t.name in a.value ? a.value[t.name] : null : e[t.name] = a.value && t.name in a.value ? a.value[t.name] : "";
|
|
86
|
+
}), e;
|
|
87
|
+
}), j = Y(() => {
|
|
88
|
+
const e = {};
|
|
89
|
+
Object.keys(n.value).forEach((t) => {
|
|
90
|
+
e[t] = n.value[t];
|
|
91
|
+
}), r("update:value", e);
|
|
92
|
+
}, 500), z = (e) => (t) => {
|
|
93
|
+
n.value[e] !== t && (n.value[e] = t);
|
|
94
|
+
}, B = (e) => (t) => {
|
|
95
|
+
r("update:validity", { id: e, isValid: t });
|
|
96
|
+
}, M = (e) => {
|
|
97
|
+
r("update:media", e);
|
|
98
|
+
}, w = (e) => {
|
|
99
|
+
r("clear:media", e);
|
|
100
|
+
}, T = () => {
|
|
101
|
+
const e = {};
|
|
102
|
+
return Object.keys(n.value).forEach((t) => {
|
|
103
|
+
e[t] = n.value[t];
|
|
104
|
+
}), e;
|
|
105
|
+
}, k = async () => {
|
|
106
|
+
const e = await P();
|
|
107
|
+
return {
|
|
108
|
+
valid: e.valid,
|
|
109
|
+
errors: e.errors || {},
|
|
110
|
+
results: T()
|
|
111
|
+
};
|
|
112
|
+
}, v = C((e) => {
|
|
113
|
+
console.log("Base information form submitted:", e);
|
|
114
|
+
});
|
|
115
|
+
return $(() => {
|
|
116
|
+
n.value = { ...d.value }, c = !1;
|
|
117
|
+
}), b(() => d.value, (e) => {
|
|
118
|
+
!l && c && (l = !0, n.value = { ...e }, l = !1);
|
|
119
|
+
}, { deep: !0 }), b(n, () => {
|
|
120
|
+
l || j();
|
|
121
|
+
}, { deep: !0, immediate: !1 }), I({
|
|
122
|
+
validateForm: k,
|
|
123
|
+
validationSchema: p,
|
|
124
|
+
errors: O
|
|
125
|
+
}), (e, t) => (u(), m("form", {
|
|
126
|
+
onSubmit: t[0] || (t[0] = A(
|
|
127
|
+
//@ts-ignore
|
|
128
|
+
(...o) => h(v) && h(v)(...o),
|
|
129
|
+
["prevent"]
|
|
130
|
+
)),
|
|
131
|
+
class: "sl-space-y-4"
|
|
132
|
+
}, [
|
|
133
|
+
N("div", Z, [
|
|
134
|
+
(u(!0), m(R, null, G(E.value, (o, f) => (u(), m("div", {
|
|
135
|
+
key: o.name,
|
|
136
|
+
class: H(f === 1 || f === 2 ? "md:sl-flex-1 md:sl-flex-col" : "sl-flex-1")
|
|
137
|
+
}, [
|
|
138
|
+
(u(), J(K(U(o.as ?? "TextInput")), Q({
|
|
139
|
+
name: o.name
|
|
140
|
+
}, { ref_for: !0 }, _(o), {
|
|
141
|
+
value: n.value[o.name],
|
|
142
|
+
"onUpdate:value": (D) => z(o.name),
|
|
143
|
+
"onUpdate:media": M,
|
|
144
|
+
"onClear:media": w,
|
|
145
|
+
"onUpdate:validity": (D) => B(o.name)
|
|
146
|
+
}), null, 16, ["name", "value", "onUpdate:value", "onUpdate:validity"]))
|
|
147
|
+
], 2))), 128))
|
|
148
|
+
])
|
|
149
|
+
], 32));
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
export {
|
|
153
|
+
oe as _
|
|
154
|
+
};
|
|
@@ -2,7 +2,7 @@ import { defineComponent as Y, ref as Z, reactive as _, watch as w, computed as
|
|
|
2
2
|
import { useForm as te } from "vee-validate";
|
|
3
3
|
import { ExclamationCircleIcon as se } from "@heroicons/vue/24/outline";
|
|
4
4
|
import A from "./components/Button.js";
|
|
5
|
-
import { _ as ae } from "./DynamicFormField.vue_vue_type_script_setup_true_lang-
|
|
5
|
+
import { _ as ae } from "./DynamicFormField.vue_vue_type_script_setup_true_lang-DVoVGq7g.js";
|
|
6
6
|
const le = {
|
|
7
7
|
key: 0,
|
|
8
8
|
class: "sl-mb-6"
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { defineComponent as k, computed as o, defineAsyncComponent as C, createBlock as p, createElementBlock as _, openBlock as d, resolveDynamicComponent as h, mergeProps as y, toHandlers as x, createElementVNode as i, createVNode as T, unref as E, toDisplayString as D } from "vue";
|
|
2
|
+
import s from "./inputs/TextInput.js";
|
|
3
|
+
import { ExclamationTriangleIcon as F } from "@heroicons/vue/24/outline";
|
|
4
|
+
const L = {
|
|
5
|
+
key: 2,
|
|
6
|
+
class: "sl-p-4 sl-bg-yellow-50 dark:sl-bg-yellow-900/30 sl-border sl-border-yellow-200 dark:sl-border-yellow-800 sl-rounded-md"
|
|
7
|
+
}, M = { class: "sl-flex" }, P = { class: "sl-ml-3" }, S = { class: "sl-mt-2 sl-text-sm sl-text-yellow-700 dark:sl-text-yellow-300" }, q = /* @__PURE__ */ k({
|
|
8
|
+
__name: "DynamicFormField",
|
|
9
|
+
props: {
|
|
10
|
+
field: {},
|
|
11
|
+
modelValue: { type: [String, Number, Boolean, null, Array, Object] },
|
|
12
|
+
formData: {}
|
|
13
|
+
},
|
|
14
|
+
emits: ["update:modelValue", "field-change"],
|
|
15
|
+
setup(n, { emit: b }) {
|
|
16
|
+
const e = n, u = b, v = {
|
|
17
|
+
// Simple input types
|
|
18
|
+
text: () => Promise.resolve(s),
|
|
19
|
+
email: () => import("./inputs/EmailInput.js"),
|
|
20
|
+
phone: () => import("./inputs/PhoneInput.js"),
|
|
21
|
+
password: () => Promise.resolve(s),
|
|
22
|
+
number: () => Promise.resolve(s),
|
|
23
|
+
tel: () => Promise.resolve(s),
|
|
24
|
+
url: () => Promise.resolve(s),
|
|
25
|
+
textarea: () => import("./inputs/TextAreaInput.js"),
|
|
26
|
+
select: () => import("./inputs/SelectInput.js"),
|
|
27
|
+
combobox: () => import("./inputs/ComboboxInput.js"),
|
|
28
|
+
checkbox: () => import("./inputs/CheckboxInput.js"),
|
|
29
|
+
switch: () => import("./inputs/SwitchInput.js"),
|
|
30
|
+
// Compound input types (for complex forms like registration)
|
|
31
|
+
names: () => import("./NamesInput-DHs3Gie7.js"),
|
|
32
|
+
baseInfo: () => import("./BaseInformationInput-DmtT4C7P.js"),
|
|
33
|
+
address: () => import("./inputs/AddressInput.js"),
|
|
34
|
+
selectText: () => import("./inputs/SelectTextInput.js")
|
|
35
|
+
}, w = ["names", "baseInfo", "selectText"], g = o(
|
|
36
|
+
() => w.includes(e.field.type)
|
|
37
|
+
), a = o(() => {
|
|
38
|
+
const l = v[e.field.type];
|
|
39
|
+
return l ? C({
|
|
40
|
+
loader: l,
|
|
41
|
+
errorComponent: () => null,
|
|
42
|
+
delay: 0
|
|
43
|
+
}) : null;
|
|
44
|
+
}), r = o({
|
|
45
|
+
get: () => e.modelValue ?? e.field.defaultValue ?? V(),
|
|
46
|
+
set: (l) => {
|
|
47
|
+
u("update:modelValue", l), u("field-change", e.field, l);
|
|
48
|
+
}
|
|
49
|
+
}), c = o(() => {
|
|
50
|
+
const l = {
|
|
51
|
+
name: e.field.name,
|
|
52
|
+
label: e.field.label,
|
|
53
|
+
placeholder: e.field.placeholder,
|
|
54
|
+
disabled: e.field.disabled,
|
|
55
|
+
rules: e.field.validation,
|
|
56
|
+
validateOnMount: e.field.validateOnMount,
|
|
57
|
+
tertiaryLabel: e.field.tertiaryLabel,
|
|
58
|
+
successMessage: e.field.successMessage
|
|
59
|
+
};
|
|
60
|
+
switch (e.field.type) {
|
|
61
|
+
case "text":
|
|
62
|
+
case "password":
|
|
63
|
+
case "number":
|
|
64
|
+
case "tel":
|
|
65
|
+
case "url":
|
|
66
|
+
return {
|
|
67
|
+
...l,
|
|
68
|
+
type: e.field.inputType || e.field.type,
|
|
69
|
+
maxlength: e.field.maxLength,
|
|
70
|
+
minlength: e.field.minLength,
|
|
71
|
+
min: e.field.min,
|
|
72
|
+
max: e.field.max,
|
|
73
|
+
step: e.field.step,
|
|
74
|
+
spellcheck: e.field.spellcheck,
|
|
75
|
+
autocomplete: e.field.autocomplete
|
|
76
|
+
};
|
|
77
|
+
case "email":
|
|
78
|
+
return {
|
|
79
|
+
...l,
|
|
80
|
+
colorfulValidation: e.field.colorfulValidation ?? !0,
|
|
81
|
+
showErrors: !0,
|
|
82
|
+
autocomplete: e.field.autocomplete || "email"
|
|
83
|
+
};
|
|
84
|
+
case "phone":
|
|
85
|
+
return {
|
|
86
|
+
...l,
|
|
87
|
+
required: e.field.required,
|
|
88
|
+
colorfulValidation: e.field.colorfulValidation ?? !0,
|
|
89
|
+
showErrors: !0,
|
|
90
|
+
defaultCountry: e.field.defaultCountry,
|
|
91
|
+
autoDetectCountry: e.field.autoDetectCountry ?? !0
|
|
92
|
+
};
|
|
93
|
+
case "textarea":
|
|
94
|
+
return {
|
|
95
|
+
...l,
|
|
96
|
+
rows: e.field.rows,
|
|
97
|
+
maxlength: e.field.maxLength,
|
|
98
|
+
spellcheck: e.field.spellcheck
|
|
99
|
+
};
|
|
100
|
+
case "select":
|
|
101
|
+
return {
|
|
102
|
+
...l,
|
|
103
|
+
items: e.field.options || [],
|
|
104
|
+
multiple: e.field.multiple,
|
|
105
|
+
itemKey: e.field.optionKey || "value",
|
|
106
|
+
itemText: e.field.optionLabel || "label",
|
|
107
|
+
showAll: e.field.showSelectAll
|
|
108
|
+
};
|
|
109
|
+
case "combobox":
|
|
110
|
+
return {
|
|
111
|
+
...l,
|
|
112
|
+
items: e.field.options || [],
|
|
113
|
+
itemKey: e.field.optionKey || "value",
|
|
114
|
+
itemText: e.field.optionLabel || "label",
|
|
115
|
+
customQuery: e.field.customQuery,
|
|
116
|
+
loading: e.field.loading
|
|
117
|
+
};
|
|
118
|
+
case "checkbox":
|
|
119
|
+
return {
|
|
120
|
+
...l,
|
|
121
|
+
description: e.field.description,
|
|
122
|
+
immediate: e.field.immediate ?? !0,
|
|
123
|
+
isDescriptionHtml: e.field.isDescriptionHtml
|
|
124
|
+
};
|
|
125
|
+
case "switch":
|
|
126
|
+
return {
|
|
127
|
+
...l,
|
|
128
|
+
description: e.field.description,
|
|
129
|
+
immediate: e.field.immediate ?? !0,
|
|
130
|
+
boxShadow: e.field.boxShadow,
|
|
131
|
+
hideMainLabel: e.field.hideMainLabel,
|
|
132
|
+
textTrue: e.field.textTrue,
|
|
133
|
+
textFalse: e.field.textFalse
|
|
134
|
+
};
|
|
135
|
+
case "names":
|
|
136
|
+
return {
|
|
137
|
+
...l,
|
|
138
|
+
schema: e.field.schema,
|
|
139
|
+
requiredFields: e.field.requiredFields || ["first_name", "last_name"]
|
|
140
|
+
};
|
|
141
|
+
case "baseInfo":
|
|
142
|
+
return {
|
|
143
|
+
...l,
|
|
144
|
+
schema: e.field.schema,
|
|
145
|
+
use: e.field.use || "registration",
|
|
146
|
+
enableVerification: e.field.enableVerification ?? !1
|
|
147
|
+
};
|
|
148
|
+
case "address":
|
|
149
|
+
return {
|
|
150
|
+
...l,
|
|
151
|
+
showSuggestionCount: e.field.showSuggestionCount ?? !0,
|
|
152
|
+
allowManualEntry: e.field.allowManualEntry ?? !0
|
|
153
|
+
};
|
|
154
|
+
case "selectText":
|
|
155
|
+
return {
|
|
156
|
+
...l,
|
|
157
|
+
select: e.field.select,
|
|
158
|
+
text: e.field.text,
|
|
159
|
+
delimiter: e.field.delimiter || " ",
|
|
160
|
+
formatter: e.field.formatter,
|
|
161
|
+
showErrors: !0,
|
|
162
|
+
hasError: !1,
|
|
163
|
+
colorfulValidation: e.field.colorfulValidation ?? !0,
|
|
164
|
+
showValidCheck: e.field.showValidCheck ?? !0
|
|
165
|
+
};
|
|
166
|
+
default:
|
|
167
|
+
return l;
|
|
168
|
+
}
|
|
169
|
+
}), m = o(() => {
|
|
170
|
+
const l = {};
|
|
171
|
+
return e.field.onBlur && (l.blur = e.field.onBlur), e.field.onFocus && (l.focus = e.field.onFocus), e.field.onChange && (l["update:modelValue"] = (t) => {
|
|
172
|
+
r.value = t, e.field.onChange?.(t, e.field, e.formData ?? {});
|
|
173
|
+
}), l;
|
|
174
|
+
}), V = () => {
|
|
175
|
+
switch (e.field.type) {
|
|
176
|
+
case "checkbox":
|
|
177
|
+
case "switch":
|
|
178
|
+
return !1;
|
|
179
|
+
case "select":
|
|
180
|
+
return e.field.multiple ? [] : null;
|
|
181
|
+
case "number":
|
|
182
|
+
return e.field.min || 0;
|
|
183
|
+
case "names":
|
|
184
|
+
case "baseInfo":
|
|
185
|
+
case "address":
|
|
186
|
+
return {};
|
|
187
|
+
case "selectText":
|
|
188
|
+
return { select: void 0, text: void 0, display: void 0 };
|
|
189
|
+
default:
|
|
190
|
+
return "";
|
|
191
|
+
}
|
|
192
|
+
}, f = (l) => {
|
|
193
|
+
r.value = l;
|
|
194
|
+
};
|
|
195
|
+
return (l, t) => a.value && g.value ? (d(), p(h(a.value), y({ key: 0 }, c.value, x(m.value), {
|
|
196
|
+
value: r.value,
|
|
197
|
+
"onUpdate:value": f
|
|
198
|
+
}), null, 16, ["value"])) : a.value ? (d(), p(h(a.value), y({ key: 1 }, c.value, x(m.value), {
|
|
199
|
+
"model-value": r.value,
|
|
200
|
+
"onUpdate:modelValue": f
|
|
201
|
+
}), null, 16, ["model-value"])) : (d(), _("div", L, [
|
|
202
|
+
i("div", M, [
|
|
203
|
+
T(E(F), { class: "sl-h-5 sl-w-5 sl-text-yellow-400" }),
|
|
204
|
+
i("div", P, [
|
|
205
|
+
t[0] || (t[0] = i("h3", { class: "sl-text-sm sl-font-medium sl-text-yellow-800 dark:sl-text-yellow-200" }, " Unknown field type ", -1)),
|
|
206
|
+
i("div", S, [
|
|
207
|
+
i("p", null, 'Field type "' + D(n.field.type) + '" is not supported.', 1)
|
|
208
|
+
])
|
|
209
|
+
])
|
|
210
|
+
])
|
|
211
|
+
]));
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
export {
|
|
215
|
+
q as _
|
|
216
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { defineComponent as se, defineAsyncComponent as T, ref as _, computed as u, onMounted as re, watch as w, createElementBlock as o, openBlock as l, withModifiers as ae, unref as i, createVNode as m, createElementVNode as p, withCtx as k, Fragment as h, renderList as q, createCommentVNode as le, createBlock as oe, resolveDynamicComponent as ne, toDisplayString as ue } from "vue";
|
|
2
|
+
import { TransitionRoot as I } from "@headlessui/vue";
|
|
3
|
+
import { QuestionMarkCircleIcon as ie } from "@heroicons/vue/20/solid";
|
|
4
|
+
import { useField as V, useForm as ce } from "vee-validate";
|
|
5
|
+
import { object as me } from "yup";
|
|
6
|
+
import pe from "lodash-es/debounce";
|
|
7
|
+
import M from "./inputs/TextInput.js";
|
|
8
|
+
const de = { class: "sl-flex sl-flex-col sm:sl-flex-row sl-gap-4" }, ve = {
|
|
9
|
+
key: 0,
|
|
10
|
+
class: "sl-flex-1"
|
|
11
|
+
}, ye = { class: "sl-flex sl-flex-col sm:sl-flex-row sl-gap-4" }, fe = { class: "sl-flex sl-items-center sl-mt-2 sl-text-sm sl-text-gray-600 dark:sl-text-gray-400 sl-space-x-2" }, E = "sl-transition sl-ease-out sl-duration-300", j = "sl-opacity-0 sl-transform sl-scale-95", O = "sl-opacity-100 sl-transform sl-scale-100", N = "sl-transition sl-ease-in sl-duration-200", U = "sl-opacity-100 sl-transform sl-scale-100", B = "sl-opacity-0 sl-transform sl-scale-95", Te = /* @__PURE__ */ se({
|
|
12
|
+
__name: "NamesInput",
|
|
13
|
+
props: {
|
|
14
|
+
value: {
|
|
15
|
+
type: Object,
|
|
16
|
+
default: () => ({})
|
|
17
|
+
},
|
|
18
|
+
name: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: !0
|
|
21
|
+
},
|
|
22
|
+
label: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: ""
|
|
25
|
+
},
|
|
26
|
+
rules: {
|
|
27
|
+
type: [Function, Object],
|
|
28
|
+
default: () => ({})
|
|
29
|
+
},
|
|
30
|
+
schema: {
|
|
31
|
+
type: Object,
|
|
32
|
+
required: !0
|
|
33
|
+
},
|
|
34
|
+
requiredFields: {
|
|
35
|
+
type: Array,
|
|
36
|
+
default: () => ["first_name", "last_name"]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
emits: ["update:value"],
|
|
40
|
+
setup(R, { expose: L, emit: A }) {
|
|
41
|
+
const D = T(() => import("./inputs/ComboboxInput.js")), z = T(() => import("./inputs/SelectInput.js")), r = R, K = A;
|
|
42
|
+
let c = !1, x = !0;
|
|
43
|
+
const n = _(!1), a = _({}), d = {}, Q = (e) => {
|
|
44
|
+
switch (e) {
|
|
45
|
+
case "ComboboxInput":
|
|
46
|
+
return D;
|
|
47
|
+
case "SelectInput":
|
|
48
|
+
return z;
|
|
49
|
+
case "TextInput":
|
|
50
|
+
default:
|
|
51
|
+
return M;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
r.schema.fields.forEach((e) => {
|
|
55
|
+
const { errorMessage: s } = V(e.name, e.rules);
|
|
56
|
+
d[e.name] = s;
|
|
57
|
+
});
|
|
58
|
+
const G = u(() => new Set(r.requiredFields)), v = (e, s) => G.value.has(e) ? !0 : !!s, H = u(() => r.schema.fields.slice(0, 2)), J = u(() => [...r.schema.fields].sort((e, s) => (e.position ?? 0) - (s.position ?? 0))), P = (e) => typeof e == "string" ? e : e === null ? null : typeof e == "object" && e !== void 0 ? e : typeof e == "number" || typeof e == "boolean" ? String(e) : "", b = (e) => {
|
|
59
|
+
const s = a.value[e];
|
|
60
|
+
return typeof s == "string" ? s : "";
|
|
61
|
+
}, W = (e) => e.as === "TextInput" ? b(e.name) : a.value[e.name], y = u(() => {
|
|
62
|
+
const e = {};
|
|
63
|
+
return r.schema.fields.forEach((s) => {
|
|
64
|
+
const t = r.value ? r.value[s.name] : void 0;
|
|
65
|
+
e[s.name] = P(t);
|
|
66
|
+
}), e;
|
|
67
|
+
}), g = u(() => me(
|
|
68
|
+
r.schema.fields.reduce((e, s) => (s.rules && (e[s.name] = s.rules), e), {})
|
|
69
|
+
)), { handleSubmit: X, validate: Y, errors: Z } = ce({
|
|
70
|
+
validationSchema: g.value,
|
|
71
|
+
initialValues: y.value
|
|
72
|
+
});
|
|
73
|
+
r.schema.fields.forEach((e) => {
|
|
74
|
+
const { errorMessage: s } = V(e.name);
|
|
75
|
+
d[e.name] = s;
|
|
76
|
+
});
|
|
77
|
+
const $ = async () => {
|
|
78
|
+
const e = await Y();
|
|
79
|
+
return {
|
|
80
|
+
valid: e.valid,
|
|
81
|
+
errors: e.errors || {},
|
|
82
|
+
results: { ...a.value }
|
|
83
|
+
};
|
|
84
|
+
}, ee = pe(() => {
|
|
85
|
+
const e = {};
|
|
86
|
+
Object.keys(a.value).forEach((s) => {
|
|
87
|
+
e[s] = a.value[s];
|
|
88
|
+
}), K("update:value", e);
|
|
89
|
+
}, 500), F = (e, s) => {
|
|
90
|
+
a.value[e] = s;
|
|
91
|
+
}, te = () => {
|
|
92
|
+
n.value = !n.value;
|
|
93
|
+
}, S = (e) => e ? "Required" : "Optional", C = X((e) => {
|
|
94
|
+
console.log("Names form submitted:", e);
|
|
95
|
+
});
|
|
96
|
+
return re(() => {
|
|
97
|
+
a.value = { ...y.value }, x = !1;
|
|
98
|
+
}), w(() => y.value, (e) => {
|
|
99
|
+
!c && x && (c = !0, a.value = { ...e }, c = !1);
|
|
100
|
+
}, { deep: !0 }), w(a, () => {
|
|
101
|
+
c || ee();
|
|
102
|
+
}, { deep: !0, immediate: !1 }), L({
|
|
103
|
+
validateForm: $,
|
|
104
|
+
validationSchema: g,
|
|
105
|
+
errors: Z
|
|
106
|
+
}), (e, s) => (l(), o("form", {
|
|
107
|
+
onSubmit: s[0] || (s[0] = ae(
|
|
108
|
+
//@ts-ignore
|
|
109
|
+
(...t) => i(C) && i(C)(...t),
|
|
110
|
+
["prevent"]
|
|
111
|
+
)),
|
|
112
|
+
class: "sl-space-y-4"
|
|
113
|
+
}, [
|
|
114
|
+
m(i(I), {
|
|
115
|
+
enter: E,
|
|
116
|
+
"enter-from": j,
|
|
117
|
+
"enter-to": O,
|
|
118
|
+
leave: N,
|
|
119
|
+
"leave-from": U,
|
|
120
|
+
"leave-to": B,
|
|
121
|
+
show: !n.value
|
|
122
|
+
}, {
|
|
123
|
+
default: k(() => [
|
|
124
|
+
p("div", de, [
|
|
125
|
+
(l(!0), o(h, null, q(H.value, (t) => (l(), o(h, {
|
|
126
|
+
key: t.name
|
|
127
|
+
}, [
|
|
128
|
+
t.as === "TextInput" ? (l(), o("div", ve, [
|
|
129
|
+
m(M, {
|
|
130
|
+
value: b(t.name),
|
|
131
|
+
error: d[t.name]?.value,
|
|
132
|
+
label: t.label,
|
|
133
|
+
name: t.name,
|
|
134
|
+
placeholder: t.placeholder,
|
|
135
|
+
"validate-on-mount": t.validateOnMount,
|
|
136
|
+
class: "sl-text-sm sl-leading-6 sl-text-gray-800 dark:sl-text-gray-200",
|
|
137
|
+
"onUpdate:value": (f) => F(t.name, f),
|
|
138
|
+
rules: t.rules,
|
|
139
|
+
"tertiary-label": S(v(t.name, t.required))
|
|
140
|
+
}, null, 8, ["value", "error", "label", "name", "placeholder", "validate-on-mount", "onUpdate:value", "rules", "tertiary-label"])
|
|
141
|
+
])) : le("", !0)
|
|
142
|
+
], 64))), 128))
|
|
143
|
+
])
|
|
144
|
+
]),
|
|
145
|
+
_: 1
|
|
146
|
+
}, 8, ["show"]),
|
|
147
|
+
m(i(I), {
|
|
148
|
+
enter: E,
|
|
149
|
+
"enter-from": j,
|
|
150
|
+
"enter-to": O,
|
|
151
|
+
leave: N,
|
|
152
|
+
"leave-from": U,
|
|
153
|
+
"leave-to": B,
|
|
154
|
+
show: n.value
|
|
155
|
+
}, {
|
|
156
|
+
default: k(() => [
|
|
157
|
+
p("div", ye, [
|
|
158
|
+
(l(!0), o(h, null, q(J.value, (t) => (l(), o("div", {
|
|
159
|
+
key: t.name,
|
|
160
|
+
class: "sl-flex-1"
|
|
161
|
+
}, [
|
|
162
|
+
(l(), oe(ne(Q(t.as ?? "TextInput")), {
|
|
163
|
+
name: t.name,
|
|
164
|
+
placeholder: t.placeholder,
|
|
165
|
+
label: t.label,
|
|
166
|
+
value: W(t),
|
|
167
|
+
items: t.items,
|
|
168
|
+
"item-key": t.itemKey,
|
|
169
|
+
"item-text": t.itemText,
|
|
170
|
+
clearable: t.clearable,
|
|
171
|
+
rules: t.rules,
|
|
172
|
+
required: v(t.name, t.required),
|
|
173
|
+
"tertiary-label": S(v(t.name, t.required)),
|
|
174
|
+
class: "sl-text-sm sl-leading-6 sl-text-gray-800 dark:sl-text-gray-200",
|
|
175
|
+
"onUpdate:value": (f) => F(t.name, f)
|
|
176
|
+
}, null, 40, ["name", "placeholder", "label", "value", "items", "item-key", "item-text", "clearable", "rules", "required", "tertiary-label", "onUpdate:value"]))
|
|
177
|
+
]))), 128))
|
|
178
|
+
])
|
|
179
|
+
]),
|
|
180
|
+
_: 1
|
|
181
|
+
}, 8, ["show"]),
|
|
182
|
+
p("p", fe, [
|
|
183
|
+
p("button", {
|
|
184
|
+
type: "button",
|
|
185
|
+
onClick: te,
|
|
186
|
+
class: "sl-text-xs sl-uppercase sl-py-1 hover:sl-text-primary-600 dark:hover:sl-text-primary-400 sl-transition-colors"
|
|
187
|
+
}, ue(n.value ? "Show Less" : "Show More"), 1),
|
|
188
|
+
m(i(ie), { class: "sl-h-4 sl-w-4" })
|
|
189
|
+
])
|
|
190
|
+
], 32));
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
export {
|
|
194
|
+
Te as _
|
|
195
|
+
};
|