@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/utils/emoji.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { useStorage } from '@vueuse/core';
|
|
2
|
-
|
|
3
|
-
import { type WalineEmojiConfig } from './config.js';
|
|
4
|
-
import { removeEndingSplash } from './path.js';
|
|
5
|
-
import { type WalineEmojiInfo } from '../typings/index.js';
|
|
6
|
-
|
|
7
|
-
const hasVersion = (url: string): boolean =>
|
|
8
|
-
Boolean(/@[0-9]+\.[0-9]+\.[0-9]+/.test(url));
|
|
9
|
-
|
|
10
|
-
const fetchEmoji = (link: string): Promise<WalineEmojiInfo> => {
|
|
11
|
-
const emojiStore = useStorage<Record<string, WalineEmojiInfo>>(
|
|
12
|
-
'WALINE_EMOJI',
|
|
13
|
-
{},
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const result = hasVersion(link);
|
|
17
|
-
|
|
18
|
-
if (result) {
|
|
19
|
-
const info = emojiStore.value[link];
|
|
20
|
-
|
|
21
|
-
if (info) return Promise.resolve(info);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return fetch(`${link}/info.json`)
|
|
25
|
-
.then((resp) => <Promise<Omit<WalineEmojiInfo, 'folder'>>>resp.json())
|
|
26
|
-
.then((emojiInfo) => {
|
|
27
|
-
const info = {
|
|
28
|
-
folder: link,
|
|
29
|
-
...emojiInfo,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
if (result) emojiStore.value[link] = info;
|
|
33
|
-
|
|
34
|
-
return info;
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const getLink = (name: string, folder = '', prefix = '', type = ''): string =>
|
|
39
|
-
`${folder ? `${folder}/` : ''}${prefix}${name}${type ? `.${type}` : ''}`;
|
|
40
|
-
|
|
41
|
-
export const getEmojis = (
|
|
42
|
-
emojis: (string | WalineEmojiInfo)[],
|
|
43
|
-
): Promise<WalineEmojiConfig> =>
|
|
44
|
-
Promise.all(
|
|
45
|
-
emojis.map((emoji) =>
|
|
46
|
-
typeof emoji === 'string'
|
|
47
|
-
? fetchEmoji(removeEndingSplash(emoji))
|
|
48
|
-
: Promise.resolve(emoji),
|
|
49
|
-
),
|
|
50
|
-
).then((emojiInfos) => {
|
|
51
|
-
const emojiConfig: WalineEmojiConfig = {
|
|
52
|
-
tabs: [],
|
|
53
|
-
map: {},
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
emojiInfos.forEach((emojiInfo) => {
|
|
57
|
-
const { name, folder, icon, prefix, type, items } = emojiInfo;
|
|
58
|
-
|
|
59
|
-
emojiConfig.tabs.push({
|
|
60
|
-
name,
|
|
61
|
-
icon: getLink(icon, folder, prefix, type),
|
|
62
|
-
items: items.map((item) => {
|
|
63
|
-
const key = `${prefix || ''}${item}`;
|
|
64
|
-
|
|
65
|
-
emojiConfig.map[key] = getLink(item, folder, prefix, type);
|
|
66
|
-
|
|
67
|
-
return key;
|
|
68
|
-
}),
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return emojiConfig;
|
|
73
|
-
});
|
package/src/utils/error.ts
DELETED
package/src/utils/getRoot.ts
DELETED
package/src/utils/image.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const isImage = (item: DataTransferItem): boolean =>
|
|
2
|
-
item.type.includes('image');
|
|
3
|
-
|
|
4
|
-
export const getImageFromDataTransfer = (
|
|
5
|
-
items: DataTransferItemList,
|
|
6
|
-
): File | null => {
|
|
7
|
-
const image = Array.from(items).find(isImage);
|
|
8
|
-
|
|
9
|
-
return image ? (image.getAsFile() as File) : null;
|
|
10
|
-
};
|
package/src/utils/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export * from './config.js';
|
|
2
|
-
export * from './darkmode.js';
|
|
3
|
-
export * from './date.js';
|
|
4
|
-
export * from './email.js';
|
|
5
|
-
export * from './emoji.js';
|
|
6
|
-
export * from './error.js';
|
|
7
|
-
export * from './getRoot.js';
|
|
8
|
-
export * from './image.js';
|
|
9
|
-
export * from './markdown.js';
|
|
10
|
-
export * from './path.js';
|
|
11
|
-
export * from './query.js';
|
|
12
|
-
export * from './wordCount.js';
|
|
13
|
-
export * from './userAgent.js';
|
package/src/utils/markdown.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { marked } from 'marked';
|
|
2
|
-
|
|
3
|
-
import { markedTeXExtensions } from './markedMathExtension.js';
|
|
4
|
-
import {
|
|
5
|
-
type WalineEmojiMaps,
|
|
6
|
-
type WalineHighlighter,
|
|
7
|
-
type WalineTeXRenderer,
|
|
8
|
-
} from '../typings/index.js';
|
|
9
|
-
|
|
10
|
-
export const parseEmoji = (text = '', emojiMap: WalineEmojiMaps = {}): string =>
|
|
11
|
-
text.replace(/:(.+?):/g, (placeholder, key: string) =>
|
|
12
|
-
emojiMap[key]
|
|
13
|
-
? `<img class="wl-emoji" src="${emojiMap[key]}" alt="${key}">`
|
|
14
|
-
: placeholder,
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
export interface ParseMarkdownOptions {
|
|
18
|
-
emojiMap: WalineEmojiMaps;
|
|
19
|
-
highlighter: WalineHighlighter | false;
|
|
20
|
-
texRenderer: WalineTeXRenderer | false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const parseMarkdown = (
|
|
24
|
-
content: string,
|
|
25
|
-
{ emojiMap, highlighter, texRenderer }: ParseMarkdownOptions,
|
|
26
|
-
): string => {
|
|
27
|
-
marked.setOptions({
|
|
28
|
-
highlight: highlighter || undefined,
|
|
29
|
-
breaks: true,
|
|
30
|
-
smartLists: true,
|
|
31
|
-
smartypants: true,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
if (texRenderer) {
|
|
35
|
-
const extensions = markedTeXExtensions(texRenderer);
|
|
36
|
-
|
|
37
|
-
marked.use({ extensions });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return marked.parse(parseEmoji(content, emojiMap));
|
|
41
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { type marked } from 'marked';
|
|
2
|
-
|
|
3
|
-
import { type WalineTeXRenderer } from '../typings/index.js';
|
|
4
|
-
|
|
5
|
-
const inlineMathStart = /\$.*?\$/;
|
|
6
|
-
const inlineMathReg = /^\$(.*?)\$/;
|
|
7
|
-
const blockMathReg = /^(?:\s{0,3})\$\$((?:[^\n]|\n[^\n])+?)\n{0,1}\$\$/;
|
|
8
|
-
|
|
9
|
-
export const markedTeXExtensions = (
|
|
10
|
-
texRenderer: WalineTeXRenderer,
|
|
11
|
-
): marked.TokenizerExtension[] => {
|
|
12
|
-
const blockMathExtension: marked.TokenizerExtension = {
|
|
13
|
-
name: 'blockMath',
|
|
14
|
-
level: 'block',
|
|
15
|
-
tokenizer(src: string) {
|
|
16
|
-
const cap = blockMathReg.exec(src);
|
|
17
|
-
|
|
18
|
-
if (cap !== null) {
|
|
19
|
-
return {
|
|
20
|
-
type: 'html',
|
|
21
|
-
raw: cap[0],
|
|
22
|
-
text: texRenderer(true, cap[1]),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return undefined;
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const inlineMathExtension: marked.TokenizerExtension = {
|
|
31
|
-
name: 'inlineMath',
|
|
32
|
-
level: 'inline',
|
|
33
|
-
start(src: string) {
|
|
34
|
-
const idx = src.search(inlineMathStart);
|
|
35
|
-
|
|
36
|
-
return idx !== -1 ? idx : src.length;
|
|
37
|
-
},
|
|
38
|
-
tokenizer(src: string) {
|
|
39
|
-
const cap = inlineMathReg.exec(src);
|
|
40
|
-
|
|
41
|
-
if (cap !== null) {
|
|
42
|
-
return {
|
|
43
|
-
type: 'html',
|
|
44
|
-
raw: cap[0],
|
|
45
|
-
text: texRenderer(false, cap[1]),
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return undefined;
|
|
50
|
-
},
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return [blockMathExtension, inlineMathExtension];
|
|
54
|
-
};
|
package/src/utils/path.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const decodePath = (path: string): string => {
|
|
2
|
-
try {
|
|
3
|
-
path = decodeURI(path);
|
|
4
|
-
} catch (err) {
|
|
5
|
-
// ignore error
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return path;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const removeEndingSplash = (content = ''): string =>
|
|
12
|
-
content.replace(/\/$/u, '');
|
|
13
|
-
|
|
14
|
-
export const isLinkHttp = (link: string): boolean =>
|
|
15
|
-
/^(https?:)?\/\//.test(link);
|
package/src/utils/query.ts
DELETED
package/src/utils/userAgent.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/// <reference types="user-agent-data-types" />
|
|
2
|
-
|
|
3
|
-
export const userAgent = async (): Promise<string> => {
|
|
4
|
-
if (!navigator) {
|
|
5
|
-
return '';
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const { userAgentData } = navigator;
|
|
9
|
-
let ua = navigator.userAgent;
|
|
10
|
-
|
|
11
|
-
// https://learn.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11
|
|
12
|
-
if (!userAgentData || userAgentData.platform !== 'Windows') {
|
|
13
|
-
return ua;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const { platformVersion } = await userAgentData.getHighEntropyValues([
|
|
17
|
-
'platformVersion',
|
|
18
|
-
]);
|
|
19
|
-
|
|
20
|
-
if (!platformVersion) {
|
|
21
|
-
return ua;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const isWindows11Later = parseInt(platformVersion.split('.')[0]) >= 13;
|
|
25
|
-
|
|
26
|
-
if (isWindows11Later) {
|
|
27
|
-
ua = ua.replace('Windows NT 10.0', 'Windows NT 11.0');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return ua;
|
|
31
|
-
};
|
package/src/utils/wordCount.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The wordCount module should be lightweight as it's packed into client.
|
|
3
|
-
*
|
|
4
|
-
* So We just make a simple implement here
|
|
5
|
-
*
|
|
6
|
-
* Forked from https://github.com/vuepress-theme-hope/vuepress-theme-hope/blob/main/packages/reading-time2/src/node/readingTime.ts
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Extract Latin words from content
|
|
11
|
-
*/
|
|
12
|
-
export const getWords = (content: string): RegExpMatchArray | null =>
|
|
13
|
-
// \u00C0-\u024F are Latin Supplement letters, maybe used in language like french
|
|
14
|
-
// \u0400-\u04FF are Cyrillic letters, used in russian
|
|
15
|
-
content.match(/[\w\d\s,.\u00C0-\u024F\u0400-\u04FF]+/giu);
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Extract Chinese Characters from content
|
|
19
|
-
*/
|
|
20
|
-
export const getChinese = (content: string): RegExpMatchArray | null =>
|
|
21
|
-
content.match(/[\u4E00-\u9FD5]/gu);
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get word number of given string
|
|
25
|
-
*/
|
|
26
|
-
export const getWordNumber = (content: string): number =>
|
|
27
|
-
(getWords(content)?.reduce<number>(
|
|
28
|
-
(accumulator, word) =>
|
|
29
|
-
accumulator + (word.trim() === '' ? 0 : word.trim().split(/\s+/u).length),
|
|
30
|
-
0,
|
|
31
|
-
) || 0) + (getChinese(content)?.length || 0);
|
package/src/version.ts
DELETED
package/src/widgets/index.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { getRecentComment } from '../api/index.js';
|
|
2
|
-
import { useUserInfo } from '../composables/index.js';
|
|
3
|
-
import { type WalineComment } from '../typings/index.js';
|
|
4
|
-
import { getRoot } from '../utils/index.js';
|
|
5
|
-
|
|
6
|
-
export interface WalineRecentCommentsOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Waline 服务端地址
|
|
9
|
-
*
|
|
10
|
-
* Waline serverURL
|
|
11
|
-
*/
|
|
12
|
-
serverURL: string;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 获取最新评论的数量
|
|
16
|
-
*
|
|
17
|
-
* fetch number of latest comments
|
|
18
|
-
*/
|
|
19
|
-
count: number;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 需要挂载的元素
|
|
23
|
-
*
|
|
24
|
-
* Element to be mounted
|
|
25
|
-
*/
|
|
26
|
-
el?: string | HTMLElement;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 错误提示消息所使用的语言
|
|
30
|
-
*
|
|
31
|
-
* Language of error message
|
|
32
|
-
*
|
|
33
|
-
* @default navigator.language
|
|
34
|
-
*/
|
|
35
|
-
lang?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface WalineRecentCommentsResult {
|
|
39
|
-
/**
|
|
40
|
-
* 评论数据
|
|
41
|
-
*
|
|
42
|
-
* Comment Data
|
|
43
|
-
*/
|
|
44
|
-
comments: WalineComment[];
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 取消挂载挂件
|
|
48
|
-
*
|
|
49
|
-
* Umount widget
|
|
50
|
-
*/
|
|
51
|
-
destroy: () => void;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const RecentComments = ({
|
|
55
|
-
el,
|
|
56
|
-
serverURL,
|
|
57
|
-
count,
|
|
58
|
-
lang = navigator.language,
|
|
59
|
-
}: WalineRecentCommentsOptions): Promise<WalineRecentCommentsResult> => {
|
|
60
|
-
const userInfo = useUserInfo();
|
|
61
|
-
const root = getRoot(el);
|
|
62
|
-
const controller = new AbortController();
|
|
63
|
-
|
|
64
|
-
return getRecentComment({
|
|
65
|
-
serverURL,
|
|
66
|
-
count,
|
|
67
|
-
lang,
|
|
68
|
-
signal: controller.signal,
|
|
69
|
-
token: userInfo.value?.token,
|
|
70
|
-
}).then((comments) => {
|
|
71
|
-
if (root && comments.length) {
|
|
72
|
-
root.innerHTML = `<ul class="wl-recent-list">${comments
|
|
73
|
-
.map(
|
|
74
|
-
(comment) =>
|
|
75
|
-
`<li class="wl-recent-item"><a href="${comment.url}">${comment.nick}</a>:${comment.comment}</li>`,
|
|
76
|
-
)
|
|
77
|
-
.join('')}</ul>`;
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
comments,
|
|
81
|
-
destroy: (): void => {
|
|
82
|
-
controller.abort();
|
|
83
|
-
root.innerHTML = '';
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
comments,
|
|
90
|
-
destroy: (): void => controller.abort(),
|
|
91
|
-
};
|
|
92
|
-
});
|
|
93
|
-
};
|
package/src/widgets/userList.ts
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { getUserList, WalineUser } from '../api';
|
|
2
|
-
import { DEFAULT_LANG, DEFAULT_LOCALES } from '../config';
|
|
3
|
-
import { WalineLocale } from '../typings';
|
|
4
|
-
import { getRoot } from '../utils';
|
|
5
|
-
|
|
6
|
-
export interface WalineUserListOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Waline 服务端地址
|
|
9
|
-
*
|
|
10
|
-
* Waline serverURL
|
|
11
|
-
*/
|
|
12
|
-
serverURL: string;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 获取用户列表的数量
|
|
16
|
-
*
|
|
17
|
-
* fetch number of user list
|
|
18
|
-
*/
|
|
19
|
-
count: number;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 需要挂载的元素
|
|
23
|
-
*
|
|
24
|
-
* Element to be mounted
|
|
25
|
-
*/
|
|
26
|
-
el?: string | HTMLElement;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 错误提示消息所使用的语言
|
|
30
|
-
*
|
|
31
|
-
* Language of error message
|
|
32
|
-
*
|
|
33
|
-
* @default navigator.language
|
|
34
|
-
*/
|
|
35
|
-
lang?: string;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* 自定义 waline 语言显示
|
|
39
|
-
*
|
|
40
|
-
* @see [自定义语言](https://waline.js.org/client/i18n.html)
|
|
41
|
-
*
|
|
42
|
-
* Custom display language in waline
|
|
43
|
-
*
|
|
44
|
-
* @see [I18n](https://waline.js.org/en/client/i18n.html)
|
|
45
|
-
*/
|
|
46
|
-
locale?: WalineLocale;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 列表模式还是头像墙模式
|
|
50
|
-
*
|
|
51
|
-
* list mode or avatar wall mode
|
|
52
|
-
*/
|
|
53
|
-
mode: 'list' | 'wall';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface WalineUserListResult {
|
|
57
|
-
/**
|
|
58
|
-
* 用户数据
|
|
59
|
-
*
|
|
60
|
-
* User Data
|
|
61
|
-
*/
|
|
62
|
-
users: WalineUser[];
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* 取消挂载挂件
|
|
66
|
-
*
|
|
67
|
-
* Umount widget
|
|
68
|
-
*/
|
|
69
|
-
destroy: () => void;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export const UserList = ({
|
|
73
|
-
el,
|
|
74
|
-
serverURL,
|
|
75
|
-
count,
|
|
76
|
-
locale,
|
|
77
|
-
lang = navigator.language,
|
|
78
|
-
mode = 'list',
|
|
79
|
-
}: WalineUserListOptions): Promise<WalineUserListResult> => {
|
|
80
|
-
const root = getRoot(el);
|
|
81
|
-
const controller = new AbortController();
|
|
82
|
-
|
|
83
|
-
return getUserList({
|
|
84
|
-
serverURL,
|
|
85
|
-
pageSize: count,
|
|
86
|
-
lang,
|
|
87
|
-
signal: controller.signal,
|
|
88
|
-
}).then((users) => {
|
|
89
|
-
if (!root || !users.length)
|
|
90
|
-
return {
|
|
91
|
-
users,
|
|
92
|
-
destroy: (): void => controller.abort(),
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
locale = {
|
|
96
|
-
...(DEFAULT_LOCALES[lang] || DEFAULT_LOCALES[DEFAULT_LANG]),
|
|
97
|
-
...(typeof locale === 'object' ? locale : {}),
|
|
98
|
-
} as WalineLocale;
|
|
99
|
-
|
|
100
|
-
root.innerHTML = `<ul class="wl-user-${mode}">${users
|
|
101
|
-
.map((user, index) =>
|
|
102
|
-
[
|
|
103
|
-
`<li class="wl-user-item" aria-label="${user.nick}">`,
|
|
104
|
-
user.link && `<a href="${user.link}" target="_blank">`,
|
|
105
|
-
'<div class="wl-user-avatar">',
|
|
106
|
-
`<img src="${user.avatar}" alt="${user.nick}">`,
|
|
107
|
-
`<span class="wl-user-badge">${index + 1}</span>`,
|
|
108
|
-
'</div>',
|
|
109
|
-
'<div class="wl-user-meta">',
|
|
110
|
-
'<div class="wl-user-name">',
|
|
111
|
-
user.nick,
|
|
112
|
-
user.level &&
|
|
113
|
-
`<span class="wl-badge">${
|
|
114
|
-
locale ? locale[`level${user.level}`] : `Level ${user.level}`
|
|
115
|
-
}</span>`,
|
|
116
|
-
user.label && `<span class="wl-badge">${user.label}</span>`,
|
|
117
|
-
'</div>',
|
|
118
|
-
user.link && user.link,
|
|
119
|
-
'</div>',
|
|
120
|
-
user.link && '</a>',
|
|
121
|
-
'</li>',
|
|
122
|
-
]
|
|
123
|
-
.filter((v) => v)
|
|
124
|
-
.join(''),
|
|
125
|
-
)
|
|
126
|
-
.join('')}</ul>`;
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
users,
|
|
130
|
-
destroy: (): void => {
|
|
131
|
-
controller.abort();
|
|
132
|
-
root.innerHTML = '';
|
|
133
|
-
},
|
|
134
|
-
};
|
|
135
|
-
});
|
|
136
|
-
};
|