@effect-app/vue-components 0.3.0 → 0.3.2
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/useOmegaForm.d.ts +6 -2
- package/dist/vue-components.es11.js +1 -1
- package/dist/vue-components.es15.js +5 -4
- package/dist/vue-components.es16.js +2 -93
- package/dist/vue-components.es17.js +93 -11
- package/dist/vue-components.es18.js +11 -2
- package/dist/vue-components.es19.js +2 -115
- package/dist/vue-components.es20.js +117 -0
- package/dist/{vue-components.es21.js → vue-components.es22.js} +1 -1
- package/dist/vue-components.es5.js +113 -79
- package/dist/vue-components.es8.js +1 -1
- package/package.json +1 -1
- package/src/components/OmegaForm/useOmegaForm.ts +150 -64
- package/src/stories/OmegaForm/ComplexForm.vue +1 -1
- package/src/stories/OmegaForm/PersistencyForm.vue +1 -8
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S } from "effect-app";
|
|
1
|
+
import { type Record, S } from "effect-app";
|
|
2
2
|
import { type NestedKeyOf, type FilterItems, type FormProps, type MetaRecord, type OmegaFormApi } from "./OmegaFormStuff";
|
|
3
3
|
type keysRule<T> = {
|
|
4
4
|
keys?: NestedKeyOf<T>[];
|
|
@@ -9,7 +9,11 @@ type keysRule<T> = {
|
|
|
9
9
|
};
|
|
10
10
|
export type OmegaConfig<T> = {
|
|
11
11
|
persistency?: {
|
|
12
|
-
|
|
12
|
+
/** Order of importance:
|
|
13
|
+
* - "querystring": Highest priority when persisting
|
|
14
|
+
* - "local" and then "session": Lower priority storage options
|
|
15
|
+
*/
|
|
16
|
+
policies?: ("local" | "session" | "querystring")[];
|
|
13
17
|
overrideDefaultValues?: boolean;
|
|
14
18
|
id?: string;
|
|
15
19
|
} & keysRule<T>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineComponent as d, watch as b, createElementBlock as g, openBlock as S, withModifiers as v, unref as n, createElementVNode as h, renderSlot as O } from "vue";
|
|
2
2
|
import { useStore as i } from "@tanstack/vue-form";
|
|
3
|
-
import { getOmegaStore as M } from "./vue-components.
|
|
3
|
+
import { getOmegaStore as M } from "./vue-components.es18.js";
|
|
4
4
|
import { provideOmegaErrors as y } from "./vue-components.es4.js";
|
|
5
5
|
import { useOmegaForm as E } from "./vue-components.es5.js";
|
|
6
6
|
const w = ["disabled"], A = /* @__PURE__ */ d({
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { isFunction as c } from "./vue-components.es16.js";
|
|
2
|
+
const s = c, t = (o) => typeof o == "object" && o !== null, i = (o) => t(o) || s(o);
|
|
2
3
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
s as isFunction,
|
|
5
|
+
i as isObject,
|
|
6
|
+
t as isRecordOrArray
|
|
6
7
|
};
|
|
@@ -1,95 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { defineComponent as B, getCurrentInstance as L, useId as P, computed as n, watch as x, onMounted as _, ref as S, watchEffect as A, renderSlot as D, normalizeProps as F, guardReactiveProps as M, createElementVNode as N, createBlock as R, createCommentVNode as T, unref as U, openBlock as z, mergeProps as j } from "vue";
|
|
3
|
-
import { useStore as G } from "@tanstack/vue-form";
|
|
4
|
-
import { useOmegaErrors as H } from "./vue-components.es4.js";
|
|
5
|
-
import J from "./vue-components.es19.js";
|
|
6
|
-
|
|
7
|
-
const Z = /* @__PURE__ */ B({
|
|
8
|
-
inheritAttrs: !1,
|
|
9
|
-
__name: "OmegaInternalInput",
|
|
10
|
-
props: {
|
|
11
|
-
field: {},
|
|
12
|
-
meta: {},
|
|
13
|
-
label: {},
|
|
14
|
-
options: {},
|
|
15
|
-
type: {},
|
|
16
|
-
validators: {}
|
|
17
|
-
},
|
|
18
|
-
setup(q) {
|
|
19
|
-
const e = q, o = L(), C = o == null ? void 0 : o.appContext.components.VTextField, u = P(), s = e.field, a = G(s.store, (t) => t), f = n(() => {
|
|
20
|
-
var t, r;
|
|
21
|
-
return e.type ? e.type : ((t = e.meta) == null ? void 0 : t.type) === "string" ? e.meta.format === "email" ? "email" : "string" : ((r = e.meta) == null ? void 0 : r.type) || "unknown";
|
|
22
|
-
}), l = n(() => a.value.value), d = n(
|
|
23
|
-
() => (
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
a.value.meta.errors.map((t) => t == null ? void 0 : t.message).filter(Boolean)
|
|
26
|
-
)
|
|
27
|
-
);
|
|
28
|
-
x(
|
|
29
|
-
() => [!!l.value],
|
|
30
|
-
() => {
|
|
31
|
-
var t, r;
|
|
32
|
-
d.value.length && !l.value && !((t = e.meta) != null && t.required) && s.setValue(
|
|
33
|
-
((r = e.meta) == null ? void 0 : r.nullableOrUndefined) === "undefined" ? void 0 : null
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
), _(() => {
|
|
37
|
-
var t, r;
|
|
38
|
-
!l.value && !((t = e.meta) != null && t.required) && ((r = e.meta) == null ? void 0 : r.nullableOrUndefined) === "null" && s.setValue(null);
|
|
39
|
-
});
|
|
40
|
-
const { addError: I, removeError: O, showErrors: $, showErrorsOn: k } = H(), i = S(!1);
|
|
41
|
-
A(() => {
|
|
42
|
-
($.value || k === "onChange") && (i.value = !0);
|
|
43
|
-
});
|
|
44
|
-
const m = () => {
|
|
45
|
-
i.value = !0;
|
|
46
|
-
};
|
|
47
|
-
_(() => {
|
|
48
|
-
l.value && m();
|
|
49
|
-
});
|
|
50
|
-
const v = n(() => !i.value && f.value !== "select" ? [] : d.value);
|
|
51
|
-
x(
|
|
52
|
-
() => a.value.meta.errors,
|
|
53
|
-
() => {
|
|
54
|
-
a.value.meta.errors.length ? I({
|
|
55
|
-
inputId: u,
|
|
56
|
-
errors: a.value.meta.errors.map((t) => t.message).filter(Boolean),
|
|
57
|
-
label: e.label
|
|
58
|
-
}) : O(u);
|
|
59
|
-
}
|
|
60
|
-
);
|
|
61
|
-
const p = n(() => {
|
|
62
|
-
var t, r, c, g, y, h, b, E, V, w;
|
|
63
|
-
return {
|
|
64
|
-
id: u,
|
|
65
|
-
required: (t = e.meta) == null ? void 0 : t.required,
|
|
66
|
-
minLength: ((r = e.meta) == null ? void 0 : r.type) === "string" && ((c = e.meta) == null ? void 0 : c.minLength),
|
|
67
|
-
maxLength: ((g = e.meta) == null ? void 0 : g.type) === "string" && ((y = e.meta) == null ? void 0 : y.maxLength),
|
|
68
|
-
max: ((h = e.meta) == null ? void 0 : h.type) === "number" && ((b = e.meta) == null ? void 0 : b.maximum),
|
|
69
|
-
min: ((E = e.meta) == null ? void 0 : E.type) === "number" && ((V = e.meta) == null ? void 0 : V.minimum),
|
|
70
|
-
name: e.field.name,
|
|
71
|
-
modelValue: e.field.state.value,
|
|
72
|
-
errorMessages: v.value,
|
|
73
|
-
error: !!v.value.length,
|
|
74
|
-
field: e.field,
|
|
75
|
-
setRealDirty: m,
|
|
76
|
-
type: f.value,
|
|
77
|
-
label: `${e.label}${(w = e.meta) != null && w.required ? " *" : ""}`,
|
|
78
|
-
options: e.options
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
return (t, r) => D(t.$slots, "default", F(M(p.value)), () => [
|
|
82
|
-
N("div", { onFocusout: m }, [
|
|
83
|
-
U(C) ? (z(), R(J, j({
|
|
84
|
-
key: 0,
|
|
85
|
-
"input-props": p.value
|
|
86
|
-
}, t.$attrs, {
|
|
87
|
-
"vuetify-value": p.value.field.state.value
|
|
88
|
-
}), null, 16, ["input-props", "vuetify-value"])) : T("", !0)
|
|
89
|
-
], 32)
|
|
90
|
-
]);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
1
|
+
const o = (n) => typeof n == "function";
|
|
93
2
|
export {
|
|
94
|
-
|
|
3
|
+
o as isFunction
|
|
95
4
|
};
|
|
@@ -1,13 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
import { computed as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
(function(){"use strict";try{if(typeof document<"u"){var n=document.createElement("style");if(n.appendChild(document.createTextNode(".omega-input .v-input__details:has(.v-messages:empty){grid-template-rows:0fr;transition:all .2s}.omega-input .v-messages:empty{min-height:0}.omega-input .v-input__details:has(.v-messages){transition:all .2s;overflow:hidden;min-height:0;display:grid;grid-template-rows:1fr}.omega-input .v-messages{transition:all .2s}.omega-input .v-messages>*{transition-duration:0s!important}.omega-input [role=alert]:has(.v-messages:empty){padding:0}.omega-input .v-btn{cursor:pointer;width:auto;-webkit-appearance:none;-moz-appearance:none;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),document.head.appendChild(n),window.customElements){const e=window.customElements.define;window.customElements.define=function(o,t){const a=t.prototype.connectedCallback;return t.prototype.connectedCallback=function(){if(a&&a.call(this),this.shadowRoot){const i=document.createElement("style");i.appendChild(document.createTextNode(".omega-input .v-input__details:has(.v-messages:empty){grid-template-rows:0fr;transition:all .2s}.omega-input .v-messages:empty{min-height:0}.omega-input .v-input__details:has(.v-messages){transition:all .2s;overflow:hidden;min-height:0;display:grid;grid-template-rows:1fr}.omega-input .v-messages{transition:all .2s}.omega-input .v-messages>*{transition-duration:0s!important}.omega-input [role=alert]:has(.v-messages:empty){padding:0}.omega-input .v-btn{cursor:pointer;width:auto;-webkit-appearance:none;-moz-appearance:none;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),this.shadowRoot.appendChild(i)}},e.call(window.customElements,o,t)}}}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
|
|
2
|
+
import { defineComponent as B, getCurrentInstance as L, useId as P, computed as n, watch as x, onMounted as _, ref as S, watchEffect as A, renderSlot as D, normalizeProps as F, guardReactiveProps as M, createElementVNode as N, createBlock as R, createCommentVNode as T, unref as U, openBlock as z, mergeProps as j } from "vue";
|
|
3
|
+
import { useStore as G } from "@tanstack/vue-form";
|
|
4
|
+
import { useOmegaErrors as H } from "./vue-components.es4.js";
|
|
5
|
+
import J from "./vue-components.es20.js";
|
|
6
|
+
|
|
7
|
+
const Z = /* @__PURE__ */ B({
|
|
8
|
+
inheritAttrs: !1,
|
|
9
|
+
__name: "OmegaInternalInput",
|
|
10
|
+
props: {
|
|
11
|
+
field: {},
|
|
12
|
+
meta: {},
|
|
13
|
+
label: {},
|
|
14
|
+
options: {},
|
|
15
|
+
type: {},
|
|
16
|
+
validators: {}
|
|
17
|
+
},
|
|
18
|
+
setup(q) {
|
|
19
|
+
const e = q, o = L(), C = o == null ? void 0 : o.appContext.components.VTextField, u = P(), s = e.field, a = G(s.store, (t) => t), f = n(() => {
|
|
20
|
+
var t, r;
|
|
21
|
+
return e.type ? e.type : ((t = e.meta) == null ? void 0 : t.type) === "string" ? e.meta.format === "email" ? "email" : "string" : ((r = e.meta) == null ? void 0 : r.type) || "unknown";
|
|
22
|
+
}), l = n(() => a.value.value), d = n(
|
|
23
|
+
() => (
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
a.value.meta.errors.map((t) => t == null ? void 0 : t.message).filter(Boolean)
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
x(
|
|
29
|
+
() => [!!l.value],
|
|
30
|
+
() => {
|
|
31
|
+
var t, r;
|
|
32
|
+
d.value.length && !l.value && !((t = e.meta) != null && t.required) && s.setValue(
|
|
33
|
+
((r = e.meta) == null ? void 0 : r.nullableOrUndefined) === "undefined" ? void 0 : null
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
), _(() => {
|
|
37
|
+
var t, r;
|
|
38
|
+
!l.value && !((t = e.meta) != null && t.required) && ((r = e.meta) == null ? void 0 : r.nullableOrUndefined) === "null" && s.setValue(null);
|
|
39
|
+
});
|
|
40
|
+
const { addError: I, removeError: O, showErrors: $, showErrorsOn: k } = H(), i = S(!1);
|
|
41
|
+
A(() => {
|
|
42
|
+
($.value || k === "onChange") && (i.value = !0);
|
|
43
|
+
});
|
|
44
|
+
const m = () => {
|
|
45
|
+
i.value = !0;
|
|
46
|
+
};
|
|
47
|
+
_(() => {
|
|
48
|
+
l.value && m();
|
|
49
|
+
});
|
|
50
|
+
const v = n(() => !i.value && f.value !== "select" ? [] : d.value);
|
|
51
|
+
x(
|
|
52
|
+
() => a.value.meta.errors,
|
|
53
|
+
() => {
|
|
54
|
+
a.value.meta.errors.length ? I({
|
|
55
|
+
inputId: u,
|
|
56
|
+
errors: a.value.meta.errors.map((t) => t.message).filter(Boolean),
|
|
57
|
+
label: e.label
|
|
58
|
+
}) : O(u);
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
const p = n(() => {
|
|
62
|
+
var t, r, c, g, y, h, b, E, V, w;
|
|
63
|
+
return {
|
|
64
|
+
id: u,
|
|
65
|
+
required: (t = e.meta) == null ? void 0 : t.required,
|
|
66
|
+
minLength: ((r = e.meta) == null ? void 0 : r.type) === "string" && ((c = e.meta) == null ? void 0 : c.minLength),
|
|
67
|
+
maxLength: ((g = e.meta) == null ? void 0 : g.type) === "string" && ((y = e.meta) == null ? void 0 : y.maxLength),
|
|
68
|
+
max: ((h = e.meta) == null ? void 0 : h.type) === "number" && ((b = e.meta) == null ? void 0 : b.maximum),
|
|
69
|
+
min: ((E = e.meta) == null ? void 0 : E.type) === "number" && ((V = e.meta) == null ? void 0 : V.minimum),
|
|
70
|
+
name: e.field.name,
|
|
71
|
+
modelValue: e.field.state.value,
|
|
72
|
+
errorMessages: v.value,
|
|
73
|
+
error: !!v.value.length,
|
|
74
|
+
field: e.field,
|
|
75
|
+
setRealDirty: m,
|
|
76
|
+
type: f.value,
|
|
77
|
+
label: `${e.label}${(w = e.meta) != null && w.required ? " *" : ""}`,
|
|
78
|
+
options: e.options
|
|
79
|
+
};
|
|
80
|
+
});
|
|
81
|
+
return (t, r) => D(t.$slots, "default", F(M(p.value)), () => [
|
|
82
|
+
N("div", { onFocusout: m }, [
|
|
83
|
+
U(C) ? (z(), R(J, j({
|
|
84
|
+
key: 0,
|
|
85
|
+
"input-props": p.value
|
|
86
|
+
}, t.$attrs, {
|
|
87
|
+
"vuetify-value": p.value.field.state.value
|
|
88
|
+
}), null, 16, ["input-props", "vuetify-value"])) : T("", !0)
|
|
89
|
+
], 32)
|
|
90
|
+
]);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
11
93
|
export {
|
|
12
|
-
|
|
94
|
+
Z as default
|
|
13
95
|
};
|
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useStore as u } from "@tanstack/vue-form";
|
|
2
|
+
import { computed as f } from "vue";
|
|
3
|
+
function c(o, t) {
|
|
4
|
+
return f(() => t ? u(o.store, (n) => {
|
|
5
|
+
const r = {};
|
|
6
|
+
for (const e of t)
|
|
7
|
+
r[e] = n[e];
|
|
8
|
+
return r;
|
|
9
|
+
}).value : {});
|
|
10
|
+
}
|
|
2
11
|
export {
|
|
3
|
-
|
|
12
|
+
c as getOmegaStore
|
|
4
13
|
};
|
|
@@ -1,117 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
const b = /* @__PURE__ */ P({
|
|
3
|
-
inheritAttrs: !1,
|
|
4
|
-
__name: "OmegaInputVuetify",
|
|
5
|
-
props: {
|
|
6
|
-
inputProps: {},
|
|
7
|
-
vuetifyValue: {}
|
|
8
|
-
},
|
|
9
|
-
emits: ["focus", "blur"],
|
|
10
|
-
setup(y) {
|
|
11
|
-
return (e, r) => {
|
|
12
|
-
const a = u("v-checkbox"), i = u("v-text-field"), t = u("v-textarea"), m = u("v-select"), d = u("v-autocomplete");
|
|
13
|
-
return o(), g("div", {
|
|
14
|
-
class: "omega-input",
|
|
15
|
-
onFocusout: r[4] || (r[4] = (p) => e.$emit("blur", p)),
|
|
16
|
-
onFocusin: r[5] || (r[5] = (p) => e.$emit("focus", p))
|
|
17
|
-
}, [
|
|
18
|
-
e.inputProps.type === "boolean" ? (o(), n(a, s({
|
|
19
|
-
key: 0,
|
|
20
|
-
id: e.inputProps.id,
|
|
21
|
-
name: e.inputProps.name,
|
|
22
|
-
label: e.inputProps.label,
|
|
23
|
-
"error-messages": e.inputProps.errorMessages,
|
|
24
|
-
error: e.inputProps.error,
|
|
25
|
-
ripple: ""
|
|
26
|
-
}, e.$attrs, {
|
|
27
|
-
"model-value": e.vuetifyValue,
|
|
28
|
-
onChange: r[0] || (r[0] = (p) => e.inputProps.field.handleChange(p.target.checked))
|
|
29
|
-
}), null, 16, ["id", "name", "label", "error-messages", "error", "model-value"])) : l("", !0),
|
|
30
|
-
e.inputProps.type === "email" || e.inputProps.type === "string" ? (o(), n(i, s({
|
|
31
|
-
key: 1,
|
|
32
|
-
id: e.inputProps.id,
|
|
33
|
-
required: e.inputProps.required,
|
|
34
|
-
"min-length": e.inputProps.minLength,
|
|
35
|
-
"max-length": e.inputProps.maxLength,
|
|
36
|
-
type: e.inputProps.type,
|
|
37
|
-
name: e.inputProps.name,
|
|
38
|
-
label: e.inputProps.label,
|
|
39
|
-
"error-messages": e.inputProps.errorMessages,
|
|
40
|
-
error: e.inputProps.error
|
|
41
|
-
}, e.$attrs, {
|
|
42
|
-
"model-value": e.vuetifyValue,
|
|
43
|
-
"onUpdate:modelValue": e.inputProps.field.handleChange
|
|
44
|
-
}), null, 16, ["id", "required", "min-length", "max-length", "type", "name", "label", "error-messages", "error", "model-value", "onUpdate:modelValue"])) : l("", !0),
|
|
45
|
-
e.inputProps.type === "text" ? (o(), n(t, s({
|
|
46
|
-
key: 2,
|
|
47
|
-
id: e.inputProps.id,
|
|
48
|
-
required: e.inputProps.required,
|
|
49
|
-
"min-length": e.inputProps.minLength,
|
|
50
|
-
"max-length": e.inputProps.maxLength,
|
|
51
|
-
type: e.inputProps.type,
|
|
52
|
-
name: e.inputProps.name,
|
|
53
|
-
label: e.inputProps.label,
|
|
54
|
-
"error-messages": e.inputProps.errorMessages,
|
|
55
|
-
error: e.inputProps.error
|
|
56
|
-
}, e.$attrs, {
|
|
57
|
-
"model-value": e.vuetifyValue,
|
|
58
|
-
"onUpdate:modelValue": e.inputProps.field.handleChange
|
|
59
|
-
}), null, 16, ["id", "required", "min-length", "max-length", "type", "name", "label", "error-messages", "error", "model-value", "onUpdate:modelValue"])) : l("", !0),
|
|
60
|
-
e.inputProps.type === "number" ? (o(), n(i, s({
|
|
61
|
-
key: 3,
|
|
62
|
-
id: e.inputProps.id,
|
|
63
|
-
required: e.inputProps.required,
|
|
64
|
-
min: e.inputProps.min,
|
|
65
|
-
max: e.inputProps.max,
|
|
66
|
-
type: e.inputProps.type,
|
|
67
|
-
name: e.inputProps.name,
|
|
68
|
-
label: e.inputProps.label,
|
|
69
|
-
"error-messages": e.inputProps.errorMessages,
|
|
70
|
-
error: e.inputProps.error
|
|
71
|
-
}, e.$attrs, {
|
|
72
|
-
"model-value": e.vuetifyValue,
|
|
73
|
-
"onUpdate:modelValue": r[1] || (r[1] = (p) => {
|
|
74
|
-
e.inputProps.field.handleChange(Number(p));
|
|
75
|
-
})
|
|
76
|
-
}), null, 16, ["id", "required", "min", "max", "type", "name", "label", "error-messages", "error", "model-value"])) : l("", !0),
|
|
77
|
-
e.inputProps.type === "select" || e.inputProps.type === "multiple" ? (o(), n(m, s({
|
|
78
|
-
key: 4,
|
|
79
|
-
id: e.inputProps.id,
|
|
80
|
-
clearable: e.inputProps.type === "select",
|
|
81
|
-
required: e.inputProps.required,
|
|
82
|
-
multiple: e.inputProps.type === "multiple",
|
|
83
|
-
chips: e.inputProps.type === "multiple",
|
|
84
|
-
name: e.inputProps.name,
|
|
85
|
-
label: e.inputProps.label,
|
|
86
|
-
items: e.inputProps.options,
|
|
87
|
-
"error-messages": e.inputProps.errorMessages,
|
|
88
|
-
error: e.inputProps.error
|
|
89
|
-
}, e.$attrs, {
|
|
90
|
-
"model-value": e.vuetifyValue,
|
|
91
|
-
onClear: r[2] || (r[2] = (p) => e.inputProps.field.handleChange(void 0)),
|
|
92
|
-
"onUpdate:modelValue": e.inputProps.field.handleChange
|
|
93
|
-
}), null, 16, ["id", "clearable", "required", "multiple", "chips", "name", "label", "items", "error-messages", "error", "model-value", "onUpdate:modelValue"])) : l("", !0),
|
|
94
|
-
e.inputProps.type === "autocomplete" || e.inputProps.type === "autocompletemultiple" ? (o(), n(d, s({
|
|
95
|
-
key: 5,
|
|
96
|
-
id: e.inputProps.id,
|
|
97
|
-
clearable: e.inputProps.type === "autocomplete",
|
|
98
|
-
multiple: e.inputProps.type === "autocompletemultiple",
|
|
99
|
-
required: e.inputProps.required,
|
|
100
|
-
name: e.inputProps.name,
|
|
101
|
-
label: e.inputProps.label,
|
|
102
|
-
items: e.inputProps.options,
|
|
103
|
-
"error-messages": e.inputProps.errorMessages,
|
|
104
|
-
error: e.inputProps.error,
|
|
105
|
-
chips: e.inputProps.type === "autocompletemultiple"
|
|
106
|
-
}, e.$attrs, {
|
|
107
|
-
"model-value": e.vuetifyValue,
|
|
108
|
-
onClear: r[3] || (r[3] = (p) => e.inputProps.field.handleChange(void 0)),
|
|
109
|
-
"onUpdate:modelValue": e.inputProps.field.handleChange
|
|
110
|
-
}), null, 16, ["id", "clearable", "multiple", "required", "name", "label", "items", "error-messages", "error", "chips", "model-value", "onUpdate:modelValue"])) : l("", !0)
|
|
111
|
-
], 32);
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
});
|
|
1
|
+
import f from "./vue-components.es17.js";
|
|
115
2
|
export {
|
|
116
|
-
|
|
3
|
+
f as default
|
|
117
4
|
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { defineComponent as P, resolveComponent as u, createElementBlock as g, openBlock as o, createBlock as n, createCommentVNode as l, mergeProps as s } from "vue";
|
|
2
|
+
const b = /* @__PURE__ */ P({
|
|
3
|
+
inheritAttrs: !1,
|
|
4
|
+
__name: "OmegaInputVuetify",
|
|
5
|
+
props: {
|
|
6
|
+
inputProps: {},
|
|
7
|
+
vuetifyValue: {}
|
|
8
|
+
},
|
|
9
|
+
emits: ["focus", "blur"],
|
|
10
|
+
setup(y) {
|
|
11
|
+
return (e, r) => {
|
|
12
|
+
const a = u("v-checkbox"), i = u("v-text-field"), t = u("v-textarea"), m = u("v-select"), d = u("v-autocomplete");
|
|
13
|
+
return o(), g("div", {
|
|
14
|
+
class: "omega-input",
|
|
15
|
+
onFocusout: r[4] || (r[4] = (p) => e.$emit("blur", p)),
|
|
16
|
+
onFocusin: r[5] || (r[5] = (p) => e.$emit("focus", p))
|
|
17
|
+
}, [
|
|
18
|
+
e.inputProps.type === "boolean" ? (o(), n(a, s({
|
|
19
|
+
key: 0,
|
|
20
|
+
id: e.inputProps.id,
|
|
21
|
+
name: e.inputProps.name,
|
|
22
|
+
label: e.inputProps.label,
|
|
23
|
+
"error-messages": e.inputProps.errorMessages,
|
|
24
|
+
error: e.inputProps.error,
|
|
25
|
+
ripple: ""
|
|
26
|
+
}, e.$attrs, {
|
|
27
|
+
"model-value": e.vuetifyValue,
|
|
28
|
+
onChange: r[0] || (r[0] = (p) => e.inputProps.field.handleChange(p.target.checked))
|
|
29
|
+
}), null, 16, ["id", "name", "label", "error-messages", "error", "model-value"])) : l("", !0),
|
|
30
|
+
e.inputProps.type === "email" || e.inputProps.type === "string" ? (o(), n(i, s({
|
|
31
|
+
key: 1,
|
|
32
|
+
id: e.inputProps.id,
|
|
33
|
+
required: e.inputProps.required,
|
|
34
|
+
"min-length": e.inputProps.minLength,
|
|
35
|
+
"max-length": e.inputProps.maxLength,
|
|
36
|
+
type: e.inputProps.type,
|
|
37
|
+
name: e.inputProps.name,
|
|
38
|
+
label: e.inputProps.label,
|
|
39
|
+
"error-messages": e.inputProps.errorMessages,
|
|
40
|
+
error: e.inputProps.error
|
|
41
|
+
}, e.$attrs, {
|
|
42
|
+
"model-value": e.vuetifyValue,
|
|
43
|
+
"onUpdate:modelValue": e.inputProps.field.handleChange
|
|
44
|
+
}), null, 16, ["id", "required", "min-length", "max-length", "type", "name", "label", "error-messages", "error", "model-value", "onUpdate:modelValue"])) : l("", !0),
|
|
45
|
+
e.inputProps.type === "text" ? (o(), n(t, s({
|
|
46
|
+
key: 2,
|
|
47
|
+
id: e.inputProps.id,
|
|
48
|
+
required: e.inputProps.required,
|
|
49
|
+
"min-length": e.inputProps.minLength,
|
|
50
|
+
"max-length": e.inputProps.maxLength,
|
|
51
|
+
type: e.inputProps.type,
|
|
52
|
+
name: e.inputProps.name,
|
|
53
|
+
label: e.inputProps.label,
|
|
54
|
+
"error-messages": e.inputProps.errorMessages,
|
|
55
|
+
error: e.inputProps.error
|
|
56
|
+
}, e.$attrs, {
|
|
57
|
+
"model-value": e.vuetifyValue,
|
|
58
|
+
"onUpdate:modelValue": e.inputProps.field.handleChange
|
|
59
|
+
}), null, 16, ["id", "required", "min-length", "max-length", "type", "name", "label", "error-messages", "error", "model-value", "onUpdate:modelValue"])) : l("", !0),
|
|
60
|
+
e.inputProps.type === "number" ? (o(), n(i, s({
|
|
61
|
+
key: 3,
|
|
62
|
+
id: e.inputProps.id,
|
|
63
|
+
required: e.inputProps.required,
|
|
64
|
+
min: e.inputProps.min,
|
|
65
|
+
max: e.inputProps.max,
|
|
66
|
+
type: e.inputProps.type,
|
|
67
|
+
name: e.inputProps.name,
|
|
68
|
+
label: e.inputProps.label,
|
|
69
|
+
"error-messages": e.inputProps.errorMessages,
|
|
70
|
+
error: e.inputProps.error
|
|
71
|
+
}, e.$attrs, {
|
|
72
|
+
"model-value": e.vuetifyValue,
|
|
73
|
+
"onUpdate:modelValue": r[1] || (r[1] = (p) => {
|
|
74
|
+
e.inputProps.field.handleChange(Number(p));
|
|
75
|
+
})
|
|
76
|
+
}), null, 16, ["id", "required", "min", "max", "type", "name", "label", "error-messages", "error", "model-value"])) : l("", !0),
|
|
77
|
+
e.inputProps.type === "select" || e.inputProps.type === "multiple" ? (o(), n(m, s({
|
|
78
|
+
key: 4,
|
|
79
|
+
id: e.inputProps.id,
|
|
80
|
+
clearable: e.inputProps.type === "select",
|
|
81
|
+
required: e.inputProps.required,
|
|
82
|
+
multiple: e.inputProps.type === "multiple",
|
|
83
|
+
chips: e.inputProps.type === "multiple",
|
|
84
|
+
name: e.inputProps.name,
|
|
85
|
+
label: e.inputProps.label,
|
|
86
|
+
items: e.inputProps.options,
|
|
87
|
+
"error-messages": e.inputProps.errorMessages,
|
|
88
|
+
error: e.inputProps.error
|
|
89
|
+
}, e.$attrs, {
|
|
90
|
+
"model-value": e.vuetifyValue,
|
|
91
|
+
onClear: r[2] || (r[2] = (p) => e.inputProps.field.handleChange(void 0)),
|
|
92
|
+
"onUpdate:modelValue": e.inputProps.field.handleChange
|
|
93
|
+
}), null, 16, ["id", "clearable", "required", "multiple", "chips", "name", "label", "items", "error-messages", "error", "model-value", "onUpdate:modelValue"])) : l("", !0),
|
|
94
|
+
e.inputProps.type === "autocomplete" || e.inputProps.type === "autocompletemultiple" ? (o(), n(d, s({
|
|
95
|
+
key: 5,
|
|
96
|
+
id: e.inputProps.id,
|
|
97
|
+
clearable: e.inputProps.type === "autocomplete",
|
|
98
|
+
multiple: e.inputProps.type === "autocompletemultiple",
|
|
99
|
+
required: e.inputProps.required,
|
|
100
|
+
name: e.inputProps.name,
|
|
101
|
+
label: e.inputProps.label,
|
|
102
|
+
items: e.inputProps.options,
|
|
103
|
+
"error-messages": e.inputProps.errorMessages,
|
|
104
|
+
error: e.inputProps.error,
|
|
105
|
+
chips: e.inputProps.type === "autocompletemultiple"
|
|
106
|
+
}, e.$attrs, {
|
|
107
|
+
"model-value": e.vuetifyValue,
|
|
108
|
+
onClear: r[3] || (r[3] = (p) => e.inputProps.field.handleChange(void 0)),
|
|
109
|
+
"onUpdate:modelValue": e.inputProps.field.handleChange
|
|
110
|
+
}), null, 16, ["id", "clearable", "multiple", "required", "name", "label", "items", "error-messages", "error", "chips", "model-value", "onUpdate:modelValue"])) : l("", !0)
|
|
111
|
+
], 32);
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
export {
|
|
116
|
+
b as default
|
|
117
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function(){"use strict";try{if(typeof document<"u"){var n=document.createElement("style");if(n.appendChild(document.createTextNode(".omega-input .v-input__details:has(.v-messages:empty){grid-template-rows:0fr;transition:all .2s}.omega-input .v-messages:empty{min-height:0}.omega-input .v-input__details:has(.v-messages){transition:all .2s;overflow:hidden;min-height:0;display:grid;grid-template-rows:1fr}.omega-input .v-messages{transition:all .2s}.omega-input .v-messages>*{transition-duration:0s!important}.omega-input [role=alert]:has(.v-messages:empty){padding:0}.omega-input .v-btn{cursor:pointer;width:auto;-webkit-appearance:none;-moz-appearance:none;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),document.head.appendChild(n),window.customElements){const e=window.customElements.define;window.customElements.define=function(o,t){const a=t.prototype.connectedCallback;return t.prototype.connectedCallback=function(){if(a&&a.call(this),this.shadowRoot){const i=document.createElement("style");i.appendChild(document.createTextNode(".omega-input .v-input__details:has(.v-messages:empty){grid-template-rows:0fr;transition:all .2s}.omega-input .v-messages:empty{min-height:0}.omega-input .v-input__details:has(.v-messages){transition:all .2s;overflow:hidden;min-height:0;display:grid;grid-template-rows:1fr}.omega-input .v-messages{transition:all .2s}.omega-input .v-messages>*{transition-duration:0s!important}.omega-input [role=alert]:has(.v-messages:empty){padding:0}.omega-input .v-btn{cursor:pointer;width:auto;-webkit-appearance:none;-moz-appearance:none;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),this.shadowRoot.appendChild(i)}},e.call(window.customElements,o,t)}}}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
|
|
2
|
-
import o from "./vue-components.
|
|
2
|
+
import o from "./vue-components.es20.js";
|
|
3
3
|
|
|
4
4
|
export {
|
|
5
5
|
o as default
|
|
@@ -1,91 +1,125 @@
|
|
|
1
1
|
import { useForm as E } from "@tanstack/vue-form";
|
|
2
|
-
import { S as
|
|
3
|
-
import { generateMetaFromSchema as
|
|
4
|
-
import { computed as
|
|
5
|
-
import {
|
|
6
|
-
const
|
|
7
|
-
if (!
|
|
8
|
-
const
|
|
9
|
-
var
|
|
10
|
-
if ((
|
|
11
|
-
return
|
|
12
|
-
const
|
|
13
|
-
return `${
|
|
14
|
-
}),
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
2
|
+
import { S as I } from "effect-app";
|
|
3
|
+
import { generateMetaFromSchema as N } from "./vue-components.es6.js";
|
|
4
|
+
import { computed as a, onUnmounted as R, onMounted as A, onBeforeUnmount as D } from "vue";
|
|
5
|
+
import { isObject as J } from "./vue-components.es15.js";
|
|
6
|
+
const z = (h, u, i) => {
|
|
7
|
+
if (!h) throw new Error("Schema is required");
|
|
8
|
+
const b = I.standardSchemaV1(h), { filterItems: V, meta: t } = N(h), c = a(() => {
|
|
9
|
+
var l;
|
|
10
|
+
if ((l = i == null ? void 0 : i.persistency) != null && l.id)
|
|
11
|
+
return i.persistency.id;
|
|
12
|
+
const e = window.location.pathname, r = Object.keys(t);
|
|
13
|
+
return `${e}-${r.join("-")}`;
|
|
14
|
+
}), L = () => {
|
|
15
|
+
const e = new URLSearchParams(window.location.search);
|
|
16
|
+
e.delete(c.value);
|
|
17
|
+
const r = new URL(window.location.href);
|
|
18
|
+
r.search = e.toString(), window.history.replaceState({}, "", r.toString());
|
|
19
|
+
};
|
|
20
|
+
function f(e, r) {
|
|
21
|
+
for (const l in r)
|
|
22
|
+
r[l] && J(r[l]) ? (e[l] || (e[l] = {}), f(e[l], r[l])) : e[l] = r[l];
|
|
23
|
+
return e;
|
|
24
|
+
}
|
|
25
|
+
const U = a(() => {
|
|
26
|
+
var l;
|
|
27
|
+
if (u != null && u.defaultValues && !((l = i == null ? void 0 : i.persistency) != null && l.overrideDefaultValues))
|
|
28
|
+
return u == null ? void 0 : u.defaultValues;
|
|
29
|
+
let e;
|
|
30
|
+
const r = i == null ? void 0 : i.persistency;
|
|
31
|
+
if (!(r != null && r.policies) || r.policies.length === 0) return {};
|
|
32
|
+
if (r.policies.includes("querystring"))
|
|
33
|
+
try {
|
|
34
|
+
const d = new URLSearchParams(window.location.search).get(c.value);
|
|
35
|
+
L(), d && (e = JSON.parse(d));
|
|
36
|
+
} catch (s) {
|
|
37
|
+
console.error(s);
|
|
38
|
+
}
|
|
39
|
+
if (
|
|
40
|
+
// query string has higher priority than local/session storage
|
|
41
|
+
!e && (r.policies.includes("local") || r.policies.includes("session"))
|
|
42
|
+
) {
|
|
43
|
+
const s = r.policies.includes("local") ? localStorage : sessionStorage;
|
|
44
|
+
if (s)
|
|
45
|
+
try {
|
|
46
|
+
const d = JSON.parse(
|
|
47
|
+
s.getItem(c.value) || "{}"
|
|
48
|
+
);
|
|
49
|
+
s.removeItem(c.value), e = d;
|
|
50
|
+
} catch (d) {
|
|
51
|
+
console.error(d);
|
|
34
52
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
53
|
+
}
|
|
54
|
+
if (e ?? (e = {}), (u == null ? void 0 : u.defaultValues) == null)
|
|
55
|
+
return e;
|
|
56
|
+
{
|
|
57
|
+
const s = u == null ? void 0 : u.defaultValues;
|
|
58
|
+
return f(s, e);
|
|
59
|
+
}
|
|
60
|
+
}), n = E({
|
|
61
|
+
...u,
|
|
40
62
|
validators: {
|
|
41
|
-
onSubmit:
|
|
42
|
-
...(
|
|
63
|
+
onSubmit: b,
|
|
64
|
+
...(u == null ? void 0 : u.validators) || {}
|
|
43
65
|
},
|
|
44
|
-
onSubmit:
|
|
45
|
-
var
|
|
46
|
-
return (
|
|
47
|
-
formApi:
|
|
66
|
+
onSubmit: u != null && u.onSubmit ? ({ formApi: e, meta: r, value: l }) => {
|
|
67
|
+
var s;
|
|
68
|
+
return (s = u.onSubmit) == null ? void 0 : s.call(u, {
|
|
69
|
+
formApi: e,
|
|
48
70
|
meta: r,
|
|
49
|
-
value:
|
|
71
|
+
value: l
|
|
50
72
|
});
|
|
51
73
|
} : void 0,
|
|
52
|
-
defaultValues:
|
|
53
|
-
}),
|
|
54
|
-
Object.keys(
|
|
55
|
-
|
|
74
|
+
defaultValues: U.value
|
|
75
|
+
}), j = () => {
|
|
76
|
+
Object.keys(t).forEach((e) => {
|
|
77
|
+
n.setFieldValue(e, void 0);
|
|
56
78
|
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
n.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
}, o = (e) => e.reduce(
|
|
80
|
+
(r, l) => {
|
|
81
|
+
const s = l.split(".");
|
|
82
|
+
return s.reduce((d, w, P) => (P === s.length - 1 ? d[w] = n.getFieldValue(l) : d[w] = d[w] ?? {}, d[w]), r), r;
|
|
83
|
+
},
|
|
84
|
+
{}
|
|
85
|
+
), v = (e) => {
|
|
86
|
+
if (e) {
|
|
87
|
+
if (Array.isArray(e.keys))
|
|
88
|
+
return o(e.keys);
|
|
89
|
+
if (Array.isArray(e.banKeys)) {
|
|
90
|
+
const r = Object.keys(t).filter(
|
|
91
|
+
(l) => {
|
|
92
|
+
var s;
|
|
93
|
+
return (s = e.banKeys) == null ? void 0 : s.includes(l);
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
return o(r);
|
|
97
|
+
}
|
|
98
|
+
return n.store.state.values;
|
|
99
|
+
}
|
|
100
|
+
}, S = () => {
|
|
101
|
+
const e = i == null ? void 0 : i.persistency;
|
|
102
|
+
if (!(!(e != null && e.policies) || e.policies.length === 0) && (e.policies.includes("local") || e.policies.includes("session"))) {
|
|
103
|
+
const r = e.policies.includes("local") ? localStorage : sessionStorage;
|
|
104
|
+
if (!r) return;
|
|
105
|
+
const l = v(e);
|
|
106
|
+
return r.setItem(c.value, JSON.stringify(l));
|
|
107
|
+
}
|
|
108
|
+
}, y = () => {
|
|
109
|
+
const e = i == null ? void 0 : i.persistency;
|
|
110
|
+
if (!(!(e != null && e.policies) || e.policies.length === 0) && e.policies.includes("querystring")) {
|
|
111
|
+
const r = v(e), l = new URLSearchParams(window.location.search);
|
|
112
|
+
l.set(c.value, JSON.stringify(r));
|
|
113
|
+
const s = new URL(window.location.href);
|
|
114
|
+
s.search = l.toString(), window.history.replaceState({}, "", s.toString());
|
|
115
|
+
}
|
|
82
116
|
};
|
|
83
|
-
return
|
|
84
|
-
window.addEventListener("beforeunload",
|
|
85
|
-
}),
|
|
86
|
-
window.removeEventListener("beforeunload",
|
|
87
|
-
}), V;
|
|
117
|
+
return R(S), A(() => {
|
|
118
|
+
window.addEventListener("beforeunload", S), window.addEventListener("blur", y);
|
|
119
|
+
}), D(() => {
|
|
120
|
+
window.removeEventListener("beforeunload", S), window.removeEventListener("blur", y);
|
|
121
|
+
}), Object.assign(n, { meta: t, filterItems: V, clear: j });
|
|
88
122
|
};
|
|
89
123
|
export {
|
|
90
|
-
|
|
124
|
+
z as useOmegaForm
|
|
91
125
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { defineComponent as i, computed as t, createBlock as p, openBlock as d, resolveDynamicComponent as u, withCtx as r, createVNode as f, mergeProps as c, renderSlot as v, normalizeProps as h, guardReactiveProps as g } from "vue";
|
|
2
2
|
import { generateInputStandardSchemaFromFieldMeta as y } from "./vue-components.es6.js";
|
|
3
|
-
import b from "./vue-components.
|
|
3
|
+
import b from "./vue-components.es17.js";
|
|
4
4
|
const S = /* @__PURE__ */ i({
|
|
5
5
|
inheritAttrs: !1,
|
|
6
6
|
__name: "OmegaInput",
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
type FormAsyncValidateOrFn,
|
|
6
6
|
type StandardSchemaV1,
|
|
7
7
|
} from "@tanstack/vue-form"
|
|
8
|
-
import {
|
|
8
|
+
import { type Record, S } from "effect-app"
|
|
9
9
|
import {
|
|
10
10
|
generateMetaFromSchema,
|
|
11
11
|
type NestedKeyOf,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
type OmegaFormApi,
|
|
16
16
|
} from "./OmegaFormStuff"
|
|
17
17
|
import { computed, onBeforeUnmount, onMounted, onUnmounted } from "vue"
|
|
18
|
-
import {
|
|
18
|
+
import { isObject } from "effect/Predicate"
|
|
19
19
|
|
|
20
20
|
type keysRule<T> =
|
|
21
21
|
| {
|
|
@@ -29,7 +29,11 @@ type keysRule<T> =
|
|
|
29
29
|
|
|
30
30
|
export type OmegaConfig<T> = {
|
|
31
31
|
persistency?: {
|
|
32
|
-
|
|
32
|
+
/** Order of importance:
|
|
33
|
+
* - "querystring": Highest priority when persisting
|
|
34
|
+
* - "local" and then "session": Lower priority storage options
|
|
35
|
+
*/
|
|
36
|
+
policies?: ("local" | "session" | "querystring")[]
|
|
33
37
|
overrideDefaultValues?: boolean
|
|
34
38
|
id?: string
|
|
35
39
|
} & keysRule<T>
|
|
@@ -65,36 +69,91 @@ export const useOmegaForm = <
|
|
|
65
69
|
return `${path}-${keys.join("-")}`
|
|
66
70
|
})
|
|
67
71
|
|
|
72
|
+
const clearUrlParams = () => {
|
|
73
|
+
const params = new URLSearchParams(window.location.search)
|
|
74
|
+
params.delete(persistencyKey.value)
|
|
75
|
+
const url = new URL(window.location.href)
|
|
76
|
+
url.search = params.toString()
|
|
77
|
+
window.history.replaceState({}, "", url.toString())
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function deepMerge(target: any, source: any) {
|
|
81
|
+
for (const key in source) {
|
|
82
|
+
if (source[key] && isObject(source[key])) {
|
|
83
|
+
if (!target[key]) {
|
|
84
|
+
target[key] = {}
|
|
85
|
+
}
|
|
86
|
+
deepMerge(target[key], source[key])
|
|
87
|
+
} else {
|
|
88
|
+
target[key] = source[key]
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return target
|
|
92
|
+
}
|
|
93
|
+
|
|
68
94
|
const defaultValues = computed(() => {
|
|
69
95
|
if (
|
|
70
96
|
tanstackFormOptions?.defaultValues &&
|
|
71
97
|
!omegaConfig?.persistency?.overrideDefaultValues
|
|
72
|
-
)
|
|
73
|
-
|
|
98
|
+
) {
|
|
99
|
+
// defaultValues from tanstack are not partial,
|
|
100
|
+
// so if ovverrideDefaultValues is false we simply return them
|
|
101
|
+
return tanstackFormOptions?.defaultValues
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// we are here because there are no default values from tankstack
|
|
105
|
+
// or because omegaConfig?.persistency?.overrideDefaultValues is true
|
|
106
|
+
|
|
107
|
+
// will contain what we get from querystring or local/session storage
|
|
108
|
+
let defValuesPatch
|
|
109
|
+
|
|
74
110
|
const persistency = omegaConfig?.persistency
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
|
|
111
|
+
if (!persistency?.policies || persistency.policies.length === 0) return {}
|
|
112
|
+
if (persistency.policies.includes("querystring")) {
|
|
113
|
+
try {
|
|
114
|
+
const params = new URLSearchParams(window.location.search)
|
|
115
|
+
const value = params.get(persistencyKey.value)
|
|
116
|
+
clearUrlParams()
|
|
117
|
+
if (value) {
|
|
118
|
+
defValuesPatch = JSON.parse(value)
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error(error)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (
|
|
126
|
+
// query string has higher priority than local/session storage
|
|
127
|
+
!defValuesPatch &&
|
|
128
|
+
(persistency.policies.includes("local") ||
|
|
129
|
+
persistency.policies.includes("session"))
|
|
130
|
+
) {
|
|
131
|
+
const storage = persistency.policies.includes("local")
|
|
132
|
+
? localStorage
|
|
133
|
+
: sessionStorage
|
|
134
|
+
if (storage) {
|
|
135
|
+
try {
|
|
136
|
+
const value = JSON.parse(
|
|
137
|
+
storage.getItem(persistencyKey.value) || "{}",
|
|
138
|
+
)
|
|
139
|
+
storage.removeItem(persistencyKey.value)
|
|
140
|
+
defValuesPatch = value
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error(error)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// to be sure we have a valid object at the end of the gathering process
|
|
148
|
+
defValuesPatch ??= {}
|
|
149
|
+
|
|
150
|
+
if (tanstackFormOptions?.defaultValues == undefined) {
|
|
151
|
+
// we just return what we gathered from the query/storage
|
|
152
|
+
return defValuesPatch
|
|
153
|
+
} else {
|
|
154
|
+
const startingDefValues = tanstackFormOptions?.defaultValues
|
|
155
|
+
return deepMerge(startingDefValues, defValuesPatch)
|
|
156
|
+
}
|
|
98
157
|
})
|
|
99
158
|
|
|
100
159
|
const form = useForm<
|
|
@@ -131,55 +190,82 @@ export const useOmegaForm = <
|
|
|
131
190
|
})
|
|
132
191
|
}
|
|
133
192
|
|
|
134
|
-
const
|
|
193
|
+
const createNestedObjectFromPaths = (paths: string[]) =>
|
|
194
|
+
paths.reduce(
|
|
195
|
+
(result, path) => {
|
|
196
|
+
const parts = path.split(".")
|
|
197
|
+
parts.reduce((acc, part, i) => {
|
|
198
|
+
if (i === parts.length - 1) {
|
|
199
|
+
acc[part] = form.getFieldValue(path as any)
|
|
200
|
+
} else {
|
|
201
|
+
acc[part] = acc[part] ?? {}
|
|
202
|
+
}
|
|
203
|
+
return acc[part]
|
|
204
|
+
}, result)
|
|
205
|
+
return result
|
|
206
|
+
},
|
|
207
|
+
{} as Record<string, any>,
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
const persistFilter = (persistency: OmegaConfig<From>["persistency"]) => {
|
|
211
|
+
if (!persistency) return
|
|
212
|
+
if (Array.isArray(persistency.keys)) {
|
|
213
|
+
return createNestedObjectFromPaths(persistency.keys)
|
|
214
|
+
}
|
|
215
|
+
if (Array.isArray(persistency.banKeys)) {
|
|
216
|
+
const subs = Object.keys(meta).filter(metakey =>
|
|
217
|
+
persistency.banKeys?.includes(metakey as any),
|
|
218
|
+
)
|
|
219
|
+
return createNestedObjectFromPaths(subs)
|
|
220
|
+
}
|
|
221
|
+
return form.store.state.values
|
|
222
|
+
}
|
|
135
223
|
|
|
136
|
-
// This is fragile as fuck. It's an experiment, it's only used because
|
|
137
|
-
// it's not a core feature of our products, so even if the this is not consistent
|
|
138
|
-
// it's not a big deal. So not take this code as a good example of how to do things.
|
|
139
|
-
// This is done only because this function is called before the component is destroyed,
|
|
140
|
-
// so the state would be lost anyway. So in this case we can play with the state, without
|
|
141
|
-
// worrying about the side effects.
|
|
142
224
|
const persistData = () => {
|
|
143
225
|
const persistency = omegaConfig?.persistency
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
|
|
226
|
+
if (!persistency?.policies || persistency.policies.length === 0) {
|
|
227
|
+
return
|
|
228
|
+
}
|
|
229
|
+
if (
|
|
230
|
+
persistency.policies.includes("local") ||
|
|
231
|
+
persistency.policies.includes("session")
|
|
232
|
+
) {
|
|
233
|
+
const storage = persistency.policies.includes("local")
|
|
234
|
+
? localStorage
|
|
235
|
+
: sessionStorage
|
|
236
|
+
if (!storage) return
|
|
237
|
+
const values = persistFilter(persistency)
|
|
238
|
+
return storage.setItem(persistencyKey.value, JSON.stringify(values))
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const saveDataInUrl = () => {
|
|
243
|
+
const persistency = omegaConfig?.persistency
|
|
244
|
+
if (!persistency?.policies || persistency.policies.length === 0) {
|
|
245
|
+
return
|
|
246
|
+
}
|
|
247
|
+
if (persistency.policies.includes("querystring")) {
|
|
248
|
+
const values = persistFilter(persistency)
|
|
249
|
+
const searchParams = new URLSearchParams(window.location.search)
|
|
250
|
+
searchParams.set(persistencyKey.value, JSON.stringify(values))
|
|
251
|
+
const url = new URL(window.location.href)
|
|
252
|
+
url.search = searchParams.toString()
|
|
253
|
+
window.history.replaceState({}, "", url.toString())
|
|
254
|
+
}
|
|
173
255
|
}
|
|
174
256
|
|
|
175
257
|
onUnmounted(persistData)
|
|
176
258
|
|
|
177
259
|
onMounted(() => {
|
|
178
260
|
window.addEventListener("beforeunload", persistData)
|
|
261
|
+
window.addEventListener("blur", saveDataInUrl)
|
|
179
262
|
})
|
|
180
263
|
onBeforeUnmount(() => {
|
|
181
264
|
window.removeEventListener("beforeunload", persistData)
|
|
265
|
+
window.removeEventListener("blur", saveDataInUrl)
|
|
182
266
|
})
|
|
183
267
|
|
|
268
|
+
const exposed = Object.assign(form, { meta, filterItems, clear })
|
|
269
|
+
|
|
184
270
|
return exposed
|
|
185
271
|
}
|
|
@@ -44,7 +44,7 @@ const addForm = useOmegaForm(
|
|
|
44
44
|
{},
|
|
45
45
|
{
|
|
46
46
|
persistency: {
|
|
47
|
-
|
|
47
|
+
policies: ["session", "querystring"],
|
|
48
48
|
keys: ["first", "third.fourth"],
|
|
49
49
|
},
|
|
50
50
|
},
|
|
@@ -55,11 +55,4 @@ const values = addForm.useStore(({ values }) => values)
|
|
|
55
55
|
watch(values, ({ first, second }) => {
|
|
56
56
|
sum.value = first + second
|
|
57
57
|
})
|
|
58
|
-
|
|
59
|
-
// TODO: Implement this when we have a way to persist the form values
|
|
60
|
-
// {
|
|
61
|
-
// persist: "session",
|
|
62
|
-
// persistKeys: ["riskCategoryPeriod"],
|
|
63
|
-
// persistBanKeys: ["riskCategory"],
|
|
64
|
-
// }
|
|
65
58
|
</script>
|