@shotik/react-native 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE +26 -0
- package/README.md +39 -3
- package/README.ru.md +40 -3
- package/dist/analytics/core.d.ts +96 -11
- package/dist/analytics/core.js +295 -22
- package/dist/analytics/privacy.d.ts +4 -0
- package/dist/analytics/privacy.js +46 -0
- package/dist/analytics/replay.d.ts +41 -0
- package/dist/analytics/replay.js +192 -0
- package/dist/analytics/rn.d.ts +52 -2
- package/dist/analytics/rn.js +669 -62
- package/dist/analytics/wire.d.ts +54 -2
- package/dist/analytics/wire.js +44 -4
- package/dist/client.d.ts +94 -1
- package/dist/client.js +254 -17
- package/dist/flow.d.ts +48 -0
- package/dist/flow.js +56 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/parts.d.ts +42 -1
- package/dist/parts.js +72 -14
- package/dist/react.d.ts +24 -3
- package/dist/react.js +42 -15
- package/dist/sheet.d.ts +2 -1
- package/dist/sheet.js +207 -16
- package/dist/support.js +2 -2
- package/dist/theme.d.ts +43 -0
- package/dist/theme.js +90 -4
- package/package.json +15 -2
- package/recipe.json +1 -1
- package/src/analytics/README.md +10 -6
- package/src/analytics/core.ts +314 -25
- package/src/analytics/privacy.ts +50 -0
- package/src/analytics/recipe.json +1 -1
- package/src/analytics/replay.ts +190 -0
- package/src/analytics/rn.tsx +620 -63
- package/src/analytics/wire.ts +99 -8
- package/src/client.ts +344 -19
- package/src/flow.ts +100 -0
- package/src/index.ts +4 -4
- package/src/parts.tsx +102 -14
- package/src/react.tsx +57 -16
- package/src/sheet.tsx +423 -20
- package/src/support.ts +2 -2
- package/src/theme.ts +90 -4
package/dist/parts.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
// Small building blocks:
|
|
2
|
+
// Small building blocks: Pikaicons glyphs (drawn with react-native-svg when the app has it, else plain View stand-ins),
|
|
3
3
|
// the typing dots, the floating launcher, motion tokens and the optional photo / screenshot / svg peers.
|
|
4
4
|
import { useEffect, useRef, useState } from 'react';
|
|
5
5
|
import { AccessibilityInfo, Animated, Easing, I18nManager, Platform, Pressable, StyleSheet, Text, View } from 'react-native';
|
|
@@ -10,7 +10,8 @@ export const motion = {
|
|
|
10
10
|
sheet: { damping: 30, stiffness: 320, mass: 1 },
|
|
11
11
|
bubble: { duration: 170, easing: Easing.bezier(0.25, 0.1, 0.25, 1) },
|
|
12
12
|
chips: { duration: 200, stagger: 40 },
|
|
13
|
-
dots: { period: 900, gap: 150 }
|
|
13
|
+
dots: { period: 900, gap: 150 },
|
|
14
|
+
reveal: { duration: 200, y: 6 }
|
|
14
15
|
};
|
|
15
16
|
export function useReduceMotion() {
|
|
16
17
|
const [reduce, setReduce] = useState(false);
|
|
@@ -26,15 +27,21 @@ export function T({ c, bold, style, ...p }) {
|
|
|
26
27
|
return _jsx(Text, { ...p, maxFontSizeMultiplier: 2, style: [{ color: c.text }, font(c, bold), style] });
|
|
27
28
|
}
|
|
28
29
|
const flip = I18nManager.isRTL ? [{ scaleX: -1 }] : [];
|
|
29
|
-
//
|
|
30
|
+
// Pikaicons free pack (@pikaicons/core-free 0.1.0, MIT, stroke style), 24x24 paths; names in REFS.md, notice in LICENSE.
|
|
30
31
|
const icons = {
|
|
31
|
-
back: ['M15
|
|
32
|
-
close: ['
|
|
33
|
-
send: ['
|
|
34
|
-
attach: ['M12
|
|
35
|
-
clock: ['
|
|
36
|
-
ai: ['
|
|
37
|
-
|
|
32
|
+
back: ['M15 18a30.6 30.6 0 0 1-5.817-5.49.8.8 0 0 1 0-1.02A30.6 30.6 0 0 1 15 6'],
|
|
33
|
+
close: ['m6 18 6-6m0 0 6-6m-6 6L6 6m6 6 6 6'],
|
|
34
|
+
send: ['M6 9.83a30.2 30.2 0 0 1 5.406-5.62A.95.95 0 0 1 12 4m6 5.83a30.2 30.2 0 0 0-5.406-5.62A.95.95 0 0 0 12 4m0 0v16'],
|
|
35
|
+
attach: ['M12 19v-7m0 0V5m0 7H5m7 0h7'],
|
|
36
|
+
clock: ['M12 8v4.816a.5.5 0 0 0 .231.422L15 15m6.15-3a9.15 9.15 0 1 1-18.3 0 9.15 9.15 0 0 1 18.3 0Z'],
|
|
37
|
+
ai: ['M5 17.65V19m0 0v1.35M5 19h1.35M5 19H3.65M12.9 3c.64 5.037 2.63 8.142 8.1 9-5.19.814-7.43 3.728-8.1 9-.67-5.272-2.91-8.186-8.1-9 5.19-.814 7.43-3.728 8.1-9ZM5.7 3c.248 1.506 1.151 2.445 2.7 2.7-1.549.255-2.452 1.194-2.7 2.7C5.452 6.894 4.548 5.955 3 5.7 4.506 5.452 5.445 4.548 5.7 3Z'],
|
|
38
|
+
forward: ['M9 18a30.6 30.6 0 0 0 5.817-5.49.8.8 0 0 0 0-1.02A30.6 30.6 0 0 0 9 6'],
|
|
39
|
+
tick: ['m8.5 12.513 2.341 2.338A15 15 0 0 1 15.4 9.915l.101-.069M21.15 12a9.15 9.15 0 1 1-18.3 0 9.15 9.15 0 0 1 18.3 0Z'],
|
|
40
|
+
trash: ['m16 6-1.106-2.211a3.236 3.236 0 0 0-5.788 0L8 6M4 6h16M6 6h12v9c0 1.864 0 2.796-.305 3.53a4 4 0 0 1-2.164 2.165C14.796 21 13.864 21 12 21s-2.796 0-3.53-.305a4 4 0 0 1-2.166-2.164C6 17.796 6 16.864 6 15z'],
|
|
41
|
+
alert: ['M12 12.624v-4M12 16zm9-4a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z'],
|
|
42
|
+
thumbUp: ['m15.162 7.17.047-.123a7 7 0 0 0 .157-.426 3 3 0 0 0-.602-2.846 7 7 0 0 0-.315-.325 3 3 0 0 0-.184-.176 1 1 0 0 0-1.382.123c-.035.04-.073.095-.15.205L9.721 7.928c-.64.919-.959 1.378-1.185 1.878-.202.443-.348.91-.436 1.389-.1.54-.1 1.1-.1 2.218v1.788c0 1.68 0 2.52.327 3.162a3 3 0 0 0 1.311 1.31c.642.328 1.482.328 3.162.328h3.509c1.467 0 2.2 0 2.792-.27a3 3 0 0 0 1.276-1.098c.354-.546.462-1.271.68-2.722l.53-3.555c.143-.95.214-1.425.072-1.794a1.5 1.5 0 0 0-.66-.766c-.344-.195-.825-.195-1.785-.195h-2.386c-.372 0-.557 0-.694-.026a1.5 1.5 0 0 1-1.199-1.748c.026-.137.093-.31.226-.657Z', 'M3 11.5a2.5 2.5 0 0 1 5 0v6a2.5 2.5 0 1 1-5 0z'],
|
|
43
|
+
thumbDown: ['M16 11.064V12.5a2.5 2.5 0 0 0 5 0v-6a2.5 2.5 0 0 0-5 0v1.768m0 2.796c-.002.813-.015 1.285-.1 1.742a6 6 0 0 1-.436 1.389c-.226.5-.546.959-1.185 1.878l-3.012 4.326c-.077.11-.115.164-.15.205a1 1 0 0 1-1.382.123 3 3 0 0 1-.184-.176c-.164-.164-.245-.245-.315-.326a3 3 0 0 1-.602-2.845c.032-.102.073-.21.157-.426l.048-.124c.133-.346.2-.52.226-.656a1.5 1.5 0 0 0-1.199-1.748c-.137-.026-.322-.026-.694-.026H4.786c-.96 0-1.44 0-1.785-.195a1.5 1.5 0 0 1-.66-.766c-.142-.37-.07-.844.071-1.794l.532-3.555c.217-1.451.325-2.177.679-2.722A3 3 0 0 1 4.899 4.27C5.49 4 6.224 4 7.69 4h3.51c1.68 0 2.52 0 3.162.327a3 3 0 0 1 1.311 1.311c.29.57.323 1.297.327 2.63m0 2.796V8.268'],
|
|
44
|
+
chat: ['M8 10h8m-8 4h4m9-2a9 9 0 0 1-10.272 8.91c-1.203-.17-1.805-.255-1.964-.267-.257-.02-.165-.016-.423-.014-.159 0-.34.014-.702.04l-2.153.153c-.857.062-1.286.092-1.607-.06a1.35 1.35 0 0 1-.641-.641c-.152-.32-.122-.75-.06-1.607l.153-2.153c.026-.362.04-.543.04-.702.002-.258.006-.166-.014-.423-.012-.159-.098-.76-.268-1.964A9 9 0 1 1 21 12Z'],
|
|
38
45
|
};
|
|
39
46
|
// Stroke scaled so every glyph renders about 1.7 pt wide whatever its size.
|
|
40
47
|
function hi(name, color, size, style) {
|
|
@@ -55,10 +62,52 @@ export function Plus({ color }) {
|
|
|
55
62
|
export function ArrowUp({ color }) {
|
|
56
63
|
return hi('send', color, 18) ?? (_jsxs(View, { style: g.box, children: [_jsx(View, { style: [g.bar, { width: 12, backgroundColor: color, transform: [{ rotate: '90deg' }, { translateX: 1 }] }] }), _jsx(View, { style: [g.up, { borderColor: color }] })] }));
|
|
57
64
|
}
|
|
58
|
-
export function Clock({ color }) {
|
|
59
|
-
return hi('clock', color,
|
|
65
|
+
export function Clock({ color, size = 12 }) {
|
|
66
|
+
return hi('clock', color, size) ?? (_jsx(View, { style: [g.clock, { borderColor: color }], children: _jsx(View, { style: [g.hand, { backgroundColor: color }] }) }));
|
|
60
67
|
}
|
|
61
|
-
|
|
68
|
+
export function Forward({ color }) {
|
|
69
|
+
return hi('forward', color, 18, { transform: flip }) ?? (_jsx(View, { style: [g.box, { transform: [{ scaleX: -1 }, ...flip] }], children: _jsx(View, { style: [g.chev, { borderColor: color, width: 7, height: 7 }] }) }));
|
|
70
|
+
}
|
|
71
|
+
export function Tick({ color, size = 14 }) {
|
|
72
|
+
return hi('tick', color, size) ?? _jsx(View, { style: [g.tick, { borderColor: color }] });
|
|
73
|
+
}
|
|
74
|
+
export function Alert({ color, size = 14 }) {
|
|
75
|
+
return hi('alert', color, size) ?? (_jsx(View, { style: [g.clock, { borderColor: color, width: size - 2, height: size - 2, borderRadius: size / 2 }], children: _jsx(View, { style: [g.hand, { backgroundColor: color }] }) }));
|
|
76
|
+
}
|
|
77
|
+
export function Trash({ color, size = 24 }) {
|
|
78
|
+
return hi('trash', color, size) ?? _jsx(View, { style: [g.trash, { borderColor: color }] });
|
|
79
|
+
}
|
|
80
|
+
// Without react-native-svg the Yes / No label carries the meaning on its own.
|
|
81
|
+
export function Thumb({ up, color }) {
|
|
82
|
+
return hi(up ? 'thumbUp' : 'thumbDown', color, 16);
|
|
83
|
+
}
|
|
84
|
+
// Pending action: a short bar sliding in a track (dee68144 "loads then lands on a check"), native driver; Reduce Motion: static.
|
|
85
|
+
export function LoadingBar({ color, reduce }) {
|
|
86
|
+
const v = useRef(new Animated.Value(0)).current;
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (reduce)
|
|
89
|
+
return;
|
|
90
|
+
const loop = Animated.loop(Animated.timing(v, { toValue: 1, duration: motion.dots.period, easing: Easing.inOut(Easing.ease), useNativeDriver: true }));
|
|
91
|
+
loop.start();
|
|
92
|
+
return () => loop.stop();
|
|
93
|
+
}, [reduce, v]);
|
|
94
|
+
const translateX = v.interpolate({ inputRange: [0, 0.5, 1], outputRange: [0, 10, 0] });
|
|
95
|
+
return (_jsx(View, { style: [g.track, { backgroundColor: color + '33' }], children: _jsx(Animated.View, { style: [g.bar6, { backgroundColor: color, opacity: reduce ? 0.6 : 1, transform: [{ translateX: reduce ? 5 : translateX }] }] }) }));
|
|
96
|
+
}
|
|
97
|
+
// Fade + y 6 -> 0 for things that appear in place (consent line, rating, chip); Reduce Motion: fade only.
|
|
98
|
+
export function Reveal({ reduce, style, children }) {
|
|
99
|
+
const v = useRef(new Animated.Value(0)).current;
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
Animated.timing(v, { toValue: 1, duration: motion.reveal.duration, easing: motion.bubble.easing, useNativeDriver: true }).start();
|
|
102
|
+
}, [v]);
|
|
103
|
+
const y = reduce ? 0 : v.interpolate({ inputRange: [0, 1], outputRange: [motion.reveal.y, 0] });
|
|
104
|
+
return _jsx(Animated.View, { style: [style, { opacity: v, transform: [{ translateY: y }] }], children: children });
|
|
105
|
+
}
|
|
106
|
+
// Non-modal help chip after friction (77f37af3 feedback pill + d2671762 toast close): text opens support, x is "Not now".
|
|
107
|
+
export function FrictionChip({ c, t, reduce, onOpen, onClose, style }) {
|
|
108
|
+
return (_jsx(View, { pointerEvents: "box-none", style: [g.chipWrap, style], children: _jsxs(Reveal, { reduce: reduce, style: [g.chip, { backgroundColor: c.bg, borderColor: c.line }], children: [_jsx(Pressable, { onPress: onOpen, accessibilityRole: "button", accessibilityLabel: t.friction, style: g.chipText, children: _jsx(T, { c: c, style: g.chipLabel, numberOfLines: 1, children: t.friction }) }), _jsx(Pressable, { onPress: onClose, hitSlop: 6, accessibilityRole: "button", accessibilityLabel: t.frictionClose, style: [g.chipX, { backgroundColor: c.raised }], children: _jsx(Cross, { color: c.sub, size: 9 }) })] }) }));
|
|
109
|
+
}
|
|
110
|
+
// AI mark: Pikaicons sparkle-ai-01 (a small accent diamond without react-native-svg).
|
|
62
111
|
export function Spark({ color, size = 7 }) {
|
|
63
112
|
return hi('ai', color, Math.round(size * 1.7)) ?? _jsx(View, { style: { width: size, height: size, borderRadius: 1.5, backgroundColor: color, transform: [{ rotate: '45deg' }] } });
|
|
64
113
|
}
|
|
@@ -153,5 +202,14 @@ const g = StyleSheet.create({
|
|
|
153
202
|
gdot: { width: 3.5, height: 3.5, borderRadius: 2 },
|
|
154
203
|
tail: { width: 0, height: 0, borderStartWidth: 5, borderEndWidth: 0, borderTopWidth: 5, borderStartColor: 'transparent', borderEndColor: 'transparent', marginStart: -10, marginTop: -1 },
|
|
155
204
|
badge: { position: 'absolute', top: -4, end: -4, minWidth: 22, height: 22, borderRadius: 11, borderWidth: 2, paddingHorizontal: 5, alignItems: 'center', justifyContent: 'center' },
|
|
156
|
-
badgeText: { color: '#FFFFFF', fontSize: 12, fontWeight: '600', fontVariant: ['tabular-nums'] }
|
|
205
|
+
badgeText: { color: '#FFFFFF', fontSize: 12, fontWeight: '600', fontVariant: ['tabular-nums'] },
|
|
206
|
+
tick: { width: 10, height: 6, borderStartWidth: 1.7, borderBottomWidth: 1.7, transform: [{ rotate: '-45deg' }], marginTop: -2 },
|
|
207
|
+
track: { width: 16, height: 3, borderRadius: 1.5, overflow: 'hidden' },
|
|
208
|
+
trash: { width: 14, height: 16, borderWidth: 1.7, borderTopWidth: 3, borderRadius: 2 },
|
|
209
|
+
bar6: { width: 6, height: 3, borderRadius: 1.5 },
|
|
210
|
+
chipWrap: { position: 'absolute', start: 16, end: 16, bottom: Platform.OS === 'ios' ? 40 : 24, alignItems: 'center' },
|
|
211
|
+
chip: { flexDirection: 'row', alignItems: 'center', gap: 4, minHeight: 44, maxWidth: '100%', borderRadius: 22, borderWidth: StyleSheet.hairlineWidth, paddingStart: 14, paddingEnd: 6, shadowColor: '#000', shadowOpacity: 0.12, shadowRadius: 16, shadowOffset: { width: 0, height: 6 }, elevation: 4 },
|
|
212
|
+
chipText: { flexShrink: 1, justifyContent: 'center', minHeight: 44 },
|
|
213
|
+
chipLabel: { fontSize: 15, lineHeight: 20, flexShrink: 1 },
|
|
214
|
+
chipX: { width: 32, height: 32, borderRadius: 16, alignItems: 'center', justifyContent: 'center', marginStart: 4 }
|
|
157
215
|
});
|
package/dist/react.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
3
3
|
import { SupportClient } from './client';
|
|
4
|
-
import type { LocalAttachment, UserInfo } from './client';
|
|
4
|
+
import type { ActionKind, ActionResult, CancelReason, LocalAttachment, SupportAction, SupportEventKind, UserInfo } from './client';
|
|
5
5
|
import type { SupportTheme } from './theme';
|
|
6
6
|
export interface WidgetProps {
|
|
7
7
|
title?: string;
|
|
@@ -12,6 +12,8 @@ export interface WidgetProps {
|
|
|
12
12
|
quickReplies?: string[];
|
|
13
13
|
locale?: string;
|
|
14
14
|
accentColor?: string;
|
|
15
|
+
appName?: string;
|
|
16
|
+
frictionChip?: boolean;
|
|
15
17
|
}
|
|
16
18
|
export interface ProviderProps extends WidgetProps {
|
|
17
19
|
appKey?: string;
|
|
@@ -31,6 +33,15 @@ export declare function useSupport(): {
|
|
|
31
33
|
close: () => void | undefined;
|
|
32
34
|
select: (conversationId: string | null) => void | undefined;
|
|
33
35
|
identify: (user?: UserInfo) => Promise<void>;
|
|
36
|
+
setAiConsent: (allowed: boolean) => Promise<void> | undefined;
|
|
37
|
+
runAction: (action: SupportAction, conversationId?: string | null) => Promise<ActionResult>;
|
|
38
|
+
canRun: (kind: ActionKind, value?: string) => boolean;
|
|
39
|
+
track: (kind: SupportEventKind, data?: Record<string, string | number | boolean>, conversationId?: string | null) => void | undefined;
|
|
40
|
+
rate: (conversationId: string, score: 1 | -1, comment?: string) => Promise<void> | undefined;
|
|
41
|
+
askForOffer: (reason: CancelReason) => void | undefined;
|
|
42
|
+
deleteMyData: () => Promise<"done" | "pending">;
|
|
43
|
+
openFriction: () => void | undefined;
|
|
44
|
+
dismissFriction: () => void | undefined;
|
|
34
45
|
status: import("./client").Status;
|
|
35
46
|
userId: string | null;
|
|
36
47
|
conversations: import("./client").Conversation[];
|
|
@@ -40,12 +51,22 @@ export declare function useSupport(): {
|
|
|
40
51
|
activeConversationId: string | null;
|
|
41
52
|
error: string | null;
|
|
42
53
|
typing: Record<string, import("./client").Typing>;
|
|
54
|
+
aiConsent: boolean | null;
|
|
55
|
+
subscription: import("./client").Subscription | null;
|
|
56
|
+
widget: import("./client").WidgetConfig | null;
|
|
57
|
+
friction: import("./client").Friction | null;
|
|
43
58
|
};
|
|
44
59
|
export type SupportApi = ReturnType<typeof useSupport>;
|
|
45
60
|
export interface SheetViewProps extends Omit<WidgetProps, 'launcher' | 'launcherStyle'> {
|
|
46
61
|
api?: SupportApi;
|
|
47
62
|
presentation?: 'modal' | 'inline';
|
|
48
63
|
}
|
|
49
|
-
export declare function SupportSheet({ api, presentation, title, teamName, theme, quickReplies, locale, accentColor }: SheetViewProps): import("react").JSX.Element;
|
|
64
|
+
export declare function SupportSheet({ api, presentation, title, teamName, theme, quickReplies, locale, accentColor, appName }: SheetViewProps): import("react").JSX.Element;
|
|
65
|
+
export interface FrictionChipProps {
|
|
66
|
+
theme?: SupportTheme;
|
|
67
|
+
locale?: string;
|
|
68
|
+
style?: StyleProp<ViewStyle>;
|
|
69
|
+
}
|
|
70
|
+
export declare function SupportFrictionChip({ theme, locale, style }: FrictionChipProps): import("react").JSX.Element | null;
|
|
50
71
|
export declare function SupportRoute(): null;
|
|
51
|
-
export declare function SupportWidget({ title, teamName, theme, launcher, launcherStyle, quickReplies, locale, accentColor }: WidgetProps): import("react").JSX.Element;
|
|
72
|
+
export declare function SupportWidget({ title, teamName, theme, launcher, launcherStyle, quickReplies, locale, accentColor, appName, frictionChip }: WidgetProps): import("react").JSX.Element;
|
package/dist/react.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
// React bindings: <ShotikSupportProvider> (state, AppState catch-up, the widget), useSupport()
|
|
3
|
-
//
|
|
2
|
+
// React bindings: <ShotikSupportProvider> (state, AppState catch-up, the widget), useSupport(), <SupportWidget/> (an
|
|
3
|
+
// optional floating launcher with an unread badge, the friction chip, and the chat sheet, mounted on first open only)
|
|
4
|
+
// and <SupportFrictionChip/> for hosts that place the chip themselves.
|
|
4
5
|
import { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore } from 'react';
|
|
5
|
-
import { AppState, useColorScheme } from 'react-native';
|
|
6
|
+
import { AppState, Platform, StyleSheet, useColorScheme } from 'react-native';
|
|
6
7
|
import { nativeDevice } from './native';
|
|
7
|
-
import { Launcher } from './parts';
|
|
8
|
+
import { FrictionChip, Launcher, useReduceMotion } from './parts';
|
|
8
9
|
import { Sheet } from './sheet';
|
|
9
10
|
import { ShotikSupport } from './support';
|
|
10
11
|
import { copyFor, resolveTheme } from './theme';
|
|
@@ -30,7 +31,7 @@ export function ShotikSupportProvider({ appKey, serverUrl, children, widget = tr
|
|
|
30
31
|
}, [client]);
|
|
31
32
|
return (_jsxs(Ctx.Provider, { value: client, children: [children, widget && client ? _jsx(SupportWidget, { ...ui }) : null] }));
|
|
32
33
|
}
|
|
33
|
-
const idle = { status: 'idle', userId: null, conversations: [], messages: {}, unread: 0, unreadBy: {}, open: false, activeConversationId: null, error: null, typing: {} };
|
|
34
|
+
const idle = { status: 'idle', userId: null, conversations: [], messages: {}, unread: 0, unreadBy: {}, open: false, activeConversationId: null, error: null, typing: {}, aiConsent: null, subscription: null, widget: null, friction: null };
|
|
34
35
|
const noop = () => () => { };
|
|
35
36
|
export function useSupport() {
|
|
36
37
|
const client = useContext(Ctx) ?? ShotikSupport.client;
|
|
@@ -46,16 +47,39 @@ export function useSupport() {
|
|
|
46
47
|
open: (conversationId) => client?.open(conversationId),
|
|
47
48
|
close: () => client?.close(),
|
|
48
49
|
select: (conversationId) => client?.select(conversationId),
|
|
49
|
-
identify: (user) => client?.identify(user) ?? Promise.resolve()
|
|
50
|
+
identify: (user) => client?.identify(user) ?? Promise.resolve(),
|
|
51
|
+
setAiConsent: (allowed) => client?.setAiConsent(allowed).catch(() => { }),
|
|
52
|
+
runAction: (action, conversationId) => client?.runAction(action, conversationId) ?? Promise.resolve('failed'),
|
|
53
|
+
// Whether an action can do anything here: the host's onAction, or a store URL fallback it can open.
|
|
54
|
+
canRun: (kind, value) => !!client && (!!client.config.onAction || (!!client.config.openUrl && !!client.fallbackUrl({ kind, value }))),
|
|
55
|
+
track: (kind, data, conversationId) => client?.track(kind, data, conversationId),
|
|
56
|
+
rate: (conversationId, score, comment) => client?.rate(conversationId, score, comment).catch(() => { }),
|
|
57
|
+
askForOffer: (reason) => client?.askForOffer(reason),
|
|
58
|
+
// Delete my data (§3.13): 'done' once the server erased it, 'pending' while the request waits for the network.
|
|
59
|
+
deleteMyData: () => client?.deleteMyData() ?? Promise.resolve('done'),
|
|
60
|
+
openFriction: () => client?.openFriction(),
|
|
61
|
+
dismissFriction: () => client?.dismissFriction()
|
|
50
62
|
}), [state, client]);
|
|
51
63
|
}
|
|
52
|
-
|
|
53
|
-
const live = useSupport();
|
|
54
|
-
const s = api ?? live;
|
|
64
|
+
function useLook(theme, accentColor, locale) {
|
|
55
65
|
const system = useColorScheme() === 'dark' ? 'dark' : 'light';
|
|
56
66
|
const c = useMemo(() => resolveTheme(accentColor && !theme?.accent ? { ...theme, accent: accentColor } : theme, system), [theme, accentColor, system]);
|
|
57
67
|
const t = useMemo(() => copyFor(locale ?? nativeDevice().locale), [locale]);
|
|
58
|
-
return
|
|
68
|
+
return { c, t };
|
|
69
|
+
}
|
|
70
|
+
export function SupportSheet({ api, presentation = 'inline', title, teamName, theme, quickReplies = [], locale, accentColor, appName }) {
|
|
71
|
+
const live = useSupport();
|
|
72
|
+
const s = api ?? live;
|
|
73
|
+
const { c, t } = useLook(theme, accentColor, locale);
|
|
74
|
+
return _jsx(Sheet, { s: s, c: c, t: t, title: title ?? t.title, team: teamName ?? t.team, quickReplies: quickReplies, presentation: presentation, appName: appName });
|
|
75
|
+
}
|
|
76
|
+
export function SupportFrictionChip({ theme, locale, style }) {
|
|
77
|
+
const s = useSupport();
|
|
78
|
+
const { c, t } = useLook(theme, undefined, locale);
|
|
79
|
+
const reduce = useReduceMotion();
|
|
80
|
+
if (!s.friction || s.visible)
|
|
81
|
+
return null;
|
|
82
|
+
return _jsx(FrictionChip, { c: c, t: t, reduce: reduce, onOpen: s.openFriction, onClose: s.dismissFriction, style: style });
|
|
59
83
|
}
|
|
60
84
|
// A route that opens the widget and steps back, so <scheme>://support deep links and push taps land in support.
|
|
61
85
|
// Expo Router: export { SupportRoute as default } from '@shotik/react-native' in app/support.tsx.
|
|
@@ -74,15 +98,18 @@ export function SupportRoute() {
|
|
|
74
98
|
return null;
|
|
75
99
|
}
|
|
76
100
|
// Nothing but the (optional) launcher renders until the first open; the sheet stays mounted afterwards.
|
|
77
|
-
export function SupportWidget({ title, teamName, theme, launcher = false, launcherStyle, quickReplies = [], locale, accentColor }) {
|
|
101
|
+
export function SupportWidget({ title, teamName, theme, launcher = false, launcherStyle, quickReplies = [], locale, accentColor, appName, frictionChip = true }) {
|
|
78
102
|
const s = useSupport();
|
|
79
|
-
const
|
|
80
|
-
const
|
|
81
|
-
const t = useMemo(() => copyFor(locale ?? nativeDevice().locale), [locale]);
|
|
103
|
+
const { c, t } = useLook(theme, accentColor, locale);
|
|
104
|
+
const reduce = useReduceMotion();
|
|
82
105
|
const [mounted, setMounted] = useState(s.visible);
|
|
83
106
|
useEffect(() => {
|
|
84
107
|
if (s.visible)
|
|
85
108
|
setMounted(true);
|
|
86
109
|
}, [s.visible]);
|
|
87
|
-
return (_jsxs(_Fragment, { children: [launcher && !s.visible ? _jsx(Launcher, { c: c, t: t, unread: s.unread, onPress: () => s.open(), style: launcherStyle }) : null, mounted ? _jsx(Sheet, { s: s, c: c, t: t, title: title ?? t.title, team: teamName ?? t.team, quickReplies: quickReplies }) : null] }));
|
|
110
|
+
return (_jsxs(_Fragment, { children: [frictionChip && s.friction && !s.visible ? _jsx(FrictionChip, { c: c, t: t, reduce: reduce, onOpen: s.openFriction, onClose: s.dismissFriction, style: launcher ? st.aboveLauncher : undefined }) : null, launcher && !s.visible ? _jsx(Launcher, { c: c, t: t, unread: s.unread, onPress: () => s.open(), style: launcherStyle }) : null, mounted ? _jsx(Sheet, { s: s, c: c, t: t, title: title ?? t.title, team: teamName ?? t.team, quickReplies: quickReplies, appName: appName }) : null] }));
|
|
88
111
|
}
|
|
112
|
+
const st = StyleSheet.create({
|
|
113
|
+
// The chip sits above the 56 pt launcher with a 16 pt gap.
|
|
114
|
+
aboveLauncher: { bottom: (Platform.OS === 'ios' ? 40 : 24) + 56 + 16, end: 20, start: 20, alignItems: 'flex-end' }
|
|
115
|
+
});
|
package/dist/sheet.d.ts
CHANGED
|
@@ -8,5 +8,6 @@ export interface SheetProps {
|
|
|
8
8
|
team: string;
|
|
9
9
|
quickReplies: string[];
|
|
10
10
|
presentation?: 'modal' | 'inline';
|
|
11
|
+
appName?: string;
|
|
11
12
|
}
|
|
12
|
-
export declare function Sheet({ s, c, t, title, team, quickReplies, presentation }: SheetProps): import("react").JSX.Element;
|
|
13
|
+
export declare function Sheet({ s, c, t, title, team, quickReplies, presentation, appName }: SheetProps): import("react").JSX.Element;
|