2
0

Introducing The Forge (#1072)

The Forge allows anyone to easily create their own Typebot Block.

Closes #380
This commit is contained in:
Baptiste Arnaud
2023-12-13 10:22:02 +01:00
committed by GitHub
parent c373108b55
commit 5e019bbb22
184 changed files with 42659 additions and 37411 deletions

View File

@ -0,0 +1,48 @@
import { ZodArray, ZodDate, ZodOptional, ZodString, ZodTypeAny, z } from 'zod'
type OptionableZodType<T extends ZodTypeAny> = T | ZodOptional<T>
export interface ZodLayoutMetadata<
T extends ZodTypeAny,
TInferred = z.input<T> | z.output<T>
> {
accordion?: string
label?: string
input?: 'variableDropdown' | 'textarea' | 'password'
defaultValue?: T extends ZodDate ? string : TInferred
placeholder?: string
helperText?: string
direction?: 'row' | 'column'
isRequired?: boolean
withVariableButton?: boolean
fetcher?: T extends OptionableZodType<ZodString> ? string : never
itemLabel?: T extends OptionableZodType<ZodArray<any>> ? string : never
isOrdered?: T extends OptionableZodType<ZodArray<any>> ? boolean : never
isHidden?: boolean
moreInfoTooltip?: string
}
declare module 'zod' {
interface ZodType<Output, Def extends ZodTypeDef, Input = Output> {
layout<T extends ZodTypeAny>(this: T, metadata: ZodLayoutMetadata<T>): T
}
interface ZodTypeDef {
layout?: ZodLayoutMetadata<ZodTypeAny>
}
}
export const extendWithTypebotLayout = (zod: typeof z) => {
if (typeof zod.ZodType.prototype.layout !== 'undefined') {
return
}
zod.ZodType.prototype.layout = function (layout) {
const result = new (this as any).constructor({
...this._def,
layout,
})
return result
}
}

View File

@ -0,0 +1,10 @@
import { z } from 'zod'
import {
extendWithTypebotLayout,
ZodLayoutMetadata,
} from './extendWithTypebotLayout'
extendWithTypebotLayout(z)
export { z }
export type { ZodLayoutMetadata }