@effect-app/vue-components 0.7.6 → 0.8.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.
@@ -15,7 +15,7 @@ export type OmegaInputProps<From, To> = {
15
15
  }[];
16
16
  type?: TypeOverride;
17
17
  };
18
- export type TypeOverride = "string" | "text" | "number" | "select" | "multiple" | "boolean" | "autocomplete" | "autocompletemultiple" | "switch";
18
+ export type TypeOverride = "string" | "text" | "number" | "select" | "multiple" | "boolean" | "autocomplete" | "autocompletemultiple" | "switch" | "range";
19
19
  export interface OmegaError {
20
20
  label: string;
21
21
  inputId: string;
@@ -1,10 +1,10 @@
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 { defineComponent as B, getCurrentInstance as L, useId as P, computed as n, watch as w, nextTick as S, onMounted as x, ref as T, watchEffect as z, renderSlot as A, normalizeProps as D, guardReactiveProps as F, createElementVNode as M, normalizeClass as N, createBlock as R, createCommentVNode as U, unref as j, openBlock as G, mergeProps as H } from "vue";
2
+ import { defineComponent as q, getCurrentInstance as L, useId as P, computed as l, watch as w, nextTick as F, onMounted as x, ref as S, watchEffect as T, renderSlot as z, normalizeProps as A, guardReactiveProps as D, createElementVNode as M, normalizeClass as R, createBlock as U, createCommentVNode as Z, unref as j, openBlock as G, mergeProps as H } from "vue";
3
3
  import { useStore as J } from "@tanstack/vue-form";
4
4
  import { useOmegaErrors as K } from "./vue-components.es7.js";
5
5
  import Q from "./vue-components.es27.js";
6
6
 
7
- const te = /* @__PURE__ */ B({
7
+ const re = /* @__PURE__ */ q({
8
8
  inheritAttrs: !1,
9
9
  __name: "OmegaInternalInput",
10
10
  props: {
@@ -16,33 +16,33 @@ const te = /* @__PURE__ */ B({
16
16
  validators: {}
17
17
  },
18
18
  setup(C) {
19
- const e = C, o = L(), $ = o == null ? void 0 : o.appContext.components.VTextField, s = P(), u = e.field, a = J(u.store, (t) => t), d = 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
- }), i = n(() => a.value.value), k = n(
19
+ const t = C, o = L(), N = o == null ? void 0 : o.appContext.components.VTextField, s = P(), u = t.field, a = J(u.store, (e) => e), d = l(() => {
20
+ var e, r;
21
+ return t.type ? t.type : ((e = t.meta) == null ? void 0 : e.type) === "string" ? t.meta.format === "email" ? "email" : "string" : ((r = t.meta) == null ? void 0 : r.type) || "unknown";
22
+ }), i = l(() => a.value.value), $ = l(
23
23
  () => (
24
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)
25
+ a.value.meta.errors.map((e) => e == null ? void 0 : e.message).filter(Boolean)
26
26
  )
27
- );
27
+ ), k = (e) => e == null || e === !1 || e === "" || Number.isNaN(e);
28
28
  w(
29
29
  () => !!i.value,
30
- (t) => {
30
+ (e) => {
31
31
  var r;
32
- !t && ((r = e.meta) == null ? void 0 : r.type) !== "boolean" && S(() => {
33
- var l;
32
+ k(e) && ((r = t.meta) == null ? void 0 : r.type) !== "boolean" && F(() => {
33
+ var n;
34
34
  u.setValue(
35
- ((l = e.meta) == null ? void 0 : l.nullableOrUndefined) === "undefined" ? void 0 : null
35
+ ((n = t.meta) == null ? void 0 : n.nullableOrUndefined) === "undefined" ? void 0 : null
36
36
  );
37
37
  });
38
38
  }
39
39
  ), x(() => {
40
- var t, r;
41
- !i.value && !((t = e.meta) != null && t.required) && ((r = e.meta) == null ? void 0 : r.nullableOrUndefined) === "null" && u.setValue(null);
40
+ var e, r;
41
+ !i.value && !((e = t.meta) != null && e.required) && ((r = t.meta) == null ? void 0 : r.nullableOrUndefined) === "null" && u.setValue(null);
42
42
  });
43
- const { addError: I, removeError: O, showErrors: _, showErrorsOn: q } = K(), m = T(!1);
44
- z(() => {
45
- (_.value || q === "onChange") && (m.value = !0);
43
+ const { addError: B, removeError: I, showErrors: O, showErrorsOn: _ } = K(), m = S(!1);
44
+ T(() => {
45
+ (O.value || _ === "onChange") && (m.value = !0);
46
46
  });
47
47
  const p = () => {
48
48
  m.value = !0;
@@ -50,52 +50,52 @@ const te = /* @__PURE__ */ B({
50
50
  x(() => {
51
51
  i.value && p();
52
52
  });
53
- const c = n(() => !m.value && d.value !== "select" ? [] : k.value);
53
+ const c = l(() => !m.value && d.value !== "select" ? [] : $.value);
54
54
  w(
55
55
  () => a.value.meta.errors,
56
56
  () => {
57
- a.value.meta.errors.length ? I({
57
+ a.value.meta.errors.length ? B({
58
58
  inputId: s,
59
- errors: a.value.meta.errors.map((t) => t.message).filter(Boolean),
60
- label: e.label
61
- }) : O(s);
59
+ errors: a.value.meta.errors.map((e) => e.message).filter(Boolean),
60
+ label: t.label
61
+ }) : I(s);
62
62
  }
63
63
  );
64
- const f = n(() => {
65
- var t, r, l, v, g, y, h, b, E, V;
64
+ const f = l(() => {
65
+ var e, r, n, v, g, y, h, b, E, V;
66
66
  return {
67
67
  id: s,
68
- required: (t = e.meta) == null ? void 0 : t.required,
69
- minLength: ((r = e.meta) == null ? void 0 : r.type) === "string" && ((l = e.meta) == null ? void 0 : l.minLength),
70
- maxLength: ((v = e.meta) == null ? void 0 : v.type) === "string" && ((g = e.meta) == null ? void 0 : g.maxLength),
71
- max: ((y = e.meta) == null ? void 0 : y.type) === "number" && ((h = e.meta) == null ? void 0 : h.maximum),
72
- min: ((b = e.meta) == null ? void 0 : b.type) === "number" && ((E = e.meta) == null ? void 0 : E.minimum),
73
- name: e.field.name,
74
- modelValue: e.field.state.value,
68
+ required: (e = t.meta) == null ? void 0 : e.required,
69
+ minLength: ((r = t.meta) == null ? void 0 : r.type) === "string" && ((n = t.meta) == null ? void 0 : n.minLength),
70
+ maxLength: ((v = t.meta) == null ? void 0 : v.type) === "string" && ((g = t.meta) == null ? void 0 : g.maxLength),
71
+ max: ((y = t.meta) == null ? void 0 : y.type) === "number" && ((h = t.meta) == null ? void 0 : h.maximum),
72
+ min: ((b = t.meta) == null ? void 0 : b.type) === "number" && ((E = t.meta) == null ? void 0 : E.minimum),
73
+ name: t.field.name,
74
+ modelValue: t.field.state.value,
75
75
  errorMessages: c.value,
76
76
  error: !!c.value.length,
77
- field: e.field,
77
+ field: t.field,
78
78
  setRealDirty: p,
79
79
  type: d.value,
80
- label: `${e.label}${(V = e.meta) != null && V.required ? " *" : ""}`,
81
- options: e.options
80
+ label: `${t.label}${(V = t.meta) != null && V.required ? " *" : ""}`,
81
+ options: t.options
82
82
  };
83
83
  });
84
- return (t, r) => A(t.$slots, "default", D(F(f.value)), () => [
84
+ return (e, r) => z(e.$slots, "default", A(D(f.value)), () => [
85
85
  M("div", {
86
- class: N(t.$attrs.class),
86
+ class: R(e.$attrs.class),
87
87
  onFocusout: p
88
88
  }, [
89
- j($) ? (G(), R(Q, H({
89
+ j(N) ? (G(), U(Q, H({
90
90
  key: 0,
91
91
  "input-props": f.value
92
- }, t.$attrs, {
92
+ }, e.$attrs, {
93
93
  "vuetify-value": f.value.field.state.value
94
- }), null, 16, ["input-props", "vuetify-value"])) : U("", !0)
94
+ }), null, 16, ["input-props", "vuetify-value"])) : Z("", !0)
95
95
  ], 34)
96
96
  ]);
97
97
  }
98
98
  });
99
99
  export {
100
- te as default
100
+ re as default
101
101
  };
@@ -1,5 +1,5 @@
1
- import { defineComponent as d, resolveComponent as s, createElementBlock as P, openBlock as o, createBlock as n, createCommentVNode as l, resolveDynamicComponent as g, mergeProps as i } from "vue";
2
- const b = /* @__PURE__ */ d({
1
+ import { defineComponent as P, resolveComponent as s, createElementBlock as g, openBlock as o, createBlock as n, createCommentVNode as l, resolveDynamicComponent as u, mergeProps as i } from "vue";
2
+ const b = /* @__PURE__ */ P({
3
3
  inheritAttrs: !1,
4
4
  __name: "OmegaInputVuetify",
5
5
  props: {
@@ -9,13 +9,13 @@ const b = /* @__PURE__ */ d({
9
9
  emits: ["focus", "blur"],
10
10
  setup(y) {
11
11
  return (e, r) => {
12
- const u = s("v-text-field"), a = s("v-textarea"), t = s("v-select"), m = s("v-autocomplete");
13
- return o(), P("div", {
12
+ const a = s("v-text-field"), t = s("v-textarea"), m = s("v-select"), d = s("v-autocomplete");
13
+ return o(), g("div", {
14
14
  class: "omega-input",
15
15
  onFocusout: r[4] || (r[4] = (p) => e.$emit("blur", p)),
16
16
  onFocusin: r[5] || (r[5] = (p) => e.$emit("focus", p))
17
17
  }, [
18
- e.inputProps.type === "boolean" || e.inputProps.type === "switch" ? (o(), n(g(e.inputProps.type === "boolean" ? "v-checkbox" : "v-switch"), i({
18
+ e.inputProps.type === "boolean" || e.inputProps.type === "switch" ? (o(), n(u(e.inputProps.type === "boolean" ? "v-checkbox" : "v-switch"), i({
19
19
  key: 0,
20
20
  id: e.inputProps.id,
21
21
  name: e.inputProps.name,
@@ -27,7 +27,7 @@ const b = /* @__PURE__ */ d({
27
27
  "model-value": e.vuetifyValue,
28
28
  onChange: r[0] || (r[0] = (p) => e.inputProps.field.handleChange(p.target.checked))
29
29
  }), null, 16, ["id", "name", "label", "error-messages", "error", "model-value"])) : l("", !0),
30
- e.inputProps.type === "email" || e.inputProps.type === "string" ? (o(), n(u, i({
30
+ e.inputProps.type === "email" || e.inputProps.type === "string" ? (o(), n(a, i({
31
31
  key: 1,
32
32
  id: e.inputProps.id,
33
33
  required: e.inputProps.required,
@@ -42,7 +42,7 @@ const b = /* @__PURE__ */ d({
42
42
  "model-value": e.vuetifyValue,
43
43
  "onUpdate:modelValue": e.inputProps.field.handleChange
44
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(a, i({
45
+ e.inputProps.type === "text" ? (o(), n(t, i({
46
46
  key: 2,
47
47
  id: e.inputProps.id,
48
48
  required: e.inputProps.required,
@@ -57,7 +57,7 @@ const b = /* @__PURE__ */ d({
57
57
  "model-value": e.vuetifyValue,
58
58
  "onUpdate:modelValue": e.inputProps.field.handleChange
59
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(u, i({
60
+ e.inputProps.type === "number" || e.inputProps.type === "range" ? (o(), n(u(e.inputProps.type === "range" ? "v-slider" : "v-text-field"), i({
61
61
  key: 3,
62
62
  id: e.inputProps.id,
63
63
  required: e.inputProps.required,
@@ -74,7 +74,7 @@ const b = /* @__PURE__ */ d({
74
74
  e.inputProps.field.handleChange(Number(p));
75
75
  })
76
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(t, i({
77
+ e.inputProps.type === "select" || e.inputProps.type === "multiple" ? (o(), n(m, i({
78
78
  key: 4,
79
79
  id: e.inputProps.id,
80
80
  clearable: e.inputProps.type === "select",
@@ -91,7 +91,7 @@ const b = /* @__PURE__ */ d({
91
91
  onClear: r[2] || (r[2] = (p) => e.inputProps.field.handleChange(void 0)),
92
92
  "onUpdate:modelValue": e.inputProps.field.handleChange
93
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(m, i({
94
+ e.inputProps.type === "autocomplete" || e.inputProps.type === "autocompletemultiple" ? (o(), n(d, i({
95
95
  key: 5,
96
96
  id: e.inputProps.id,
97
97
  clearable: e.inputProps.type === "autocomplete",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "0.7.6",
3
+ "version": "0.8.0",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "@tanstack/vue-form": "^1.2.4",
@@ -39,6 +39,7 @@ export type TypeOverride =
39
39
  | "autocomplete"
40
40
  | "autocompletemultiple"
41
41
  | "switch"
42
+ | "range"
42
43
 
43
44
  export interface OmegaError {
44
45
  label: string
@@ -47,8 +47,9 @@
47
47
  :model-value="vuetifyValue"
48
48
  @update:model-value="inputProps.field.handleChange"
49
49
  />
50
- <v-text-field
51
- v-if="inputProps.type === 'number'"
50
+ <component
51
+ :is="inputProps.type === 'range' ? 'v-slider' : 'v-text-field'"
52
+ v-if="inputProps.type === 'number' || inputProps.type === 'range'"
52
53
  :id="inputProps.id"
53
54
  :required="inputProps.required"
54
55
  :min="inputProps.min"
@@ -71,12 +71,16 @@ const errors = computed(() =>
71
71
  fieldState.value.meta.errors.map((e: any) => e?.message).filter(Boolean),
72
72
  )
73
73
 
74
+ const isFalsyButNotZero = (value: unknown): boolean => {
75
+ return value == null || value === false || value === "" || Number.isNaN(value)
76
+ }
77
+
74
78
  // we remove value and errors when the field is empty and not required
75
79
  //watchEffect will trigger infinite times with both free fieldValue and errors, so bet to watch a stupid boolean
76
80
  watch(
77
81
  () => !!fieldValue.value,
78
82
  value => {
79
- if (!value && props.meta?.type !== "boolean") {
83
+ if (isFalsyButNotZero(value) && props.meta?.type !== "boolean") {
80
84
  nextTick(() => {
81
85
  fieldApi.setValue(
82
86
  props.meta?.nullableOrUndefined === "undefined" ? undefined : null,