🚸 (js) Improve setHiddenVariables command
Extend existing variables instead of overwriting everything
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "typebot-js",
|
"name": "typebot-js",
|
||||||
"version": "2.2.15",
|
"version": "2.2.16",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"unpkg": "dist/index.global.js",
|
"unpkg": "dist/index.global.js",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
|
|||||||
@@ -7,18 +7,17 @@ export const setHiddenVariables = (
|
|||||||
| HTMLIFrameElement
|
| HTMLIFrameElement
|
||||||
| undefined
|
| undefined
|
||||||
if (!existingIframe) return
|
if (!existingIframe) return
|
||||||
const hostUrlParams = new URLSearchParams(document.location.search)
|
const existingUrl =
|
||||||
const hostQueryObj: { [key: string]: string } = {}
|
existingIframe.getAttribute('data-src') || existingIframe.src
|
||||||
hostUrlParams.forEach((value, key) => {
|
const existingHiddenVariables = new URLSearchParams(existingUrl.split('?')[1])
|
||||||
hostQueryObj[key] = value
|
const existingQueryObj: { [key: string]: string } = {}
|
||||||
|
existingHiddenVariables.forEach((value, key) => {
|
||||||
|
existingQueryObj[key] = value
|
||||||
})
|
})
|
||||||
const isLoadWhenVisible = existingIframe.hasAttribute('data-src')
|
const isLoadWhenVisible = existingIframe.hasAttribute('data-src')
|
||||||
const url = (
|
const iframeUrl = `${existingUrl.split('?')[0]}${parseQueryParams({
|
||||||
existingIframe.getAttribute('data-src') || existingIframe.src
|
...existingQueryObj,
|
||||||
).split('?')[0]
|
|
||||||
const iframeUrl = `${url}${parseQueryParams({
|
|
||||||
...hiddenVariables,
|
...hiddenVariables,
|
||||||
...hostQueryObj,
|
|
||||||
})}`
|
})}`
|
||||||
existingIframe.setAttribute(isLoadWhenVisible ? 'data-src' : 'src', iframeUrl)
|
existingIframe.setAttribute(isLoadWhenVisible ? 'data-src' : 'src', iframeUrl)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user