@the-seeker/changes-react 0.0.0-stage → 0.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.
- package/README.md +104 -2
- package/dist/core/cache.d.ts +14 -0
- package/dist/core/cache.js +34 -0
- package/dist/core/client.d.ts +161 -0
- package/dist/core/client.js +97 -0
- package/dist/core/decide.d.ts +16 -0
- package/dist/core/decide.js +57 -0
- package/dist/core/rating.d.ts +7 -0
- package/dist/core/rating.js +18 -0
- package/dist/core/storage.d.ts +20 -0
- package/dist/core/storage.js +73 -0
- package/dist/core/types.d.ts +332 -0
- package/dist/core/types.js +126 -0
- package/dist/core/versions.d.ts +2 -0
- package/dist/core/versions.js +20 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +47 -0
- package/dist/web/Blocks.d.ts +5 -0
- package/dist/web/Blocks.js +42 -0
- package/dist/web/ChangelogButton.d.ts +5 -0
- package/dist/web/ChangelogButton.js +17 -0
- package/dist/web/ChangelogDialog.d.ts +2 -0
- package/dist/web/ChangelogDialog.js +19 -0
- package/dist/web/ChangelogList.d.ts +2 -0
- package/dist/web/ChangelogList.js +32 -0
- package/dist/web/CommentComposer.d.ts +9 -0
- package/dist/web/CommentComposer.js +47 -0
- package/dist/web/CommentItem.d.ts +11 -0
- package/dist/web/CommentItem.js +23 -0
- package/dist/web/CommentsThread.d.ts +4 -0
- package/dist/web/CommentsThread.js +15 -0
- package/dist/web/DialogShell.d.ts +11 -0
- package/dist/web/DialogShell.js +36 -0
- package/dist/web/Provider.d.ts +24 -0
- package/dist/web/Provider.js +109 -0
- package/dist/web/ReleaseCard.d.ts +5 -0
- package/dist/web/ReleaseCard.js +23 -0
- package/dist/web/ReleaseEngagement.d.ts +5 -0
- package/dist/web/ReleaseEngagement.js +24 -0
- package/dist/web/ReleaseSummary.d.ts +8 -0
- package/dist/web/ReleaseSummary.js +15 -0
- package/dist/web/ReportMenu.d.ts +4 -0
- package/dist/web/ReportMenu.js +79 -0
- package/dist/web/VoteCapsule.d.ts +9 -0
- package/dist/web/VoteCapsule.js +12 -0
- package/dist/web/WhatsNewModal.d.ts +2 -0
- package/dist/web/WhatsNewModal.js +26 -0
- package/dist/web/context.d.ts +82 -0
- package/dist/web/context.js +5 -0
- package/dist/web/controls-css.d.ts +1 -0
- package/dist/web/controls-css.js +48 -0
- package/dist/web/focus-trap.d.ts +7 -0
- package/dist/web/focus-trap.js +69 -0
- package/dist/web/icons.d.ts +17 -0
- package/dist/web/icons.js +29 -0
- package/dist/web/links.d.ts +11 -0
- package/dist/web/links.js +45 -0
- package/dist/web/load.d.ts +35 -0
- package/dist/web/load.js +61 -0
- package/dist/web/local-store.d.ts +7 -0
- package/dist/web/local-store.js +27 -0
- package/dist/web/model.d.ts +36 -0
- package/dist/web/model.js +37 -0
- package/dist/web/storage.d.ts +7 -0
- package/dist/web/storage.js +53 -0
- package/dist/web/styles.d.ts +273 -0
- package/dist/web/styles.js +201 -0
- package/dist/web/texts-defaults.d.ts +115 -0
- package/dist/web/texts-defaults.js +117 -0
- package/dist/web/texts.d.ts +9 -0
- package/dist/web/texts.js +49 -0
- package/dist/web/theme.d.ts +6 -0
- package/dist/web/theme.js +82 -0
- package/dist/web/use-actions.d.ts +10 -0
- package/dist/web/use-actions.js +114 -0
- package/dist/web/use-comments-api.d.ts +5 -0
- package/dist/web/use-comments-api.js +75 -0
- package/dist/web/use-thread.d.ts +23 -0
- package/dist/web/use-thread.js +82 -0
- package/dist/web/useChanges.d.ts +5 -0
- package/dist/web/useChanges.js +19 -0
- package/package.json +33 -3
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_TEXTS = void 0;
|
|
4
|
+
// Server text keys mirror crm src/lib/changes/texts.ts DEFAULT_CHANGES_TEXTS; the SDK keys after
|
|
5
|
+
// `tag_deprecated` exist only in the SDK (error, empty and pagination states the server never renders).
|
|
6
|
+
exports.DEFAULT_TEXTS = {
|
|
7
|
+
ko: {
|
|
8
|
+
title: "업데이트",
|
|
9
|
+
subtitle: "더 나은 경험을 위한 새로운 소식",
|
|
10
|
+
whatsNew: "새로운 소식",
|
|
11
|
+
viewAll: "전체 보기",
|
|
12
|
+
close: "닫기",
|
|
13
|
+
continue: "계속",
|
|
14
|
+
readUpdate: "업데이트 읽기",
|
|
15
|
+
upvote: "좋아요",
|
|
16
|
+
downvote: "아쉬워요",
|
|
17
|
+
comments: "댓글",
|
|
18
|
+
viewComments: "댓글 보기",
|
|
19
|
+
writeComment: "댓글 쓰기",
|
|
20
|
+
commentPlaceholder: "의견을 남겨 주세요",
|
|
21
|
+
commentSubmit: "댓글 등록",
|
|
22
|
+
reply: "답글",
|
|
23
|
+
developerBadge: "개발자",
|
|
24
|
+
report: "신고",
|
|
25
|
+
reportReasons_spam: "스팸",
|
|
26
|
+
reportReasons_abuse: "욕설 및 괴롭힘",
|
|
27
|
+
reportReasons_off_topic: "주제와 무관",
|
|
28
|
+
reportReasons_other: "기타",
|
|
29
|
+
reported: "신고되었습니다",
|
|
30
|
+
guidelinesTitle: "커뮤니티 이용 안내",
|
|
31
|
+
guidelinesBody: "서로를 존중하며 업데이트에 관한 의견을 나눠 주세요. 개인정보, 스팸, 욕설 및 괴롭힘은 허용되지 않습니다.",
|
|
32
|
+
guidelinesAccept: "이용 안내를 읽고 동의합니다",
|
|
33
|
+
feedbackLabel: "개발자에게 의견 보내기",
|
|
34
|
+
feedbackPlaceholder: "어떤 점을 개선하면 좋을까요?",
|
|
35
|
+
feedbackSubmit: "의견 보내기",
|
|
36
|
+
feedbackThanks: "의견을 보내 주셔서 감사합니다",
|
|
37
|
+
rateAppStore: "App Store에서 평가",
|
|
38
|
+
ratePlay: "Google Play에서 평가",
|
|
39
|
+
rateWeb: "리뷰 남기기",
|
|
40
|
+
empty: "아직 업데이트가 없습니다",
|
|
41
|
+
loadError: "소식을 불러오지 못했습니다",
|
|
42
|
+
offline: "오프라인입니다. 저장된 소식을 표시합니다",
|
|
43
|
+
contactDeveloper: "개발자에게 문의",
|
|
44
|
+
tag_new: "새 기능",
|
|
45
|
+
tag_improved: "개선",
|
|
46
|
+
tag_fixed: "수정",
|
|
47
|
+
tag_security: "보안",
|
|
48
|
+
tag_deprecated: "지원 중단 예정",
|
|
49
|
+
unreadCount: "새 소식 {count}개",
|
|
50
|
+
commentCount: "댓글 {count}개",
|
|
51
|
+
noComments: "아직 댓글이 없습니다. 첫 의견을 남겨 보세요",
|
|
52
|
+
loadMore: "댓글 더 보기",
|
|
53
|
+
cancel: "취소",
|
|
54
|
+
retry: "다시 시도",
|
|
55
|
+
commentMenu: "댓글 메뉴",
|
|
56
|
+
errorBanned: "이 커뮤니티에서는 더 이상 댓글을 쓰거나 투표할 수 없습니다",
|
|
57
|
+
errorCommentsDisabled: "지금은 댓글을 쓸 수 없습니다",
|
|
58
|
+
errorRateLimited: "댓글을 너무 자주 등록했습니다. 몇 분 뒤 다시 시도해 주세요",
|
|
59
|
+
errorGuidelines: "댓글을 등록하려면 이용 안내에 동의해 주세요",
|
|
60
|
+
errorGeneric: "보내지 못했습니다. 연결을 확인하고 다시 시도해 주세요",
|
|
61
|
+
},
|
|
62
|
+
en: {
|
|
63
|
+
title: "Updates",
|
|
64
|
+
subtitle: "The latest improvements to your experience",
|
|
65
|
+
whatsNew: "What's new",
|
|
66
|
+
viewAll: "View all",
|
|
67
|
+
close: "Close",
|
|
68
|
+
continue: "Continue",
|
|
69
|
+
readUpdate: "Read update",
|
|
70
|
+
upvote: "Upvote",
|
|
71
|
+
downvote: "Downvote",
|
|
72
|
+
comments: "Comments",
|
|
73
|
+
viewComments: "View comments",
|
|
74
|
+
writeComment: "Write a comment",
|
|
75
|
+
commentPlaceholder: "Share your thoughts",
|
|
76
|
+
commentSubmit: "Post comment",
|
|
77
|
+
reply: "Reply",
|
|
78
|
+
developerBadge: "Developer",
|
|
79
|
+
report: "Report",
|
|
80
|
+
reportReasons_spam: "Spam",
|
|
81
|
+
reportReasons_abuse: "Abuse or harassment",
|
|
82
|
+
reportReasons_off_topic: "Off topic",
|
|
83
|
+
reportReasons_other: "Other",
|
|
84
|
+
reported: "Reported",
|
|
85
|
+
guidelinesTitle: "Community guidelines",
|
|
86
|
+
guidelinesBody: "Respect others and keep comments relevant to the update. Personal information, spam, abuse and harassment are not allowed.",
|
|
87
|
+
guidelinesAccept: "I have read and accept the guidelines",
|
|
88
|
+
feedbackLabel: "Send feedback to the developer",
|
|
89
|
+
feedbackPlaceholder: "What could we improve?",
|
|
90
|
+
feedbackSubmit: "Send feedback",
|
|
91
|
+
feedbackThanks: "Thank you for your feedback",
|
|
92
|
+
rateAppStore: "Rate on the App Store",
|
|
93
|
+
ratePlay: "Rate on Google Play",
|
|
94
|
+
rateWeb: "Write a review",
|
|
95
|
+
empty: "No updates yet",
|
|
96
|
+
loadError: "Could not load updates",
|
|
97
|
+
offline: "You are offline. Showing saved updates",
|
|
98
|
+
contactDeveloper: "Contact developer",
|
|
99
|
+
tag_new: "New",
|
|
100
|
+
tag_improved: "Improved",
|
|
101
|
+
tag_fixed: "Fixed",
|
|
102
|
+
tag_security: "Security",
|
|
103
|
+
tag_deprecated: "Deprecated",
|
|
104
|
+
unreadCount: "{count} new",
|
|
105
|
+
commentCount: "{count} comments",
|
|
106
|
+
noComments: "No comments yet. Start the conversation",
|
|
107
|
+
loadMore: "Show more comments",
|
|
108
|
+
cancel: "Cancel",
|
|
109
|
+
retry: "Try again",
|
|
110
|
+
commentMenu: "Comment menu",
|
|
111
|
+
errorBanned: "You can no longer comment or vote in this community",
|
|
112
|
+
errorCommentsDisabled: "Comments are turned off right now",
|
|
113
|
+
errorRateLimited: "You are posting too often. Try again in a few minutes",
|
|
114
|
+
errorGuidelines: "Accept the guidelines to post a comment",
|
|
115
|
+
errorGeneric: "Unable to send. Check your connection and try again",
|
|
116
|
+
},
|
|
117
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Config } from "../core/types";
|
|
2
|
+
import type { Locale, Texts } from "./texts-defaults";
|
|
3
|
+
export type { Locale, TextKey, Texts } from "./texts-defaults";
|
|
4
|
+
export type LocalePreference = "auto" | Locale;
|
|
5
|
+
export declare function resolveLocale(preference: LocalePreference, config: Config | null, languages: readonly string[]): Locale;
|
|
6
|
+
export declare function resolveTexts(config: Config | null, locale: Locale): Texts;
|
|
7
|
+
export declare function fillCount(template: string, count: number): string;
|
|
8
|
+
export declare function formatDate(iso: string, locale: Locale): string;
|
|
9
|
+
export declare function formatShortDate(iso: string, locale: Locale): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveLocale = resolveLocale;
|
|
4
|
+
exports.resolveTexts = resolveTexts;
|
|
5
|
+
exports.fillCount = fillCount;
|
|
6
|
+
exports.formatDate = formatDate;
|
|
7
|
+
exports.formatShortDate = formatShortDate;
|
|
8
|
+
const texts_defaults_1 = require("./texts-defaults");
|
|
9
|
+
function resolveLocale(preference, config, languages) {
|
|
10
|
+
if (preference !== "auto")
|
|
11
|
+
return preference;
|
|
12
|
+
for (const language of languages) {
|
|
13
|
+
const lower = language.toLowerCase();
|
|
14
|
+
if (lower.startsWith("ko"))
|
|
15
|
+
return "ko";
|
|
16
|
+
if (lower.startsWith("en"))
|
|
17
|
+
return "en";
|
|
18
|
+
}
|
|
19
|
+
return config?.defaultLocale ?? "ko";
|
|
20
|
+
}
|
|
21
|
+
function resolveTexts(config, locale) {
|
|
22
|
+
const defaults = texts_defaults_1.DEFAULT_TEXTS[locale];
|
|
23
|
+
const custom = config?.texts[locale];
|
|
24
|
+
if (!custom)
|
|
25
|
+
return defaults;
|
|
26
|
+
const merged = { ...defaults };
|
|
27
|
+
for (const key of Object.keys(defaults)) {
|
|
28
|
+
const value = custom[key];
|
|
29
|
+
if (isTextKey(key) && value)
|
|
30
|
+
merged[key] = value;
|
|
31
|
+
}
|
|
32
|
+
return merged;
|
|
33
|
+
}
|
|
34
|
+
function isTextKey(key) {
|
|
35
|
+
return Object.prototype.hasOwnProperty.call(texts_defaults_1.DEFAULT_TEXTS.ko, key);
|
|
36
|
+
}
|
|
37
|
+
function fillCount(template, count) {
|
|
38
|
+
return template.replace("{count}", String(count));
|
|
39
|
+
}
|
|
40
|
+
function formatDate(iso, locale) {
|
|
41
|
+
return new Intl.DateTimeFormat(locale === "ko" ? "ko-KR" : "en-US", {
|
|
42
|
+
year: "numeric",
|
|
43
|
+
month: "long",
|
|
44
|
+
day: "numeric",
|
|
45
|
+
}).format(new Date(iso));
|
|
46
|
+
}
|
|
47
|
+
function formatShortDate(iso, locale) {
|
|
48
|
+
return new Intl.DateTimeFormat(locale === "ko" ? "ko-KR" : "en-US", { month: "short", day: "numeric" }).format(new Date(iso));
|
|
49
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CSSProperties } from "react";
|
|
2
|
+
export type ColorScheme = "auto" | "light" | "dark";
|
|
3
|
+
export declare const DEFAULT_ACCENT = "#5e6ad2";
|
|
4
|
+
/** CSS variables for one SDK root: the project accent, its label color and its translucent steps. */
|
|
5
|
+
export declare function accentVars(accentColor: string | undefined): CSSProperties & Readonly<Record<`--${string}`, string>>;
|
|
6
|
+
export declare const THEME_CSS: string;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.THEME_CSS = exports.DEFAULT_ACCENT = void 0;
|
|
4
|
+
exports.accentVars = accentVars;
|
|
5
|
+
// Neutral ramp, status and elevation values copy the CRM Linear tokens (crm DESIGN.md §2.1/§2.2:
|
|
6
|
+
// surface-2, surface, hover, active, border*, fg*, status-down, backdrop, dialog/overlay shadow).
|
|
7
|
+
// Only the accent comes from the project config (`--tsc-accent`).
|
|
8
|
+
const LIGHT = [
|
|
9
|
+
"--tsc-surface:#ffffff",
|
|
10
|
+
"--tsc-control:#fbfbfb",
|
|
11
|
+
"--tsc-hover:#f3f3f4",
|
|
12
|
+
"--tsc-active:#ececee",
|
|
13
|
+
"--tsc-border:#e6e6e6",
|
|
14
|
+
"--tsc-border-subtle:#efefef",
|
|
15
|
+
"--tsc-border-strong:#d8d8da",
|
|
16
|
+
"--tsc-fg:#1b1c1e",
|
|
17
|
+
"--tsc-fg-2:#6b6f76",
|
|
18
|
+
"--tsc-fg-3:#8f939a",
|
|
19
|
+
"--tsc-danger-soft:rgba(217,61,66,.1)",
|
|
20
|
+
"--tsc-backdrop:rgba(20,20,24,.28)",
|
|
21
|
+
"--tsc-shadow:0 0 0 1px rgba(0,0,0,.06),0 16px 70px rgba(0,0,0,.18)",
|
|
22
|
+
"--tsc-menu-shadow:0 0 0 1px rgba(0,0,0,.06),0 4px 12px -2px rgba(0,0,0,.08),0 16px 32px -8px rgba(0,0,0,.12)",
|
|
23
|
+
"--tsc-accent-soft:var(--tsc-accent-soft-light)",
|
|
24
|
+
"--tsc-accent-ring:var(--tsc-accent-ring-light)",
|
|
25
|
+
"color-scheme:light",
|
|
26
|
+
].join(";");
|
|
27
|
+
const DARK = [
|
|
28
|
+
"--tsc-surface:#1c1d1f",
|
|
29
|
+
"--tsc-control:#161718",
|
|
30
|
+
"--tsc-hover:#232427",
|
|
31
|
+
"--tsc-active:#232427",
|
|
32
|
+
"--tsc-border:rgba(255,255,255,.08)",
|
|
33
|
+
"--tsc-border-subtle:rgba(255,255,255,.05)",
|
|
34
|
+
"--tsc-border-strong:rgba(255,255,255,.14)",
|
|
35
|
+
"--tsc-fg:#f7f8f8",
|
|
36
|
+
"--tsc-fg-2:#8a8f98",
|
|
37
|
+
"--tsc-fg-3:#62666d",
|
|
38
|
+
"--tsc-danger-soft:rgba(229,72,77,.14)",
|
|
39
|
+
"--tsc-backdrop:rgba(0,0,0,.55)",
|
|
40
|
+
"--tsc-shadow:0 0 0 1px rgba(255,255,255,.08),0 16px 70px rgba(0,0,0,.6)",
|
|
41
|
+
"--tsc-menu-shadow:0 0 0 1px rgba(255,255,255,.06),0 8px 16px -4px rgba(0,0,0,.5),0 24px 48px -12px rgba(0,0,0,.6)",
|
|
42
|
+
"--tsc-accent-soft:var(--tsc-accent-soft-dark)",
|
|
43
|
+
"--tsc-accent-ring:var(--tsc-accent-ring-dark)",
|
|
44
|
+
"color-scheme:dark",
|
|
45
|
+
].join(";");
|
|
46
|
+
exports.DEFAULT_ACCENT = "#5e6ad2";
|
|
47
|
+
function channels(hex) {
|
|
48
|
+
const value = Number.parseInt(hex.slice(1), 16);
|
|
49
|
+
return [(value >> 16) & 255, (value >> 8) & 255, value & 255];
|
|
50
|
+
}
|
|
51
|
+
function luminance([red, green, blue]) {
|
|
52
|
+
const linear = (channel) => {
|
|
53
|
+
const scaled = channel / 255;
|
|
54
|
+
return scaled <= 0.04045 ? scaled / 12.92 : ((scaled + 0.055) / 1.055) ** 2.4;
|
|
55
|
+
};
|
|
56
|
+
return 0.2126 * linear(red) + 0.7152 * linear(green) + 0.0722 * linear(blue);
|
|
57
|
+
}
|
|
58
|
+
/** CSS variables for one SDK root: the project accent, its label color and its translucent steps. */
|
|
59
|
+
function accentVars(accentColor) {
|
|
60
|
+
const accent = accentColor && /^#[0-9a-fA-F]{6}$/.test(accentColor) ? accentColor : exports.DEFAULT_ACCENT;
|
|
61
|
+
const rgb = channels(accent);
|
|
62
|
+
const level = luminance(rgb);
|
|
63
|
+
const whiteContrast = 1.05 / (level + 0.05);
|
|
64
|
+
const darkContrast = (level + 0.05) / (luminance(channels("#1b1c1e")) + 0.05);
|
|
65
|
+
const alpha = (value) => `rgba(${rgb.join(",")},${value})`;
|
|
66
|
+
return {
|
|
67
|
+
"--tsc-accent": accent,
|
|
68
|
+
"--tsc-accent-fg": whiteContrast >= darkContrast ? "#ffffff" : "#1b1c1e",
|
|
69
|
+
"--tsc-accent-soft-light": alpha(0.1),
|
|
70
|
+
"--tsc-accent-soft-dark": alpha(0.16),
|
|
71
|
+
"--tsc-accent-ring-light": alpha(0.4),
|
|
72
|
+
"--tsc-accent-ring-dark": alpha(0.55),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
exports.THEME_CSS = [
|
|
76
|
+
`[data-tsc]{${LIGHT};--tsc-ease:cubic-bezier(.215,.61,.355,1);--tsc-mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;color:var(--tsc-fg);word-break:keep-all;overflow-wrap:break-word;-webkit-tap-highlight-color:transparent}`,
|
|
77
|
+
`@media (prefers-color-scheme:dark){[data-tsc]:not([data-tsc-scheme=light]){${DARK}}}`,
|
|
78
|
+
`[data-tsc][data-tsc-scheme=dark]{${DARK}}`,
|
|
79
|
+
// :where() keeps these resets at zero specificity so component rules always win.
|
|
80
|
+
`:where([data-tsc]),:where([data-tsc]) *,:where([data-tsc]) *::before,:where([data-tsc]) *::after{box-sizing:border-box}`,
|
|
81
|
+
`:where([data-tsc]) :where(button,textarea,input){font:inherit;color:inherit;margin:0}`,
|
|
82
|
+
].join("\n");
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Dispatch, SetStateAction } from "react";
|
|
2
|
+
import type { ErrorCode, Failure } from "../core/types";
|
|
3
|
+
import type { ChangesContextValue } from "./context";
|
|
4
|
+
import type { Model } from "./model";
|
|
5
|
+
type SetModel = Dispatch<SetStateAction<Model>>;
|
|
6
|
+
export type Actions = Pick<ChangesContextValue, "vote" | "sendFeedback" | "openChangelog" | "closeChangelog" | "markPresented" | "dismissWhatsNew" | "openRating" | "comments" | "acceptGuidelines">;
|
|
7
|
+
export declare const notReady: Failure;
|
|
8
|
+
export declare const failure: (code: ErrorCode) => Failure;
|
|
9
|
+
export declare function useActions(model: Model, setModel: SetModel): Actions;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.failure = exports.notReady = void 0;
|
|
4
|
+
exports.useActions = useActions;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const decide_1 = require("../core/decide");
|
|
7
|
+
const storage_1 = require("../core/storage");
|
|
8
|
+
const links_1 = require("./links");
|
|
9
|
+
const local_store_1 = require("./local-store");
|
|
10
|
+
const model_1 = require("./model");
|
|
11
|
+
const use_comments_api_1 = require("./use-comments-api");
|
|
12
|
+
exports.notReady = { ok: false, code: "NETWORK_ERROR" };
|
|
13
|
+
const failure = (code) => ({ ok: false, code });
|
|
14
|
+
exports.failure = failure;
|
|
15
|
+
function useActions(model, setModel) {
|
|
16
|
+
const { runtime, config, state, votes, releases } = model;
|
|
17
|
+
const presented = (0, react_1.useRef)(new Set());
|
|
18
|
+
const vote = (0, react_1.useCallback)(async (releaseId, value) => {
|
|
19
|
+
if (runtime === null)
|
|
20
|
+
return exports.notReady;
|
|
21
|
+
if (config !== null && !config.community.votesEnabled)
|
|
22
|
+
return (0, exports.failure)("VOTES_DISABLED");
|
|
23
|
+
const current = releases.find((release) => release.id === releaseId);
|
|
24
|
+
if (current === undefined)
|
|
25
|
+
return (0, exports.failure)("RELEASE_NOT_FOUND");
|
|
26
|
+
const before = (0, model_1.releaseView)(model, current);
|
|
27
|
+
setModel((next) => (0, model_1.withOverride)(next, releaseId, (0, model_1.optimisticVote)(before, value)));
|
|
28
|
+
const result = await runtime.client.vote({ releaseId, value, voter: { installId: runtime.installId } });
|
|
29
|
+
if (!result.ok) {
|
|
30
|
+
const { upvotes, downvotes, myVote } = before;
|
|
31
|
+
setModel((next) => ({
|
|
32
|
+
...(0, model_1.withOverride)(next, releaseId, { upvotes, downvotes, myVote }),
|
|
33
|
+
banned: next.banned || result.code === "BANNED",
|
|
34
|
+
}));
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
const nextVotes = (0, local_store_1.withVote)(votes, releaseId, result.body.myVote);
|
|
38
|
+
setModel((next) => ({ ...(0, model_1.withOverride)(next, releaseId, result.body), votes: nextVotes }));
|
|
39
|
+
await (0, local_store_1.writeVotes)(runtime.storage, runtime.key, nextVotes);
|
|
40
|
+
return result;
|
|
41
|
+
}, [runtime, config, releases, model, votes, setModel]);
|
|
42
|
+
const sendFeedback = (0, react_1.useCallback)(async (input) => {
|
|
43
|
+
if (runtime === null)
|
|
44
|
+
return exports.notReady;
|
|
45
|
+
const pageUrl = typeof location === "undefined" ? undefined : location.href;
|
|
46
|
+
return runtime.client.sendFeedback({
|
|
47
|
+
releaseId: input.releaseId,
|
|
48
|
+
message: input.message,
|
|
49
|
+
voter: { installId: runtime.installId },
|
|
50
|
+
client: { platform: "web" },
|
|
51
|
+
...(input.email ? { email: input.email } : {}),
|
|
52
|
+
...(pageUrl ? { pageUrl } : {}),
|
|
53
|
+
});
|
|
54
|
+
}, [runtime]);
|
|
55
|
+
const persistState = (0, react_1.useCallback)((active, next) => {
|
|
56
|
+
setModel((current) => ({ ...current, state: next }));
|
|
57
|
+
void (0, storage_1.writeState)(active.storage, active.key, next);
|
|
58
|
+
}, [setModel]);
|
|
59
|
+
const openChangelog = (0, react_1.useCallback)(() => {
|
|
60
|
+
setModel((current) => ({ ...current, changelogOpen: true }));
|
|
61
|
+
if (runtime !== null && state !== null)
|
|
62
|
+
persistState(runtime, (0, decide_1.markListOpened)(state, new Date().toISOString()));
|
|
63
|
+
}, [runtime, state, persistState, setModel]);
|
|
64
|
+
const closeChangelog = (0, react_1.useCallback)(() => setModel((current) => ({ ...current, changelogOpen: false })), [setModel]);
|
|
65
|
+
const dismissWhatsNew = (0, react_1.useCallback)(() => setModel((current) => ({ ...current, pending: null })), [setModel]);
|
|
66
|
+
const markPresented = (0, react_1.useCallback)((release) => {
|
|
67
|
+
if (runtime === null || state === null || presented.current.has(release.id))
|
|
68
|
+
return;
|
|
69
|
+
presented.current.add(release.id);
|
|
70
|
+
persistState(runtime, (0, decide_1.markPresented)(state, release, runtime.appVersion));
|
|
71
|
+
void runtime.client.track({ releaseId: release.id, type: "view", voter: { installId: runtime.installId } });
|
|
72
|
+
}, [runtime, state, persistState]);
|
|
73
|
+
const openRating = (0, react_1.useCallback)((release) => {
|
|
74
|
+
const target = (0, links_1.ratingTarget)(config);
|
|
75
|
+
if (target === null || typeof window === "undefined")
|
|
76
|
+
return;
|
|
77
|
+
window.open(target.url, "_blank", "noopener,noreferrer");
|
|
78
|
+
const subject = release ?? releases[0];
|
|
79
|
+
if (runtime === null || subject === undefined)
|
|
80
|
+
return;
|
|
81
|
+
void runtime.client.track({
|
|
82
|
+
releaseId: subject.id,
|
|
83
|
+
type: "rating_click",
|
|
84
|
+
voter: { installId: runtime.installId },
|
|
85
|
+
});
|
|
86
|
+
}, [config, releases, runtime]);
|
|
87
|
+
const acceptGuidelines = (0, react_1.useCallback)(() => {
|
|
88
|
+
setModel((current) => ({ ...current, guidelinesAccepted: true }));
|
|
89
|
+
if (runtime !== null)
|
|
90
|
+
void (0, local_store_1.writeGuidelines)(runtime.storage, runtime.key, true);
|
|
91
|
+
}, [runtime, setModel]);
|
|
92
|
+
const comments = (0, use_comments_api_1.useCommentsApi)(model, setModel);
|
|
93
|
+
return (0, react_1.useMemo)(() => ({
|
|
94
|
+
vote,
|
|
95
|
+
sendFeedback,
|
|
96
|
+
openChangelog,
|
|
97
|
+
closeChangelog,
|
|
98
|
+
markPresented,
|
|
99
|
+
dismissWhatsNew,
|
|
100
|
+
openRating,
|
|
101
|
+
comments,
|
|
102
|
+
acceptGuidelines,
|
|
103
|
+
}), [
|
|
104
|
+
vote,
|
|
105
|
+
sendFeedback,
|
|
106
|
+
openChangelog,
|
|
107
|
+
closeChangelog,
|
|
108
|
+
markPresented,
|
|
109
|
+
dismissWhatsNew,
|
|
110
|
+
openRating,
|
|
111
|
+
comments,
|
|
112
|
+
acceptGuidelines,
|
|
113
|
+
]);
|
|
114
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Dispatch, SetStateAction } from "react";
|
|
2
|
+
import type { CommentsApi } from "./context";
|
|
3
|
+
import type { Model } from "./model";
|
|
4
|
+
/** Comment reads and writes bound to this install; writes update ban, guideline and count state. */
|
|
5
|
+
export declare function useCommentsApi(model: Model, setModel: Dispatch<SetStateAction<Model>>): CommentsApi;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCommentsApi = useCommentsApi;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const local_store_1 = require("./local-store");
|
|
6
|
+
const model_1 = require("./model");
|
|
7
|
+
const notReady = { ok: false, code: "NETWORK_ERROR" };
|
|
8
|
+
const disabled = { ok: false, code: "COMMENTS_DISABLED" };
|
|
9
|
+
/** Comment reads and writes bound to this install; writes update ban, guideline and count state. */
|
|
10
|
+
function useCommentsApi(model, setModel) {
|
|
11
|
+
const { runtime, config, guidelinesAccepted, releases } = model;
|
|
12
|
+
const enabled = config === null || config.community.commentsEnabled;
|
|
13
|
+
const noteFailure = (0, react_1.useCallback)((code) => {
|
|
14
|
+
if (code === "BANNED")
|
|
15
|
+
setModel((current) => ({ ...current, banned: true }));
|
|
16
|
+
if (code === "GUIDELINES_REQUIRED") {
|
|
17
|
+
setModel((current) => ({ ...current, guidelinesAccepted: false }));
|
|
18
|
+
if (runtime !== null)
|
|
19
|
+
void (0, local_store_1.writeGuidelines)(runtime.storage, runtime.key, false);
|
|
20
|
+
}
|
|
21
|
+
}, [runtime, setModel]);
|
|
22
|
+
const list = (0, react_1.useCallback)(async (releaseId, cursor) => {
|
|
23
|
+
if (runtime === null)
|
|
24
|
+
return notReady;
|
|
25
|
+
return runtime.client.listComments({ releaseId, voter: runtime.installId, ...(cursor ? { cursor } : {}) });
|
|
26
|
+
}, [runtime]);
|
|
27
|
+
const post = (0, react_1.useCallback)(async (input) => {
|
|
28
|
+
if (runtime === null)
|
|
29
|
+
return notReady;
|
|
30
|
+
if (!enabled)
|
|
31
|
+
return disabled;
|
|
32
|
+
const accepted = input.guidelinesAccepted === true || guidelinesAccepted;
|
|
33
|
+
const result = await runtime.client.postComment({
|
|
34
|
+
releaseId: input.releaseId,
|
|
35
|
+
body: input.body.trim(),
|
|
36
|
+
voter: { installId: runtime.installId },
|
|
37
|
+
client: { platform: "web" },
|
|
38
|
+
...(input.parentId ? { parentId: input.parentId } : {}),
|
|
39
|
+
...(accepted ? { guidelinesAccepted: true } : {}),
|
|
40
|
+
});
|
|
41
|
+
if (!result.ok) {
|
|
42
|
+
noteFailure(result.code);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
const release = releases.find((candidate) => candidate.id === input.releaseId);
|
|
46
|
+
setModel((current) => {
|
|
47
|
+
const counted = release === undefined
|
|
48
|
+
? current
|
|
49
|
+
: (0, model_1.withOverride)(current, input.releaseId, { commentCount: (0, model_1.releaseView)(current, release).commentCount + 1 });
|
|
50
|
+
return accepted ? { ...counted, guidelinesAccepted: true } : counted;
|
|
51
|
+
});
|
|
52
|
+
if (accepted && !guidelinesAccepted)
|
|
53
|
+
await (0, local_store_1.writeGuidelines)(runtime.storage, runtime.key, true);
|
|
54
|
+
return { ok: true, body: result.body.comment };
|
|
55
|
+
}, [runtime, enabled, guidelinesAccepted, releases, noteFailure, setModel]);
|
|
56
|
+
const vote = (0, react_1.useCallback)(async (commentId, value) => {
|
|
57
|
+
if (runtime === null)
|
|
58
|
+
return notReady;
|
|
59
|
+
const result = await runtime.client.voteComment({ commentId, value, voter: { installId: runtime.installId } });
|
|
60
|
+
if (!result.ok)
|
|
61
|
+
noteFailure(result.code);
|
|
62
|
+
return result;
|
|
63
|
+
}, [runtime, noteFailure]);
|
|
64
|
+
const report = (0, react_1.useCallback)(async (commentId, reason, note) => {
|
|
65
|
+
if (runtime === null)
|
|
66
|
+
return notReady;
|
|
67
|
+
return runtime.client.reportComment({
|
|
68
|
+
commentId,
|
|
69
|
+
reason,
|
|
70
|
+
voter: { installId: runtime.installId },
|
|
71
|
+
...(note ? { note } : {}),
|
|
72
|
+
});
|
|
73
|
+
}, [runtime]);
|
|
74
|
+
return (0, react_1.useMemo)(() => ({ list, post, vote, report }), [list, post, vote, report]);
|
|
75
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Comment, CommentReply } from "../core/types";
|
|
2
|
+
import type { VoteValue } from "./context";
|
|
3
|
+
export type ThreadState = Readonly<{
|
|
4
|
+
status: "loading" | "ready" | "error";
|
|
5
|
+
items: readonly Comment[];
|
|
6
|
+
nextCursor: string | null;
|
|
7
|
+
total: number;
|
|
8
|
+
loadingMore: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
/** Loads one release's thread and applies local additions and optimistic comment votes. */
|
|
11
|
+
export declare function useThread(releaseId: string): {
|
|
12
|
+
thread: Readonly<{
|
|
13
|
+
status: "loading" | "ready" | "error";
|
|
14
|
+
items: readonly Comment[];
|
|
15
|
+
nextCursor: string | null;
|
|
16
|
+
total: number;
|
|
17
|
+
loadingMore: boolean;
|
|
18
|
+
}>;
|
|
19
|
+
loadMore: () => Promise<void>;
|
|
20
|
+
added: (comment: CommentReply, parentId?: string) => void;
|
|
21
|
+
voteOn: (comment: CommentReply, value: VoteValue) => Promise<void>;
|
|
22
|
+
retry: () => Promise<void>;
|
|
23
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useThread = useThread;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useChanges_1 = require("./useChanges");
|
|
6
|
+
const initial = { status: "loading", items: [], nextCursor: null, total: 0, loadingMore: false };
|
|
7
|
+
function patchComment(items, commentId, counts) {
|
|
8
|
+
return items.map((item) => item.id === commentId
|
|
9
|
+
? { ...item, ...counts }
|
|
10
|
+
: { ...item, replies: item.replies.map((reply) => (reply.id === commentId ? { ...reply, ...counts } : reply)) });
|
|
11
|
+
}
|
|
12
|
+
function firstPage(result) {
|
|
13
|
+
return result.ok
|
|
14
|
+
? {
|
|
15
|
+
status: "ready",
|
|
16
|
+
items: result.body.items,
|
|
17
|
+
nextCursor: result.body.nextCursor,
|
|
18
|
+
total: result.body.total,
|
|
19
|
+
loadingMore: false,
|
|
20
|
+
}
|
|
21
|
+
: { ...initial, status: "error" };
|
|
22
|
+
}
|
|
23
|
+
function optimistic(comment, to) {
|
|
24
|
+
const up = comment.upvotes - (comment.myVote === 1 ? 1 : 0) + (to === 1 ? 1 : 0);
|
|
25
|
+
const down = comment.downvotes - (comment.myVote === -1 ? 1 : 0) + (to === -1 ? 1 : 0);
|
|
26
|
+
return { upvotes: Math.max(0, up), downvotes: Math.max(0, down), myVote: to };
|
|
27
|
+
}
|
|
28
|
+
/** Loads one release's thread and applies local additions and optimistic comment votes. */
|
|
29
|
+
function useThread(releaseId) {
|
|
30
|
+
const { list, vote } = (0, useChanges_1.useChanges)().comments;
|
|
31
|
+
const [thread, setThread] = (0, react_1.useState)(initial);
|
|
32
|
+
(0, react_1.useEffect)(() => {
|
|
33
|
+
let active = true;
|
|
34
|
+
void (async () => {
|
|
35
|
+
const result = await list(releaseId);
|
|
36
|
+
if (active)
|
|
37
|
+
setThread(firstPage(result));
|
|
38
|
+
})();
|
|
39
|
+
return () => {
|
|
40
|
+
active = false;
|
|
41
|
+
};
|
|
42
|
+
}, [list, releaseId]);
|
|
43
|
+
const loadMore = (0, react_1.useCallback)(async () => {
|
|
44
|
+
const cursor = thread.nextCursor;
|
|
45
|
+
if (cursor === null || thread.loadingMore)
|
|
46
|
+
return;
|
|
47
|
+
setThread((current) => ({ ...current, loadingMore: true }));
|
|
48
|
+
const result = await list(releaseId, cursor);
|
|
49
|
+
setThread((current) => result.ok
|
|
50
|
+
? {
|
|
51
|
+
...current,
|
|
52
|
+
items: [...current.items, ...result.body.items],
|
|
53
|
+
nextCursor: result.body.nextCursor,
|
|
54
|
+
loadingMore: false,
|
|
55
|
+
}
|
|
56
|
+
: { ...current, loadingMore: false });
|
|
57
|
+
}, [list, releaseId, thread.nextCursor, thread.loadingMore]);
|
|
58
|
+
const added = (0, react_1.useCallback)((comment, parentId) => {
|
|
59
|
+
setThread((current) => ({
|
|
60
|
+
...current,
|
|
61
|
+
total: current.total + 1,
|
|
62
|
+
items: parentId
|
|
63
|
+
? current.items.map((item) => (item.id === parentId ? { ...item, replies: [...item.replies, comment] } : item))
|
|
64
|
+
: [{ ...comment, replies: [] }, ...current.items],
|
|
65
|
+
}));
|
|
66
|
+
}, []);
|
|
67
|
+
const voteOn = (0, react_1.useCallback)(async (comment, value) => {
|
|
68
|
+
const before = { upvotes: comment.upvotes, downvotes: comment.downvotes, myVote: comment.myVote };
|
|
69
|
+
setThread((current) => ({
|
|
70
|
+
...current,
|
|
71
|
+
items: patchComment(current.items, comment.id, optimistic(before, value)),
|
|
72
|
+
}));
|
|
73
|
+
const result = await vote(comment.id, value);
|
|
74
|
+
const settled = result.ok ? result.body : before;
|
|
75
|
+
setThread((current) => ({ ...current, items: patchComment(current.items, comment.id, settled) }));
|
|
76
|
+
}, [vote]);
|
|
77
|
+
const retry = (0, react_1.useCallback)(async () => {
|
|
78
|
+
setThread(initial);
|
|
79
|
+
setThread(firstPage(await list(releaseId)));
|
|
80
|
+
}, [list, releaseId]);
|
|
81
|
+
return { thread, loadMore, added, voteOn, retry };
|
|
82
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ChangesProviderMissingError = void 0;
|
|
4
|
+
exports.useChanges = useChanges;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const context_1 = require("./context");
|
|
7
|
+
class ChangesProviderMissingError extends Error {
|
|
8
|
+
constructor() {
|
|
9
|
+
super("useChanges() must be called inside <ChangesProvider>");
|
|
10
|
+
this.name = "ChangesProviderMissingError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.ChangesProviderMissingError = ChangesProviderMissingError;
|
|
14
|
+
function useChanges() {
|
|
15
|
+
const value = (0, react_1.useContext)(context_1.ChangesContext);
|
|
16
|
+
if (value === null)
|
|
17
|
+
throw new ChangesProviderMissingError();
|
|
18
|
+
return value;
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-seeker/changes-react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"README.md"
|
|
9
|
+
],
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"react": ">=18",
|
|
17
|
+
"react-dom": ">=18"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"zod": "^4"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"typescript": "^5",
|
|
24
|
+
"vitest": "^4.1.11",
|
|
25
|
+
"@types/react": "^19",
|
|
26
|
+
"@types/react-dom": "^19",
|
|
27
|
+
"react": "19.2.3",
|
|
28
|
+
"react-dom": "19.2.3",
|
|
29
|
+
"jsdom": "^29"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsc -p tsconfig.build.json",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"test": "vitest run"
|
|
35
|
+
}
|
|
6
36
|
}
|