@waline/client 2.12.0 → 2.13.0
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/api.cjs +1 -1
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +12 -1
- package/dist/api.d.mts +12 -1
- package/dist/api.d.ts +12 -1
- package/dist/api.mjs +1 -1
- package/dist/api.mjs.map +1 -1
- package/dist/comment.cjs +1 -1
- package/dist/comment.js +1 -1
- package/dist/comment.mjs +1 -1
- package/dist/component.mjs +1 -1
- package/dist/component.mjs.map +1 -1
- package/dist/legacy.umd.js +1 -1
- package/dist/legacy.umd.js.map +1 -1
- package/dist/pageview.cjs +1 -1
- package/dist/pageview.js +1 -1
- package/dist/pageview.mjs +1 -1
- package/dist/shim.cjs +1 -1
- package/dist/shim.cjs.map +1 -1
- package/dist/shim.d.cts +65 -1
- package/dist/shim.d.mts +65 -1
- package/dist/shim.mjs +1 -1
- package/dist/shim.mjs.map +1 -1
- package/dist/waline.cjs +1 -1
- package/dist/waline.cjs.map +1 -1
- package/dist/waline.css +1 -1
- package/dist/waline.css.map +1 -1
- package/dist/waline.d.cts +65 -1
- package/dist/waline.d.mts +65 -1
- package/dist/waline.d.ts +65 -1
- package/dist/waline.js +1 -1
- package/dist/waline.js.map +1 -1
- package/dist/waline.mjs +1 -1
- package/dist/waline.mjs.map +1 -1
- package/package.json +3 -3
- package/src/api/index.ts +1 -0
- package/src/api/user.ts +35 -0
- package/src/components/CommentBox.vue +1 -1
- package/src/composables/userInfo.ts +1 -2
- package/src/composables/vote.ts +1 -1
- package/src/styles/index.scss +1 -0
- package/src/styles/userlist.scss +116 -0
- package/src/widgets/index.ts +1 -0
- package/src/widgets/userList.ts +138 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waline/client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.0",
|
|
4
4
|
"description": "client for waline comment system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"valine",
|
|
@@ -134,8 +134,8 @@
|
|
|
134
134
|
"@rollup/plugin-replace": "4.0.0",
|
|
135
135
|
"@types/autosize": "4.0.1",
|
|
136
136
|
"@types/marked": "4.0.7",
|
|
137
|
-
"@types/node": "18.
|
|
138
|
-
"@vitejs/plugin-vue": "3.1.
|
|
137
|
+
"@types/node": "18.8.2",
|
|
138
|
+
"@vitejs/plugin-vue": "3.1.2",
|
|
139
139
|
"recaptcha-v3": "1.10.0",
|
|
140
140
|
"rimraf": "3.0.2",
|
|
141
141
|
"rollup": "2.79.1",
|
package/src/api/index.ts
CHANGED
package/src/api/user.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { WalineComment } from '../typings';
|
|
2
|
+
import { errorCheck } from './utils';
|
|
3
|
+
|
|
4
|
+
export interface FetchUserListOptions {
|
|
5
|
+
serverURL: string;
|
|
6
|
+
pageSize: number;
|
|
7
|
+
signal: AbortSignal;
|
|
8
|
+
lang: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface WalineUser
|
|
12
|
+
extends Pick<WalineComment, 'nick' | 'link' | 'avatar' | 'label' | 'level'> {
|
|
13
|
+
count: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const fetchUserList = ({
|
|
17
|
+
serverURL,
|
|
18
|
+
signal,
|
|
19
|
+
pageSize,
|
|
20
|
+
lang,
|
|
21
|
+
}: FetchUserListOptions): Promise<WalineUser[]> => {
|
|
22
|
+
return fetch(`${serverURL}/user?pageSize=${pageSize}&lang=${lang}`, {
|
|
23
|
+
signal,
|
|
24
|
+
})
|
|
25
|
+
.then(
|
|
26
|
+
(resp) =>
|
|
27
|
+
resp.json() as Promise<{
|
|
28
|
+
errno: number;
|
|
29
|
+
message: string;
|
|
30
|
+
data: WalineUser[];
|
|
31
|
+
}>
|
|
32
|
+
)
|
|
33
|
+
.then((resp) => errorCheck(resp, 'user list'))
|
|
34
|
+
.then((resp) => resp.data);
|
|
35
|
+
};
|
|
@@ -10,8 +10,7 @@ export type UserInfoRef = Ref<UserInfo | Record<string, never>>;
|
|
|
10
10
|
let userInfoStorage: UserInfoRef | null = null;
|
|
11
11
|
|
|
12
12
|
export const useUserInfo = (): UserInfoRef =>
|
|
13
|
-
userInfoStorage
|
|
14
|
-
(userInfoStorage = useStorage<UserInfo | Record<string, never>>(
|
|
13
|
+
(userInfoStorage ??= useStorage<UserInfo | Record<string, never>>(
|
|
15
14
|
USER_KEY,
|
|
16
15
|
{}
|
|
17
16
|
));
|
package/src/composables/vote.ts
CHANGED
|
@@ -17,4 +17,4 @@ export type VoteRef = Ref<VoteLogItem[]>;
|
|
|
17
17
|
let voteStorage: VoteRef | null = null;
|
|
18
18
|
|
|
19
19
|
export const useVoteStorage = (): VoteRef =>
|
|
20
|
-
|
|
20
|
+
(voteStorage ??= useStorage<VoteLogItem[]>(VOTE_KEY, []));
|
package/src/styles/index.scss
CHANGED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--waline-rank-gold-bgcolor: #FA3939;
|
|
3
|
+
--waline-rank-silver-bgcolor: #FB811C;
|
|
4
|
+
--waline-rank-copper-bgcolor: #FEB207;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.wl-user-list {
|
|
8
|
+
list-style: none;
|
|
9
|
+
padding: 0;
|
|
10
|
+
|
|
11
|
+
> li + li {
|
|
12
|
+
margin-top: 10px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
> li, > li > a {
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: row;
|
|
18
|
+
gap: 10px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
a,
|
|
22
|
+
a:hover,
|
|
23
|
+
a:visited {
|
|
24
|
+
text-decoration: none;
|
|
25
|
+
color: var(--waline-color);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.wl-user-avatar {
|
|
29
|
+
position: relative;
|
|
30
|
+
line-height: 0;
|
|
31
|
+
|
|
32
|
+
> i {
|
|
33
|
+
position: absolute;
|
|
34
|
+
bottom: 0;
|
|
35
|
+
right: 0;
|
|
36
|
+
min-width: 1.5em;
|
|
37
|
+
height: 1.5em;
|
|
38
|
+
line-height: 1.5em;
|
|
39
|
+
background: var(--waline-info-bgcolor);
|
|
40
|
+
text-align: center;
|
|
41
|
+
font-size: 10px;
|
|
42
|
+
border-radius: 2px;
|
|
43
|
+
font-style: normal;
|
|
44
|
+
color: var(--waline-info-color);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
img {
|
|
49
|
+
width: 48px;
|
|
50
|
+
height: 48px;
|
|
51
|
+
border-radius: 2px;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.wl-user-name {
|
|
55
|
+
display: flex;
|
|
56
|
+
flex-direction: row;
|
|
57
|
+
align-items: center;
|
|
58
|
+
gap: 10px;
|
|
59
|
+
}
|
|
60
|
+
.wl-user-tag {
|
|
61
|
+
padding-bottom: 0;
|
|
62
|
+
border-bottom: none;
|
|
63
|
+
width: auto;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
> li:nth-child(1) i {
|
|
68
|
+
background: var(--waline-rank-gold-bgcolor);
|
|
69
|
+
color: var(--waline-white);
|
|
70
|
+
font-weight: bold;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
> li:nth-child(2) i {
|
|
74
|
+
background: var(--waline-rank-silver-bgcolor);
|
|
75
|
+
color: var(--waline-white);
|
|
76
|
+
font-weight: bold;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
> li:nth-child(3) i {
|
|
80
|
+
background: var(--waline-rank-copper-bgcolor);
|
|
81
|
+
color: var(--waline-white);
|
|
82
|
+
font-weight: bold;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.wl-user-wall {
|
|
87
|
+
display: flex;
|
|
88
|
+
flex-direction: row;
|
|
89
|
+
list-style: none;
|
|
90
|
+
padding: 0;
|
|
91
|
+
|
|
92
|
+
> li {
|
|
93
|
+
width: 48px;
|
|
94
|
+
height: 48px;
|
|
95
|
+
overflow: hidden;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
> li:hover img {
|
|
99
|
+
transform: scale(1.25);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
img {
|
|
103
|
+
width: 48px;
|
|
104
|
+
height: 48px;
|
|
105
|
+
border-radius: 0;
|
|
106
|
+
transition: transform ease-in-out 400ms;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.wl-user-avatar > i,
|
|
110
|
+
.wl-user-meta {
|
|
111
|
+
display: none;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
package/src/widgets/index.ts
CHANGED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { fetchUserList, WalineUser } from '../api';
|
|
2
|
+
import { defaultLang, defaultLocales } from '../config';
|
|
3
|
+
import { WalineLocale } from '../typings';
|
|
4
|
+
import { getRoot } from '../utils';
|
|
5
|
+
|
|
6
|
+
export interface WalineUserListOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Waline 服务端地址
|
|
9
|
+
*
|
|
10
|
+
* Waline serverURL
|
|
11
|
+
*/
|
|
12
|
+
serverURL: string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 获取用户列表的数量
|
|
16
|
+
*
|
|
17
|
+
* fetch number of user list
|
|
18
|
+
*/
|
|
19
|
+
count: number;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 需要挂载的元素
|
|
23
|
+
*
|
|
24
|
+
* Element to be mounted
|
|
25
|
+
*/
|
|
26
|
+
el?: string | HTMLElement;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 错误提示消息所使用的语言
|
|
30
|
+
*
|
|
31
|
+
* Language of error message
|
|
32
|
+
*
|
|
33
|
+
* @default 'zh-CN'
|
|
34
|
+
*/
|
|
35
|
+
lang?: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 自定义 waline 语言显示
|
|
39
|
+
*
|
|
40
|
+
* @see [自定义语言](https://waline.js.org/client/i18n.html)
|
|
41
|
+
*
|
|
42
|
+
* Custom display language in waline
|
|
43
|
+
*
|
|
44
|
+
* @see [I18n](https://waline.js.org/en/client/i18n.html)
|
|
45
|
+
*/
|
|
46
|
+
locale?: WalineLocale;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 列表模式还是头像墙模式
|
|
50
|
+
*
|
|
51
|
+
* list mode or avatar wall mode
|
|
52
|
+
*/
|
|
53
|
+
mode: 'list' | 'wall';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface WalineUserListResult {
|
|
57
|
+
/**
|
|
58
|
+
* 用户数据
|
|
59
|
+
*
|
|
60
|
+
* User Data
|
|
61
|
+
*/
|
|
62
|
+
users: WalineUser[];
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 取消挂载挂件
|
|
66
|
+
*
|
|
67
|
+
* Umount widget
|
|
68
|
+
*/
|
|
69
|
+
destroy: () => void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const UserList = ({
|
|
73
|
+
el,
|
|
74
|
+
serverURL,
|
|
75
|
+
count,
|
|
76
|
+
locale,
|
|
77
|
+
lang = defaultLang,
|
|
78
|
+
mode = 'list',
|
|
79
|
+
}: WalineUserListOptions): Promise<WalineUserListResult> => {
|
|
80
|
+
const root = getRoot(el);
|
|
81
|
+
const controller = new AbortController();
|
|
82
|
+
|
|
83
|
+
return fetchUserList({
|
|
84
|
+
serverURL,
|
|
85
|
+
pageSize: count,
|
|
86
|
+
lang,
|
|
87
|
+
signal: controller.signal,
|
|
88
|
+
}).then((users) => {
|
|
89
|
+
if (!root || !users.length) {
|
|
90
|
+
return {
|
|
91
|
+
users,
|
|
92
|
+
destroy: (): void => controller.abort(),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
locale = {
|
|
97
|
+
...(defaultLocales[lang] || defaultLocales[defaultLang]),
|
|
98
|
+
...(typeof locale === 'object' ? locale : {}),
|
|
99
|
+
} as WalineLocale;
|
|
100
|
+
|
|
101
|
+
root.innerHTML = `<ul class="wl-user-${mode}">${users
|
|
102
|
+
.map((user, index) =>
|
|
103
|
+
[
|
|
104
|
+
'<li class="wl-user-item">',
|
|
105
|
+
user.link && `<a href="${user.link}" target="_blank">`,
|
|
106
|
+
'<div class="wl-user-avatar">',
|
|
107
|
+
`<img src="${user.avatar}" alt="${user.nick}">`,
|
|
108
|
+
`<i>${index + 1}</i>`,
|
|
109
|
+
'</div>',
|
|
110
|
+
'<div class="wl-user-meta">',
|
|
111
|
+
`<div class="wl-user-name"><div>${user.nick}</div>`,
|
|
112
|
+
'<div class="wl-user-tag wl-card">',
|
|
113
|
+
user.level &&
|
|
114
|
+
`<span class="wl-badge">${
|
|
115
|
+
locale ? locale[`level${user.level}`] : `Level ${user.level}`
|
|
116
|
+
}</span>`,
|
|
117
|
+
user.label && `<span class="wl-badge">${user.label}</span>`,
|
|
118
|
+
'</div>',
|
|
119
|
+
'</div>',
|
|
120
|
+
user.link && `<span class="wl-user-meta">${user.link}</span>`,
|
|
121
|
+
'</div>',
|
|
122
|
+
user.link && '</a>',
|
|
123
|
+
'</li>',
|
|
124
|
+
]
|
|
125
|
+
.filter((v) => v)
|
|
126
|
+
.join('')
|
|
127
|
+
)
|
|
128
|
+
.join('')}</ul>`;
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
users,
|
|
132
|
+
destroy: (): void => {
|
|
133
|
+
controller.abort();
|
|
134
|
+
root.innerHTML = '';
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
};
|