@spexsol/chat-widget-react 0.0.0-stage → 0.1.0
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 +32 -2
- package/dist/index.d.ts +15 -0
- package/dist/index.js +30 -0
- package/package.json +34 -3
package/README.md
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @spexsol/chat-widget-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React component that loads the Spexsol chat widget.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @spexsol/chat-widget-react
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { ChatWidget } from '@spexsol/chat-widget-react'
|
|
11
|
+
|
|
12
|
+
export default function App() {
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
{/* ... */}
|
|
16
|
+
<ChatWidget widgetKey="YOUR_WIDGET_KEY" src="https://YOUR_INSTANCE/widget.js" lang="sk" />
|
|
17
|
+
</>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
| Prop | Required | Meaning |
|
|
23
|
+
| ----------- | -------- | --------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `widgetKey` | yes | Widget key from the dashboard |
|
|
25
|
+
| `src` | yes | `widget.js` URL of your chatbot instance |
|
|
26
|
+
| `lang` | no | `sk`, `cs`, `de` or `en`; omit to follow the browser. Changing it switches the widget language live |
|
|
27
|
+
| `api` | no | API base URL, default `<origin of src>/v1` |
|
|
28
|
+
|
|
29
|
+
Mount it once, in the app root. The widget is one per page: it stays when the component unmounts,
|
|
30
|
+
and later changes to `src`, `widgetKey` or `api` take effect only after a page reload.
|
|
31
|
+
Your site's origin must be on the widget's allowed origins in the dashboard.
|
|
32
|
+
|
|
33
|
+
Next.js: works in the App Router, also from server components (the package is marked `'use client'`).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type ChatWidgetProps = {
|
|
2
|
+
/** Widget key from the dashboard (the script's data-key). */
|
|
3
|
+
widgetKey: string;
|
|
4
|
+
/** URL of widget.js on your chatbot instance, e.g. https://chat.example.com/widget.js */
|
|
5
|
+
src: string;
|
|
6
|
+
/** Interface language (sk, cs, de, en). Omit to follow the browser. Changing it switches the open widget. */
|
|
7
|
+
lang?: string;
|
|
8
|
+
/** API base URL; defaults to `<origin of src>/v1`. */
|
|
9
|
+
api?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Loads the chat widget once per page; renders nothing itself.
|
|
13
|
+
* The widget is a page singleton: it stays after unmount, and later changes to src, widgetKey or api are ignored.
|
|
14
|
+
*/
|
|
15
|
+
export declare function ChatWidget({ widgetKey, src, lang, api }: ChatWidgetProps): null;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
const ID = 'spexsol-chat-widget';
|
|
4
|
+
/**
|
|
5
|
+
* Loads the chat widget once per page; renders nothing itself.
|
|
6
|
+
* The widget is a page singleton: it stays after unmount, and later changes to src, widgetKey or api are ignored.
|
|
7
|
+
*/
|
|
8
|
+
export function ChatWidget({ widgetKey, src, lang, api }) {
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
let script = document.getElementById(ID);
|
|
11
|
+
const fresh = !script;
|
|
12
|
+
if (!script) {
|
|
13
|
+
script = document.createElement('script');
|
|
14
|
+
script.id = ID;
|
|
15
|
+
script.async = true;
|
|
16
|
+
script.src = src;
|
|
17
|
+
script.dataset.key = widgetKey;
|
|
18
|
+
if (api)
|
|
19
|
+
script.dataset.api = api;
|
|
20
|
+
}
|
|
21
|
+
// the widget watches data-lang and remounts in the new language
|
|
22
|
+
if (lang)
|
|
23
|
+
script.dataset.lang = lang;
|
|
24
|
+
else
|
|
25
|
+
delete script.dataset.lang;
|
|
26
|
+
if (fresh)
|
|
27
|
+
document.body.appendChild(script);
|
|
28
|
+
}, [widgetKey, src, lang, api]);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spexsol/chat-widget-react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "React component for the Spexsol chat widget",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react": ">=17"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@testing-library/react": "^16.3.3",
|
|
25
|
+
"@types/react": "^19",
|
|
26
|
+
"jsdom": "^28.1.0",
|
|
27
|
+
"react": "19.3.1",
|
|
28
|
+
"react-dom": "19.3.1",
|
|
29
|
+
"typescript": "^7.0.2",
|
|
30
|
+
"vitest": "5.1.1"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"test": "vitest run"
|
|
36
|
+
}
|
|
6
37
|
}
|