@zean-chat/react-native 0.1.13 → 0.1.14

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 CHANGED
@@ -22,6 +22,8 @@ import { ZeanChat, useZean } from "@zean-chat/react-native";
22
22
  const { open, close, toggle, unreadCount, identify, signOut, setAttributes, setPushToken } = useZean();
23
23
  ```
24
24
 
25
+ `open({ message })` opens the chat with that text in the message field: the person edits it and sends it, nothing goes before. Give the details of the screen they ask from, such as an order number.
26
+
25
27
  Passing `user` signs the person in; `undefined` signs them out. `locale` (`fr`, `en`) and `colorScheme` (`light`, `dark`) default to the phone's. `maxPhotos` sets the photos per message, 1 to 6; 4 by default. The chat keeps the newest 100 messages in your app's storage: it shows them at once and downloads only new ones. To choose the storage, pass `storage`: AsyncStorage, an MMKV instance (any version) or anything with `getItem` and `setItem`. Full guide: [install the chat in React Native and Expo](https://zean.chat/docs/install-react-native), [React Native reference](https://zean.chat/docs/reference-react-native).
26
28
 
27
29
  ## Push notifications
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * The Contact's message field: a pill with the photo button, when the app installed a picker, and a round send button
3
3
  * in the App's colour. 16 point text; the field grows with the text up to five lines. Emoji come from the phone's keyboard.
4
- * Picked photos show above the field and upload when the message is sent.
4
+ * Picked photos show above the field and upload when the message is sent. A message given to `open()` fills the field.
5
5
  */
6
6
  export declare function Composer(): import("react").JSX.Element;
package/dist/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { ZeanChat } from './components/ZeanChat';
2
2
  export { useZean } from './hooks/use-zean';
3
3
  export { openFromNotification } from './models/sdk.store';
4
4
  export { isZeanNotification } from './models/sdk.utils';
5
- export type { ZeanAttributeValue, ZeanAttributes, ZeanChatProps, ZeanColorScheme, ZeanControls, ZeanKeyValueStorage, ZeanLocale, ZeanMMKV, ZeanStorage, ZeanUser } from './interfaces';
5
+ export type { ZeanAttributeValue, ZeanAttributes, ZeanChatProps, ZeanColorScheme, ZeanControls, ZeanKeyValueStorage, ZeanLocale, ZeanMMKV, ZeanOpenOptions, ZeanStorage, ZeanUser } from './interfaces';
package/dist/index.js CHANGED
@@ -6631,19 +6631,34 @@ var identity = null;
6631
6631
  var signOutWaiting = false;
6632
6632
  var attributes = {};
6633
6633
  var pushToken;
6634
+ var draft = null;
6635
+ var notify = () => {
6636
+ for (const listener of listeners) listener();
6637
+ };
6634
6638
  var emit = () => {
6635
6639
  const unread = chat?.getState().unread ?? 0;
6636
6640
  if (view.open === open && view.unread === unread) return;
6637
6641
  view = { open, unread };
6638
- for (const listener of listeners) listener();
6642
+ notify();
6643
+ };
6644
+ var setDraft = (next) => {
6645
+ draft = next;
6646
+ notify();
6639
6647
  };
6640
6648
  var setOpen = (next) => {
6641
6649
  open = next;
6642
6650
  emit();
6643
6651
  };
6644
6652
  var zean = {
6645
- open: () => setOpen(true),
6646
- close: () => setOpen(false),
6653
+ open(options) {
6654
+ const message = options?.message;
6655
+ if (typeof message === "string" && message.trim() !== "") setDraft(message.slice(0, MAX_MESSAGE_LENGTH));
6656
+ setOpen(true);
6657
+ },
6658
+ close() {
6659
+ setDraft(null);
6660
+ setOpen(false);
6661
+ },
6647
6662
  toggle: () => setOpen(!open),
6648
6663
  identify(user) {
6649
6664
  identity = user;
@@ -6688,6 +6703,12 @@ function attachChat(next) {
6688
6703
  function chatView() {
6689
6704
  return view;
6690
6705
  }
6706
+ function chatDraft() {
6707
+ return draft;
6708
+ }
6709
+ function clearDraft() {
6710
+ setDraft(null);
6711
+ }
6691
6712
  function subscribeChatView(listener) {
6692
6713
  listeners.add(listener);
6693
6714
  return () => listeners.delete(listener);
@@ -7406,10 +7427,16 @@ function Composer() {
7406
7427
  const pending = usePendingPhotos();
7407
7428
  const picker = photoPicker();
7408
7429
  const canSend = !pending.sending && (text.trim().length > 0 || pending.photos.length > 0);
7430
+ const draft2 = (0, import_react8.useSyncExternalStore)(subscribeChatView, chatDraft);
7409
7431
  const changeText = (value) => {
7410
7432
  typed.current = value;
7411
7433
  setText(value);
7412
7434
  };
7435
+ (0, import_react8.useEffect)(() => {
7436
+ if (draft2 === null) return;
7437
+ changeText(draft2);
7438
+ clearDraft();
7439
+ }, [draft2]);
7413
7440
  const handleSend = async () => {
7414
7441
  const attachments = pending.photos.length > 0 ? await pending.send() : [];
7415
7442
  if (!attachments) return;
@@ -50,9 +50,18 @@ export interface ZeanChatProps {
50
50
  */
51
51
  backendUrl?: string;
52
52
  }
53
+ /** How `open()` opens the chat. */
54
+ export interface ZeanOpenOptions {
55
+ /**
56
+ * Text put in the message field, in place of what it held: the person reads it, edits it and sends it. Nothing is
57
+ * sent until they do. Cut at 5,000 characters.
58
+ */
59
+ message?: string;
60
+ }
53
61
  /** The chat's methods, and the count of replies the Contact has not seen. */
54
62
  export interface ZeanControls {
55
- open: () => void;
63
+ /** Opens the chat; with `message`, that text waits in the message field. */
64
+ open: (options?: ZeanOpenOptions) => void;
56
65
  close: () => void;
57
66
  toggle: () => void;
58
67
  /**
@@ -12,4 +12,8 @@ export declare function openFromNotification(data: unknown): boolean;
12
12
  export declare function attachChat(next: Chat): () => void;
13
13
  /** Whether the chat is open and how many replies wait: the same object until one changes. */
14
14
  export declare function chatView(): ChatView;
15
+ /** The text waiting for the message field, or null. */
16
+ export declare function chatDraft(): string | null;
17
+ /** The message field took the draft. */
18
+ export declare function clearDraft(): void;
15
19
  export declare function subscribeChatView(listener: () => void): () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zean-chat/react-native",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
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",