/
context.ts
124 lines (93 loc) · 3.03 KB
/
context.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import type { TInjectedServices } from '@/service'
import type { CheckerCaptchaPayload, CheckerPayload } from '@/components/checker'
import type { EventManagerFuncs } from '@/lib/event-manager'
import type { TMarked } from '@/lib/marked'
import type { I18n } from '@/i18n'
import type { Api, ApiHandlers } from '@/api'
import type { CommentNode } from '@/comment'
import type {
SidebarShowPayload,
EventPayloadMap,
ArtalkConfig,
CommentData,
DataManagerApi,
ListFetchParams,
NotifyLevel,
} from '.'
/**
* Artalk Context
*/
export interface ContextApi extends EventManagerFuncs<EventPayloadMap> {
/** Artalk 根元素对象 */
$root: HTMLElement
/** 依赖注入函数 */
inject<K extends keyof TInjectedServices>(depName: K, obj: TInjectedServices[K]): void
/** 获取依赖对象 */
get<K extends keyof TInjectedServices>(depName: K): TInjectedServices[K]
/** 配置对象 */
// TODO: 修改为 getConf() 和 setConf() 并且返回拷贝而不是引用
conf: ArtalkConfig
/** marked 依赖对象 */
getMarked(): TMarked | undefined
/** 获取 API 以供 HTTP 请求 */
getApi(): Api
/** Get API handlers */
getApiHandlers(): ApiHandlers
/** 获取数据管理器对象 */
getData(): DataManagerApi
/** 评论回复 */
replyComment(commentData: CommentData, $comment: HTMLElement): void
/** 编辑评论 */
editComment(commentData: CommentData, $comment: HTMLElement): void
/** 获取评论数据 */
fetch(params: Partial<ListFetchParams>): void
/** 重载评论数据 */
reload(): void
/** 列表滚动到第一个评论的位置 */
listGotoFirst(): void
/** Get the comment data list */
getComments(): CommentData[]
/** Get the comment node list */
getCommentNodes(): CommentNode[]
/**
* Get the comment data list
* @deprecated Use `getComments()` instead
*/
getCommentDataList(): CommentData[]
/**
* Get the comment node list
* @deprecated Use `getCommentNodes()` instead
*/
getCommentList(): CommentNode[]
/** 显示侧边栏 */
showSidebar(payload?: SidebarShowPayload): void
/** 隐藏侧边栏 */
hideSidebar(): void
/** 编辑器 - 显示加载 */
editorShowLoading(): void
/** 编辑器 - 隐藏加载 */
editorHideLoading(): void
/** 编辑器 - 显示提示消息 */
editorShowNotify(msg: string, type: NotifyLevel): void
/** 评论框 - 复原状态 */
editorResetState(): void
/** 验证码检测 */
checkCaptcha(payload: CheckerCaptchaPayload): Promise<void>
/** 管理员检测 */
checkAdmin(payload: CheckerPayload): Promise<void>
/** i18n 翻译 */
$t(key: keyof I18n, args?: { [key: string]: string }): string
/** 设置夜间模式 */
setDarkMode(darkMode: boolean | 'auto'): void
/** 获取配置 */
getConf(): ArtalkConfig
/** 获取挂载元素 */
getEl(): HTMLElement
/** 更新配置 */
updateConf(conf: Partial<ArtalkConfig>): void
/** 监听配置更新 */
watchConf<T extends (keyof ArtalkConfig)[]>(
keys: T,
effect: (val: Pick<ArtalkConfig, T[number]>) => void,
): void
}