@waline/client 2.3.0 → 2.4.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 (57) hide show
  1. package/dist/component.esm.js +1 -1
  2. package/dist/component.esm.js.map +1 -1
  3. package/dist/component.js +1 -1
  4. package/dist/component.js.map +1 -1
  5. package/dist/legacy.d.ts +4 -9
  6. package/dist/legacy.js +1 -1
  7. package/dist/legacy.js.map +1 -1
  8. package/dist/pageview.cjs.d.ts +47 -0
  9. package/dist/pageview.cjs.js +1 -1
  10. package/dist/pageview.cjs.js.map +1 -1
  11. package/dist/pageview.esm.d.ts +47 -0
  12. package/dist/pageview.esm.js +1 -1
  13. package/dist/pageview.esm.js.map +1 -1
  14. package/dist/pageview.js +1 -1
  15. package/dist/pageview.js.map +1 -1
  16. package/dist/shim.d.ts +46 -11
  17. package/dist/shim.esm.d.ts +46 -11
  18. package/dist/shim.esm.js +1 -1
  19. package/dist/shim.esm.js.map +1 -1
  20. package/dist/shim.js +1 -1
  21. package/dist/shim.js.map +1 -1
  22. package/dist/waline.cjs.d.ts +46 -11
  23. package/dist/waline.cjs.js +1 -1
  24. package/dist/waline.cjs.js.map +1 -1
  25. package/dist/waline.css +1 -1
  26. package/dist/waline.css.map +1 -1
  27. package/dist/waline.d.ts +46 -11
  28. package/dist/waline.esm.d.ts +46 -11
  29. package/dist/waline.esm.js +1 -1
  30. package/dist/waline.esm.js.map +1 -1
  31. package/dist/waline.js +1 -1
  32. package/dist/waline.js.map +1 -1
  33. package/package.json +6 -7
  34. package/src/components/CommentBox.vue +1 -3
  35. package/src/components/CommentCard.vue +69 -6
  36. package/src/components/Icons.ts +28 -2
  37. package/src/components/Waline.vue +200 -112
  38. package/src/composables/index.ts +1 -0
  39. package/src/composables/likeStorage.ts +11 -0
  40. package/src/composables/userInfo.ts +2 -0
  41. package/src/config/highlighter.ts +74 -0
  42. package/src/config/i18n/en.ts +2 -0
  43. package/src/config/i18n/generate.ts +2 -0
  44. package/src/config/i18n/jp.ts +2 -0
  45. package/src/config/i18n/pt-BR.ts +2 -0
  46. package/src/config/i18n/ru.ts +2 -0
  47. package/src/config/i18n/vi-VN.ts +2 -0
  48. package/src/config/i18n/zh-CN.ts +2 -0
  49. package/src/config/i18n/zh-TW.ts +2 -0
  50. package/src/config/index.ts +1 -0
  51. package/src/styles/card.scss +24 -0
  52. package/src/typings/base.ts +1 -7
  53. package/src/typings/comment.ts +56 -1
  54. package/src/typings/locale.ts +3 -8
  55. package/src/utils/config.ts +3 -3
  56. package/src/utils/fetch.ts +77 -4
  57. package/src/shims-hanabi.d.ts +0 -9
@@ -0,0 +1,74 @@
1
+ /**
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) egoist <0x142857@gmail.com> (https://egoistian.com)
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ *
24
+ */
25
+
26
+ const WORD_REGEXP =
27
+ /[\u4E00-\u9FFF\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af\u0400-\u04FF]+|\w+/;
28
+ const LEFT_ANGLE_REGEXP = /</;
29
+ const LINE_COMMENT_REGEXP = /(?:^|\s)\/\/(.+?)$/gm;
30
+ const BLOCK_COMMENT_REGEXP = /\/\*([\S\s]*?)\*\//gm;
31
+ const REGEXP = new RegExp(
32
+ `(${WORD_REGEXP.source}|${LEFT_ANGLE_REGEXP.source})|((?:${LINE_COMMENT_REGEXP.source})|(?:${BLOCK_COMMENT_REGEXP.source}))`,
33
+ 'gmi'
34
+ );
35
+
36
+ const COLORS = [
37
+ '23AC69',
38
+ '91C132',
39
+ 'F19726',
40
+ 'E8552D',
41
+ '1AAB8E',
42
+ 'E1147F',
43
+ '2980C1',
44
+ '1BA1E6',
45
+ '9FA0A0',
46
+ 'F19726',
47
+ 'E30B20',
48
+ 'E30B20',
49
+ 'A3338B',
50
+ ];
51
+ const cache: Record<string, string> = {};
52
+
53
+ export const defaultHighlighter = (input: string): string => {
54
+ let index = 0;
55
+
56
+ return input.replace(REGEXP, (_match, word: string, comment: string) => {
57
+ if (comment) return `<span style="color: slategray">${comment}</span>`;
58
+ if (word === '<') return '&lt;';
59
+
60
+ let color: string;
61
+
62
+ if (cache[word]) color = cache[word];
63
+ else {
64
+ color = COLORS[index];
65
+ cache[word] = color;
66
+ }
67
+
68
+ const out = `<span style="color: #${color}">${word}</span>`;
69
+
70
+ index = ++index % COLORS.length;
71
+
72
+ return out;
73
+ });
74
+ };
@@ -10,6 +10,8 @@ export default generateLocale([
10
10
  'Comment here...',
11
11
  'No comment yet.',
12
12
  'Submit',
13
+ 'Like',
14
+ 'Cancel like',
13
15
  'Reply',
14
16
  'Cancel reply',
15
17
  'Comments',
@@ -10,6 +10,8 @@ const localeKeys = [
10
10
  'placeholder',
11
11
  'sofa',
12
12
  'submit',
13
+ 'like',
14
+ 'cancelLike',
13
15
  'reply',
14
16
  'cancelReply',
15
17
  'comment',
@@ -10,6 +10,8 @@ export default generateLocale([
10
10
  'ここにコメント',
11
11
  'コメントしましょう~',
12
12
  '提出する',
13
+ 'Like',
14
+ 'Cancel like',
13
15
  '返信する',
14
16
  'キャンセル',
15
17
  'コメント',
@@ -10,6 +10,8 @@ export default generateLocale([
10
10
  'Comente aqui...',
11
11
  'Nenhum comentário, ainda.',
12
12
  'Enviar',
13
+ 'Like',
14
+ 'Cancel like',
13
15
  'Responder',
14
16
  'Cancelar resposta',
15
17
  'Comentários',
@@ -10,6 +10,8 @@ export default generateLocale([
10
10
  'Комментарий здесь...',
11
11
  'Пока нет комментариев.',
12
12
  'Отправить',
13
+ 'Like',
14
+ 'Cancel like',
13
15
  'Отвечать',
14
16
  'Отменить ответ',
15
17
  'Комментарии',
@@ -10,6 +10,8 @@ export default generateLocale([
10
10
  'Hãy bình luận có văn hoá!',
11
11
  'Chưa có bình luận',
12
12
  'Gửi',
13
+ 'Like',
14
+ 'Cancel like',
13
15
  'Trả lời',
14
16
  'Hủy bỏ',
15
17
  'bình luận',
@@ -10,6 +10,8 @@ export default generateLocale([
10
10
  '欢迎评论',
11
11
  '来发评论吧~',
12
12
  '提交',
13
+ '喜欢',
14
+ '取消喜欢',
13
15
  '回复',
14
16
  '取消回复',
15
17
  '评论',
@@ -10,6 +10,8 @@ export default generateLocale([
10
10
  '歡迎評論',
11
11
  '來發評論吧~',
12
12
  '提交',
13
+ '喜歡',
14
+ '取消喜歡',
13
15
  '回覆',
14
16
  '取消回覆',
15
17
  '評論',
@@ -1,2 +1,3 @@
1
1
  export * from './default';
2
+ export * from './highlighter';
2
3
  export * from './i18n';
@@ -101,6 +101,8 @@
101
101
  font-size: 0.75em;
102
102
  }
103
103
 
104
+ .wl-delete,
105
+ .wl-like,
104
106
  .wl-reply {
105
107
  float: right;
106
108
 
@@ -213,6 +215,28 @@
213
215
  }
214
216
  }
215
217
 
218
+ .wl-admin-actions {
219
+ margin: 8px 0;
220
+ text-align: right;
221
+ font-size: 12px;
222
+ }
223
+
224
+ .wl-comment-status {
225
+ margin: 0 8px;
226
+
227
+ .wl-btn {
228
+ border-radius: 0;
229
+
230
+ &:first-child {
231
+ border-radius: 0.5em 0 0 0.5em;
232
+ }
233
+
234
+ &:last-child {
235
+ border-radius: 0 0.5em 0.5em 0;
236
+ }
237
+ }
238
+ }
239
+
216
240
  .wl-quote {
217
241
  border-left: 1px dashed rgb(237 237 237 / 50%);
218
242
 
@@ -43,12 +43,6 @@ export type WalineMeta = 'nick' | 'mail' | 'link';
43
43
 
44
44
  export type WalineImageUploader = (image: File) => Promise<string>;
45
45
 
46
- export type WalineHighlighter =
47
- | ((code: string, lang: string) => string)
48
- | ((
49
- code: string,
50
- lang: string,
51
- callback?: (error: unknown | undefined, code?: string) => void
52
- ) => void);
46
+ export type WalineHighlighter = (code: string, lang: string) => string;
53
47
 
54
48
  export type WalineTexRenderer = (blockMode: boolean, tex: string) => string;
@@ -1,21 +1,71 @@
1
1
  export interface WalineCommentData {
2
+ /**
3
+ * User Nickname
4
+ */
2
5
  nick: string;
6
+
7
+ /**
8
+ * User email
9
+ */
3
10
  mail: string;
11
+
12
+ /**
13
+ * User link
14
+ */
4
15
  link?: string;
16
+
17
+ /**
18
+ * Content of comment
19
+ */
5
20
  comment: string;
21
+
22
+ /**
23
+ * User Agent
24
+ */
6
25
  ua: string;
7
26
 
27
+ /**
28
+ * Parent comment id
29
+ */
30
+
8
31
  pid?: string;
32
+
33
+ /**
34
+ * Root comment id
35
+ */
9
36
  rid?: string;
37
+
38
+ /**
39
+ * User id being at
40
+ */
10
41
  at?: string;
42
+
43
+ /**
44
+ * Comment link
45
+ */
11
46
  url: string;
12
47
  }
13
48
 
49
+ export type WalineCommentStatus = 'approved' | 'waiting' | 'spam';
50
+
14
51
  export interface WalineComment extends Exclude<WalineCommentData, 'ua'> {
52
+ /**
53
+ * User avatar
54
+ */
15
55
  avatar: string;
16
- type?: string;
56
+
57
+ /**
58
+ * User type
59
+ */
60
+ type?: 'administrator' | 'guest' | `verify:${string}`;
61
+
17
62
  objectId: string;
63
+
64
+ /**
65
+ * Time ISOString when the comment is created
66
+ */
18
67
  createdAt: string;
68
+
19
69
  insertedAt: string;
20
70
  updatedAt: string;
21
71
  children: WalineComment[];
@@ -25,4 +75,9 @@ export interface WalineComment extends Exclude<WalineCommentData, 'ua'> {
25
75
  level?: number;
26
76
  addr?: string;
27
77
  label?: string;
78
+ // TODO: Rename it to `userId` in next major version
79
+ // eslint-disable-next-line @typescript-eslint/naming-convention
80
+ user_id?: string | number;
81
+ status?: WalineCommentStatus;
82
+ like?: number;
28
83
  }
@@ -6,14 +6,7 @@ export interface WalineDateLocale {
6
6
  now: string;
7
7
  }
8
8
 
9
- export interface WalineLevelLocale {
10
- level0: string;
11
- level1: string;
12
- level2: string;
13
- level3: string;
14
- level4: string;
15
- level5: string;
16
- }
9
+ export type WalineLevelLocale = Record<`level${number}`, string>;
17
10
 
18
11
  export interface WalineLocale extends WalineDateLocale, WalineLevelLocale {
19
12
  nick: string;
@@ -25,6 +18,8 @@ export interface WalineLocale extends WalineDateLocale, WalineLevelLocale {
25
18
  placeholder: string;
26
19
  sofa: string;
27
20
  submit: string;
21
+ like: string;
22
+ cancelLike: string;
28
23
  reply: string;
29
24
  cancelReply: string;
30
25
  comment: string;
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  defaultLang,
3
3
  defaultUploadImage,
4
+ defaultHighlighter,
4
5
  defaultTexRenderer,
5
6
  getMeta,
6
7
  defaultLocales,
@@ -14,7 +15,6 @@ import type {
14
15
  WalineLocale,
15
16
  WalineProps,
16
17
  } from '../typings';
17
- import hanabi from 'hanabi';
18
18
 
19
19
  export interface WalineEmojiConfig {
20
20
  tabs: Pick<WalineEmojiInfo, 'name' | 'icon' | 'items'>[];
@@ -68,12 +68,12 @@ export const getConfig = ({
68
68
  locale: {
69
69
  ...(defaultLocales[lang] || defaultLocales[defaultLang]),
70
70
  ...(typeof locale === 'object' ? locale : {}),
71
- },
71
+ } as WalineLocale,
72
72
  wordLimit: getWordLimit(wordLimit),
73
73
  meta: getMeta(meta),
74
74
  requiredMeta: getMeta(requiredMeta),
75
75
  imageUploader: fallback(imageUploader, defaultUploadImage),
76
- highlighter: fallback(highlighter, hanabi),
76
+ highlighter: fallback(highlighter, defaultHighlighter),
77
77
  texRenderer: fallback(texRenderer, defaultTexRenderer),
78
78
  lang,
79
79
  dark,
@@ -5,6 +5,11 @@ export interface FetchErrorData {
5
5
  errmsg: string;
6
6
  }
7
7
 
8
+ const JSON_HEADERS: Record<string, string> = {
9
+ // eslint-disable-next-line @typescript-eslint/naming-convention
10
+ 'Content-Type': 'application/json',
11
+ };
12
+
8
13
  const errorCheck = <T = unknown>(data: T | FetchErrorData, name = ''): T => {
9
14
  if (typeof data === 'object' && (data as FetchErrorData).errno)
10
15
  throw new TypeError(
@@ -143,6 +148,77 @@ export const postComment = ({
143
148
  }).then((resp) => resp.json() as Promise<PostCommentResponse>);
144
149
  };
145
150
 
151
+ export interface DeleteCommentOptions {
152
+ serverURL: string;
153
+ lang: string;
154
+ token: string;
155
+ objectId: string | number;
156
+ }
157
+
158
+ export const deleteComment = ({
159
+ serverURL,
160
+ lang,
161
+ token,
162
+ objectId,
163
+ }: DeleteCommentOptions): Promise<void> => {
164
+ const headers: Record<string, string> = {
165
+ Authorization: `Bearer ${token}`,
166
+ };
167
+
168
+ return fetch(`${serverURL}/comment/${objectId}?lang=${lang}`, {
169
+ method: 'DELETE',
170
+ headers,
171
+ }).then((resp) => resp.json() as Promise<void>);
172
+ };
173
+
174
+ export interface LikeCommentOptions {
175
+ serverURL: string;
176
+ lang: string;
177
+ objectId: number | string;
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) => resp.json() as Promise<void>);
192
+
193
+ export interface UpdateCommentOptions {
194
+ serverURL: string;
195
+ lang: string;
196
+ token: string;
197
+ objectId: number | string;
198
+ status?: 'approved' | 'waiting' | 'spam';
199
+ sticky?: number;
200
+ }
201
+
202
+ export const updateComment = ({
203
+ serverURL,
204
+ lang,
205
+ token,
206
+ objectId,
207
+ ...data
208
+ }: UpdateCommentOptions): Promise<void> => {
209
+ const headers: Record<string, string> = {
210
+ // eslint-disable-next-line @typescript-eslint/naming-convention
211
+ 'Content-Type': 'application/json',
212
+ Authorization: `Bearer ${token}`,
213
+ };
214
+
215
+ return fetch(`${serverURL}/comment/${objectId}?lang=${lang}`, {
216
+ method: 'PUT',
217
+ headers,
218
+ body: JSON.stringify(data),
219
+ }).then((resp) => resp.json() as Promise<void>);
220
+ };
221
+
146
222
  export interface FetchPageviewsOptions {
147
223
  serverURL: string;
148
224
  lang: string;
@@ -180,10 +256,7 @@ export const updatePageviews = ({
180
256
  }: UpdatePageviewsOptions): Promise<number> =>
181
257
  fetch(`${serverURL}/article?lang=${lang}`, {
182
258
  method: 'POST',
183
- headers: {
184
- // eslint-disable-next-line @typescript-eslint/naming-convention
185
- 'Content-Type': 'application/json',
186
- },
259
+ headers: JSON_HEADERS,
187
260
  body: JSON.stringify({ path }),
188
261
  })
189
262
  .then((resp) => resp.json() as Promise<number>)
@@ -1,9 +0,0 @@
1
- declare module 'hanabi' {
2
- const hanabi: (
3
- code: string,
4
- lang: string,
5
- callback?: (error: unknown, code?: string | undefined) => void
6
- ) => string | void;
7
-
8
- export default hanabi;
9
- }