@waline/client 2.14.2 → 2.14.4

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 (60) hide show
  1. package/dist/api.cjs +1 -1
  2. package/dist/api.cjs.map +1 -1
  3. package/dist/api.d.cts +22 -20
  4. package/dist/api.d.mts +22 -20
  5. package/dist/api.d.ts +22 -20
  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 +1 -1
  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 +1 -1
  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.d.cts +1 -1
  25. package/dist/pageview.d.mts +1 -1
  26. package/dist/pageview.d.ts +1 -1
  27. package/dist/pageview.js +1 -1
  28. package/dist/pageview.js.map +1 -1
  29. package/dist/pageview.mjs +1 -1
  30. package/dist/pageview.mjs.map +1 -1
  31. package/dist/shim.cjs +1 -1
  32. package/dist/shim.cjs.map +1 -1
  33. package/dist/shim.d.cts +5 -5
  34. package/dist/shim.d.mts +5 -5
  35. package/dist/shim.mjs +1 -1
  36. package/dist/shim.mjs.map +1 -1
  37. package/dist/waline.cjs +1 -1
  38. package/dist/waline.cjs.map +1 -1
  39. package/dist/waline.css +1 -1
  40. package/dist/waline.css.map +1 -1
  41. package/dist/waline.d.cts +5 -5
  42. package/dist/waline.d.mts +5 -5
  43. package/dist/waline.d.ts +5 -5
  44. package/dist/waline.js +1 -1
  45. package/dist/waline.js.map +1 -1
  46. package/dist/waline.mjs +1 -1
  47. package/dist/waline.mjs.map +1 -1
  48. package/package.json +8 -8
  49. package/src/api/comment.ts +25 -24
  50. package/src/comment.ts +2 -2
  51. package/src/components/ArticleReaction.vue +7 -14
  52. package/src/components/WalineComment.vue +28 -366
  53. package/src/config/default.ts +1 -1
  54. package/src/config/i18n/index.ts +1 -0
  55. package/src/pageview.ts +2 -2
  56. package/src/styles/reaction.scss +28 -11
  57. package/src/typings/waline.ts +1 -1
  58. package/src/utils/config.ts +2 -2
  59. package/src/widgets/recentComments.ts +2 -2
  60. package/src/widgets/userList.ts +2 -2
@@ -84,7 +84,7 @@
84
84
  </template>
85
85
 
86
86
  <script setup lang="ts">
87
- /* eslint-disable vue/no-unused-properties */
87
+ /* eslint-disable vue/no-unused-properties vue/require-prop-comment vue/require-prop-types */
88
88
  import { useStyleTag } from '@vueuse/core';
89
89
  import { computed, onMounted, onUnmounted, provide, ref, watch } from 'vue';
90
90
  import Reaction from './ArticleReaction.vue';
@@ -98,372 +98,34 @@ import { version } from '../version.js';
98
98
 
99
99
  import type {
100
100
  WalineComment,
101
+ WalineCommentSorting,
101
102
  WalineCommentStatus,
102
- WalineLocale,
103
+ WalineProps,
103
104
  } from '../typings/index.js';
104
105
 
105
106
  type SortKey = 'insertedAt_desc' | 'insertedAt_asc' | 'like_desc';
106
107
 
107
- // TODO: Currently complex types and type imports from other files are not supported. It is possible to support type imports in the future.
108
- // @see https://vuejs.org/api/sfc-script-setup.html#typescript-only-features
109
- // this issue may be addressed in Vue3.3
110
- // the following line is the same as WalineProps
111
-
112
- type WalineCommentSorting = 'latest' | 'oldest' | 'hottest';
113
-
114
- type WalineEmojiPresets =
115
- | `//${string}`
116
- | `http://${string}`
117
- | `https://${string}`;
118
-
119
- interface WalineEmojiInfo {
120
- /**
121
- * 选项卡上的 Emoji 名称
122
- *
123
- * Emoji name show on tab
124
- */
125
- name: string;
126
- /**
127
- * 所在文件夹链接
128
- *
129
- * Current folder link
130
- */
131
- folder?: string;
132
- /**
133
- * Emoji 通用路径前缀
134
- *
135
- * Common prefix of Emoji icons
136
- */
137
- prefix?: string;
138
- /**
139
- * Emoji 图片的类型,会作为文件扩展名使用
140
- *
141
- * Type of Emoji icons, will be regarded as file extension
142
- */
143
- type?: string;
144
- /**
145
- * 选项卡显示的 Emoji 图标
146
- *
147
- * Emoji icon show on tab
148
- */
149
- icon: string;
150
- /**
151
- * Emoji 图片列表
152
- *
153
- * Emoji image list
154
- */
155
- items: string[];
156
- }
157
-
158
- type WalineLoginStatus = 'enable' | 'disable' | 'force';
159
-
160
- interface WalineSearchImageData extends Record<string, unknown> {
161
- /**
162
- * 图片链接
163
- *
164
- * Image link
165
- */
166
- src: string;
167
-
168
- /**
169
- * 图片标题
170
- *
171
- * @description 用于图片的 alt 属性
172
- *
173
- * Image title
174
- *
175
- * @description Used for alt attribute of image
176
- */
177
- title?: string;
178
-
179
- /**
180
- * 图片缩略图
181
- *
182
- * @description 为了更好的加载性能,我们会优先在列表中使用此缩略图
183
- *
184
- * Image preview link
185
- *
186
- * @description For better loading performance, we will use this thumbnail first in the list
187
- *
188
- * @default src
189
- */
190
- preview?: string;
191
- }
192
-
193
- type WalineSearchResult = WalineSearchImageData[];
194
-
195
- interface WalineSearchOptions {
196
- /**
197
- * 搜索操作
198
- *
199
- * Search action
200
- */
201
- search: (word: string) => Promise<WalineSearchResult>;
202
-
203
- /**
204
- * 打开列表时展示的默认结果
205
- *
206
- * Default result when opening list
207
- *
208
- * @default () => search('')
209
- */
210
- default?: () => Promise<WalineSearchResult>;
211
-
212
- /**
213
- * 获取更多的操作
214
- *
215
- * @description 会在列表滚动到底部时触发,如果你的搜索服务支持分页功能,你应该设置此项实现无限滚动
216
- *
217
- * Fetch more action
218
- *
219
- * @description It will be triggered when the list scrolls to the bottom. If your search service supports paging, you should set this to achieve infinite scrolling
220
- *
221
- * @default (word) => search(word)
222
- */
223
- more?: (word: string, currentCount: number) => Promise<WalineSearchResult>;
224
- }
225
-
226
- type WalineMeta = 'nick' | 'mail' | 'link';
227
-
228
- type WalineImageUploader = (image: File) => Promise<string>;
229
-
230
- type WalineHighlighter = (code: string, lang: string) => string;
231
-
232
- type WalineTexRenderer = (blockMode: boolean, tex: string) => string;
233
-
234
- const props = defineProps<{
235
- /**
236
- * Waline 的服务端地址
237
- *
238
- * Waline server address url
239
- */
240
- serverURL: string;
241
-
242
- /**
243
- * 当前 _文章页_ 路径,用于区分不同的 _文章页_ ,以保证正确读取该 _文章页_ 下的评论列表
244
- *
245
- * 你可以将其设置为 `window.location.pathname`
246
- *
247
- * Article path id. Used to distinguish different _article pages_ to ensure loading the correct comment list under the _article page_.
248
- *
249
- * You can set it to `window.location.pathname`
250
- */
251
- path: string;
252
-
253
- /**
254
- * 评论者相关属性
255
- *
256
- * `Meta` 可选值: `'nick'`, `'mail'`, `'link'`
257
- *
258
- * Reviewer attributes.
259
- *
260
- * Optional values for `Meta`: `'nick'`, `'mail'`, `'link'`
261
- *
262
- * @default ['nick', 'mail', 'link']
263
- */
264
- meta?: WalineMeta[];
265
-
266
- /**
267
- * 设置**必填项**,默认昵称为匿名
268
- *
269
- * Set required fields, default anonymous with nickname
270
- *
271
- * @default []
272
- */
273
- requiredMeta?: WalineMeta[];
274
-
275
- /**
276
- * 评论字数限制。填入单个数字时为最大字数限制
277
- *
278
- * @more 设置为 `0` 时无限制
279
- *
280
- * Comment word s limit. When a single number is filled in, it 's the maximum number of comment words.
281
- *
282
- * @more No limit when set to `0`.
283
- *
284
- * @default 0
285
- */
286
- wordLimit?: number | [number, number];
287
-
288
- /**
289
- * 评论列表分页,每页条数
290
- *
291
- * number of pages per page
292
- *
293
- * @default 10
294
- */
295
- pageSize?: number;
296
-
297
- /**
298
- * Waline 显示语言
299
- *
300
- * 可选值:
301
- *
302
- * - `'zh'`
303
- * - `'zh-cn'`
304
- * - `'zh-CN'`
305
- * - `'zh-tw'`
306
- * - `'zh-TW'`
307
- * - `'en'`
308
- * - `'en-US'`
309
- * - `'en-us'`
310
- * - `'jp'`
311
- * - `'jp-jp'`
312
- * - `'jp-JP'`
313
- * - `'pt-br'`
314
- * - `'pt-BR'`
315
- * - `'ru'`
316
- * - `'ru-ru'`
317
- * - `'ru-RU'`
318
- *
319
- * Display language for waline
320
- *
321
- * Optional value:
322
- *
323
- * - `'zh'`
324
- * - `'zh-cn'`
325
- * - `'zh-CN'`
326
- * - `'zh-tw'`
327
- * - `'zh-TW'`
328
- * - `'en'`
329
- * - `'en-US'`
330
- * - `'en-us'`
331
- * - `'jp'`
332
- * - `'jp-jp'`
333
- * - `'jp-JP'`
334
- * - `'pt-br'`
335
- * - `'pt-BR'`
336
- * - `'ru'`
337
- * - `'ru-ru'`
338
- * - `'ru-RU'`
339
- *
340
- * @default 'zh-CN'
341
- */
342
- lang?: string;
343
-
344
- /**
345
- * 自定义 waline 语言显示
346
- *
347
- * @see [自定义语言](https://waline.js.org/client/i18n.html)
348
- *
349
- * Custom display language in waline
350
- *
351
- * @see [I18n](https://waline.js.org/en/client/i18n.html)
352
- */
353
- locale?: Partial<WalineLocale>;
354
-
355
- /**
356
- * 评论列表排序方式
357
- *
358
- * Sorting method for comment list
359
- *
360
- * @default 'latest'
361
- */
362
- commentSorting?: WalineCommentSorting;
363
-
364
- /**
365
- * 是否启用暗黑模式适配
366
- *
367
- * @more 设置 `'auto'` 会根据设备暗黑模式自适应。填入 CSS 选择器会在对应选择器生效时启用夜间模式。
368
- *
369
- * Whether to enable darkmode support
370
- *
371
- * @more Setting `'auto'` will display darkmode due to device settings. Filling in CSS selector will enable darkmode only when the selector match waline ancestor nodes.
372
- */
373
- dark?: string | boolean;
374
-
375
- /**
376
- * 设置表情包
377
- *
378
- * Set Emojis
379
- *
380
- * @default ['//unpkg.com/@waline/emojis@1.1.0/weibo']
381
- */
382
- emoji?: (WalineEmojiInfo | WalineEmojiPresets)[] | boolean;
383
-
384
- /**
385
- * 设置搜索功能
386
- *
387
- * Customize Search feature
388
- *
389
- * @default true
390
- */
391
- search?: WalineSearchOptions | boolean;
392
-
393
- /**
394
- * 代码高亮
395
- *
396
- * Code highlighting
397
- *
398
- * @default true
399
- */
400
-
401
- highlighter?: WalineHighlighter | boolean;
402
-
403
- /**
404
- * 自定义图片上传方法,方便更好的存储图片
405
- *
406
- * 方法执行时会将图片对象传入。
407
- *
408
- * Custom image upload callback to manage picture by yourself.
409
- *
410
- * We will pass a picture file object when execute it.
411
- *
412
- * @default true
413
- */
414
-
415
- imageUploader?: WalineImageUploader | boolean;
416
-
417
- /**
418
- * 自定义数学公式处理方法,用于预览。
419
- *
420
- * Custom math formula parse callback for preview.
421
- *
422
- * @default true
423
- */
424
- texRenderer?: WalineTexRenderer | boolean;
425
-
426
- /**
427
- *
428
- * 登录模式状态,可选值:
429
- *
430
- * - `'enable'`: 启用登录 (默认)
431
- * - `'disable'`: 禁用登录,用户只能填写信息评论
432
- * - `'force'`: 强制登录,用户必须注册并登录才可发布评论
433
- *
434
- * Login mode status, optional values:
435
- *
436
- * - `'enable'`: enable login (default)
437
- * - `'disable'`: Login is disabled, users should fill in information to comment
438
- * - `'force'`: Forced login, users must login to comment
439
- *
440
- * @default 'enable'
441
- */
442
- login?: WalineLoginStatus;
443
-
444
- /**
445
- * 是否在页脚展示版权信息
446
- *
447
- * 为了支持 Waline,我们强烈建议你开启它
448
- *
449
- * Whether show copyright in footer
450
- *
451
- * We strongly recommended you to keep it on to support waline
452
- *
453
- * @default true
454
- */
455
- copyright?: boolean;
456
-
457
- /**
458
- * recaptcha v3 client key
459
- */
460
- recaptchaV3Key?: string;
461
-
462
- /**
463
- * reaction
464
- */
465
- reaction?: string[] | boolean;
466
- }>();
108
+ const props = defineProps([
109
+ 'serverURL',
110
+ 'path',
111
+ 'meta',
112
+ 'requiredMeta',
113
+ 'dark',
114
+ 'commentSorting',
115
+ 'lang',
116
+ 'locale',
117
+ 'pageSize',
118
+ 'wordLimit',
119
+ 'emoji',
120
+ 'login',
121
+ 'highlighter',
122
+ 'texRenderer',
123
+ 'imageUploader',
124
+ 'search',
125
+ 'copyright',
126
+ 'recaptchaV3Key',
127
+ 'reaction',
128
+ ]);
467
129
 
468
130
  const sortKeyMap: Record<WalineCommentSorting, SortKey> = {
469
131
  latest: 'insertedAt_desc',
@@ -481,7 +143,7 @@ const count = ref(0);
481
143
  const page = ref(1);
482
144
  const totalPages = ref(0);
483
145
 
484
- const config = computed(() => getConfig(props));
146
+ const config = computed(() => getConfig(props as WalineProps));
485
147
 
486
148
  // eslint-disable-next-line vue/no-ref-object-destructure
487
149
  const commentSorting = ref(config.value.commentSorting);
@@ -589,7 +251,7 @@ const onStatusChange = async ({
589
251
  lang,
590
252
  token: userInfo.value?.token,
591
253
  objectId: comment.objectId,
592
- status,
254
+ comment: { status },
593
255
  });
594
256
 
595
257
  comment.status = status;
@@ -605,7 +267,7 @@ const onSticky = async (comment: WalineComment): Promise<void> => {
605
267
  lang,
606
268
  token: userInfo.value?.token,
607
269
  objectId: comment.objectId,
608
- sticky: comment.sticky ? 0 : 1,
270
+ comment: { sticky: comment.sticky ? 0 : 1 },
609
271
  });
610
272
 
611
273
  comment.sticky = !comment.sticky;
@@ -655,7 +317,7 @@ const onLike = async (comment: WalineComment): Promise<void> => {
655
317
  lang,
656
318
  objectId,
657
319
  token: userInfo.value?.token,
658
- like: !hasLiked,
320
+ comment: { like: !hasLiked },
659
321
  });
660
322
 
661
323
  if (hasLiked)
@@ -15,7 +15,7 @@ export const defaultEmoji: WalineEmojiPresets[] = [
15
15
  '//unpkg.com/@waline/emojis@1.1.0/weibo',
16
16
  ];
17
17
 
18
- export const defaultLang = 'zh-CN';
18
+ export const defaultLang = 'en-US';
19
19
 
20
20
  export const defaultUploadImage = (file: File): Promise<string> =>
21
21
  new Promise((resolve, reject) => {
@@ -20,6 +20,7 @@ export const defaultLocales: Locales = {
20
20
  'en-US': en,
21
21
  'en-us': en,
22
22
  jp: jp,
23
+ ja: jp,
23
24
  'jp-jp': jp,
24
25
  'jp-JP': jp,
25
26
  'pt-br': ptBR,
package/src/pageview.ts CHANGED
@@ -43,7 +43,7 @@ export interface WalinePageviewCountOptions {
43
43
  *
44
44
  * Language of error message
45
45
  *
46
- * @default 'zh-CN'
46
+ * @default navigator.language
47
47
  */
48
48
  lang?: string;
49
49
  }
@@ -62,7 +62,7 @@ export const pageviewCount = ({
62
62
  path = window.location.pathname,
63
63
  selector = '.waline-pageview-count',
64
64
  update = true,
65
- lang = 'zh-CN',
65
+ lang = navigator.language,
66
66
  }: WalinePageviewCountOptions): WalineAbort => {
67
67
  const controller = new AbortController();
68
68
 
@@ -1,6 +1,7 @@
1
1
  .wl-reaction {
2
2
  margin-bottom: 1.75em;
3
3
  text-align: center;
4
+ overflow-x: auto;
4
5
 
5
6
  img {
6
7
  width: 100%;
@@ -8,7 +9,14 @@
8
9
  transition: all 250ms ease-in-out;
9
10
  }
10
11
 
11
- &-list {
12
+ .reaction-title {
13
+ margin: 16px auto;
14
+ font-size: 18px;
15
+ font-weight: bold;
16
+ }
17
+
18
+ .reaction-list {
19
+ padding: 8px;
12
20
  display: flex;
13
21
  flex-direction: row;
14
22
  gap: 16px;
@@ -17,9 +25,13 @@
17
25
  margin: 0;
18
26
 
19
27
  list-style-type: none;
28
+
29
+ @media (max-width: 580px) {
30
+ gap: 12px;
31
+ }
20
32
  }
21
33
 
22
- &-item {
34
+ .reaction-item {
23
35
  display: flex;
24
36
  flex-direction: column;
25
37
  align-items: center;
@@ -30,25 +42,30 @@
30
42
  transform: scale(1.15);
31
43
  }
32
44
 
33
- &.active .wl-reaction {
34
- &-votes {
45
+ &.active {
46
+ .reaction-votes {
35
47
  background: var(--waline-theme-color);
36
48
  color: var(--waline-bgcolor);
37
49
  }
38
50
 
39
- &-text {
51
+ .reaction-text {
40
52
  color: var(--waline-theme-color);
41
53
  }
42
54
  }
43
55
  }
44
56
 
45
- &-img {
57
+ .reaction-img {
46
58
  position: relative;
47
59
  width: 42px;
48
60
  height: 42px;
61
+
62
+ @media (max-width: 580px) {
63
+ width: 32px;
64
+ height: 32px;
65
+ }
49
66
  }
50
67
 
51
- &-loading {
68
+ .reaction-loading {
52
69
  position: absolute;
53
70
  top: -4px;
54
71
  right: -5px;
@@ -59,10 +76,10 @@
59
76
  color: var(--waline-theme-color);
60
77
  }
61
78
 
62
- &-votes {
79
+ .reaction-votes {
63
80
  position: absolute;
64
- top: -4px;
65
- right: -5px;
81
+ top: -9px;
82
+ right: -9px;
66
83
 
67
84
  min-width: 1em;
68
85
  padding: 2px;
@@ -77,7 +94,7 @@
77
94
  line-height: 1;
78
95
  }
79
96
 
80
- &-text {
97
+ .reaction-text {
81
98
  font-size: 0.875em;
82
99
  }
83
100
  }
@@ -117,7 +117,7 @@ export interface WalineProps {
117
117
  * - `'ru-ru'`
118
118
  * - `'ru-RU'`
119
119
  *
120
- * @default 'zh-CN'
120
+ * @default navigator.language
121
121
  */
122
122
  lang?: string;
123
123
 
@@ -68,7 +68,7 @@ export const getConfig = ({
68
68
  serverURL,
69
69
 
70
70
  path = location.pathname,
71
- lang = defaultLang,
71
+ lang = typeof navigator === 'undefined' ? 'en-US' : navigator.language,
72
72
  locale,
73
73
  emoji = defaultEmoji,
74
74
  meta = ['nick', 'mail', 'link'],
@@ -99,7 +99,7 @@ export const getConfig = ({
99
99
  imageUploader: fallback(imageUploader, defaultUploadImage),
100
100
  highlighter: fallback(highlighter, defaultHighlighter),
101
101
  texRenderer: fallback(texRenderer, defaultTexRenderer),
102
- lang,
102
+ lang: Object.keys(defaultLocales).includes(lang) ? lang : 'en-US',
103
103
  dark,
104
104
  emoji: typeof emoji === 'boolean' ? (emoji ? defaultEmoji : []) : emoji,
105
105
  pageSize,
@@ -31,7 +31,7 @@ export interface WalineRecentCommentsOptions {
31
31
  *
32
32
  * Language of error message
33
33
  *
34
- * @default 'zh-CN'
34
+ * @default navigator.language
35
35
  */
36
36
  lang?: string;
37
37
  }
@@ -56,7 +56,7 @@ export const RecentComments = ({
56
56
  el,
57
57
  serverURL,
58
58
  count,
59
- lang = 'zh-CN',
59
+ lang = navigator.language,
60
60
  }: WalineRecentCommentsOptions): Promise<WalineRecentCommentsResult> => {
61
61
  const userInfo = useUserInfo();
62
62
  const root = getRoot(el);
@@ -30,7 +30,7 @@ export interface WalineUserListOptions {
30
30
  *
31
31
  * Language of error message
32
32
  *
33
- * @default 'zh-CN'
33
+ * @default navigator.language
34
34
  */
35
35
  lang?: string;
36
36
 
@@ -74,7 +74,7 @@ export const UserList = ({
74
74
  serverURL,
75
75
  count,
76
76
  locale,
77
- lang = defaultLang,
77
+ lang = navigator.language,
78
78
  mode = 'list',
79
79
  }: WalineUserListOptions): Promise<WalineUserListResult> => {
80
80
  const root = getRoot(el);