@effect-app/vue-components 0.4.2 → 0.4.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.
@@ -0,0 +1,45 @@
1
+ <template>
2
+ <OmegaInput
3
+ v-bind="$props"
4
+ :form="form"
5
+ :name="name"
6
+ :label="label"
7
+ :validators="validators"
8
+ :options="options"
9
+ :type="type"
10
+ >
11
+ <template #default="slotProps">
12
+ <slot v-bind="slotProps"></slot>
13
+ </template>
14
+ </OmegaInput>
15
+ </template>
16
+
17
+ <script setup lang="ts" generic="From, To extends Record<PropertyKey, any>">
18
+ import { inject } from "vue"
19
+ import type {
20
+ FieldValidators,
21
+ NestedKeyOf,
22
+ TypeOverride,
23
+ } from "./OmegaFormStuff"
24
+ import type { InputProps } from "./InputProps"
25
+ import OmegaInput from "./OmegaInput.vue"
26
+ import { OmegaFormKey } from "./useOmegaForm" // Import the injection key
27
+
28
+ const form = inject(OmegaFormKey)
29
+ if (!form) {
30
+ throw new Error("OmegaFormInput must be used within an OmegaForm context")
31
+ }
32
+
33
+ defineProps<{
34
+ name: NestedKeyOf<To>
35
+ label: string
36
+ validators?: FieldValidators<From>
37
+ options?: { title: string; value: string }[]
38
+ type?: TypeOverride
39
+ }>()
40
+
41
+ defineSlots<{
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ default: (props: InputProps<To>) => any
44
+ }>()
45
+ </script>
@@ -13,20 +13,17 @@ import {
13
13
  type FormProps,
14
14
  type MetaRecord,
15
15
  type OmegaFormApi,
16
- type OmegaInputProps,
17
16
  } from "./OmegaFormStuff"
18
17
  import {
19
18
  computed,
20
19
  onBeforeUnmount,
21
20
  onMounted,
22
21
  onUnmounted,
23
- defineComponent,
24
- h,
25
- type DefineComponent,
26
- type Component,
22
+ provide,
23
+ type InjectionKey,
27
24
  } from "vue"
28
25
  import { isObject } from "effect/Predicate"
29
- import OmegaInput from "./OmegaInput.vue"
26
+ import OmegaFormInput from "./OmegaFormInput.vue"
30
27
 
31
28
  type keysRule<T> =
32
29
  | {
@@ -55,8 +52,12 @@ interface OF<To, From> extends OmegaFormApi<To, From> {
55
52
  filterItems?: FilterItems
56
53
  clear: () => void
57
54
  }
58
- export interface OmegaFormReturn<To, From> extends OF<To, From> {
59
- Input: DefineComponent<Omit<OmegaInputProps<From, To>, "form">, {}, {}>
55
+
56
+ export const OmegaFormKey = Symbol("OmegaForm") as InjectionKey<OF<any, any>>
57
+
58
+ export interface OmegaFormReturn<To extends Record<PropertyKey, any>, From>
59
+ extends OF<To, From> {
60
+ Input: typeof OmegaFormInput<From, To>
60
61
  }
61
62
 
62
63
  export const useOmegaForm = <
@@ -285,33 +286,9 @@ export const useOmegaForm = <
285
286
  clear,
286
287
  })
287
288
 
288
- return Object.assign(formWithExtras, {
289
- Input: defineComponent({
290
- name: "FormInput",
291
- inheritAttrs: true,
292
- setup(_, { attrs, slots }) {
293
- const name = attrs.name as NestedKeyOf<To>
294
- const label = attrs.label as string
295
- if (!name || !label) {
296
- throw new Error("OmegaForm.Input requires name and label props")
297
- }
289
+ provide(OmegaFormKey, formWithExtras)
298
290
 
299
- return () =>
300
- h(
301
- OmegaInput as Component,
302
- {
303
- ...attrs,
304
- name,
305
- label,
306
- form: formWithExtras,
307
- },
308
- slots,
309
- )
310
- },
311
- }) as any as DefineComponent<
312
- Omit<OmegaInputProps<From, To>, "form">,
313
- {},
314
- {}
315
- >,
291
+ return Object.assign(formWithExtras, {
292
+ Input: OmegaFormInput,
316
293
  })
317
294
  }
@@ -4,11 +4,23 @@
4
4
  :on-submit="console.log"
5
5
  >
6
6
  <template #internalForm="{ form }">
7
- <component :is="form.Input" label="myString" name="myString" />
7
+ <component :is="form.Input" label="myString" name="myString">
8
+ <template #default="{ field }">
9
+ <div>
10
+ <input v-model="field.state.value" />
11
+ </div>
12
+ </template>
13
+ </component>
8
14
  </template>
9
15
  </OmegaForm>
10
16
  <OmegaForm :form="exampleForm">
11
- <exampleForm.Input label="aString" name="aString" />
17
+ <exampleForm.Input label="aString" name="aString">
18
+ <template #default="{ field }">
19
+ <div>
20
+ <input v-model="field.state.value" />
21
+ </div>
22
+ </template>
23
+ </exampleForm.Input>
12
24
  <exampleForm.Input label="aStringMin2" name="aStringMin2" />
13
25
  <exampleForm.Input label="aStringMin2Max4" name="aStringMin2Max4" />
14
26
  <exampleForm.Input
@@ -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
- const o = (n) => typeof n == "function";
2
- export {
3
- o as isFunction
4
- };