@the-seeker/feedback-react-native 0.0.0-stage → 0.2.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.
- package/README.md +266 -2
- package/dist/core/author-token.d.ts +16 -0
- package/dist/core/author-token.js +96 -0
- package/dist/core/client.d.ts +55 -0
- package/dist/core/client.js +98 -0
- package/dist/core/config.d.ts +59 -0
- package/dist/core/config.js +112 -0
- package/dist/core/posts-schema.d.ts +306 -0
- package/dist/core/posts-schema.js +131 -0
- package/dist/core/posts.d.ts +67 -0
- package/dist/core/posts.js +113 -0
- package/dist/core/request.d.ts +53 -0
- package/dist/core/request.js +88 -0
- package/dist/core/survey.d.ts +12 -0
- package/dist/core/survey.js +26 -0
- package/dist/core/texts.d.ts +196 -0
- package/dist/core/texts.js +232 -0
- package/dist/core/theme.d.ts +6 -0
- package/dist/core/theme.js +55 -0
- package/dist/core/transport.d.ts +9 -0
- package/dist/core/transport.js +37 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +34 -0
- package/dist/ui/Attachments.d.ts +9 -0
- package/dist/ui/Attachments.js +27 -0
- package/dist/ui/FeedbackForm.d.ts +8 -0
- package/dist/ui/FeedbackForm.js +92 -0
- package/dist/ui/FeedbackPostScreen.d.ts +8 -0
- package/dist/ui/FeedbackPostScreen.js +74 -0
- package/dist/ui/FeedbackSheet.d.ts +2 -0
- package/dist/ui/FeedbackSheet.js +14 -0
- package/dist/ui/FollowUpSheet.d.ts +17 -0
- package/dist/ui/FollowUpSheet.js +50 -0
- package/dist/ui/Inline.d.ts +6 -0
- package/dist/ui/Inline.js +16 -0
- package/dist/ui/Launcher.d.ts +1 -0
- package/dist/ui/Launcher.js +16 -0
- package/dist/ui/MyFeedbackModal.d.ts +10 -0
- package/dist/ui/MyFeedbackModal.js +45 -0
- package/dist/ui/MyFeedbackScreen.d.ts +9 -0
- package/dist/ui/MyFeedbackScreen.js +88 -0
- package/dist/ui/PostThread.d.ts +17 -0
- package/dist/ui/PostThread.js +57 -0
- package/dist/ui/Provider.d.ts +24 -0
- package/dist/ui/Provider.js +186 -0
- package/dist/ui/SurveyPrompt.d.ts +2 -0
- package/dist/ui/SurveyPrompt.js +52 -0
- package/dist/ui/context.d.ts +122 -0
- package/dist/ui/context.js +28 -0
- package/dist/ui/device.d.ts +10 -0
- package/dist/ui/device.js +22 -0
- package/dist/ui/forms.d.ts +32 -0
- package/dist/ui/forms.js +62 -0
- package/dist/ui/motion.d.ts +1 -0
- package/dist/ui/motion.js +23 -0
- package/dist/ui/post-format.d.ts +19 -0
- package/dist/ui/post-format.js +79 -0
- package/dist/ui/post-pieces.d.ts +24 -0
- package/dist/ui/post-pieces.js +60 -0
- package/dist/ui/post-styles.d.ts +317 -0
- package/dist/ui/post-styles.js +103 -0
- package/dist/ui/post-view-model.d.ts +52 -0
- package/dist/ui/post-view-model.js +181 -0
- package/dist/ui/primitives.d.ts +33 -0
- package/dist/ui/primitives.js +55 -0
- package/dist/ui/prop-state.d.ts +9 -0
- package/dist/ui/prop-state.js +27 -0
- package/dist/ui/storage.d.ts +15 -0
- package/dist/ui/storage.js +35 -0
- package/dist/ui/styles.d.ts +774 -0
- package/dist/ui/styles.js +185 -0
- package/dist/ui/surfaces.d.ts +13 -0
- package/dist/ui/surfaces.js +41 -0
- package/dist/ui/tokens.d.ts +16 -0
- package/dist/ui/tokens.js +62 -0
- package/dist/ui/useMyPosts.d.ts +35 -0
- package/dist/ui/useMyPosts.js +124 -0
- package/dist/ui/useSurvey.d.ts +12 -0
- package/dist/ui/useSurvey.js +52 -0
- package/package.json +32 -3
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TYPE = exports.HOME_INDICATOR = exports.TOUCH = exports.SPACE = void 0;
|
|
4
|
+
exports.createStyles = createStyles;
|
|
5
|
+
exports.useFeedbackTheme = useFeedbackTheme;
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const react_native_1 = require("react-native");
|
|
8
|
+
const theme_1 = require("../core/theme");
|
|
9
|
+
const tokens_1 = require("./tokens");
|
|
10
|
+
// Layout scale: 6 inside a group (label → field), 16 between groups, 20 panel inset (web widget values).
|
|
11
|
+
exports.SPACE = { hair: 4, tight: 6, gap: 8, block: 12, group: 16, panel: 20 };
|
|
12
|
+
exports.TOUCH = 44;
|
|
13
|
+
// No safe-area module (pure JS): clear the iOS home indicator (34pt) under the launcher and sheet.
|
|
14
|
+
exports.HOME_INDICATOR = react_native_1.Platform.OS === "ios" ? 12 : 0;
|
|
15
|
+
const LAUNCHER_BOTTOM = 24 + exports.HOME_INDICATOR;
|
|
16
|
+
const SURVEY_ABOVE_LAUNCHER = LAUNCHER_BOTTOM + exports.TOUCH + exports.SPACE.block;
|
|
17
|
+
const SHEET_BOTTOM = exports.SPACE.panel + (react_native_1.Platform.OS === "ios" ? 14 : 0);
|
|
18
|
+
// Native-mobile type scale: screen 26 → post 20 → sheet 17 → row 16 → body 15 → label 14; inputs 16; meta 13.
|
|
19
|
+
exports.TYPE = {
|
|
20
|
+
screen: { fontSize: 26, lineHeight: 32, fontWeight: "700", letterSpacing: -0.4 },
|
|
21
|
+
headline: { fontSize: 20, lineHeight: 26, fontWeight: "600", letterSpacing: -0.3 },
|
|
22
|
+
title: { fontSize: 17, lineHeight: 22, fontWeight: "600", letterSpacing: -0.2 },
|
|
23
|
+
item: { fontSize: 16, lineHeight: 22, fontWeight: "600" },
|
|
24
|
+
body: { fontSize: 15, lineHeight: 22 },
|
|
25
|
+
label: { fontSize: 14, lineHeight: 20, fontWeight: "500" },
|
|
26
|
+
input: { fontSize: 16, lineHeight: 22 },
|
|
27
|
+
action: { fontSize: 15, lineHeight: 20, fontWeight: "600" },
|
|
28
|
+
meta: { fontSize: 13, lineHeight: 18 },
|
|
29
|
+
};
|
|
30
|
+
function lift(tokens, depth) {
|
|
31
|
+
return {
|
|
32
|
+
shadowColor: tokens.shadow,
|
|
33
|
+
shadowOffset: { width: 0, height: depth * 6 },
|
|
34
|
+
shadowOpacity: tokens.shadowOpacity,
|
|
35
|
+
shadowRadius: depth * 10,
|
|
36
|
+
elevation: depth * 6,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function createStyles(t) {
|
|
40
|
+
const field = { borderRadius: t.radius.field, borderWidth: 1, borderColor: t.input, backgroundColor: t.background };
|
|
41
|
+
return react_native_1.StyleSheet.create({
|
|
42
|
+
launcher: {
|
|
43
|
+
position: "absolute",
|
|
44
|
+
bottom: LAUNCHER_BOTTOM,
|
|
45
|
+
maxWidth: "70%",
|
|
46
|
+
minHeight: exports.TOUCH,
|
|
47
|
+
justifyContent: "center",
|
|
48
|
+
paddingHorizontal: 18,
|
|
49
|
+
borderRadius: t.radius.button,
|
|
50
|
+
backgroundColor: t.accent,
|
|
51
|
+
...lift(t, 1),
|
|
52
|
+
},
|
|
53
|
+
launcherRight: { right: exports.SPACE.panel },
|
|
54
|
+
launcherLeft: { left: exports.SPACE.panel },
|
|
55
|
+
launcherPressed: { opacity: 0.88, transform: [{ scale: 0.97 }] },
|
|
56
|
+
launcherLabel: { ...exports.TYPE.action, color: t.accentText },
|
|
57
|
+
launcherRow: { flexDirection: "row", alignItems: "center", gap: exports.SPACE.tight },
|
|
58
|
+
launcherDot: { width: 8, height: 8, borderRadius: 4, backgroundColor: t.accentText },
|
|
59
|
+
head: { flexDirection: "row", alignItems: "center", justifyContent: "space-between", gap: exports.SPACE.gap },
|
|
60
|
+
headTitle: { flexShrink: 1 },
|
|
61
|
+
sheetRoot: { flex: 1, justifyContent: "flex-end" },
|
|
62
|
+
// Explicit edges: `absoluteFillObject` is gone in RN 0.86 and `absoluteFill` changed shape across versions.
|
|
63
|
+
scrim: { position: "absolute", top: 0, right: 0, bottom: 0, left: 0, backgroundColor: t.scrim },
|
|
64
|
+
sheet: {
|
|
65
|
+
maxHeight: "90%",
|
|
66
|
+
borderTopLeftRadius: t.radius.panel,
|
|
67
|
+
borderTopRightRadius: t.radius.panel,
|
|
68
|
+
borderTopWidth: 1,
|
|
69
|
+
borderColor: t.border,
|
|
70
|
+
backgroundColor: t.background,
|
|
71
|
+
...lift(t, 2),
|
|
72
|
+
},
|
|
73
|
+
sheetContent: { padding: exports.SPACE.panel, paddingBottom: SHEET_BOTTOM },
|
|
74
|
+
card: {
|
|
75
|
+
padding: exports.SPACE.panel,
|
|
76
|
+
borderRadius: t.radius.panel,
|
|
77
|
+
borderWidth: 1,
|
|
78
|
+
borderColor: t.border,
|
|
79
|
+
backgroundColor: t.background,
|
|
80
|
+
},
|
|
81
|
+
title: { ...exports.TYPE.title, color: t.text },
|
|
82
|
+
description: { ...exports.TYPE.body, marginTop: exports.SPACE.hair, marginBottom: exports.SPACE.group, color: t.mutedText },
|
|
83
|
+
field: { marginBottom: exports.SPACE.group },
|
|
84
|
+
label: { ...exports.TYPE.label, marginBottom: exports.SPACE.tight, color: t.text },
|
|
85
|
+
input: {
|
|
86
|
+
...field,
|
|
87
|
+
...exports.TYPE.input,
|
|
88
|
+
minHeight: exports.TOUCH,
|
|
89
|
+
paddingHorizontal: exports.SPACE.block,
|
|
90
|
+
paddingVertical: 10,
|
|
91
|
+
color: t.text,
|
|
92
|
+
},
|
|
93
|
+
multiline: { minHeight: 120, textAlignVertical: "top" },
|
|
94
|
+
multilineShort: { minHeight: 72, textAlignVertical: "top" },
|
|
95
|
+
inputFocused: { borderColor: t.accent },
|
|
96
|
+
inputInvalid: { borderColor: t.danger },
|
|
97
|
+
fieldFoot: { flexDirection: "row", gap: exports.SPACE.block, marginTop: exports.SPACE.tight },
|
|
98
|
+
error: { ...exports.TYPE.meta, flex: 1, color: t.danger },
|
|
99
|
+
meta: { ...exports.TYPE.meta, color: t.mutedText, fontVariant: ["tabular-nums"] },
|
|
100
|
+
end: { marginStart: "auto" },
|
|
101
|
+
tools: { flexDirection: "row", alignItems: "center", gap: exports.SPACE.block },
|
|
102
|
+
hint: { ...exports.TYPE.meta, marginTop: exports.SPACE.tight, color: t.mutedText },
|
|
103
|
+
strip: { flexDirection: "row", flexWrap: "wrap", gap: exports.SPACE.block, marginTop: exports.SPACE.block },
|
|
104
|
+
thumb: {
|
|
105
|
+
width: 72,
|
|
106
|
+
height: 72,
|
|
107
|
+
borderRadius: Math.min(t.radius.field, 8),
|
|
108
|
+
borderWidth: 1,
|
|
109
|
+
borderColor: t.imageEdge,
|
|
110
|
+
backgroundColor: t.surface,
|
|
111
|
+
},
|
|
112
|
+
removeBadge: {
|
|
113
|
+
position: "absolute",
|
|
114
|
+
top: -exports.SPACE.tight,
|
|
115
|
+
end: -exports.SPACE.tight,
|
|
116
|
+
width: 24,
|
|
117
|
+
height: 24,
|
|
118
|
+
alignItems: "center",
|
|
119
|
+
justifyContent: "center",
|
|
120
|
+
borderRadius: 12,
|
|
121
|
+
borderWidth: 2,
|
|
122
|
+
borderColor: t.background,
|
|
123
|
+
backgroundColor: t.text,
|
|
124
|
+
},
|
|
125
|
+
removePressed: { backgroundColor: t.danger },
|
|
126
|
+
status: { ...exports.TYPE.meta, marginBottom: exports.SPACE.block, color: t.mutedText },
|
|
127
|
+
statusError: { color: t.danger },
|
|
128
|
+
actions: { flexDirection: "row", justifyContent: "flex-end", gap: exports.SPACE.gap },
|
|
129
|
+
button: {
|
|
130
|
+
minHeight: exports.TOUCH,
|
|
131
|
+
minWidth: exports.TOUCH,
|
|
132
|
+
alignItems: "center",
|
|
133
|
+
justifyContent: "center",
|
|
134
|
+
paddingHorizontal: 18,
|
|
135
|
+
borderRadius: t.radius.button,
|
|
136
|
+
borderWidth: 1,
|
|
137
|
+
borderColor: "transparent",
|
|
138
|
+
},
|
|
139
|
+
primary: { backgroundColor: t.accent },
|
|
140
|
+
primaryPressed: { opacity: 0.88 },
|
|
141
|
+
secondary: { borderColor: t.input, backgroundColor: t.background },
|
|
142
|
+
secondaryPressed: { backgroundColor: t.surface },
|
|
143
|
+
ghost: { backgroundColor: "transparent" },
|
|
144
|
+
ghostPressed: { backgroundColor: t.hover },
|
|
145
|
+
disabled: { opacity: 0.5 },
|
|
146
|
+
buttonLabel: { ...exports.TYPE.action, color: t.text },
|
|
147
|
+
primaryLabel: { color: t.accentText },
|
|
148
|
+
thanks: { ...exports.TYPE.body, paddingVertical: exports.SPACE.group, color: t.text },
|
|
149
|
+
surveyDock: { position: "absolute", left: exports.SPACE.group, right: exports.SPACE.group, pointerEvents: "box-none" },
|
|
150
|
+
dockLow: { bottom: LAUNCHER_BOTTOM },
|
|
151
|
+
dockRaised: { bottom: SURVEY_ABOVE_LAUNCHER },
|
|
152
|
+
dockStart: { alignItems: "flex-start" },
|
|
153
|
+
dockEnd: { alignItems: "flex-end" },
|
|
154
|
+
surveyCard: {
|
|
155
|
+
width: "100%",
|
|
156
|
+
maxWidth: 400,
|
|
157
|
+
padding: exports.SPACE.group,
|
|
158
|
+
borderRadius: t.radius.panel,
|
|
159
|
+
borderWidth: 1,
|
|
160
|
+
borderColor: t.border,
|
|
161
|
+
backgroundColor: t.background,
|
|
162
|
+
...lift(t, 2),
|
|
163
|
+
},
|
|
164
|
+
question: { ...exports.TYPE.label, fontWeight: "600", marginBottom: exports.SPACE.block, color: t.text },
|
|
165
|
+
scale: { flexDirection: "row", gap: exports.SPACE.hair },
|
|
166
|
+
score: { ...field, flex: 1, minHeight: exports.TOUCH, alignItems: "center", justifyContent: "center" },
|
|
167
|
+
scoreSelected: { borderColor: t.accent, backgroundColor: t.accent },
|
|
168
|
+
scorePressed: { backgroundColor: t.surface },
|
|
169
|
+
scoreLabel: { ...exports.TYPE.label, color: t.text, fontVariant: ["tabular-nums"] },
|
|
170
|
+
scoreLabelSelected: { color: t.accentText },
|
|
171
|
+
anchors: { flexDirection: "row", justifyContent: "space-between", gap: exports.SPACE.gap, marginTop: exports.SPACE.tight },
|
|
172
|
+
anchorGap: { marginBottom: exports.SPACE.block },
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
/** Resolves the widget theme (light/dark/auto) against the device scheme into tokens and styles. */
|
|
176
|
+
function useFeedbackTheme(config) {
|
|
177
|
+
const system = (0, react_native_1.useColorScheme)();
|
|
178
|
+
const systemScheme = system === "dark" || system === "light" ? system : null;
|
|
179
|
+
return (0, react_1.useMemo)(() => {
|
|
180
|
+
if (config === null)
|
|
181
|
+
return null;
|
|
182
|
+
const tokens = (0, tokens_1.resolveTokens)(config, (0, theme_1.resolveScheme)(config.theme, systemScheme));
|
|
183
|
+
return { tokens, styles: createStyles(tokens) };
|
|
184
|
+
}, [config, systemScheme]);
|
|
185
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type Surface = "send" | "mine";
|
|
2
|
+
export type Surfaces = Readonly<{
|
|
3
|
+
shown: Surface | null;
|
|
4
|
+
session: number;
|
|
5
|
+
show: (target: Surface) => void;
|
|
6
|
+
hide: () => void;
|
|
7
|
+
dismissed: () => void;
|
|
8
|
+
}>;
|
|
9
|
+
/**
|
|
10
|
+
* The send sheet and the my-feedback screens are sibling modals. iOS cannot present one while the
|
|
11
|
+
* other is still on screen, so a switch there waits for the closing modal's `onDismiss`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useSurfaces(): Surfaces;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSurfaces = useSurfaces;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
6
|
+
/**
|
|
7
|
+
* The send sheet and the my-feedback screens are sibling modals. iOS cannot present one while the
|
|
8
|
+
* other is still on screen, so a switch there waits for the closing modal's `onDismiss`.
|
|
9
|
+
*/
|
|
10
|
+
function useSurfaces() {
|
|
11
|
+
const [shown, setShown] = (0, react_1.useState)(null);
|
|
12
|
+
const [session, setSession] = (0, react_1.useState)(0);
|
|
13
|
+
const queued = (0, react_1.useRef)(null);
|
|
14
|
+
const present = (0, react_1.useCallback)((target) => {
|
|
15
|
+
if (target === "mine")
|
|
16
|
+
setSession((count) => count + 1);
|
|
17
|
+
setShown(target);
|
|
18
|
+
}, []);
|
|
19
|
+
const show = (0, react_1.useCallback)((target) => {
|
|
20
|
+
if (shown === target)
|
|
21
|
+
return;
|
|
22
|
+
if (shown !== null && react_native_1.Platform.OS === "ios") {
|
|
23
|
+
queued.current = target;
|
|
24
|
+
setShown(null);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
queued.current = null;
|
|
28
|
+
present(target);
|
|
29
|
+
}, [shown, present]);
|
|
30
|
+
const hide = (0, react_1.useCallback)(() => {
|
|
31
|
+
queued.current = null;
|
|
32
|
+
setShown(null);
|
|
33
|
+
}, []);
|
|
34
|
+
const dismissed = (0, react_1.useCallback)(() => {
|
|
35
|
+
const next = queued.current;
|
|
36
|
+
queued.current = null;
|
|
37
|
+
if (next !== null)
|
|
38
|
+
present(next);
|
|
39
|
+
}, [present]);
|
|
40
|
+
return { shown, session, show, hide, dismissed };
|
|
41
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Scheme, WidgetConfig } from "../core/config";
|
|
2
|
+
import type { Palette } from "../core/theme";
|
|
3
|
+
export type Tokens = Palette & Readonly<{
|
|
4
|
+
scheme: Scheme;
|
|
5
|
+
input: string;
|
|
6
|
+
danger: string;
|
|
7
|
+
scrim: string;
|
|
8
|
+
surface: string;
|
|
9
|
+
hover: string;
|
|
10
|
+
imageEdge: string;
|
|
11
|
+
shadow: string;
|
|
12
|
+
shadowOpacity: number;
|
|
13
|
+
}>;
|
|
14
|
+
/** `color-mix(in srgb, foreground weight, background)` for `#rrggbb` inputs; falls back to the background. */
|
|
15
|
+
export declare function mixHex(foreground: string, background: string, weight: number): string;
|
|
16
|
+
export declare function resolveTokens(config: WidgetConfig, scheme: Scheme): Tokens;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mixHex = mixHex;
|
|
4
|
+
exports.resolveTokens = resolveTokens;
|
|
5
|
+
const theme_1 = require("../core/theme");
|
|
6
|
+
// Mirrors the web widget's `:host` custom properties (public/js/feedback.js) for the roles the
|
|
7
|
+
// core palette does not carry: input outline, danger text, scrim, surface and pressed fills.
|
|
8
|
+
const SCHEME_TOKENS = {
|
|
9
|
+
light: {
|
|
10
|
+
input: "rgba(0,0,0,.14)",
|
|
11
|
+
danger: "#c9352b",
|
|
12
|
+
scrim: "rgba(8,9,10,.36)",
|
|
13
|
+
surface: "#faf8f5",
|
|
14
|
+
hover: "#ebe9e6",
|
|
15
|
+
imageEdge: "rgba(0,0,0,.1)",
|
|
16
|
+
shadow: "#000000",
|
|
17
|
+
shadowOpacity: 0.18,
|
|
18
|
+
},
|
|
19
|
+
dark: {
|
|
20
|
+
input: "rgba(255,255,255,.16)",
|
|
21
|
+
danger: "#f87171",
|
|
22
|
+
scrim: "rgba(0,0,0,.6)",
|
|
23
|
+
surface: "#1f2025",
|
|
24
|
+
hover: "#2a2c33",
|
|
25
|
+
imageEdge: "rgba(255,255,255,.1)",
|
|
26
|
+
shadow: "#000000",
|
|
27
|
+
shadowOpacity: 0.5,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
function channels(hex) {
|
|
31
|
+
if (!/^#[0-9a-f]{6}$/i.test(hex))
|
|
32
|
+
return null;
|
|
33
|
+
const read = (start) => Number.parseInt(hex.slice(start, start + 2), 16);
|
|
34
|
+
return [read(1), read(3), read(5)];
|
|
35
|
+
}
|
|
36
|
+
/** `color-mix(in srgb, foreground weight, background)` for `#rrggbb` inputs; falls back to the background. */
|
|
37
|
+
function mixHex(foreground, background, weight) {
|
|
38
|
+
const fg = channels(foreground);
|
|
39
|
+
const bg = channels(background);
|
|
40
|
+
if (fg === null || bg === null)
|
|
41
|
+
return background;
|
|
42
|
+
const mix = (index) => Math.round(fg[index] * weight + bg[index] * (1 - weight))
|
|
43
|
+
.toString(16)
|
|
44
|
+
.padStart(2, "0");
|
|
45
|
+
return `#${mix(0)}${mix(1)}${mix(2)}`;
|
|
46
|
+
}
|
|
47
|
+
function resolveTokens(config, scheme) {
|
|
48
|
+
const palette = (0, theme_1.resolvePalette)(config, scheme);
|
|
49
|
+
const overrides = config.appearance[scheme];
|
|
50
|
+
const base = SCHEME_TOKENS[scheme];
|
|
51
|
+
// Same derivation as the web widget: a custom background re-tints the surface/pressed fills,
|
|
52
|
+
// a custom border also outlines the inputs.
|
|
53
|
+
const tinted = overrides.background !== undefined;
|
|
54
|
+
return {
|
|
55
|
+
...palette,
|
|
56
|
+
...base,
|
|
57
|
+
scheme,
|
|
58
|
+
input: overrides.border ?? base.input,
|
|
59
|
+
surface: tinted ? mixHex(palette.text, palette.background, 0.04) : base.surface,
|
|
60
|
+
hover: tinted ? mixHex(palette.text, palette.background, 0.09) : base.hover,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
import type { RandomBytes } from "../core/author-token";
|
|
3
|
+
import type { SubmitResult } from "../core/client";
|
|
4
|
+
import type { AppSite, CreatePostInput, PostsClient } from "../core/posts";
|
|
5
|
+
import type { FeedbackPayload, ImageAsset } from "../core/request";
|
|
6
|
+
import type { FeedbackStorage } from "./storage";
|
|
7
|
+
export type MyPostsSource = Readonly<{
|
|
8
|
+
id: string;
|
|
9
|
+
client: PostsClient;
|
|
10
|
+
site: AppSite;
|
|
11
|
+
}>;
|
|
12
|
+
export type MyPosts = Readonly<{
|
|
13
|
+
source: MyPostsSource | null;
|
|
14
|
+
unreadCount: number;
|
|
15
|
+
refreshUnread: () => Promise<void>;
|
|
16
|
+
}>;
|
|
17
|
+
export type MyPostsOptions = Readonly<{
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
widgetKey: string;
|
|
20
|
+
appId: string;
|
|
21
|
+
/** `false` without an app-provided storage: a token kept only in memory would orphan the posts on restart. */
|
|
22
|
+
persistent: boolean;
|
|
23
|
+
storage: RefObject<FeedbackStorage | undefined>;
|
|
24
|
+
randomBytes: RefObject<RandomBytes | undefined>;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Resolves whether this install can use the my-feedback screens (author token, then `GET site`) and
|
|
28
|
+
* keeps the unread count fresh on start and whenever the app returns to the foreground.
|
|
29
|
+
* Any failure keeps the screens hidden; the legacy send flow does not depend on this.
|
|
30
|
+
*/
|
|
31
|
+
export declare function useMyPosts(options: MyPostsOptions): MyPosts;
|
|
32
|
+
/** The send form's payload as a post body; the contact goes out as email or free text, whichever the form took. */
|
|
33
|
+
export declare function postInput(payload: FeedbackPayload, screen: string): CreatePostInput;
|
|
34
|
+
/** The send form's payload as an owned post, so it shows up under "내 피드백" with its answers. */
|
|
35
|
+
export declare function submitAsPost(client: PostsClient, payload: FeedbackPayload, screen: string, images: readonly ImageAsset[]): Promise<SubmitResult>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMyPosts = useMyPosts;
|
|
4
|
+
exports.postInput = postInput;
|
|
5
|
+
exports.submitAsPost = submitAsPost;
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const react_native_1 = require("react-native");
|
|
8
|
+
const author_token_1 = require("../core/author-token");
|
|
9
|
+
const posts_1 = require("../core/posts");
|
|
10
|
+
const prop_state_1 = require("./prop-state");
|
|
11
|
+
async function authorToken(storage, key, random) {
|
|
12
|
+
try {
|
|
13
|
+
return await (0, author_token_1.getOrCreateAuthorToken)(storage, key, random);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (!(error instanceof author_token_1.AuthorTokenUnavailable))
|
|
17
|
+
throw error;
|
|
18
|
+
(0, prop_state_1.devWarn)(`my-feedback screens stay hidden: ${error.message}. Install react-native-get-random-values.`);
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolves whether this install can use the my-feedback screens (author token, then `GET site`) and
|
|
24
|
+
* keeps the unread count fresh on start and whenever the app returns to the foreground.
|
|
25
|
+
* Any failure keeps the screens hidden; the legacy send flow does not depend on this.
|
|
26
|
+
*/
|
|
27
|
+
function useMyPosts(options) {
|
|
28
|
+
const { baseUrl, widgetKey, appId, persistent, storage, randomBytes } = options;
|
|
29
|
+
const id = `${baseUrl}\n${widgetKey}\n${appId}`;
|
|
30
|
+
const [loaded, setLoaded] = (0, react_1.useState)(null);
|
|
31
|
+
const source = persistent && loaded?.id === id ? loaded : null;
|
|
32
|
+
(0, react_1.useEffect)(() => {
|
|
33
|
+
let live = true;
|
|
34
|
+
async function load() {
|
|
35
|
+
const adapter = storage.current;
|
|
36
|
+
if (!persistent || adapter === undefined)
|
|
37
|
+
return (0, prop_state_1.devWarn)("pass `storage` to enable the my-feedback screens.");
|
|
38
|
+
const token = await authorToken(adapter, widgetKey, randomBytes.current);
|
|
39
|
+
if (!live || token === null)
|
|
40
|
+
return;
|
|
41
|
+
const client = (0, posts_1.createPostsClient)({ baseUrl, publicKey: widgetKey, appId, authorToken: token });
|
|
42
|
+
const site = await client.getSite();
|
|
43
|
+
if (!live)
|
|
44
|
+
return;
|
|
45
|
+
if (!site.ok)
|
|
46
|
+
return (0, prop_state_1.devWarn)(`my-feedback screens stay hidden (${site.code}).`);
|
|
47
|
+
if (site.value.myPostsEnabled)
|
|
48
|
+
setLoaded({ id, client, site: site.value });
|
|
49
|
+
}
|
|
50
|
+
void load();
|
|
51
|
+
return () => {
|
|
52
|
+
live = false;
|
|
53
|
+
};
|
|
54
|
+
}, [id, baseUrl, widgetKey, appId, persistent, storage, randomBytes]);
|
|
55
|
+
const [unread, setUnread] = (0, react_1.useState)(null);
|
|
56
|
+
const refreshUnread = (0, react_1.useCallback)(async () => {
|
|
57
|
+
if (source === null)
|
|
58
|
+
return;
|
|
59
|
+
const result = await source.client.getUnread();
|
|
60
|
+
if (result.ok)
|
|
61
|
+
setUnread({ id: source.id, count: result.value.count });
|
|
62
|
+
}, [source]);
|
|
63
|
+
(0, react_1.useEffect)(() => {
|
|
64
|
+
if (source === null)
|
|
65
|
+
return;
|
|
66
|
+
async function refresh() {
|
|
67
|
+
await refreshUnread();
|
|
68
|
+
}
|
|
69
|
+
void refresh();
|
|
70
|
+
const subscription = react_native_1.AppState.addEventListener("change", (state) => {
|
|
71
|
+
if (state === "active")
|
|
72
|
+
void refresh();
|
|
73
|
+
});
|
|
74
|
+
return () => subscription.remove();
|
|
75
|
+
}, [source, refreshUnread]);
|
|
76
|
+
const unreadCount = source !== null && unread?.id === source.id ? unread.count : 0;
|
|
77
|
+
return { source, unreadCount, refreshUnread };
|
|
78
|
+
}
|
|
79
|
+
function submitCode(code) {
|
|
80
|
+
switch (code) {
|
|
81
|
+
case "VALIDATION_ERROR":
|
|
82
|
+
case "RATE_LIMITED":
|
|
83
|
+
case "APP_NOT_ALLOWED":
|
|
84
|
+
case "IMAGES_DISABLED":
|
|
85
|
+
case "TOO_MANY_IMAGES":
|
|
86
|
+
case "IMAGE_TOO_LARGE":
|
|
87
|
+
case "INVALID_IMAGE":
|
|
88
|
+
case "NETWORK_ERROR":
|
|
89
|
+
case "ELIGIBILITY":
|
|
90
|
+
return code;
|
|
91
|
+
case "SITE_NOT_FOUND":
|
|
92
|
+
case "NOT_FOUND":
|
|
93
|
+
return "WIDGET_NOT_FOUND";
|
|
94
|
+
case "ONE_WAY":
|
|
95
|
+
case "CLOSED":
|
|
96
|
+
case "REQUEST_FAILED":
|
|
97
|
+
case "INVALID_RESPONSE":
|
|
98
|
+
return "VALIDATION_ERROR";
|
|
99
|
+
default:
|
|
100
|
+
return assertNever(code);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/** The send form's payload as a post body; the contact goes out as email or free text, whichever the form took. */
|
|
104
|
+
function postInput(payload, screen) {
|
|
105
|
+
const contact = {
|
|
106
|
+
...(payload.contactEmail === undefined ? {} : { email: payload.contactEmail }),
|
|
107
|
+
...(payload.contact === undefined ? {} : { text: payload.contact }),
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
content: payload.content,
|
|
111
|
+
screen,
|
|
112
|
+
...(payload.uid === undefined ? {} : { uid: payload.uid }),
|
|
113
|
+
...(payload.client === undefined ? {} : { client: payload.client }),
|
|
114
|
+
...(Object.keys(contact).length === 0 ? {} : { contact }),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** The send form's payload as an owned post, so it shows up under "내 피드백" with its answers. */
|
|
118
|
+
async function submitAsPost(client, payload, screen, images) {
|
|
119
|
+
const result = await client.createPost(postInput(payload, screen), images);
|
|
120
|
+
return result.ok ? { ok: true, id: result.value.id } : { ok: false, code: submitCode(result.code) };
|
|
121
|
+
}
|
|
122
|
+
function assertNever(value) {
|
|
123
|
+
throw new TypeError(`Unexpected posts error: ${String(value)}`);
|
|
124
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
import type { Survey } from "../core/config";
|
|
3
|
+
import type { FeedbackStorage } from "./storage";
|
|
4
|
+
export type SurveySlot = Readonly<{
|
|
5
|
+
survey: Survey | null;
|
|
6
|
+
dismiss: () => void;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* Same rules as the web widget's scheduleSurvey: path match, cooldown from storage, sample rate,
|
|
10
|
+
* then `delaySeconds`. Re-evaluated whenever the screen changes; shown at most once per provider.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useSurvey(survey: Survey | null, screen: string, storage: RefObject<FeedbackStorage>): SurveySlot;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSurvey = useSurvey;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const survey_1 = require("../core/survey");
|
|
6
|
+
const prop_state_1 = require("./prop-state");
|
|
7
|
+
const storage_1 = require("./storage");
|
|
8
|
+
async function remember(storage, survey) {
|
|
9
|
+
const error = await (0, storage_1.writeStorage)(storage, (0, survey_1.surveyStorageKey)(survey.id), String(Date.now()));
|
|
10
|
+
if (error !== null)
|
|
11
|
+
(0, prop_state_1.devWarn)(`survey storage write failed: ${error.message}`);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Same rules as the web widget's scheduleSurvey: path match, cooldown from storage, sample rate,
|
|
15
|
+
* then `delaySeconds`. Re-evaluated whenever the screen changes; shown at most once per provider.
|
|
16
|
+
*/
|
|
17
|
+
function useSurvey(survey, screen, storage) {
|
|
18
|
+
const [active, setActive] = (0, react_1.useState)(null);
|
|
19
|
+
const shown = (0, react_1.useRef)(new Set());
|
|
20
|
+
(0, react_1.useEffect)(() => {
|
|
21
|
+
if (survey === null || shown.current.has(survey.id))
|
|
22
|
+
return;
|
|
23
|
+
let live = true;
|
|
24
|
+
let timer;
|
|
25
|
+
async function schedule(target) {
|
|
26
|
+
const read = await (0, storage_1.readStorage)(storage.current, (0, survey_1.surveyStorageKey)(target.id));
|
|
27
|
+
if (!live)
|
|
28
|
+
return;
|
|
29
|
+
if (!read.ok)
|
|
30
|
+
return (0, prop_state_1.devWarn)(`survey storage read failed: ${read.error.message}`);
|
|
31
|
+
const now = Date.now();
|
|
32
|
+
if (!(0, survey_1.isSurveyEligible)({ survey: target, screen, lastShown: read.value, now, random: Math.random() }))
|
|
33
|
+
return;
|
|
34
|
+
timer = setTimeout(() => {
|
|
35
|
+
shown.current = new Set([...shown.current, target.id]);
|
|
36
|
+
void remember(storage.current, target);
|
|
37
|
+
setActive(target);
|
|
38
|
+
}, target.delaySeconds * 1000);
|
|
39
|
+
}
|
|
40
|
+
void schedule(survey);
|
|
41
|
+
return () => {
|
|
42
|
+
live = false;
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
};
|
|
45
|
+
}, [survey, screen, storage]);
|
|
46
|
+
const dismiss = (0, react_1.useCallback)(() => {
|
|
47
|
+
if (active !== null)
|
|
48
|
+
void remember(storage.current, active);
|
|
49
|
+
setActive(null);
|
|
50
|
+
}, [active, storage]);
|
|
51
|
+
return { survey: active, dismiss };
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-seeker/feedback-react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"react-native": "dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"react": ">=18",
|
|
18
|
+
"react-native": ">=0.74"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"zod": "^4"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"typescript": "^5",
|
|
25
|
+
"vitest": "^5.1.1",
|
|
26
|
+
"@types/react": "^19",
|
|
27
|
+
"react": "19.2.3",
|
|
28
|
+
"react-native": "0.86.x"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc -p tsconfig.build.json",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"test": "vitest run"
|
|
34
|
+
}
|
|
6
35
|
}
|