artalk 2.3.4 → 2.4.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 (98) hide show
  1. package/dist/Artalk.css +1 -1
  2. package/dist/Artalk.es.js +3171 -3008
  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 +3124 -2980
  7. package/dist/ArtalkLite.iife.js +1 -1
  8. package/dist/ArtalkLite.js +1 -1
  9. package/dist/src/api/admin.d.ts +10 -0
  10. package/dist/src/api/api-base.d.ts +14 -0
  11. package/dist/src/api/captcha.d.ts +14 -0
  12. package/dist/src/api/comment.d.ts +29 -0
  13. package/dist/src/api/index.d.ts +31 -0
  14. package/dist/src/api/page.d.ts +22 -0
  15. package/dist/src/api/request.d.ts +12 -0
  16. package/dist/src/api/site.d.ts +17 -0
  17. package/dist/src/api/system.d.ts +13 -0
  18. package/dist/src/api/upload.d.ts +11 -0
  19. package/dist/src/api/user.d.ts +28 -0
  20. package/dist/src/artalk.d.ts +58 -0
  21. package/dist/src/comment/actions.d.ts +17 -0
  22. package/dist/src/comment/comment.d.ts +67 -0
  23. package/dist/src/comment/index.d.ts +2 -0
  24. package/dist/src/comment/render.d.ts +76 -0
  25. package/dist/src/components/action-btn.d.ts +52 -0
  26. package/dist/src/components/dialog.d.ts +18 -0
  27. package/dist/src/components/pagination.d.ts +30 -0
  28. package/dist/src/components/read-more-btn.d.ts +33 -0
  29. package/dist/src/context.d.ts +72 -0
  30. package/dist/src/defaults.d.ts +3 -0
  31. package/dist/src/editor/editor.d.ts +84 -0
  32. package/dist/src/editor/index.d.ts +2 -0
  33. package/dist/src/editor/plugs/editor-plug.d.ts +26 -0
  34. package/dist/src/editor/plugs/emoticons-plug.d.ts +36 -0
  35. package/dist/src/editor/plugs/header-input-plug.d.ts +13 -0
  36. package/dist/src/editor/plugs/preview-plug.d.ts +10 -0
  37. package/dist/src/editor/plugs/upload-plug.d.ts +10 -0
  38. package/dist/src/i18n/en.d.ts +69 -0
  39. package/dist/src/i18n/index.d.ts +294 -0
  40. package/dist/src/i18n/zh-CN.d.ts +3 -0
  41. package/dist/src/layer/index.d.ts +3 -0
  42. package/dist/src/layer/layer.d.ts +32 -0
  43. package/dist/src/layer/sidebar-layer.d.ts +20 -0
  44. package/dist/src/lib/checker/admin-checker.d.ts +3 -0
  45. package/dist/src/lib/checker/captcha-checker.d.ts +3 -0
  46. package/dist/src/lib/checker/index.d.ts +42 -0
  47. package/dist/src/lib/component.d.ts +12 -0
  48. package/dist/src/lib/detect.d.ts +10 -0
  49. package/dist/src/lib/stat.d.ts +15 -0
  50. package/dist/src/lib/ui.d.ts +23 -0
  51. package/dist/src/lib/user.d.ts +13 -0
  52. package/dist/src/lib/utils.d.ts +39 -0
  53. package/dist/src/list/index.d.ts +2 -0
  54. package/dist/src/list/list-lite.d.ts +63 -0
  55. package/dist/src/list/list-nest.d.ts +10 -0
  56. package/dist/src/list/list.d.ts +26 -0
  57. package/dist/src/main.d.ts +2 -0
  58. package/dist/types/artalk-config.d.ts +132 -0
  59. package/dist/types/artalk-data.d.ts +204 -0
  60. package/dist/types/context.d.ts +146 -0
  61. package/dist/types/event.d.ts +28 -0
  62. package/dist/types/global.d.ts +0 -0
  63. package/dist/types/plug.d.ts +4 -0
  64. package/index.html +3 -3
  65. package/package.json +5 -5
  66. package/src/api/admin.ts +18 -0
  67. package/src/api/api-base.ts +27 -0
  68. package/src/api/captcha.ts +24 -0
  69. package/src/api/comment.ts +84 -0
  70. package/src/api/index.ts +25 -366
  71. package/src/api/page.ts +85 -0
  72. package/src/api/site.ts +51 -0
  73. package/src/api/system.ts +39 -0
  74. package/src/api/upload.ts +29 -0
  75. package/src/api/user.ts +75 -0
  76. package/src/artalk.ts +52 -46
  77. package/src/comment/actions.ts +3 -3
  78. package/src/comment/comment.ts +6 -9
  79. package/src/comment/render.ts +76 -40
  80. package/src/components/pagination.ts +0 -1
  81. package/src/context.ts +31 -31
  82. package/src/editor/editor.ts +2 -4
  83. package/src/editor/plugs/header-input-plug.ts +1 -1
  84. package/src/editor/plugs/upload-plug.ts +1 -1
  85. package/src/i18n/index.ts +117 -2
  86. package/src/layer/sidebar-layer.ts +1 -3
  87. package/src/lib/checker/admin-checker.ts +1 -1
  88. package/src/lib/checker/captcha-checker.ts +3 -3
  89. package/src/lib/stat.ts +2 -2
  90. package/src/lib/ui.ts +6 -0
  91. package/src/list/list-lite.ts +25 -25
  92. package/src/list/list.ts +3 -4
  93. package/src/style/main.less +6 -0
  94. package/types/context.d.ts +4 -1
  95. package/types/global.d.ts +0 -2
  96. package/vite-base.config.ts +9 -5
  97. package/vite.config.ts +1 -1
  98. package/types/index.d.ts +0 -3
@@ -7,7 +7,7 @@ import Comment from '../comment'
7
7
  import Pagination from '../components/pagination'
8
8
  import ReadMoreBtn from '../components/read-more-btn'
9
9
  import * as ListNest from './list-nest'
10
- import { backendMinVersion } from '../../package.json'
10
+ import { backendMinVersion, version as ARTALK_VERSION } from '../../package.json'
11
11
 
12
12
  export default class ListLite extends Component {
13
13
  protected $commentsWrap: HTMLElement
@@ -78,40 +78,42 @@ export default class ListLite extends Component {
78
78
  return this.$commentsWrap
79
79
  }
80
80
 
81
+ /** 加载动画 */
82
+ public setLoading(val: boolean, isFirstLoad: boolean = false) {
83
+ this.isLoading = val
84
+ if (isFirstLoad) Ui.setLoading(val, this.$el)
85
+ else if (this.pageMode === 'read-more') this.readMoreBtn!.setLoading(val)
86
+ else if (this.pageMode === 'pagination') this.pagination!.setLoading(val)
87
+ }
88
+
81
89
  /** 评论获取 */
82
90
  public async fetchComments(offset: number) {
83
91
  if (this.isLoading) return
84
92
 
93
+ const isFirstLoad = (offset === 0)
94
+ const setLoading = (val: boolean) => this.setLoading(val, isFirstLoad)
95
+
85
96
  // 加载动画
86
- const showLoading = () => {
87
- this.isLoading = true
88
- if (offset === 0) Ui.showLoading(this.$el)
89
- else if (this.pageMode === 'read-more') this.readMoreBtn!.setLoading(true)
90
- else if (this.pageMode === 'pagination') this.pagination!.setLoading(true)
91
- }
92
- const hideLoading = () => {
93
- this.isLoading = false
94
- if (offset === 0) Ui.hideLoading(this.$el)
95
- else if (this.pageMode === 'read-more') this.readMoreBtn!.setLoading(false)
96
- else if (this.pageMode === 'pagination') this.pagination!.setLoading(false)
97
- }
98
- showLoading()
97
+ setLoading(true)
99
98
 
100
99
  // 事件通知(开始加载评论)
101
100
  this.ctx.trigger('list-load')
102
101
 
103
102
  // 清空评论(加载按钮)
104
- if (this.pageMode === 'read-more' && offset === 0) { this.ctx.clearAllComments() }
103
+ if (isFirstLoad && this.pageMode === 'read-more') {
104
+ this.ctx.clearAllComments()
105
+ }
105
106
 
106
107
  // 请求评论数据
107
108
  let listData: ListData
108
109
  try {
109
- listData = await this.ctx.getApi().get(offset, this.pageSize, this.flatMode, this.paramsEditor)
110
+ listData = await this.ctx.getApi().comment
111
+ .get(offset, this.pageSize, this.flatMode, this.paramsEditor)
110
112
  } catch (e: any) {
111
113
  this.onError(e.msg || String(e), offset, e.data)
112
114
  throw e
113
115
  } finally {
114
- hideLoading()
116
+ setLoading(false)
115
117
  }
116
118
 
117
119
  // 清除原有错误
@@ -124,7 +126,7 @@ export default class ListLite extends Component {
124
126
  this.onError(String(e), offset)
125
127
  throw e
126
128
  } finally {
127
- hideLoading()
129
+ setLoading(false)
128
130
  }
129
131
  }
130
132
 
@@ -194,15 +196,13 @@ export default class ListLite extends Component {
194
196
  const at = this.scrollListenerAt || document
195
197
  if (this.autoLoadScrollEvent) at.removeEventListener('scroll', this.autoLoadScrollEvent) // 解除原有
196
198
  this.autoLoadScrollEvent = () => {
197
- if (this.pageMode !== 'read-more') return
198
- if (!this.readMoreBtn) return
199
-
200
- if (!this.readMoreBtn.hasMore) return
201
- if (this.isLoading) return
199
+ if (this.pageMode !== 'read-more'
200
+ || !this.readMoreBtn?.hasMore
201
+ || this.isLoading
202
+ ) return
202
203
 
203
204
  const $target = this.$el.querySelector<HTMLElement>('.atk-list-comments-wrap > .atk-comment-wrap:nth-last-child(3)') // 获取倒数第3个评论元素
204
- if (!$target) return
205
- if (Ui.isVisible($target, this.scrollListenerAt)) {
205
+ if ($target && Ui.isVisible($target, this.scrollListenerAt)) {
206
206
  this.readMoreBtn.click() // 自动点击加载更多按钮
207
207
  }
208
208
  }
package/src/list/list.ts CHANGED
@@ -1,7 +1,6 @@
1
- import '../style/list.less'
2
-
3
1
  import { ListData, NotifyData } from '~/types/artalk-data'
4
2
  import Context from '~/types/context'
3
+ import { version as ARTALK_VERSION } from '../../package.json'
5
4
  import * as Utils from '../lib/utils'
6
5
  import * as Ui from '../lib/ui'
7
6
  import ListHTML from './list.html?raw'
@@ -143,7 +142,7 @@ export default class List extends ListLite {
143
142
  // 已阅 API
144
143
  const notifyKey = Utils.getQueryParam('atk_notify_key')
145
144
  if (notifyKey) {
146
- this.ctx.getApi().markRead(notifyKey)
145
+ this.ctx.getApi().user.markRead(notifyKey)
147
146
  .then(() => {
148
147
  this.unread = this.unread.filter(o => o.comment_id !== commentId)
149
148
  this.updateUnread(this.unread)
@@ -175,7 +174,7 @@ export default class List extends ListLite {
175
174
  if (!this.data || !this.data.page) return
176
175
 
177
176
  this.ctx.editorShowLoading()
178
- this.ctx.getApi().pageEdit(this.data.page)
177
+ this.ctx.getApi().page.pageEdit(this.data.page)
179
178
  .then((page) => {
180
179
  if (this.data)
181
180
  this.data.page = { ...page }
@@ -1,4 +1,9 @@
1
1
  @import "./_color.less";
2
+ @import './comment.less';
3
+ @import './list.less';
4
+ @import './pagination.less';
5
+ @import './editor.less';
6
+ @import './sidebar-layer.less';
2
7
 
3
8
  .artalk {
4
9
  position: relative;
@@ -460,4 +465,5 @@ i.atk-icon {
460
465
 
461
466
  img[atk-emoticon] {
462
467
  max-height: 60px;
468
+ display: initial;
463
469
  }
@@ -38,7 +38,7 @@ export default interface ContextApi {
38
38
  /* 设置持有的同事类 (中介者模式) */
39
39
  setApi(api: Api): void
40
40
  setEditor(editor: Editor): void
41
- setList(list: ListLite): void
41
+ setList(list?: ListLite): void
42
42
  setSidebarLayer(list: SidebarLayer): void
43
43
  setCheckerLauncher(checkerLauncher: CheckerLauncher): void
44
44
 
@@ -90,6 +90,9 @@ export default interface ContextApi {
90
90
  /** 列表 - UI 更新 */
91
91
  listRefreshUI(): void
92
92
 
93
+ /** 列表 - HashGoto 功能检测 */
94
+ listHashGotoCheck(): void
95
+
93
96
  /** 显示侧边栏 */
94
97
  showSidebar(payload?: SidebarShowPayload): void
95
98
 
package/types/global.d.ts CHANGED
@@ -1,2 +0,0 @@
1
- declare const ARTALK_VERSION: string
2
- declare const ARTALK_LITE: boolean
@@ -1,11 +1,9 @@
1
1
  import { defineConfig } from 'vite'
2
2
  import tsconfigPaths from 'vite-tsconfig-paths'
3
- import { version } from './package.json'
3
+ import { resolve } from 'path'
4
+ import dts from 'vite-plugin-dts'
4
5
 
5
6
  export default defineConfig({
6
- define: {
7
- ARTALK_VERSION: JSON.stringify(version),
8
- },
9
7
  css: {
10
8
  preprocessorOptions: {
11
9
  less: {
@@ -13,5 +11,11 @@ export default defineConfig({
13
11
  },
14
12
  },
15
13
  },
16
- plugins: [tsconfigPaths()],
14
+ resolve: {
15
+ alias: {
16
+ '@': resolve(__dirname, 'src'),
17
+ '~': resolve(__dirname),
18
+ }
19
+ },
20
+ plugins: [tsconfigPaths(), dts()],
17
21
  })
package/vite.config.ts CHANGED
@@ -17,7 +17,7 @@ export default Utils.mergeDeep(baseConf, defineConfig({
17
17
  },
18
18
  rollupOptions: {
19
19
  output: {
20
- assetFileNames: (assetInfo) => (/\.css$/.test(assetInfo.name) ? "Artalk.css" : "[name].[ext]")
20
+ assetFileNames: (assetInfo) => (/\.css$/.test(assetInfo.name || '') ? "Artalk.css" : "[name].[ext]"),
21
21
  }
22
22
  }
23
23
  },
package/types/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import Artalk from '../src/artalk'
2
-
3
- export default Artalk