@clivly/chat-widget 0.4.0 → 0.7.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 +81 -4
- package/dist/browser-mount.cjs +297 -71
- package/dist/browser-mount.d.cts +40 -11
- package/dist/browser-mount.d.mts +40 -11
- package/dist/browser-mount.mjs +298 -72
- package/dist/browser.cjs +297 -71
- package/dist/browser.d.cts +41 -11
- package/dist/browser.d.mts +41 -11
- package/dist/browser.mjs +298 -72
- package/dist/index.cjs +299 -72
- package/dist/index.d.cts +59 -36
- package/dist/index.d.mts +59 -36
- package/dist/index.mjs +300 -74
- package/dist/widget.global.js +228 -84
- package/package.json +7 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { Root } from "react-dom/client";
|
|
2
|
-
import { ReactElement } from "react";
|
|
3
|
-
|
|
2
|
+
import { CSSProperties, ReactElement } from "react";
|
|
3
|
+
//#region src/theme.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Theme resolution for the widget.
|
|
6
|
+
*
|
|
7
|
+
* The script-tag build mounts into a Shadow DOM, so the host's `.dark` class on
|
|
8
|
+
* `<html>` can never reach the widget through a CSS selector. The theme has to
|
|
9
|
+
* be resolved in JavaScript — reading the same signals the host's own CSS reads
|
|
10
|
+
* — and applied to an attribute inside the widget. That is what this module
|
|
11
|
+
* does, and why it is a plain DOM module rather than a stylesheet.
|
|
12
|
+
*/
|
|
13
|
+
type ChatWidgetTheme = "auto" | "dark" | "light";
|
|
14
|
+
type ResolvedTheme = "dark" | "light";
|
|
15
|
+
interface ResolveThemeOptions {
|
|
16
|
+
/** Injection seam for tests. Defaults to the ambient document/window. */
|
|
17
|
+
root?: Element | null;
|
|
18
|
+
view?: Window | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolve a requested theme to the one the widget should actually paint.
|
|
22
|
+
*
|
|
23
|
+
* Falls back to `light` when there is nothing to read — during SSR there is no
|
|
24
|
+
* document, and guessing dark would flash the wrong palette on hydration for
|
|
25
|
+
* the majority of pages.
|
|
26
|
+
*/
|
|
27
|
+
declare function resolveTheme(theme: ChatWidgetTheme, { root, view }?: ResolveThemeOptions): ResolvedTheme;
|
|
28
|
+
//#endregion
|
|
4
29
|
//#region src/types.d.ts
|
|
5
30
|
type WidgetSenderType = "visitor" | "operator" | "system";
|
|
6
31
|
interface WidgetConfig {
|
|
@@ -29,7 +54,7 @@ interface WidgetMessage {
|
|
|
29
54
|
senderType: WidgetSenderType;
|
|
30
55
|
}
|
|
31
56
|
interface WidgetSessionPayload {
|
|
32
|
-
contact: WidgetContact;
|
|
57
|
+
contact: WidgetContact | null;
|
|
33
58
|
conversation: WidgetConversation;
|
|
34
59
|
expiresAt: string;
|
|
35
60
|
messages: WidgetMessage[];
|
|
@@ -100,21 +125,13 @@ interface CreateWebSocketTransportOptions {
|
|
|
100
125
|
getProtocols?: (session: WidgetSessionPayload) => string | string[] | undefined;
|
|
101
126
|
resolveUrl: (session: WidgetSessionPayload) => string;
|
|
102
127
|
}
|
|
103
|
-
declare function createWebSocketTransport({
|
|
104
|
-
createSocket,
|
|
105
|
-
getProtocols,
|
|
106
|
-
resolveUrl
|
|
107
|
-
}: CreateWebSocketTransportOptions): CreateChatTransport;
|
|
128
|
+
declare function createWebSocketTransport({ createSocket, getProtocols, resolveUrl }: CreateWebSocketTransportOptions): CreateChatTransport;
|
|
108
129
|
interface CreateLoopbackTransportOptions {
|
|
109
130
|
operatorName?: string;
|
|
110
131
|
operatorReply?: (body: string) => string | null;
|
|
111
132
|
replyDelayMs?: number;
|
|
112
133
|
}
|
|
113
|
-
declare function createLoopbackTransport({
|
|
114
|
-
operatorName,
|
|
115
|
-
operatorReply,
|
|
116
|
-
replyDelayMs
|
|
117
|
-
}?: CreateLoopbackTransportOptions): CreateChatTransport;
|
|
134
|
+
declare function createLoopbackTransport({ operatorName, operatorReply, replyDelayMs }?: CreateLoopbackTransportOptions): CreateChatTransport;
|
|
118
135
|
//#endregion
|
|
119
136
|
//#region src/chat-widget.d.ts
|
|
120
137
|
interface ChatWidgetProps {
|
|
@@ -124,17 +141,21 @@ interface ChatWidgetProps {
|
|
|
124
141
|
initiallyOpen?: boolean;
|
|
125
142
|
launcherLabel?: string;
|
|
126
143
|
storage?: Pick<Storage, "getItem" | "setItem">;
|
|
144
|
+
/**
|
|
145
|
+
* Inline styles on the widget root. The intended use is overriding palette
|
|
146
|
+
* tokens — `{ "--clivly-chat-panel": "#0b0f19" }` — which works because
|
|
147
|
+
* inline declarations beat both palette rules without any specificity games.
|
|
148
|
+
*/
|
|
149
|
+
style?: CSSProperties;
|
|
150
|
+
/**
|
|
151
|
+
* `"auto"` (the default) follows the host app: a `data-theme` attribute or a
|
|
152
|
+
* `dark`/`light` class on `<html>`, then the OS preference. `"light"` and
|
|
153
|
+
* `"dark"` pin the widget regardless of what the host is doing.
|
|
154
|
+
*/
|
|
155
|
+
theme?: ChatWidgetTheme;
|
|
127
156
|
widgetId: string;
|
|
128
157
|
}
|
|
129
|
-
declare function ChatWidget({
|
|
130
|
-
className,
|
|
131
|
-
createTransport,
|
|
132
|
-
getSession,
|
|
133
|
-
initiallyOpen,
|
|
134
|
-
launcherLabel,
|
|
135
|
-
storage,
|
|
136
|
-
widgetId
|
|
137
|
-
}: ChatWidgetProps): ReactElement;
|
|
158
|
+
declare function ChatWidget({ className, createTransport, getSession, initiallyOpen, launcherLabel, storage, style, theme, widgetId }: ChatWidgetProps): ReactElement;
|
|
138
159
|
declare function ChatLauncher(): null;
|
|
139
160
|
declare function ChatPanel(): null;
|
|
140
161
|
declare function MessageComposer(): null;
|
|
@@ -148,16 +169,20 @@ interface MountChatWidgetOptions$1 extends Omit<ChatWidgetProps, "getSession" |
|
|
|
148
169
|
socketUrlTemplate?: string;
|
|
149
170
|
widgetId: string;
|
|
150
171
|
}
|
|
151
|
-
|
|
152
|
-
container,
|
|
153
|
-
createTransport,
|
|
154
|
-
sessionUrl,
|
|
155
|
-
socketUrlTemplate,
|
|
156
|
-
widgetId,
|
|
157
|
-
...props
|
|
158
|
-
}: MountChatWidgetOptions$1): Root;
|
|
159
|
-
interface ScriptMountResult$1 {
|
|
172
|
+
interface ChatWidgetMount$1 {
|
|
160
173
|
root: Root;
|
|
174
|
+
/**
|
|
175
|
+
* Repaint the widget in a different theme. `"auto"` resumes following the
|
|
176
|
+
* host, so a caller can hand control back as easily as taking it.
|
|
177
|
+
*
|
|
178
|
+
* Only needed by hosts whose theme toggle does not touch `<html>` — the
|
|
179
|
+
* default `"auto"` already tracks a `data-theme` attribute or a `dark`
|
|
180
|
+
* class there.
|
|
181
|
+
*/
|
|
182
|
+
setTheme: (theme: ChatWidgetTheme) => void;
|
|
183
|
+
}
|
|
184
|
+
declare function mountChatWidget$1(options: MountChatWidgetOptions$1): Root;
|
|
185
|
+
interface ScriptMountResult$1 extends ChatWidgetMount$1 {
|
|
161
186
|
shadowRoot: ShadowRoot;
|
|
162
187
|
}
|
|
163
188
|
declare function mountChatWidgetScript$1(script?: HTMLScriptElement): ScriptMountResult$1;
|
|
@@ -181,12 +206,10 @@ interface CreateSessionFetcherOptions {
|
|
|
181
206
|
fetchImpl?: typeof fetch;
|
|
182
207
|
sessionUrl: string;
|
|
183
208
|
}
|
|
184
|
-
declare function createSessionFetcher({
|
|
185
|
-
fetchImpl,
|
|
186
|
-
sessionUrl
|
|
187
|
-
}: CreateSessionFetcherOptions): GetSession;
|
|
209
|
+
declare function createSessionFetcher({ fetchImpl, sessionUrl }: CreateSessionFetcherOptions): GetSession;
|
|
188
210
|
//#endregion
|
|
189
211
|
//#region src/index.d.ts
|
|
212
|
+
type ChatWidgetMount = ChatWidgetMount$1;
|
|
190
213
|
type MountChatWidgetOptions = MountChatWidgetOptions$1;
|
|
191
214
|
type ScriptMountResult = ScriptMountResult$1;
|
|
192
215
|
declare const autoMountChatWidgetScript: typeof autoMountChatWidgetScript$1;
|
|
@@ -195,4 +218,4 @@ declare const createClivlyTransport: typeof createClivlyTransport$1;
|
|
|
195
218
|
declare const mountChatWidget: typeof mountChatWidget$1;
|
|
196
219
|
declare const mountChatWidgetScript: typeof mountChatWidgetScript$1;
|
|
197
220
|
//#endregion
|
|
198
|
-
export { ChatLauncher, ChatPanel, type ChatTransportConnection, type ChatTransportHandlers, ChatWidget, type ChatWidgetVisitor, ConversationView, type CreateChatTransport, type CreateChatTransportOptions, CreateClivlyTransportOptions, type CreateLoopbackTransportOptions, type CreateWebSocketTransportOptions, type GetSession, type GetSessionOptions, MessageComposer, MountChatWidgetOptions, PreChatForm, ScriptMountResult, type WidgetClientCreateMessageEvent, type WidgetClientEvent, type WidgetConfig, type WidgetContact, type WidgetConversation, type WidgetConversationSnapshotEvent, type WidgetErrorEvent, type WidgetMessage, type WidgetMessageAckEvent, type WidgetMessageCreatedEvent, type WidgetSenderType, type WidgetServerEvent, type WidgetSessionPayload, type WidgetSessionReadyEvent, type WidgetSummary, autoMountChatWidgetScript, createClivlyTransport, createLoopbackTransport, createSessionFetcher, createWebSocketTransport, mountChatWidget, mountChatWidgetScript };
|
|
221
|
+
export { ChatLauncher, ChatPanel, type ChatTransportConnection, type ChatTransportHandlers, ChatWidget, ChatWidgetMount, type ChatWidgetProps, type ChatWidgetTheme, type ChatWidgetVisitor, ConversationView, type CreateChatTransport, type CreateChatTransportOptions, CreateClivlyTransportOptions, type CreateLoopbackTransportOptions, type CreateWebSocketTransportOptions, type GetSession, type GetSessionOptions, MessageComposer, MountChatWidgetOptions, PreChatForm, type ResolvedTheme, ScriptMountResult, type WidgetClientCreateMessageEvent, type WidgetClientEvent, type WidgetConfig, type WidgetContact, type WidgetConversation, type WidgetConversationSnapshotEvent, type WidgetErrorEvent, type WidgetMessage, type WidgetMessageAckEvent, type WidgetMessageCreatedEvent, type WidgetSenderType, type WidgetServerEvent, type WidgetSessionPayload, type WidgetSessionReadyEvent, type WidgetSummary, autoMountChatWidgetScript, createClivlyTransport, createLoopbackTransport, createSessionFetcher, createWebSocketTransport, mountChatWidget, mountChatWidgetScript, resolveTheme };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { Root } from "react-dom/client";
|
|
2
|
-
import { ReactElement } from "react";
|
|
3
|
-
|
|
2
|
+
import { CSSProperties, ReactElement } from "react";
|
|
3
|
+
//#region src/theme.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Theme resolution for the widget.
|
|
6
|
+
*
|
|
7
|
+
* The script-tag build mounts into a Shadow DOM, so the host's `.dark` class on
|
|
8
|
+
* `<html>` can never reach the widget through a CSS selector. The theme has to
|
|
9
|
+
* be resolved in JavaScript — reading the same signals the host's own CSS reads
|
|
10
|
+
* — and applied to an attribute inside the widget. That is what this module
|
|
11
|
+
* does, and why it is a plain DOM module rather than a stylesheet.
|
|
12
|
+
*/
|
|
13
|
+
type ChatWidgetTheme = "auto" | "dark" | "light";
|
|
14
|
+
type ResolvedTheme = "dark" | "light";
|
|
15
|
+
interface ResolveThemeOptions {
|
|
16
|
+
/** Injection seam for tests. Defaults to the ambient document/window. */
|
|
17
|
+
root?: Element | null;
|
|
18
|
+
view?: Window | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resolve a requested theme to the one the widget should actually paint.
|
|
22
|
+
*
|
|
23
|
+
* Falls back to `light` when there is nothing to read — during SSR there is no
|
|
24
|
+
* document, and guessing dark would flash the wrong palette on hydration for
|
|
25
|
+
* the majority of pages.
|
|
26
|
+
*/
|
|
27
|
+
declare function resolveTheme(theme: ChatWidgetTheme, { root, view }?: ResolveThemeOptions): ResolvedTheme;
|
|
28
|
+
//#endregion
|
|
4
29
|
//#region src/types.d.ts
|
|
5
30
|
type WidgetSenderType = "visitor" | "operator" | "system";
|
|
6
31
|
interface WidgetConfig {
|
|
@@ -29,7 +54,7 @@ interface WidgetMessage {
|
|
|
29
54
|
senderType: WidgetSenderType;
|
|
30
55
|
}
|
|
31
56
|
interface WidgetSessionPayload {
|
|
32
|
-
contact: WidgetContact;
|
|
57
|
+
contact: WidgetContact | null;
|
|
33
58
|
conversation: WidgetConversation;
|
|
34
59
|
expiresAt: string;
|
|
35
60
|
messages: WidgetMessage[];
|
|
@@ -100,21 +125,13 @@ interface CreateWebSocketTransportOptions {
|
|
|
100
125
|
getProtocols?: (session: WidgetSessionPayload) => string | string[] | undefined;
|
|
101
126
|
resolveUrl: (session: WidgetSessionPayload) => string;
|
|
102
127
|
}
|
|
103
|
-
declare function createWebSocketTransport({
|
|
104
|
-
createSocket,
|
|
105
|
-
getProtocols,
|
|
106
|
-
resolveUrl
|
|
107
|
-
}: CreateWebSocketTransportOptions): CreateChatTransport;
|
|
128
|
+
declare function createWebSocketTransport({ createSocket, getProtocols, resolveUrl }: CreateWebSocketTransportOptions): CreateChatTransport;
|
|
108
129
|
interface CreateLoopbackTransportOptions {
|
|
109
130
|
operatorName?: string;
|
|
110
131
|
operatorReply?: (body: string) => string | null;
|
|
111
132
|
replyDelayMs?: number;
|
|
112
133
|
}
|
|
113
|
-
declare function createLoopbackTransport({
|
|
114
|
-
operatorName,
|
|
115
|
-
operatorReply,
|
|
116
|
-
replyDelayMs
|
|
117
|
-
}?: CreateLoopbackTransportOptions): CreateChatTransport;
|
|
134
|
+
declare function createLoopbackTransport({ operatorName, operatorReply, replyDelayMs }?: CreateLoopbackTransportOptions): CreateChatTransport;
|
|
118
135
|
//#endregion
|
|
119
136
|
//#region src/chat-widget.d.ts
|
|
120
137
|
interface ChatWidgetProps {
|
|
@@ -124,17 +141,21 @@ interface ChatWidgetProps {
|
|
|
124
141
|
initiallyOpen?: boolean;
|
|
125
142
|
launcherLabel?: string;
|
|
126
143
|
storage?: Pick<Storage, "getItem" | "setItem">;
|
|
144
|
+
/**
|
|
145
|
+
* Inline styles on the widget root. The intended use is overriding palette
|
|
146
|
+
* tokens — `{ "--clivly-chat-panel": "#0b0f19" }` — which works because
|
|
147
|
+
* inline declarations beat both palette rules without any specificity games.
|
|
148
|
+
*/
|
|
149
|
+
style?: CSSProperties;
|
|
150
|
+
/**
|
|
151
|
+
* `"auto"` (the default) follows the host app: a `data-theme` attribute or a
|
|
152
|
+
* `dark`/`light` class on `<html>`, then the OS preference. `"light"` and
|
|
153
|
+
* `"dark"` pin the widget regardless of what the host is doing.
|
|
154
|
+
*/
|
|
155
|
+
theme?: ChatWidgetTheme;
|
|
127
156
|
widgetId: string;
|
|
128
157
|
}
|
|
129
|
-
declare function ChatWidget({
|
|
130
|
-
className,
|
|
131
|
-
createTransport,
|
|
132
|
-
getSession,
|
|
133
|
-
initiallyOpen,
|
|
134
|
-
launcherLabel,
|
|
135
|
-
storage,
|
|
136
|
-
widgetId
|
|
137
|
-
}: ChatWidgetProps): ReactElement;
|
|
158
|
+
declare function ChatWidget({ className, createTransport, getSession, initiallyOpen, launcherLabel, storage, style, theme, widgetId }: ChatWidgetProps): ReactElement;
|
|
138
159
|
declare function ChatLauncher(): null;
|
|
139
160
|
declare function ChatPanel(): null;
|
|
140
161
|
declare function MessageComposer(): null;
|
|
@@ -148,16 +169,20 @@ interface MountChatWidgetOptions$1 extends Omit<ChatWidgetProps, "getSession" |
|
|
|
148
169
|
socketUrlTemplate?: string;
|
|
149
170
|
widgetId: string;
|
|
150
171
|
}
|
|
151
|
-
|
|
152
|
-
container,
|
|
153
|
-
createTransport,
|
|
154
|
-
sessionUrl,
|
|
155
|
-
socketUrlTemplate,
|
|
156
|
-
widgetId,
|
|
157
|
-
...props
|
|
158
|
-
}: MountChatWidgetOptions$1): Root;
|
|
159
|
-
interface ScriptMountResult$1 {
|
|
172
|
+
interface ChatWidgetMount$1 {
|
|
160
173
|
root: Root;
|
|
174
|
+
/**
|
|
175
|
+
* Repaint the widget in a different theme. `"auto"` resumes following the
|
|
176
|
+
* host, so a caller can hand control back as easily as taking it.
|
|
177
|
+
*
|
|
178
|
+
* Only needed by hosts whose theme toggle does not touch `<html>` — the
|
|
179
|
+
* default `"auto"` already tracks a `data-theme` attribute or a `dark`
|
|
180
|
+
* class there.
|
|
181
|
+
*/
|
|
182
|
+
setTheme: (theme: ChatWidgetTheme) => void;
|
|
183
|
+
}
|
|
184
|
+
declare function mountChatWidget$1(options: MountChatWidgetOptions$1): Root;
|
|
185
|
+
interface ScriptMountResult$1 extends ChatWidgetMount$1 {
|
|
161
186
|
shadowRoot: ShadowRoot;
|
|
162
187
|
}
|
|
163
188
|
declare function mountChatWidgetScript$1(script?: HTMLScriptElement): ScriptMountResult$1;
|
|
@@ -181,12 +206,10 @@ interface CreateSessionFetcherOptions {
|
|
|
181
206
|
fetchImpl?: typeof fetch;
|
|
182
207
|
sessionUrl: string;
|
|
183
208
|
}
|
|
184
|
-
declare function createSessionFetcher({
|
|
185
|
-
fetchImpl,
|
|
186
|
-
sessionUrl
|
|
187
|
-
}: CreateSessionFetcherOptions): GetSession;
|
|
209
|
+
declare function createSessionFetcher({ fetchImpl, sessionUrl }: CreateSessionFetcherOptions): GetSession;
|
|
188
210
|
//#endregion
|
|
189
211
|
//#region src/index.d.ts
|
|
212
|
+
type ChatWidgetMount = ChatWidgetMount$1;
|
|
190
213
|
type MountChatWidgetOptions = MountChatWidgetOptions$1;
|
|
191
214
|
type ScriptMountResult = ScriptMountResult$1;
|
|
192
215
|
declare const autoMountChatWidgetScript: typeof autoMountChatWidgetScript$1;
|
|
@@ -195,4 +218,4 @@ declare const createClivlyTransport: typeof createClivlyTransport$1;
|
|
|
195
218
|
declare const mountChatWidget: typeof mountChatWidget$1;
|
|
196
219
|
declare const mountChatWidgetScript: typeof mountChatWidgetScript$1;
|
|
197
220
|
//#endregion
|
|
198
|
-
export { ChatLauncher, ChatPanel, type ChatTransportConnection, type ChatTransportHandlers, ChatWidget, type ChatWidgetVisitor, ConversationView, type CreateChatTransport, type CreateChatTransportOptions, CreateClivlyTransportOptions, type CreateLoopbackTransportOptions, type CreateWebSocketTransportOptions, type GetSession, type GetSessionOptions, MessageComposer, MountChatWidgetOptions, PreChatForm, ScriptMountResult, type WidgetClientCreateMessageEvent, type WidgetClientEvent, type WidgetConfig, type WidgetContact, type WidgetConversation, type WidgetConversationSnapshotEvent, type WidgetErrorEvent, type WidgetMessage, type WidgetMessageAckEvent, type WidgetMessageCreatedEvent, type WidgetSenderType, type WidgetServerEvent, type WidgetSessionPayload, type WidgetSessionReadyEvent, type WidgetSummary, autoMountChatWidgetScript, createClivlyTransport, createLoopbackTransport, createSessionFetcher, createWebSocketTransport, mountChatWidget, mountChatWidgetScript };
|
|
221
|
+
export { ChatLauncher, ChatPanel, type ChatTransportConnection, type ChatTransportHandlers, ChatWidget, ChatWidgetMount, type ChatWidgetProps, type ChatWidgetTheme, type ChatWidgetVisitor, ConversationView, type CreateChatTransport, type CreateChatTransportOptions, CreateClivlyTransportOptions, type CreateLoopbackTransportOptions, type CreateWebSocketTransportOptions, type GetSession, type GetSessionOptions, MessageComposer, MountChatWidgetOptions, PreChatForm, type ResolvedTheme, ScriptMountResult, type WidgetClientCreateMessageEvent, type WidgetClientEvent, type WidgetConfig, type WidgetContact, type WidgetConversation, type WidgetConversationSnapshotEvent, type WidgetErrorEvent, type WidgetMessage, type WidgetMessageAckEvent, type WidgetMessageCreatedEvent, type WidgetSenderType, type WidgetServerEvent, type WidgetSessionPayload, type WidgetSessionReadyEvent, type WidgetSummary, autoMountChatWidgetScript, createClivlyTransport, createLoopbackTransport, createSessionFetcher, createWebSocketTransport, mountChatWidget, mountChatWidgetScript, resolveTheme };
|