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,20 @@
1
+ {
2
+ "init": "Gitalking ...",
3
+ "no-found-related": "Zugehöriger %{link} nicht gefunden",
4
+ "please-contact": "Bitte kontaktiere %{user} um den Kommentar zu initialisieren",
5
+ "init-issue": "Initialisiere Issue",
6
+ "leave-a-comment": "Hinterlasse einen Kommentar",
7
+ "preview": "Vorschau",
8
+ "edit": "Editieren",
9
+ "comment": "Kommentieren",
10
+ "support-markdown": "Markdown wird unterstützt",
11
+ "login-with-github": "Mit GitHub-Account anmelden",
12
+ "first-comment-person": "Sei die erste Person, welche einen Kommentar hinterlässt!",
13
+ "commented": "kommentierte",
14
+ "load-more": "Zeige mehr",
15
+ "counts": "%{counts} Kommentar |||| %{counts} Kommentare",
16
+ "sort-asc": "Älteste zuerst",
17
+ "sort-desc": "Neuste zuerst",
18
+ "logout": "Abmelden",
19
+ "anonymous": "Anonym"
20
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "init": "Gitalking ...",
3
+ "no-found-related": "Related %{link} not found",
4
+ "please-contact": "Please contact %{user} to initialize the comment",
5
+ "init-issue": "Init Issue",
6
+ "leave-a-comment": "Leave a comment",
7
+ "preview": "Preview",
8
+ "edit": "Edit",
9
+ "comment": "Comment",
10
+ "support-markdown": "Markdown is supported",
11
+ "login-with-github": "Login with GitHub",
12
+ "first-comment-person": "Be the first person to leave a comment!",
13
+ "commented": "commented",
14
+ "load-more": "Load more",
15
+ "counts": "%{counts} comment |||| %{counts} comments",
16
+ "sort-asc": "Sort by Oldest",
17
+ "sort-desc": "Sort by Latest",
18
+ "logout": "Logout",
19
+ "anonymous": "Anonymous"
20
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "init": "Gitalking ...",
3
+ "no-found-related": "Link %{link} no encontrado",
4
+ "please-contact": "Por favor contacta con %{user} para inicializar el comentario",
5
+ "init-issue": "Iniciar Issue",
6
+ "leave-a-comment": "Deja un comentario",
7
+ "preview": "Avance",
8
+ "edit": "Editar",
9
+ "comment": "Comentario",
10
+ "support-markdown": "Markdown es soportado",
11
+ "login-with-github": "Entrar con GitHub",
12
+ "first-comment-person": "Sé el primero en dejar un comentario!",
13
+ "commented": "comentó",
14
+ "load-more": "Cargar más",
15
+ "counts": "%{counts} comentario |||| %{counts} comentarios",
16
+ "sort-asc": "Ordenar por Antiguos",
17
+ "sort-desc": "Ordenar por Recientes",
18
+ "logout": "Salir",
19
+ "anonymous": "Anónimo"
20
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "init": "بارگزاری ...",
3
+ "no-found-related": "%{link} مرتبط پیدا نشد.",
4
+ "please-contact": "لطفاً با %{user} اطلاع دهید تا اضافه کند.",
5
+ "init-issue": "شروع نظرات",
6
+ "leave-a-comment": "نظرتان را بنویسید",
7
+ "preview": "پیش‌نمایش",
8
+ "edit": "ویرایش",
9
+ "comment": "ثبت",
10
+ "support-markdown": "پشتیبانی از مارک‌داون",
11
+ "login-with-github": "ورود با گیت‌هاب",
12
+ "first-comment-person": "اولین نظر را شما بنویسید!",
13
+ "commented": " - ",
14
+ "load-more": "نظرات بیشتر",
15
+ "counts": "%{counts} نظر |||| %{counts} نظر",
16
+ "sort-asc": "مرتب‌سازی از قدیمی‌ترین",
17
+ "sort-desc": "مرتب‌سازی از جدیدترین",
18
+ "logout": "خروج",
19
+ "anonymous": "بی‌نام"
20
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "init": "Gitalking ...",
3
+ "no-found-related": "Lien %{link} non trouvé",
4
+ "please-contact": "Veuillez contacter %{user} pour initialiser les commentaires",
5
+ "init-issue": "Initialisation des issues",
6
+ "leave-a-comment": "Laisser un commentaire",
7
+ "preview": "Aperçu",
8
+ "edit": "Modifier",
9
+ "comment": "Commentaire",
10
+ "support-markdown": "Markdown est supporté",
11
+ "login-with-github": "Se connecter avec GitHub",
12
+ "first-comment-person": "Soyez le premier à laisser un commentaire !",
13
+ "commented": "a commenté",
14
+ "load-more": "Charger plus",
15
+ "counts": "%{counts} commentaire |||| %{counts} commentaires",
16
+ "sort-asc": "Trier du plus ancien au plus récent",
17
+ "sort-desc": "Trier du plus récent au plus ancien",
18
+ "logout": "Déconnexion",
19
+ "anonymous": "Anonyme"
20
+ }
@@ -0,0 +1,40 @@
1
+ import Polyglot from "node-polyglot";
2
+
3
+ import { DEFAULT_LANG } from "../constants";
4
+ import DE from "./de.json";
5
+ import EN from "./en.json";
6
+ import ES from "./es-ES.json";
7
+ import FA from "./fa.json";
8
+ import FR from "./fr.json";
9
+ import JA from "./ja.json";
10
+ import KO from "./ko.json";
11
+ import PL from "./pl.json";
12
+ import RU from "./ru.json";
13
+ import ZHCN from "./zh-CN.json";
14
+ import ZHTW from "./zh-TW.json";
15
+
16
+ const i18nMap = {
17
+ zh: ZHCN,
18
+ "zh-CN": ZHCN,
19
+ "zh-TW": ZHTW,
20
+ en: EN,
21
+ "es-ES": ES,
22
+ fr: FR,
23
+ ru: RU,
24
+ de: DE,
25
+ pl: PL,
26
+ ko: KO,
27
+ fa: FA,
28
+ ja: JA,
29
+ };
30
+
31
+ export type Lang = keyof typeof i18nMap;
32
+
33
+ const getPolyglotInstance = (lang: Lang = DEFAULT_LANG) => {
34
+ return new Polyglot({
35
+ phrases: i18nMap[lang] ?? i18nMap.en,
36
+ locale: lang,
37
+ });
38
+ };
39
+
40
+ export default getPolyglotInstance;
@@ -0,0 +1,20 @@
1
+ {
2
+ "init": "Gitalk を読み込んでいます...",
3
+ "no-found-related": "%{link} に関連するものが見当たりません",
4
+ "please-contact": "コメントを初期化するために %{user} に連絡してください",
5
+ "init-issue": "イシューを初期化する",
6
+ "leave-a-comment": "コメントを残す",
7
+ "preview": "プレビュー",
8
+ "edit": "編集する",
9
+ "comment": "コメント",
10
+ "support-markdown": "Markdown 記法をサポートしています",
11
+ "login-with-github": "GitHub にログインする",
12
+ "first-comment-person": "最初にコメントを残しましょう!",
13
+ "commented": "によるコメント",
14
+ "load-more": "もっと見る",
15
+ "counts": "%{counts} つのコメント",
16
+ "sort-asc": "投稿順に並び替え",
17
+ "sort-desc": "最新順で並び替え",
18
+ "logout": "ログアウト",
19
+ "anonymous": "匿名"
20
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "init": "초기화 중 ...",
3
+ "no-found-related": "관련 링크를 찾을 수 없습니다: %{link} ",
4
+ "please-contact": "초기화를 위해 %{user} 에게 연락해 주세요",
5
+ "init-issue": "이슈 초기화",
6
+ "leave-a-comment": "댓글을 남겨보세요",
7
+ "preview": "미리보기",
8
+ "edit": "수정하기",
9
+ "comment": "댓글 달기",
10
+ "support-markdown": "마크다운(Markdown) 문법 지원",
11
+ "login-with-github": "GitHub로 로그인하기",
12
+ "first-comment-person": "첫 번째로 댓글을 남겨보세요!",
13
+ "commented": "님이 작성함",
14
+ "load-more": "더 보기",
15
+ "counts": "댓글 %{counts} 개",
16
+ "sort-asc": "오래된 댓글 먼저",
17
+ "sort-desc": "최신 댓글 먼저",
18
+ "logout": "로그아웃",
19
+ "anonymous": "익명"
20
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "init": "Gitalking ...",
3
+ "no-found-related": "Nie znaleziono powiązanego zgłoszenia: %{link}",
4
+ "please-contact": "Skontaktuj się z %{user}, aby umożliwić komentowanie",
5
+ "init-issue": "Utwórz zgłoszenie (GitHub Issue)",
6
+ "leave-a-comment": "Skomentuj",
7
+ "preview": "Podgląd",
8
+ "edit": "Edytuj",
9
+ "comment": "Wyślij",
10
+ "support-markdown": "Możesz użyć składni Markdown",
11
+ "login-with-github": "Zaloguj się poprzez GitHub",
12
+ "first-comment-person": "Skomentuj jako pierwszy!",
13
+ "commented": "skomentowany",
14
+ "load-more": "Załaduj więcej",
15
+ "counts": "%{counts} komentarz |||| %{counts} komentarze |||| %{counts} komentarzy",
16
+ "sort-asc": "Sortuj od najstarszych",
17
+ "sort-desc": "Sortuj od najnowszych",
18
+ "logout": "Wyloguj",
19
+ "anonymous": "Anonimowy"
20
+ }
21
+
@@ -0,0 +1,20 @@
1
+ {
2
+ "init": "Gitalking ...",
3
+ "no-found-related": "Связанные %{link} не найдены",
4
+ "please-contact": "Пожалуйста, свяжитесь с %{user} чтобы инициализировать комментарий",
5
+ "init-issue": "Выпуск инициализации",
6
+ "leave-a-comment": "Оставить комментарий",
7
+ "preview": "Предварительный просмотр",
8
+ "edit": "Pедактировать",
9
+ "comment": "Комментарий",
10
+ "support-markdown": "Поддерживается Markdown",
11
+ "login-with-github": "Вход через GitHub",
12
+ "first-comment-person": "Будьте первым, кто оставил комментарий",
13
+ "commented": "прокомментированный",
14
+ "load-more": "Загрузить ещё",
15
+ "counts": "%{counts} комментарий |||| %{counts} комментариев",
16
+ "sort-asc": "Сортировать по старым",
17
+ "sort-desc": "Сортировать по последним",
18
+ "logout": "Выход",
19
+ "anonymous": "Анонимный"
20
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "init": "Gitalk 加载中 ...",
3
+ "no-found-related": "未找到相关的 %{link} 进行评论",
4
+ "please-contact": "请联系 %{user} 初始化创建",
5
+ "init-issue": "初始化 Issue",
6
+ "leave-a-comment": "说点什么",
7
+ "preview": "预览",
8
+ "edit": "编辑",
9
+ "comment": "评论",
10
+ "support-markdown": "支持 Markdown 语法",
11
+ "login-with-github": "使用 GitHub 登录",
12
+ "first-comment-person": "来做第一个留言的人吧!",
13
+ "commented": "发表于",
14
+ "load-more": "加载更多",
15
+ "counts": "%{counts} 条评论",
16
+ "sort-asc": "从旧到新排序",
17
+ "sort-desc": "从新到旧排序",
18
+ "logout": "注销",
19
+ "anonymous": "未登录用户"
20
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "init": "Gitalk 載入中…",
3
+ "no-found-related": "未找到相關的 %{link}",
4
+ "please-contact": "請聯絡 %{user} 初始化評論",
5
+ "init-issue": "初始化 Issue",
6
+ "leave-a-comment": "寫點什麼",
7
+ "preview": "預覽",
8
+ "edit": "編輯",
9
+ "comment": "評論",
10
+ "support-markdown": "支援 Markdown 語法",
11
+ "login-with-github": "使用 GitHub 登入",
12
+ "first-comment-person": "成為首個留言的人吧!",
13
+ "commented": "評論於",
14
+ "load-more": "載入更多",
15
+ "counts": "%{counts} 筆評論",
16
+ "sort-asc": "從舊至新排序",
17
+ "sort-desc": "從新至舊排序",
18
+ "logout": "登出",
19
+ "anonymous": "訪客"
20
+ }
@@ -0,0 +1,30 @@
1
+ import type { Endpoints } from "@octokit/types";
2
+
3
+ export type User = Endpoints["GET /user"]["response"]["data"];
4
+
5
+ export type Issue =
6
+ Endpoints["GET /repos/{owner}/{repo}/issues/{issue_number}"]["response"]["data"];
7
+
8
+ type CommentDefine =
9
+ Endpoints["GET /repos/{owner}/{repo}/issues/{issue_number}/comments"]["response"]["data"][number];
10
+
11
+ export type Comment = Pick<
12
+ CommentDefine,
13
+ "id" | "body" | "body_html" | "created_at" | "html_url"
14
+ > & {
15
+ user: Pick<
16
+ NonNullable<CommentDefine["user"]>,
17
+ "avatar_url" | "login" | "html_url"
18
+ >;
19
+ reactions: Pick<NonNullable<CommentDefine["reactions"]>, "heart">;
20
+ reactionsHeart: {
21
+ totalCount: number;
22
+ viewerHasReacted: boolean;
23
+ nodes: {
24
+ databaseId: number;
25
+ user: {
26
+ login: string;
27
+ };
28
+ }[];
29
+ };
30
+ };
@@ -0,0 +1,85 @@
1
+ import { type GitalkProps } from "../../gitalk";
2
+ import type { Comment } from "../../interfaces";
3
+
4
+ export interface IssueCommentsQLResponse {
5
+ repository: {
6
+ issue: {
7
+ comments: {
8
+ totalCount: number;
9
+ pageInfo: {
10
+ hasPreviousPage?: boolean;
11
+ hasNextPage?: boolean;
12
+ startCursor?: string;
13
+ endCursor?: string;
14
+ };
15
+ nodes: (Pick<Comment, "body"> & {
16
+ databaseId: Comment["id"];
17
+ author: {
18
+ avatarUrl: Comment["user"]["avatar_url"];
19
+ login: Comment["user"]["login"];
20
+ url: Comment["user"]["html_url"];
21
+ };
22
+ bodyHTML: Comment["body_html"];
23
+ createdAt: Comment["created_at"];
24
+ resourcePath: Comment["html_url"];
25
+ reactions: Comment["reactionsHeart"];
26
+ })[];
27
+ };
28
+ };
29
+ };
30
+ }
31
+
32
+ export const getIssueCommentsQL = ({
33
+ pagerDirection,
34
+ }: {
35
+ pagerDirection: GitalkProps["pagerDirection"];
36
+ }): string => {
37
+ const cursorDirection = pagerDirection === "last" ? "before" : "after";
38
+
39
+ return `
40
+ query getIssueAndComments(
41
+ $owner: String!,
42
+ $repo: String!,
43
+ $id: Int!,
44
+ $cursor: String,
45
+ $pageSize: Int!
46
+ ) {
47
+ repository(owner: $owner, name: $repo) {
48
+ issue(number: $id) {
49
+ comments(${pagerDirection}: $pageSize, ${cursorDirection}: $cursor) {
50
+ totalCount
51
+ pageInfo {
52
+ ${pagerDirection === "last" ? "hasPreviousPage" : "hasNextPage"}
53
+ ${cursorDirection === "before" ? "startCursor" : "endCursor"}
54
+ }
55
+ nodes {
56
+ databaseId
57
+ author {
58
+ avatarUrl
59
+ login
60
+ url
61
+ }
62
+ body
63
+ bodyHTML
64
+ createdAt
65
+ resourcePath
66
+ reactions(first: 100, content: HEART) {
67
+ totalCount
68
+ viewerHasReacted
69
+ pageInfo {
70
+ hasNextPage
71
+ }
72
+ nodes {
73
+ databaseId
74
+ user {
75
+ login
76
+ }
77
+ }
78
+ }
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }
84
+ `;
85
+ };
@@ -0,0 +1,24 @@
1
+ import { Octokit, type RequestError } from "octokit";
2
+
3
+ import { ACCESS_TOKEN_KEY } from "../constants";
4
+ import logger from "../utils/logger";
5
+
6
+ export const getOctokitInstance = (accessToken?: string) => {
7
+ const _octokit = new Octokit(
8
+ accessToken
9
+ ? {
10
+ auth: accessToken,
11
+ }
12
+ : {},
13
+ );
14
+ _octokit.hook.error("request", (error) => {
15
+ if ((error as RequestError).status === 401) {
16
+ localStorage.removeItem(ACCESS_TOKEN_KEY);
17
+ logger.w(`Access token expired.`);
18
+ }
19
+ throw error;
20
+ });
21
+ return _octokit;
22
+ };
23
+
24
+ export default getOctokitInstance;
@@ -0,0 +1,40 @@
1
+ import { stringifySearchQuery } from "../utils/query";
2
+
3
+ export const getAuthorizeUrl = (clientID: string) => {
4
+ const query = {
5
+ client_id: clientID,
6
+ redirect_uri: window.location.href,
7
+ scope: "public_repo",
8
+ };
9
+ return `https://github.com/login/oauth/authorize?${stringifySearchQuery(query)}`;
10
+ };
11
+
12
+ export const getAccessToken = async ({
13
+ url,
14
+ code,
15
+ clientID,
16
+ clientSecret,
17
+ }: {
18
+ url: string;
19
+ code: string;
20
+ clientID: string;
21
+ clientSecret: string;
22
+ }) => {
23
+ const res = await fetch(url, {
24
+ method: "POST",
25
+ headers: {
26
+ Accept: "application/json",
27
+ "Content-Type": "application/json",
28
+ },
29
+ body: JSON.stringify({
30
+ code,
31
+ client_id: clientID,
32
+ client_secret: clientSecret,
33
+ }),
34
+ });
35
+
36
+ const resData = await res.json();
37
+ const { access_token } = resData;
38
+
39
+ return access_token as string;
40
+ };