@botu/widget-react 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/dist/index.d.mts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +64 -0
- package/dist/index.mjs +36 -0
- package/package.json +31 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BootOptions, LoadOptions } from '@botu/widget';
|
|
2
|
+
export { boot } from '@botu/widget';
|
|
3
|
+
|
|
4
|
+
type BotuChatWidgetProps = {
|
|
5
|
+
projectId: string;
|
|
6
|
+
bootOptions?: Omit<BootOptions, "project_id">;
|
|
7
|
+
loadOptions?: LoadOptions;
|
|
8
|
+
autoload?: boolean;
|
|
9
|
+
shutdownOnUnmount?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* React wrapper for @botu/widget.
|
|
13
|
+
* - If autoload=true (default), calls boot() on mount.
|
|
14
|
+
* - Renders nothing.
|
|
15
|
+
*/
|
|
16
|
+
declare function BotuChatWidget({ projectId, bootOptions, loadOptions, autoload, shutdownOnUnmount, }: BotuChatWidgetProps): null;
|
|
17
|
+
|
|
18
|
+
export { BotuChatWidget, type BotuChatWidgetProps };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BootOptions, LoadOptions } from '@botu/widget';
|
|
2
|
+
export { boot } from '@botu/widget';
|
|
3
|
+
|
|
4
|
+
type BotuChatWidgetProps = {
|
|
5
|
+
projectId: string;
|
|
6
|
+
bootOptions?: Omit<BootOptions, "project_id">;
|
|
7
|
+
loadOptions?: LoadOptions;
|
|
8
|
+
autoload?: boolean;
|
|
9
|
+
shutdownOnUnmount?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* React wrapper for @botu/widget.
|
|
13
|
+
* - If autoload=true (default), calls boot() on mount.
|
|
14
|
+
* - Renders nothing.
|
|
15
|
+
*/
|
|
16
|
+
declare function BotuChatWidget({ projectId, bootOptions, loadOptions, autoload, shutdownOnUnmount, }: BotuChatWidgetProps): null;
|
|
17
|
+
|
|
18
|
+
export { BotuChatWidget, type BotuChatWidgetProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
BotuChatWidget: () => BotuChatWidget,
|
|
24
|
+
boot: () => import_widget2.boot
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
|
|
28
|
+
// src/chat-widget.ts
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
var import_widget = require("@botu/widget");
|
|
31
|
+
function BotuChatWidget({
|
|
32
|
+
projectId,
|
|
33
|
+
bootOptions,
|
|
34
|
+
loadOptions,
|
|
35
|
+
autoload = true,
|
|
36
|
+
shutdownOnUnmount = false
|
|
37
|
+
}) {
|
|
38
|
+
const didBootRef = (0, import_react.useRef)(false);
|
|
39
|
+
(0, import_react.useEffect)(() => {
|
|
40
|
+
if (!autoload) return;
|
|
41
|
+
if (didBootRef.current) return;
|
|
42
|
+
didBootRef.current = true;
|
|
43
|
+
(0, import_widget.boot)({ project_id: projectId, ...bootOptions ?? {} }, loadOptions).catch((e) => {
|
|
44
|
+
console.error("[Widget] boot failed:", e);
|
|
45
|
+
});
|
|
46
|
+
return () => {
|
|
47
|
+
if (!shutdownOnUnmount) return;
|
|
48
|
+
try {
|
|
49
|
+
const maybe = import_widget.boot;
|
|
50
|
+
maybe.shutdown?.();
|
|
51
|
+
} catch {
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/index.ts
|
|
59
|
+
var import_widget2 = require("@botu/widget");
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
BotuChatWidget,
|
|
63
|
+
boot
|
|
64
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/chat-widget.ts
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { boot } from "@botu/widget";
|
|
4
|
+
function BotuChatWidget({
|
|
5
|
+
projectId,
|
|
6
|
+
bootOptions,
|
|
7
|
+
loadOptions,
|
|
8
|
+
autoload = true,
|
|
9
|
+
shutdownOnUnmount = false
|
|
10
|
+
}) {
|
|
11
|
+
const didBootRef = useRef(false);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!autoload) return;
|
|
14
|
+
if (didBootRef.current) return;
|
|
15
|
+
didBootRef.current = true;
|
|
16
|
+
boot({ project_id: projectId, ...bootOptions ?? {} }, loadOptions).catch((e) => {
|
|
17
|
+
console.error("[Widget] boot failed:", e);
|
|
18
|
+
});
|
|
19
|
+
return () => {
|
|
20
|
+
if (!shutdownOnUnmount) return;
|
|
21
|
+
try {
|
|
22
|
+
const maybe = boot;
|
|
23
|
+
maybe.shutdown?.();
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
import { boot as boot2 } from "@botu/widget";
|
|
33
|
+
export {
|
|
34
|
+
BotuChatWidget,
|
|
35
|
+
boot2 as boot
|
|
36
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@botu/widget-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
20
|
+
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@botu/widget": "^0.1.3"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --external react --external react-dom"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
}
|
|
31
|
+
}
|