@waline/client 2.1.2 → 2.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waline/client",
3
- "version": "2.1.2",
3
+ "version": "2.3.1",
4
4
  "description": "client for waline comment system",
5
5
  "keywords": [
6
6
  "valine",
@@ -56,15 +56,6 @@
56
56
  "dist",
57
57
  "src"
58
58
  ],
59
- "scripts": {
60
- "build": "npm run rollup && npm run style",
61
- "clean": "rimraf ./dist",
62
- "dev": "vite -c config/vite.config.js",
63
- "lint": "eslint --ext .ts,.vue .",
64
- "prepublish": "npm run clean && npm run build",
65
- "rollup": "rollup -c ./config/rollup.config.js",
66
- "style": "sass ./src/styles/index.scss ./dist/waline.css --style=compressed"
67
- },
68
59
  "browserslist": {
69
60
  "production": [
70
61
  ">0.5%",
@@ -80,9 +71,8 @@
80
71
  ]
81
72
  },
82
73
  "dependencies": {
83
- "@vueuse/core": "^8.3.1",
74
+ "@vueuse/core": "^8.4.0",
84
75
  "autosize": "^5.0.1",
85
- "hanabi": "^0.4.0",
86
76
  "marked": "^4.0.15",
87
77
  "vue": "^3.2.33"
88
78
  },
@@ -90,9 +80,18 @@
90
80
  "@types/autosize": "^4.0.1",
91
81
  "@types/marked": "^4.0.3",
92
82
  "@vitejs/plugin-vue": "^2.3.1",
93
- "vite": "^2.9.6"
83
+ "vite": "^2.9.7"
94
84
  },
95
85
  "engines": {
96
86
  "node": ">=12.20.0"
87
+ },
88
+ "scripts": {
89
+ "build": "pnpm rollup && pnpm style",
90
+ "clean": "rimraf ./dist",
91
+ "dev": "vite -c config/vite.config.js",
92
+ "lint": "eslint --ext .ts,.vue .",
93
+ "prepublish": "pnpm clean && pnpm build",
94
+ "rollup": "rollup -c ./config/rollup.config.js",
95
+ "style": "sass ./src/styles/index.scss ./dist/waline.css --style=compressed"
97
96
  }
98
- }
97
+ }
@@ -22,10 +22,11 @@
22
22
  class="wl-badge"
23
23
  v-text="locale.admin"
24
24
  />
25
+ <span v-if="comment.label" class="wl-badge" v-text="comment.label" />
25
26
  <span v-if="comment.sticky" class="wl-badge" v-text="locale.sticky" />
26
27
  <span
27
28
  v-if="comment.level >= 0"
28
- class="wl-badge"
29
+ :class="`wl-badge level${comment.level}`"
29
30
  v-text="locale[`level${comment.level}`] || `Level ${comment.level}`"
30
31
  />
31
32
 
@@ -41,6 +42,7 @@
41
42
  </button>
42
43
  </div>
43
44
  <div class="wl-meta" aria-hidden="true">
45
+ <span v-if="comment.addr" v-text="comment.addr" />
44
46
  <span v-if="comment.browser" v-text="comment.browser" />
45
47
  <span v-if="comment.os" v-text="comment.os" />
46
48
  </div>
@@ -67,7 +67,7 @@ import CommentBox from './CommentBox.vue';
67
67
  import CommentCard from './CommentCard.vue';
68
68
  import { LoadingIcon } from './Icons';
69
69
  import { useUserInfo } from '../composables';
70
- import { locales } from '../config';
70
+ import { defaultLocales } from '../config';
71
71
  import { fetchCommentList, getConfig, getDarkStyle } from '../utils';
72
72
 
73
73
  import type { PropType } from 'vue';
@@ -126,27 +126,21 @@ export default defineComponent({
126
126
  : {}),
127
127
  },
128
128
 
129
- dark: {
130
- type: [String, Boolean],
131
- },
129
+ dark: [String, Boolean],
132
130
 
133
131
  lang: {
134
132
  type: String,
135
133
  ...(SHOULD_VALIDATE
136
134
  ? {
137
135
  validator: (value: unknown): boolean =>
138
- Object.keys(locales).includes(value as string),
136
+ Object.keys(defaultLocales).includes(value as string),
139
137
  }
140
138
  : {}),
141
139
  },
142
140
 
143
- locale: {
144
- type: Object as PropType<Partial<WalineLocale>>,
145
- },
141
+ locale: Object as PropType<Partial<WalineLocale>>,
146
142
 
147
- pageSize: {
148
- type: Number,
149
- },
143
+ pageSize: Number,
150
144
 
151
145
  wordLimit: {
152
146
  type: [Number, Array] as PropType<number | [number, number]>,
@@ -185,21 +179,15 @@ export default defineComponent({
185
179
  : {}),
186
180
  },
187
181
 
188
- login: {
189
- type: String as PropType<'enable' | 'disable' | 'force'>,
190
- },
182
+ login: String as PropType<'enable' | 'disable' | 'force'>,
191
183
 
192
- highlighter: {
193
- type: Function as PropType<WalineHighlighter>,
194
- },
184
+ highlighter: Function as PropType<WalineHighlighter>,
195
185
 
196
- imageUploader: {
197
- type: [Function, Boolean] as PropType<WalineImageUploader | false>,
198
- },
186
+ imageUploader: [Function, Boolean] as PropType<WalineImageUploader | false>,
199
187
 
200
- texRenderer: {
201
- type: [Function, Boolean] as PropType<WalineTexRenderer | false>,
202
- },
188
+ texRenderer: [Function, Boolean] as PropType<WalineTexRenderer | false>,
189
+
190
+ copyright: Boolean,
203
191
  },
204
192
 
205
193
  setup(props) {
@@ -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 '&lt;';
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
+ };
@@ -10,7 +10,7 @@ import type { WalineLocale } from '../../typings';
10
10
 
11
11
  export type Locales = Record<string, WalineLocale>;
12
12
 
13
- export const locales: Locales = {
13
+ export const defaultLocales: Locales = {
14
14
  zh: zhCN,
15
15
  'zh-cn': zhCN,
16
16
  'zh-CN': zhCN,
@@ -1,2 +1,3 @@
1
1
  export * from './default';
2
+ export * from './highlighter';
2
3
  export * from './i18n';
@@ -1,4 +1,4 @@
1
- export * from '../config';
1
+ export { defaultLocales } from '../config';
2
2
  export * from '../comment';
3
3
  export * from '../init';
4
4
  export * from '../pageview';
@@ -1,4 +1,4 @@
1
1
  export * from '../init';
2
- export * from '../config';
2
+ export { defaultLocales } from '../config';
3
3
  export * from '../typings';
4
4
  export * from '../version';
package/src/init.ts CHANGED
@@ -28,7 +28,7 @@ export interface WalineInstance {
28
28
  *
29
29
  * @description when not setting `path` option, it will be reset to `window.location.pathname`
30
30
  */
31
- update: (newOptions: Partial<Omit<WalineInitOptions, 'el'>>) => void;
31
+ update: (newOptions?: Partial<Omit<WalineInitOptions, 'el'>>) => void;
32
32
 
33
33
  /**
34
34
  * 取消挂载并摧毁 Waline 实例
@@ -96,7 +96,7 @@ export const init = ({
96
96
  pageview,
97
97
  path = window.location.pathname,
98
98
  ...newProps
99
- }: Partial<Omit<WalineInitOptions, 'el'>>): void => {
99
+ }: Partial<Omit<WalineInitOptions, 'el'>> = {}): void => {
100
100
  Object.entries(newProps).forEach(([key, value]) => {
101
101
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
102
102
  // @ts-ignore
@@ -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;
@@ -23,4 +23,6 @@ export interface WalineComment extends Exclude<WalineCommentData, 'ua'> {
23
23
  browser?: string;
24
24
  os?: string;
25
25
  level?: number;
26
+ addr?: string;
27
+ label?: string;
26
28
  }
@@ -6,7 +6,16 @@ export interface WalineDateLocale {
6
6
  now: string;
7
7
  }
8
8
 
9
- export interface WalineLocale extends WalineDateLocale {
9
+ export interface WalineLevelLocale {
10
+ level0: string;
11
+ level1: string;
12
+ level2: string;
13
+ level3: string;
14
+ level4: string;
15
+ level5: string;
16
+ }
17
+
18
+ export interface WalineLocale extends WalineDateLocale, WalineLevelLocale {
10
19
  nick: string;
11
20
  nickError: string;
12
21
  mail: string;
@@ -1,9 +1,10 @@
1
1
  import {
2
2
  defaultLang,
3
3
  defaultUploadImage,
4
+ defaultHighlighter,
4
5
  defaultTexRenderer,
5
6
  getMeta,
6
- locales,
7
+ defaultLocales,
7
8
  } from '../config';
8
9
 
9
10
  import { decodePath, isLinkHttp, removeEndingSplash } from './path';
@@ -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'>[];
@@ -66,14 +66,14 @@ export const getConfig = ({
66
66
  serverURL: getServerURL(serverURL),
67
67
  path: decodePath(path),
68
68
  locale: {
69
- ...(locales[lang] || locales[defaultLang]),
69
+ ...(defaultLocales[lang] || defaultLocales[defaultLang]),
70
70
  ...(typeof locale === 'object' ? locale : {}),
71
71
  },
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, hanabi),
76
+ highlighter: fallback(highlighter, defaultHighlighter),
77
77
  texRenderer: fallback(texRenderer, defaultTexRenderer),
78
78
  lang,
79
79
  dark,
@@ -1,9 +0,0 @@
1
- declare module 'hanabi' {
2
- const hanabi: (
3
- code: string,
4
- lang: string,
5
- callback?: (error: unknown, code?: string | undefined) => void
6
- ) => string | void;
7
-
8
- export default hanabi;
9
- }