@asgard-js/react 0.0.40-canary.2 → 0.0.41-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/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/chatbot/chatbot.d.ts +0 -3
- package/dist/components/chatbot/chatbot.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 +18568 -19052
- 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/dist/components/chatbot/api-key-input/api-key-input.d.ts +0 -11
- package/dist/components/chatbot/api-key-input/api-key-input.d.ts.map +0 -1
- package/dist/components/chatbot/api-key-input/index.d.ts +0 -2
- package/dist/components/chatbot/api-key-input/index.d.ts.map +0 -1
- package/eslint.config.cjs +0 -12
- package/src/components/chatbot/api-key-input/api-key-input.module.scss +0 -192
- package/src/components/chatbot/api-key-input/api-key-input.tsx +0 -119
- 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 -195
- 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
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const SUPPORTED_IMAGE_TYPES: string[];
|
|
2
|
+
export declare const MAX_FILE_SIZE: number;
|
|
3
|
+
export interface FileValidationResult {
|
|
4
|
+
isValid: boolean;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function validateImageFile(file: File): FileValidationResult;
|
|
8
|
+
export declare function validateImageFiles(files: FileList | File[]): {
|
|
9
|
+
validFiles: File[];
|
|
10
|
+
errors: string[];
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=file-validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-validation.d.ts","sourceRoot":"","sources":["../../src/utils/file-validation.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,UAMjC,CAAC;AAEF,eAAO,MAAM,aAAa,QAAmB,CAAC;AAE9C,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,oBAAoB,CAsBlE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE,GAAG;IAC5D,UAAU,EAAE,IAAI,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAgBA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asgard-js/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.41-canary.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"vitest": "^1.6.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"@asgard-js/core": "^0.0.
|
|
57
|
+
"@asgard-js/core": "^0.0.41-canary.1",
|
|
58
58
|
"react": "^18.0.0",
|
|
59
59
|
"react-dom": "^18.0.0"
|
|
60
60
|
},
|
package/.babelrc
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export interface ApiKeyInputProps {
|
|
2
|
-
onSubmit: (apiKey: string) => void;
|
|
3
|
-
loading?: boolean;
|
|
4
|
-
error?: string;
|
|
5
|
-
placeholder?: string;
|
|
6
|
-
title?: string;
|
|
7
|
-
showToggle?: boolean;
|
|
8
|
-
className?: string;
|
|
9
|
-
}
|
|
10
|
-
export declare function ApiKeyInput({ onSubmit, loading, error, placeholder, title, showToggle, className, }: ApiKeyInputProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
-
//# sourceMappingURL=api-key-input.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-key-input.d.ts","sourceRoot":"","sources":["../../../../src/components/chatbot/api-key-input/api-key-input.tsx"],"names":[],"mappings":"AAKA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,OAAe,EACf,KAAK,EACL,WAA8B,EAC9B,KAAiB,EACjB,UAAiB,EACjB,SAAS,GACV,EAAE,gBAAgB,2CA+FlB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/chatbot/api-key-input/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/eslint.config.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const nx = require('@nx/eslint-plugin');
|
|
2
|
-
const baseConfig = require('../../eslint.config.cjs');
|
|
3
|
-
|
|
4
|
-
module.exports = [
|
|
5
|
-
...baseConfig,
|
|
6
|
-
...nx.configs['flat/react'],
|
|
7
|
-
{
|
|
8
|
-
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
|
|
9
|
-
// Override or add rules here
|
|
10
|
-
rules: {},
|
|
11
|
-
},
|
|
12
|
-
];
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
.container {
|
|
2
|
-
width: 220px;
|
|
3
|
-
background: rgba(45, 45, 45, 0.95);
|
|
4
|
-
border-radius: 12px;
|
|
5
|
-
padding: 24px 20px 20px;
|
|
6
|
-
backdrop-filter: blur(10px);
|
|
7
|
-
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
8
|
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
|
9
|
-
color: white;
|
|
10
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.header {
|
|
14
|
-
display: flex;
|
|
15
|
-
flex-direction: column;
|
|
16
|
-
align-items: center;
|
|
17
|
-
margin-bottom: 24px;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.icon {
|
|
21
|
-
width: 48px;
|
|
22
|
-
height: 48px;
|
|
23
|
-
margin-bottom: 12px;
|
|
24
|
-
opacity: 0.7;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.title {
|
|
28
|
-
margin: 0;
|
|
29
|
-
font-size: 18px;
|
|
30
|
-
font-weight: 500;
|
|
31
|
-
color: white;
|
|
32
|
-
text-align: center;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.form {
|
|
36
|
-
width: 100%;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.inputGroup {
|
|
40
|
-
margin-bottom: 20px;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.label {
|
|
44
|
-
display: block;
|
|
45
|
-
font-size: 14px;
|
|
46
|
-
font-weight: 400;
|
|
47
|
-
color: rgba(255, 255, 255, 0.7);
|
|
48
|
-
margin-bottom: 8px;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.inputWrapper {
|
|
52
|
-
position: relative;
|
|
53
|
-
width: 100%;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.input {
|
|
57
|
-
width: 100%;
|
|
58
|
-
height: 42px;
|
|
59
|
-
padding: 0 40px 0 12px;
|
|
60
|
-
font-size: 14px;
|
|
61
|
-
font-weight: 400;
|
|
62
|
-
color: rgba(255, 255, 255, 0.8);
|
|
63
|
-
background: rgba(255, 255, 255, 0.05);
|
|
64
|
-
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
65
|
-
border-radius: 6px;
|
|
66
|
-
outline: none;
|
|
67
|
-
transition: all 0.2s ease;
|
|
68
|
-
box-sizing: border-box;
|
|
69
|
-
|
|
70
|
-
&::placeholder {
|
|
71
|
-
color: rgba(255, 255, 255, 0.4);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
&:focus {
|
|
75
|
-
border-color: rgba(255, 255, 255, 0.3);
|
|
76
|
-
background: rgba(255, 255, 255, 0.08);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
&.error {
|
|
80
|
-
border-color: rgba(255, 69, 58, 0.6);
|
|
81
|
-
background: rgba(255, 69, 58, 0.05);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
&.disabled {
|
|
85
|
-
opacity: 0.5;
|
|
86
|
-
cursor: not-allowed;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
.toggleButton {
|
|
91
|
-
position: absolute;
|
|
92
|
-
right: 8px;
|
|
93
|
-
top: 50%;
|
|
94
|
-
transform: translateY(-50%);
|
|
95
|
-
background: transparent;
|
|
96
|
-
border: none;
|
|
97
|
-
color: rgba(255, 255, 255, 0.5);
|
|
98
|
-
cursor: pointer;
|
|
99
|
-
padding: 4px;
|
|
100
|
-
border-radius: 4px;
|
|
101
|
-
transition: all 0.2s ease;
|
|
102
|
-
display: flex;
|
|
103
|
-
align-items: center;
|
|
104
|
-
justify-content: center;
|
|
105
|
-
|
|
106
|
-
&:hover:not(:disabled) {
|
|
107
|
-
color: rgba(255, 255, 255, 0.7);
|
|
108
|
-
background: rgba(255, 255, 255, 0.05);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
&:disabled {
|
|
112
|
-
opacity: 0.3;
|
|
113
|
-
cursor: not-allowed;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
.toggleIcon {
|
|
118
|
-
width: 16px;
|
|
119
|
-
height: 16px;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
.errorMessage {
|
|
123
|
-
margin-top: 6px;
|
|
124
|
-
font-size: 12px;
|
|
125
|
-
color: rgba(255, 69, 58, 0.8);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
.submitButton {
|
|
129
|
-
width: 100%;
|
|
130
|
-
height: 42px;
|
|
131
|
-
background: #5856D6;
|
|
132
|
-
border: none;
|
|
133
|
-
border-radius: 6px;
|
|
134
|
-
color: white;
|
|
135
|
-
font-size: 14px;
|
|
136
|
-
font-weight: 500;
|
|
137
|
-
cursor: pointer;
|
|
138
|
-
transition: all 0.2s ease;
|
|
139
|
-
outline: none;
|
|
140
|
-
|
|
141
|
-
&:hover:not(:disabled) {
|
|
142
|
-
background: #4845C7;
|
|
143
|
-
transform: translateY(-1px);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
&:active:not(:disabled) {
|
|
147
|
-
transform: translateY(0);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
&:disabled {
|
|
151
|
-
opacity: 0.5;
|
|
152
|
-
cursor: not-allowed;
|
|
153
|
-
transform: none;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
&.loading {
|
|
157
|
-
position: relative;
|
|
158
|
-
color: transparent;
|
|
159
|
-
|
|
160
|
-
&::after {
|
|
161
|
-
content: '';
|
|
162
|
-
position: absolute;
|
|
163
|
-
top: 50%;
|
|
164
|
-
left: 50%;
|
|
165
|
-
width: 16px;
|
|
166
|
-
height: 16px;
|
|
167
|
-
margin-left: -8px;
|
|
168
|
-
margin-top: -8px;
|
|
169
|
-
border: 2px solid transparent;
|
|
170
|
-
border-top: 2px solid white;
|
|
171
|
-
border-radius: 50%;
|
|
172
|
-
animation: spin 1s linear infinite;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
@keyframes spin {
|
|
178
|
-
0% {
|
|
179
|
-
transform: rotate(0deg);
|
|
180
|
-
}
|
|
181
|
-
100% {
|
|
182
|
-
transform: rotate(360deg);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// 響應式設計
|
|
187
|
-
@media (max-width: 280px) {
|
|
188
|
-
.container {
|
|
189
|
-
width: 100%;
|
|
190
|
-
min-width: 200px;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { useState, FormEvent, ChangeEvent } from 'react';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import ProfileSvg from '../../../icons/profile.svg?react';
|
|
4
|
-
import styles from './api-key-input.module.scss';
|
|
5
|
-
|
|
6
|
-
export interface ApiKeyInputProps {
|
|
7
|
-
onSubmit: (apiKey: string) => void;
|
|
8
|
-
loading?: boolean;
|
|
9
|
-
error?: string;
|
|
10
|
-
placeholder?: string;
|
|
11
|
-
title?: string;
|
|
12
|
-
showToggle?: boolean;
|
|
13
|
-
className?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function ApiKeyInput({
|
|
17
|
-
onSubmit,
|
|
18
|
-
loading = false,
|
|
19
|
-
error,
|
|
20
|
-
placeholder = 'Enter your key',
|
|
21
|
-
title = 'Preview',
|
|
22
|
-
showToggle = true,
|
|
23
|
-
className,
|
|
24
|
-
}: ApiKeyInputProps) {
|
|
25
|
-
const [apiKey, setApiKey] = useState('');
|
|
26
|
-
const [showPassword, setShowPassword] = useState(false);
|
|
27
|
-
|
|
28
|
-
const handleSubmit = (e: FormEvent) => {
|
|
29
|
-
e.preventDefault();
|
|
30
|
-
if (apiKey.trim() && !loading) {
|
|
31
|
-
onSubmit(apiKey.trim());
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
|
36
|
-
setApiKey(e.target.value);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const togglePasswordVisibility = () => {
|
|
40
|
-
setShowPassword(!showPassword);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<div className={clsx(styles.container, className)}>
|
|
45
|
-
<div className={styles.header}>
|
|
46
|
-
<ProfileSvg className={styles.icon} />
|
|
47
|
-
<h2 className={styles.title}>{title}</h2>
|
|
48
|
-
</div>
|
|
49
|
-
|
|
50
|
-
<form onSubmit={handleSubmit} className={styles.form}>
|
|
51
|
-
<div className={styles.inputGroup}>
|
|
52
|
-
<label className={styles.label}>Key</label>
|
|
53
|
-
<div className={styles.inputWrapper}>
|
|
54
|
-
<input
|
|
55
|
-
type={showPassword ? 'text' : 'password'}
|
|
56
|
-
value={apiKey}
|
|
57
|
-
onChange={handleInputChange}
|
|
58
|
-
placeholder={placeholder}
|
|
59
|
-
className={clsx(styles.input, {
|
|
60
|
-
[styles.error]: error,
|
|
61
|
-
[styles.disabled]: loading,
|
|
62
|
-
})}
|
|
63
|
-
disabled={loading}
|
|
64
|
-
autoComplete="off"
|
|
65
|
-
/>
|
|
66
|
-
{showToggle && (
|
|
67
|
-
<button
|
|
68
|
-
type="button"
|
|
69
|
-
onClick={togglePasswordVisibility}
|
|
70
|
-
className={styles.toggleButton}
|
|
71
|
-
disabled={loading}
|
|
72
|
-
aria-label={showPassword ? 'Hide password' : 'Show password'}
|
|
73
|
-
>
|
|
74
|
-
<svg
|
|
75
|
-
className={styles.toggleIcon}
|
|
76
|
-
width="16"
|
|
77
|
-
height="16"
|
|
78
|
-
viewBox="0 0 24 24"
|
|
79
|
-
fill="none"
|
|
80
|
-
stroke="currentColor"
|
|
81
|
-
strokeWidth="2"
|
|
82
|
-
strokeLinecap="round"
|
|
83
|
-
strokeLinejoin="round"
|
|
84
|
-
>
|
|
85
|
-
{showPassword ? (
|
|
86
|
-
<>
|
|
87
|
-
<path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"/>
|
|
88
|
-
<line x1="1" y1="1" x2="23" y2="23"/>
|
|
89
|
-
</>
|
|
90
|
-
) : (
|
|
91
|
-
<>
|
|
92
|
-
<path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/>
|
|
93
|
-
<circle cx="12" cy="12" r="3"/>
|
|
94
|
-
</>
|
|
95
|
-
)}
|
|
96
|
-
</svg>
|
|
97
|
-
</button>
|
|
98
|
-
)}
|
|
99
|
-
</div>
|
|
100
|
-
{error && (
|
|
101
|
-
<div className={styles.errorMessage}>
|
|
102
|
-
{error}
|
|
103
|
-
</div>
|
|
104
|
-
)}
|
|
105
|
-
</div>
|
|
106
|
-
|
|
107
|
-
<button
|
|
108
|
-
type="submit"
|
|
109
|
-
disabled={!apiKey.trim() || loading}
|
|
110
|
-
className={clsx(styles.submitButton, {
|
|
111
|
-
[styles.loading]: loading,
|
|
112
|
-
})}
|
|
113
|
-
>
|
|
114
|
-
{loading ? 'Loading...' : 'Continue'}
|
|
115
|
-
</button>
|
|
116
|
-
</form>
|
|
117
|
-
</div>
|
|
118
|
-
);
|
|
119
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './api-key-input';
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { ReactNode, useEffect, useMemo } from 'react';
|
|
2
|
-
import { useAsgardContext } from '../../../context/asgard-service-context';
|
|
3
|
-
import styles from './chatbot-body.module.scss';
|
|
4
|
-
import { ConversationMessageRenderer } from './conversation-message-renderer';
|
|
5
|
-
import { BotTypingPlaceholder } from '../../templates';
|
|
6
|
-
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
7
|
-
import clsx from 'clsx';
|
|
8
|
-
|
|
9
|
-
export function ChatbotBody(): ReactNode {
|
|
10
|
-
const { chatbot } = useAsgardThemeContext();
|
|
11
|
-
|
|
12
|
-
const { messages, messageBoxBottomRef, botTypingPlaceholder } =
|
|
13
|
-
useAsgardContext();
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
messageBoxBottomRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
17
|
-
}, [messages, messageBoxBottomRef]);
|
|
18
|
-
|
|
19
|
-
const contentStyles = useMemo(
|
|
20
|
-
() => ({
|
|
21
|
-
maxWidth: chatbot?.contentMaxWidth ?? '1200px',
|
|
22
|
-
}),
|
|
23
|
-
[chatbot]
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<div
|
|
28
|
-
className={clsx('asgard-chatbot-body', styles.chatbot_body)}
|
|
29
|
-
style={chatbot?.body?.style}
|
|
30
|
-
>
|
|
31
|
-
<div className={styles.chatbot_body__content} style={contentStyles}>
|
|
32
|
-
{Array.from(messages?.values() ?? []).map((message) => (
|
|
33
|
-
<ConversationMessageRenderer
|
|
34
|
-
key={message.messageId}
|
|
35
|
-
message={message}
|
|
36
|
-
/>
|
|
37
|
-
))}
|
|
38
|
-
<BotTypingPlaceholder
|
|
39
|
-
placeholder={botTypingPlaceholder ?? '正在輸入訊息'}
|
|
40
|
-
/>
|
|
41
|
-
<div ref={messageBoxBottomRef} />
|
|
42
|
-
</div>
|
|
43
|
-
</div>
|
|
44
|
-
);
|
|
45
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
import { ConversationMessage, MessageTemplateType } from '@asgard-js/core';
|
|
3
|
-
import {
|
|
4
|
-
BotTypingBox,
|
|
5
|
-
ButtonTemplate,
|
|
6
|
-
CarouselTemplate,
|
|
7
|
-
HintTemplate,
|
|
8
|
-
TextTemplate,
|
|
9
|
-
ChartTemplate,
|
|
10
|
-
ImageTemplate,
|
|
11
|
-
} from '../../templates';
|
|
12
|
-
|
|
13
|
-
interface ConversationMessageRendererProps {
|
|
14
|
-
message: ConversationMessage;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function ConversationMessageRenderer(
|
|
18
|
-
props: ConversationMessageRendererProps
|
|
19
|
-
): ReactNode {
|
|
20
|
-
const { message } = props;
|
|
21
|
-
|
|
22
|
-
if (message.type === 'user') {
|
|
23
|
-
return <TextTemplate message={message} />;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (message.type === 'error') {
|
|
27
|
-
return <HintTemplate message={message} />;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (message.isTyping) {
|
|
31
|
-
return (
|
|
32
|
-
<BotTypingBox
|
|
33
|
-
isTyping={message.isTyping}
|
|
34
|
-
typingText={message.typingText}
|
|
35
|
-
/>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
switch (message.message.template?.type) {
|
|
40
|
-
case MessageTemplateType.TEXT:
|
|
41
|
-
return <TextTemplate message={message} />;
|
|
42
|
-
case MessageTemplateType.HINT:
|
|
43
|
-
return <HintTemplate message={message} />;
|
|
44
|
-
case MessageTemplateType.BUTTON:
|
|
45
|
-
return <ButtonTemplate message={message} />;
|
|
46
|
-
case MessageTemplateType.CAROUSEL:
|
|
47
|
-
return <CarouselTemplate message={message} />;
|
|
48
|
-
case MessageTemplateType.CHART:
|
|
49
|
-
return <ChartTemplate message={message} />;
|
|
50
|
-
case MessageTemplateType.IMAGE:
|
|
51
|
-
return <ImageTemplate message={message} />;
|
|
52
|
-
default:
|
|
53
|
-
return <div />;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './chatbot-body';
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
@use '../../../styles';
|
|
2
|
-
|
|
3
|
-
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@100..900&family=Space+Grotesk:wght@300..700&display=swap');
|
|
4
|
-
|
|
5
|
-
.chatbot_root {
|
|
6
|
-
@include styles.generate();
|
|
7
|
-
|
|
8
|
-
font-family: 'Space Grotesk', 'Noto Sans TC', sans-serif;
|
|
9
|
-
|
|
10
|
-
* {
|
|
11
|
-
line-height: 1.5;
|
|
12
|
-
box-sizing: border-box;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.full_screen {
|
|
17
|
-
position: fixed;
|
|
18
|
-
top: 0;
|
|
19
|
-
left: 0;
|
|
20
|
-
width: 100%;
|
|
21
|
-
height: calc(var(--vh, 1vh) * 100);
|
|
22
|
-
background-color: var(--asg-color-bg);
|
|
23
|
-
|
|
24
|
-
.chatbot_container {
|
|
25
|
-
height: 100%;
|
|
26
|
-
transition: all 0.1s;
|
|
27
|
-
padding: env(safe-area-inset-top) env(safe-area-inset-right)
|
|
28
|
-
env(safe-area-inset-bottom) env(safe-area-inset-left);
|
|
29
|
-
|
|
30
|
-
&.screen_keyboard_open {
|
|
31
|
-
padding: env(safe-area-inset-top) env(safe-area-inset-right) 0
|
|
32
|
-
env(safe-area-inset-left);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.chatbot_container {
|
|
38
|
-
display: grid;
|
|
39
|
-
grid-template-rows: max-content auto max-content;
|
|
40
|
-
background-color: var(--asg-color-bg);
|
|
41
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren, ReactNode, useRef, CSSProperties } from 'react';
|
|
2
|
-
import { useUpdateVh } from '../../../hooks';
|
|
3
|
-
import { ChatbotFullScreenContainer } from './chatbot-full-screen-container';
|
|
4
|
-
import classes from './chatbot-container.module.scss';
|
|
5
|
-
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
6
|
-
import clsx from 'clsx';
|
|
7
|
-
|
|
8
|
-
interface ChatbotContainerProps extends PropsWithChildren {
|
|
9
|
-
className?: string;
|
|
10
|
-
style?: CSSProperties;
|
|
11
|
-
fullScreen?: boolean;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function ChatbotContainer(props: ChatbotContainerProps): ReactNode {
|
|
15
|
-
const { fullScreen, children, className, style = {} } = props;
|
|
16
|
-
|
|
17
|
-
const rootRef = useRef<HTMLDivElement>(null);
|
|
18
|
-
|
|
19
|
-
useUpdateVh(rootRef);
|
|
20
|
-
|
|
21
|
-
const {
|
|
22
|
-
chatbot: {
|
|
23
|
-
style: rootStyle,
|
|
24
|
-
header,
|
|
25
|
-
body,
|
|
26
|
-
footer,
|
|
27
|
-
...chatbotInnerContainerStyle
|
|
28
|
-
},
|
|
29
|
-
} = useAsgardThemeContext();
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<div
|
|
33
|
-
ref={rootRef}
|
|
34
|
-
className={clsx(classes.chatbot_root, className)}
|
|
35
|
-
style={Object.assign({}, rootStyle, style)}
|
|
36
|
-
>
|
|
37
|
-
{fullScreen ? (
|
|
38
|
-
<ChatbotFullScreenContainer>{children}</ChatbotFullScreenContainer>
|
|
39
|
-
) : (
|
|
40
|
-
<div
|
|
41
|
-
className={classes.chatbot_container}
|
|
42
|
-
style={chatbotInnerContainerStyle}
|
|
43
|
-
>
|
|
44
|
-
{children}
|
|
45
|
-
</div>
|
|
46
|
-
)}
|
|
47
|
-
</div>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren, ReactNode, useMemo, useRef } from 'react';
|
|
2
|
-
import clsx from 'clsx';
|
|
3
|
-
import {
|
|
4
|
-
useIsOnScreenKeyboardOpen,
|
|
5
|
-
useOnScreenKeyboardScrollFix,
|
|
6
|
-
usePreventOverScrolling,
|
|
7
|
-
useViewportSize,
|
|
8
|
-
} from '../../../hooks';
|
|
9
|
-
import classes from './chatbot-container.module.scss';
|
|
10
|
-
import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
|
|
11
|
-
|
|
12
|
-
export function ChatbotFullScreenContainer(
|
|
13
|
-
props: PropsWithChildren
|
|
14
|
-
): ReactNode {
|
|
15
|
-
const { children } = props;
|
|
16
|
-
|
|
17
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
18
|
-
|
|
19
|
-
const theme = useAsgardThemeContext();
|
|
20
|
-
|
|
21
|
-
usePreventOverScrolling(containerRef);
|
|
22
|
-
|
|
23
|
-
useOnScreenKeyboardScrollFix();
|
|
24
|
-
|
|
25
|
-
const [, height] = useViewportSize() ?? [];
|
|
26
|
-
|
|
27
|
-
const isOnScreenKeyboardOpen = useIsOnScreenKeyboardOpen();
|
|
28
|
-
|
|
29
|
-
const styles = useMemo(() => {
|
|
30
|
-
return Object.assign(
|
|
31
|
-
theme?.chatbot?.backgroundColor
|
|
32
|
-
? {
|
|
33
|
-
backgroundColor: theme.chatbot?.backgroundColor,
|
|
34
|
-
}
|
|
35
|
-
: {},
|
|
36
|
-
isOnScreenKeyboardOpen ? { height } : {}
|
|
37
|
-
);
|
|
38
|
-
}, [height, isOnScreenKeyboardOpen, theme]);
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<div className={classes.full_screen}>
|
|
42
|
-
<div
|
|
43
|
-
ref={containerRef}
|
|
44
|
-
className={clsx(
|
|
45
|
-
classes.chatbot_container,
|
|
46
|
-
isOnScreenKeyboardOpen && classes.screen_keyboard_open
|
|
47
|
-
)}
|
|
48
|
-
style={styles}
|
|
49
|
-
>
|
|
50
|
-
{children}
|
|
51
|
-
</div>
|
|
52
|
-
</div>
|
|
53
|
-
);
|
|
54
|
-
}
|