@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.
Files changed (66) hide show
  1. package/dist/api.cjs +1 -1
  2. package/dist/api.cjs.map +1 -1
  3. package/dist/api.d.cts +60 -34
  4. package/dist/api.d.mts +60 -34
  5. package/dist/api.d.ts +60 -34
  6. package/dist/api.mjs +1 -1
  7. package/dist/api.mjs.map +1 -1
  8. package/dist/comment.cjs +1 -1
  9. package/dist/comment.cjs.map +1 -1
  10. package/dist/comment.d.cts +1 -1
  11. package/dist/comment.d.mts +1 -1
  12. package/dist/comment.d.ts +1 -1
  13. package/dist/comment.js +40 -45
  14. package/dist/comment.js.map +1 -1
  15. package/dist/comment.mjs +1 -1
  16. package/dist/comment.mjs.map +1 -1
  17. package/dist/component.mjs +1 -1
  18. package/dist/component.mjs.map +1 -1
  19. package/dist/legacy.umd.d.ts +13 -3
  20. package/dist/legacy.umd.js +1 -1
  21. package/dist/legacy.umd.js.map +1 -1
  22. package/dist/pageview.cjs +1 -1
  23. package/dist/pageview.cjs.map +1 -1
  24. package/dist/pageview.js +44 -49
  25. package/dist/pageview.js.map +1 -1
  26. package/dist/pageview.mjs +1 -1
  27. package/dist/pageview.mjs.map +1 -1
  28. package/dist/shim.cjs +1 -1
  29. package/dist/shim.cjs.map +1 -1
  30. package/dist/shim.d.cts +15 -9
  31. package/dist/shim.d.mts +15 -9
  32. package/dist/shim.mjs +1 -1
  33. package/dist/shim.mjs.map +1 -1
  34. package/dist/waline.cjs +1 -1
  35. package/dist/waline.cjs.map +1 -1
  36. package/dist/waline.css +1 -1
  37. package/dist/waline.css.map +1 -1
  38. package/dist/waline.d.cts +15 -9
  39. package/dist/waline.d.mts +15 -9
  40. package/dist/waline.d.ts +15 -9
  41. package/dist/waline.js +441 -449
  42. package/dist/waline.js.map +1 -1
  43. package/dist/waline.mjs +1 -1
  44. package/dist/waline.mjs.map +1 -1
  45. package/package.json +1 -1
  46. package/src/api/articleCounter.ts +3 -7
  47. package/src/api/comment.ts +60 -49
  48. package/src/api/commentCount.ts +0 -2
  49. package/src/api/pageview.ts +2 -2
  50. package/src/api/recentComment.ts +2 -5
  51. package/src/api/user.ts +2 -4
  52. package/src/api/utils.ts +17 -10
  53. package/src/comment.ts +1 -1
  54. package/src/compact/convert.ts +1 -1
  55. package/src/components/CommentBox.vue +14 -11
  56. package/src/components/Waline.vue +35 -34
  57. package/src/pageview.ts +3 -3
  58. package/src/styles/index.scss +2 -2
  59. package/src/styles/{nomalize.scss → normalize.scss} +0 -0
  60. package/src/styles/panel.scss +1 -1
  61. package/src/styles/{userlist.scss → user-list.scss} +0 -0
  62. package/src/typings/base.ts +5 -1
  63. package/src/typings/comment.ts +1 -5
  64. package/src/typings/waline.ts +13 -2
  65. package/src/utils/config.ts +2 -0
  66. package/src/utils/date.ts +3 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waline/client",
3
- "version": "2.13.1",
3
+ "version": "2.14.0",
4
4
  "description": "client for waline comment system",
5
5
  "keywords": [
6
6
  "valine",
@@ -1,4 +1,4 @@
1
- import { JSON_HEADERS, errorCheck } from './utils';
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());
@@ -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
- * 待获取评论列hi奥德路径
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 panination number
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
- `${serverURL}/comment${comment.eid ? `/${comment.eid}` : ''}?lang=${lang}`,
139
- {
140
- method: 'PUT',
141
- headers,
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<void> =>
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
- }).then((resp) => <Promise<void>>resp.json());
175
+ })
176
+ .then((resp) => <Promise<DeleteCommentResponse>>resp.json())
177
+ .then((resp) => errorCheck(resp, 'Delete comment'));
164
178
 
165
- export interface LikeCommentOptions extends BaseAPIOptions {
179
+ export interface UpdateCommentOptions extends BaseAPIOptions {
166
180
  /**
167
- * 评论的 ID
181
+ * 用户令牌
168
182
  *
169
- * Comment ID
183
+ * User token
170
184
  */
171
- objectId: number | string;
185
+ token: string;
172
186
 
173
187
  /**
174
- * 点赞还是取消点赞
188
+ * 评论的 ID
175
189
  *
176
- * Like or dislike
190
+ * Comment ID
177
191
  */
178
- like: boolean;
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
- * User token
197
+ * Comment data
198
198
  */
199
- token: string;
199
+ comment?: WalineCommentData;
200
200
 
201
201
  /**
202
- * 评论的 ID
202
+ * 点赞还是取消点赞
203
203
  *
204
- * Comment ID
204
+ * Like or dislike
205
205
  */
206
- objectId: number | string;
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<void> =>
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
- }).then((resp) => <Promise<void>>resp.json());
248
+ })
249
+ .then((resp) => <Promise<UpdateCommentResponse>>resp.json())
250
+ .then((resp) => errorCheck(resp, 'Update comment'));
@@ -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]));
@@ -17,7 +17,7 @@ interface GetPageviewOptions extends BaseAPIOptions {
17
17
  signal?: AbortSignal;
18
18
  }
19
19
 
20
- export const getPageviews = ({
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 updatePageviews = (
47
+ export const updatePageview = (
48
48
  options: UpdatePageviewOptions
49
49
  ): Promise<number> =>
50
50
  updateArticleCounter({
@@ -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 numebr to be fetched
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 APIErrorResponse {
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 = unknown>(
28
- data: T | APIErrorResponse,
38
+ export const errorCheck = <T extends ErrorStatusResponse>(
39
+ data: T,
29
40
  name = ''
30
41
  ): T => {
31
- if (typeof data === 'object' && (data as APIErrorResponse).errno)
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 as T;
45
+ return data;
39
46
  };
package/src/comment.ts CHANGED
@@ -13,7 +13,7 @@ export interface WalineCommentCountOptions {
13
13
  /**
14
14
  * 评论数 CSS 选择器
15
15
  *
16
- * Commment count CSS selector
16
+ * Comment count CSS selector
17
17
  *
18
18
  * @default '.waline-comment-count'
19
19
  */
@@ -44,7 +44,7 @@ export const covertOptions = (
44
44
  ...more
45
45
  } = options;
46
46
 
47
- // error with those which can no longr be handled
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="{ actived: showEmoji }"
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="{ actived: showGif }"
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="{ actived: showPreview }"
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
- addComment({
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 onMessageRecive = ({ data }: any): void => {
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', onMessageRecive);
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', onMessageRecive);
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 sortByItems"
13
- :key="item.key"
14
- :class="[item.key === sortBy ? 'active' : '']"
15
- @click="onSortByChange(item.key)"
12
+ v-for="item in sortingMethods"
13
+ :key="item"
14
+ :class="[item === commentSorting ? 'active' : '']"
15
+ @click="onSortByChange(item)"
16
16
  >
17
- {{ i18n[item.name] }}
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, likeComment, updateComment } from '../api';
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 SortKeyItems = 'insertedAt_desc' | 'insertedAt_asc' | 'like_desc';
141
- type SortNameItems = 'latest' | 'oldest' | 'hottest';
142
- type SortByItems = { key: SortKeyItems; name: SortNameItems }[];
143
- const sortByItems: SortByItems = [
144
- {
145
- key: 'insertedAt_desc',
146
- name: 'latest',
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<'enable' | 'disable' | 'force'>,
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 sortBy = ref<SortKeyItems>(sortByItems[0].key);
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: sortBy.value,
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: SortKeyItems): void => {
338
- if (sortBy.value === item) {
339
- return;
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 likeComment({
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
- sortBy,
488
- sortByItems,
488
+ commentSorting,
489
+ sortingMethods,
489
490
  data,
490
491
  reply,
491
492
  edit,
package/src/pageview.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { getPageviews, updatePageviews } from './api';
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
- getPageviews({
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 updatePageviews({
95
+ void updatePageview({
96
96
  serverURL: getServerURL(serverURL),
97
97
  path,
98
98
  lang,
@@ -1,5 +1,5 @@
1
1
  @use 'config';
2
- @use 'nomalize';
2
+ @use 'normalize';
3
3
 
4
4
  @use 'base';
5
5
 
@@ -14,4 +14,4 @@
14
14
  @use 'highlight';
15
15
 
16
16
  @use 'recent';
17
- @use 'userlist';
17
+ @use 'user-list';
File without changes
@@ -242,7 +242,7 @@
242
242
  color: var(--waline-theme-color);
243
243
  }
244
244
 
245
- &.actived {
245
+ &.active {
246
246
  color: var(--waline-active-color);
247
247
  }
248
248
  }
File without changes