artalk 2.6.3 → 2.7.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/Artalk.css +1 -1
- package/dist/Artalk.es.js +7673 -7330
- package/dist/Artalk.iife.js +1 -1
- package/dist/Artalk.js +1 -1
- package/dist/ArtalkLite.css +1 -1
- package/dist/ArtalkLite.es.js +5304 -4961
- package/dist/ArtalkLite.iife.js +1 -1
- package/dist/ArtalkLite.js +1 -1
- package/dist/src/api/{api-base.d.ts → _base.d.ts} +3 -7
- package/dist/src/api/_options.d.ts +19 -0
- package/dist/src/api/{request.d.ts → _request.d.ts} +3 -3
- package/dist/src/api/admin.d.ts +1 -1
- package/dist/src/api/captcha.d.ts +1 -1
- package/dist/src/api/comment.d.ts +2 -2
- package/dist/src/api/index.d.ts +2 -4
- package/dist/src/api/page.d.ts +3 -3
- package/dist/src/api/site.d.ts +2 -2
- package/dist/src/api/system.d.ts +13 -3
- package/dist/src/api/upload.d.ts +1 -1
- package/dist/src/api/user.d.ts +2 -2
- package/dist/src/artalk.d.ts +14 -37
- package/dist/src/comment/actions.d.ts +1 -1
- package/dist/src/comment/comment.d.ts +3 -4
- package/dist/src/comment/render.d.ts +21 -3
- package/dist/src/comment/renders/actions.d.ts +2 -2
- package/dist/src/comment/renders/avatar.d.ts +2 -2
- package/dist/src/comment/renders/content.d.ts +2 -2
- package/dist/src/comment/renders/header.d.ts +2 -2
- package/dist/src/comment/renders/index.d.ts +2 -2
- package/dist/src/comment/renders/pending.d.ts +2 -2
- package/dist/src/comment/renders/reply-at.d.ts +2 -2
- package/dist/src/comment/renders/reply-to.d.ts +2 -2
- package/dist/src/components/action-btn.d.ts +3 -5
- package/dist/src/{lib → components}/checker/admin.d.ts +1 -1
- package/dist/src/{lib → components}/checker/captcha-renders.d.ts +1 -1
- package/dist/src/{lib → components}/checker/captcha.d.ts +1 -1
- package/dist/src/{lib → components}/checker/index.d.ts +10 -7
- package/dist/src/components/dark-mode.d.ts +2 -0
- package/dist/src/components/dialog.d.ts +1 -3
- package/dist/src/components/error-dialog.d.ts +8 -0
- package/dist/src/components/pagination.d.ts +4 -3
- package/dist/src/components/read-more-btn.d.ts +3 -3
- package/dist/src/config.d.ts +24 -8
- package/dist/src/context.d.ts +16 -35
- package/dist/src/data.d.ts +27 -0
- package/dist/src/defaults.d.ts +1 -1
- package/dist/src/editor/editor.d.ts +14 -59
- package/dist/src/editor/state.d.ts +20 -0
- package/dist/src/i18n/zh-CN.d.ts +1 -1
- package/dist/src/layer/index.d.ts +4 -3
- package/dist/src/layer/layer-manager.d.ts +9 -0
- package/dist/src/layer/layer.d.ts +8 -28
- package/dist/src/layer/scrollbar-helper.d.ts +5 -0
- package/dist/src/layer/sidebar-layer.d.ts +6 -6
- package/dist/src/layer/wrap.d.ts +13 -0
- package/dist/src/lib/component.d.ts +3 -8
- package/dist/src/lib/event-manager.d.ts +28 -0
- package/dist/src/lib/highlight.d.ts +1 -0
- package/dist/src/lib/marked-renderer.d.ts +4 -0
- package/dist/src/lib/marked.d.ts +4 -2
- package/dist/src/lib/sanitizer.d.ts +1 -0
- package/dist/src/lib/ui.d.ts +3 -2
- package/dist/src/lib/user.d.ts +8 -5
- package/dist/src/lib/utils.d.ts +11 -5
- package/dist/src/list/comment.d.ts +3 -0
- package/dist/src/list/layout.d.ts +23 -0
- package/dist/src/list/list.d.ts +13 -25
- package/dist/src/list/{list-nest.d.ts → nest.d.ts} +1 -1
- package/dist/src/list/page.d.ts +2 -0
- package/dist/src/list/paginator/index.d.ts +22 -7
- package/dist/src/list/paginator/read-more.d.ts +18 -0
- package/dist/src/list/paginator/up-down.d.ts +14 -0
- package/dist/src/main.d.ts +2 -0
- package/dist/src/plugins/admin-only-elem.d.ts +2 -0
- package/dist/src/plugins/conf-remoter.d.ts +2 -0
- package/dist/src/plugins/dark-mode.d.ts +2 -0
- package/dist/src/plugins/editor/_kit.d.ts +27 -0
- package/dist/src/plugins/editor/_plug.d.ts +29 -0
- package/dist/src/plugins/editor/_sample.d.ts +5 -0
- package/dist/src/plugins/editor/closable.d.ts +7 -0
- package/dist/src/{editor/plugs/emoticons-plug.d.ts → plugins/editor/emoticons.d.ts} +10 -16
- package/dist/src/plugins/editor/header-event.d.ts +6 -0
- package/dist/src/plugins/editor/header-link.d.ts +6 -0
- package/dist/src/plugins/editor/header-user.d.ts +16 -0
- package/dist/src/plugins/editor/index.d.ts +6 -0
- package/dist/src/plugins/editor/local-storage.d.ts +6 -0
- package/dist/src/plugins/editor/mover.d.ts +6 -0
- package/dist/src/plugins/editor/preview.d.ts +7 -0
- package/dist/src/plugins/editor/state-edit.d.ts +11 -0
- package/dist/src/plugins/editor/state-reply.d.ts +8 -0
- package/dist/src/plugins/editor/submit-add.d.ts +18 -0
- package/dist/src/plugins/editor/submit-btn.d.ts +5 -0
- package/dist/src/plugins/editor/submit.d.ts +17 -0
- package/dist/src/plugins/editor/textarea.d.ts +8 -0
- package/dist/src/plugins/editor/upload.d.ts +9 -0
- package/dist/src/plugins/editor-kit.d.ts +42 -0
- package/dist/src/plugins/index.d.ts +2 -0
- package/dist/src/plugins/list/copyright.d.ts +2 -0
- package/dist/src/plugins/list/count.d.ts +2 -0
- package/dist/src/plugins/list/dropdown.d.ts +2 -0
- package/dist/src/plugins/list/error-dialog.d.ts +2 -0
- package/dist/src/plugins/list/fetch.d.ts +2 -0
- package/dist/src/plugins/list/goto-first.d.ts +3 -0
- package/dist/src/plugins/list/goto.d.ts +2 -0
- package/dist/src/plugins/list/index.d.ts +3 -0
- package/dist/src/plugins/list/loading.d.ts +2 -0
- package/dist/src/plugins/list/no-comment.d.ts +2 -0
- package/dist/src/plugins/list/reach-bottom.d.ts +2 -0
- package/dist/src/plugins/list/sidebar-btn.d.ts +2 -0
- package/dist/src/plugins/list/time-ticking.d.ts +3 -0
- package/dist/src/plugins/list/unread-badge.d.ts +2 -0
- package/dist/src/plugins/list/unread.d.ts +2 -0
- package/dist/src/plugins/list/with-editor.d.ts +2 -0
- package/dist/src/plugins/markdown.d.ts +2 -0
- package/dist/src/plugins/stat.d.ts +13 -0
- package/dist/src/plugins/version-check.d.ts +2 -0
- package/dist/src/service.d.ts +19 -23
- package/dist/tests/e2e/comment-add.spec.d.ts +1 -0
- package/dist/types/config.d.ts +110 -0
- package/dist/types/context.d.ts +56 -136
- package/dist/types/data.d.ts +194 -0
- package/dist/types/editor.d.ts +76 -0
- package/dist/types/event.d.ts +36 -25
- package/dist/types/index.d.ts +7 -0
- package/dist/types/plugin.d.ts +2 -0
- package/dist/types/sidebar.d.ts +3 -0
- package/package.json +5 -2
- package/src/api/_base.ts +18 -0
- package/src/api/_options.ts +25 -0
- package/src/api/{request.ts → _request.ts} +19 -18
- package/src/api/admin.ts +1 -1
- package/src/api/captcha.ts +1 -1
- package/src/api/comment.ts +4 -4
- package/src/api/index.ts +3 -12
- package/src/api/page.ts +5 -5
- package/src/api/site.ts +2 -2
- package/src/api/system.ts +19 -7
- package/src/api/upload.ts +3 -3
- package/src/api/user.ts +3 -3
- package/src/artalk.ts +49 -97
- package/src/comment/actions.ts +1 -4
- package/src/comment/comment.ts +9 -6
- package/src/comment/render.ts +27 -5
- package/src/comment/renders/actions.ts +45 -45
- package/src/comment/renders/avatar.ts +7 -7
- package/src/comment/renders/content.ts +18 -18
- package/src/comment/renders/header.ts +13 -13
- package/src/comment/renders/index.ts +3 -3
- package/src/comment/renders/pending.ts +5 -5
- package/src/comment/renders/reply-at.ts +8 -8
- package/src/comment/renders/reply-to.ts +13 -13
- package/src/components/action-btn.ts +11 -13
- package/src/{lib → components}/checker/admin.ts +6 -6
- package/src/{lib → components}/checker/captcha-renders.ts +7 -6
- package/src/{lib → components}/checker/captcha.ts +1 -1
- package/src/{lib → components}/checker/index.ts +21 -26
- package/src/components/dark-mode.ts +30 -0
- package/src/components/dialog.ts +4 -9
- package/src/components/error-dialog.ts +35 -0
- package/src/components/pagination.ts +10 -6
- package/src/components/read-more-btn.ts +7 -7
- package/src/config.ts +60 -6
- package/src/context.ts +39 -144
- package/src/data.ts +110 -0
- package/src/defaults.ts +1 -1
- package/src/editor/editor.ts +41 -146
- package/src/editor/state.ts +52 -0
- package/src/i18n/zh-CN.ts +1 -1
- package/src/layer/index.ts +4 -4
- package/src/layer/layer-manager.ts +32 -0
- package/src/layer/layer.ts +20 -144
- package/src/layer/scrollbar-helper.ts +24 -0
- package/src/layer/sidebar-layer.ts +74 -64
- package/src/layer/wrap.ts +77 -0
- package/src/lib/component.ts +4 -11
- package/src/lib/detect.ts +1 -1
- package/src/lib/event-manager.ts +47 -0
- package/src/lib/highlight.ts +5 -0
- package/src/lib/marked-renderer.ts +32 -0
- package/src/lib/marked.ts +43 -104
- package/src/lib/sanitizer.ts +57 -0
- package/src/lib/ui.ts +22 -15
- package/src/lib/user.ts +21 -16
- package/src/lib/utils.ts +29 -18
- package/src/list/comment.ts +20 -0
- package/src/list/layout.ts +120 -0
- package/src/list/list.html +3 -1
- package/src/list/list.ts +56 -200
- package/src/list/{list-nest.ts → nest.ts} +1 -1
- package/src/list/page.ts +97 -0
- package/src/list/paginator/index.ts +20 -8
- package/src/list/paginator/read-more.ts +67 -0
- package/src/list/paginator/up-down.ts +51 -0
- package/src/main.ts +2 -0
- package/src/plugins/admin-only-elem.ts +40 -0
- package/src/plugins/conf-remoter.ts +54 -0
- package/src/plugins/dark-mode.ts +12 -0
- package/src/plugins/editor/_kit.ts +57 -0
- package/src/plugins/editor/_plug.ts +60 -0
- package/src/plugins/editor/_sample.ts +8 -0
- package/src/plugins/editor/closable.ts +44 -0
- package/src/{editor/plugs/emoticons-plug.ts → plugins/editor/emoticons.ts} +51 -52
- package/src/plugins/editor/header-event.ts +35 -0
- package/src/plugins/editor/header-link.ts +31 -0
- package/src/plugins/editor/header-user.ts +98 -0
- package/src/plugins/editor/index.ts +40 -0
- package/src/plugins/editor/local-storage.ts +36 -0
- package/src/plugins/editor/mover.ts +29 -0
- package/src/plugins/editor/preview.ts +41 -0
- package/src/plugins/editor/state-edit.ts +116 -0
- package/src/plugins/editor/state-reply.ts +91 -0
- package/src/plugins/editor/submit-add.ts +33 -0
- package/src/plugins/editor/submit-btn.ts +25 -0
- package/src/plugins/editor/submit.ts +73 -0
- package/src/plugins/editor/textarea.ts +55 -0
- package/src/plugins/editor/upload.ts +145 -0
- package/src/plugins/editor-kit.ts +161 -0
- package/src/plugins/index.ts +16 -0
- package/src/plugins/list/copyright.ts +16 -0
- package/src/plugins/list/count.ts +31 -0
- package/src/plugins/list/dropdown.ts +95 -0
- package/src/plugins/list/error-dialog.ts +22 -0
- package/src/plugins/list/fetch.ts +64 -0
- package/src/plugins/list/goto-first.ts +23 -0
- package/src/plugins/list/goto.ts +72 -0
- package/src/plugins/list/index.ts +25 -0
- package/src/plugins/list/loading.ts +17 -0
- package/src/plugins/list/no-comment.ts +25 -0
- package/src/plugins/list/reach-bottom.ts +46 -0
- package/src/plugins/list/sidebar-btn.ts +39 -0
- package/src/plugins/list/time-ticking.ts +22 -0
- package/src/plugins/list/unread-badge.ts +26 -0
- package/src/plugins/list/unread.ts +38 -0
- package/src/plugins/list/with-editor.ts +59 -0
- package/src/plugins/markdown.ts +10 -0
- package/src/plugins/stat.ts +79 -0
- package/src/plugins/version-check.ts +37 -0
- package/src/service.ts +34 -61
- package/src/style/comment.scss +5 -7
- package/src/style/editor.scss +5 -0
- package/src/style/list.scss +2 -7
- package/types/{artalk-config.d.ts → config.ts} +16 -2
- package/types/context.ts +84 -0
- package/{dist/types/artalk-data.d.ts → types/data.ts} +41 -0
- package/types/editor.ts +95 -0
- package/types/event.ts +40 -0
- package/types/index.ts +7 -0
- package/types/plugin.ts +3 -0
- package/types/sidebar.ts +3 -0
- package/dist/src/comment/render-ctx.d.ts +0 -23
- package/dist/src/editor/edit-mode.d.ts +0 -9
- package/dist/src/editor/funcs.d.ts +0 -2
- package/dist/src/editor/index.d.ts +0 -2
- package/dist/src/editor/mover.d.ts +0 -8
- package/dist/src/editor/plug-manager.d.ts +0 -17
- package/dist/src/editor/plugs/editor-plug.d.ts +0 -38
- package/dist/src/editor/plugs/header-input-plug.d.ts +0 -13
- package/dist/src/editor/plugs/preview-plug.d.ts +0 -10
- package/dist/src/editor/plugs/upload-plug.d.ts +0 -10
- package/dist/src/editor/reply.d.ts +0 -9
- package/dist/src/editor/submit.d.ts +0 -16
- package/dist/src/lib/dark-mode.d.ts +0 -4
- package/dist/src/lib/stat.d.ts +0 -15
- package/dist/src/list/index.d.ts +0 -2
- package/dist/src/list/list-lite.d.ts +0 -77
- package/dist/src/list/list-ui.d.ts +0 -16
- package/dist/src/list/paginator/adaptors/index.d.ts +0 -12
- package/dist/src/list/paginator/adaptors/pagination.d.ts +0 -9
- package/dist/src/list/paginator/adaptors/read-more.d.ts +0 -10
- package/dist/src/list/paginator/holder.d.ts +0 -16
- package/dist/types/artalk-config.d.ts +0 -139
- package/dist/types/plug.d.ts +0 -4
- package/src/api/api-base.ts +0 -27
- package/src/comment/render-ctx.ts +0 -30
- package/src/editor/edit-mode.ts +0 -103
- package/src/editor/funcs.ts +0 -97
- package/src/editor/index.ts +0 -3
- package/src/editor/mover.ts +0 -43
- package/src/editor/plug-manager.ts +0 -172
- package/src/editor/plugs/editor-plug.ts +0 -69
- package/src/editor/plugs/header-input-plug.ts +0 -79
- package/src/editor/plugs/preview-plug.ts +0 -44
- package/src/editor/plugs/upload-plug.ts +0 -122
- package/src/editor/reply.ts +0 -62
- package/src/editor/submit.ts +0 -99
- package/src/lib/dark-mode.ts +0 -48
- package/src/lib/stat.ts +0 -71
- package/src/list/index.ts +0 -3
- package/src/list/list-lite.ts +0 -424
- package/src/list/list-ui.ts +0 -137
- package/src/list/paginator/adaptors/index.ts +0 -21
- package/src/list/paginator/adaptors/pagination.ts +0 -42
- package/src/list/paginator/adaptors/read-more.ts +0 -56
- package/src/list/paginator/holder.ts +0 -56
- package/types/artalk-data.d.ts +0 -230
- package/types/context.d.ts +0 -142
- package/types/event.d.ts +0 -28
- package/types/plug.d.ts +0 -4
- /package/src/{editor/plugs/emoticons-plug.scss → plugins/editor/emoticons.scss} +0 -0
- /package/src/{editor/plugs/preview-plug.scss → plugins/editor/preview.scss} +0 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
|
|
2
|
+
|
|
3
|
+
import { ApiOptions } from './_options'
|
|
2
4
|
import User from '../lib/user'
|
|
3
5
|
import $t from '../i18n'
|
|
4
6
|
|
|
5
7
|
/** 公共请求函数 */
|
|
6
|
-
export async function Fetch(
|
|
8
|
+
export async function Fetch(opts: ApiOptions, input: RequestInfo, init: RequestInit, timeout?: number): Promise<any> {
|
|
7
9
|
// JWT
|
|
8
10
|
if (User.data.token) {
|
|
9
11
|
const headers = new Headers(init.headers) // 保留原有 headers
|
|
@@ -15,7 +17,7 @@ export async function Fetch(ctx: Context, input: RequestInfo, init: RequestInit,
|
|
|
15
17
|
// init.credentials = 'include'
|
|
16
18
|
|
|
17
19
|
// 请求操作
|
|
18
|
-
const resp = await timeoutFetch(
|
|
20
|
+
const resp = await timeoutFetch(input, timeout || opts.timeout || 15000, init)
|
|
19
21
|
|
|
20
22
|
const respHttpCode = resp.status
|
|
21
23
|
const noAccessCodes = [401, 400]
|
|
@@ -29,7 +31,7 @@ export async function Fetch(ctx: Context, input: RequestInfo, init: RequestInit,
|
|
|
29
31
|
|
|
30
32
|
// 重新发起请求
|
|
31
33
|
const recall = (resolve, reject) => {
|
|
32
|
-
Fetch(
|
|
34
|
+
Fetch(opts, input, init)
|
|
33
35
|
.then(d => { resolve(d) })
|
|
34
36
|
.catch(e => { reject(e) })
|
|
35
37
|
}
|
|
@@ -38,19 +40,18 @@ export async function Fetch(ctx: Context, input: RequestInfo, init: RequestInit,
|
|
|
38
40
|
if (json.data?.need_captcha) {
|
|
39
41
|
// 请求需要验证码
|
|
40
42
|
json = await (new Promise<any>((resolve, reject) => {
|
|
41
|
-
|
|
42
|
-
imgData: json.data.img_data,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
onCancel: () => { reject(json) }
|
|
43
|
+
opts.onNeedCheckCaptcha && opts.onNeedCheckCaptcha({
|
|
44
|
+
data: { imgData: json.data.img_data, iframe: json.data.iframe },
|
|
45
|
+
recall: () => { recall(resolve, reject) },
|
|
46
|
+
reject: () => { reject(json) }
|
|
46
47
|
})
|
|
47
48
|
}))
|
|
48
49
|
} else if (json.data?.need_login || isNoAccess) {
|
|
49
50
|
// 请求需要管理员权限
|
|
50
51
|
json = await (new Promise<any>((resolve, reject) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
opts.onNeedCheckAdmin && opts.onNeedCheckAdmin({
|
|
53
|
+
recall: () => { recall(resolve, reject) },
|
|
54
|
+
reject: () => { reject(json) }
|
|
54
55
|
})
|
|
55
56
|
}))
|
|
56
57
|
}
|
|
@@ -61,20 +62,20 @@ export async function Fetch(ctx: Context, input: RequestInfo, init: RequestInit,
|
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
/** 公共 POST 请求 */
|
|
64
|
-
export async function POST<T>(
|
|
65
|
+
export async function POST<T>(opts: ApiOptions, url: string, data?: {[key: string]: any}) {
|
|
65
66
|
const init: RequestInit = {
|
|
66
67
|
method: 'POST',
|
|
67
68
|
}
|
|
68
|
-
data = { site_name:
|
|
69
|
+
data = { site_name: opts.siteName || '', ...(data || {}) } // 总是携带 site_name
|
|
69
70
|
init.body = ToFormData(data)
|
|
70
71
|
|
|
71
|
-
const json = await Fetch(
|
|
72
|
+
const json = await Fetch(opts, url, init)
|
|
72
73
|
return ((json.data || {}) as T)
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
/** 公共 GET 请求 (无 GET 方式 API) */
|
|
76
|
-
// export async function GET<T>(
|
|
77
|
-
// const json = await Fetch(
|
|
77
|
+
// export async function GET<T>(opts: ApiOptions, url: string, data?: {[key: string]: any}) {
|
|
78
|
+
// const json = await Fetch(opts, url + (data ? (`?${new URLSearchParams(data)}`) : ''), {
|
|
78
79
|
// method: 'GET',
|
|
79
80
|
// })
|
|
80
81
|
// return ((json.data || {}) as T)
|
|
@@ -88,7 +89,7 @@ export function ToFormData(object: {[key: string]: any}): FormData {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/** 我靠,fetch 一个 timeout,都要丑陋的实现 */
|
|
91
|
-
function timeoutFetch(
|
|
92
|
+
function timeoutFetch(url: RequestInfo, ms: number, opts: RequestInit) {
|
|
92
93
|
const controller = new AbortController()
|
|
93
94
|
opts.signal?.addEventListener('abort', () => controller.abort()) // 保留原有 signal 功能
|
|
94
95
|
let promise = fetch(url, { ...opts, signal: controller.signal })
|
package/src/api/admin.ts
CHANGED
package/src/api/captcha.ts
CHANGED
package/src/api/comment.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CommentData, ListData } from '~/types
|
|
1
|
+
import type { CommentData, ListData } from '~/types'
|
|
2
2
|
import * as Utils from '../lib/utils'
|
|
3
|
-
import ApiBase from './
|
|
3
|
+
import ApiBase from './_base'
|
|
4
4
|
import User from '../lib/user'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -10,8 +10,8 @@ export default class CommentApi extends ApiBase {
|
|
|
10
10
|
/** 评论 · 获取 */
|
|
11
11
|
public get(offset: number, pageSize: number, flatMode?: boolean, paramsEditor?: (params: any) => void) {
|
|
12
12
|
const params: any = {
|
|
13
|
-
page_key: this.
|
|
14
|
-
site_name: this.
|
|
13
|
+
page_key: this.options.pageKey,
|
|
14
|
+
site_name: this.options.siteName,
|
|
15
15
|
limit: pageSize,
|
|
16
16
|
offset,
|
|
17
17
|
}
|
package/src/api/index.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
|
|
3
|
-
|
|
1
|
+
import { ApiOptions } from './_options'
|
|
4
2
|
import comment from './comment'
|
|
5
3
|
import page from './page'
|
|
6
4
|
import site from './site'
|
|
@@ -17,16 +15,9 @@ const ApiComponents = {
|
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
class Api {
|
|
20
|
-
|
|
21
|
-
public get baseURL() {
|
|
22
|
-
return `${this.ctx.conf.server}/api`
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
constructor (ctx: Context) {
|
|
26
|
-
this.ctx = ctx
|
|
27
|
-
|
|
18
|
+
constructor (opts: ApiOptions) {
|
|
28
19
|
Object.entries(ApiComponents).forEach(([key, ApiComponent]) => {
|
|
29
|
-
this[key] = new ApiComponent(
|
|
20
|
+
this[key] = new ApiComponent(opts)
|
|
30
21
|
})
|
|
31
22
|
}
|
|
32
23
|
}
|
package/src/api/page.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { PageData, CommentData } from '~/types
|
|
2
|
-
import ApiBase from './
|
|
1
|
+
import type { PageData, CommentData } from '~/types'
|
|
2
|
+
import ApiBase from './_base'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 页面 API
|
|
@@ -24,7 +24,7 @@ export default class PageApi extends ApiBase {
|
|
|
24
24
|
key: data.key,
|
|
25
25
|
title: data.title,
|
|
26
26
|
admin_only: data.admin_only,
|
|
27
|
-
site_name: data.site_name || this.
|
|
27
|
+
site_name: data.site_name || this.options.siteName,
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
const d = await this.POST<any>('/admin/page-edit', params)
|
|
@@ -55,8 +55,8 @@ export default class PageApi extends ApiBase {
|
|
|
55
55
|
/** PV */
|
|
56
56
|
public async pv() {
|
|
57
57
|
const params: any = {
|
|
58
|
-
page_key: this.
|
|
59
|
-
page_title: this.
|
|
58
|
+
page_key: this.options.pageKey || '',
|
|
59
|
+
page_title: this.options.pageTitle || ''
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
const p = await this.POST<any>('/pv', params)
|
package/src/api/site.ts
CHANGED
package/src/api/system.ts
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
import ArtalkConfig from '~/types
|
|
2
|
-
import ApiBase from './
|
|
3
|
-
|
|
1
|
+
import type { ArtalkConfig } from '~/types'
|
|
2
|
+
import ApiBase from './_base'
|
|
3
|
+
|
|
4
|
+
interface ApiVersionInfo {
|
|
5
|
+
app: string
|
|
6
|
+
version: string
|
|
7
|
+
commit_hash: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface SystemConfResp {
|
|
11
|
+
frontend_conf: Partial<ArtalkConfig>
|
|
12
|
+
version: ApiVersionInfo
|
|
13
|
+
}
|
|
4
14
|
|
|
5
15
|
/**
|
|
6
16
|
* 系统 API
|
|
7
17
|
*/
|
|
8
18
|
export default class SystemApi extends ApiBase {
|
|
9
19
|
/** 获取配置 */
|
|
10
|
-
public async conf() {
|
|
20
|
+
public async conf(): Promise<SystemConfResp> {
|
|
11
21
|
const data = await this.POST<any>(`/conf`)
|
|
12
|
-
const conf = (data.frontend_conf || {}) as ArtalkConfig
|
|
13
22
|
|
|
14
|
-
return
|
|
23
|
+
return {
|
|
24
|
+
frontend_conf: data.frontend_conf,
|
|
25
|
+
version: data.version,
|
|
26
|
+
}
|
|
15
27
|
}
|
|
16
28
|
|
|
17
29
|
/** 获取配置数据 */
|
|
@@ -30,7 +42,7 @@ export default class SystemApi extends ApiBase {
|
|
|
30
42
|
|
|
31
43
|
/** 获取 API 版本信息 */
|
|
32
44
|
public async version() {
|
|
33
|
-
const resp = await fetch(`${this.
|
|
45
|
+
const resp = await fetch(`${this.options.baseURL}/version`, { method: 'POST' })
|
|
34
46
|
const data = await resp.json()
|
|
35
47
|
return data as { app: string, version: string, commit_hash: string, fe_min_version: string }
|
|
36
48
|
}
|
package/src/api/upload.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ToFormData } from './
|
|
2
|
-
import ApiBase from './
|
|
1
|
+
import { ToFormData } from './_request'
|
|
2
|
+
import ApiBase from './_base'
|
|
3
3
|
import User from '../lib/user'
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -11,7 +11,7 @@ export default class UploadApi extends ApiBase {
|
|
|
11
11
|
const params: any = {
|
|
12
12
|
name: User.data.nick,
|
|
13
13
|
email: User.data.email,
|
|
14
|
-
page_key: this.
|
|
14
|
+
page_key: this.options.pageKey,
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const form = ToFormData(params)
|
package/src/api/user.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { UserData, NotifyData, UserDataForAdmin } from '~/types
|
|
2
|
-
import ApiBase from './
|
|
3
|
-
import { ToFormData } from './
|
|
1
|
+
import type { UserData, NotifyData, UserDataForAdmin } from '~/types'
|
|
2
|
+
import ApiBase from './_base'
|
|
3
|
+
import { ToFormData } from './_request'
|
|
4
4
|
import User from '../lib/user'
|
|
5
5
|
|
|
6
6
|
/**
|
package/src/artalk.ts
CHANGED
|
@@ -1,105 +1,84 @@
|
|
|
1
1
|
import './style/main.scss'
|
|
2
2
|
|
|
3
|
-
import type ArtalkConfig from '~/types
|
|
4
|
-
import type {
|
|
5
|
-
import type ArtalkPlug from '~/types/plug'
|
|
6
|
-
import type Context from '~/types/context'
|
|
3
|
+
import type { ArtalkConfig, EventPayloadMap, ArtalkPlugin, ContextApi } from '~/types'
|
|
4
|
+
import type { EventHandler } from './lib/event-manager'
|
|
7
5
|
import ConcreteContext from './context'
|
|
8
6
|
import defaults from './defaults'
|
|
9
|
-
import {
|
|
7
|
+
import { handelCustomConf, convertApiOptions } from './config'
|
|
10
8
|
import Services from './service'
|
|
11
|
-
import
|
|
12
|
-
import
|
|
9
|
+
import { DefaultPlugins } from './plugins'
|
|
10
|
+
import * as Stat from './plugins/stat'
|
|
13
11
|
import Api from './api'
|
|
14
12
|
|
|
13
|
+
/** Global Plugins for all instances */
|
|
14
|
+
const GlobalPlugins: ArtalkPlugin[] = [ ...DefaultPlugins ]
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* Artalk
|
|
17
18
|
*
|
|
18
19
|
* @see https://artalk.js.org
|
|
19
20
|
*/
|
|
20
21
|
export default class Artalk {
|
|
21
|
-
private static instance?: Artalk
|
|
22
|
-
|
|
23
|
-
public static ListLite = ListLite
|
|
24
|
-
public static readonly defaults: ArtalkConfig = defaults
|
|
25
|
-
|
|
26
22
|
public conf!: ArtalkConfig
|
|
27
|
-
public ctx!:
|
|
23
|
+
public ctx!: ContextApi
|
|
28
24
|
public $root!: HTMLElement
|
|
29
25
|
|
|
30
26
|
/** Plugins */
|
|
31
|
-
protected
|
|
32
|
-
public static DisabledComponents: string[] = []
|
|
27
|
+
protected plugins: ArtalkPlugin[] = [ ...GlobalPlugins ]
|
|
33
28
|
|
|
34
29
|
constructor(conf: Partial<ArtalkConfig>) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// 初始化基本配置
|
|
38
|
-
this.conf = handelBaseConf(conf)
|
|
30
|
+
// Init Config
|
|
31
|
+
this.conf = handelCustomConf(conf)
|
|
39
32
|
if (this.conf.el instanceof HTMLElement) this.$root = this.conf.el
|
|
40
33
|
|
|
41
|
-
//
|
|
34
|
+
// Init Context
|
|
42
35
|
this.ctx = new ConcreteContext(this.conf, this.$root)
|
|
43
36
|
|
|
44
|
-
//
|
|
37
|
+
// Init Services
|
|
45
38
|
Object.entries(Services).forEach(([name, initService]) => {
|
|
46
|
-
if (Artalk.DisabledComponents.includes(name)) return
|
|
47
39
|
const obj = initService(this.ctx)
|
|
48
40
|
if (obj) this.ctx.inject(name as any, obj) // auto inject deps to ctx
|
|
49
41
|
})
|
|
50
42
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
if (typeof plugin === 'function')
|
|
54
|
-
plugin(this.ctx)
|
|
43
|
+
// Init Plugins
|
|
44
|
+
this.plugins.forEach(plugin => {
|
|
45
|
+
if (typeof plugin === 'function') plugin(this.ctx)
|
|
55
46
|
})
|
|
56
|
-
}
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (this.instance) Artalk.destroy()
|
|
61
|
-
this.instance = new Artalk(conf)
|
|
62
|
-
return this.instance
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Use Plugin (plugin will be called in instance `use` func) */
|
|
66
|
-
public use(plugin: ArtalkPlug) {
|
|
67
|
-
Artalk.plugins.push(plugin)
|
|
68
|
-
if (typeof plugin === 'function') plugin(this.ctx)
|
|
48
|
+
// Trigger inited event
|
|
49
|
+
this.ctx.trigger('inited')
|
|
69
50
|
}
|
|
70
51
|
|
|
71
52
|
/** Update config of Artalk */
|
|
72
53
|
public update(conf: Partial<ArtalkConfig>) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
return Artalk.instance
|
|
54
|
+
this.ctx.updateConf(conf)
|
|
55
|
+
return this
|
|
76
56
|
}
|
|
77
57
|
|
|
78
58
|
/** Reload comment list of Artalk */
|
|
79
59
|
public reload() {
|
|
80
|
-
this.ctx.
|
|
60
|
+
this.ctx.reload()
|
|
81
61
|
}
|
|
82
62
|
|
|
83
63
|
/** Destroy instance of Artalk */
|
|
84
64
|
public destroy() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
delete Artalk.instance
|
|
65
|
+
this.ctx.trigger('destroy')
|
|
66
|
+
this.$root.remove()
|
|
88
67
|
}
|
|
89
68
|
|
|
90
69
|
/** Add an event listener */
|
|
91
|
-
public on<K extends keyof EventPayloadMap>(name: K, handler:
|
|
92
|
-
this.ctx.on(name, handler
|
|
70
|
+
public on<K extends keyof EventPayloadMap>(name: K, handler: EventHandler<EventPayloadMap[K]>) {
|
|
71
|
+
this.ctx.on(name, handler)
|
|
93
72
|
}
|
|
94
73
|
|
|
95
74
|
/** Remove an event listener */
|
|
96
|
-
public off<K extends keyof EventPayloadMap>(name: K, handler:
|
|
97
|
-
this.ctx.off(name, handler
|
|
75
|
+
public off<K extends keyof EventPayloadMap>(name: K, handler: EventHandler<EventPayloadMap[K]>) {
|
|
76
|
+
this.ctx.off(name, handler)
|
|
98
77
|
}
|
|
99
78
|
|
|
100
79
|
/** Trigger an event */
|
|
101
80
|
public trigger<K extends keyof EventPayloadMap>(name: K, payload?: EventPayloadMap[K]) {
|
|
102
|
-
this.ctx.trigger(name, payload
|
|
81
|
+
this.ctx.trigger(name, payload)
|
|
103
82
|
}
|
|
104
83
|
|
|
105
84
|
/** Set dark mode */
|
|
@@ -108,60 +87,33 @@ export default class Artalk {
|
|
|
108
87
|
}
|
|
109
88
|
|
|
110
89
|
// ===========================
|
|
111
|
-
// Static
|
|
90
|
+
// Static Members
|
|
112
91
|
// ===========================
|
|
113
92
|
|
|
114
|
-
/**
|
|
115
|
-
public static
|
|
116
|
-
this.plugins.push(plugin)
|
|
117
|
-
if (this.instance && typeof plugin === 'function') plugin(this.instance.ctx)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** Update config of Artalk */
|
|
121
|
-
public static update(conf: Partial<ArtalkConfig>) {
|
|
122
|
-
return this.instance?.update(conf)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** Reload comment list of Artalk */
|
|
126
|
-
public static reload() {
|
|
127
|
-
this.instance?.reload()
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** Destroy instance of Artalk */
|
|
131
|
-
public static destroy() {
|
|
132
|
-
this.instance?.destroy()
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** Add an event listener */
|
|
136
|
-
public static on<K extends keyof EventPayloadMap>(name: K, handler: Handler<EventPayloadMap[K]>) {
|
|
137
|
-
this.instance?.on(name, handler)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/** Remove an event listener */
|
|
141
|
-
public static off<K extends keyof EventPayloadMap>(name: K, handler: Handler<EventPayloadMap[K]>) {
|
|
142
|
-
this.instance?.off(name, handler)
|
|
143
|
-
}
|
|
93
|
+
/** Default Configs */
|
|
94
|
+
public static readonly defaults: ArtalkConfig = defaults
|
|
144
95
|
|
|
145
|
-
/**
|
|
146
|
-
public static
|
|
147
|
-
|
|
96
|
+
/** Init Artalk */
|
|
97
|
+
public static init(conf: Partial<ArtalkConfig>): Artalk {
|
|
98
|
+
return new Artalk(conf)
|
|
148
99
|
}
|
|
149
100
|
|
|
150
|
-
/**
|
|
151
|
-
public static
|
|
152
|
-
|
|
101
|
+
/** Use plugin, the plugin will be used when Artalk.init */
|
|
102
|
+
public static use(plugin: ArtalkPlugin) {
|
|
103
|
+
if (GlobalPlugins.includes(plugin)) return
|
|
104
|
+
GlobalPlugins.push(plugin)
|
|
153
105
|
}
|
|
154
106
|
|
|
155
107
|
/** Load count widget */
|
|
156
|
-
public static loadCountWidget(
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
Stat.initCountWidget({
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
108
|
+
public static loadCountWidget(c: Partial<ArtalkConfig>) {
|
|
109
|
+
const conf = handelCustomConf(c)
|
|
110
|
+
|
|
111
|
+
Stat.initCountWidget({
|
|
112
|
+
getApi: () => new Api(convertApiOptions(conf)),
|
|
113
|
+
pageKey: conf.pageKey,
|
|
114
|
+
countEl: conf.countEl,
|
|
115
|
+
pvEl: conf.pvEl,
|
|
116
|
+
pvAdd: false
|
|
117
|
+
})
|
|
166
118
|
}
|
|
167
119
|
}
|
package/src/comment/actions.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Comment from './comment'
|
|
1
|
+
import type Comment from './comment'
|
|
2
2
|
import ActionBtn from '../components/action-btn'
|
|
3
3
|
|
|
4
4
|
export default class CommentActions {
|
|
@@ -50,9 +50,6 @@ export default class CommentActions {
|
|
|
50
50
|
|
|
51
51
|
// 刷新当前 Comment UI
|
|
52
52
|
this.comment.setData(data)
|
|
53
|
-
|
|
54
|
-
// 刷新 List UI
|
|
55
|
-
this.ctx.listRefreshUI()
|
|
56
53
|
}).catch((err) => {
|
|
57
54
|
console.error(err)
|
|
58
55
|
btnElem.setError(this.ctx.$t('editFail'))
|
package/src/comment/comment.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { CommentData } from '~/types
|
|
2
|
-
import Context from '~/types/context'
|
|
1
|
+
import type { CommentData, ContextApi } from '~/types'
|
|
3
2
|
import Component from '../lib/component'
|
|
4
3
|
import * as Utils from '../lib/utils'
|
|
5
4
|
import marked from '../lib/marked'
|
|
@@ -31,7 +30,7 @@ export default class Comment extends Component {
|
|
|
31
30
|
private nestCurt: number // 当前嵌套层数
|
|
32
31
|
private nestMax: number // 最大嵌套层数
|
|
33
32
|
|
|
34
|
-
constructor(ctx:
|
|
33
|
+
constructor(ctx: ContextApi, data: CommentData, conf: CommentConf) {
|
|
35
34
|
super(ctx)
|
|
36
35
|
|
|
37
36
|
// 最大嵌套数
|
|
@@ -160,17 +159,21 @@ export default class Comment extends Component {
|
|
|
160
159
|
|
|
161
160
|
/** 获取 Gravatar 头像 URL */
|
|
162
161
|
public getGravatarURL() {
|
|
163
|
-
return Utils.getGravatarURL(
|
|
162
|
+
return Utils.getGravatarURL({
|
|
163
|
+
mirror: this.ctx.conf.gravatar.mirror,
|
|
164
|
+
params: this.ctx.conf.gravatar.params,
|
|
165
|
+
emailMD5: this.data.email_encrypted,
|
|
166
|
+
})
|
|
164
167
|
}
|
|
165
168
|
|
|
166
169
|
/** 获取评论 markdown 解析后的内容 */
|
|
167
170
|
public getContentMarked() {
|
|
168
|
-
return marked(this.
|
|
171
|
+
return marked(this.data.content)
|
|
169
172
|
}
|
|
170
173
|
|
|
171
174
|
/** 获取格式化后的日期 */
|
|
172
175
|
public getDateFormatted() {
|
|
173
|
-
return Utils.timeAgo(new Date(this.data.date), this.ctx)
|
|
176
|
+
return Utils.timeAgo(new Date(this.data.date), this.ctx.$t)
|
|
174
177
|
}
|
|
175
178
|
|
|
176
179
|
/** 获取用户 UserAgent 信息 */
|
package/src/comment/render.ts
CHANGED
|
@@ -1,15 +1,37 @@
|
|
|
1
|
+
import type Comment from './comment'
|
|
2
|
+
import ActionBtn from '../components/action-btn'
|
|
1
3
|
import * as Utils from '../lib/utils'
|
|
2
4
|
import * as Ui from '../lib/ui'
|
|
3
5
|
|
|
6
|
+
import * as HeightLimit from './height-limit'
|
|
4
7
|
import CommentHTML from './comment.html?raw'
|
|
5
|
-
import Comment from './comment'
|
|
6
|
-
import RenderCtx from './render-ctx'
|
|
7
8
|
import loadRenders from './renders'
|
|
8
|
-
import * as HeightLimit from './height-limit'
|
|
9
9
|
|
|
10
|
-
export default class
|
|
10
|
+
export default class Render {
|
|
11
|
+
public comment: Comment
|
|
12
|
+
|
|
13
|
+
public get ctx() { return this.comment.ctx }
|
|
14
|
+
public get data() { return this.comment.getData() }
|
|
15
|
+
public get conf() { return this.comment.conf }
|
|
16
|
+
public get cConf() { return this.comment.getConf() }
|
|
17
|
+
|
|
18
|
+
public $el!: HTMLElement
|
|
19
|
+
public $main!: HTMLElement
|
|
20
|
+
public $header!: HTMLElement
|
|
21
|
+
public $headerNick!: HTMLElement
|
|
22
|
+
public $headerBadgeWrap!: HTMLElement
|
|
23
|
+
public $body!: HTMLElement
|
|
24
|
+
public $content!: HTMLElement
|
|
25
|
+
public $childrenWrap!: HTMLElement|null
|
|
26
|
+
public $actions!: HTMLElement
|
|
27
|
+
public voteBtnUp?: ActionBtn
|
|
28
|
+
public voteBtnDown?: ActionBtn
|
|
29
|
+
|
|
30
|
+
public $replyTo?: HTMLElement // 回复评论内容 (平铺下显示)
|
|
31
|
+
public $replyAt?: HTMLElement // 回复 AT(层级嵌套下显示)
|
|
32
|
+
|
|
11
33
|
public constructor(comment: Comment) {
|
|
12
|
-
|
|
34
|
+
this.comment = comment
|
|
13
35
|
}
|
|
14
36
|
|
|
15
37
|
public render() {
|