✨ (embed) Add new command setInputValue
This commit is contained in:
@@ -43,8 +43,8 @@ export const NextjsLogo = (props: IconProps) => (
|
|||||||
y1="116.5"
|
y1="116.5"
|
||||||
y2="160.5"
|
y2="160.5"
|
||||||
>
|
>
|
||||||
<stop stop-color="white"></stop>
|
<stop stopColor="white"></stop>
|
||||||
<stop offset="1" stop-color="white" stop-opacity="0"></stop>
|
<stop offset="1" stopColor="white" stopOpacity="0"></stop>
|
||||||
</linearGradient>
|
</linearGradient>
|
||||||
<linearGradient
|
<linearGradient
|
||||||
gradientUnits="userSpaceOnUse"
|
gradientUnits="userSpaceOnUse"
|
||||||
@@ -54,8 +54,8 @@ export const NextjsLogo = (props: IconProps) => (
|
|||||||
y1="54"
|
y1="54"
|
||||||
y2="106.875"
|
y2="106.875"
|
||||||
>
|
>
|
||||||
<stop stop-color="white"></stop>
|
<stop stopColor="white"></stop>
|
||||||
<stop offset="1" stop-color="white" stop-opacity="0"></stop>
|
<stop offset="1" stopColor="white" stopOpacity="0"></stop>
|
||||||
</linearGradient>
|
</linearGradient>
|
||||||
</defs>
|
</defs>
|
||||||
</Icon>
|
</Icon>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ Here are the commands you can use to trigger your embedded typebot:
|
|||||||
- `Typebot.showPreviewMessage()`: Show preview message from the bubble,
|
- `Typebot.showPreviewMessage()`: Show preview message from the bubble,
|
||||||
- `Typebot.hidePreviewMessage()`: Hide preview message from the bubble,
|
- `Typebot.hidePreviewMessage()`: Hide preview message from the bubble,
|
||||||
- `Typebot.setPrefilledVariables(...)`: Set prefilled variables.
|
- `Typebot.setPrefilledVariables(...)`: Set prefilled variables.
|
||||||
|
- `Typebot.setInputValue(...)`: Set the value in the currently displayed input.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/js",
|
"name": "@typebot.io/js",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"description": "Javascript library to display typebots on your website",
|
"description": "Javascript library to display typebots on your website",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { ShortTextInput } from '@/components'
|
import { ShortTextInput } from '@/components'
|
||||||
import { SendButton } from '@/components/SendButton'
|
import { SendButton } from '@/components/SendButton'
|
||||||
|
import { CommandData } from '@/features/commands/types'
|
||||||
import { InputSubmitContent } from '@/types'
|
import { InputSubmitContent } from '@/types'
|
||||||
import { isMobile } from '@/utils/isMobileSignal'
|
import { isMobile } from '@/utils/isMobileSignal'
|
||||||
import type { EmailInputBlock } from '@typebot.io/schemas'
|
import type { EmailInputBlock } from '@typebot.io/schemas'
|
||||||
import { createSignal, onMount } from 'solid-js'
|
import { createSignal, onCleanup, onMount } from 'solid-js'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
block: EmailInputBlock
|
block: EmailInputBlock
|
||||||
@@ -30,8 +31,19 @@ export const EmailInput = (props: Props) => {
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!isMobile() && inputRef) inputRef.focus()
|
if (!isMobile() && inputRef) inputRef.focus()
|
||||||
|
window.addEventListener('message', processIncomingEvent)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
window.removeEventListener('message', processIncomingEvent)
|
||||||
|
})
|
||||||
|
|
||||||
|
const processIncomingEvent = (event: MessageEvent<CommandData>) => {
|
||||||
|
const { data } = event
|
||||||
|
if (!data.isFromTypebot) return
|
||||||
|
if (data.command === 'setInputValue') setInputValue(data.value)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={'flex items-end justify-between pr-2 typebot-input w-full'}
|
class={'flex items-end justify-between pr-2 typebot-input w-full'}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { ShortTextInput } from '@/components'
|
import { ShortTextInput } from '@/components'
|
||||||
import { SendButton } from '@/components/SendButton'
|
import { SendButton } from '@/components/SendButton'
|
||||||
|
import { CommandData } from '@/features/commands/types'
|
||||||
import { InputSubmitContent } from '@/types'
|
import { InputSubmitContent } from '@/types'
|
||||||
import { isMobile } from '@/utils/isMobileSignal'
|
import { isMobile } from '@/utils/isMobileSignal'
|
||||||
import type { NumberInputBlock } from '@typebot.io/schemas'
|
import type { NumberInputBlock } from '@typebot.io/schemas'
|
||||||
import { createSignal, onMount } from 'solid-js'
|
import { createSignal, onCleanup, onMount } from 'solid-js'
|
||||||
|
|
||||||
type NumberInputProps = {
|
type NumberInputProps = {
|
||||||
block: NumberInputBlock
|
block: NumberInputBlock
|
||||||
@@ -30,8 +31,19 @@ export const NumberInput = (props: NumberInputProps) => {
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!isMobile() && inputRef) inputRef.focus()
|
if (!isMobile() && inputRef) inputRef.focus()
|
||||||
|
window.addEventListener('message', processIncomingEvent)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
window.removeEventListener('message', processIncomingEvent)
|
||||||
|
})
|
||||||
|
|
||||||
|
const processIncomingEvent = (event: MessageEvent<CommandData>) => {
|
||||||
|
const { data } = event
|
||||||
|
if (!data.isFromTypebot) return
|
||||||
|
if (data.command === 'setInputValue') setInputValue(data.value)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={'flex items-end justify-between pr-2 typebot-input w-full'}
|
class={'flex items-end justify-between pr-2 typebot-input w-full'}
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ import { SendButton } from '@/components/SendButton'
|
|||||||
import { InputSubmitContent } from '@/types'
|
import { InputSubmitContent } from '@/types'
|
||||||
import { isMobile } from '@/utils/isMobileSignal'
|
import { isMobile } from '@/utils/isMobileSignal'
|
||||||
import type { PhoneNumberInputOptions } from '@typebot.io/schemas'
|
import type { PhoneNumberInputOptions } from '@typebot.io/schemas'
|
||||||
import { createSignal, For, onMount } from 'solid-js'
|
import { createSignal, For, onCleanup, onMount } from 'solid-js'
|
||||||
import { isEmpty } from '@typebot.io/lib'
|
import { isEmpty } from '@typebot.io/lib'
|
||||||
import { phoneCountries } from '@typebot.io/lib/phoneCountries'
|
import { phoneCountries } from '@typebot.io/lib/phoneCountries'
|
||||||
|
import { CommandData } from '@/features/commands/types'
|
||||||
|
|
||||||
type PhoneInputProps = Pick<
|
type PhoneInputProps = Pick<
|
||||||
PhoneNumberInputOptions,
|
PhoneNumberInputOptions,
|
||||||
@@ -33,7 +34,7 @@ export const PhoneInput = (props: PhoneInputProps) => {
|
|||||||
const matchedCountry =
|
const matchedCountry =
|
||||||
inputValue?.startsWith('+') &&
|
inputValue?.startsWith('+') &&
|
||||||
inputValue.length > 2 &&
|
inputValue.length > 2 &&
|
||||||
phoneCountries.reduce<typeof phoneCountries[number] | null>(
|
phoneCountries.reduce<(typeof phoneCountries)[number] | null>(
|
||||||
(matchedCountry, country) => {
|
(matchedCountry, country) => {
|
||||||
if (
|
if (
|
||||||
!country?.dial_code ||
|
!country?.dial_code ||
|
||||||
@@ -87,8 +88,19 @@ export const PhoneInput = (props: PhoneInputProps) => {
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!isMobile() && inputRef) inputRef.focus()
|
if (!isMobile() && inputRef) inputRef.focus()
|
||||||
|
window.addEventListener('message', processIncomingEvent)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
window.removeEventListener('message', processIncomingEvent)
|
||||||
|
})
|
||||||
|
|
||||||
|
const processIncomingEvent = (event: MessageEvent<CommandData>) => {
|
||||||
|
const { data } = event
|
||||||
|
if (!data.isFromTypebot) return
|
||||||
|
if (data.command === 'setInputValue') setInputValue(data.value)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={'flex items-end justify-between pr-2 typebot-input'}
|
class={'flex items-end justify-between pr-2 typebot-input'}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { Textarea, ShortTextInput } from '@/components'
|
import { Textarea, ShortTextInput } from '@/components'
|
||||||
import { SendButton } from '@/components/SendButton'
|
import { SendButton } from '@/components/SendButton'
|
||||||
|
import { CommandData } from '@/features/commands'
|
||||||
import { InputSubmitContent } from '@/types'
|
import { InputSubmitContent } from '@/types'
|
||||||
import { isMobile } from '@/utils/isMobileSignal'
|
import { isMobile } from '@/utils/isMobileSignal'
|
||||||
import type { TextInputBlock } from '@typebot.io/schemas'
|
import type { TextInputBlock } from '@typebot.io/schemas'
|
||||||
import { createSignal, onMount } from 'solid-js'
|
import { createSignal, onCleanup, onMount } from 'solid-js'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
block: TextInputBlock
|
block: TextInputBlock
|
||||||
@@ -36,8 +37,19 @@ export const TextInput = (props: Props) => {
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!isMobile() && inputRef) inputRef.focus()
|
if (!isMobile() && inputRef) inputRef.focus()
|
||||||
|
window.addEventListener('message', processIncomingEvent)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
window.removeEventListener('message', processIncomingEvent)
|
||||||
|
})
|
||||||
|
|
||||||
|
const processIncomingEvent = (event: MessageEvent<CommandData>) => {
|
||||||
|
const { data } = event
|
||||||
|
if (!data.isFromTypebot) return
|
||||||
|
if (data.command === 'setInputValue') setInputValue(data.value)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={'flex items-end justify-between pr-2 typebot-input w-full'}
|
class={'flex items-end justify-between pr-2 typebot-input w-full'}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { ShortTextInput } from '@/components'
|
import { ShortTextInput } from '@/components'
|
||||||
import { SendButton } from '@/components/SendButton'
|
import { SendButton } from '@/components/SendButton'
|
||||||
|
import { CommandData } from '@/features/commands/types'
|
||||||
import { InputSubmitContent } from '@/types'
|
import { InputSubmitContent } from '@/types'
|
||||||
import { isMobile } from '@/utils/isMobileSignal'
|
import { isMobile } from '@/utils/isMobileSignal'
|
||||||
import type { UrlInputBlock } from '@typebot.io/schemas'
|
import type { UrlInputBlock } from '@typebot.io/schemas'
|
||||||
import { createSignal, onMount } from 'solid-js'
|
import { createSignal, onCleanup, onMount } from 'solid-js'
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
block: UrlInputBlock
|
block: UrlInputBlock
|
||||||
@@ -36,8 +37,19 @@ export const UrlInput = (props: Props) => {
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!isMobile() && inputRef) inputRef.focus()
|
if (!isMobile() && inputRef) inputRef.focus()
|
||||||
|
window.addEventListener('message', processIncomingEvent)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
window.removeEventListener('message', processIncomingEvent)
|
||||||
|
})
|
||||||
|
|
||||||
|
const processIncomingEvent = (event: MessageEvent<CommandData>) => {
|
||||||
|
const { data } = event
|
||||||
|
if (!data.isFromTypebot) return
|
||||||
|
if (data.command === 'setInputValue') setInputValue(data.value)
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
class={'flex items-end justify-between pr-2 typebot-input w-full'}
|
class={'flex items-end justify-between pr-2 typebot-input w-full'}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export type CommandData = {
|
|||||||
}
|
}
|
||||||
| ShowMessageCommandData
|
| ShowMessageCommandData
|
||||||
| SetPrefilledVariablesCommandData
|
| SetPrefilledVariablesCommandData
|
||||||
|
| SetInputValueCommandData
|
||||||
)
|
)
|
||||||
|
|
||||||
export type ShowMessageCommandData = {
|
export type ShowMessageCommandData = {
|
||||||
@@ -19,3 +20,8 @@ export type SetPrefilledVariablesCommandData = {
|
|||||||
command: 'setPrefilledVariables'
|
command: 'setPrefilledVariables'
|
||||||
variables: Record<string, string | number | boolean>
|
variables: Record<string, string | number | boolean>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type SetInputValueCommandData = {
|
||||||
|
command: 'setInputValue'
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ export * from './open'
|
|||||||
export * from './setPrefilledVariables'
|
export * from './setPrefilledVariables'
|
||||||
export * from './showPreviewMessage'
|
export * from './showPreviewMessage'
|
||||||
export * from './toggle'
|
export * from './toggle'
|
||||||
|
export * from './setInputValue'
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { CommandData } from '../types'
|
||||||
|
|
||||||
|
export const setInputValue = (value: string) => {
|
||||||
|
const message: CommandData = {
|
||||||
|
isFromTypebot: true,
|
||||||
|
command: 'setInputValue',
|
||||||
|
value,
|
||||||
|
}
|
||||||
|
window.postMessage(message)
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/nextjs",
|
"name": "@typebot.io/nextjs",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"description": "Convenient library to display typebots on your Next.js website",
|
"description": "Convenient library to display typebots on your Next.js website",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/react",
|
"name": "@typebot.io/react",
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"description": "Convenient library to display typebots on your Next.js website",
|
"description": "Convenient library to display typebots on your Next.js website",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
showPreviewMessage,
|
showPreviewMessage,
|
||||||
hidePreviewMessage,
|
hidePreviewMessage,
|
||||||
setPrefilledVariables,
|
setPrefilledVariables,
|
||||||
|
setInputValue,
|
||||||
} from '@typebot.io/js'
|
} from '@typebot.io/js'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { leadGenerationTypebot } from './assets/leadGenerationTypebot'
|
import { leadGenerationTypebot } from './assets/leadGenerationTypebot'
|
||||||
@@ -23,6 +24,7 @@ export const Default = () => {
|
|||||||
<button onClick={() => showPreviewMessage()}>
|
<button onClick={() => showPreviewMessage()}>
|
||||||
Show Preview Message
|
Show Preview Message
|
||||||
</button>
|
</button>
|
||||||
|
<button onClick={() => setInputValue('YOOOO!')}>Set input value</button>
|
||||||
<button onClick={hidePreviewMessage}>Close Preview Message</button>
|
<button onClick={hidePreviewMessage}>Close Preview Message</button>
|
||||||
<div>
|
<div>
|
||||||
<p>Predefined name:</p>
|
<p>Predefined name:</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user