gitalk-react 1.0.0-beta.2 → 1.0.0-beta.4

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.
package/README-zh-CN.md CHANGED
@@ -1,7 +1,12 @@
1
+ 基于 Github 议题和 React 的现代评论组件。
2
+
1
3
  [ENGLISH](./README.md) | 简体中文
2
4
 
3
5
  # Gitalk React
4
6
 
7
+ [![NPM][npm-version-image]][npm-version-url]
8
+ [![gzip-size][gzip-size]][gzip-url]
9
+
5
10
  使用 TypeScript, React 和 Vite 重新实现 [Gitalk](https://github.com/gitalk/gitalk) —— 基于 Github 议题的评论组件。
6
11
 
7
12
  面向现代浏览器开发,专注于减少构建包的体积,提升开发与使用的体验。
@@ -10,10 +15,13 @@
10
15
 
11
16
  - **不兼容旧版浏览器**:仅保证兼容支持 [ES2020](https://caniuse.com/?feats=mdn-javascript_operators_optional_chaining,mdn-javascript_operators_nullish_coalescing,mdn-javascript_builtins_globalthis,es6-module-dynamic-import,bigint,mdn-javascript_builtins_promise_allsettled,mdn-javascript_builtins_string_matchall,mdn-javascript_statements_export_namespace,mdn-javascript_operators_import_meta) 的现代浏览器。
12
17
  - **依赖 React 运行时环境**:`react >= 16.8.0 && react-dom >= 16.8.0`。
18
+ - **部分参数的默认值发生了变化**:迁移到此组件时请留意。
19
+ - `id`:Gitalk 使用 `location.href` 作为默认值,Gitalk React 使用 `location.host + location.pathname` 作为默认值,避免预期外的查询参数。
20
+ - `defaultAuthor`:仍然可以使用。Gitalk React 新增了参数项 `defaultUser` 来设置评论的默认用户,保持字段命名与 Github API 一致。
13
21
 
14
22
  ## 开发中的功能
15
23
 
16
- - [ ] Feature: 支持在 Gitalk 编辑自己发表的评论。
24
+ - [ ] Feature: 支持在 Gitalk React 编辑自己发表的评论。
17
25
  - [ ] refactor: 逐渐移除对非必要三方库的依赖。减少构建包的体积。
18
26
  - [ ] test: 添加自动化测试流程。提升项目的健壮性。
19
27
  - [ ] chore: 部署预览环境。
@@ -28,7 +36,7 @@ npm install gitalk-react
28
36
 
29
37
  ### 使用
30
38
 
31
- 在项目中引入 Gitalk 的样式与组件:
39
+ 在项目中引入 Gitalk React 的样式与组件:
32
40
 
33
41
  ```tsx
34
42
  // 引入浅色模式样式
@@ -39,15 +47,15 @@ import 'gitalk-react/gitalk-dark.css'
39
47
  import Gitalk from 'gitalk-react'
40
48
  ```
41
49
 
42
- Gitalk 依赖于 Github OAuth App 实现登录鉴权,您需要首先[注册一个应用](https://github.com/settings/applications/new)。请注意,您必须将站点域名作为 `Authorization callback URL` 字段的值,例如 `https://yourdomain.com/site` 或开发环境下的 `http://localhost:5432`。
50
+ Gitalk React 依赖于 Github OAuth App 实现登录鉴权,您需要首先[注册一个应用](https://github.com/settings/applications/new)。请注意,您必须将站点域名作为 `Authorization callback URL` 字段的值,例如 `https://yourdomain.com/site` 或开发环境下的 `http://localhost:5432`。
43
51
 
44
- 使用 Gitalk 组件,填写必要的配置项:
52
+ 使用 Gitalk React 组件,填写必要的配置项:
45
53
 
46
54
  - `clientId`:Github OAuth App 的 ID。
47
55
  - `clientSecret`:Github OAuth App 的 Secret 密钥。
48
56
  - `owner`:Github 用户名。
49
57
  - `repo`:Github 仓库名。需要是公开的仓库。
50
- - `admin`:Gitalk 管理员列表,只有列表里的人可以初始化评论议题。可以是 Github 仓库的拥有者和协作者。
58
+ - `admin`:Gitalk React 管理员列表,只有列表里的人可以初始化评论议题。可以是 Github 仓库的拥有者和协作者。
51
59
 
52
60
  ```tsx
53
61
  <Gitalk
@@ -79,21 +87,21 @@ Gitalk 依赖于 Github OAuth App 实现登录鉴权,您需要首先[注册一
79
87
 
80
88
  ### admin `string[]`
81
89
 
82
- **必填项**。Gitalk 管理员列表。可以是 Github 仓库的拥有者和协作者:拥有对此仓库**写权限**的用户。
90
+ **必填项**。Gitalk React 管理员列表。可以是 Github 仓库的拥有者和协作者:拥有对此仓库**写权限**的用户。
83
91
 
84
- ### id `string = location.href`
92
+ ### id `string = location.host + location.pathname`
85
93
 
86
94
  评论议题的唯一标识符,长度不能超过 50。
87
95
 
88
- Gitalk 在创建评论议题时,自动将此参数作为评论议题的标签项,并默认通过它来获取评论议题。
96
+ Gitalk React 在创建评论议题时,自动将此参数作为评论议题的标签项,并默认通过它来获取评论议题。
89
97
 
90
98
  对于博客等类型的站点,推荐将页面的 `slug` 作为参数。
91
99
 
92
- ### number `number = -1`
100
+ ### number `number`
93
101
 
94
102
  评论议题的编号。
95
103
 
96
- 如果指定了此参数,那么 Gitalk 将通过它来获取评论议题,而非标识符。
104
+ 如果指定了此参数,那么 Gitalk React 将通过它来获取评论议题,而非标识符。
97
105
 
98
106
  ### labels `string[] = ["Gitalk"]`
99
107
 
@@ -109,7 +117,7 @@ Gitalk 在创建评论议题时,自动将此参数作为评论议题的标签
109
117
 
110
118
  ### language `string = navigator.language`
111
119
 
112
- Gitalk 使用的语言。
120
+ Gitalk React 使用的语言。
113
121
 
114
122
  可用的语言包括:`"de" | "en" | "es-ES" | "fa" | "fr" | "ja" | "ko" | "pl" | "ru" | "zh-CN" | "zh-TW"`。
115
123
 
@@ -121,15 +129,15 @@ Gitalk 使用的语言。
121
129
 
122
130
  评论排序的方式。`last` 表示按评论创建时间倒叙排列,`first` 表示按评论创建时间正叙排列。
123
131
 
124
- ### createIssueManually `boolean = true`
132
+ ### createIssueManually `boolean = false`
125
133
 
126
- 当评论议题不存在时,Gitalk 将会自动为您创建一个新的评论议题。
134
+ 当评论议题不存在时,Gitalk React 将会自动为您创建一个新的评论议题。
127
135
 
128
- 如果您希望在管理员登录后,手动点击按钮以创建评论议题,则可以将其设置为 `false`。
136
+ 如果您希望以管理员身份登录后,手动点击按钮来创建评论议题,则可以将其设置为 `true`。
129
137
 
130
138
  ### enableHotKey `boolean = true`
131
139
 
132
- 是否启用热键 `cmd + enter` 或 `ctrl + enter` 来创建评论。
140
+ 是否启用热键 `cmd + enter` 或 `ctrl + enter` 来发表评论。
133
141
 
134
142
  ### distractionFreeMode `boolean = false`
135
143
 
@@ -154,6 +162,20 @@ Gitalk 使用的语言。
154
162
 
155
163
  Github OAuth App 鉴权反向代理,支持 CORS。[为什么需要它?](https://github.com/isaacs/github/issues/330)
156
164
 
165
+ ### defaultUser `{ avatar_url: string; login: string; html_url: string }`
166
+
167
+ 评论用户不存在时,使用的默认用户。
168
+
169
+ `avatar_url` 为用户头像地址,`login` 为用户名,`html_url` 为点击用户后跳转的页面。默认值:
170
+
171
+ ```json
172
+ {
173
+ "avatar_url": "//avatars1.githubusercontent.com/u/29697133?s=50",
174
+ "login": "null",
175
+ "html_url": ""
176
+ }
177
+ ```
178
+
157
179
  ### updateCountCallback `(count: number) => void`
158
180
 
159
181
  评论数量更新的调用的回调方法。
@@ -164,7 +186,7 @@ Github OAuth App 鉴权反向代理,支持 CORS。[为什么需要它?](http
164
186
 
165
187
  ## 主题样式
166
188
 
167
- 通过设置 CSS 变量,您可以快速地将 Gitalk 的主题颜色修改为适配您站点的样式。
189
+ 通过设置 CSS 变量,您可以快速地将 Gitalk React 的主题颜色修改为适配您站点的样式。
168
190
 
169
191
  当您引入浅色主题 `import 'gitalk-react/gitalk.css'` 时,默认的 CSS 变量如下:
170
192
 
@@ -255,3 +277,8 @@ yarn build
255
277
  ## 许可证
256
278
 
257
279
  [MIT](./LICENSE)
280
+
281
+ [npm-version-image]: https://img.shields.io/npm/v/gitalk-react.svg?style=flat-square
282
+ [npm-version-url]: https://www.npmjs.com/package/gitalk-react
283
+ [gzip-size]: https://img.badgesize.io/https://unpkg.com/gitalk-react/dist/gitalk.umd.cjs?compression=gzip&style=flat-square
284
+ [gzip-url]: https://unpkg.com/gitalk-react/dist/gitalk.umd.cjs
package/README.md CHANGED
@@ -1,7 +1,12 @@
1
+ Modern comment component based on GitHub Issue and React.
2
+
1
3
  ENGLISH | [简体中文](./README-zh-CN.md)
2
4
 
3
5
  # Gitalk React
4
6
 
7
+ [![NPM][npm-version-image]][npm-version-url]
8
+ [![gzip-size][gzip-size]][gzip-url]
9
+
5
10
  Reimplementing [Gitalk](https://github.com/gitalk/gitalk) with TypeScript, React, and Vite — a comment component based on GitHub issues.
6
11
 
7
12
  Developed for modern browsers, focusing on reducing build size and enhancing development and usage experience.
@@ -10,10 +15,13 @@ Developed for modern browsers, focusing on reducing build size and enhancing dev
10
15
 
11
16
  - **Not compatible with older browsers**: Only guarantees compatibility with modern browsers that support [ES2020](https://caniuse.com/?feats=mdn-javascript_operators_optional_chaining,mdn-javascript_operators_nullish_coalescing,mdn-javascript_builtins_globalthis,es6-module-dynamic-import,bigint,mdn-javascript_builtins_promise_allsettled,mdn-javascript_builtins_string_matchall,mdn-javascript_statements_export_namespace,mdn-javascript_operators_import_meta).
12
17
  - **Depends on React runtime environment**: `react >= 16.8.0 && react-dom >= 16.8.0`.
18
+ - **Some default values for parameters have changed**: Please pay attention when migrating to this component.
19
+ - `id`: Gitalk uses `location.href` as the default value, while Gitalk React uses `location.host + location.pathname` as the default value, to avoid unexpected search parameters.
20
+ - `defaultAuthor`: Can still be used. Gitalk React has added a new parameter `defaultUser` to set the default user for comments, keeping the field naming consistent with the GitHub API.
13
21
 
14
22
  ## Features in Development
15
23
 
16
- - [ ] Feature: Support editing comments published by the user in Gitalk.
24
+ - [ ] Feature: Support editing comments published by the user in Gitalk React.
17
25
  - [ ] refactor: Gradually remove dependencies on non-essential third-party libraries to reduce build size.
18
26
  - [ ] test: Add automated testing processes to enhance project robustness.
19
27
  - [ ] chore: Deploy preview environment.
@@ -39,15 +47,15 @@ import 'gitalk-react/gitalk-dark.css'
39
47
  import Gitalk from 'gitalk-react'
40
48
  ```
41
49
 
42
- Gitalk relies on GitHub OAuth App for login authentication; you need to first [register an application](https://github.com/settings/applications/new). Please note that you must set your site domain as the value of the `Authorization callback URL` field, such as `https://yourdomain.com/site` or for development environments `http://localhost:5432`.
50
+ Gitalk React relies on GitHub OAuth App for login authentication; you need to first [register an application](https://github.com/settings/applications/new). Please note that you must set your site domain as the value of the `Authorization callback URL` field, such as `https://yourdomain.com/site` or for development environments `http://localhost:5432`.
43
51
 
44
- When using the Gitalk component, fill in the necessary configuration items:
52
+ When using the Gitalk React component, fill in the necessary configuration items:
45
53
 
46
54
  - `clientId`: The ID of your GitHub OAuth App.
47
55
  - `clientSecret`: The Secret key of your GitHub OAuth App.
48
56
  - `owner`: Your GitHub username.
49
57
  - `repo`: The name of your GitHub repository. It must be a public repository.
50
- - `admin`: A list of Gitalk administrators; only those listed can initialize comment topics. This can include the owner and collaborators of the GitHub repository.
58
+ - `admin`: A list of Gitalk React administrators; only those listed can initialize comment topics. This can include the owner and collaborators of the GitHub repository.
51
59
 
52
60
  ```tsx
53
61
  <Gitalk
@@ -79,21 +87,21 @@ When using the Gitalk component, fill in the necessary configuration items:
79
87
 
80
88
  ### admin `string[]`
81
89
 
82
- **Required**. A list of Gitalk administrators. This can include users who have write access to this repository: owners and collaborators.
90
+ **Required**. A list of Gitalk React administrators. This can include users who have **write access** to this repository: owners and collaborators.
83
91
 
84
- ### id `string = location.href`
92
+ ### id `string = location.host + location.pathname`
85
93
 
86
94
  A unique identifier for the comment topic; length cannot exceed 50 characters.
87
95
 
88
- When creating a comment topic, Gitalk automatically uses this parameter as a label item for the comment topic and defaults to fetching comments based on it.
96
+ When creating a comment topic, Gitalk React automatically uses this parameter as a label item for the comment topic and defaults to fetching comments based on it.
89
97
 
90
- For blog-type sites, it is recommended to use the page's slug as this parameter.
98
+ For blog-type sites, it is recommended to use the page's `slug` as this parameter.
91
99
 
92
- ### number `number = -1`
100
+ ### number `number`
93
101
 
94
102
  The number of the comment topic.
95
103
 
96
- If this parameter is specified, then Gitalk will fetch comments based on it rather than using the identifier.
104
+ If this parameter is specified, then Gitalk React will fetch comments based on it rather than using the identifier.
97
105
 
98
106
  ### labels `string[] = ["Gitalk"]`
99
107
 
@@ -109,9 +117,9 @@ The content of the comment topic.
109
117
 
110
118
  ### language `string = navigator.language`
111
119
 
112
- The language used by Gitalk.
120
+ The language used by Gitalk React.
113
121
 
114
- Available languages include: "de" | "en" | "es-ES" | "fa" | "fr" | "ja" | "ko" | "pl" | "ru" | "zh-CN" | "zh-TW".
122
+ Available languages include: `"de" | "en" | "es-ES" | "fa" | "fr" | "ja" | "ko" | "pl" | "ru" | "zh-CN" | "zh-TW"`.
115
123
 
116
124
  ### perPage `number = 10`
117
125
 
@@ -119,17 +127,17 @@ The number of comments loaded per page; cannot exceed 100.
119
127
 
120
128
  ### pagerDirection `"last" | "first" = "last"`
121
129
 
122
- The sorting method for comments. last indicates descending order by creation time, while first indicates ascending order by creation time.
130
+ The sorting method for comments. `last` indicates descending order by creation time, while `first` indicates ascending order by creation time.
123
131
 
124
- ### createIssueManually `boolean = true`
132
+ ### createIssueManually `boolean = false`
125
133
 
126
- When a comment topic does not exist, Gitalk will automatically create a new one for you.
134
+ When a comment topic does not exist, Gitalk React will automatically create a new one for you.
127
135
 
128
- If you prefer to create a comment topic manually by clicking a button after logging in as an administrator, set this to false.
136
+ If you prefer to create a comment topic manually by clicking a button after logging in as an administrator, set this to `true`.
129
137
 
130
138
  ### enableHotKey `boolean = true`
131
139
 
132
- Whether to enable hotkeys like cmd + enter or ctrl + enter to create comments.
140
+ Whether to enable hotkeys like `cmd + enter` or `ctrl + enter` to publish comments.
133
141
 
134
142
  ### distractionFreeMode `boolean = false`
135
143
 
@@ -139,7 +147,7 @@ Whether to enable full-screen overlay effects similar to Facebook's comment box.
139
147
 
140
148
  Animation effects for the comment list.
141
149
 
142
- Default values (referenced effects can be found here):
150
+ Default values (referenced effects can be found [here](https://github.com/joshwcomeau/react-flip-move/blob/master/documentation/enter_leave_animations.md)):
143
151
 
144
152
  ```json
145
153
  {
@@ -152,7 +160,21 @@ Default values (referenced effects can be found here):
152
160
 
153
161
  ### proxy `string = "https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token"`
154
162
 
155
- Reverse proxy for authenticating with Github OAuth App that supports CORS. Why is it needed?
163
+ Reverse proxy for authenticating with Github OAuth App that supports CORS. [Why needed?](https://github.com/isaacs/github/issues/330)
164
+
165
+ ### defaultUser `{ avatar_url: string; login: string; html_url: string }`
166
+
167
+ The default user used when the comment user does not exist.
168
+
169
+ `avatar_url` is the user's avatar URL, `login` is the username, and `html_url` is the page to which users are redirected when clicked. Default values:
170
+
171
+ ```json
172
+ {
173
+ "avatar_url": "//avatars1.githubusercontent.com/u/29697133?s=50",
174
+ "login": "null",
175
+ "html_url": ""
176
+ }
177
+ ```
156
178
 
157
179
  ### updateCountCallback `(count: number) => void`
158
180
 
@@ -164,7 +186,7 @@ Callback method invoked when a comment is successfully created.
164
186
 
165
187
  ## Theme Styles
166
188
 
167
- You can quickly modify Gitalk's theme colors to match your site's style by setting CSS variables.
189
+ You can quickly modify Gitalk React's theme colors to match your site's style by setting CSS variables.
168
190
 
169
191
  When you import light theme with `import 'gitalk-react/gitalk.css'`, the default CSS variables are as follows:
170
192
 
@@ -255,3 +277,8 @@ yarn build
255
277
  ## License
256
278
 
257
279
  [MIT](./LICENSE)
280
+
281
+ [npm-version-image]: https://img.shields.io/npm/v/gitalk-react.svg?style=flat-square
282
+ [npm-version-url]: https://www.npmjs.com/package/gitalk-react
283
+ [gzip-size]: https://img.badgesize.io/https://unpkg.com/gitalk-react/dist/gitalk.umd.cjs?compression=gzip&style=flat-square
284
+ [gzip-url]: https://unpkg.com/gitalk-react/dist/gitalk.umd.cjs
package/dist/gitalk.d.ts CHANGED
@@ -49,14 +49,12 @@ declare interface GitalkProps extends Omit<default_2.HTMLAttributes<HTMLDivEleme
49
49
  * The unique id of the page.
50
50
  * Length must less than 50.
51
51
  *
52
- * @default location.href
52
+ * @default location.host + location.pathname
53
53
  */
54
54
  id?: string;
55
55
  /**
56
56
  * The issue ID of the page.
57
57
  * If the number attribute is not defined, issue will be located using id.
58
- *
59
- * @default -1
60
58
  */
61
59
  number?: number;
62
60
  /**
@@ -161,6 +159,12 @@ declare interface GitalkProps extends Omit<default_2.HTMLAttributes<HTMLDivEleme
161
159
  * @param count comments number
162
160
  */
163
161
  updateCountCallback?: (count: number) => void;
162
+ /**
163
+ * Callback method invoked when a new issue is successfully created.
164
+ *
165
+ * @param issue created issue
166
+ */
167
+ onCreateIssue?: (issue: Issue) => void;
164
168
  /**
165
169
  * Callback method invoked when a new comment is successfully created.
166
170
  *
@@ -412,6 +416,8 @@ declare const i18nMap: {
412
416
  };
413
417
  };
414
418
 
419
+ declare type Issue = Endpoints["GET /repos/{owner}/{repo}/issues/{issue_number}"]["response"]["data"];
420
+
415
421
  declare interface IssueCommentsQLResponse {
416
422
  repository: {
417
423
  issue: {