@effect-app/vue-components 2.11.4 → 3.0.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.
- package/dist/types/components/OmegaForm/OmegaFormStuff.d.ts +0 -1
- package/dist/types/components/OmegaForm/useOmegaForm.d.ts +0 -1
- package/dist/vue-components.es10.js +101 -106
- package/dist/vue-components.es12.js +147 -154
- package/dist/vue-components.es17.js +1 -1
- package/dist/vue-components.es20.js +2 -2
- package/dist/vue-components.es21.js +2 -2
- package/dist/vue-components.es30.js +41 -191
- package/dist/vue-components.es31.js +4 -0
- package/dist/vue-components.es32.js +2 -42
- package/dist/vue-components.es33.js +111 -2
- package/dist/vue-components.es35.js +7 -111
- package/dist/vue-components.es36.js +34 -0
- package/dist/vue-components.es38.js +187 -27
- package/dist/vue-components.es40.js +1 -1
- package/dist/vue-components.es6.js +31 -28
- package/dist/vue-components.es7.js +1 -1
- package/dist/vue-components.es8.js +13 -13
- package/dist/vue-components.es9.js +9 -15
- package/package.json +1 -1
- package/src/components/OmegaForm/OmegaFormStuff.ts +7 -24
- package/src/components/OmegaForm/OmegaInput.vue +16 -5
- package/src/components/OmegaForm/OmegaTaggedUnion.vue +0 -1
- package/src/components/OmegaForm/OmegaTaggedUnionInternal.vue +8 -16
- package/src/components/OmegaForm/useOmegaForm.ts +3 -16
- package/src/components/OmegaForm/useRegisterField.ts +1 -3
- package/dist/vue-components.es34.js +0 -4
- package/dist/vue-components.es37.js +0 -9
|
@@ -144,7 +144,6 @@ export declare const generateMetaFromSchema: <From, To>(schema: S.Schema<To, Fro
|
|
|
144
144
|
schema: S.Schema<To, From, never>;
|
|
145
145
|
meta: MetaRecord<To>;
|
|
146
146
|
unionMeta: Record<string, MetaRecord<To>>;
|
|
147
|
-
unionDefaultValues: Record<string, Record<string, any>>;
|
|
148
147
|
};
|
|
149
148
|
export declare const generateInputStandardSchemaFromFieldMeta: (meta: FieldMeta, trans?: ReturnType<typeof useIntl>["trans"]) => StandardSchemaV1<any, any>;
|
|
150
149
|
export declare const nullableInput: <A, I, R>(schema: S.Schema<A, I, R>, defaultValue: () => A) => S.transform<import("effect/Schema").NullOr<S.Schema<A, I, R>> & {
|
|
@@ -62,7 +62,6 @@ export type OmegaConfig<T> = {
|
|
|
62
62
|
export interface OF<From, To> extends OmegaFormApi<From, To> {
|
|
63
63
|
meta: MetaRecord<From>;
|
|
64
64
|
unionMeta: Record<string, MetaRecord<From>>;
|
|
65
|
-
unionDefaultValues: Record<string, Record<string, any>>;
|
|
66
65
|
clear: () => void;
|
|
67
66
|
i18nNamespace?: string;
|
|
68
67
|
ignorePreventCloseEvents?: boolean;
|
|
@@ -1,60 +1,60 @@
|
|
|
1
|
-
import { useForm as
|
|
2
|
-
import { Data as
|
|
3
|
-
import { runtimeFiberAsPromise as
|
|
4
|
-
import { computed as x, onUnmounted as
|
|
5
|
-
import { useIntl as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { generateMetaFromSchema as
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import { trace as
|
|
1
|
+
import { useForm as K } from "@tanstack/vue-form";
|
|
2
|
+
import { Data as T, S as W, Effect as d, Fiber as $, Option as P, Array as F } from "effect-app";
|
|
3
|
+
import { runtimeFiberAsPromise as z } from "./vue-components.es17.js";
|
|
4
|
+
import { computed as x, onUnmounted as D, onMounted as G, onBeforeUnmount as Z, watch as R, ref as Q, h as J } from "vue";
|
|
5
|
+
import { useIntl as X } from "./vue-components.es3.js";
|
|
6
|
+
import Y from "./vue-components.es18.js";
|
|
7
|
+
import C from "./vue-components.es19.js";
|
|
8
|
+
import ee from "./vue-components.es20.js";
|
|
9
|
+
import { generateMetaFromSchema as re, deepMerge as N, defaultsValueFromSchema as te } from "./vue-components.es12.js";
|
|
10
|
+
import se from "./vue-components.es6.js";
|
|
11
|
+
import ne from "./vue-components.es8.js";
|
|
12
|
+
import oe from "./vue-components.es21.js";
|
|
13
|
+
import { trace as H } from "./vue-components.es22.js";
|
|
14
14
|
import { context as U } from "./vue-components.es23.js";
|
|
15
|
-
class
|
|
15
|
+
class ie extends T.TaggedError("FormErrors") {
|
|
16
16
|
}
|
|
17
17
|
const M = (i) => function(s) {
|
|
18
18
|
return {
|
|
19
19
|
render() {
|
|
20
|
-
return
|
|
20
|
+
return J(s, {
|
|
21
21
|
form: i,
|
|
22
22
|
...this.$attrs
|
|
23
23
|
}, this.$slots);
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
|
-
},
|
|
27
|
-
const { formatMessage: l } =
|
|
26
|
+
}, ae = (i) => {
|
|
27
|
+
const { formatMessage: l } = X(), s = (a) => a.replace(/([A-Z])/g, " $1").replace(/^./, (g) => g.toUpperCase()).trim(), f = (a) => l ? l({ id: `general.fields.${a}`, defaultMessage: s(a) }) : s(a);
|
|
28
28
|
return (a) => i.i18nNamespace ? l({ id: `${i.i18nNamespace}.fields.${a}`, defaultMessage: f(a) }) : f(a);
|
|
29
|
-
},
|
|
29
|
+
}, ce = (i) => function(s) {
|
|
30
30
|
return {
|
|
31
31
|
setup() {
|
|
32
|
-
const { fieldMap: f, form: m } = i, a = m.useStore((
|
|
33
|
-
const
|
|
32
|
+
const { fieldMap: f, form: m } = i, a = m.useStore((v) => v.errors), g = m.useStore((v) => v.fieldMeta), p = m.useStore((v) => v.errorMap), j = ae(m), A = x(() => {
|
|
33
|
+
const v = F.filterMap(
|
|
34
34
|
Object.entries(g.value),
|
|
35
|
-
([
|
|
36
|
-
const w =
|
|
37
|
-
if (!w.length) return
|
|
38
|
-
const u = f.value.get(
|
|
39
|
-
return u ?
|
|
35
|
+
([O, h]) => {
|
|
36
|
+
const w = h.errors ?? [];
|
|
37
|
+
if (!w.length) return P.none();
|
|
38
|
+
const u = f.value.get(O);
|
|
39
|
+
return u ? P.some({
|
|
40
40
|
label: u.label,
|
|
41
41
|
inputId: u.id,
|
|
42
42
|
// Only show the first error
|
|
43
43
|
errors: [w[0]?.message].filter(Boolean)
|
|
44
|
-
}) :
|
|
44
|
+
}) : P.none();
|
|
45
45
|
}
|
|
46
|
-
),
|
|
47
|
-
if (
|
|
48
|
-
for (const [
|
|
49
|
-
if (F.isArray(
|
|
50
|
-
for (const w of
|
|
46
|
+
), o = [];
|
|
47
|
+
if (p.value.onSubmit) {
|
|
48
|
+
for (const [O, h] of Object.entries(p.value.onSubmit))
|
|
49
|
+
if (F.isArray(h) && h.length)
|
|
50
|
+
for (const w of h) {
|
|
51
51
|
const u = w;
|
|
52
52
|
if (u?.path && F.isArray(u.path) && u.path.length) {
|
|
53
|
-
const
|
|
54
|
-
if (!f.value.has(
|
|
55
|
-
|
|
56
|
-
label:
|
|
57
|
-
inputId:
|
|
53
|
+
const E = u.path.join(".");
|
|
54
|
+
if (!f.value.has(E)) {
|
|
55
|
+
o.push({
|
|
56
|
+
label: j(E),
|
|
57
|
+
inputId: E,
|
|
58
58
|
errors: [u.message].filter(Boolean)
|
|
59
59
|
});
|
|
60
60
|
break;
|
|
@@ -62,55 +62,55 @@ const M = (i) => function(s) {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
return [...
|
|
65
|
+
return [...v, ...o];
|
|
66
66
|
});
|
|
67
67
|
return {
|
|
68
68
|
generalErrors: a,
|
|
69
|
-
errors:
|
|
69
|
+
errors: A
|
|
70
70
|
};
|
|
71
71
|
},
|
|
72
72
|
render({ errors: f, generalErrors: m }) {
|
|
73
|
-
return
|
|
73
|
+
return J(s, {
|
|
74
74
|
errors: f,
|
|
75
75
|
generalErrors: m,
|
|
76
76
|
...this.$attrs
|
|
77
77
|
}, this.$slots);
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
|
-
},
|
|
80
|
+
}, b = (i, l) => i.includes(l), Me = (i, l, s) => {
|
|
81
81
|
if (!i) throw new Error("Schema is required");
|
|
82
|
-
const f = W.standardSchemaV1(i), m = W.decode(i), { meta: a,
|
|
82
|
+
const f = W.standardSchemaV1(i), m = W.decode(i), { meta: a, unionMeta: g } = re(i), p = x(() => {
|
|
83
83
|
if (s?.persistency?.id)
|
|
84
84
|
return s.persistency.id;
|
|
85
85
|
const e = window.location.pathname, r = Object.keys(a);
|
|
86
86
|
return `${e}-${r.join("-")}`;
|
|
87
|
-
}),
|
|
87
|
+
}), j = () => {
|
|
88
88
|
const e = new URLSearchParams(window.location.search);
|
|
89
|
-
e.delete(
|
|
89
|
+
e.delete(p.value);
|
|
90
90
|
const r = new URL(window.location.href);
|
|
91
91
|
r.search = e.toString(), window.history.replaceState({}, "", r.toString());
|
|
92
|
-
},
|
|
92
|
+
}, A = x(() => {
|
|
93
93
|
let e;
|
|
94
94
|
const r = s?.persistency;
|
|
95
95
|
if (
|
|
96
96
|
// query string has higher priority than local/session storage
|
|
97
|
-
r?.policies && !e && (
|
|
97
|
+
r?.policies && !e && (b(r.policies, "local") || b(r.policies, "session"))
|
|
98
98
|
) {
|
|
99
|
-
const n =
|
|
99
|
+
const n = b(r.policies, "local") ? localStorage : sessionStorage;
|
|
100
100
|
if (n)
|
|
101
101
|
try {
|
|
102
102
|
const t = JSON.parse(
|
|
103
|
-
n.getItem(
|
|
103
|
+
n.getItem(p.value) || "{}"
|
|
104
104
|
);
|
|
105
|
-
n.removeItem(
|
|
105
|
+
n.removeItem(p.value), e = t;
|
|
106
106
|
} catch (t) {
|
|
107
107
|
console.error(t);
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
if (r?.policies &&
|
|
110
|
+
if (r?.policies && b(r.policies, "querystring"))
|
|
111
111
|
try {
|
|
112
|
-
const t = new URLSearchParams(window.location.search).get(
|
|
113
|
-
|
|
112
|
+
const t = new URLSearchParams(window.location.search).get(p.value);
|
|
113
|
+
j(), t && (e = N(e || {}, JSON.parse(t)));
|
|
114
114
|
} catch (n) {
|
|
115
115
|
console.error(n);
|
|
116
116
|
}
|
|
@@ -118,127 +118,122 @@ const M = (i) => function(s) {
|
|
|
118
118
|
const c = {
|
|
119
119
|
tanstack: l?.defaultValues || {},
|
|
120
120
|
persistency: e,
|
|
121
|
-
schema:
|
|
121
|
+
schema: te(i)
|
|
122
122
|
};
|
|
123
123
|
return (s?.defaultValuesPriority || ["tanstack", "persistency", "schema"]).reverse().reduce(
|
|
124
|
-
(n, t) => Object.keys(n).length ?
|
|
124
|
+
(n, t) => Object.keys(n).length ? N(n, c[t]) : c[t],
|
|
125
125
|
{}
|
|
126
126
|
);
|
|
127
|
-
}),
|
|
127
|
+
}), v = (e, r) => e ? U.with(H.setSpan(U.active(), e), r) : r(), o = K({
|
|
128
128
|
...l,
|
|
129
129
|
validators: {
|
|
130
130
|
onSubmit: f,
|
|
131
131
|
...l?.validators || {}
|
|
132
132
|
},
|
|
133
|
-
onSubmit: l?.onSubmit ? ({ formApi: e, meta: r, value: c }) =>
|
|
133
|
+
onSubmit: l?.onSubmit ? ({ formApi: e, meta: r, value: c }) => v(r?.currentSpan, async () => {
|
|
134
134
|
const n = await d.runPromise(m(c)), t = l.onSubmit({
|
|
135
135
|
formApi: e,
|
|
136
136
|
meta: r,
|
|
137
137
|
value: n
|
|
138
138
|
});
|
|
139
|
-
return $.isFiber(t) && $.isRuntimeFiber(t) ? await
|
|
139
|
+
return $.isFiber(t) && $.isRuntimeFiber(t) ? await z(t) : d.isEffect(t) ? await d.runPromise(
|
|
140
140
|
t.pipe(
|
|
141
141
|
// meta?.currentSpan
|
|
142
142
|
// ? Effect.withParentSpan(meta.currentSpan)
|
|
143
143
|
// : (_) => _,
|
|
144
|
-
d.flatMap((
|
|
144
|
+
d.flatMap((S) => $.join(S))
|
|
145
145
|
)
|
|
146
146
|
) : t;
|
|
147
147
|
}) : void 0,
|
|
148
|
-
defaultValues:
|
|
149
|
-
}),
|
|
148
|
+
defaultValues: A.value
|
|
149
|
+
}), O = () => {
|
|
150
150
|
Object.keys(a).forEach((e) => {
|
|
151
151
|
o.setFieldValue(e, void 0);
|
|
152
152
|
});
|
|
153
|
-
},
|
|
153
|
+
}, h = (e) => e.reduce((r, c) => {
|
|
154
154
|
const n = c.split(".");
|
|
155
|
-
return n.reduce((t,
|
|
156
|
-
}, {}),
|
|
155
|
+
return n.reduce((t, S, _) => (_ === n.length - 1 ? t[S] = o.getFieldValue(c) : t[S] = t[S] ?? {}, t[S]), r), r;
|
|
156
|
+
}, {}), w = (e) => {
|
|
157
157
|
if (e) {
|
|
158
158
|
if (F.isArray(e.keys))
|
|
159
|
-
return
|
|
159
|
+
return h(e.keys);
|
|
160
160
|
if (F.isArray(e.banKeys)) {
|
|
161
161
|
const r = Object.keys(a).filter((c) => e.banKeys?.includes(c));
|
|
162
|
-
return
|
|
162
|
+
return h(r);
|
|
163
163
|
}
|
|
164
164
|
return o.store.state.values;
|
|
165
165
|
}
|
|
166
|
-
},
|
|
166
|
+
}, u = () => {
|
|
167
167
|
const e = s?.persistency;
|
|
168
|
-
if (!(!e?.policies || e.policies.length === 0) && (
|
|
169
|
-
const r =
|
|
168
|
+
if (!(!e?.policies || e.policies.length === 0) && (b(e.policies, "local") || b(e.policies, "session"))) {
|
|
169
|
+
const r = b(e.policies, "local") ? localStorage : sessionStorage;
|
|
170
170
|
if (!r) return;
|
|
171
|
-
const c =
|
|
172
|
-
return r.setItem(
|
|
171
|
+
const c = w(e);
|
|
172
|
+
return r.setItem(p.value, JSON.stringify(c));
|
|
173
173
|
}
|
|
174
|
-
},
|
|
174
|
+
}, E = () => {
|
|
175
175
|
const e = s?.persistency;
|
|
176
|
-
if (!(!e?.policies || e.policies.length === 0) &&
|
|
177
|
-
const r =
|
|
178
|
-
c.set(
|
|
176
|
+
if (!(!e?.policies || e.policies.length === 0) && b(e.policies, "querystring")) {
|
|
177
|
+
const r = w(e), c = new URLSearchParams(window.location.search);
|
|
178
|
+
c.set(p.value, JSON.stringify(r));
|
|
179
179
|
const n = new URL(window.location.href);
|
|
180
180
|
n.search = c.toString(), window.history.replaceState({}, "", n.toString());
|
|
181
181
|
}
|
|
182
182
|
}, k = (e) => {
|
|
183
183
|
o.store.state.isDirty && e.preventDefault();
|
|
184
184
|
};
|
|
185
|
-
if (
|
|
186
|
-
window.addEventListener("beforeunload",
|
|
187
|
-
}),
|
|
188
|
-
window.removeEventListener("beforeunload",
|
|
185
|
+
if (D(u), G(() => {
|
|
186
|
+
window.addEventListener("beforeunload", u), window.addEventListener("blur", E), s?.preventWindowExit && s.preventWindowExit !== "nope" && window.addEventListener("beforeunload", k);
|
|
187
|
+
}), Z(() => {
|
|
188
|
+
window.removeEventListener("beforeunload", u), window.removeEventListener("blur", E), s?.preventWindowExit && s.preventWindowExit !== "nope" && window.removeEventListener("beforeunload", k);
|
|
189
189
|
}), s?.preventWindowExit === "prevent-and-reset") {
|
|
190
190
|
const e = o.useStore((t) => t.isSubmitting), r = o.useStore((t) => t.submissionAttempts), c = o.useStore((t) => t.canSubmit), n = o.useStore((t) => t.values);
|
|
191
|
-
|
|
192
|
-
_ && !t &&
|
|
191
|
+
R([e, r], ([t, S], [_]) => {
|
|
192
|
+
_ && !t && S > 0 && c.value && o.reset(n.value);
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
const I = (e) => d.currentSpan.pipe(
|
|
196
196
|
d.option,
|
|
197
197
|
d.flatMap(
|
|
198
|
-
(r) => d.promise(() => o.handleSubmit(
|
|
198
|
+
(r) => d.promise(() => o.handleSubmit(P.isSome(r) ? { currentSpan: r.value, ...e } : e))
|
|
199
199
|
)
|
|
200
|
-
),
|
|
200
|
+
), q = (e) => e?.checkErrors ? I(e?.meta).pipe(d.flatMap(d.fnUntraced(function* () {
|
|
201
201
|
const r = o.getAllErrors();
|
|
202
202
|
if (Object.keys(r.fields).length || r.form.errors.length)
|
|
203
|
-
return yield* new
|
|
204
|
-
}))) : I(e?.meta),
|
|
203
|
+
return yield* new ie({ form: r.form, fields: r.fields });
|
|
204
|
+
}))) : I(e?.meta), B = o.handleSubmit, L = Q(/* @__PURE__ */ new Map()), y = Object.assign(o, {
|
|
205
205
|
i18nNamespace: s?.i18nNamespace,
|
|
206
206
|
ignorePreventCloseEvents: s?.ignorePreventCloseEvents,
|
|
207
207
|
meta: a,
|
|
208
|
-
unionMeta:
|
|
209
|
-
|
|
210
|
-
clear: b,
|
|
208
|
+
unionMeta: g,
|
|
209
|
+
clear: O,
|
|
211
210
|
handleSubmit: (e) => {
|
|
212
|
-
const r =
|
|
213
|
-
return
|
|
211
|
+
const r = H.getSpan(U.active());
|
|
212
|
+
return B({ currentSpan: r, ...e });
|
|
214
213
|
},
|
|
215
214
|
// /** @experimental */
|
|
216
|
-
handleSubmitEffect:
|
|
215
|
+
handleSubmitEffect: q,
|
|
217
216
|
registerField: (e) => {
|
|
218
|
-
|
|
219
|
-
j.value.set(r.name, { label: r.label, id: r.id });
|
|
220
|
-
}, { immediate: !0 }), R(() => {
|
|
221
|
-
j.value.get(e.value.name)?.id === e.value.id && j.value.delete(e.value.name);
|
|
222
|
-
});
|
|
217
|
+
R(e, (r) => L.value.set(r.name, { label: r.label, id: r.id }), { immediate: !0 }), D(() => L.value.delete(e.value.name));
|
|
223
218
|
}
|
|
224
|
-
}),
|
|
225
|
-
return Object.assign(
|
|
219
|
+
}), V = { form: y, fieldMap: L };
|
|
220
|
+
return Object.assign(y, {
|
|
226
221
|
// Type-level properties for performance optimization (not used at runtime)
|
|
227
222
|
_paths: void 0,
|
|
228
223
|
_keys: void 0,
|
|
229
224
|
_schema: i,
|
|
230
|
-
errorContext:
|
|
231
|
-
Form: M(
|
|
232
|
-
Input: M(
|
|
233
|
-
TaggedUnion: M(
|
|
225
|
+
errorContext: V,
|
|
226
|
+
Form: M(y)(oe),
|
|
227
|
+
Input: M(y)(s?.input ?? se),
|
|
228
|
+
TaggedUnion: M(y)(ne),
|
|
234
229
|
Field: o.Field,
|
|
235
|
-
Errors:
|
|
236
|
-
Array: M(
|
|
237
|
-
AutoGen: M(
|
|
230
|
+
Errors: ce(V)(ee),
|
|
231
|
+
Array: M(y)(Y),
|
|
232
|
+
AutoGen: M(y)(C)
|
|
238
233
|
});
|
|
239
234
|
};
|
|
240
235
|
export {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
236
|
+
ie as FormErrors,
|
|
237
|
+
ae as useErrorLabel,
|
|
238
|
+
Me as useOmegaForm
|
|
244
239
|
};
|