@waline/client 2.13.1 → 2.14.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 +60 -34
- package/dist/api.d.mts +60 -34
- package/dist/api.d.ts +60 -34
- package/dist/api.mjs +1 -1
- package/dist/api.mjs.map +1 -1
- package/dist/comment.cjs +1 -1
- package/dist/comment.cjs.map +1 -1
- package/dist/comment.d.cts +1 -1
- package/dist/comment.d.mts +1 -1
- package/dist/comment.d.ts +1 -1
- package/dist/comment.js +40 -45
- package/dist/comment.js.map +1 -1
- package/dist/comment.mjs +1 -1
- package/dist/comment.mjs.map +1 -1
- package/dist/component.mjs +1 -1
- package/dist/component.mjs.map +1 -1
- package/dist/legacy.umd.d.ts +13 -3
- package/dist/legacy.umd.js +1 -1
- package/dist/legacy.umd.js.map +1 -1
- package/dist/pageview.cjs +1 -1
- package/dist/pageview.cjs.map +1 -1
- package/dist/pageview.js +44 -49
- package/dist/pageview.js.map +1 -1
- package/dist/pageview.mjs +1 -1
- package/dist/pageview.mjs.map +1 -1
- package/dist/shim.cjs +1 -1
- package/dist/shim.cjs.map +1 -1
- package/dist/shim.d.cts +15 -9
- package/dist/shim.d.mts +15 -9
- 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 +15 -9
- package/dist/waline.d.mts +15 -9
- package/dist/waline.d.ts +15 -9
- package/dist/waline.js +441 -449
- package/dist/waline.js.map +1 -1
- package/dist/waline.mjs +1 -1
- package/dist/waline.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/articleCounter.ts +3 -7
- package/src/api/comment.ts +60 -49
- package/src/api/commentCount.ts +0 -2
- package/src/api/pageview.ts +2 -2
- package/src/api/recentComment.ts +2 -5
- package/src/api/user.ts +2 -4
- package/src/api/utils.ts +17 -10
- package/src/comment.ts +1 -1
- package/src/compact/convert.ts +1 -1
- package/src/components/CommentBox.vue +14 -11
- package/src/components/Waline.vue +35 -34
- package/src/pageview.ts +3 -3
- package/src/styles/index.scss +2 -2
- package/src/styles/{nomalize.scss → normalize.scss} +0 -0
- package/src/styles/panel.scss +1 -1
- package/src/styles/{userlist.scss → user-list.scss} +0 -0
- package/src/typings/base.ts +5 -1
- package/src/typings/comment.ts +1 -5
- package/src/typings/waline.ts +13 -2
- package/src/utils/config.ts +2 -0
- package/src/utils/date.ts +3 -3
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSON_HEADERS
|
|
1
|
+
import { JSON_HEADERS } from './utils';
|
|
2
2
|
import type { BaseAPIOptions } from './utils';
|
|
3
3
|
|
|
4
4
|
export interface GetArticleCounterOptions extends BaseAPIOptions {
|
|
@@ -42,9 +42,7 @@ export const getArticleCounter = ({
|
|
|
42
42
|
paths.join(',')
|
|
43
43
|
)}&type=${encodeURIComponent(type.join(','))}&lang=${lang}`,
|
|
44
44
|
{ signal }
|
|
45
|
-
)
|
|
46
|
-
.then((resp) => <Promise<GetArticleCounterResponse>>resp.json())
|
|
47
|
-
.then((data) => errorCheck(data, 'article count'));
|
|
45
|
+
).then((resp) => <Promise<GetArticleCounterResponse>>resp.json());
|
|
48
46
|
|
|
49
47
|
export interface UpdateArticleCounterOptions extends BaseAPIOptions {
|
|
50
48
|
/**
|
|
@@ -82,6 +80,4 @@ export const updateArticleCounter = ({
|
|
|
82
80
|
method: 'POST',
|
|
83
81
|
headers: JSON_HEADERS,
|
|
84
82
|
body: JSON.stringify({ path, type, action }),
|
|
85
|
-
})
|
|
86
|
-
.then((resp) => <Promise<number>>resp.json())
|
|
87
|
-
.then((data) => errorCheck(data, 'article count'));
|
|
83
|
+
}).then((resp) => <Promise<number>>resp.json());
|
package/src/api/comment.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { JSON_HEADERS, errorCheck } from './utils';
|
|
2
|
-
import type { BaseAPIOptions } from './utils';
|
|
2
|
+
import type { BaseAPIOptions, ErrorStatusResponse } from './utils';
|
|
3
3
|
import type { WalineComment, WalineCommentData } from '../typings';
|
|
4
4
|
|
|
5
5
|
export interface GetCommentOptions extends BaseAPIOptions {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* 待获取评论列表的 path
|
|
8
8
|
*
|
|
9
9
|
* Path of comment list
|
|
10
10
|
*/
|
|
@@ -13,12 +13,12 @@ export interface GetCommentOptions extends BaseAPIOptions {
|
|
|
13
13
|
/**
|
|
14
14
|
* 评论分页数
|
|
15
15
|
*
|
|
16
|
-
* Comment
|
|
16
|
+
* Comment pagination number
|
|
17
17
|
*/
|
|
18
18
|
page: number;
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* 每页评论个数
|
|
22
22
|
*
|
|
23
23
|
* Comment number per page
|
|
24
24
|
*/
|
|
@@ -46,7 +46,7 @@ export interface GetCommentOptions extends BaseAPIOptions {
|
|
|
46
46
|
signal?: AbortSignal;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export interface GetCommentResponse {
|
|
49
|
+
export interface GetCommentResponse extends ErrorStatusResponse {
|
|
50
50
|
/**
|
|
51
51
|
* 评论数量
|
|
52
52
|
*
|
|
@@ -54,6 +54,20 @@ export interface GetCommentResponse {
|
|
|
54
54
|
*/
|
|
55
55
|
count: number;
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* 评论分页数
|
|
59
|
+
*
|
|
60
|
+
* Comment pagination number
|
|
61
|
+
*/
|
|
62
|
+
page: number;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 每页评论个数
|
|
66
|
+
*
|
|
67
|
+
* Comment number per page
|
|
68
|
+
*/
|
|
69
|
+
pageSize: number;
|
|
70
|
+
|
|
57
71
|
/**
|
|
58
72
|
* 评论数据
|
|
59
73
|
*
|
|
@@ -90,7 +104,7 @@ export const getComment = ({
|
|
|
90
104
|
{ signal, headers }
|
|
91
105
|
)
|
|
92
106
|
.then((resp) => <Promise<GetCommentResponse>>resp.json())
|
|
93
|
-
.then((data) => errorCheck(data, 'comment data'));
|
|
107
|
+
.then((data) => errorCheck(data, 'Get comment data'));
|
|
94
108
|
};
|
|
95
109
|
|
|
96
110
|
export interface AddCommentOptions extends BaseAPIOptions {
|
|
@@ -109,16 +123,13 @@ export interface AddCommentOptions extends BaseAPIOptions {
|
|
|
109
123
|
comment: WalineCommentData;
|
|
110
124
|
}
|
|
111
125
|
|
|
112
|
-
export interface AddCommentResponse {
|
|
126
|
+
export interface AddCommentResponse extends ErrorStatusResponse {
|
|
113
127
|
/**
|
|
114
128
|
* 渲染好的评论数据
|
|
115
129
|
*
|
|
116
130
|
* Comment data rendered
|
|
117
131
|
*/
|
|
118
132
|
data?: WalineComment;
|
|
119
|
-
|
|
120
|
-
/** 错误原因 */
|
|
121
|
-
errmsg?: string;
|
|
122
133
|
}
|
|
123
134
|
|
|
124
135
|
export const addComment = ({
|
|
@@ -134,14 +145,11 @@ export const addComment = ({
|
|
|
134
145
|
|
|
135
146
|
if (token) headers.Authorization = `Bearer ${token}`;
|
|
136
147
|
|
|
137
|
-
return fetch(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
body: JSON.stringify(comment),
|
|
143
|
-
}
|
|
144
|
-
).then((resp) => <Promise<AddCommentResponse>>resp.json());
|
|
148
|
+
return fetch(`${serverURL}/comment?lang=${lang}`, {
|
|
149
|
+
method: 'POST',
|
|
150
|
+
headers,
|
|
151
|
+
body: JSON.stringify(comment),
|
|
152
|
+
}).then((resp) => <Promise<AddCommentResponse>>resp.json());
|
|
145
153
|
};
|
|
146
154
|
|
|
147
155
|
export interface DeleteCommentOptions extends BaseAPIOptions {
|
|
@@ -149,61 +157,53 @@ export interface DeleteCommentOptions extends BaseAPIOptions {
|
|
|
149
157
|
objectId: string | number;
|
|
150
158
|
}
|
|
151
159
|
|
|
160
|
+
export interface DeleteCommentResponse extends ErrorStatusResponse {
|
|
161
|
+
data: '';
|
|
162
|
+
}
|
|
163
|
+
|
|
152
164
|
export const deleteComment = ({
|
|
153
165
|
serverURL,
|
|
154
166
|
lang,
|
|
155
167
|
token,
|
|
156
168
|
objectId,
|
|
157
|
-
}: DeleteCommentOptions): Promise<
|
|
169
|
+
}: DeleteCommentOptions): Promise<DeleteCommentResponse> =>
|
|
158
170
|
fetch(`${serverURL}/comment/${objectId}?lang=${lang}`, {
|
|
159
171
|
method: 'DELETE',
|
|
160
172
|
headers: {
|
|
161
173
|
Authorization: `Bearer ${token}`,
|
|
162
174
|
},
|
|
163
|
-
})
|
|
175
|
+
})
|
|
176
|
+
.then((resp) => <Promise<DeleteCommentResponse>>resp.json())
|
|
177
|
+
.then((resp) => errorCheck(resp, 'Delete comment'));
|
|
164
178
|
|
|
165
|
-
export interface
|
|
179
|
+
export interface UpdateCommentOptions extends BaseAPIOptions {
|
|
166
180
|
/**
|
|
167
|
-
*
|
|
181
|
+
* 用户令牌
|
|
168
182
|
*
|
|
169
|
-
*
|
|
183
|
+
* User token
|
|
170
184
|
*/
|
|
171
|
-
|
|
185
|
+
token: string;
|
|
172
186
|
|
|
173
187
|
/**
|
|
174
|
-
*
|
|
188
|
+
* 评论的 ID
|
|
175
189
|
*
|
|
176
|
-
*
|
|
190
|
+
* Comment ID
|
|
177
191
|
*/
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export const likeComment = ({
|
|
182
|
-
serverURL,
|
|
183
|
-
lang,
|
|
184
|
-
objectId,
|
|
185
|
-
like,
|
|
186
|
-
}: LikeCommentOptions): Promise<void> =>
|
|
187
|
-
fetch(`${serverURL}/comment/${objectId}?lang=${lang}`, {
|
|
188
|
-
method: 'PUT',
|
|
189
|
-
headers: JSON_HEADERS,
|
|
190
|
-
body: JSON.stringify({ like }),
|
|
191
|
-
}).then((resp) => <Promise<void>>resp.json());
|
|
192
|
+
objectId: number | string;
|
|
192
193
|
|
|
193
|
-
export interface UpdateCommentOptions extends BaseAPIOptions {
|
|
194
194
|
/**
|
|
195
|
-
*
|
|
195
|
+
* 评论数据
|
|
196
196
|
*
|
|
197
|
-
*
|
|
197
|
+
* Comment data
|
|
198
198
|
*/
|
|
199
|
-
|
|
199
|
+
comment?: WalineCommentData;
|
|
200
200
|
|
|
201
201
|
/**
|
|
202
|
-
*
|
|
202
|
+
* 点赞还是取消点赞
|
|
203
203
|
*
|
|
204
|
-
*
|
|
204
|
+
* Like or dislike
|
|
205
205
|
*/
|
|
206
|
-
|
|
206
|
+
like?: boolean;
|
|
207
207
|
|
|
208
208
|
/**
|
|
209
209
|
* 评论的状态
|
|
@@ -222,13 +222,22 @@ export interface UpdateCommentOptions extends BaseAPIOptions {
|
|
|
222
222
|
sticky?: 0 | 1;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
+
export interface UpdateCommentResponse extends ErrorStatusResponse {
|
|
226
|
+
/**
|
|
227
|
+
* 更新后的评论数据
|
|
228
|
+
*
|
|
229
|
+
* Comment data rendered
|
|
230
|
+
*/
|
|
231
|
+
data: WalineComment;
|
|
232
|
+
}
|
|
233
|
+
|
|
225
234
|
export const updateComment = ({
|
|
226
235
|
serverURL,
|
|
227
236
|
lang,
|
|
228
237
|
token,
|
|
229
238
|
objectId,
|
|
230
239
|
...data
|
|
231
|
-
}: UpdateCommentOptions): Promise<
|
|
240
|
+
}: UpdateCommentOptions): Promise<UpdateCommentResponse> =>
|
|
232
241
|
fetch(`${serverURL}/comment/${objectId}?lang=${lang}`, {
|
|
233
242
|
method: 'PUT',
|
|
234
243
|
headers: {
|
|
@@ -236,4 +245,6 @@ export const updateComment = ({
|
|
|
236
245
|
Authorization: `Bearer ${token}`,
|
|
237
246
|
},
|
|
238
247
|
body: JSON.stringify(data),
|
|
239
|
-
})
|
|
248
|
+
})
|
|
249
|
+
.then((resp) => <Promise<UpdateCommentResponse>>resp.json())
|
|
250
|
+
.then((resp) => errorCheck(resp, 'Update comment'));
|
package/src/api/commentCount.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { errorCheck } from './utils';
|
|
2
1
|
import type { BaseAPIOptions } from './utils';
|
|
3
2
|
|
|
4
3
|
export interface GetCommentCountOptions extends BaseAPIOptions {
|
|
@@ -30,6 +29,5 @@ export const fetchCommentCount = ({
|
|
|
30
29
|
{ signal }
|
|
31
30
|
)
|
|
32
31
|
.then((resp) => <Promise<number | number[]>>resp.json())
|
|
33
|
-
.then((data) => errorCheck(data, 'comment count'))
|
|
34
32
|
// TODO: Improve this API
|
|
35
33
|
.then((counts) => (Array.isArray(counts) ? counts : [counts]));
|
package/src/api/pageview.ts
CHANGED
|
@@ -17,7 +17,7 @@ interface GetPageviewOptions extends BaseAPIOptions {
|
|
|
17
17
|
signal?: AbortSignal;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export const
|
|
20
|
+
export const getPageview = ({
|
|
21
21
|
serverURL,
|
|
22
22
|
lang,
|
|
23
23
|
paths,
|
|
@@ -44,7 +44,7 @@ export interface UpdatePageviewOptions extends BaseAPIOptions {
|
|
|
44
44
|
path: string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
export const
|
|
47
|
+
export const updatePageview = (
|
|
48
48
|
options: UpdatePageviewOptions
|
|
49
49
|
): Promise<number> =>
|
|
50
50
|
updateArticleCounter({
|
package/src/api/recentComment.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { errorCheck } from './utils';
|
|
2
1
|
import type { BaseAPIOptions } from './utils';
|
|
3
2
|
import type { WalineComment } from '../typings';
|
|
4
3
|
|
|
@@ -6,7 +5,7 @@ export interface GetRecentCommentOptions extends BaseAPIOptions {
|
|
|
6
5
|
/**
|
|
7
6
|
* 获取评论的数量
|
|
8
7
|
*
|
|
9
|
-
* Comment
|
|
8
|
+
* Comment number to be fetched
|
|
10
9
|
*/
|
|
11
10
|
count: number;
|
|
12
11
|
|
|
@@ -39,7 +38,5 @@ export const getRecentComment = ({
|
|
|
39
38
|
return fetch(`${serverURL}/comment?type=recent&count=${count}&lang=${lang}`, {
|
|
40
39
|
signal,
|
|
41
40
|
headers,
|
|
42
|
-
})
|
|
43
|
-
.then((resp) => <Promise<WalineComment[]>>resp.json())
|
|
44
|
-
.then((data) => errorCheck(data, 'recent comment'));
|
|
41
|
+
}).then((resp) => <Promise<WalineComment[]>>resp.json());
|
|
45
42
|
};
|
package/src/api/user.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { errorCheck } from './utils';
|
|
1
|
+
import { errorCheck, ErrorStatusResponse } from './utils';
|
|
2
2
|
import type { BaseAPIOptions } from './utils';
|
|
3
3
|
import type { WalineComment } from '../typings';
|
|
4
4
|
|
|
@@ -23,9 +23,7 @@ export interface WalineUser
|
|
|
23
23
|
count: number;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export interface GetUserListResponse {
|
|
27
|
-
errno: number;
|
|
28
|
-
message: string;
|
|
26
|
+
export interface GetUserListResponse extends ErrorStatusResponse {
|
|
29
27
|
data: WalineUser[];
|
|
30
28
|
}
|
|
31
29
|
|
package/src/api/utils.ts
CHANGED
|
@@ -14,8 +14,19 @@ export interface BaseAPIOptions {
|
|
|
14
14
|
lang: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export interface
|
|
17
|
+
export interface ErrorStatusResponse {
|
|
18
|
+
/**
|
|
19
|
+
* 错误代码
|
|
20
|
+
*
|
|
21
|
+
* Error number
|
|
22
|
+
*/
|
|
18
23
|
errno: number;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 错误消息
|
|
27
|
+
*
|
|
28
|
+
* Error msg
|
|
29
|
+
*/
|
|
19
30
|
errmsg: string;
|
|
20
31
|
}
|
|
21
32
|
|
|
@@ -24,16 +35,12 @@ export const JSON_HEADERS: Record<string, string> = {
|
|
|
24
35
|
'Content-Type': 'application/json',
|
|
25
36
|
};
|
|
26
37
|
|
|
27
|
-
export const errorCheck = <T
|
|
28
|
-
data: T
|
|
38
|
+
export const errorCheck = <T extends ErrorStatusResponse>(
|
|
39
|
+
data: T,
|
|
29
40
|
name = ''
|
|
30
41
|
): T => {
|
|
31
|
-
if (typeof data === 'object' &&
|
|
32
|
-
throw new TypeError(
|
|
33
|
-
`Fetch ${name} failed with ${(data as APIErrorResponse).errno}: ${
|
|
34
|
-
(data as APIErrorResponse).errmsg
|
|
35
|
-
}`
|
|
36
|
-
);
|
|
42
|
+
if (typeof data === 'object' && data.errno)
|
|
43
|
+
throw new TypeError(`${name} failed with ${data.errno}: ${data.errmsg}`);
|
|
37
44
|
|
|
38
|
-
return data
|
|
45
|
+
return data;
|
|
39
46
|
};
|
package/src/comment.ts
CHANGED
package/src/compact/convert.ts
CHANGED
|
@@ -44,7 +44,7 @@ export const covertOptions = (
|
|
|
44
44
|
...more
|
|
45
45
|
} = options;
|
|
46
46
|
|
|
47
|
-
// error with those which can no
|
|
47
|
+
// error with those which can no longer be handled
|
|
48
48
|
DROPPED_OPTIONS_WHICH_CAN_NOT_BE_POLYFILLED.filter((item) =>
|
|
49
49
|
Object.keys(options).includes(item)
|
|
50
50
|
).forEach((item) =>
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
v-show="emoji.tabs.length"
|
|
95
95
|
ref="emojiButtonRef"
|
|
96
96
|
class="wl-action"
|
|
97
|
-
:class="{
|
|
97
|
+
:class="{ active: showEmoji }"
|
|
98
98
|
:title="locale.emoji"
|
|
99
99
|
@click="showEmoji = !showEmoji"
|
|
100
100
|
>
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
v-if="config.search"
|
|
106
106
|
ref="gifButtonRef"
|
|
107
107
|
class="wl-action"
|
|
108
|
-
:class="{
|
|
108
|
+
:class="{ active: showGif }"
|
|
109
109
|
:title="locale.gif"
|
|
110
110
|
@click="showGif = !showGif"
|
|
111
111
|
>
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
|
|
133
133
|
<button
|
|
134
134
|
class="wl-action"
|
|
135
|
-
:class="{
|
|
135
|
+
:class="{ active: showPreview }"
|
|
136
136
|
:title="locale.preview"
|
|
137
137
|
@click="showPreview = !showPreview"
|
|
138
138
|
>
|
|
@@ -287,7 +287,7 @@ import {
|
|
|
287
287
|
GifIcon,
|
|
288
288
|
} from './Icons';
|
|
289
289
|
import ImageWall from './ImageWall.vue';
|
|
290
|
-
import { addComment, login } from '../api';
|
|
290
|
+
import { addComment, login, updateComment } from '../api';
|
|
291
291
|
import { useEditor, useUserMeta, useUserInfo } from '../composables';
|
|
292
292
|
import {
|
|
293
293
|
getEmojis,
|
|
@@ -526,18 +526,21 @@ export default defineComponent({
|
|
|
526
526
|
comment.pid = props.replyId;
|
|
527
527
|
comment.rid = props.rootId;
|
|
528
528
|
comment.at = props.replyUser;
|
|
529
|
-
} else if (props.edit) {
|
|
530
|
-
comment.eid = props.edit.objectId;
|
|
531
529
|
}
|
|
532
530
|
|
|
533
531
|
isSubmitting.value = true;
|
|
534
532
|
|
|
535
|
-
|
|
533
|
+
const options = {
|
|
536
534
|
serverURL,
|
|
537
535
|
lang,
|
|
538
536
|
token: userInfo.value?.token,
|
|
539
537
|
comment,
|
|
540
|
-
}
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
(props.edit
|
|
541
|
+
? updateComment({ objectId: props.edit.objectId, ...options })
|
|
542
|
+
: addComment(options)
|
|
543
|
+
)
|
|
541
544
|
.then((resp) => {
|
|
542
545
|
isSubmitting.value = false;
|
|
543
546
|
|
|
@@ -673,7 +676,7 @@ export default defineComponent({
|
|
|
673
676
|
);
|
|
674
677
|
|
|
675
678
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
676
|
-
const
|
|
679
|
+
const onMessageReceive = ({ data }: any): void => {
|
|
677
680
|
if (!data || data.type !== 'profile') return;
|
|
678
681
|
|
|
679
682
|
userInfo.value = { ...userInfo.value, ...data.data };
|
|
@@ -687,7 +690,7 @@ export default defineComponent({
|
|
|
687
690
|
|
|
688
691
|
onMounted(() => {
|
|
689
692
|
document.body.addEventListener('click', popupHandler);
|
|
690
|
-
window.addEventListener('message',
|
|
693
|
+
window.addEventListener('message', onMessageReceive);
|
|
691
694
|
if (props.edit?.objectId) {
|
|
692
695
|
editor.value = props.edit.orig;
|
|
693
696
|
}
|
|
@@ -745,7 +748,7 @@ export default defineComponent({
|
|
|
745
748
|
|
|
746
749
|
onUnmounted(() => {
|
|
747
750
|
document.body.removeEventListener('click', popupHandler);
|
|
748
|
-
window.removeEventListener('message',
|
|
751
|
+
window.removeEventListener('message', onMessageReceive);
|
|
749
752
|
});
|
|
750
753
|
|
|
751
754
|
return {
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
</div>
|
|
10
10
|
<ul class="wl-sort">
|
|
11
11
|
<li
|
|
12
|
-
v-for="item in
|
|
13
|
-
:key="item
|
|
14
|
-
:class="[item
|
|
15
|
-
@click="onSortByChange(item
|
|
12
|
+
v-for="item in sortingMethods"
|
|
13
|
+
:key="item"
|
|
14
|
+
:class="[item === commentSorting ? 'active' : '']"
|
|
15
|
+
@click="onSortByChange(item)"
|
|
16
16
|
>
|
|
17
|
-
{{ i18n[item
|
|
17
|
+
{{ i18n[item] }}
|
|
18
18
|
</li>
|
|
19
19
|
</ul>
|
|
20
20
|
</div>
|
|
@@ -96,14 +96,16 @@ import CommentCard from './CommentCard.vue';
|
|
|
96
96
|
import { LoadingIcon } from './Icons';
|
|
97
97
|
import { useUserInfo, useLikeStorage } from '../composables';
|
|
98
98
|
import { defaultLocales } from '../config';
|
|
99
|
-
import { deleteComment, getComment,
|
|
99
|
+
import { deleteComment, getComment, updateComment } from '../api';
|
|
100
100
|
import { getConfig, getDarkStyle } from '../utils';
|
|
101
101
|
|
|
102
102
|
import type { PropType } from 'vue';
|
|
103
103
|
import type {
|
|
104
104
|
WalineComment,
|
|
105
|
+
WalineCommentSorting,
|
|
105
106
|
WalineCommentStatus,
|
|
106
107
|
WalineEmojiInfo,
|
|
108
|
+
WalineLoginStatus,
|
|
107
109
|
WalineHighlighter,
|
|
108
110
|
WalineTexRenderer,
|
|
109
111
|
WalineImageUploader,
|
|
@@ -122,6 +124,7 @@ const props = [
|
|
|
122
124
|
'meta',
|
|
123
125
|
'requiredMeta',
|
|
124
126
|
'dark',
|
|
127
|
+
'commentSorting',
|
|
125
128
|
'lang',
|
|
126
129
|
'locale',
|
|
127
130
|
'pageSize',
|
|
@@ -137,23 +140,13 @@ const props = [
|
|
|
137
140
|
'reaction',
|
|
138
141
|
];
|
|
139
142
|
|
|
140
|
-
type
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
key: 'insertedAt_asc',
|
|
150
|
-
name: 'oldest',
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
key: 'like_desc',
|
|
154
|
-
name: 'hottest',
|
|
155
|
-
},
|
|
156
|
-
];
|
|
143
|
+
type SortKey = 'insertedAt_desc' | 'insertedAt_asc' | 'like_desc';
|
|
144
|
+
const sortKeyMap: Record<WalineCommentSorting, SortKey> = {
|
|
145
|
+
latest: 'insertedAt_desc',
|
|
146
|
+
oldest: 'insertedAt_asc',
|
|
147
|
+
hottest: 'like_desc',
|
|
148
|
+
};
|
|
149
|
+
const sortingMethods = Object.keys(sortKeyMap) as WalineCommentSorting[];
|
|
157
150
|
|
|
158
151
|
const propsWithValidate = {
|
|
159
152
|
serverURL: {
|
|
@@ -184,6 +177,14 @@ const propsWithValidate = {
|
|
|
184
177
|
|
|
185
178
|
dark: [String, Boolean],
|
|
186
179
|
|
|
180
|
+
commentSorting: {
|
|
181
|
+
type: String,
|
|
182
|
+
default: 'latest',
|
|
183
|
+
validator: (value: unknown): boolean =>
|
|
184
|
+
typeof value === 'string' &&
|
|
185
|
+
['latest', 'oldest', 'hottest'].includes(value),
|
|
186
|
+
},
|
|
187
|
+
|
|
187
188
|
lang: {
|
|
188
189
|
type: String,
|
|
189
190
|
default: 'zh-CN',
|
|
@@ -223,7 +224,7 @@ const propsWithValidate = {
|
|
|
223
224
|
)),
|
|
224
225
|
},
|
|
225
226
|
|
|
226
|
-
login: String as PropType<
|
|
227
|
+
login: String as PropType<WalineLoginStatus>,
|
|
227
228
|
|
|
228
229
|
highlighter: Function as PropType<WalineHighlighter>,
|
|
229
230
|
|
|
@@ -278,7 +279,7 @@ export default defineComponent({
|
|
|
278
279
|
const count = ref(0);
|
|
279
280
|
const page = ref(1);
|
|
280
281
|
const totalPages = ref(0);
|
|
281
|
-
const
|
|
282
|
+
const commentSorting = ref(config.value.commentSorting);
|
|
282
283
|
|
|
283
284
|
const data = ref<WalineComment[]>([]);
|
|
284
285
|
const reply = ref<WalineComment | null>(null);
|
|
@@ -304,7 +305,7 @@ export default defineComponent({
|
|
|
304
305
|
lang: config.value.lang,
|
|
305
306
|
path,
|
|
306
307
|
pageSize,
|
|
307
|
-
sortBy:
|
|
308
|
+
sortBy: sortKeyMap[commentSorting.value],
|
|
308
309
|
page: pageNumber,
|
|
309
310
|
signal: controller.signal,
|
|
310
311
|
token: userInfo.value?.token,
|
|
@@ -334,12 +335,11 @@ export default defineComponent({
|
|
|
334
335
|
getCommentData(1);
|
|
335
336
|
};
|
|
336
337
|
|
|
337
|
-
const onSortByChange = (item:
|
|
338
|
-
if (
|
|
339
|
-
|
|
338
|
+
const onSortByChange = (item: WalineCommentSorting): void => {
|
|
339
|
+
if (commentSorting.value !== item) {
|
|
340
|
+
commentSorting.value = item;
|
|
341
|
+
refresh();
|
|
340
342
|
}
|
|
341
|
-
sortBy.value = item;
|
|
342
|
-
refresh();
|
|
343
343
|
};
|
|
344
344
|
|
|
345
345
|
const onReply = (comment: WalineComment | null): void => {
|
|
@@ -445,10 +445,11 @@ export default defineComponent({
|
|
|
445
445
|
const { objectId } = comment;
|
|
446
446
|
const hasLiked = likeStorage.value.includes(objectId);
|
|
447
447
|
|
|
448
|
-
await
|
|
448
|
+
await updateComment({
|
|
449
449
|
serverURL,
|
|
450
450
|
lang,
|
|
451
451
|
objectId,
|
|
452
|
+
token: userInfo.value?.token,
|
|
452
453
|
like: !hasLiked,
|
|
453
454
|
});
|
|
454
455
|
|
|
@@ -484,8 +485,8 @@ export default defineComponent({
|
|
|
484
485
|
count,
|
|
485
486
|
page,
|
|
486
487
|
totalPages,
|
|
487
|
-
|
|
488
|
-
|
|
488
|
+
commentSorting,
|
|
489
|
+
sortingMethods,
|
|
489
490
|
data,
|
|
490
491
|
reply,
|
|
491
492
|
edit,
|
package/src/pageview.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getPageview, updatePageview } from './api';
|
|
2
2
|
import { errorHandler, getQuery, getServerURL } from './utils';
|
|
3
3
|
|
|
4
4
|
import type { WalineAbort } from './typings';
|
|
@@ -78,7 +78,7 @@ export const pageviewCount = ({
|
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
const fetch = (elements: HTMLElement[]): Promise<void> =>
|
|
81
|
-
|
|
81
|
+
getPageview({
|
|
82
82
|
serverURL: getServerURL(serverURL),
|
|
83
83
|
paths: elements.map((element) => getQuery(element) || path),
|
|
84
84
|
lang,
|
|
@@ -92,7 +92,7 @@ export const pageviewCount = ({
|
|
|
92
92
|
const normalElements = elements.filter((element) => !filter(element));
|
|
93
93
|
const elementsNeedstoBeFetched = elements.filter(filter);
|
|
94
94
|
|
|
95
|
-
void
|
|
95
|
+
void updatePageview({
|
|
96
96
|
serverURL: getServerURL(serverURL),
|
|
97
97
|
path,
|
|
98
98
|
lang,
|
package/src/styles/index.scss
CHANGED
|
File without changes
|
package/src/styles/panel.scss
CHANGED
|
File without changes
|