artalk 2.0.4 → 2.1.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 (91) hide show
  1. package/README.md +7 -60
  2. package/dist/Artalk.css +1 -1
  3. package/dist/Artalk.es.js +5996 -1
  4. package/dist/Artalk.iife.js +266 -1
  5. package/dist/Artalk.js +266 -1
  6. package/package.json +3 -4
  7. package/src/api/index.ts +269 -0
  8. package/src/api/request.ts +125 -0
  9. package/src/artalk.ts +153 -0
  10. package/src/components/_component.ts.txt +10 -0
  11. package/src/components/action-btn.ts +169 -0
  12. package/src/components/admin/page-list.ts +194 -0
  13. package/src/components/admin/site-list-floater.ts +98 -0
  14. package/src/components/admin/site-list.ts +289 -0
  15. package/src/components/comment.ts +478 -0
  16. package/src/components/dialog.ts +63 -0
  17. package/src/components/editor-plugs/{_ExamplePlug.ts.txt → _example-plug.ts.txt} +0 -0
  18. package/src/components/editor-plugs/{EditorPlug.ts → editor-plug.ts} +3 -3
  19. package/src/components/editor-plugs/{EmoticonsPlug.less → emoticons-plug.less} +0 -0
  20. package/src/components/editor-plugs/{EmoticonsPlug.ts → emoticons-plug.ts} +9 -9
  21. package/src/components/editor-plugs/{PreviewPlug.less → preview-plug.less} +0 -0
  22. package/src/components/editor-plugs/{PreviewPlug.ts → preview-plug.ts} +10 -10
  23. package/src/components/{Editor.ts → editor.ts} +104 -102
  24. package/src/components/html/comment.html +2 -6
  25. package/src/components/html/list.html +0 -1
  26. package/src/components/html/sidebar.html +18 -4
  27. package/src/components/item-text-editor.ts +136 -0
  28. package/src/components/layer.ts +135 -0
  29. package/src/components/list-lite.ts +507 -0
  30. package/src/components/list.ts +172 -0
  31. package/src/components/pagination.ts +150 -0
  32. package/src/components/read-more-btn.ts +71 -0
  33. package/src/components/sidebar-view.ts +26 -0
  34. package/src/components/sidebar-views/comments-view.ts +66 -0
  35. package/src/components/sidebar-views/pages-view.ts +61 -0
  36. package/src/components/sidebar-views/setting-view.ts +21 -0
  37. package/src/components/sidebar-views/sites-view.ts +42 -0
  38. package/src/components/sidebar-views/transfer-view.ts +218 -0
  39. package/src/components/sidebar.ts +288 -0
  40. package/src/context.ts +42 -0
  41. package/src/default-conf.ts +42 -0
  42. package/src/lib/checker/admin-checker.ts +33 -0
  43. package/src/lib/checker/captcha-checker.ts +38 -0
  44. package/src/lib/checker/index.ts +134 -0
  45. package/src/lib/component.ts +3 -3
  46. package/src/lib/md5.js +6 -0
  47. package/src/lib/ui.ts +64 -74
  48. package/src/lib/user.ts +2 -8
  49. package/src/lib/utils.ts +30 -11
  50. package/src/main.ts +1 -1
  51. package/src/style/_color.less +8 -2
  52. package/src/style/_extend.less +81 -0
  53. package/src/style/_variables.less +3 -0
  54. package/src/style/comment.less +60 -24
  55. package/src/style/editor.less +3 -0
  56. package/src/style/item-text-editor.less +35 -0
  57. package/src/style/list.less +51 -32
  58. package/src/style/main.less +75 -1
  59. package/src/style/page-list.less +50 -0
  60. package/src/style/pagination.less +58 -0
  61. package/src/style/sidebar.less +274 -199
  62. package/src/style/site-list.less +208 -0
  63. package/tsconfig.json +27 -0
  64. package/types/artalk-config.d.ts +68 -51
  65. package/types/artalk-data.d.ts +38 -1
  66. package/types/event.d.ts +73 -0
  67. package/types/index.d.ts +1 -6
  68. package/.github/workflows/npm.yml +0 -31
  69. package/.github/workflows/pages.yml +0 -30
  70. package/dist/src/Event.d.ts +0 -59
  71. package/dist/types/artalk-config.d.ts +0 -79
  72. package/dist/types/artalk-data.d.ts +0 -153
  73. package/dist/types/global.d.ts +0 -1
  74. package/dist/types/index.d.ts +0 -8
  75. package/dist/types/vite-env.d.ts +0 -1
  76. package/example/pjax/res1.html +0 -41
  77. package/example/pjax/res2.html +0 -41
  78. package/src/Artalk.ts +0 -160
  79. package/src/Constant.ts +0 -6
  80. package/src/Context.ts +0 -34
  81. package/src/Event.d.ts +0 -59
  82. package/src/components/Comment.ts +0 -402
  83. package/src/components/Layer.ts +0 -138
  84. package/src/components/List.ts +0 -162
  85. package/src/components/ListLite.ts +0 -407
  86. package/src/components/Sidebar.ts +0 -141
  87. package/src/components/sidebar-views/AdminView.ts +0 -523
  88. package/src/components/sidebar-views/MessageView.ts +0 -48
  89. package/src/components/sidebar-views/SidebarView.ts +0 -24
  90. package/src/lib/api.ts +0 -380
  91. package/src/lib/checker.ts +0 -164
@@ -1,79 +0,0 @@
1
- export interface ArtalkConfig {
2
- /**
3
- * 装载元素
4
- */
5
- el: string
6
-
7
- /**
8
- * 评论框占位字符
9
- */
10
- placeholder?: string
11
-
12
- /**
13
- * 评论为空时显示字符
14
- */
15
- noComment?: string
16
-
17
- /**
18
- * 发送按钮文字
19
- */
20
- sendBtn?: string
21
-
22
- /**
23
- * 默认头像(URL or Gravatar Type)
24
- */
25
- defaultAvatar?: string
26
-
27
- /**
28
- * 页面唯一标识
29
- */
30
- pageKey: string
31
-
32
- /**
33
- * 页面可访问链接
34
- */
35
- pageUrl?: string
36
-
37
- /**
38
- * 页面标题
39
- */
40
- pageTitle?: string
41
-
42
- /**
43
- * 服务器地址
44
- */
45
- server: string
46
-
47
- /**
48
- * 站点名
49
- */
50
- site?: string
51
-
52
- /**
53
- * 表情包
54
- */
55
- emoticons?: object|any
56
-
57
- /**
58
- * 头像
59
- */
60
- gravatar?: {
61
- /** CDN 地址 */
62
- cdn?: string
63
- }
64
-
65
- /**
66
- * 查看更多配置
67
- */
68
- readMore?: {
69
- /** 每次请求获取数量 */
70
- pageSize?: number
71
- /** 滚动到底部自动加载 */
72
- autoLoad?: boolean
73
- }
74
-
75
- /**
76
- * 暗黑模式
77
- */
78
- darkMode?: boolean
79
- }
@@ -1,153 +0,0 @@
1
- export interface CommentData {
2
- /** 评论 ID */
3
- id: number
4
-
5
- /** 评论正文 */
6
- content: string
7
-
8
- /** 用户昵称 */
9
- nick: string
10
-
11
- /** 用户邮箱(已加密) */
12
- email_encrypted: string
13
-
14
- /** 用户链接 */
15
- link: string
16
-
17
- /** 回复目标评论 ID */
18
- rid: number
19
-
20
- /** User Agent */
21
- ua: string
22
-
23
- /** 评论日期 */
24
- date: string
25
-
26
- /** 是否折叠 */
27
- is_collapsed?: boolean
28
-
29
- /** 是否待审 */
30
- is_pending?: boolean
31
-
32
- /** 是否为管理员 */
33
- is_admin?: boolean
34
-
35
- /** 徽章文字 */
36
- badge_name?: string
37
-
38
- /** 徽章颜色 */
39
- badge_color?: string
40
-
41
- /** 是否允许回复 */
42
- is_allow_reply?: boolean
43
-
44
- /** 评论页面 key */
45
- page_key: string
46
-
47
- /** 评论页面 url */
48
- page_url?: string
49
-
50
- /** 评论页面 title */
51
- page_title?: string
52
-
53
- /** 是否可见 */
54
- visible: boolean
55
-
56
- /** 站点名(用于隔离) */
57
- site_name: string
58
-
59
- /** 赞同数 */
60
- vote_up: number
61
-
62
- /** 反对数 */
63
- vote_down: number
64
- }
65
-
66
- export interface ListData {
67
- /** 评论数据 */
68
- comments: CommentData[]
69
-
70
- /** 父级评论总数 */
71
- total_parents: number
72
-
73
- /** 评论总数(包括所有子评论) */
74
- total: number
75
-
76
- /** 页面信息 */
77
- page: PageData
78
-
79
- unread: NotifyData[]
80
-
81
- unread_count: number
82
-
83
- sites?: SiteData[]
84
- }
85
-
86
- export interface PageData {
87
- /** 页面 ID */
88
- id: number
89
-
90
- /** 页面唯一标识符 */
91
- key: string
92
-
93
- /** 页面标题 */
94
- title: string
95
-
96
- /** 页面 url */
97
- url: string
98
-
99
- /** 仅管理员可评 */
100
- admin_only: boolean
101
-
102
- /** 站点名(用于隔离) */
103
- site_name: string
104
- }
105
-
106
- export interface SiteData {
107
- /** 站点 ID */
108
- id: number
109
-
110
- /** 站点名 */
111
- name: string
112
-
113
- /** 站点 URLs */
114
- urls: string[]
115
-
116
- /** 站点 URLs(原始字符串) */
117
- urls_raw: string
118
-
119
- /** 站点主 URL */
120
- first_url: string
121
- }
122
-
123
- export interface UserData {
124
- /** 用户 ID */
125
- id: number
126
-
127
- /** 用户名 */
128
- name: string
129
-
130
- /** 邮箱 */
131
- email: string
132
-
133
- /** 链接 */
134
- link: string
135
-
136
- /** 徽章名称 */
137
- badge_name: string
138
-
139
- /** 徽章颜色 */
140
- badge_color: string
141
-
142
- /** 是否属于管理员 */
143
- is_admin: boolean
144
- }
145
-
146
- export interface NotifyData {
147
- id: number
148
- user_id: number
149
- comment_id: number
150
- is_read: boolean
151
- is_emailed: boolean
152
- read_link: string
153
- }
@@ -1 +0,0 @@
1
- declare const ARTALK_VERSION: string
@@ -1,8 +0,0 @@
1
- import { ArtalkConfig } from "./artalk-config"
2
-
3
- declare class Artalk {
4
- constructor (conf: ArtalkConfig)
5
- }
6
-
7
- export as namespace Artalk
8
- export default Artalk
@@ -1 +0,0 @@
1
- /// <reference types="vite/client" />
@@ -1,41 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Res</title>
6
- <!-- 1. 引入 Artalk.css -->
7
- <link rel="stylesheet" href="/dist/Artalk.css">
8
- </head>
9
- <body>
10
-
11
- <div class="main"> <!-- △ fragment: .main -->
12
- <section id="comments">
13
- <div id="ArtalkComments"></div>
14
- </section>
15
-
16
- <!-- 2. 引入 Artalk.js -->
17
- <script src="/dist/Artalk.js"></script>
18
- <!-- 3. 配置 Artalk -->
19
- <script>
20
- window.artalk = new Artalk({
21
- el: '#ArtalkComments',
22
- placeholder: '来啊,快活啊 ( ゜- ゜)',
23
- noComment: '快来成为第一个评论的人吧~',
24
- defaultAvatar: 'mp',
25
- pageKey: 'pjax-example-page1',
26
- serverUrl: 'http://localhost:23366/index.php',
27
- readMore: {
28
- pageSize: 15,
29
- autoLoad: true
30
- }
31
- });
32
- </script>
33
-
34
- </div>
35
-
36
- <!-- Pjax 配置 -->
37
- <script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
38
- <script src="https://cdn.jsdelivr.net/npm/jquery-pjax@2.0.1/jquery.pjax.min.js"></script>
39
-
40
- </body>
41
- </html>
@@ -1,41 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8">
5
- <title>Res</title>
6
- <!-- 1. 引入 Artalk.css -->
7
- <link rel="stylesheet" href="/dist/Artalk.css">
8
- </head>
9
- <body>
10
-
11
- <div class="main"> <!-- △ fragment: .main -->
12
- <section id="comments">
13
- <div id="ArtalkComments"></div>
14
- </section>
15
-
16
- <!-- 2. 引入 Artalk.js -->
17
- <script src="/dist/Artalk.js"></script>
18
- <!-- 3. 配置 Artalk -->
19
- <script>
20
- window.artalk = new Artalk({
21
- el: '#ArtalkComments',
22
- placeholder: '来啊,快活啊 ( ゜- ゜)',
23
- noComment: '快来成为第一个评论的人吧~',
24
- defaultAvatar: 'mp',
25
- pageKey: 'pjax-example-page2',
26
- serverUrl: 'http://localhost:23366/index.php',
27
- readMore: {
28
- pageSize: 15,
29
- autoLoad: true
30
- }
31
- });
32
- </script>
33
-
34
- </div>
35
-
36
- <!-- Pjax 配置 -->
37
- <script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
38
- <script src="https://cdn.jsdelivr.net/npm/jquery-pjax@2.0.1/jquery.pjax.min.js"></script>
39
-
40
- </body>
41
- </html>
package/src/Artalk.ts DELETED
@@ -1,160 +0,0 @@
1
- import './style/main.less'
2
- import Checker from './lib/checker'
3
- import Editor from './components/Editor'
4
- import List from './components/List'
5
- import Sidebar from './components/Sidebar'
6
- import { GetLayerWrap } from './components/Layer'
7
- import * as Ui from './lib/ui'
8
- import * as Utils from './lib/utils'
9
- import { ArtalkConfig } from '~/types/artalk-config'
10
- import Context from './Context'
11
- import emoticons from './assets/emoticons.json'
12
- import Constant from './Constant'
13
-
14
- const defaultOpts: ArtalkConfig = {
15
- el: '',
16
- placeholder: '来啊,快活啊 ( ゜- ゜)',
17
- noComment: '快来成为第一个评论的人吧~',
18
- sendBtn: '发送评论',
19
- defaultAvatar: 'mp',
20
- pageKey: '',
21
- server: '',
22
- site: '',
23
- emoticons,
24
- gravatar: {
25
- cdn: 'https://sdn.geekzu.org/avatar/'
26
- },
27
- darkMode: false,
28
- }
29
-
30
- export default class Artalk {
31
- public conf: ArtalkConfig
32
- public ctx: Context
33
- public el: HTMLElement
34
- public readonly contextID: number = new Date().getTime() // 实例唯一 ID
35
- public checker: Checker
36
- public editor: Editor
37
- public list: List
38
- public sidebar: Sidebar
39
- public comments: Comment[] = []
40
-
41
- constructor (conf: ArtalkConfig) {
42
- // Version Information
43
- console.log(`\n %c `
44
- + `Artalk v${ARTALK_VERSION} %c 一款简洁有趣的可拓展评论系统 \n\n%c`
45
- + `> https://artalk.js.org\n`
46
- + `> https://github.com/ArtalkJS/Artalk\n`,
47
- 'color: #FFF; background: #1DAAFF; padding:5px 0;', 'color: #FFF; background: #656565; padding:5px 0;', '')
48
-
49
- // Options
50
- this.conf = { ...defaultOpts, ...conf }
51
- this.conf.server = this.conf.server.replace(/\/$/, '')
52
-
53
- // Default `pageKey` conf
54
- if (!this.conf.pageKey) {
55
- // TODO 自动获取和 atk_comment query 冲突
56
- // eslint-disable-next-line prefer-destructuring
57
- this.conf.pageKey = window.location.href.split('#')[0]
58
- }
59
-
60
- // Main Element
61
- try {
62
- const el = document.querySelector<HTMLElement>(this.conf.el)
63
- if (el === null) {
64
- throw Error(`Sorry, Target element "${this.conf.el}" was not found.`)
65
- }
66
- this.el = el
67
- } catch (e) {
68
- console.error(e)
69
- throw new Error('Artalk config `el` error')
70
- }
71
-
72
- // Create context
73
- this.ctx = new Context(this.el, this.conf)
74
-
75
- this.el.classList.add('artalk')
76
- this.el.setAttribute('atk-run-id', this.contextID.toString())
77
-
78
- // 若该元素中 artalk 已装载
79
- if (this.el.innerHTML.trim() !== '') this.el.innerHTML = ''
80
-
81
- // Components
82
- this.initDarkMode()
83
-
84
- this.checker = new Checker(this.ctx)
85
-
86
- this.editor = new Editor(this.ctx)
87
- this.list = new List(this.ctx)
88
- this.sidebar = new Sidebar(this.ctx)
89
-
90
- this.el.appendChild(this.editor.el)
91
- this.el.appendChild(this.list.el)
92
- this.el.appendChild(this.sidebar.el)
93
-
94
- // 请求获取评论
95
- this.list.reqComments()
96
-
97
- // 锚点快速跳转评论
98
- window.addEventListener('hashchange', () => {
99
- this.list.checkGoToCommentByUrlHash()
100
- })
101
-
102
- // 仅管理员显示控制
103
- this.ctx.addEventListener('check-admin-show-el', () => {
104
- const items: HTMLElement[] = []
105
-
106
- this.el.querySelectorAll<HTMLElement>(`[atk-only-admin-show]`).forEach(item => items.push(item))
107
- // for layer
108
- const { wrapEl: layerWrapEl } = GetLayerWrap(this.ctx)
109
- if (layerWrapEl)
110
- layerWrapEl.querySelectorAll<HTMLElement>(`[atk-only-admin-show]`).forEach(item => items.push(item))
111
-
112
- items.forEach((itemEl: HTMLElement) => {
113
- if (this.ctx.user.data.isAdmin)
114
- itemEl.classList.remove('atk-hide')
115
- else
116
- itemEl.classList.add('atk-hide')
117
- })
118
- })
119
-
120
- this.ctx.addEventListener('user-changed', () => {
121
- this.ctx.dispatchEvent('check-admin-show-el')
122
- this.ctx.dispatchEvent('list-refresh-ui')
123
- })
124
- }
125
-
126
- /** 暗黑模式 - 初始化 */
127
- initDarkMode() {
128
- if (this.conf.darkMode) {
129
- this.el.classList.add(Constant.DARK_MODE_CLASSNAME)
130
- } else {
131
- this.el.classList.remove(Constant.DARK_MODE_CLASSNAME)
132
- }
133
-
134
- // for Layer
135
- const { wrapEl: layerWrapEl } = GetLayerWrap(this.ctx)
136
- if (layerWrapEl) {
137
- if (this.conf.darkMode) {
138
- layerWrapEl.classList.add(Constant.DARK_MODE_CLASSNAME)
139
- } else {
140
- layerWrapEl.classList.remove(Constant.DARK_MODE_CLASSNAME)
141
- }
142
- }
143
- }
144
-
145
- /** 暗黑模式 - 设定 */
146
- setDarkMode(darkMode: boolean) {
147
- this.ctx.conf.darkMode = darkMode
148
- this.initDarkMode()
149
- }
150
-
151
- /** 暗黑模式 - 开启 */
152
- openDarkMode() {
153
- this.setDarkMode(true)
154
- }
155
-
156
- /** 暗黑模式 - 关闭 */
157
- closeDarkMode() {
158
- this.setDarkMode(false)
159
- }
160
- }
package/src/Constant.ts DELETED
@@ -1,6 +0,0 @@
1
- const Constant = {
2
- DARK_MODE_CLASSNAME: 'atk-dark-mode'
3
- }
4
-
5
- export default Constant
6
-
package/src/Context.ts DELETED
@@ -1,34 +0,0 @@
1
- import { ArtalkConfig } from '~/types/artalk-config'
2
- import User from './lib/user'
3
- import { EventPayloadMap, Listener, Event } from './Event'
4
-
5
- export default class Context {
6
- public cid: number // Context 唯一标识
7
- public rootEl: HTMLElement
8
- public conf: ArtalkConfig
9
- public user: User
10
-
11
- private eventList: Event[] = []
12
-
13
- public constructor (rootEl: HTMLElement, conf: ArtalkConfig) {
14
- this.cid = +new Date()
15
- this.rootEl = rootEl
16
- this.conf = conf
17
- this.user = new User(this.conf)
18
- }
19
-
20
- public addEventListener<K extends keyof EventPayloadMap>(name: K, listener: Listener<EventPayloadMap[K]>): void {
21
- this.eventList.push({ name, listener: listener as any })
22
- }
23
-
24
- public removeEventListener<K extends keyof EventPayloadMap>(name: K): void {
25
- this.eventList = this.eventList.filter((event) => event.name !== name)
26
- }
27
-
28
- public dispatchEvent<K extends keyof EventPayloadMap>(name: K, payload?: EventPayloadMap[K]): void {
29
- this.eventList
30
- .filter((event) => event.name === name)
31
- .map((event) => event.listener)
32
- .forEach((listener) => listener(payload as any))
33
- }
34
- }
package/src/Event.d.ts DELETED
@@ -1,59 +0,0 @@
1
- import { ListData, CommentData, NotifyData } from '~/types/artalk-data'
2
-
3
- /** EventName to EventPayload Type */
4
- export interface EventPayloadMap {
5
- 'list-loading': undefined
6
- 'list-clear': undefined
7
- 'list-refresh-ui': undefined
8
- 'list-import': CommentData[]
9
- 'list-insert': CommentData
10
- 'list-comment-del': CommentData
11
- 'list-reload': undefined
12
- 'list-update-data': (data: ListData | undefined) => void
13
- 'sidebar-show'?: SidebarShowPayload
14
- 'sidebar-hide': undefined
15
- 'check-admin-show-el': undefined
16
- 'editor-open-comment': undefined
17
- 'editor-close-comment': undefined
18
- 'editor-show-loading': undefined
19
- 'editor-hide-loading': undefined
20
- 'editor-notify': NotifyConf
21
- 'editor-reply': CommentData
22
- 'user-changed': undefined
23
- 'unread-update': UnreadUpdatePayload
24
- 'checker-admin': CheckerConf
25
- 'checker-captcha': CheckerCaptchaConf
26
- }
27
-
28
- export interface CheckerConf {
29
- onSuccess?: (inputVal: string, dialogEl?: HTMLElement) => void
30
- onMount?: (dialogEl: HTMLElement) => void
31
- onCancel?: () => void
32
- }
33
-
34
- export interface NotifyConf {
35
- msg: string
36
- type: any
37
- }
38
-
39
- export interface CheckerCaptchaConf extends CheckerConf {
40
- imgData?: string
41
- }
42
-
43
- export interface SidebarShowPayload {
44
- viewName?: string
45
- }
46
-
47
- export interface UnreadUpdatePayload {
48
- notifies: NotifyData[]
49
- }
50
-
51
- // ============================================
52
- export interface Listener<P> {
53
- (payload: P): void
54
- }
55
-
56
- export interface Event<K extends keyof EventPayloadMap = keyof EventPayloadMap> {
57
- name: keyof EventPayloadMap
58
- listener: Listener<EventPayloadMap[K]>
59
- }