@asgard-js/react 0.0.36 → 0.0.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asgard-js/react",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
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.36",
57
+ "@asgard-js/core": "^0.0.37",
58
58
  "react": "^18.0.0",
59
59
  "react-dom": "^18.0.0"
60
60
  },
@@ -14,20 +14,16 @@ import SendSvg from '../../../icons/send.svg?react';
14
14
  import { SpeechInputButton } from './speech-input-button';
15
15
  import clsx from 'clsx';
16
16
  import { useAsgardThemeContext } from '../../../context/asgard-theme-context';
17
- import { useAsgardAppInitializationContext } from '../../../context/asgard-app-initialization-context';
18
17
 
19
18
  export function ChatbotFooter(): ReactNode {
20
19
  const { sendMessage, isConnecting } = useAsgardContext();
21
20
 
22
21
  const { chatbot } = useAsgardThemeContext();
23
- const { data: { annotations } } = useAsgardAppInitializationContext();
24
22
 
25
23
  const [value, setValue] = useState('');
26
24
  const [isComposing, setIsComposing] = useState(false);
27
25
  const textareaRef = useRef<HTMLTextAreaElement>(null);
28
26
 
29
- const inputPlaceholder = annotations?.embedConfig?.inputPlaceholder || 'Enter message';
30
-
31
27
  const disabled = useMemo(
32
28
  () => isConnecting || !value.trim(),
33
29
  [isConnecting, value]
@@ -110,7 +106,7 @@ export function ChatbotFooter(): ReactNode {
110
106
  disabled={isConnecting}
111
107
  cols={40}
112
108
  value={value}
113
- placeholder={inputPlaceholder}
109
+ placeholder="Enter message"
114
110
  onChange={onChange}
115
111
  onKeyDown={onKeyDown}
116
112
  onCompositionStart={() => setIsComposing(true)}
@@ -19,7 +19,6 @@ import {
19
19
  UseChannelProps,
20
20
  UseChannelReturn,
21
21
  } from '../hooks';
22
- import { useAsgardAppInitializationContext } from './asgard-app-initialization-context';
23
22
 
24
23
  export interface AsgardServiceContextValue {
25
24
  avatar?: string;
@@ -69,20 +68,12 @@ export function AsgardServiceContextProvider(
69
68
  children,
70
69
  parentRef,
71
70
  config,
72
- botTypingPlaceholder: botTypingPlaceholderFromProps,
71
+ botTypingPlaceholder,
73
72
  customChannelId,
74
73
  initMessages,
75
74
  onSseMessage,
76
75
  } = props;
77
76
 
78
- const { data } = useAsgardAppInitializationContext();
79
- const { annotations } = data;
80
-
81
- // API 優先,Props 次之,最後才是預設值
82
- const botTypingPlaceholder =
83
- annotations?.embedConfig?.botTypingPlaceholder ||
84
- botTypingPlaceholderFromProps;
85
-
86
77
  const messageBoxBottomRef = useRef<HTMLDivElement>(null);
87
78
 
88
79
  const client = useAsgardServiceClient({ config });
@@ -4,12 +4,10 @@ import {
4
4
  PropsWithChildren,
5
5
  ReactNode,
6
6
  useContext,
7
- useEffect,
8
7
  useMemo,
9
8
  useCallback,
10
9
  } from 'react';
11
10
  import { deepMerge } from '../utils/deep-merge';
12
- import { addTransparency, darkenColor } from '../utils/color-utils';
13
11
  import {
14
12
  useAsgardAppInitializationContext,
15
13
  Annotations,
@@ -333,7 +331,7 @@ export function AsgardThemeContextProvider(
333
331
  borderColor: themeFromAnnotations.chatbot?.borderColor,
334
332
  backgroundColor: themeFromAnnotations.botMessage
335
333
  ?.backgroundColor
336
- ? addTransparency(themeFromAnnotations.botMessage.backgroundColor, 0.2)
334
+ ? `${themeFromAnnotations.botMessage.backgroundColor}33`
337
335
  : undefined,
338
336
  },
339
337
  },
@@ -348,9 +346,6 @@ export function AsgardThemeContextProvider(
348
346
  // For unset messages
349
347
  color:
350
348
  themeFromAnnotations.chatbot?.primaryComponent?.secondaryColor,
351
- backgroundColor: themeFromAnnotations.botMessage?.backgroundColor
352
- ? addTransparency(themeFromAnnotations.botMessage.backgroundColor, 0.2)
353
- : undefined,
354
349
  },
355
350
  },
356
351
  ButtonMessageTemplate: {
@@ -394,17 +389,6 @@ export function AsgardThemeContextProvider(
394
389
 
395
390
  const value = useMemo(() => deepMergeTheme(), [deepMergeTheme]);
396
391
 
397
- // 設置 CSS 自定義屬性
398
- useEffect(() => {
399
- const botMessageBgColor = annotations?.embedConfig?.theme?.botMessage?.backgroundColor;
400
- if (botMessageBgColor) {
401
- document.documentElement.style.setProperty(
402
- '--bot-message-hyperlink-color',
403
- darkenColor(botMessageBgColor, 0.2)
404
- );
405
- }
406
- }, [annotations?.embedConfig?.theme?.botMessage?.backgroundColor]);
407
-
408
392
  return (
409
393
  <AsgardThemeContext.Provider value={value}>
410
394
  {children}
@@ -113,13 +113,7 @@ const LinkRenderer = ({ children, href, ...props }: React.ComponentProps<'a'>):
113
113
  );
114
114
 
115
115
  return (
116
- <a
117
- href={href}
118
- onClick={handleClick}
119
- rel="noopener noreferrer"
120
- style={{ color: 'var(--bot-message-hyperlink-color, #4467eb)' }}
121
- {...props}
122
- >
116
+ <a href={href} onClick={handleClick} rel="noopener noreferrer" {...props}>
123
117
  {children}
124
118
  </a>
125
119
  );
@@ -1,18 +0,0 @@
1
- /**
2
- * 顏色工具函數
3
- */
4
- /**
5
- * 為顏色添加透明度
6
- * @param color 十六進制顏色值 (例如: #FF0000)
7
- * @param alpha 透明度 (0-1)
8
- * @returns 帶透明度的十六進制顏色值
9
- */
10
- export declare const addTransparency: (color: string, alpha: number) => string;
11
- /**
12
- * 加深顏色
13
- * @param color 十六進制顏色值 (例如: #FF0000)
14
- * @param amount 加深程度 (0-1)
15
- * @returns 加深後的十六進制顏色值
16
- */
17
- export declare const darkenColor: (color: string, amount: number) => string;
18
- //# sourceMappingURL=color-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"color-utils.d.ts","sourceRoot":"","sources":["../../src/utils/color-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UAAW,MAAM,SAAS,MAAM,KAAG,MAM9D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,UAAW,MAAM,UAAU,MAAM,KAAG,MAa3D,CAAC"}
@@ -1,38 +0,0 @@
1
- /**
2
- * 顏色工具函數
3
- */
4
-
5
- /**
6
- * 為顏色添加透明度
7
- * @param color 十六進制顏色值 (例如: #FF0000)
8
- * @param alpha 透明度 (0-1)
9
- * @returns 帶透明度的十六進制顏色值
10
- */
11
- export const addTransparency = (color: string, alpha: number): string => {
12
- if (!color.startsWith('#')) return color;
13
-
14
- const hex = Math.round(alpha * 255).toString(16).padStart(2, '0');
15
-
16
- return `${color}${hex}`;
17
- };
18
-
19
- /**
20
- * 加深顏色
21
- * @param color 十六進制顏色值 (例如: #FF0000)
22
- * @param amount 加深程度 (0-1)
23
- * @returns 加深後的十六進制顏色值
24
- */
25
- export const darkenColor = (color: string, amount: number): string => {
26
- if (!color.startsWith('#')) return color;
27
-
28
- const hex = color.slice(1);
29
- const r = parseInt(hex.slice(0, 2), 16);
30
- const g = parseInt(hex.slice(2, 4), 16);
31
- const b = parseInt(hex.slice(4, 6), 16);
32
-
33
- const newR = Math.max(0, Math.round(r * (1 - amount)));
34
- const newG = Math.max(0, Math.round(g * (1 - amount)));
35
- const newB = Math.max(0, Math.round(b * (1 - amount)));
36
-
37
- return `#${newR.toString(16).padStart(2, '0')}${newG.toString(16).padStart(2, '0')}${newB.toString(16).padStart(2, '0')}`;
38
- };