@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.
- package/dist/types/components/OmegaForm/OmegaFormStuff.d.ts +1 -1
- package/dist/types/components/OmegaForm/useOmegaForm.d.ts +3 -2
- package/dist/vue-components.es9.js +90 -78
- package/package.json +2 -2
- package/src/components/OmegaForm/OmegaFormStuff.ts +1 -1
- package/src/components/OmegaForm/useOmegaForm.ts +23 -3
|
@@ -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
|
-
|
|
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
|
|
2
|
-
import { S as
|
|
3
|
-
import { runtimeFiberAsPromise as
|
|
4
|
-
import { isObject as
|
|
5
|
-
import { computed as
|
|
6
|
-
import
|
|
7
|
-
import { generateMetaFromSchema as
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
13
|
-
const e = window.location.pathname, r = Object.keys(
|
|
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
|
-
}),
|
|
15
|
+
}), E = () => {
|
|
16
16
|
const e = new URLSearchParams(window.location.search);
|
|
17
|
-
e.delete(
|
|
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
|
|
22
|
-
for (const
|
|
23
|
-
r[
|
|
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
|
|
27
|
-
if (
|
|
28
|
-
return
|
|
26
|
+
const P = b(() => {
|
|
27
|
+
if (s?.defaultValues && !a?.persistency?.overrideDefaultValues)
|
|
28
|
+
return s?.defaultValues;
|
|
29
29
|
let e;
|
|
30
|
-
const r =
|
|
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
|
|
35
|
-
|
|
36
|
-
} catch (
|
|
37
|
-
console.error(
|
|
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
|
|
44
|
-
if (
|
|
43
|
+
const t = r.policies.includes("local") ? localStorage : sessionStorage;
|
|
44
|
+
if (t)
|
|
45
45
|
try {
|
|
46
|
-
const
|
|
47
|
-
|
|
46
|
+
const i = JSON.parse(
|
|
47
|
+
t.getItem(l.value) || "{}"
|
|
48
48
|
);
|
|
49
|
-
|
|
50
|
-
} catch (
|
|
51
|
-
console.error(
|
|
49
|
+
t.removeItem(l.value), e = i;
|
|
50
|
+
} catch (i) {
|
|
51
|
+
console.error(i);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
if (e ??= {},
|
|
54
|
+
if (e ??= {}, s?.defaultValues == null)
|
|
55
55
|
return e;
|
|
56
56
|
{
|
|
57
|
-
const
|
|
58
|
-
return
|
|
57
|
+
const t = s?.defaultValues;
|
|
58
|
+
return S(t, e);
|
|
59
59
|
}
|
|
60
|
-
}),
|
|
61
|
-
...
|
|
60
|
+
}), c = U({
|
|
61
|
+
...s,
|
|
62
62
|
validators: {
|
|
63
|
-
onSubmit:
|
|
64
|
-
...
|
|
63
|
+
onSubmit: g,
|
|
64
|
+
...s?.validators || {}
|
|
65
65
|
},
|
|
66
|
-
onSubmit:
|
|
67
|
-
const
|
|
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:
|
|
70
|
+
value: t
|
|
71
71
|
});
|
|
72
|
-
return
|
|
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:
|
|
75
|
-
}),
|
|
76
|
-
Object.keys(
|
|
77
|
-
|
|
79
|
+
defaultValues: P.value
|
|
80
|
+
}), j = () => {
|
|
81
|
+
Object.keys(u).forEach((e) => {
|
|
82
|
+
c.setFieldValue(e, void 0);
|
|
78
83
|
});
|
|
79
|
-
},
|
|
80
|
-
const
|
|
81
|
-
return
|
|
82
|
-
}, {}),
|
|
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
|
|
90
|
+
return w(e.keys);
|
|
86
91
|
if (Array.isArray(e.banKeys)) {
|
|
87
|
-
const r = Object.keys(
|
|
88
|
-
return
|
|
92
|
+
const r = Object.keys(u).filter((t) => e.banKeys?.includes(t));
|
|
93
|
+
return w(r);
|
|
89
94
|
}
|
|
90
|
-
return
|
|
95
|
+
return c.store.state.values;
|
|
91
96
|
}
|
|
92
|
-
},
|
|
93
|
-
const e =
|
|
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
|
|
98
|
-
return r.setItem(
|
|
102
|
+
const t = h(e);
|
|
103
|
+
return r.setItem(l.value, JSON.stringify(t));
|
|
99
104
|
}
|
|
100
105
|
}, y = () => {
|
|
101
|
-
const e =
|
|
106
|
+
const e = a?.persistency;
|
|
102
107
|
if (!(!e?.policies || e.policies.length === 0) && e.policies.includes("querystring")) {
|
|
103
|
-
const r =
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
|
|
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
|
-
|
|
110
|
-
window.addEventListener("beforeunload",
|
|
111
|
-
}),
|
|
112
|
-
window.removeEventListener("beforeunload",
|
|
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
|
|
115
|
-
meta:
|
|
116
|
-
filterItems:
|
|
117
|
-
clear:
|
|
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
|
|
120
|
-
Input:
|
|
121
|
-
Field:
|
|
131
|
+
return D(q, v), Object.assign(v, {
|
|
132
|
+
Input: J,
|
|
133
|
+
Field: c.Field
|
|
122
134
|
});
|
|
123
135
|
};
|
|
124
136
|
export {
|
|
125
|
-
|
|
126
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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)
|