@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.
- package/dist/component.esm.js +1 -1
- package/dist/component.esm.js.map +1 -1
- package/dist/component.js +1 -1
- package/dist/component.js.map +1 -1
- package/dist/legacy.d.ts +4 -9
- package/dist/legacy.js +1 -1
- package/dist/legacy.js.map +1 -1
- package/dist/pageview.cjs.d.ts +47 -0
- package/dist/pageview.cjs.js +1 -1
- package/dist/pageview.cjs.js.map +1 -1
- package/dist/pageview.esm.d.ts +47 -0
- package/dist/pageview.esm.js +1 -1
- package/dist/pageview.esm.js.map +1 -1
- package/dist/pageview.js +1 -1
- package/dist/pageview.js.map +1 -1
- package/dist/shim.d.ts +46 -11
- package/dist/shim.esm.d.ts +46 -11
- package/dist/shim.esm.js +1 -1
- package/dist/shim.esm.js.map +1 -1
- package/dist/shim.js +1 -1
- package/dist/shim.js.map +1 -1
- package/dist/waline.cjs.d.ts +46 -11
- package/dist/waline.cjs.js +1 -1
- package/dist/waline.cjs.js.map +1 -1
- package/dist/waline.css +1 -1
- package/dist/waline.css.map +1 -1
- package/dist/waline.d.ts +46 -11
- package/dist/waline.esm.d.ts +46 -11
- package/dist/waline.esm.js +1 -1
- package/dist/waline.esm.js.map +1 -1
- package/dist/waline.js +1 -1
- package/dist/waline.js.map +1 -1
- package/package.json +6 -7
- package/src/components/CommentBox.vue +1 -3
- package/src/components/CommentCard.vue +69 -6
- package/src/components/Icons.ts +28 -2
- package/src/components/Waline.vue +200 -112
- package/src/composables/index.ts +1 -0
- package/src/composables/likeStorage.ts +11 -0
- package/src/composables/userInfo.ts +2 -0
- package/src/config/highlighter.ts +74 -0
- package/src/config/i18n/en.ts +2 -0
- package/src/config/i18n/generate.ts +2 -0
- package/src/config/i18n/jp.ts +2 -0
- package/src/config/i18n/pt-BR.ts +2 -0
- package/src/config/i18n/ru.ts +2 -0
- package/src/config/i18n/vi-VN.ts +2 -0
- package/src/config/i18n/zh-CN.ts +2 -0
- package/src/config/i18n/zh-TW.ts +2 -0
- package/src/config/index.ts +1 -0
- package/src/styles/card.scss +24 -0
- package/src/typings/base.ts +1 -7
- package/src/typings/comment.ts +56 -1
- package/src/typings/locale.ts +3 -8
- package/src/utils/config.ts +3 -3
- package/src/utils/fetch.ts +77 -4
- 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 '<';
|
|
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
|
+
};
|
package/src/config/i18n/en.ts
CHANGED
package/src/config/i18n/jp.ts
CHANGED
package/src/config/i18n/pt-BR.ts
CHANGED
package/src/config/i18n/ru.ts
CHANGED
package/src/config/i18n/vi-VN.ts
CHANGED
package/src/config/i18n/zh-CN.ts
CHANGED
package/src/config/i18n/zh-TW.ts
CHANGED
package/src/config/index.ts
CHANGED
package/src/styles/card.scss
CHANGED
|
@@ -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
|
|
package/src/typings/base.ts
CHANGED
|
@@ -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;
|
package/src/typings/comment.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
}
|
package/src/typings/locale.ts
CHANGED
|
@@ -6,14 +6,7 @@ export interface WalineDateLocale {
|
|
|
6
6
|
now: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export
|
|
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;
|
package/src/utils/config.ts
CHANGED
|
@@ -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,
|
|
76
|
+
highlighter: fallback(highlighter, defaultHighlighter),
|
|
77
77
|
texRenderer: fallback(texRenderer, defaultTexRenderer),
|
|
78
78
|
lang,
|
|
79
79
|
dark,
|
package/src/utils/fetch.ts
CHANGED
|
@@ -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>)
|