@inditeai/react 0.0.8 → 0.0.81
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/README.md +144 -144
- package/base.json +22 -22
- package/dist/Standard.d.ts +1 -1
- package/dist/Standard.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +45 -47
- package/react-library.json +11 -11
- package/src/Bubble.tsx +51 -51
- package/src/Popup.tsx +56 -56
- package/src/Standard.tsx +35 -35
- package/src/index.ts +5 -4
- package/tsconfig.json +15 -15
package/README.md
CHANGED
|
@@ -1,144 +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.
|
|
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/base.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
-
"display": "Default",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"composite": false,
|
|
6
|
-
"declaration": false,
|
|
7
|
-
"declarationMap": false,
|
|
8
|
-
"esModuleInterop": true,
|
|
9
|
-
"forceConsistentCasingInFileNames": true,
|
|
10
|
-
"inlineSources": false,
|
|
11
|
-
"isolatedModules": true,
|
|
12
|
-
"moduleResolution": "node",
|
|
13
|
-
"noUnusedLocals": false,
|
|
14
|
-
"noUnusedParameters": false,
|
|
15
|
-
"preserveWatchOutput": true,
|
|
16
|
-
"skipLibCheck": true,
|
|
17
|
-
"strict": true,
|
|
18
|
-
"downlevelIteration": true,
|
|
19
|
-
"noEmit": true
|
|
20
|
-
},
|
|
21
|
-
"exclude": ["node_modules"]
|
|
22
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"display": "Default",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"composite": false,
|
|
6
|
+
"declaration": false,
|
|
7
|
+
"declarationMap": false,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"inlineSources": false,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"moduleResolution": "node",
|
|
13
|
+
"noUnusedLocals": false,
|
|
14
|
+
"noUnusedParameters": false,
|
|
15
|
+
"preserveWatchOutput": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"strict": true,
|
|
18
|
+
"downlevelIteration": true,
|
|
19
|
+
"noEmit": true
|
|
20
|
+
},
|
|
21
|
+
"exclude": ["node_modules"]
|
|
22
|
+
}
|
package/dist/Standard.d.ts
CHANGED
package/dist/Standard.d.ts.map
CHANGED
|
@@ -1 +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,
|
|
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,cAAc,CAAA;AAC5C,OAAO,uBAAuB,CAAA;AAE9B,KAAK,KAAK,GAAG,QAAQ,GAAG;IACtB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,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.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// v0.0.
|
|
1
|
+
// v0.0.81
|
|
2
2
|
import{jsx as r}from"react/jsx-runtime";import{useRef as e,useEffect as t,useCallback as n}from"react";import"@inditeai/js/dist/web";export*from"@inditeai/js/dist";"function"==typeof SuppressedError&&SuppressedError;const o=n=>{var{style:o,className:c}=n,u=function(r,e){var t={};for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&e.indexOf(n)<0&&(t[n]=r[n]);if(null!=r&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(r);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(r,n[o])&&(t[n[o]]=r[n[o]])}return t}(n,["style","className"]);const l=e(null);return t((()=>{l.current&&Object.assign(l.current,u)}),[u]),r("bot-standard",{ref:l,style:o,class:c})},c=r=>{const o=e(null),c=n((r=>{const e=document.createElement("bot-bubble");o.current=e,u(o.current,r),document.body.prepend(o.current)}),[]);t((()=>{o.current||c(r),u(o.current,r)}),[c,r]),t((()=>()=>{var r;null===(r=o.current)||void 0===r||r.remove(),o.current=null}),[]);const u=(r,e)=>{Object.assign(r,e)};return null},u=o=>{const c=e(null),u=e(null),l=n((r=>{var e;const t=document.createElement("bot-popup");u.current=t,s(u.current,r),c.current?null===(e=c.current)||void 0===e||e.append(u.current):console.warn("Could not attach popup to container because containerRef.current is null")}),[]);t((()=>{u.current||l(o),s(u.current,o)}),[l,o]),t((()=>()=>{var r;null===(r=u.current)||void 0===r||r.remove(),u.current=null}),[]);const s=(r,e)=>{Object.assign(r,e)};return r("div",{ref:c})};export{c as Bubble,u as Popup,o as Standard};
|
package/package.json
CHANGED
|
@@ -1,48 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@inditeai/react",
|
|
3
|
-
"version": "0.0.
|
|
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
|
-
|
|
9
|
-
"dev": "rollup --watch --config rollup.config.js",
|
|
10
|
-
"build": "rollup --config rollup.config.js",
|
|
11
|
-
"lint": "eslint --fix \"src/**/*.ts*\"",
|
|
12
|
-
"format:check": "prettier --check ./src"
|
|
13
|
-
},
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"@
|
|
24
|
-
"@
|
|
25
|
-
"@rollup/plugin-
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"@
|
|
29
|
-
"@indite.io/
|
|
30
|
-
"@indite.io/
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"react": "^16.0.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
47
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@inditeai/react",
|
|
3
|
+
"version": "0.0.81",
|
|
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
|
+
"dev": "rollup --watch --config rollup.config.js",
|
|
10
|
+
"build": "rollup --config rollup.config.js",
|
|
11
|
+
"lint": "eslint --fix \"src/**/*.ts*\"",
|
|
12
|
+
"format:check": "prettier --check ./src"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "ART",
|
|
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
|
+
"@inditeai/js": "1.2.62",
|
|
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
|
+
}
|
|
48
46
|
}
|
package/react-library.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
-
"display": "React Library",
|
|
4
|
-
"extends": "./base.json",
|
|
5
|
-
"compilerOptions": {
|
|
6
|
-
"jsx": "react-jsx",
|
|
7
|
-
"lib": ["ES2015", "dom", "dom.iterable"],
|
|
8
|
-
"module": "ESNext",
|
|
9
|
-
"target": "es6"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"display": "React Library",
|
|
4
|
+
"extends": "./base.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"lib": ["ES2015", "dom", "dom.iterable"],
|
|
8
|
+
"module": "ESNext",
|
|
9
|
+
"target": "es6"
|
|
10
|
+
}
|
|
11
|
+
}
|
package/src/Bubble.tsx
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef } from 'react'
|
|
2
|
-
import type { BubbleProps } from '@inditeai/js/dist'
|
|
3
|
-
import '@inditeai/js/dist/web'
|
|
4
|
-
|
|
5
|
-
type Props = BubbleProps
|
|
6
|
-
|
|
7
|
-
declare global {
|
|
8
|
-
namespace JSX {
|
|
9
|
-
interface IntrinsicElements {
|
|
10
|
-
'bot-bubble': React.DetailedHTMLProps<
|
|
11
|
-
React.HTMLAttributes<HTMLElement>,
|
|
12
|
-
HTMLElement
|
|
13
|
-
>
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type BubbleElement = HTMLElement & Props
|
|
19
|
-
|
|
20
|
-
export const Bubble = (props: Props) => {
|
|
21
|
-
const bubbleElement = useRef<BubbleElement | null>(null)
|
|
22
|
-
|
|
23
|
-
const attachBubbleToDom = useCallback((props: Props) => {
|
|
24
|
-
const newBubbleElement = document.createElement(
|
|
25
|
-
'bot-bubble'
|
|
26
|
-
) as BubbleElement
|
|
27
|
-
bubbleElement.current = newBubbleElement
|
|
28
|
-
injectPropsToElement(bubbleElement.current, props)
|
|
29
|
-
document.body.prepend(bubbleElement.current)
|
|
30
|
-
}, [])
|
|
31
|
-
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (!bubbleElement.current) attachBubbleToDom(props)
|
|
34
|
-
injectPropsToElement(bubbleElement.current as BubbleElement, props)
|
|
35
|
-
}, [attachBubbleToDom, props])
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
return () => {
|
|
39
|
-
bubbleElement.current?.remove()
|
|
40
|
-
bubbleElement.current = null
|
|
41
|
-
}
|
|
42
|
-
}, [])
|
|
43
|
-
|
|
44
|
-
const injectPropsToElement = (element: BubbleElement, props: Props) => {
|
|
45
|
-
Object.assign(element, props)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return null
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default Bubble
|
|
1
|
+
import React, { useCallback, useEffect, useRef } from 'react'
|
|
2
|
+
import type { BubbleProps } from '@inditeai/js/dist'
|
|
3
|
+
import '@inditeai/js/dist/web'
|
|
4
|
+
|
|
5
|
+
type Props = BubbleProps
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
namespace JSX {
|
|
9
|
+
interface IntrinsicElements {
|
|
10
|
+
'bot-bubble': React.DetailedHTMLProps<
|
|
11
|
+
React.HTMLAttributes<HTMLElement>,
|
|
12
|
+
HTMLElement
|
|
13
|
+
>
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type BubbleElement = HTMLElement & Props
|
|
19
|
+
|
|
20
|
+
export const Bubble = (props: Props) => {
|
|
21
|
+
const bubbleElement = useRef<BubbleElement | null>(null)
|
|
22
|
+
|
|
23
|
+
const attachBubbleToDom = useCallback((props: Props) => {
|
|
24
|
+
const newBubbleElement = document.createElement(
|
|
25
|
+
'bot-bubble'
|
|
26
|
+
) as BubbleElement
|
|
27
|
+
bubbleElement.current = newBubbleElement
|
|
28
|
+
injectPropsToElement(bubbleElement.current, props)
|
|
29
|
+
document.body.prepend(bubbleElement.current)
|
|
30
|
+
}, [])
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!bubbleElement.current) attachBubbleToDom(props)
|
|
34
|
+
injectPropsToElement(bubbleElement.current as BubbleElement, props)
|
|
35
|
+
}, [attachBubbleToDom, props])
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
return () => {
|
|
39
|
+
bubbleElement.current?.remove()
|
|
40
|
+
bubbleElement.current = null
|
|
41
|
+
}
|
|
42
|
+
}, [])
|
|
43
|
+
|
|
44
|
+
const injectPropsToElement = (element: BubbleElement, props: Props) => {
|
|
45
|
+
Object.assign(element, props)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return null
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default Bubble
|
package/src/Popup.tsx
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useRef } from 'react'
|
|
2
|
-
import type { PopupProps } from '@inditeai/js/dist'
|
|
3
|
-
import '@inditeai/js/dist/web'
|
|
4
|
-
|
|
5
|
-
type Props = PopupProps
|
|
6
|
-
|
|
7
|
-
declare global {
|
|
8
|
-
namespace JSX {
|
|
9
|
-
interface IntrinsicElements {
|
|
10
|
-
'bot-popup': React.DetailedHTMLProps<
|
|
11
|
-
React.HTMLAttributes<HTMLElement>,
|
|
12
|
-
HTMLElement
|
|
13
|
-
> & { class?: string }
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type PopupElement = HTMLElement & Props
|
|
19
|
-
|
|
20
|
-
export const Popup = (props: Props) => {
|
|
21
|
-
const containerRef = useRef<HTMLDivElement | null>(null)
|
|
22
|
-
const popupRef = useRef<PopupElement | null>(null)
|
|
23
|
-
|
|
24
|
-
const attachPopupToContainer = useCallback((props: Props) => {
|
|
25
|
-
const popupElement = document.createElement('bot-popup') as PopupElement
|
|
26
|
-
popupRef.current = popupElement
|
|
27
|
-
injectPropsToElement(popupRef.current, props)
|
|
28
|
-
if (!containerRef.current) {
|
|
29
|
-
console.warn(
|
|
30
|
-
'Could not attach popup to container because containerRef.current is null'
|
|
31
|
-
)
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
containerRef.current?.append(popupRef.current)
|
|
35
|
-
}, [])
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
if (!popupRef.current) attachPopupToContainer(props)
|
|
39
|
-
injectPropsToElement(popupRef.current as PopupElement, props)
|
|
40
|
-
}, [attachPopupToContainer, props])
|
|
41
|
-
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
return () => {
|
|
44
|
-
popupRef.current?.remove()
|
|
45
|
-
popupRef.current = null
|
|
46
|
-
}
|
|
47
|
-
}, [])
|
|
48
|
-
|
|
49
|
-
const injectPropsToElement = (element: PopupElement, props: Props) => {
|
|
50
|
-
Object.assign(element, props)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return <div ref={containerRef} />
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default Popup
|
|
1
|
+
import React, { useCallback, useEffect, useRef } from 'react'
|
|
2
|
+
import type { PopupProps } from '@inditeai/js/dist'
|
|
3
|
+
import '@inditeai/js/dist/web'
|
|
4
|
+
|
|
5
|
+
type Props = PopupProps
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
namespace JSX {
|
|
9
|
+
interface IntrinsicElements {
|
|
10
|
+
'bot-popup': React.DetailedHTMLProps<
|
|
11
|
+
React.HTMLAttributes<HTMLElement>,
|
|
12
|
+
HTMLElement
|
|
13
|
+
> & { class?: string }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type PopupElement = HTMLElement & Props
|
|
19
|
+
|
|
20
|
+
export const Popup = (props: Props) => {
|
|
21
|
+
const containerRef = useRef<HTMLDivElement | null>(null)
|
|
22
|
+
const popupRef = useRef<PopupElement | null>(null)
|
|
23
|
+
|
|
24
|
+
const attachPopupToContainer = useCallback((props: Props) => {
|
|
25
|
+
const popupElement = document.createElement('bot-popup') as PopupElement
|
|
26
|
+
popupRef.current = popupElement
|
|
27
|
+
injectPropsToElement(popupRef.current, props)
|
|
28
|
+
if (!containerRef.current) {
|
|
29
|
+
console.warn(
|
|
30
|
+
'Could not attach popup to container because containerRef.current is null'
|
|
31
|
+
)
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
containerRef.current?.append(popupRef.current)
|
|
35
|
+
}, [])
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (!popupRef.current) attachPopupToContainer(props)
|
|
39
|
+
injectPropsToElement(popupRef.current as PopupElement, props)
|
|
40
|
+
}, [attachPopupToContainer, props])
|
|
41
|
+
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
return () => {
|
|
44
|
+
popupRef.current?.remove()
|
|
45
|
+
popupRef.current = null
|
|
46
|
+
}
|
|
47
|
+
}, [])
|
|
48
|
+
|
|
49
|
+
const injectPropsToElement = (element: PopupElement, props: Props) => {
|
|
50
|
+
Object.assign(element, props)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return <div ref={containerRef} />
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default Popup
|
package/src/Standard.tsx
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import React, { useEffect, useRef } from 'react'
|
|
2
|
-
import type { BotProps } from '@inditeai/js
|
|
3
|
-
import '@inditeai/js/dist/web'
|
|
4
|
-
|
|
5
|
-
type Props = BotProps & {
|
|
6
|
-
style?: React.CSSProperties
|
|
7
|
-
className?: string
|
|
8
|
-
source?: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare global {
|
|
12
|
-
namespace JSX {
|
|
13
|
-
interface IntrinsicElements {
|
|
14
|
-
'bot-standard': React.DetailedHTMLProps<
|
|
15
|
-
React.HTMLAttributes<HTMLElement>,
|
|
16
|
-
HTMLElement
|
|
17
|
-
> & { class?: string }
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
type StandardElement = HTMLElement & Props
|
|
23
|
-
|
|
24
|
-
export const Standard = ({ style, className, ...assignableProps }: Props) => {
|
|
25
|
-
const ref = useRef<StandardElement | null>(null)
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (!ref.current) return
|
|
29
|
-
Object.assign(ref.current, assignableProps)
|
|
30
|
-
}, [assignableProps])
|
|
31
|
-
|
|
32
|
-
return <bot-standard ref={ref} style={style} class={className} />
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export default Standard
|
|
1
|
+
import React, { useEffect, useRef } from 'react'
|
|
2
|
+
import type { BotProps } from '@inditeai/js'
|
|
3
|
+
import '@inditeai/js/dist/web'
|
|
4
|
+
|
|
5
|
+
type Props = BotProps & {
|
|
6
|
+
style?: React.CSSProperties
|
|
7
|
+
className?: string
|
|
8
|
+
source?: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare global {
|
|
12
|
+
namespace JSX {
|
|
13
|
+
interface IntrinsicElements {
|
|
14
|
+
'bot-standard': React.DetailedHTMLProps<
|
|
15
|
+
React.HTMLAttributes<HTMLElement>,
|
|
16
|
+
HTMLElement
|
|
17
|
+
> & { class?: string }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type StandardElement = HTMLElement & Props
|
|
23
|
+
|
|
24
|
+
export const Standard = ({ style, className, ...assignableProps }: Props) => {
|
|
25
|
+
const ref = useRef<StandardElement | null>(null)
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!ref.current) return
|
|
29
|
+
Object.assign(ref.current, assignableProps)
|
|
30
|
+
}, [assignableProps])
|
|
31
|
+
|
|
32
|
+
return <bot-standard ref={ref} style={style} class={className} />
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export default Standard
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { Standard } from './Standard'
|
|
2
|
-
export { Bubble } from './Bubble'
|
|
3
|
-
export { Popup } from './Popup'
|
|
4
|
-
export * from '@inditeai/js/dist'
|
|
1
|
+
export { Standard } from './Standard'
|
|
2
|
+
export { Bubble } from './Bubble'
|
|
3
|
+
export { Popup } from './Popup'
|
|
4
|
+
export * from '@inditeai/js/dist'
|
|
5
|
+
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./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
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "./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
|
+
}
|