@effect-app/vue-components 4.0.0-beta.319 → 4.0.0-beta.320

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.
@@ -1,7 +1,7 @@
1
1
  import { useIntl as e } from "./vue-components6.es.js";
2
2
  import { computed as t, h as n, onUnmounted as r, ref as i, watch as a } from "vue";
3
3
  //#region src/components/OmegaForm/errors.ts
4
- var o = (t) => {
4
+ var o = (e) => e.replace(/\[(\d+)\]/g, ".$1"), s = (t) => {
5
5
  let { formatMessage: n } = e(), r = (e) => e.replace(/([A-Z])/g, " $1").replace(/^./, (e) => e.toUpperCase()).trim(), i = (e) => n ? n({
6
6
  id: `general.fields.${e}`,
7
7
  defaultMessage: r(e)
@@ -10,30 +10,30 @@ var o = (t) => {
10
10
  id: `${t.i18nNamespace}.fields.${e}`,
11
11
  defaultMessage: i(e)
12
12
  }) : i(e);
13
- }, s = (e) => function(r) {
13
+ }, c = (e) => function(r) {
14
14
  return {
15
15
  setup() {
16
- let { fieldMap: n, form: r } = e, i = r.useStore((e) => e.errors), a = r.useStore((e) => e.fieldMeta), s = r.useStore((e) => e.errorMap), c = o(r);
16
+ let { fieldMap: n, form: r } = e, i = r.useStore((e) => e.errors), a = r.useStore((e) => e.fieldMeta), c = r.useStore((e) => e.errorMap), l = s(r);
17
17
  return {
18
18
  generalErrors: i,
19
19
  errors: t(() => {
20
20
  let e = Object.entries(a.value).reduce((e, [t, r]) => {
21
21
  let i = r?.errors ?? [];
22
22
  if (!i.length) return e;
23
- let a = n.value.get(t);
23
+ let a = n.value.get(o(t));
24
24
  return a && e.push({
25
25
  label: a.label,
26
26
  inputId: a.id,
27
27
  errors: [i[0]?.message].filter(Boolean)
28
28
  }), e;
29
- }, []), t = [], r = [s.value.onDynamic, s.value.onSubmit].filter(Boolean), i = /* @__PURE__ */ new Set();
29
+ }, []), t = [], r = [c.value.onDynamic, c.value.onSubmit].filter(Boolean), i = /* @__PURE__ */ new Set();
30
30
  for (let e of r) for (let [r, a] of Object.entries(e)) if (Array.isArray(a) && a.length) for (let e of a) {
31
31
  let r = e;
32
32
  if (r?.path && Array.isArray(r.path) && r.path.length) {
33
33
  let e = r.path.join(".");
34
34
  if (!n.value.has(e) && !i.has(e)) {
35
35
  i.add(e), t.push({
36
- label: c(e),
36
+ label: l(e),
37
37
  inputId: e,
38
38
  errors: [r.message].filter(Boolean)
39
39
  });
@@ -53,21 +53,22 @@ var o = (t) => {
53
53
  }, this.$slots);
54
54
  }
55
55
  };
56
- }, c = () => {
56
+ }, l = () => {
57
57
  let e = i(/* @__PURE__ */ new Map());
58
58
  return {
59
59
  fieldMap: e,
60
60
  registerField: (t) => {
61
61
  a(t, (t) => {
62
- e.value.set(t.name, {
62
+ e.value.set(o(t.name), {
63
63
  label: t.label,
64
64
  id: t.id
65
65
  });
66
66
  }, { immediate: !0 }), r(() => {
67
- e.value.get(t.value.name)?.id === t.value.id && e.value.delete(t.value.name);
67
+ let n = o(t.value.name);
68
+ e.value.get(n)?.id === t.value.id && e.value.delete(n);
68
69
  });
69
70
  }
70
71
  };
71
72
  };
72
73
  //#endregion
73
- export { s as eHoc, c as makeFieldMap, o as useErrorLabel };
74
+ export { c as eHoc, l as makeFieldMap, s as useErrorLabel };
@@ -1,6 +1,6 @@
1
- import { Fragment as e, computed as t, createBlock as n, createElementBlock as r, defineComponent as i, guardReactiveProps as a, mergeProps as o, normalizeProps as s, onMounted as c, openBlock as l, provide as u, renderList as d, renderSlot as f, resolveDynamicComponent as p, withCtx as m } from "vue";
1
+ import { Fragment as e, computed as t, createBlock as n, createElementBlock as r, defineComponent as i, guardReactiveProps as a, mergeProps as o, normalizeProps as s, onMounted as c, openBlock as l, renderList as u, renderSlot as d, resolveDynamicComponent as f, withCtx as p } from "vue";
2
2
  //#region src/components/OmegaForm/OmegaArray.vue?vue&type=script&setup=true&lang.ts
3
- var h = /*@__PURE__*/ i({
3
+ var m = /*@__PURE__*/ i({
4
4
  inheritAttrs: !1,
5
5
  __name: "OmegaArray",
6
6
  props: {
@@ -12,30 +12,27 @@ var h = /*@__PURE__*/ i({
12
12
  items: {}
13
13
  },
14
14
  setup(i) {
15
- let h = i, g = h.form.useStore((e) => e.values), _ = t(() => {
16
- let e = h.name.replace(/\[/g, ".").replace(/\]/g, "");
15
+ let m = i, h = m.form.useStore((e) => e.values), g = t(() => {
16
+ let e = m.name.replace(/\[/g, ".").replace(/\]/g, "");
17
17
  try {
18
- return e.split(".").reduce((e, t) => e && e[t], g.value);
18
+ return e.split(".").reduce((e, t) => e && e[t], h.value);
19
19
  } catch (e) {
20
20
  return console.error(e), [];
21
21
  }
22
22
  });
23
23
  return c(async () => {
24
- h.defaultItems && !_.value && h.form.setFieldValue(h.name, h.defaultItems);
25
- }), u("getMetaFromArray", t(() => (e) => {
26
- let t = e.replace(/\[\d+\]/g, "");
27
- return h.form.meta[t];
28
- })), (t, c) => (l(), n(p(i.form.Field), { name: i.name }, {
29
- default: m(({ field: c }) => [
30
- f(t.$slots, "pre-array", s(a({
24
+ m.defaultItems && !g.value && m.form.setFieldValue(m.name, m.defaultItems);
25
+ }), (t, c) => (l(), n(f(i.form.Field), { name: i.name }, {
26
+ default: p(({ field: c }) => [
27
+ d(t.$slots, "pre-array", s(a({
31
28
  field: c,
32
29
  state: c.state
33
30
  }))),
34
- (l(!0), r(e, null, d(_.value, (e, r) => (l(), n(p(i.form.Field), {
31
+ (l(!0), r(e, null, u(g.value, (e, r) => (l(), n(f(i.form.Field), {
35
32
  key: `${i.name}[${Number(r)}]`,
36
33
  name: `${i.name}[${Number(r)}]`
37
34
  }, {
38
- default: m(({ field: e }) => [f(t.$slots, "default", o({ ref_for: !0 }, {
35
+ default: p(({ field: e }) => [d(t.$slots, "default", o({ ref_for: !0 }, {
39
36
  subField: e,
40
37
  subState: e.state,
41
38
  index: Number(r),
@@ -43,15 +40,15 @@ var h = /*@__PURE__*/ i({
43
40
  }))]),
44
41
  _: 2
45
42
  }, 1032, ["name"]))), 128)),
46
- f(t.$slots, "post-array", s(a({
43
+ d(t.$slots, "post-array", s(a({
47
44
  field: c,
48
45
  state: c.state
49
46
  }))),
50
- f(t.$slots, "field", s(a({ field: c })))
47
+ d(t.$slots, "field", s(a({ field: c })))
51
48
  ]),
52
49
  _: 3
53
50
  }, 8, ["name"]));
54
51
  }
55
52
  });
56
53
  //#endregion
57
- export { h as default };
54
+ export { m as default };
@@ -27,7 +27,7 @@ var _ = /*@__PURE__*/ o({
27
27
  inputs: _.form.inputs
28
28
  })), y = n(() => _.name), b = h(), x = n(() => {
29
29
  if (_.inputClass !== null) return _.inputClass === void 0 ? b.class : _.inputClass;
30
- }), S = c("getMetaFromArray", null), C = n(() => S?.value && S.value(_.name) ? S.value(y.value) : _.form.meta[y.value]), w = e(_.form);
30
+ }), S = c("getMetaFromArray", null), C = n(() => S?.value?.(y.value) || (_.form.meta[y.value] ?? _.form.meta[y.value.replace(/\[\d+\]/g, "")])), w = e(_.form);
31
31
  return (e, n) => (d(), r(p(o.form.Field), {
32
32
  name: o.name,
33
33
  validators: o.validators
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "4.0.0-beta.319",
3
+ "version": "4.0.0-beta.320",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/effect-app/libs.git",
@@ -62,8 +62,8 @@
62
62
  "highlight.js": "^11.11.1",
63
63
  "mitt": "^3.0.1",
64
64
  "vue3-highlightjs": "^1.0.5",
65
- "@effect-app/vue": "4.0.0-beta.319",
66
- "effect-app": "4.0.0-beta.319"
65
+ "@effect-app/vue": "4.0.0-beta.320",
66
+ "effect-app": "4.0.0-beta.320"
67
67
  },
68
68
  "scripts": {
69
69
  "check": "vue-tsc",
@@ -44,7 +44,7 @@
44
44
  generic="From extends Record<PropertyKey, any>, To extends Record<PropertyKey, any>, Name extends DeepKeys<From>"
45
45
  >
46
46
  import { type DeepKeys } from "@tanstack/vue-form"
47
- import { computed, onMounted, provide } from "vue"
47
+ import { computed, onMounted } from "vue"
48
48
  import { type OmegaArrayProps } from "./types"
49
49
 
50
50
  const props = defineProps<OmegaArrayProps<From, To, Name>>()
@@ -73,17 +73,4 @@ onMounted(async () => {
73
73
  props.form.setFieldValue(props.name, props.defaultItems)
74
74
  }
75
75
  })
76
-
77
- const getMetaFromArray = computed(() => {
78
- const getMeta = (path: string) => {
79
- // Transform path like 'a[0].b[11].c' into 'a.b.c'
80
- const simplifiedPath = path.replace(/\[\d+\]/g, "")
81
-
82
- return props.form.meta[simplifiedPath as keyof typeof props.form.meta]
83
- }
84
-
85
- return getMeta
86
- })
87
-
88
- provide("getMetaFromArray", getMetaFromArray)
89
76
  </script>
@@ -85,10 +85,10 @@ const getMetaFromArray = inject<Ref<(name: string) => FieldMeta | null> | null>(
85
85
  )
86
86
 
87
87
  const meta = computed(() => {
88
- if (getMetaFromArray?.value && getMetaFromArray.value(props.name as DeepKeys<From>)) {
89
- return getMetaFromArray.value(propsName.value)
90
- }
88
+ const fromArray = getMetaFromArray?.value?.(propsName.value)
89
+ if (fromArray) return fromArray
91
90
  return props.form.meta[propsName.value]
91
+ ?? props.form.meta[propsName.value.replace(/\[\d+\]/g, "") as DeepKeys<From>]
92
92
  })
93
93
 
94
94
  const errori18n = useErrorLabel(props.form)
@@ -5,6 +5,8 @@ import { useIntl } from "../../utils"
5
5
  import type { OmegaError } from "./types"
6
6
  import type { OF } from "./useOmegaForm"
7
7
 
8
+ const normalizePath = (path: string) => path.replace(/\[(\d+)\]/g, ".$1")
9
+
8
10
  export const useErrorLabel = (form: OF<any, any>) => {
9
11
  const { formatMessage } = useIntl()
10
12
  const humanize = (str: string) => {
@@ -49,7 +51,7 @@ export const eHoc = (errorProps: {
49
51
  return acc
50
52
  }
51
53
 
52
- const fieldInfo = fieldMap.value.get(key)
54
+ const fieldInfo = fieldMap.value.get(normalizePath(key))
53
55
  if (!fieldInfo) {
54
56
  return acc
55
57
  }
@@ -120,15 +122,16 @@ export const makeFieldMap = () => {
120
122
  const fieldMap = ref(new Map<string, { label: string; id: string }>())
121
123
  const registerField = (field: ComputedRef<{ name: string; label: string; id: string }>) => {
122
124
  watch(field, (f) => {
123
- fieldMap.value.set(f.name, { label: f.label, id: f.id })
125
+ fieldMap.value.set(normalizePath(f.name), { label: f.label, id: f.id })
124
126
  }, { immediate: true })
125
127
  onUnmounted(() => {
126
128
  // Only delete if we still own this entry (id matches)
127
129
  // This prevents old components from deleting entries registered by new components
128
130
  // during re-mount transitions (e.g., when :key changes)
129
- const currentEntry = fieldMap.value.get(field.value.name)
131
+ const path = normalizePath(field.value.name)
132
+ const currentEntry = fieldMap.value.get(path)
130
133
  if (currentEntry?.id === field.value.id) {
131
- fieldMap.value.delete(field.value.name)
134
+ fieldMap.value.delete(path)
132
135
  }
133
136
  })
134
137
  }