2
0

feat(lib): ️ Pass host URL params

This commit is contained in:
Baptiste Arnaud
2022-04-28 16:47:22 -07:00
parent 1d82940ed7
commit 7b4dc47f11
2 changed files with 11 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "typebot-js", "name": "typebot-js",
"version": "2.2.3", "version": "2.2.4",
"main": "dist/index.js", "main": "dist/index.js",
"unpkg": "dist/index.umd.min.js", "unpkg": "dist/index.umd.min.js",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",

View File

@@ -7,7 +7,15 @@ export const createIframe = ({
...iframeParams ...iframeParams
}: IframeParams): HTMLIFrameElement => { }: IframeParams): HTMLIFrameElement => {
const { loadWhenVisible, hiddenVariables } = iframeParams const { loadWhenVisible, hiddenVariables } = iframeParams
const iframeUrl = `${url}${parseQueryParams(hiddenVariables)}` const hostUrlParams = new URLSearchParams(document.location.search)
const hostQueryObj: { [key: string]: string } = {}
hostUrlParams.forEach((value, key) => {
hostQueryObj[key] = value
})
const iframeUrl = `${url}${parseQueryParams({
...hiddenVariables,
...hostQueryObj,
})}`
const iframe = document.createElement('iframe') const iframe = document.createElement('iframe')
iframe.setAttribute(loadWhenVisible ? 'data-src' : 'src', iframeUrl) iframe.setAttribute(loadWhenVisible ? 'data-src' : 'src', iframeUrl)
iframe.setAttribute('data-id', url) iframe.setAttribute('data-id', url)
@@ -25,11 +33,7 @@ export const createIframe = ({
const parseQueryParams = (starterVariables?: { const parseQueryParams = (starterVariables?: {
[key: string]: string | undefined [key: string]: string | undefined
}): string => { }): string => {
return parseHostnameQueryParam() + parseStarterVariables(starterVariables) return parseStarterVariables(starterVariables)
}
const parseHostnameQueryParam = () => {
return `?hn=${window.location.hostname}`
} }
const parseStarterVariables = (starterVariables?: { const parseStarterVariables = (starterVariables?: {