UNPKG

16.2 kBTypeScriptView Raw
1type WalineCommentSorting = 'latest' | 'oldest' | 'hottest';
2type WalineEmojiPresets = `//${string}` | `http://${string}` | `https://${string}`;
3interface WalineEmojiInfo {
4 /**
5 * 选项卡上的 Emoji 名称
6 *
7 * Emoji name show on tab
8 */
9 name: string;
10 /**
11 * 所在文件夹链接
12 *
13 * Current folder link
14 */
15 folder?: string;
16 /**
17 * Emoji 通用路径前缀
18 *
19 * Common prefix of Emoji icons
20 */
21 prefix?: string;
22 /**
23 * Emoji 图片的类型,会作为文件扩展名使用
24 *
25 * Type of Emoji icons, will be regarded as file extension
26 */
27 type?: string;
28 /**
29 * 选项卡显示的 Emoji 图标
30 *
31 * Emoji icon show on tab
32 */
33 icon: string;
34 /**
35 * Emoji 图片列表
36 *
37 * Emoji image list
38 */
39 items: string[];
40}
41type WalineLoginStatus = 'enable' | 'disable' | 'force';
42interface WalineSearchImageData extends Record<string, unknown> {
43 /**
44 * 图片链接
45 *
46 * Image link
47 */
48 src: string;
49 /**
50 * 图片标题
51 *
52 * @description 用于图片的 alt 属性
53 *
54 * Image title
55 *
56 * @description Used for alt attribute of image
57 */
58 title?: string;
59 /**
60 * 图片缩略图
61 *
62 * @description 为了更好的加载性能,我们会优先在列表中使用此缩略图
63 *
64 * Image preview link
65 *
66 * @description For better loading performance, we will use this thumbnail first in the list
67 *
68 * @default src
69 */
70 preview?: string;
71}
72type WalineSearchResult = WalineSearchImageData[];
73interface WalineSearchOptions {
74 /**
75 * 搜索操作
76 *
77 * Search action
78 */
79 search: (word: string) => Promise<WalineSearchResult>;
80 /**
81 * 打开列表时展示的默认结果
82 *
83 * Default result when opening list
84 *
85 * @default () => search('')
86 */
87 default?: () => Promise<WalineSearchResult>;
88 /**
89 * 获取更多的操作
90 *
91 * @description 会在列表滚动到底部时触发,如果你的搜索服务支持分页功能,你应该设置此项实现无限滚动
92 *
93 * Fetch more action
94 *
95 * @description It will be triggered when the list scrolls to the bottom. If your search service supports paging, you should set this to achieve infinite scrolling
96 *
97 * @default (word) => search(word)
98 */
99 more?: (word: string, currentCount: number) => Promise<WalineSearchResult>;
100}
101type WalineMeta = 'nick' | 'mail' | 'link';
102type WalineImageUploader = (image: File) => Promise<string>;
103type WalineHighlighter = (code: string, lang: string) => string;
104type WalineTexRenderer = (blockMode: boolean, tex: string) => string;
105
106interface WalineDateLocale {
107 seconds: string;
108 minutes: string;
109 hours: string;
110 days: string;
111 now: string;
112}
113type WalineLevelLocale = Record<`level${number}`, string>;
114interface WalineReactionLocale {
115 reactionTitle: string;
116 reaction0: string;
117 reaction1: string;
118 reaction2: string;
119 reaction3: string;
120 reaction4: string;
121 reaction5: string;
122 reaction6: string;
123 reaction7: string;
124 reaction8: string;
125}
126interface WalineLocale extends WalineDateLocale, WalineLevelLocale, WalineReactionLocale {
127 nick: string;
128 mail: string;
129 link: string;
130 optional: string;
131 placeholder: string;
132 sofa: string;
133 submit: string;
134 comment: string;
135 refresh: string;
136 more: string;
137 uploading: string;
138 login: string;
139 admin: string;
140 sticky: string;
141 word: string;
142 anonymous: string;
143 gif: string;
144 gifSearchPlaceholder: string;
145 approved: string;
146 waiting: string;
147 spam: string;
148 unsticky: string;
149 oldest: string;
150 latest: string;
151 hottest: string;
152 nickError: string;
153 mailError: string;
154 wordHint: string;
155 like: string;
156 cancelLike: string;
157 reply: string;
158 cancelReply: string;
159 preview: string;
160 emoji: string;
161 uploadImage: string;
162 profile: string;
163 logout: string;
164}
165
166interface WalineProps {
167 /**
168 * Waline 的服务端地址
169 *
170 * Waline server address url
171 */
172 serverURL: string;
173 /**
174 * 当前 _文章页_ 路径,用于区分不同的 _文章页_ ,以保证正确读取该 _文章页_ 下的评论列表
175 *
176 * 你可以将其设置为 `window.location.pathname`
177 *
178 * Article path id. Used to distinguish different _article pages_ to ensure loading the correct comment list under the _article page_.
179 *
180 * You can set it to `window.location.pathname`
181 */
182 path: string;
183 /**
184 * 评论者相关属性
185 *
186 * `Meta` 可选值: `'nick'`, `'mail'`, `'link'`
187 *
188 * Reviewer attributes.
189 *
190 * Optional values for `Meta`: `'nick'`, `'mail'`, `'link'`
191 *
192 * @default ['nick', 'mail', 'link']
193 */
194 meta?: WalineMeta[];
195 /**
196 * 设置**必填项**,默认昵称为匿名
197 *
198 * Set required fields, default anonymous with nickname
199 *
200 * @default []
201 */
202 requiredMeta?: WalineMeta[];
203 /**
204 * 评论字数限制。填入单个数字时为最大字数限制
205 *
206 * @more 设置为 `0` 时无限制
207 *
208 * Comment word s limit. When a single number is filled in, it 's the maximum number of comment words.
209 *
210 * @more No limit when set to `0`.
211 *
212 * @default 0
213 */
214 wordLimit?: number | [number, number];
215 /**
216 * 评论列表分页,每页条数
217 *
218 * number of pages per page
219 *
220 * @default 10
221 */
222 pageSize?: number;
223 /**
224 * Waline 显示语言
225 *
226 * 可选值:
227 *
228 * - `'zh'`
229 * - `'zh-cn'`
230 * - `'zh-CN'`
231 * - `'zh-tw'`
232 * - `'zh-TW'`
233 * - `'en'`
234 * - `'en-US'`
235 * - `'en-us'`
236 * - `'jp'`
237 * - `'jp-jp'`
238 * - `'jp-JP'`
239 * - `'pt-br'`
240 * - `'pt-BR'`
241 * - `'ru'`
242 * - `'ru-ru'`
243 * - `'ru-RU'`
244 *
245 * Display language for waline
246 *
247 * Optional value:
248 *
249 * - `'zh'`
250 * - `'zh-cn'`
251 * - `'zh-CN'`
252 * - `'zh-tw'`
253 * - `'zh-TW'`
254 * - `'en'`
255 * - `'en-US'`
256 * - `'en-us'`
257 * - `'jp'`
258 * - `'jp-jp'`
259 * - `'jp-JP'`
260 * - `'pt-br'`
261 * - `'pt-BR'`
262 * - `'ru'`
263 * - `'ru-ru'`
264 * - `'ru-RU'`
265 *
266 * @default navigator.language
267 */
268 lang?: string;
269 /**
270 * 自定义 waline 语言显示
271 *
272 * @see [自定义语言](https://waline.js.org/client/i18n.html)
273 *
274 * Custom display language in waline
275 *
276 * @see [I18n](https://waline.js.org/en/client/i18n.html)
277 */
278 locale?: Partial<WalineLocale>;
279 /**
280 * 评论列表排序方式
281 *
282 * Sorting method for comment list
283 *
284 * @default 'latest'
285 */
286 commentSorting?: WalineCommentSorting;
287 /**
288 * 是否启用暗黑模式适配
289 *
290 * @more 设置 `'auto'` 会根据设备暗黑模式自适应。填入 CSS 选择器会在对应选择器生效时启用夜间模式。
291 *
292 * Whether to enable darkmode support
293 *
294 * @more Setting `'auto'` will display darkmode due to device settings. Filling in CSS selector will enable darkmode only when the selector match waline ancestor nodes.
295 */
296 dark?: string | boolean;
297 /**
298 * 设置表情包
299 *
300 * Set Emojis
301 *
302 * @default ['//unpkg.com/@waline/emojis@1.1.0/weibo']
303 */
304 emoji?: (WalineEmojiInfo | WalineEmojiPresets)[] | boolean;
305 /**
306 * 设置搜索功能
307 *
308 * Customize Search feature
309 *
310 * @default true
311 */
312 search?: WalineSearchOptions | boolean;
313 /**
314 * 代码高亮
315 *
316 * Code highlighting
317 *
318 * @default true
319 */
320 highlighter?: WalineHighlighter | boolean;
321 /**
322 * 自定义图片上传方法,方便更好的存储图片
323 *
324 * 方法执行时会将图片对象传入。
325 *
326 * Custom image upload callback to manage picture by yourself.
327 *
328 * We will pass a picture file object when execute it.
329 *
330 * @default true
331 */
332 imageUploader?: WalineImageUploader | boolean;
333 /**
334 * 自定义数学公式处理方法,用于预览。
335 *
336 * Custom math formula parse callback for preview.
337 *
338 * @default true
339 */
340 texRenderer?: WalineTexRenderer | boolean;
341 /**
342 *
343 * 登录模式状态,可选值:
344 *
345 * - `'enable'`: 启用登录 (默认)
346 * - `'disable'`: 禁用登录,用户只能填写信息评论
347 * - `'force'`: 强制登录,用户必须注册并登录才可发布评论
348 *
349 * Login mode status, optional values:
350 *
351 * - `'enable'`: enable login (default)
352 * - `'disable'`: Login is disabled, users should fill in information to comment
353 * - `'force'`: Forced login, users must login to comment
354 *
355 * @default 'enable'
356 */
357 login?: WalineLoginStatus;
358 /**
359 * 是否在页脚展示版权信息
360 *
361 * 为了支持 Waline,我们强烈建议你开启它
362 *
363 * Whether show copyright in footer
364 *
365 * We strongly recommended you to keep it on to support waline
366 *
367 * @default true
368 */
369 copyright?: boolean;
370 /**
371 * recaptcha v3 client key
372 */
373 recaptchaV3Key?: string;
374 /**
375 * reaction
376 */
377 reaction?: string[] | boolean;
378}
379
380interface WalineInitOptions extends Omit<WalineProps, 'path'> {
381 /**
382 * Waline 的初始化挂载器。必须是一个**有效的** CSS 选择器 或 HTML 元素
383 *
384 * The DOM element to be mounted on initialization. It must be a **valid** CSS selector string or HTML Element.
385 */
386 el?: string | HTMLElement | null;
387 /**
388 * 评论数统计
389 *
390 * Comment number support
391 *
392 * @default false
393 */
394 comment?: string | boolean;
395 /**
396 * 页面访问量统计
397 *
398 * Pageview number support
399 *
400 * @default false
401 */
402 pageview?: string | boolean;
403 /**
404 * 当前 _文章页_ 路径,用于区分不同的 _文章页_ ,以保证正确读取该 _文章页_ 下的评论列表
405 *
406 * 你可以将其设置为 `window.location.pathname`
407 *
408 * Article path id. Used to distinguish different _article pages_ to ensure loading the correct comment list under the _article page_.
409 *
410 * You can set it to `window.location.pathname`
411 *
412 * @default window.location.pathname
413 */
414 path?: string;
415}
416
417interface WalineInstance {
418 /**
419 * Waline 被挂载到的元素
420 *
421 * @description 当通过 `el: null` 初始化,值为 `null`
422 *
423 * Element where Waline is mounted
424 *
425 * @description when initialized with `el: null`, it will be `null`
426 */
427 el: HTMLElement | null;
428 /**
429 * 更新 Waline 实例
430 *
431 * @description 只要不设置`path` 选项,更新时它就会被重置为 `windows.location.pathname`
432 *
433 * Update Waline instance
434 *
435 * @description when not setting `path` option, it will be reset to `window.location.pathname`
436 */
437 update: (newOptions?: Partial<Omit<WalineInitOptions, 'el'>>) => void;
438 /**
439 * 取消挂载并摧毁 Waline 实例
440 *
441 * Unmount and destroy Waline instance
442 */
443 destroy: () => void;
444}
445
446type DeprecatedAvatar = '' | 'mp' | 'identicon' | 'monsterid' | 'wavatar' | 'retro' | 'robohash' | 'hide';
447type DeprecatedEmojiMaps = Record<string, string>;
448interface DeprecatedValineOptions {
449 /**
450 * @deprecated Use `locale.placeholder` instead, dropped in V2
451 */
452 placeholder?: string;
453 /**
454 * @deprecated Use `locale` instead, dropped in V2
455 */
456 langMode?: Partial<WalineLocale>;
457 /**
458 * @deprecated Use `requiredMeta` instead, dropped in V2
459 */
460 requiredFields?: WalineMeta[];
461 /**
462 * @deprecated Please use `AVATAR_PROXY` in server, dropped in V2
463 *
464 * [Gravatar](http://cn.gravatar.com/) 头像展示方式
465 *
466 * 可选值:
467 *
468 * - `''`
469 * - `'mp'`
470 * - `'identicon'`
471 * - `'monsterid'`
472 * - `'wavatar'`
473 * - `'retro'`
474 * - `'robohash'`
475 * - `'hide'`
476 *
477 * [Gravatar](http://gravatar.com/) type
478 *
479 * Optional value:
480 *
481 * - `''`
482 * - `'mp'`
483 * - `'identicon'`
484 * - `'monsterid'`
485 * - `'wavatar'`
486 * - `'retro'`
487 * - `'robohash'`
488 * - `'hide'`
489 *
490 * @default 'mp'
491 */
492 avatar?: DeprecatedAvatar;
493 /**
494 * @deprecated no longer needed, dropped in V2
495 *
496 * 每次访问是否**强制**拉取最新的*评论列表头像*
497 *
498 * Whether **force** pulling the latest avatar each time
499 *
500 * @default false
501 */
502 avatarForce?: boolean;
503 /**
504 * @deprecated Use `emojis` instead, dropped in V2
505 *
506 * 设置**表情包 CDN**
507 *
508 * @see [自定义表情包](https://waline.js.org/client/emoji.html)
509 *
510 * Set **Emoji Pack CDN**
511 *
512 * @see [Custom Emoji](https://waline.js.org/en/client/emoji.html)
513 *
514 * @default 'https://img.t.sinajs.cn/t4/appstyle/expression/ext/normal/'
515 */
516 emojiCDN?: string;
517 /**
518 * @deprecated Use `emojis` instead, dropped in V2
519 *
520 * 设置**表情包映射**
521 *
522 * @see [自定义表情](https://waline.js.org/client/emoji.html)
523 *
524 * Set **emoji maps**
525 *
526 * @see [Custom Emoji](https://waline.js.org/en/client/emoji.html)
527 *
528 * @default 微博表情包
529 */
530 emojiMaps?: DeprecatedEmojiMaps;
531}
532
533interface DeprecatedWalineOptions {
534 /**
535 * @deprecated Please use mathjax in server, dropped in V2
536 *
537 * 是否注入额外的样式添加对 `<math>` 块的兼容
538 *
539 * Whether injecting additional styles to support math block
540 *
541 * @default false
542 */
543 mathTagSupport?: boolean;
544 /**
545 * @deprecated use `pageview` instead, dropped in V2
546 *
547 * 文章访问量统计
548 *
549 * Article reading statistics
550 *
551 * @default false
552 */
553 visitor?: boolean;
554 /**
555 * @deprecated use `highlighter` instead, dropped in V2
556 *
557 * 代码高亮
558 *
559 * Code highlighting
560 */
561 highlight?: WalineHighlighter | false;
562 /**
563 * @deprecated use `imageUploader` instead, dropped in V2
564 *
565 * 自定义图片上传方法,方便更好的存储图片
566 *
567 * 方法执行时会将图片对象传入。
568 *
569 * Custom image upload callback to manage picture by yourself.
570 *
571 * We will pass a picture file object when execute it.
572 */
573 uploadImage?: WalineImageUploader | false;
574 /**
575 * @deprecated Use `login` instead, dropped in V2
576 *
577 * 是否允许登录评论
578 *
579 * 默认情况是两者都支持,设置为 `true` 表示仅支持匿名评论,`false` 表示仅支持登录评论。
580 *
581 * Whether to allow login comments.
582 *
583 * Both supported by default, set to `true` means only support anonymous comments, `false` means only support login comments.
584 *
585 * @default undefined
586 */
587 anonymous?: boolean;
588 /**
589 * @deprecated Please use `AVATAR_PROXY` in server, dropped in V2
590 *
591 * 设置 Gravatar 头像 CDN 地址
592 *
593 * Gravatar CDN baseURL
594 *
595 * @default 'https://www.gravatar.com/avatar'
596 */
597 avatarCDN?: string;
598 /**
599 * @deprecated Use `texRenderer` instead, dropped in V2
600 *
601 * 自定义 Tex 处理方法,用于预览。
602 *
603 * Custom math formula parse callback for preview.
604 */
605 previewMath?: WalineTexRenderer | false;
606 /**
607 * @deprecated use `copyright` instead, dropped in V2
608 *
609 * 是否在页脚展示版权信息
610 *
611 * 为了支持 Waline,我们强烈建议你开启它
612 *
613 * Whether show copyright in footer
614 *
615 * We strongly recommended you to keep it on to support waline
616 *
617 * @default true
618 */
619 copyRight?: boolean;
620}
621
622declare function legacyWaline(options: WalineInitOptions & DeprecatedValineOptions & DeprecatedWalineOptions): WalineInstance | null;
623
624export { WalineInstance, legacyWaline as default };