@effect-app/vue-components 4.0.0-beta.151 → 4.0.0-beta.153

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.
@@ -37,8 +37,8 @@ var y = /* @__PURE__ */ c({
37
37
  key: T.value,
38
38
  name: c.name,
39
39
  validators: {
40
- onBlur: k.value,
41
- ...c.validators
40
+ ...c.validators,
41
+ onSubmit: k.value
42
42
  }
43
43
  }, {
44
44
  default: v(({ field: t, state: r }) => [w.value ? (p(), a(n, d({ key: 0 }, {
@@ -9,12 +9,12 @@ 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 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";
12
+ import { computed as m, h, onBeforeUnmount as ee, onMounted as te, onUnmounted as g, ref as _, watch as v } from "vue";
13
+ import { Array as y, Context as b, Data as x, Effect as S, Fiber as C, Option as w, S as T } from "effect-app";
14
+ import { useForm as E } from "@tanstack/vue-form";
15
+ import { makeRunPromise as D } from "@effect-app/vue/runtime";
16
16
  //#region src/components/OmegaForm/useOmegaForm.ts
17
- var te = class extends S.TaggedError("FormErrors") {}, k = (e) => function(t) {
17
+ var O = class extends x.TaggedError("FormErrors") {}, k = (e) => function(t) {
18
18
  return { render() {
19
19
  return h(t, {
20
20
  form: e,
@@ -48,9 +48,9 @@ var te = class extends S.TaggedError("FormErrors") {}, k = (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 (b.isArray(r) && r.length) for (let e of r) {
51
+ for (let [e, r] of Object.entries(a.value.onSubmit)) if (y.isArray(r) && r.length) for (let e of r) {
52
52
  let r = e;
53
- if (r?.path && b.isArray(r.path) && r.path.length) {
53
+ if (r?.path && y.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,15 +75,15 @@ var te = class extends S.TaggedError("FormErrors") {}, k = (e) => function(t) {
75
75
  }, this.$slots);
76
76
  }
77
77
  };
78
- }, M = (e, t) => e.includes(t), N = O(x.empty()), P = (e, h, x) => {
78
+ }, M = (e, t) => e.includes(t), N = D(b.empty()), P = (e, h, b) => {
79
79
  if (!e) throw Error("Schema is required");
80
- let S = i(e), O = E.toStandardSchemaV1(S), A = E.decodeUnknownEffect(S), { meta: P, unionMeta: ne } = r(S), F = m(() => x?.persistency?.id ? x.persistency.id : `${window.location.pathname}-${Object.keys(P).join("-")}`), I = () => {
80
+ let x = i(e), D = T.toStandardSchemaV1(x), A = T.decodeUnknownEffect(x), { meta: P, unionMeta: ne } = r(x), F = m(() => b?.persistency?.id ? b.persistency.id : `${window.location.pathname}-${Object.keys(P).join("-")}`), re = () => {
81
81
  let e = new URLSearchParams(window.location.search);
82
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
- }, L = m(() => {
86
- let r, i = x?.persistency;
85
+ }, I = m(() => {
86
+ let r, i = b?.persistency;
87
87
  if (i?.policies && !r && (M(i.policies, "local") || M(i.policies, "session"))) {
88
88
  let e = M(i.policies, "local") ? localStorage : sessionStorage;
89
89
  if (e) try {
@@ -95,7 +95,7 @@ var te = class extends S.TaggedError("FormErrors") {}, k = (e) => function(t) {
95
95
  }
96
96
  if (i?.policies && M(i.policies, "querystring")) try {
97
97
  let e = new URLSearchParams(window.location.search).get(F.value);
98
- I(), e && (r = t(r || {}, JSON.parse(e)));
98
+ re(), e && (r = t(r || {}, JSON.parse(e)));
99
99
  } catch (e) {
100
100
  console.error(e);
101
101
  }
@@ -105,106 +105,106 @@ var te = class extends S.TaggedError("FormErrors") {}, k = (e) => function(t) {
105
105
  persistency: r,
106
106
  schema: n(e)
107
107
  };
108
- return (x?.defaultValuesPriority || [
108
+ return (b?.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 = D({
113
+ }), L = (e, t) => e ? a.with(o.setSpan(a.active(), e), t) : t(), R = E({
114
114
  ...h,
115
115
  validators: {
116
- onSubmit: O,
116
+ onSubmit: D,
117
117
  ...h?.validators || {}
118
118
  },
119
- onSubmit: h?.onSubmit ? ({ formApi: e, meta: t, value: n }) => R(t?.currentSpan, async () => {
119
+ onSubmit: h?.onSubmit ? ({ formApi: e, meta: t, value: n }) => L(t?.currentSpan, async () => {
120
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
- if (w.isFiber(i)) return await s(i);
126
- if (C.isEffect(i)) {
125
+ if (C.isFiber(i)) return await s(i);
126
+ if (S.isEffect(i)) {
127
127
  let e = await N(i);
128
- return w.isFiber(e) ? await s(e) : e;
128
+ return C.isFiber(e) ? await s(e) : e;
129
129
  }
130
130
  return i;
131
131
  }) : void 0,
132
- defaultValues: L.value
133
- }), B = () => {
132
+ defaultValues: I.value
133
+ }), z = () => {
134
134
  Object.keys(P).forEach((e) => {
135
- z.setFieldValue(e, void 0);
135
+ R.setFieldValue(e, void 0);
136
136
  });
137
- }, V = (e) => e.reduce((e, t) => {
137
+ }, B = (e) => e.reduce((e, t) => {
138
138
  let n = t.split(".");
139
- return n.reduce((e, r, i) => (i === n.length - 1 ? e[r] = z.getFieldValue(t) : e[r] = e[r] ?? {}, e[r]), e), e;
140
- }, {}), H = (e) => {
139
+ return n.reduce((e, r, i) => (i === n.length - 1 ? e[r] = R.getFieldValue(t) : e[r] = e[r] ?? {}, e[r]), e), e;
140
+ }, {}), V = (e) => {
141
141
  if (!e) return;
142
142
  let { banKeys: t, keys: n } = e;
143
- return b.isArray(n) ? V(n) : b.isArray(t) ? V(Object.keys(P).filter((e) => t.includes(e))) : z.store.state.values;
144
- }, U = () => {
145
- let e = x?.persistency;
143
+ return y.isArray(n) ? B(n) : y.isArray(t) ? B(Object.keys(P).filter((e) => t.includes(e))) : R.store.state.values;
144
+ }, H = () => {
145
+ let e = b?.persistency;
146
146
  if (!(!e?.policies || e.policies.length === 0) && (M(e.policies, "local") || M(e.policies, "session"))) {
147
147
  let t = M(e.policies, "local") ? localStorage : sessionStorage;
148
148
  if (!t) return;
149
- let n = H(e);
149
+ let n = V(e);
150
150
  return t.setItem(F.value, JSON.stringify(n));
151
151
  }
152
- }, W = () => {
153
- let e = x?.persistency;
152
+ }, U = () => {
153
+ let e = b?.persistency;
154
154
  if (!(!e?.policies || e.policies.length === 0) && M(e.policies, "querystring")) {
155
- let t = H(e), n = new URLSearchParams(window.location.search);
155
+ let t = V(e), n = new URLSearchParams(window.location.search);
156
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
- }, G = (e) => {
161
- z.store.state.isDirty && e.preventDefault();
160
+ }, W = (e) => {
161
+ R.store.state.isDirty && e.preventDefault();
162
162
  };
163
- if (_(U), ee(() => {
164
- window.addEventListener("beforeunload", U), window.addEventListener("blur", W), x?.preventWindowExit && x.preventWindowExit !== "nope" && window.addEventListener("beforeunload", G);
165
- }), g(() => {
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
- 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
- y([e, t], ([e, t], [i]) => {
170
- i && !e && t > 0 && n.value && z.reset(r.value);
163
+ if (g(H), te(() => {
164
+ window.addEventListener("beforeunload", H), window.addEventListener("blur", U), b?.preventWindowExit && b.preventWindowExit !== "nope" && window.addEventListener("beforeunload", W);
165
+ }), ee(() => {
166
+ window.removeEventListener("beforeunload", H), window.removeEventListener("blur", U), b?.preventWindowExit && b.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", W);
167
+ }), b?.preventWindowExit === "prevent-and-reset") {
168
+ let e = R.useStore((e) => e.isSubmitting), t = R.useStore((e) => e.submissionAttempts), n = R.useStore((e) => e.canSubmit), r = R.useStore((e) => e.values);
169
+ v([e, t], ([e, t], [i]) => {
170
+ i && !e && t > 0 && n.value && R.reset(r.value);
171
171
  });
172
172
  }
173
- let K = (e) => C.currentSpan.pipe(C.option, C.flatMap((t) => C.promise(() => z.handleSubmit(T.isSome(t) ? {
173
+ let G = R.handleSubmit, K = async (e) => await G(e), q = (e) => S.currentSpan.pipe(S.option, S.flatMap((t) => S.promise(() => K(w.isSome(t) ? {
174
174
  currentSpan: t.value,
175
175
  ...e
176
- } : e)))), q = (e) => e?.checkErrors ? K(e?.meta).pipe(C.flatMap(C.fnUntraced(function* () {
177
- let e = z.getAllErrors();
178
- if (Object.keys(e.fields).length || e.form.errors.length) return yield* C.fail(new te({
176
+ } : e)))), J = (e) => e?.checkErrors ? q(e?.meta).pipe(S.flatMap(S.fnUntraced(function* () {
177
+ let e = R.getAllErrors();
178
+ if (Object.keys(e.fields).length || e.form.errors.length) return yield* S.fail(new O({
179
179
  form: e.form,
180
180
  fields: e.fields
181
181
  }));
182
- }))) : K(e?.meta), J = z.handleSubmit, Y = v(/* @__PURE__ */ new Map()), X = Object.assign(z, {
183
- i18nNamespace: x?.i18nNamespace,
184
- ignorePreventCloseEvents: x?.ignorePreventCloseEvents,
182
+ }))) : q(e?.meta), Y = _(/* @__PURE__ */ new Map()), X = Object.assign(R, {
183
+ i18nNamespace: b?.i18nNamespace,
184
+ ignorePreventCloseEvents: b?.ignorePreventCloseEvents,
185
185
  meta: P,
186
186
  unionMeta: ne,
187
- clear: B,
188
- handleSubmit: (e) => J({
187
+ clear: z,
188
+ handleSubmit: (e) => K({
189
189
  currentSpan: o.getSpan(a.active()),
190
190
  ...e
191
191
  }),
192
- handleSubmitEffect: q,
192
+ handleSubmitEffect: J,
193
193
  registerField: (e) => {
194
- y(e, (e) => {
194
+ v(e, (e) => {
195
195
  Y.value.set(e.name, {
196
196
  label: e.label,
197
197
  id: e.id
198
198
  });
199
- }, { immediate: !0 }), _(() => {
199
+ }, { immediate: !0 }), g(() => {
200
200
  Y.value.get(e.value.name)?.id === e.value.id && Y.value.delete(e.value.name);
201
201
  });
202
202
  }
203
- }), Z = v(0), Q = z.useStore((e) => e.submissionAttempts);
204
- y(z.useStore((e) => e.values), () => {
203
+ }), Z = _(0), Q = R.useStore((e) => e.submissionAttempts);
204
+ v(R.useStore((e) => e.values), () => {
205
205
  if (Z.value !== Q.value) {
206
206
  Z.value = Q.value;
207
- for (let e of Object.values(z.fieldInfo)) e?.instance?.state.meta.errorMap?.onSubmit && e.instance.setMeta((e) => ({
207
+ for (let e of Object.values(R.fieldInfo)) e?.instance?.state.meta.errorMap?.onSubmit && e.instance.setMeta((e) => ({
208
208
  ...e,
209
209
  errorMap: {
210
210
  ...e.errorMap,
@@ -223,9 +223,9 @@ var te = class extends S.TaggedError("FormErrors") {}, k = (e) => function(t) {
223
223
  _schema: e,
224
224
  errorContext: $,
225
225
  Form: k(X)(p),
226
- Input: k(X)(x?.input ?? d),
226
+ Input: k(X)(b?.input ?? d),
227
227
  TaggedUnion: k(X)(f),
228
- Field: z.Field,
228
+ Field: R.Field,
229
229
  Errors: j($)(u),
230
230
  Array: k(X)(c),
231
231
  AutoGen: k(X)(l)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "4.0.0-beta.151",
3
+ "version": "4.0.0-beta.153",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "effect": "^4.0.0-beta.56",
@@ -58,8 +58,8 @@
58
58
  "highlight.js": "^11.11.1",
59
59
  "mitt": "^3.0.1",
60
60
  "vue3-highlightjs": "^1.0.5",
61
- "@effect-app/vue": "4.0.0-beta.151",
62
- "effect-app": "4.0.0-beta.151"
61
+ "@effect-app/vue": "4.0.0-beta.153",
62
+ "effect-app": "4.0.0-beta.153"
63
63
  },
64
64
  "scripts": {
65
65
  "check": "vue-tsc",
@@ -4,16 +4,15 @@
4
4
  :key="fieldKey"
5
5
  :name="name"
6
6
  :validators="{
7
- // onChange: schema,
8
- onBlur: schema,
9
- ...validators
7
+ ...validators,
8
+ onSubmit: schema
10
9
  }"
11
10
  >
12
11
  <template #default="{ field, state }">
13
12
  <OmegaInternalInput
14
13
  v-if="meta"
15
14
  v-bind="{ ...$attrs, ...$props, inputClass: computedClass }"
16
- :field="field"
15
+ :field="field as any"
17
16
  :state="state"
18
17
  :register="form.registerField"
19
18
  :label="label ?? errori18n(propsName)"
@@ -923,12 +923,20 @@ export const useOmegaForm = <
923
923
  })
924
924
  }
925
925
 
926
+ const hs = form.handleSubmit
927
+
928
+ const handleSubmit: typeof form.handleSubmit = async (meta?: Record<string, any>) => {
929
+ // workaround for not revealing all form errors on submit
930
+ // await form.validateAllFields("blur")
931
+ return await hs(meta)
932
+ }
933
+
926
934
  const handleSubmitEffect_ = (meta?: Record<string, any>) =>
927
935
  Effect.currentSpan.pipe(
928
936
  Effect.option,
929
937
  Effect
930
938
  .flatMap((span) =>
931
- Effect.promise(() => form.handleSubmit(Option.isSome(span) ? { currentSpan: span.value, ...meta } : meta))
939
+ Effect.promise(() => handleSubmit(Option.isSome(span) ? { currentSpan: span.value, ...meta } : meta))
932
940
  )
933
941
  )
934
942
 
@@ -947,8 +955,6 @@ export const useOmegaForm = <
947
955
  })))
948
956
  : handleSubmitEffect_(options?.meta)
949
957
 
950
- const handleSubmit = form.handleSubmit
951
-
952
958
  const fieldMap = ref(new Map<string, { label: string; id: string }>())
953
959
 
954
960
  const formWithExtras: OF<From, To> = Object.assign(form, {