@waline/client 2.15.8 → 3.0.0-alpha.2
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/comment.cjs +1 -1
- package/dist/comment.cjs.map +1 -1
- package/dist/comment.d.cts +2 -1
- package/dist/comment.d.mts +2 -1
- package/dist/comment.d.ts +2 -1
- package/dist/comment.js +1 -1
- package/dist/comment.js.map +1 -1
- package/dist/comment.mjs +1 -1
- package/dist/comment.mjs.map +1 -1
- package/dist/component.mjs +8 -1
- package/dist/component.mjs.map +1 -1
- package/dist/pageview.cjs +1 -1
- package/dist/pageview.cjs.map +1 -1
- package/dist/pageview.d.cts +2 -1
- package/dist/pageview.d.mts +2 -1
- package/dist/pageview.d.ts +2 -1
- package/dist/pageview.js +1 -1
- package/dist/pageview.js.map +1 -1
- package/dist/pageview.mjs +1 -1
- package/dist/pageview.mjs.map +1 -1
- package/dist/shim.cjs +8 -1
- package/dist/shim.cjs.map +1 -1
- package/dist/shim.d.cts +7 -82
- package/dist/shim.d.mts +7 -82
- package/dist/shim.mjs +8 -1
- package/dist/shim.mjs.map +1 -1
- package/dist/waline.cjs +53 -1
- package/dist/waline.cjs.map +1 -1
- package/dist/waline.css +1 -1
- package/dist/waline.css.map +1 -1
- package/dist/waline.d.cts +7 -82
- package/dist/waline.d.mts +7 -82
- package/dist/waline.d.ts +7 -82
- package/dist/waline.js +53 -1
- package/dist/waline.js.map +1 -1
- package/dist/waline.mjs +53 -1
- package/dist/waline.mjs.map +1 -1
- package/package.json +20 -53
- package/dist/api.cjs +0 -2
- package/dist/api.cjs.map +0 -1
- package/dist/api.d.cts +0 -445
- package/dist/api.d.mts +0 -445
- package/dist/api.d.ts +0 -445
- package/dist/api.mjs +0 -2
- package/dist/api.mjs.map +0 -1
- package/dist/legacy.umd.d.ts +0 -628
- package/dist/legacy.umd.js +0 -2
- package/dist/legacy.umd.js.map +0 -1
- package/src/api/articleCounter.ts +0 -82
- package/src/api/comment.ts +0 -258
- package/src/api/commentCount.ts +0 -33
- package/src/api/index.ts +0 -7
- package/src/api/login.ts +0 -96
- package/src/api/pageview.ts +0 -54
- package/src/api/recentComment.ts +0 -42
- package/src/api/user.ts +0 -44
- package/src/api/utils.ts +0 -46
- package/src/comment.ts +0 -69
- package/src/compact/convert.ts +0 -80
- package/src/compact/dropped.ts +0 -35
- package/src/compact/index.ts +0 -4
- package/src/compact/logger.ts +0 -5
- package/src/compact/v1.ts +0 -103
- package/src/compact/valine.ts +0 -132
- package/src/components/ArticleReaction.vue +0 -159
- package/src/components/CommentBox.vue +0 -807
- package/src/components/CommentCard.vue +0 -271
- package/src/components/Icons.ts +0 -181
- package/src/components/ImageWall.vue +0 -169
- package/src/components/WalineComment.vue +0 -353
- package/src/composables/index.ts +0 -6
- package/src/composables/inputs.ts +0 -17
- package/src/composables/like.ts +0 -13
- package/src/composables/reaction.ts +0 -15
- package/src/composables/recaptchaV3.ts +0 -19
- package/src/composables/turnstile.ts +0 -50
- package/src/composables/userInfo.ts +0 -16
- package/src/config/default.ts +0 -93
- package/src/config/highlighter.ts +0 -74
- package/src/config/i18n/en.ts +0 -53
- package/src/config/i18n/generate.ts +0 -58
- package/src/config/i18n/index.ts +0 -30
- package/src/config/i18n/jp.ts +0 -53
- package/src/config/i18n/pt-BR.ts +0 -53
- package/src/config/i18n/ru.ts +0 -53
- package/src/config/i18n/vi-VN.ts +0 -53
- package/src/config/i18n/zh-CN.ts +0 -53
- package/src/config/i18n/zh-TW.ts +0 -53
- package/src/config/index.ts +0 -3
- package/src/entries/api.ts +0 -1
- package/src/entries/comment.ts +0 -2
- package/src/entries/components.ts +0 -2
- package/src/entries/full.ts +0 -7
- package/src/entries/init.ts +0 -4
- package/src/entries/legacy.ts +0 -31
- package/src/entries/pageview.ts +0 -2
- package/src/init.ts +0 -112
- package/src/pageview.ts +0 -116
- package/src/shims-vue.d.ts +0 -6
- package/src/styles/base.scss +0 -67
- package/src/styles/card.scss +0 -258
- package/src/styles/config.scss +0 -52
- package/src/styles/emoji.scss +0 -137
- package/src/styles/gif.scss +0 -73
- package/src/styles/helpers/_svg.scss +0 -51
- package/src/styles/highlight.scss +0 -138
- package/src/styles/index.scss +0 -12
- package/src/styles/layout.scss +0 -105
- package/src/styles/meta.scss +0 -82
- package/src/styles/normalize.scss +0 -117
- package/src/styles/panel.scss +0 -286
- package/src/styles/reaction.scss +0 -103
- package/src/styles/recent.scss +0 -3
- package/src/styles/user-list.scss +0 -159
- package/src/typings/base.ts +0 -123
- package/src/typings/comment.ts +0 -94
- package/src/typings/index.ts +0 -5
- package/src/typings/locale.ts +0 -73
- package/src/typings/options.ts +0 -44
- package/src/typings/waline.ts +0 -251
- package/src/utils/config.ts +0 -122
- package/src/utils/darkmode.ts +0 -11
- package/src/utils/date.ts +0 -71
- package/src/utils/email.ts +0 -8
- package/src/utils/emoji.ts +0 -73
- package/src/utils/error.ts +0 -3
- package/src/utils/getRoot.ts +0 -8
- package/src/utils/image.ts +0 -10
- package/src/utils/index.ts +0 -13
- package/src/utils/markdown.ts +0 -41
- package/src/utils/markedMathExtension.ts +0 -54
- package/src/utils/path.ts +0 -15
- package/src/utils/query.ts +0 -2
- package/src/utils/userAgent.ts +0 -31
- package/src/utils/wordCount.ts +0 -31
- package/src/version.ts +0 -3
- package/src/widgets/index.ts +0 -2
- package/src/widgets/recentComments.ts +0 -93
- package/src/widgets/userList.ts +0 -136
package/src/comment.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { fetchCommentCount } from './api/index.js';
|
|
2
|
-
import { type WalineAbort } from './typings/index.js';
|
|
3
|
-
import { decodePath, errorHandler, getServerURL } from './utils/index.js';
|
|
4
|
-
|
|
5
|
-
export interface WalineCommentCountOptions {
|
|
6
|
-
/**
|
|
7
|
-
* Waline 服务端地址
|
|
8
|
-
*
|
|
9
|
-
* Waline server url
|
|
10
|
-
*/
|
|
11
|
-
serverURL: string;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 评论数 CSS 选择器
|
|
15
|
-
*
|
|
16
|
-
* Comment count CSS selector
|
|
17
|
-
*
|
|
18
|
-
* @default '.waline-comment-count'
|
|
19
|
-
*/
|
|
20
|
-
selector?: string;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 需要获取的默认路径
|
|
24
|
-
*
|
|
25
|
-
* Path to be fetched by default
|
|
26
|
-
*
|
|
27
|
-
* @default window.location.pathname
|
|
28
|
-
*/
|
|
29
|
-
path?: string;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 错误提示消息所使用的语言
|
|
33
|
-
*
|
|
34
|
-
* Language of error message
|
|
35
|
-
*
|
|
36
|
-
* @default navigator.language
|
|
37
|
-
*/
|
|
38
|
-
lang?: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const commentCount = ({
|
|
42
|
-
serverURL,
|
|
43
|
-
path = window.location.pathname,
|
|
44
|
-
selector = '.waline-comment-count',
|
|
45
|
-
lang = navigator.language,
|
|
46
|
-
}: WalineCommentCountOptions): WalineAbort => {
|
|
47
|
-
const controller = new AbortController();
|
|
48
|
-
|
|
49
|
-
// comment count
|
|
50
|
-
const elements = document.querySelectorAll<HTMLElement>(selector);
|
|
51
|
-
|
|
52
|
-
if (elements.length)
|
|
53
|
-
void fetchCommentCount({
|
|
54
|
-
serverURL: getServerURL(serverURL),
|
|
55
|
-
paths: Array.from(elements).map((element) =>
|
|
56
|
-
decodePath(element.dataset.path || element.getAttribute('id') || path),
|
|
57
|
-
),
|
|
58
|
-
lang,
|
|
59
|
-
signal: controller.signal,
|
|
60
|
-
})
|
|
61
|
-
.then((counts) => {
|
|
62
|
-
elements.forEach((element, index) => {
|
|
63
|
-
element.innerText = counts[index].toString();
|
|
64
|
-
});
|
|
65
|
-
})
|
|
66
|
-
.catch(errorHandler);
|
|
67
|
-
|
|
68
|
-
return controller.abort.bind(controller);
|
|
69
|
-
};
|
package/src/compact/convert.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DROPPED_OPTIONS_WHICH_CAN_NOT_BE_POLYFILLED,
|
|
3
|
-
DROPPED_OPTIONS_WHICH_CAN_STILL_BE_POLYFILLED,
|
|
4
|
-
} from './dropped.js';
|
|
5
|
-
import { warning } from './logger.js';
|
|
6
|
-
import { type DeprecatedWalineOptions } from './v1.js';
|
|
7
|
-
import { resolveOldEmojiMap, type DeprecatedValineOptions } from './valine.js';
|
|
8
|
-
import { type WalineInitOptions } from '../typings/index.js';
|
|
9
|
-
|
|
10
|
-
export const covertOptions = (
|
|
11
|
-
options: WalineInitOptions &
|
|
12
|
-
DeprecatedValineOptions &
|
|
13
|
-
DeprecatedWalineOptions,
|
|
14
|
-
): WalineInitOptions => {
|
|
15
|
-
const {
|
|
16
|
-
// Options which needs to be polyfilled
|
|
17
|
-
placeholder,
|
|
18
|
-
langMode = {},
|
|
19
|
-
emojiCDN,
|
|
20
|
-
emojiMaps,
|
|
21
|
-
requiredFields = [],
|
|
22
|
-
anonymous,
|
|
23
|
-
previewMath,
|
|
24
|
-
uploadImage,
|
|
25
|
-
highlight,
|
|
26
|
-
copyRight,
|
|
27
|
-
visitor,
|
|
28
|
-
|
|
29
|
-
pageview = visitor === true
|
|
30
|
-
? '.leancloud_visitors,.leancloud-visitors,.waline-visitor-count,.waline-pageview-count'
|
|
31
|
-
: visitor,
|
|
32
|
-
locale = langMode,
|
|
33
|
-
emoji,
|
|
34
|
-
requiredMeta = requiredFields,
|
|
35
|
-
highlighter = highlight,
|
|
36
|
-
imageUploader = uploadImage,
|
|
37
|
-
texRenderer = previewMath,
|
|
38
|
-
copyright = copyRight,
|
|
39
|
-
login = anonymous === true
|
|
40
|
-
? 'disable'
|
|
41
|
-
: anonymous === false
|
|
42
|
-
? 'force'
|
|
43
|
-
: 'enable',
|
|
44
|
-
...more
|
|
45
|
-
} = options;
|
|
46
|
-
|
|
47
|
-
// error with those which can no longer be handled
|
|
48
|
-
DROPPED_OPTIONS_WHICH_CAN_NOT_BE_POLYFILLED.filter((item) =>
|
|
49
|
-
Object.keys(options).includes(item),
|
|
50
|
-
).forEach((item) =>
|
|
51
|
-
warning(`Option "${item}" is REMOVED and CAN NOT be polyfilled!`),
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
// warnings with those which is being polyfilled
|
|
55
|
-
DROPPED_OPTIONS_WHICH_CAN_STILL_BE_POLYFILLED.filter(([oldOption]) =>
|
|
56
|
-
Object.keys(options).includes(oldOption),
|
|
57
|
-
).forEach(([oldOption, newOption]) =>
|
|
58
|
-
warning(
|
|
59
|
-
`Deprecated option "${oldOption}" is currently being polyfilled, Please switch to option "${newOption}" in v2!`,
|
|
60
|
-
),
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
if (placeholder) locale.placeholder = placeholder;
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
locale,
|
|
67
|
-
emoji:
|
|
68
|
-
emojiCDN && typeof emojiMaps === 'object'
|
|
69
|
-
? resolveOldEmojiMap(emojiMaps, emojiCDN)
|
|
70
|
-
: emoji,
|
|
71
|
-
requiredMeta,
|
|
72
|
-
imageUploader,
|
|
73
|
-
highlighter,
|
|
74
|
-
texRenderer,
|
|
75
|
-
copyright,
|
|
76
|
-
login,
|
|
77
|
-
pageview,
|
|
78
|
-
...more,
|
|
79
|
-
};
|
|
80
|
-
};
|
package/src/compact/dropped.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export const DROPPED_OPTIONS_WHICH_CAN_NOT_BE_POLYFILLED: string[] = [
|
|
2
|
-
// valine
|
|
3
|
-
'region',
|
|
4
|
-
'appId',
|
|
5
|
-
'appKey',
|
|
6
|
-
'notify',
|
|
7
|
-
'verify',
|
|
8
|
-
'avatar',
|
|
9
|
-
'avatarForce',
|
|
10
|
-
'enableQQ',
|
|
11
|
-
'recordIP',
|
|
12
|
-
'serverURLs',
|
|
13
|
-
|
|
14
|
-
// waline v1
|
|
15
|
-
'avatarCDN',
|
|
16
|
-
'mathTagSupport',
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
export const DROPPED_OPTIONS_WHICH_CAN_STILL_BE_POLYFILLED: [string, string][] =
|
|
20
|
-
[
|
|
21
|
-
// valine
|
|
22
|
-
['emojiCDN', 'emoji'],
|
|
23
|
-
['emojiMaps', 'emoji'],
|
|
24
|
-
['requiredFields', 'requiredMeta'],
|
|
25
|
-
['visitor', 'pageview'],
|
|
26
|
-
['langMode', 'locale'],
|
|
27
|
-
['placeholder', 'locale.placeholder'],
|
|
28
|
-
|
|
29
|
-
// waline v1
|
|
30
|
-
['highlight', 'highlighter'],
|
|
31
|
-
['uploadImage', 'imageUploader'],
|
|
32
|
-
['previewMath', 'texRenderer'],
|
|
33
|
-
['anonymous', 'login'],
|
|
34
|
-
['copyRight', 'copyright'],
|
|
35
|
-
];
|
package/src/compact/index.ts
DELETED
package/src/compact/logger.ts
DELETED
package/src/compact/v1.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type WalineHighlighter,
|
|
3
|
-
type WalineImageUploader,
|
|
4
|
-
type WalineTeXRenderer,
|
|
5
|
-
} from '../typings/index.js';
|
|
6
|
-
|
|
7
|
-
export interface DeprecatedWalineOptions {
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated Please use mathjax in server, dropped in V2
|
|
10
|
-
*
|
|
11
|
-
* 是否注入额外的样式添加对 `<math>` 块的兼容
|
|
12
|
-
*
|
|
13
|
-
* Whether injecting additional styles to support math block
|
|
14
|
-
*
|
|
15
|
-
* @default false
|
|
16
|
-
*/
|
|
17
|
-
mathTagSupport?: boolean;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated use `pageview` instead, dropped in V2
|
|
21
|
-
*
|
|
22
|
-
* 文章访问量统计
|
|
23
|
-
*
|
|
24
|
-
* Article reading statistics
|
|
25
|
-
*
|
|
26
|
-
* @default false
|
|
27
|
-
*/
|
|
28
|
-
visitor?: boolean;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @deprecated use `highlighter` instead, dropped in V2
|
|
32
|
-
*
|
|
33
|
-
* 代码高亮
|
|
34
|
-
*
|
|
35
|
-
* Code highlighting
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
highlight?: WalineHighlighter | false;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @deprecated use `imageUploader` instead, dropped in V2
|
|
42
|
-
*
|
|
43
|
-
* 自定义图片上传方法,方便更好的存储图片
|
|
44
|
-
*
|
|
45
|
-
* 方法执行时会将图片对象传入。
|
|
46
|
-
*
|
|
47
|
-
* Custom image upload callback to manage picture by yourself.
|
|
48
|
-
*
|
|
49
|
-
* We will pass a picture file object when execute it.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
uploadImage?: WalineImageUploader | false;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @deprecated Use `login` instead, dropped in V2
|
|
56
|
-
*
|
|
57
|
-
* 是否允许登录评论
|
|
58
|
-
*
|
|
59
|
-
* 默认情况是两者都支持,设置为 `true` 表示仅支持匿名评论,`false` 表示仅支持登录评论。
|
|
60
|
-
*
|
|
61
|
-
* Whether to allow login comments.
|
|
62
|
-
*
|
|
63
|
-
* Both supported by default, set to `true` means only support anonymous comments, `false` means only support login comments.
|
|
64
|
-
*
|
|
65
|
-
* @default undefined
|
|
66
|
-
*/
|
|
67
|
-
anonymous?: boolean;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @deprecated Please use `AVATAR_PROXY` in server, dropped in V2
|
|
71
|
-
*
|
|
72
|
-
* 设置 Gravatar 头像 CDN 地址
|
|
73
|
-
*
|
|
74
|
-
* Gravatar CDN baseURL
|
|
75
|
-
*
|
|
76
|
-
* @default 'https://www.gravatar.com/avatar'
|
|
77
|
-
*/
|
|
78
|
-
avatarCDN?: string;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @deprecated Use `texRenderer` instead, dropped in V2
|
|
82
|
-
*
|
|
83
|
-
* 自定义 TeX 处理方法,用于预览。
|
|
84
|
-
*
|
|
85
|
-
* Custom math formula parse callback for preview.
|
|
86
|
-
*/
|
|
87
|
-
previewMath?: WalineTeXRenderer | false;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @deprecated use `copyright` instead, dropped in V2
|
|
91
|
-
*
|
|
92
|
-
* 是否在页脚展示版权信息
|
|
93
|
-
*
|
|
94
|
-
* 为了支持 Waline,我们强烈建议你开启它
|
|
95
|
-
*
|
|
96
|
-
* Whether show copyright in footer
|
|
97
|
-
*
|
|
98
|
-
* We strongly recommended you to keep it on to support waline
|
|
99
|
-
*
|
|
100
|
-
* @default true
|
|
101
|
-
*/
|
|
102
|
-
copyRight?: boolean;
|
|
103
|
-
}
|
package/src/compact/valine.ts
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type WalineEmojiInfo,
|
|
3
|
-
type WalineEmojiMaps,
|
|
4
|
-
type WalineLocale,
|
|
5
|
-
type WalineMeta,
|
|
6
|
-
} from '../typings/index.js';
|
|
7
|
-
|
|
8
|
-
export type DeprecatedAvatar =
|
|
9
|
-
| ''
|
|
10
|
-
| 'mp'
|
|
11
|
-
| 'identicon'
|
|
12
|
-
| 'monsterid'
|
|
13
|
-
| 'wavatar'
|
|
14
|
-
| 'retro'
|
|
15
|
-
| 'robohash'
|
|
16
|
-
| 'hide';
|
|
17
|
-
|
|
18
|
-
export type DeprecatedEmojiMaps = Record<string, string>;
|
|
19
|
-
|
|
20
|
-
export interface DeprecatedValineOptions {
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Use `locale.placeholder` instead, dropped in V2
|
|
23
|
-
*/
|
|
24
|
-
placeholder?: string;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @deprecated Use `locale` instead, dropped in V2
|
|
28
|
-
*/
|
|
29
|
-
langMode?: Partial<WalineLocale>;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @deprecated Use `requiredMeta` instead, dropped in V2
|
|
33
|
-
*/
|
|
34
|
-
requiredFields?: WalineMeta[];
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @deprecated Please use `AVATAR_PROXY` in server, dropped in V2
|
|
38
|
-
*
|
|
39
|
-
* [Gravatar](http://cn.gravatar.com/) 头像展示方式
|
|
40
|
-
*
|
|
41
|
-
* 可选值:
|
|
42
|
-
*
|
|
43
|
-
* - `''`
|
|
44
|
-
* - `'mp'`
|
|
45
|
-
* - `'identicon'`
|
|
46
|
-
* - `'monsterid'`
|
|
47
|
-
* - `'wavatar'`
|
|
48
|
-
* - `'retro'`
|
|
49
|
-
* - `'robohash'`
|
|
50
|
-
* - `'hide'`
|
|
51
|
-
*
|
|
52
|
-
* [Gravatar](http://gravatar.com/) type
|
|
53
|
-
*
|
|
54
|
-
* Optional value:
|
|
55
|
-
*
|
|
56
|
-
* - `''`
|
|
57
|
-
* - `'mp'`
|
|
58
|
-
* - `'identicon'`
|
|
59
|
-
* - `'monsterid'`
|
|
60
|
-
* - `'wavatar'`
|
|
61
|
-
* - `'retro'`
|
|
62
|
-
* - `'robohash'`
|
|
63
|
-
* - `'hide'`
|
|
64
|
-
*
|
|
65
|
-
* @default 'mp'
|
|
66
|
-
*/
|
|
67
|
-
avatar?: DeprecatedAvatar;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @deprecated no longer needed, dropped in V2
|
|
71
|
-
*
|
|
72
|
-
* 每次访问是否**强制**拉取最新的*评论列表头像*
|
|
73
|
-
*
|
|
74
|
-
* Whether **force** pulling the latest avatar each time
|
|
75
|
-
*
|
|
76
|
-
* @default false
|
|
77
|
-
*/
|
|
78
|
-
avatarForce?: boolean;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* @deprecated Use `emojis` instead, dropped in V2
|
|
82
|
-
*
|
|
83
|
-
* 设置**表情包 CDN**
|
|
84
|
-
*
|
|
85
|
-
* @see [自定义表情包](https://waline.js.org/client/emoji.html)
|
|
86
|
-
*
|
|
87
|
-
* Set **Emoji Pack CDN**
|
|
88
|
-
*
|
|
89
|
-
* @see [Custom Emoji](https://waline.js.org/en/client/emoji.html)
|
|
90
|
-
*
|
|
91
|
-
* @default 'https://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/'
|
|
92
|
-
*/
|
|
93
|
-
emojiCDN?: string;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* @deprecated Use `emojis` instead, dropped in V2
|
|
97
|
-
*
|
|
98
|
-
* 设置**表情包映射**
|
|
99
|
-
*
|
|
100
|
-
* @see [自定义表情](https://waline.js.org/client/emoji.html)
|
|
101
|
-
*
|
|
102
|
-
* Set **emoji maps**
|
|
103
|
-
*
|
|
104
|
-
* @see [Custom Emoji](https://waline.js.org/en/client/emoji.html)
|
|
105
|
-
*
|
|
106
|
-
* @default 微博表情包
|
|
107
|
-
*/
|
|
108
|
-
|
|
109
|
-
emojiMaps?: DeprecatedEmojiMaps;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// TODO: remove
|
|
113
|
-
export const resolveOldEmojiMap = (
|
|
114
|
-
emojiMaps: DeprecatedEmojiMaps,
|
|
115
|
-
emojiCDN = '',
|
|
116
|
-
): WalineEmojiInfo[] => {
|
|
117
|
-
const resolvedEmojiMaps: WalineEmojiMaps = {};
|
|
118
|
-
|
|
119
|
-
for (const key in emojiMaps) {
|
|
120
|
-
resolvedEmojiMaps[key] = /(?:https?:)?\/\//.test(emojiMaps[key])
|
|
121
|
-
? emojiMaps[key]
|
|
122
|
-
: `${emojiCDN}${emojiMaps[key]}`;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return [
|
|
126
|
-
{
|
|
127
|
-
name: 'Emoji',
|
|
128
|
-
icon: Object.values(resolvedEmojiMaps).pop() || '',
|
|
129
|
-
items: Object.keys(resolvedEmojiMaps),
|
|
130
|
-
},
|
|
131
|
-
];
|
|
132
|
-
};
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div v-if="reactionsInfo.length" class="wl-reaction">
|
|
3
|
-
<div class="wl-reaction-title" v-text="locale.reactionTitle" />
|
|
4
|
-
|
|
5
|
-
<ul class="wl-reaction-list">
|
|
6
|
-
<li
|
|
7
|
-
v-for="({ active, icon, desc }, index) in reactionsInfo"
|
|
8
|
-
:key="index"
|
|
9
|
-
class="wl-reaction-item"
|
|
10
|
-
:class="{ active }"
|
|
11
|
-
@click="vote(index)"
|
|
12
|
-
>
|
|
13
|
-
<div class="wl-reaction-img">
|
|
14
|
-
<img :src="icon" :alt="desc" />
|
|
15
|
-
|
|
16
|
-
<LoadingIcon
|
|
17
|
-
v-if="votingIndex === index"
|
|
18
|
-
class="wl-reaction-loading"
|
|
19
|
-
/>
|
|
20
|
-
|
|
21
|
-
<div
|
|
22
|
-
v-else
|
|
23
|
-
class="wl-reaction-votes"
|
|
24
|
-
v-text="voteNumbers[index] || 0"
|
|
25
|
-
/>
|
|
26
|
-
</div>
|
|
27
|
-
|
|
28
|
-
<div class="wl-reaction-text" v-text="desc" />
|
|
29
|
-
</li>
|
|
30
|
-
</ul>
|
|
31
|
-
</div>
|
|
32
|
-
</template>
|
|
33
|
-
|
|
34
|
-
<script setup lang="ts">
|
|
35
|
-
import {
|
|
36
|
-
type ComputedRef,
|
|
37
|
-
computed,
|
|
38
|
-
inject,
|
|
39
|
-
onMounted,
|
|
40
|
-
onUnmounted,
|
|
41
|
-
ref,
|
|
42
|
-
watch,
|
|
43
|
-
} from 'vue';
|
|
44
|
-
|
|
45
|
-
import { LoadingIcon } from './Icons.js';
|
|
46
|
-
import { getArticleCounter, updateArticleCounter } from '../api/index.js';
|
|
47
|
-
import { useReactionStorage } from '../composables/index.js';
|
|
48
|
-
import { type WalineReactionLocale } from '../typings/index.js';
|
|
49
|
-
import { type WalineConfig } from '../utils/index.js';
|
|
50
|
-
|
|
51
|
-
defineExpose();
|
|
52
|
-
|
|
53
|
-
interface ReactionItem {
|
|
54
|
-
icon: string;
|
|
55
|
-
desc: string;
|
|
56
|
-
active?: boolean;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const reactionStorage = useReactionStorage();
|
|
60
|
-
const config = inject<ComputedRef<WalineConfig>>('config')!;
|
|
61
|
-
|
|
62
|
-
const votingIndex = ref(-1);
|
|
63
|
-
const voteNumbers = ref<number[]>([]);
|
|
64
|
-
|
|
65
|
-
const locale = computed(() => config.value.locale);
|
|
66
|
-
const isReactionEnabled = computed(() => config.value.reaction.length > 0);
|
|
67
|
-
|
|
68
|
-
const reactionsInfo = computed<ReactionItem[]>(() => {
|
|
69
|
-
const { reaction, path } = config.value;
|
|
70
|
-
|
|
71
|
-
return reaction.map((icon, index) => ({
|
|
72
|
-
icon,
|
|
73
|
-
desc: locale.value[`reaction${index}` as keyof WalineReactionLocale],
|
|
74
|
-
active: reactionStorage.value[path] === index,
|
|
75
|
-
}));
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
let abort: () => void;
|
|
79
|
-
|
|
80
|
-
const fetchReaction = async (): Promise<void> => {
|
|
81
|
-
if (isReactionEnabled.value) {
|
|
82
|
-
const { serverURL, lang, path, reaction } = config.value;
|
|
83
|
-
const controller = new AbortController();
|
|
84
|
-
|
|
85
|
-
abort = controller.abort.bind(controller);
|
|
86
|
-
|
|
87
|
-
const resp = await getArticleCounter({
|
|
88
|
-
serverURL,
|
|
89
|
-
lang,
|
|
90
|
-
paths: [path],
|
|
91
|
-
type: reaction.map((_reaction, index) => `reaction${index}`),
|
|
92
|
-
signal: controller.signal,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// TODO: Remove this compact code
|
|
96
|
-
if (Array.isArray(resp) || typeof resp === 'number') return;
|
|
97
|
-
|
|
98
|
-
voteNumbers.value = reaction.map(
|
|
99
|
-
(_reaction, index) => resp[`reaction${index}`],
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const vote = async (index: number): Promise<void> => {
|
|
105
|
-
// we should ensure that only one vote request is sent at a time
|
|
106
|
-
if (votingIndex.value === -1) {
|
|
107
|
-
const { serverURL, lang, path } = config.value;
|
|
108
|
-
const currentVoteItemIndex = reactionStorage.value[path];
|
|
109
|
-
|
|
110
|
-
// mark voting status
|
|
111
|
-
votingIndex.value = index;
|
|
112
|
-
|
|
113
|
-
// if user already vote current article, decrease the voted item number
|
|
114
|
-
if (currentVoteItemIndex !== undefined) {
|
|
115
|
-
await updateArticleCounter({
|
|
116
|
-
serverURL,
|
|
117
|
-
lang,
|
|
118
|
-
path,
|
|
119
|
-
type: `reaction${currentVoteItemIndex}`,
|
|
120
|
-
action: 'desc',
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
voteNumbers.value[currentVoteItemIndex] = Math.max(
|
|
124
|
-
voteNumbers.value[currentVoteItemIndex] - 1,
|
|
125
|
-
0,
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// increase voting number if current reaction item is not been voted
|
|
130
|
-
if (currentVoteItemIndex !== index) {
|
|
131
|
-
await updateArticleCounter({
|
|
132
|
-
serverURL,
|
|
133
|
-
lang,
|
|
134
|
-
path,
|
|
135
|
-
type: `reaction${index}`,
|
|
136
|
-
});
|
|
137
|
-
voteNumbers.value[index] = (voteNumbers.value[index] || 0) + 1;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// update vote info in local storage
|
|
141
|
-
if (currentVoteItemIndex === index) delete reactionStorage.value[path];
|
|
142
|
-
else reactionStorage.value[path] = index;
|
|
143
|
-
|
|
144
|
-
// voting is completed
|
|
145
|
-
votingIndex.value = -1;
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
onMounted(() => {
|
|
150
|
-
watch(
|
|
151
|
-
() => [config.value.serverURL, config.value.path],
|
|
152
|
-
() => {
|
|
153
|
-
void fetchReaction();
|
|
154
|
-
},
|
|
155
|
-
{ immediate: true },
|
|
156
|
-
);
|
|
157
|
-
});
|
|
158
|
-
onUnmounted(() => abort?.());
|
|
159
|
-
</script>
|