@effect-app/vue-components 0.6.2 → 0.7.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.
Files changed (37) hide show
  1. package/dist/types/components/OmegaForm/OmegaArray.vue.d.ts +24 -0
  2. package/dist/types/components/OmegaForm/OmegaFormStuff.d.ts +16 -2
  3. package/dist/types/components/OmegaForm/index.d.ts +2 -1
  4. package/dist/vue-components.es.js +22 -19
  5. package/dist/vue-components.es10.js +5 -5
  6. package/dist/vue-components.es11.js +6 -108
  7. package/dist/vue-components.es12.js +110 -0
  8. package/dist/vue-components.es14.js +7 -2
  9. package/dist/vue-components.es15.js +2 -88
  10. package/dist/vue-components.es16.js +90 -0
  11. package/dist/vue-components.es18.js +2 -5
  12. package/dist/vue-components.es19.js +2 -32
  13. package/dist/vue-components.es2.js +14 -11
  14. package/dist/vue-components.es20.js +5 -2
  15. package/dist/vue-components.es21.js +32 -2
  16. package/dist/vue-components.es22.js +32 -31
  17. package/dist/vue-components.es24.js +2 -2
  18. package/dist/vue-components.es25.js +2 -115
  19. package/dist/vue-components.es26.js +4 -0
  20. package/dist/vue-components.es27.js +115 -4
  21. package/dist/vue-components.es29.js +6 -0
  22. package/dist/vue-components.es4.js +19 -18
  23. package/dist/vue-components.es6.js +50 -36
  24. package/dist/vue-components.es7.js +34 -131
  25. package/dist/vue-components.es8.js +128 -211
  26. package/dist/vue-components.es9.js +218 -6
  27. package/package.json +1 -1
  28. package/src/components/OmegaForm/OmegaArray.vue +67 -0
  29. package/src/components/OmegaForm/OmegaErrors.vue +7 -3
  30. package/src/components/OmegaForm/OmegaFormInput.vue +6 -2
  31. package/src/components/OmegaForm/OmegaFormStuff.ts +5 -1
  32. package/src/components/OmegaForm/OmegaInput.vue +9 -1
  33. package/src/components/OmegaForm/OmegaInputVuetify.vue +3 -2
  34. package/src/components/OmegaForm/OmegaInternalInput.vue +1 -1
  35. package/src/components/OmegaForm/index.ts +2 -1
  36. package/dist/vue-components.es13.js +0 -9
  37. package/dist/vue-components.es17.js +0 -4
@@ -1,135 +1,38 @@
1
- import { useForm as I } from "@tanstack/vue-form";
2
- import { S as N } from "effect-app";
3
- import { generateMetaFromSchema as R } from "./vue-components.es8.js";
4
- import { computed as b, onUnmounted as A, onMounted as D, onBeforeUnmount as J, provide as K } from "vue";
5
- import { isObject as q } from "./vue-components.es18.js";
6
- import M from "./vue-components.es19.js";
7
- const x = Symbol("OmegaForm"), H = (w, s, i) => {
8
- if (!w) throw new Error("Schema is required");
9
- const V = N.standardSchemaV1(w), { filterItems: L, meta: t } = R(w), d = b(() => {
10
- var l;
11
- if ((l = i == null ? void 0 : i.persistency) != null && l.id)
12
- return i.persistency.id;
13
- const e = window.location.pathname, r = Object.keys(t);
14
- return `${e}-${r.join("-")}`;
15
- }), U = () => {
16
- const e = new URLSearchParams(window.location.search);
17
- e.delete(d.value);
18
- const r = new URL(window.location.href);
19
- r.search = e.toString(), window.history.replaceState({}, "", r.toString());
20
- };
21
- function v(e, r) {
22
- for (const l in r)
23
- r[l] && q(r[l]) ? (e[l] || (e[l] = {}), v(e[l], r[l])) : e[l] = r[l];
24
- return e;
25
- }
26
- const j = b(() => {
27
- var l;
28
- if (s != null && s.defaultValues && !((l = i == null ? void 0 : i.persistency) != null && l.overrideDefaultValues))
29
- return s == null ? void 0 : s.defaultValues;
30
- let e;
31
- const r = i == null ? void 0 : i.persistency;
32
- if (!(r != null && r.policies) || r.policies.length === 0) return {};
33
- if (r.policies.includes("querystring"))
34
- try {
35
- const c = new URLSearchParams(window.location.search).get(d.value);
36
- U(), c && (e = JSON.parse(c));
37
- } catch (u) {
38
- console.error(u);
39
- }
40
- if (
41
- // query string has higher priority than local/session storage
42
- !e && (r.policies.includes("local") || r.policies.includes("session"))
43
- ) {
44
- const u = r.policies.includes("local") ? localStorage : sessionStorage;
45
- if (u)
46
- try {
47
- const c = JSON.parse(
48
- u.getItem(d.value) || "{}"
49
- );
50
- u.removeItem(d.value), e = c;
51
- } catch (c) {
52
- console.error(c);
53
- }
54
- }
55
- if (e ?? (e = {}), (s == null ? void 0 : s.defaultValues) == null)
56
- return e;
57
- {
58
- const u = s == null ? void 0 : s.defaultValues;
59
- return v(u, e);
60
- }
61
- }), n = I({
62
- ...s,
63
- validators: {
64
- onSubmit: V,
65
- ...(s == null ? void 0 : s.validators) || {}
66
- },
67
- onSubmit: s != null && s.onSubmit ? ({ formApi: e, meta: r, value: l }) => {
68
- var u;
69
- return (u = s.onSubmit) == null ? void 0 : u.call(s, {
70
- formApi: e,
71
- meta: r,
72
- value: l
73
- });
74
- } : void 0,
75
- defaultValues: j.value
76
- }), E = () => {
77
- Object.keys(t).forEach((e) => {
78
- n.setFieldValue(e, void 0);
79
- });
80
- }, S = (e) => e.reduce(
81
- (r, l) => {
82
- const u = l.split(".");
83
- return u.reduce((c, o, P) => (P === u.length - 1 ? c[o] = n.getFieldValue(l) : c[o] = c[o] ?? {}, c[o]), r), r;
84
- },
85
- {}
86
- ), f = (e) => {
87
- if (e) {
88
- if (Array.isArray(e.keys))
89
- return S(e.keys);
90
- if (Array.isArray(e.banKeys)) {
91
- const r = Object.keys(t).filter(
92
- (l) => {
93
- var u;
94
- return (u = e.banKeys) == null ? void 0 : u.includes(l);
95
- }
96
- );
97
- return S(r);
98
- }
99
- return n.store.state.values;
100
- }
101
- }, h = () => {
102
- const e = i == null ? void 0 : i.persistency;
103
- if (!(!(e != null && e.policies) || e.policies.length === 0) && (e.policies.includes("local") || e.policies.includes("session"))) {
104
- const r = e.policies.includes("local") ? localStorage : sessionStorage;
105
- if (!r) return;
106
- const l = f(e);
107
- return r.setItem(d.value, JSON.stringify(l));
108
- }
109
- }, a = () => {
110
- const e = i == null ? void 0 : i.persistency;
111
- if (!(!(e != null && e.policies) || e.policies.length === 0) && e.policies.includes("querystring")) {
112
- const r = f(e), l = new URLSearchParams(window.location.search);
113
- l.set(d.value, JSON.stringify(r));
114
- const u = new URL(window.location.href);
115
- u.search = l.toString(), window.history.replaceState({}, "", u.toString());
1
+ import { ref as l, computed as p, readonly as v, provide as E, inject as f } from "vue";
2
+ const u = Symbol();
3
+ function h(e, a, t = "onSubmit") {
4
+ const r = l([]), n = (o) => {
5
+ r.value = r.value.filter((d) => d.inputId !== o);
6
+ }, c = (o) => {
7
+ n(o.inputId), r.value.push(o);
8
+ }, i = () => {
9
+ r.value = [];
10
+ }, m = p(() => {
11
+ switch (t) {
12
+ case "onChange":
13
+ return !0;
14
+ default:
15
+ return e.value > 0;
116
16
  }
17
+ }), s = {
18
+ errors: v(r),
19
+ addError: c,
20
+ removeError: n,
21
+ clearErrors: i,
22
+ showErrors: m,
23
+ generalErrors: a,
24
+ showErrorsOn: t ?? "onSubmit"
117
25
  };
118
- A(h), D(() => {
119
- window.addEventListener("beforeunload", h), window.addEventListener("blur", a);
120
- }), J(() => {
121
- window.removeEventListener("beforeunload", h), window.removeEventListener("blur", a);
122
- });
123
- const y = Object.assign(n, {
124
- meta: t,
125
- filterItems: L,
126
- clear: E
127
- });
128
- return K(x, y), Object.assign(y, {
129
- Input: M
130
- });
131
- };
26
+ return E(u, s), s;
27
+ }
28
+ function w() {
29
+ const e = f(u);
30
+ if (!e)
31
+ throw new Error("useOmegaErrors must be used within an OmegaForm provider");
32
+ return e;
33
+ }
132
34
  export {
133
- x as OmegaFormKey,
134
- H as useOmegaForm
35
+ u as OmegaErrorsKey,
36
+ h as provideOmegaErrors,
37
+ w as useOmegaErrors
135
38
  };
@@ -1,218 +1,135 @@
1
- import { S as i, pipe as p, Option as f } from "effect-app";
2
- import { useIntl as S } from "./vue-components.es3.js";
3
- const y = i.NonEmptyArray(i.String), v = (e) => i.AST.isUnion(e) && e.types.find((t) => t._tag === "UndefinedKeyword" || t === i.Null.ast), x = (e) => !e || !i.AST.isUnion(e) ? !1 : e.types.find((t) => t._tag === "UndefinedKeyword") ? "undefined" : e.types.find((t) => t === i.Null.ast) ? "null" : !1, m = ({ meta: e = {}, parent: t = "", property: n, propertySignatures: a }, l = {}) => {
4
- if (n && n._tag === "Transformation")
5
- return m({
6
- parent: t,
7
- meta: e,
8
- property: n.from
9
- });
10
- if ((n == null ? void 0 : n._tag) === "TypeLiteral" && "propertySignatures" in n)
11
- return m({
12
- meta: e,
13
- propertySignatures: n.propertySignatures
14
- });
15
- if (a) {
16
- for (const s of a) {
17
- const u = t ? `${t}.${s.name.toString()}` : s.name.toString(), r = x(s.type), o = !r;
18
- let d = s.type;
19
- if (i.AST.isUnion(s.type) && (d = s.type.types.find(
20
- (g) => g._tag !== "UndefinedKeyword" && g !== i.Null.ast
21
- )), "propertySignatures" in d)
22
- Object.assign(
23
- l,
24
- m({
25
- parent: u,
26
- propertySignatures: d.propertySignatures,
27
- meta: { required: o, nullableOrUndefined: r }
28
- })
29
- );
30
- else {
31
- const g = m({
32
- parent: u,
33
- property: s.type,
34
- meta: { required: o, nullableOrUndefined: r }
35
- });
36
- l[u] = g;
1
+ import { useForm as I } from "@tanstack/vue-form";
2
+ import { S as N } from "effect-app";
3
+ import { generateMetaFromSchema as R } from "./vue-components.es9.js";
4
+ import { computed as b, onUnmounted as A, onMounted as D, onBeforeUnmount as J, provide as K } from "vue";
5
+ import { isObject as q } from "./vue-components.es20.js";
6
+ import M from "./vue-components.es21.js";
7
+ const x = Symbol("OmegaForm"), H = (w, s, i) => {
8
+ if (!w) throw new Error("Schema is required");
9
+ const V = N.standardSchemaV1(w), { filterItems: L, meta: t } = R(w), d = b(() => {
10
+ var l;
11
+ if ((l = i == null ? void 0 : i.persistency) != null && l.id)
12
+ return i.persistency.id;
13
+ const e = window.location.pathname, r = Object.keys(t);
14
+ return `${e}-${r.join("-")}`;
15
+ }), U = () => {
16
+ const e = new URLSearchParams(window.location.search);
17
+ e.delete(d.value);
18
+ const r = new URL(window.location.href);
19
+ r.search = e.toString(), window.history.replaceState({}, "", r.toString());
20
+ };
21
+ function v(e, r) {
22
+ for (const l in r)
23
+ r[l] && q(r[l]) ? (e[l] || (e[l] = {}), v(e[l], r[l])) : e[l] = r[l];
24
+ return e;
25
+ }
26
+ const j = b(() => {
27
+ var l;
28
+ if (s != null && s.defaultValues && !((l = i == null ? void 0 : i.persistency) != null && l.overrideDefaultValues))
29
+ return s == null ? void 0 : s.defaultValues;
30
+ let e;
31
+ const r = i == null ? void 0 : i.persistency;
32
+ if (!(r != null && r.policies) || r.policies.length === 0) return {};
33
+ if (r.policies.includes("querystring"))
34
+ try {
35
+ const c = new URLSearchParams(window.location.search).get(d.value);
36
+ U(), c && (e = JSON.parse(c));
37
+ } catch (u) {
38
+ console.error(u);
37
39
  }
40
+ if (
41
+ // query string has higher priority than local/session storage
42
+ !e && (r.policies.includes("local") || r.policies.includes("session"))
43
+ ) {
44
+ const u = r.policies.includes("local") ? localStorage : sessionStorage;
45
+ if (u)
46
+ try {
47
+ const c = JSON.parse(
48
+ u.getItem(d.value) || "{}"
49
+ );
50
+ u.removeItem(d.value), e = c;
51
+ } catch (c) {
52
+ console.error(c);
53
+ }
38
54
  }
39
- return l;
40
- }
41
- if (n) {
42
- const s = v(n);
43
- if (Object.hasOwnProperty.call(e, "required") || (e.required = !s), i.AST.isUnion(n)) {
44
- const r = n.types.find(
45
- (o) => o._tag !== "UndefinedKeyword" && o !== i.Null.ast
46
- );
47
- return "propertySignatures" in r ? m({
48
- propertySignatures: r.propertySignatures,
49
- parent: t,
50
- meta: e
51
- }) : n.types.every(i.AST.isLiteral) ? {
52
- ...e,
53
- type: "select",
54
- members: n.types.map((o) => o.literal)
55
- } : {
56
- ...e,
57
- ...m({
58
- parent: t,
59
- meta: e,
60
- property: r
61
- })
62
- };
55
+ if (e ?? (e = {}), (s == null ? void 0 : s.defaultValues) == null)
56
+ return e;
57
+ {
58
+ const u = s == null ? void 0 : s.defaultValues;
59
+ return v(u, e);
63
60
  }
64
- if (i.AST.isTupleType(n))
65
- return {
66
- ...e,
67
- type: "multiple",
68
- members: n.elements
69
- };
70
- const u = i.AST.getAnnotation(
71
- n,
72
- i.AST.JSONSchemaAnnotationId
73
- ).pipe(f.getOrElse(() => ({})));
74
- return e = { ...e, ...u }, "from" in n ? m({
75
- parent: t,
76
- meta: e,
77
- property: n.from
78
- }) : (e.type = i.AST.getAnnotation(
79
- n,
80
- i.AST.TitleAnnotationId
81
- ).pipe(
82
- f.getOrElse(() => "unknown")
83
- ), e);
84
- }
85
- return l;
86
- }, c = (e) => {
87
- const t = e.ast, n = {};
88
- if (t._tag === "Transformation" || t._tag === "Refinement")
89
- return c(i.make(t.from));
90
- if ("propertySignatures" in t) {
91
- const a = m({
92
- propertySignatures: t.propertySignatures
61
+ }), n = I({
62
+ ...s,
63
+ validators: {
64
+ onSubmit: V,
65
+ ...(s == null ? void 0 : s.validators) || {}
66
+ },
67
+ onSubmit: s != null && s.onSubmit ? ({ formApi: e, meta: r, value: l }) => {
68
+ var u;
69
+ return (u = s.onSubmit) == null ? void 0 : u.call(s, {
70
+ formApi: e,
71
+ meta: r,
72
+ value: l
73
+ });
74
+ } : void 0,
75
+ defaultValues: j.value
76
+ }), E = () => {
77
+ Object.keys(t).forEach((e) => {
78
+ n.setFieldValue(e, void 0);
93
79
  });
94
- if (Object.values(a).every((s) => s && "type" in s))
95
- return a;
96
- const l = (s, u = "") => {
97
- for (const r in s) {
98
- const o = u ? `${u}.${r}` : r;
99
- s[r] && typeof s[r] == "object" && "type" in s[r] ? n[o] = s[r] : s[r] && typeof s[r] == "object" && l(s[r], o);
80
+ }, S = (e) => e.reduce(
81
+ (r, l) => {
82
+ const u = l.split(".");
83
+ return u.reduce((c, o, P) => (P === u.length - 1 ? c[o] = n.getFieldValue(l) : c[o] = c[o] ?? {}, c[o]), r), r;
84
+ },
85
+ {}
86
+ ), f = (e) => {
87
+ if (e) {
88
+ if (Array.isArray(e.keys))
89
+ return S(e.keys);
90
+ if (Array.isArray(e.banKeys)) {
91
+ const r = Object.keys(t).filter(
92
+ (l) => {
93
+ var u;
94
+ return (u = e.banKeys) == null ? void 0 : u.includes(l);
95
+ }
96
+ );
97
+ return S(r);
100
98
  }
101
- };
102
- l(a);
103
- }
104
- return n;
105
- }, b = (e) => i.extend(e, i.Struct({})), A = (e) => {
106
- const t = c(e), n = p(
107
- e.ast,
108
- f.liftPredicate((a) => a._tag === "Refinement" && "filter" in a),
109
- f.flatMap((a) => i.AST.getJSONSchemaAnnotation(a)),
110
- f.filter((a) => "items" in a),
111
- f.filterMap(
112
- ({ items: a }) => i.decodeUnknownOption(y)(a)
113
- ),
114
- f.zipWith(
115
- i.AST.getMessageAnnotation(e.ast),
116
- (a, l) => ({
117
- items: a,
118
- message: l("")
119
- })
120
- ),
121
- f.getOrUndefined
122
- );
123
- return { schema: e, meta: t, filterItems: n };
124
- }, O = (e) => {
125
- const { trans: t } = S();
126
- let n;
127
- switch (e.type) {
128
- case "string":
129
- n = i.String.annotations({
130
- message: () => t("validation.empty")
131
- }), e.format === "email" && (n = i.compose(
132
- n,
133
- i.Email.annotations({
134
- message: () => t("validation.email.invalid")
135
- })
136
- )), e.required && n.annotations({
137
- message: () => t("validation.empty")
138
- }), e.maxLength && (n = n.pipe(i.maxLength(e.maxLength)).annotations({
139
- message: () => t("validation.string.maxLength", {
140
- maxLength: e.maxLength
141
- })
142
- })), e.minLength && (n = n.pipe(i.minLength(e.minLength)).annotations({
143
- message: () => t("validation.string.minLength", {
144
- minLength: e.minLength
145
- })
146
- }));
147
- break;
148
- case "number":
149
- n = i.Number.annotations({
150
- message: () => t("validation.empty")
151
- }), e.required && n.annotations({
152
- message: () => t("validation.empty")
153
- }), e.minimum && (n = n.pipe(i.greaterThanOrEqualTo(e.minimum)).annotations({
154
- message: () => t("validation.number.min", {
155
- minimum: e.minimum,
156
- isExclusive: !0
157
- })
158
- })), e.maximum && (n = n.pipe(i.lessThanOrEqualTo(e.maximum)).annotations({
159
- message: () => t("validation.number.max", {
160
- maximum: e.maximum,
161
- isExclusive: !0
162
- })
163
- })), e.exclusiveMinimum && (n = n.pipe(i.greaterThan(e.exclusiveMinimum)).annotations({
164
- message: () => t("validation.number.min", {
165
- minimum: e.exclusiveMinimum,
166
- isExclusive: !1
167
- })
168
- })), e.exclusiveMaximum && (n = n.pipe(i.lessThan(e.exclusiveMaximum)).annotations({
169
- message: () => t("validation.number.max", {
170
- maximum: e.exclusiveMaximum,
171
- isExclusive: !1
172
- })
173
- }));
174
- break;
175
- case "select":
176
- n = i.Literal(...e.members).annotations({
177
- message: () => ({
178
- message: t("validation.not_a_valid", {
179
- type: "select",
180
- message: e.members.join(", ")
181
- }),
182
- override: !0
183
- })
184
- });
185
- break;
186
- case "multiple":
187
- n = i.Array(i.String).annotations({
188
- message: () => t("validation.not_a_valid", {
189
- type: "multiple",
190
- message: e.members.join(", ")
191
- })
192
- });
193
- break;
194
- case "boolean":
195
- n = i.Boolean;
196
- break;
197
- // todo: switch must be exhaustive or have default case, otherwise falls through with schema undefined.
198
- case "unknown":
199
- n = i.Unknown;
200
- break;
201
- }
202
- return e.required ? n.pipe(
203
- i.annotations({
204
- message: () => t("validation.empty")
205
- })
206
- ) : n = i.NullishOr(n), i.standardSchemaV1(n);
207
- }, L = (e, t) => i.NullOr(e).pipe(
208
- i.transform(i.typeSchema(e), {
209
- decode: (n) => n ?? t(),
210
- encode: (n) => n
211
- })
212
- );
99
+ return n.store.state.values;
100
+ }
101
+ }, h = () => {
102
+ const e = i == null ? void 0 : i.persistency;
103
+ if (!(!(e != null && e.policies) || e.policies.length === 0) && (e.policies.includes("local") || e.policies.includes("session"))) {
104
+ const r = e.policies.includes("local") ? localStorage : sessionStorage;
105
+ if (!r) return;
106
+ const l = f(e);
107
+ return r.setItem(d.value, JSON.stringify(l));
108
+ }
109
+ }, a = () => {
110
+ const e = i == null ? void 0 : i.persistency;
111
+ if (!(!(e != null && e.policies) || e.policies.length === 0) && e.policies.includes("querystring")) {
112
+ const r = f(e), l = new URLSearchParams(window.location.search);
113
+ l.set(d.value, JSON.stringify(r));
114
+ const u = new URL(window.location.href);
115
+ u.search = l.toString(), window.history.replaceState({}, "", u.toString());
116
+ }
117
+ };
118
+ A(h), D(() => {
119
+ window.addEventListener("beforeunload", h), window.addEventListener("blur", a);
120
+ }), J(() => {
121
+ window.removeEventListener("beforeunload", h), window.removeEventListener("blur", a);
122
+ });
123
+ const y = Object.assign(n, {
124
+ meta: t,
125
+ filterItems: L,
126
+ clear: E
127
+ });
128
+ return K(x, y), Object.assign(y, {
129
+ Input: M
130
+ });
131
+ };
213
132
  export {
214
- b as duplicateSchema,
215
- O as generateInputStandardSchemaFromFieldMeta,
216
- A as generateMetaFromSchema,
217
- L as nullableInput
133
+ x as OmegaFormKey,
134
+ H as useOmegaForm
218
135
  };