🧑💻 Better Typebot import in vanilla JS sites
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/js",
|
"name": "@typebot.io/js",
|
||||||
"version": "0.0.7",
|
"version": "0.0.8",
|
||||||
"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,5 +1,10 @@
|
|||||||
import { registerWebComponents } from './register'
|
import { registerWebComponents } from './register'
|
||||||
import { injectTypebotInWindow } from './window'
|
import { parseTypebot, injectTypebotInWindow } from './window'
|
||||||
|
|
||||||
registerWebComponents()
|
registerWebComponents()
|
||||||
injectTypebotInWindow()
|
|
||||||
|
const typebot = parseTypebot()
|
||||||
|
|
||||||
|
injectTypebotInWindow(typebot)
|
||||||
|
|
||||||
|
export default typebot
|
||||||
|
|||||||
@@ -31,36 +31,37 @@ export const initBubble = (props: BubbleProps) => {
|
|||||||
document.body.appendChild(bubbleElement)
|
document.body.appendChild(bubbleElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Typebot = {
|
||||||
|
initStandard: typeof initStandard
|
||||||
|
initPopup: typeof initPopup
|
||||||
|
initBubble: typeof initBubble
|
||||||
|
close: typeof close
|
||||||
|
hidePreviewMessage: typeof hidePreviewMessage
|
||||||
|
open: typeof open
|
||||||
|
setPrefilledVariables: typeof setPrefilledVariables
|
||||||
|
showPreviewMessage: typeof showPreviewMessage
|
||||||
|
toggle: typeof toggle
|
||||||
|
}
|
||||||
|
|
||||||
declare const window:
|
declare const window:
|
||||||
| {
|
| {
|
||||||
Typebot:
|
Typebot: Typebot | undefined
|
||||||
| {
|
|
||||||
initStandard: typeof initStandard
|
|
||||||
initPopup: typeof initPopup
|
|
||||||
initBubble: typeof initBubble
|
|
||||||
close: typeof close
|
|
||||||
hidePreviewMessage: typeof hidePreviewMessage
|
|
||||||
open: typeof open
|
|
||||||
setPrefilledVariables: typeof setPrefilledVariables
|
|
||||||
showPreviewMessage: typeof showPreviewMessage
|
|
||||||
toggle: typeof toggle
|
|
||||||
}
|
|
||||||
| undefined
|
|
||||||
}
|
}
|
||||||
| undefined
|
| undefined
|
||||||
|
|
||||||
export const injectTypebotInWindow = () => {
|
export const parseTypebot = () => ({
|
||||||
if (typeof window === 'undefined') return
|
initStandard,
|
||||||
|
initPopup,
|
||||||
|
initBubble,
|
||||||
|
close,
|
||||||
|
hidePreviewMessage,
|
||||||
|
open,
|
||||||
|
setPrefilledVariables,
|
||||||
|
showPreviewMessage,
|
||||||
|
toggle,
|
||||||
|
})
|
||||||
|
|
||||||
window.Typebot = {
|
export const injectTypebotInWindow = (typebot: Typebot) => {
|
||||||
initStandard,
|
if (typeof window === 'undefined') return
|
||||||
initPopup,
|
window.Typebot = { ...typebot }
|
||||||
initBubble,
|
|
||||||
close,
|
|
||||||
hidePreviewMessage,
|
|
||||||
open,
|
|
||||||
setPrefilledVariables,
|
|
||||||
showPreviewMessage,
|
|
||||||
toggle,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@typebot.io/react",
|
"name": "@typebot.io/react",
|
||||||
"version": "0.0.7",
|
"version": "0.0.8",
|
||||||
"description": "React library to display typebots on your website",
|
"description": "React library to display typebots on your website",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
Reference in New Issue
Block a user