2
0

🧑‍💻 Better Typebot import in vanilla JS sites

This commit is contained in:
Baptiste Arnaud
2023-02-21 10:05:24 +01:00
parent 907cad8050
commit ab43d809c3
4 changed files with 36 additions and 30 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.0.7",
"version": "0.0.8",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",

View File

@@ -1,5 +1,10 @@
import { registerWebComponents } from './register'
import { injectTypebotInWindow } from './window'
import { parseTypebot, injectTypebotInWindow } from './window'
registerWebComponents()
injectTypebotInWindow()
const typebot = parseTypebot()
injectTypebotInWindow(typebot)
export default typebot

View File

@@ -31,10 +31,7 @@ export const initBubble = (props: BubbleProps) => {
document.body.appendChild(bubbleElement)
}
declare const window:
| {
Typebot:
| {
type Typebot = {
initStandard: typeof initStandard
initPopup: typeof initPopup
initBubble: typeof initBubble
@@ -45,14 +42,14 @@ declare const window:
showPreviewMessage: typeof showPreviewMessage
toggle: typeof toggle
}
| undefined
declare const window:
| {
Typebot: Typebot | undefined
}
| undefined
export const injectTypebotInWindow = () => {
if (typeof window === 'undefined') return
window.Typebot = {
export const parseTypebot = () => ({
initStandard,
initPopup,
initBubble,
@@ -62,5 +59,9 @@ export const injectTypebotInWindow = () => {
setPrefilledVariables,
showPreviewMessage,
toggle,
}
})
export const injectTypebotInWindow = (typebot: Typebot) => {
if (typeof window === 'undefined') return
window.Typebot = { ...typebot }
}

View File

@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.0.7",
"version": "0.0.8",
"description": "React library to display typebots on your website",
"main": "dist/index.js",
"types": "dist/index.d.ts",