mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-07 04:19:22 +00:00
chore: ad release label
This commit is contained in:
@@ -1,52 +1,63 @@
|
||||
<script setup lang="ts" generic="T extends ZodRawShape">
|
||||
import type { ZodAny, ZodObject, ZodRawShape } from 'zod'
|
||||
import { computed, provide } from 'vue'
|
||||
import { FieldContextKey, useField } from 'vee-validate'
|
||||
import AutoFormField from './AutoFormField.vue'
|
||||
import type { Config, ConfigItem, Shape } from './interface'
|
||||
import { beautifyObjectName, getBaseSchema, getBaseType, getDefaultValueInZodStack } from './utils'
|
||||
import AutoFormLabel from './AutoFormLabel.vue'
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'
|
||||
import { FormItem } from '@/components/ui/form'
|
||||
import type { ZodAny, ZodObject, ZodRawShape } from "zod";
|
||||
import { computed, provide } from "vue";
|
||||
import { FieldContextKey, useField } from "vee-validate";
|
||||
import AutoFormField from "./AutoFormField.vue";
|
||||
import type { Config, ConfigItem, Shape } from "./interface";
|
||||
import {
|
||||
beautifyObjectName,
|
||||
getBaseSchema,
|
||||
getBaseType,
|
||||
getDefaultValueInZodStack,
|
||||
} from "./utils";
|
||||
import AutoFormLabel from "./AutoFormLabel.vue";
|
||||
import {
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionItem,
|
||||
AccordionTrigger,
|
||||
} from "@/components/ui/accordion";
|
||||
import { FormItem } from "@/components/ui/form";
|
||||
|
||||
const props = defineProps<{
|
||||
fieldName: string
|
||||
required?: boolean
|
||||
config?: Config<T>
|
||||
schema?: ZodObject<T>
|
||||
disabled?: boolean
|
||||
}>()
|
||||
fieldName: string;
|
||||
required?: boolean;
|
||||
config?: Config<T>;
|
||||
schema?: ZodObject<T>;
|
||||
disabled?: boolean;
|
||||
}>();
|
||||
|
||||
const shapes = computed(() => {
|
||||
// @ts-expect-error ignore {} not assignable to object
|
||||
const val: { [key in keyof T]: Shape } = {}
|
||||
// @ts-expect-error ignore {} not assignable to object
|
||||
const val: { [key in keyof T]: Shape } = {};
|
||||
|
||||
if (!props.schema)
|
||||
return
|
||||
const shape = getBaseSchema(props.schema)?.shape
|
||||
if (!shape)
|
||||
return
|
||||
Object.keys(shape).forEach((name) => {
|
||||
const item = shape[name] as ZodAny
|
||||
const baseItem = getBaseSchema(item) as ZodAny
|
||||
let options = (baseItem && 'values' in baseItem._def) ? baseItem._def.values as string[] : undefined
|
||||
if (!Array.isArray(options) && typeof options === 'object')
|
||||
options = Object.values(options)
|
||||
if (!props.schema) return;
|
||||
const shape = getBaseSchema(props.schema)?.shape;
|
||||
if (!shape) return;
|
||||
Object.keys(shape).forEach((name) => {
|
||||
const item = shape[name] as ZodAny;
|
||||
const baseItem = getBaseSchema(item) as ZodAny;
|
||||
let options =
|
||||
baseItem && "values" in baseItem._def
|
||||
? (baseItem._def.values as string[])
|
||||
: undefined;
|
||||
if (!Array.isArray(options) && typeof options === "object")
|
||||
options = Object.values(options);
|
||||
|
||||
val[name as keyof T] = {
|
||||
type: getBaseType(item),
|
||||
default: getDefaultValueInZodStack(item),
|
||||
options,
|
||||
required: !['ZodOptional', 'ZodNullable'].includes(item._def.typeName),
|
||||
schema: item,
|
||||
}
|
||||
})
|
||||
return val
|
||||
})
|
||||
val[name as keyof T] = {
|
||||
type: getBaseType(item),
|
||||
default: getDefaultValueInZodStack(item),
|
||||
options,
|
||||
required: !["ZodOptional", "ZodNullable"].includes(item._def.typeName),
|
||||
schema: item,
|
||||
};
|
||||
});
|
||||
return val;
|
||||
});
|
||||
|
||||
const fieldContext = useField(props.fieldName)
|
||||
const fieldContext = useField(props.fieldName);
|
||||
// @ts-expect-error ignore missing `id`
|
||||
provide(FieldContextKey, fieldContext)
|
||||
provide(FieldContextKey, fieldContext);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user