@effect-app/vue-components 0.27.16 → 1.0.0-next.1

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 (74) hide show
  1. package/dist/types/components/OmegaForm/OmegaArray.vue.d.ts +2 -3
  2. package/dist/types/components/OmegaForm/OmegaErrorsContext.d.ts +4 -4
  3. package/dist/types/components/OmegaForm/OmegaErrorsInternal.vue.d.ts +22 -0
  4. package/dist/types/components/OmegaForm/OmegaInput.vue.d.ts +1 -2
  5. package/dist/types/components/OmegaForm/OmegaWrapper.vue.d.ts +7 -37
  6. package/dist/types/components/OmegaForm/index.d.ts +1 -7
  7. package/dist/types/components/OmegaForm/useOmegaForm.d.ts +65 -1
  8. package/dist/types/utils/index.d.ts +9 -0
  9. package/dist/vue-components.es.js +16 -25
  10. package/dist/vue-components.es10.js +5 -333
  11. package/dist/vue-components.es11.js +54 -6
  12. package/dist/vue-components.es12.js +71 -6
  13. package/dist/vue-components.es13.js +6 -2
  14. package/dist/vue-components.es14.js +6 -2
  15. package/dist/vue-components.es15.js +3 -86
  16. package/dist/vue-components.es16.js +5 -0
  17. package/dist/vue-components.es17.js +89 -7
  18. package/dist/vue-components.es18.js +42 -2
  19. package/dist/vue-components.es19.js +1 -1
  20. package/dist/vue-components.es2.js +10 -20
  21. package/dist/vue-components.es20.js +2 -126
  22. package/dist/vue-components.es21.js +92 -0
  23. package/dist/vue-components.es23.js +7 -5
  24. package/dist/vue-components.es24.js +31 -3
  25. package/dist/vue-components.es26.js +2 -11
  26. package/dist/vue-components.es27.js +23 -90
  27. package/dist/vue-components.es28.js +5 -42
  28. package/dist/vue-components.es29.js +21 -2
  29. package/dist/vue-components.es3.js +12 -8
  30. package/dist/vue-components.es30.js +27 -20
  31. package/dist/vue-components.es31.js +22 -5
  32. package/dist/vue-components.es32.js +6 -15
  33. package/dist/vue-components.es33.js +5 -30
  34. package/dist/vue-components.es34.js +19 -22
  35. package/dist/vue-components.es35.js +9 -12
  36. package/dist/vue-components.es36.js +31 -5
  37. package/dist/vue-components.es37.js +48 -19
  38. package/dist/vue-components.es38.js +26 -9
  39. package/dist/vue-components.es39.js +11 -31
  40. package/dist/vue-components.es4.js +47 -47
  41. package/dist/vue-components.es40.js +114 -47
  42. package/dist/vue-components.es42.js +1 -1
  43. package/dist/vue-components.es44.js +1 -1
  44. package/dist/vue-components.es45.js +3 -3
  45. package/dist/vue-components.es46.js +3 -3
  46. package/dist/vue-components.es47.js +1 -1
  47. package/dist/vue-components.es48.js +4 -115
  48. package/dist/vue-components.es49.js +4 -0
  49. package/dist/vue-components.es5.js +29 -70
  50. package/dist/vue-components.es50.js +44 -2
  51. package/dist/vue-components.es51.js +2 -44
  52. package/dist/vue-components.es6.js +209 -31
  53. package/dist/vue-components.es7.js +331 -49
  54. package/dist/vue-components.es8.js +2 -29
  55. package/dist/vue-components.es9.js +10 -148
  56. package/package.json +2 -2
  57. package/src/components/OmegaForm/OmegaArray.vue +4 -2
  58. package/src/components/OmegaForm/OmegaAutoGen.vue +5 -5
  59. package/src/components/OmegaForm/OmegaErrorsContext.ts +10 -8
  60. package/src/components/OmegaForm/{OmegaErrors.vue → OmegaErrorsInternal.vue} +11 -5
  61. package/src/components/OmegaForm/OmegaFormInput.vue +4 -2
  62. package/src/components/OmegaForm/OmegaFormStuff.ts +5 -6
  63. package/src/components/OmegaForm/OmegaInput.vue +6 -5
  64. package/src/components/OmegaForm/OmegaInternalInput.vue +1 -2
  65. package/src/components/OmegaForm/OmegaWrapper.vue +23 -247
  66. package/src/components/OmegaForm/index.ts +1 -7
  67. package/src/components/OmegaForm/useOmegaForm.ts +239 -7
  68. package/src/utils/index.ts +16 -0
  69. package/dist/types/components/OmegaForm/OmegaErrors.vue.d.ts +0 -15
  70. package/dist/vue-components.es22.js +0 -12
  71. package/dist/vue-components.es25.js +0 -5
  72. package/dist/vue-components.es41.js +0 -28
  73. package/dist/vue-components.es52.js +0 -4
  74. package/dist/vue-components.es53.js +0 -6
@@ -2,14 +2,20 @@
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
 
4
4
  import * as api from "@opentelemetry/api"
5
- import { type DeepKeys, type FormAsyncValidateOrFn, type FormValidateOrFn, type StandardSchemaV1, useForm } from "@tanstack/vue-form"
5
+ import { type DeepKeys, type FormAsyncValidateOrFn, type FormValidateOrFn, type StandardSchemaV1, StandardSchemaV1Issue, useForm, useStore } from "@tanstack/vue-form"
6
6
  import { Effect, Fiber, S } from "effect-app"
7
7
  import { runtimeFiberAsPromise } from "effect-app/utils"
8
8
  import { isObject } from "effect/Predicate"
9
- import { computed, type InjectionKey, onBeforeUnmount, onMounted, onUnmounted, provide } from "vue"
9
+ import { Component, computed, ConcreteComponent, h, type InjectionKey, onBeforeUnmount, onMounted, onUnmounted, watch } from "vue"
10
+ import { getOmegaStore } from "./getOmegaStore"
10
11
  import { type InputProps } from "./InputProps"
11
- import OmegaFormInput from "./OmegaFormInput.vue"
12
- import { type FieldValidators, type FilterItems, type FormProps, generateMetaFromSchema, type MetaRecord, type NestedKeyOf, type OmegaFormApi, type TypeOverride } from "./OmegaFormStuff"
12
+ import OmegaArray from "./OmegaArray.vue"
13
+ import OmegaAutoGen from "./OmegaAutoGen.vue"
14
+ import { buildOmegaErrors } from "./OmegaErrorsContext"
15
+ import OmegaErrorsInternal from "./OmegaErrorsInternal.vue"
16
+ import { type FieldValidators, type FilterItems, type FormProps, generateMetaFromSchema, type MetaRecord, type NestedKeyOf, type OmegaFormApi, OmegaFormState, ShowErrorsOn, type TypeOverride } from "./OmegaFormStuff"
17
+ import OmegaInput from "./OmegaInput.vue"
18
+ import OmegaForm from "./OmegaWrapper.vue"
13
19
 
14
20
  type keysRule<T> =
15
21
  | {
@@ -21,8 +27,63 @@ type keysRule<T> =
21
27
  banKeys?: NestedKeyOf<T>[]
22
28
  }
23
29
 
30
+ const fHoc = (form: OF<any, any>) => {
31
+ return function FormHoc<P>(
32
+ WrappedComponent: Component<P>
33
+ ): ConcreteComponent<P> {
34
+ // return defineComponent({
35
+ // setup() {
36
+ // return {
37
+ // child: WrappedComponent,
38
+ // form
39
+ // }
40
+ // },
41
+ // template: `<component :is="child" v-bind="$attrs" :form="form" v-on="$listeners">
42
+ // <template v-for="(_, name) in $slots" #[name]="scope">
43
+ // <slot :name v-bind="scope ?? {}" />
44
+ // </template>
45
+ // </component>`
46
+ // })
47
+
48
+ return {
49
+ render() {
50
+ return h(WrappedComponent, {
51
+ form,
52
+ on: this.$listeners,
53
+ attrs: this.$attrs
54
+ } as any, this.$slots)
55
+ }
56
+ }
57
+ }
58
+ }
59
+
60
+ const eHoc = (errorProps: ReturnType<typeof buildOmegaErrors>) => {
61
+ return function FormHoc<P>(
62
+ WrappedComponent: Component<P>
63
+ ): ConcreteComponent<P> {
64
+ return {
65
+ setup() {
66
+ return {
67
+ ...errorProps
68
+ }
69
+ },
70
+ render({ errors, generalErrors, showErrors }: any) {
71
+ return h(WrappedComponent, {
72
+ errors,
73
+ generalErrors,
74
+ showErrors,
75
+ on: this.$listeners,
76
+ attrs: this.$attrs,
77
+ scopedSlots: this.$scopedSlots
78
+ } as any)
79
+ }
80
+ }
81
+ }
82
+ }
83
+
24
84
  export type OmegaConfig<T> = {
25
85
  i18nNamespace?: string
86
+ showErrorsOn?: ShowErrorsOn
26
87
 
27
88
  persistency?: {
28
89
  /** Order of importance:
@@ -102,6 +163,125 @@ export interface OmegaFormReturn<
102
163
  ) => import("vue").VNode & {
103
164
  __ctx?: Awaited<typeof __VLS_setup>
104
165
  }
166
+ Errors: (
167
+ __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"],
168
+ __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>,
169
+ __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"],
170
+ __VLS_setup?: Promise<{
171
+ props:
172
+ & __VLS_PrettifyLocal<
173
+ & Pick<
174
+ & Partial<{}>
175
+ & Omit<
176
+ {} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps,
177
+ never
178
+ >,
179
+ never
180
+ >
181
+ & Omit<ReturnType<typeof OmegaErrorsInternal["props"]>, "errors" | "generalErrors" | "showErrors">
182
+ & Partial<{}>
183
+ >
184
+ & import("vue").PublicProps
185
+ expose(exposed: import("vue").ShallowUnwrapRef<{}>): void
186
+ attrs: any
187
+ slots: {}
188
+ emit: {}
189
+ }>
190
+ ) => import("vue").VNode & {
191
+ __ctx?: Awaited<typeof __VLS_setup>
192
+ }
193
+ Array: (
194
+ __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"],
195
+ __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>,
196
+ __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"],
197
+ __VLS_setup?: Promise<{
198
+ props:
199
+ & __VLS_PrettifyLocal<
200
+ & Pick<
201
+ & Partial<{}>
202
+ & Omit<
203
+ {} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps,
204
+ never
205
+ >,
206
+ never
207
+ >
208
+ & Omit<ReturnType<typeof OmegaArray<From, To>>["props"], "form">
209
+ & Partial<{}>
210
+ >
211
+ & import("vue").PublicProps
212
+ expose(exposed: import("vue").ShallowUnwrapRef<{}>): void
213
+ attrs: any
214
+ slots: {
215
+ // todo
216
+ default(props: { subField: any; subState: any; index: number; field: any }): void
217
+ preArray(props: { field: any; state: any }): void
218
+ postArray(props: { field: any; state: any }): void
219
+ field(props: { field: any }): void
220
+ }
221
+
222
+ emit: {}
223
+ }>
224
+ ) => import("vue").VNode & {
225
+ __ctx?: Awaited<typeof __VLS_setup>
226
+ }
227
+
228
+ AutoGen: (
229
+ __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"],
230
+ __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>,
231
+ __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"],
232
+ __VLS_setup?: Promise<{
233
+ props:
234
+ & __VLS_PrettifyLocal<
235
+ & Pick<
236
+ & Partial<{}>
237
+ & Omit<
238
+ {} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps,
239
+ never
240
+ >,
241
+ never
242
+ >
243
+ & Omit<ReturnType<typeof OmegaAutoGen<From, To>>["props"], "form">
244
+ & Partial<{}>
245
+ >
246
+ & import("vue").PublicProps
247
+ expose(exposed: import("vue").ShallowUnwrapRef<{}>): void
248
+ attrs: any
249
+ slots: {}
250
+ emit: {}
251
+ }>
252
+ ) => import("vue").VNode & {
253
+ __ctx?: Awaited<typeof __VLS_setup>
254
+ }
255
+
256
+ Form: <K extends keyof OmegaFormState<To, From>, Props = DefaultInputProps<From>>(
257
+ __VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"],
258
+ __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>,
259
+ __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"],
260
+ __VLS_setup?: Promise<{
261
+ props:
262
+ & __VLS_PrettifyLocal<
263
+ & Pick<
264
+ & Partial<{}>
265
+ & Omit<
266
+ {} & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps,
267
+ never
268
+ >,
269
+ never
270
+ >
271
+ & ReturnType<typeof OmegaForm<From, To, K, Props>>["props"]
272
+ & Partial<{}>
273
+ >
274
+ & import("vue").PublicProps
275
+ expose(exposed: import("vue").ShallowUnwrapRef<{}>): void
276
+ attrs: any
277
+ slots: {
278
+ default(props: { subscribedValues: ReturnType<typeof getOmegaStore<To, From, K>>["value"] }): void
279
+ }
280
+ emit: {}
281
+ }>
282
+ ) => import("vue").VNode & {
283
+ __ctx?: Awaited<typeof __VLS_setup>
284
+ }
105
285
  }
106
286
 
107
287
  export const useOmegaForm = <
@@ -366,10 +546,62 @@ export const useOmegaForm = <
366
546
  // )
367
547
  })
368
548
 
369
- provide(OmegaFormKey, formWithExtras)
549
+ const formSubmissionAttempts = useStore(
550
+ formWithExtras.store,
551
+ (state) => state.submissionAttempts
552
+ )
553
+
554
+ const errors = formWithExtras.useStore((state) => state.errors)
555
+
556
+ watch(
557
+ () => [formWithExtras.filterItems, errors.value],
558
+ () => {
559
+ const filterItems: FilterItems | undefined = formWithExtras.filterItems
560
+ const currentErrors = errors.value
561
+ if (!filterItems) return {}
562
+ if (!currentErrors) return {}
563
+ const errorList = Object
564
+ .values(currentErrors)
565
+ .filter(
566
+ (fieldErrors): fieldErrors is Record<string, StandardSchemaV1Issue[]> => Boolean(fieldErrors)
567
+ )
568
+ .flatMap((fieldErrors) =>
569
+ Object
570
+ .values(fieldErrors)
571
+ .flat()
572
+ .map((issue: StandardSchemaV1Issue) => issue.message)
573
+ )
574
+
575
+ if (errorList.some((e) => e === filterItems.message)) {
576
+ // TODO: Investigate if filterItems.items should be typed based on DeepKeys<To>.
577
+ filterItems.items.forEach((item: keyof From) => {
578
+ const m = formWithExtras.getFieldMeta(item as any)
579
+ if (m) {
580
+ formWithExtras.setFieldMeta(item as any, {
581
+ ...m,
582
+ errorMap: {
583
+ onSubmit: [
584
+ { path: [item as string], message: filterItems.message }
585
+ ]
586
+ }
587
+ })
588
+ }
589
+ })
590
+ }
591
+ return {}
592
+ }
593
+ )
594
+
595
+ // provide(OmegaFormKey, formWithExtras)
596
+ const errorContext = buildOmegaErrors(formSubmissionAttempts, errors, omegaConfig?.showErrorsOn)
370
597
 
371
598
  return Object.assign(formWithExtras, {
372
- Input: omegaConfig?.input ? omegaConfig.input(formWithExtras) : OmegaFormInput as any,
373
- Field: form.Field
599
+ errorContext,
600
+ Form: fHoc(formWithExtras)(OmegaForm as any) as any,
601
+ Input: omegaConfig?.input ? omegaConfig.input(formWithExtras) : fHoc(formWithExtras)(OmegaInput) as any,
602
+ Field: form.Field,
603
+ Errors: eHoc(errorContext)(OmegaErrorsInternal) as any,
604
+ Array: fHoc(formWithExtras)(OmegaArray) as any,
605
+ AutoGen: fHoc(formWithExtras)(OmegaAutoGen as any) as any
374
606
  })
375
607
  }
@@ -1,4 +1,5 @@
1
1
  import { type makeIntl } from "@effect-app/vue"
2
+ import { type S } from "effect-app"
2
3
  import { inject, type InjectionKey, provide } from "vue"
3
4
 
4
5
  export const useIntlKey = Symbol() as InjectionKey<
@@ -14,3 +15,18 @@ export const useIntl = () => {
14
15
  export const provideIntl = (
15
16
  intl: ReturnType<typeof makeIntl>["useIntl"]
16
17
  ) => provide(useIntlKey, intl)
18
+
19
+ /**
20
+ * Recursively extracts the source AST from a transformation chain.
21
+ * If the provided AST is a transformation, it follows the chain to find the original source AST.
22
+ *
23
+ * @param ast - The AST node to extract the transformation source from
24
+ * @returns The source AST at the end of the transformation chain
25
+ */
26
+ export function getTransformationFrom(ast: S.AST.AST) {
27
+ if (ast._tag === "Transformation") {
28
+ return getTransformationFrom(ast.from)
29
+ } else {
30
+ return ast
31
+ }
32
+ }
@@ -1,15 +0,0 @@
1
- declare var __VLS_6: {
2
- errors: readonly import("./OmegaFormStuff").OmegaError[];
3
- showedGeneralErrors: string[];
4
- };
5
- type __VLS_Slots = {} & {
6
- default?: (props: typeof __VLS_6) => any;
7
- };
8
- declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
9
- declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
10
- export default _default;
11
- type __VLS_WithSlots<T, S> = T & {
12
- new (): {
13
- $slots: S;
14
- };
15
- };
@@ -1,12 +0,0 @@
1
- import { Exit as c, Runtime as s } from "effect";
2
- import { dual as n, isFunction as m } from "./vue-components.es28.js";
3
- const i = Symbol.for("clone-trait"), u = n(2, (e, t) => i in e ? e[i](t) : Object.setPrototypeOf(t, Object.getPrototypeOf(e)));
4
- n(2, (e, t) => u(e, { ...e, ...m(t) ? t(e) : t }));
5
- const b = (e) => new Promise((t, r) => e.addObserver((o) => {
6
- c.isSuccess(o) ? t(o.value) : r(s.makeFiberFailure(o.cause));
7
- }));
8
- export {
9
- u as clone,
10
- i as cloneTrait,
11
- b as runtimeFiberAsPromise
12
- };
@@ -1,5 +0,0 @@
1
- import { ContextAPI as t } from "./vue-components.es40.js";
2
- var o = t.getInstance();
3
- export {
4
- o as context
5
- };
@@ -1,28 +0,0 @@
1
- import { registerGlobal as a, getGlobal as p, unregisterGlobal as s } from "./vue-components.es45.js";
2
- import { ProxyTracerProvider as i } from "./vue-components.es34.js";
3
- import { wrapSpanContext as c, isSpanContextValid as h } from "./vue-components.es37.js";
4
- import { deleteSpan as g, getSpan as S, getActiveSpan as x, getSpanContext as d, setSpan as f, setSpanContext as l } from "./vue-components.es46.js";
5
- import { DiagAPI as o } from "./vue-components.es42.js";
6
- var n = "trace", y = (
7
- /** @class */
8
- (function() {
9
- function t() {
10
- this._proxyTracerProvider = new i(), this.wrapSpanContext = c, this.isSpanContextValid = h, this.deleteSpan = g, this.getSpan = S, this.getActiveSpan = x, this.getSpanContext = d, this.setSpan = f, this.setSpanContext = l;
11
- }
12
- return t.getInstance = function() {
13
- return this._instance || (this._instance = new t()), this._instance;
14
- }, t.prototype.setGlobalTracerProvider = function(r) {
15
- var e = a(n, this._proxyTracerProvider, o.instance());
16
- return e && this._proxyTracerProvider.setDelegate(r), e;
17
- }, t.prototype.getTracerProvider = function() {
18
- return p(n) || this._proxyTracerProvider;
19
- }, t.prototype.getTracer = function(r, e) {
20
- return this.getTracerProvider().getTracer(r, e);
21
- }, t.prototype.disable = function() {
22
- s(n, o.instance()), this._proxyTracerProvider = new i();
23
- }, t;
24
- })()
25
- );
26
- export {
27
- y as TraceAPI
28
- };
@@ -1,4 +0,0 @@
1
- var o = typeof globalThis == "object" ? globalThis : typeof self == "object" ? self : typeof window == "object" ? window : typeof global == "object" ? global : {};
2
- export {
3
- o as _globalThis
4
- };
@@ -1,6 +0,0 @@
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 o from "./vue-components.es48.js";
3
-
4
- export {
5
- o as default
6
- };