artalk 2.2.12 → 2.3.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/Artalk.css +1 -1
- package/dist/Artalk.es.js +1535 -1175
- package/dist/Artalk.iife.js +1 -1
- package/dist/Artalk.js +1 -1
- package/dist/ArtalkLite.css +1 -0
- package/dist/ArtalkLite.es.js +5123 -0
- package/dist/ArtalkLite.iife.js +1 -0
- package/dist/ArtalkLite.js +1 -0
- package/index.html +2 -2
- package/package.json +6 -5
- package/src/api/index.ts +20 -1
- package/src/api/request.ts +7 -7
- package/src/artalk.ts +117 -121
- package/src/comment/actions.ts +86 -0
- package/src/{components/html → comment}/comment.html +1 -1
- package/src/comment/comment.ts +191 -0
- package/src/comment/index.ts +3 -0
- package/src/comment/render.ts +425 -0
- package/src/components/action-btn.ts +6 -3
- package/src/components/dialog.ts +7 -3
- package/src/components/read-more-btn.ts +6 -2
- package/src/context.ts +204 -13
- package/src/defaults.ts +16 -5
- package/src/editor/editor.html +18 -0
- package/src/editor/editor.ts +419 -0
- package/src/editor/index.ts +3 -0
- package/src/editor/plugs/editor-plug.ts +51 -0
- package/src/{components/editor-plugs → editor/plugs}/emoticons-plug.less +2 -1
- package/src/{components/editor-plugs → editor/plugs}/emoticons-plug.ts +65 -63
- package/src/editor/plugs/header-input-plug.ts +78 -0
- package/src/{components/editor-plugs → editor/plugs}/preview-plug.less +0 -0
- package/src/editor/plugs/preview-plug.ts +40 -0
- package/src/editor/plugs/upload-plug.ts +124 -0
- package/src/i18n/en.ts +78 -0
- package/src/i18n/index.ts +21 -0
- package/src/i18n/zh-CN.ts +82 -0
- package/src/layer/index.ts +4 -0
- package/src/{components → layer}/layer.ts +9 -9
- package/src/{components/html → layer}/sidebar-layer.html +0 -0
- package/src/{components → layer}/sidebar-layer.ts +17 -47
- package/src/lib/checker/admin-checker.ts +7 -7
- package/src/lib/checker/captcha-checker.ts +5 -6
- package/src/lib/checker/index.ts +22 -17
- package/src/lib/component.ts +7 -2
- package/src/lib/stat.ts +63 -0
- package/src/lib/ui.ts +6 -12
- package/src/lib/user.ts +20 -3
- package/src/lib/utils.ts +23 -9
- package/src/list/index.ts +3 -0
- package/src/{components → list}/list-lite.ts +80 -100
- package/src/{components → list}/list-nest.ts +0 -0
- package/src/{components/html → list}/list.html +3 -6
- package/src/{components → list}/list.ts +44 -42
- package/src/style/_variables.less +1 -2
- package/src/style/comment.less +26 -13
- package/src/style/editor.less +22 -14
- package/src/style/list.less +6 -9
- package/src/style/main.less +9 -8
- package/src/style/pagination.less +1 -1
- package/test/ArtalkCount.html +16 -0
- package/test/ArtalkI18n.html +15 -0
- package/test/ArtalkLite.html +15 -0
- package/types/artalk-config.d.ts +50 -32
- package/types/context.d.ts +128 -0
- package/types/event.d.ts +6 -66
- package/types/global.d.ts +1 -0
- package/types/plug.d.ts +4 -0
- package/{vite-common.config.ts → vite-base.config.ts} +6 -4
- package/vite-demo.config.ts +2 -4
- package/vite-lite.config.ts +22 -0
- package/vite.config.ts +9 -12
- package/src/components/_component.ts.txt +0 -10
- package/src/components/comment.ts +0 -605
- package/src/components/editor-plugs/_example-plug.ts.txt +0 -29
- package/src/components/editor-plugs/editor-plug.ts +0 -20
- package/src/components/editor-plugs/preview-plug.ts +0 -48
- package/src/components/editor.ts +0 -607
- package/src/components/html/editor.html +0 -18
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { marked as libMarked } from 'marked'
|
|
2
|
+
import ArtalkConfig from './artalk-config'
|
|
3
|
+
import { CommentData, NotifyData } from './artalk-data'
|
|
4
|
+
import { EventPayloadMap, Event, EventScopeType, Handler } from './event'
|
|
5
|
+
import { internal as internalLocales, I18n } from '../src/i18n'
|
|
6
|
+
import Api from '../src/api'
|
|
7
|
+
import User from '../src/lib/user'
|
|
8
|
+
import Editor from '../src/editor'
|
|
9
|
+
import Comment from '../src/comment'
|
|
10
|
+
import ListLite from '../src/list/list-lite'
|
|
11
|
+
import SidebarLayer, { SidebarShowPayload } from '../src/layer/sidebar-layer'
|
|
12
|
+
import CheckerLauncher, { CheckerCaptchaPayload, CheckerPayload } from '../src/lib/checker'
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Context 接口
|
|
16
|
+
*
|
|
17
|
+
* (面向接口的编程)
|
|
18
|
+
*/
|
|
19
|
+
export default interface ContextApi {
|
|
20
|
+
/** Context 唯一标识 */
|
|
21
|
+
cid: number
|
|
22
|
+
|
|
23
|
+
/** Artalk 根元素对象 */
|
|
24
|
+
$root: HTMLElement
|
|
25
|
+
|
|
26
|
+
/** 配置对象 */
|
|
27
|
+
conf: ArtalkConfig
|
|
28
|
+
|
|
29
|
+
/** 用户对象 */
|
|
30
|
+
user: User
|
|
31
|
+
|
|
32
|
+
/** marked 依赖对象 */
|
|
33
|
+
markedInstance?: typeof libMarked
|
|
34
|
+
|
|
35
|
+
/** marked 内容替换器 */
|
|
36
|
+
markedReplacers: ((raw: string) => string)[]
|
|
37
|
+
|
|
38
|
+
/* 设置持有的同事类 (中介者模式) */
|
|
39
|
+
setApi(api: Api): void
|
|
40
|
+
setEditor(editor: Editor): void
|
|
41
|
+
setList(list: ListLite): void
|
|
42
|
+
setSidebarLayer(list: SidebarLayer): void
|
|
43
|
+
setCheckerLauncher(checkerLauncher: CheckerLauncher): void
|
|
44
|
+
|
|
45
|
+
/** 获取 API 以供 HTTP 请求 */
|
|
46
|
+
getApi(): Api
|
|
47
|
+
|
|
48
|
+
/** 获取评论实例对象列表 */
|
|
49
|
+
getCommentList(): Comment[]
|
|
50
|
+
|
|
51
|
+
/** 获取评论数据列表 */
|
|
52
|
+
getCommentDataList(): CommentData[]
|
|
53
|
+
|
|
54
|
+
/** 查找评论 */
|
|
55
|
+
findComment(id: number): Comment|undefined
|
|
56
|
+
|
|
57
|
+
/** 删除评论 */
|
|
58
|
+
deleteComment(comment: number|Comment): void
|
|
59
|
+
|
|
60
|
+
/** 清空评论 */
|
|
61
|
+
clearAllComments(): void
|
|
62
|
+
|
|
63
|
+
/** 插入评论 */
|
|
64
|
+
insertComment(commentData: CommentData): void
|
|
65
|
+
|
|
66
|
+
/** 评论回复 */
|
|
67
|
+
replyComment(commentData: CommentData, $comment: HTMLElement, scroll?: boolean): void
|
|
68
|
+
|
|
69
|
+
/** 取消回复评论 */
|
|
70
|
+
cancelReplyComment(): void
|
|
71
|
+
|
|
72
|
+
/** 更新通知数据 */
|
|
73
|
+
updateNotifies(notifies: NotifyData[]): void
|
|
74
|
+
|
|
75
|
+
/** 列表 - 重新加载数据 */
|
|
76
|
+
listReload(): void
|
|
77
|
+
|
|
78
|
+
/** 列表 - UI 更新 */
|
|
79
|
+
listRefreshUI(): void
|
|
80
|
+
|
|
81
|
+
/** 显示侧边栏 */
|
|
82
|
+
showSidebar(payload?: SidebarShowPayload): void
|
|
83
|
+
|
|
84
|
+
/** 隐藏侧边栏 */
|
|
85
|
+
hideSidebar(): void
|
|
86
|
+
|
|
87
|
+
/** 编辑器 - 关闭评论 */
|
|
88
|
+
editorClose(): void
|
|
89
|
+
|
|
90
|
+
/** 编辑器 - 打开评论 */
|
|
91
|
+
editorOpen(): void
|
|
92
|
+
|
|
93
|
+
/** 编辑器 - 显示加载 */
|
|
94
|
+
editorShowLoading(): void
|
|
95
|
+
|
|
96
|
+
/** 编辑器 - 隐藏加载 */
|
|
97
|
+
editorHideLoading(): void
|
|
98
|
+
|
|
99
|
+
/** 编辑器 - 显示提示消息 */
|
|
100
|
+
editorShowNotify(msg: string, type: "i" | "s" | "w" | "e"): void
|
|
101
|
+
|
|
102
|
+
/** 评论框 - 位置移动 */
|
|
103
|
+
editorTravel($el: HTMLElement): void
|
|
104
|
+
|
|
105
|
+
/** 评论框 - 位置回归 */
|
|
106
|
+
editorTravelBack(): void
|
|
107
|
+
|
|
108
|
+
/** 验证码检测 */
|
|
109
|
+
checkCaptcha(payload: CheckerCaptchaPayload): void
|
|
110
|
+
|
|
111
|
+
/** 管理员检测 */
|
|
112
|
+
checkAdmin(payload: CheckerPayload): void
|
|
113
|
+
|
|
114
|
+
/** 管理员显示元素可见性更新 */
|
|
115
|
+
checkAdminShowEl(): void
|
|
116
|
+
|
|
117
|
+
/** 订阅注册 */
|
|
118
|
+
on<K extends keyof EventPayloadMap>(name: K, handler: Handler<EventPayloadMap[K]>, scope?: EventScopeType): void
|
|
119
|
+
|
|
120
|
+
/** 订阅取消 */
|
|
121
|
+
off<K extends keyof EventPayloadMap>(name: K, handler?: Handler<EventPayloadMap[K]>, scope?: EventScopeType): void
|
|
122
|
+
|
|
123
|
+
/** 订阅发布 */
|
|
124
|
+
trigger<K extends keyof EventPayloadMap>(name: K, payload?: EventPayloadMap[K], scope?: EventScopeType): void
|
|
125
|
+
|
|
126
|
+
/** i18n 翻译 */
|
|
127
|
+
$t(key: keyof I18n, args?: {[key: string]: string}): string
|
|
128
|
+
}
|
package/types/event.d.ts
CHANGED
|
@@ -1,77 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommentData } from './artalk-data'
|
|
2
2
|
import { LocalUser } from './artalk-config'
|
|
3
3
|
|
|
4
4
|
/** EventName to EventPayload Type */
|
|
5
5
|
export interface EventPayloadMap {
|
|
6
|
-
'
|
|
7
|
-
'
|
|
6
|
+
'list-load': undefined // 评论加载时
|
|
7
|
+
'list-loaded': undefined // 评论装载后
|
|
8
|
+
'list-inserted': CommentData // 评论插入后
|
|
8
9
|
'editor-submit': undefined // 编辑器提交时
|
|
9
10
|
'editor-submitted': undefined // 编辑器提交后
|
|
10
11
|
'user-changed': LocalUser // 本地用户数据变更时
|
|
11
12
|
'conf-updated': undefined // Artalk 配置变更时
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
'list-reload': undefined // 重新加载 List
|
|
15
|
-
'list-import': CommentData[] // 评论导入
|
|
16
|
-
'list-insert': CommentData // 评论添加
|
|
17
|
-
'list-delete': CommentData // 评论删除
|
|
18
|
-
'list-update': ListUpdatePayload // 更新评论数据
|
|
19
|
-
'list-refresh-ui': undefined // 刷新 List UI
|
|
20
|
-
|
|
21
|
-
// Sidebar
|
|
22
|
-
'sidebar-show': SidebarShowPayload // 侧边栏显示
|
|
23
|
-
'sidebar-hide': undefined // 侧边栏隐藏
|
|
24
|
-
|
|
25
|
-
// Editor
|
|
26
|
-
'editor-open': undefined // 打开评论
|
|
27
|
-
'editor-close': undefined // 关闭评论
|
|
28
|
-
'editor-show-loading': undefined // 加载显示
|
|
29
|
-
'editor-hide-loading': undefined // 加载隐藏
|
|
30
|
-
'editor-notify': NotifyConf // 显示提示
|
|
31
|
-
'editor-reply': EditorReplyPayload // 设置回复
|
|
32
|
-
'editor-reply-cancel': undefined // 取消回复
|
|
33
|
-
'editor-travel': HTMLElement
|
|
34
|
-
'editor-travel-back': undefined
|
|
35
|
-
|
|
36
|
-
// Notify
|
|
37
|
-
'unread-update': UnreadUpdatePayload // 未读数据更新
|
|
38
|
-
|
|
39
|
-
// Checker
|
|
40
|
-
'checker-admin': CheckerPayload // 检查管理员
|
|
41
|
-
'checker-captcha': CheckerCaptchaPayload // 检查验证码
|
|
42
|
-
'check-admin-show-el': undefined // 检查并更新仅管理员显示的元素
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface CheckerPayload {
|
|
46
|
-
onSuccess?: (inputVal: string, dialogEl?: HTMLElement) => void
|
|
47
|
-
onMount?: (dialogEl: HTMLElement) => void
|
|
48
|
-
onCancel?: () => void
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export interface NotifyConf {
|
|
52
|
-
msg: string
|
|
53
|
-
type: any
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface CheckerCaptchaPayload extends CheckerPayload {
|
|
57
|
-
imgData?: string
|
|
58
|
-
iframe?: string
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export interface UnreadUpdatePayload {
|
|
62
|
-
notifies: NotifyData[]
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export type ListUpdatePayload = (data: ListData | undefined) => void
|
|
66
|
-
|
|
67
|
-
export interface EditorReplyPayload {
|
|
68
|
-
data: CommentData
|
|
69
|
-
$el: HTMLElement
|
|
70
|
-
scroll?: boolean
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export interface SidebarShowPayload {
|
|
74
|
-
view?: 'comments'|'sites'|'pages'|'transfer'|string
|
|
13
|
+
'sidebar-show': undefined // 侧边栏显示
|
|
14
|
+
'sidebar-hide': undefined // 侧边栏隐藏
|
|
75
15
|
}
|
|
76
16
|
|
|
77
17
|
// ============================================
|
package/types/global.d.ts
CHANGED
package/types/plug.d.ts
ADDED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineConfig } from 'vite'
|
|
2
|
+
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
2
3
|
import { version } from './package.json'
|
|
3
4
|
|
|
4
|
-
export default {
|
|
5
|
+
export default defineConfig({
|
|
5
6
|
define: {
|
|
6
|
-
ARTALK_VERSION: JSON.stringify(version)
|
|
7
|
+
ARTALK_VERSION: JSON.stringify(version),
|
|
7
8
|
},
|
|
8
9
|
css: {
|
|
9
10
|
preprocessorOptions: {
|
|
@@ -12,4 +13,5 @@ export default {
|
|
|
12
13
|
},
|
|
13
14
|
},
|
|
14
15
|
},
|
|
15
|
-
|
|
16
|
+
plugins: [tsconfigPaths()],
|
|
17
|
+
})
|
package/vite-demo.config.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { defineConfig } from 'vite'
|
|
2
2
|
import { resolve } from 'path'
|
|
3
|
-
import
|
|
4
|
-
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
3
|
+
import baseConf from './vite-base.config'
|
|
5
4
|
|
|
6
5
|
export default defineConfig({
|
|
7
6
|
build: {
|
|
@@ -9,6 +8,5 @@ export default defineConfig({
|
|
|
9
8
|
outDir: resolve(__dirname, "deploy"),
|
|
10
9
|
rollupOptions: {}
|
|
11
10
|
},
|
|
12
|
-
|
|
13
|
-
...commonConf
|
|
11
|
+
...baseConf
|
|
14
12
|
})
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import fullVersionConf from './vite.config'
|
|
2
|
+
import * as Utils from './src/lib/utils'
|
|
3
|
+
|
|
4
|
+
export default Utils.mergeDeep(fullVersionConf, {
|
|
5
|
+
build: {
|
|
6
|
+
lib: {
|
|
7
|
+
fileName: (format) => ((format == "umd") ? 'ArtalkLite.js' : `ArtalkLite.${format}.js`),
|
|
8
|
+
},
|
|
9
|
+
rollupOptions: {
|
|
10
|
+
external: ['marked'],
|
|
11
|
+
output: {
|
|
12
|
+
globals: {
|
|
13
|
+
marked: 'marked',
|
|
14
|
+
},
|
|
15
|
+
assetFileNames: (assetInfo) => (/\.css$/.test(assetInfo.name) ? "ArtalkLite.css" : "[name].[ext]")
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
define: {
|
|
20
|
+
ARTALK_LITE: true,
|
|
21
|
+
},
|
|
22
|
+
})
|
package/vite.config.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { defineConfig } from 'vite'
|
|
2
2
|
import { resolve } from 'path'
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import baseConf from './vite-base.config'
|
|
4
|
+
import * as Utils from './src/lib/utils'
|
|
5
5
|
|
|
6
|
-
export default defineConfig({
|
|
6
|
+
export default Utils.mergeDeep(baseConf, defineConfig({
|
|
7
7
|
build: {
|
|
8
8
|
target: 'es2015',
|
|
9
9
|
outDir: resolve(__dirname, "dist"),
|
|
10
10
|
minify: 'terser',
|
|
11
|
+
emptyOutDir: false,
|
|
11
12
|
lib: {
|
|
12
13
|
entry: resolve(__dirname, 'src/main.ts'),
|
|
13
14
|
name: 'Artalk',
|
|
@@ -16,15 +17,11 @@ export default defineConfig({
|
|
|
16
17
|
},
|
|
17
18
|
rollupOptions: {
|
|
18
19
|
output: {
|
|
19
|
-
assetFileNames: assetInfo =>
|
|
20
|
-
if (/\.css$/.test(assetInfo.name)) {
|
|
21
|
-
return 'Artalk.css'
|
|
22
|
-
}
|
|
23
|
-
return "[name].[ext]"
|
|
24
|
-
}
|
|
20
|
+
assetFileNames: (assetInfo) => (/\.css$/.test(assetInfo.name) ? "Artalk.css" : "[name].[ext]")
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
23
|
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
24
|
+
define: {
|
|
25
|
+
ARTALK_LITE: false,
|
|
26
|
+
},
|
|
27
|
+
}))
|