2
0

feat(editor): Add file upload input

This commit is contained in:
Baptiste Arnaud
2022-06-12 17:34:33 +02:00
parent d4c52d47b3
commit 75365a0d82
48 changed files with 1022 additions and 587 deletions

View File

@ -20,14 +20,6 @@ export const defaultChoiceInputOptions: ChoiceInputOptions = {
isMultipleChoice: false,
}
export const choiceInputSchema = blockBaseSchema.and(
z.object({
type: z.enum([InputBlockType.CHOICE]),
items: z.array(z.any()),
options: choiceInputOptionsSchema,
})
)
export const buttonItemSchema = itemBaseSchema.and(
z.object({
type: z.literal(ItemType.BUTTON),
@ -35,6 +27,14 @@ export const buttonItemSchema = itemBaseSchema.and(
})
)
export const choiceInputSchema = blockBaseSchema.and(
z.object({
type: z.enum([InputBlockType.CHOICE]),
items: z.array(buttonItemSchema),
options: choiceInputOptionsSchema,
})
)
export type ButtonItem = z.infer<typeof buttonItemSchema>
export type ChoiceInputBlock = z.infer<typeof choiceInputSchema>
export type ChoiceInputOptions = z.infer<typeof choiceInputOptionsSchema>

View File

@ -0,0 +1,33 @@
import { z } from 'zod'
import { InputBlockType, optionBaseSchema, blockBaseSchema } from '../shared'
export const fileInputOptionsSchema = optionBaseSchema.and(
z.object({
isMultipleAllowed: z.boolean(),
labels: z.object({
placeholder: z.string(),
button: z.string(),
}),
})
)
export const fileInputStepSchema = blockBaseSchema.and(
z.object({
type: z.literal(InputBlockType.FILE),
options: fileInputOptionsSchema,
})
)
export const defaultFileInputOptions: FileInputOptions = {
isMultipleAllowed: false,
labels: {
placeholder: `<strong>
Click to upload
</strong> or drag and drop<br>
(size limit: 10MB)`,
button: 'Upload',
},
}
export type FileInputBlock = z.infer<typeof fileInputStepSchema>
export type FileInputOptions = z.infer<typeof fileInputOptionsSchema>

View File

@ -8,3 +8,4 @@ export * from './choice'
export * from './payment'
export * from './phone'
export * from './rating'
export * from './file'

View File

@ -11,6 +11,7 @@ import {
} from './phone'
import { ratingInputOptionsSchema, ratingInputBlockSchema } from './rating'
import { textInputOptionsSchema, textInputSchema } from './text'
import { fileInputOptionsSchema, fileInputStepSchema } from './file'
import { urlInputOptionsSchema, urlInputSchema } from './url'
export type OptionBase = z.infer<typeof optionBaseSchema>
@ -24,6 +25,7 @@ export const inputBlockOptionsSchema = textInputOptionsSchema
.or(dateInputOptionsSchema)
.or(paymentInputOptionsSchema)
.or(ratingInputOptionsSchema)
.or(fileInputOptionsSchema)
export const inputBlockSchema = textInputSchema
.or(numberInputSchema)
@ -34,6 +36,7 @@ export const inputBlockSchema = textInputSchema
.or(choiceInputSchema)
.or(paymentInputSchema)
.or(ratingInputBlockSchema)
.or(fileInputStepSchema)
export type InputBlock = z.infer<typeof inputBlockSchema>
export type InputBlockOptions = z.infer<typeof inputBlockOptionsSchema>

View File

@ -40,6 +40,7 @@ export enum InputBlockType {
CHOICE = 'choice input',
PAYMENT = 'payment input',
RATING = 'rating input',
FILE = 'file input',
}
export enum LogicBlockType {