@anker-in/campaign-ui 0.0.33-alpha3 → 0.0.33-alpha4
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/chat/Response.d.ts +1 -1
- package/dist/cjs/components/chat/action.d.ts +3 -1
- package/dist/cjs/components/chat/action.js +1 -1
- package/dist/cjs/components/chat/action.js.map +3 -3
- package/dist/cjs/components/chat/index.d.ts +13 -3
- package/dist/cjs/components/chat/index.js +1 -1
- package/dist/cjs/components/chat/index.js.map +3 -3
- package/dist/cjs/components/chat/messages.js +1 -1
- package/dist/cjs/components/chat/messages.js.map +3 -3
- package/dist/cjs/components/chat/response.js +1 -1
- package/dist/cjs/components/chat/response.js.map +2 -2
- package/dist/cjs/stories/chat.stories.js +1 -1
- package/dist/cjs/stories/chat.stories.js.map +2 -2
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/components/chat/Response.d.ts +1 -1
- package/dist/esm/components/chat/action.d.ts +3 -1
- package/dist/esm/components/chat/action.js +1 -1
- package/dist/esm/components/chat/action.js.map +3 -3
- package/dist/esm/components/chat/index.d.ts +13 -3
- package/dist/esm/components/chat/index.js +1 -1
- package/dist/esm/components/chat/index.js.map +3 -3
- package/dist/esm/components/chat/messages.js +1 -1
- package/dist/esm/components/chat/messages.js.map +3 -3
- package/dist/esm/components/chat/response.js +1 -1
- package/dist/esm/components/chat/response.js.map +2 -2
- package/dist/esm/stories/chat.stories.js +1 -1
- package/dist/esm/stories/chat.stories.js.map +2 -2
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/chat/action.tsx +31 -8
- package/src/components/chat/index.tsx +17 -3
- package/src/components/chat/messages.tsx +43 -2
- package/src/components/chat/response.tsx +6 -4
- package/src/stories/chat.stories.tsx +2 -3
- package/src/styles/css/messages.css +8 -0
- package/src/styles/css/response.css +0 -1
|
@@ -14,6 +14,8 @@ interface Message {
|
|
|
14
14
|
export interface ActionProps {
|
|
15
15
|
start?: string
|
|
16
16
|
history: Message[]
|
|
17
|
+
gotocheckoutRender?: string | ((_props: any) => React.ReactElement)
|
|
18
|
+
gotocartRender?: string | ((_props: any) => React.ReactElement)
|
|
17
19
|
addtocartRender?: string | ((_props: any) => React.ReactElement)
|
|
18
20
|
productRender?: string | ((_props: any) => React.ReactElement)
|
|
19
21
|
signupRender?: string | ((_props: any) => React.ReactElement)
|
|
@@ -23,6 +25,8 @@ export interface ActionProps {
|
|
|
23
25
|
export const CopilotAction = ({
|
|
24
26
|
start,
|
|
25
27
|
history,
|
|
28
|
+
gotocheckoutRender,
|
|
29
|
+
gotocartRender,
|
|
26
30
|
addtocartRender,
|
|
27
31
|
productRender,
|
|
28
32
|
signupRender,
|
|
@@ -35,7 +39,6 @@ export const CopilotAction = ({
|
|
|
35
39
|
if (originhistory?.length > 0) {
|
|
36
40
|
const content = originhistory?.map(value => {
|
|
37
41
|
if (value?.name && value?.arguments) {
|
|
38
|
-
console.log('value?.name && value?.arguments', value?.name, value?.arguments)
|
|
39
42
|
return new ActionExecutionMessage({
|
|
40
43
|
name: value?.name,
|
|
41
44
|
arguments: value?.arguments,
|
|
@@ -52,20 +55,40 @@ export const CopilotAction = ({
|
|
|
52
55
|
}, [history])
|
|
53
56
|
|
|
54
57
|
useCopilotAction({
|
|
55
|
-
name: '
|
|
56
|
-
description: '
|
|
58
|
+
name: 'go_to_checkout',
|
|
59
|
+
description: 'go to cart',
|
|
57
60
|
parameters: [{ sku: '', handle: '' }] as any,
|
|
58
|
-
render:
|
|
61
|
+
render: gotocheckoutRender || (props => <div className="hidden">{JSON.stringify(props)}</div>),
|
|
59
62
|
handler: function () {
|
|
60
63
|
// console.log('buynow-props', props)
|
|
61
64
|
},
|
|
62
65
|
})
|
|
63
66
|
|
|
64
67
|
useCopilotAction({
|
|
65
|
-
name: '
|
|
66
|
-
description: '
|
|
68
|
+
name: 'go_to_cart',
|
|
69
|
+
description: 'go to cart',
|
|
67
70
|
parameters: [{ sku: '', handle: '' }] as any,
|
|
68
|
-
render:
|
|
71
|
+
render: gotocartRender || (props => <div className="hidden">{JSON.stringify(props)}</div>),
|
|
72
|
+
handler: function () {
|
|
73
|
+
// console.log('buynow-props', props)
|
|
74
|
+
},
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
useCopilotAction({
|
|
78
|
+
name: 'add_to_cart',
|
|
79
|
+
description: 'add to cart',
|
|
80
|
+
parameters: [{ sku: '', handle: '' }] as any,
|
|
81
|
+
render: addtocartRender || (props => <div className="hidden">{JSON.stringify(props)}</div>),
|
|
82
|
+
handler: function () {
|
|
83
|
+
// console.log('buynow-props', props)
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
useCopilotAction({
|
|
88
|
+
name: 'show_product_card',
|
|
89
|
+
description: 'product card',
|
|
90
|
+
parameters: [{ sku: '', handle: '' }] as any,
|
|
91
|
+
render: productRender || (props => <div className="hidden">{JSON.stringify(props)}</div>),
|
|
69
92
|
handler: function () {
|
|
70
93
|
// console.log('buynow-props', props)
|
|
71
94
|
},
|
|
@@ -79,7 +102,7 @@ export const CopilotAction = ({
|
|
|
79
102
|
name: 'signup',
|
|
80
103
|
},
|
|
81
104
|
] as any,
|
|
82
|
-
render: signupRender || (props => <div>{JSON.stringify(props)}</div>),
|
|
105
|
+
render: signupRender || (props => <div className="hidden">{JSON.stringify(props)}</div>),
|
|
83
106
|
handler: function () {
|
|
84
107
|
// console.log('signup-props', props)
|
|
85
108
|
},
|
|
@@ -27,17 +27,27 @@ export interface ChatProps {
|
|
|
27
27
|
*/
|
|
28
28
|
query?: string
|
|
29
29
|
/** 'follow' or 'unfollow' | true or false
|
|
30
|
+
* follow: ResponseButton 会跟随在 messages 的后边
|
|
31
|
+
* unfollow: ResponseButton 在聊天框底部
|
|
30
32
|
*/
|
|
31
33
|
showResponseButton?: string | boolean
|
|
32
|
-
/**
|
|
34
|
+
/** 跳转 checkout action 卡片,接受参数: {"status":"complete","args":[{"sku":["A3936031"],"handle":"space-a40-a3936031"}],"result":""}
|
|
35
|
+
* 后端接口文档:https://anker-in.feishu.cn/wiki/DOYJwE9oxipWmYk072ncnJNznBb
|
|
36
|
+
*/
|
|
37
|
+
gotocheckoutRender?: string | ((_props: any) => React.ReactElement)
|
|
38
|
+
/** 打开购物车 action 卡片,接受参数: {"status":"complete","args":[{"sku":["A3936031"],"handle":"space-a40-a3936031"}],"result":""}
|
|
39
|
+
* 后端接口文档:https://anker-in.feishu.cn/wiki/DOYJwE9oxipWmYk072ncnJNznBb
|
|
40
|
+
*/
|
|
41
|
+
gotocartRender?: string | ((_props: any) => React.ReactElement)
|
|
42
|
+
/** 加购卡片,接受参数: {"status":"complete","args":[{"sku":["A3936031"],"handle":"space-a40-a3936031"}],"result":""}
|
|
33
43
|
* 后端接口文档:https://anker-in.feishu.cn/wiki/DOYJwE9oxipWmYk072ncnJNznBb
|
|
34
44
|
*/
|
|
35
45
|
addtocartRender?: string | ((_props: any) => React.ReactElement)
|
|
36
|
-
/** 产品卡片,接受参数: {"status":"complete","args":[{"sku":"A3936031","handle":"space-a40-a3936031"}],"result":""}
|
|
46
|
+
/** 产品卡片,接受参数: {"status":"complete","args":[{"sku":["A3936031"],"handle":"space-a40-a3936031"}],"result":""}
|
|
37
47
|
* 后端接口文档:https://anker-in.feishu.cn/wiki/DOYJwE9oxipWmYk072ncnJNznBb
|
|
38
48
|
*/
|
|
39
49
|
productRender?: string | ((_props: any) => React.ReactElement)
|
|
40
|
-
/** 订阅卡片,接受参数:
|
|
50
|
+
/** 订阅卡片,接受参数: {"status":"complete","args":[{"sku":["A3936031"],"handle":"space-a40-a3936031"}],"result":""}
|
|
41
51
|
* 后端接口文档:https://anker-in.feishu.cn/wiki/DOYJwE9oxipWmYk072ncnJNznBb
|
|
42
52
|
*/
|
|
43
53
|
signupRender?: string | ((_props: any) => React.ReactElement)
|
|
@@ -61,6 +71,8 @@ const Chat = (props: ChatProps) => {
|
|
|
61
71
|
locale = '',
|
|
62
72
|
query = '',
|
|
63
73
|
showResponseButton,
|
|
74
|
+
gotocheckoutRender,
|
|
75
|
+
gotocartRender,
|
|
64
76
|
addtocartRender,
|
|
65
77
|
productRender,
|
|
66
78
|
signupRender,
|
|
@@ -182,6 +194,8 @@ const Chat = (props: ChatProps) => {
|
|
|
182
194
|
<CopilotAction
|
|
183
195
|
start={start}
|
|
184
196
|
history={history}
|
|
197
|
+
gotocartRender={gotocartRender}
|
|
198
|
+
gotocheckoutRender={gotocheckoutRender}
|
|
185
199
|
addtocartRender={addtocartRender}
|
|
186
200
|
productRender={productRender}
|
|
187
201
|
signupRender={signupRender}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useMemo } from 'react'
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react'
|
|
2
2
|
import type { MessagesProps } from './props.js'
|
|
3
3
|
import { useChatContext } from '@copilotkit/react-ui'
|
|
4
4
|
import { Markdown } from './markdown.js'
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
} from '@copilotkit/runtime-client-gql'
|
|
14
14
|
|
|
15
15
|
const Messages = ({ messages, inProgress, ResponseButton, children }: MessagesProps) => {
|
|
16
|
+
const [isExpanded, setIsExpanded] = useState(true)
|
|
17
|
+
|
|
16
18
|
const { chatComponentsCache } = useCopilotContext()
|
|
17
19
|
|
|
18
20
|
const context = useChatContext()
|
|
@@ -35,6 +37,7 @@ const Messages = ({ messages, inProgress, ResponseButton, children }: MessagesPr
|
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
const messagesEndRef = React.useRef<HTMLDivElement>(null)
|
|
40
|
+
const messagesEndChildRef = React.useRef<HTMLDivElement>(null)
|
|
38
41
|
|
|
39
42
|
const scrollToBottom = () => {
|
|
40
43
|
if (messagesEndRef.current) {
|
|
@@ -48,6 +51,40 @@ const Messages = ({ messages, inProgress, ResponseButton, children }: MessagesPr
|
|
|
48
51
|
scrollToBottom()
|
|
49
52
|
}, [messages])
|
|
50
53
|
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
const textarea = document.querySelector('.copilotKitInput textarea') as HTMLTextAreaElement
|
|
56
|
+
|
|
57
|
+
textarea &&
|
|
58
|
+
textarea.addEventListener('click', function () {
|
|
59
|
+
if (textarea.value && document.activeElement === textarea) {
|
|
60
|
+
setIsExpanded(false)
|
|
61
|
+
} else {
|
|
62
|
+
setIsExpanded(true)
|
|
63
|
+
scrollToBottom()
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
textarea &&
|
|
67
|
+
textarea.addEventListener('input', function () {
|
|
68
|
+
if (textarea.value && document.activeElement === textarea) {
|
|
69
|
+
setIsExpanded(false)
|
|
70
|
+
} else {
|
|
71
|
+
setIsExpanded(true)
|
|
72
|
+
scrollToBottom()
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
}, [])
|
|
76
|
+
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
const content = messagesEndChildRef.current
|
|
79
|
+
if (isExpanded && content) {
|
|
80
|
+
content.style.maxHeight = '500px'
|
|
81
|
+
content.style.overflow = 'visible'
|
|
82
|
+
} else if (!isExpanded && content) {
|
|
83
|
+
content.style.maxHeight = '0'
|
|
84
|
+
content.style.overflow = 'hidden'
|
|
85
|
+
}
|
|
86
|
+
}, [isExpanded])
|
|
87
|
+
|
|
51
88
|
return (
|
|
52
89
|
<div className="copilotKitMessages">
|
|
53
90
|
{messages.map((message, index) => {
|
|
@@ -140,7 +177,11 @@ const Messages = ({ messages, inProgress, ResponseButton, children }: MessagesPr
|
|
|
140
177
|
}
|
|
141
178
|
})}
|
|
142
179
|
<div className="responseButtonBox">{ResponseButton}</div>
|
|
143
|
-
<footer ref={messagesEndRef}>
|
|
180
|
+
<footer ref={messagesEndRef}>
|
|
181
|
+
<div className="copilotKitMessagesFooter" ref={messagesEndChildRef}>
|
|
182
|
+
{children}
|
|
183
|
+
</div>
|
|
184
|
+
</footer>
|
|
144
185
|
</div>
|
|
145
186
|
)
|
|
146
187
|
}
|
|
@@ -7,10 +7,12 @@ const ResponseButton = () => {
|
|
|
7
7
|
const { isLoading, reloadMessages, stopGeneration } = useCopilotChat()
|
|
8
8
|
|
|
9
9
|
return (
|
|
10
|
-
|
|
11
|
-
{isLoading ?
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
!isLoading && (
|
|
11
|
+
<button onClick={isLoading ? stopGeneration : reloadMessages} className="copilotKitResponseButton">
|
|
12
|
+
{isLoading ? context.labels.stopGenerating : context.labels.regenerateResponse}
|
|
13
|
+
<span>{isLoading ? context.icons.stopIcon : context.icons.regenerateIcon}</span>
|
|
14
|
+
</button>
|
|
15
|
+
)
|
|
14
16
|
)
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -20,8 +20,7 @@ const meta: Meta<typeof Chat> = {
|
|
|
20
20
|
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
|
21
21
|
decorators: [
|
|
22
22
|
Story => (
|
|
23
|
-
<div style={{
|
|
24
|
-
{/* 👇 Decorators in Storybook also accept a function. Replace <Story/> with Story() to enable it */}
|
|
23
|
+
<div style={{ height: '700px' }}>
|
|
25
24
|
<Story />
|
|
26
25
|
</div>
|
|
27
26
|
),
|
|
@@ -35,7 +34,7 @@ export const Default: Story = {
|
|
|
35
34
|
title: 'DTC Live Chat',
|
|
36
35
|
runtimeUrl: 'https://beta-dtcapi.anker.com',
|
|
37
36
|
shopify_domain: 'soundcoreusa.myshopify.com',
|
|
38
|
-
user_id: '
|
|
37
|
+
user_id: 'arno6',
|
|
39
38
|
showResponseButton: 'follow',
|
|
40
39
|
lang: { popupTip: 'Hi ! Welcome to soundcore Innovations live chat!', popupTipTimeout: [3000, 6000] },
|
|
41
40
|
},
|
|
@@ -75,3 +75,11 @@
|
|
|
75
75
|
.copilotKitMessage.copilotKitAssistantMessage:has(.copilotKitMarkdown:empty) {
|
|
76
76
|
display: none;
|
|
77
77
|
}
|
|
78
|
+
|
|
79
|
+
.copilotKitMessagesFooter {
|
|
80
|
+
transition: all 300ms ease-out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.copilotKitCustomAssistantMessage .hidden {
|
|
84
|
+
display: none !important;
|
|
85
|
+
}
|