@asgard-js/react 0.0.40 → 0.0.41-canary.2
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/components/chatbot/chatbot-body/conversation-message-renderer.d.ts.map +1 -1
- package/dist/components/chatbot/chatbot-footer/chatbot-footer.d.ts.map +1 -1
- package/dist/components/templates/index.d.ts +1 -0
- package/dist/components/templates/index.d.ts.map +1 -1
- package/dist/components/templates/user-image-template/index.d.ts +2 -0
- package/dist/components/templates/user-image-template/index.d.ts.map +1 -0
- package/dist/components/templates/user-image-template/user-image-template.d.ts +12 -0
- package/dist/components/templates/user-image-template/user-image-template.d.ts.map +1 -0
- package/dist/context/asgard-service-context.d.ts +1 -0
- package/dist/context/asgard-service-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/index.js +17672 -18151
- package/dist/style.css +1 -1
- package/dist/utils/file-validation.d.ts +12 -0
- package/dist/utils/file-validation.d.ts.map +1 -0
- package/package.json +2 -2
- package/.babelrc +0 -12
- package/eslint.config.cjs +0 -12
- 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 -121
- 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 -145
- 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 -154
- 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,123 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
MouseEventHandler,
|
|
3
|
-
ReactNode,
|
|
4
|
-
useCallback,
|
|
5
|
-
useMemo,
|
|
6
|
-
CSSProperties,
|
|
7
|
-
} from 'react';
|
|
8
|
-
import styles from './card.module.scss';
|
|
9
|
-
import {
|
|
10
|
-
ButtonAction,
|
|
11
|
-
ButtonMessageTemplate,
|
|
12
|
-
CarouselMessageTemplate,
|
|
13
|
-
} from '@asgard-js/core';
|
|
14
|
-
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
15
|
-
import { useAsgardTemplateContext } from '../../../context/asgard-template-context';
|
|
16
|
-
import { safeWindowOpen } from '../../../utils/uri-validation';
|
|
17
|
-
import clsx from 'clsx';
|
|
18
|
-
|
|
19
|
-
interface CardProps {
|
|
20
|
-
template: ButtonMessageTemplate | CarouselMessageTemplate['columns'][number];
|
|
21
|
-
customStyle?: {
|
|
22
|
-
style?: CSSProperties;
|
|
23
|
-
button?: {
|
|
24
|
-
style?: CSSProperties;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function Card(props: CardProps): ReactNode {
|
|
30
|
-
const { template, customStyle } = props;
|
|
31
|
-
|
|
32
|
-
const { sendMessage } = useAsgardContext();
|
|
33
|
-
const { onTemplateBtnClick, defaultLinkTarget } = useAsgardTemplateContext();
|
|
34
|
-
|
|
35
|
-
const src = useMemo(() => {
|
|
36
|
-
return (
|
|
37
|
-
template?.thumbnailImageUrl
|
|
38
|
-
?.replace(/^http:/, '')
|
|
39
|
-
.replace(/^https:/, '') ||
|
|
40
|
-
'https://via.assets.so/img.jpg?w=200&h=270&tc=white&bg=#eeeeee'
|
|
41
|
-
);
|
|
42
|
-
}, [template]);
|
|
43
|
-
|
|
44
|
-
const aspectRatio = useMemo(() => {
|
|
45
|
-
switch (template?.imageAspectRatio) {
|
|
46
|
-
case 'square':
|
|
47
|
-
return '1 / 1';
|
|
48
|
-
case 'rectangle':
|
|
49
|
-
default:
|
|
50
|
-
return '1.51 / 1';
|
|
51
|
-
}
|
|
52
|
-
}, [template]);
|
|
53
|
-
|
|
54
|
-
const handleClick = useCallback(
|
|
55
|
-
(action: ButtonAction): MouseEventHandler<HTMLButtonElement> => {
|
|
56
|
-
return function clickHandler() {
|
|
57
|
-
switch (action.type) {
|
|
58
|
-
case 'message':
|
|
59
|
-
case 'MESSAGE':
|
|
60
|
-
sendMessage?.({ text: action.text });
|
|
61
|
-
|
|
62
|
-
return;
|
|
63
|
-
case 'uri':
|
|
64
|
-
case 'URI':
|
|
65
|
-
safeWindowOpen(
|
|
66
|
-
action.uri,
|
|
67
|
-
action.target || defaultLinkTarget || '_blank'
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
return;
|
|
71
|
-
case 'emit':
|
|
72
|
-
case 'EMIT':
|
|
73
|
-
onTemplateBtnClick?.(action.payload, {
|
|
74
|
-
sse: {
|
|
75
|
-
sendMessage: (payload) => {
|
|
76
|
-
sendMessage?.(payload);
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
},
|
|
85
|
-
[sendMessage, onTemplateBtnClick, defaultLinkTarget]
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<div
|
|
90
|
-
className={clsx('asgard-card', styles.card_root)}
|
|
91
|
-
style={customStyle?.style}
|
|
92
|
-
>
|
|
93
|
-
{template?.thumbnailImageUrl && (
|
|
94
|
-
<img
|
|
95
|
-
alt={template?.title}
|
|
96
|
-
src={src}
|
|
97
|
-
style={{
|
|
98
|
-
display: 'block',
|
|
99
|
-
width: '100%',
|
|
100
|
-
maxHeight: '170px',
|
|
101
|
-
objectFit: template?.imageSize,
|
|
102
|
-
aspectRatio,
|
|
103
|
-
}}
|
|
104
|
-
/>
|
|
105
|
-
)}
|
|
106
|
-
<div className={styles.card_content}>
|
|
107
|
-
<h5 className={styles.card_title}>{template?.title}</h5>
|
|
108
|
-
<div className={styles.card_description}>{template?.text}</div>
|
|
109
|
-
<div className={styles.card_actions}>
|
|
110
|
-
{template?.buttons?.map((btn: { label: string; action: ButtonAction }, index: number) => (
|
|
111
|
-
<button
|
|
112
|
-
key={index}
|
|
113
|
-
onClick={handleClick(btn.action)}
|
|
114
|
-
style={customStyle?.button?.style}
|
|
115
|
-
>
|
|
116
|
-
{btn.label}
|
|
117
|
-
</button>
|
|
118
|
-
))}
|
|
119
|
-
</div>
|
|
120
|
-
</div>
|
|
121
|
-
</div>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './button-template';
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { TemplateBox, TemplateBoxContent } from '../template-box';
|
|
3
|
-
import { Avatar } from '../avatar';
|
|
4
|
-
import styles from './carousel-template.module.scss';
|
|
5
|
-
import { Card } from '../button-template/card';
|
|
6
|
-
import {
|
|
7
|
-
CarouselMessageTemplate,
|
|
8
|
-
ConversationBotMessage,
|
|
9
|
-
ButtonMessageTemplate,
|
|
10
|
-
} from '@asgard-js/core';
|
|
11
|
-
import { Time } from '../time';
|
|
12
|
-
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
13
|
-
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
14
|
-
|
|
15
|
-
interface CarouselTemplateProps {
|
|
16
|
-
message: ConversationBotMessage;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function CarouselTemplate(props: CarouselTemplateProps): ReactNode {
|
|
20
|
-
const { message } = props;
|
|
21
|
-
|
|
22
|
-
const { template: themeTemplate } = useAsgardThemeContext();
|
|
23
|
-
const { avatar } = useAsgardContext();
|
|
24
|
-
|
|
25
|
-
const template = message.message.template as CarouselMessageTemplate;
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<TemplateBox
|
|
29
|
-
className="asgard-carousel-template"
|
|
30
|
-
type="bot"
|
|
31
|
-
direction="vertical"
|
|
32
|
-
style={themeTemplate?.CarouselMessageTemplate?.style}
|
|
33
|
-
>
|
|
34
|
-
<Avatar avatar={avatar} />
|
|
35
|
-
<TemplateBoxContent quickReplies={template.quickReplies}>
|
|
36
|
-
<div className={styles.carousel_root}>
|
|
37
|
-
{template.columns?.map((column: Omit<ButtonMessageTemplate, 'type' | 'quickReplies'>, index: number) => (
|
|
38
|
-
<Card
|
|
39
|
-
key={index}
|
|
40
|
-
template={column}
|
|
41
|
-
customStyle={themeTemplate?.CarouselMessageTemplate?.card}
|
|
42
|
-
/>
|
|
43
|
-
))}
|
|
44
|
-
</div>
|
|
45
|
-
</TemplateBoxContent>
|
|
46
|
-
<Time className={styles.carousel_time} time={message.time} />
|
|
47
|
-
</TemplateBox>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './carousel-template';
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
.text {
|
|
2
|
-
display: inline-block;
|
|
3
|
-
padding: 8px 12px;
|
|
4
|
-
border-radius: 8px;
|
|
5
|
-
color: white;
|
|
6
|
-
word-break: break-all;
|
|
7
|
-
|
|
8
|
-
> span {
|
|
9
|
-
word-break: break-all;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.md_container {
|
|
13
|
-
display: inline-block;
|
|
14
|
-
|
|
15
|
-
p {
|
|
16
|
-
margin: 0;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.text--user {
|
|
22
|
-
max-width: 75%;
|
|
23
|
-
background: #4767eb;
|
|
24
|
-
border-top-right-radius: 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.text--bot {
|
|
28
|
-
max-width: 70%;
|
|
29
|
-
background: #585858;
|
|
30
|
-
border-top-left-radius: 0;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.chart_time {
|
|
34
|
-
justify-content: flex-end;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.quick_replies_box {
|
|
38
|
-
display: flex;
|
|
39
|
-
flex-wrap: wrap;
|
|
40
|
-
gap: 8px;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.quick_reply {
|
|
44
|
-
font: inherit;
|
|
45
|
-
font-size: 13px;
|
|
46
|
-
padding: 4px 8px;
|
|
47
|
-
border-radius: 8px;
|
|
48
|
-
border: 1px solid #434343;
|
|
49
|
-
background: rgba(88, 88, 88, 0.2);
|
|
50
|
-
color: white;
|
|
51
|
-
cursor: pointer;
|
|
52
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ReactNode, useMemo, useState, CSSProperties } from 'react';
|
|
2
|
-
import { TemplateBox, TemplateBoxContent } from '../template-box';
|
|
3
|
-
import { Avatar } from '../avatar';
|
|
4
|
-
import { ConversationBotMessage, ChartMessageTemplate } from '@asgard-js/core';
|
|
5
|
-
import { Time } from '../time';
|
|
6
|
-
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
7
|
-
import { VegaLite, VisualizationSpec } from 'react-vega';
|
|
8
|
-
import clsx from 'clsx';
|
|
9
|
-
import classes from './chart-template.module.scss';
|
|
10
|
-
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
11
|
-
|
|
12
|
-
interface ChartTemplateProps {
|
|
13
|
-
message: ConversationBotMessage;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function ChartTemplate(props: ChartTemplateProps): ReactNode {
|
|
17
|
-
const { message } = props;
|
|
18
|
-
const template = message.message.template as ChartMessageTemplate;
|
|
19
|
-
|
|
20
|
-
const { template: themeTemplate, botMessage } = useAsgardThemeContext();
|
|
21
|
-
const { avatar } = useAsgardContext();
|
|
22
|
-
|
|
23
|
-
const [option, setOption] = useState(
|
|
24
|
-
template?.defaultChart ?? template?.chartOptions?.[0]?.type
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
const options = useMemo(() => template.chartOptions, [template]);
|
|
28
|
-
|
|
29
|
-
const spec = useMemo(
|
|
30
|
-
() =>
|
|
31
|
-
(template?.chartOptions?.find((item: { type: string; title: string; spec: Record<string, unknown> }) => item.type === option)?.spec ??
|
|
32
|
-
options[0].spec) as VisualizationSpec,
|
|
33
|
-
[option, template.chartOptions, options]
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
const styles = useMemo<CSSProperties>(
|
|
37
|
-
() => ({
|
|
38
|
-
color: botMessage?.color,
|
|
39
|
-
backgroundColor: botMessage?.backgroundColor,
|
|
40
|
-
}),
|
|
41
|
-
[botMessage]
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
return (
|
|
45
|
-
<TemplateBox
|
|
46
|
-
className="asgard-chart-template"
|
|
47
|
-
type="bot"
|
|
48
|
-
direction="vertical"
|
|
49
|
-
style={themeTemplate?.ChartMessageTemplate?.style}
|
|
50
|
-
>
|
|
51
|
-
<Avatar avatar={avatar} />
|
|
52
|
-
<div className={clsx(classes.text, classes['text--bot'])} style={styles}>
|
|
53
|
-
<div>{template.title}</div>
|
|
54
|
-
<div>{template.text}</div>
|
|
55
|
-
</div>
|
|
56
|
-
{options.length > 1 && (
|
|
57
|
-
<div className={classes.quick_replies_box}>
|
|
58
|
-
{options.map((option: { type: string; title: string; spec: Record<string, unknown> }) => (
|
|
59
|
-
<button
|
|
60
|
-
key={option.type}
|
|
61
|
-
className={classes.quick_reply}
|
|
62
|
-
onClick={() => setOption(option.type)}
|
|
63
|
-
>
|
|
64
|
-
{option.title}
|
|
65
|
-
</button>
|
|
66
|
-
))}
|
|
67
|
-
</div>
|
|
68
|
-
)}
|
|
69
|
-
<TemplateBoxContent quickReplies={template?.quickReplies}>
|
|
70
|
-
<VegaLite spec={spec} />
|
|
71
|
-
</TemplateBoxContent>
|
|
72
|
-
<Time className={classes.chart_time} time={message.time} />
|
|
73
|
-
</TemplateBox>
|
|
74
|
-
);
|
|
75
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './chart-template';
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
.hint_root {
|
|
2
|
-
margin: 0 auto;
|
|
3
|
-
display: flex;
|
|
4
|
-
flex-direction: column;
|
|
5
|
-
align-items: center;
|
|
6
|
-
padding: 4px 12px;
|
|
7
|
-
gap: 4px;
|
|
8
|
-
border-radius: 2px;
|
|
9
|
-
background: rgba(88, 88, 88, 0.2);
|
|
10
|
-
font-size: 13px;
|
|
11
|
-
color: white;
|
|
12
|
-
word-break: break-all;
|
|
13
|
-
|
|
14
|
-
&.hint_root__error {
|
|
15
|
-
color: var(--asg-color-error);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.error_hint_title {
|
|
19
|
-
display: flex;
|
|
20
|
-
align-items: center;
|
|
21
|
-
gap: var(--asg-spacing-2);
|
|
22
|
-
color: var(--asg-color-error);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
.error_hint_message {
|
|
26
|
-
font-size: 12px;
|
|
27
|
-
color: white;
|
|
28
|
-
|
|
29
|
-
> span {
|
|
30
|
-
border-bottom: 1px solid white;
|
|
31
|
-
cursor: pointer;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.hint_text {
|
|
37
|
-
color: white;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.time {
|
|
41
|
-
font-size: 12px;
|
|
42
|
-
color: rgba(140, 140, 140, 1);
|
|
43
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { ReactNode, useCallback } from 'react';
|
|
2
|
-
import classes from './hint-template.module.scss';
|
|
3
|
-
import { formatTime } from '../../../utils';
|
|
4
|
-
import {
|
|
5
|
-
ConversationErrorMessage,
|
|
6
|
-
ConversationMessage,
|
|
7
|
-
MessageTemplateType,
|
|
8
|
-
} from '@asgard-js/core';
|
|
9
|
-
import { useAsgardTemplateContext, useAsgardThemeContext } from '../../../context';
|
|
10
|
-
import clsx from 'clsx';
|
|
11
|
-
|
|
12
|
-
interface HintTemplateProps {
|
|
13
|
-
message: ConversationMessage;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function HintTemplate(props: HintTemplateProps): ReactNode {
|
|
17
|
-
const { message } = props;
|
|
18
|
-
|
|
19
|
-
const { template: themeTemplate } = useAsgardThemeContext();
|
|
20
|
-
const { onErrorClick, errorMessageRenderer } = useAsgardTemplateContext();
|
|
21
|
-
|
|
22
|
-
const onErrorHintClick = useCallback(() => {
|
|
23
|
-
onErrorClick?.(message as ConversationErrorMessage);
|
|
24
|
-
}, [message, onErrorClick]);
|
|
25
|
-
|
|
26
|
-
if (message.type === 'user') return null;
|
|
27
|
-
|
|
28
|
-
if (message.type === 'error')
|
|
29
|
-
return (
|
|
30
|
-
<div
|
|
31
|
-
className={clsx(
|
|
32
|
-
'asgard-hint-template asgard-hint-template--error',
|
|
33
|
-
classes.hint_root
|
|
34
|
-
)}
|
|
35
|
-
>
|
|
36
|
-
{errorMessageRenderer?.(message) ?? (
|
|
37
|
-
<>
|
|
38
|
-
<div className={classes.error_hint_title}>
|
|
39
|
-
<span className={classes.time}>{formatTime(message.time)}</span>
|
|
40
|
-
<span>Unexpected error</span>
|
|
41
|
-
</div>
|
|
42
|
-
{onErrorClick && (
|
|
43
|
-
<div
|
|
44
|
-
className={classes.error_hint_message}
|
|
45
|
-
onClick={onErrorHintClick}
|
|
46
|
-
>
|
|
47
|
-
Click <span>here</span> to view the report.
|
|
48
|
-
</div>
|
|
49
|
-
)}
|
|
50
|
-
</>
|
|
51
|
-
)}
|
|
52
|
-
</div>
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const template = message.message.template;
|
|
56
|
-
|
|
57
|
-
if (template.type !== MessageTemplateType.HINT) return null;
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<div
|
|
61
|
-
className={clsx(
|
|
62
|
-
'asgard-hint-template asgard-hint-template--hint',
|
|
63
|
-
classes.hint_root
|
|
64
|
-
)}
|
|
65
|
-
style={themeTemplate?.HintMessageTemplate?.style}
|
|
66
|
-
>
|
|
67
|
-
<div className={classes.time}>{formatTime(message.time)}</div>
|
|
68
|
-
<div
|
|
69
|
-
className={classes.hint_text}
|
|
70
|
-
style={themeTemplate?.HintMessageTemplate?.style}
|
|
71
|
-
>
|
|
72
|
-
{template.text}
|
|
73
|
-
</div>
|
|
74
|
-
</div>
|
|
75
|
-
);
|
|
76
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './hint-template';
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
.image_box {
|
|
2
|
-
display: flex;
|
|
3
|
-
align-items: center;
|
|
4
|
-
justify-content: flex-start;
|
|
5
|
-
max-width: 80%;
|
|
6
|
-
border-radius: 8px;
|
|
7
|
-
box-sizing: border-box;
|
|
8
|
-
> img {
|
|
9
|
-
width: 100%;
|
|
10
|
-
border-radius: 8px;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.time {
|
|
15
|
-
justify-content: flex-end;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
.quick_replies_box {
|
|
19
|
-
display: flex;
|
|
20
|
-
flex-wrap: wrap;
|
|
21
|
-
gap: 8px;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.full_screen {
|
|
25
|
-
display: flex;
|
|
26
|
-
align-items: center;
|
|
27
|
-
justify-content: center;
|
|
28
|
-
z-index: 9999;
|
|
29
|
-
position: fixed;
|
|
30
|
-
top: 0;
|
|
31
|
-
left: 0;
|
|
32
|
-
background: rgba(30, 30, 30, 0.8);
|
|
33
|
-
backdrop-filter: blur(5px);
|
|
34
|
-
width: 100%;
|
|
35
|
-
height: 100%;
|
|
36
|
-
overflow: hidden;
|
|
37
|
-
box-sizing: border-box;
|
|
38
|
-
> .imageOrigin {
|
|
39
|
-
width: 100%;
|
|
40
|
-
max-width: 100%;
|
|
41
|
-
height: 100%;
|
|
42
|
-
max-height: 90%;
|
|
43
|
-
border-radius: 8px;
|
|
44
|
-
background-repeat: no-repeat;
|
|
45
|
-
background-size: contain;
|
|
46
|
-
background-position: center;
|
|
47
|
-
}
|
|
48
|
-
> .full_screen_close {
|
|
49
|
-
position: absolute;
|
|
50
|
-
top: 16px;
|
|
51
|
-
right: 16px;
|
|
52
|
-
font-size: 24px;
|
|
53
|
-
cursor: pointer;
|
|
54
|
-
z-index: 9999;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.quick_reply {
|
|
59
|
-
font: inherit;
|
|
60
|
-
font-size: 13px;
|
|
61
|
-
padding: 4px 8px;
|
|
62
|
-
border-radius: 8px;
|
|
63
|
-
border: 1px solid #434343;
|
|
64
|
-
background: rgba(88, 88, 88, 0.2);
|
|
65
|
-
color: white;
|
|
66
|
-
cursor: pointer;
|
|
67
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { ReactNode, useState } from 'react';
|
|
2
|
-
import { TemplateBox, TemplateBoxContent } from '../template-box';
|
|
3
|
-
import { Avatar } from '../avatar';
|
|
4
|
-
import styles from './image-template.module.scss';
|
|
5
|
-
import { ConversationBotMessage, ImageMessageTemplate } from '@asgard-js/core';
|
|
6
|
-
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
7
|
-
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
8
|
-
import CloseSvg from '../../../icons/close.svg?react';
|
|
9
|
-
|
|
10
|
-
interface ImageTemplateProps {
|
|
11
|
-
message: ConversationBotMessage;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function ImageTemplate(props: ImageTemplateProps): ReactNode {
|
|
15
|
-
const { message } = props;
|
|
16
|
-
const template = message.message.template as ImageMessageTemplate;
|
|
17
|
-
const { previewImageUrl, originalContentUrl } = template;
|
|
18
|
-
|
|
19
|
-
const { template: themeTemplate } = useAsgardThemeContext();
|
|
20
|
-
|
|
21
|
-
const { avatar } = useAsgardContext();
|
|
22
|
-
const [isFullScreen, setIsFullScreen] = useState(false);
|
|
23
|
-
if (isFullScreen) {
|
|
24
|
-
return (
|
|
25
|
-
<div
|
|
26
|
-
className={styles.full_screen}
|
|
27
|
-
onClick={() => setIsFullScreen(false)}
|
|
28
|
-
>
|
|
29
|
-
<div className={styles.full_screen_close}>
|
|
30
|
-
<CloseSvg />
|
|
31
|
-
</div>
|
|
32
|
-
<div
|
|
33
|
-
className={styles.imageOrigin}
|
|
34
|
-
style={{ backgroundImage: `url(${originalContentUrl})` }}
|
|
35
|
-
/>
|
|
36
|
-
</div>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<TemplateBox
|
|
42
|
-
className="asgard-image-template"
|
|
43
|
-
type="bot"
|
|
44
|
-
direction="horizontal"
|
|
45
|
-
style={themeTemplate?.ImageMessageTemplate?.style}
|
|
46
|
-
>
|
|
47
|
-
<Avatar avatar={avatar} />
|
|
48
|
-
<TemplateBoxContent
|
|
49
|
-
quickReplies={template.quickReplies}
|
|
50
|
-
time={message.time}
|
|
51
|
-
>
|
|
52
|
-
<div className={styles.image_box} onClick={() => setIsFullScreen(true)}>
|
|
53
|
-
<img src={previewImageUrl} alt="Conversation content" />
|
|
54
|
-
</div>
|
|
55
|
-
</TemplateBoxContent>
|
|
56
|
-
</TemplateBox>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './image-template';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './template-box';
|
|
2
|
-
|
|
3
|
-
export * from './button-template';
|
|
4
|
-
export * from './text-template';
|
|
5
|
-
export * from './carousel-template';
|
|
6
|
-
export * from './hint-template';
|
|
7
|
-
export * from './chart-template';
|
|
8
|
-
export * from './image-template';
|
|
9
|
-
|
|
10
|
-
export * from './quick-replies';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './quick-replies';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
.quick_replies_box {
|
|
2
|
-
display: flex;
|
|
3
|
-
flex-wrap: wrap;
|
|
4
|
-
gap: 8px;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
.quick_reply {
|
|
8
|
-
font: inherit;
|
|
9
|
-
font-size: 13px;
|
|
10
|
-
padding: 4px 8px;
|
|
11
|
-
border-radius: 8px;
|
|
12
|
-
border: 1px solid #434343;
|
|
13
|
-
background: rgba(88, 88, 88, 0.2);
|
|
14
|
-
color: white;
|
|
15
|
-
cursor: pointer;
|
|
16
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ReactNode, useCallback } from 'react';
|
|
2
|
-
import styles from './quick-replies.module.scss';
|
|
3
|
-
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
4
|
-
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
5
|
-
import clsx from 'clsx';
|
|
6
|
-
|
|
7
|
-
interface QuickRepliesProps {
|
|
8
|
-
quickReplies: { text: string }[];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function QuickReplies(props: QuickRepliesProps): ReactNode {
|
|
12
|
-
const { quickReplies } = props;
|
|
13
|
-
|
|
14
|
-
const { template, botMessage } = useAsgardThemeContext();
|
|
15
|
-
const { sendMessage, isConnecting } = useAsgardContext();
|
|
16
|
-
|
|
17
|
-
const onClick = useCallback(
|
|
18
|
-
(text: string) => sendMessage?.({ text }),
|
|
19
|
-
[sendMessage]
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
if (!quickReplies?.length) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<div
|
|
28
|
-
className={clsx('asgard-quick-replies', styles.quick_replies_box)}
|
|
29
|
-
style={template?.quickReplies?.style}
|
|
30
|
-
>
|
|
31
|
-
{quickReplies.map((quickReply) => (
|
|
32
|
-
<button
|
|
33
|
-
key={quickReply.text}
|
|
34
|
-
className={styles.quick_reply}
|
|
35
|
-
style={{
|
|
36
|
-
...template?.quickReplies?.button?.style,
|
|
37
|
-
backgroundColor: botMessage?.quickReplyBackgroundColor || template?.quickReplies?.button?.style?.backgroundColor,
|
|
38
|
-
}}
|
|
39
|
-
disabled={isConnecting}
|
|
40
|
-
onClick={() => onClick(quickReply.text)}
|
|
41
|
-
>
|
|
42
|
-
{quickReply.text}
|
|
43
|
-
</button>
|
|
44
|
-
))}
|
|
45
|
-
</div>
|
|
46
|
-
);
|
|
47
|
-
}
|