@waline/client 2.0.0-alpha.2 → 2.0.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.js +1 -1
- package/dist/component.js.map +1 -1
- package/dist/legacy.d.ts +505 -0
- package/dist/legacy.js +2 -0
- package/dist/legacy.js.map +1 -0
- package/dist/pageview.cjs.js +1 -1
- package/dist/pageview.cjs.js.map +1 -1
- package/dist/pageview.d.ts +18 -12
- 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 +63 -16
- package/dist/shim.esm.d.ts +63 -16
- 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 +63 -16
- 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 +63 -16
- package/dist/waline.esm.d.ts +63 -16
- 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 +2 -2
- package/src/comment.ts +25 -2
- package/src/compact/convert.ts +80 -0
- package/src/compact/dropped.ts +35 -0
- package/src/compact/index.ts +4 -0
- package/src/compact/logger.ts +5 -0
- package/src/compact/v1.ts +103 -0
- package/src/compact/valine.ts +132 -0
- package/src/components/Icons.ts +1 -1
- package/src/components/Waline.vue +18 -18
- package/src/entrys/legacy.ts +29 -0
- package/src/init.ts +27 -2
- package/src/pageview.ts +26 -20
- package/src/styles/emoji.scss +1 -1
- package/src/styles/nomalize.scss +2 -0
- package/src/typings/base.ts +1 -1
- package/src/typings/options.ts +3 -0
- package/src/utils/emoji.ts +2 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waline/client",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "client for waline comment system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"valine",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"./package.json": "./package.json"
|
|
25
25
|
},
|
|
26
26
|
"main": "./dist/shim.js",
|
|
27
|
-
"browser": "./dist/
|
|
27
|
+
"browser": "./dist/legacy.js",
|
|
28
28
|
"types": "./dist/shim.d.ts",
|
|
29
29
|
"files": [
|
|
30
30
|
"dist",
|
package/src/comment.ts
CHANGED
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
import { useUserInfo } from './composables';
|
|
2
2
|
import { decodePath, errorHandler, fetchCommentCount } from './utils';
|
|
3
|
+
import type { WalineAbort } from './typings';
|
|
3
4
|
|
|
4
|
-
export interface
|
|
5
|
+
export interface WalineCommentCountOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Waline 服务端地址
|
|
8
|
+
*
|
|
9
|
+
* Waline server url
|
|
10
|
+
*/
|
|
5
11
|
serverURL: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 评论数 CSS 选择器
|
|
15
|
+
*
|
|
16
|
+
* Commment count CSS selector
|
|
17
|
+
*
|
|
18
|
+
* @default '.waline-comment-count'
|
|
19
|
+
*/
|
|
6
20
|
selector?: string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 需要获取的默认路径
|
|
24
|
+
*
|
|
25
|
+
* Path to be fetched by default
|
|
26
|
+
*
|
|
27
|
+
* @default window.location.pathname
|
|
28
|
+
*/
|
|
7
29
|
path?: string;
|
|
8
30
|
}
|
|
9
31
|
|
|
@@ -11,7 +33,8 @@ export const commentCount = ({
|
|
|
11
33
|
serverURL,
|
|
12
34
|
path = window.location.pathname,
|
|
13
35
|
selector = '.waline-comment-count',
|
|
14
|
-
}:
|
|
36
|
+
}: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
WalineCommentCountOptions): WalineAbort => {
|
|
15
38
|
const controller = new AbortController();
|
|
16
39
|
|
|
17
40
|
// comment count
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { warning } from './logger';
|
|
2
|
+
import { resolveOldEmojiMap } from './valine';
|
|
3
|
+
|
|
4
|
+
import type { DeprecatedValineOptions } from './valine';
|
|
5
|
+
import {
|
|
6
|
+
DROPPED_OPTIONS_WHICH_CAN_NOT_BE_POLYFILLED,
|
|
7
|
+
DROPPED_OPTIONS_WHICH_CAN_STILL_BE_POLYFILLED,
|
|
8
|
+
} from './dropped';
|
|
9
|
+
import type { DeprecatedWalineOptions } from './v1';
|
|
10
|
+
import type { WalineInitOptions } from '../typings';
|
|
11
|
+
|
|
12
|
+
export const covertOptions = (
|
|
13
|
+
options: WalineInitOptions & DeprecatedValineOptions & 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,.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 longr 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 can no longr be handled
|
|
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
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
];
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
WalineHighlighter,
|
|
3
|
+
WalineImageUploader,
|
|
4
|
+
WalineTexRenderer,
|
|
5
|
+
} from '../typings';
|
|
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
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
WalineEmojiInfo,
|
|
3
|
+
WalineEmojiMaps,
|
|
4
|
+
WalineLocale,
|
|
5
|
+
WalineMeta,
|
|
6
|
+
} from '../typings';
|
|
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
|
+
};
|
package/src/components/Icons.ts
CHANGED
|
@@ -6,6 +6,18 @@
|
|
|
6
6
|
{{ i18n.comment }}
|
|
7
7
|
</div>
|
|
8
8
|
|
|
9
|
+
<div class="wl-cards">
|
|
10
|
+
<CommentCard
|
|
11
|
+
v-for="comment in data"
|
|
12
|
+
:key="comment.objectId"
|
|
13
|
+
:root-id="comment.objectId"
|
|
14
|
+
:comment="comment"
|
|
15
|
+
:reply="reply"
|
|
16
|
+
@reply="onReply"
|
|
17
|
+
@submit="onSubmit"
|
|
18
|
+
/>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
9
21
|
<div v-if="status === 'error'" class="wl-action">
|
|
10
22
|
<button
|
|
11
23
|
type="button"
|
|
@@ -15,27 +27,15 @@
|
|
|
15
27
|
/>
|
|
16
28
|
</div>
|
|
17
29
|
|
|
18
|
-
<div v-else-if="status === 'loading'" class="wl-loading">
|
|
19
|
-
<LoadingIcon :size="30" />
|
|
20
|
-
</div>
|
|
21
|
-
|
|
22
30
|
<template v-else>
|
|
23
|
-
<div v-if="
|
|
24
|
-
|
|
25
|
-
<div v-else class="wl-cards">
|
|
26
|
-
<CommentCard
|
|
27
|
-
v-for="comment in data"
|
|
28
|
-
:key="comment.objectId"
|
|
29
|
-
:root-id="comment.objectId"
|
|
30
|
-
:comment="comment"
|
|
31
|
-
:reply="reply"
|
|
32
|
-
@reply="onReply"
|
|
33
|
-
@submit="onSubmit"
|
|
34
|
-
/>
|
|
31
|
+
<div v-if="status === 'loading'" class="wl-loading">
|
|
32
|
+
<LoadingIcon :size="30" />
|
|
35
33
|
</div>
|
|
36
34
|
|
|
35
|
+
<div v-else-if="!data.length" class="wl-empty" v-text="i18n.sofa" />
|
|
36
|
+
|
|
37
37
|
<!-- Load more button -->
|
|
38
|
-
<div v-if="page < totalPages" class="wl-more">
|
|
38
|
+
<div v-else-if="page < totalPages" class="wl-more">
|
|
39
39
|
<button
|
|
40
40
|
type="button"
|
|
41
41
|
class="wl-btn"
|
|
@@ -93,7 +93,7 @@ declare const SHOULD_VALIDATE: boolean;
|
|
|
93
93
|
declare const VERSION: string;
|
|
94
94
|
|
|
95
95
|
export default defineComponent({
|
|
96
|
-
name: '
|
|
96
|
+
name: 'WalineRoot',
|
|
97
97
|
|
|
98
98
|
components: {
|
|
99
99
|
CommentBox,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { covertOptions, warning } from '../compact';
|
|
2
|
+
import { init, WalineInstance } from '../init';
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
DeprecatedValineOptions,
|
|
6
|
+
DeprecatedWalineOptions,
|
|
7
|
+
} from '../compact';
|
|
8
|
+
import type { WalineInitOptions } from '../typings';
|
|
9
|
+
|
|
10
|
+
export { WalineInstance } from '../init';
|
|
11
|
+
|
|
12
|
+
warning(
|
|
13
|
+
' This is a legacy package compatable with Valine and Waline@v1, please switch to Waline@v2 using https://<CDN.LINK>/@waline/client@next/dist/waline.js instead!'
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// inject css styles
|
|
17
|
+
|
|
18
|
+
const link = document.createElement('link');
|
|
19
|
+
|
|
20
|
+
link.rel = 'stylesheet';
|
|
21
|
+
link.href = '//cdn.jsdelivr.net/npm/@waline/client@next/dist/waline.css';
|
|
22
|
+
|
|
23
|
+
document.head.appendChild(link);
|
|
24
|
+
|
|
25
|
+
export default function legacyWaline(
|
|
26
|
+
options: WalineInitOptions & DeprecatedValineOptions & DeprecatedWalineOptions
|
|
27
|
+
): WalineInstance | null {
|
|
28
|
+
return init(covertOptions(options));
|
|
29
|
+
}
|
package/src/init.ts
CHANGED
|
@@ -5,11 +5,36 @@ import { commentCount } from './comment';
|
|
|
5
5
|
import { pageviewCount } from './pageview';
|
|
6
6
|
import { getRoot } from './utils';
|
|
7
7
|
|
|
8
|
-
import type { WalineInitOptions
|
|
8
|
+
import type { WalineInitOptions } from './typings';
|
|
9
9
|
|
|
10
10
|
export interface WalineInstance {
|
|
11
|
+
/**
|
|
12
|
+
* Waline 被挂载到的元素
|
|
13
|
+
*
|
|
14
|
+
* @description 当通过 `el: null` 初始化,值为 `null`
|
|
15
|
+
*
|
|
16
|
+
* Element where Waline is mounted
|
|
17
|
+
*
|
|
18
|
+
* @description when initialized with `el: null`, it will be `null`
|
|
19
|
+
*/
|
|
11
20
|
el: HTMLElement | null;
|
|
12
|
-
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 更新 Waline 实例
|
|
24
|
+
*
|
|
25
|
+
* @description 只要不设置`path` 选项,更新时它就会被重置为 `windows.location.pathname`
|
|
26
|
+
*
|
|
27
|
+
* Update Waline instance
|
|
28
|
+
*
|
|
29
|
+
* @description when not setting `path` option, it will be reset to `window.location.pathname`
|
|
30
|
+
*/
|
|
31
|
+
update: (newOptions: Partial<Omit<WalineInitOptions, 'el'>>) => void;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 取消挂载并摧毁 Waline 实例
|
|
35
|
+
*
|
|
36
|
+
* Unmount and destroy Waline instance
|
|
37
|
+
*/
|
|
13
38
|
destroy: () => void;
|
|
14
39
|
}
|
|
15
40
|
|
package/src/pageview.ts
CHANGED
|
@@ -5,53 +5,59 @@ import {
|
|
|
5
5
|
updatePageviews,
|
|
6
6
|
} from './utils';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
counts: number[],
|
|
10
|
-
countElements: HTMLElement[]
|
|
11
|
-
): void => {
|
|
12
|
-
countElements.forEach((element, index) => {
|
|
13
|
-
element.innerText = counts[index].toString();
|
|
14
|
-
});
|
|
15
|
-
};
|
|
8
|
+
import type { WalineAbort } from './typings';
|
|
16
9
|
|
|
17
|
-
export interface
|
|
10
|
+
export interface WalinePageviewCountOptions {
|
|
18
11
|
/**
|
|
19
|
-
* Waline server url
|
|
20
|
-
*
|
|
21
12
|
* Waline 服务端地址
|
|
13
|
+
*
|
|
14
|
+
* Waline server url
|
|
22
15
|
*/
|
|
23
16
|
serverURL: string;
|
|
24
17
|
|
|
25
18
|
/**
|
|
26
|
-
*
|
|
19
|
+
* 浏览量 CSS 选择器
|
|
27
20
|
*
|
|
28
|
-
*
|
|
21
|
+
* Pageview CSS selector
|
|
29
22
|
*
|
|
30
|
-
* @default window.location.pathname
|
|
31
|
-
*/
|
|
32
|
-
path?: string;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
23
|
* @default '.waline-pageview-count'
|
|
36
24
|
*/
|
|
37
25
|
selector?: string;
|
|
38
26
|
|
|
39
27
|
/**
|
|
40
|
-
*
|
|
28
|
+
* 需要更新和获取的路径
|
|
29
|
+
*
|
|
30
|
+
* Path to be fetched and updated
|
|
41
31
|
*
|
|
32
|
+
* @default window.location.pathname
|
|
33
|
+
*/
|
|
34
|
+
path?: string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
42
37
|
* 是否在查询时更新 path 的浏览量
|
|
43
38
|
*
|
|
39
|
+
* Whether update pageviews when fetching path result
|
|
40
|
+
*
|
|
44
41
|
* @default true
|
|
45
42
|
*/
|
|
46
43
|
update?: boolean;
|
|
47
44
|
}
|
|
48
45
|
|
|
46
|
+
const renderVisitorCount = (
|
|
47
|
+
counts: number[],
|
|
48
|
+
countElements: HTMLElement[]
|
|
49
|
+
): void => {
|
|
50
|
+
countElements.forEach((element, index) => {
|
|
51
|
+
element.innerText = counts[index].toString();
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
49
55
|
export const pageviewCount = ({
|
|
50
56
|
serverURL,
|
|
51
57
|
path = window.location.pathname,
|
|
52
58
|
selector = '.waline-pageview-count',
|
|
53
59
|
update = true,
|
|
54
|
-
}:
|
|
60
|
+
}: WalinePageviewCountOptions): WalineAbort => {
|
|
55
61
|
const controller = new AbortController();
|
|
56
62
|
|
|
57
63
|
const elements = Array.from(
|
package/src/styles/emoji.scss
CHANGED
package/src/styles/nomalize.scss
CHANGED
package/src/typings/base.ts
CHANGED
package/src/typings/options.ts
CHANGED
package/src/utils/emoji.ts
CHANGED
|
@@ -33,12 +33,8 @@ const fetchEmoji = (link: string): Promise<WalineEmojiInfo> => {
|
|
|
33
33
|
});
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
const getLink = (
|
|
37
|
-
name:
|
|
38
|
-
folder: string,
|
|
39
|
-
prefix = '',
|
|
40
|
-
type = ''
|
|
41
|
-
): string => `${folder}/${prefix}${name}${type ? `.${type}` : ''}`;
|
|
36
|
+
const getLink = (name: string, folder = '', prefix = '', type = ''): string =>
|
|
37
|
+
`${folder ? `${folder}/` : ''}${prefix}${name}${type ? `.${type}` : ''}`;
|
|
42
38
|
|
|
43
39
|
export const getEmojis = (
|
|
44
40
|
emojis: (string | WalineEmojiInfo)[]
|