@waline/client 2.3.1 → 2.4.1

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 (55) 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 +3 -8
  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 +45 -10
  17. package/dist/shim.esm.d.ts +45 -10
  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 +45 -10
  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 +45 -10
  28. package/dist/waline.esm.d.ts +45 -10
  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 +20 -5
  34. package/src/components/CommentBox.vue +1 -3
  35. package/src/components/CommentCard.vue +80 -14
  36. package/src/components/Icons.ts +28 -2
  37. package/src/components/Waline.vue +220 -98
  38. package/src/composables/index.ts +1 -0
  39. package/src/composables/like.ts +14 -0
  40. package/src/composables/userInfo.ts +9 -1
  41. package/src/config/i18n/en.ts +2 -0
  42. package/src/config/i18n/generate.ts +2 -0
  43. package/src/config/i18n/jp.ts +2 -0
  44. package/src/config/i18n/pt-BR.ts +2 -0
  45. package/src/config/i18n/ru.ts +2 -0
  46. package/src/config/i18n/vi-VN.ts +2 -0
  47. package/src/config/i18n/zh-CN.ts +2 -0
  48. package/src/config/i18n/zh-TW.ts +2 -0
  49. package/src/styles/card.scss +55 -27
  50. package/src/styles/nomalize.scss +0 -1
  51. package/src/styles/panel.scss +0 -1
  52. package/src/typings/comment.ts +56 -1
  53. package/src/typings/locale.ts +3 -8
  54. package/src/utils/config.ts +1 -1
  55. package/src/utils/fetch.ts +77 -4
@@ -10,11 +10,19 @@ export interface UserInfo {
10
10
  token: string;
11
11
  avatar: string;
12
12
  mailMd5: string;
13
+ objectId: string | number;
14
+ type: 'administrator' | 'guest';
13
15
  }
14
16
 
15
17
  export const USER_KEY = 'WALINE_USER';
16
18
 
17
19
  export type UserInfoRef = Ref<UserInfo | Record<string, never>>;
18
20
 
21
+ let userInfoStorage: UserInfoRef | null = null;
22
+
19
23
  export const useUserInfo = (): UserInfoRef =>
20
- useStorage<UserInfo | Record<string, never>>('USER_KEY', {});
24
+ userInfoStorage ||
25
+ (userInfoStorage = useStorage<UserInfo | Record<string, never>>(
26
+ 'USER_KEY',
27
+ {}
28
+ ));
@@ -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
  '評論',
@@ -18,13 +18,13 @@
18
18
  .wl-user {
19
19
  --avatar-size: var(--waline-avatar-size);
20
20
 
21
+ position: relative;
22
+ margin-right: 0.75em;
23
+
21
24
  @media (max-width: 720px) {
22
25
  --avatar-size: var(--waline-m-avatar-size);
23
26
  }
24
27
 
25
- position: relative;
26
- margin-right: 0.75em;
27
-
28
28
  img {
29
29
  width: var(--avatar-size);
30
30
  height: var(--avatar-size);
@@ -101,30 +101,6 @@
101
101
  font-size: 0.75em;
102
102
  }
103
103
 
104
- .wl-reply {
105
- float: right;
106
-
107
- padding: 4px;
108
- border: none;
109
-
110
- background: transparent;
111
- color: var(--waline-color);
112
-
113
- line-height: 1;
114
-
115
- cursor: pointer;
116
-
117
- transition: color 0.2s ease;
118
-
119
- &:hover {
120
- color: var(--waline-theme-color);
121
- }
122
-
123
- &.active {
124
- color: var(--waline-active-color);
125
- }
126
- }
127
-
128
104
  .wl-meta {
129
105
  position: relative;
130
106
  line-height: 1;
@@ -152,6 +128,36 @@
152
128
  }
153
129
  }
154
130
 
131
+ .wl-comment-actions {
132
+ float: right;
133
+ }
134
+
135
+ .wl-delete,
136
+ .wl-like,
137
+ .wl-reply {
138
+ display: inline-flex;
139
+ align-items: center;
140
+ padding: 4px;
141
+ border: none;
142
+
143
+ background: transparent;
144
+ color: var(--waline-color);
145
+
146
+ line-height: 1;
147
+
148
+ cursor: pointer;
149
+
150
+ transition: color 0.2s ease;
151
+
152
+ &:hover {
153
+ color: var(--waline-theme-color);
154
+ }
155
+
156
+ &.active {
157
+ color: var(--waline-active-color);
158
+ }
159
+ }
160
+
155
161
  .wl-content {
156
162
  position: relative;
157
163
 
@@ -213,6 +219,28 @@
213
219
  }
214
220
  }
215
221
 
222
+ .wl-admin-actions {
223
+ margin: 8px 0;
224
+ font-size: 12px;
225
+ text-align: right;
226
+ }
227
+
228
+ .wl-comment-status {
229
+ margin: 0 8px;
230
+
231
+ .wl-btn {
232
+ border-radius: 0;
233
+
234
+ &:first-child {
235
+ border-radius: 0.5em 0 0 0.5em;
236
+ }
237
+
238
+ &:last-child {
239
+ border-radius: 0 0.5em 0.5em 0;
240
+ }
241
+ }
242
+ }
243
+
216
244
  .wl-quote {
217
245
  border-left: 1px dashed rgb(237 237 237 / 50%);
218
246
 
@@ -19,7 +19,6 @@
19
19
  color: var(--waline-theme-color);
20
20
 
21
21
  text-decoration: none;
22
-
23
22
  word-break: break-word;
24
23
 
25
24
  cursor: pointer;
@@ -196,7 +196,6 @@
196
196
  .wl-content {
197
197
  min-height: 1.25em;
198
198
  padding: 0.25em;
199
-
200
199
  word-break: break-word;
201
200
  hyphens: auto;
202
201
 
@@ -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;
@@ -68,7 +68,7 @@ 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),
@@ -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>)