@the-seeker/changes-react-native 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.
Files changed (70) hide show
  1. package/README.md +119 -2
  2. package/dist/core/cache.d.ts +14 -0
  3. package/dist/core/cache.js +34 -0
  4. package/dist/core/client.d.ts +161 -0
  5. package/dist/core/client.js +97 -0
  6. package/dist/core/decide.d.ts +16 -0
  7. package/dist/core/decide.js +57 -0
  8. package/dist/core/rating.d.ts +7 -0
  9. package/dist/core/rating.js +18 -0
  10. package/dist/core/storage.d.ts +20 -0
  11. package/dist/core/storage.js +73 -0
  12. package/dist/core/types.d.ts +332 -0
  13. package/dist/core/types.js +126 -0
  14. package/dist/core/versions.d.ts +2 -0
  15. package/dist/core/versions.js +20 -0
  16. package/dist/index.d.ts +22 -0
  17. package/dist/index.js +44 -0
  18. package/dist/native/Blocks.d.ts +7 -0
  19. package/dist/native/Blocks.js +45 -0
  20. package/dist/native/ChangelogButton.d.ts +6 -0
  21. package/dist/native/ChangelogButton.js +16 -0
  22. package/dist/native/ChangelogScreen.d.ts +6 -0
  23. package/dist/native/ChangelogScreen.js +52 -0
  24. package/dist/native/CommentComposer.d.ts +11 -0
  25. package/dist/native/CommentComposer.js +40 -0
  26. package/dist/native/CommentItem.d.ts +15 -0
  27. package/dist/native/CommentItem.js +35 -0
  28. package/dist/native/CommentsThread.d.ts +9 -0
  29. package/dist/native/CommentsThread.js +24 -0
  30. package/dist/native/Provider.d.ts +11 -0
  31. package/dist/native/Provider.js +68 -0
  32. package/dist/native/ReleaseView.d.ts +11 -0
  33. package/dist/native/ReleaseView.js +37 -0
  34. package/dist/native/WhatsNewSheet.d.ts +6 -0
  35. package/dist/native/WhatsNewSheet.js +52 -0
  36. package/dist/native/community.d.ts +18 -0
  37. package/dist/native/community.js +39 -0
  38. package/dist/native/context.d.ts +123 -0
  39. package/dist/native/context.js +26 -0
  40. package/dist/native/default-texts.d.ts +89 -0
  41. package/dist/native/default-texts.js +92 -0
  42. package/dist/native/format.d.ts +5 -0
  43. package/dist/native/format.js +34 -0
  44. package/dist/native/messages.d.ts +44 -0
  45. package/dist/native/messages.js +83 -0
  46. package/dist/native/primitives.d.ts +39 -0
  47. package/dist/native/primitives.js +78 -0
  48. package/dist/native/rating-plan.d.ts +31 -0
  49. package/dist/native/rating-plan.js +101 -0
  50. package/dist/native/resolve.d.ts +21 -0
  51. package/dist/native/resolve.js +73 -0
  52. package/dist/native/session.d.ts +48 -0
  53. package/dist/native/session.js +83 -0
  54. package/dist/native/styles-community.d.ts +1447 -0
  55. package/dist/native/styles-community.js +117 -0
  56. package/dist/native/styles-scale.d.ts +66 -0
  57. package/dist/native/styles-scale.js +22 -0
  58. package/dist/native/styles.d.ts +2584 -0
  59. package/dist/native/styles.js +161 -0
  60. package/dist/native/tokens.d.ts +51 -0
  61. package/dist/native/tokens.js +90 -0
  62. package/dist/native/use-actions.d.ts +55 -0
  63. package/dist/native/use-actions.js +59 -0
  64. package/dist/native/use-comments.d.ts +40 -0
  65. package/dist/native/use-comments.js +83 -0
  66. package/dist/native/use-controller.d.ts +101 -0
  67. package/dist/native/use-controller.js +144 -0
  68. package/dist/native/use-session.d.ts +268 -0
  69. package/dist/native/use-session.js +86 -0
  70. package/package.json +49 -3
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createStyles = createStyles;
4
+ exports.useChangesTheme = useChangesTheme;
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const styles_community_1 = require("./styles-community");
8
+ const styles_scale_1 = require("./styles-scale");
9
+ const tokens_1 = require("./tokens");
10
+ // No safe-area module (pure JS): clear the iOS home indicator under the sheet's last button.
11
+ const SHEET_BOTTOM = styles_scale_1.SPACE.panel + (react_native_1.Platform.OS === "ios" ? 14 : 0);
12
+ const MONO = react_native_1.Platform.select({ ios: "Menlo", default: "monospace" });
13
+ function lift(tokens) {
14
+ return {
15
+ shadowColor: tokens.shadow,
16
+ shadowOffset: { width: 0, height: -6 },
17
+ shadowOpacity: tokens.shadowOpacity,
18
+ shadowRadius: 20,
19
+ elevation: 12,
20
+ };
21
+ }
22
+ function createBaseStyles(t) {
23
+ const text = (style, color = t.text) => ({ ...style, color });
24
+ return react_native_1.StyleSheet.create({
25
+ sheetRoot: { flex: 1, justifyContent: "flex-end" },
26
+ scrim: { position: "absolute", top: 0, right: 0, bottom: 0, left: 0, backgroundColor: t.scrim },
27
+ sheet: {
28
+ maxHeight: "92%",
29
+ borderTopLeftRadius: styles_scale_1.RADIUS.sheet,
30
+ borderTopRightRadius: styles_scale_1.RADIUS.sheet,
31
+ backgroundColor: t.background,
32
+ ...lift(t),
33
+ },
34
+ handle: {
35
+ alignSelf: "center",
36
+ width: 36,
37
+ height: 5,
38
+ marginTop: styles_scale_1.SPACE.gap,
39
+ borderRadius: styles_scale_1.RADIUS.pill,
40
+ backgroundColor: t.border,
41
+ },
42
+ sheetContent: { paddingHorizontal: styles_scale_1.SPACE.panel, paddingTop: styles_scale_1.SPACE.block, paddingBottom: SHEET_BOTTOM },
43
+ screen: { flex: 1, backgroundColor: t.background },
44
+ screenHeader: {
45
+ flexDirection: "row",
46
+ alignItems: "center",
47
+ justifyContent: "space-between",
48
+ gap: styles_scale_1.SPACE.block,
49
+ paddingStart: styles_scale_1.SPACE.panel,
50
+ paddingEnd: styles_scale_1.SPACE.tight,
51
+ paddingVertical: styles_scale_1.SPACE.tight,
52
+ borderBottomWidth: react_native_1.StyleSheet.hairlineWidth,
53
+ borderColor: t.border,
54
+ },
55
+ screenTitle: { ...text(styles_scale_1.TYPE.title), flex: 1 },
56
+ listContent: { paddingHorizontal: styles_scale_1.SPACE.panel, paddingTop: styles_scale_1.SPACE.panel, paddingBottom: SHEET_BOTTOM },
57
+ listHeader: { marginBottom: styles_scale_1.SPACE.section, gap: styles_scale_1.SPACE.hair },
58
+ display: text(styles_scale_1.TYPE.display),
59
+ subtitle: text(styles_scale_1.TYPE.body, t.mutedText),
60
+ separator: { height: react_native_1.StyleSheet.hairlineWidth, marginVertical: styles_scale_1.SPACE.section, backgroundColor: t.border },
61
+ eyebrow: text(styles_scale_1.TYPE.eyebrow, t.mutedText),
62
+ releaseHead: { gap: styles_scale_1.SPACE.hair, marginBottom: styles_scale_1.SPACE.block },
63
+ releaseTitle: text(styles_scale_1.TYPE.title),
64
+ meta: { ...text(styles_scale_1.TYPE.meta, t.mutedText), fontVariant: ["tabular-nums"] },
65
+ tags: { flexDirection: "row", flexWrap: "wrap", gap: styles_scale_1.SPACE.tight, marginTop: styles_scale_1.SPACE.tight },
66
+ tag: {
67
+ paddingHorizontal: styles_scale_1.SPACE.gap,
68
+ paddingVertical: 2,
69
+ borderRadius: styles_scale_1.RADIUS.chip,
70
+ borderWidth: react_native_1.StyleSheet.hairlineWidth,
71
+ borderColor: t.border,
72
+ backgroundColor: t.surface,
73
+ },
74
+ tagLabel: text(styles_scale_1.TYPE.small, t.mutedText),
75
+ blocks: { gap: styles_scale_1.SPACE.block },
76
+ paragraph: text(styles_scale_1.TYPE.body),
77
+ heading: { ...text(styles_scale_1.TYPE.label), fontWeight: "600" },
78
+ list: { gap: styles_scale_1.SPACE.tight },
79
+ listItem: { flexDirection: "row", gap: styles_scale_1.SPACE.gap },
80
+ bullet: text(styles_scale_1.TYPE.body, t.mutedText),
81
+ listText: { ...text(styles_scale_1.TYPE.body), flex: 1 },
82
+ strong: { fontWeight: "600" },
83
+ code: { fontFamily: MONO, fontSize: 14, backgroundColor: t.surface },
84
+ link: { color: t.accentInk, textDecorationLine: "underline" },
85
+ actionsRow: {
86
+ flexDirection: "row",
87
+ flexWrap: "wrap",
88
+ alignItems: "center",
89
+ justifyContent: "space-between",
90
+ gap: styles_scale_1.SPACE.block,
91
+ marginTop: styles_scale_1.SPACE.group,
92
+ },
93
+ footer: { gap: styles_scale_1.SPACE.gap, marginTop: styles_scale_1.SPACE.panel },
94
+ button: {
95
+ minHeight: styles_scale_1.TOUCH,
96
+ alignItems: "center",
97
+ justifyContent: "center",
98
+ paddingHorizontal: 18,
99
+ borderRadius: styles_scale_1.RADIUS.control,
100
+ borderWidth: 1,
101
+ borderColor: "transparent",
102
+ },
103
+ primary: { backgroundColor: t.accent },
104
+ primaryPressed: { opacity: 0.88 },
105
+ secondary: { borderColor: t.input, backgroundColor: t.background },
106
+ secondaryPressed: { backgroundColor: t.surface },
107
+ ghost: { backgroundColor: "transparent", paddingHorizontal: styles_scale_1.SPACE.block },
108
+ ghostPressed: { backgroundColor: t.pressed },
109
+ disabled: { opacity: 0.5 },
110
+ buttonLabel: text(styles_scale_1.TYPE.action),
111
+ primaryLabel: { color: t.accentText },
112
+ linkLabel: { color: t.accentInk },
113
+ banner: {
114
+ padding: styles_scale_1.SPACE.block,
115
+ marginBottom: styles_scale_1.SPACE.group,
116
+ borderRadius: styles_scale_1.RADIUS.control,
117
+ backgroundColor: t.surface,
118
+ },
119
+ bannerInHeader: { marginTop: styles_scale_1.SPACE.block, marginBottom: 0 },
120
+ bannerText: text(styles_scale_1.TYPE.meta, t.mutedText),
121
+ status: text(styles_scale_1.TYPE.meta, t.mutedText),
122
+ statusError: { color: t.danger },
123
+ centered: { alignItems: "center", gap: styles_scale_1.SPACE.block, paddingVertical: styles_scale_1.SPACE.section },
124
+ launcher: {
125
+ flexDirection: "row",
126
+ alignItems: "center",
127
+ gap: styles_scale_1.SPACE.gap,
128
+ minHeight: styles_scale_1.TOUCH,
129
+ paddingHorizontal: 14,
130
+ borderRadius: styles_scale_1.RADIUS.control,
131
+ borderWidth: 1,
132
+ borderColor: t.input,
133
+ backgroundColor: t.background,
134
+ },
135
+ launcherPressed: { backgroundColor: t.surface },
136
+ countBadge: {
137
+ minWidth: 20,
138
+ height: 20,
139
+ alignItems: "center",
140
+ justifyContent: "center",
141
+ paddingHorizontal: styles_scale_1.SPACE.tight,
142
+ borderRadius: styles_scale_1.RADIUS.pill,
143
+ backgroundColor: t.accent,
144
+ },
145
+ countLabel: { ...text(styles_scale_1.TYPE.small, t.accentText), fontVariant: ["tabular-nums"] },
146
+ });
147
+ }
148
+ function createStyles(tokens) {
149
+ return { ...createBaseStyles(tokens), ...(0, styles_community_1.createCommunityStyles)(tokens) };
150
+ }
151
+ /** Project accent against the device light/dark scheme. */
152
+ function useChangesTheme(accentColor) {
153
+ const system = (0, react_native_1.useColorScheme)();
154
+ const scheme = system === "dark" ? "dark" : "light";
155
+ return (0, react_1.useMemo)(() => {
156
+ if (accentColor === null)
157
+ return null;
158
+ const tokens = (0, tokens_1.resolveTokens)(accentColor, scheme);
159
+ return { tokens, styles: createStyles(tokens) };
160
+ }, [accentColor, scheme]);
161
+ }
@@ -0,0 +1,51 @@
1
+ export type Scheme = "light" | "dark";
2
+ export declare const DEFAULT_ACCENT = "#5e6ad2";
3
+ declare const SCHEMES: {
4
+ readonly light: {
5
+ readonly background: "#ffffff";
6
+ readonly surface: "#f6f6f7";
7
+ readonly pressed: "#ebebed";
8
+ readonly text: "#08090a";
9
+ readonly mutedText: "#5f6b67";
10
+ readonly border: "#e4e4e7";
11
+ readonly input: "rgba(0,0,0,.14)";
12
+ readonly danger: "#c9352b";
13
+ readonly scrim: "rgba(8,9,10,.36)";
14
+ readonly shadow: "#000000";
15
+ readonly shadowOpacity: 0.18;
16
+ readonly imageEdge: "rgba(0,0,0,.1)";
17
+ };
18
+ readonly dark: {
19
+ readonly background: "#17181c";
20
+ readonly surface: "#1f2025";
21
+ readonly pressed: "#2a2c33";
22
+ readonly text: "#f4f5f6";
23
+ readonly mutedText: "#a1a7b3";
24
+ readonly border: "#2c2e35";
25
+ readonly input: "rgba(255,255,255,.16)";
26
+ readonly danger: "#f87171";
27
+ readonly scrim: "rgba(0,0,0,.6)";
28
+ readonly shadow: "#000000";
29
+ readonly shadowOpacity: 0.5;
30
+ readonly imageEdge: "rgba(255,255,255,.1)";
31
+ };
32
+ };
33
+ export type Tokens = Readonly<{
34
+ [K in keyof (typeof SCHEMES)["light"]]: (typeof SCHEMES)["light"][K] extends number ? number : string;
35
+ } & {
36
+ scheme: Scheme;
37
+ accent: string;
38
+ /** Label color on an accent fill. */
39
+ accentText: string;
40
+ /** Selected-control fill: the accent mixed into the canvas. */
41
+ accentSoft: string;
42
+ /** Accent used as text or a glyph on the canvas, nudged toward the text color until it reads at 4.5:1. */
43
+ accentInk: string;
44
+ }>;
45
+ /** WCAG 2 contrast ratio between two `#rrggbb` colors. */
46
+ export declare function contrastRatio(a: string, b: string): number;
47
+ /** `color-mix(in srgb, foreground weight, background)` for `#rrggbb` inputs; falls back to the background. */
48
+ export declare function mixHex(foreground: string, background: string, weight: number): string;
49
+ /** Resolves the project accent (`config.app.accentColor`) against the device color scheme. */
50
+ export declare function resolveTokens(accentColor: string, scheme: Scheme): Tokens;
51
+ export {};
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_ACCENT = void 0;
4
+ exports.contrastRatio = contrastRatio;
5
+ exports.mixHex = mixHex;
6
+ exports.resolveTokens = resolveTokens;
7
+ exports.DEFAULT_ACCENT = "#5e6ad2";
8
+ // Neutral roles mirror the feedback SDK palette so both TheSeeker sheets look like one family.
9
+ const SCHEMES = {
10
+ light: {
11
+ background: "#ffffff",
12
+ surface: "#f6f6f7",
13
+ pressed: "#ebebed",
14
+ text: "#08090a",
15
+ mutedText: "#5f6b67",
16
+ border: "#e4e4e7",
17
+ input: "rgba(0,0,0,.14)",
18
+ danger: "#c9352b",
19
+ scrim: "rgba(8,9,10,.36)",
20
+ shadow: "#000000",
21
+ shadowOpacity: 0.18,
22
+ imageEdge: "rgba(0,0,0,.1)",
23
+ },
24
+ dark: {
25
+ background: "#17181c",
26
+ surface: "#1f2025",
27
+ pressed: "#2a2c33",
28
+ text: "#f4f5f6",
29
+ mutedText: "#a1a7b3",
30
+ border: "#2c2e35",
31
+ input: "rgba(255,255,255,.16)",
32
+ danger: "#f87171",
33
+ scrim: "rgba(0,0,0,.6)",
34
+ shadow: "#000000",
35
+ shadowOpacity: 0.5,
36
+ imageEdge: "rgba(255,255,255,.1)",
37
+ },
38
+ };
39
+ function channels(hex) {
40
+ if (!/^#[0-9a-f]{6}$/i.test(hex))
41
+ return null;
42
+ const read = (start) => Number.parseInt(hex.slice(start, start + 2), 16);
43
+ return [read(1), read(3), read(5)];
44
+ }
45
+ function luminance(hex) {
46
+ const rgb = channels(hex) ?? [0, 0, 0];
47
+ const linear = (value) => {
48
+ const n = value / 255;
49
+ return n <= 0.04045 ? n / 12.92 : ((n + 0.055) / 1.055) ** 2.4;
50
+ };
51
+ return linear(rgb[0]) * 0.2126 + linear(rgb[1]) * 0.7152 + linear(rgb[2]) * 0.0722;
52
+ }
53
+ /** WCAG 2 contrast ratio between two `#rrggbb` colors. */
54
+ function contrastRatio(a, b) {
55
+ const [high, low] = [luminance(a), luminance(b)].sort((x, y) => y - x);
56
+ return ((high ?? 0) + 0.05) / ((low ?? 0) + 0.05);
57
+ }
58
+ /** `color-mix(in srgb, foreground weight, background)` for `#rrggbb` inputs; falls back to the background. */
59
+ function mixHex(foreground, background, weight) {
60
+ const fg = channels(foreground);
61
+ const bg = channels(background);
62
+ if (fg === null || bg === null)
63
+ return background;
64
+ const mix = (index) => Math.round(fg[index] * weight + bg[index] * (1 - weight))
65
+ .toString(16)
66
+ .padStart(2, "0");
67
+ return `#${mix(0)}${mix(1)}${mix(2)}`;
68
+ }
69
+ /** Resolves the project accent (`config.app.accentColor`) against the device color scheme. */
70
+ function resolveTokens(accentColor, scheme) {
71
+ const base = SCHEMES[scheme];
72
+ const accent = channels(accentColor) === null ? exports.DEFAULT_ACCENT : accentColor.toLowerCase();
73
+ const accentText = contrastRatio("#ffffff", accent) >= contrastRatio("#0a0a0a", accent) ? "#ffffff" : "#0a0a0a";
74
+ return {
75
+ ...base,
76
+ scheme,
77
+ accent,
78
+ accentText,
79
+ accentSoft: mixHex(accent, base.background, scheme === "dark" ? 0.22 : 0.12),
80
+ accentInk: readableOn(accent, base.text, base.background),
81
+ };
82
+ }
83
+ function readableOn(color, ink, background) {
84
+ for (let step = 0; step <= 10; step += 1) {
85
+ const candidate = mixHex(ink, color, step / 10);
86
+ if (contrastRatio(candidate, background) >= 4.5)
87
+ return candidate;
88
+ }
89
+ return ink;
90
+ }
@@ -0,0 +1,55 @@
1
+ import type { Dispatch, SetStateAction } from "react";
2
+ import type { ChangesClient } from "../core/client";
3
+ import type { ClientInfo, Config, ErrorCode, Platform, Release } from "../core/types";
4
+ import type { ReleaseFeedbackInput, VoteValue } from "./context";
5
+ import type { StoreReviewAdapter } from "./rating-plan";
6
+ export type ActionDeps = Readonly<{
7
+ client: ChangesClient;
8
+ installId: string | null;
9
+ config: Config | null;
10
+ platform: Platform;
11
+ clientInfo: ClientInfo | undefined;
12
+ openUrl: (url: string) => Promise<unknown>;
13
+ storeReview: StoreReviewAdapter | undefined;
14
+ useNativeReview: boolean;
15
+ guidelinesAccepted: boolean;
16
+ setReleases: Dispatch<SetStateAction<readonly Release[]>>;
17
+ fail: (code: ErrorCode) => void;
18
+ }>;
19
+ /** Writes against the loaded session: release votes, feedback, rating, view events and comments. */
20
+ export declare function useReleaseActions(deps: ActionDeps): {
21
+ trackView: (release: Release) => void;
22
+ vote: (releaseId: string, value: VoteValue) => Promise<Readonly<{
23
+ ok: false;
24
+ code: ErrorCode;
25
+ }> | Readonly<{
26
+ ok: true;
27
+ body: Readonly<{
28
+ upvotes: number;
29
+ downvotes: number;
30
+ myVote: 0 | 1 | -1;
31
+ }>;
32
+ }>>;
33
+ sendFeedback: ({ releaseId, message, email }: ReleaseFeedbackInput) => Promise<Readonly<{
34
+ ok: false;
35
+ code: ErrorCode;
36
+ }> | Readonly<{
37
+ ok: true;
38
+ body: Readonly<{
39
+ id: string;
40
+ }>;
41
+ }>>;
42
+ openRating: (releaseId?: string) => Promise<boolean>;
43
+ comments: Readonly<{
44
+ list: (releaseId: string, cursor?: string) => Promise<import("../core/types").Result<import("./context").CommentsPage>>;
45
+ post: (input: Pick<import("../core/client").CommentInput, "releaseId" | "body"> & Readonly<{
46
+ parentId?: string;
47
+ guidelinesAccepted?: boolean;
48
+ }>) => Promise<import("../core/types").Result<Readonly<{
49
+ comment: import("../core/types").CommentReply;
50
+ }>>>;
51
+ vote: (commentId: string, value: VoteValue) => Promise<import("../core/types").Result<import("./session").VoteCounts>>;
52
+ report: (commentId: string, reason: import("../core/client").ReportInput["reason"], note?: string) => Promise<import("../core/types").Result<unknown>>;
53
+ }>;
54
+ ratingAvailable: boolean;
55
+ };
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useReleaseActions = useReleaseActions;
4
+ const react_1 = require("react");
5
+ const community_1 = require("./community");
6
+ const rating_plan_1 = require("./rating-plan");
7
+ const session_1 = require("./session");
8
+ /** Writes against the loaded session: release votes, feedback, rating, view events and comments. */
9
+ function useReleaseActions(deps) {
10
+ const { client, installId, config, platform, clientInfo, openUrl, storeReview, useNativeReview } = deps;
11
+ const { guidelinesAccepted, setReleases, fail } = deps;
12
+ const trackView = (0, react_1.useCallback)((release) => {
13
+ if (installId !== null)
14
+ void client.track({ releaseId: release.id, type: "view", voter: { installId } });
15
+ }, [client, installId]);
16
+ const vote = (0, react_1.useCallback)(async (releaseId, value) => {
17
+ if (installId === null)
18
+ return community_1.NOT_READY;
19
+ const result = await client.vote({ releaseId, value, voter: { installId } });
20
+ if (result.ok)
21
+ setReleases((current) => (0, session_1.applyVote)(current, releaseId, result.body));
22
+ else
23
+ fail(result.code);
24
+ return result;
25
+ }, [client, installId, setReleases, fail]);
26
+ const sendFeedback = (0, react_1.useCallback)(async ({ releaseId, message, email }) => {
27
+ if (installId === null)
28
+ return community_1.NOT_READY;
29
+ const result = await client.sendFeedback({
30
+ releaseId,
31
+ message,
32
+ voter: { installId },
33
+ ...(email === undefined ? {} : { email }),
34
+ ...(clientInfo === undefined ? {} : { client: clientInfo }),
35
+ });
36
+ if (!result.ok)
37
+ fail(result.code);
38
+ return result;
39
+ }, [client, installId, clientInfo, fail]);
40
+ const openRating = (0, react_1.useCallback)(async (releaseId) => {
41
+ if (config === null)
42
+ return false;
43
+ if (releaseId !== undefined && installId !== null) {
44
+ void client.track({ releaseId, type: "rating_click", voter: { installId } });
45
+ }
46
+ const nativeAvailable = storeReview !== undefined && useNativeReview && (await storeReview.isAvailableAsync().catch(() => false));
47
+ return (0, rating_plan_1.runRatingPlan)((0, rating_plan_1.planRatingOpen)({ platform, config, nativeAvailable, useNativeReview }), {
48
+ openUrl,
49
+ ...(storeReview === undefined ? {} : { requestReview: () => storeReview.requestReview() }),
50
+ });
51
+ }, [config, installId, client, storeReview, useNativeReview, platform, openUrl]);
52
+ const reads = (0, react_1.useMemo)(() => (0, community_1.createCommentReads)({ client, installId }), [client, installId]);
53
+ const onPosted = (0, react_1.useCallback)((releaseId) => setReleases((current) => current.map((release) => release.id === releaseId ? { ...release, commentCount: release.commentCount + 1 } : release)), [setReleases]);
54
+ const post = (0, react_1.useMemo)(() => (0, community_1.createCommentPost)({ client, installId, guidelinesAccepted, clientInfo, onPosted }), [client, installId, guidelinesAccepted, clientInfo, onPosted]);
55
+ const comments = (0, react_1.useMemo)(() => ({ ...reads, post }), [reads, post]);
56
+ const ratingAvailable = config !== null &&
57
+ (0, rating_plan_1.planRatingOpen)({ platform, config, nativeAvailable: storeReview !== undefined, useNativeReview }).length > 0;
58
+ return { trackView, vote, sendFeedback, openRating, comments, ratingAvailable };
59
+ }
@@ -0,0 +1,40 @@
1
+ import type { ReportInput } from "../core/client";
2
+ import type { ErrorCode } from "../core/types";
3
+ import type { ChangesApi, VoteValue } from "./context";
4
+ export type ThreadStatus = "loading" | "ready" | "error";
5
+ export type ReplyTarget = Readonly<{
6
+ id: string;
7
+ name: string;
8
+ }>;
9
+ /** One release's comment thread: paging, server-counted votes, posting and reports. */
10
+ export declare function useCommentsThread(api: ChangesApi, releaseId: string): {
11
+ items: readonly Readonly<{
12
+ upvotes: number;
13
+ downvotes: number;
14
+ myVote: 0 | 1 | -1;
15
+ id: string;
16
+ authorName: string;
17
+ isDeveloper: boolean;
18
+ body: string;
19
+ createdAt: string;
20
+ replies: readonly Readonly<{
21
+ upvotes: number;
22
+ downvotes: number;
23
+ myVote: 0 | 1 | -1;
24
+ id: string;
25
+ authorName: string;
26
+ isDeveloper: boolean;
27
+ body: string;
28
+ createdAt: string;
29
+ }>[];
30
+ }>[];
31
+ total: number;
32
+ status: ThreadStatus;
33
+ hasMore: boolean;
34
+ reported: ReadonlySet<string>;
35
+ loadMore: () => Promise<void>;
36
+ vote: (commentId: string, value: VoteValue) => Promise<ErrorCode | null>;
37
+ post: (body: string, parentId: string | null, guidelinesAccepted: boolean) => Promise<ErrorCode | null>;
38
+ report: (commentId: string, reason: ReportInput["reason"]) => Promise<ErrorCode | null>;
39
+ retry: () => void;
40
+ };
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCommentsThread = useCommentsThread;
4
+ const react_1 = require("react");
5
+ const session_1 = require("./session");
6
+ /** One release's comment thread: paging, server-counted votes, posting and reports. */
7
+ function useCommentsThread(api, releaseId) {
8
+ const [items, setItems] = (0, react_1.useState)([]);
9
+ const [total, setTotal] = (0, react_1.useState)(0);
10
+ const [cursor, setCursor] = (0, react_1.useState)(null);
11
+ const [settled, setSettled] = (0, react_1.useState)(null);
12
+ const [reported, setReported] = (0, react_1.useState)(new Set());
13
+ const { list, vote: voteComment, post: postComment, report: reportComment } = api.comments;
14
+ const firstPage = (0, react_1.useCallback)(() => list(releaseId), [list, releaseId]);
15
+ const apply = (0, react_1.useCallback)((result, source) => {
16
+ if (result.ok) {
17
+ setItems(result.body.items);
18
+ setTotal(result.body.total);
19
+ setCursor(result.body.nextCursor);
20
+ }
21
+ setSettled({ source, status: result.ok ? "ready" : "error" });
22
+ }, []);
23
+ (0, react_1.useEffect)(() => {
24
+ let live = true;
25
+ async function run() {
26
+ const result = await firstPage();
27
+ if (live)
28
+ apply(result, firstPage);
29
+ }
30
+ void run();
31
+ return () => {
32
+ live = false;
33
+ };
34
+ }, [firstPage, apply]);
35
+ const retry = (0, react_1.useCallback)(() => {
36
+ setSettled(null);
37
+ async function run() {
38
+ apply(await firstPage(), firstPage);
39
+ }
40
+ void run();
41
+ }, [firstPage, apply]);
42
+ const status = settled !== null && settled.source === firstPage ? settled.status : "loading";
43
+ const loadMore = (0, react_1.useCallback)(async () => {
44
+ if (cursor === null)
45
+ return;
46
+ const result = await list(releaseId, cursor);
47
+ if (!result.ok)
48
+ return;
49
+ setItems((current) => [...current, ...result.body.items.filter((item) => !current.some((c) => c.id === item.id))]);
50
+ setCursor(result.body.nextCursor);
51
+ }, [list, releaseId, cursor]);
52
+ const vote = (0, react_1.useCallback)(async (commentId, value) => {
53
+ const result = await voteComment(commentId, value);
54
+ if (!result.ok)
55
+ return result.code;
56
+ setItems((current) => (0, session_1.applyCommentVote)(current, commentId, result.body));
57
+ return null;
58
+ }, [voteComment]);
59
+ const post = (0, react_1.useCallback)(async (body, parentId, guidelinesAccepted) => {
60
+ const result = await postComment({
61
+ releaseId,
62
+ body,
63
+ guidelinesAccepted,
64
+ ...(parentId === null ? {} : { parentId }),
65
+ });
66
+ if (!result.ok)
67
+ return result.code;
68
+ const { comment } = result.body;
69
+ setItems((current) => parentId === null
70
+ ? [{ ...comment, replies: [] }, ...current]
71
+ : current.map((item) => (item.id === parentId ? { ...item, replies: [...item.replies, comment] } : item)));
72
+ setTotal((count) => count + 1);
73
+ return null;
74
+ }, [postComment, releaseId]);
75
+ const report = (0, react_1.useCallback)(async (commentId, reason) => {
76
+ const result = await reportComment(commentId, reason);
77
+ if (!result.ok)
78
+ return result.code;
79
+ setReported((current) => new Set([...current, commentId]));
80
+ return null;
81
+ }, [reportComment]);
82
+ return { items, total, status, hasMore: cursor !== null, reported, loadMore, vote, post, report, retry };
83
+ }
@@ -0,0 +1,101 @@
1
+ import type { FetchImpl } from "../core/client";
2
+ import type { ClientInfo, ErrorCode, Platform, Release, User } from "../core/types";
3
+ import type { ChangesStatus } from "./context";
4
+ import type { StoreReviewAdapter } from "./rating-plan";
5
+ import type { ChangesStorageAdapter, LocaleMode } from "./resolve";
6
+ export type ControllerProps = Readonly<{
7
+ changesKey: string;
8
+ appId: string;
9
+ /** e.g. `Application.nativeApplicationVersion` from expo-application; omitted means web-mode decisions. */
10
+ appVersion?: string | null;
11
+ user?: User;
12
+ locale?: LocaleMode;
13
+ baseUrl?: string;
14
+ /** AsyncStorage or any `{getItem,setItem}`; read once on mount. Without it state lives in memory. */
15
+ storage?: ChangesStorageAdapter;
16
+ /** `import * as StoreReview from "expo-store-review"`; used only with `useNativeReview`. */
17
+ storeReview?: StoreReviewAdapter;
18
+ useNativeReview?: boolean;
19
+ showOnFirstLaunch?: boolean;
20
+ forceShow?: boolean;
21
+ /** Render the built-in What's New sheet for `pendingWhatsNew` (default true). */
22
+ autoPresent?: boolean;
23
+ onError?: (code: ErrorCode) => void;
24
+ }>;
25
+ export type ControllerEnv = Readonly<{
26
+ platform: Platform;
27
+ deviceLocale: string;
28
+ clientInfo: ClientInfo | undefined;
29
+ fetchImpl: FetchImpl;
30
+ randomBytes: (length: number) => Uint8Array;
31
+ openUrl: (url: string) => Promise<unknown>;
32
+ warn: (message: string) => void;
33
+ }>;
34
+ export declare function useChangesController(props: ControllerProps, env: ControllerEnv): {
35
+ api: Readonly<{
36
+ status: ChangesStatus;
37
+ stale: boolean;
38
+ error: ErrorCode | null;
39
+ config: import("../core/types").Config | null;
40
+ locale: import("./resolve").ChangesLocale;
41
+ t: import("./messages").Translate;
42
+ releases: readonly Release[];
43
+ latest: Release | null;
44
+ unseenCount: number;
45
+ pendingWhatsNew: Release | null;
46
+ vote: (releaseId: string, value: import("./context").VoteValue) => Promise<import("../core/types").Result<import("./session").VoteCounts>>;
47
+ sendFeedback: (input: import("./context").ReleaseFeedbackInput) => Promise<import("../core/types").Result<Readonly<{
48
+ id: string;
49
+ }>>>;
50
+ isChangelogOpen: boolean;
51
+ openChangelog: () => void;
52
+ closeChangelog: () => void;
53
+ showWhatsNew: (release?: Release) => void;
54
+ dismissWhatsNew: () => void;
55
+ markPresented: (release: Release) => void;
56
+ markChangelogSeen: () => void;
57
+ openRating: (releaseId?: string) => Promise<boolean>;
58
+ comments: import("./context").ChangesComments;
59
+ guidelinesAccepted: boolean;
60
+ acceptGuidelines: () => void;
61
+ reload: () => void;
62
+ }>;
63
+ sheetRelease: Readonly<{
64
+ commentCount: number;
65
+ upvotes: number;
66
+ downvotes: number;
67
+ myVote: 0 | 1 | -1;
68
+ id: string;
69
+ version: string | null;
70
+ ref: string;
71
+ title: string;
72
+ body: string;
73
+ blocks: readonly (Readonly<{
74
+ t: "p" | "h";
75
+ c: readonly (Readonly<{
76
+ t: "text" | "strong" | "code";
77
+ v: string;
78
+ }> | Readonly<{
79
+ t: "link";
80
+ v: string;
81
+ href: string;
82
+ }>)[];
83
+ }> | Readonly<{
84
+ t: "ul";
85
+ items: readonly (readonly (Readonly<{
86
+ t: "text" | "strong" | "code";
87
+ v: string;
88
+ }> | Readonly<{
89
+ t: "link";
90
+ v: string;
91
+ href: string;
92
+ }>)[])[];
93
+ }>)[];
94
+ tags: readonly ("new" | "improved" | "fixed" | "security" | "deprecated")[];
95
+ platforms: readonly ("web" | "ios" | "android")[];
96
+ source: "manual" | "app_store";
97
+ publishedAt: string;
98
+ }> | null;
99
+ ratingAvailable: boolean;
100
+ trackView: (release: Release) => void;
101
+ };