gitalk-react 1.0.0 → 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 (63) hide show
  1. package/README-zh-CN.md +152 -53
  2. package/README.md +132 -34
  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 +2737 -10382
  11. package/package.json +61 -41
  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 -623
  16. package/dist/gitalk.umd.cjs +0 -126
  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 -166
  28. package/lib/components/comment.tsx +0 -204
  29. package/lib/components/comments-list.tsx +0 -112
  30. package/lib/components/meta.tsx +0 -133
  31. package/lib/components/svg.tsx +0 -29
  32. package/lib/constants/index.ts +0 -71
  33. package/lib/contexts/I18nContext.ts +0 -20
  34. package/lib/gitalk.tsx +0 -891
  35. package/lib/i18n/ar.json +0 -20
  36. package/lib/i18n/bn.json +0 -20
  37. package/lib/i18n/de.json +0 -20
  38. package/lib/i18n/en.json +0 -20
  39. package/lib/i18n/es.json +0 -20
  40. package/lib/i18n/fa.json +0 -20
  41. package/lib/i18n/fr.json +0 -20
  42. package/lib/i18n/hi.json +0 -20
  43. package/lib/i18n/index.ts +0 -53
  44. package/lib/i18n/ja.json +0 -20
  45. package/lib/i18n/ko.json +0 -20
  46. package/lib/i18n/pl.json +0 -21
  47. package/lib/i18n/pt.json +0 -20
  48. package/lib/i18n/ru.json +0 -20
  49. package/lib/i18n/ur.json +0 -20
  50. package/lib/i18n/zh-CN.json +0 -20
  51. package/lib/i18n/zh-TW.json +0 -20
  52. package/lib/interfaces/index.ts +0 -198
  53. package/lib/services/graphql/comment.ts +0 -84
  54. package/lib/services/request.ts +0 -24
  55. package/lib/services/user.ts +0 -40
  56. package/lib/themes/base.scss +0 -630
  57. package/lib/themes/gitalk-dark.scss +0 -28
  58. package/lib/themes/gitalk-light.scss +0 -28
  59. package/lib/utils/compatibility.ts +0 -35
  60. package/lib/utils/dom.ts +0 -15
  61. package/lib/utils/logger.ts +0 -66
  62. package/lib/utils/query.ts +0 -19
  63. package/lib/vite-env.d.ts +0 -1
@@ -1,133 +0,0 @@
1
- import cn from "classnames";
2
- import React, { useContext, useState } from "react";
3
-
4
- import ArrowDown from "../assets/arrow-down.svg?raw";
5
- import { HOMEPAGE, VERSION } from "../constants";
6
- import I18nContext from "../contexts/I18nContext";
7
- import type { GitalkProps, Issue, User } from "../interfaces";
8
- import { hasClassInParent } from "../utils/dom";
9
- import Action from "./action";
10
- import Svg from "./svg";
11
-
12
- interface MetaProps extends Pick<GitalkProps, "pagerDirection"> {
13
- issue?: Issue;
14
- user?: User;
15
- commentsCount: number;
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
- function hidePopup(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={cn("gt-action-sortasc", {
79
- "is--active": pagerDirection === "first",
80
- })}
81
- onClick={() => onPagerDirectionChange("first")}
82
- text={polyglot.t("sort-asc")}
83
- />,
84
- <Action
85
- key="sort-desc"
86
- className={cn("gt-action-sortdesc", {
87
- "is--active": pagerDirection === "last",
88
- })}
89
- onClick={() => onPagerDirectionChange("last")}
90
- text={polyglot.t("sort-desc")}
91
- />,
92
- ]
93
- : null}
94
- {user ? (
95
- <Action
96
- className="gt-action-logout"
97
- onClick={onLogout}
98
- text={polyglot.t("logout")}
99
- />
100
- ) : (
101
- <a className="gt-action gt-action-login" onClick={onLogin}>
102
- {polyglot.t("login-with-github")}
103
- </a>
104
- )}
105
- <div className="gt-copyright">
106
- <a
107
- className="gt-link gt-link-project"
108
- href={HOMEPAGE}
109
- target="_blank"
110
- rel="noopener noreferrer"
111
- >
112
- GitalkR
113
- </a>
114
- <span className="gt-version">{VERSION}</span>
115
- </div>
116
- </div>
117
- )}
118
- <div className="gt-user">
119
- <div
120
- className={cn("gt-user-inner", { "is--poping": showPopup })}
121
- onClick={onShowOrHidePopup}
122
- >
123
- <span className="gt-user-name">
124
- {user?.login ?? polyglot.t("anonymous")}
125
- </span>
126
- <Svg className="gt-ico-arrdown" icon={ArrowDown} />
127
- </div>
128
- </div>
129
- </div>
130
- );
131
- };
132
-
133
- export default Meta;
@@ -1,29 +0,0 @@
1
- import cn from "classnames";
2
- import React from "react";
3
-
4
- export interface SVGProps 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={cn("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,71 +0,0 @@
1
- import {
2
- ar,
3
- bn,
4
- de,
5
- enUS,
6
- es,
7
- faIR,
8
- fr,
9
- hi,
10
- ja,
11
- ko,
12
- type Locale,
13
- pl,
14
- pt,
15
- ru,
16
- zhCN,
17
- zhTW,
18
- } from "date-fns/locale";
19
-
20
- import packageJson from "../../package.json";
21
- import { type Lang } from "../i18n";
22
- import type { GitalkProps } from "../interfaces";
23
-
24
- export const VERSION = packageJson.version;
25
- export const HOMEPAGE = packageJson.homepage;
26
-
27
- export const DEFAULT_LANG: Lang = "en";
28
- export const DEFAULT_LABELS = ["Gitalk"];
29
- export const DEFAULT_FLIP_MOVE_OPTIONS: NonNullable<
30
- GitalkProps["flipMoveOptions"]
31
- > = {
32
- staggerDelayBy: 150,
33
- appearAnimation: "accordionVertical",
34
- enterAnimation: "accordionVertical",
35
- leaveAnimation: "accordionVertical",
36
- };
37
- export const DEFAULT_PROXY =
38
- "https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token";
39
- export const DEFAULT_AVATAR =
40
- "https://cdn.jsdelivr.net/npm/gitalk@1/src/assets/icon/github.svg";
41
- export const DEFAULT_USER: GitalkProps["defaultUser"] = {
42
- avatar_url: "//avatars1.githubusercontent.com/u/29697133?s=50",
43
- login: "null",
44
- html_url: "",
45
- };
46
-
47
- export const ACCESS_TOKEN_KEY = "GT_ACCESS_TOKEN";
48
- export const STORED_COMMENTS_KEY = "GT_COMMENT";
49
-
50
- export const DATE_FNS_LOCALE_MAP: Record<Lang, Locale> = {
51
- en: enUS,
52
- zh: zhCN,
53
- "zh-CN": zhCN,
54
- "zh-SG": zhCN,
55
- "zh-TW": zhTW,
56
- "zh-HK": zhTW,
57
- "zh-MO": zhTW,
58
- hi: hi,
59
- es: es,
60
- fr: fr,
61
- ar: ar,
62
- bn: bn,
63
- ru: ru,
64
- pt: pt,
65
- ur: enUS,
66
- ko: ko,
67
- ja: ja,
68
- de: de,
69
- pl: pl,
70
- fa: faIR,
71
- };
@@ -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;