⚡ (video) Allow changing video height when resolved to an iframe
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
import { Stack, Text } from '@chakra-ui/react'
|
import { Stack, Text } from '@chakra-ui/react'
|
||||||
import { VideoBubbleContent } from '@typebot.io/schemas'
|
import {
|
||||||
import { TextInput } from '@/components/inputs'
|
VariableString,
|
||||||
|
VideoBubbleContent,
|
||||||
|
VideoBubbleContentType,
|
||||||
|
} from '@typebot.io/schemas'
|
||||||
|
import { NumberInput, TextInput } from '@/components/inputs'
|
||||||
import { useScopedI18n } from '@/locales'
|
import { useScopedI18n } from '@/locales'
|
||||||
import { parseVideoUrl } from '@typebot.io/lib/parseVideoUrl'
|
import { parseVideoUrl } from '@typebot.io/lib/parseVideoUrl'
|
||||||
|
|
||||||
@@ -11,7 +15,7 @@ type Props = {
|
|||||||
|
|
||||||
export const VideoUploadContent = ({ content, onSubmit }: Props) => {
|
export const VideoUploadContent = ({ content, onSubmit }: Props) => {
|
||||||
const scopedT = useScopedI18n('editor.blocks.bubbles.video.settings')
|
const scopedT = useScopedI18n('editor.blocks.bubbles.video.settings')
|
||||||
const handleUrlChange = (url: string) => {
|
const updateUrl = (url: string) => {
|
||||||
const info = parseVideoUrl(url)
|
const info = parseVideoUrl(url)
|
||||||
return onSubmit({
|
return onSubmit({
|
||||||
type: info.type,
|
type: info.type,
|
||||||
@@ -19,16 +23,34 @@ export const VideoUploadContent = ({ content, onSubmit }: Props) => {
|
|||||||
id: info.id,
|
id: info.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const updateHeight = (height?: number | VariableString) => {
|
||||||
|
return onSubmit({
|
||||||
|
...content,
|
||||||
|
height,
|
||||||
|
})
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<Stack p="2">
|
<Stack p="2" spacing={4}>
|
||||||
|
<Stack>
|
||||||
<TextInput
|
<TextInput
|
||||||
placeholder={scopedT('worksWith.placeholder')}
|
placeholder={scopedT('worksWith.placeholder')}
|
||||||
defaultValue={content?.url ?? ''}
|
defaultValue={content?.url ?? ''}
|
||||||
onChange={handleUrlChange}
|
onChange={updateUrl}
|
||||||
/>
|
/>
|
||||||
<Text fontSize="sm" color="gray.400" textAlign="center">
|
<Text fontSize="sm" color="gray.400" textAlign="center">
|
||||||
{scopedT('worksWith.text')}
|
{scopedT('worksWith.text')}
|
||||||
</Text>
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
{content?.type !== VideoBubbleContentType.URL && (
|
||||||
|
<NumberInput
|
||||||
|
label="Height:"
|
||||||
|
defaultValue={content?.height ?? 400}
|
||||||
|
onValueChange={updateHeight}
|
||||||
|
suffix={scopedT('numberInput.unit')}
|
||||||
|
width="150px"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -322,6 +322,7 @@ export default {
|
|||||||
'Funktioniert mit YouTube, Vimeo und anderen',
|
'Funktioniert mit YouTube, Vimeo und anderen',
|
||||||
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
|
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
|
||||||
'Füge den Videolink ein...',
|
'Füge den Videolink ein...',
|
||||||
|
'editor.blocks.bubbles.video.settings.numberInput.unit': 'px',
|
||||||
'editor.blocks.bubbles.textEditor.plate.label': 'Texteditor',
|
'editor.blocks.bubbles.textEditor.plate.label': 'Texteditor',
|
||||||
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
|
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
|
||||||
'Nach einer Variable suchen',
|
'Nach einer Variable suchen',
|
||||||
|
|||||||
@@ -311,6 +311,7 @@ export default {
|
|||||||
'Works with Youtube, Vimeo and others',
|
'Works with Youtube, Vimeo and others',
|
||||||
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
|
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
|
||||||
'Paste the video link...',
|
'Paste the video link...',
|
||||||
|
'editor.blocks.bubbles.video.settings.numberInput.unit': 'px',
|
||||||
'editor.blocks.bubbles.textEditor.plate.label': 'Text editor',
|
'editor.blocks.bubbles.textEditor.plate.label': 'Text editor',
|
||||||
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
|
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
|
||||||
'Search for a variable',
|
'Search for a variable',
|
||||||
|
|||||||
@@ -325,6 +325,7 @@ export default {
|
|||||||
'Fonctionne avec Youtube, Vimeo et autres',
|
'Fonctionne avec Youtube, Vimeo et autres',
|
||||||
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
|
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
|
||||||
'Collez le lien de la vidéo...',
|
'Collez le lien de la vidéo...',
|
||||||
|
'editor.blocks.bubbles.video.settings.numberInput.unit': 'px',
|
||||||
'editor.blocks.bubbles.textEditor.plate.label': 'Éditeur de texte',
|
'editor.blocks.bubbles.textEditor.plate.label': 'Éditeur de texte',
|
||||||
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
|
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
|
||||||
'Rechercher une variable',
|
'Rechercher une variable',
|
||||||
|
|||||||
@@ -321,6 +321,7 @@ export default {
|
|||||||
'Compatível com Youtube, Vimeo e outros',
|
'Compatível com Youtube, Vimeo e outros',
|
||||||
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
|
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
|
||||||
'Colar o link do vídeo...',
|
'Colar o link do vídeo...',
|
||||||
|
'editor.blocks.bubbles.video.settings.numberInput.unit': 'px',
|
||||||
'editor.blocks.bubbles.textEditor.plate.label': 'Editor de texto',
|
'editor.blocks.bubbles.textEditor.plate.label': 'Editor de texto',
|
||||||
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
|
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
|
||||||
'Pesquisar uma variável',
|
'Pesquisar uma variável',
|
||||||
|
|||||||
@@ -322,6 +322,7 @@ export default {
|
|||||||
'Compatível com Youtube, Vimeo e outros',
|
'Compatível com Youtube, Vimeo e outros',
|
||||||
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
|
'editor.blocks.bubbles.video.settings.worksWith.placeholder':
|
||||||
'Colar o link do vídeo...',
|
'Colar o link do vídeo...',
|
||||||
|
'editor.blocks.bubbles.video.settings.numberInput.unit': 'px',
|
||||||
'editor.blocks.bubbles.textEditor.plate.label': 'Editor de texto',
|
'editor.blocks.bubbles.textEditor.plate.label': 'Editor de texto',
|
||||||
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
|
'editor.blocks.bubbles.textEditor.searchVariable.placeholder':
|
||||||
'Pesquisar uma variável',
|
'Pesquisar uma variável',
|
||||||
|
|||||||
@@ -60,7 +60,13 @@ export const parseBubbleBlock = (
|
|||||||
const parsedContent = deepParseVariables(variables)(block.content)
|
const parsedContent = deepParseVariables(variables)(block.content)
|
||||||
return {
|
return {
|
||||||
...block,
|
...block,
|
||||||
content: parsedContent.url ? parseVideoUrl(parsedContent.url) : {},
|
content: {
|
||||||
|
...(parsedContent.url ? parseVideoUrl(parsedContent.url) : {}),
|
||||||
|
height:
|
||||||
|
typeof parsedContent.height === 'string'
|
||||||
|
? parseFloat(parsedContent.height)
|
||||||
|
: parsedContent.height,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ export const VideoBubble = (props: Props) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="flex flex-col animate-fade-in" ref={ref}>
|
<div class="flex flex-col w-full animate-fade-in" ref={ref}>
|
||||||
<div class="flex w-full items-center">
|
<div class="flex w-full items-center">
|
||||||
<div class="flex relative z-10 items-start typebot-host-bubble overflow-hidden">
|
<div class="flex relative z-10 items-start typebot-host-bubble overflow-hidden w-full">
|
||||||
<div
|
<div
|
||||||
class="flex items-center absolute px-4 py-2 bubble-typing z-10 "
|
class="flex items-center absolute px-4 py-2 bubble-typing z-10 "
|
||||||
style={{
|
style={{
|
||||||
@@ -86,7 +86,11 @@ export const VideoBubble = (props: Props) => {
|
|||||||
isTyping() ? 'opacity-0' : 'opacity-100 p-4'
|
isTyping() ? 'opacity-0' : 'opacity-100 p-4'
|
||||||
)}
|
)}
|
||||||
style={{
|
style={{
|
||||||
height: isTyping() ? (isMobile() ? '32px' : '36px') : '200px',
|
height: isTyping()
|
||||||
|
? isMobile()
|
||||||
|
? '32px'
|
||||||
|
: '36px'
|
||||||
|
: `${props.content.height ?? '400'}px`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<iframe
|
<iframe
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ import { z } from 'zod'
|
|||||||
import { blockBaseSchema } from '../../baseSchemas'
|
import { blockBaseSchema } from '../../baseSchemas'
|
||||||
import { BubbleBlockType } from '../enums'
|
import { BubbleBlockType } from '../enums'
|
||||||
import { VideoBubbleContentType } from './enums'
|
import { VideoBubbleContentType } from './enums'
|
||||||
|
import { variableStringSchema } from '../../../utils'
|
||||||
|
|
||||||
export const videoBubbleContentSchema = z.object({
|
export const videoBubbleContentSchema = z.object({
|
||||||
url: z.string().optional(),
|
url: z.string().optional(),
|
||||||
id: z.string().optional(),
|
id: z.string().optional(),
|
||||||
type: z.nativeEnum(VideoBubbleContentType).optional(),
|
type: z.nativeEnum(VideoBubbleContentType).optional(),
|
||||||
|
height: z.number().or(variableStringSchema).optional(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export const videoBubbleBlockSchema = blockBaseSchema.merge(
|
export const videoBubbleBlockSchema = blockBaseSchema.merge(
|
||||||
|
|||||||
Reference in New Issue
Block a user