@effect-app/vue-components 0.6.3 → 0.7.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.
Files changed (36) hide show
  1. package/dist/types/components/OmegaForm/OmegaArray.vue.d.ts +24 -0
  2. package/dist/types/components/OmegaForm/OmegaFormStuff.d.ts +15 -1
  3. package/dist/types/components/OmegaForm/index.d.ts +2 -1
  4. package/dist/vue-components.es.js +22 -19
  5. package/dist/vue-components.es10.js +5 -5
  6. package/dist/vue-components.es11.js +6 -108
  7. package/dist/vue-components.es12.js +110 -0
  8. package/dist/vue-components.es14.js +7 -2
  9. package/dist/vue-components.es15.js +2 -88
  10. package/dist/vue-components.es16.js +90 -0
  11. package/dist/vue-components.es18.js +2 -5
  12. package/dist/vue-components.es19.js +2 -32
  13. package/dist/vue-components.es2.js +14 -11
  14. package/dist/vue-components.es20.js +5 -2
  15. package/dist/vue-components.es21.js +32 -2
  16. package/dist/vue-components.es22.js +99 -11
  17. package/dist/vue-components.es23.js +11 -99
  18. package/dist/vue-components.es24.js +2 -2
  19. package/dist/vue-components.es25.js +2 -115
  20. package/dist/vue-components.es26.js +4 -0
  21. package/dist/vue-components.es27.js +115 -4
  22. package/dist/vue-components.es29.js +6 -0
  23. package/dist/vue-components.es4.js +19 -18
  24. package/dist/vue-components.es6.js +50 -36
  25. package/dist/vue-components.es7.js +34 -131
  26. package/dist/vue-components.es8.js +128 -211
  27. package/dist/vue-components.es9.js +218 -6
  28. package/package.json +1 -1
  29. package/src/components/OmegaForm/OmegaArray.vue +67 -0
  30. package/src/components/OmegaForm/OmegaErrors.vue +7 -3
  31. package/src/components/OmegaForm/OmegaFormInput.vue +6 -2
  32. package/src/components/OmegaForm/OmegaFormStuff.ts +4 -1
  33. package/src/components/OmegaForm/OmegaInput.vue +9 -1
  34. package/src/components/OmegaForm/index.ts +2 -1
  35. package/dist/vue-components.es13.js +0 -9
  36. package/dist/vue-components.es17.js +0 -4
@@ -1,8 +1,220 @@
1
- (function(){"use strict";try{if(typeof document<"u"){var n=document.createElement("style");if(n.appendChild(document.createTextNode("fieldset[data-v-a32b1c91]{display:contents}")),document.head.appendChild(n),window.customElements){const e=window.customElements.define;window.customElements.define=function(c,t){const o=t.prototype.connectedCallback;return t.prototype.connectedCallback=function(){if(o&&o.call(this),this.shadowRoot){const d=document.createElement("style");d.appendChild(document.createTextNode("fieldset[data-v-a32b1c91]{display:contents}")),this.shadowRoot.appendChild(d)}},e.call(window.customElements,c,t)}}}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})();
2
- import o from "./vue-components.es11.js";
3
-
4
- import r from "./vue-components.es13.js";
5
- const m = /* @__PURE__ */ r(o, [["__scopeId", "data-v-a32b1c91"]]);
1
+ import { S as i, Option as f, pipe as p } from "effect-app";
2
+ import { useIntl as S } from "./vue-components.es3.js";
3
+ const y = i.NonEmptyArray(i.String), v = (e) => i.AST.isUnion(e) && e.types.find((t) => t._tag === "UndefinedKeyword" || t === i.Null.ast), x = (e) => !e || !i.AST.isUnion(e) ? !1 : e.types.find((t) => t._tag === "UndefinedKeyword") ? "undefined" : e.types.find((t) => t === i.Null.ast) ? "null" : !1, m = ({ meta: e = {}, parent: t = "", property: n, propertySignatures: a }, l = {}) => {
4
+ if (n && n._tag === "Transformation")
5
+ return m({
6
+ parent: t,
7
+ meta: e,
8
+ property: n.from
9
+ });
10
+ if ((n == null ? void 0 : n._tag) === "TypeLiteral" && "propertySignatures" in n)
11
+ return m({
12
+ meta: e,
13
+ propertySignatures: n.propertySignatures
14
+ });
15
+ if (a) {
16
+ for (const s of a) {
17
+ const u = t ? `${t}.${s.name.toString()}` : s.name.toString(), r = x(s.type), o = !r;
18
+ let d = s.type;
19
+ if (i.AST.isUnion(s.type) && (d = s.type.types.find(
20
+ (g) => g._tag !== "UndefinedKeyword" && g !== i.Null.ast
21
+ )), "propertySignatures" in d)
22
+ Object.assign(
23
+ l,
24
+ m({
25
+ parent: u,
26
+ propertySignatures: d.propertySignatures,
27
+ meta: { required: o, nullableOrUndefined: r }
28
+ })
29
+ );
30
+ else {
31
+ const g = m({
32
+ parent: u,
33
+ property: s.type,
34
+ meta: { required: o, nullableOrUndefined: r }
35
+ });
36
+ l[u] = g;
37
+ }
38
+ }
39
+ return l;
40
+ }
41
+ if (n) {
42
+ const s = v(n);
43
+ if (Object.hasOwnProperty.call(e, "required") || (e.required = !s), i.AST.isUnion(n)) {
44
+ const r = n.types.find(
45
+ (o) => o._tag !== "UndefinedKeyword" && o !== i.Null.ast
46
+ );
47
+ return "propertySignatures" in r ? m({
48
+ propertySignatures: r.propertySignatures,
49
+ parent: t,
50
+ meta: e
51
+ }) : n.types.every(i.AST.isLiteral) ? {
52
+ ...e,
53
+ type: "select",
54
+ members: n.types.map((o) => o.literal)
55
+ } : {
56
+ ...e,
57
+ ...m({
58
+ parent: t,
59
+ meta: e,
60
+ property: r
61
+ })
62
+ };
63
+ }
64
+ if (i.AST.isTupleType(n))
65
+ return {
66
+ ...e,
67
+ type: "multiple",
68
+ members: n.elements,
69
+ rest: n.rest
70
+ };
71
+ const u = i.AST.getAnnotation(
72
+ n,
73
+ i.AST.JSONSchemaAnnotationId
74
+ ).pipe(f.getOrElse(() => ({})));
75
+ return e = { ...e, ...u }, "from" in n ? m({
76
+ parent: t,
77
+ meta: e,
78
+ property: n.from
79
+ }) : (e.type = i.AST.getAnnotation(
80
+ n,
81
+ i.AST.TitleAnnotationId
82
+ ).pipe(
83
+ f.getOrElse(() => "unknown")
84
+ ), e);
85
+ }
86
+ return l;
87
+ }, c = (e) => {
88
+ const t = e.ast, n = {};
89
+ if (t._tag === "Transformation" || t._tag === "Refinement")
90
+ return c(i.make(t.from));
91
+ if ("propertySignatures" in t) {
92
+ const a = m({
93
+ propertySignatures: t.propertySignatures
94
+ });
95
+ if (Object.values(a).every((s) => s && "type" in s))
96
+ return a;
97
+ const l = (s, u = "") => {
98
+ for (const r in s) {
99
+ const o = u ? `${u}.${r}` : r;
100
+ s[r] && typeof s[r] == "object" && "type" in s[r] ? n[o] = s[r] : s[r] && typeof s[r] == "object" && l(s[r], o);
101
+ }
102
+ };
103
+ l(a);
104
+ }
105
+ return n;
106
+ }, b = (e) => i.extend(e, i.Struct({})), A = (e) => {
107
+ const t = c(e), n = p(
108
+ e.ast,
109
+ f.liftPredicate((a) => a._tag === "Refinement" && "filter" in a),
110
+ f.flatMap((a) => i.AST.getJSONSchemaAnnotation(a)),
111
+ f.filter((a) => "items" in a),
112
+ f.filterMap(
113
+ ({ items: a }) => i.decodeUnknownOption(y)(a)
114
+ ),
115
+ f.zipWith(
116
+ i.AST.getMessageAnnotation(e.ast),
117
+ (a, l) => ({
118
+ items: a,
119
+ message: l("")
120
+ })
121
+ ),
122
+ f.getOrUndefined
123
+ );
124
+ return { schema: e, meta: t, filterItems: n };
125
+ }, O = (e) => {
126
+ const { trans: t } = S();
127
+ let n;
128
+ switch (e.type) {
129
+ case "string":
130
+ n = i.String.annotations({
131
+ message: () => t("validation.empty")
132
+ }), e.format === "email" && (n = i.compose(
133
+ n,
134
+ i.Email.annotations({
135
+ message: () => t("validation.email.invalid")
136
+ })
137
+ )), e.required && n.annotations({
138
+ message: () => t("validation.empty")
139
+ }), e.maxLength && (n = n.pipe(i.maxLength(e.maxLength)).annotations({
140
+ message: () => t("validation.string.maxLength", {
141
+ maxLength: e.maxLength
142
+ })
143
+ })), e.minLength && (n = n.pipe(i.minLength(e.minLength)).annotations({
144
+ message: () => t("validation.string.minLength", {
145
+ minLength: e.minLength
146
+ })
147
+ }));
148
+ break;
149
+ case "number":
150
+ n = i.Number.annotations({
151
+ message: () => t("validation.empty")
152
+ }), e.required && n.annotations({
153
+ message: () => t("validation.empty")
154
+ }), e.minimum && (n = n.pipe(i.greaterThanOrEqualTo(e.minimum)).annotations({
155
+ message: () => t("validation.number.min", {
156
+ minimum: e.minimum,
157
+ isExclusive: !0
158
+ })
159
+ })), e.maximum && (n = n.pipe(i.lessThanOrEqualTo(e.maximum)).annotations({
160
+ message: () => t("validation.number.max", {
161
+ maximum: e.maximum,
162
+ isExclusive: !0
163
+ })
164
+ })), e.exclusiveMinimum && (n = n.pipe(i.greaterThan(e.exclusiveMinimum)).annotations({
165
+ message: () => t("validation.number.min", {
166
+ minimum: e.exclusiveMinimum,
167
+ isExclusive: !1
168
+ })
169
+ })), e.exclusiveMaximum && (n = n.pipe(i.lessThan(e.exclusiveMaximum)).annotations({
170
+ message: () => t("validation.number.max", {
171
+ maximum: e.exclusiveMaximum,
172
+ isExclusive: !1
173
+ })
174
+ }));
175
+ break;
176
+ case "select":
177
+ n = i.Literal(...e.members).annotations({
178
+ message: () => ({
179
+ message: t("validation.not_a_valid", {
180
+ type: "select",
181
+ message: e.members.join(", ")
182
+ }),
183
+ override: !0
184
+ })
185
+ });
186
+ break;
187
+ case "multiple":
188
+ n = i.Array(i.String).annotations({
189
+ message: () => t("validation.not_a_valid", {
190
+ type: "multiple",
191
+ message: e.members.join(", ")
192
+ })
193
+ });
194
+ break;
195
+ case "boolean":
196
+ n = i.Boolean;
197
+ break;
198
+ // todo: switch must be exhaustive or have default case, otherwise falls through with schema undefined.
199
+ case "unknown":
200
+ n = i.Unknown;
201
+ break;
202
+ }
203
+ return e.required ? n.pipe(
204
+ i.annotations({
205
+ message: () => t("validation.empty")
206
+ })
207
+ ) : n = i.NullishOr(n), i.standardSchemaV1(n);
208
+ }, L = (e, t) => i.NullOr(e).pipe(
209
+ i.transform(i.typeSchema(e), {
210
+ decode: (n) => n ?? t(),
211
+ encode: (n) => n
212
+ })
213
+ );
6
214
  export {
7
- m as default
215
+ m as createMeta,
216
+ b as duplicateSchema,
217
+ O as generateInputStandardSchemaFromFieldMeta,
218
+ A as generateMetaFromSchema,
219
+ L as nullableInput
8
220
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-app/vue-components",
3
- "version": "0.6.3",
3
+ "version": "0.7.0",
4
4
  "peerDependencies": {
5
5
  "@mdi/js": "^7.4.47",
6
6
  "@tanstack/vue-form": "^1.2.4",
@@ -0,0 +1,67 @@
1
+ <template>
2
+ <component :is="form.Field" :name="name">
3
+ <template #default="{ field }">
4
+ <component
5
+ :is="form.Field"
6
+ v-for="(_, i) of field.state.value"
7
+ :key="i"
8
+ :name="`${name}[${i}]`"
9
+ >
10
+ <template #default="{ field: subField, state: subState }">
11
+ <slot
12
+ v-bind="{
13
+ field,
14
+ subField,
15
+ subState,
16
+ index: i,
17
+ }"
18
+ />
19
+ </template>
20
+ </component>
21
+ <slot name="field" v-bind="{ field }" />
22
+ </template>
23
+ </component>
24
+ </template>
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"
30
+
31
+ const props =
32
+ defineProps<
33
+ Omit<OmegaInputProps<From, To>, "validators" | "options" | "label" | "type">
34
+ >()
35
+
36
+ defineOptions({
37
+ inheritAttrs: false,
38
+ })
39
+
40
+ const getMetaFromArray = computed(() => {
41
+ const inputMeta = props.form.meta[props.name]
42
+ 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
+ )
54
+
55
+ const arrayMeta = createMeta(propertySignatures)
56
+ const getMeta = (index: string) => {
57
+ const parts = index.split("].")
58
+ const key = parts[parts.length - 1]
59
+ return arrayMeta[key as keyof typeof arrayMeta]
60
+ }
61
+ return getMeta
62
+ }
63
+ return (_: string) => undefined
64
+ })
65
+
66
+ provide("getMetaFromArray", getMetaFromArray)
67
+ </script>
@@ -130,15 +130,19 @@ const showedGeneralErrors = computed(() => {
130
130
  }
131
131
  }
132
132
 
133
+ .error-list {
134
+ list-style-position: inside;
135
+ }
136
+
133
137
  div.error-list {
134
138
  container-type: inline-size;
135
139
  display: grid;
136
140
  grid-template-columns: auto 1fr auto;
137
- gap: 0.5em;
141
+ gap: 1.5em;
138
142
  align-items: start;
139
143
  }
140
144
 
141
- @container (max-width: 28.125rem) {
145
+ @container (max-width: 27.125rem) {
142
146
  div.error-list {
143
147
  grid-template-columns: auto 1fr;
144
148
  }
@@ -149,7 +153,7 @@ div.error-list {
149
153
  }
150
154
  }
151
155
 
152
- @container (max-width: 18.75rem) {
156
+ @container (max-width: 17.75rem) {
153
157
  div.error-list {
154
158
  grid-template-columns: 1fr;
155
159
  }
@@ -20,12 +20,16 @@ import type {
20
20
  FieldValidators,
21
21
  NestedKeyOf,
22
22
  TypeOverride,
23
+ FormType,
24
+ MetaRecord,
23
25
  } from "./OmegaFormStuff"
24
26
  import type { InputProps } from "./InputProps"
25
27
  import OmegaInput from "./OmegaInput.vue"
26
- import { OmegaFormKey } from "./useOmegaForm" // Import the injection key
28
+ import { OmegaFormKey } from "./useOmegaForm"
27
29
 
28
- const form = inject(OmegaFormKey)
30
+ const form = inject(OmegaFormKey) as FormType<From, To> & {
31
+ meta: MetaRecord<To>
32
+ }
29
33
  if (!form) {
30
34
  throw new Error("OmegaFormInput must be used within an OmegaForm context")
31
35
  }
@@ -170,6 +170,7 @@ export type SelectFieldMeta = BaseFieldMeta & {
170
170
  export type MultipleFieldMeta = BaseFieldMeta & {
171
171
  type: "multiple"
172
172
  members: any[]
173
+ rest: S.AST.Type[]
173
174
  }
174
175
 
175
176
  export type BooleanFieldMeta = BaseFieldMeta & {
@@ -230,7 +231,7 @@ const isNullableOrUndefined = (property: false | S.AST.AST | undefined) => {
230
231
  return false
231
232
  }
232
233
 
233
- const createMeta = <T = any>(
234
+ export const createMeta = <T = any>(
234
235
  { meta = {}, parent = "", property, propertySignatures }: CreateMeta,
235
236
  acc: Partial<MetaRecord<T>> = {},
236
237
  ): MetaRecord<T> | FieldMeta => {
@@ -326,6 +327,7 @@ const createMeta = <T = any>(
326
327
  ...meta,
327
328
  type: "multiple",
328
329
  members: property.elements,
330
+ rest: property.rest,
329
331
  } as FieldMeta
330
332
  }
331
333
 
@@ -430,6 +432,7 @@ export const generateMetaFromSchema = <From, To>(
430
432
  ),
431
433
  Option.getOrUndefined,
432
434
  )
435
+
433
436
  return { schema, meta, filterItems }
434
437
  }
435
438
 
@@ -9,6 +9,7 @@
9
9
  >
10
10
  <template #default="{ field }: { field: OmegaFieldInternalApi<To> }">
11
11
  <OmegaInternalInput
12
+ v-if="meta"
12
13
  :field="field"
13
14
  :label="label"
14
15
  :options="options"
@@ -25,8 +26,9 @@
25
26
  </template>
26
27
 
27
28
  <script setup lang="ts" generic="From, To">
28
- import { computed } from "vue"
29
+ import { computed, inject, type Ref } from "vue"
29
30
  import {
31
+ type FieldMeta,
30
32
  generateInputStandardSchemaFromFieldMeta,
31
33
  type OmegaInputProps,
32
34
  } from "./OmegaFormStuff"
@@ -39,7 +41,13 @@ defineOptions({
39
41
  inheritAttrs: false,
40
42
  })
41
43
 
44
+ const getMetaFromArray =
45
+ inject<Ref<(name: string) => FieldMeta | null>>("getMetaFromArray")
46
+
42
47
  const meta = computed(() => {
48
+ if (getMetaFromArray?.value && getMetaFromArray.value(props.name)) {
49
+ return getMetaFromArray.value(props.name)
50
+ }
43
51
  return props.form.meta[props.name]
44
52
  })
45
53
 
@@ -2,10 +2,11 @@ import { default as OmegaForm } from "./OmegaWrapper.vue"
2
2
  import { default as OmegaInput } from "./OmegaInput.vue"
3
3
  import { default as OmegaErrors } from "./OmegaErrors.vue"
4
4
  import { default as OmegaAutoGen } from "./OmegaAutoGen.vue"
5
+ import { default as OmegaArray } from "./OmegaArray.vue"
5
6
 
6
7
  export * as OmegaErrorsContext from "./OmegaErrorsContext"
7
8
  export * from "./OmegaFormStuff"
8
9
  export { useOmegaForm, type OmegaFormReturn } from "./useOmegaForm"
9
10
  export { default } from "./OmegaWrapper.vue"
10
11
 
11
- export { OmegaForm, OmegaInput, OmegaErrors, OmegaAutoGen }
12
+ export { OmegaForm, OmegaInput, OmegaErrors, OmegaAutoGen, OmegaArray }
@@ -1,9 +0,0 @@
1
- const s = (t, e) => {
2
- const o = t.__vccOpts || t;
3
- for (const [r, c] of e)
4
- o[r] = c;
5
- return o;
6
- };
7
- export {
8
- s as default
9
- };
@@ -1,4 +0,0 @@
1
- import f from "./vue-components.es5.js";
2
- export {
3
- f as default
4
- };