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.
Files changed (300) hide show
  1. package/dist/Artalk.css +1 -1
  2. package/dist/Artalk.es.js +7673 -7330
  3. package/dist/Artalk.iife.js +1 -1
  4. package/dist/Artalk.js +1 -1
  5. package/dist/ArtalkLite.css +1 -1
  6. package/dist/ArtalkLite.es.js +5304 -4961
  7. package/dist/ArtalkLite.iife.js +1 -1
  8. package/dist/ArtalkLite.js +1 -1
  9. package/dist/src/api/{api-base.d.ts → _base.d.ts} +3 -7
  10. package/dist/src/api/_options.d.ts +19 -0
  11. package/dist/src/api/{request.d.ts → _request.d.ts} +3 -3
  12. package/dist/src/api/admin.d.ts +1 -1
  13. package/dist/src/api/captcha.d.ts +1 -1
  14. package/dist/src/api/comment.d.ts +2 -2
  15. package/dist/src/api/index.d.ts +2 -4
  16. package/dist/src/api/page.d.ts +3 -3
  17. package/dist/src/api/site.d.ts +2 -2
  18. package/dist/src/api/system.d.ts +13 -3
  19. package/dist/src/api/upload.d.ts +1 -1
  20. package/dist/src/api/user.d.ts +2 -2
  21. package/dist/src/artalk.d.ts +14 -37
  22. package/dist/src/comment/actions.d.ts +1 -1
  23. package/dist/src/comment/comment.d.ts +3 -4
  24. package/dist/src/comment/render.d.ts +21 -3
  25. package/dist/src/comment/renders/actions.d.ts +2 -2
  26. package/dist/src/comment/renders/avatar.d.ts +2 -2
  27. package/dist/src/comment/renders/content.d.ts +2 -2
  28. package/dist/src/comment/renders/header.d.ts +2 -2
  29. package/dist/src/comment/renders/index.d.ts +2 -2
  30. package/dist/src/comment/renders/pending.d.ts +2 -2
  31. package/dist/src/comment/renders/reply-at.d.ts +2 -2
  32. package/dist/src/comment/renders/reply-to.d.ts +2 -2
  33. package/dist/src/components/action-btn.d.ts +3 -5
  34. package/dist/src/{lib → components}/checker/admin.d.ts +1 -1
  35. package/dist/src/{lib → components}/checker/captcha-renders.d.ts +1 -1
  36. package/dist/src/{lib → components}/checker/captcha.d.ts +1 -1
  37. package/dist/src/{lib → components}/checker/index.d.ts +10 -7
  38. package/dist/src/components/dark-mode.d.ts +2 -0
  39. package/dist/src/components/dialog.d.ts +1 -3
  40. package/dist/src/components/error-dialog.d.ts +8 -0
  41. package/dist/src/components/pagination.d.ts +4 -3
  42. package/dist/src/components/read-more-btn.d.ts +3 -3
  43. package/dist/src/config.d.ts +24 -8
  44. package/dist/src/context.d.ts +16 -35
  45. package/dist/src/data.d.ts +27 -0
  46. package/dist/src/defaults.d.ts +1 -1
  47. package/dist/src/editor/editor.d.ts +14 -59
  48. package/dist/src/editor/state.d.ts +20 -0
  49. package/dist/src/i18n/zh-CN.d.ts +1 -1
  50. package/dist/src/layer/index.d.ts +4 -3
  51. package/dist/src/layer/layer-manager.d.ts +9 -0
  52. package/dist/src/layer/layer.d.ts +8 -28
  53. package/dist/src/layer/scrollbar-helper.d.ts +5 -0
  54. package/dist/src/layer/sidebar-layer.d.ts +6 -6
  55. package/dist/src/layer/wrap.d.ts +13 -0
  56. package/dist/src/lib/component.d.ts +3 -8
  57. package/dist/src/lib/event-manager.d.ts +28 -0
  58. package/dist/src/lib/highlight.d.ts +1 -0
  59. package/dist/src/lib/marked-renderer.d.ts +4 -0
  60. package/dist/src/lib/marked.d.ts +4 -2
  61. package/dist/src/lib/sanitizer.d.ts +1 -0
  62. package/dist/src/lib/ui.d.ts +3 -2
  63. package/dist/src/lib/user.d.ts +8 -5
  64. package/dist/src/lib/utils.d.ts +11 -5
  65. package/dist/src/list/comment.d.ts +3 -0
  66. package/dist/src/list/layout.d.ts +23 -0
  67. package/dist/src/list/list.d.ts +13 -25
  68. package/dist/src/list/{list-nest.d.ts → nest.d.ts} +1 -1
  69. package/dist/src/list/page.d.ts +2 -0
  70. package/dist/src/list/paginator/index.d.ts +22 -7
  71. package/dist/src/list/paginator/read-more.d.ts +18 -0
  72. package/dist/src/list/paginator/up-down.d.ts +14 -0
  73. package/dist/src/main.d.ts +2 -0
  74. package/dist/src/plugins/admin-only-elem.d.ts +2 -0
  75. package/dist/src/plugins/conf-remoter.d.ts +2 -0
  76. package/dist/src/plugins/dark-mode.d.ts +2 -0
  77. package/dist/src/plugins/editor/_kit.d.ts +27 -0
  78. package/dist/src/plugins/editor/_plug.d.ts +29 -0
  79. package/dist/src/plugins/editor/_sample.d.ts +5 -0
  80. package/dist/src/plugins/editor/closable.d.ts +7 -0
  81. package/dist/src/{editor/plugs/emoticons-plug.d.ts → plugins/editor/emoticons.d.ts} +10 -16
  82. package/dist/src/plugins/editor/header-event.d.ts +6 -0
  83. package/dist/src/plugins/editor/header-link.d.ts +6 -0
  84. package/dist/src/plugins/editor/header-user.d.ts +16 -0
  85. package/dist/src/plugins/editor/index.d.ts +6 -0
  86. package/dist/src/plugins/editor/local-storage.d.ts +6 -0
  87. package/dist/src/plugins/editor/mover.d.ts +6 -0
  88. package/dist/src/plugins/editor/preview.d.ts +7 -0
  89. package/dist/src/plugins/editor/state-edit.d.ts +11 -0
  90. package/dist/src/plugins/editor/state-reply.d.ts +8 -0
  91. package/dist/src/plugins/editor/submit-add.d.ts +18 -0
  92. package/dist/src/plugins/editor/submit-btn.d.ts +5 -0
  93. package/dist/src/plugins/editor/submit.d.ts +17 -0
  94. package/dist/src/plugins/editor/textarea.d.ts +8 -0
  95. package/dist/src/plugins/editor/upload.d.ts +9 -0
  96. package/dist/src/plugins/editor-kit.d.ts +42 -0
  97. package/dist/src/plugins/index.d.ts +2 -0
  98. package/dist/src/plugins/list/copyright.d.ts +2 -0
  99. package/dist/src/plugins/list/count.d.ts +2 -0
  100. package/dist/src/plugins/list/dropdown.d.ts +2 -0
  101. package/dist/src/plugins/list/error-dialog.d.ts +2 -0
  102. package/dist/src/plugins/list/fetch.d.ts +2 -0
  103. package/dist/src/plugins/list/goto-first.d.ts +3 -0
  104. package/dist/src/plugins/list/goto.d.ts +2 -0
  105. package/dist/src/plugins/list/index.d.ts +3 -0
  106. package/dist/src/plugins/list/loading.d.ts +2 -0
  107. package/dist/src/plugins/list/no-comment.d.ts +2 -0
  108. package/dist/src/plugins/list/reach-bottom.d.ts +2 -0
  109. package/dist/src/plugins/list/sidebar-btn.d.ts +2 -0
  110. package/dist/src/plugins/list/time-ticking.d.ts +3 -0
  111. package/dist/src/plugins/list/unread-badge.d.ts +2 -0
  112. package/dist/src/plugins/list/unread.d.ts +2 -0
  113. package/dist/src/plugins/list/with-editor.d.ts +2 -0
  114. package/dist/src/plugins/markdown.d.ts +2 -0
  115. package/dist/src/plugins/stat.d.ts +13 -0
  116. package/dist/src/plugins/version-check.d.ts +2 -0
  117. package/dist/src/service.d.ts +19 -23
  118. package/dist/tests/e2e/comment-add.spec.d.ts +1 -0
  119. package/dist/types/config.d.ts +110 -0
  120. package/dist/types/context.d.ts +56 -136
  121. package/dist/types/data.d.ts +194 -0
  122. package/dist/types/editor.d.ts +76 -0
  123. package/dist/types/event.d.ts +36 -25
  124. package/dist/types/index.d.ts +7 -0
  125. package/dist/types/plugin.d.ts +2 -0
  126. package/dist/types/sidebar.d.ts +3 -0
  127. package/package.json +5 -2
  128. package/src/api/_base.ts +18 -0
  129. package/src/api/_options.ts +25 -0
  130. package/src/api/{request.ts → _request.ts} +19 -18
  131. package/src/api/admin.ts +1 -1
  132. package/src/api/captcha.ts +1 -1
  133. package/src/api/comment.ts +4 -4
  134. package/src/api/index.ts +3 -12
  135. package/src/api/page.ts +5 -5
  136. package/src/api/site.ts +2 -2
  137. package/src/api/system.ts +19 -7
  138. package/src/api/upload.ts +3 -3
  139. package/src/api/user.ts +3 -3
  140. package/src/artalk.ts +49 -97
  141. package/src/comment/actions.ts +1 -4
  142. package/src/comment/comment.ts +9 -6
  143. package/src/comment/render.ts +27 -5
  144. package/src/comment/renders/actions.ts +45 -45
  145. package/src/comment/renders/avatar.ts +7 -7
  146. package/src/comment/renders/content.ts +18 -18
  147. package/src/comment/renders/header.ts +13 -13
  148. package/src/comment/renders/index.ts +3 -3
  149. package/src/comment/renders/pending.ts +5 -5
  150. package/src/comment/renders/reply-at.ts +8 -8
  151. package/src/comment/renders/reply-to.ts +13 -13
  152. package/src/components/action-btn.ts +11 -13
  153. package/src/{lib → components}/checker/admin.ts +6 -6
  154. package/src/{lib → components}/checker/captcha-renders.ts +7 -6
  155. package/src/{lib → components}/checker/captcha.ts +1 -1
  156. package/src/{lib → components}/checker/index.ts +21 -26
  157. package/src/components/dark-mode.ts +30 -0
  158. package/src/components/dialog.ts +4 -9
  159. package/src/components/error-dialog.ts +35 -0
  160. package/src/components/pagination.ts +10 -6
  161. package/src/components/read-more-btn.ts +7 -7
  162. package/src/config.ts +60 -6
  163. package/src/context.ts +39 -144
  164. package/src/data.ts +110 -0
  165. package/src/defaults.ts +1 -1
  166. package/src/editor/editor.ts +41 -146
  167. package/src/editor/state.ts +52 -0
  168. package/src/i18n/zh-CN.ts +1 -1
  169. package/src/layer/index.ts +4 -4
  170. package/src/layer/layer-manager.ts +32 -0
  171. package/src/layer/layer.ts +20 -144
  172. package/src/layer/scrollbar-helper.ts +24 -0
  173. package/src/layer/sidebar-layer.ts +74 -64
  174. package/src/layer/wrap.ts +77 -0
  175. package/src/lib/component.ts +4 -11
  176. package/src/lib/detect.ts +1 -1
  177. package/src/lib/event-manager.ts +47 -0
  178. package/src/lib/highlight.ts +5 -0
  179. package/src/lib/marked-renderer.ts +32 -0
  180. package/src/lib/marked.ts +43 -104
  181. package/src/lib/sanitizer.ts +57 -0
  182. package/src/lib/ui.ts +22 -15
  183. package/src/lib/user.ts +21 -16
  184. package/src/lib/utils.ts +29 -18
  185. package/src/list/comment.ts +20 -0
  186. package/src/list/layout.ts +120 -0
  187. package/src/list/list.html +3 -1
  188. package/src/list/list.ts +56 -200
  189. package/src/list/{list-nest.ts → nest.ts} +1 -1
  190. package/src/list/page.ts +97 -0
  191. package/src/list/paginator/index.ts +20 -8
  192. package/src/list/paginator/read-more.ts +67 -0
  193. package/src/list/paginator/up-down.ts +51 -0
  194. package/src/main.ts +2 -0
  195. package/src/plugins/admin-only-elem.ts +40 -0
  196. package/src/plugins/conf-remoter.ts +54 -0
  197. package/src/plugins/dark-mode.ts +12 -0
  198. package/src/plugins/editor/_kit.ts +57 -0
  199. package/src/plugins/editor/_plug.ts +60 -0
  200. package/src/plugins/editor/_sample.ts +8 -0
  201. package/src/plugins/editor/closable.ts +44 -0
  202. package/src/{editor/plugs/emoticons-plug.ts → plugins/editor/emoticons.ts} +51 -52
  203. package/src/plugins/editor/header-event.ts +35 -0
  204. package/src/plugins/editor/header-link.ts +31 -0
  205. package/src/plugins/editor/header-user.ts +98 -0
  206. package/src/plugins/editor/index.ts +40 -0
  207. package/src/plugins/editor/local-storage.ts +36 -0
  208. package/src/plugins/editor/mover.ts +29 -0
  209. package/src/plugins/editor/preview.ts +41 -0
  210. package/src/plugins/editor/state-edit.ts +116 -0
  211. package/src/plugins/editor/state-reply.ts +91 -0
  212. package/src/plugins/editor/submit-add.ts +33 -0
  213. package/src/plugins/editor/submit-btn.ts +25 -0
  214. package/src/plugins/editor/submit.ts +73 -0
  215. package/src/plugins/editor/textarea.ts +55 -0
  216. package/src/plugins/editor/upload.ts +145 -0
  217. package/src/plugins/editor-kit.ts +161 -0
  218. package/src/plugins/index.ts +16 -0
  219. package/src/plugins/list/copyright.ts +16 -0
  220. package/src/plugins/list/count.ts +31 -0
  221. package/src/plugins/list/dropdown.ts +95 -0
  222. package/src/plugins/list/error-dialog.ts +22 -0
  223. package/src/plugins/list/fetch.ts +64 -0
  224. package/src/plugins/list/goto-first.ts +23 -0
  225. package/src/plugins/list/goto.ts +72 -0
  226. package/src/plugins/list/index.ts +25 -0
  227. package/src/plugins/list/loading.ts +17 -0
  228. package/src/plugins/list/no-comment.ts +25 -0
  229. package/src/plugins/list/reach-bottom.ts +46 -0
  230. package/src/plugins/list/sidebar-btn.ts +39 -0
  231. package/src/plugins/list/time-ticking.ts +22 -0
  232. package/src/plugins/list/unread-badge.ts +26 -0
  233. package/src/plugins/list/unread.ts +38 -0
  234. package/src/plugins/list/with-editor.ts +59 -0
  235. package/src/plugins/markdown.ts +10 -0
  236. package/src/plugins/stat.ts +79 -0
  237. package/src/plugins/version-check.ts +37 -0
  238. package/src/service.ts +34 -61
  239. package/src/style/comment.scss +5 -7
  240. package/src/style/editor.scss +5 -0
  241. package/src/style/list.scss +2 -7
  242. package/types/{artalk-config.d.ts → config.ts} +16 -2
  243. package/types/context.ts +84 -0
  244. package/{dist/types/artalk-data.d.ts → types/data.ts} +41 -0
  245. package/types/editor.ts +95 -0
  246. package/types/event.ts +40 -0
  247. package/types/index.ts +7 -0
  248. package/types/plugin.ts +3 -0
  249. package/types/sidebar.ts +3 -0
  250. package/dist/src/comment/render-ctx.d.ts +0 -23
  251. package/dist/src/editor/edit-mode.d.ts +0 -9
  252. package/dist/src/editor/funcs.d.ts +0 -2
  253. package/dist/src/editor/index.d.ts +0 -2
  254. package/dist/src/editor/mover.d.ts +0 -8
  255. package/dist/src/editor/plug-manager.d.ts +0 -17
  256. package/dist/src/editor/plugs/editor-plug.d.ts +0 -38
  257. package/dist/src/editor/plugs/header-input-plug.d.ts +0 -13
  258. package/dist/src/editor/plugs/preview-plug.d.ts +0 -10
  259. package/dist/src/editor/plugs/upload-plug.d.ts +0 -10
  260. package/dist/src/editor/reply.d.ts +0 -9
  261. package/dist/src/editor/submit.d.ts +0 -16
  262. package/dist/src/lib/dark-mode.d.ts +0 -4
  263. package/dist/src/lib/stat.d.ts +0 -15
  264. package/dist/src/list/index.d.ts +0 -2
  265. package/dist/src/list/list-lite.d.ts +0 -77
  266. package/dist/src/list/list-ui.d.ts +0 -16
  267. package/dist/src/list/paginator/adaptors/index.d.ts +0 -12
  268. package/dist/src/list/paginator/adaptors/pagination.d.ts +0 -9
  269. package/dist/src/list/paginator/adaptors/read-more.d.ts +0 -10
  270. package/dist/src/list/paginator/holder.d.ts +0 -16
  271. package/dist/types/artalk-config.d.ts +0 -139
  272. package/dist/types/plug.d.ts +0 -4
  273. package/src/api/api-base.ts +0 -27
  274. package/src/comment/render-ctx.ts +0 -30
  275. package/src/editor/edit-mode.ts +0 -103
  276. package/src/editor/funcs.ts +0 -97
  277. package/src/editor/index.ts +0 -3
  278. package/src/editor/mover.ts +0 -43
  279. package/src/editor/plug-manager.ts +0 -172
  280. package/src/editor/plugs/editor-plug.ts +0 -69
  281. package/src/editor/plugs/header-input-plug.ts +0 -79
  282. package/src/editor/plugs/preview-plug.ts +0 -44
  283. package/src/editor/plugs/upload-plug.ts +0 -122
  284. package/src/editor/reply.ts +0 -62
  285. package/src/editor/submit.ts +0 -99
  286. package/src/lib/dark-mode.ts +0 -48
  287. package/src/lib/stat.ts +0 -71
  288. package/src/list/index.ts +0 -3
  289. package/src/list/list-lite.ts +0 -424
  290. package/src/list/list-ui.ts +0 -137
  291. package/src/list/paginator/adaptors/index.ts +0 -21
  292. package/src/list/paginator/adaptors/pagination.ts +0 -42
  293. package/src/list/paginator/adaptors/read-more.ts +0 -56
  294. package/src/list/paginator/holder.ts +0 -56
  295. package/types/artalk-data.d.ts +0 -230
  296. package/types/context.d.ts +0 -142
  297. package/types/event.d.ts +0 -28
  298. package/types/plug.d.ts +0 -4
  299. /package/src/{editor/plugs/emoticons-plug.scss → plugins/editor/emoticons.scss} +0 -0
  300. /package/src/{editor/plugs/preview-plug.scss → plugins/editor/preview.scss} +0 -0
package/src/service.ts CHANGED
@@ -1,26 +1,23 @@
1
- import Context from '~/types/context'
2
- import CheckerLauncher from './lib/checker'
3
- import Api from './api'
4
- import Editor from './editor'
5
- import List from './list'
6
- import Layer from './layer'
1
+ import type { ContextApi } from '~/types'
2
+ import CheckerLauncher from './components/checker'
3
+ import Editor from './editor/editor'
7
4
  import SidebarLayer from './layer/sidebar-layer'
8
- import { initMarked } from './lib/marked'
5
+
9
6
  import User from './lib/user'
10
- import ListLite from './list/list-lite'
11
- import * as DarkMode from './lib/dark-mode'
7
+ import List from './list/list'
8
+
12
9
  import * as I18n from './i18n'
10
+ import { PlugManager } from './plugins/editor-kit'
11
+ import { LayerManager } from './layer/layer-manager'
13
12
 
14
13
  /**
15
14
  * Services
16
15
  *
17
- * @description
18
- * 当函数有返回值时,该值将自动添加到 Context 类作为一个 private 成员的值,
19
- * 这个成员的名称与函数名对应。可在 Context 类中访问该对象(同事类)。
16
+ * @description Call these services by `ctx.get('serviceName')` or `ctx.serviceName`
20
17
  */
21
18
  const services = {
22
19
  // I18n
23
- i18n(ctx: Context) {
20
+ i18n(ctx: ContextApi) {
24
21
  I18n.setLocale(ctx.conf.locale)
25
22
 
26
23
  ctx.on('conf-loaded', () => {
@@ -28,82 +25,58 @@ const services = {
28
25
  })
29
26
  },
30
27
 
31
- // Markdown 组件
32
- markdown() {
33
- initMarked()
34
- },
35
-
36
28
  // User Store
37
- user(ctx: Context) {
38
- User.setContext(ctx)
29
+ user(ctx: ContextApi) {
30
+ User.setOnUserChanged((user) => {
31
+ ctx?.trigger('user-changed', user)
32
+ })
39
33
  return User
40
34
  },
41
35
 
42
- // HTTP API client
43
- api(ctx: Context) {
44
- const api = new Api(ctx)
45
- return api
36
+ // 弹出层
37
+ layerManager(ctx: ContextApi) {
38
+ return new LayerManager(ctx)
46
39
  },
47
40
 
48
41
  // CheckerLauncher
49
- checkerLauncher(ctx: Context) {
50
- const checkerLauncher = new CheckerLauncher(ctx)
42
+ checkerLauncher(ctx: ContextApi) {
43
+ const checkerLauncher = new CheckerLauncher({
44
+ getCtx: () => ctx,
45
+ getApi: () => ctx.getApi(),
46
+ getIframeURLBase: () => ctx.conf.server,
47
+ onReload: () => ctx.reload()
48
+ })
51
49
  return checkerLauncher
52
50
  },
53
51
 
54
52
  // 编辑器
55
- editor(ctx: Context) {
53
+ editor(ctx: ContextApi) {
56
54
  const editor = new Editor(ctx)
57
55
  ctx.$root.appendChild(editor.$el)
58
56
  return editor
59
57
  },
60
58
 
61
59
  // 评论列表
62
- list(ctx: Context): ListLite|undefined {
63
- // 评论列表
60
+ list(ctx: ContextApi): List {
64
61
  const list = new List(ctx)
65
62
  ctx.$root.appendChild(list.$el)
66
-
67
- // 评论获取
68
- list.fetchComments(0)
69
-
70
63
  return list
71
64
  },
72
65
 
73
- // 弹出层
74
- layer(ctx: Context) {
75
- // 记录页面原始 CSS 属性
76
- Layer.BodyOrgOverflow = document.body.style.overflow
77
- Layer.BodyOrgPaddingRight = document.body.style.paddingRight
78
- },
79
-
80
66
  // 侧边栏 Layer
81
- sidebarLayer(ctx: Context) {
67
+ sidebarLayer(ctx: ContextApi) {
82
68
  const sidebarLayer = new SidebarLayer(ctx)
83
69
  return sidebarLayer
84
70
  },
85
71
 
86
- // 默认事件绑定
87
- eventsDefault(ctx: Context) {
88
- // 锚点快速跳转评论
89
- window.addEventListener('hashchange', () => {
90
- ctx.listHashGotoCheck()
91
- })
72
+ // Extra Service
73
+ // -----------------------------------------
74
+ // Only for type check
75
+ // Not inject to ctx immediately,
76
+ // but can be injected by other occasions
92
77
 
93
- // 本地用户数据变更
94
- ctx.on('user-changed', () => {
95
- ctx.checkAdminShowEl()
96
- ctx.listRefreshUI()
97
- })
98
- },
99
-
100
- // 夜间模式
101
- darkMode(ctx: Context) {
102
- DarkMode.syncDarkModeConf(ctx)
103
-
104
- ctx.on('conf-loaded', () => {
105
- DarkMode.syncDarkModeConf(ctx)
106
- })
78
+ editorPlugs(): PlugManager|undefined {
79
+ return undefined
107
80
  }
108
81
  }
109
82
 
@@ -41,7 +41,7 @@
41
41
 
42
42
  .atk-comment {
43
43
  display: block;
44
- padding: 12px 10px;
44
+ padding: 10px;
45
45
 
46
46
  & > .atk-avatar {
47
47
  display: block;
@@ -239,23 +239,21 @@
239
239
  }
240
240
 
241
241
  & > .atk-footer {
242
- margin-top: 12px;
242
+ margin-top: 5px;
243
243
 
244
244
  .atk-actions {
245
245
  display: flex;
246
246
  flex-direction: row;
247
247
  align-items: center;
248
248
  flex-wrap: wrap;
249
- margin-bottom: -15px;
250
249
 
251
250
  & > span {
252
251
  color: var(--at-color-meta);
253
252
  font-size: 13px;
254
- line-height: 15px;
253
+ line-height: 25px;
255
254
  display: inline-flex;
256
255
  cursor: pointer;
257
256
  user-select: none;
258
- margin-bottom: 15px;
259
257
 
260
258
  &.atk-error, &.atk-error:hover {
261
259
  color: var(--at-color-red);
@@ -340,11 +338,11 @@
340
338
  border-left: 1px dashed transparent;
341
339
  border-bottom-color: transparent;
342
340
  &:not(:last-child) {
343
- margin-bottom: 5px;
341
+ margin-bottom: 10px;
344
342
  }
345
343
 
346
344
  & > .atk-comment {
347
- padding: 4px 0;
345
+ padding: 0;
348
346
 
349
347
  & > .atk-avatar img {
350
348
  width: 36px;
@@ -11,6 +11,11 @@
11
11
  margin-bottom: 7px;
12
12
  }
13
13
 
14
+ &.editor-traveling {
15
+ margin-top: 5px;
16
+ margin-bottom: 10px;
17
+ }
18
+
14
19
  & > .atk-header {
15
20
  display: flex;
16
21
  flex-direction: row;
@@ -132,14 +132,10 @@
132
132
  }
133
133
 
134
134
  & > .atk-list-footer {
135
- z-index: 1;
136
- position: absolute;
137
- bottom: 5px;
138
- right: 0;
135
+ text-align: right;
139
136
 
140
137
  @media only screen and (max-width: 768px) {
141
- position: relative;
142
- margin-top: 10px;
138
+ float: initial;
143
139
  text-align: center;
144
140
  }
145
141
 
@@ -148,7 +144,6 @@
148
144
  font-size: 12px;
149
145
  color: var(--at-color-meta);
150
146
  padding-right: 15px;
151
- margin-top: 5px;
152
147
 
153
148
  a {
154
149
  color: var(--at-color-main);
@@ -1,7 +1,7 @@
1
1
  import { I18n } from '~/src/i18n'
2
- import { CommentData } from './artalk-data'
2
+ import { CommentData } from './data'
3
3
 
4
- export default interface ArtalkConfig {
4
+ export interface ArtalkConfig {
5
5
  /** 装载元素 */
6
6
  el: string|HTMLElement
7
7
 
@@ -115,6 +115,20 @@ export default interface ArtalkConfig {
115
115
 
116
116
  /** 语言本地化 */
117
117
  locale: I18n|string
118
+
119
+ /** 后端版本 (系统数据,用户不允许更改) */
120
+ apiVersion?: string
121
+
122
+ /** Replacer for marked */
123
+ markedReplacers?: ((raw: string) => string)[]
124
+
125
+ /** 列表请求参数修改器 */
126
+ listFetchParamsModifier?: (params: any) => void
127
+
128
+ // TODO consider merge list related config into one object, or flatten all to keep simple (keep consistency)
129
+ remoteConfModifier?: (conf: Partial<ArtalkConfig>) => void
130
+ listUnreadHighlight?: boolean
131
+ scrollRelativeTo?: () => HTMLElement
118
132
  }
119
133
 
120
134
  /**
@@ -0,0 +1,84 @@
1
+ import type { TInjectedServices } from '@/service'
2
+ import type { CheckerCaptchaPayload, CheckerPayload } from '@/components/checker'
3
+ import type { EventManagerFuncs } from '@/lib/event-manager'
4
+ import type { TMarked } from '@/lib/marked'
5
+ import type { I18n } from '@/i18n'
6
+ import type Api from '@/api'
7
+ import type { SidebarShowPayload, EventPayloadMap, ArtalkConfig, CommentData, DataManagerApi, ListFetchParams, NotifyLevel } from '.'
8
+
9
+ /**
10
+ * Context 接口
11
+ *
12
+ * (面向接口的编程)
13
+ */
14
+ export interface ContextApi extends EventManagerFuncs<EventPayloadMap> {
15
+ /** Artalk 根元素对象 */
16
+ $root: HTMLElement
17
+
18
+ /** 依赖注入函数 */
19
+ inject<K extends keyof TInjectedServices>(depName: K, obj: TInjectedServices[K]): void
20
+
21
+ /** 获取依赖对象 */
22
+ get<K extends keyof TInjectedServices>(depName: K): TInjectedServices[K]
23
+
24
+ /** 配置对象 */
25
+ // TODO 修改为 getConf() 和 setConf() 并且返回拷贝而不是引用
26
+ conf: ArtalkConfig
27
+
28
+ /** marked 依赖对象 */
29
+ getMarked(): TMarked | undefined
30
+
31
+ /** 获取 API 以供 HTTP 请求 */
32
+ getApi(): Api
33
+
34
+ /** 获取数据管理器对象 */
35
+ getData(): DataManagerApi
36
+
37
+ /** 评论回复 */
38
+ replyComment(commentData: CommentData, $comment: HTMLElement): void
39
+
40
+ /** 编辑评论 */
41
+ editComment(commentData: CommentData, $comment: HTMLElement): void
42
+
43
+ /** 获取评论数据 */
44
+ fetch(params: Partial<ListFetchParams>): void
45
+
46
+ /** 重载评论数据 */
47
+ reload(): void
48
+
49
+ /** 列表滚动到第一个评论的位置 */
50
+ listGotoFirst(): void
51
+
52
+ /** 显示侧边栏 */
53
+ showSidebar(payload?: SidebarShowPayload): void
54
+
55
+ /** 隐藏侧边栏 */
56
+ hideSidebar(): void
57
+
58
+ /** 编辑器 - 显示加载 */
59
+ editorShowLoading(): void
60
+
61
+ /** 编辑器 - 隐藏加载 */
62
+ editorHideLoading(): void
63
+
64
+ /** 编辑器 - 显示提示消息 */
65
+ editorShowNotify(msg: string, type: NotifyLevel): void
66
+
67
+ /** 评论框 - 复原状态 */
68
+ editorResetState(): void
69
+
70
+ /** 验证码检测 */
71
+ checkCaptcha(payload: CheckerCaptchaPayload): void
72
+
73
+ /** 管理员检测 */
74
+ checkAdmin(payload: CheckerPayload): void
75
+
76
+ /** i18n 翻译 */
77
+ $t(key: keyof I18n, args?: {[key: string]: string}): string
78
+
79
+ /** 设置夜间模式 */
80
+ setDarkMode(darkMode: boolean|'auto'): void
81
+
82
+ /** 更新配置 */
83
+ updateConf(conf: Partial<ArtalkConfig>): void
84
+ }
@@ -228,3 +228,44 @@ export interface ApiVersionData {
228
228
  /** API 程序 CommitHash */
229
229
  commit_hash: string
230
230
  }
231
+
232
+ export interface ListFetchParams {
233
+ offset: number
234
+ limit: number
235
+ flatMode: boolean
236
+ paramsModifier?: (p: any) => void
237
+ onSuccess?: (data: ListData) => void
238
+ onError?: (err: any) => void
239
+ }
240
+
241
+ export interface ListLastFetchData {
242
+ params: ListFetchParams
243
+ data?: ListData
244
+ }
245
+
246
+ export interface DataManagerApi {
247
+ getLoading(): boolean
248
+ setLoading(val: boolean): void
249
+
250
+ getListLastFetch(): ListLastFetchData|undefined
251
+ setListLastFetch(val: ListLastFetchData): void
252
+
253
+ getComments(): CommentData[]
254
+ findComment(id: number): CommentData|undefined
255
+
256
+ fetchComments(params: Partial<ListFetchParams>): void
257
+ loadComments(comments: CommentData[]): void
258
+ clearComments(): void
259
+
260
+ insertComment(comment: CommentData): void
261
+ updateComment(comment: CommentData): void
262
+ deleteComment(id: number): void
263
+
264
+ getUnreads(): NotifyData[]
265
+ updateUnreads(unreads: NotifyData[]): void
266
+
267
+ getPage(): PageData|undefined
268
+ updatePage(pageData: PageData): void
269
+ }
270
+
271
+ export type NotifyLevel = "i" | "s" | "w" | "e"
@@ -0,0 +1,95 @@
1
+ import type { CommentData, NotifyLevel } from '.'
2
+ import type Component from '../src/lib/component'
3
+ import type { EditorUI } from '../src/editor/ui'
4
+
5
+ export type EditorState = 'reply' | 'edit' | 'normal'
6
+
7
+ export interface EditorApi extends Component {
8
+ getUI(): EditorUI
9
+
10
+ /**
11
+ * Get the header input elements
12
+ */
13
+ getHeaderInputEls(): Record<string, HTMLInputElement>
14
+
15
+ /**
16
+ * Set content
17
+ */
18
+ setContent(val: string): void
19
+
20
+ /**
21
+ * Insert content
22
+ */
23
+ insertContent(val: string): void
24
+
25
+ /**
26
+ * Get the final content
27
+ *
28
+ * This function returns the raw content or the content transformed through a plugin hook.
29
+ */
30
+ getContentFinal(): string
31
+
32
+ /**
33
+ * Get the raw content which is inputed by user
34
+ */
35
+ getContentRaw(): string
36
+
37
+ /**
38
+ * Get the HTML format content which is rendered by marked (a markdown parser)
39
+ */
40
+ getContentMarked(): string
41
+
42
+ /**
43
+ * Get editor current state
44
+ */
45
+ getState(): EditorState
46
+
47
+ /**
48
+ * Focus editor
49
+ */
50
+ focus(): void
51
+
52
+ /**
53
+ * Reset editor
54
+ */
55
+ reset(): void
56
+
57
+ /**
58
+ * Reset editor UI
59
+ *
60
+ * call it will move editor to the initial position
61
+ */
62
+ resetState(): void
63
+
64
+ /**
65
+ * Submit comment
66
+ */
67
+ submit(): void
68
+
69
+ /**
70
+ * Show notification message
71
+ */
72
+ showNotify(msg: string, type: NotifyLevel): void
73
+
74
+ /**
75
+ * Show loading on editor
76
+ */
77
+ showLoading(): void
78
+
79
+ /**
80
+ * Hide loading on editor
81
+ */
82
+ hideLoading(): void
83
+
84
+ /**
85
+ * Start replaying a comment
86
+ */
87
+ setReply(commentData: CommentData, $comment: HTMLElement, scroll?: boolean): void
88
+
89
+ /**
90
+ * Start editing a comment
91
+ */
92
+ setEditComment(commentData: CommentData, $comment: HTMLElement): void
93
+ }
94
+
95
+ export default EditorApi
package/types/event.ts ADDED
@@ -0,0 +1,40 @@
1
+ import type Comment from '~/src/comment'
2
+ import { CommentData, ListData, ListFetchParams, NotifyData, PageData } from './data'
3
+ import { ArtalkConfig, LocalUser } from './config'
4
+
5
+ interface ErrorData { msg: string, data?: any }
6
+ interface ListFetchedArgs { params: Partial<ListFetchParams>, data?: ListData, error?: ErrorData }
7
+
8
+ /** EventName to EventPayload Type */
9
+ export interface EventPayloadMap {
10
+ 'inited': undefined // Artalk 初始化后
11
+ 'destroy': undefined // Artalk 销毁时
12
+ 'list-fetch': Partial<ListFetchParams> // 评论列表请求时
13
+ 'list-fetched': ListFetchedArgs // 评论列表请求后
14
+ 'list-load': CommentData[] // 评论装载前
15
+
16
+ // TODO merge 'list-loaded' and 'list-error', for purpose of `once` 'list-loaded' and simplify
17
+ // example need bind 'list-loaded' and 'list-error' to same handler
18
+ // consider name it to 'list-fetched': { data: CommentData[], error?: { msg: string, data?: any } }
19
+ // and remove `list-load`
20
+ 'list-loaded': CommentData[] // 评论装载后
21
+ 'list-error': ErrorData // 评论加载错误时
22
+
23
+ 'list-goto-first': undefined // 评论列表归位时
24
+ 'list-reach-bottom': undefined // 评论列表滚动到底部时
25
+
26
+ 'comment-inserted': CommentData // 评论插入后
27
+ 'comment-updated': CommentData // 评论更新后
28
+ 'comment-deleted': CommentData // 评论删除后
29
+ 'comment-rendered': Comment // 评论节点渲染后
30
+ 'unreads-updated': NotifyData[] // 未读消息变更时
31
+ 'list-goto': number // 评论跳转时
32
+ 'page-loaded': PageData // 页面数据更新后
33
+ 'editor-submit': undefined // 编辑器提交时
34
+ 'editor-submitted': undefined // 编辑器提交后
35
+ 'user-changed': LocalUser // 本地用户数据变更时
36
+ 'conf-loaded': ArtalkConfig // Artalk 配置变更时
37
+ 'dark-mode-changed': boolean // 深色模式变更时
38
+ 'sidebar-show': undefined // 侧边栏显示
39
+ 'sidebar-hide': undefined // 侧边栏隐藏
40
+ }
package/types/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from './config'
2
+ export * from './data'
3
+ export * from './context'
4
+ export * from './editor'
5
+ export * from './event'
6
+ export * from './plugin'
7
+ export * from './sidebar'
@@ -0,0 +1,3 @@
1
+ import { ContextApi } from './context'
2
+
3
+ export type ArtalkPlugin = (ctx: ContextApi) => void
@@ -0,0 +1,3 @@
1
+ export interface SidebarShowPayload {
2
+ view?: 'comments'|'sites'|'pages'|'transfer'
3
+ }
@@ -1,23 +0,0 @@
1
- import Comment from './comment';
2
- import ActionBtn from '../components/action-btn';
3
- export default class RenderCtx {
4
- comment: Comment;
5
- get ctx(): import("../../types/context").default;
6
- get data(): import("../../types/artalk-data").CommentData;
7
- get conf(): import("../../types/artalk-config").default;
8
- get cConf(): import("./comment").CommentConf;
9
- $el: HTMLElement;
10
- $main: HTMLElement;
11
- $header: HTMLElement;
12
- $headerNick: HTMLElement;
13
- $headerBadgeWrap: HTMLElement;
14
- $body: HTMLElement;
15
- $content: HTMLElement;
16
- $childrenWrap: HTMLElement | null;
17
- $actions: HTMLElement;
18
- voteBtnUp?: ActionBtn;
19
- voteBtnDown?: ActionBtn;
20
- $replyTo?: HTMLElement;
21
- $replyAt?: HTMLElement;
22
- constructor(comment: Comment);
23
- }
@@ -1,9 +0,0 @@
1
- import type { CommentData } from '../../types/artalk-data';
2
- import Editor from './editor';
3
- export interface EditModeManager {
4
- editor: Editor;
5
- comment?: CommentData;
6
- setEdit: (comment: CommentData, $comment: HTMLElement) => void;
7
- cancelEdit: () => void;
8
- }
9
- export declare function createEditModeManager(editor: Editor): EditModeManager;
@@ -1,2 +0,0 @@
1
- import Editor from './editor';
2
- export default function initEditorFuncs(editor: Editor): void;
@@ -1,2 +0,0 @@
1
- import Editor from './editor';
2
- export default Editor;
@@ -1,8 +0,0 @@
1
- import Editor from './editor';
2
- export interface Mover {
3
- editor: Editor;
4
- isMoved: boolean;
5
- move(afterEl: HTMLElement): void;
6
- back(): void;
7
- }
8
- export declare function createMover(editor: Editor): Mover;
@@ -1,17 +0,0 @@
1
- import EditorPlug from './plugs/editor-plug';
2
- import Editor from './editor';
3
- /** Context of an editor plug manager */
4
- export interface PlugManager {
5
- editor: Editor;
6
- plugList: {
7
- [name: string]: EditorPlug;
8
- };
9
- openedPlugName: string | null;
10
- openPlugPanel(plugName: string): void;
11
- closePlugPanel(): void;
12
- triggerHeaderInputEvt(field: string, $input: HTMLInputElement): void;
13
- triggerContentUpdatedEvt(content: string): void;
14
- getTransformedContent(raw: string): string;
15
- }
16
- /** Create an editor plug manager */
17
- export declare function createPlugManager(editor: Editor): PlugManager;
@@ -1,38 +0,0 @@
1
- import Editor from '../editor';
2
- /**
3
- * Editor 插件
4
- *
5
- * @desc 使用 Interface x Abstract 合并声明
6
- * @see https://www.typescriptlang.org/docs/handbook/declaration-merging.html#merging-interfaces
7
- */
8
- interface EditorPlug {
9
- onPanelShow?(): void;
10
- onPanelHide?(): void;
11
- }
12
- declare abstract class EditorPlug {
13
- protected editor: Editor;
14
- protected get ctx(): import("../../../types/context").default;
15
- protected $panel?: HTMLElement;
16
- protected $btn?: HTMLElement;
17
- onHeaderInput?: (key: string, $input: HTMLElement) => void;
18
- contentTransformer?: (rawContent: string) => string;
19
- onContentUpdated?: (content: string) => void;
20
- constructor(editor: Editor);
21
- /** Name of plug */
22
- static Name: string;
23
- /** Register plug panel will provide a plug el */
24
- protected registerPanel(html?: string): HTMLElement;
25
- /** Register plug btn will add a btn on the bottom of editor */
26
- protected registerBtn(html: string): HTMLElement;
27
- /** Register the event of header input is changed */
28
- protected registerHeaderInputEvt(func: (key: string, $input: HTMLElement) => void): void;
29
- /** Register the content transformer to handle the content of the last submit by the editor */
30
- protected registerContentTransformer(func: (raw: string) => string): void;
31
- /** Register the event of editor content is updated */
32
- protected registerContentUpdatedEvt(func: (content: string) => void): void;
33
- /** Get panel element of plug */
34
- getPanel(): HTMLElement | undefined;
35
- /** Get btn element of plug */
36
- getBtn(): HTMLElement | undefined;
37
- }
38
- export default EditorPlug;
@@ -1,13 +0,0 @@
1
- import Editor from '../editor';
2
- import EditorPlug from './editor-plug';
3
- export default class HeaderInputPlug extends EditorPlug {
4
- static Name: string;
5
- constructor(editor: Editor);
6
- queryUserInfo: {
7
- timeout: number | null;
8
- abortFunc: (() => void) | null;
9
- };
10
- /** 远程获取用户数据 */
11
- fetchUserInfo(): void;
12
- showLoginDialog(): void;
13
- }
@@ -1,10 +0,0 @@
1
- import Editor from '../editor';
2
- import EditorPlug from './editor-plug';
3
- export default class PreviewPlug extends EditorPlug {
4
- static Name: string;
5
- protected $panel: HTMLElement;
6
- private isBind;
7
- constructor(editor: Editor);
8
- onPanelShow(): void;
9
- updateContent(): void;
10
- }