@effect-app/vue-components 0.15.29 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -182,3 +182,24 @@ In [tsconfig.json](tsconfig.js), set the following to address [Issue #32](https:
182
182
  ]
183
183
  }
184
184
  ```
185
+
186
+ ### On Submit event
187
+ The :on-submit event could be tricky in `<OmegaForm />` component.
188
+ This is a prop that is basically a map of Tanstack Form `onSubmit` option and accept a function that return a Promise. If you want to use it as an event, you have to manage the state of loading yourself with `@submit` with a function returning `void`
189
+
190
+ E.g.
191
+
192
+ to use it as a Promise based Tanstack way:
193
+ ```html
194
+ <OmegaForm :schema="schema" :on-submit="onSubmit" :subscribe="['values']">
195
+ ```
196
+
197
+ to use it as an event:
198
+ ```html
199
+ <OmegaForm :schema="schema" @submit="onSubmit" :is-loading="false" :subscribe="['values']">
200
+ ```
201
+
202
+ this will give you a type error instead, because `:is-loading` is only accepted in event mode
203
+ ```html
204
+ <OmegaForm :schema="schema" :on-submit="onSubmit" :is-loading="false" :subscribe="['values']">
205
+ ```
@@ -1,23 +1,23 @@
1
1
  import { type S } from "effect-app";
2
- import { type OmegaFormState, type ShowErrorsOn } from "./OmegaFormStuff";
2
+ import { type FormProps, type OmegaFormState, type ShowErrorsOn } from "./OmegaFormStuff";
3
3
  import { type OmegaConfig, type OmegaFormReturn } from "./useOmegaForm";
4
4
  declare const _default: <From extends Record<PropertyKey, any>, To extends Record<PropertyKey, any>, K extends keyof OmegaFormState<From, To> = keyof OmegaFormState<From, To>>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
5
5
  props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & ({
6
6
  omegaConfig?: OmegaConfig<From>;
7
7
  subscribe?: K[];
8
8
  showErrorsOn?: ShowErrorsOn;
9
- } & Omit<import("@tanstack/vue-form").FormOptions<From, import("@tanstack/vue-form").FormValidateOrFn<From> | undefined, import("@tanstack/vue-form").FormValidateOrFn<From> | undefined, import("@tanstack/vue-form").StandardSchemaV1<From, To>, import("@tanstack/vue-form").FormValidateOrFn<From> | undefined, import("@tanstack/vue-form").FormAsyncValidateOrFn<From> | undefined, import("@tanstack/vue-form").FormValidateOrFn<From> | undefined, import("@tanstack/vue-form").FormAsyncValidateOrFn<From> | undefined, import("@tanstack/vue-form").FormAsyncValidateOrFn<From> | undefined, import("@tanstack/vue-form").FormAsyncValidateOrFn<From> | undefined>, "onSubmit"> & ({
10
- onSubmit?: ((props: {
11
- formApi: import("./OmegaFormStuff").OmegaFormParams<From, To>;
12
- meta: any;
13
- value: To;
14
- }) => Promise<any> | any) | undefined;
15
- } & ({
9
+ } & Omit<FormProps<From, To>, "onSubmit"> & (({
16
10
  form: OmegaFormReturn<From, To>;
17
11
  schema?: undefined;
18
12
  } | {
19
13
  form?: undefined;
20
14
  schema: S.Schema<To, From, never>;
15
+ }) & ({
16
+ isLoading?: undefined;
17
+ onSubmit?: FormProps<From, To>["onSubmit"];
18
+ } | {
19
+ isLoading: boolean;
20
+ onSubmit: (data: To) => void;
21
21
  }))) & {}> & import("vue").PublicProps;
22
22
  expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
23
23
  attrs: any;
@@ -1,8 +1,8 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var n=document.createElement("style");if(n.appendChild(document.createTextNode("fieldset[data-v-fd69dadb]{display:contents}")),document.head.appendChild(n),window.customElements){const e=window.customElements.define;window.customElements.define=function(i,t){const d=t.prototype.connectedCallback;return t.prototype.connectedCallback=function(){if(d&&d.call(this),this.shadowRoot){const o=document.createElement("style");o.appendChild(document.createTextNode("fieldset[data-v-fd69dadb]{display:contents}")),this.shadowRoot.appendChild(o)}},e.call(window.customElements,i,t)}}}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
1
+ (function(){"use strict";try{if(typeof document<"u"){var n=document.createElement("style");if(n.appendChild(document.createTextNode("fieldset[data-v-34631bd6]{display:contents}fieldset[disabled][data-v-34631bd6]>*{pointer-events:none}")),document.head.appendChild(n),window.customElements){const e=window.customElements.define;window.customElements.define=function(i,t){const d=t.prototype.connectedCallback;return t.prototype.connectedCallback=function(){if(d&&d.call(this),this.shadowRoot){const o=document.createElement("style");o.appendChild(document.createTextNode("fieldset[data-v-34631bd6]{display:contents}fieldset[disabled][data-v-34631bd6]>*{pointer-events:none}")),this.shadowRoot.appendChild(o)}},e.call(window.customElements,i,t)}}}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
2
2
  import o from "./vue-components.es20.js";
3
3
 
4
4
  import r from "./vue-components.es17.js";
5
- const m = /* @__PURE__ */ r(o, [["__scopeId", "data-v-fd69dadb"]]);
5
+ const m = /* @__PURE__ */ r(o, [["__scopeId", "data-v-34631bd6"]]);
6
6
  export {
7
7
  m as default
8
8
  };
@@ -1,9 +1,9 @@
1
- import { defineComponent as w, computed as f, onBeforeMount as E, watch as j, createElementBlock as v, openBlock as b, withModifiers as F, createElementVNode as M, unref as c, renderSlot as p, createCommentVNode as k, Fragment as V } from "vue";
2
- import { useStore as g } from "@tanstack/vue-form";
3
- import { getOmegaStore as B } from "./vue-components.es24.js";
4
- import { provideOmegaErrors as C } from "./vue-components.es8.js";
5
- import { useOmegaForm as I } from "./vue-components.es9.js";
6
- const $ = ["disabled"], N = /* @__PURE__ */ w({
1
+ import { defineComponent as M, getCurrentInstance as F, computed as c, watch as b, onBeforeMount as B, createElementBlock as v, openBlock as g, withModifiers as C, createElementVNode as I, unref as m, renderSlot as d, createCommentVNode as L, Fragment as V } from "vue";
2
+ import { useStore as O } from "@tanstack/vue-form";
3
+ import { getOmegaStore as k } from "./vue-components.es24.js";
4
+ import { provideOmegaErrors as $ } from "./vue-components.es8.js";
5
+ import { useOmegaForm as A } from "./vue-components.es9.js";
6
+ const K = ["disabled"], W = /* @__PURE__ */ M({
7
7
  __name: "OmegaWrapper",
8
8
  props: {
9
9
  omegaConfig: {},
@@ -15,99 +15,113 @@ const $ = ["disabled"], N = /* @__PURE__ */ w({
15
15
  asyncDebounceMs: {},
16
16
  validators: {},
17
17
  onSubmitMeta: {},
18
- onSubmitInvalid: { type: Function },
18
+ onSubmitInvalid: {},
19
19
  transform: {},
20
- onSubmit: { type: Function },
21
20
  form: {},
22
- schema: {}
21
+ schema: {},
22
+ isLoading: { type: Boolean, default: void 0 },
23
+ onSubmit: {}
23
24
  },
24
- setup(O) {
25
- const o = O, m = f(() => {
26
- if (!(o.form || !o.schema))
27
- return I(o.schema, o, o.omegaConfig);
28
- }), t = f(() => o.form ?? m.value);
29
- E(() => {
25
+ setup(S) {
26
+ const o = S, h = F(), y = c(
27
+ () => ({ value: e }) => {
28
+ new Promise((r) => {
29
+ h.emit("submit", e);
30
+ const n = b(() => o.isLoading, (t) => {
31
+ t || (r(), n.stop());
32
+ });
33
+ });
34
+ }
35
+ ), u = o.form || !o.schema ? void 0 : A(
36
+ o.schema,
37
+ {
38
+ ...o,
39
+ onSubmit: typeof o.isLoading < "u" ? y.value : o.onSubmit
40
+ },
41
+ o.omegaConfig
42
+ ), s = c(() => o.form ?? u);
43
+ B(() => {
30
44
  if (!o.form) return;
31
- const e = Object.keys(o.form.options || {}), s = /* @__PURE__ */ new Set([
45
+ const e = Object.keys(o.form.options || {}), r = /* @__PURE__ */ new Set([
32
46
  "omegaConfig",
33
47
  "subscribe",
34
48
  "showErrorsOn",
35
49
  "asyncAlways",
36
50
  "form",
37
51
  "schema"
38
- ]), i = Object.fromEntries(
52
+ ]), n = Object.fromEntries(
39
53
  Object.entries(o).filter(
40
- ([a, u]) => !s.has(a) && u !== void 0
54
+ ([a, f]) => a === "isLoading" ? !1 : !r.has(a) && f !== void 0
41
55
  )
42
- ), r = Object.keys(i), n = e.filter(
43
- (a) => r.includes(a) && i[a] !== void 0
56
+ ), t = Object.keys(n), i = e.filter(
57
+ (a) => t.includes(a) && n[a] !== void 0
44
58
  );
45
- n.length > 0 && console.warn(
59
+ i.length > 0 && console.warn(
46
60
  `[OmegaWrapper] Overlapping keys found between form options and filtered props:
47
- ${n.join(
61
+ ${i.join(
48
62
  `,
49
63
  `
50
64
  )}.
51
65
  Props will overwrite existing form options. This might indicate a configuration issue.`
52
66
  );
53
- const S = {
54
- ...t.value.options,
55
- ...i
67
+ const j = {
68
+ ...s.value.options,
69
+ ...n
56
70
  };
57
- t.value.options = Object.fromEntries(
71
+ s.value.options = Object.fromEntries(
58
72
  // TODO
59
- Object.entries(S).filter(
60
- ([a, u]) => u !== void 0
73
+ Object.entries(j).filter(
74
+ ([a, f]) => f !== void 0
61
75
  )
62
76
  );
63
77
  });
64
- const h = g(
65
- t.value.store,
78
+ const w = O(
79
+ s.value.store,
66
80
  (e) => e.isSubmitting
67
- ), d = B(
68
- t.value,
81
+ ), p = k(
82
+ s.value,
69
83
  o.subscribe
70
- ), y = g(
71
- t.value.store,
84
+ ), E = O(
85
+ s.value.store,
72
86
  (e) => e.submissionAttempts
73
- ), l = f(() => t.value.useStore((e) => e.errors));
74
- return j(
75
- () => [t.value.filterItems, l.value.value],
87
+ ), l = c(() => s.value.useStore((e) => e.errors));
88
+ return b(
89
+ () => [s.value.filterItems, l.value.value],
76
90
  () => {
77
- const e = t.value.filterItems, s = l.value.value;
78
- return e ? s ? (Object.values(s).filter(
79
- (r) => !!r
91
+ const e = s.value.filterItems, r = l.value.value;
92
+ return e ? r ? (Object.values(r).filter(
93
+ (t) => !!t
80
94
  ).flatMap(
81
- (r) => Object.values(r).flat().map((n) => n.message)
82
- ).some((r) => r === e.message) && e.items.forEach((r) => {
83
- const n = t.value.getFieldMeta(r);
84
- n && t.value.setFieldMeta(r, {
85
- ...n,
95
+ (t) => Object.values(t).flat().map((i) => i.message)
96
+ ).some((t) => t === e.message) && e.items.forEach((t) => {
97
+ const i = s.value.getFieldMeta(t);
98
+ i && s.value.setFieldMeta(t, {
99
+ ...i,
86
100
  errorMap: {
87
101
  onSubmit: [
88
- { path: [r], message: e.message }
102
+ { path: [t], message: e.message }
89
103
  ]
90
104
  }
91
105
  });
92
106
  }), {}) : {} : {};
93
107
  }
94
- ), C(y, l.value, o.showErrorsOn), (e, s) => (b(), v("form", {
108
+ ), $(E, l.value, o.showErrorsOn), (e, r) => (g(), v("form", {
95
109
  novalidate: "",
96
- onSubmit: s[0] || (s[0] = F((i) => t.value.handleSubmit(), ["prevent", "stop"]))
110
+ onSubmit: r[0] || (r[0] = C((n) => s.value.handleSubmit(), ["prevent", "stop"]))
97
111
  }, [
98
- M("fieldset", { disabled: c(h) }, [
99
- o.form ? (b(), v(V, { key: 0 }, [
100
- p(e.$slots, "externalForm", { subscribedValues: c(d) }, void 0, !0),
101
- p(e.$slots, "default", {}, void 0, !0)
102
- ], 64)) : m.value ? p(e.$slots, "internalForm", {
112
+ I("fieldset", { disabled: m(w) }, [
113
+ o.form ? (g(), v(V, { key: 0 }, [
114
+ d(e.$slots, "externalForm", { subscribedValues: m(p) }, void 0, !0),
115
+ d(e.$slots, "default", {}, void 0, !0)
116
+ ], 64)) : m(u) ? d(e.$slots, "internalForm", {
103
117
  key: 1,
104
- form: m.value,
105
- subscribedValues: c(d)
106
- }, void 0, !0) : k("", !0)
107
- ], 8, $)
118
+ form: m(u),
119
+ subscribedValues: m(p)
120
+ }, void 0, !0) : L("", !0)
121
+ ], 8, K)
108
122
  ], 32));
109
123
  }
110
124
  });
111
125
  export {
112
- N as default
126
+ W as default
113
127
  };
@@ -1,4 +1,4 @@
1
- import { isFunction as c } from "./vue-components.es25.js";
1
+ import { isFunction as c } from "./vue-components.es23.js";
2
2
  const s = c, t = (o) => typeof o == "object" && o !== null, i = (o) => t(o) || s(o);
3
3
  export {
4
4
  s as isFunction,
@@ -1,92 +1,4 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var i=document.createElement("style");if(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;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),document.head.appendChild(i),window.customElements){const e=window.customElements.define;window.customElements.define=function(s,t){const n=t.prototype.connectedCallback;return t.prototype.connectedCallback=function(){if(n&&n.call(this),this.shadowRoot){const a=document.createElement("style");a.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;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),this.shadowRoot.appendChild(a)}},e.call(window.customElements,s,t)}}}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
2
- import { defineComponent as w, getCurrentInstance as x, useId as C, computed as a, watch as f, nextTick as N, onMounted as d, ref as $, watchEffect as k, renderSlot as B, normalizeProps as I, guardReactiveProps as O, createElementVNode as _, normalizeClass as q, createBlock as L, createCommentVNode as P, unref as F, openBlock as S, mergeProps as T } from "vue";
3
- import { useStore as z } from "@tanstack/vue-form";
4
- import { useOmegaErrors as A } from "./vue-components.es8.js";
5
- import D from "./vue-components.es27.js";
6
-
7
- const J = /* @__PURE__ */ w({
8
- inheritAttrs: !1,
9
- __name: "OmegaInternalInput",
10
- props: {
11
- field: {},
12
- meta: {},
13
- label: {},
14
- options: {},
15
- type: {},
16
- validators: {}
17
- },
18
- setup(c) {
19
- const e = c, v = x()?.appContext.components.VTextField, l = C(), o = e.field, r = z(o.store, (t) => t), m = a(() => e.type ? e.type : e.meta?.type === "string" ? e.meta.format === "email" ? "email" : "string" : e.meta?.type || "unknown"), n = a(() => r.value.value), g = a(
20
- () => (
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- r.value.meta.errors.map((t) => t?.message).filter(Boolean)
23
- )
24
- ), y = (t) => t == null || t === !1 || t === "" || Number.isNaN(t);
25
- f(
26
- () => !!n.value,
27
- () => {
28
- y(n.value) && e.meta?.type !== "boolean" && N(() => {
29
- o.setValue(
30
- e.meta?.nullableOrUndefined === "undefined" ? void 0 : null
31
- );
32
- });
33
- }
34
- ), d(() => {
35
- !n.value && !e.meta?.required && e.meta?.nullableOrUndefined === "null" && o.setValue(null);
36
- });
37
- const { addError: h, removeError: b, showErrors: E, showErrorsOn: V } = A(), s = $(!1);
38
- k(() => {
39
- (E.value || V === "onChange") && (s.value = !0);
40
- });
41
- const u = () => {
42
- s.value = !0;
43
- };
44
- d(() => {
45
- n.value && u();
46
- });
47
- const p = a(() => !s.value && m.value !== "select" ? [] : g.value);
48
- f(
49
- () => r.value.meta.errors,
50
- () => {
51
- r.value.meta.errors.length ? h({
52
- inputId: l,
53
- errors: r.value.meta.errors.map((t) => t.message).filter(Boolean),
54
- label: e.label
55
- }) : b(l);
56
- }
57
- );
58
- const i = a(() => ({
59
- id: l,
60
- required: e.meta?.required,
61
- minLength: e.meta?.type === "string" && e.meta?.minLength,
62
- maxLength: e.meta?.type === "string" && e.meta?.maxLength,
63
- max: e.meta?.type === "number" && e.meta?.maximum,
64
- min: e.meta?.type === "number" && e.meta?.minimum,
65
- name: e.field.name,
66
- modelValue: e.field.state.value,
67
- errorMessages: p.value,
68
- error: !!p.value.length,
69
- field: e.field,
70
- setRealDirty: u,
71
- type: m.value,
72
- label: `${e.label}${e.meta?.required ? " *" : ""}`,
73
- options: e.options
74
- }));
75
- return (t, R) => B(t.$slots, "default", I(O(i.value)), () => [
76
- _("div", {
77
- class: q(t.$attrs.class),
78
- onFocusout: u
79
- }, [
80
- F(v) ? (S(), L(D, T({
81
- key: 0,
82
- "input-props": i.value
83
- }, t.$attrs, {
84
- "vuetify-value": i.value.field.state.value
85
- }), null, 16, ["input-props", "vuetify-value"])) : P("", !0)
86
- ], 34)
87
- ]);
88
- }
89
- });
1
+ const o = (n) => typeof n == "function";
90
2
  export {
91
- J as default
3
+ o as isFunction
92
4
  };
@@ -1,4 +1,92 @@
1
- const o = (n) => typeof n == "function";
1
+ (function(){"use strict";try{if(typeof document<"u"){var i=document.createElement("style");if(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;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),document.head.appendChild(i),window.customElements){const e=window.customElements.define;window.customElements.define=function(s,t){const n=t.prototype.connectedCallback;return t.prototype.connectedCallback=function(){if(n&&n.call(this),this.shadowRoot){const a=document.createElement("style");a.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;appearance:none;box-shadow:none;display:block;min-width:auto;height:auto;padding:.5em .5em .5em 1em}")),this.shadowRoot.appendChild(a)}},e.call(window.customElements,s,t)}}}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
2
+ import { defineComponent as w, getCurrentInstance as x, useId as C, computed as a, watch as f, nextTick as N, onMounted as d, ref as $, watchEffect as k, renderSlot as B, normalizeProps as I, guardReactiveProps as O, createElementVNode as _, normalizeClass as q, createBlock as L, createCommentVNode as P, unref as F, openBlock as S, mergeProps as T } from "vue";
3
+ import { useStore as z } from "@tanstack/vue-form";
4
+ import { useOmegaErrors as A } from "./vue-components.es8.js";
5
+ import D from "./vue-components.es27.js";
6
+
7
+ const J = /* @__PURE__ */ w({
8
+ inheritAttrs: !1,
9
+ __name: "OmegaInternalInput",
10
+ props: {
11
+ field: {},
12
+ meta: {},
13
+ label: {},
14
+ options: {},
15
+ type: {},
16
+ validators: {}
17
+ },
18
+ setup(c) {
19
+ const e = c, v = x()?.appContext.components.VTextField, l = C(), o = e.field, r = z(o.store, (t) => t), m = a(() => e.type ? e.type : e.meta?.type === "string" ? e.meta.format === "email" ? "email" : "string" : e.meta?.type || "unknown"), n = a(() => r.value.value), g = a(
20
+ () => (
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ r.value.meta.errors.map((t) => t?.message).filter(Boolean)
23
+ )
24
+ ), y = (t) => t == null || t === !1 || t === "" || Number.isNaN(t);
25
+ f(
26
+ () => !!n.value,
27
+ () => {
28
+ y(n.value) && e.meta?.type !== "boolean" && N(() => {
29
+ o.setValue(
30
+ e.meta?.nullableOrUndefined === "undefined" ? void 0 : null
31
+ );
32
+ });
33
+ }
34
+ ), d(() => {
35
+ !n.value && !e.meta?.required && e.meta?.nullableOrUndefined === "null" && o.setValue(null);
36
+ });
37
+ const { addError: h, removeError: b, showErrors: E, showErrorsOn: V } = A(), s = $(!1);
38
+ k(() => {
39
+ (E.value || V === "onChange") && (s.value = !0);
40
+ });
41
+ const u = () => {
42
+ s.value = !0;
43
+ };
44
+ d(() => {
45
+ n.value && u();
46
+ });
47
+ const p = a(() => !s.value && m.value !== "select" ? [] : g.value);
48
+ f(
49
+ () => r.value.meta.errors,
50
+ () => {
51
+ r.value.meta.errors.length ? h({
52
+ inputId: l,
53
+ errors: r.value.meta.errors.map((t) => t.message).filter(Boolean),
54
+ label: e.label
55
+ }) : b(l);
56
+ }
57
+ );
58
+ const i = a(() => ({
59
+ id: l,
60
+ required: e.meta?.required,
61
+ minLength: e.meta?.type === "string" && e.meta?.minLength,
62
+ maxLength: e.meta?.type === "string" && e.meta?.maxLength,
63
+ max: e.meta?.type === "number" && e.meta?.maximum,
64
+ min: e.meta?.type === "number" && e.meta?.minimum,
65
+ name: e.field.name,
66
+ modelValue: e.field.state.value,
67
+ errorMessages: p.value,
68
+ error: !!p.value.length,
69
+ field: e.field,
70
+ setRealDirty: u,
71
+ type: m.value,
72
+ label: `${e.label}${e.meta?.required ? " *" : ""}`,
73
+ options: e.options
74
+ }));
75
+ return (t, R) => B(t.$slots, "default", I(O(i.value)), () => [
76
+ _("div", {
77
+ class: q(t.$attrs.class),
78
+ onFocusout: u
79
+ }, [
80
+ F(v) ? (S(), L(D, T({
81
+ key: 0,
82
+ "input-props": i.value
83
+ }, t.$attrs, {
84
+ "vuetify-value": i.value.field.state.value
85
+ }), null, 16, ["input-props", "vuetify-value"])) : P("", !0)
86
+ ], 34)
87
+ ]);
88
+ }
89
+ });
2
90
  export {
3
- o as isFunction
91
+ J as default
4
92
  };
@@ -1,4 +1,4 @@
1
- import f from "./vue-components.es23.js";
1
+ import f from "./vue-components.es25.js";
2
2
  export {
3
3
  f as default
4
4
  };
@@ -1,6 +1,6 @@
1
1
  import { defineComponent as d, inject as f, computed as r, createBlock as n, openBlock as m, resolveDynamicComponent as c, withCtx as l, createCommentVNode as v, mergeProps as y, renderSlot as g, normalizeProps as h, guardReactiveProps as b } from "vue";
2
2
  import { generateInputStandardSchemaFromFieldMeta as C } from "./vue-components.es10.js";
3
- import F from "./vue-components.es23.js";
3
+ import F from "./vue-components.es25.js";
4
4
  const P = /* @__PURE__ */ d({
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.15.29",
3
+ "version": "0.17.0",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "@tanstack/vue-form": "1.2.4",
@@ -53,8 +53,8 @@
53
53
  "dependencies": {
54
54
  "highlight.js": "^11.11.1",
55
55
  "vue3-highlightjs": "^1.0.5",
56
- "@effect-app/vue": "2.54.4",
57
- "effect-app": "3.2.4"
56
+ "effect-app": "3.2.4",
57
+ "@effect-app/vue": "2.54.4"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "pnpm build:run",
@@ -66,20 +66,20 @@
66
66
  */
67
67
  /* eslint-disable @typescript-eslint/no-explicit-any */
68
68
  import { type StandardSchemaV1Issue, useStore } from "@tanstack/vue-form"
69
- import { type S } from "effect-app"
70
- import { computed, onBeforeMount, watch } from "vue"
69
+ import { type Record, type S } from "effect-app"
70
+ import { computed, type ComputedRef, getCurrentInstance, onBeforeMount, watch } from "vue"
71
71
  import { getOmegaStore } from "./getOmegaStore"
72
72
  import { provideOmegaErrors } from "./OmegaErrorsContext"
73
73
  import { type FilterItems, type FormProps, type OmegaFormApi, type OmegaFormState, type ShowErrorsOn } from "./OmegaFormStuff"
74
74
  import { type OmegaConfig, type OmegaFormReturn, useOmegaForm } from "./useOmegaForm"
75
75
 
76
- const props = defineProps<
76
+ type OmegaWrapperProps =
77
77
  & {
78
78
  omegaConfig?: OmegaConfig<From>
79
79
  subscribe?: K[]
80
80
  showErrorsOn?: ShowErrorsOn
81
81
  }
82
- & FormProps<From, To>
82
+ & Omit<FormProps<From, To>, "onSubmit">
83
83
  & (
84
84
  | {
85
85
  form: OmegaFormReturn<From, To>
@@ -90,16 +90,55 @@ const props = defineProps<
90
90
  schema: S.Schema<To, From, never>
91
91
  }
92
92
  )
93
- >()
93
+ & (
94
+ | {
95
+ isLoading?: undefined
96
+ onSubmit?: FormProps<From, To>["onSubmit"]
97
+ }
98
+ | {
99
+ isLoading: boolean
100
+ onSubmit: (data: To) => void
101
+ }
102
+ )
94
103
 
95
- const localForm = computed(() => {
96
- if (props.form || !props.schema) {
97
- return undefined
98
- }
99
- return useOmegaForm<From, To>(props.schema, props, props.omegaConfig)
104
+ const props = withDefaults(defineProps<OmegaWrapperProps>(), {
105
+ isLoading: undefined
100
106
  })
101
107
 
102
- const formToUse = computed(() => props.form ?? localForm.value!)
108
+ const instance = getCurrentInstance()
109
+
110
+ // we prefer to use the standard abstraction in Vue which separates props (going down) and event emits (going back up)
111
+ // so if isLoading + @submit are provided, we wrap them into a Promise, so that TanStack Form can properly track the submitting state.
112
+ // we use this approach because it means we can keep relying on the built-in beaviour of TanStack Form, and we dont have to re-implement/keep in sync/break any internals.
113
+ const eventOnSubmit: ComputedRef<FormProps<From, To>["onSubmit"]> = computed(
114
+ () => ({ value }) => {
115
+ new Promise<void>((resolve) => {
116
+ instance!.emit("submit", value)
117
+ // even if the emit would be immediately handled, prop changes are not published/received immediately.
118
+ // so we have to wait for the prop to change to true, and back to false again.
119
+ const handle = watch(() => props.isLoading, (v) => {
120
+ if (v) return
121
+ resolve()
122
+ handle.stop()
123
+ })
124
+ })
125
+ }
126
+ )
127
+
128
+ const localForm = props.form || !props.schema
129
+ ? undefined
130
+ : useOmegaForm<From, To>(
131
+ props.schema,
132
+ {
133
+ ...props,
134
+ onSubmit: typeof props.isLoading !== "undefined"
135
+ ? eventOnSubmit.value
136
+ : props.onSubmit
137
+ },
138
+ props.omegaConfig
139
+ )
140
+
141
+ const formToUse = computed(() => props.form ?? localForm!)
103
142
 
104
143
  onBeforeMount(() => {
105
144
  if (!props.form) return
@@ -116,17 +155,22 @@ onBeforeMount(() => {
116
155
 
117
156
  const filteredProps = Object.fromEntries(
118
157
  Object.entries(props).filter(
119
- ([key, value]) =>
120
- !excludedKeys.has(key as keyof typeof props) && value !== undefined
158
+ ([key, value]) => {
159
+ if (key === "isLoading") {
160
+ return false
161
+ }
162
+ return !excludedKeys.has(key as keyof typeof props)
163
+ && value !== undefined
164
+ }
121
165
  )
122
- ) as Partial<typeof props>
166
+ ) as Record<string, unknown>
123
167
 
124
168
  const propsKeys = Object.keys(filteredProps)
125
169
 
126
170
  const overlappingKeys = formOptionsKeys.filter(
127
171
  (key) =>
128
172
  propsKeys.includes(key)
129
- && filteredProps[key as keyof typeof props] !== undefined
173
+ && filteredProps[key] !== undefined
130
174
  )
131
175
 
132
176
  if (overlappingKeys.length > 0) {
@@ -227,5 +271,9 @@ defineSlots<{
227
271
  <style scoped>
228
272
  fieldset {
229
273
  display: contents;
274
+
275
+ &[disabled] > * {
276
+ pointer-events: none;
277
+ }
230
278
  }
231
279
  </style>