@effect-app/vue-components 0.3.0 → 0.3.1

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,7 +9,11 @@ type keysRule<T> = {
9
9
  };
10
10
  export type OmegaConfig<T> = {
11
11
  persistency?: {
12
- method?: "session" | "local" | "none";
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.es17.js";
3
+ import { getOmegaStore as M } from "./vue-components.es16.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,95 @@
1
- const o = (n) => () => n, t = /* @__PURE__ */ o(void 0), c = t;
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.es18.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
+ });
2
93
  export {
3
- t as constUndefined,
4
- c as constVoid,
5
- o as constant
94
+ Z as default
6
95
  };
@@ -1,95 +1,13 @@
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.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
+ 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
+ }
93
11
  export {
94
- Z as default
12
+ c as getOmegaStore
95
13
  };
@@ -1,13 +1,4 @@
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
- }
1
+ import f from "./vue-components.es15.js";
11
2
  export {
12
- c as getOmegaStore
3
+ f as default
13
4
  };
@@ -1,4 +1,117 @@
1
- import f from "./vue-components.es16.js";
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
+ });
2
115
  export {
3
- f as default
116
+ b as default
4
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.es19.js";
2
+ import o from "./vue-components.es18.js";
3
3
 
4
4
  export {
5
5
  o as default
@@ -1,91 +1,110 @@
1
- import { useForm as E } from "@tanstack/vue-form";
2
- import { S as j, Match as n } from "effect-app";
3
- import { generateMetaFromSchema as A } from "./vue-components.es6.js";
4
- import { computed as b, onUnmounted as I, onMounted as K, onBeforeUnmount as M } from "vue";
5
- import { constVoid as x } from "./vue-components.es15.js";
6
- const m = (i, e, u) => {
7
- if (!i) throw new Error("Schema is required");
8
- const a = j.standardSchemaV1(i), { filterItems: f, meta: y } = A(i), o = b(() => {
9
- var d;
10
- if ((d = u == null ? void 0 : u.persistency) != null && d.id)
11
- return u.persistency.id;
12
- const l = window.location.pathname, r = Object.keys(y);
13
- return `${l}-${r.join("-")}`;
14
- }), w = b(() => {
1
+ import { useForm as p } from "@tanstack/vue-form";
2
+ import { S as E } from "effect-app";
3
+ import { generateMetaFromSchema as P } from "./vue-components.es6.js";
4
+ import { computed as y, onUnmounted as I, onMounted as N, onBeforeUnmount as R } from "vue";
5
+ const K = (a, t, u) => {
6
+ if (!a) throw new Error("Schema is required");
7
+ const b = E.standardSchemaV1(a), { filterItems: f, meta: c } = P(a), i = y(() => {
15
8
  var r;
16
- if (e != null && e.defaultValues && !((r = u == null ? void 0 : u.persistency) != null && r.overrideDefaultValues))
17
- return e.defaultValues;
18
- const l = u == null ? void 0 : u.persistency;
19
- return n.value(l).pipe(
20
- n.when(
21
- { method: (d) => ["local", "session"].includes(d) },
22
- (d) => {
23
- const c = d.method === "local" ? localStorage : sessionStorage;
24
- if (c)
25
- try {
26
- const s = JSON.parse(
27
- c.getItem(o.value) || "{}"
28
- );
29
- return c.removeItem(o.value), s;
30
- } catch (s) {
31
- return console.error(s), {};
32
- }
33
- return {};
9
+ if ((r = u == null ? void 0 : u.persistency) != null && r.id)
10
+ return u.persistency.id;
11
+ const e = window.location.pathname, l = Object.keys(c);
12
+ return `${e}-${l.join("-")}`;
13
+ }), L = () => {
14
+ const e = new URLSearchParams(window.location.search);
15
+ e.delete(i.value);
16
+ const l = new URL(window.location.href);
17
+ l.search = e.toString(), window.history.replaceState({}, "", l.toString());
18
+ }, U = y(() => {
19
+ var l;
20
+ if (t != null && t.defaultValues && !((l = u == null ? void 0 : u.persistency) != null && l.overrideDefaultValues))
21
+ return t == null ? void 0 : t.defaultValues;
22
+ const e = u == null ? void 0 : u.persistency;
23
+ if (!(e != null && e.policies) || e.policies.length === 0) return {};
24
+ if (e.policies.includes("querystring"))
25
+ try {
26
+ const s = new URLSearchParams(window.location.search).get(i.value);
27
+ if (L(), s)
28
+ return JSON.parse(s);
29
+ } catch (r) {
30
+ console.error(r);
31
+ }
32
+ if (e.policies.includes("local") || e.policies.includes("session")) {
33
+ const r = e.policies.includes("local") ? localStorage : sessionStorage;
34
+ if (r)
35
+ try {
36
+ const s = JSON.parse(
37
+ r.getItem(i.value) || "{}"
38
+ );
39
+ return r.removeItem(i.value), s;
40
+ } catch (s) {
41
+ console.error(s);
34
42
  }
35
- ),
36
- n.orElse(() => ({}))
37
- );
38
- }), h = E({
39
- ...e,
43
+ }
44
+ return {};
45
+ }), n = p({
46
+ ...t,
40
47
  validators: {
41
- onSubmit: a,
42
- ...(e == null ? void 0 : e.validators) || {}
48
+ onSubmit: b,
49
+ ...(t == null ? void 0 : t.validators) || {}
43
50
  },
44
- onSubmit: e != null && e.onSubmit ? ({ formApi: l, meta: r, value: d }) => {
45
- var t;
46
- return (t = e.onSubmit) == null ? void 0 : t.call(e, {
47
- formApi: l,
48
- meta: r,
49
- value: d
51
+ onSubmit: t != null && t.onSubmit ? ({ formApi: e, meta: l, value: r }) => {
52
+ var s;
53
+ return (s = t.onSubmit) == null ? void 0 : s.call(t, {
54
+ formApi: e,
55
+ meta: l,
56
+ value: r
50
57
  });
51
58
  } : void 0,
52
- defaultValues: w.value
53
- }), V = Object.assign(h, { meta: y, filterItems: f, clear: () => {
54
- Object.keys(y).forEach((l) => {
55
- h.setFieldValue(l, void 0);
59
+ defaultValues: U.value
60
+ }), V = () => {
61
+ Object.keys(c).forEach((e) => {
62
+ n.setFieldValue(e, void 0);
56
63
  });
57
- } }), v = () => {
58
- const l = u == null ? void 0 : u.persistency;
59
- n.value(l).pipe(
60
- n.when(
61
- { method: (r) => ["local", "session"].includes(r) },
62
- (r) => {
63
- const t = r.method === "local" ? localStorage : sessionStorage;
64
- if (t)
65
- return Array.isArray(r.keys) && Object.keys(y).filter(
66
- (s) => {
67
- var S;
68
- return !((S = r.keys) != null && S.includes(s));
69
- }
70
- ).forEach((s) => {
71
- h.setFieldValue(s, void 0);
72
- }), Array.isArray(r.banKeys) && r.banKeys.forEach((c) => {
73
- h.setFieldValue(c, void 0);
74
- }), t.setItem(
75
- o.value,
76
- JSON.stringify(h.store.state.values)
77
- );
78
- }
79
- ),
80
- n.orElse(x)
81
- );
64
+ }, S = (e) => e.reduce(
65
+ (l, r) => {
66
+ const s = r.split(".");
67
+ return s.reduce((d, o, j) => (j === s.length - 1 ? d[o] = n.getFieldValue(r) : d[o] = d[o] || {}, d[o]), l);
68
+ },
69
+ {}
70
+ ), h = (e) => {
71
+ if (e) {
72
+ if (Array.isArray(e.keys))
73
+ return S(e.keys);
74
+ if (Array.isArray(e.banKeys)) {
75
+ const l = Object.keys(c).filter(
76
+ (r) => {
77
+ var s;
78
+ return (s = e.banKeys) == null ? void 0 : s.includes(r);
79
+ }
80
+ );
81
+ return S(l);
82
+ }
83
+ return n.store.state.values;
84
+ }
85
+ }, w = () => {
86
+ const e = u == null ? void 0 : u.persistency;
87
+ if (!(!(e != null && e.policies) || e.policies.length === 0) && (e.policies.includes("local") || e.policies.includes("session"))) {
88
+ const l = e.policies.includes("local") ? localStorage : sessionStorage;
89
+ if (!l) return;
90
+ const r = h(e);
91
+ return l.setItem(i.value, JSON.stringify(r));
92
+ }
93
+ }, v = () => {
94
+ const e = u == null ? void 0 : u.persistency;
95
+ if (!(!(e != null && e.policies) || e.policies.length === 0) && e.policies.includes("querystring")) {
96
+ const l = h(e), r = new URLSearchParams(window.location.search);
97
+ r.set(i.value, JSON.stringify(l));
98
+ const s = new URL(window.location.href);
99
+ s.search = r.toString(), window.history.replaceState({}, "", s.toString());
100
+ }
82
101
  };
83
- return I(v), K(() => {
84
- window.addEventListener("beforeunload", v);
85
- }), M(() => {
86
- window.removeEventListener("beforeunload", v);
87
- }), V;
102
+ return I(w), N(() => {
103
+ window.addEventListener("beforeunload", w), window.addEventListener("blur", v);
104
+ }), R(() => {
105
+ window.removeEventListener("beforeunload", w), window.removeEventListener("blur", v);
106
+ }), Object.assign(n, { meta: c, filterItems: f, clear: V });
88
107
  };
89
108
  export {
90
- m as useOmegaForm
109
+ K as useOmegaForm
91
110
  };
@@ -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.es16.js";
3
+ import b from "./vue-components.es15.js";
4
4
  const S = /* @__PURE__ */ i({
5
5
  inheritAttrs: !1,
6
6
  __name: "OmegaInput",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "@tanstack/vue-form": "^1.2.4",
@@ -5,7 +5,7 @@ import {
5
5
  type FormAsyncValidateOrFn,
6
6
  type StandardSchemaV1,
7
7
  } from "@tanstack/vue-form"
8
- import { Match, S } from "effect-app"
8
+ import { S } from "effect-app"
9
9
  import {
10
10
  generateMetaFromSchema,
11
11
  type NestedKeyOf,
@@ -15,7 +15,6 @@ import {
15
15
  type OmegaFormApi,
16
16
  } from "./OmegaFormStuff"
17
17
  import { computed, onBeforeUnmount, onMounted, onUnmounted } from "vue"
18
- import { constVoid } from "effect/Function"
19
18
 
20
19
  type keysRule<T> =
21
20
  | {
@@ -29,7 +28,11 @@ type keysRule<T> =
29
28
 
30
29
  export type OmegaConfig<T> = {
31
30
  persistency?: {
32
- method?: "session" | "local" | "none"
31
+ /** Order of importance:
32
+ * - "querystring": Highest priority when persisting
33
+ * - "local" and then "session": Lower priority storage options
34
+ */
35
+ policies?: ("local" | "session" | "querystring")[]
33
36
  overrideDefaultValues?: boolean
34
37
  id?: string
35
38
  } & keysRule<T>
@@ -65,36 +68,56 @@ export const useOmegaForm = <
65
68
  return `${path}-${keys.join("-")}`
66
69
  })
67
70
 
71
+ const clearUrlParams = () => {
72
+ const params = new URLSearchParams(window.location.search)
73
+ params.delete(persistencyKey.value)
74
+ const url = new URL(window.location.href)
75
+ url.search = params.toString()
76
+ window.history.replaceState({}, "", url.toString())
77
+ }
78
+
68
79
  const defaultValues = computed(() => {
69
80
  if (
70
81
  tanstackFormOptions?.defaultValues &&
71
82
  !omegaConfig?.persistency?.overrideDefaultValues
72
- )
73
- return tanstackFormOptions.defaultValues
83
+ ) {
84
+ return tanstackFormOptions?.defaultValues
85
+ }
74
86
  const persistency = omegaConfig?.persistency
75
- return Match.value(persistency).pipe(
76
- Match.when(
77
- { method: method => ["local", "session"].includes(method) },
78
- persistency => {
79
- const method = persistency.method
80
- const storage = method === "local" ? localStorage : sessionStorage
81
- if (storage) {
82
- try {
83
- const value = JSON.parse(
84
- storage.getItem(persistencyKey.value) || "{}",
85
- )
86
- storage.removeItem(persistencyKey.value)
87
- return value
88
- } catch (error) {
89
- console.error(error)
90
- return {}
91
- }
92
- }
93
- return {}
94
- },
95
- ),
96
- Match.orElse(() => ({})),
97
- )
87
+ if (!persistency?.policies || persistency.policies.length === 0) return {}
88
+ if (persistency.policies.includes("querystring")) {
89
+ try {
90
+ const params = new URLSearchParams(window.location.search)
91
+ const value = params.get(persistencyKey.value)
92
+ clearUrlParams()
93
+ if (value) {
94
+ return JSON.parse(value)
95
+ }
96
+ } catch (error) {
97
+ console.error(error)
98
+ }
99
+ }
100
+
101
+ if (
102
+ persistency.policies.includes("local") ||
103
+ persistency.policies.includes("session")
104
+ ) {
105
+ const storage = persistency.policies.includes("local")
106
+ ? localStorage
107
+ : sessionStorage
108
+ if (storage) {
109
+ try {
110
+ const value = JSON.parse(
111
+ storage.getItem(persistencyKey.value) || "{}",
112
+ )
113
+ storage.removeItem(persistencyKey.value)
114
+ return value
115
+ } catch (error) {
116
+ console.error(error)
117
+ }
118
+ }
119
+ }
120
+ return {}
98
121
  })
99
122
 
100
123
  const form = useForm<
@@ -131,55 +154,81 @@ export const useOmegaForm = <
131
154
  })
132
155
  }
133
156
 
134
- const exposed = Object.assign(form, { meta, filterItems, clear })
157
+ const createNestedObjectFromPaths = (paths: string[]) =>
158
+ paths.reduce(
159
+ (result, path) => {
160
+ const parts = path.split(".")
161
+ return parts.reduce((acc, part, i) => {
162
+ if (i === parts.length - 1) {
163
+ acc[part] = form.getFieldValue(path as any)
164
+ } else {
165
+ acc[part] = acc[part] || {}
166
+ }
167
+ return acc[part]
168
+ }, result)
169
+ },
170
+ {} as Record<string, any>,
171
+ )
172
+
173
+ const persistFilter = (persistency: OmegaConfig<From>["persistency"]) => {
174
+ if (!persistency) return
175
+ if (Array.isArray(persistency.keys)) {
176
+ return createNestedObjectFromPaths(persistency.keys)
177
+ }
178
+ if (Array.isArray(persistency.banKeys)) {
179
+ const subs = Object.keys(meta).filter(metakey =>
180
+ persistency.banKeys?.includes(metakey as any),
181
+ )
182
+ return createNestedObjectFromPaths(subs)
183
+ }
184
+ return form.store.state.values
185
+ }
135
186
 
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
187
  const persistData = () => {
143
188
  const persistency = omegaConfig?.persistency
144
- Match.value(persistency).pipe(
145
- Match.when(
146
- { method: method => ["local", "session"].includes(method) },
147
- persistency => {
148
- const method = persistency.method
149
- const storage = method === "local" ? localStorage : sessionStorage
150
- if (storage) {
151
- if (Array.isArray(persistency.keys)) {
152
- const subs = Object.keys(meta).filter(
153
- metakey => !persistency.keys?.includes(metakey as any),
154
- )
155
- subs.forEach(key => {
156
- form.setFieldValue(key as any, undefined)
157
- })
158
- }
159
- if (Array.isArray(persistency.banKeys)) {
160
- persistency.banKeys.forEach(key => {
161
- form.setFieldValue(key as any, undefined)
162
- })
163
- }
164
- return storage.setItem(
165
- persistencyKey.value,
166
- JSON.stringify(form.store.state.values),
167
- )
168
- }
169
- },
170
- ),
171
- Match.orElse(constVoid),
172
- )
189
+ if (!persistency?.policies || persistency.policies.length === 0) {
190
+ return
191
+ }
192
+ if (
193
+ persistency.policies.includes("local") ||
194
+ persistency.policies.includes("session")
195
+ ) {
196
+ const storage = persistency.policies.includes("local")
197
+ ? localStorage
198
+ : sessionStorage
199
+ if (!storage) return
200
+ const values = persistFilter(persistency)
201
+ return storage.setItem(persistencyKey.value, JSON.stringify(values))
202
+ }
203
+ }
204
+
205
+ const saveDataInUrl = () => {
206
+ const persistency = omegaConfig?.persistency
207
+ if (!persistency?.policies || persistency.policies.length === 0) {
208
+ return
209
+ }
210
+ if (persistency.policies.includes("querystring")) {
211
+ const values = persistFilter(persistency)
212
+ const searchParams = new URLSearchParams(window.location.search)
213
+ searchParams.set(persistencyKey.value, JSON.stringify(values))
214
+ const url = new URL(window.location.href)
215
+ url.search = searchParams.toString()
216
+ window.history.replaceState({}, "", url.toString())
217
+ }
173
218
  }
174
219
 
175
220
  onUnmounted(persistData)
176
221
 
177
222
  onMounted(() => {
178
223
  window.addEventListener("beforeunload", persistData)
224
+ window.addEventListener("blur", saveDataInUrl)
179
225
  })
180
226
  onBeforeUnmount(() => {
181
227
  window.removeEventListener("beforeunload", persistData)
228
+ window.removeEventListener("blur", saveDataInUrl)
182
229
  })
183
230
 
231
+ const exposed = Object.assign(form, { meta, filterItems, clear })
232
+
184
233
  return exposed
185
234
  }
@@ -73,7 +73,7 @@ const form = useOmegaForm(
73
73
  },
74
74
  {
75
75
  persistency: {
76
- method: "local",
76
+ policies: ["local"],
77
77
  overrideDefaultValues: true,
78
78
  },
79
79
  },
@@ -44,7 +44,7 @@ const addForm = useOmegaForm(
44
44
  {},
45
45
  {
46
46
  persistency: {
47
- method: "session",
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>
@@ -1,117 +0,0 @@
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
- };