@asgard-js/react 0.0.43-canary.9 → 0.0.44-canary.1
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 +45 -1
- package/dist/components/chatbot/api-key-input/api-key-input.d.ts.map +1 -1
- package/dist/components/chatbot/chatbot.d.ts +2 -3
- package/dist/components/chatbot/chatbot.d.ts.map +1 -1
- package/dist/context/asgard-service-context.d.ts +1 -1
- package/dist/context/asgard-service-context.d.ts.map +1 -1
- package/dist/context/asgard-theme-context.d.ts +2 -0
- package/dist/context/asgard-theme-context.d.ts.map +1 -1
- package/dist/hooks/use-channel.d.ts +1 -1
- package/dist/hooks/use-channel.d.ts.map +1 -1
- package/dist/hooks/use-on-screen-keyboard-scroll-fix.d.ts +1 -1
- package/dist/hooks/use-on-screen-keyboard-scroll-fix.d.ts.map +1 -1
- package/dist/{style.css → index.css} +1 -1
- package/dist/index.js +21396 -21771
- package/package.json +3 -3
- package/.babelrc +0 -12
- package/eslint.config.cjs +0 -12
- package/src/components/.DS_Store +0 -0
- package/src/components/chatbot/api-key-input/api-key-input.module.scss +0 -184
- package/src/components/chatbot/api-key-input/api-key-input.tsx +0 -129
- package/src/components/chatbot/api-key-input/index.ts +0 -1
- package/src/components/chatbot/chatbot-body/chatbot-body.module.scss +0 -13
- package/src/components/chatbot/chatbot-body/chatbot-body.tsx +0 -45
- package/src/components/chatbot/chatbot-body/conversation-message-renderer.tsx +0 -55
- package/src/components/chatbot/chatbot-body/index.ts +0 -1
- package/src/components/chatbot/chatbot-container/chatbot-container.module.scss +0 -41
- package/src/components/chatbot/chatbot-container/chatbot-container.tsx +0 -49
- package/src/components/chatbot/chatbot-container/chatbot-full-screen-container.tsx +0 -54
- package/src/components/chatbot/chatbot-footer/chatbot-footer.module.scss +0 -67
- package/src/components/chatbot/chatbot-footer/chatbot-footer.tsx +0 -140
- package/src/components/chatbot/chatbot-footer/index.ts +0 -1
- package/src/components/chatbot/chatbot-footer/speech-input-button.tsx +0 -132
- package/src/components/chatbot/chatbot-header/chatbot-header.module.scss +0 -48
- package/src/components/chatbot/chatbot-header/chatbot-header.tsx +0 -98
- package/src/components/chatbot/chatbot-header/index.ts +0 -1
- package/src/components/chatbot/chatbot.spec.tsx +0 -8
- package/src/components/chatbot/chatbot.tsx +0 -233
- package/src/components/chatbot/profile-icon.tsx +0 -26
- package/src/components/index.ts +0 -2
- package/src/components/templates/avatar/avatar.module.scss +0 -6
- package/src/components/templates/avatar/avatar.tsx +0 -28
- package/src/components/templates/avatar/index.ts +0 -1
- package/src/components/templates/button-template/button-template.module.scss +0 -0
- package/src/components/templates/button-template/button-template.tsx +0 -45
- package/src/components/templates/button-template/card.module.scss +0 -58
- package/src/components/templates/button-template/card.spec.tsx +0 -213
- package/src/components/templates/button-template/card.tsx +0 -123
- package/src/components/templates/button-template/index.ts +0 -1
- package/src/components/templates/carousel-template/carousel-template.module.scss +0 -15
- package/src/components/templates/carousel-template/carousel-template.tsx +0 -49
- package/src/components/templates/carousel-template/index.ts +0 -1
- package/src/components/templates/chart-template/chart-template.module.scss +0 -52
- package/src/components/templates/chart-template/chart-template.tsx +0 -75
- package/src/components/templates/chart-template/index.ts +0 -1
- package/src/components/templates/hint-template/hint-template.module.scss +0 -43
- package/src/components/templates/hint-template/hint-template.tsx +0 -76
- package/src/components/templates/hint-template/index.ts +0 -1
- package/src/components/templates/image-template/image-template.module.scss +0 -67
- package/src/components/templates/image-template/image-template.tsx +0 -58
- package/src/components/templates/image-template/index.ts +0 -1
- package/src/components/templates/index.ts +0 -10
- package/src/components/templates/quick-replies/index.ts +0 -1
- package/src/components/templates/quick-replies/quick-replies.module.scss +0 -16
- package/src/components/templates/quick-replies/quick-replies.tsx +0 -47
- package/src/components/templates/template-box/index.ts +0 -2
- package/src/components/templates/template-box/template-box-content.module.scss +0 -13
- package/src/components/templates/template-box/template-box-content.tsx +0 -30
- package/src/components/templates/template-box/template-box.module.scss +0 -19
- package/src/components/templates/template-box/template-box.tsx +0 -48
- package/src/components/templates/text-template/bot-typing-box.tsx +0 -81
- package/src/components/templates/text-template/bot-typing-placeholder.tsx +0 -28
- package/src/components/templates/text-template/index.ts +0 -3
- package/src/components/templates/text-template/text-template.module.scss +0 -131
- package/src/components/templates/text-template/text-template.tsx +0 -94
- package/src/components/templates/text-template/use-react-markdown-renderer.spec.tsx +0 -758
- package/src/components/templates/time/index.ts +0 -1
- package/src/components/templates/time/time.module.scss +0 -6
- package/src/components/templates/time/time.tsx +0 -34
- package/src/context/asgard-app-initialization-context.tsx +0 -154
- package/src/context/asgard-service-context.tsx +0 -148
- package/src/context/asgard-template-context.tsx +0 -83
- package/src/context/asgard-theme-context.tsx +0 -546
- package/src/context/index.ts +0 -4
- package/src/hooks/index.ts +0 -11
- package/src/hooks/use-asgard-service-client.ts +0 -68
- package/src/hooks/use-channel.ts +0 -160
- package/src/hooks/use-debounce.ts +0 -18
- package/src/hooks/use-deep-compare-memo.ts +0 -19
- package/src/hooks/use-is-on-screen-keyboard-open.ts +0 -43
- package/src/hooks/use-on-screen-keyboard-scroll-fix.ts +0 -15
- package/src/hooks/use-prevent-over-scrolling.ts +0 -77
- package/src/hooks/use-react-markdown-renderer.tsx +0 -278
- package/src/hooks/use-resize-observer.tsx +0 -27
- package/src/hooks/use-update-vh.ts +0 -30
- package/src/hooks/use-viewport-size.ts +0 -51
- package/src/icons/add_a_photo.svg +0 -3
- package/src/icons/bot.svg +0 -14
- package/src/icons/close.svg +0 -3
- package/src/icons/distance.svg +0 -3
- package/src/icons/mic.svg +0 -3
- package/src/icons/photo_library.svg +0 -3
- package/src/icons/profile.svg +0 -28
- package/src/icons/refresh.svg +0 -3
- package/src/icons/send.svg +0 -3
- package/src/icons/stop.svg +0 -22
- package/src/icons/volume_up.svg +0 -3
- package/src/index.ts +0 -4
- package/src/models/bot-provider.ts +0 -108
- package/src/styles/_index.scss +0 -1
- package/src/styles/_styles.scss +0 -11
- package/src/styles/colors/_colors.scss +0 -10
- package/src/styles/colors/_index.scss +0 -1
- package/src/styles/colors/_variables.scss +0 -72
- package/src/styles/palette/_index.scss +0 -1
- package/src/styles/palette/_palette.scss +0 -42
- package/src/styles/palette/_variables.scss +0 -40
- package/src/styles/radius/_index.scss +0 -1
- package/src/styles/radius/_radius.scss +0 -8
- package/src/styles/radius/_variables.scss +0 -12
- package/src/styles/spacing/_index.scss +0 -1
- package/src/styles/spacing/_spacing.scss +0 -8
- package/src/styles/spacing/_variables.scss +0 -13
- package/src/styles/utils/_index.scss +0 -1
- package/src/styles/utils/_map.scss +0 -22
- package/src/test-setup.ts +0 -1
- package/src/utils/color-utils.ts +0 -52
- package/src/utils/deep-merge.ts +0 -26
- package/src/utils/extractors.ts +0 -20
- package/src/utils/format-time.ts +0 -8
- package/src/utils/index.ts +0 -1
- package/src/utils/is.ts +0 -72
- package/src/utils/selectors.ts +0 -7
- package/src/utils/uri-validation.spec.ts +0 -208
- package/src/utils/uri-validation.ts +0 -103
- package/tsconfig.json +0 -16
- package/tsconfig.lib.json +0 -63
- package/tsconfig.spec.json +0 -36
- package/tsconfig.tsbuildinfo +0 -1
- package/vite.config.ts +0 -63
|
@@ -1,546 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createContext,
|
|
3
|
-
CSSProperties,
|
|
4
|
-
PropsWithChildren,
|
|
5
|
-
ReactNode,
|
|
6
|
-
useContext,
|
|
7
|
-
useMemo,
|
|
8
|
-
useCallback,
|
|
9
|
-
} from 'react';
|
|
10
|
-
import { deepMerge } from '../utils/deep-merge';
|
|
11
|
-
import { darkenColor } from '../utils/color-utils';
|
|
12
|
-
import {
|
|
13
|
-
useAsgardAppInitializationContext,
|
|
14
|
-
Annotations,
|
|
15
|
-
} from './asgard-app-initialization-context';
|
|
16
|
-
|
|
17
|
-
export interface AsgardThemeContextValue {
|
|
18
|
-
chatbot: Pick<
|
|
19
|
-
CSSProperties,
|
|
20
|
-
| 'width'
|
|
21
|
-
| 'height'
|
|
22
|
-
| 'maxWidth'
|
|
23
|
-
| 'minWidth'
|
|
24
|
-
| 'maxHeight'
|
|
25
|
-
| 'minHeight'
|
|
26
|
-
| 'backgroundColor'
|
|
27
|
-
| 'borderColor'
|
|
28
|
-
| 'borderRadius'
|
|
29
|
-
> & {
|
|
30
|
-
contentMaxWidth?: CSSProperties['maxWidth'];
|
|
31
|
-
backgroundColor?: CSSProperties['backgroundColor'];
|
|
32
|
-
borderColor?: CSSProperties['borderColor'];
|
|
33
|
-
inactiveColor?: CSSProperties['color'];
|
|
34
|
-
primaryComponent?: {
|
|
35
|
-
mainColor?: CSSProperties['color'];
|
|
36
|
-
secondaryColor?: CSSProperties['color'];
|
|
37
|
-
};
|
|
38
|
-
style?: CSSProperties;
|
|
39
|
-
header?: Partial<{
|
|
40
|
-
style: CSSProperties;
|
|
41
|
-
title: {
|
|
42
|
-
style: CSSProperties;
|
|
43
|
-
};
|
|
44
|
-
actionButton?: {
|
|
45
|
-
style: CSSProperties;
|
|
46
|
-
};
|
|
47
|
-
}>;
|
|
48
|
-
body?: Partial<{
|
|
49
|
-
style: CSSProperties;
|
|
50
|
-
}>;
|
|
51
|
-
footer?: Partial<{
|
|
52
|
-
style: CSSProperties;
|
|
53
|
-
textArea: {
|
|
54
|
-
style: CSSProperties;
|
|
55
|
-
'::placeholder': CSSProperties;
|
|
56
|
-
};
|
|
57
|
-
submitButton: {
|
|
58
|
-
style: CSSProperties;
|
|
59
|
-
};
|
|
60
|
-
speechInputButton: {
|
|
61
|
-
style: CSSProperties;
|
|
62
|
-
};
|
|
63
|
-
}>;
|
|
64
|
-
};
|
|
65
|
-
botMessage: Pick<CSSProperties, 'color' | 'backgroundColor'> & {
|
|
66
|
-
carouselButtonBackgroundColor?: CSSProperties['backgroundColor'];
|
|
67
|
-
linkColor?: CSSProperties['color'];
|
|
68
|
-
unsentBackgroundColor?: CSSProperties['backgroundColor'];
|
|
69
|
-
quickReplyBackgroundColor?: CSSProperties['backgroundColor'];
|
|
70
|
-
};
|
|
71
|
-
userMessage: Pick<CSSProperties, 'color' | 'backgroundColor'>;
|
|
72
|
-
template?: Partial<{
|
|
73
|
-
/**
|
|
74
|
-
* first level for common/shared properties.
|
|
75
|
-
* Check MessageTemplate type for more details (packages/core/src/types/sse-response.ts).
|
|
76
|
-
*/
|
|
77
|
-
quickReplies?: Partial<{
|
|
78
|
-
style: CSSProperties;
|
|
79
|
-
button: {
|
|
80
|
-
style: CSSProperties;
|
|
81
|
-
};
|
|
82
|
-
}>;
|
|
83
|
-
time?: Partial<{
|
|
84
|
-
style: CSSProperties;
|
|
85
|
-
}>;
|
|
86
|
-
/**
|
|
87
|
-
* TBD: Fill the necessary properties based on the requirements.
|
|
88
|
-
*/
|
|
89
|
-
TextMessageTemplate: Partial<{ style: CSSProperties }>;
|
|
90
|
-
/**
|
|
91
|
-
* TBD: Fill the necessary properties based on the requirements.
|
|
92
|
-
*/
|
|
93
|
-
HintMessageTemplate: Partial<{ style: CSSProperties }>;
|
|
94
|
-
/**
|
|
95
|
-
* TBD: Fill the necessary properties based on the requirements.
|
|
96
|
-
*/
|
|
97
|
-
ImageMessageTemplate: Partial<{ style: CSSProperties }>;
|
|
98
|
-
/**
|
|
99
|
-
* TBD: Fill the necessary properties based on the requirements.
|
|
100
|
-
*/
|
|
101
|
-
VideoMessageTemplate: Partial<{ style: CSSProperties }>;
|
|
102
|
-
/**
|
|
103
|
-
* TBD: Fill the necessary properties based on the requirements.
|
|
104
|
-
*/
|
|
105
|
-
AudioMessageTemplate: Partial<{ style: CSSProperties }>;
|
|
106
|
-
/**
|
|
107
|
-
* TBD: Fill the necessary properties based on the requirements.
|
|
108
|
-
*/
|
|
109
|
-
LocationMessageTemplate: Partial<{ style: CSSProperties }>;
|
|
110
|
-
/**
|
|
111
|
-
* TBD: Fill the necessary properties based on the requirements.
|
|
112
|
-
*/
|
|
113
|
-
ChartMessageTemplate: Partial<{ style: CSSProperties }>;
|
|
114
|
-
/**
|
|
115
|
-
* TBD: Fill the necessary properties based on the requirements.
|
|
116
|
-
*/
|
|
117
|
-
ButtonMessageTemplate: Partial<{
|
|
118
|
-
style: CSSProperties;
|
|
119
|
-
button?: {
|
|
120
|
-
style: CSSProperties;
|
|
121
|
-
};
|
|
122
|
-
}>;
|
|
123
|
-
/**
|
|
124
|
-
* TBD: Fill the necessary properties based on the requirements.
|
|
125
|
-
*/
|
|
126
|
-
CarouselMessageTemplate: Partial<{
|
|
127
|
-
style: CSSProperties;
|
|
128
|
-
card: {
|
|
129
|
-
style: CSSProperties;
|
|
130
|
-
button?: {
|
|
131
|
-
style: CSSProperties;
|
|
132
|
-
};
|
|
133
|
-
};
|
|
134
|
-
}>;
|
|
135
|
-
}>;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export const defaultAsgardThemeContextValue: AsgardThemeContextValue = {
|
|
139
|
-
chatbot: {
|
|
140
|
-
width: '375px',
|
|
141
|
-
height: '640px',
|
|
142
|
-
backgroundColor: 'var(--asg-color-bg)',
|
|
143
|
-
borderColor: 'var(--asg-color-border)',
|
|
144
|
-
borderRadius: 'var(--asg-radius-md)',
|
|
145
|
-
contentMaxWidth: '1200px',
|
|
146
|
-
style: {},
|
|
147
|
-
header: {
|
|
148
|
-
style: {},
|
|
149
|
-
title: {
|
|
150
|
-
style: {},
|
|
151
|
-
},
|
|
152
|
-
actionButton: {
|
|
153
|
-
style: {},
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
body: {
|
|
157
|
-
style: {},
|
|
158
|
-
},
|
|
159
|
-
footer: {
|
|
160
|
-
style: {},
|
|
161
|
-
textArea: {
|
|
162
|
-
style: {},
|
|
163
|
-
'::placeholder': {
|
|
164
|
-
color: 'var(--asg-color-text-placeholder)',
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
submitButton: {
|
|
168
|
-
style: {},
|
|
169
|
-
},
|
|
170
|
-
speechInputButton: {
|
|
171
|
-
style: {},
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
botMessage: {
|
|
176
|
-
color: 'var(--asg-color-text)',
|
|
177
|
-
backgroundColor: 'var(--asg-color-secondary)',
|
|
178
|
-
},
|
|
179
|
-
userMessage: {
|
|
180
|
-
color: 'var(--asg-color-text)',
|
|
181
|
-
backgroundColor: 'var(--asg-color-primary)',
|
|
182
|
-
},
|
|
183
|
-
template: {
|
|
184
|
-
quickReplies: {
|
|
185
|
-
style: {},
|
|
186
|
-
button: {
|
|
187
|
-
style: {},
|
|
188
|
-
},
|
|
189
|
-
},
|
|
190
|
-
time: {
|
|
191
|
-
style: {},
|
|
192
|
-
},
|
|
193
|
-
TextMessageTemplate: {
|
|
194
|
-
style: {},
|
|
195
|
-
},
|
|
196
|
-
HintMessageTemplate: {
|
|
197
|
-
style: {},
|
|
198
|
-
},
|
|
199
|
-
ImageMessageTemplate: {
|
|
200
|
-
style: {},
|
|
201
|
-
},
|
|
202
|
-
VideoMessageTemplate: {
|
|
203
|
-
style: {},
|
|
204
|
-
},
|
|
205
|
-
AudioMessageTemplate: {
|
|
206
|
-
style: {},
|
|
207
|
-
},
|
|
208
|
-
LocationMessageTemplate: {
|
|
209
|
-
style: {},
|
|
210
|
-
},
|
|
211
|
-
ChartMessageTemplate: {
|
|
212
|
-
style: {},
|
|
213
|
-
},
|
|
214
|
-
ButtonMessageTemplate: {
|
|
215
|
-
style: {},
|
|
216
|
-
button: {
|
|
217
|
-
style: {
|
|
218
|
-
border: '1px solid var(--asg-color-border)',
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
CarouselMessageTemplate: {
|
|
223
|
-
style: {},
|
|
224
|
-
card: {
|
|
225
|
-
style: {},
|
|
226
|
-
button: {
|
|
227
|
-
style: {
|
|
228
|
-
border: '1px solid var(--asg-color-border)',
|
|
229
|
-
},
|
|
230
|
-
},
|
|
231
|
-
},
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
export const AsgardThemeContext = createContext<AsgardThemeContextValue>(
|
|
237
|
-
defaultAsgardThemeContextValue
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
export function AsgardThemeContextProvider(
|
|
241
|
-
props: PropsWithChildren<{
|
|
242
|
-
theme?: Partial<AsgardThemeContextValue>;
|
|
243
|
-
}>
|
|
244
|
-
): ReactNode {
|
|
245
|
-
const { children, theme = {} } = props;
|
|
246
|
-
const {
|
|
247
|
-
data: { annotations },
|
|
248
|
-
} = useAsgardAppInitializationContext();
|
|
249
|
-
|
|
250
|
-
const deepMergeTheme = useCallback(
|
|
251
|
-
function () {
|
|
252
|
-
/**
|
|
253
|
-
* Orders of theme (high to low):
|
|
254
|
-
* 1. Theme from props
|
|
255
|
-
* 2. Theme from annotations
|
|
256
|
-
* 3. Default theme
|
|
257
|
-
*/
|
|
258
|
-
|
|
259
|
-
const themeFromAnnotations: Annotations['embedConfig']['theme'] =
|
|
260
|
-
annotations?.embedConfig?.theme ?? {
|
|
261
|
-
chatbot: {},
|
|
262
|
-
botMessage: {},
|
|
263
|
-
userMessage: {},
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
const tempTheme = deepMerge(defaultAsgardThemeContextValue as unknown as Record<string, unknown>, {
|
|
267
|
-
chatbot: {
|
|
268
|
-
backgroundColor: themeFromAnnotations.chatbot?.backgroundColor,
|
|
269
|
-
borderColor: themeFromAnnotations.chatbot?.borderColor,
|
|
270
|
-
header: {
|
|
271
|
-
style: {
|
|
272
|
-
borderBottomColor: themeFromAnnotations.chatbot?.borderColor,
|
|
273
|
-
},
|
|
274
|
-
title: {
|
|
275
|
-
style: {
|
|
276
|
-
color:
|
|
277
|
-
themeFromAnnotations.chatbot?.primaryComponent
|
|
278
|
-
?.secondaryColor, // Title text color
|
|
279
|
-
},
|
|
280
|
-
},
|
|
281
|
-
actionButton: {
|
|
282
|
-
style: {
|
|
283
|
-
color: themeFromAnnotations.chatbot?.inactiveColor,
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
body: {
|
|
288
|
-
style: {
|
|
289
|
-
// Time/timestamp text color
|
|
290
|
-
color: themeFromAnnotations.chatbot?.inactiveColor,
|
|
291
|
-
},
|
|
292
|
-
},
|
|
293
|
-
footer: {
|
|
294
|
-
style: {
|
|
295
|
-
borderTopColor: themeFromAnnotations.chatbot?.borderColor,
|
|
296
|
-
},
|
|
297
|
-
textArea: {
|
|
298
|
-
style: {
|
|
299
|
-
color: themeFromAnnotations.chatbot?.inactiveColor,
|
|
300
|
-
backgroundColor: themeFromAnnotations.chatbot?.backgroundColor,
|
|
301
|
-
},
|
|
302
|
-
'::placeholder': {
|
|
303
|
-
color: themeFromAnnotations.chatbot?.inactiveColor,
|
|
304
|
-
},
|
|
305
|
-
},
|
|
306
|
-
submitButton: {
|
|
307
|
-
style: {
|
|
308
|
-
color:
|
|
309
|
-
themeFromAnnotations.chatbot?.primaryComponent
|
|
310
|
-
?.secondaryColor,
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
speechInputButton: {
|
|
314
|
-
style: {
|
|
315
|
-
color:
|
|
316
|
-
themeFromAnnotations.chatbot?.primaryComponent
|
|
317
|
-
?.secondaryColor,
|
|
318
|
-
},
|
|
319
|
-
},
|
|
320
|
-
},
|
|
321
|
-
},
|
|
322
|
-
botMessage: {
|
|
323
|
-
backgroundColor: themeFromAnnotations.botMessage?.backgroundColor, // #585858
|
|
324
|
-
color: themeFromAnnotations.botMessage?.color,
|
|
325
|
-
linkColor: themeFromAnnotations.botMessage?.backgroundColor
|
|
326
|
-
? darkenColor(themeFromAnnotations.botMessage.backgroundColor, 0.2)
|
|
327
|
-
: undefined,
|
|
328
|
-
unsentBackgroundColor: themeFromAnnotations.botMessage?.backgroundColor
|
|
329
|
-
? `color-mix(in srgb, ${themeFromAnnotations.botMessage.backgroundColor} 20%, transparent)`
|
|
330
|
-
: undefined,
|
|
331
|
-
quickReplyBackgroundColor: themeFromAnnotations.botMessage?.backgroundColor
|
|
332
|
-
? `color-mix(in srgb, ${themeFromAnnotations.botMessage.backgroundColor} 20%, transparent)`
|
|
333
|
-
: undefined,
|
|
334
|
-
},
|
|
335
|
-
userMessage: {
|
|
336
|
-
backgroundColor: themeFromAnnotations.userMessage?.backgroundColor,
|
|
337
|
-
color: themeFromAnnotations.userMessage?.color,
|
|
338
|
-
},
|
|
339
|
-
template: {
|
|
340
|
-
quickReplies: {
|
|
341
|
-
button: {
|
|
342
|
-
style: {
|
|
343
|
-
color:
|
|
344
|
-
themeFromAnnotations.chatbot?.primaryComponent
|
|
345
|
-
?.secondaryColor, // Button text (#FFFFFF)
|
|
346
|
-
borderColor: themeFromAnnotations.chatbot?.borderColor,
|
|
347
|
-
backgroundColor: themeFromAnnotations.botMessage
|
|
348
|
-
?.backgroundColor
|
|
349
|
-
? `${themeFromAnnotations.botMessage.backgroundColor}33`
|
|
350
|
-
: undefined,
|
|
351
|
-
},
|
|
352
|
-
},
|
|
353
|
-
},
|
|
354
|
-
time: {
|
|
355
|
-
style: {
|
|
356
|
-
color: themeFromAnnotations.chatbot?.inactiveColor,
|
|
357
|
-
},
|
|
358
|
-
},
|
|
359
|
-
TextMessageTemplate: {
|
|
360
|
-
style: {
|
|
361
|
-
// For unset messages
|
|
362
|
-
color:
|
|
363
|
-
themeFromAnnotations.chatbot?.primaryComponent?.secondaryColor,
|
|
364
|
-
},
|
|
365
|
-
},
|
|
366
|
-
ButtonMessageTemplate: {
|
|
367
|
-
button: {
|
|
368
|
-
style: {
|
|
369
|
-
borderColor: themeFromAnnotations.chatbot?.primaryComponent?.mainColor,
|
|
370
|
-
backgroundColor:
|
|
371
|
-
themeFromAnnotations.chatbot?.primaryComponent?.mainColor,
|
|
372
|
-
color:
|
|
373
|
-
themeFromAnnotations.chatbot?.primaryComponent
|
|
374
|
-
?.secondaryColor,
|
|
375
|
-
},
|
|
376
|
-
},
|
|
377
|
-
},
|
|
378
|
-
CarouselMessageTemplate: {
|
|
379
|
-
card: {
|
|
380
|
-
style: {
|
|
381
|
-
backgroundColor:
|
|
382
|
-
themeFromAnnotations.botMessage
|
|
383
|
-
?.carouselButtonBackgroundColor,
|
|
384
|
-
},
|
|
385
|
-
button: {
|
|
386
|
-
style: {
|
|
387
|
-
borderColor: themeFromAnnotations.chatbot?.primaryComponent?.mainColor,
|
|
388
|
-
backgroundColor:
|
|
389
|
-
themeFromAnnotations.chatbot?.primaryComponent?.mainColor,
|
|
390
|
-
color:
|
|
391
|
-
themeFromAnnotations.chatbot?.primaryComponent
|
|
392
|
-
?.secondaryColor,
|
|
393
|
-
},
|
|
394
|
-
},
|
|
395
|
-
},
|
|
396
|
-
},
|
|
397
|
-
},
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
// Handle theme prop that contains backend format (like themeFromAnnotations)
|
|
401
|
-
const propsTheme = theme as any; // Cast to handle backend format
|
|
402
|
-
const propsHasBackendFormat = propsTheme.chatbot?.primaryComponent || propsTheme.chatbot?.backgroundColor || propsTheme.botMessage || propsTheme.userMessage;
|
|
403
|
-
|
|
404
|
-
if (propsHasBackendFormat) {
|
|
405
|
-
// Apply same transformation logic as tempTheme for props theme
|
|
406
|
-
const transformedPropsTheme = deepMerge(defaultAsgardThemeContextValue as unknown as Record<string, unknown>, {
|
|
407
|
-
chatbot: {
|
|
408
|
-
backgroundColor: propsTheme.chatbot?.backgroundColor,
|
|
409
|
-
borderColor: propsTheme.chatbot?.borderColor,
|
|
410
|
-
header: {
|
|
411
|
-
style: {
|
|
412
|
-
borderBottomColor: propsTheme.chatbot?.borderColor,
|
|
413
|
-
},
|
|
414
|
-
title: {
|
|
415
|
-
style: {
|
|
416
|
-
color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
|
|
417
|
-
},
|
|
418
|
-
},
|
|
419
|
-
actionButton: {
|
|
420
|
-
style: {
|
|
421
|
-
color: propsTheme.chatbot?.inactiveColor,
|
|
422
|
-
},
|
|
423
|
-
},
|
|
424
|
-
},
|
|
425
|
-
body: {
|
|
426
|
-
style: {
|
|
427
|
-
// Time/timestamp text color
|
|
428
|
-
color: propsTheme.chatbot?.inactiveColor,
|
|
429
|
-
},
|
|
430
|
-
},
|
|
431
|
-
footer: {
|
|
432
|
-
style: {
|
|
433
|
-
borderTopColor: propsTheme.chatbot?.borderColor,
|
|
434
|
-
},
|
|
435
|
-
textArea: {
|
|
436
|
-
style: {
|
|
437
|
-
color: propsTheme.chatbot?.inactiveColor,
|
|
438
|
-
backgroundColor: propsTheme.chatbot?.backgroundColor,
|
|
439
|
-
},
|
|
440
|
-
'::placeholder': {
|
|
441
|
-
color: propsTheme.chatbot?.inactiveColor,
|
|
442
|
-
},
|
|
443
|
-
},
|
|
444
|
-
submitButton: {
|
|
445
|
-
style: {
|
|
446
|
-
color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
|
|
447
|
-
},
|
|
448
|
-
},
|
|
449
|
-
speechInputButton: {
|
|
450
|
-
style: {
|
|
451
|
-
color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
|
|
452
|
-
},
|
|
453
|
-
},
|
|
454
|
-
},
|
|
455
|
-
},
|
|
456
|
-
botMessage: {
|
|
457
|
-
backgroundColor: propsTheme.botMessage?.backgroundColor,
|
|
458
|
-
color: propsTheme.botMessage?.color,
|
|
459
|
-
linkColor: propsTheme.botMessage?.backgroundColor
|
|
460
|
-
? darkenColor(propsTheme.botMessage.backgroundColor, 0.2)
|
|
461
|
-
: undefined,
|
|
462
|
-
unsentBackgroundColor: propsTheme.botMessage?.backgroundColor
|
|
463
|
-
? `color-mix(in srgb, ${propsTheme.botMessage.backgroundColor} 20%, transparent)`
|
|
464
|
-
: undefined,
|
|
465
|
-
quickReplyBackgroundColor: propsTheme.botMessage?.backgroundColor
|
|
466
|
-
? `color-mix(in srgb, ${propsTheme.botMessage.backgroundColor} 20%, transparent)`
|
|
467
|
-
: undefined,
|
|
468
|
-
},
|
|
469
|
-
userMessage: {
|
|
470
|
-
backgroundColor: propsTheme.userMessage?.backgroundColor,
|
|
471
|
-
color: propsTheme.userMessage?.color,
|
|
472
|
-
},
|
|
473
|
-
template: {
|
|
474
|
-
quickReplies: {
|
|
475
|
-
button: {
|
|
476
|
-
style: {
|
|
477
|
-
color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
|
|
478
|
-
borderColor: propsTheme.chatbot?.borderColor,
|
|
479
|
-
backgroundColor: propsTheme.botMessage?.backgroundColor
|
|
480
|
-
? `${propsTheme.botMessage.backgroundColor}33`
|
|
481
|
-
: undefined,
|
|
482
|
-
},
|
|
483
|
-
},
|
|
484
|
-
},
|
|
485
|
-
time: {
|
|
486
|
-
style: {
|
|
487
|
-
color: propsTheme.chatbot?.inactiveColor,
|
|
488
|
-
},
|
|
489
|
-
},
|
|
490
|
-
TextMessageTemplate: {
|
|
491
|
-
style: {
|
|
492
|
-
// For unset messages
|
|
493
|
-
color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
|
|
494
|
-
},
|
|
495
|
-
},
|
|
496
|
-
HintMessageTemplate: {
|
|
497
|
-
style: {
|
|
498
|
-
color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
|
|
499
|
-
},
|
|
500
|
-
},
|
|
501
|
-
ButtonMessageTemplate: {
|
|
502
|
-
button: {
|
|
503
|
-
style: {
|
|
504
|
-
borderColor: propsTheme.chatbot?.primaryComponent?.mainColor,
|
|
505
|
-
backgroundColor: propsTheme.chatbot?.primaryComponent?.mainColor,
|
|
506
|
-
color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
|
|
507
|
-
},
|
|
508
|
-
},
|
|
509
|
-
},
|
|
510
|
-
CarouselMessageTemplate: {
|
|
511
|
-
card: {
|
|
512
|
-
style: {
|
|
513
|
-
backgroundColor: propsTheme.botMessage?.carouselButtonBackgroundColor,
|
|
514
|
-
},
|
|
515
|
-
button: {
|
|
516
|
-
style: {
|
|
517
|
-
borderColor: propsTheme.chatbot?.primaryComponent?.mainColor,
|
|
518
|
-
backgroundColor: propsTheme.chatbot?.primaryComponent?.mainColor,
|
|
519
|
-
color: propsTheme.chatbot?.primaryComponent?.secondaryColor,
|
|
520
|
-
},
|
|
521
|
-
},
|
|
522
|
-
},
|
|
523
|
-
},
|
|
524
|
-
},
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
return deepMerge(tempTheme, transformedPropsTheme);
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
return deepMerge(tempTheme, theme);
|
|
531
|
-
},
|
|
532
|
-
[theme, annotations?.embedConfig?.theme]
|
|
533
|
-
);
|
|
534
|
-
|
|
535
|
-
const value = useMemo(() => deepMergeTheme(), [deepMergeTheme]);
|
|
536
|
-
|
|
537
|
-
return (
|
|
538
|
-
<AsgardThemeContext.Provider value={value}>
|
|
539
|
-
{children}
|
|
540
|
-
</AsgardThemeContext.Provider>
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
export function useAsgardThemeContext(): AsgardThemeContextValue {
|
|
545
|
-
return useContext(AsgardThemeContext);
|
|
546
|
-
}
|
package/src/context/index.ts
DELETED
package/src/hooks/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './use-asgard-service-client';
|
|
2
|
-
export * from './use-channel';
|
|
3
|
-
export * from './use-debounce';
|
|
4
|
-
export * from './use-viewport-size';
|
|
5
|
-
export * from './use-is-on-screen-keyboard-open';
|
|
6
|
-
export * from './use-on-screen-keyboard-scroll-fix';
|
|
7
|
-
export * from './use-prevent-over-scrolling';
|
|
8
|
-
export * from './use-update-vh';
|
|
9
|
-
export * from './use-resize-observer';
|
|
10
|
-
export * from './use-deep-compare-memo';
|
|
11
|
-
export * from './use-react-markdown-renderer';
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { ClientConfig, AsgardServiceClient, EventType } from '@asgard-js/core';
|
|
2
|
-
import { useEffect, useRef } from 'react';
|
|
3
|
-
|
|
4
|
-
interface UseAsgardServiceClientProps {
|
|
5
|
-
config: ClientConfig;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function useAsgardServiceClient(
|
|
9
|
-
props: UseAsgardServiceClientProps
|
|
10
|
-
): AsgardServiceClient | null {
|
|
11
|
-
const { config } = props;
|
|
12
|
-
|
|
13
|
-
const { onRunInit, onProcess, onMessage, onToolCall, onRunDone, onRunError } =
|
|
14
|
-
config;
|
|
15
|
-
|
|
16
|
-
const clientRef = useRef<AsgardServiceClient | null>(null);
|
|
17
|
-
|
|
18
|
-
if (!clientRef.current) {
|
|
19
|
-
clientRef.current = new AsgardServiceClient(config);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
return (): void => {
|
|
24
|
-
if (clientRef.current) {
|
|
25
|
-
clientRef.current.close();
|
|
26
|
-
clientRef.current = null;
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
}, []);
|
|
30
|
-
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (!clientRef.current || !onRunInit) return;
|
|
33
|
-
|
|
34
|
-
clientRef.current.on(EventType.INIT, onRunInit);
|
|
35
|
-
}, [onRunInit]);
|
|
36
|
-
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
if (!clientRef.current || !onProcess) return;
|
|
39
|
-
|
|
40
|
-
clientRef.current.on(EventType.PROCESS, onProcess);
|
|
41
|
-
}, [onProcess]);
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (!clientRef.current || !onMessage) return;
|
|
45
|
-
|
|
46
|
-
clientRef.current.on(EventType.MESSAGE, onMessage);
|
|
47
|
-
}, [onMessage]);
|
|
48
|
-
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
if (!clientRef.current || !onToolCall) return;
|
|
51
|
-
|
|
52
|
-
clientRef.current.on(EventType.TOOL_CALL, onToolCall);
|
|
53
|
-
}, [onToolCall]);
|
|
54
|
-
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
if (!clientRef.current || !onRunDone) return;
|
|
57
|
-
|
|
58
|
-
clientRef.current.on(EventType.DONE, onRunDone);
|
|
59
|
-
}, [onRunDone]);
|
|
60
|
-
|
|
61
|
-
useEffect(() => {
|
|
62
|
-
if (!clientRef.current || !onRunError) return;
|
|
63
|
-
|
|
64
|
-
clientRef.current.on(EventType.ERROR, onRunError);
|
|
65
|
-
}, [onRunError]);
|
|
66
|
-
|
|
67
|
-
return clientRef.current;
|
|
68
|
-
}
|