@microsurveysai/react-native 0.1.7 → 0.1.8
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/dist/index.cjs +50 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +51 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -74,6 +74,8 @@ interface Trigger {
|
|
|
74
74
|
warmupCount: number;
|
|
75
75
|
steps: TriggerStep[];
|
|
76
76
|
}
|
|
77
|
+
/** Thank-you pace; anything else (or null) is normal. */
|
|
78
|
+
type SuccessPace = "slow" | "fast";
|
|
77
79
|
interface Survey {
|
|
78
80
|
id: string;
|
|
79
81
|
name: string;
|
|
@@ -89,6 +91,8 @@ interface Survey {
|
|
|
89
91
|
/** `"sheet"` | `"dialog"` | null (inherit the project theme's position). */
|
|
90
92
|
presentation?: string | null;
|
|
91
93
|
successMessage?: string | null;
|
|
94
|
+
/** How long the thank-you stays up: "slow" | "fast" | null (normal). */
|
|
95
|
+
successPace?: SuccessPace | null;
|
|
92
96
|
/** Platform targeting for auto-presentation. Empty/absent = all platforms.
|
|
93
97
|
* The engine skips a survey whose list is non-empty and excludes the client's
|
|
94
98
|
* platform. Explicit inline `<MicroSurvey>` embeds ignore this. */
|
|
@@ -462,4 +466,4 @@ interface SurveyModalProps {
|
|
|
462
466
|
}
|
|
463
467
|
declare function SurveyModal({ survey, theme: projectTheme, fontFamily, onResult, onClose }: SurveyModalProps): react.JSX.Element | null;
|
|
464
468
|
|
|
465
|
-
export { type AmplitudeEvent, type AnswerValue, type AsyncKeyValueStorage, type KeyValueStorage, MicroSurvey, type MicroSurveyProps, MicroSurveys, type MicroSurveysAmplitudePlugin, type MicroSurveysOptions, MicroSurveysProvider, type MicroSurveysProviderProps, type ProjectTheme, type Question, type Survey, type SurveyAnswer, SurveyModal, type SurveyModalProps, type SurveyResult, hydrateAsyncStorage, parseConfig, useMicroSurveys, useMicroSurveysInstance };
|
|
469
|
+
export { type AmplitudeEvent, type AnswerValue, type AsyncKeyValueStorage, type KeyValueStorage, MicroSurvey, type MicroSurveyProps, MicroSurveys, type MicroSurveysAmplitudePlugin, type MicroSurveysOptions, MicroSurveysProvider, type MicroSurveysProviderProps, type ProjectTheme, type Question, type SuccessPace, type Survey, type SurveyAnswer, SurveyModal, type SurveyModalProps, type SurveyResult, hydrateAsyncStorage, parseConfig, useMicroSurveys, useMicroSurveysInstance };
|
package/dist/index.d.ts
CHANGED
|
@@ -74,6 +74,8 @@ interface Trigger {
|
|
|
74
74
|
warmupCount: number;
|
|
75
75
|
steps: TriggerStep[];
|
|
76
76
|
}
|
|
77
|
+
/** Thank-you pace; anything else (or null) is normal. */
|
|
78
|
+
type SuccessPace = "slow" | "fast";
|
|
77
79
|
interface Survey {
|
|
78
80
|
id: string;
|
|
79
81
|
name: string;
|
|
@@ -89,6 +91,8 @@ interface Survey {
|
|
|
89
91
|
/** `"sheet"` | `"dialog"` | null (inherit the project theme's position). */
|
|
90
92
|
presentation?: string | null;
|
|
91
93
|
successMessage?: string | null;
|
|
94
|
+
/** How long the thank-you stays up: "slow" | "fast" | null (normal). */
|
|
95
|
+
successPace?: SuccessPace | null;
|
|
92
96
|
/** Platform targeting for auto-presentation. Empty/absent = all platforms.
|
|
93
97
|
* The engine skips a survey whose list is non-empty and excludes the client's
|
|
94
98
|
* platform. Explicit inline `<MicroSurvey>` embeds ignore this. */
|
|
@@ -462,4 +466,4 @@ interface SurveyModalProps {
|
|
|
462
466
|
}
|
|
463
467
|
declare function SurveyModal({ survey, theme: projectTheme, fontFamily, onResult, onClose }: SurveyModalProps): react.JSX.Element | null;
|
|
464
468
|
|
|
465
|
-
export { type AmplitudeEvent, type AnswerValue, type AsyncKeyValueStorage, type KeyValueStorage, MicroSurvey, type MicroSurveyProps, MicroSurveys, type MicroSurveysAmplitudePlugin, type MicroSurveysOptions, MicroSurveysProvider, type MicroSurveysProviderProps, type ProjectTheme, type Question, type Survey, type SurveyAnswer, SurveyModal, type SurveyModalProps, type SurveyResult, hydrateAsyncStorage, parseConfig, useMicroSurveys, useMicroSurveysInstance };
|
|
469
|
+
export { type AmplitudeEvent, type AnswerValue, type AsyncKeyValueStorage, type KeyValueStorage, MicroSurvey, type MicroSurveyProps, MicroSurveys, type MicroSurveysAmplitudePlugin, type MicroSurveysOptions, MicroSurveysProvider, type MicroSurveysProviderProps, type ProjectTheme, type Question, type SuccessPace, type Survey, type SurveyAnswer, SurveyModal, type SurveyModalProps, type SurveyResult, hydrateAsyncStorage, parseConfig, useMicroSurveys, useMicroSurveysInstance };
|
package/dist/index.js
CHANGED
|
@@ -180,6 +180,7 @@ function normalizeSurvey(raw) {
|
|
|
180
180
|
dismissible: typeof raw.dismissible === "boolean" ? raw.dismissible : null,
|
|
181
181
|
presentation: strOrUndef(raw.presentation) ?? null,
|
|
182
182
|
successMessage: strOrUndef(raw.successMessage) ?? null,
|
|
183
|
+
successPace: raw.successPace === "slow" || raw.successPace === "fast" ? raw.successPace : null,
|
|
183
184
|
platforms: Array.isArray(raw.platforms) ? raw.platforms.filter((p) => typeof p === "string") : null
|
|
184
185
|
};
|
|
185
186
|
}
|
|
@@ -918,7 +919,7 @@ function debugProperties(properties) {
|
|
|
918
919
|
}
|
|
919
920
|
|
|
920
921
|
// src/core/version.ts
|
|
921
|
-
var SDK_VERSION = "0.1.
|
|
922
|
+
var SDK_VERSION = "0.1.8";
|
|
922
923
|
|
|
923
924
|
// src/core/client.ts
|
|
924
925
|
var DEFAULT_BASE_URL = "https://console.microsurveys.ai";
|
|
@@ -1282,6 +1283,19 @@ function createClient(opts) {
|
|
|
1282
1283
|
return new MicroSurveysClient(opts);
|
|
1283
1284
|
}
|
|
1284
1285
|
|
|
1286
|
+
// src/core/thanks.ts
|
|
1287
|
+
var DEFAULT_SUCCESS_MESSAGE = "Thanks!";
|
|
1288
|
+
function thanksMessage(message) {
|
|
1289
|
+
const trimmed = message?.trim();
|
|
1290
|
+
return trimmed ? trimmed : DEFAULT_SUCCESS_MESSAGE;
|
|
1291
|
+
}
|
|
1292
|
+
function thanksDurationMs(message, pace) {
|
|
1293
|
+
const chars = [...thanksMessage(message)].length;
|
|
1294
|
+
const base = Math.min(Math.max(1e3 + 50 * chars, 1300), 7e3);
|
|
1295
|
+
const percent = pace === "slow" ? 150 : pace === "fast" ? 70 : 100;
|
|
1296
|
+
return Math.round(base * percent / 100);
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1285
1299
|
// src/amplitude.ts
|
|
1286
1300
|
function createAmplitudePlugin(forwarder) {
|
|
1287
1301
|
return {
|
|
@@ -1517,7 +1531,7 @@ import { SafeAreaProvider, initialWindowMetrics, useSafeAreaInsets } from "react
|
|
|
1517
1531
|
|
|
1518
1532
|
// src/ui/SurveyCard.tsx
|
|
1519
1533
|
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState as useState2 } from "react";
|
|
1520
|
-
import { Animated, Platform as Platform4, Pressable as Pressable3, ScrollView, StyleSheet as StyleSheet3, Text as Text2, View as View3 } from "react-native";
|
|
1534
|
+
import { AccessibilityInfo, Animated, Platform as Platform4, Pressable as Pressable3, ScrollView, StyleSheet as StyleSheet3, Text as Text2, View as View3 } from "react-native";
|
|
1521
1535
|
|
|
1522
1536
|
// src/ui/CloseButton.tsx
|
|
1523
1537
|
import { Platform as Platform3, Pressable, StyleSheet, View } from "react-native";
|
|
@@ -1948,7 +1962,6 @@ var styles2 = StyleSheet2.create({
|
|
|
1948
1962
|
// src/ui/SurveyCard.tsx
|
|
1949
1963
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1950
1964
|
var CLIP_ROOM = 4;
|
|
1951
|
-
var THANKS_MS = 1300;
|
|
1952
1965
|
var SurveyCard = forwardRef(function SurveyCard2({ survey, theme, variant, bottomInset, onResult, onClose }, ref) {
|
|
1953
1966
|
const questions = useMemo(() => [...survey.questions].sort((a, b) => a.order - b.order), [survey]);
|
|
1954
1967
|
const dismissible = survey.dismissible !== false;
|
|
@@ -1959,9 +1972,27 @@ var SurveyCard = forwardRef(function SurveyCard2({ survey, theme, variant, botto
|
|
|
1959
1972
|
const [height, setHeight] = useState2(0);
|
|
1960
1973
|
const reported = useRef(false);
|
|
1961
1974
|
const closeTimer = useRef(null);
|
|
1975
|
+
const closed = useRef(false);
|
|
1976
|
+
const unmounted = useRef(false);
|
|
1962
1977
|
useEffect(() => () => {
|
|
1978
|
+
unmounted.current = true;
|
|
1963
1979
|
if (closeTimer.current) clearTimeout(closeTimer.current);
|
|
1964
1980
|
}, []);
|
|
1981
|
+
function closeThanks() {
|
|
1982
|
+
if (closed.current) return;
|
|
1983
|
+
closed.current = true;
|
|
1984
|
+
if (closeTimer.current) clearTimeout(closeTimer.current);
|
|
1985
|
+
closeTimer.current = null;
|
|
1986
|
+
onClose();
|
|
1987
|
+
}
|
|
1988
|
+
function startThanksTimer() {
|
|
1989
|
+
const ms = thanksDurationMs(survey.successMessage, survey.successPace);
|
|
1990
|
+
const schedule = (screenReader) => {
|
|
1991
|
+
if (closed.current || unmounted.current || closeTimer.current) return;
|
|
1992
|
+
closeTimer.current = setTimeout(closeThanks, screenReader ? ms * 2 : ms);
|
|
1993
|
+
};
|
|
1994
|
+
AccessibilityInfo.isScreenReaderEnabled().then(schedule, () => schedule(false));
|
|
1995
|
+
}
|
|
1965
1996
|
const question = questions[index];
|
|
1966
1997
|
const isLast = index >= questions.length - 1;
|
|
1967
1998
|
const valid = question ? isAnswerValid(question, current) : false;
|
|
@@ -1991,7 +2022,7 @@ var SurveyCard = forwardRef(function SurveyCard2({ survey, theme, variant, botto
|
|
|
1991
2022
|
}
|
|
1992
2023
|
if (report(true)) {
|
|
1993
2024
|
setDone(true);
|
|
1994
|
-
|
|
2025
|
+
startThanksTimer();
|
|
1995
2026
|
}
|
|
1996
2027
|
}
|
|
1997
2028
|
const pad = theme.spacing + 4;
|
|
@@ -1999,13 +2030,22 @@ var SurveyCard = forwardRef(function SurveyCard2({ survey, theme, variant, botto
|
|
|
1999
2030
|
const hasProgress = questions.length > 1;
|
|
2000
2031
|
if (!question) return null;
|
|
2001
2032
|
if (done) {
|
|
2002
|
-
const custom = survey.successMessage?.trim();
|
|
2003
2033
|
return (
|
|
2004
2034
|
// Keep the card's height so the sheet doesn't jump when the content swaps.
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2035
|
+
// Tapping the thanks closes it at once.
|
|
2036
|
+
/* @__PURE__ */ jsx3(
|
|
2037
|
+
Pressable3,
|
|
2038
|
+
{
|
|
2039
|
+
onPress: closeThanks,
|
|
2040
|
+
accessibilityLiveRegion: "polite",
|
|
2041
|
+
accessibilityHint: "Closes the survey",
|
|
2042
|
+
style: [styles3.thanks, { minHeight: height, padding: pad }],
|
|
2043
|
+
children: /* @__PURE__ */ jsx3(FadeIn, { children: /* @__PURE__ */ jsxs2(View3, { style: styles3.thanksStack, children: [
|
|
2044
|
+
/* @__PURE__ */ jsx3(View3, { style: [styles3.check, { backgroundColor: theme.accent }], children: /* @__PURE__ */ jsx3(Text2, { allowFontScaling: false, style: [styles3.checkGlyph, { color: theme.accentText }], children: "\u2713" }) }),
|
|
2045
|
+
/* @__PURE__ */ jsx3(Text2, { style: [promptStyle(theme), { color: theme.text, textAlign: "center", marginTop: theme.spacing }], children: thanksMessage(survey.successMessage) })
|
|
2046
|
+
] }) })
|
|
2047
|
+
}
|
|
2048
|
+
)
|
|
2009
2049
|
);
|
|
2010
2050
|
}
|
|
2011
2051
|
return /* @__PURE__ */ jsxs2(View3, { onLayout: (e) => setHeight(e.nativeEvent.layout.height), style: styles3.card, children: [
|
|
@@ -2083,7 +2123,8 @@ var styles3 = StyleSheet3.create({
|
|
|
2083
2123
|
scroll: { flexGrow: 0, flexShrink: 1 },
|
|
2084
2124
|
button: { alignItems: "center", justifyContent: "center" },
|
|
2085
2125
|
thanks: { alignItems: "center", justifyContent: "center" },
|
|
2086
|
-
|
|
2126
|
+
// Stretch so a long message wraps inside the card instead of overflowing it.
|
|
2127
|
+
thanksStack: { alignItems: "center", alignSelf: "stretch" },
|
|
2087
2128
|
check: { width: 48, height: 48, borderRadius: 24, alignItems: "center", justifyContent: "center" },
|
|
2088
2129
|
checkGlyph: { fontSize: 26, fontWeight: "700", lineHeight: 30 }
|
|
2089
2130
|
});
|