gitalk-react 1.0.0-beta.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 (47) hide show
  1. package/LICENSE +9 -0
  2. package/README-zh-CN.md +257 -0
  3. package/README.md +257 -0
  4. package/dist/gitalk-dark.css +1 -0
  5. package/dist/gitalk-light.css +1 -0
  6. package/dist/gitalk.d.ts +445 -0
  7. package/dist/gitalk.js +12560 -0
  8. package/dist/gitalk.umd.cjs +121 -0
  9. package/lib/assets/arrow-down.svg +1 -0
  10. package/lib/assets/edit.svg +3 -0
  11. package/lib/assets/github.svg +3 -0
  12. package/lib/assets/heart-filled.svg +3 -0
  13. package/lib/assets/heart.svg +3 -0
  14. package/lib/assets/reply.svg +3 -0
  15. package/lib/assets/tip.svg +8 -0
  16. package/lib/components/action.tsx +21 -0
  17. package/lib/components/avatar.tsx +42 -0
  18. package/lib/components/button.tsx +35 -0
  19. package/lib/components/comment.tsx +153 -0
  20. package/lib/components/svg.tsx +29 -0
  21. package/lib/constants/index.ts +43 -0
  22. package/lib/contexts/I18nContext.ts +18 -0
  23. package/lib/gitalk.tsx +1231 -0
  24. package/lib/i18n/de.json +20 -0
  25. package/lib/i18n/en.json +20 -0
  26. package/lib/i18n/es-ES.json +20 -0
  27. package/lib/i18n/fa.json +20 -0
  28. package/lib/i18n/fr.json +20 -0
  29. package/lib/i18n/index.ts +40 -0
  30. package/lib/i18n/ja.json +20 -0
  31. package/lib/i18n/ko.json +20 -0
  32. package/lib/i18n/pl.json +21 -0
  33. package/lib/i18n/ru.json +20 -0
  34. package/lib/i18n/zh-CN.json +20 -0
  35. package/lib/i18n/zh-TW.json +20 -0
  36. package/lib/interfaces/index.ts +30 -0
  37. package/lib/services/graphql/comment.ts +85 -0
  38. package/lib/services/request.ts +24 -0
  39. package/lib/services/user.ts +40 -0
  40. package/lib/themes/base.scss +592 -0
  41. package/lib/themes/gitalk-dark.scss +24 -0
  42. package/lib/themes/gitalk-light.scss +24 -0
  43. package/lib/utils/compatibility.ts +35 -0
  44. package/lib/utils/dom.ts +15 -0
  45. package/lib/utils/logger.ts +56 -0
  46. package/lib/utils/query.ts +19 -0
  47. package/package.json +83 -0
@@ -0,0 +1,56 @@
1
+ enum LogLevel {
2
+ INFO,
3
+ SUCCESS,
4
+ WARNING,
5
+ ERROR,
6
+ NO_LOG = Infinity,
7
+ }
8
+
9
+ class Logger {
10
+ prefix = "Gitalk";
11
+ logLevel = import.meta.env.PROD ? LogLevel.WARNING : LogLevel.INFO;
12
+
13
+ i(...infos: unknown[]) {
14
+ if (this.logLevel > LogLevel.INFO) return;
15
+
16
+ console.info(
17
+ `%c ${this.prefix} [INFO] `,
18
+ "color:#111 ;background-color: #f9fafb;",
19
+ ...infos,
20
+ );
21
+ }
22
+
23
+ s(...successes: unknown[]) {
24
+ if (this.logLevel > LogLevel.SUCCESS) return;
25
+
26
+ console.info(
27
+ `%c ${this.prefix} [SUCCESS] `,
28
+ "color:#111 ;background-color: #84cc16;",
29
+ ...successes,
30
+ );
31
+ }
32
+
33
+ w(...warnings: unknown[]) {
34
+ if (this.logLevel > LogLevel.WARNING) return;
35
+
36
+ console.warn(
37
+ `%c ${this.prefix} [WARNING] `,
38
+ "color:#eee ;background-color:#c2410c;",
39
+ ...warnings,
40
+ );
41
+ }
42
+
43
+ e(...errors: unknown[]) {
44
+ if (this.logLevel > LogLevel.ERROR) return;
45
+
46
+ console.error(
47
+ `%c ${this.prefix} [ERROR] `,
48
+ "color:#eee ;background-color:#dc2626;",
49
+ ...errors,
50
+ );
51
+ }
52
+ }
53
+
54
+ const logger = new Logger();
55
+
56
+ export default logger;
@@ -0,0 +1,19 @@
1
+ export const parseSearchQuery = (search: string = location.search) => {
2
+ const query: Record<string, string> = {};
3
+ if (!search) return query;
4
+
5
+ const queryString = search[0] === "?" ? search.substring(1) : search;
6
+ queryString.split("&").forEach((queryStr) => {
7
+ const [key, value] = queryStr.split("=");
8
+ if (key) query[decodeURIComponent(key)] = decodeURIComponent(value || "");
9
+ });
10
+
11
+ return query;
12
+ };
13
+
14
+ export const stringifySearchQuery = (query: Record<string, string>) => {
15
+ const queryString = Object.keys(query)
16
+ .map((key) => `${key}=${encodeURIComponent(query[key] || "")}`)
17
+ .join("&");
18
+ return queryString;
19
+ };
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "gitalk-react",
3
+ "version": "1.0.0-beta.1",
4
+ "private": false,
5
+ "author": {
6
+ "name": "LolipopJ",
7
+ "email": "mail@towind.fun",
8
+ "url": "https://github.com/LolipopJ"
9
+ },
10
+ "homepage": "https://github.com/LolipopJ/gitalk-react",
11
+ "license": "MIT",
12
+ "type": "module",
13
+ "files": [
14
+ "dist",
15
+ "lib",
16
+ "LICENSE",
17
+ "package.json",
18
+ "README-zh-CN.md",
19
+ "README.md"
20
+ ],
21
+ "main": "./dist/gitalk.umd.cjs",
22
+ "module": "./dist/gitalk.js",
23
+ "exports": {
24
+ ".": {
25
+ "import": "./dist/gitalk.js",
26
+ "require": "./dist/gitalk.umd.cjs"
27
+ },
28
+ "./gitalk.css": "./dist/gitalk-light.css",
29
+ "./gitalk-light.css": "./dist/gitalk-light.css",
30
+ "./gitalk-dark.css": "./dist/gitalk-dark.css"
31
+ },
32
+ "scripts": {
33
+ "dev": "vite",
34
+ "build": "npm run build:ts && npm run build:scss",
35
+ "build:ts": "tsc -b && vite build",
36
+ "build:scss": "vite build --config vite.config.scss.ts",
37
+ "lint": "npm run lint:ts && npm run lint:scss",
38
+ "lint:ts": "eslint . --fix",
39
+ "lint:scss": "stylelint lib/**/*.scss --fix",
40
+ "preview": "vite preview"
41
+ },
42
+ "dependencies": {
43
+ "ahooks": "^3.0.0",
44
+ "date-fns": "^4.0.0",
45
+ "node-polyglot": "^2.0.0",
46
+ "octokit": "^4.0.0",
47
+ "react-flip-move": "^3.0.0"
48
+ },
49
+ "peerDependencies": {
50
+ "react": ">=16.8.0",
51
+ "react-dom": ">=16.8.0"
52
+ },
53
+ "devDependencies": {
54
+ "@eslint/js": "^9.24.0",
55
+ "@octokit/types": "^14.0.0",
56
+ "@types/node": "^22.14.1",
57
+ "@types/node-polyglot": "^2.5.0",
58
+ "@types/react": "^16.8.0",
59
+ "@types/react-dom": "^16.8.0",
60
+ "@vitejs/plugin-react": "^4.4.0",
61
+ "eslint": "^9.24.0",
62
+ "eslint-config-prettier": "^10.1.2",
63
+ "eslint-plugin-prettier": "^5.2.6",
64
+ "eslint-plugin-react": "^7.37.5",
65
+ "eslint-plugin-react-hooks": "^5.2.0",
66
+ "eslint-plugin-react-refresh": "^0.4.19",
67
+ "eslint-plugin-simple-import-sort": "^12.1.1",
68
+ "github-markdown-css": "^5.8.1",
69
+ "globals": "^16.0.0",
70
+ "prettier": "^3.5.3",
71
+ "react": "^16.8.0",
72
+ "react-dom": "^16.8.0",
73
+ "rollup-plugin-visualizer": "^5.14.0",
74
+ "sass-embedded": "^1.86.3",
75
+ "stylelint": "^16.18.0",
76
+ "stylelint-config-recess-order": "^6.0.0",
77
+ "stylelint-config-standard-scss": "^14.0.0",
78
+ "typescript": "~5.8.3",
79
+ "typescript-eslint": "^8.30.1",
80
+ "vite": "^6.3.1",
81
+ "vite-plugin-dts": "^4.5.3"
82
+ }
83
+ }