@anker-in/campaign-ui 0.1.1 → 0.1.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/README.md +0 -4
- package/dist/cjs/components/chat/action.d.ts +2 -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/chatContext.js +2 -0
- package/dist/cjs/components/chat/chatContext.js.map +7 -0
- package/dist/cjs/components/chat/index.d.ts +3 -0
- package/dist/cjs/components/chat/index.js +1 -1
- package/dist/cjs/components/chat/index.js.map +3 -3
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/components/chat/action.d.ts +2 -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/chatContext.js +2 -0
- package/dist/esm/components/chat/chatContext.js.map +7 -0
- package/dist/esm/components/chat/index.d.ts +3 -0
- package/dist/esm/components/chat/index.js +1 -1
- package/dist/esm/components/chat/index.js.map +3 -3
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/chat/action.tsx +12 -0
- package/src/components/chat/chatContext.tsx +161 -0
- package/src/components/chat/index.tsx +5 -0
- package/CONTRIBUTING.md +0 -175
|
@@ -15,6 +15,7 @@ export interface ActionProps {
|
|
|
15
15
|
start?: string
|
|
16
16
|
history: Message[]
|
|
17
17
|
addtocartHandler?: (_args: any) => Promise<any>
|
|
18
|
+
commonRender?: string | ((_props: any) => React.ReactElement)
|
|
18
19
|
gotocheckoutRender?: string | ((_props: any) => React.ReactElement)
|
|
19
20
|
gotocartRender?: string | ((_props: any) => React.ReactElement)
|
|
20
21
|
addtocartRender?: string | ((_props: any) => React.ReactElement)
|
|
@@ -28,6 +29,7 @@ export const CopilotAction = ({
|
|
|
28
29
|
start,
|
|
29
30
|
history,
|
|
30
31
|
addtocartHandler,
|
|
32
|
+
commonRender,
|
|
31
33
|
gotocheckoutRender,
|
|
32
34
|
gotocartRender,
|
|
33
35
|
addtocartRender,
|
|
@@ -68,6 +70,16 @@ export const CopilotAction = ({
|
|
|
68
70
|
},
|
|
69
71
|
})
|
|
70
72
|
|
|
73
|
+
useCopilotAction({
|
|
74
|
+
name: 'common_action',
|
|
75
|
+
description: 'common action',
|
|
76
|
+
parameters: [{ act: '' }] as any,
|
|
77
|
+
render: commonRender || (props => <div className="hidden">{JSON.stringify(props)}</div>),
|
|
78
|
+
handler: function () {
|
|
79
|
+
// console.log('common_action', props)
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
|
|
71
83
|
useCopilotAction({
|
|
72
84
|
name: 'go_to_cart',
|
|
73
85
|
description: 'go to cart',
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Icons for CopilotChat component.
|
|
5
|
+
*/
|
|
6
|
+
export interface CopilotChatIcons {
|
|
7
|
+
/**
|
|
8
|
+
* The icon to use for the open chat button.
|
|
9
|
+
* @default <OpenIcon />
|
|
10
|
+
*/
|
|
11
|
+
openIcon?: React.ReactNode
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The icon to use for the close chat button.
|
|
15
|
+
* @default <CloseIcon />
|
|
16
|
+
*/
|
|
17
|
+
closeIcon?: React.ReactNode
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The icon to use for the close chat button in the header.
|
|
21
|
+
* @default <HeaderCloseIcon />
|
|
22
|
+
*/
|
|
23
|
+
headerCloseIcon?: React.ReactNode
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The icon to use for the send button.
|
|
27
|
+
* @default <SendIcon />
|
|
28
|
+
*/
|
|
29
|
+
sendIcon?: React.ReactNode
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The icon to use for the activity indicator.
|
|
33
|
+
* @default <ActivityIcon />
|
|
34
|
+
*/
|
|
35
|
+
activityIcon?: React.ReactNode
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The icon to use for the spinner.
|
|
39
|
+
* @default <SpinnerIcon />
|
|
40
|
+
*/
|
|
41
|
+
spinnerIcon?: React.ReactNode
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The icon to use for the stop button.
|
|
45
|
+
* @default <StopIcon />
|
|
46
|
+
*/
|
|
47
|
+
stopIcon?: React.ReactNode
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The icon to use for the regenerate button.
|
|
51
|
+
* @default <RegenerateIcon />
|
|
52
|
+
*/
|
|
53
|
+
regenerateIcon?: React.ReactNode
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The icons to use for push to talk.
|
|
57
|
+
* @default <PushToTalkIcon />
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
pushToTalkIcon?: React.ReactNode
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Labels for CopilotChat component.
|
|
65
|
+
*/
|
|
66
|
+
export interface CopilotChatLabels {
|
|
67
|
+
/**
|
|
68
|
+
* The initial message(s) to display in the chat window.
|
|
69
|
+
*/
|
|
70
|
+
initial?: string | string[]
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The title to display in the header.
|
|
74
|
+
* @default "CopilotKit"
|
|
75
|
+
*/
|
|
76
|
+
title?: string
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The placeholder to display in the input.
|
|
80
|
+
* @default "Type a message..."
|
|
81
|
+
*/
|
|
82
|
+
placeholder?: string
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The message to display when an error occurs.
|
|
86
|
+
* @default "❌ An error occurred. Please try again."
|
|
87
|
+
*/
|
|
88
|
+
error?: string
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The label to display on the stop button.
|
|
92
|
+
* @default "Stop generating"
|
|
93
|
+
*/
|
|
94
|
+
stopGenerating?: string
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The label to display on the regenerate button.
|
|
98
|
+
* @default "Regenerate response"
|
|
99
|
+
*/
|
|
100
|
+
regenerateResponse?: string
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
interface ChatContext {
|
|
104
|
+
labels: Required<CopilotChatLabels>
|
|
105
|
+
icons: Required<CopilotChatIcons>
|
|
106
|
+
open: boolean
|
|
107
|
+
setOpen: (_open: boolean) => void
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const ChatContext = React.createContext<ChatContext | undefined>(undefined)
|
|
111
|
+
|
|
112
|
+
export function useChatContext(): ChatContext {
|
|
113
|
+
const context = React.useContext(ChatContext)
|
|
114
|
+
if (context === undefined) {
|
|
115
|
+
throw new Error('Context not found. Did you forget to wrap your app in a <ChatContextProvider> component?')
|
|
116
|
+
}
|
|
117
|
+
return context
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface ChatContextProps {
|
|
121
|
+
// temperature?: number;
|
|
122
|
+
// instructions?: string;
|
|
123
|
+
// maxFeedback?: number;
|
|
124
|
+
labels?: CopilotChatLabels
|
|
125
|
+
icons?: CopilotChatIcons
|
|
126
|
+
children?: React.ReactNode
|
|
127
|
+
open: boolean
|
|
128
|
+
setOpen: (_open: boolean) => void
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// export const ChatContextProvider = ({
|
|
132
|
+
// // temperature,
|
|
133
|
+
// // instructions,
|
|
134
|
+
// // maxFeedback,
|
|
135
|
+
// labels,
|
|
136
|
+
// icons,
|
|
137
|
+
// children,
|
|
138
|
+
// open,
|
|
139
|
+
// setOpen,
|
|
140
|
+
// }: ChatContextProps) => {
|
|
141
|
+
// const context = {
|
|
142
|
+
// labels: {
|
|
143
|
+
// ...{
|
|
144
|
+
// initial: "",
|
|
145
|
+
// title: "CopilotKit",
|
|
146
|
+
// placeholder: "Type a message...",
|
|
147
|
+
// error: "❌ An error occurred. Please try again.",
|
|
148
|
+
// stopGenerating: "Stop generating",
|
|
149
|
+
// regenerateResponse: "Regenerate response",
|
|
150
|
+
// },
|
|
151
|
+
// ...labels,
|
|
152
|
+
// },
|
|
153
|
+
|
|
154
|
+
// icons: {
|
|
155
|
+
// ...icons,
|
|
156
|
+
// },
|
|
157
|
+
// open,
|
|
158
|
+
// setOpen,
|
|
159
|
+
// };
|
|
160
|
+
// return <ChatContext.Provider value={context}>{children}</ChatContext.Provider>;
|
|
161
|
+
// };
|
|
@@ -37,6 +37,9 @@ export interface ChatProps {
|
|
|
37
37
|
/** 跳转 checkout action 卡片,接受参数: {"status":"complete","args":[{"sku":["A3936031"],"handle":"space-a40-a3936031"}],"result":""}
|
|
38
38
|
* 后端接口文档:https://anker-in.feishu.cn/wiki/DOYJwE9oxipWmYk072ncnJNznBb
|
|
39
39
|
*/
|
|
40
|
+
commonRender?: string | ((_props: any) => React.ReactElement)
|
|
41
|
+
/** 通用 action 的触发事件
|
|
42
|
+
*/
|
|
40
43
|
gotocheckoutRender?: string | ((_props: any) => React.ReactElement)
|
|
41
44
|
/** 打开购物车 action 卡片,接受参数: {"status":"complete","args":[{"sku":["A3936031"],"handle":"space-a40-a3936031"}],"result":""}
|
|
42
45
|
* 后端接口文档:https://anker-in.feishu.cn/wiki/DOYJwE9oxipWmYk072ncnJNznBb
|
|
@@ -79,6 +82,7 @@ const Chat = (props: ChatProps) => {
|
|
|
79
82
|
query = '',
|
|
80
83
|
showResponseButton,
|
|
81
84
|
gotocheckoutRender,
|
|
85
|
+
commonRender,
|
|
82
86
|
gotocartRender,
|
|
83
87
|
addtocartRender,
|
|
84
88
|
productRender,
|
|
@@ -203,6 +207,7 @@ const Chat = (props: ChatProps) => {
|
|
|
203
207
|
<CopilotAction
|
|
204
208
|
start={start}
|
|
205
209
|
history={history}
|
|
210
|
+
commonRender={commonRender}
|
|
206
211
|
gotocartRender={gotocartRender}
|
|
207
212
|
gotocheckoutRender={gotocheckoutRender}
|
|
208
213
|
addtocartRender={addtocartRender}
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
# Contributing
|
|
2
|
-
|
|
3
|
-
# 关于
|
|
4
|
-
|
|
5
|
-
这是一个基于@radix-ui/primitive 二次封装的组件库,目标是通过 css 变量的形式,实现多主题,以达到同时支持多品牌站点开发的能力。
|
|
6
|
-
|
|
7
|
-
# 代码文件结构
|
|
8
|
-
|
|
9
|
-
```shell
|
|
10
|
-
apps
|
|
11
|
-
├── playground
|
|
12
|
-
packages
|
|
13
|
-
├── storybook
|
|
14
|
-
│ └── public
|
|
15
|
-
└── ui
|
|
16
|
-
└── src
|
|
17
|
-
├── components
|
|
18
|
-
├── helpers
|
|
19
|
-
├── icons
|
|
20
|
-
├── props
|
|
21
|
-
├── stories
|
|
22
|
-
└── styles
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
| 路径 | 描述 |
|
|
27
|
-
| -------------------------- | ------------------------- |
|
|
28
|
-
| apps/playground | playground,一个nextjs项目 |
|
|
29
|
-
| packages/storybook | storybook 配置 |
|
|
30
|
-
| packages/ui | 组件根目录 |
|
|
31
|
-
| packages/ui/src/components | 所有的组件都在这个目录 |
|
|
32
|
-
| packages/ui/src/stories | 组件对应的storybook 文件 |
|
|
33
|
-
| packages/ui/src/styles | 样式文件 |
|
|
34
|
-
|
|
35
|
-
# 如何运行
|
|
36
|
-
|
|
37
|
-
本地开发
|
|
38
|
-
|
|
39
|
-
先clone 代码到本地
|
|
40
|
-
|
|
41
|
-
```shell
|
|
42
|
-
git clone
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
安装依赖
|
|
46
|
-
|
|
47
|
-
```shell
|
|
48
|
-
pnpm install
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
ui 添加新的依赖
|
|
52
|
-
|
|
53
|
-
```shell
|
|
54
|
-
pnpm add {packages} --filter @anker-in/headless-ui
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
进入根目录
|
|
58
|
-
|
|
59
|
-
````
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
本地启动
|
|
63
|
-
|
|
64
|
-
```shell
|
|
65
|
-
pnpm run dev
|
|
66
|
-
````
|
|
67
|
-
|
|
68
|
-
这会运行storybook和playground,可以一边修改组件源码,一边查看效果。
|
|
69
|
-
|
|
70
|
-
# 如何新增组件
|
|
71
|
-
|
|
72
|
-
新增组件之前先看下仓库有没有类似的组件已经存在。
|
|
73
|
-
如果不存在,需要新增组件,
|
|
74
|
-
|
|
75
|
-
**建议新组件基于 [@radix-ui/primitive](https://www.radix-ui.com/primitives) 或者手动复制[shadcn](https://ui.shadcn.com/) 的组件 进行二次封装。**
|
|
76
|
-
|
|
77
|
-
组件目录位于`packages/ui/src`。
|
|
78
|
-
|
|
79
|
-
运行`pnpm run dev` 之后,会运行storybook 和 playground 项目,在storybook 中测试组件的功能,编写文档。
|
|
80
|
-
在playground 中可以添加组件的展示,测试组件在nextjs 项目中的使用。
|
|
81
|
-
|
|
82
|
-
组件需要覆盖全品牌,如果新增css 变量,需要在`packages/ui/src/styles/global.css` 补充在各个品牌的作用域之下。
|
|
83
|
-
如果某个品牌没有添加,会默认使用root 下的定义作为fallback。
|
|
84
|
-
|
|
85
|
-
比如新的组件`Card`
|
|
86
|
-
需要新加一个Card 的背景颜色
|
|
87
|
-
|
|
88
|
-
```css
|
|
89
|
-
--card-bg-color: #fefefe;
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
请在不同的品牌的作用域下添加
|
|
93
|
-
比如
|
|
94
|
-
|
|
95
|
-
```css
|
|
96
|
-
:root[data-theme='anker'] {
|
|
97
|
-
--card-bg-color: #fefefe;
|
|
98
|
-
}
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
原理
|
|
102
|
-
|
|
103
|
-
<img src="./css-explain.png" width="500" height="500"/>
|
|
104
|
-
|
|
105
|
-
⚠️注意
|
|
106
|
-
组件编写后请按照checklist 进行检查
|
|
107
|
-
|
|
108
|
-
## checklist
|
|
109
|
-
|
|
110
|
-
- [ ] 已经为组件编写了storybook API文档
|
|
111
|
-
- [ ] 组件在storybook accessibility 通过测试
|
|
112
|
-
- [ ] 完成组件的单元测试
|
|
113
|
-
- [ ] 组件在不同品牌下的样式正常显示
|
|
114
|
-
- [ ] 组件在不同设备,分辨率下显示正常
|
|
115
|
-
- [ ] 组件不包含业务代码,包括文案,接口等
|
|
116
|
-
|
|
117
|
-
# 如何提交代码
|
|
118
|
-
|
|
119
|
-
git flow 和code review
|
|
120
|
-
|
|
121
|
-
1. 主分支 (main):存储正式发布的历史。
|
|
122
|
-
2. 开发分支 (develop):集成各种功能的分支。
|
|
123
|
-
3. 功能分支 (feature/x):从develop分支出来,用于新功能的开发。
|
|
124
|
-
4. 修补分支 (hotfix/x):从main分支出来,用于快速修补生产环境的问题。
|
|
125
|
-
|
|
126
|
-
# 代码规范
|
|
127
|
-
|
|
128
|
-
请遵循 eslint 的配置编写代码。
|
|
129
|
-
|
|
130
|
-
提交代码前运行lint
|
|
131
|
-
|
|
132
|
-
```shell
|
|
133
|
-
pnpm lint
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
如果遇到eslint 报错,但是坚持自己的写法的,可以通过注释的方式,阻止eslint 校验, 并且要写明阻止的规则
|
|
137
|
-
比如
|
|
138
|
-
|
|
139
|
-
```js
|
|
140
|
-
// eslint-disable-next-line no-alert
|
|
141
|
-
alert('Example of disabled line for no-alert')
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
如果希望修改eslint 规则,修改根目录下的`.eslintrc.json`
|
|
145
|
-
|
|
146
|
-
❗ 在ui/目录下的代码导入的时候,要带上.js后缀,比如 import { cn } from '../helpers/index.js' 否则在使用的时候会出现 ERR_UNSUPPORTED_DIR_IMPORT 问题
|
|
147
|
-
|
|
148
|
-
# Tesing
|
|
149
|
-
|
|
150
|
-
unit test 使用 [jest](https://jestjs.io/) 和 [@test-library/react](https://testing-library.com/)。
|
|
151
|
-
|
|
152
|
-
运行单元测试
|
|
153
|
-
|
|
154
|
-
```shell
|
|
155
|
-
pnpm test
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
# publish
|
|
159
|
-
|
|
160
|
-
先从 master 分支checkout 出新的分支。
|
|
161
|
-
|
|
162
|
-
在新的分支执行
|
|
163
|
-
|
|
164
|
-
`pnpm changeset add `
|
|
165
|
-
空格选择要发布的包 @anker-in/headless-ui
|
|
166
|
-
回车
|
|
167
|
-
|
|
168
|
-
会依次出现要增加的语意版本号
|
|
169
|
-
`{major -> minor -> patch}`
|
|
170
|
-
这里如果只增加patch 可以一路回车。
|
|
171
|
-
|
|
172
|
-
然后提交代码,合并到`master`分支。
|
|
173
|
-
|
|
174
|
-
最后到`coding`网站的持续集成找到项目,手动触发ci/cd。
|
|
175
|
-
|