2
0

feat(lib): 🎨 Ask for URL instead of publishId

This commit is contained in:
Baptiste Arnaud
2022-03-14 14:57:10 +01:00
parent d6b94130cb
commit 5a2df9fe72
10 changed files with 384 additions and 375 deletions

View File

@ -3,18 +3,16 @@ import './style.css'
export const createIframe = ({
backgroundColor,
viewerHost = 'https://typebot-viewer.vercel.app',
isV1,
url,
...iframeParams
}: IframeParams): HTMLIFrameElement => {
const { publishId, loadWhenVisible, hiddenVariables } = iframeParams
const host = isV1 ? `https://bot.typebot.io` : viewerHost
const iframeUrl = `${host}/${publishId}${parseQueryParams(hiddenVariables)}`
const { loadWhenVisible, hiddenVariables } = iframeParams
const iframeUrl = `${url}${parseQueryParams(hiddenVariables)}`
const iframe = document.createElement('iframe')
iframe.setAttribute(loadWhenVisible ? 'data-src' : 'src', iframeUrl)
iframe.setAttribute('data-id', iframeParams.publishId)
iframe.setAttribute('data-id', url)
const randomThreeLettersId = Math.random().toString(36).substring(7)
const uniqueId = `${publishId}-${randomThreeLettersId}`
const uniqueId = `${url}-${randomThreeLettersId}`
iframe.setAttribute('id', uniqueId)
if (backgroundColor) iframe.style.backgroundColor = backgroundColor
iframe.classList.add('typebot-iframe')

View File

@ -1,7 +1,5 @@
export type IframeParams = {
publishId: string
isV1?: boolean
viewerHost?: string
url: string
backgroundColor?: string
hiddenVariables?: { [key: string]: string | undefined }
customDomain?: string