gitalk-react 1.0.0-beta.8 → 1.1.0

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 (58) hide show
  1. package/README-zh-CN.md +159 -57
  2. package/README.md +142 -40
  3. package/dist/gitalk-dark.css +1 -1
  4. package/dist/gitalk-light.css +1 -1
  5. package/dist/gitalk.browser.full.js +102 -0
  6. package/dist/gitalk.browser.js +94 -0
  7. package/dist/gitalk.cjs +94 -0
  8. package/dist/gitalk.d.cts +14 -0
  9. package/dist/gitalk.d.mts +174 -0
  10. package/dist/gitalk.js +7427 -12628
  11. package/package.json +67 -44
  12. package/proxy-server/.env.example +6 -0
  13. package/proxy-server/README.md +38 -0
  14. package/proxy-server/server.mjs +110 -0
  15. package/dist/gitalk.d.ts +0 -455
  16. package/dist/gitalk.umd.cjs +0 -123
  17. package/lib/assets/arrow-down.svg +0 -1
  18. package/lib/assets/edit.svg +0 -3
  19. package/lib/assets/github.svg +0 -3
  20. package/lib/assets/heart-filled.svg +0 -3
  21. package/lib/assets/heart.svg +0 -3
  22. package/lib/assets/reply.svg +0 -3
  23. package/lib/assets/tip.svg +0 -8
  24. package/lib/components/action.tsx +0 -21
  25. package/lib/components/avatar.tsx +0 -42
  26. package/lib/components/button.tsx +0 -35
  27. package/lib/components/comment-textarea.tsx +0 -164
  28. package/lib/components/comment.tsx +0 -185
  29. package/lib/components/comments-list.tsx +0 -106
  30. package/lib/components/meta.tsx +0 -129
  31. package/lib/components/svg.tsx +0 -29
  32. package/lib/constants/index.ts +0 -57
  33. package/lib/contexts/I18nContext.ts +0 -20
  34. package/lib/gitalk.tsx +0 -882
  35. package/lib/i18n/de.json +0 -20
  36. package/lib/i18n/en.json +0 -20
  37. package/lib/i18n/es-ES.json +0 -20
  38. package/lib/i18n/fa.json +0 -20
  39. package/lib/i18n/fr.json +0 -20
  40. package/lib/i18n/index.ts +0 -40
  41. package/lib/i18n/ja.json +0 -20
  42. package/lib/i18n/ko.json +0 -20
  43. package/lib/i18n/pl.json +0 -21
  44. package/lib/i18n/ru.json +0 -20
  45. package/lib/i18n/zh-CN.json +0 -20
  46. package/lib/i18n/zh-TW.json +0 -20
  47. package/lib/interfaces/index.ts +0 -196
  48. package/lib/services/graphql/comment.ts +0 -84
  49. package/lib/services/request.ts +0 -24
  50. package/lib/services/user.ts +0 -40
  51. package/lib/themes/base.scss +0 -628
  52. package/lib/themes/gitalk-dark.scss +0 -28
  53. package/lib/themes/gitalk-light.scss +0 -28
  54. package/lib/utils/compatibility.ts +0 -35
  55. package/lib/utils/dom.ts +0 -15
  56. package/lib/utils/logger.ts +0 -66
  57. package/lib/utils/query.ts +0 -19
  58. package/lib/vite-env.d.ts +0 -1
@@ -1,129 +0,0 @@
1
- import React, { useCallback, useContext, useState } from "react";
2
-
3
- import ArrowDown from "../assets/arrow-down.svg?raw";
4
- import { HOMEPAGE, VERSION } from "../constants";
5
- import I18nContext from "../contexts/I18nContext";
6
- import type { GitalkProps, Issue, User } from "../interfaces";
7
- import { hasClassInParent } from "../utils/dom";
8
- import Action from "./action";
9
- import Svg from "./svg";
10
-
11
- interface MetaProps {
12
- issue?: Issue;
13
- user?: User;
14
- commentsCount: number;
15
- pagerDirection: GitalkProps["pagerDirection"];
16
- onPagerDirectionChange: (
17
- direction: NonNullable<GitalkProps["pagerDirection"]>,
18
- ) => void;
19
- onLogin: () => void;
20
- onLogout: () => void;
21
- }
22
-
23
- const Meta: React.FC<MetaProps> = (props) => {
24
- const {
25
- issue,
26
- user,
27
- commentsCount,
28
- pagerDirection,
29
- onPagerDirectionChange,
30
- onLogin,
31
- onLogout,
32
- } = props;
33
-
34
- const { polyglot } = useContext(I18nContext);
35
-
36
- const [showPopup, setShowPopup] = useState<boolean>(false);
37
-
38
- const hidePopup = useCallback((e: MouseEvent) => {
39
- const target = e.target as HTMLElement;
40
- if (target && hasClassInParent(target, "gt-user", "gt-popup")) {
41
- return;
42
- }
43
- document.removeEventListener("click", hidePopup);
44
- setShowPopup(false);
45
- }, []);
46
-
47
- const onShowOrHidePopup: React.MouseEventHandler<HTMLDivElement> = (e) => {
48
- e.preventDefault();
49
- e.stopPropagation();
50
-
51
- setShowPopup((visible) => {
52
- if (visible) {
53
- document.removeEventListener("click", hidePopup);
54
- } else {
55
- document.addEventListener("click", hidePopup);
56
- }
57
- return !visible;
58
- });
59
- };
60
-
61
- return (
62
- <div className="gt-meta" key="meta">
63
- <span
64
- className="gt-counts"
65
- dangerouslySetInnerHTML={{
66
- __html: polyglot.t("counts", {
67
- counts: `<a class="gt-link gt-link-counts" href="${issue?.html_url}" target="_blank" rel="noopener noreferrer">${commentsCount}</a>`,
68
- smart_count: commentsCount,
69
- }),
70
- }}
71
- />
72
- {showPopup && (
73
- <div className="gt-popup">
74
- {user
75
- ? [
76
- <Action
77
- key="sort-asc"
78
- className={`gt-action-sortasc${pagerDirection === "first" ? " is--active" : ""}`}
79
- onClick={() => onPagerDirectionChange("first")}
80
- text={polyglot.t("sort-asc")}
81
- />,
82
- <Action
83
- key="sort-desc"
84
- className={`gt-action-sortdesc${pagerDirection === "last" ? " is--active" : ""}`}
85
- onClick={() => onPagerDirectionChange("last")}
86
- text={polyglot.t("sort-desc")}
87
- />,
88
- ]
89
- : null}
90
- {user ? (
91
- <Action
92
- className="gt-action-logout"
93
- onClick={onLogout}
94
- text={polyglot.t("logout")}
95
- />
96
- ) : (
97
- <a className="gt-action gt-action-login" onClick={onLogin}>
98
- {polyglot.t("login-with-github")}
99
- </a>
100
- )}
101
- <div className="gt-copyright">
102
- <a
103
- className="gt-link gt-link-project"
104
- href={HOMEPAGE}
105
- target="_blank"
106
- rel="noopener noreferrer"
107
- >
108
- GitalkR
109
- </a>
110
- <span className="gt-version">{VERSION}</span>
111
- </div>
112
- </div>
113
- )}
114
- <div className="gt-user">
115
- <div
116
- className={`gt-user-inner${showPopup ? " is--poping" : ""}`}
117
- onClick={onShowOrHidePopup}
118
- >
119
- <span className="gt-user-name">
120
- {user?.login ?? polyglot.t("anonymous")}
121
- </span>
122
- <Svg className="gt-ico-arrdown" icon={ArrowDown} />
123
- </div>
124
- </div>
125
- </div>
126
- );
127
- };
128
-
129
- export default Meta;
@@ -1,29 +0,0 @@
1
- import React from "react";
2
-
3
- export interface SVGProps
4
- extends React.DetailedHTMLProps<
5
- React.HTMLAttributes<HTMLSpanElement>,
6
- HTMLSpanElement
7
- > {
8
- icon: string;
9
- text?: string;
10
- }
11
-
12
- const Svg: React.FC<SVGProps> = ({
13
- icon,
14
- text,
15
- className = "",
16
- ...restProps
17
- }) => (
18
- <span className={`gt-ico ${className}`} {...restProps}>
19
- <span
20
- className="gt-svg"
21
- dangerouslySetInnerHTML={{
22
- __html: icon,
23
- }}
24
- />
25
- {text && <span className="gt-ico-text">{text}</span>}
26
- </span>
27
- );
28
-
29
- export default Svg;
@@ -1,57 +0,0 @@
1
- import {
2
- de,
3
- enUS,
4
- es,
5
- faIR,
6
- fr,
7
- ja,
8
- ko,
9
- type Locale,
10
- pl,
11
- ru,
12
- zhCN,
13
- zhTW,
14
- } from "date-fns/locale";
15
-
16
- import packageJson from "../../package.json";
17
- import { type Lang } from "../i18n";
18
- import type { GitalkProps } from "../interfaces";
19
-
20
- export const VERSION = packageJson.version;
21
- export const HOMEPAGE = packageJson.homepage;
22
-
23
- export const DEFAULT_LANG: Lang = "en";
24
- export const DEFAULT_LABELS = ["Gitalk"];
25
- export const DEFAULT_FLIP_MOVE_OPTIONS: GitalkProps["flipMoveOptions"] = {
26
- staggerDelayBy: 150,
27
- appearAnimation: "accordionVertical",
28
- enterAnimation: "accordionVertical",
29
- leaveAnimation: "accordionVertical",
30
- };
31
- export const DEFAULT_PROXY =
32
- "https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token";
33
- export const DEFAULT_AVATAR =
34
- "https://cdn.jsdelivr.net/npm/gitalk@1/src/assets/icon/github.svg";
35
- export const DEFAULT_USER: GitalkProps["defaultUser"] = {
36
- avatar_url: "//avatars1.githubusercontent.com/u/29697133?s=50",
37
- login: "null",
38
- html_url: "",
39
- };
40
-
41
- export const ACCESS_TOKEN_KEY = "GT_ACCESS_TOKEN";
42
- export const STORED_COMMENTS_KEY = "GT_COMMENT";
43
-
44
- export const DATE_FNS_LOCALE_MAP: Record<Lang, Locale> = {
45
- zh: zhCN,
46
- "zh-CN": zhCN,
47
- "zh-TW": zhTW,
48
- en: enUS,
49
- "es-ES": es,
50
- fr,
51
- ru,
52
- de,
53
- pl,
54
- ko,
55
- fa: faIR,
56
- ja,
57
- };
@@ -1,20 +0,0 @@
1
- import { type Locale } from "date-fns";
2
- import type Polyglot from "node-polyglot";
3
- import { createContext } from "react";
4
-
5
- import { DATE_FNS_LOCALE_MAP, DEFAULT_LANG } from "../constants";
6
- import i18n, { type Lang } from "../i18n";
7
-
8
- export interface I18nContextValue {
9
- language: Lang;
10
- polyglot: Polyglot;
11
- dateFnsLocaleMap: Record<string, Locale>;
12
- }
13
-
14
- export const I18nContext = createContext<I18nContextValue>({
15
- language: DEFAULT_LANG,
16
- polyglot: i18n(DEFAULT_LANG),
17
- dateFnsLocaleMap: DATE_FNS_LOCALE_MAP,
18
- });
19
-
20
- export default I18nContext;