@the-seeker/feedback-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 (48) hide show
  1. package/README.md +215 -2
  2. package/dist/core/client.d.ts +57 -0
  3. package/dist/core/client.js +113 -0
  4. package/dist/core/config.d.ts +59 -0
  5. package/dist/core/config.js +112 -0
  6. package/dist/core/request.d.ts +53 -0
  7. package/dist/core/request.js +86 -0
  8. package/dist/core/survey.d.ts +12 -0
  9. package/dist/core/survey.js +26 -0
  10. package/dist/core/texts.d.ts +104 -0
  11. package/dist/core/texts.js +140 -0
  12. package/dist/core/theme.d.ts +6 -0
  13. package/dist/core/theme.js +55 -0
  14. package/dist/index.d.ts +14 -0
  15. package/dist/index.js +32 -0
  16. package/dist/ui/Attachments.d.ts +9 -0
  17. package/dist/ui/Attachments.js +27 -0
  18. package/dist/ui/FeedbackForm.d.ts +8 -0
  19. package/dist/ui/FeedbackForm.js +90 -0
  20. package/dist/ui/FeedbackSheet.d.ts +2 -0
  21. package/dist/ui/FeedbackSheet.js +32 -0
  22. package/dist/ui/Inline.d.ts +6 -0
  23. package/dist/ui/Inline.js +16 -0
  24. package/dist/ui/Launcher.d.ts +1 -0
  25. package/dist/ui/Launcher.js +14 -0
  26. package/dist/ui/Provider.d.ts +21 -0
  27. package/dist/ui/Provider.js +131 -0
  28. package/dist/ui/SurveyPrompt.d.ts +2 -0
  29. package/dist/ui/SurveyPrompt.js +52 -0
  30. package/dist/ui/context.d.ts +79 -0
  31. package/dist/ui/context.js +28 -0
  32. package/dist/ui/device.d.ts +10 -0
  33. package/dist/ui/device.js +22 -0
  34. package/dist/ui/forms.d.ts +32 -0
  35. package/dist/ui/forms.js +62 -0
  36. package/dist/ui/primitives.d.ts +33 -0
  37. package/dist/ui/primitives.js +55 -0
  38. package/dist/ui/prop-state.d.ts +9 -0
  39. package/dist/ui/prop-state.js +27 -0
  40. package/dist/ui/storage.d.ts +15 -0
  41. package/dist/ui/storage.js +35 -0
  42. package/dist/ui/styles.d.ts +697 -0
  43. package/dist/ui/styles.js +177 -0
  44. package/dist/ui/tokens.d.ts +16 -0
  45. package/dist/ui/tokens.js +62 -0
  46. package/dist/ui/useSurvey.d.ts +12 -0
  47. package/dist/ui/useSurvey.js +52 -0
  48. package/package.json +34 -4
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FeedbackSheet = FeedbackSheet;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const context_1 = require("./context");
8
+ const FeedbackForm_1 = require("./FeedbackForm");
9
+ function useReducedMotion() {
10
+ const [reduced, setReduced] = (0, react_1.useState)(false);
11
+ (0, react_1.useEffect)(() => {
12
+ let live = true;
13
+ async function read() {
14
+ const value = await react_native_1.AccessibilityInfo.isReduceMotionEnabled();
15
+ if (live)
16
+ setReduced(value);
17
+ }
18
+ void read();
19
+ const subscription = react_native_1.AccessibilityInfo.addEventListener("reduceMotionChanged", setReduced);
20
+ return () => {
21
+ live = false;
22
+ subscription.remove();
23
+ };
24
+ }, []);
25
+ return reduced;
26
+ }
27
+ /** Bottom sheet: slides up (cross-fades under Reduce Motion); scrim tap, Cancel and back close it. */
28
+ function FeedbackSheet() {
29
+ const { isOpen, close, styles } = (0, context_1.useFeedbackUi)();
30
+ const reducedMotion = useReducedMotion();
31
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Modal, { visible: isOpen, transparent: true, animationType: reducedMotion ? "fade" : "slide", onRequestClose: close, statusBarTranslucent: true, children: (0, jsx_runtime_1.jsxs)(react_native_1.KeyboardAvoidingView, { behavior: "padding", style: styles.sheetRoot, children: [(0, jsx_runtime_1.jsx)(react_native_1.Pressable, { testID: "theseeker-feedback-scrim", style: styles.scrim, onPress: close, accessible: false, importantForAccessibility: "no" }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.sheet, accessibilityViewIsModal: true, onAccessibilityEscape: close, children: (0, jsx_runtime_1.jsx)(react_native_1.ScrollView, { keyboardShouldPersistTaps: "handled", contentContainerStyle: styles.sheetContent, alwaysBounceVertical: false, children: (0, jsx_runtime_1.jsx)(FeedbackForm_1.FeedbackForm, { variant: "sheet" }) }) })] }) }));
32
+ }
@@ -0,0 +1,6 @@
1
+ import type { StyleProp, ViewStyle } from "react-native";
2
+ export type TheSeekerFeedbackInlineProps = Readonly<{
3
+ style?: StyleProp<ViewStyle>;
4
+ }>;
5
+ /** The feedback form as an in-place card (e.g. a settings screen); renders nothing until the config loads. */
6
+ export declare function TheSeekerFeedbackInline({ style }: TheSeekerFeedbackInlineProps): import("react").JSX.Element | null;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TheSeekerFeedbackInline = TheSeekerFeedbackInline;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const context_1 = require("./context");
8
+ const FeedbackForm_1 = require("./FeedbackForm");
9
+ /** The feedback form as an in-place card (e.g. a settings screen); renders nothing until the config loads. */
10
+ function TheSeekerFeedbackInline({ style }) {
11
+ (0, context_1.useTheSeekerFeedback)();
12
+ const ui = (0, react_1.useContext)(context_1.FeedbackUiContext);
13
+ if (ui === null)
14
+ return null;
15
+ return ((0, jsx_runtime_1.jsx)(react_native_1.View, { testID: "theseeker-feedback-inline", style: [ui.styles.card, style], children: (0, jsx_runtime_1.jsx)(FeedbackForm_1.FeedbackForm, { variant: "inline" }) }));
16
+ }
@@ -0,0 +1 @@
1
+ export declare function Launcher(): import("react").JSX.Element;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Launcher = Launcher;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_native_1 = require("react-native");
6
+ const context_1 = require("./context");
7
+ function Launcher() {
8
+ const { config, texts, styles, open } = (0, context_1.useFeedbackUi)();
9
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { testID: "theseeker-feedback-launcher", accessibilityRole: "button", accessibilityLabel: texts.launcher, onPress: open, style: ({ pressed }) => [
10
+ styles.launcher,
11
+ config.position === "bottom-left" ? styles.launcherLeft : styles.launcherRight,
12
+ pressed && styles.launcherPressed,
13
+ ], children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.launcherLabel, numberOfLines: 1, children: texts.launcher }) }));
14
+ }
@@ -0,0 +1,21 @@
1
+ import type { ReactNode } from "react";
2
+ import type { ClientMetadata, FeedbackErrorCode } from "../core/request";
3
+ import type { LocaleMode } from "../core/texts";
4
+ import type { PickImages, SubmissionKind } from "./context";
5
+ import type { FeedbackStorage } from "./storage";
6
+ export type TheSeekerFeedbackProviderProps = Readonly<{
7
+ widgetKey: string;
8
+ appId: string;
9
+ baseUrl?: string;
10
+ userId?: string | number | null;
11
+ locale?: LocaleMode;
12
+ screen?: string;
13
+ launcher?: boolean;
14
+ pickImages?: PickImages;
15
+ storage?: FeedbackStorage;
16
+ client?: ClientMetadata;
17
+ onSubmitted?: (id: string, kind: SubmissionKind) => void;
18
+ onError?: (code: FeedbackErrorCode) => void;
19
+ children?: ReactNode;
20
+ }>;
21
+ export declare function TheSeekerFeedbackProvider(props: TheSeekerFeedbackProviderProps): import("react").JSX.Element;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TheSeekerFeedbackProvider = TheSeekerFeedbackProvider;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const client_1 = require("../core/client");
8
+ const request_1 = require("../core/request");
9
+ const texts_1 = require("../core/texts");
10
+ const context_1 = require("./context");
11
+ const device_1 = require("./device");
12
+ const FeedbackSheet_1 = require("./FeedbackSheet");
13
+ const forms_1 = require("./forms");
14
+ const Launcher_1 = require("./Launcher");
15
+ const prop_state_1 = require("./prop-state");
16
+ const storage_1 = require("./storage");
17
+ const styles_1 = require("./styles");
18
+ const SurveyPrompt_1 = require("./SurveyPrompt");
19
+ const useSurvey_1 = require("./useSurvey");
20
+ const DEFAULT_STORAGE = (0, storage_1.createMemoryStorage)();
21
+ const DEFAULT_CLIENT = (0, device_1.clientFromPlatform)({
22
+ os: react_native_1.Platform.OS,
23
+ version: react_native_1.Platform.Version,
24
+ ...(react_native_1.Platform.OS === "android" ? { release: react_native_1.Platform.constants.Release } : {}),
25
+ ...(react_native_1.Platform.OS === "ios" ? { isPad: react_native_1.Platform.isPad } : {}),
26
+ });
27
+ function TheSeekerFeedbackProvider(props) {
28
+ const { widgetKey, appId, baseUrl = "https://crm.theseeker.io", launcher = true, children } = props;
29
+ const [screen, setScreen] = (0, prop_state_1.usePropOverride)(props.screen ?? "/");
30
+ const [uid, setUser] = (0, prop_state_1.usePropOverride)(props.userId ?? null);
31
+ const [localeMode, setLocale] = (0, prop_state_1.usePropOverride)(props.locale ?? "ko");
32
+ const [contact, setContact] = (0, react_1.useState)(null);
33
+ const [isOpen, setOpen] = (0, react_1.useState)(false);
34
+ const [draft] = (0, react_1.useState)(forms_1.createDraftStore);
35
+ const latest = (0, prop_state_1.useLatestRef)(props);
36
+ const storage = (0, prop_state_1.useLatestRef)(props.storage ?? DEFAULT_STORAGE);
37
+ const api = (0, react_1.useMemo)(() => (0, client_1.createFeedbackClient)({ baseUrl, widgetKey, appId }), [baseUrl, widgetKey, appId]);
38
+ const [loaded, setLoaded] = (0, react_1.useState)(null);
39
+ const config = loaded !== null && loaded.api === api ? loaded.config : null;
40
+ (0, react_1.useEffect)(() => {
41
+ let live = true;
42
+ async function load() {
43
+ const result = await api.fetchConfig();
44
+ if (!live)
45
+ return;
46
+ if (result.ok)
47
+ return setLoaded({ api, config: result.config });
48
+ (0, prop_state_1.devWarn)(`widget config unavailable (${result.code}); feedback UI stays hidden.`);
49
+ latest.current.onError?.(result.code);
50
+ }
51
+ void load();
52
+ return () => {
53
+ live = false;
54
+ };
55
+ }, [api, latest]);
56
+ const report = (0, react_1.useCallback)((result, kind) => {
57
+ if (result.ok)
58
+ latest.current.onSubmitted?.(result.id, kind);
59
+ else
60
+ latest.current.onError?.(result.code);
61
+ return result;
62
+ }, [latest]);
63
+ const clientMeta = props.client ?? DEFAULT_CLIENT;
64
+ const base = (0, react_1.useMemo)(() => ({ key: widgetKey, appId, screen, uid, ...(clientMeta === undefined ? {} : { client: clientMeta }) }), [widgetKey, appId, screen, uid, clientMeta]);
65
+ const submit = (0, react_1.useCallback)(async ({ message, contact: given, images = [] }) => {
66
+ if (config === null)
67
+ return report({ ok: false, code: "WIDGET_NOT_FOUND" }, "feedback");
68
+ if (!message.trim())
69
+ return report({ ok: false, code: "VALIDATION_ERROR" }, "feedback");
70
+ if (images.length > 0 && !config.images)
71
+ return report({ ok: false, code: "IMAGES_DISABLED" }, "feedback");
72
+ const payload = (0, request_1.buildFeedbackPayload)({
73
+ ...base,
74
+ message,
75
+ contact: given ?? contact,
76
+ contactMode: config.contactMode,
77
+ });
78
+ return report(await api.submit(payload, images), "feedback");
79
+ }, [api, base, config, contact, report]);
80
+ const slot = (0, useSurvey_1.useSurvey)(config?.survey ?? null, screen, storage);
81
+ const { survey, dismiss } = slot;
82
+ const sendSurvey = (0, react_1.useCallback)(async (score, message) => {
83
+ if (survey === null)
84
+ return { ok: false, code: "VALIDATION_ERROR" };
85
+ const payload = (0, request_1.buildSurveyPayload)({ ...base, message, kind: survey.type, score, surveyId: survey.id });
86
+ return report(await api.submit(payload), survey.type);
87
+ }, [api, base, report, survey]);
88
+ const ready = config !== null;
89
+ const open = (0, react_1.useCallback)(() => setOpen(ready), [ready]);
90
+ const close = (0, react_1.useCallback)(() => setOpen(false), []);
91
+ const value = (0, react_1.useMemo)(() => ({ ready, config, open, close, setScreen, setUser, setContact, setLocale, submit }), [ready, config, open, close, setScreen, setUser, setLocale, submit]);
92
+ const locale = (0, texts_1.resolveLocale)(localeMode, localeMode === "auto" ? (0, device_1.deviceLocale)() : null);
93
+ const theme = (0, styles_1.useFeedbackTheme)(config);
94
+ const { pickImages } = props;
95
+ const ui = (0, react_1.useMemo)(() => {
96
+ if (config === null || theme === null)
97
+ return null;
98
+ return {
99
+ ...theme,
100
+ config,
101
+ texts: (0, texts_1.resolveTexts)(config, locale),
102
+ isOpen,
103
+ launcherShown: launcher && config.mode === "launcher",
104
+ contact,
105
+ draft,
106
+ pickImages: config.images ? pickImages : undefined,
107
+ open,
108
+ close,
109
+ submit,
110
+ survey,
111
+ dismissSurvey: dismiss,
112
+ sendSurvey,
113
+ };
114
+ }, [
115
+ config,
116
+ theme,
117
+ locale,
118
+ isOpen,
119
+ launcher,
120
+ contact,
121
+ draft,
122
+ open,
123
+ close,
124
+ submit,
125
+ survey,
126
+ dismiss,
127
+ sendSurvey,
128
+ pickImages,
129
+ ]);
130
+ return ((0, jsx_runtime_1.jsx)(context_1.FeedbackApiContext.Provider, { value: value, children: (0, jsx_runtime_1.jsxs)(context_1.FeedbackUiContext.Provider, { value: ui, children: [children, ui?.launcherShown === true ? (0, jsx_runtime_1.jsx)(Launcher_1.Launcher, {}) : null, ui === null ? null : (0, jsx_runtime_1.jsx)(FeedbackSheet_1.FeedbackSheet, {}), ui === null || ui.survey === null ? null : (0, jsx_runtime_1.jsx)(SurveyPrompt_1.SurveyPrompt, {}, ui.survey.id)] }) }));
131
+ }
@@ -0,0 +1,2 @@
1
+ /** NPS/CSAT card docked above the launcher; Close and a successful send both count as "shown". */
2
+ export declare function SurveyPrompt(): import("react").JSX.Element | null;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SurveyPrompt = SurveyPrompt;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const react_native_1 = require("react-native");
7
+ const request_1 = require("../core/request");
8
+ const context_1 = require("./context");
9
+ const forms_1 = require("./forms");
10
+ const primitives_1 = require("./primitives");
11
+ /** NPS/CSAT card docked above the launcher; Close and a successful send both count as "shown". */
12
+ function SurveyPrompt() {
13
+ const { survey, config, texts, styles, launcherShown, dismissSurvey, sendSurvey } = (0, context_1.useFeedbackUi)();
14
+ const [score, setScore] = (0, react_1.useState)(null);
15
+ const [followUp, setFollowUp] = (0, react_1.useState)("");
16
+ const [busy, setBusy] = (0, react_1.useState)(false);
17
+ const [outcome, setOutcome] = (0, react_1.useState)(null);
18
+ const done = outcome?.tone === "info";
19
+ (0, react_1.useEffect)(() => {
20
+ if (!done)
21
+ return;
22
+ const timer = setTimeout(dismissSurvey, forms_1.AUTO_CLOSE_MS);
23
+ return () => clearTimeout(timer);
24
+ }, [done, dismissSurvey]);
25
+ if (survey === null)
26
+ return null;
27
+ const nps = survey.type === "nps";
28
+ async function send() {
29
+ if (score === null || busy)
30
+ return;
31
+ setBusy(true);
32
+ const result = await sendSurvey(score, followUp);
33
+ setBusy(false);
34
+ const next = result.ok
35
+ ? { text: texts.surveyThanks, tone: "info" }
36
+ : { text: texts[(0, request_1.errorMessageKey)(result.code)], tone: "error" };
37
+ setOutcome(next);
38
+ (0, primitives_1.announce)(next.text);
39
+ }
40
+ return ((0, jsx_runtime_1.jsx)(react_native_1.KeyboardAvoidingView, { behavior: "padding", style: [
41
+ styles.surveyDock,
42
+ launcherShown ? styles.dockRaised : styles.dockLow,
43
+ config.position === "bottom-left" ? styles.dockStart : styles.dockEnd,
44
+ ], children: (0, jsx_runtime_1.jsxs)(react_native_1.View, { testID: "theseeker-survey", style: styles.surveyCard, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.question, accessibilityRole: "header", children: survey.question }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.scale, accessibilityRole: "radiogroup", accessibilityLabel: nps ? texts.npsScale : texts.csatScale, children: (0, forms_1.surveyScores)(survey.type).map((value) => {
45
+ const selected = value === score;
46
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { testID: `theseeker-survey-score-${value}`, accessibilityRole: "radio", accessibilityLabel: texts.score.replace("{n}", String(value)), accessibilityState: { checked: selected, disabled: done }, disabled: done, onPress: () => setScore(value), style: ({ pressed }) => [
47
+ styles.score,
48
+ pressed && styles.scorePressed,
49
+ selected && styles.scoreSelected,
50
+ ], children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [styles.scoreLabel, selected && styles.scoreLabelSelected], children: value }) }, value));
51
+ }) }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: [styles.anchors, styles.anchorGap], children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.meta, children: nps ? texts.npsLow : texts.csatLow }), (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.meta, children: nps ? texts.npsHigh : texts.csatHigh })] }), survey.followUp === null ? null : ((0, jsx_runtime_1.jsx)(primitives_1.TextField, { label: survey.followUp, value: followUp, onChangeText: setFollowUp, short: true, input: { testID: "theseeker-survey-follow-up", multiline: true, maxLength: forms_1.MAX_MESSAGE, editable: !done } })), (0, jsx_runtime_1.jsx)(primitives_1.Status, { text: outcome?.text ?? null, tone: outcome?.tone ?? "info" }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.actions, children: [(0, jsx_runtime_1.jsx)(primitives_1.Button, { variant: "ghost", label: texts.close, onPress: dismissSurvey, testID: "theseeker-survey-close" }), (0, jsx_runtime_1.jsx)(primitives_1.Button, { variant: "primary", label: busy ? texts.sending : texts.send, onPress: () => void send(), disabled: score === null || busy || done, busy: busy, testID: "theseeker-survey-send" })] })] }) }));
52
+ }
@@ -0,0 +1,79 @@
1
+ import type { SubmitResult } from "../core/client";
2
+ import type { Survey, WidgetConfig } from "../core/config";
3
+ import type { ImageAsset } from "../core/request";
4
+ import type { LocaleMode, ResolvedTexts } from "../core/texts";
5
+ import type { DraftStore } from "./forms";
6
+ import type { FeedbackStyles } from "./styles";
7
+ import type { Tokens } from "./tokens";
8
+ export type SubmissionKind = "feedback" | "nps" | "csat";
9
+ export type SubmitInput = Readonly<{
10
+ message: string;
11
+ contact?: string | null;
12
+ images?: readonly ImageAsset[];
13
+ }>;
14
+ export type PickImages = () => Promise<readonly ImageAsset[]>;
15
+ export type TheSeekerFeedbackApi = Readonly<{
16
+ /** `true` once the widget config loaded; the form, launcher and survey only render when ready. */
17
+ ready: boolean;
18
+ config: WidgetConfig | null;
19
+ open: () => void;
20
+ close: () => void;
21
+ setScreen: (screen: string) => void;
22
+ setUser: (userId: string | number | null) => void;
23
+ setContact: (contact: string | null) => void;
24
+ setLocale: (locale: LocaleMode) => void;
25
+ submit: (input: SubmitInput) => Promise<SubmitResult>;
26
+ }>;
27
+ /** Everything the built-in components need; only provided while the config is loaded. */
28
+ export type FeedbackUi = Readonly<{
29
+ config: WidgetConfig;
30
+ texts: ResolvedTexts;
31
+ tokens: Tokens;
32
+ styles: FeedbackStyles;
33
+ isOpen: boolean;
34
+ launcherShown: boolean;
35
+ contact: string | null;
36
+ draft: DraftStore;
37
+ pickImages: PickImages | undefined;
38
+ open: () => void;
39
+ close: () => void;
40
+ submit: (input: SubmitInput) => Promise<SubmitResult>;
41
+ survey: Survey | null;
42
+ dismissSurvey: () => void;
43
+ sendSurvey: (score: number, message: string) => Promise<SubmitResult>;
44
+ }>;
45
+ export declare class TheSeekerFeedbackContextError extends Error {
46
+ readonly caller: string;
47
+ constructor(caller: string);
48
+ }
49
+ export declare const FeedbackApiContext: import("react").Context<Readonly<{
50
+ /** `true` once the widget config loaded; the form, launcher and survey only render when ready. */
51
+ ready: boolean;
52
+ config: WidgetConfig | null;
53
+ open: () => void;
54
+ close: () => void;
55
+ setScreen: (screen: string) => void;
56
+ setUser: (userId: string | number | null) => void;
57
+ setContact: (contact: string | null) => void;
58
+ setLocale: (locale: LocaleMode) => void;
59
+ submit: (input: SubmitInput) => Promise<SubmitResult>;
60
+ }> | null>;
61
+ export declare const FeedbackUiContext: import("react").Context<Readonly<{
62
+ config: WidgetConfig;
63
+ texts: ResolvedTexts;
64
+ tokens: Tokens;
65
+ styles: FeedbackStyles;
66
+ isOpen: boolean;
67
+ launcherShown: boolean;
68
+ contact: string | null;
69
+ draft: DraftStore;
70
+ pickImages: PickImages | undefined;
71
+ open: () => void;
72
+ close: () => void;
73
+ submit: (input: SubmitInput) => Promise<SubmitResult>;
74
+ survey: Survey | null;
75
+ dismissSurvey: () => void;
76
+ sendSurvey: (score: number, message: string) => Promise<SubmitResult>;
77
+ }> | null>;
78
+ export declare function useTheSeekerFeedback(): TheSeekerFeedbackApi;
79
+ export declare function useFeedbackUi(): FeedbackUi;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FeedbackUiContext = exports.FeedbackApiContext = exports.TheSeekerFeedbackContextError = void 0;
4
+ exports.useTheSeekerFeedback = useTheSeekerFeedback;
5
+ exports.useFeedbackUi = useFeedbackUi;
6
+ const react_1 = require("react");
7
+ class TheSeekerFeedbackContextError extends Error {
8
+ constructor(caller) {
9
+ super(`${caller} must be rendered inside <TheSeekerFeedbackProvider>.`);
10
+ this.caller = caller;
11
+ this.name = "TheSeekerFeedbackContextError";
12
+ }
13
+ }
14
+ exports.TheSeekerFeedbackContextError = TheSeekerFeedbackContextError;
15
+ exports.FeedbackApiContext = (0, react_1.createContext)(null);
16
+ exports.FeedbackUiContext = (0, react_1.createContext)(null);
17
+ function useTheSeekerFeedback() {
18
+ const api = (0, react_1.useContext)(exports.FeedbackApiContext);
19
+ if (api === null)
20
+ throw new TheSeekerFeedbackContextError("useTheSeekerFeedback()");
21
+ return api;
22
+ }
23
+ function useFeedbackUi() {
24
+ const ui = (0, react_1.useContext)(exports.FeedbackUiContext);
25
+ if (ui === null)
26
+ throw new TheSeekerFeedbackContextError("TheSeekerFeedback UI");
27
+ return ui;
28
+ }
@@ -0,0 +1,10 @@
1
+ import type { ClientMetadata } from "../core/request";
2
+ /** The slice of RN `Platform` the client metadata needs; kept RN-free so it stays unit-testable. */
3
+ export type PlatformInfo = Readonly<{
4
+ os: string;
5
+ version: string | number;
6
+ release?: string;
7
+ isPad?: boolean;
8
+ }>;
9
+ export declare function clientFromPlatform({ os, version, release, isPad }: PlatformInfo): ClientMetadata | undefined;
10
+ export declare function deviceLocale(): string;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clientFromPlatform = clientFromPlatform;
4
+ exports.deviceLocale = deviceLocale;
5
+ function clientFromPlatform({ os, version, release, isPad }) {
6
+ switch (os) {
7
+ case "ios":
8
+ return {
9
+ platform: "ios",
10
+ osVersion: String(version).slice(0, 32),
11
+ deviceType: isPad === true ? "tablet" : "phone",
12
+ };
13
+ case "android":
14
+ // Platform.Version is the API level (35); the user-facing release ("15") reads better in the CRM.
15
+ return { platform: "android", osVersion: (release ?? String(version)).slice(0, 32) };
16
+ default:
17
+ return undefined;
18
+ }
19
+ }
20
+ function deviceLocale() {
21
+ return Intl.DateTimeFormat().resolvedOptions().locale;
22
+ }
@@ -0,0 +1,32 @@
1
+ import type { ContactMode, Survey } from "../core/config";
2
+ import type { ImageAsset } from "../core/request";
3
+ import type { ResolvedTexts } from "../core/texts";
4
+ export declare const MAX_MESSAGE = 5000;
5
+ export declare const MAX_IMAGES = 4;
6
+ export declare const AUTO_CLOSE_MS = 1500;
7
+ export type TextKey = keyof ResolvedTexts;
8
+ export type DraftError = Readonly<{
9
+ field: "message" | "contact";
10
+ key: TextKey;
11
+ }>;
12
+ export type Draft = Readonly<{
13
+ message: string;
14
+ contact: string | null;
15
+ images: readonly ImageAsset[];
16
+ }>;
17
+ export type DraftStore = Readonly<{
18
+ read(): Draft;
19
+ write(draft: Draft): void;
20
+ }>;
21
+ export type PickOutcome = Readonly<{
22
+ images: readonly ImageAsset[];
23
+ errorKey: TextKey | null;
24
+ }>;
25
+ export declare const EMPTY_DRAFT: Draft;
26
+ /** First problem with a draft, keyed to the field it belongs to; `null` when it can be sent. */
27
+ export declare function draftError(message: string, contact: string, mode: ContactMode): DraftError | null;
28
+ /** Appends picked assets one by one, skipping invalid ones and stopping at the attachment limit. */
29
+ export declare function addPicked(current: readonly ImageAsset[], picked: readonly ImageAsset[]): PickOutcome;
30
+ export declare function surveyScores(type: Survey["type"]): readonly number[];
31
+ /** Keeps the sheet's unsent draft across close/open; a plain closure so render never touches a ref. */
32
+ export declare function createDraftStore(): DraftStore;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EMPTY_DRAFT = exports.AUTO_CLOSE_MS = exports.MAX_IMAGES = exports.MAX_MESSAGE = void 0;
4
+ exports.draftError = draftError;
5
+ exports.addPicked = addPicked;
6
+ exports.surveyScores = surveyScores;
7
+ exports.createDraftStore = createDraftStore;
8
+ const zod_1 = require("zod");
9
+ const request_1 = require("../core/request");
10
+ exports.MAX_MESSAGE = 5000;
11
+ exports.MAX_IMAGES = 4;
12
+ exports.AUTO_CLOSE_MS = 1500;
13
+ exports.EMPTY_DRAFT = { message: "", contact: null, images: [] };
14
+ // Same check the server runs on `contactEmail`, so the form never accepts what the API rejects.
15
+ const emailSchema = zod_1.z.email().max(254);
16
+ /** First problem with a draft, keyed to the field it belongs to; `null` when it can be sent. */
17
+ function draftError(message, contact, mode) {
18
+ if (!message.trim())
19
+ return { field: "message", key: "empty" };
20
+ const trimmed = contact.trim();
21
+ if (mode === "email" && trimmed && !emailSchema.safeParse(trimmed).success)
22
+ return { field: "contact", key: "badEmail" };
23
+ return null;
24
+ }
25
+ /** Appends picked assets one by one, skipping invalid ones and stopping at the attachment limit. */
26
+ function addPicked(current, picked) {
27
+ let images = current;
28
+ let errorKey = null;
29
+ for (const asset of picked) {
30
+ if (images.length >= exports.MAX_IMAGES)
31
+ return { images, errorKey: "tooMany" };
32
+ const verdict = (0, request_1.validateImages)([asset]);
33
+ if (verdict === "ok")
34
+ images = [...images, asset];
35
+ else
36
+ errorKey = (0, request_1.errorMessageKey)(verdict);
37
+ }
38
+ return { images, errorKey };
39
+ }
40
+ function surveyScores(type) {
41
+ switch (type) {
42
+ case "nps":
43
+ return Array.from({ length: 11 }, (_, index) => index);
44
+ case "csat":
45
+ return Array.from({ length: 5 }, (_, index) => index + 1);
46
+ default:
47
+ return assertNever(type);
48
+ }
49
+ }
50
+ /** Keeps the sheet's unsent draft across close/open; a plain closure so render never touches a ref. */
51
+ function createDraftStore() {
52
+ let draft = exports.EMPTY_DRAFT;
53
+ return {
54
+ read: () => draft,
55
+ write: (next) => {
56
+ draft = next;
57
+ },
58
+ };
59
+ }
60
+ function assertNever(value) {
61
+ throw new TypeError(`Unexpected survey type: ${String(value)}`);
62
+ }
@@ -0,0 +1,33 @@
1
+ import type { ReactNode } from "react";
2
+ import type { TextInputProps } from "react-native";
3
+ /** VoiceOver has no live regions; Android already reads `accessibilityLiveRegion` text. */
4
+ export declare function announce(text: string): void;
5
+ export type ButtonProps = Readonly<{
6
+ label: string;
7
+ variant: "primary" | "secondary" | "ghost";
8
+ onPress: () => void;
9
+ disabled?: boolean;
10
+ busy?: boolean;
11
+ testID?: string;
12
+ }>;
13
+ export declare function Button({ label, variant, onPress, disabled, busy, testID }: ButtonProps): import("react").JSX.Element;
14
+ /** lucide:x (two 2/24-stroke diagonals from 6,6 to 18,18) drawn with Views: no SVG renderer in pure JS. */
15
+ export declare function XGlyph({ size, color }: Readonly<{
16
+ size: number;
17
+ color: string;
18
+ }>): import("react").JSX.Element;
19
+ export type TextFieldProps = Readonly<{
20
+ label: string;
21
+ value: string;
22
+ onChangeText: (value: string) => void;
23
+ error?: string | null;
24
+ meta?: string;
25
+ short?: boolean;
26
+ input?: Omit<TextInputProps, "value" | "onChangeText" | "style">;
27
+ }>;
28
+ /** Visible label + input + error/meta line; errors sit under the field that failed. */
29
+ export declare function TextField({ label, value, onChangeText, error, meta, short, input }: TextFieldProps): import("react").JSX.Element;
30
+ export declare function Status({ text, tone }: Readonly<{
31
+ text: string | null;
32
+ tone: "info" | "error";
33
+ }>): ReactNode;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.announce = announce;
4
+ exports.Button = Button;
5
+ exports.XGlyph = XGlyph;
6
+ exports.TextField = TextField;
7
+ exports.Status = Status;
8
+ const jsx_runtime_1 = require("react/jsx-runtime");
9
+ const react_1 = require("react");
10
+ const react_native_1 = require("react-native");
11
+ const context_1 = require("./context");
12
+ /** VoiceOver has no live regions; Android already reads `accessibilityLiveRegion` text. */
13
+ function announce(text) {
14
+ if (react_native_1.Platform.OS === "ios")
15
+ react_native_1.AccessibilityInfo.announceForAccessibility(text);
16
+ }
17
+ function Button({ label, variant, onPress, disabled = false, busy = false, testID }) {
18
+ const { styles } = (0, context_1.useFeedbackUi)();
19
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Pressable, { accessibilityRole: "button", accessibilityState: { disabled, busy }, disabled: disabled, onPress: onPress, ...(testID === undefined ? {} : { testID }), style: ({ pressed }) => [
20
+ styles.button,
21
+ styles[variant],
22
+ pressed && styles[`${variant}Pressed`],
23
+ disabled && styles.disabled,
24
+ ], children: (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [styles.buttonLabel, variant === "primary" && styles.primaryLabel], numberOfLines: 1, children: label }) }));
25
+ }
26
+ /** lucide:x (two 2/24-stroke diagonals from 6,6 to 18,18) drawn with Views: no SVG renderer in pure JS. */
27
+ function XGlyph({ size, color }) {
28
+ const thickness = Math.max(1.5, size / 12);
29
+ const bar = {
30
+ position: "absolute",
31
+ width: size * 0.71 + thickness,
32
+ height: thickness,
33
+ borderRadius: thickness / 2,
34
+ backgroundColor: color,
35
+ };
36
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: { width: size, height: size, alignItems: "center", justifyContent: "center" }, children: [(0, jsx_runtime_1.jsx)(react_native_1.View, { style: [bar, { transform: [{ rotate: "45deg" }] }] }), (0, jsx_runtime_1.jsx)(react_native_1.View, { style: [bar, { transform: [{ rotate: "-45deg" }] }] })] }));
37
+ }
38
+ /** Visible label + input + error/meta line; errors sit under the field that failed. */
39
+ function TextField({ label, value, onChangeText, error = null, meta, short = false, input }) {
40
+ const { styles, tokens } = (0, context_1.useFeedbackUi)();
41
+ const [focused, setFocused] = (0, react_1.useState)(false);
42
+ const multiline = input?.multiline === true;
43
+ return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.field, children: [(0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.label, children: label }), (0, jsx_runtime_1.jsx)(react_native_1.TextInput, { ...input, accessibilityLabel: label, ...(error === null ? {} : { accessibilityHint: error }), value: value, onChangeText: onChangeText, onFocus: () => setFocused(true), onBlur: () => setFocused(false), placeholderTextColor: tokens.mutedText, selectionColor: tokens.accent, keyboardAppearance: tokens.scheme, style: [
44
+ styles.input,
45
+ multiline && (short ? styles.multilineShort : styles.multiline),
46
+ focused && styles.inputFocused,
47
+ error !== null && styles.inputInvalid,
48
+ ] }), error === null && meta === undefined ? null : ((0, jsx_runtime_1.jsxs)(react_native_1.View, { style: styles.fieldFoot, children: [error === null ? null : ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: styles.error, accessibilityLiveRegion: "polite", children: error })), meta === undefined ? null : (0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [styles.meta, styles.end], children: meta })] }))] }));
49
+ }
50
+ function Status({ text, tone }) {
51
+ const { styles } = (0, context_1.useFeedbackUi)();
52
+ if (text === null)
53
+ return null;
54
+ return ((0, jsx_runtime_1.jsx)(react_native_1.Text, { style: [styles.status, tone === "error" && styles.statusError], accessibilityLiveRegion: "polite", children: text }));
55
+ }
@@ -0,0 +1,9 @@
1
+ import type { RefObject } from "react";
2
+ /**
3
+ * A prop the app can also override imperatively (`setScreen`, `setUser`, …). The override holds
4
+ * until the prop itself changes, so a re-rendered prop always wins over an older setter call.
5
+ */
6
+ export declare function usePropOverride<T>(prop: T): readonly [T, (next: T) => void];
7
+ /** Latest value for callbacks/effects that must not re-run when an inline prop changes identity. */
8
+ export declare function useLatestRef<T>(value: T): RefObject<T>;
9
+ export declare function devWarn(message: string): void;