@zean-chat/react-native 0.1.2 → 0.1.6

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.
@@ -1,7 +1,10 @@
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
- /** Where the chat keeps the device's secret and unsent messages: AsyncStorage, MMKV, or anything with these two. */
4
+ /**
5
+ * Where the chat keeps the device's secret, unsent messages and the newest 100 messages: AsyncStorage, MMKV, or anything
6
+ * with these two.
7
+ */
5
8
  export interface ZeanStorage {
6
9
  getItem: (key: string) => string | null | Promise<string | null>;
7
10
  setItem: (key: string, value: string) => void | Promise<void>;
@@ -31,7 +34,13 @@ export interface ZeanChatProps {
31
34
  locale?: ZeanLocale;
32
35
  /** Leave it out: the phone's. */
33
36
  colorScheme?: ZeanColorScheme;
34
- /** Where the chat's backend is. Leave it out: the default is Zean's own. */
37
+ /** Photos the person sends in one message, from 1 to 6. Leave it out: 4. */
38
+ maxPhotos?: number;
39
+ /**
40
+ * Where the chat's backend is. Leave it out: the App key says which of Zean's own. For local development only, so
41
+ * left out of the documentation.
42
+ * @internal
43
+ */
35
44
  backendUrl?: string;
36
45
  }
37
46
  /** The chat's methods, and the count of replies the Contact has not seen. */
@@ -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,32 @@ 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;
7
9
  /** A photo's link asked for before its message is stored is refused: asked again this often, a few times. */
8
10
  export declare const LINK_RETRY_MS = 1500;
9
11
  export declare const LINK_RETRIES = 5;
10
12
  /** Signed links last an hour: asked again after 50 minutes. */
11
13
  export declare const LINK_LIFETIME_MS: number;
12
- /** The colours around the App's own, as in the web widget (zinc). */
14
+ /** The colours around the App's own: iOS's greys, the page a step darker than what sits on it. */
13
15
  export declare const NEUTRAL_COLORS: Record<ZeanColorScheme, NeutralColors>;
16
+ /** Corners, in points: inside a run of bubbles, a pill, a bubble or a card, the message field. */
17
+ export declare const RADII: {
18
+ inner: number;
19
+ pill: number;
20
+ group: number;
21
+ composer: number;
22
+ };
23
+ /** The message field's buttons and its one-line height. */
24
+ export declare const COMPOSER_BUTTON = 40;
25
+ /** Messages from one sender this close in time are one run: one name, one avatar, one time. */
26
+ export declare const RUN_GAP_MS: number;
27
+ /** How far the Contact scrolls up from the newest message before the button back to it shows. */
28
+ export declare const NEWEST_BUTTON_OFFSET = 120;
29
+ /** The longest side of an image in the Conversation. */
30
+ export declare const IMAGE_SIDE = 240;
31
+ /** A message that arrives while the chat is open rises into place this fast. */
32
+ export declare const ENTER_MS = 180;
14
33
  /**
15
34
  * The web widget's icons (Lucide), and the product's mark, drawn black at 72 pixels and tinted on screen: React Native
16
35
  * draws no SVG without a native package.
@@ -1,6 +1,8 @@
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';
5
+ import type { StyleProp, ViewStyle } from 'react-native';
4
6
  import type { ZeanColorScheme } from '../interfaces';
5
7
  import type { fr } from '../i18n/fr';
6
8
  export interface ChatView {
@@ -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
- openImage: (image: ViewedImage) => void;
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 being sent with the Contact's next message. */
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
- status: 'uploading' | 'ready' | 'failed';
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
- message: ChatMessage;
122
+ row: ConversationRow;
91
123
  app: ChatApp;
92
- /** The team's name above the first message of a run. */
93
- showName: boolean;
94
- /** Under the Contact's latest message: sending, sent or seen. */
95
- status: string | null;
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
- image: ViewedImage;
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?: number;
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;
@@ -3,6 +3,8 @@ import type { ZeanColorScheme } from '../interfaces';
3
3
  /** `{name}` in a text, filled from `values`. */
4
4
  export declare function format(template: string, values: Record<string, string | number>): string;
5
5
  /** The chat's colours: the App's, made for the screen's scheme, and the neutral ones around them. */
6
+ /** Photos per message: what the app chose, a whole number from 1 to what a message takes; 4 when it chose none. */
7
+ export declare function photoLimit(chosen: number | undefined): number;
6
8
  export declare function chatColors(color: string, scheme: ZeanColorScheme): ChatColors;
7
9
  /**
8
10
  * The phone's languages, preferred first. On iOS the list the person ordered in Settings: the app's own language is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zean-chat/react-native",
3
- "version": "0.1.2",
3
+ "version": "0.1.6",
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,7 +52,8 @@
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": {
58
59
  "expo-image-picker": "*",
@@ -69,13 +70,20 @@
69
70
  }
70
71
  },
71
72
  "devDependencies": {
73
+ "@jest/globals": "29.7.0",
74
+ "@react-native/babel-preset": "0.87.1",
75
+ "@react-native/jest-preset": "0.87.1",
76
+ "@testing-library/react-native": "14.1.0",
72
77
  "@types/react": "19.2.14",
73
78
  "@zean/config": "*",
74
79
  "@zean/sdk-core": "*",
75
80
  "@zean/shared": "*",
81
+ "babel-jest": "29.7.0",
76
82
  "convex": "1.46.0",
83
+ "jest": "29.7.0",
77
84
  "react": "19.2.5",
78
85
  "react-native": "0.87.1",
86
+ "test-renderer": "1.3.1",
79
87
  "typescript": "6.0.3",
80
88
  "vitest": "4.1.11"
81
89
  }