Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/legal-lions-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-app/vue-components": patch
---

revert to cleaner solution
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@
generic="
// dprint ignore - somehow with 120 chars, this becomes a mess. should report it.
From extends Record<PropertyKey, any>,
To extends Record<PropertyKey, any>
To extends Record<PropertyKey, any>,
Name extends DeepKeys<From>
"
>
import { type DeepKeys } from "@tanstack/vue-form"
import { computed, onMounted, provide } from "vue"
import { type OmegaArrayProps } from "./OmegaFormStuff"

const props = defineProps<OmegaArrayProps<From, To>>()
const props = defineProps<OmegaArrayProps<From, To, Name>>()

defineOptions({
inheritAttrs: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:child="{ name, label, ...attrs }"
>
<form.Input
:name="name"
:name="name as FieldPath<From>"
:label="label"
v-bind="attrs"
/>
Expand All @@ -16,15 +16,16 @@
lang="ts"
generic="
From extends Record<PropertyKey, string>,
To extends Record<PropertyKey, string>
To extends Record<PropertyKey, string>,
Name extends DeepKeys<From>
"
>
import { type DeepKeys } from "@tanstack/vue-form"
import { Array as A, Order, pipe } from "effect-app"
import { computed } from "vue"
import { type FieldMeta, type OmegaAutoGenMeta, type OmegaInputProps } from "./OmegaFormStuff"
import { type FieldMeta, type FieldPath, type OmegaAutoGenMeta, type OmegaInputProps } from "./OmegaFormStuff"

type NewMeta = OmegaAutoGenMeta<From, To>
type NewMeta = OmegaAutoGenMeta<From, To, Name>

const mapObject = <K extends string, A, B>(fn: (value: A, key: K) => B) => (obj: Record<K, A>): Record<K, B> =>
Object.fromEntries(
Expand All @@ -51,7 +52,7 @@ const filterMapRecord =
)

const props = defineProps<{
form: OmegaInputProps<From, To>["form"]
form: OmegaInputProps<From, To, Name>["form"]
pick?: DeepKeys<From>[]
omit?: DeepKeys<From>[]
labelMap?: (key: DeepKeys<From>) => string | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ import { OmegaFormKey } from "./useOmegaForm"

const form = inject(OmegaFormKey) as unknown as OmegaInputProps<
From,
To
To,
Name
>["form"]

if (!form) {
throw new Error("OmegaFormInput must be used within an OmegaForm context")
}

defineProps<
BaseProps<From> & DefaultTypeProps
BaseProps<From, Name> & DefaultTypeProps
>()

defineSlots<{
Expand Down
28 changes: 16 additions & 12 deletions packages/vue-components/src/components/OmegaForm/OmegaFormStuff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ export type FieldPath<T> = unknown extends T ? string
// technically we cannot have primitive at the root
: T extends string | boolean | number | null | undefined | symbol | bigint ? ""
// technically we cannot have array at the root
: T extends ReadonlyArray<infer U> ? Compute<FieldPath_<U, `[${number}]`>>
: T extends ReadonlyArray<infer U> ? FieldPath_<U, `[${number}]`>
: {
[K in keyof T]: Compute<FieldPath_<T[K], `${K & string}`>>
[K in keyof T]: FieldPath_<T[K], `${K & string}`>
}[keyof T]

export type FieldPath_<T, Path extends string> = unknown extends T ? string
: T extends string | boolean | number | null | undefined | symbol | bigint ? Path
: T extends ReadonlyArray<infer U> ? Compute<FieldPath_<U, `${Path}[${number}]`>> | Path
: T extends ReadonlyArray<infer U> ? FieldPath_<U, `${Path}[${number}]`> | Path
: {
[K in keyof T]: Compute<FieldPath_<T[K], `${Path}.${K & string}`>>
[K in keyof T]: FieldPath_<T[K], `${Path}.${K & string}`>
}[keyof T]

export type BaseProps<From, TName extends FieldPath<From> = FieldPath<From>> = {
export type BaseProps<From, TName extends FieldPath<From>> = {
/**
* Will fallback to i18n when not specified.
* Can also be provided via #label slot for custom HTML labels.
Expand Down Expand Up @@ -64,31 +64,34 @@ export type DefaultTypeProps = {

export type OmegaInputPropsBase<
From extends Record<PropertyKey, any>,
To extends Record<PropertyKey, any>
To extends Record<PropertyKey, any>,
Name extends DeepKeys<From>
> = {
form: OF<From, To> & {
meta: MetaRecord<From>
i18nNamespace?: string
}
} & BaseProps<From>
} & BaseProps<From, Name>

export type OmegaInputProps<
From extends Record<PropertyKey, any>,
To extends Record<PropertyKey, any>,
Name extends DeepKeys<From>,
TypeProps = DefaultTypeProps
> = {
form: OmegaFormReturn<From, To, TypeProps> & {
meta: MetaRecord<From>
i18nNamespace?: string
}
} & BaseProps<From>
} & BaseProps<From, Name>

export type OmegaArrayProps<
From extends Record<PropertyKey, any>,
To extends Record<PropertyKey, any>
To extends Record<PropertyKey, any>,
Name extends DeepKeys<From>
> =
& Omit<
OmegaInputProps<From, To>,
OmegaInputProps<From, To, Name>,
"validators" | "options" | "label" | "type" | "items" | "name"
>
& {
Expand Down Expand Up @@ -886,8 +889,9 @@ export const nullableInput = <A, I, R>(

export type OmegaAutoGenMeta<
From extends Record<PropertyKey, any>,
To extends Record<PropertyKey, any>
> = Omit<OmegaInputProps<From, To>, "form">
To extends Record<PropertyKey, any>,
Name extends DeepKeys<From>
> = Omit<OmegaInputProps<From, To, Name>, "form">

const supportedInputs = [
"button",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
generic="
// dprint ignore - somehow with 120 chars, this becomes a mess. should report it.
From extends Record<PropertyKey, any>,
To extends Record<PropertyKey, any>
To extends Record<PropertyKey, any>,
Name extends DeepKeys<From>
"
>
import { type DeepKeys } from "@tanstack/vue-form"
Expand All @@ -49,7 +50,7 @@ import { useIntl } from "../../utils"
import { type FieldMeta, generateInputStandardSchemaFromFieldMeta, type OmegaInputPropsBase } from "./OmegaFormStuff"
import OmegaInternalInput from "./OmegaInternalInput.vue"

const props = defineProps<OmegaInputPropsBase<From, To>>()
const props = defineProps<OmegaInputPropsBase<From, To, Name>>()

// downgrade to *as* DeepKeys<From> to avoid useless and possible infinite recursion in TS
const propsName = computed(() => props.name as DeepKeys<From>)
Expand Down
Loading