@effect-app/vue-components 1.0.0-next.9 → 1.0.1

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 (43) hide show
  1. package/dist/types/components/OmegaForm/OmegaFormStuff.d.ts +1 -1
  2. package/dist/types/components/OmegaForm/index.d.ts +1 -0
  3. package/dist/types/components/OmegaForm/useOmegaForm.d.ts +26 -13
  4. package/dist/vue-components.es.js +21 -19
  5. package/dist/vue-components.es10.js +10 -5
  6. package/dist/vue-components.es11.js +5 -54
  7. package/dist/vue-components.es12.js +49 -66
  8. package/dist/vue-components.es13.js +71 -6
  9. package/dist/vue-components.es14.js +5 -5
  10. package/dist/vue-components.es15.js +6 -3
  11. package/dist/vue-components.es16.js +3 -3
  12. package/dist/vue-components.es17.js +3 -89
  13. package/dist/vue-components.es18.js +2 -42
  14. package/dist/vue-components.es19.js +42 -2
  15. package/dist/vue-components.es2.js +10 -8
  16. package/dist/vue-components.es21.js +2 -90
  17. package/dist/vue-components.es22.js +92 -0
  18. package/dist/vue-components.es24.js +7 -31
  19. package/dist/vue-components.es25.js +33 -0
  20. package/dist/vue-components.es30.js +1 -1
  21. package/dist/vue-components.es37.js +3 -3
  22. package/dist/vue-components.es38.js +3 -3
  23. package/dist/vue-components.es39.js +43 -23
  24. package/dist/vue-components.es4.js +80 -42
  25. package/dist/vue-components.es42.js +4 -65
  26. package/dist/vue-components.es43.js +54 -45
  27. package/dist/vue-components.es44.js +54 -15
  28. package/dist/vue-components.es45.js +15 -31
  29. package/dist/vue-components.es46.js +30 -26
  30. package/dist/vue-components.es47.js +29 -42
  31. package/dist/vue-components.es48.js +42 -4
  32. package/dist/vue-components.es5.js +51 -29
  33. package/dist/vue-components.es6.js +27 -207
  34. package/dist/vue-components.es7.js +202 -343
  35. package/dist/vue-components.es8.js +350 -2
  36. package/dist/vue-components.es9.js +2 -10
  37. package/package.json +4 -4
  38. package/src/components/OmegaForm/OmegaFormStuff.ts +1 -0
  39. package/src/components/OmegaForm/OmegaInputVuetify.vue +19 -0
  40. package/src/components/OmegaForm/index.ts +2 -0
  41. package/src/components/OmegaForm/useOmegaForm.ts +287 -29
  42. package/dist/vue-components.es23.js +0 -9
  43. package/dist/vue-components.es26.js +0 -4
@@ -1,352 +1,211 @@
1
- import { S as n, Option as c, pipe as L } from "effect-app";
2
- import { getTransformationFrom as U, useIntl as _ } from "./vue-components.es3.js";
3
- const N = n.NonEmptyArray(n.String), E = (e) => n.AST.isUnion(e) && e.types.find((i) => i._tag === "UndefinedKeyword" || i === n.Null.ast), g = (e) => !e || !n.AST.isUnion(e) ? !1 : e.types.find((i) => i._tag === "UndefinedKeyword") ? "undefined" : e.types.find((i) => i === n.Null.ast) ? "null" : !1, m = ({ meta: e = {}, parent: i = "", property: t, propertySignatures: p }, o = {}) => {
4
- if (t && t._tag === "Transformation")
5
- return m({
6
- parent: i,
7
- meta: e,
8
- property: t.from
9
- });
10
- if (t?._tag === "TypeLiteral" && "propertySignatures" in t)
11
- return m({
12
- meta: e,
13
- propertySignatures: t.propertySignatures
14
- });
15
- if (p) {
16
- for (const r of p) {
17
- const l = i ? `${i}.${r.name.toString()}` : r.name.toString(), a = g(r.type), u = !a, A = r.type;
18
- if (n.AST.isUnion(r.type)) {
19
- const T = r.type.types.filter(
20
- (s) => s._tag !== "UndefinedKeyword" && s !== n.Null.ast
21
- ).map(U);
22
- if (T.some(
23
- (s) => "propertySignatures" in s
24
- )) {
25
- if (!a) {
26
- const s = m({
27
- parent: l,
28
- property: r.type,
29
- meta: { required: u, nullableOrUndefined: a }
30
- });
31
- o[l] = s;
32
- }
33
- for (const s of T)
34
- "propertySignatures" in s && Object.assign(
35
- o,
36
- m({
37
- parent: l,
38
- propertySignatures: s.propertySignatures,
39
- meta: { required: u, nullableOrUndefined: a }
40
- })
41
- );
42
- } else {
43
- const s = T.filter(n.AST.isTupleType);
44
- if (s.length > 0) {
45
- const f = s[0];
46
- if (o[l] = {
47
- type: "multiple",
48
- members: f.elements,
49
- rest: f.rest,
50
- required: u,
51
- nullableOrUndefined: a
52
- }, f.rest && f.rest.length > 0) {
53
- const d = f.rest[0];
54
- if (d.type._tag === "TypeLiteral" && "propertySignatures" in d.type)
55
- for (const y of d.type.propertySignatures) {
56
- const b = `${l}.${y.name.toString()}`, S = m({
57
- parent: b,
58
- property: y.type,
59
- meta: {
60
- required: !g(y.type),
61
- nullableOrUndefined: g(y.type)
62
- }
63
- });
64
- if (S && typeof S == "object" && "type" in S && (o[b] = S, S.type === "multiple" && n.AST.isTupleType(y.type) && y.type.rest && y.type.rest.length > 0)) {
65
- const O = y.type.rest[0];
66
- if (O.type._tag === "TypeLiteral" && "propertySignatures" in O.type)
67
- for (const x of O.type.propertySignatures) {
68
- const M = `${b}.${x.name.toString()}`, v = m({
69
- parent: M,
70
- property: x.type,
71
- meta: {
72
- required: !g(x.type),
73
- nullableOrUndefined: g(x.type)
74
- }
75
- });
76
- v && typeof v == "object" && "type" in v && (o[M] = v);
77
- }
78
- }
79
- }
80
- }
81
- } else {
82
- const f = m({
83
- parent: l,
84
- property: r.type,
85
- meta: { required: u, nullableOrUndefined: a }
86
- });
87
- o[l] = f;
88
- }
89
- }
90
- } else if ("propertySignatures" in A)
91
- Object.assign(
92
- o,
93
- m({
94
- parent: l,
95
- propertySignatures: A.propertySignatures,
96
- meta: { required: u, nullableOrUndefined: a }
97
- })
98
- );
99
- else if (n.AST.isTupleType(r.type))
100
- if (r.type.rest.length > 0 && r.type.rest[0].type._tag === "TypeLiteral" && "propertySignatures" in r.type.rest[0].type) {
101
- const h = r.type.rest[0].type;
102
- if (h._tag === "TypeLiteral" && "propertySignatures" in h)
103
- for (const s of h.propertySignatures) {
104
- const f = `${l}.${s.name.toString()}`;
105
- if (n.AST.isTupleType(s.type) && s.type.rest.length > 0) {
106
- const d = s.type.rest[0].type;
107
- if (d._tag === "TypeLiteral" && "propertySignatures" in d)
108
- for (const y of d.propertySignatures) {
109
- const b = `${f}.${y.name.toString()}`, S = m({
110
- parent: b,
111
- property: y.type,
112
- meta: {
113
- required: !g(y.type),
114
- nullableOrUndefined: g(y.type)
115
- }
116
- });
117
- o[b] = S;
118
- }
119
- else
120
- o[f] = {
121
- type: "multiple",
122
- members: s.type.elements,
123
- rest: s.type.rest,
124
- required: !g(s.type),
125
- nullableOrUndefined: g(s.type)
126
- };
127
- } else {
128
- const d = m({
129
- parent: f,
130
- property: s.type,
131
- meta: {
132
- required: !g(s.type),
133
- nullableOrUndefined: g(s.type)
134
- }
135
- });
136
- o[f] = d;
137
- }
138
- }
139
- } else
140
- o[l] = {
141
- type: "multiple",
142
- members: r.type.elements,
143
- rest: r.type.rest,
144
- required: u,
145
- nullableOrUndefined: a
146
- };
147
- else {
148
- const T = m({
149
- parent: l,
150
- property: r.type,
151
- meta: { required: u, nullableOrUndefined: a }
152
- });
153
- o[l] = T;
154
- }
1
+ import { useForm as D, useStore as H } from "@tanstack/vue-form";
2
+ import { S as O, Effect as d, Fiber as y } from "effect-app";
3
+ import { runtimeFiberAsPromise as J } from "./vue-components.es10.js";
4
+ import { isObject as q } from "./vue-components.es11.js";
5
+ import { computed as I, onUnmounted as K, onMounted as B, onBeforeUnmount as G, watch as W, h as $ } from "vue";
6
+ import k from "./vue-components.es12.js";
7
+ import z from "./vue-components.es13.js";
8
+ import { buildOmegaErrors as Q } from "./vue-components.es6.js";
9
+ import T from "./vue-components.es14.js";
10
+ import { generateMetaFromSchema as X } from "./vue-components.es8.js";
11
+ import Y from "./vue-components.es5.js";
12
+ import Z from "./vue-components.es15.js";
13
+ import { trace as P } from "./vue-components.es16.js";
14
+ import { context as g } from "./vue-components.es17.js";
15
+ const p = (c) => function(o) {
16
+ return {
17
+ render() {
18
+ return $(o, {
19
+ form: c,
20
+ on: this.$listeners,
21
+ attrs: this.$attrs
22
+ }, this.$slots);
155
23
  }
156
- return o;
157
- }
158
- if (t) {
159
- const r = E(t);
160
- if (Object.hasOwnProperty.call(e, "required") || (e.required = !r), n.AST.isUnion(t)) {
161
- const a = t.types.find(
162
- (u) => u._tag !== "UndefinedKeyword" && u !== n.Null.ast
163
- );
164
- return "propertySignatures" in a ? m({
165
- propertySignatures: a.propertySignatures,
166
- parent: i,
167
- meta: e
168
- }) : t.types.every(n.AST.isLiteral) ? {
169
- ...e,
170
- type: "select",
171
- members: t.types.map((u) => u.literal)
172
- } : {
173
- ...e,
174
- ...m({
175
- parent: i,
176
- meta: e,
177
- property: a
178
- })
179
- };
180
- }
181
- if (n.AST.isTupleType(t))
24
+ };
25
+ }, C = (c) => function(o) {
26
+ return {
27
+ setup() {
182
28
  return {
183
- ...e,
184
- type: "multiple",
185
- members: t.elements,
186
- rest: t.rest
29
+ ...c
187
30
  };
188
- const l = n.AST.getAnnotation(
189
- t,
190
- n.AST.JSONSchemaAnnotationId
191
- ).pipe(c.getOrElse(() => ({})));
192
- return e = { ...e, ...l }, "from" in t ? m({
193
- parent: i,
194
- meta: e,
195
- property: t.from
196
- }) : (e.type = n.AST.getAnnotation(
197
- t,
198
- n.AST.TitleAnnotationId
199
- ).pipe(
200
- c.getOrElse(() => "unknown")
201
- ), e);
31
+ },
32
+ render({ errors: h, generalErrors: w, showErrors: S }) {
33
+ return $(o, {
34
+ errors: h,
35
+ generalErrors: w,
36
+ showErrors: S,
37
+ on: this.$listeners,
38
+ attrs: this.$attrs
39
+ }, this.$slots);
40
+ }
41
+ };
42
+ }, pe = (c, a, o) => {
43
+ if (!c) throw new Error("Schema is required");
44
+ const h = O.standardSchemaV1(c), w = O.decode(c), { filterItems: S, meta: f } = X(c), l = I(() => {
45
+ if (o?.persistency?.id)
46
+ return o.persistency.id;
47
+ const e = window.location.pathname, r = Object.keys(f);
48
+ return `${e}-${r.join("-")}`;
49
+ }), A = () => {
50
+ const e = new URLSearchParams(window.location.search);
51
+ e.delete(l.value);
52
+ const r = new URL(window.location.href);
53
+ r.search = e.toString(), window.history.replaceState({}, "", r.toString());
54
+ };
55
+ function E(e, r) {
56
+ for (const t in r)
57
+ r[t] && q(r[t]) ? (e[t] || (e[t] = {}), E(e[t], r[t])) : e[t] = r[t];
58
+ return e;
202
59
  }
203
- return o;
204
- }, q = (e) => {
205
- const i = e.ast, t = {};
206
- if (i._tag === "Transformation" || i._tag === "Refinement")
207
- return q(n.make(i.from));
208
- if ("propertySignatures" in i) {
209
- const p = m({
210
- propertySignatures: i.propertySignatures
60
+ const U = I(() => {
61
+ if (a?.defaultValues && !o?.persistency?.overrideDefaultValues)
62
+ return a?.defaultValues;
63
+ let e;
64
+ const r = o?.persistency;
65
+ if (!r?.policies || r.policies.length === 0) return {};
66
+ if (r.policies.includes("querystring"))
67
+ try {
68
+ const s = new URLSearchParams(window.location.search).get(l.value);
69
+ A(), s && (e = JSON.parse(s));
70
+ } catch (t) {
71
+ console.error(t);
72
+ }
73
+ if (
74
+ // query string has higher priority than local/session storage
75
+ !e && (r.policies.includes("local") || r.policies.includes("session"))
76
+ ) {
77
+ const t = r.policies.includes("local") ? localStorage : sessionStorage;
78
+ if (t)
79
+ try {
80
+ const s = JSON.parse(
81
+ t.getItem(l.value) || "{}"
82
+ );
83
+ t.removeItem(l.value), e = s;
84
+ } catch (s) {
85
+ console.error(s);
86
+ }
87
+ }
88
+ if (e ??= {}, a?.defaultValues == null)
89
+ return e;
90
+ {
91
+ const t = a?.defaultValues;
92
+ return E(t, e);
93
+ }
94
+ }), M = (e, r) => e ? g.with(P.setSpan(g.active(), e), r) : r(), u = D({
95
+ ...a,
96
+ validators: {
97
+ onSubmit: h,
98
+ ...a?.validators || {}
99
+ },
100
+ onSubmit: a?.onSubmit ? ({ formApi: e, meta: r, value: t }) => M(r?.currentSpan, async () => {
101
+ const s = await d.runPromise(w(t)), n = a.onSubmit({
102
+ formApi: e,
103
+ meta: r,
104
+ value: s
105
+ });
106
+ return y.isFiber(n) && y.isRuntimeFiber(n) ? await J(n) : d.isEffect(n) ? await d.runPromise(
107
+ n.pipe(
108
+ // meta?.currentSpan
109
+ // ? Effect.withParentSpan(meta.currentSpan)
110
+ // : (_) => _,
111
+ d.flatMap((m) => y.join(m))
112
+ )
113
+ ) : n;
114
+ }) : void 0,
115
+ defaultValues: U.value
116
+ }), N = () => {
117
+ Object.keys(f).forEach((e) => {
118
+ u.setFieldValue(e, void 0);
211
119
  });
212
- if (Object.values(p).every((r) => r && "type" in r))
213
- return p;
214
- const o = (r, l = "") => {
215
- for (const a in r) {
216
- const u = l ? `${l}.${a}` : a;
217
- r[a] && typeof r[a] == "object" && "type" in r[a] ? t[u] = r[a] : r[a] && typeof r[a] == "object" && o(r[a], u);
120
+ }, V = (e) => e.reduce((r, t) => {
121
+ const s = t.split(".");
122
+ return s.reduce((n, m, x) => (x === s.length - 1 ? n[m] = u.getFieldValue(t) : n[m] = n[m] ?? {}, n[m]), r), r;
123
+ }, {}), F = (e) => {
124
+ if (e) {
125
+ if (Array.isArray(e.keys))
126
+ return V(e.keys);
127
+ if (Array.isArray(e.banKeys)) {
128
+ const r = Object.keys(f).filter((t) => e.banKeys?.includes(t));
129
+ return V(r);
218
130
  }
219
- };
220
- o(p);
221
- }
222
- return t;
223
- }, I = (e) => n.extend(e, n.Struct({})), K = (e) => {
224
- const i = q(e), t = L(
225
- e.ast,
226
- c.liftPredicate((p) => p._tag === "Refinement" && "filter" in p),
227
- c.flatMap((p) => n.AST.getJSONSchemaAnnotation(p)),
228
- c.filter((p) => "items" in p),
229
- c.filterMap(({ items: p }) => n.decodeUnknownOption(N)(p)),
230
- c.zipWith(
231
- n.AST.getMessageAnnotation(e.ast),
232
- (p, o) => ({
233
- items: p,
234
- message: o("")
235
- })
236
- ),
237
- c.getOrUndefined
131
+ return u.store.state.values;
132
+ }
133
+ }, v = () => {
134
+ const e = o?.persistency;
135
+ if (!(!e?.policies || e.policies.length === 0) && (e.policies.includes("local") || e.policies.includes("session"))) {
136
+ const r = e.policies.includes("local") ? localStorage : sessionStorage;
137
+ if (!r) return;
138
+ const t = F(e);
139
+ return r.setItem(l.value, JSON.stringify(t));
140
+ }
141
+ }, j = () => {
142
+ const e = o?.persistency;
143
+ if (!(!e?.policies || e.policies.length === 0) && e.policies.includes("querystring")) {
144
+ const r = F(e), t = new URLSearchParams(window.location.search);
145
+ t.set(l.value, JSON.stringify(r));
146
+ const s = new URL(window.location.href);
147
+ s.search = t.toString(), window.history.replaceState({}, "", s.toString());
148
+ }
149
+ };
150
+ K(v), B(() => {
151
+ window.addEventListener("beforeunload", v), window.addEventListener("blur", j);
152
+ }), G(() => {
153
+ window.removeEventListener("beforeunload", v), window.removeEventListener("blur", j);
154
+ });
155
+ const R = u.handleSubmit, i = Object.assign(u, {
156
+ i18nNamespace: o?.i18nNamespace,
157
+ meta: f,
158
+ filterItems: S,
159
+ clear: N,
160
+ handleSubmit: (e) => {
161
+ const r = P.getSpan(g.active());
162
+ return R({ currentSpan: r, ...e });
163
+ }
164
+ // /** @experimental */
165
+ // handleSubmitEffect: (meta?: Record<string, any>) =>
166
+ // Effect.currentSpan.pipe(
167
+ // Effect.option,
168
+ // Effect
169
+ // .flatMap((span) =>
170
+ // Effect.promise(() => form.handleSubmit(Option.isSome(span) ? { currentSpan: span.value, ...meta } : meta))
171
+ // )
172
+ // )
173
+ }), _ = H(
174
+ i.store,
175
+ (e) => e.submissionAttempts
176
+ ), b = i.useStore((e) => e.errors);
177
+ W(
178
+ () => [i.filterItems, b.value],
179
+ () => {
180
+ const e = i.filterItems, r = b.value;
181
+ return e ? r ? (Object.values(r).filter(
182
+ (s) => !!s
183
+ ).flatMap(
184
+ (s) => Object.values(s).flat().map((n) => n.message)
185
+ ).some((s) => s === e.message) && e.items.forEach((s) => {
186
+ const n = i.getFieldMeta(s);
187
+ n && i.setFieldMeta(s, {
188
+ ...n,
189
+ errorMap: {
190
+ onSubmit: [
191
+ { path: [s], message: e.message }
192
+ ]
193
+ }
194
+ });
195
+ }), {}) : {} : {};
196
+ }
238
197
  );
239
- return { schema: e, meta: i, filterItems: t };
240
- }, P = (e) => {
241
- const { trans: i } = _();
242
- let t;
243
- switch (e.type) {
244
- case "string":
245
- t = n.String.annotations({
246
- message: () => i("validation.empty")
247
- }), e.format === "email" && (t = n.compose(
248
- t,
249
- n.Email.annotations({
250
- message: () => i("validation.email.invalid")
251
- })
252
- )), e.required && t.annotations({
253
- message: () => i("validation.empty")
254
- }), e.maxLength && (t = t.pipe(n.maxLength(e.maxLength)).annotations({
255
- message: () => i("validation.string.maxLength", {
256
- maxLength: e.maxLength
257
- })
258
- })), e.minLength && (t = t.pipe(n.minLength(e.minLength)).annotations({
259
- message: () => i("validation.string.minLength", {
260
- minLength: e.minLength
261
- })
262
- }));
263
- break;
264
- case "number":
265
- t = n.Number.annotations({
266
- message: () => i("validation.empty")
267
- }), e.required && t.annotations({
268
- message: () => i("validation.empty")
269
- }), e.minimum && (t = t.pipe(n.greaterThanOrEqualTo(e.minimum)).annotations({
270
- message: () => i("validation.number.min", {
271
- minimum: e.minimum,
272
- isExclusive: !0
273
- })
274
- })), e.maximum && (t = t.pipe(n.lessThanOrEqualTo(e.maximum)).annotations({
275
- message: () => i("validation.number.max", {
276
- maximum: e.maximum,
277
- isExclusive: !0
278
- })
279
- })), e.exclusiveMinimum && (t = t.pipe(n.greaterThan(e.exclusiveMinimum)).annotations({
280
- message: () => i("validation.number.min", {
281
- minimum: e.exclusiveMinimum,
282
- isExclusive: !1
283
- })
284
- })), e.exclusiveMaximum && (t = t.pipe(n.lessThan(e.exclusiveMaximum)).annotations({
285
- message: () => i("validation.number.max", {
286
- maximum: e.exclusiveMaximum,
287
- isExclusive: !1
288
- })
289
- }));
290
- break;
291
- case "select":
292
- t = n.Literal(...e.members).annotations({
293
- message: () => ({
294
- message: i("validation.not_a_valid", {
295
- type: "select",
296
- message: e.members.join(", ")
297
- }),
298
- override: !0
299
- })
300
- });
301
- break;
302
- case "multiple":
303
- t = n.Array(n.String).annotations({
304
- message: () => i("validation.not_a_valid", {
305
- type: "multiple",
306
- message: e.members.join(", ")
307
- })
308
- });
309
- break;
310
- case "boolean":
311
- t = n.Boolean;
312
- break;
313
- // todo: switch must be exhaustive or have default case, otherwise falls through with schema undefined.
314
- case "unknown":
315
- t = n.Unknown;
316
- break;
317
- }
318
- return e.required ? t.pipe(
319
- n.annotations({
320
- message: () => i("validation.empty")
321
- })
322
- ) : t = n.NullishOr(t), n.standardSchemaV1(t);
323
- }, j = (e, i) => n.NullOr(e).pipe(
324
- n.transform(n.typeSchema(e), {
325
- decode: (t) => t ?? i(),
326
- encode: (t) => t
327
- })
328
- ), k = [
329
- "button",
330
- "checkbox",
331
- "color",
332
- "date",
333
- "email",
334
- "number",
335
- "password",
336
- "radio",
337
- "range",
338
- "search",
339
- "submit",
340
- "tel",
341
- "text",
342
- "time",
343
- "url"
344
- ], F = (e) => k.includes(e) ? e : "text";
198
+ const L = Q(_, b, o?.showErrorsOn);
199
+ return Object.assign(i, {
200
+ errorContext: L,
201
+ Form: p(i)(Z),
202
+ Input: p(i)(o?.input ?? Y),
203
+ Field: u.Field,
204
+ Errors: C(L)(T),
205
+ Array: p(i)(k),
206
+ AutoGen: p(i)(z)
207
+ });
208
+ };
345
209
  export {
346
- m as createMeta,
347
- I as duplicateSchema,
348
- P as generateInputStandardSchemaFromFieldMeta,
349
- K as generateMetaFromSchema,
350
- F as getInputType,
351
- j as nullableInput
210
+ pe as useOmegaForm
352
211
  };