@inditeai/react 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +8 -0
- package/README.md +144 -0
- package/dist/Bubble.d.ts +13 -0
- package/dist/Bubble.d.ts.map +1 -0
- package/dist/Popup.d.ts +15 -0
- package/dist/Popup.d.ts.map +1 -0
- package/dist/Standard.d.ts +18 -0
- package/dist/Standard.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/stories/bubble.stories.d.ts +2 -0
- package/dist/stories/bubble.stories.d.ts.map +1 -0
- package/dist/stories/popup.stories.d.ts +2 -0
- package/dist/stories/popup.stories.d.ts.map +1 -0
- package/dist/stories/standard.stories.d.ts +3 -0
- package/dist/stories/standard.stories.d.ts.map +1 -0
- package/package.json +46 -0
- package/rollup.config.js +42 -0
- package/tsconfig.json +15 -0
package/.eslintrc.cjs
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
## Install
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
npm install @inditeai/js @inditeai/react
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
## Standard
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { Standard } from '@inditeai/react'
|
|
11
|
+
|
|
12
|
+
const App = () => {
|
|
13
|
+
return (
|
|
14
|
+
<Standard
|
|
15
|
+
bot="lead-generation-copy-3luzm6b"
|
|
16
|
+
style={{ width: '100%', height: '600px' }}
|
|
17
|
+
/>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
This code is creating a container with a 100% width (will match parent width) and 600px height.
|
|
23
|
+
|
|
24
|
+
## Popup
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { Popup } from '@inditeai/react'
|
|
28
|
+
|
|
29
|
+
const App = () => {
|
|
30
|
+
return <Popup bot="lead-generation-copy-3luzm6b" autoShowDelay={3000} />
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
This code will automatically trigger the popup window after 3 seconds.
|
|
35
|
+
|
|
36
|
+
### Open or Close a popup
|
|
37
|
+
|
|
38
|
+
You can use these commands:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
import { open } from '@inditeai/react'
|
|
42
|
+
|
|
43
|
+
open()
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import { close } from '@inditeai/react'
|
|
48
|
+
|
|
49
|
+
close()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
import { toggle } from '@inditeai/react'
|
|
54
|
+
|
|
55
|
+
toggle()
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Bubble
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { Bubble } from '@inditeai/react'
|
|
62
|
+
|
|
63
|
+
const App = () => {
|
|
64
|
+
return (
|
|
65
|
+
<Bubble
|
|
66
|
+
bot="lead-generation-copy-3luzm6b"
|
|
67
|
+
previewMessage={{
|
|
68
|
+
message: 'I have a question for you!',
|
|
69
|
+
autoShowDelay: 5000,
|
|
70
|
+
avatarUrl: 'https://avatars.githubusercontent.com/u/16015833?v=4',
|
|
71
|
+
}}
|
|
72
|
+
theme={{
|
|
73
|
+
button: { backgroundColor: '#0042DA', iconColor: '#FFFFFF' },
|
|
74
|
+
previewMessage: { backgroundColor: '#ffffff', textColor: 'black' },
|
|
75
|
+
}}
|
|
76
|
+
/>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
This code will show the bubble and let a preview message appear after 5 seconds.
|
|
82
|
+
|
|
83
|
+
### Open or close the preview message
|
|
84
|
+
|
|
85
|
+
You can use these commands:
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
import { showPreviewMessage } from '@inditeai/react'
|
|
89
|
+
|
|
90
|
+
Bot.showPreviewMessage()
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import { hidePreviewMessage } from '@inditeai/react'
|
|
95
|
+
|
|
96
|
+
Bot.hidePreviewMessage()
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Open or close the chat window
|
|
100
|
+
|
|
101
|
+
You can use these commands:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
import { open } from '@inditeai/react'
|
|
105
|
+
|
|
106
|
+
open()
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
import { close } from '@inditeai/react'
|
|
111
|
+
|
|
112
|
+
close()
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import { toggle } from '@inditeai/react'
|
|
117
|
+
|
|
118
|
+
toggle()
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Additional configuration
|
|
122
|
+
|
|
123
|
+
You can prefill the bot variable values in your embed code by adding the `prefilledVariables` option. Here is an example:
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
import { Standard } from '@inditeai/react'
|
|
127
|
+
|
|
128
|
+
const App = () => {
|
|
129
|
+
return (
|
|
130
|
+
<Standard
|
|
131
|
+
bot="lead-generation-copy-3luzm6b"
|
|
132
|
+
style={{ width: '100%', height: '600px' }}
|
|
133
|
+
prefilledVariables={{
|
|
134
|
+
'Current URL': 'https://my-site/account',
|
|
135
|
+
'User name': 'John Doe',
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
It will prefill the `Current URL` variable with "https://my-site/account" and the `User name` variable with "John Doe". More info about variables: [here](/editor/variables).
|
|
143
|
+
|
|
144
|
+
Note that if your site URL contains query params (i.e. https://indite.io?User%20name=John%20Doe), the variables will automatically be injected to the bot. So you don't need to manually transfer query params to the bot embed configuration.
|
package/dist/Bubble.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { BubbleProps } from '@indite.io/js';
|
|
3
|
+
type Props = BubbleProps;
|
|
4
|
+
declare global {
|
|
5
|
+
namespace JSX {
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
'bot-bubble': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare const Bubble: (props: Props) => null;
|
|
12
|
+
export default Bubble;
|
|
13
|
+
//# sourceMappingURL=Bubble.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bubble.d.ts","sourceRoot":"","sources":["../src/Bubble.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAGhD,KAAK,KAAK,GAAG,WAAW,CAAA;AAExB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,GAAG,CAAC;QACZ,UAAU,iBAAiB;YACzB,YAAY,EAAE,KAAK,CAAC,iBAAiB,CACnC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EACjC,WAAW,CACZ,CAAA;SACF;KACF;CACF;AAID,eAAO,MAAM,MAAM,UAAW,KAAK,SA6BlC,CAAA;AAED,eAAe,MAAM,CAAA"}
|
package/dist/Popup.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PopupProps } from '@indite.io/js';
|
|
3
|
+
type Props = PopupProps;
|
|
4
|
+
declare global {
|
|
5
|
+
namespace JSX {
|
|
6
|
+
interface IntrinsicElements {
|
|
7
|
+
'bot-popup': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
|
|
8
|
+
class?: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export declare const Popup: (props: Props) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export default Popup;
|
|
15
|
+
//# sourceMappingURL=Popup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Popup.d.ts","sourceRoot":"","sources":["../src/Popup.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAG/C,KAAK,KAAK,GAAG,UAAU,CAAA;AAEvB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,GAAG,CAAC;QACZ,UAAU,iBAAiB;YACzB,WAAW,EAAE,KAAK,CAAC,iBAAiB,CAClC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EACjC,WAAW,CACZ,GAAG;gBAAE,KAAK,CAAC,EAAE,MAAM,CAAA;aAAE,CAAA;SACvB;KACF;CACF;AAID,eAAO,MAAM,KAAK,UAAW,KAAK,4CAkCjC,CAAA;AAED,eAAe,KAAK,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { BotProps } from '@indite.io/js';
|
|
3
|
+
type Props = BotProps & {
|
|
4
|
+
style?: React.CSSProperties;
|
|
5
|
+
className?: string;
|
|
6
|
+
};
|
|
7
|
+
declare global {
|
|
8
|
+
namespace JSX {
|
|
9
|
+
interface IntrinsicElements {
|
|
10
|
+
'bot-standard': React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> & {
|
|
11
|
+
class?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export declare const Standard: ({ style, className, ...assignableProps }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export default Standard;
|
|
18
|
+
//# sourceMappingURL=Standard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Standard.d.ts","sourceRoot":"","sources":["../src/Standard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4B,MAAM,OAAO,CAAA;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAG7C,KAAK,KAAK,GAAG,QAAQ,GAAG;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,GAAG,CAAC;QACZ,UAAU,iBAAiB;YACzB,cAAc,EAAE,KAAK,CAAC,iBAAiB,CACrC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,EACjC,WAAW,CACZ,GAAG;gBAAE,KAAK,CAAC,EAAE,MAAM,CAAA;aAAE,CAAA;SACvB;KACF;CACF;AAID,eAAO,MAAM,QAAQ,6CAA8C,KAAK,4CASvE,CAAA;AAED,eAAe,QAAQ,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,cAAc,eAAe,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// v0.0.1
|
|
2
|
+
import{jsx as e}from"react/jsx-runtime";import{useRef as r,useEffect as t,useCallback as o}from"react";"function"==typeof SuppressedError&&SuppressedError;const n=o=>{var{style:n,className:s}=o,a=function(e,r){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&r.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)r.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(t[o[n]]=e[o[n]])}return t}(o,["style","className"]);const c=r(null);return t((()=>{c.current&&Object.assign(c.current,a)}),[a]),e("bot-standard",{ref:c,style:n,class:s})},s=e=>{const n=r(null),s=o((e=>{const r=document.createElement("bot-bubble");n.current=r,a(n.current,e),document.body.prepend(n.current)}),[]);t((()=>{n.current||s(e),a(n.current,e)}),[s,e]),t((()=>()=>{var e;null===(e=n.current)||void 0===e||e.remove(),n.current=null}),[]);const a=(e,r)=>{Object.assign(e,r)};return null},a=n=>{const s=r(null),a=r(null),c=o((e=>{var r;const t=document.createElement("bot-popup");a.current=t,u(a.current,e),s.current?null===(r=s.current)||void 0===r||r.append(a.current):console.warn("Could not attach popup to container because containerRef.current is null")}),[]);t((()=>{a.current||c(n),u(a.current,n)}),[c,n]),t((()=>()=>{var e;null===(e=a.current)||void 0===e||e.remove(),a.current=null}),[]);const u=(e,r)=>{Object.assign(e,r)};return e("div",{ref:s})},c=()=>{window.postMessage({isFromBot:!0,command:"close"})},u=()=>{window.postMessage({isFromBot:!0,command:"hidePreviewMessage"})},l=()=>{window.postMessage({isFromBot:!0,command:"open"})},i=e=>{const r={isFromBot:!0,command:"setPrefilledVariables",variables:e};window.postMessage(r)},m=e=>{const r={isFromBot:!0,command:"showPreviewMessage",message:e};window.postMessage(r)},p=()=>{window.postMessage({isFromBot:!0,command:"toggle"})},d=e=>{const r={isFromBot:!0,command:"setInputValue",value:e};window.postMessage(r)},w=()=>{window.postMessage({isFromBot:!0,command:"unmount"})};export{s as Bubble,a as Popup,n as Standard,c as close,u as hidePreviewMessage,l as open,d as setInputValue,i as setPrefilledVariables,m as showPreviewMessage,p as toggle,w as unmount};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bubble.stories.d.ts","sourceRoot":"","sources":["../../src/stories/bubble.stories.tsx"],"names":[],"mappings":"AAaA,eAAO,MAAM,OAAO,+CA6CnB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"popup.stories.d.ts","sourceRoot":"","sources":["../../src/stories/popup.stories.tsx"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO,+CAiBnB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standard.stories.d.ts","sourceRoot":"","sources":["../../src/stories/standard.stories.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO,+CAWnB,CAAA;AAED,eAAO,MAAM,iBAAiB,+CAa7B,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inditeai/react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Convenient library to display bots on your React app",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"stories:dev": "ladle serve -p 3006",
|
|
10
|
+
"stories:build": "ladle build",
|
|
11
|
+
"dev": "rollup --watch --config rollup.config.js",
|
|
12
|
+
"build": "rollup --config rollup.config.js",
|
|
13
|
+
"lint": "eslint --fix \"src/**/*.ts*\"",
|
|
14
|
+
"format:check": "prettier --check ./src"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@ladle/react": "2.5.1"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@babel/preset-react": "7.22.5",
|
|
22
|
+
"@babel/preset-typescript": "7.22.5",
|
|
23
|
+
"@rollup/plugin-babel": "6.0.3",
|
|
24
|
+
"@rollup/plugin-node-resolve": "15.1.0",
|
|
25
|
+
"@rollup/plugin-terser": "0.4.3",
|
|
26
|
+
"@indite.io/js": "workspace:*",
|
|
27
|
+
"@indite.io/lib": "workspace:*",
|
|
28
|
+
"@indite.io/prisma": "workspace:*",
|
|
29
|
+
"@indite.io/schemas": "workspace:*",
|
|
30
|
+
"@indite.io/tsconfig": "workspace:*",
|
|
31
|
+
"@types/node": "20.4.2",
|
|
32
|
+
"@types/react": "18.2.15",
|
|
33
|
+
"eslint": "8.44.0",
|
|
34
|
+
"eslint-config-custom": "workspace:*",
|
|
35
|
+
"react": "18.2.0",
|
|
36
|
+
"rollup": "3.26.2",
|
|
37
|
+
"rollup-plugin-typescript-paths": "1.4.0",
|
|
38
|
+
"tslib": "2.6.0",
|
|
39
|
+
"tsx": "4.6.2",
|
|
40
|
+
"typescript": "5.4.5",
|
|
41
|
+
"@rollup/plugin-typescript": "11.1.2"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": "^16.0.0 || ^17.0.0 || ^18.0.0"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve'
|
|
2
|
+
import terser from '@rollup/plugin-terser'
|
|
3
|
+
import { babel } from '@rollup/plugin-babel'
|
|
4
|
+
import { typescriptPaths } from 'rollup-plugin-typescript-paths'
|
|
5
|
+
import typescript from '@rollup/plugin-typescript'
|
|
6
|
+
import fs from 'fs'
|
|
7
|
+
|
|
8
|
+
const extensions = ['.ts', '.tsx']
|
|
9
|
+
|
|
10
|
+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'))
|
|
11
|
+
const packageVersion = packageJson.version
|
|
12
|
+
const preamble = `// v${packageVersion}`
|
|
13
|
+
|
|
14
|
+
const indexConfig = {
|
|
15
|
+
input: './src/index.ts',
|
|
16
|
+
output: {
|
|
17
|
+
file: './dist/index.js',
|
|
18
|
+
format: 'es',
|
|
19
|
+
},
|
|
20
|
+
external: ['react', 'react/jsx-runtime'],
|
|
21
|
+
watch: {
|
|
22
|
+
clearScreen: false,
|
|
23
|
+
},
|
|
24
|
+
plugins: [
|
|
25
|
+
resolve({ extensions }),
|
|
26
|
+
babel({
|
|
27
|
+
babelHelpers: 'bundled',
|
|
28
|
+
exclude: 'node_modules/**',
|
|
29
|
+
presets: ['@babel/preset-react', '@babel/preset-typescript'],
|
|
30
|
+
extensions,
|
|
31
|
+
}),
|
|
32
|
+
typescriptPaths({ preserveExtensions: true }),
|
|
33
|
+
typescript({
|
|
34
|
+
noEmitOnError: !process.env.ROLLUP_WATCH,
|
|
35
|
+
}),
|
|
36
|
+
terser({ format: { preamble } }),
|
|
37
|
+
],
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const configs = [indexConfig]
|
|
41
|
+
|
|
42
|
+
export default configs
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@indite.io/tsconfig/react-library.json",
|
|
3
|
+
"include": ["src/**/*"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"paths": {
|
|
7
|
+
"@/*": ["src/*"]
|
|
8
|
+
},
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"declarationMap": true,
|
|
12
|
+
"noEmit": false,
|
|
13
|
+
"emitDeclarationOnly": true
|
|
14
|
+
}
|
|
15
|
+
}
|