@effect-app/vue-components 0.7.2 → 0.7.4

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,6 +1,9 @@
1
1
  import { type OmegaInputProps } from "./OmegaFormStuff";
2
- declare const _default: <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<{
3
- props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & Omit<OmegaInputProps<From, To>, "type" | "validators" | "label" | "options"> & Partial<{}>> & import("vue").PublicProps;
2
+ import { type DeepValue, type DeepKeys } from "@tanstack/vue-form";
3
+ declare const _default: <T>(__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<{
4
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, never>, never> & (Omit<OmegaInputProps<T, T>, "type" | "validators" | "items" | "label" | "options"> & {
5
+ items?: DeepValue<T, DeepKeys<T>>;
6
+ }) & Partial<{}>> & import("vue").PublicProps;
4
7
  expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
5
8
  attrs: any;
6
9
  slots: {
@@ -85,7 +85,7 @@ export type FilterItems = {
85
85
  readonly message: string | Effect.Effect<string>;
86
86
  };
87
87
  };
88
- type CreateMeta = {
88
+ export type CreateMeta = {
89
89
  parent?: string;
90
90
  meta?: Record<string, any>;
91
91
  nullableOrUndefined?: false | "undefined" | "null";
@@ -107,4 +107,3 @@ export declare const generateInputStandardSchemaFromFieldMeta: (meta: FieldMeta)
107
107
  export declare const nullableInput: <A, I, R>(schema: S.Schema<A, I, R>, defaultValue: () => A) => S.transform<import("effect/Schema").NullOr<S.Schema<A, I, R>> & {
108
108
  withDefault: S.PropertySignature<":", A | null, never, ":", I | null, true, R>;
109
109
  }, S.SchemaClass<A, A, never>>;
110
- export {};
@@ -1,52 +1,67 @@
1
- import { defineComponent as c, computed as g, provide as M, createBlock as m, openBlock as s, resolveDynamicComponent as u, withCtx as i, createElementBlock as _, renderSlot as l, Fragment as h, renderList as k, mergeProps as v, normalizeProps as F, guardReactiveProps as S } from "vue";
2
- import { createMeta as A } from "./vue-components.es9.js";
3
- const C = /* @__PURE__ */ c({
1
+ import { defineComponent as c, onMounted as g, watch as M, computed as F, provide as h, createBlock as p, openBlock as m, resolveDynamicComponent as i, withCtx as l, createElementBlock as _, renderSlot as u, Fragment as k, renderList as v, mergeProps as A, normalizeProps as S, guardReactiveProps as $ } from "vue";
2
+ import { createMeta as B } from "./vue-components.es9.js";
3
+ const w = /* @__PURE__ */ c({
4
4
  inheritAttrs: !1,
5
5
  __name: "OmegaArray",
6
6
  props: {
7
7
  form: {},
8
- name: {}
8
+ name: {},
9
+ items: {}
9
10
  },
10
11
  setup(f) {
11
- const p = f, d = g(() => {
12
- const e = p.form.meta[p.name];
12
+ const r = f;
13
+ g(() => {
14
+ r.items && r.form.setFieldValue(r.name, r.items);
15
+ }), M(
16
+ () => r.items,
17
+ async (e) => {
18
+ e && r.form.setFieldValue(r.name, e);
19
+ }
20
+ );
21
+ const d = F(() => {
22
+ const e = r.form.meta[r.name];
13
23
  if (e && e.type === "multiple") {
14
- const n = e.rest.reduce(
15
- (t, r) => (r.type._tag === "TypeLiteral" && t.propertySignatures.push(...r.type.propertySignatures), t),
16
- {
17
- propertySignatures: []
18
- }
19
- ), a = A(n);
24
+ const o = e.rest.reduce((t, a) => a.type._tag === "TypeLiteral" ? {
25
+ ...t,
26
+ propertySignatures: [
27
+ ...t.propertySignatures || [],
28
+ ...a.type.propertySignatures
29
+ ]
30
+ } : {
31
+ ...t,
32
+ property: a.type
33
+ }, {}), n = B({ ...o, meta: e });
20
34
  return (t) => {
21
- const r = t.split("]."), o = r[r.length - 1];
22
- return a[o];
35
+ if (t.endsWith("]")) return n;
36
+ const a = t.split("]."), s = a[a.length - 1];
37
+ return n[s];
23
38
  };
24
39
  }
25
- return (n) => {
40
+ return (o) => {
26
41
  };
27
42
  });
28
- return M("getMetaFromArray", d), (e, n) => (s(), m(u(e.form.Field), { name: e.name }, {
29
- default: i(({ field: a }) => [
30
- (s(!0), _(h, null, k(a.state.value, (y, t) => (s(), m(u(e.form.Field), {
43
+ return h("getMetaFromArray", d), (e, o) => (m(), p(i(e.form.Field), { name: e.name }, {
44
+ default: l(({ field: n }) => [
45
+ (m(!0), _(k, null, v(n.state.value, (y, t) => (m(), p(i(e.form.Field), {
31
46
  key: t,
32
47
  name: `${e.name}[${t}]`
33
48
  }, {
34
- default: i(({ field: r, state: o }) => [
35
- l(e.$slots, "default", v({ ref_for: !0 }, {
36
- field: a,
37
- subField: r,
38
- subState: o,
49
+ default: l(({ field: a, state: s }) => [
50
+ u(e.$slots, "default", A({ ref_for: !0 }, {
51
+ field: n,
52
+ subField: a,
53
+ subState: s,
39
54
  index: t
40
55
  }))
41
56
  ]),
42
57
  _: 2
43
58
  }, 1032, ["name"]))), 128)),
44
- l(e.$slots, "field", F(S({ field: a })))
59
+ u(e.$slots, "field", S($({ field: n })))
45
60
  ]),
46
61
  _: 3
47
62
  }, 8, ["name"]));
48
63
  }
49
64
  });
50
65
  export {
51
- C as default
66
+ w as default
52
67
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "@tanstack/vue-form": "^1.2.4",
@@ -23,37 +23,65 @@
23
23
  </component>
24
24
  </template>
25
25
 
26
- <script setup lang="ts" generic="From, To">
27
- import { computed, provide } from "vue"
28
- import { type OmegaInputProps, createMeta } from "./OmegaFormStuff"
29
- import { type S } from "effect-app"
26
+ <script setup lang="ts" generic="T">
27
+ import { computed, onMounted, provide, watch } from "vue"
28
+ import {
29
+ type CreateMeta,
30
+ type OmegaInputProps,
31
+ createMeta,
32
+ } from "./OmegaFormStuff"
33
+ import { type DeepValue, type DeepKeys } from "@tanstack/vue-form"
30
34
 
31
- const props =
32
- defineProps<
33
- Omit<OmegaInputProps<From, To>, "validators" | "options" | "label" | "type">
34
- >()
35
+ const props = defineProps<
36
+ Omit<
37
+ OmegaInputProps<T, T>,
38
+ "validators" | "options" | "label" | "type" | "items"
39
+ > & {
40
+ items?: DeepValue<T, DeepKeys<T>>
41
+ }
42
+ >()
35
43
 
36
44
  defineOptions({
37
45
  inheritAttrs: false,
38
46
  })
39
47
 
48
+ onMounted(() => {
49
+ if (props.items) {
50
+ props.form.setFieldValue(props.name, props.items)
51
+ }
52
+ })
53
+
54
+ watch(
55
+ () => props.items,
56
+ async items => {
57
+ if (items) {
58
+ props.form.setFieldValue(props.name, items)
59
+ }
60
+ },
61
+ )
62
+
40
63
  const getMetaFromArray = computed(() => {
41
64
  const inputMeta = props.form.meta[props.name]
42
65
  if (inputMeta && inputMeta.type === "multiple") {
43
- const propertySignatures = inputMeta.rest.reduce(
44
- (acc, curr) => {
45
- if (curr.type._tag === "TypeLiteral") {
46
- acc.propertySignatures.push(...curr.type.propertySignatures)
47
- }
48
- return acc
49
- },
50
- {
51
- propertySignatures: [],
52
- } as { propertySignatures: S.AST.PropertySignature[] },
53
- )
66
+ const result = inputMeta.rest.reduce<CreateMeta>((acc, curr) => {
67
+ if (curr.type._tag === "TypeLiteral") {
68
+ return {
69
+ ...acc,
70
+ propertySignatures: [
71
+ ...(acc.propertySignatures || []),
72
+ ...curr.type.propertySignatures,
73
+ ],
74
+ } as CreateMeta
75
+ }
76
+ return {
77
+ ...acc,
78
+ property: curr.type,
79
+ } as CreateMeta
80
+ }, {} as CreateMeta)
54
81
 
55
- const arrayMeta = createMeta(propertySignatures)
82
+ const arrayMeta = createMeta({ ...result, meta: inputMeta })
56
83
  const getMeta = (index: string) => {
84
+ if (index.endsWith("]")) return arrayMeta
57
85
  const parts = index.split("].")
58
86
  const key = parts[parts.length - 1]
59
87
  return arrayMeta[key as keyof typeof arrayMeta]
@@ -201,7 +201,7 @@ export type FilterItems = {
201
201
  | { readonly message: string | Effect.Effect<string> }
202
202
  }
203
203
 
204
- type CreateMeta = {
204
+ export type CreateMeta = {
205
205
  parent?: string
206
206
  meta?: Record<string, any>
207
207
  nullableOrUndefined?: false | "undefined" | "null"