@effect-app/vue-components 0.26.0 → 0.27.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.
@@ -1,40 +1,40 @@
1
- import { useForm as I } from "@tanstack/vue-form";
2
- import { S as R, Fiber as m, Effect as p } from "effect-app";
3
- import { runtimeFiberAsPromise as A } from "./vue-components.es22.js";
4
- import { isObject as D } from "./vue-components.es23.js";
5
- import { computed as g, onUnmounted as J, onMounted as K, onBeforeUnmount as M, provide as q } from "vue";
6
- import x from "./vue-components.es6.js";
7
- import { generateMetaFromSchema as _ } from "./vue-components.es10.js";
8
- import { trace as V } from "./vue-components.es24.js";
1
+ import { useForm as A } from "@tanstack/vue-form";
2
+ import { S as g, Effect as f, Fiber as p } from "effect-app";
3
+ import { runtimeFiberAsPromise as D } from "./vue-components.es22.js";
4
+ import { isObject as J } from "./vue-components.es23.js";
5
+ import { computed as V, onUnmounted as K, onMounted as M, onBeforeUnmount as q, provide as x } from "vue";
6
+ import _ from "./vue-components.es6.js";
7
+ import { generateMetaFromSchema as $ } from "./vue-components.es10.js";
8
+ import { trace as P } from "./vue-components.es24.js";
9
9
  import { context as w } from "./vue-components.es25.js";
10
- const $ = Symbol("OmegaForm"), Y = (d, i, n) => {
11
- if (!d) throw new Error("Schema is required");
12
- const j = R.standardSchemaV1(d), { filterItems: E, meta: l } = _(d), o = g(() => {
13
- if (n?.persistency?.id)
14
- return n.persistency.id;
15
- const e = window.location.pathname, r = Object.keys(l);
10
+ const B = Symbol("OmegaForm"), Z = (u, n, o) => {
11
+ if (!u) throw new Error("Schema is required");
12
+ const j = g.standardSchemaV1(u), E = g.decode(u), { filterItems: L, meta: d } = $(u), a = V(() => {
13
+ if (o?.persistency?.id)
14
+ return o.persistency.id;
15
+ const e = window.location.pathname, r = Object.keys(d);
16
16
  return `${e}-${r.join("-")}`;
17
- }), L = () => {
17
+ }), U = () => {
18
18
  const e = new URLSearchParams(window.location.search);
19
- e.delete(o.value);
19
+ e.delete(a.value);
20
20
  const r = new URL(window.location.href);
21
21
  r.search = e.toString(), window.history.replaceState({}, "", r.toString());
22
22
  };
23
23
  function S(e, r) {
24
24
  for (const t in r)
25
- r[t] && D(r[t]) ? (e[t] || (e[t] = {}), S(e[t], r[t])) : e[t] = r[t];
25
+ r[t] && J(r[t]) ? (e[t] || (e[t] = {}), S(e[t], r[t])) : e[t] = r[t];
26
26
  return e;
27
27
  }
28
- const P = g(() => {
29
- if (i?.defaultValues && !n?.persistency?.overrideDefaultValues)
30
- return i?.defaultValues;
28
+ const F = V(() => {
29
+ if (n?.defaultValues && !o?.persistency?.overrideDefaultValues)
30
+ return n?.defaultValues;
31
31
  let e;
32
- const r = n?.persistency;
32
+ const r = o?.persistency;
33
33
  if (!r?.policies || r.policies.length === 0) return {};
34
34
  if (r.policies.includes("querystring"))
35
35
  try {
36
- const s = new URLSearchParams(window.location.search).get(o.value);
37
- L(), s && (e = JSON.parse(s));
36
+ const s = new URLSearchParams(window.location.search).get(a.value);
37
+ U(), s && (e = JSON.parse(s));
38
38
  } catch (t) {
39
39
  console.error(t);
40
40
  }
@@ -46,88 +46,88 @@ const $ = Symbol("OmegaForm"), Y = (d, i, n) => {
46
46
  if (t)
47
47
  try {
48
48
  const s = JSON.parse(
49
- t.getItem(o.value) || "{}"
49
+ t.getItem(a.value) || "{}"
50
50
  );
51
- t.removeItem(o.value), e = s;
51
+ t.removeItem(a.value), e = s;
52
52
  } catch (s) {
53
53
  console.error(s);
54
54
  }
55
55
  }
56
- if (e ??= {}, i?.defaultValues == null)
56
+ if (e ??= {}, n?.defaultValues == null)
57
57
  return e;
58
58
  {
59
- const t = i?.defaultValues;
59
+ const t = n?.defaultValues;
60
60
  return S(t, e);
61
61
  }
62
- }), U = (e, r) => e ? w.with(V.setSpan(w.active(), e), r) : r(), a = I({
63
- ...i,
62
+ }), N = (e, r) => e ? w.with(P.setSpan(w.active(), e), r) : r(), c = A({
63
+ ...n,
64
64
  validators: {
65
65
  onSubmit: j,
66
- ...i?.validators || {}
66
+ ...n?.validators || {}
67
67
  },
68
- onSubmit: i?.onSubmit ? ({ formApi: e, meta: r, value: t }) => U(r?.currentSpan, async () => {
69
- const s = i.onSubmit({
68
+ onSubmit: n?.onSubmit ? ({ formApi: e, meta: r, value: t }) => N(r?.currentSpan, async () => {
69
+ const s = await f.runPromise(E(t)), i = n.onSubmit({
70
70
  formApi: e,
71
71
  meta: r,
72
- value: t
72
+ value: s
73
73
  });
74
- return m.isFiber(s) && m.isRuntimeFiber(s) ? await A(s) : p.isEffect(s) ? await p.runPromise(
75
- s.pipe(
74
+ return p.isFiber(i) && p.isRuntimeFiber(i) ? await D(i) : f.isEffect(i) ? await f.runPromise(
75
+ i.pipe(
76
76
  // meta?.currentSpan
77
77
  // ? Effect.withParentSpan(meta.currentSpan)
78
78
  // : (_) => _,
79
- p.flatMap((c) => m.join(c))
79
+ f.flatMap((l) => p.join(l))
80
80
  )
81
- ) : s;
81
+ ) : i;
82
82
  }) : void 0,
83
- defaultValues: P.value
84
- }), F = () => {
85
- Object.keys(l).forEach((e) => {
86
- a.setFieldValue(e, void 0);
83
+ defaultValues: F.value
84
+ }), O = () => {
85
+ Object.keys(d).forEach((e) => {
86
+ c.setFieldValue(e, void 0);
87
87
  });
88
88
  }, h = (e) => e.reduce((r, t) => {
89
89
  const s = t.split(".");
90
- return s.reduce((c, u, O) => (O === s.length - 1 ? c[u] = a.getFieldValue(t) : c[u] = c[u] ?? {}, c[u]), r), r;
90
+ return s.reduce((i, l, R) => (R === s.length - 1 ? i[l] = c.getFieldValue(t) : i[l] = i[l] ?? {}, i[l]), r), r;
91
91
  }, {}), y = (e) => {
92
92
  if (e) {
93
93
  if (Array.isArray(e.keys))
94
94
  return h(e.keys);
95
95
  if (Array.isArray(e.banKeys)) {
96
- const r = Object.keys(l).filter((t) => e.banKeys?.includes(t));
96
+ const r = Object.keys(d).filter((t) => e.banKeys?.includes(t));
97
97
  return h(r);
98
98
  }
99
- return a.store.state.values;
99
+ return c.store.state.values;
100
100
  }
101
- }, f = () => {
102
- const e = n?.persistency;
101
+ }, m = () => {
102
+ const e = o?.persistency;
103
103
  if (!(!e?.policies || e.policies.length === 0) && (e.policies.includes("local") || e.policies.includes("session"))) {
104
104
  const r = e.policies.includes("local") ? localStorage : sessionStorage;
105
105
  if (!r) return;
106
106
  const t = y(e);
107
- return r.setItem(o.value, JSON.stringify(t));
107
+ return r.setItem(a.value, JSON.stringify(t));
108
108
  }
109
109
  }, v = () => {
110
- const e = n?.persistency;
110
+ const e = o?.persistency;
111
111
  if (!(!e?.policies || e.policies.length === 0) && e.policies.includes("querystring")) {
112
112
  const r = y(e), t = new URLSearchParams(window.location.search);
113
- t.set(o.value, JSON.stringify(r));
113
+ t.set(a.value, JSON.stringify(r));
114
114
  const s = new URL(window.location.href);
115
115
  s.search = t.toString(), window.history.replaceState({}, "", s.toString());
116
116
  }
117
117
  };
118
- J(f), K(() => {
119
- window.addEventListener("beforeunload", f), window.addEventListener("blur", v);
120
- }), M(() => {
121
- window.removeEventListener("beforeunload", f), window.removeEventListener("blur", v);
118
+ K(m), M(() => {
119
+ window.addEventListener("beforeunload", m), window.addEventListener("blur", v);
120
+ }), q(() => {
121
+ window.removeEventListener("beforeunload", m), window.removeEventListener("blur", v);
122
122
  });
123
- const N = a.handleSubmit, b = Object.assign(a, {
124
- i18nNamespace: n?.i18nNamespace,
125
- meta: l,
126
- filterItems: E,
127
- clear: F,
123
+ const I = c.handleSubmit, b = Object.assign(c, {
124
+ i18nNamespace: o?.i18nNamespace,
125
+ meta: d,
126
+ filterItems: L,
127
+ clear: O,
128
128
  handleSubmit: (e) => {
129
- const r = V.getSpan(w.active());
130
- return N({ currentSpan: r, ...e });
129
+ const r = P.getSpan(w.active());
130
+ return I({ currentSpan: r, ...e });
131
131
  }
132
132
  // /** @experimental */
133
133
  // handleSubmitEffect: (meta?: Record<string, any>) =>
@@ -139,12 +139,12 @@ const $ = Symbol("OmegaForm"), Y = (d, i, n) => {
139
139
  // )
140
140
  // )
141
141
  });
142
- return q($, b), Object.assign(b, {
143
- Input: x,
144
- Field: a.Field
142
+ return x(B, b), Object.assign(b, {
143
+ Input: _,
144
+ Field: c.Field
145
145
  });
146
146
  };
147
147
  export {
148
- $ as OmegaFormKey,
149
- Y as useOmegaForm
148
+ B as OmegaFormKey,
149
+ Z as useOmegaForm
150
150
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "0.26.0",
3
+ "version": "0.27.0",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "effect": "^3.17.13",
@@ -29,7 +29,7 @@
29
29
  "vitepress": "^1.6.4",
30
30
  "vitest": "^3.2.4",
31
31
  "vue-tsc": "^3.0.7",
32
- "@effect-app/eslint-shared-config": "0.2.0"
32
+ "@effect-app/eslint-shared-config": "0.2.1"
33
33
  },
34
34
  "files": [
35
35
  "src",
@@ -106,6 +106,7 @@ export const useOmegaForm = <
106
106
  ): OmegaFormReturn<From, To> => {
107
107
  if (!schema) throw new Error("Schema is required")
108
108
  const standardSchema = S.standardSchemaV1(schema)
109
+ const decode = S.decode(schema)
109
110
 
110
111
  const { filterItems, meta } = generateMetaFromSchema(schema)
111
112
 
@@ -231,10 +232,12 @@ export const useOmegaForm = <
231
232
  onSubmit: tanstackFormOptions?.onSubmit
232
233
  ? ({ formApi, meta, value }) =>
233
234
  wrapWithSpan(meta?.currentSpan, async () => {
235
+ // validators only validate, they don't actually transform, so we have to do that manually here.
236
+ const parsedValue = await Effect.runPromise(decode(value))
234
237
  const r = tanstackFormOptions.onSubmit!({
235
238
  formApi: formApi as OmegaFormApi<From, To>,
236
239
  meta,
237
- value: value as unknown as To
240
+ value: parsedValue
238
241
  })
239
242
  if (Fiber.isFiber(r) && Fiber.isRuntimeFiber(r)) {
240
243
  return await runtimeFiberAsPromise(r)