@marketcanopy/react-native-live-chat 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +288 -2
- package/lib/module/components/LiveChat.js +77 -0
- package/lib/module/components/LiveChat.js.map +1 -0
- package/lib/module/components/LiveChatBanner.js +71 -0
- package/lib/module/components/LiveChatBanner.js.map +1 -0
- package/lib/module/components/LiveChatBubble.js +110 -0
- package/lib/module/components/LiveChatBubble.js.map +1 -0
- package/lib/module/components/LiveChatMessageBubble.js +154 -0
- package/lib/module/components/LiveChatMessageBubble.js.map +1 -0
- package/lib/module/components/LiveChatScreen.js +260 -0
- package/lib/module/components/LiveChatScreen.js.map +1 -0
- package/lib/module/components/primitives.js +131 -0
- package/lib/module/components/primitives.js.map +1 -0
- package/lib/module/icons.js +93 -0
- package/lib/module/icons.js.map +1 -0
- package/lib/module/index.js +10 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/live-chat-api.js +138 -0
- package/lib/module/live-chat-api.js.map +1 -0
- package/lib/module/live-chat-messages.js +116 -0
- package/lib/module/live-chat-messages.js.map +1 -0
- package/lib/module/live-chat-push.js +14 -0
- package/lib/module/live-chat-push.js.map +1 -0
- package/lib/module/live-chat-socket.js +95 -0
- package/lib/module/live-chat-socket.js.map +1 -0
- package/lib/module/live-chat.js +676 -0
- package/lib/module/live-chat.js.map +1 -0
- package/lib/module/message-text.js +66 -0
- package/lib/module/message-text.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/strings.js +59 -0
- package/lib/module/strings.js.map +1 -0
- package/lib/module/theme.js +455 -0
- package/lib/module/theme.js.map +1 -0
- package/lib/module/translations.js +556 -0
- package/lib/module/translations.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/ui-context.js +42 -0
- package/lib/module/ui-context.js.map +1 -0
- package/lib/module/useKeyboardInset.js +30 -0
- package/lib/module/useKeyboardInset.js.map +1 -0
- package/lib/module/useLiveChat.js +16 -0
- package/lib/module/useLiveChat.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/components/LiveChat.d.ts +23 -0
- package/lib/typescript/src/components/LiveChat.d.ts.map +1 -0
- package/lib/typescript/src/components/LiveChatBanner.d.ts +15 -0
- package/lib/typescript/src/components/LiveChatBanner.d.ts.map +1 -0
- package/lib/typescript/src/components/LiveChatBubble.d.ts +13 -0
- package/lib/typescript/src/components/LiveChatBubble.d.ts.map +1 -0
- package/lib/typescript/src/components/LiveChatMessageBubble.d.ts +17 -0
- package/lib/typescript/src/components/LiveChatMessageBubble.d.ts.map +1 -0
- package/lib/typescript/src/components/LiveChatScreen.d.ts +16 -0
- package/lib/typescript/src/components/LiveChatScreen.d.ts.map +1 -0
- package/lib/typescript/src/components/primitives.d.ts +43 -0
- package/lib/typescript/src/components/primitives.d.ts.map +1 -0
- package/lib/typescript/src/icons.d.ts +10 -0
- package/lib/typescript/src/icons.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +12 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/live-chat-api.d.ts +30 -0
- package/lib/typescript/src/live-chat-api.d.ts.map +1 -0
- package/lib/typescript/src/live-chat-messages.d.ts +102 -0
- package/lib/typescript/src/live-chat-messages.d.ts.map +1 -0
- package/lib/typescript/src/live-chat-push.d.ts +9 -0
- package/lib/typescript/src/live-chat-push.d.ts.map +1 -0
- package/lib/typescript/src/live-chat-socket.d.ts +42 -0
- package/lib/typescript/src/live-chat-socket.d.ts.map +1 -0
- package/lib/typescript/src/live-chat.d.ts +96 -0
- package/lib/typescript/src/live-chat.d.ts.map +1 -0
- package/lib/typescript/src/message-text.d.ts +20 -0
- package/lib/typescript/src/message-text.d.ts.map +1 -0
- package/lib/typescript/src/strings.d.ts +16 -0
- package/lib/typescript/src/strings.d.ts.map +1 -0
- package/lib/typescript/src/theme.d.ts +50 -0
- package/lib/typescript/src/theme.d.ts.map +1 -0
- package/lib/typescript/src/translations.d.ts +36 -0
- package/lib/typescript/src/translations.d.ts.map +1 -0
- package/lib/typescript/src/types.d.ts +74 -0
- package/lib/typescript/src/types.d.ts.map +1 -0
- package/lib/typescript/src/ui-context.d.ts +25 -0
- package/lib/typescript/src/ui-context.d.ts.map +1 -0
- package/lib/typescript/src/useKeyboardInset.d.ts +8 -0
- package/lib/typescript/src/useKeyboardInset.d.ts.map +1 -0
- package/lib/typescript/src/useLiveChat.d.ts +13 -0
- package/lib/typescript/src/useLiveChat.d.ts.map +1 -0
- package/package.json +124 -4
- package/src/components/LiveChat.tsx +101 -0
- package/src/components/LiveChatBanner.tsx +83 -0
- package/src/components/LiveChatBubble.tsx +116 -0
- package/src/components/LiveChatMessageBubble.tsx +210 -0
- package/src/components/LiveChatScreen.tsx +281 -0
- package/src/components/primitives.tsx +202 -0
- package/src/icons.tsx +87 -0
- package/src/index.ts +40 -0
- package/src/live-chat-api.ts +209 -0
- package/src/live-chat-messages.ts +177 -0
- package/src/live-chat-push.ts +13 -0
- package/src/live-chat-socket.ts +108 -0
- package/src/live-chat.ts +757 -0
- package/src/message-text.ts +67 -0
- package/src/strings.ts +74 -0
- package/src/theme.ts +448 -0
- package/src/translations.ts +554 -0
- package/src/types.ts +92 -0
- package/src/ui-context.tsx +74 -0
- package/src/useKeyboardInset.ts +32 -0
- package/src/useLiveChat.ts +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Market Canopy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,289 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @marketcanopy/react-native-live-chat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Market Canopy live chat for React Native: the chat your site's widget runs, as native screens.
|
|
4
|
+
|
|
5
|
+
- A full-screen chat with the agent's name, business hours notice, streamed AI replies, quick replies, links, typing dots and file attachments.
|
|
6
|
+
- A floating bubble while the chat is minimized, which the person drags out of the way, with the count of unread replies.
|
|
7
|
+
- A banner at the top of the app when a reply arrives while the chat is minimized.
|
|
8
|
+
- Light and dark themes, your colors and font, and strings in 17 languages (`ar`, `de`, `en`, `es`, `fa`, `fr`, `hi`, `id`, `ja`, `ko`, `ro`, `ru`, `tr`, `uk`, `ur`, `vi`, `zh`).
|
|
9
|
+
|
|
10
|
+
It is JavaScript only. It has no native code of its own.
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install @marketcanopy/react-native-live-chat react-native-safe-area-context react-native-svg
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
| Peer dependency | Version |
|
|
19
|
+
| -------------------------------- | --------- |
|
|
20
|
+
| `react` | `>= 19.0` |
|
|
21
|
+
| `react-native` | `>= 0.79` |
|
|
22
|
+
| `react-native-safe-area-context` | `>= 5.0` |
|
|
23
|
+
| `react-native-svg` | `>= 15.0` |
|
|
24
|
+
|
|
25
|
+
The two native peers are installed in your app, so their native code is linked once (run `pod install` for iOS). The package itself bundles `socket.io-client` and `zustand`.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
Create one chat for the life of the app, and render `<LiveChat>` once, after your own tree and inside your `SafeAreaProvider`.
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { createLiveChat, LiveChat } from '@marketcanopy/react-native-live-chat';
|
|
33
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
34
|
+
|
|
35
|
+
const chat = createLiveChat({
|
|
36
|
+
session: {
|
|
37
|
+
// Opens the conversation, or resumes the open one. See "The session".
|
|
38
|
+
start: () => startSupportChatSession(),
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
export function App() {
|
|
43
|
+
return (
|
|
44
|
+
<SafeAreaProvider>
|
|
45
|
+
<Navigation />
|
|
46
|
+
<LiveChat chat={chat} />
|
|
47
|
+
</SafeAreaProvider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Open it from anywhere, for example a "Chat with us" row:
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
<Button title="Chat with us" onPress={chat.open} />
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`<LiveChat>` shows nothing until `chat.open()`.
|
|
59
|
+
|
|
60
|
+
## The session
|
|
61
|
+
|
|
62
|
+
The chat talks to the Market Canopy API as a visitor of one conversation. `session.start` resolves that visitor session:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
interface LiveChatSession {
|
|
66
|
+
token: string; // the visitor token
|
|
67
|
+
conversationId: string;
|
|
68
|
+
appearance?: { agentName?: string; accent?: string; logoUrl?: string } | null;
|
|
69
|
+
availability?: {
|
|
70
|
+
isOpen: boolean;
|
|
71
|
+
nextOpenAt?: string;
|
|
72
|
+
unavailableMessage?: string;
|
|
73
|
+
replyTimeExpectation?: string;
|
|
74
|
+
} | null;
|
|
75
|
+
handoverState?: 'ai' | 'queued' | 'human';
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The chat calls `start` when it opens, and again whenever the token expires, so `start` must always return a fresh token for the same open conversation.
|
|
80
|
+
|
|
81
|
+
For an app whose users sign in with Market Canopy (a device session), the session comes from the signed-in API, which resumes the person's open conversation on the chat widget attached to the app, or opens one linked to them:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
async function startSupportChatSession(): Promise<LiveChatSession> {
|
|
85
|
+
const response = await fetch(
|
|
86
|
+
'https://api.marketcanopy.com/v1/auth/devices/current/support-chat/sessions',
|
|
87
|
+
{ method: 'POST', headers: { authorization: `Bearer ${accessToken}` } }
|
|
88
|
+
);
|
|
89
|
+
if (!response.ok) throw new Error(`Chat session failed: ${response.status}`);
|
|
90
|
+
return (await response.json()).data;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Starting a session from a chat widget's public key alone, for an app whose users do not sign in with Market Canopy, is not available yet: the public widget routes accept browser origins only.
|
|
95
|
+
|
|
96
|
+
## `createLiveChat(options)`
|
|
97
|
+
|
|
98
|
+
| Option | Type | Default | |
|
|
99
|
+
| ------------- | ----------------------------------- | ------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
100
|
+
| `session` | `LiveChatSessionSource` | required | `start()`, and optionally `recordScreen(view)` (see "Screens"). |
|
|
101
|
+
| `baseUrl` | `string` | `https://api.marketcanopy.com` | The API origin. |
|
|
102
|
+
| `realtimeUrl` | `string` | `baseUrl` | The socket origin. |
|
|
103
|
+
| `storage` | `LiveChatStorage` | in memory | Lets `resume()` bring a running chat back after a restart (see "Resuming"). |
|
|
104
|
+
| `playSound` | `(sound: 'send' \| 'receive') => void` | none | Plays a cue (see "Sounds"). |
|
|
105
|
+
| `onError` | `(source, error) => void` | none | Every failure the chat handled, for your error reporting. The chat shows its own notice. |
|
|
106
|
+
| `appState` | `LiveChatAppState` | React Native's `AppState` | The socket closes in the background, and the transcript catches up on return. |
|
|
107
|
+
|
|
108
|
+
It returns the chat:
|
|
109
|
+
|
|
110
|
+
| Member | |
|
|
111
|
+
| ------------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
112
|
+
| `open()` | Shows the full-screen chat, starting or resuming the conversation. |
|
|
113
|
+
| `minimize()` | Hides it. The bubble stays while the chat runs. |
|
|
114
|
+
| `end()` | The person's "End chat": no bubble until the chat is opened again. The conversation stays for the agent. |
|
|
115
|
+
| `reset()` | Ends the chat and forgets it. Call it on sign-out. |
|
|
116
|
+
| `resume()` | Brings back a chat that was running when the app last closed (needs `storage`). |
|
|
117
|
+
| `hasChat()` | True while a chat runs. |
|
|
118
|
+
| `reportScreen({ screen, title })` | Tells the agent which screen the person is on (see "Screens"). |
|
|
119
|
+
| `sendText(text)`, `sendFile(file)`, `retry(messageId)`, `attachmentUrl(message)`, `dismissBanner()` | What the built-in screens call; useful for a UI of your own. |
|
|
120
|
+
| `store` | A zustand store of the chat's state (`phase`, `visible`, `messages`, `unread`, ...). |
|
|
121
|
+
| `destroy()` | Stops listening to `AppState` and closes the socket, for a chat you throw away. |
|
|
122
|
+
| `start(appState)` | Listens to another app state source and returns the stop function, for an app with a lifecycle of its own. The chat already listens from creation. |
|
|
123
|
+
|
|
124
|
+
## `<LiveChat>`
|
|
125
|
+
|
|
126
|
+
| Prop | Type | Default | |
|
|
127
|
+
| ---------------- | -------------------------------------- | ------------------ | ------------------------------------------------------------------------------------- |
|
|
128
|
+
| `chat` | the chat | required | |
|
|
129
|
+
| `pickAttachment` | `() => Promise<LiveChatFile \| null>` | none | Your file picker. Without it the chat has no paperclip (see "Attachments"). |
|
|
130
|
+
| `theme` | `{ colors?, fontFamily? }` | built-in | Any of the colors, over the light and dark themes (see "Theme"). |
|
|
131
|
+
| `colorScheme` | `'light' \| 'dark'` | the system setting | |
|
|
132
|
+
| `locale` | `string` | the device locale | A BCP 47 tag for the strings, times and numbers. |
|
|
133
|
+
| `strings` | `Partial<LiveChatStrings>` | none | Wording of your own, or a locale the package does not ship. |
|
|
134
|
+
| `testID` | `string` | `live-chat` | The bubble is `<testID>-bubble`, the banner `<testID>-banner`. |
|
|
135
|
+
|
|
136
|
+
### `useLiveChat(chat)`
|
|
137
|
+
|
|
138
|
+
For your own entry points: `{ active, visible, unread, open }`.
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
const { unread, open } = useLiveChat(chat);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Theme
|
|
145
|
+
|
|
146
|
+
The person's own bubbles take the accent color set on the chat widget in the dashboard. Everything else comes from the theme:
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
<LiveChat
|
|
150
|
+
chat={chat}
|
|
151
|
+
theme={{
|
|
152
|
+
colors: { primary: '#155dfc', primaryForeground: '#ffffff' },
|
|
153
|
+
fontFamily: 'Inter',
|
|
154
|
+
}}
|
|
155
|
+
/>
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Colors: `background`, `foreground`, `muted`, `mutedForeground`, `border`, `input`, `primary`, `primaryForeground`, `secondary`, `destructive`, `destructiveForeground`, `popover`, `success`. `lightColors` and `darkColors` are exported. Pass a stable `theme` object (a constant or `useMemo`), not a new one on every render.
|
|
159
|
+
|
|
160
|
+
The layout uses logical properties, so it mirrors in a right-to-left app.
|
|
161
|
+
|
|
162
|
+
## Attachments
|
|
163
|
+
|
|
164
|
+
The package does not pick files. Give it your picker, built on the library your app already uses:
|
|
165
|
+
|
|
166
|
+
```tsx
|
|
167
|
+
import { pick } from '@react-native-documents/picker';
|
|
168
|
+
|
|
169
|
+
<LiveChat
|
|
170
|
+
chat={chat}
|
|
171
|
+
pickAttachment={async () => {
|
|
172
|
+
try {
|
|
173
|
+
const [file] = await pick();
|
|
174
|
+
return file === undefined
|
|
175
|
+
? null
|
|
176
|
+
: {
|
|
177
|
+
uri: file.uri,
|
|
178
|
+
name: file.name ?? 'attachment',
|
|
179
|
+
contentType: file.type ?? 'application/octet-stream',
|
|
180
|
+
size: file.size ?? undefined,
|
|
181
|
+
};
|
|
182
|
+
} catch {
|
|
183
|
+
return null; // cancelled
|
|
184
|
+
}
|
|
185
|
+
}}
|
|
186
|
+
/>
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`uri` must be one the app can `fetch` (`file://`, `content://`, `ph://`).
|
|
190
|
+
|
|
191
|
+
## Sounds
|
|
192
|
+
|
|
193
|
+
The package plays nothing by itself. `playSound` is called with `'send'` when the person's message goes out and `'receive'` when a reply comes in, only while the app is in the foreground. Play them with your own audio library; a player that throws changes nothing in the chat.
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import Sound from 'react-native-sound';
|
|
197
|
+
|
|
198
|
+
const sounds = {
|
|
199
|
+
send: new Sound('send.mp3', Sound.MAIN_BUNDLE),
|
|
200
|
+
receive: new Sound('receive.wav', Sound.MAIN_BUNDLE),
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const chat = createLiveChat({
|
|
204
|
+
session,
|
|
205
|
+
playSound: (sound) => sounds[sound].play(),
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
With `react-native-sound` on iOS, the `RNSound` pod may fail to link (`AVAudioPlayer` undefined) until the Podfile's `post_install` adds `-framework AVFoundation` and `-framework AudioToolbox` to that target's `OTHER_LDFLAGS`.
|
|
210
|
+
|
|
211
|
+
## Push notifications
|
|
212
|
+
|
|
213
|
+
A reply's push carries `type: 'support_chat.reply'` in its data. `isLiveChatPush(data)` recognizes it:
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
import { isLiveChatPush } from '@marketcanopy/react-native-live-chat';
|
|
217
|
+
|
|
218
|
+
// A notification the person tapped:
|
|
219
|
+
if (isLiveChatPush(notification.data)) chat.open();
|
|
220
|
+
|
|
221
|
+
// A message received in the foreground: the running chat already shows it.
|
|
222
|
+
const show = !(isLiveChatPush(message.data) && chat.hasChat());
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Screens
|
|
226
|
+
|
|
227
|
+
While a chat runs, the agent can see which screen the person is on, as a site's page views. Call `reportScreen` on every navigation change, and give the session a `recordScreen` that posts the view:
|
|
228
|
+
|
|
229
|
+
```ts
|
|
230
|
+
const chat = createLiveChat({
|
|
231
|
+
session: {
|
|
232
|
+
start: startSupportChatSession,
|
|
233
|
+
recordScreen: (view) =>
|
|
234
|
+
post('/v1/auth/devices/current/support-chat/page-views', view),
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
<NavigationContainer
|
|
239
|
+
onStateChange={() => chat.reportScreen({ screen: currentRouteName() })}
|
|
240
|
+
/>
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Without `recordScreen`, `reportScreen` does nothing.
|
|
244
|
+
|
|
245
|
+
## Resuming
|
|
246
|
+
|
|
247
|
+
With a `storage`, the chat notes that a conversation runs. Call `resume()` once the person can chat again (for example after sign-in is restored at launch) and the bubble comes back. Any synchronous key-value store fits, MMKV as is:
|
|
248
|
+
|
|
249
|
+
```ts
|
|
250
|
+
import { createMMKV } from 'react-native-mmkv';
|
|
251
|
+
|
|
252
|
+
const mmkv = createMMKV({ id: 'live-chat' });
|
|
253
|
+
const chat = createLiveChat({
|
|
254
|
+
session,
|
|
255
|
+
storage: {
|
|
256
|
+
getString: (key) => mmkv.getString(key),
|
|
257
|
+
set: (key, value) => mmkv.set(key, value),
|
|
258
|
+
remove: (key) => {
|
|
259
|
+
mmkv.remove(key);
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
chat.resume();
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Call `chat.reset()` on sign-out.
|
|
268
|
+
|
|
269
|
+
## Accessibility
|
|
270
|
+
|
|
271
|
+
Every control has a role and a translated label, touch targets are at least 44 points, text scales with the system font size, and a new reply's banner is a polite live region.
|
|
272
|
+
|
|
273
|
+
## Development
|
|
274
|
+
|
|
275
|
+
```sh
|
|
276
|
+
corepack enable
|
|
277
|
+
yarn install
|
|
278
|
+
yarn lint
|
|
279
|
+
yarn typecheck
|
|
280
|
+
yarn test --coverage
|
|
281
|
+
yarn build
|
|
282
|
+
yarn check-pack
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Every pull request to `main` runs these as one check, `Lint, typecheck, test, build`. A release is a pull request that raises `version` in `package.json`: on merge, the `Release` workflow publishes that version to npm and creates the GitHub release.
|
|
286
|
+
|
|
287
|
+
## License
|
|
288
|
+
|
|
289
|
+
MIT. The icons are from [Lucide](https://lucide.dev) (ISC License).
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Modal, StyleSheet, View } from 'react-native';
|
|
4
|
+
import { useStore } from 'zustand';
|
|
5
|
+
import { LiveChatUiProvider, useLiveChatUi } from "../ui-context.js";
|
|
6
|
+
import { LiveChatBanner } from "./LiveChatBanner.js";
|
|
7
|
+
import { LiveChatBubble } from "./LiveChatBubble.js";
|
|
8
|
+
import { LiveChatScreen } from "./LiveChatScreen.js";
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
function Surfaces({
|
|
11
|
+
chat,
|
|
12
|
+
pickAttachment,
|
|
13
|
+
testID
|
|
14
|
+
}) {
|
|
15
|
+
const {
|
|
16
|
+
t
|
|
17
|
+
} = useLiveChatUi();
|
|
18
|
+
const visible = useStore(chat.store, state => state.visible);
|
|
19
|
+
const phase = useStore(chat.store, state => state.phase);
|
|
20
|
+
const unread = useStore(chat.store, state => state.unread);
|
|
21
|
+
const banner = useStore(chat.store, state => state.banner);
|
|
22
|
+
const agentName = useStore(chat.store, state => state.appearance?.agentName ?? null);
|
|
23
|
+
const active = phase === 'open' || phase === 'starting';
|
|
24
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
25
|
+
style: StyleSheet.absoluteFill,
|
|
26
|
+
pointerEvents: "box-none",
|
|
27
|
+
children: [active && !visible && /*#__PURE__*/_jsx(LiveChatBubble, {
|
|
28
|
+
unread: unread,
|
|
29
|
+
onPress: chat.open,
|
|
30
|
+
testID: `${testID}-bubble`
|
|
31
|
+
}), banner !== null && !visible && /*#__PURE__*/_jsx(LiveChatBanner, {
|
|
32
|
+
message: banner,
|
|
33
|
+
agentName: agentName ?? t('support'),
|
|
34
|
+
onOpen: chat.open,
|
|
35
|
+
onDismiss: chat.dismissBanner,
|
|
36
|
+
testID: `${testID}-banner`
|
|
37
|
+
}), /*#__PURE__*/_jsx(Modal, {
|
|
38
|
+
visible: visible,
|
|
39
|
+
animationType: "slide",
|
|
40
|
+
presentationStyle: "fullScreen",
|
|
41
|
+
statusBarTranslucent: true,
|
|
42
|
+
onRequestClose: chat.minimize,
|
|
43
|
+
children: /*#__PURE__*/_jsx(LiveChatScreen, {
|
|
44
|
+
chat: chat,
|
|
45
|
+
...(pickAttachment === undefined ? {} : {
|
|
46
|
+
pickAttachment
|
|
47
|
+
}),
|
|
48
|
+
testID: testID
|
|
49
|
+
})
|
|
50
|
+
})]
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The chat over the app: the full-screen chat, the floating bubble while it
|
|
56
|
+
* is minimized and the banner for a reply. Render it once, after the app's
|
|
57
|
+
* own tree and inside its `SafeAreaProvider`, so it draws above every screen.
|
|
58
|
+
* It shows nothing until `chat.open()`.
|
|
59
|
+
*/
|
|
60
|
+
export function LiveChat({
|
|
61
|
+
chat,
|
|
62
|
+
pickAttachment,
|
|
63
|
+
testID = 'live-chat',
|
|
64
|
+
...ui
|
|
65
|
+
}) {
|
|
66
|
+
return /*#__PURE__*/_jsx(LiveChatUiProvider, {
|
|
67
|
+
...ui,
|
|
68
|
+
children: /*#__PURE__*/_jsx(Surfaces, {
|
|
69
|
+
chat: chat,
|
|
70
|
+
testID: testID,
|
|
71
|
+
...(pickAttachment === undefined ? {} : {
|
|
72
|
+
pickAttachment
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=LiveChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Modal","StyleSheet","View","useStore","LiveChatUiProvider","useLiveChatUi","LiveChatBanner","LiveChatBubble","LiveChatScreen","jsx","_jsx","jsxs","_jsxs","Surfaces","chat","pickAttachment","testID","t","visible","store","state","phase","unread","banner","agentName","appearance","active","style","absoluteFill","pointerEvents","children","onPress","open","message","onOpen","onDismiss","dismissBanner","animationType","presentationStyle","statusBarTranslucent","onRequestClose","minimize","undefined","LiveChat","ui"],"sourceRoot":"../../../src","sources":["components/LiveChat.tsx"],"mappings":";;AACA,SAASA,KAAK,EAAEC,UAAU,EAAEC,IAAI,QAAQ,cAAc;AACtD,SAASC,QAAQ,QAAQ,SAAS;AAIlC,SACEC,kBAAkB,EAClBC,aAAa,QAER,kBAAe;AACtB,SAASC,cAAc,QAAQ,qBAAkB;AACjD,SAASC,cAAc,QAAQ,qBAAkB;AACjD,SAASC,cAAc,QAAQ,qBAAkB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAclD,SAASC,QAAQA,CAAC;EAChBC,IAAI;EACJC,cAAc;EACdC;AAEoC,CAAC,EAAgB;EACrD,MAAM;IAAEC;EAAE,CAAC,GAAGZ,aAAa,CAAC,CAAC;EAC7B,MAAMa,OAAO,GAAGf,QAAQ,CAACW,IAAI,CAACK,KAAK,EAAGC,KAAK,IAAKA,KAAK,CAACF,OAAO,CAAC;EAC9D,MAAMG,KAAK,GAAGlB,QAAQ,CAACW,IAA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AAA,CAACF,cAAc;QACbM,IAAI,EAAEA,IAAK;QAAA,IACNC,cAAc,KAAK2B,SAAS,GAAG,CAAC,CAAC,GAAG;UAAE3B;QAAe,CAAC;QAC3DC,MAAM,EAAEA;MAAO,CAChB;IAAC,CACG,CAAC;EAAA,CACJ,CAAC;AAEX;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAAS2B,QAAQA,CAAC;EACvB7B,IAAI;EACJC,cAAc;EACdC,MAAM,GAAG,WAAW;EACpB,GAAG4B;AACU,CAAC,EAAgB;EAC9B,oBACElC,IAAA,CAACN,kBAAkB;IAAA,GAAKwC,EAAE;IAAAd,QAAA,eACxBpB,IAAA,CAACG,QAAQ;MACPC,IAAI,EAAEA,IAAK;MACXE,MAAM,EAAEA,MAAO;MAAA,IACVD,cAAc,KAAK2B,SAAS,GAAG,CAAC,CAAC,GAAG;QAAE3B;MAAe,CAAC;IAAA,CAC5D;EAAC,CACgB,CAAC;AAEzB","ignoreList":[]}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { View } from 'react-native';
|
|
5
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
|
+
import { Icon } from "../icons.js";
|
|
7
|
+
import { formatAgentName } from "../live-chat-messages.js";
|
|
8
|
+
import { messageSegments } from "../message-text.js";
|
|
9
|
+
import { useLiveChatUi } from "../ui-context.js";
|
|
10
|
+
import { IconButton, Press, Txt } from "./primitives.js";
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
/** A reply that arrived while the chat was minimized, at the top of the app; a tap opens the chat. */
|
|
13
|
+
export function LiveChatBanner({
|
|
14
|
+
message,
|
|
15
|
+
agentName,
|
|
16
|
+
onOpen,
|
|
17
|
+
onDismiss,
|
|
18
|
+
durationMs = 6000,
|
|
19
|
+
testID
|
|
20
|
+
}) {
|
|
21
|
+
const {
|
|
22
|
+
t,
|
|
23
|
+
theme,
|
|
24
|
+
styles
|
|
25
|
+
} = useLiveChatUi();
|
|
26
|
+
const insets = useSafeAreaInsets();
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const timer = setTimeout(onDismiss, durationMs);
|
|
29
|
+
return () => clearTimeout(timer);
|
|
30
|
+
}, [durationMs, message.id, onDismiss]);
|
|
31
|
+
const name = message.senderName !== undefined && message.sentByAssistant !== true ? formatAgentName(message.senderName, agentName) : agentName;
|
|
32
|
+
const preview = message.text.trim() === '' ? message.attachment?.name ?? t('attachment') : messageSegments(message.text).map(segment => segment.text).join('');
|
|
33
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
34
|
+
style: [styles.banner, {
|
|
35
|
+
top: insets.top + 8
|
|
36
|
+
}],
|
|
37
|
+
accessibilityLiveRegion: "polite",
|
|
38
|
+
testID: testID,
|
|
39
|
+
children: [/*#__PURE__*/_jsxs(Press, {
|
|
40
|
+
style: styles.bannerBody,
|
|
41
|
+
accessibilityLabel: `${t('bannerTitle', {
|
|
42
|
+
name
|
|
43
|
+
})}. ${preview}`,
|
|
44
|
+
onPress: onOpen,
|
|
45
|
+
testID: testID === undefined ? undefined : `${testID}-open`,
|
|
46
|
+
children: [/*#__PURE__*/_jsx(Txt, {
|
|
47
|
+
variant: "label",
|
|
48
|
+
numberOfLines: 1,
|
|
49
|
+
children: t('bannerTitle', {
|
|
50
|
+
name
|
|
51
|
+
})
|
|
52
|
+
}), /*#__PURE__*/_jsx(Txt, {
|
|
53
|
+
variant: "bodySmall",
|
|
54
|
+
tone: "muted",
|
|
55
|
+
numberOfLines: 2,
|
|
56
|
+
children: preview
|
|
57
|
+
})]
|
|
58
|
+
}), /*#__PURE__*/_jsx(Icon, {
|
|
59
|
+
name: "message-square",
|
|
60
|
+
size: 20,
|
|
61
|
+
color: theme.colors.mutedForeground
|
|
62
|
+
}), /*#__PURE__*/_jsx(IconButton, {
|
|
63
|
+
icon: "x",
|
|
64
|
+
size: "sm",
|
|
65
|
+
accessibilityLabel: t('dismiss'),
|
|
66
|
+
onPress: onDismiss,
|
|
67
|
+
testID: testID === undefined ? undefined : `${testID}-dismiss`
|
|
68
|
+
})]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=LiveChatBanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","View","useSafeAreaInsets","Icon","formatAgentName","messageSegments","useLiveChatUi","IconButton","Press","Txt","jsx","_jsx","jsxs","_jsxs","LiveChatBanner","message","agentName","onOpen","onDismiss","durationMs","testID","t","theme","styles","insets","timer","setTimeout","clearTimeout","id","name","senderName","undefined","sentByAssistant","preview","text","trim","attachment","map","segment","join","style","banner","top","accessibilityLiveRegion","children","bannerBody","accessibilityLabel","onPress","variant","numberOfLines","tone","size","color","colors","mutedForeground","icon"],"sourceRoot":"../../../src","sources":["components/LiveChatBanner.tsx"],"mappings":";;AAAA,SAASA,SAAS,QAA2B,OAAO;AACpD,SAASC,IAAI,QAAQ,cAAc;AACnC,SAASC,iBAAiB,QAAQ,gCAAgC;AAElE,SAASC,IAAI,QAAQ,aAAU;AAC/B,SAASC,eAAe,QAA8B,0BAAuB;AAC7E,SAASC,eAAe,QAAQ,oBAAiB;AACjD,SAASC,aAAa,QAAQ,kBAAe;AAC7C,SAASC,UAAU,EAAEC,KAAK,EAAEC,GAAG,QAAQ,iBAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAatD;AACA,OAAO,SAASC,cAAcA,CAAC;EAC7BC,OAAO;EACPC,SAAS;EACTC,MAAM;EACNC,SAAS;EACTC,UAAU,GAAG,IAAI;EACjBC;AACmB,CAAC,EAAgB;EACpC,MAAM;IAAEC,CAAC;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGjB,aAAa,CAAC,CAAC;EAC5C,MAAMkB,MAAM,GAAGtB,iBAAiB,CAAC,CAAC;EAElCF,SAAS,CAA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C,aAAa,EAAE,CAAE;QAAAL,QAAA,EACnCvB,CAAC,CAAC,aAAa,EAAE;UAAEQ;QAAK,CAAC;MAAC,CACxB,CAAC,eACNlB,IAAA,CAACF,GAAG;QAACuC,OAAO,EAAC,WAAW;QAACE,IAAI,EAAC,OAAO;QAACD,aAAa,EAAE,CAAE;QAAAL,QAAA,EACpDX;MAAO,CACL,CAAC;IAAA,CACD,CAAC,eACRtB,IAAA,CAACR,IAAI;MACH0B,IAAI,EAAC,gBAAgB;MACrBsB,IAAI,EAAE,EAAG;MACTC,KAAK,EAAE9B,KAAK,CAAC+B,MAAM,CAACC;IAAgB,CACrC,CAAC,eACF3C,IAAA,CAACJ,UAAU;MACTgD,IAAI,EAAC,GAAG;MACRJ,IAAI,EAAC,IAAI;MACTL,kBAAkB,EAAEzB,CAAC,CAAC,SAAS,CAAE;MACjC0B,OAAO,EAAE7B,SAAU;MACnBE,MAAM,EAAEA,MAAM,KAAKW,SAAS,GAAGA,SAAS,GAAG,GAAGX,MAAM;IAAW,CAChE,CAAC;EAAA,CACE,CAAC;AAEX","ignoreList":[]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useMemo, useRef } from 'react';
|
|
4
|
+
import { Animated, PanResponder, Pressable, Text, useWindowDimensions, View } from 'react-native';
|
|
5
|
+
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
6
|
+
import { Icon } from "../icons.js";
|
|
7
|
+
import { formatNumber } from "../strings.js";
|
|
8
|
+
import { BUBBLE_MARGIN, BUBBLE_REST_OFFSET, BUBBLE_SIZE } from "../theme.js";
|
|
9
|
+
import { useLiveChatUi } from "../ui-context.js";
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
/** A drag shorter than this is a tap. */
|
|
12
|
+
const TAP_SLOP = 6;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The minimized chat: a round button over every screen that the person drags
|
|
16
|
+
* out of the way (it settles on the nearer side) and taps to open the chat
|
|
17
|
+
* again, with the count of replies they have not read.
|
|
18
|
+
*/
|
|
19
|
+
export function LiveChatBubble({
|
|
20
|
+
unread,
|
|
21
|
+
onPress,
|
|
22
|
+
testID
|
|
23
|
+
}) {
|
|
24
|
+
const {
|
|
25
|
+
t,
|
|
26
|
+
theme,
|
|
27
|
+
styles,
|
|
28
|
+
locale
|
|
29
|
+
} = useLiveChatUi();
|
|
30
|
+
const insets = useSafeAreaInsets();
|
|
31
|
+
const window = useWindowDimensions();
|
|
32
|
+
const size = BUBBLE_SIZE;
|
|
33
|
+
const margin = BUBBLE_MARGIN;
|
|
34
|
+
const bounds = useRef({
|
|
35
|
+
width: window.width,
|
|
36
|
+
height: window.height
|
|
37
|
+
});
|
|
38
|
+
bounds.current = {
|
|
39
|
+
width: window.width,
|
|
40
|
+
height: window.height
|
|
41
|
+
};
|
|
42
|
+
const position = useRef(new Animated.ValueXY({
|
|
43
|
+
x: window.width - size - margin,
|
|
44
|
+
y: window.height - size - insets.bottom - BUBBLE_REST_OFFSET
|
|
45
|
+
})).current;
|
|
46
|
+
const start = useRef({
|
|
47
|
+
x: 0,
|
|
48
|
+
y: 0
|
|
49
|
+
});
|
|
50
|
+
const responder = useMemo(() => PanResponder.create({
|
|
51
|
+
onMoveShouldSetPanResponder: (_event, gesture) => Math.abs(gesture.dx) > TAP_SLOP || Math.abs(gesture.dy) > TAP_SLOP,
|
|
52
|
+
onPanResponderGrant: () => {
|
|
53
|
+
position.stopAnimation(value => {
|
|
54
|
+
start.current = value;
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
onPanResponderMove: (_event, gesture) => position.setValue({
|
|
58
|
+
x: start.current.x + gesture.dx,
|
|
59
|
+
y: start.current.y + gesture.dy
|
|
60
|
+
}),
|
|
61
|
+
onPanResponderRelease: (_event, gesture) => {
|
|
62
|
+
const {
|
|
63
|
+
width,
|
|
64
|
+
height
|
|
65
|
+
} = bounds.current;
|
|
66
|
+
const x = start.current.x + gesture.dx;
|
|
67
|
+
const y = start.current.y + gesture.dy;
|
|
68
|
+
Animated.spring(position, {
|
|
69
|
+
toValue: {
|
|
70
|
+
x: x + size / 2 < width / 2 ? margin : width - size - margin,
|
|
71
|
+
y: Math.min(Math.max(y, insets.top + margin), height - size - insets.bottom - margin)
|
|
72
|
+
},
|
|
73
|
+
useNativeDriver: false
|
|
74
|
+
}).start();
|
|
75
|
+
}
|
|
76
|
+
}), [insets.bottom, insets.top, margin, position, size]);
|
|
77
|
+
return /*#__PURE__*/_jsxs(Animated.View, {
|
|
78
|
+
style: [styles.floating, {
|
|
79
|
+
transform: position.getTranslateTransform()
|
|
80
|
+
}],
|
|
81
|
+
...responder.panHandlers,
|
|
82
|
+
testID: testID,
|
|
83
|
+
children: [/*#__PURE__*/_jsx(Pressable, {
|
|
84
|
+
accessibilityRole: "button",
|
|
85
|
+
accessibilityLabel: t('openBubble'),
|
|
86
|
+
...(unread > 0 ? {
|
|
87
|
+
accessibilityHint: t('newMessages', {
|
|
88
|
+
count: unread
|
|
89
|
+
})
|
|
90
|
+
} : {}),
|
|
91
|
+
onPress: onPress,
|
|
92
|
+
hitSlop: TAP_SLOP,
|
|
93
|
+
testID: testID === undefined ? undefined : `${testID}-button`,
|
|
94
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
95
|
+
name: "message-square",
|
|
96
|
+
size: 24,
|
|
97
|
+
color: theme.colors.primaryForeground
|
|
98
|
+
})
|
|
99
|
+
}), unread > 0 && /*#__PURE__*/_jsx(View, {
|
|
100
|
+
style: styles.count,
|
|
101
|
+
pointerEvents: "none",
|
|
102
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
103
|
+
style: styles.countText,
|
|
104
|
+
maxFontSizeMultiplier: 1.2,
|
|
105
|
+
children: formatNumber(Math.min(unread, 99), locale)
|
|
106
|
+
})
|
|
107
|
+
})]
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=LiveChatBubble.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useMemo","useRef","Animated","PanResponder","Pressable","Text","useWindowDimensions","View","useSafeAreaInsets","Icon","formatNumber","BUBBLE_MARGIN","BUBBLE_REST_OFFSET","BUBBLE_SIZE","useLiveChatUi","jsx","_jsx","jsxs","_jsxs","TAP_SLOP","LiveChatBubble","unread","onPress","testID","t","theme","styles","locale","insets","window","size","margin","bounds","width","height","current","position","ValueXY","x","y","bottom","start","responder","create","onMoveShouldSetPanResponder","_event","gesture","Math","abs","dx","dy","onPanResponderGrant","stopAnimation","value","onPanResponderMove","setValue","onPanResponderRelease","spring","toValue","min","max","top","useNativeDriver","style","floating","transform","getTranslateTransform","panHandlers","children","accessibilityRole","accessibilityLabel","accessibilityHint","count","hitSlop","undefined","name","color","colors","primaryForeground","pointerEvents","countText","maxFontSizeMultiplier"],"sourceRoot":"../../../src","sources":["components/LiveChatBubble.tsx"],"mappings":";;AAAA,SAASA,OAAO,EAAEC,MAAM,QAA2B,OAAO;AAC1D,SACEC,QAAQ,EACRC,YAAY,EACZC,SAAS,EACTC,IAAI,EACJC,mBAAmB,EACnBC,IAAI,QACC,cAAc;AACrB,SAASC,iBAAiB,QAAQ,gCAAgC;AAElE,SAASC,IAAI,QAAQ,aAAU;AAC/B,SAASC,YAAY,QAAQ,eAAY;AACzC,SAASC,aAAa,EAAEC,kBAAkB,EAAEC,WAAW,QAAQ,aAAU;AACzE,SAASC,aAAa,QAAQ,kBAAe;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAQ9C;AACA,MAAMC,QAAQ,GAAG,CAAC;;AAElB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAAC;EAC7BC,MAAM;EACNC,OAAO;EACPC;AACmB,CAAC,EAAgB;EACpC,MAAM;IAAEC,CAAC;IAAEC,KAAK;IAAEC,MAAM;IAAEC;EAAO,CAAC,GAAGb,aAAa,CAAC,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