@zean-chat/react-native 0.1.4 → 0.1.7
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 +7 -6
- package/dist/components/AppMark.d.ts +1 -1
- package/dist/components/ChatHeader.d.ts +2 -2
- package/dist/components/ChatModal.d.ts +3 -2
- package/dist/components/ChatNotice.d.ts +1 -1
- package/dist/components/Composer.d.ts +3 -2
- package/dist/components/EmailForm.d.ts +1 -1
- package/dist/components/ImageViewer.d.ts +5 -2
- package/dist/components/MessageBubble.d.ts +5 -2
- package/dist/components/MessageFiles.d.ts +1 -1
- package/dist/components/MessageList.d.ts +2 -1
- package/dist/components/MessageMeta.d.ts +3 -0
- package/dist/components/PendingPhotos.d.ts +3 -0
- package/dist/components/PoweredBy.d.ts +1 -1
- package/dist/components/Skeleton.d.ts +3 -0
- package/dist/components/TypingBubble.d.ts +1 -1
- package/dist/components/ZeanChat.d.ts +1 -1
- package/dist/hooks/use-keyboard-overlap.d.ts +4 -3
- package/dist/hooks/use-pending-photos.d.ts +5 -4
- package/dist/hooks/use-rise-in.d.ts +8 -0
- package/dist/i18n/en.d.ts +5 -0
- package/dist/i18n/fr.d.ts +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1257 -548
- package/dist/interfaces.d.ts +16 -4
- package/dist/models/conversation.utils.d.ts +15 -0
- package/dist/models/sdk.constants.d.ts +22 -1
- package/dist/models/sdk.interface.d.ts +76 -14
- package/dist/models/sdk.utils.d.ts +17 -1
- package/package.json +31 -3
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
export type ZeanAttributeValue = string | number | boolean;
|
|
2
2
|
/** What the app knows about the person, shown on the Contact's profile: `{ city: 'Douala', orders: 12 }`. */
|
|
3
3
|
export type ZeanAttributes = Record<string, ZeanAttributeValue>;
|
|
4
|
-
/**
|
|
5
|
-
export interface
|
|
4
|
+
/** Storage read with `getItem` and written with `setItem`: AsyncStorage, Expo SQLite's `expo-sqlite/kv-store`, or your own. */
|
|
5
|
+
export interface ZeanKeyValueStorage {
|
|
6
6
|
getItem: (key: string) => string | null | Promise<string | null>;
|
|
7
7
|
setItem: (key: string, value: string) => void | Promise<void>;
|
|
8
8
|
}
|
|
9
|
+
/** An MMKV instance from `react-native-mmkv`, any version, passed as it is. */
|
|
10
|
+
export interface ZeanMMKV {
|
|
11
|
+
getString: (key: string) => string | undefined;
|
|
12
|
+
set: (key: string, value: string) => void;
|
|
13
|
+
}
|
|
14
|
+
/** Where the chat keeps the device's secret, unsent messages and the newest 100 messages. */
|
|
15
|
+
export type ZeanStorage = ZeanKeyValueStorage | ZeanMMKV;
|
|
9
16
|
export type ZeanLocale = 'fr' | 'en';
|
|
10
17
|
/** The person signed in to your app. Only `id` is needed; the rest shows on their Contact. */
|
|
11
18
|
export interface ZeanUser {
|
|
@@ -21,8 +28,11 @@ export type ZeanColorScheme = 'light' | 'dark';
|
|
|
21
28
|
export interface ZeanChatProps {
|
|
22
29
|
/** The App's public key, from the install code. */
|
|
23
30
|
appKey: string;
|
|
24
|
-
/**
|
|
25
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Leave it out: the chat finds the storage the app has, MMKV, AsyncStorage or Expo SQLite. Pass one to choose it.
|
|
33
|
+
* Read once, when the chat starts.
|
|
34
|
+
*/
|
|
35
|
+
storage?: ZeanStorage;
|
|
26
36
|
/** The person signed in to your app: `{ id, name, email }`. Leave it out when no one is: the chat signs out. */
|
|
27
37
|
user?: ZeanUser;
|
|
28
38
|
/** What the app knows about the person, shown on the Contact's profile. */
|
|
@@ -31,6 +41,8 @@ export interface ZeanChatProps {
|
|
|
31
41
|
locale?: ZeanLocale;
|
|
32
42
|
/** Leave it out: the phone's. */
|
|
33
43
|
colorScheme?: ZeanColorScheme;
|
|
44
|
+
/** Photos the person sends in one message, from 1 to 6. Leave it out: 4. */
|
|
45
|
+
maxPhotos?: number;
|
|
34
46
|
/**
|
|
35
47
|
* Where the chat's backend is. Leave it out: the App key says which of Zean's own. For local development only, so
|
|
36
48
|
* left out of the documentation.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ChatMessage } from '@zean/sdk-core';
|
|
2
|
+
import type { Locale } from '@zean/shared/constants/app';
|
|
3
|
+
import type { ConversationRow } from './sdk.interface';
|
|
4
|
+
import type { fr } from '../i18n/fr';
|
|
5
|
+
/**
|
|
6
|
+
* The Conversation, oldest first, with what each message's neighbours decide about it: where runs by one sender start
|
|
7
|
+
* and end, where days start, and how far the Contact's own messages went. `seen`: the team read the Contact's latest
|
|
8
|
+
* message, so every one before it; a message a Member answered after, by name, was read too. The welcome goes first,
|
|
9
|
+
* on the day of the first message.
|
|
10
|
+
*/
|
|
11
|
+
export declare function conversationRows(messages: ReadonlyArray<ChatMessage>, seen: boolean, welcome: ChatMessage | null): Array<ConversationRow>;
|
|
12
|
+
/** The time under a run: `14:05`. */
|
|
13
|
+
export declare function messageTime(timestamp: number, locale: Locale): string;
|
|
14
|
+
/** The day above its messages: today, yesterday, the weekday within the week, then the date, with its year if not this one. */
|
|
15
|
+
export declare function dayLabel(timestamp: number, now: number, locale: Locale, t: Pick<typeof fr, 'today' | 'yesterday'>): string;
|
|
@@ -4,13 +4,34 @@ import type { ZeanColorScheme } from '../interfaces';
|
|
|
4
4
|
export declare const OFFLINE_NOTICE_MS = 3000;
|
|
5
5
|
/** Android's navigation bar with its three buttons, in points: the gesture bar is half as tall. */
|
|
6
6
|
export declare const ANDROID_NAVIGATION_BAR = 48;
|
|
7
|
+
/** Photos a Contact sends in one message, unless `ZeanChat`'s `maxPhotos` says otherwise. */
|
|
8
|
+
export declare const DEFAULT_MAX_PHOTOS = 4;
|
|
9
|
+
/** The chat's own MMKV instance, apart from the app's. */
|
|
10
|
+
export declare const CHAT_STORAGE_ID = "zean-chat";
|
|
7
11
|
/** A photo's link asked for before its message is stored is refused: asked again this often, a few times. */
|
|
8
12
|
export declare const LINK_RETRY_MS = 1500;
|
|
9
13
|
export declare const LINK_RETRIES = 5;
|
|
10
14
|
/** Signed links last an hour: asked again after 50 minutes. */
|
|
11
15
|
export declare const LINK_LIFETIME_MS: number;
|
|
12
|
-
/** The colours around the App's own
|
|
16
|
+
/** The colours around the App's own: iOS's greys, the page a step darker than what sits on it. */
|
|
13
17
|
export declare const NEUTRAL_COLORS: Record<ZeanColorScheme, NeutralColors>;
|
|
18
|
+
/** Corners, in points: inside a run of bubbles, a pill, a bubble or a card, the message field. */
|
|
19
|
+
export declare const RADII: {
|
|
20
|
+
inner: number;
|
|
21
|
+
pill: number;
|
|
22
|
+
group: number;
|
|
23
|
+
composer: number;
|
|
24
|
+
};
|
|
25
|
+
/** The message field's buttons and its one-line height. */
|
|
26
|
+
export declare const COMPOSER_BUTTON = 40;
|
|
27
|
+
/** Messages from one sender this close in time are one run: one name, one avatar, one time. */
|
|
28
|
+
export declare const RUN_GAP_MS: number;
|
|
29
|
+
/** How far the Contact scrolls up from the newest message before the button back to it shows. */
|
|
30
|
+
export declare const NEWEST_BUTTON_OFFSET = 120;
|
|
31
|
+
/** The longest side of an image in the Conversation. */
|
|
32
|
+
export declare const IMAGE_SIDE = 240;
|
|
33
|
+
/** A message that arrives while the chat is open rises into place this fast. */
|
|
34
|
+
export declare const ENTER_MS = 180;
|
|
14
35
|
/**
|
|
15
36
|
* The web widget's icons (Lucide), and the product's mark, drawn black at 72 pixels and tinted on screen: React Native
|
|
16
37
|
* draws no SVG without a native package.
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { Chat, ChatApp, ChatAttachment, ChatMessage, ChatResult, ChatSender, ChatState } from '@zean/sdk-core';
|
|
2
|
+
import type { Locale } from '@zean/shared/constants/app';
|
|
2
3
|
import type { AccentColors } from '@zean/shared/interfaces/widget';
|
|
3
4
|
import type { ReactNode } from 'react';
|
|
4
|
-
import type {
|
|
5
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
6
|
+
import type { ZeanColorScheme, ZeanMMKV } from '../interfaces';
|
|
5
7
|
import type { fr } from '../i18n/fr';
|
|
6
8
|
export interface ChatView {
|
|
7
9
|
open: boolean;
|
|
@@ -17,6 +19,8 @@ export interface NeutralColors {
|
|
|
17
19
|
border: string;
|
|
18
20
|
danger: string;
|
|
19
21
|
online: string;
|
|
22
|
+
/** Bones while something loads. */
|
|
23
|
+
skeleton: string;
|
|
20
24
|
}
|
|
21
25
|
/** The colours of the chat, for the App's colour and the screen's scheme. */
|
|
22
26
|
export interface ChatColors extends AccentColors, NeutralColors {
|
|
@@ -30,8 +34,33 @@ export interface SignedLink {
|
|
|
30
34
|
export interface ChatContextValue {
|
|
31
35
|
chat: Chat;
|
|
32
36
|
t: typeof fr;
|
|
37
|
+
locale: Locale;
|
|
33
38
|
colors: ChatColors;
|
|
34
|
-
|
|
39
|
+
/** When the chat opened: a message newer than this arrived while it was open, and rises into place. */
|
|
40
|
+
openedAt: number;
|
|
41
|
+
/** The viewer, on one of a message's images. */
|
|
42
|
+
openImages: (gallery: ViewedGallery) => void;
|
|
43
|
+
/** Photos the Contact sends in one message. */
|
|
44
|
+
maxPhotos: number;
|
|
45
|
+
}
|
|
46
|
+
/** Where a message sits among its neighbours, worked out once for the whole Conversation. */
|
|
47
|
+
export interface ConversationRow {
|
|
48
|
+
message: ChatMessage;
|
|
49
|
+
/** First of a run by one sender: the gap above, the name, the round corner. */
|
|
50
|
+
startsRun: boolean;
|
|
51
|
+
/** Last of its run: the avatar, the time and the delivery under it. */
|
|
52
|
+
endsRun: boolean;
|
|
53
|
+
/** First message of a day: the day above it. */
|
|
54
|
+
startsDay: boolean;
|
|
55
|
+
/** The Contact's own: on its way, stored, or read by the team. Null for the team's. */
|
|
56
|
+
receipt: 'sending' | 'sent' | 'seen' | null;
|
|
57
|
+
/** The App's welcome, written by no one: no time under it. */
|
|
58
|
+
welcome: boolean;
|
|
59
|
+
}
|
|
60
|
+
/** The images the viewer pages through, and the one it shows first. */
|
|
61
|
+
export interface ViewedGallery {
|
|
62
|
+
images: Array<ViewedImage>;
|
|
63
|
+
index: number;
|
|
35
64
|
}
|
|
36
65
|
/** An image shown full screen: its link and its file name, read as its label. */
|
|
37
66
|
export interface ViewedImage {
|
|
@@ -53,12 +82,16 @@ export interface PickedPhoto {
|
|
|
53
82
|
export interface PhotoPicker {
|
|
54
83
|
pick: (limit: number) => Promise<Array<PickedPhoto>>;
|
|
55
84
|
}
|
|
56
|
-
/** A photo
|
|
85
|
+
/** A photo picked for the Contact's next message: `picked` until the message is sent, then uploaded. */
|
|
57
86
|
export interface PendingPhoto {
|
|
58
87
|
id: string;
|
|
59
88
|
name: string;
|
|
60
89
|
uri: string;
|
|
61
|
-
|
|
90
|
+
/** Checked when picked: a photo type the chat takes. */
|
|
91
|
+
type: string;
|
|
92
|
+
width?: number;
|
|
93
|
+
height?: number;
|
|
94
|
+
status: 'picked' | 'uploading' | 'ready' | 'failed';
|
|
62
95
|
attachment: ChatAttachment | null;
|
|
63
96
|
}
|
|
64
97
|
/** The space the screen's edges and the keyboard take, in points. */
|
|
@@ -69,6 +102,7 @@ export interface ScreenInsets {
|
|
|
69
102
|
export interface ChatModalProps {
|
|
70
103
|
chat: Chat;
|
|
71
104
|
colorScheme?: ZeanColorScheme;
|
|
105
|
+
maxPhotos?: number;
|
|
72
106
|
}
|
|
73
107
|
export interface ChatScreenProps {
|
|
74
108
|
state: ChatState;
|
|
@@ -78,8 +112,6 @@ export interface ChatScreenProps {
|
|
|
78
112
|
export interface ChatHeaderProps {
|
|
79
113
|
app: ChatApp;
|
|
80
114
|
online: boolean;
|
|
81
|
-
/** The header text, shown until the Contact writes. */
|
|
82
|
-
greeting: string | null;
|
|
83
115
|
topInset: number;
|
|
84
116
|
onClose: () => void;
|
|
85
117
|
}
|
|
@@ -87,12 +119,12 @@ export interface MessageListProps {
|
|
|
87
119
|
state: ChatState;
|
|
88
120
|
}
|
|
89
121
|
export interface MessageBubbleProps {
|
|
90
|
-
|
|
122
|
+
row: ConversationRow;
|
|
91
123
|
app: ChatApp;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
124
|
+
onRetry: () => void;
|
|
125
|
+
}
|
|
126
|
+
export interface MessageMetaProps {
|
|
127
|
+
row: ConversationRow;
|
|
96
128
|
onRetry: () => void;
|
|
97
129
|
}
|
|
98
130
|
export interface MessageFilesProps {
|
|
@@ -126,15 +158,25 @@ export interface ChatNoticeProps {
|
|
|
126
158
|
children: ReactNode;
|
|
127
159
|
}
|
|
128
160
|
export interface ImageViewerProps {
|
|
129
|
-
|
|
161
|
+
gallery: ViewedGallery;
|
|
162
|
+
topInset: number;
|
|
130
163
|
onClose: () => void;
|
|
131
164
|
}
|
|
165
|
+
export interface SkeletonProps {
|
|
166
|
+
style?: StyleProp<ViewStyle>;
|
|
167
|
+
}
|
|
168
|
+
export interface PendingPhotosProps {
|
|
169
|
+
photos: Array<PendingPhoto>;
|
|
170
|
+
/** While the message goes, its photos stay as they are. */
|
|
171
|
+
locked: boolean;
|
|
172
|
+
onRemove: (id: string) => void;
|
|
173
|
+
}
|
|
132
174
|
export interface IconProps {
|
|
133
175
|
name: IconName;
|
|
134
176
|
color: string;
|
|
135
|
-
size
|
|
177
|
+
size: number;
|
|
136
178
|
}
|
|
137
|
-
export type IconName = 'close' | 'send' | 'photo' | 'file' | 'download' | 'remove' | 'mark';
|
|
179
|
+
export type IconName = 'close' | 'send' | 'photo' | 'file' | 'download' | 'remove' | 'mark' | 'check' | 'seen' | 'down';
|
|
138
180
|
export interface ExpoImagePickerAsset {
|
|
139
181
|
uri: string;
|
|
140
182
|
fileName?: string | null;
|
|
@@ -187,6 +229,26 @@ export interface ImagePickerResult {
|
|
|
187
229
|
errorCode?: string;
|
|
188
230
|
assets?: Array<ImagePickerAsset>;
|
|
189
231
|
}
|
|
232
|
+
/** `react-native-mmkv`: `createMMKV` from version 4, the `MMKV` class before. */
|
|
233
|
+
export interface MMKVModule {
|
|
234
|
+
createMMKV?: (config: {
|
|
235
|
+
id: string;
|
|
236
|
+
}) => ZeanMMKV;
|
|
237
|
+
MMKV?: new (config: {
|
|
238
|
+
id: string;
|
|
239
|
+
}) => ZeanMMKV;
|
|
240
|
+
}
|
|
241
|
+
/** `expo-application`: the app's Bundle ID on iOS, its Package name on Android. */
|
|
242
|
+
export interface ExpoApplicationModule {
|
|
243
|
+
applicationId: string | null;
|
|
244
|
+
}
|
|
245
|
+
/** `react-native-device-info`, its named exports or its default one. */
|
|
246
|
+
export interface DeviceInfoModule {
|
|
247
|
+
getBundleId?: () => string;
|
|
248
|
+
default?: {
|
|
249
|
+
getBundleId?: () => string;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
190
252
|
export interface ImagePickerModule {
|
|
191
253
|
launchImageLibrary: (options: ImagePickerOptions) => Promise<ImagePickerResult>;
|
|
192
254
|
}
|
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
import type { ChatColors, ScreenInsets } from './sdk.interface';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AppBundle, ChatStorage } from '@zean/sdk-core';
|
|
3
|
+
import type { ZeanColorScheme, ZeanStorage } from '../interfaces';
|
|
3
4
|
/** `{name}` in a text, filled from `values`. */
|
|
4
5
|
export declare function format(template: string, values: Record<string, string | number>): string;
|
|
5
6
|
/** The chat's colours: the App's, made for the screen's scheme, and the neutral ones around them. */
|
|
7
|
+
/** Photos per message: what the app chose, a whole number from 1 to what a message takes; 4 when it chose none. */
|
|
8
|
+
export declare function photoLimit(chosen: number | undefined): number;
|
|
6
9
|
export declare function chatColors(color: string, scheme: ZeanColorScheme): ChatColors;
|
|
7
10
|
/**
|
|
8
11
|
* The phone's languages, preferred first. On iOS the list the person ordered in Settings: the app's own language is
|
|
9
12
|
* only one the app was translated into.
|
|
10
13
|
*/
|
|
11
14
|
export declare function deviceLanguages(): Array<string>;
|
|
15
|
+
/**
|
|
16
|
+
* The app the chat runs in, which the App must allow: its Bundle ID on iOS, its Package name on Android. Read through
|
|
17
|
+
* `expo-application`, else `react-native-device-info`. With neither, none: the chat stays hidden and says which to
|
|
18
|
+
* install.
|
|
19
|
+
*/
|
|
20
|
+
export declare function appBundle(): AppBundle | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Where the chat keeps what lasts across launches: the storage the app passed, else the one it has, found by itself:
|
|
23
|
+
* MMKV, then AsyncStorage, then Expo SQLite's `kv-store`, then the browser's on the web. With none, memory: the chat
|
|
24
|
+
* starts over at each launch. A read or a write that fails, as when a native module is missing from the build, falls
|
|
25
|
+
* back to memory too.
|
|
26
|
+
*/
|
|
27
|
+
export declare function chatStorage(storage?: ZeanStorage): ChatStorage;
|
|
12
28
|
/** "iOS 18.2" or "Android 15", for the Contact panel. */
|
|
13
29
|
export declare function deviceOs(): string | undefined;
|
|
14
30
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zean-chat/react-native",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "In-app support chat for React Native and Expo, iOS and Android. Pure JS, no native module. A free Intercom, Crisp and Zendesk mobile SDK alternative.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -52,30 +52,58 @@
|
|
|
52
52
|
"scripts": {
|
|
53
53
|
"prepublishOnly": "npm run build",
|
|
54
54
|
"build": "node ../../scripts/build-sdk.mjs cjs",
|
|
55
|
-
"check-types": "tsc --noEmit"
|
|
55
|
+
"check-types": "tsc --noEmit",
|
|
56
|
+
"test": "jest --coverage"
|
|
56
57
|
},
|
|
57
58
|
"peerDependencies": {
|
|
59
|
+
"@react-native-async-storage/async-storage": "*",
|
|
60
|
+
"expo-application": "*",
|
|
58
61
|
"expo-image-picker": "*",
|
|
62
|
+
"expo-sqlite": "*",
|
|
59
63
|
"react": ">=19",
|
|
60
64
|
"react-native": ">=0.78",
|
|
61
|
-
"react-native-
|
|
65
|
+
"react-native-device-info": "*",
|
|
66
|
+
"react-native-image-picker": "*",
|
|
67
|
+
"react-native-mmkv": "*"
|
|
62
68
|
},
|
|
63
69
|
"peerDependenciesMeta": {
|
|
70
|
+
"expo-application": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"react-native-device-info": {
|
|
74
|
+
"optional": true
|
|
75
|
+
},
|
|
64
76
|
"expo-image-picker": {
|
|
65
77
|
"optional": true
|
|
66
78
|
},
|
|
67
79
|
"react-native-image-picker": {
|
|
68
80
|
"optional": true
|
|
81
|
+
},
|
|
82
|
+
"@react-native-async-storage/async-storage": {
|
|
83
|
+
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"expo-sqlite": {
|
|
86
|
+
"optional": true
|
|
87
|
+
},
|
|
88
|
+
"react-native-mmkv": {
|
|
89
|
+
"optional": true
|
|
69
90
|
}
|
|
70
91
|
},
|
|
71
92
|
"devDependencies": {
|
|
93
|
+
"@jest/globals": "29.7.0",
|
|
94
|
+
"@react-native/babel-preset": "0.87.1",
|
|
95
|
+
"@react-native/jest-preset": "0.87.1",
|
|
96
|
+
"@testing-library/react-native": "14.1.0",
|
|
72
97
|
"@types/react": "19.2.14",
|
|
73
98
|
"@zean/config": "*",
|
|
74
99
|
"@zean/sdk-core": "*",
|
|
75
100
|
"@zean/shared": "*",
|
|
101
|
+
"babel-jest": "29.7.0",
|
|
76
102
|
"convex": "1.46.0",
|
|
103
|
+
"jest": "29.7.0",
|
|
77
104
|
"react": "19.2.5",
|
|
78
105
|
"react-native": "0.87.1",
|
|
106
|
+
"test-renderer": "1.3.1",
|
|
79
107
|
"typescript": "6.0.3",
|
|
80
108
|
"vitest": "4.1.11"
|
|
81
109
|
}
|