artalk 2.6.4 → 2.7.1

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 (316) hide show
  1. package/dist/Artalk.css +1 -1
  2. package/dist/Artalk.es.js +7756 -7432
  3. package/dist/Artalk.es.js.map +1 -0
  4. package/dist/Artalk.iife.js +2 -1
  5. package/dist/Artalk.iife.js.map +1 -0
  6. package/dist/Artalk.js +2 -1
  7. package/dist/Artalk.js.map +1 -0
  8. package/dist/ArtalkLite.css +1 -1
  9. package/dist/ArtalkLite.es.js +5576 -5252
  10. package/dist/ArtalkLite.es.js.map +1 -0
  11. package/dist/ArtalkLite.iife.js +2 -1
  12. package/dist/ArtalkLite.iife.js.map +1 -0
  13. package/dist/ArtalkLite.js +2 -1
  14. package/dist/ArtalkLite.js.map +1 -0
  15. package/dist/i18n/jp.js +1 -1
  16. package/dist/i18n/zh-TW.js +1 -1
  17. package/dist/src/api/{api-base.d.ts → _base.d.ts} +3 -7
  18. package/dist/src/api/_options.d.ts +19 -0
  19. package/dist/src/api/{request.d.ts → _request.d.ts} +3 -3
  20. package/dist/src/api/admin.d.ts +1 -1
  21. package/dist/src/api/captcha.d.ts +1 -1
  22. package/dist/src/api/comment.d.ts +2 -2
  23. package/dist/src/api/index.d.ts +2 -4
  24. package/dist/src/api/page.d.ts +3 -3
  25. package/dist/src/api/site.d.ts +2 -2
  26. package/dist/src/api/system.d.ts +13 -3
  27. package/dist/src/api/upload.d.ts +1 -1
  28. package/dist/src/api/user.d.ts +2 -2
  29. package/dist/src/artalk.d.ts +12 -37
  30. package/dist/src/comment/actions.d.ts +1 -1
  31. package/dist/src/comment/comment.d.ts +3 -4
  32. package/dist/src/comment/render.d.ts +21 -3
  33. package/dist/src/comment/renders/actions.d.ts +2 -2
  34. package/dist/src/comment/renders/avatar.d.ts +2 -2
  35. package/dist/src/comment/renders/content.d.ts +2 -2
  36. package/dist/src/comment/renders/header.d.ts +2 -2
  37. package/dist/src/comment/renders/index.d.ts +2 -2
  38. package/dist/src/comment/renders/pending.d.ts +2 -2
  39. package/dist/src/comment/renders/reply-at.d.ts +2 -2
  40. package/dist/src/comment/renders/reply-to.d.ts +2 -2
  41. package/dist/src/components/action-btn.d.ts +3 -5
  42. package/dist/src/{lib → components}/checker/admin.d.ts +1 -1
  43. package/dist/src/{lib → components}/checker/captcha-renders.d.ts +1 -1
  44. package/dist/src/{lib → components}/checker/captcha.d.ts +1 -1
  45. package/dist/src/{lib → components}/checker/index.d.ts +10 -7
  46. package/dist/src/components/dark-mode.d.ts +2 -0
  47. package/dist/src/components/dialog.d.ts +1 -3
  48. package/dist/src/components/error-dialog.d.ts +8 -0
  49. package/dist/src/components/pagination.d.ts +4 -3
  50. package/dist/src/components/read-more-btn.d.ts +3 -3
  51. package/dist/src/config.d.ts +24 -8
  52. package/dist/src/context.d.ts +16 -35
  53. package/dist/src/data.d.ts +27 -0
  54. package/dist/src/defaults.d.ts +1 -1
  55. package/dist/src/editor/editor.d.ts +14 -61
  56. package/dist/src/editor/state.d.ts +20 -0
  57. package/dist/src/i18n/en.d.ts +3 -0
  58. package/dist/src/i18n/external.d.ts +3 -0
  59. package/dist/src/i18n/index.d.ts +9 -0
  60. package/dist/src/i18n/jp.d.ts +3 -0
  61. package/dist/src/i18n/zh-CN.d.ts +1 -1
  62. package/dist/src/i18n/zh-TW.d.ts +3 -0
  63. package/dist/src/layer/index.d.ts +4 -3
  64. package/dist/src/layer/layer-manager.d.ts +9 -0
  65. package/dist/src/layer/layer.d.ts +8 -28
  66. package/dist/src/layer/scrollbar-helper.d.ts +5 -0
  67. package/dist/src/layer/sidebar-layer.d.ts +6 -6
  68. package/dist/src/layer/wrap.d.ts +13 -0
  69. package/dist/src/lib/component.d.ts +3 -8
  70. package/dist/src/lib/event-manager.d.ts +28 -0
  71. package/dist/src/lib/highlight.d.ts +1 -0
  72. package/dist/src/lib/marked-renderer.d.ts +4 -0
  73. package/dist/src/lib/marked.d.ts +4 -2
  74. package/dist/src/lib/sanitizer.d.ts +1 -0
  75. package/dist/src/lib/ui.d.ts +3 -2
  76. package/dist/src/lib/user.d.ts +8 -5
  77. package/dist/src/lib/utils.d.ts +11 -5
  78. package/dist/src/list/comment.d.ts +3 -0
  79. package/dist/src/list/layout.d.ts +23 -0
  80. package/dist/src/list/list.d.ts +13 -25
  81. package/dist/src/list/{list-nest.d.ts → nest.d.ts} +1 -1
  82. package/dist/src/list/page.d.ts +2 -0
  83. package/dist/src/list/paginator/index.d.ts +22 -7
  84. package/dist/src/list/paginator/read-more.d.ts +18 -0
  85. package/dist/src/list/paginator/up-down.d.ts +14 -0
  86. package/dist/src/main.d.ts +5 -0
  87. package/dist/src/plugins/admin-only-elem.d.ts +2 -0
  88. package/dist/src/plugins/conf-remoter.d.ts +2 -0
  89. package/dist/src/plugins/dark-mode.d.ts +2 -0
  90. package/dist/src/plugins/editor/_kit.d.ts +27 -0
  91. package/dist/src/plugins/editor/_plug.d.ts +29 -0
  92. package/dist/src/plugins/editor/_sample.d.ts +5 -0
  93. package/dist/src/plugins/editor/closable.d.ts +7 -0
  94. package/dist/src/{editor/plugs/emoticons-plug.d.ts → plugins/editor/emoticons.d.ts} +10 -16
  95. package/dist/src/plugins/editor/header-event.d.ts +6 -0
  96. package/dist/src/plugins/editor/header-link.d.ts +6 -0
  97. package/dist/src/plugins/editor/header-user.d.ts +16 -0
  98. package/dist/src/plugins/editor/index.d.ts +6 -0
  99. package/dist/src/plugins/editor/local-storage.d.ts +6 -0
  100. package/dist/src/plugins/editor/mover.d.ts +6 -0
  101. package/dist/src/plugins/editor/preview.d.ts +7 -0
  102. package/dist/src/plugins/editor/state-edit.d.ts +11 -0
  103. package/dist/src/plugins/editor/state-reply.d.ts +8 -0
  104. package/dist/src/plugins/editor/submit-add.d.ts +18 -0
  105. package/dist/src/plugins/editor/submit-btn.d.ts +5 -0
  106. package/dist/src/plugins/editor/submit.d.ts +17 -0
  107. package/dist/src/plugins/editor/textarea.d.ts +8 -0
  108. package/dist/src/plugins/editor/upload.d.ts +9 -0
  109. package/dist/src/plugins/editor-kit.d.ts +42 -0
  110. package/dist/src/plugins/index.d.ts +2 -0
  111. package/dist/src/plugins/list/copyright.d.ts +2 -0
  112. package/dist/src/plugins/list/count.d.ts +2 -0
  113. package/dist/src/plugins/list/dropdown.d.ts +2 -0
  114. package/dist/src/plugins/list/error-dialog.d.ts +2 -0
  115. package/dist/src/plugins/list/fetch.d.ts +2 -0
  116. package/dist/src/plugins/list/goto-first.d.ts +3 -0
  117. package/dist/src/plugins/list/goto.d.ts +2 -0
  118. package/dist/src/plugins/list/index.d.ts +3 -0
  119. package/dist/src/plugins/list/loading.d.ts +2 -0
  120. package/dist/src/plugins/list/no-comment.d.ts +2 -0
  121. package/dist/src/plugins/list/reach-bottom.d.ts +2 -0
  122. package/dist/src/plugins/list/sidebar-btn.d.ts +2 -0
  123. package/dist/src/plugins/list/time-ticking.d.ts +3 -0
  124. package/dist/src/plugins/list/unread-badge.d.ts +2 -0
  125. package/dist/src/plugins/list/unread.d.ts +2 -0
  126. package/dist/src/plugins/list/with-editor.d.ts +2 -0
  127. package/dist/src/plugins/markdown.d.ts +2 -0
  128. package/dist/src/plugins/stat.d.ts +13 -0
  129. package/dist/src/plugins/version-check.d.ts +2 -0
  130. package/dist/src/service.d.ts +19 -23
  131. package/dist/tests/e2e/comment-add.spec.d.ts +1 -0
  132. package/dist/types/config.d.ts +110 -0
  133. package/dist/types/context.d.ts +56 -136
  134. package/dist/types/data.d.ts +194 -0
  135. package/dist/types/editor.d.ts +76 -0
  136. package/dist/types/event.d.ts +36 -25
  137. package/dist/types/index.d.ts +7 -0
  138. package/dist/types/plugin.d.ts +2 -0
  139. package/dist/types/sidebar.d.ts +3 -0
  140. package/package.json +5 -2
  141. package/src/api/_base.ts +18 -0
  142. package/src/api/_options.ts +25 -0
  143. package/src/api/{request.ts → _request.ts} +19 -18
  144. package/src/api/admin.ts +1 -1
  145. package/src/api/captcha.ts +1 -1
  146. package/src/api/comment.ts +4 -4
  147. package/src/api/index.ts +3 -12
  148. package/src/api/page.ts +5 -5
  149. package/src/api/site.ts +2 -2
  150. package/src/api/system.ts +19 -7
  151. package/src/api/upload.ts +3 -3
  152. package/src/api/user.ts +3 -3
  153. package/src/artalk.ts +47 -99
  154. package/src/comment/actions.ts +1 -4
  155. package/src/comment/comment.ts +9 -6
  156. package/src/comment/render.ts +27 -5
  157. package/src/comment/renders/actions.ts +45 -45
  158. package/src/comment/renders/avatar.ts +7 -7
  159. package/src/comment/renders/content.ts +18 -18
  160. package/src/comment/renders/header.ts +13 -13
  161. package/src/comment/renders/index.ts +3 -3
  162. package/src/comment/renders/pending.ts +5 -5
  163. package/src/comment/renders/reply-at.ts +8 -8
  164. package/src/comment/renders/reply-to.ts +13 -13
  165. package/src/components/action-btn.ts +11 -13
  166. package/src/{lib → components}/checker/admin.ts +6 -6
  167. package/src/{lib → components}/checker/captcha-renders.ts +7 -6
  168. package/src/{lib → components}/checker/captcha.ts +1 -1
  169. package/src/{lib → components}/checker/index.ts +21 -26
  170. package/src/components/dark-mode.ts +30 -0
  171. package/src/components/dialog.ts +4 -9
  172. package/src/components/error-dialog.ts +35 -0
  173. package/src/components/pagination.ts +10 -6
  174. package/src/components/read-more-btn.ts +7 -7
  175. package/src/config.ts +60 -6
  176. package/src/context.ts +39 -144
  177. package/src/data.ts +110 -0
  178. package/src/defaults.ts +1 -1
  179. package/src/editor/editor.ts +39 -152
  180. package/src/editor/state.ts +52 -0
  181. package/src/i18n/en.ts +3 -0
  182. package/src/i18n/jp.ts +3 -0
  183. package/src/i18n/zh-CN.ts +4 -1
  184. package/src/i18n/zh-TW.ts +3 -0
  185. package/src/layer/index.ts +4 -4
  186. package/src/layer/layer-manager.ts +32 -0
  187. package/src/layer/layer.ts +20 -144
  188. package/src/layer/scrollbar-helper.ts +24 -0
  189. package/src/layer/sidebar-layer.ts +74 -64
  190. package/src/layer/wrap.ts +77 -0
  191. package/src/lib/component.ts +4 -11
  192. package/src/lib/detect.ts +1 -1
  193. package/src/lib/event-manager.ts +47 -0
  194. package/src/lib/highlight.ts +5 -0
  195. package/src/lib/marked-renderer.ts +32 -0
  196. package/src/lib/marked.ts +43 -104
  197. package/src/lib/sanitizer.ts +57 -0
  198. package/src/lib/ui.ts +22 -15
  199. package/src/lib/user.ts +21 -16
  200. package/src/lib/utils.ts +29 -18
  201. package/src/list/comment.ts +20 -0
  202. package/src/list/layout.ts +120 -0
  203. package/src/list/list.html +3 -1
  204. package/src/list/list.ts +56 -200
  205. package/src/list/{list-nest.ts → nest.ts} +1 -1
  206. package/src/list/page.ts +97 -0
  207. package/src/list/paginator/index.ts +20 -8
  208. package/src/list/paginator/read-more.ts +67 -0
  209. package/src/list/paginator/up-down.ts +51 -0
  210. package/src/main.ts +11 -0
  211. package/src/plugins/admin-only-elem.ts +40 -0
  212. package/src/plugins/conf-remoter.ts +54 -0
  213. package/src/plugins/dark-mode.ts +12 -0
  214. package/src/plugins/editor/_kit.ts +57 -0
  215. package/src/plugins/editor/_plug.ts +60 -0
  216. package/src/plugins/editor/_sample.ts +8 -0
  217. package/src/plugins/editor/closable.ts +44 -0
  218. package/src/{editor/plugs/emoticons-plug.ts → plugins/editor/emoticons.ts} +51 -52
  219. package/src/plugins/editor/header-event.ts +35 -0
  220. package/src/plugins/editor/header-link.ts +31 -0
  221. package/src/plugins/editor/header-user.ts +98 -0
  222. package/src/plugins/editor/index.ts +40 -0
  223. package/src/plugins/editor/local-storage.ts +36 -0
  224. package/src/plugins/editor/mover.ts +29 -0
  225. package/src/plugins/editor/preview.ts +41 -0
  226. package/src/plugins/editor/state-edit.ts +116 -0
  227. package/src/plugins/editor/state-reply.ts +91 -0
  228. package/src/plugins/editor/submit-add.ts +33 -0
  229. package/src/plugins/editor/submit-btn.ts +25 -0
  230. package/src/plugins/editor/submit.ts +73 -0
  231. package/src/plugins/editor/textarea.ts +55 -0
  232. package/src/plugins/editor/upload.ts +145 -0
  233. package/src/plugins/editor-kit.ts +161 -0
  234. package/src/plugins/index.ts +16 -0
  235. package/src/plugins/list/copyright.ts +16 -0
  236. package/src/plugins/list/count.ts +31 -0
  237. package/src/plugins/list/dropdown.ts +95 -0
  238. package/src/plugins/list/error-dialog.ts +22 -0
  239. package/src/plugins/list/fetch.ts +64 -0
  240. package/src/plugins/list/goto-first.ts +23 -0
  241. package/src/plugins/list/goto.ts +72 -0
  242. package/src/plugins/list/index.ts +25 -0
  243. package/src/plugins/list/loading.ts +17 -0
  244. package/src/plugins/list/no-comment.ts +25 -0
  245. package/src/plugins/list/reach-bottom.ts +46 -0
  246. package/src/plugins/list/sidebar-btn.ts +39 -0
  247. package/src/plugins/list/time-ticking.ts +22 -0
  248. package/src/plugins/list/unread-badge.ts +26 -0
  249. package/src/plugins/list/unread.ts +38 -0
  250. package/src/plugins/list/with-editor.ts +59 -0
  251. package/src/plugins/markdown.ts +10 -0
  252. package/src/plugins/stat.ts +82 -0
  253. package/src/plugins/version-check.ts +36 -0
  254. package/src/service.ts +34 -61
  255. package/src/style/comment.scss +5 -7
  256. package/src/style/editor.scss +5 -0
  257. package/src/style/list.scss +1 -1
  258. package/types/{artalk-config.d.ts → config.ts} +16 -2
  259. package/types/context.ts +84 -0
  260. package/types/{artalk-data.d.ts → data.ts} +41 -0
  261. package/types/editor.ts +95 -0
  262. package/types/event.ts +40 -0
  263. package/types/index.ts +7 -0
  264. package/types/plugin.ts +3 -0
  265. package/types/sidebar.ts +3 -0
  266. package/dist/src/comment/render-ctx.d.ts +0 -23
  267. package/dist/src/editor/edit-mode.d.ts +0 -9
  268. package/dist/src/editor/funcs.d.ts +0 -2
  269. package/dist/src/editor/index.d.ts +0 -2
  270. package/dist/src/editor/mover.d.ts +0 -8
  271. package/dist/src/editor/plug-manager.d.ts +0 -17
  272. package/dist/src/editor/plugs/editor-plug.d.ts +0 -38
  273. package/dist/src/editor/plugs/header-input-plug.d.ts +0 -13
  274. package/dist/src/editor/plugs/preview-plug.d.ts +0 -10
  275. package/dist/src/editor/plugs/upload-plug.d.ts +0 -10
  276. package/dist/src/editor/reply.d.ts +0 -9
  277. package/dist/src/editor/submit.d.ts +0 -16
  278. package/dist/src/lib/dark-mode.d.ts +0 -4
  279. package/dist/src/lib/stat.d.ts +0 -15
  280. package/dist/src/list/index.d.ts +0 -2
  281. package/dist/src/list/list-lite.d.ts +0 -77
  282. package/dist/src/list/list-ui.d.ts +0 -16
  283. package/dist/src/list/paginator/adaptors/index.d.ts +0 -12
  284. package/dist/src/list/paginator/adaptors/pagination.d.ts +0 -9
  285. package/dist/src/list/paginator/adaptors/read-more.d.ts +0 -10
  286. package/dist/src/list/paginator/holder.d.ts +0 -16
  287. package/dist/types/artalk-config.d.ts +0 -139
  288. package/dist/types/artalk-data.d.ts +0 -230
  289. package/dist/types/plug.d.ts +0 -4
  290. package/src/api/api-base.ts +0 -27
  291. package/src/comment/render-ctx.ts +0 -30
  292. package/src/editor/edit-mode.ts +0 -105
  293. package/src/editor/funcs.ts +0 -150
  294. package/src/editor/index.ts +0 -3
  295. package/src/editor/mover.ts +0 -43
  296. package/src/editor/plug-manager.ts +0 -172
  297. package/src/editor/plugs/editor-plug.ts +0 -69
  298. package/src/editor/plugs/header-input-plug.ts +0 -79
  299. package/src/editor/plugs/preview-plug.ts +0 -44
  300. package/src/editor/plugs/upload-plug.ts +0 -122
  301. package/src/editor/reply.ts +0 -62
  302. package/src/editor/submit.ts +0 -99
  303. package/src/lib/dark-mode.ts +0 -48
  304. package/src/lib/stat.ts +0 -71
  305. package/src/list/index.ts +0 -3
  306. package/src/list/list-lite.ts +0 -424
  307. package/src/list/list-ui.ts +0 -137
  308. package/src/list/paginator/adaptors/index.ts +0 -21
  309. package/src/list/paginator/adaptors/pagination.ts +0 -42
  310. package/src/list/paginator/adaptors/read-more.ts +0 -56
  311. package/src/list/paginator/holder.ts +0 -56
  312. package/types/context.d.ts +0 -142
  313. package/types/event.d.ts +0 -28
  314. package/types/plug.d.ts +0 -4
  315. /package/src/{editor/plugs/emoticons-plug.scss → plugins/editor/emoticons.scss} +0 -0
  316. /package/src/{editor/plugs/preview-plug.scss → plugins/editor/preview.scss} +0 -0
@@ -1,114 +1,114 @@
1
1
  import * as Utils from '../../lib/utils'
2
2
  import ActionBtn from '../../components/action-btn'
3
- import RenderCtx from '../render-ctx'
3
+ import type Render from '../render'
4
4
 
5
5
  /**
6
6
  * 评论操作按钮界面
7
7
  */
8
- export default function renderActions(ctx: RenderCtx) {
8
+ export default function renderActions(r: Render) {
9
9
  Object.entries({
10
10
  renderVote, renderReply,
11
11
  // 管理员操作
12
12
  renderCollapse, renderModerator, renderPin, renderEdit, renderDel
13
13
  }).forEach(([name, render]) => {
14
- render(ctx)
14
+ render(r)
15
15
  })
16
16
  }
17
17
 
18
18
 
19
19
  // 操作按钮 - 投票
20
- function renderVote(ctx: RenderCtx) {
21
- if (!ctx.ctx.conf.vote) return // 关闭投票功能
20
+ function renderVote(r: Render) {
21
+ if (!r.ctx.conf.vote) return // 关闭投票功能
22
22
 
23
23
  // 赞同按钮
24
- ctx.voteBtnUp = new ActionBtn(ctx.ctx, () => `${ctx.ctx.$t('voteUp')} (${ctx.data.vote_up || 0})`).appendTo(ctx.$actions)
25
- ctx.voteBtnUp.setClick(() => {
26
- ctx.comment.getActions().vote('up')
24
+ r.voteBtnUp = new ActionBtn(() => `${r.ctx.$t('voteUp')} (${r.data.vote_up || 0})`).appendTo(r.$actions)
25
+ r.voteBtnUp.setClick(() => {
26
+ r.comment.getActions().vote('up')
27
27
  })
28
28
 
29
29
  // 反对按钮
30
- if (ctx.ctx.conf.voteDown) {
31
- ctx.voteBtnDown = new ActionBtn(ctx.ctx, () => `${ctx.ctx.$t('voteDown')} (${ctx.data.vote_down || 0})`).appendTo(ctx.$actions)
32
- ctx.voteBtnDown.setClick(() => {
33
- ctx.comment.getActions().vote('down')
30
+ if (r.ctx.conf.voteDown) {
31
+ r.voteBtnDown = new ActionBtn(() => `${r.ctx.$t('voteDown')} (${r.data.vote_down || 0})`).appendTo(r.$actions)
32
+ r.voteBtnDown.setClick(() => {
33
+ r.comment.getActions().vote('down')
34
34
  })
35
35
  }
36
36
  }
37
37
 
38
38
  // 操作按钮 - 回复
39
- function renderReply(ctx: RenderCtx) {
40
- if (!ctx.data.is_allow_reply) return // 不允许回复
39
+ function renderReply(r: Render) {
40
+ if (!r.data.is_allow_reply) return // 不允许回复
41
41
 
42
- const replyBtn = Utils.createElement(`<span>${ctx.ctx.$t('reply')}</span>`)
43
- ctx.$actions.append(replyBtn)
42
+ const replyBtn = Utils.createElement(`<span>${r.ctx.$t('reply')}</span>`)
43
+ r.$actions.append(replyBtn)
44
44
  replyBtn.addEventListener('click', (e) => {
45
45
  e.stopPropagation() // 防止穿透
46
- if (!ctx.cConf.onReplyBtnClick) {
47
- ctx.ctx.replyComment(ctx.data, ctx.$el)
46
+ if (!r.cConf.onReplyBtnClick) {
47
+ r.ctx.replyComment(r.data, r.$el)
48
48
  } else {
49
- ctx.cConf.onReplyBtnClick()
49
+ r.cConf.onReplyBtnClick()
50
50
  }
51
51
  })
52
52
  }
53
53
 
54
54
  // 操作按钮 - 折叠
55
- function renderCollapse(ctx: RenderCtx) {
56
- const collapseBtn = new ActionBtn(ctx.ctx, {
57
- text: () => (ctx.data.is_collapsed ? ctx.ctx.$t('expand') : ctx.ctx.$t('collapse')),
55
+ function renderCollapse(r: Render) {
56
+ const collapseBtn = new ActionBtn({
57
+ text: () => (r.data.is_collapsed ? r.ctx.$t('expand') : r.ctx.$t('collapse')),
58
58
  adminOnly: true
59
59
  })
60
- collapseBtn.appendTo(ctx.$actions)
60
+ collapseBtn.appendTo(r.$actions)
61
61
  collapseBtn.setClick(() => {
62
- ctx.comment.getActions().adminEdit('collapsed', collapseBtn)
62
+ r.comment.getActions().adminEdit('collapsed', collapseBtn)
63
63
  })
64
64
  }
65
65
 
66
66
  // 操作按钮 - 审核
67
- function renderModerator(ctx: RenderCtx) {
68
- const pendingBtn = new ActionBtn(ctx.ctx, {
69
- text: () => (ctx.data.is_pending ? ctx.ctx.$t('pending') : ctx.ctx.$t('approved')),
67
+ function renderModerator(r: Render) {
68
+ const pendingBtn = new ActionBtn({
69
+ text: () => (r.data.is_pending ? r.ctx.$t('pending') : r.ctx.$t('approved')),
70
70
  adminOnly: true
71
71
  })
72
- pendingBtn.appendTo(ctx.$actions)
72
+ pendingBtn.appendTo(r.$actions)
73
73
  pendingBtn.setClick(() => {
74
- ctx.comment.getActions().adminEdit('pending', pendingBtn)
74
+ r.comment.getActions().adminEdit('pending', pendingBtn)
75
75
  })
76
76
  }
77
77
 
78
78
  // 操作按钮 - 置顶
79
- function renderPin(ctx: RenderCtx) {
80
- const pinnedBtn = new ActionBtn(ctx.ctx, {
81
- text: () => (ctx.data.is_pinned ? ctx.ctx.$t('unpin') : ctx.ctx.$t('pin')),
79
+ function renderPin(r: Render) {
80
+ const pinnedBtn = new ActionBtn({
81
+ text: () => (r.data.is_pinned ? r.ctx.$t('unpin') : r.ctx.$t('pin')),
82
82
  adminOnly: true
83
83
  })
84
- pinnedBtn.appendTo(ctx.$actions)
84
+ pinnedBtn.appendTo(r.$actions)
85
85
  pinnedBtn.setClick(() => {
86
- ctx.comment.getActions().adminEdit('pinned', pinnedBtn)
86
+ r.comment.getActions().adminEdit('pinned', pinnedBtn)
87
87
  })
88
88
  }
89
89
 
90
90
  // 操作按钮 - 编辑
91
- function renderEdit(ctx: RenderCtx) {
92
- const editBtn = new ActionBtn(ctx.ctx, {
93
- text: ctx.ctx.$t('edit'),
91
+ function renderEdit(r: Render) {
92
+ const editBtn = new ActionBtn({
93
+ text: r.ctx.$t('edit'),
94
94
  adminOnly: true
95
95
  })
96
- editBtn.appendTo(ctx.$actions)
96
+ editBtn.appendTo(r.$actions)
97
97
  editBtn.setClick(() => {
98
- ctx.ctx.editComment(ctx.data, ctx.$el)
98
+ r.ctx.editComment(r.data, r.$el)
99
99
  })
100
100
  }
101
101
 
102
102
  // 操作按钮 - 删除
103
- function renderDel(ctx: RenderCtx) {
104
- const delBtn = new ActionBtn(ctx.ctx, {
105
- text: ctx.ctx.$t('delete'),
103
+ function renderDel(r: Render) {
104
+ const delBtn = new ActionBtn({
105
+ text: r.ctx.$t('delete'),
106
106
  confirm: true,
107
- confirmText: ctx.ctx.$t('deleteConfirm'),
107
+ confirmText: r.ctx.$t('deleteConfirm'),
108
108
  adminOnly: true,
109
109
  })
110
- delBtn.appendTo(ctx.$actions)
110
+ delBtn.appendTo(r.$actions)
111
111
  delBtn.setClick(() => {
112
- ctx.comment.getActions().adminDelete(delBtn)
112
+ r.comment.getActions().adminDelete(delBtn)
113
113
  })
114
114
  }
@@ -1,19 +1,19 @@
1
1
  import * as Utils from '../../lib/utils'
2
- import RenderCtx from '../render-ctx'
2
+ import type Render from '../render'
3
3
 
4
4
  /**
5
5
  * 评论头像界面
6
6
  */
7
- export default function renderAvatar(ctx: RenderCtx) {
8
- const $avatar = ctx.$el.querySelector<HTMLElement>('.atk-avatar')!
7
+ export default function renderAvatar(r: Render) {
8
+ const $avatar = r.$el.querySelector<HTMLElement>('.atk-avatar')!
9
9
  const $avatarImg = Utils.createElement<HTMLImageElement>('<img />')
10
10
 
11
- const avatarURLBuilder = ctx.conf.avatarURLBuilder
12
- $avatarImg.src = avatarURLBuilder ? avatarURLBuilder(ctx.data) : ctx.comment.getGravatarURL()
11
+ const avatarURLBuilder = r.conf.avatarURLBuilder
12
+ $avatarImg.src = avatarURLBuilder ? avatarURLBuilder(r.data) : r.comment.getGravatarURL()
13
13
 
14
- if (ctx.data.link) {
14
+ if (r.data.link) {
15
15
  const $avatarA = Utils.createElement<HTMLLinkElement>('<a target="_blank" rel="noreferrer noopener nofollow"></a>')
16
- $avatarA.href = Utils.isValidURL(ctx.data.link) ? ctx.data.link : `https://${ctx.data.link}`
16
+ $avatarA.href = Utils.isValidURL(r.data.link) ? r.data.link : `https://${r.data.link}`
17
17
  $avatarA.append($avatarImg)
18
18
  $avatar.append($avatarA)
19
19
  } else {
@@ -1,39 +1,39 @@
1
1
  import * as Utils from '../../lib/utils'
2
2
  import * as Ui from '../../lib/ui'
3
- import RenderCtx from '../render-ctx'
3
+ import type Render from '../render'
4
4
 
5
5
  /**
6
6
  * 评论内容界面
7
7
  */
8
- export default function renderContent(ctx: RenderCtx) {
9
- if (!ctx.data.is_collapsed) {
10
- ctx.$content.innerHTML = ctx.comment.getContentMarked()
11
- ctx.$content.classList.remove('atk-hide', 'atk-collapsed')
8
+ export default function renderContent(r: Render) {
9
+ if (!r.data.is_collapsed) {
10
+ r.$content.innerHTML = r.comment.getContentMarked()
11
+ r.$content.classList.remove('atk-hide', 'atk-collapsed')
12
12
  return
13
13
  }
14
14
 
15
15
  // 内容 & 折叠
16
- ctx.$content.classList.add('atk-hide', 'atk-type-collapsed')
16
+ r.$content.classList.add('atk-hide', 'atk-type-collapsed')
17
17
  const collapsedInfoEl = Utils.createElement(`
18
18
  <div class="atk-collapsed">
19
- <span class="atk-text">${ctx.ctx.$t('collapsedMsg')}</span>
20
- <span class="atk-show-btn">${ctx.ctx.$t('expand')}</span>
19
+ <span class="atk-text">${r.ctx.$t('collapsedMsg')}</span>
20
+ <span class="atk-show-btn">${r.ctx.$t('expand')}</span>
21
21
  </div>`)
22
- ctx.$body.insertAdjacentElement('beforeend', collapsedInfoEl)
22
+ r.$body.insertAdjacentElement('beforeend', collapsedInfoEl)
23
23
 
24
- const contentShowBtn = collapsedInfoEl.querySelector('.atk-show-btn')!
24
+ const contentShowBtn = collapsedInfoEl.querySelector<HTMLElement>('.atk-show-btn')!
25
25
  contentShowBtn.addEventListener('click', (e) => {
26
26
  e.stopPropagation() // 防止穿透
27
27
 
28
- if (ctx.$content.classList.contains('atk-hide')) {
29
- ctx.$content.innerHTML = ctx.comment.getContentMarked()
30
- ctx.$content.classList.remove('atk-hide')
31
- Ui.playFadeInAnim(ctx.$content)
32
- contentShowBtn.innerHTML = ctx.ctx.$t('collapse')
28
+ if (r.$content.classList.contains('atk-hide')) {
29
+ r.$content.innerHTML = r.comment.getContentMarked()
30
+ r.$content.classList.remove('atk-hide')
31
+ Ui.playFadeInAnim(r.$content)
32
+ contentShowBtn.innerText = r.ctx.$t('collapse')
33
33
  } else {
34
- ctx.$content.innerHTML = ''
35
- ctx.$content.classList.add('atk-hide')
36
- contentShowBtn.innerHTML = ctx.ctx.$t('expand')
34
+ r.$content.innerHTML = ''
35
+ r.$content.classList.add('atk-hide')
36
+ contentShowBtn.innerText = r.ctx.$t('expand')
37
37
  }
38
38
  })
39
39
  }
@@ -1,31 +1,31 @@
1
1
  import * as Utils from '../../lib/utils'
2
- import RenderCtx from '../render-ctx'
2
+ import type Render from '../render'
3
3
 
4
4
  /**
5
5
  * 评论头部界面
6
6
  */
7
- export default function renderHeader(ctx: RenderCtx) {
7
+ export default function renderHeader(r: Render) {
8
8
  Object.entries({
9
9
  renderNick, renderVerifyBadge, renderDate, renderUABadge
10
10
  }).forEach(([name, render]) => {
11
- render(ctx)
11
+ render(r)
12
12
  })
13
13
  }
14
14
 
15
- function renderNick(ctx: RenderCtx) {
16
- ctx.$headerNick = ctx.$el.querySelector<HTMLElement>('.atk-nick')!
15
+ function renderNick(r: Render) {
16
+ r.$headerNick = r.$el.querySelector<HTMLElement>('.atk-nick')!
17
17
 
18
- if (ctx.data.link) {
18
+ if (r.data.link) {
19
19
  const $nickA = Utils.createElement<HTMLLinkElement>('<a target="_blank" rel="noreferrer noopener nofollow"></a>')
20
- $nickA.innerText = ctx.data.nick
21
- $nickA.href = Utils.isValidURL(ctx.data.link) ? ctx.data.link : `https://${ctx.data.link}`
22
- ctx.$headerNick.append($nickA)
20
+ $nickA.innerText = r.data.nick
21
+ $nickA.href = Utils.isValidURL(r.data.link) ? r.data.link : `https://${r.data.link}`
22
+ r.$headerNick.append($nickA)
23
23
  } else {
24
- ctx.$headerNick.innerText = ctx.data.nick
24
+ r.$headerNick.innerText = r.data.nick
25
25
  }
26
26
  }
27
27
 
28
- function renderVerifyBadge(ctx: RenderCtx) {
28
+ function renderVerifyBadge(ctx: Render) {
29
29
  ctx.$headerBadgeWrap = ctx.$el.querySelector<HTMLElement>('.atk-badge-wrap')!
30
30
  ctx.$headerBadgeWrap.innerHTML = ''
31
31
 
@@ -44,13 +44,13 @@ function renderVerifyBadge(ctx: RenderCtx) {
44
44
  }
45
45
  }
46
46
 
47
- function renderDate(ctx: RenderCtx) {
47
+ function renderDate(ctx: Render) {
48
48
  const $date = ctx.$el.querySelector<HTMLElement>('.atk-date')!
49
49
  $date.innerText = ctx.comment.getDateFormatted()
50
50
  $date.setAttribute('data-atk-comment-date', String(+new Date(ctx.data.date)))
51
51
  }
52
52
 
53
- function renderUABadge(ctx: RenderCtx) {
53
+ function renderUABadge(ctx: Render) {
54
54
  if (!ctx.ctx.conf.uaBadge && !ctx.data.ip_region) return
55
55
 
56
56
  let $uaWrap = ctx.$header.querySelector('atk-ua-wrap')
@@ -1,4 +1,4 @@
1
- import RenderCtx from '../render-ctx'
1
+ import type Render from '../render'
2
2
  import Avatar from './avatar'
3
3
  import Header from './header'
4
4
  import Content from './content'
@@ -12,8 +12,8 @@ const Renders = {
12
12
  ReplyTo, Pending, Actions
13
13
  }
14
14
 
15
- export default function loadRenders(ctx: RenderCtx) {
15
+ export default function loadRenders(r: Render) {
16
16
  Object.entries(Renders).forEach(([ name, render ]) => {
17
- render(ctx)
17
+ render(r)
18
18
  })
19
19
  }
@@ -1,12 +1,12 @@
1
1
  import * as Utils from '../../lib/utils'
2
- import RenderCtx from '../render-ctx'
2
+ import type Render from '../render'
3
3
 
4
4
  /**
5
5
  * 待审核状态界面
6
6
  */
7
- export default function renderPending(ctx: RenderCtx) {
8
- if (!ctx.data.is_pending) return
7
+ export default function renderPending(r: Render) {
8
+ if (!r.data.is_pending) return
9
9
 
10
- const pendingEl = Utils.createElement(`<div class="atk-pending">${ctx.ctx.$t('pendingMsg')}</div>`)
11
- ctx.$body.prepend(pendingEl)
10
+ const pendingEl = Utils.createElement(`<div class="atk-pending">${r.ctx.$t('pendingMsg')}</div>`)
11
+ r.$body.prepend(pendingEl)
12
12
  }
@@ -1,16 +1,16 @@
1
1
  import * as Utils from '../../lib/utils'
2
- import RenderCtx from '../render-ctx'
2
+ import type Render from '../render'
3
3
 
4
4
  /**
5
5
  * 层级嵌套模式显示 AT 界面
6
6
  */
7
- export default function renderReplyAt(ctx: RenderCtx) {
8
- if (ctx.cConf.isFlatMode || ctx.data.rid === 0) return // not 平铺模式 或 根评论
9
- if (!ctx.cConf.replyTo) return
7
+ export default function renderReplyAt(r: Render) {
8
+ if (r.cConf.isFlatMode || r.data.rid === 0) return // not 平铺模式 或 根评论
9
+ if (!r.cConf.replyTo) return
10
10
 
11
- ctx.$replyAt = Utils.createElement(`<span class="atk-item atk-reply-at"><span class="atk-arrow"></span><span class="atk-nick"></span></span>`)
12
- ctx.$replyAt.querySelector<HTMLElement>('.atk-nick')!.innerText = `${ctx.cConf.replyTo.nick}`
13
- ctx.$replyAt.onclick = () => { ctx.comment.getActions().goToReplyComment() }
11
+ r.$replyAt = Utils.createElement(`<span class="atk-item atk-reply-at"><span class="atk-arrow"></span><span class="atk-nick"></span></span>`)
12
+ r.$replyAt.querySelector<HTMLElement>('.atk-nick')!.innerText = `${r.cConf.replyTo.nick}`
13
+ r.$replyAt.onclick = () => { r.comment.getActions().goToReplyComment() }
14
14
 
15
- ctx.$headerBadgeWrap.insertAdjacentElement('afterend', ctx.$replyAt)
15
+ r.$headerBadgeWrap.insertAdjacentElement('afterend', r.$replyAt)
16
16
  }
@@ -1,24 +1,24 @@
1
1
  import * as Utils from '../../lib/utils'
2
2
  import marked from '../../lib/marked'
3
- import RenderCtx from '../render-ctx'
3
+ import type Render from '../render'
4
4
 
5
5
  /**
6
6
  * 回复的对象界面
7
7
  */
8
- export default function renderReplyTo(ctx: RenderCtx) {
9
- if (!ctx.cConf.isFlatMode) return // 仅平铺模式显示
10
- if (!ctx.cConf.replyTo) return
8
+ export default function renderReplyTo(r: Render) {
9
+ if (!r.cConf.isFlatMode) return // 仅平铺模式显示
10
+ if (!r.cConf.replyTo) return
11
11
 
12
- ctx.$replyTo = Utils.createElement(`
12
+ r.$replyTo = Utils.createElement(`
13
13
  <div class="atk-reply-to">
14
- <div class="atk-meta">${ctx.ctx.$t('reply')} <span class="atk-nick"></span>:</div>
14
+ <div class="atk-meta">${r.ctx.$t('reply')} <span class="atk-nick"></span>:</div>
15
15
  <div class="atk-content"></div>
16
16
  </div>`)
17
- const $nick = ctx.$replyTo.querySelector<HTMLElement>('.atk-nick')!
18
- $nick.innerText = `@${ctx.cConf.replyTo.nick}`
19
- $nick.onclick = () => { ctx.comment.getActions().goToReplyComment() }
20
- let replyContent = marked(ctx.ctx, ctx.cConf.replyTo.content)
21
- if (ctx.cConf.replyTo.is_collapsed) replyContent = `[${ctx.ctx.$t('collapsed')}]`
22
- ctx.$replyTo.querySelector<HTMLElement>('.atk-content')!.innerHTML = replyContent
23
- ctx.$body.prepend(ctx.$replyTo)
17
+ const $nick = r.$replyTo.querySelector<HTMLElement>('.atk-nick')!
18
+ $nick.innerText = `@${r.cConf.replyTo.nick}`
19
+ $nick.onclick = () => { r.comment.getActions().goToReplyComment() }
20
+ let replyContent = marked(r.cConf.replyTo.content)
21
+ if (r.cConf.replyTo.is_collapsed) replyContent = `[${Utils.htmlEncode(r.ctx.$t('collapsed'))}]`
22
+ r.$replyTo.querySelector<HTMLElement>('.atk-content')!.innerHTML = replyContent
23
+ r.$body.prepend(r.$replyTo)
24
24
  }
@@ -1,7 +1,7 @@
1
- import Context from '~/types/context'
1
+ import $t from '@/i18n'
2
2
  import * as Utils from '../lib/utils'
3
3
 
4
- interface ActionBtnConf {
4
+ interface ActionBtnOptions {
5
5
  /** 按钮文字 (动态/静态) */
6
6
  text: (() => string) | string
7
7
 
@@ -19,8 +19,7 @@ interface ActionBtnConf {
19
19
  * 通用操作按钮
20
20
  */
21
21
  export default class ActionBtn {
22
- private ctx: Context
23
- private conf: ActionBtnConf
22
+ private opts: ActionBtnOptions
24
23
  public $el: HTMLElement
25
24
 
26
25
  public isLoading = false // 正在加载
@@ -33,15 +32,14 @@ export default class ActionBtn {
33
32
  public confirmRecTimer?: number // 确认消息复原定时器
34
33
 
35
34
  /** 构造函数 */
36
- constructor(ctx: Context, conf: ActionBtnConf|string|(() => string)) {
37
- this.ctx = ctx
35
+ constructor(opts: ActionBtnOptions|string|(() => string)) {
38
36
  this.$el = Utils.createElement(`<span class="atk-common-action-btn"></span>`)
39
37
 
40
- this.conf = (typeof conf !== 'object') ? ({ text: conf }) : conf
38
+ this.opts = (typeof opts !== 'object') ? ({ text: opts }) : opts
41
39
  this.$el.innerText = this.getText()
42
40
 
43
41
  // 仅管理员可操作
44
- if (this.conf.adminOnly) this.$el.setAttribute('atk-only-admin-show', '')
42
+ if (this.opts.adminOnly) this.$el.setAttribute('atk-only-admin-show', '')
45
43
  }
46
44
 
47
45
  /** 将按钮装载到指定元素 */
@@ -52,7 +50,7 @@ export default class ActionBtn {
52
50
 
53
51
  /** 获取按钮文字(动态/静态) */
54
52
  private getText() {
55
- return (typeof this.conf.text === 'string') ? this.conf.text : this.conf.text()
53
+ return (typeof this.opts.text === 'string') ? this.opts.text : this.opts.text()
56
54
  }
57
55
 
58
56
  /** 设置点击事件 */
@@ -66,7 +64,7 @@ export default class ActionBtn {
66
64
  }
67
65
 
68
66
  // 操作确认
69
- if (this.conf.confirm && !this.isMessaging) {
67
+ if (this.opts.confirm && !this.isMessaging) {
70
68
  const confirmRestore = () => {
71
69
  this.isConfirming = false
72
70
  this.$el.classList.remove('atk-btn-confirm')
@@ -76,7 +74,7 @@ export default class ActionBtn {
76
74
  if (!this.isConfirming) {
77
75
  this.isConfirming = true
78
76
  this.$el.classList.add('atk-btn-confirm')
79
- this.$el.innerText = this.conf.confirmText || this.ctx.$t('actionConfirm')
77
+ this.$el.innerText = this.opts.confirmText || $t('actionConfirm')
80
78
  this.confirmRecTimer = window.setTimeout(() => confirmRestore(), 5000)
81
79
  return
82
80
  }
@@ -99,7 +97,7 @@ export default class ActionBtn {
99
97
 
100
98
  /** 文字刷新(动态/静态) */
101
99
  public updateText(text?: (() => string) | string) {
102
- if (text) this.conf.text = text
100
+ if (text) this.opts.text = text
103
101
  this.setLoading(false)
104
102
  this.$el.innerText = this.getText()
105
103
  }
@@ -110,7 +108,7 @@ export default class ActionBtn {
110
108
  this.isLoading = value
111
109
  if (value) {
112
110
  this.$el.classList.add('atk-btn-loading')
113
- this.$el.innerText = loadingText || `${this.ctx.$t('loading')}...`
111
+ this.$el.innerText = loadingText || `${$t('loading')}...`
114
112
  } else {
115
113
  this.$el.classList.remove('atk-btn-loading')
116
114
  this.$el.innerText = this.getText()
@@ -1,6 +1,7 @@
1
- import * as Utils from '../utils'
2
- import User from '../user'
3
- import { Checker } from '.'
1
+ import $t from '@/i18n'
2
+ import * as Utils from '@/lib/utils'
3
+ import User from '@/lib/user'
4
+ import type { Checker } from '.'
4
5
 
5
6
  const AdminChecker: Checker = {
6
7
  inputType: 'password',
@@ -19,7 +20,7 @@ const AdminChecker: Checker = {
19
20
  },
20
21
 
21
22
  body(checker) {
22
- return Utils.createElement(`<span>${checker.getCtx().$t('adminCheck')}</span>`)
23
+ return Utils.createElement(`<span>${$t('adminCheck')}</span>`)
23
24
  },
24
25
 
25
26
  onSuccess(checker, userToken, inputVal, formEl) {
@@ -27,8 +28,7 @@ const AdminChecker: Checker = {
27
28
  isAdmin: true,
28
29
  token: userToken
29
30
  })
30
- checker.getCtx().trigger('user-changed', User.data)
31
- checker.getCtx().listReload()
31
+ checker.getOpts().onReload()
32
32
  },
33
33
 
34
34
  onError(checker, err, inputVal, formEl) {}
@@ -1,12 +1,13 @@
1
- import * as Utils from '../utils'
2
- import * as Ui from '../ui'
3
- import { CheckerCtx } from '.'
1
+ import $t from '@/i18n'
2
+ import * as Utils from '@/lib/utils'
3
+ import * as Ui from '@/lib/ui'
4
+ import type { CheckerCtx } from '.'
4
5
 
5
6
  /** 图片验证码 */
6
7
  export function imgBody(checker: CheckerCtx) {
7
8
  // 图片验证方式
8
9
  const elem = Utils.createElement(
9
- `<span><img class="atk-captcha-img" src="${checker.get('img_data') || ''}">${checker.getCtx().$t('captchaCheck')}</span>`
10
+ `<span><img class="atk-captcha-img" src="${checker.get('img_data') || ''}">${$t('captchaCheck')}</span>`
10
11
  );
11
12
 
12
13
  // 刷新验证码
@@ -29,7 +30,7 @@ export function iframeBody(checker: CheckerCtx) {
29
30
  const $iframe = Utils.createElement<HTMLIFrameElement>(`<iframe class="atk-fade-in"></iframe>`)
30
31
  $iframe.style.display = 'none'
31
32
  Ui.showLoading($iframeWrap, { transparentBg: true })
32
- $iframe.src = `${checker.getCtx().conf.server}/api/captcha/get?t=${+new Date()}`
33
+ $iframe.src = `${checker.getOpts().getIframeURLBase() || ''}/api/captcha/get?t=${+new Date()}`
33
34
  $iframe.onload = () => {
34
35
  $iframe.style.display = ''
35
36
  Ui.hideLoading($iframeWrap)
@@ -49,7 +50,7 @@ export function iframeBody(checker: CheckerCtx) {
49
50
  if (stop) return
50
51
  let isPass = false
51
52
  try {
52
- const resp = await checker.getCtx().getApi().captcha.captchaStatus()
53
+ const resp = await checker.getApi().captcha.captchaStatus()
53
54
  isPass = resp.is_pass
54
55
  } catch { isPass = false }
55
56
  if (isPass) {
@@ -1,5 +1,5 @@
1
1
 
2
- import { Checker } from '.'
2
+ import type { Checker } from '.'
3
3
  import * as render from './captcha-renders'
4
4
 
5
5
  const CaptchaChecker: Checker = {