@effect-app/vue-components 0.18.14 → 0.18.16

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.
@@ -28,7 +28,7 @@ export type FormProps<From, To> = Omit<FormOptions<From, FormValidateOrFn<From>
28
28
  formApi: OmegaFormParams<From, To>;
29
29
  meta: any;
30
30
  value: To;
31
- }) => Promise<any> | RuntimeFiber<any, any>;
31
+ }) => Promise<any> | RuntimeFiber<any, any> | Effect.Effect<RuntimeFiber<any, any>, any, never>;
32
32
  };
33
33
  export type OmegaFormParams<From, To> = FormApi<From, FormValidateOrFn<From> | undefined, FormValidateOrFn<From> | undefined, StandardSchemaV1<From, To>, FormValidateOrFn<From> | undefined, FormAsyncValidateOrFn<From> | undefined, FormValidateOrFn<From> | undefined, FormAsyncValidateOrFn<From> | undefined, FormAsyncValidateOrFn<From> | undefined, Record<string, any> | undefined>;
34
34
  export type OmegaFormState<From, To> = FormState<From, FormValidateOrFn<From> | undefined, FormValidateOrFn<From> | undefined, StandardSchemaV1<From, To>, FormValidateOrFn<From> | undefined, FormAsyncValidateOrFn<From> | undefined, FormValidateOrFn<From> | undefined, FormAsyncValidateOrFn<From> | undefined, FormAsyncValidateOrFn<From> | undefined>;
@@ -1,5 +1,5 @@
1
1
  import { type DeepKeys } from "@tanstack/vue-form";
2
- import { S } from "effect-app";
2
+ import { Effect, S } from "effect-app";
3
3
  import { type InjectionKey } from "vue";
4
4
  import { type InputProps } from "./InputProps";
5
5
  import { type FieldValidators, type FilterItems, type FormProps, type MetaRecord, type NestedKeyOf, type OmegaFormApi, type TypeOverride } from "./OmegaFormStuff";
@@ -24,7 +24,8 @@ export type OmegaConfig<T> = {
24
24
  interface OF<From, To> extends OmegaFormApi<From, To> {
25
25
  meta: MetaRecord<From>;
26
26
  filterItems?: FilterItems;
27
- clear: () => void;
27
+ /** @experimental */
28
+ handleSubmitEffect: (meta?: Record<string, any>) => Effect.Effect<void, never, never>;
28
29
  }
29
30
  export declare const OmegaFormKey: InjectionKey<OF<any, any>>;
30
31
  type __VLS_PrettifyLocal<T> = {
@@ -1,127 +1,139 @@
1
- import { useForm as F } from "@tanstack/vue-form";
2
- import { S as P, Fiber as v } from "effect-app";
3
- import { runtimeFiberAsPromise as E } from "./vue-components.es22.js";
4
- import { isObject as O } from "./vue-components.es23.js";
5
- import { computed as S, onUnmounted as I, onMounted as R, onBeforeUnmount as A, provide as N } from "vue";
6
- import D from "./vue-components.es6.js";
7
- import { generateMetaFromSchema as J } from "./vue-components.es10.js";
8
- const K = Symbol("OmegaForm"), k = (d, i, n) => {
9
- if (!d) throw new Error("Schema is required");
10
- const b = P.standardSchemaV1(d), { filterItems: g, meta: a } = J(d), o = S(() => {
11
- if (n?.persistency?.id)
12
- return n.persistency.id;
13
- const e = window.location.pathname, r = Object.keys(a);
1
+ import { useForm as U } from "@tanstack/vue-form";
2
+ import { S as F, Fiber as p, Effect as o, Option as O } from "effect-app";
3
+ import { runtimeFiberAsPromise as I } from "./vue-components.es22.js";
4
+ import { isObject as R } from "./vue-components.es23.js";
5
+ import { computed as b, onUnmounted as A, onMounted as M, onBeforeUnmount as N, provide as D } from "vue";
6
+ import J from "./vue-components.es6.js";
7
+ import { generateMetaFromSchema as K } from "./vue-components.es10.js";
8
+ const q = Symbol("OmegaForm"), G = (f, s, a) => {
9
+ if (!f) throw new Error("Schema is required");
10
+ const g = F.standardSchemaV1(f), { filterItems: V, meta: u } = K(f), l = b(() => {
11
+ if (a?.persistency?.id)
12
+ return a.persistency.id;
13
+ const e = window.location.pathname, r = Object.keys(u);
14
14
  return `${e}-${r.join("-")}`;
15
- }), V = () => {
15
+ }), E = () => {
16
16
  const e = new URLSearchParams(window.location.search);
17
- e.delete(o.value);
17
+ e.delete(l.value);
18
18
  const r = new URL(window.location.href);
19
19
  r.search = e.toString(), window.history.replaceState({}, "", r.toString());
20
20
  };
21
- function m(e, r) {
22
- for (const s in r)
23
- r[s] && O(r[s]) ? (e[s] || (e[s] = {}), m(e[s], r[s])) : e[s] = r[s];
21
+ function S(e, r) {
22
+ for (const t in r)
23
+ r[t] && R(r[t]) ? (e[t] || (e[t] = {}), S(e[t], r[t])) : e[t] = r[t];
24
24
  return e;
25
25
  }
26
- const L = S(() => {
27
- if (i?.defaultValues && !n?.persistency?.overrideDefaultValues)
28
- return i?.defaultValues;
26
+ const P = b(() => {
27
+ if (s?.defaultValues && !a?.persistency?.overrideDefaultValues)
28
+ return s?.defaultValues;
29
29
  let e;
30
- const r = n?.persistency;
30
+ const r = a?.persistency;
31
31
  if (!r?.policies || r.policies.length === 0) return {};
32
32
  if (r.policies.includes("querystring"))
33
33
  try {
34
- const t = new URLSearchParams(window.location.search).get(o.value);
35
- V(), t && (e = JSON.parse(t));
36
- } catch (s) {
37
- console.error(s);
34
+ const i = new URLSearchParams(window.location.search).get(l.value);
35
+ E(), i && (e = JSON.parse(i));
36
+ } catch (t) {
37
+ console.error(t);
38
38
  }
39
39
  if (
40
40
  // query string has higher priority than local/session storage
41
41
  !e && (r.policies.includes("local") || r.policies.includes("session"))
42
42
  ) {
43
- const s = r.policies.includes("local") ? localStorage : sessionStorage;
44
- if (s)
43
+ const t = r.policies.includes("local") ? localStorage : sessionStorage;
44
+ if (t)
45
45
  try {
46
- const t = JSON.parse(
47
- s.getItem(o.value) || "{}"
46
+ const i = JSON.parse(
47
+ t.getItem(l.value) || "{}"
48
48
  );
49
- s.removeItem(o.value), e = t;
50
- } catch (t) {
51
- console.error(t);
49
+ t.removeItem(l.value), e = i;
50
+ } catch (i) {
51
+ console.error(i);
52
52
  }
53
53
  }
54
- if (e ??= {}, i?.defaultValues == null)
54
+ if (e ??= {}, s?.defaultValues == null)
55
55
  return e;
56
56
  {
57
- const s = i?.defaultValues;
58
- return m(s, e);
57
+ const t = s?.defaultValues;
58
+ return S(t, e);
59
59
  }
60
- }), l = F({
61
- ...i,
60
+ }), c = U({
61
+ ...s,
62
62
  validators: {
63
- onSubmit: b,
64
- ...i?.validators || {}
63
+ onSubmit: g,
64
+ ...s?.validators || {}
65
65
  },
66
- onSubmit: i?.onSubmit ? ({ formApi: e, meta: r, value: s }) => {
67
- const t = i.onSubmit({
66
+ onSubmit: s?.onSubmit ? ({ formApi: e, meta: r, value: t }) => {
67
+ const i = s.onSubmit({
68
68
  formApi: e,
69
69
  meta: r,
70
- value: s
70
+ value: t
71
71
  });
72
- return v.isFiber(t) && v.isRuntimeFiber(t) ? E(t) : t;
72
+ return p.isFiber(i) && p.isRuntimeFiber(i) ? I(i) : o.isEffect(i) ? o.runPromise(
73
+ i.pipe(
74
+ r?.currentSpan ? o.withParentSpan(r.currentSpan) : (n) => n,
75
+ o.flatMap((n) => p.join(n))
76
+ )
77
+ ) : i;
73
78
  } : void 0,
74
- defaultValues: L.value
75
- }), U = () => {
76
- Object.keys(a).forEach((e) => {
77
- l.setFieldValue(e, void 0);
79
+ defaultValues: P.value
80
+ }), j = () => {
81
+ Object.keys(u).forEach((e) => {
82
+ c.setFieldValue(e, void 0);
78
83
  });
79
- }, p = (e) => e.reduce((r, s) => {
80
- const t = s.split(".");
81
- return t.reduce((c, u, j) => (j === t.length - 1 ? c[u] = l.getFieldValue(s) : c[u] = c[u] ?? {}, c[u]), r), r;
82
- }, {}), w = (e) => {
84
+ }, w = (e) => e.reduce((r, t) => {
85
+ const i = t.split(".");
86
+ return i.reduce((n, d, L) => (L === i.length - 1 ? n[d] = c.getFieldValue(t) : n[d] = n[d] ?? {}, n[d]), r), r;
87
+ }, {}), h = (e) => {
83
88
  if (e) {
84
89
  if (Array.isArray(e.keys))
85
- return p(e.keys);
90
+ return w(e.keys);
86
91
  if (Array.isArray(e.banKeys)) {
87
- const r = Object.keys(a).filter((s) => e.banKeys?.includes(s));
88
- return p(r);
92
+ const r = Object.keys(u).filter((t) => e.banKeys?.includes(t));
93
+ return w(r);
89
94
  }
90
- return l.store.state.values;
95
+ return c.store.state.values;
91
96
  }
92
- }, f = () => {
93
- const e = n?.persistency;
97
+ }, m = () => {
98
+ const e = a?.persistency;
94
99
  if (!(!e?.policies || e.policies.length === 0) && (e.policies.includes("local") || e.policies.includes("session"))) {
95
100
  const r = e.policies.includes("local") ? localStorage : sessionStorage;
96
101
  if (!r) return;
97
- const s = w(e);
98
- return r.setItem(o.value, JSON.stringify(s));
102
+ const t = h(e);
103
+ return r.setItem(l.value, JSON.stringify(t));
99
104
  }
100
105
  }, y = () => {
101
- const e = n?.persistency;
106
+ const e = a?.persistency;
102
107
  if (!(!e?.policies || e.policies.length === 0) && e.policies.includes("querystring")) {
103
- const r = w(e), s = new URLSearchParams(window.location.search);
104
- s.set(o.value, JSON.stringify(r));
105
- const t = new URL(window.location.href);
106
- t.search = s.toString(), window.history.replaceState({}, "", t.toString());
108
+ const r = h(e), t = new URLSearchParams(window.location.search);
109
+ t.set(l.value, JSON.stringify(r));
110
+ const i = new URL(window.location.href);
111
+ i.search = t.toString(), window.history.replaceState({}, "", i.toString());
107
112
  }
108
113
  };
109
- I(f), R(() => {
110
- window.addEventListener("beforeunload", f), window.addEventListener("blur", y);
111
- }), A(() => {
112
- window.removeEventListener("beforeunload", f), window.removeEventListener("blur", y);
114
+ A(m), M(() => {
115
+ window.addEventListener("beforeunload", m), window.addEventListener("blur", y);
116
+ }), N(() => {
117
+ window.removeEventListener("beforeunload", m), window.removeEventListener("blur", y);
113
118
  });
114
- const h = Object.assign(l, {
115
- meta: a,
116
- filterItems: g,
117
- clear: U
119
+ const v = Object.assign(c, {
120
+ meta: u,
121
+ filterItems: V,
122
+ clear: j,
123
+ /** @experimental */
124
+ handleSubmitEffect: (e) => o.currentSpan.pipe(
125
+ o.option,
126
+ o.flatMap(
127
+ (r) => o.promise(() => c.handleSubmit(O.isSome(r) ? { currentSpan: r.value, ...e } : e))
128
+ )
129
+ )
118
130
  });
119
- return N(K, h), Object.assign(h, {
120
- Input: D,
121
- Field: l.Field
131
+ return D(q, v), Object.assign(v, {
132
+ Input: J,
133
+ Field: c.Field
122
134
  });
123
135
  };
124
136
  export {
125
- K as OmegaFormKey,
126
- k as useOmegaForm
137
+ q as OmegaFormKey,
138
+ G as useOmegaForm
127
139
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "0.18.14",
3
+ "version": "0.18.16",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "@tanstack/vue-form": "1.2.4",
@@ -53,7 +53,7 @@
53
53
  "dependencies": {
54
54
  "highlight.js": "^11.11.1",
55
55
  "vue3-highlightjs": "^1.0.5",
56
- "@effect-app/vue": "2.55.7",
56
+ "@effect-app/vue": "2.55.8",
57
57
  "effect-app": "3.3.4"
58
58
  },
59
59
  "scripts": {
@@ -60,7 +60,7 @@ export type FormProps<From, To> =
60
60
  formApi: OmegaFormParams<From, To>
61
61
  meta: any
62
62
  value: To
63
- }) => Promise<any> | RuntimeFiber<any, any>
63
+ }) => Promise<any> | RuntimeFiber<any, any> | Effect.Effect<RuntimeFiber<any, any>, any, never>
64
64
  }
65
65
 
66
66
  export type OmegaFormParams<From, To> = FormApi<
@@ -2,7 +2,7 @@
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
 
4
4
  import { type DeepKeys, type FormAsyncValidateOrFn, type FormValidateOrFn, type StandardSchemaV1, useForm } from "@tanstack/vue-form"
5
- import { Fiber, S } from "effect-app"
5
+ import { Effect, Fiber, Option, S } from "effect-app"
6
6
  import { runtimeFiberAsPromise } from "effect-app/utils"
7
7
  import { isObject } from "effect/Predicate"
8
8
  import { computed, type InjectionKey, onBeforeUnmount, onMounted, onUnmounted, provide } from "vue"
@@ -35,7 +35,8 @@ export type OmegaConfig<T> = {
35
35
  interface OF<From, To> extends OmegaFormApi<From, To> {
36
36
  meta: MetaRecord<From>
37
37
  filterItems?: FilterItems
38
- clear: () => void
38
+ /** @experimental */
39
+ handleSubmitEffect: (meta?: Record<string, any>) => Effect.Effect<void, never, never>
39
40
  }
40
41
 
41
42
  export const OmegaFormKey = Symbol("OmegaForm") as InjectionKey<OF<any, any>>
@@ -226,6 +227,16 @@ export const useOmegaForm = <
226
227
  if (Fiber.isFiber(r) && Fiber.isRuntimeFiber(r)) {
227
228
  return runtimeFiberAsPromise(r)
228
229
  }
230
+ if (Effect.isEffect(r)) {
231
+ return Effect.runPromise(
232
+ r.pipe(
233
+ meta?.currentSpan
234
+ ? Effect.withParentSpan(meta.currentSpan)
235
+ : (_) => _,
236
+ Effect.flatMap((_) => Fiber.join(_))
237
+ )
238
+ )
239
+ }
229
240
  return r
230
241
  }
231
242
  : undefined,
@@ -311,7 +322,16 @@ export const useOmegaForm = <
311
322
  const formWithExtras: OF<From, To> = Object.assign(form, {
312
323
  meta,
313
324
  filterItems,
314
- clear
325
+ clear,
326
+ /** @experimental */
327
+ handleSubmitEffect: (meta?: Record<string, any>) =>
328
+ Effect.currentSpan.pipe(
329
+ Effect.option,
330
+ Effect
331
+ .flatMap((span) =>
332
+ Effect.promise(() => form.handleSubmit(Option.isSome(span) ? { currentSpan: span.value, ...meta } : meta))
333
+ )
334
+ )
315
335
  })
316
336
 
317
337
  provide(OmegaFormKey, formWithExtras)