@release0/nextjs 0.2.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 +144 -0
- package/dist/dist-7FPSDZKC.js +80 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +45 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
## Install
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
npm install @release0/nextjs
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
## Standard
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { Standard } from "@release0/nextjs";
|
|
11
|
+
|
|
12
|
+
const App = () => {
|
|
13
|
+
return (
|
|
14
|
+
<Standard
|
|
15
|
+
agent="my-questions-agent"
|
|
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 "@release0/nextjs";
|
|
28
|
+
|
|
29
|
+
const App = () => {
|
|
30
|
+
return <Popup agent="my-questions-agent" 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 "@release0/nextjs";
|
|
42
|
+
|
|
43
|
+
open();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import { close } from "@release0/nextjs";
|
|
48
|
+
|
|
49
|
+
close();
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```js
|
|
53
|
+
import { toggle } from "@release0/nextjs";
|
|
54
|
+
|
|
55
|
+
toggle();
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Bubble
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
import { Bubble } from "@release0/nextjs";
|
|
62
|
+
|
|
63
|
+
const App = () => {
|
|
64
|
+
return (
|
|
65
|
+
<Bubble
|
|
66
|
+
agent="my-questions-agent"
|
|
67
|
+
previewMessage={{
|
|
68
|
+
message: "I have a question for you!",
|
|
69
|
+
autoShowDelay: 5000,
|
|
70
|
+
avatarUrl: "https://release0.com/images/logo512.png",
|
|
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 "@release0/nextjs";
|
|
89
|
+
|
|
90
|
+
Agent.showPreviewMessage();
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```js
|
|
94
|
+
import { hidePreviewMessage } from "@release0/nextjs";
|
|
95
|
+
|
|
96
|
+
Agent.hidePreviewMessage();
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Open or close the chat window
|
|
100
|
+
|
|
101
|
+
You can use these commands:
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
import { open } from "@release0/nextjs";
|
|
105
|
+
|
|
106
|
+
open();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
import { close } from "@release0/nextjs";
|
|
111
|
+
|
|
112
|
+
close();
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import { toggle } from "@release0/nextjs";
|
|
117
|
+
|
|
118
|
+
toggle();
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Additional configuration
|
|
122
|
+
|
|
123
|
+
You can prefill the agent variable values in your embed code by adding the `prefilledVariables` option. Here is an example:
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
import { Standard } from "@release0/nextjs";
|
|
127
|
+
|
|
128
|
+
const App = () => {
|
|
129
|
+
return (
|
|
130
|
+
<Standard
|
|
131
|
+
agent="my-questions-agent"
|
|
132
|
+
style={{ width: "100%", height: "600px" }}
|
|
133
|
+
prefilledVariables={{
|
|
134
|
+
"Current URL": "https://my-site.com/account",
|
|
135
|
+
"User name": "John Doe",
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
It will prefill the `Current URL` variable with "https://my-site.com/account" and the `User name` variable with "John Doe".
|
|
143
|
+
|
|
144
|
+
Note: If your site URL contains query params (i.e. https://release0?User%20name=John%20Doe), the variables will automatically be injected to the agent. So you don't need to manually transfer query params to the agent embed configuration.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
// ../react/dist/index.js
|
|
4
|
+
import { useEffect, useRef } from "react";
|
|
5
|
+
import "@release0/js/web";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
import { useCallback, useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
8
|
+
import "@release0/js/web";
|
|
9
|
+
import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
10
|
+
import "@release0/js/web";
|
|
11
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
12
|
+
export * from "@release0/js";
|
|
13
|
+
var Standard = ({ style, className, ...assignableProps }) => {
|
|
14
|
+
const ref = useRef(null);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!ref.current) return;
|
|
17
|
+
Object.assign(ref.current, assignableProps);
|
|
18
|
+
}, [assignableProps]);
|
|
19
|
+
return /* @__PURE__ */ jsx("agent-standard", { ref, style, class: className });
|
|
20
|
+
};
|
|
21
|
+
var Bubble = (props) => {
|
|
22
|
+
const bubbleElement = useRef2(null);
|
|
23
|
+
const attachBubbleToDom = useCallback((props2) => {
|
|
24
|
+
const newBubbleElement = document.createElement(
|
|
25
|
+
"agent-bubble"
|
|
26
|
+
);
|
|
27
|
+
bubbleElement.current = newBubbleElement;
|
|
28
|
+
injectPropsToElement(bubbleElement.current, props2);
|
|
29
|
+
document.body.prepend(bubbleElement.current);
|
|
30
|
+
}, []);
|
|
31
|
+
useEffect2(() => {
|
|
32
|
+
if (!bubbleElement.current) attachBubbleToDom(props);
|
|
33
|
+
injectPropsToElement(bubbleElement.current, props);
|
|
34
|
+
}, [attachBubbleToDom, props]);
|
|
35
|
+
useEffect2(() => {
|
|
36
|
+
return () => {
|
|
37
|
+
bubbleElement.current?.remove();
|
|
38
|
+
bubbleElement.current = null;
|
|
39
|
+
};
|
|
40
|
+
}, []);
|
|
41
|
+
const injectPropsToElement = (element, props2) => {
|
|
42
|
+
Object.assign(element, props2);
|
|
43
|
+
};
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
var Popup = (props) => {
|
|
47
|
+
const containerRef = useRef3(null);
|
|
48
|
+
const popupRef = useRef3(null);
|
|
49
|
+
const attachPopupToContainer = useCallback2((props2) => {
|
|
50
|
+
const popupElement = document.createElement("agent-popup");
|
|
51
|
+
popupRef.current = popupElement;
|
|
52
|
+
injectPropsToElement(popupRef.current, props2);
|
|
53
|
+
if (!containerRef.current) {
|
|
54
|
+
console.warn(
|
|
55
|
+
"Could not attach popup to container because containerRef.current is null"
|
|
56
|
+
);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
containerRef.current?.append(popupRef.current);
|
|
60
|
+
}, []);
|
|
61
|
+
useEffect3(() => {
|
|
62
|
+
if (!popupRef.current) attachPopupToContainer(props);
|
|
63
|
+
injectPropsToElement(popupRef.current, props);
|
|
64
|
+
}, [attachPopupToContainer, props]);
|
|
65
|
+
useEffect3(() => {
|
|
66
|
+
return () => {
|
|
67
|
+
popupRef.current?.remove();
|
|
68
|
+
popupRef.current = null;
|
|
69
|
+
};
|
|
70
|
+
}, []);
|
|
71
|
+
const injectPropsToElement = (element, props2) => {
|
|
72
|
+
Object.assign(element, props2);
|
|
73
|
+
};
|
|
74
|
+
return /* @__PURE__ */ jsx2("div", { ref: containerRef });
|
|
75
|
+
};
|
|
76
|
+
export {
|
|
77
|
+
Bubble,
|
|
78
|
+
Popup,
|
|
79
|
+
Standard
|
|
80
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import * as _release0_js from '@release0/js';
|
|
3
|
+
export { close, hidePreviewMessage, open, setInputValue, setPrefilledVariables, showPreviewMessage, toggle, unmount } from '@release0/js';
|
|
4
|
+
|
|
5
|
+
declare const Standard: react.ComponentType<_release0_js.AgentProps & {
|
|
6
|
+
style?: React.CSSProperties;
|
|
7
|
+
className?: string;
|
|
8
|
+
}>;
|
|
9
|
+
declare const Bubble: react.ComponentType<_release0_js.BubbleProps>;
|
|
10
|
+
declare const Popup: react.ComponentType<_release0_js.PopupProps>;
|
|
11
|
+
|
|
12
|
+
export { Bubble, Popup, Standard };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import dynamic from "next/dynamic";
|
|
5
|
+
import {
|
|
6
|
+
unmount,
|
|
7
|
+
toggle,
|
|
8
|
+
showPreviewMessage,
|
|
9
|
+
setInputValue,
|
|
10
|
+
setPrefilledVariables,
|
|
11
|
+
open,
|
|
12
|
+
hidePreviewMessage,
|
|
13
|
+
close
|
|
14
|
+
} from "@release0/js";
|
|
15
|
+
var Standard = dynamic(
|
|
16
|
+
() => import("./dist-7FPSDZKC.js").then((mod) => mod.Standard),
|
|
17
|
+
{
|
|
18
|
+
ssr: false
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
var Bubble = dynamic(
|
|
22
|
+
() => import("./dist-7FPSDZKC.js").then((mod) => mod.Bubble),
|
|
23
|
+
{
|
|
24
|
+
ssr: false
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
var Popup = dynamic(
|
|
28
|
+
() => import("./dist-7FPSDZKC.js").then((mod) => mod.Popup),
|
|
29
|
+
{
|
|
30
|
+
ssr: false
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
export {
|
|
34
|
+
Bubble,
|
|
35
|
+
Popup,
|
|
36
|
+
Standard,
|
|
37
|
+
close,
|
|
38
|
+
hidePreviewMessage,
|
|
39
|
+
open,
|
|
40
|
+
setInputValue,
|
|
41
|
+
setPrefilledVariables,
|
|
42
|
+
showPreviewMessage,
|
|
43
|
+
toggle,
|
|
44
|
+
unmount
|
|
45
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@release0/nextjs",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "FSL-1.1-ALv2",
|
|
5
|
+
"description": "Relese0 Lib: A convenient library for displaying chat agents on Next.js websites",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "tsup --watch",
|
|
17
|
+
"build": "tsup"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@release0/js": "1.1.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@release0/tsconfig": "0.0.1",
|
|
24
|
+
"@types/react": "18.2.15",
|
|
25
|
+
"tsup": "8.3.0",
|
|
26
|
+
"react": "18.2.0",
|
|
27
|
+
"@release0/react": "1.0.0",
|
|
28
|
+
"next": "14.2.13"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": "^16.0.0 || ^17.0.0 || ^18.0.0",
|
|
32
|
+
"next": "12.x || 13.x || 14.x",
|
|
33
|
+
"@release0/js": "^1.1.3 || workspace:*"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
}
|
|
38
|
+
}
|