@anker-in/campaign-ui 0.3.4 → 0.3.6
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/cjs/components/LiveChatWidget/LiveChatWidget.js +1 -1
- package/dist/cjs/components/LiveChatWidget/LiveChatWidget.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/components/MessageContent/PromotionList.js.map +2 -2
- package/dist/cjs/components/LiveChatWidget/components/MessageList.js +3 -3
- package/dist/cjs/components/LiveChatWidget/components/MessageList.js.map +3 -3
- package/dist/cjs/components/LiveChatWidget/hooks/useChatState.d.ts +8 -3
- package/dist/cjs/components/LiveChatWidget/hooks/useChatState.js +1 -1
- package/dist/cjs/components/LiveChatWidget/hooks/useChatState.js.map +2 -2
- package/dist/cjs/components/LiveChatWidget/index.d.ts +1 -1
- package/dist/cjs/components/LiveChatWidget/index.js +1 -1
- package/dist/cjs/components/LiveChatWidget/index.js.map +2 -2
- package/dist/cjs/components/LiveChatWidget/types.d.ts +4 -1
- package/dist/cjs/components/LiveChatWidget/types.js.map +1 -1
- package/dist/cjs/components/LiveChatWidget/utils/userId.d.ts +7 -2
- package/dist/cjs/components/LiveChatWidget/utils/userId.js +1 -1
- package/dist/cjs/components/LiveChatWidget/utils/userId.js.map +3 -3
- package/dist/cjs/components/credits/creditsBanner/index.js +2 -2
- package/dist/cjs/components/credits/creditsBanner/index.js.map +2 -2
- package/dist/cjs/stories/LiveChatWidget.stories.js +2 -9
- package/dist/cjs/stories/LiveChatWidget.stories.js.map +2 -2
- package/dist/esm/components/LiveChatWidget/LiveChatWidget.js +1 -1
- package/dist/esm/components/LiveChatWidget/LiveChatWidget.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/components/MessageContent/PromotionList.js.map +2 -2
- package/dist/esm/components/LiveChatWidget/components/MessageList.js +3 -3
- package/dist/esm/components/LiveChatWidget/components/MessageList.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/hooks/useChatState.d.ts +8 -3
- package/dist/esm/components/LiveChatWidget/hooks/useChatState.js +1 -1
- package/dist/esm/components/LiveChatWidget/hooks/useChatState.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/index.d.ts +1 -1
- package/dist/esm/components/LiveChatWidget/index.js +1 -1
- package/dist/esm/components/LiveChatWidget/index.js.map +3 -3
- package/dist/esm/components/LiveChatWidget/types.d.ts +4 -1
- package/dist/esm/components/LiveChatWidget/utils/userId.d.ts +7 -2
- package/dist/esm/components/LiveChatWidget/utils/userId.js +1 -1
- package/dist/esm/components/LiveChatWidget/utils/userId.js.map +3 -3
- package/dist/esm/components/credits/creditsBanner/index.js +2 -2
- package/dist/esm/components/credits/creditsBanner/index.js.map +2 -2
- package/dist/esm/stories/LiveChatWidget.stories.js +1 -8
- package/dist/esm/stories/LiveChatWidget.stories.js.map +2 -2
- package/dist/index.d.mts +140 -13
- package/dist/index.d.ts +140 -13
- package/dist/index.js +2109 -6424
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1901 -6216
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/components/LiveChatWidget/LiveChatWidget.tsx +60 -7
- package/src/components/LiveChatWidget/components/MessageContent/PromotionList.tsx +1 -1
- package/src/components/LiveChatWidget/components/MessageList.tsx +39 -44
- package/src/components/LiveChatWidget/hooks/useChatState.ts +22 -10
- package/src/components/LiveChatWidget/index.tsx +1 -1
- package/src/components/LiveChatWidget/types.ts +4 -1
- package/src/components/LiveChatWidget/utils/userId.ts +13 -62
- package/src/components/credits/creditsBanner/index.tsx +5 -5
- package/src/stories/LiveChatWidget.stories.tsx +8 -13
- package/src/styles/livechat.css +29 -0
package/dist/index.d.ts
CHANGED
|
@@ -590,6 +590,10 @@ interface Message {
|
|
|
590
590
|
content: MessageContent[];
|
|
591
591
|
timestamp: number;
|
|
592
592
|
metadata?: MessageMetadata;
|
|
593
|
+
structured_content?: Array<{
|
|
594
|
+
type: string;
|
|
595
|
+
data: any;
|
|
596
|
+
}>;
|
|
593
597
|
}
|
|
594
598
|
type MessageContentType = 'text' | 'product_card' | 'product_list' | 'product_comparison' | 'policy' | 'quick_replies' | 'thinking' | 'error' | 'faq_list' | 'cart';
|
|
595
599
|
type MessageContent = TextContent | ProductCardContent | ProductListContent | ProductComparisonContent | PolicyContent | QuickRepliesContent | ThinkingContent | ErrorContent | FAQListContent | PromotionListContent | CartContent;
|
|
@@ -600,7 +604,11 @@ interface TextContent {
|
|
|
600
604
|
interface ProductCardContent {
|
|
601
605
|
type: 'product_card';
|
|
602
606
|
data: {
|
|
603
|
-
product
|
|
607
|
+
product?: Product;
|
|
608
|
+
rawProduct?: any;
|
|
609
|
+
productHandle: string;
|
|
610
|
+
onAddToCart?: (product: Product) => void;
|
|
611
|
+
productCardRender?: (product: any, productHandle: string) => React.ReactNode;
|
|
604
612
|
};
|
|
605
613
|
}
|
|
606
614
|
interface ProductListContent {
|
|
@@ -970,6 +978,43 @@ interface CommonText {
|
|
|
970
978
|
* @default "OFF"
|
|
971
979
|
*/
|
|
972
980
|
off?: string;
|
|
981
|
+
/**
|
|
982
|
+
* 购物车总计文案
|
|
983
|
+
* @default "Total"
|
|
984
|
+
*/
|
|
985
|
+
total?: string;
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* 法规协议弹窗配置
|
|
989
|
+
*/
|
|
990
|
+
interface ComplianceDialogConfig {
|
|
991
|
+
/**
|
|
992
|
+
* 弹窗标题
|
|
993
|
+
* @example "Hi! I'm your eufy AI assistant."
|
|
994
|
+
*/
|
|
995
|
+
title: string;
|
|
996
|
+
/**
|
|
997
|
+
* 弹窗内容文本(支持 HTML)
|
|
998
|
+
* @example "AI-generated responses can be inaccurate. Please verify important info. Do not input sensitive personal data"
|
|
999
|
+
*/
|
|
1000
|
+
content: string;
|
|
1001
|
+
/**
|
|
1002
|
+
* 勾选框文本(支持完整 HTML,包括链接)
|
|
1003
|
+
* 可以直接包含 <a> 标签等 HTML 元素
|
|
1004
|
+
* @example "By starting to use \"Live Chat\", you agree to Anker's <a href=\"https://www.anker.com/privacy\" target=\"_blank\">LIVE CHAT PRIVACY NOTICE</a>."
|
|
1005
|
+
*/
|
|
1006
|
+
checkboxText: string;
|
|
1007
|
+
/**
|
|
1008
|
+
* 同意按钮文本
|
|
1009
|
+
* @default "Agree"
|
|
1010
|
+
*/
|
|
1011
|
+
agreeButtonText?: string;
|
|
1012
|
+
/**
|
|
1013
|
+
* Cookie 名称,用于记录用户同意状态
|
|
1014
|
+
* Cookie 有效期为 365 天
|
|
1015
|
+
* @default "livechat_compliance_agreed"
|
|
1016
|
+
*/
|
|
1017
|
+
cookieName?: string;
|
|
973
1018
|
}
|
|
974
1019
|
interface LiveChatWidgetProps {
|
|
975
1020
|
/**
|
|
@@ -983,14 +1028,9 @@ interface LiveChatWidgetProps {
|
|
|
983
1028
|
* @example { "Authorization": "Bearer token", "X-Custom-Header": "value" }
|
|
984
1029
|
*/
|
|
985
1030
|
headers?: Record<string, string>;
|
|
986
|
-
/**
|
|
987
|
-
* 是否启用 reCAPTCHA 验证
|
|
988
|
-
* @default false
|
|
989
|
-
*/
|
|
990
|
-
needRecaptcha?: boolean;
|
|
991
1031
|
/**
|
|
992
1032
|
* reCAPTCHA site key
|
|
993
|
-
*
|
|
1033
|
+
* 提供此参数将自动启用 reCAPTCHA v3 验证
|
|
994
1034
|
* @example "6LfS4J4pAAAAACX1e_WrxutmxxzCK7FU4WzVqL14"
|
|
995
1035
|
*/
|
|
996
1036
|
recaptchaSitekey?: string;
|
|
@@ -1005,6 +1045,12 @@ interface LiveChatWidgetProps {
|
|
|
1005
1045
|
* @example "www.eufy.com"
|
|
1006
1046
|
*/
|
|
1007
1047
|
site?: string;
|
|
1048
|
+
/**
|
|
1049
|
+
* 渠道编码
|
|
1050
|
+
* 用于标识来源渠道
|
|
1051
|
+
* @example "web_homepage"
|
|
1052
|
+
*/
|
|
1053
|
+
channelCode?: string;
|
|
1008
1054
|
/**
|
|
1009
1055
|
* 已登录用户的 ID(可选)
|
|
1010
1056
|
* 如果提供,将在 API 请求中传递
|
|
@@ -1033,7 +1079,6 @@ interface LiveChatWidgetProps {
|
|
|
1033
1079
|
position?: BubblePosition;
|
|
1034
1080
|
/**
|
|
1035
1081
|
* 欢迎消息
|
|
1036
|
-
* @default "你好!我是 AI 助手,有什么可以帮助你的吗?"
|
|
1037
1082
|
*/
|
|
1038
1083
|
welcomeMessage?: string;
|
|
1039
1084
|
/**
|
|
@@ -1059,9 +1104,55 @@ interface LiveChatWidgetProps {
|
|
|
1059
1104
|
*/
|
|
1060
1105
|
chatBubbleIcon?: string;
|
|
1061
1106
|
/**
|
|
1062
|
-
*
|
|
1107
|
+
* 受控模式:是否打开聊天窗口
|
|
1108
|
+
* 提供此参数时,组件将处于受控模式
|
|
1109
|
+
* @example
|
|
1110
|
+
* ```tsx
|
|
1111
|
+
* const [isOpen, setIsOpen] = useState(false)
|
|
1112
|
+
* <LiveChatWidget open={isOpen} onOpenChange={setIsOpen} />
|
|
1113
|
+
* ```
|
|
1114
|
+
*/
|
|
1115
|
+
open?: boolean;
|
|
1116
|
+
/**
|
|
1117
|
+
* 受控模式:打开/关闭状态变化回调
|
|
1118
|
+
* 【必需】配合 `open` 使用,用于同步状态到父组件
|
|
1119
|
+
* 当用户点击打开或关闭按钮时触发
|
|
1120
|
+
* @example
|
|
1121
|
+
* ```tsx
|
|
1122
|
+
* <LiveChatWidget
|
|
1123
|
+
* open={isOpen}
|
|
1124
|
+
* onOpenChange={setIsOpen} // 必需:同步状态
|
|
1125
|
+
* />
|
|
1126
|
+
* ```
|
|
1127
|
+
*/
|
|
1128
|
+
onOpenChange?: (open: boolean) => void;
|
|
1129
|
+
/**
|
|
1130
|
+
* 【可选】窗口打开事件监听
|
|
1131
|
+
* 用于埋点、日志等副作用,不影响状态控制
|
|
1132
|
+
* 在 onOpenChange 之后触发
|
|
1133
|
+
* @example
|
|
1134
|
+
* ```tsx
|
|
1135
|
+
* <LiveChatWidget
|
|
1136
|
+
* open={isOpen}
|
|
1137
|
+
* onOpenChange={setIsOpen}
|
|
1138
|
+
* onOpen={() => trackEvent('chat_opened')} // 可选:埋点
|
|
1139
|
+
* />
|
|
1140
|
+
* ```
|
|
1063
1141
|
*/
|
|
1064
1142
|
onOpen?: () => void;
|
|
1143
|
+
/**
|
|
1144
|
+
* 【可选】窗口关闭事件监听
|
|
1145
|
+
* 用于埋点、日志等副作用,不影响状态控制
|
|
1146
|
+
* 在 onOpenChange 之后触发
|
|
1147
|
+
* @example
|
|
1148
|
+
* ```tsx
|
|
1149
|
+
* <LiveChatWidget
|
|
1150
|
+
* open={isOpen}
|
|
1151
|
+
* onOpenChange={setIsOpen}
|
|
1152
|
+
* onClose={() => trackEvent('chat_closed')} // 可选:埋点
|
|
1153
|
+
* />
|
|
1154
|
+
* ```
|
|
1155
|
+
*/
|
|
1065
1156
|
onClose?: () => void;
|
|
1066
1157
|
onMessageSend?: (message: string) => void;
|
|
1067
1158
|
onError?: (error: Error) => void;
|
|
@@ -1078,8 +1169,9 @@ interface LiveChatWidgetProps {
|
|
|
1078
1169
|
onProductList?: () => void;
|
|
1079
1170
|
/**
|
|
1080
1171
|
* AI 回复促销卡片时触发
|
|
1172
|
+
* @param promotions 促销活动数组数据
|
|
1081
1173
|
*/
|
|
1082
|
-
onPromotionList?: () => void;
|
|
1174
|
+
onPromotionList?: (promotions: PromotionItem[]) => void;
|
|
1083
1175
|
/**
|
|
1084
1176
|
* 商品操作回调
|
|
1085
1177
|
*/
|
|
@@ -1098,6 +1190,43 @@ interface LiveChatWidgetProps {
|
|
|
1098
1190
|
* 用于自定义按钮文案
|
|
1099
1191
|
*/
|
|
1100
1192
|
commonText?: CommonText;
|
|
1193
|
+
/**
|
|
1194
|
+
* 自定义产品卡片渲染函数
|
|
1195
|
+
* 用于自定义渲染 product_card 类型的产品卡片
|
|
1196
|
+
* 当提供此函数时,将替代默认的产品卡片渲染逻辑
|
|
1197
|
+
* @param product 原始后端产品数据(未经转换的数据),如果在 product_list 中找不到则为 undefined
|
|
1198
|
+
* @param productHandle 文本占位符中的产品 ID(如 {{product:ID}} 中的 ID),可用于应用层查询产品数据
|
|
1199
|
+
* @returns React 可渲染的内容
|
|
1200
|
+
* @example
|
|
1201
|
+
* ```tsx
|
|
1202
|
+
* <LiveChatWidget
|
|
1203
|
+
* productCardRender={(product, productHandle) => {
|
|
1204
|
+
* // product 可能为 undefined,此时可用 productHandle 查询产品
|
|
1205
|
+
* if (!product) {
|
|
1206
|
+
* return <ProductCardByHandle handle={productHandle} />
|
|
1207
|
+
* }
|
|
1208
|
+
* return (
|
|
1209
|
+
* <div>
|
|
1210
|
+
* <h3>{product.title}</h3>
|
|
1211
|
+
* <p>{product.price_range?.min}</p>
|
|
1212
|
+
* </div>
|
|
1213
|
+
* )
|
|
1214
|
+
* }}
|
|
1215
|
+
* />
|
|
1216
|
+
* ```
|
|
1217
|
+
*/
|
|
1218
|
+
productCardRender?: (product: any, productHandle: string) => React.ReactNode;
|
|
1219
|
+
/**
|
|
1220
|
+
* 输入框底部提示文本
|
|
1221
|
+
* 不传入则不显示
|
|
1222
|
+
*/
|
|
1223
|
+
bottomTips?: string;
|
|
1224
|
+
/**
|
|
1225
|
+
* 法规协议弹窗配置
|
|
1226
|
+
* 提供此参数将在用户首次点击聊天气泡时显示法规协议弹窗
|
|
1227
|
+
* 用户同意后才会打开聊天窗口
|
|
1228
|
+
*/
|
|
1229
|
+
complianceConfig?: ComplianceDialogConfig;
|
|
1101
1230
|
}
|
|
1102
1231
|
interface MessageRenderer {
|
|
1103
1232
|
render: (content: MessageContent, isUser: boolean, isSystem: boolean) => React.ReactNode;
|
|
@@ -1151,11 +1280,10 @@ type BubblePosition = PositionStyles;
|
|
|
1151
1280
|
* onMessageSend={(msg) => console.log('Sent:', msg)}
|
|
1152
1281
|
* />
|
|
1153
1282
|
*
|
|
1154
|
-
* // 启用 reCAPTCHA v3
|
|
1283
|
+
* // 启用 reCAPTCHA v3 安全防护(提供 sitekey 即自动启用)
|
|
1155
1284
|
* <LiveChatWidget
|
|
1156
1285
|
* apiBaseUrl="https://beta-api-livechat.anker.com"
|
|
1157
1286
|
* site="www.eufy.com"
|
|
1158
|
-
* needRecaptcha={true}
|
|
1159
1287
|
* recaptchaSitekey="6LfS4J4pAAAAACX1e_WrxutmxxzCK7FU4WzVqL14"
|
|
1160
1288
|
* recaptchaAction="livechat"
|
|
1161
1289
|
* />
|
|
@@ -1168,7 +1296,6 @@ type BubblePosition = PositionStyles;
|
|
|
1168
1296
|
* "Authorization": "Bearer your-token",
|
|
1169
1297
|
* "X-Custom-Header": "value"
|
|
1170
1298
|
* }}
|
|
1171
|
-
* needRecaptcha={true}
|
|
1172
1299
|
* recaptchaSitekey="your-site-key"
|
|
1173
1300
|
* />
|
|
1174
1301
|
* ```
|