@effect-app/vue-components 4.0.0-beta.53 → 4.0.0-beta.54

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.
@@ -9,19 +9,19 @@ import u from "./vue-components45.es.js";
9
9
  import d from "./vue-components52.es.js";
10
10
  import f from "./vue-components56.es.js";
11
11
  import p from "./vue-components60.es.js";
12
- import { computed as m, h, onBeforeUnmount as g, onMounted as _, onUnmounted as v, ref as y, watch as b } from "vue";
13
- import { Array as x, Data as S, Effect as C, Fiber as w, Option as T, S as E, ServiceMap as D } from "effect-app";
14
- import { useForm as O } from "@tanstack/vue-form";
15
- import { makeRunPromise as k } from "@effect-app/vue/runtime";
12
+ import { computed as m, h, onBeforeUnmount as g, onMounted as ee, onUnmounted as _, ref as v, watch as y } from "vue";
13
+ import { Array as b, Context as x, Data as S, Effect as C, Fiber as w, Option as T, S as E } from "effect-app";
14
+ import { useForm as D } from "@tanstack/vue-form";
15
+ import { makeRunPromise as O } from "@effect-app/vue/runtime";
16
16
  //#region src/components/OmegaForm/useOmegaForm.ts
17
- var ee = class extends S.TaggedError("FormErrors") {}, A = (e) => function(t) {
17
+ var te = class extends S.TaggedError("FormErrors") {}, k = (e) => function(t) {
18
18
  return { render() {
19
19
  return h(t, {
20
20
  form: e,
21
21
  ...this.$attrs
22
22
  }, this.$slots);
23
23
  } };
24
- }, j = (t) => {
24
+ }, A = (t) => {
25
25
  let { formatMessage: n } = e(), r = (e) => e.replace(/([A-Z])/g, " $1").replace(/^./, (e) => e.toUpperCase()).trim(), i = (e) => n ? n({
26
26
  id: `general.fields.${e}`,
27
27
  defaultMessage: r(e)
@@ -30,10 +30,10 @@ var ee = class extends S.TaggedError("FormErrors") {}, A = (e) => function(t) {
30
30
  id: `${t.i18nNamespace}.fields.${e}`,
31
31
  defaultMessage: i(e)
32
32
  }) : i(e);
33
- }, M = (e) => function(t) {
33
+ }, j = (e) => function(t) {
34
34
  return {
35
35
  setup() {
36
- let { fieldMap: t, form: n } = e, r = n.useStore((e) => e.errors), i = n.useStore((e) => e.fieldMeta), a = n.useStore((e) => e.errorMap), o = j(n);
36
+ let { fieldMap: t, form: n } = e, r = n.useStore((e) => e.errors), i = n.useStore((e) => e.fieldMeta), a = n.useStore((e) => e.errorMap), o = A(n);
37
37
  return {
38
38
  generalErrors: r,
39
39
  errors: m(() => {
@@ -48,9 +48,9 @@ var ee = class extends S.TaggedError("FormErrors") {}, A = (e) => function(t) {
48
48
  }), e;
49
49
  }, []), n = [];
50
50
  if (a.value.onSubmit) {
51
- for (let [e, r] of Object.entries(a.value.onSubmit)) if (x.isArray(r) && r.length) for (let e of r) {
51
+ for (let [e, r] of Object.entries(a.value.onSubmit)) if (b.isArray(r) && r.length) for (let e of r) {
52
52
  let r = e;
53
- if (r?.path && x.isArray(r.path) && r.path.length) {
53
+ if (r?.path && b.isArray(r.path) && r.path.length) {
54
54
  let e = r.path.join(".");
55
55
  if (!t.value.has(e)) {
56
56
  n.push({
@@ -75,27 +75,27 @@ var ee = class extends S.TaggedError("FormErrors") {}, A = (e) => function(t) {
75
75
  }, this.$slots);
76
76
  }
77
77
  };
78
- }, N = (e, t) => e.includes(t), P = k(D.empty()), F = (e, h, S) => {
78
+ }, M = (e, t) => e.includes(t), N = O(x.empty()), P = (e, h, x) => {
79
79
  if (!e) throw Error("Schema is required");
80
- let D = i(e), k = E.toStandardSchemaV1(D), j = E.decodeUnknownEffect(D), { meta: F, unionMeta: te } = r(e), I = m(() => S?.persistency?.id ? S.persistency.id : `${window.location.pathname}-${Object.keys(F).join("-")}`), ne = () => {
80
+ let S = i(e), O = E.toStandardSchemaV1(S), A = E.decodeUnknownEffect(S), { meta: P, unionMeta: ne } = r(e), F = m(() => x?.persistency?.id ? x.persistency.id : `${window.location.pathname}-${Object.keys(P).join("-")}`), I = () => {
81
81
  let e = new URLSearchParams(window.location.search);
82
- e.delete(I.value);
82
+ e.delete(F.value);
83
83
  let t = new URL(window.location.href);
84
84
  t.search = e.toString(), window.history.replaceState({}, "", t.toString());
85
85
  }, L = m(() => {
86
- let r, i = S?.persistency;
87
- if (i?.policies && !r && (N(i.policies, "local") || N(i.policies, "session"))) {
88
- let e = N(i.policies, "local") ? localStorage : sessionStorage;
86
+ let r, i = x?.persistency;
87
+ if (i?.policies && !r && (M(i.policies, "local") || M(i.policies, "session"))) {
88
+ let e = M(i.policies, "local") ? localStorage : sessionStorage;
89
89
  if (e) try {
90
- let t = JSON.parse(e.getItem(I.value) || "{}");
91
- e.removeItem(I.value), r = t;
90
+ let t = JSON.parse(e.getItem(F.value) || "{}");
91
+ e.removeItem(F.value), r = t;
92
92
  } catch (e) {
93
93
  console.error(e);
94
94
  }
95
95
  }
96
- if (i?.policies && N(i.policies, "querystring")) try {
97
- let e = new URLSearchParams(window.location.search).get(I.value);
98
- ne(), e && (r = t(r || {}, JSON.parse(e)));
96
+ if (i?.policies && M(i.policies, "querystring")) try {
97
+ let e = new URLSearchParams(window.location.search).get(F.value);
98
+ I(), e && (r = t(r || {}, JSON.parse(e)));
99
99
  } catch (e) {
100
100
  console.error(e);
101
101
  }
@@ -105,33 +105,33 @@ var ee = class extends S.TaggedError("FormErrors") {}, A = (e) => function(t) {
105
105
  persistency: r,
106
106
  schema: n(e)
107
107
  };
108
- return (S?.defaultValuesPriority || [
108
+ return (x?.defaultValuesPriority || [
109
109
  "tanstack",
110
110
  "persistency",
111
111
  "schema"
112
112
  ]).reverse().reduce((e, n) => Object.keys(e).length ? t(e, a[n]) : a[n], {});
113
- }), R = (e, t) => e ? a.with(o.setSpan(a.active(), e), t) : t(), z = O({
113
+ }), R = (e, t) => e ? a.with(o.setSpan(a.active(), e), t) : t(), z = D({
114
114
  ...h,
115
115
  validators: {
116
- onSubmit: k,
116
+ onSubmit: O,
117
117
  ...h?.validators || {}
118
118
  },
119
119
  onSubmit: h?.onSubmit ? ({ formApi: e, meta: t, value: n }) => R(t?.currentSpan, async () => {
120
- let r = await P(j(n)), i = h.onSubmit({
120
+ let r = await N(A(n)), i = h.onSubmit({
121
121
  formApi: e,
122
122
  meta: t,
123
123
  value: r
124
124
  });
125
125
  if (w.isFiber(i)) return await s(i);
126
126
  if (C.isEffect(i)) {
127
- let e = await P(i);
127
+ let e = await N(i);
128
128
  return w.isFiber(e) ? await s(e) : e;
129
129
  }
130
130
  return i;
131
131
  }) : void 0,
132
132
  defaultValues: L.value
133
133
  }), B = () => {
134
- Object.keys(F).forEach((e) => {
134
+ Object.keys(P).forEach((e) => {
135
135
  z.setFieldValue(e, void 0);
136
136
  });
137
137
  }, V = (e) => e.reduce((e, t) => {
@@ -140,33 +140,33 @@ var ee = class extends S.TaggedError("FormErrors") {}, A = (e) => function(t) {
140
140
  }, {}), H = (e) => {
141
141
  if (!e) return;
142
142
  let { banKeys: t, keys: n } = e;
143
- return x.isArray(n) ? V(n) : x.isArray(t) ? V(Object.keys(F).filter((e) => t.includes(e))) : z.store.state.values;
143
+ return b.isArray(n) ? V(n) : b.isArray(t) ? V(Object.keys(P).filter((e) => t.includes(e))) : z.store.state.values;
144
144
  }, U = () => {
145
- let e = S?.persistency;
146
- if (!(!e?.policies || e.policies.length === 0) && (N(e.policies, "local") || N(e.policies, "session"))) {
147
- let t = N(e.policies, "local") ? localStorage : sessionStorage;
145
+ let e = x?.persistency;
146
+ if (!(!e?.policies || e.policies.length === 0) && (M(e.policies, "local") || M(e.policies, "session"))) {
147
+ let t = M(e.policies, "local") ? localStorage : sessionStorage;
148
148
  if (!t) return;
149
149
  let n = H(e);
150
- return t.setItem(I.value, JSON.stringify(n));
150
+ return t.setItem(F.value, JSON.stringify(n));
151
151
  }
152
152
  }, W = () => {
153
- let e = S?.persistency;
154
- if (!(!e?.policies || e.policies.length === 0) && N(e.policies, "querystring")) {
153
+ let e = x?.persistency;
154
+ if (!(!e?.policies || e.policies.length === 0) && M(e.policies, "querystring")) {
155
155
  let t = H(e), n = new URLSearchParams(window.location.search);
156
- n.set(I.value, JSON.stringify(t));
156
+ n.set(F.value, JSON.stringify(t));
157
157
  let r = new URL(window.location.href);
158
158
  r.search = n.toString(), window.history.replaceState({}, "", r.toString());
159
159
  }
160
160
  }, G = (e) => {
161
161
  z.store.state.isDirty && e.preventDefault();
162
162
  };
163
- if (v(U), _(() => {
164
- window.addEventListener("beforeunload", U), window.addEventListener("blur", W), S?.preventWindowExit && S.preventWindowExit !== "nope" && window.addEventListener("beforeunload", G);
163
+ if (_(U), ee(() => {
164
+ window.addEventListener("beforeunload", U), window.addEventListener("blur", W), x?.preventWindowExit && x.preventWindowExit !== "nope" && window.addEventListener("beforeunload", G);
165
165
  }), g(() => {
166
- window.removeEventListener("beforeunload", U), window.removeEventListener("blur", W), S?.preventWindowExit && S.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", G);
167
- }), S?.preventWindowExit === "prevent-and-reset") {
166
+ window.removeEventListener("beforeunload", U), window.removeEventListener("blur", W), x?.preventWindowExit && x.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", G);
167
+ }), x?.preventWindowExit === "prevent-and-reset") {
168
168
  let e = z.useStore((e) => e.isSubmitting), t = z.useStore((e) => e.submissionAttempts), n = z.useStore((e) => e.canSubmit), r = z.useStore((e) => e.values);
169
- b([e, t], ([e, t], [i]) => {
169
+ y([e, t], ([e, t], [i]) => {
170
170
  i && !e && t > 0 && n.value && z.reset(r.value);
171
171
  });
172
172
  }
@@ -175,15 +175,15 @@ var ee = class extends S.TaggedError("FormErrors") {}, A = (e) => function(t) {
175
175
  ...e
176
176
  } : e)))), q = (e) => e?.checkErrors ? K(e?.meta).pipe(C.flatMap(C.fnUntraced(function* () {
177
177
  let e = z.getAllErrors();
178
- if (Object.keys(e.fields).length || e.form.errors.length) return yield* C.fail(new ee({
178
+ if (Object.keys(e.fields).length || e.form.errors.length) return yield* C.fail(new te({
179
179
  form: e.form,
180
180
  fields: e.fields
181
181
  }));
182
- }))) : K(e?.meta), J = z.handleSubmit, Y = y(/* @__PURE__ */ new Map()), X = Object.assign(z, {
183
- i18nNamespace: S?.i18nNamespace,
184
- ignorePreventCloseEvents: S?.ignorePreventCloseEvents,
185
- meta: F,
186
- unionMeta: te,
182
+ }))) : K(e?.meta), J = z.handleSubmit, Y = v(/* @__PURE__ */ new Map()), X = Object.assign(z, {
183
+ i18nNamespace: x?.i18nNamespace,
184
+ ignorePreventCloseEvents: x?.ignorePreventCloseEvents,
185
+ meta: P,
186
+ unionMeta: ne,
187
187
  clear: B,
188
188
  handleSubmit: (e) => J({
189
189
  currentSpan: o.getSpan(a.active()),
@@ -191,17 +191,17 @@ var ee = class extends S.TaggedError("FormErrors") {}, A = (e) => function(t) {
191
191
  }),
192
192
  handleSubmitEffect: q,
193
193
  registerField: (e) => {
194
- b(e, (e) => {
194
+ y(e, (e) => {
195
195
  Y.value.set(e.name, {
196
196
  label: e.label,
197
197
  id: e.id
198
198
  });
199
- }, { immediate: !0 }), v(() => {
199
+ }, { immediate: !0 }), _(() => {
200
200
  Y.value.get(e.value.name)?.id === e.value.id && Y.value.delete(e.value.name);
201
201
  });
202
202
  }
203
- }), Z = y(0), Q = z.useStore((e) => e.submissionAttempts);
204
- b(z.useStore((e) => e.values), () => {
203
+ }), Z = v(0), Q = z.useStore((e) => e.submissionAttempts);
204
+ y(z.useStore((e) => e.values), () => {
205
205
  if (Z.value !== Q.value) {
206
206
  Z.value = Q.value;
207
207
  for (let e of Object.values(z.fieldInfo)) e?.instance?.state.meta.errorMap?.onSubmit && e.instance.setMeta((e) => ({
@@ -222,14 +222,14 @@ var ee = class extends S.TaggedError("FormErrors") {}, A = (e) => function(t) {
222
222
  _keys: void 0,
223
223
  _schema: e,
224
224
  errorContext: $,
225
- Form: A(X)(p),
226
- Input: A(X)(S?.input ?? d),
227
- TaggedUnion: A(X)(f),
225
+ Form: k(X)(p),
226
+ Input: k(X)(x?.input ?? d),
227
+ TaggedUnion: k(X)(f),
228
228
  Field: z.Field,
229
- Errors: M($)(u),
230
- Array: A(X)(c),
231
- AutoGen: A(X)(l)
229
+ Errors: j($)(u),
230
+ Array: k(X)(c),
231
+ AutoGen: k(X)(l)
232
232
  });
233
233
  };
234
234
  //#endregion
235
- export { j as useErrorLabel, F as useOmegaForm };
235
+ export { A as useErrorLabel, P as useOmegaForm };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "4.0.0-beta.53",
3
+ "version": "4.0.0-beta.54",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "effect": "^4.0.0-beta.43",
@@ -57,8 +57,8 @@
57
57
  "highlight.js": "^11.11.1",
58
58
  "mitt": "^3.0.1",
59
59
  "vue3-highlightjs": "^1.0.5",
60
- "@effect-app/vue": "4.0.0-beta.53",
61
- "effect-app": "4.0.0-beta.53"
60
+ "@effect-app/vue": "4.0.0-beta.54",
61
+ "effect-app": "4.0.0-beta.54"
62
62
  },
63
63
  "scripts": {
64
64
  "check": "vue-tsc",
@@ -3,7 +3,7 @@
3
3
 
4
4
  import * as api from "@opentelemetry/api"
5
5
  import { type DeepKeys, DeepValue, type FormAsyncValidateOrFn, type FormValidateOrFn, type StandardSchemaV1, StandardSchemaV1Issue, useForm, ValidationError, ValidationErrorMap } from "@tanstack/vue-form"
6
- import { Array, Data, Effect, Fiber, Option, Order, S, ServiceMap } from "effect-app"
6
+ import { Array, Context, Data, Effect, Fiber, Option, Order, S } from "effect-app"
7
7
  import { runtimeFiberAsPromise, UnionToTuples } from "effect-app/utils"
8
8
  import { Component, computed, ComputedRef, ConcreteComponent, h, type InjectionKey, onBeforeUnmount, onMounted, onUnmounted, Ref, ref, watch } from "vue"
9
9
  import { useIntl } from "../../utils"
@@ -670,7 +670,7 @@ export interface OmegaFormReturn<
670
670
  }
671
671
  }
672
672
 
673
- const runPromise = makeRunPromise(ServiceMap.empty())
673
+ const runPromise = makeRunPromise(Context.empty())
674
674
 
675
675
  export const useOmegaForm = <
676
676
  // eslint-disable-next-line @typescript-eslint/no-explicit-any