@foormjs/vue 0.0.2

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/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # vue
2
+
3
+ This template should help get you started developing with Vue 3 in Vite.
4
+
5
+ ## Recommended IDE Setup
6
+
7
+ [VSCode](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) (and disable Vetur).
8
+
9
+ ## Type Support for `.vue` Imports in TS
10
+
11
+ TypeScript cannot handle type information for `.vue` imports by default, so we replace the `tsc` CLI with `vue-tsc` for type checking. In editors, we need [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) to make the TypeScript language service aware of `.vue` types.
12
+
13
+ ## Customize configuration
14
+
15
+ See [Vite Configuration Reference](https://vitejs.dev/config/).
16
+
17
+ ## Project Setup
18
+
19
+ ```sh
20
+ pnpm install
21
+ ```
22
+
23
+ ### Compile and Hot-Reload for Development
24
+
25
+ ```sh
26
+ pnpm dev
27
+ ```
28
+
29
+ ### Type-Check, Compile and Minify for Production
30
+
31
+ ```sh
32
+ pnpm build
33
+ ```
@@ -0,0 +1,150 @@
1
+ export declare const OoField: <TFormData, TFormContext>(__VLS_props: any, __VLS_ctx?: {
2
+ attrs: any;
3
+ emit: any;
4
+ slots: {
5
+ default?(_: {
6
+ onBlur: any;
7
+ error: any;
8
+ model: any;
9
+ formData: any;
10
+ formContext: any;
11
+ label: any;
12
+ description: any;
13
+ hint: any;
14
+ placeholder: any;
15
+ classes: any;
16
+ styles: any;
17
+ optional: any;
18
+ disabled: any;
19
+ hidden: any;
20
+ type: any;
21
+ altAction: any;
22
+ component: any;
23
+ vName: any;
24
+ field: any;
25
+ options: any;
26
+ length: any;
27
+ required: boolean;
28
+ autocomplete: any;
29
+ attrs: any;
30
+ }): any;
31
+ };
32
+ }, __VLS_expose?: (exposed: any) => void, __VLS_setup?: Promise<{
33
+ props: any;
34
+ expose(exposed: any): void;
35
+ attrs: any;
36
+ slots: {
37
+ default?(_: {
38
+ onBlur: any;
39
+ error: any;
40
+ model: any;
41
+ formData: any;
42
+ formContext: any;
43
+ label: any;
44
+ description: any;
45
+ hint: any;
46
+ placeholder: any;
47
+ classes: any;
48
+ styles: any;
49
+ optional: any;
50
+ disabled: any;
51
+ hidden: any;
52
+ type: any;
53
+ altAction: any;
54
+ component: any;
55
+ vName: any;
56
+ field: any;
57
+ options: any;
58
+ length: any;
59
+ required: boolean;
60
+ autocomplete: any;
61
+ attrs: any;
62
+ }): any;
63
+ };
64
+ emit: any;
65
+ }>) => any;
66
+
67
+ export declare const OoFoorm: <TFormData extends object, TFormContext extends object>(__VLS_props: any, __VLS_ctx?: {
68
+ attrs: any;
69
+ emit: any;
70
+ slots: Partial<Record<`field:${any}`, (_: any) => any>> & {
71
+ "form.header"?(_: {
72
+ clearErrors: any;
73
+ reset: any;
74
+ }): any;
75
+ "form.before"?(_: {
76
+ clearErrors: any;
77
+ reset: any;
78
+ }): any;
79
+ "form.after"?(_: {
80
+ clearErrors: any;
81
+ reset: any;
82
+ }): any;
83
+ "form.submit"?(_: {
84
+ disabled: any;
85
+ clearErrors: any;
86
+ reset: any;
87
+ }): any;
88
+ "form.footer"?(_: {
89
+ clearErrors: any;
90
+ reset: any;
91
+ }): any;
92
+ };
93
+ }, __VLS_expose?: (exposed: any) => void, __VLS_setup?: Promise<{
94
+ props: any;
95
+ expose(exposed: any): void;
96
+ attrs: any;
97
+ slots: Partial<Record<`field:${any}`, (_: any) => any>> & {
98
+ "form.header"?(_: {
99
+ clearErrors: any;
100
+ reset: any;
101
+ }): any;
102
+ "form.before"?(_: {
103
+ clearErrors: any;
104
+ reset: any;
105
+ }): any;
106
+ "form.after"?(_: {
107
+ clearErrors: any;
108
+ reset: any;
109
+ }): any;
110
+ "form.submit"?(_: {
111
+ disabled: any;
112
+ clearErrors: any;
113
+ reset: any;
114
+ }): any;
115
+ "form.footer"?(_: {
116
+ clearErrors: any;
117
+ reset: any;
118
+ }): any;
119
+ };
120
+ emit: any;
121
+ }>) => any;
122
+
123
+ export declare interface TFoormComponentProps<T, TFormData, TFormContext> {
124
+ onBlur: Function;
125
+ error?: string;
126
+ model: {
127
+ value: T;
128
+ };
129
+ formData: TFormData;
130
+ formContext?: TFormContext;
131
+ label?: string;
132
+ description?: string;
133
+ hint?: string;
134
+ placeholder?: string;
135
+ class?: Record<string, boolean>;
136
+ style?: Record<string, string>;
137
+ optional: boolean;
138
+ required: boolean;
139
+ disabled?: boolean;
140
+ hidden?: boolean;
141
+ type: string;
142
+ altAction?: string;
143
+ name?: string;
144
+ field?: string;
145
+ options?: unknown[];
146
+ length?: number;
147
+ autocomplete?: string;
148
+ }
149
+
150
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,378 @@
1
+ import { defineComponent as q, mergeModels as I, useModel as L, inject as O, ref as k, computed as u, watch as R, onUnmounted as T, getCurrentInstance as N, renderSlot as D, unref as x, provide as W, openBlock as m, createElementBlock as C, withModifiers as G, nextTick as J, createBlock as B, withCtx as w, toDisplayString as b, createCommentVNode as j, Fragment as K, renderList as Q, normalizeProps as A, guardReactiveProps as M, resolveDynamicComponent as F, mergeProps as H, normalizeClass as X, createElementVNode as $, withDirectives as Y, vModelDynamic as Z } from "vue";
2
+ function f(n, r) {
3
+ return U(n) ? n(r) : n;
4
+ }
5
+ function S(n, r) {
6
+ if (typeof n == "object" && n !== null) {
7
+ const o = {};
8
+ for (const [t, c] of Object.entries(n))
9
+ o[t] = f(c, r);
10
+ return o;
11
+ }
12
+ return U(n) ? n(r) : n;
13
+ }
14
+ function U(n) {
15
+ return typeof n == "function";
16
+ }
17
+ const ee = /* @__PURE__ */ q({
18
+ __name: "VuilessField",
19
+ props: /* @__PURE__ */ I({
20
+ rules: {}
21
+ }, {
22
+ modelValue: {},
23
+ modelModifiers: {}
24
+ }),
25
+ emits: ["update:modelValue"],
26
+ setup(n) {
27
+ const r = n, o = L(n, "modelValue"), t = O("vuiless"), c = k(), d = k(!1), v = k(!1), _ = u(() => {
28
+ var a;
29
+ if ((a = t == null ? void 0 : t.value) != null && a.firstValidation)
30
+ switch (t.value.firstValidation) {
31
+ case "on-change":
32
+ return t.value.firstSubmitHappened || d.value;
33
+ case "touched-on-blur":
34
+ return t.value.firstSubmitHappened || v.value && d.value;
35
+ case "on-blur":
36
+ return t.value.firstSubmitHappened || v.value;
37
+ case "on-submit":
38
+ return t.value.firstSubmitHappened;
39
+ case "none":
40
+ return !1;
41
+ }
42
+ return !1;
43
+ }), h = u(() => {
44
+ if (_.value || c.value)
45
+ return p();
46
+ });
47
+ R([o], () => {
48
+ c.value = void 0, d.value = !0;
49
+ }), T(() => {
50
+ var a;
51
+ (a = t == null ? void 0 : t.value) == null || a.unregister(N());
52
+ }), t != null && t.value && t.value.register(N(), {
53
+ validate: () => (c.value = p(), c.value || !0),
54
+ clearErrors: () => {
55
+ d.value = !1, v.value = !1, c.value = void 0;
56
+ },
57
+ reset: () => {
58
+ o.value = "";
59
+ }
60
+ });
61
+ function p() {
62
+ var a, e, y;
63
+ if ((a = r.rules) != null && a.length)
64
+ for (const g of r.rules) {
65
+ const s = g(
66
+ o.value,
67
+ (e = t == null ? void 0 : t.value) == null ? void 0 : e.formData,
68
+ (y = t == null ? void 0 : t.value) == null ? void 0 : y.formContext
69
+ );
70
+ if (s !== !0)
71
+ return s || "Wrong value";
72
+ }
73
+ }
74
+ function i() {
75
+ v.value = !0;
76
+ }
77
+ const l = {
78
+ v: u({
79
+ get: () => o.value,
80
+ set: (a) => o.value = a
81
+ })
82
+ };
83
+ return (a, e) => {
84
+ var y, g;
85
+ return D(a.$slots, "default", {
86
+ onBlur: i,
87
+ error: h.value,
88
+ formData: (y = x(t)) == null ? void 0 : y.formData,
89
+ formContext: (g = x(t)) == null ? void 0 : g.formContext,
90
+ model: l.v
91
+ });
92
+ };
93
+ }
94
+ }), te = /* @__PURE__ */ q({
95
+ __name: "VuilessForm",
96
+ props: {
97
+ formData: {},
98
+ formContext: {},
99
+ firstValidation: { default: "on-change" }
100
+ },
101
+ emits: ["submit"],
102
+ setup(n, { emit: r }) {
103
+ const o = n, t = r, c = /* @__PURE__ */ new Map(), d = k(!1), v = u(() => ({
104
+ firstSubmitHappened: d.value,
105
+ firstValidation: o.firstValidation,
106
+ register: (i, l) => {
107
+ c.set(i, l);
108
+ },
109
+ unregister: (i) => c.delete(i),
110
+ formData: o.formData,
111
+ formContext: o.formContext
112
+ }));
113
+ W("vuiless", v);
114
+ function _() {
115
+ d.value = !1;
116
+ for (const { clearErrors: i } of c.values())
117
+ i();
118
+ }
119
+ async function h() {
120
+ for (const { reset: i } of c.values())
121
+ i();
122
+ await J(), _();
123
+ }
124
+ function p() {
125
+ d.value = !0;
126
+ let i = !1;
127
+ if (o.firstValidation !== "none")
128
+ for (const { validate: l } of c.values())
129
+ l() !== !0 && (i = !0);
130
+ i || t("submit", o.formData);
131
+ }
132
+ return (i, l) => (m(), C("form", {
133
+ onSubmit: G(p, ["prevent"])
134
+ }, [
135
+ D(i.$slots, "default", {
136
+ clearErrors: _,
137
+ reset: h
138
+ })
139
+ ], 32));
140
+ }
141
+ }), oe = /* @__PURE__ */ q({
142
+ __name: "oo-field",
143
+ props: {
144
+ field: {},
145
+ altAction: {},
146
+ label: {},
147
+ description: {},
148
+ hint: {},
149
+ placeholder: {},
150
+ classes: {},
151
+ styles: {},
152
+ type: {},
153
+ component: {},
154
+ autocomplete: {},
155
+ name: {},
156
+ value: {},
157
+ options: {},
158
+ attrs: {},
159
+ optional: { type: Boolean },
160
+ disabled: { type: Boolean },
161
+ hidden: { type: Boolean },
162
+ length: {},
163
+ validators: {}
164
+ },
165
+ setup(n) {
166
+ const r = n, o = O(
167
+ "vuiless"
168
+ ), t = u(
169
+ () => ({
170
+ v: o.value.formData[r.field],
171
+ data: o == null ? void 0 : o.value.formData,
172
+ context: o == null ? void 0 : o.value.formContext,
173
+ entry: r
174
+ })
175
+ ), c = u(() => f(r.label, t.value)), d = u(() => f(r.description, t.value)), v = u(() => f(r.hint, t.value)), _ = u(() => f(r.placeholder, t.value)), h = u(() => f(r.optional, t.value)), p = u(() => f(r.disabled, t.value)), i = u(() => f(r.hidden, t.value)), l = u(() => f(r.options, t.value)), a = u(() => {
176
+ const s = S(r.classes, t.value);
177
+ return typeof s == "string" ? {
178
+ [s]: !0,
179
+ disabled: p.value,
180
+ // error: !validation.value.passed,
181
+ required: !h.value
182
+ } : {
183
+ ...s || {},
184
+ disabled: p.value,
185
+ // error: !validation.value.passed,
186
+ required: !h.value
187
+ };
188
+ }), e = u(
189
+ () => S(r.styles, t.value)
190
+ ), y = u(() => S(r.attrs, t.value)), g = u(() => {
191
+ var s;
192
+ return (s = r.validators) == null ? void 0 : s.map(
193
+ (E) => (V, P, z) => E({
194
+ v: V,
195
+ data: P,
196
+ context: z,
197
+ entry: r
198
+ })
199
+ );
200
+ });
201
+ return (s, E) => (m(), B(x(ee), {
202
+ modelValue: x(o).formData[r.field],
203
+ "onUpdate:modelValue": E[0] || (E[0] = (V) => x(o).formData[r.field] = V),
204
+ rules: g.value
205
+ }, {
206
+ default: w((V) => [
207
+ D(s.$slots, "default", {
208
+ onBlur: V.onBlur,
209
+ error: V.error,
210
+ model: V.model,
211
+ formData: x(o).formData,
212
+ formContext: x(o).formContext,
213
+ label: c.value,
214
+ description: d.value,
215
+ hint: v.value,
216
+ placeholder: _.value,
217
+ classes: {
218
+ ...a.value,
219
+ error: !!V.error
220
+ },
221
+ styles: e.value,
222
+ optional: h.value,
223
+ disabled: p.value,
224
+ hidden: i.value,
225
+ type: s.type,
226
+ altAction: s.altAction,
227
+ component: s.component,
228
+ vName: s.name,
229
+ field: s.field,
230
+ options: l.value,
231
+ length: s.length,
232
+ required: !h.value,
233
+ autocomplete: s.autocomplete,
234
+ attrs: y.value
235
+ })
236
+ ]),
237
+ _: 3
238
+ }, 8, ["modelValue", "rules"]));
239
+ }
240
+ }), re = { key: 0 }, ae = { key: 1 }, ne = { key: 0 }, le = ["onUpdate:modelValue", "onBlur", "placeholder", "autocomplete", "name", "type"], se = { class: "oo-error-slot" }, ue = { key: 4 }, ie = { key: 5 }, ce = ["disabled"], me = /* @__PURE__ */ q({
241
+ __name: "oo-form",
242
+ props: {
243
+ form: {},
244
+ formData: {},
245
+ formContext: {},
246
+ firstValidation: {},
247
+ components: {},
248
+ types: {}
249
+ },
250
+ emits: ["submit"],
251
+ setup(n, { emit: r }) {
252
+ const o = n, t = u(() => o.form.executable()), c = u(
253
+ () => ({
254
+ v: void 0,
255
+ data: v.value,
256
+ context: o.formContext,
257
+ entry: o
258
+ })
259
+ ), d = k({}), v = u(() => o.formData || d.value), _ = u(
260
+ () => f(t.value.submit.disabled, c.value)
261
+ ), h = r;
262
+ return (p, i) => (m(), B(x(te), {
263
+ "first-validation": p.firstValidation,
264
+ onSubmit: i[0] || (i[0] = (l) => h("submit", l)),
265
+ "form-data": v.value,
266
+ "form-context": p.formContext
267
+ }, {
268
+ default: w((l) => [
269
+ D(p.$slots, "form.header", {
270
+ clearErrors: l.clearErrors,
271
+ reset: l.reset
272
+ }, () => [
273
+ t.value.title ? (m(), C("h2", re, b(t.value.title), 1)) : j("", !0)
274
+ ]),
275
+ D(p.$slots, "form.before", {
276
+ clearErrors: l.clearErrors,
277
+ reset: l.reset
278
+ }),
279
+ (m(!0), C(K, null, Q(t.value.entries, (a) => (m(), B(oe, A(M(a)), {
280
+ default: w((e) => [
281
+ D(p.$slots, `field:${e.type}`, A(M(e)), () => {
282
+ var y, g, s;
283
+ return [
284
+ a.component && ((y = o.components) != null && y[a.component]) ? (m(), B(F(o.components[a.component]), H({
285
+ key: 0,
286
+ "on-blur": e.onBlur,
287
+ error: e.error,
288
+ model: e.model,
289
+ "form-data": e.formData,
290
+ "form-context": e.formContext,
291
+ label: e.label,
292
+ description: e.description,
293
+ hint: e.hint,
294
+ placeholder: e.placeholder,
295
+ class: e.classes,
296
+ style: e.styles,
297
+ optional: e.optional,
298
+ required: !e.required,
299
+ disabled: e.disabled,
300
+ hidden: e.hidden,
301
+ type: e.type,
302
+ "alt-action": e.altAction,
303
+ name: e.vName,
304
+ field: e,
305
+ options: e.options,
306
+ length: e.length,
307
+ autocomplete: e.autocomplete
308
+ }, e.attrs), null, 16, ["on-blur", "error", "model", "form-data", "form-context", "label", "description", "hint", "placeholder", "class", "style", "optional", "required", "disabled", "hidden", "type", "alt-action", "name", "field", "options", "length", "autocomplete"])) : a.component && !((g = o.components) != null && g[a.component]) ? (m(), C("div", ae, " [" + b(e.label) + '] Component "' + b(e.component) + '" not supplied ', 1)) : (s = o.types) != null && s[a.type] ? (m(), B(F(o.types[a.type]), H({
309
+ key: 2,
310
+ "on-blur": e.onBlur,
311
+ error: e.error,
312
+ model: e.model,
313
+ "form-data": e.formData,
314
+ "form-context": e.formContext,
315
+ label: e.label,
316
+ description: e.description,
317
+ hint: e.hint,
318
+ placeholder: e.placeholder,
319
+ class: e.classes,
320
+ style: e.styles,
321
+ optional: e.optional,
322
+ required: !e.required,
323
+ disabled: e.disabled,
324
+ hidden: e.hidden,
325
+ type: e.type,
326
+ "alt-action": e.altAction,
327
+ name: e.vName,
328
+ field: e,
329
+ options: e.options,
330
+ length: e.length,
331
+ autocomplete: e.autocomplete
332
+ }, e.attrs), null, 16, ["on-blur", "error", "model", "form-data", "form-context", "label", "description", "hint", "placeholder", "class", "style", "optional", "required", "disabled", "hidden", "type", "alt-action", "name", "field", "options", "length", "autocomplete"])) : ["text", "password", "number"].includes(e.type) ? (m(), C("div", {
333
+ key: 3,
334
+ class: X(["oo-default-field", e.classes])
335
+ }, [
336
+ $("label", null, b(e.label), 1),
337
+ e.description ? (m(), C("span", ne, b(e.description), 1)) : j("", !0),
338
+ Y($("input", {
339
+ "onUpdate:modelValue": (E) => e.model.value = E,
340
+ onBlur: e.onBlur,
341
+ placeholder: e.placeholder,
342
+ autocomplete: e.autocomplete,
343
+ name: e.vName,
344
+ type: e.type
345
+ }, null, 40, le), [
346
+ [Z, e.model.value]
347
+ ]),
348
+ $("div", se, b(e.error || e.hint), 1)
349
+ ], 2)) : e.type === "paragraph" ? (m(), C("p", ue, b(e.description), 1)) : (m(), C("div", ie, " [" + b(e.label) + '] Not supported field type "' + b(e.type) + '" ' + b(e.component), 1))
350
+ ];
351
+ })
352
+ ]),
353
+ _: 2
354
+ }, 1040))), 256)),
355
+ D(p.$slots, "form.after", {
356
+ clearErrors: l.clearErrors,
357
+ reset: l.reset
358
+ }),
359
+ D(p.$slots, "form.submit", {
360
+ disabled: _.value,
361
+ clearErrors: l.clearErrors,
362
+ reset: l.reset
363
+ }, () => [
364
+ $("button", { disabled: _.value }, b(t.value.submit.text), 9, ce)
365
+ ]),
366
+ D(p.$slots, "form.footer", {
367
+ clearErrors: l.clearErrors,
368
+ reset: l.reset
369
+ })
370
+ ]),
371
+ _: 3
372
+ }, 8, ["first-validation", "form-data", "form-context"]));
373
+ }
374
+ });
375
+ export {
376
+ oe as OoField,
377
+ me as OoFoorm
378
+ };
@@ -0,0 +1 @@
1
+ (function(B,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(B=typeof globalThis<"u"?globalThis:B||self,e(B.index={},B.Vue))})(this,function(B,e){"use strict";function f(l,n){return S(l)?l(n):l}function C(l,n){if(typeof l=="object"&&l!==null){const r={};for(const[o,p]of Object.entries(l))r[o]=f(p,n);return r}return S(l)?l(n):l}function S(l){return typeof l=="function"}const V=e.defineComponent({__name:"VuilessField",props:e.mergeModels({rules:{}},{modelValue:{},modelModifiers:{}}),emits:["update:modelValue"],setup(l){const n=l,r=e.useModel(l,"modelValue"),o=e.inject("vuiless"),p=e.ref(),d=e.ref(!1),u=e.ref(!1),h=e.computed(()=>{var a;if((a=o==null?void 0:o.value)!=null&&a.firstValidation)switch(o.value.firstValidation){case"on-change":return o.value.firstSubmitHappened||d.value;case"touched-on-blur":return o.value.firstSubmitHappened||u.value&&d.value;case"on-blur":return o.value.firstSubmitHappened||u.value;case"on-submit":return o.value.firstSubmitHappened;case"none":return!1}return!1}),y=e.computed(()=>{if(h.value||p.value)return m()});e.watch([r],()=>{p.value=void 0,d.value=!0}),e.onUnmounted(()=>{var a;(a=o==null?void 0:o.value)==null||a.unregister(e.getCurrentInstance())}),o!=null&&o.value&&o.value.register(e.getCurrentInstance(),{validate:()=>(p.value=m(),p.value||!0),clearErrors:()=>{d.value=!1,u.value=!1,p.value=void 0},reset:()=>{r.value=""}});function m(){var a,t,b;if((a=n.rules)!=null&&a.length)for(const g of n.rules){const c=g(r.value,(t=o==null?void 0:o.value)==null?void 0:t.formData,(b=o==null?void 0:o.value)==null?void 0:b.formContext);if(c!==!0)return c||"Wrong value"}}function i(){u.value=!0}const s={v:e.computed({get:()=>r.value,set:a=>r.value=a})};return(a,t)=>{var b,g;return e.renderSlot(a.$slots,"default",{onBlur:i,error:y.value,formData:(b=e.unref(o))==null?void 0:b.formData,formContext:(g=e.unref(o))==null?void 0:g.formContext,model:s.v})}}}),E=e.defineComponent({__name:"VuilessForm",props:{formData:{},formContext:{},firstValidation:{default:"on-change"}},emits:["submit"],setup(l,{emit:n}){const r=l,o=n,p=new Map,d=e.ref(!1),u=e.computed(()=>({firstSubmitHappened:d.value,firstValidation:r.firstValidation,register:(i,s)=>{p.set(i,s)},unregister:i=>p.delete(i),formData:r.formData,formContext:r.formContext}));e.provide("vuiless",u);function h(){d.value=!1;for(const{clearErrors:i}of p.values())i()}async function y(){for(const{reset:i}of p.values())i();await e.nextTick(),h()}function m(){d.value=!0;let i=!1;if(r.firstValidation!=="none")for(const{validate:s}of p.values())s()!==!0&&(i=!0);i||o("submit",r.formData)}return(i,s)=>(e.openBlock(),e.createElementBlock("form",{onSubmit:e.withModifiers(m,["prevent"])},[e.renderSlot(i.$slots,"default",{clearErrors:h,reset:y})],32))}}),_=e.defineComponent({__name:"oo-field",props:{field:{},altAction:{},label:{},description:{},hint:{},placeholder:{},classes:{},styles:{},type:{},component:{},autocomplete:{},name:{},value:{},options:{},attrs:{},optional:{type:Boolean},disabled:{type:Boolean},hidden:{type:Boolean},length:{},validators:{}},setup(l){const n=l,r=e.inject("vuiless"),o=e.computed(()=>({v:r.value.formData[n.field],data:r==null?void 0:r.value.formData,context:r==null?void 0:r.value.formContext,entry:n})),p=e.computed(()=>f(n.label,o.value)),d=e.computed(()=>f(n.description,o.value)),u=e.computed(()=>f(n.hint,o.value)),h=e.computed(()=>f(n.placeholder,o.value)),y=e.computed(()=>f(n.optional,o.value)),m=e.computed(()=>f(n.disabled,o.value)),i=e.computed(()=>f(n.hidden,o.value)),s=e.computed(()=>f(n.options,o.value)),a=e.computed(()=>{const c=C(n.classes,o.value);return typeof c=="string"?{[c]:!0,disabled:m.value,required:!y.value}:{...c||{},disabled:m.value,required:!y.value}}),t=e.computed(()=>C(n.styles,o.value)),b=e.computed(()=>C(n.attrs,o.value)),g=e.computed(()=>{var c;return(c=n.validators)==null?void 0:c.map(D=>(k,F,H)=>D({v:k,data:F,context:H,entry:n}))});return(c,D)=>(e.openBlock(),e.createBlock(e.unref(V),{modelValue:e.unref(r).formData[n.field],"onUpdate:modelValue":D[0]||(D[0]=k=>e.unref(r).formData[n.field]=k),rules:g.value},{default:e.withCtx(k=>[e.renderSlot(c.$slots,"default",{onBlur:k.onBlur,error:k.error,model:k.model,formData:e.unref(r).formData,formContext:e.unref(r).formContext,label:p.value,description:d.value,hint:u.value,placeholder:h.value,classes:{...a.value,error:!!k.error},styles:t.value,optional:y.value,disabled:m.value,hidden:i.value,type:c.type,altAction:c.altAction,component:c.component,vName:c.name,field:c.field,options:s.value,length:c.length,required:!y.value,autocomplete:c.autocomplete,attrs:b.value})]),_:3},8,["modelValue","rules"]))}}),x={key:0},N={key:1},$={key:0},q=["onUpdate:modelValue","onBlur","placeholder","autocomplete","name","type"],w={class:"oo-error-slot"},j={key:4},M={key:5},P=["disabled"],A=e.defineComponent({__name:"oo-form",props:{form:{},formData:{},formContext:{},firstValidation:{},components:{},types:{}},emits:["submit"],setup(l,{emit:n}){const r=l,o=e.computed(()=>r.form.executable()),p=e.computed(()=>({v:void 0,data:u.value,context:r.formContext,entry:r})),d=e.ref({}),u=e.computed(()=>r.formData||d.value),h=e.computed(()=>f(o.value.submit.disabled,p.value)),y=n;return(m,i)=>(e.openBlock(),e.createBlock(e.unref(E),{"first-validation":m.firstValidation,onSubmit:i[0]||(i[0]=s=>y("submit",s)),"form-data":u.value,"form-context":m.formContext},{default:e.withCtx(s=>[e.renderSlot(m.$slots,"form.header",{clearErrors:s.clearErrors,reset:s.reset},()=>[o.value.title?(e.openBlock(),e.createElementBlock("h2",x,e.toDisplayString(o.value.title),1)):e.createCommentVNode("",!0)]),e.renderSlot(m.$slots,"form.before",{clearErrors:s.clearErrors,reset:s.reset}),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.value.entries,a=>(e.openBlock(),e.createBlock(_,e.normalizeProps(e.guardReactiveProps(a)),{default:e.withCtx(t=>[e.renderSlot(m.$slots,`field:${t.type}`,e.normalizeProps(e.guardReactiveProps(t)),()=>{var b,g,c;return[a.component&&((b=r.components)!=null&&b[a.component])?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(r.components[a.component]),e.mergeProps({key:0,"on-blur":t.onBlur,error:t.error,model:t.model,"form-data":t.formData,"form-context":t.formContext,label:t.label,description:t.description,hint:t.hint,placeholder:t.placeholder,class:t.classes,style:t.styles,optional:t.optional,required:!t.required,disabled:t.disabled,hidden:t.hidden,type:t.type,"alt-action":t.altAction,name:t.vName,field:t,options:t.options,length:t.length,autocomplete:t.autocomplete},t.attrs),null,16,["on-blur","error","model","form-data","form-context","label","description","hint","placeholder","class","style","optional","required","disabled","hidden","type","alt-action","name","field","options","length","autocomplete"])):a.component&&!((g=r.components)!=null&&g[a.component])?(e.openBlock(),e.createElementBlock("div",N," ["+e.toDisplayString(t.label)+'] Component "'+e.toDisplayString(t.component)+'" not supplied ',1)):(c=r.types)!=null&&c[a.type]?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(r.types[a.type]),e.mergeProps({key:2,"on-blur":t.onBlur,error:t.error,model:t.model,"form-data":t.formData,"form-context":t.formContext,label:t.label,description:t.description,hint:t.hint,placeholder:t.placeholder,class:t.classes,style:t.styles,optional:t.optional,required:!t.required,disabled:t.disabled,hidden:t.hidden,type:t.type,"alt-action":t.altAction,name:t.vName,field:t,options:t.options,length:t.length,autocomplete:t.autocomplete},t.attrs),null,16,["on-blur","error","model","form-data","form-context","label","description","hint","placeholder","class","style","optional","required","disabled","hidden","type","alt-action","name","field","options","length","autocomplete"])):["text","password","number"].includes(t.type)?(e.openBlock(),e.createElementBlock("div",{key:3,class:e.normalizeClass(["oo-default-field",t.classes])},[e.createElementVNode("label",null,e.toDisplayString(t.label),1),t.description?(e.openBlock(),e.createElementBlock("span",$,e.toDisplayString(t.description),1)):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":D=>t.model.value=D,onBlur:t.onBlur,placeholder:t.placeholder,autocomplete:t.autocomplete,name:t.vName,type:t.type},null,40,q),[[e.vModelDynamic,t.model.value]]),e.createElementVNode("div",w,e.toDisplayString(t.error||t.hint),1)],2)):t.type==="paragraph"?(e.openBlock(),e.createElementBlock("p",j,e.toDisplayString(t.description),1)):(e.openBlock(),e.createElementBlock("div",M," ["+e.toDisplayString(t.label)+'] Not supported field type "'+e.toDisplayString(t.type)+'" '+e.toDisplayString(t.component),1))]})]),_:2},1040))),256)),e.renderSlot(m.$slots,"form.after",{clearErrors:s.clearErrors,reset:s.reset}),e.renderSlot(m.$slots,"form.submit",{disabled:h.value,clearErrors:s.clearErrors,reset:s.reset},()=>[e.createElementVNode("button",{disabled:h.value},e.toDisplayString(o.value.submit.text),9,P)]),e.renderSlot(m.$slots,"form.footer",{clearErrors:s.clearErrors,reset:s.reset})]),_:3},8,["first-validation","form-data","form-context"]))}});B.OoField=_,B.OoFoorm=A,Object.defineProperty(B,Symbol.toStringTag,{value:"Module"})});
package/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ .oo-default-field{display:flex;flex-direction:column;gap:4px}.oo-default-field.required label:after{content:" *";color:red}.oo-default-field.error input{outline:1px solid red}.oo-default-field .oo-error-slot{height:14px;line-height:12px;font-size:12px}.oo-default-field.error .oo-error-slot{color:red}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@foormjs/vue",
3
+ "version": "0.0.2",
4
+ "description": "@foormjs/vue",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "sideEffects": false,
9
+ "customBuild": true,
10
+ "exports": {
11
+ "./package.json": "./package.json",
12
+ "./styles": "./dist/style.css",
13
+ ".": {
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.umd.cjs",
16
+ "types": "./dist/index.d.ts"
17
+ }
18
+ },
19
+ "type": "module",
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/foormjs/foormjs.git",
26
+ "directory": "packages/vue"
27
+ },
28
+ "keywords": [
29
+ "foorm",
30
+ "foormjs",
31
+ "foorm",
32
+ "foormjs",
33
+ "forms",
34
+ "validations"
35
+ ],
36
+ "author": "Artem Maltsev",
37
+ "license": "MIT",
38
+ "bugs": {
39
+ "url": "https://github.com/foormjs/foormjs/issues"
40
+ },
41
+ "homepage": "https://github.com/foormjs/foormjs/tree/main/packages/vue#readme",
42
+ "scripts": {
43
+ "dev": "vite",
44
+ "build": "run-p type-check \"build-only {@}\" --",
45
+ "preview": "vite preview",
46
+ "build-only": "vite build",
47
+ "type-check": "vue-tsc --build --force"
48
+ },
49
+ "dependencies": {
50
+ "foorm": "0.0.2",
51
+ "vue": "^3.3.9",
52
+ "vuiless-forms": "^0.0.3"
53
+ },
54
+ "devDependencies": {
55
+ "@tsconfig/node20": "^20.1.2",
56
+ "@types/node": "^20.11.28",
57
+ "@vitejs/plugin-vue": "^5.0.4",
58
+ "@vue/tsconfig": "^0.5.1",
59
+ "npm-run-all2": "^6.1.2",
60
+ "typescript": "~5.4.0",
61
+ "vite": "^5.1.6",
62
+ "vite-plugin-dts": "^3.8.1",
63
+ "vue-tsc": "^2.0.6"
64
+ }
65
+ }