@medipha/chat 1.0.29 → 1.0.31

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.
Files changed (34) hide show
  1. package/README.md +82 -7
  2. package/dist/features/composer/conversation-composer.d.ts +2 -0
  3. package/dist/features/composer/emoji/emoji-picker-button.d.ts +2 -1
  4. package/dist/features/composer/toolbar/composer-toolbar.d.ts +4 -1
  5. package/dist/features/create-conversation/create-conversation-panel.d.ts +1 -1
  6. package/dist/features/media-preview/media-preview-modal.d.ts +1 -1
  7. package/dist/features/message-list/bubble/message-actions/message-actions-menu.d.ts +2 -5
  8. package/dist/features/message-list/bubble/message-bubble.d.ts +2 -5
  9. package/dist/features/message-list/overlays/message-menu/use-message-menu.d.ts +2 -0
  10. package/dist/index.cjs +47 -47
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.js +15440 -14861
  13. package/dist/module/chat-runtime-props.d.ts +2 -0
  14. package/dist/module/chat-runtime-provider.d.ts +9 -0
  15. package/dist/module/navigation/chat-navigation-context.d.ts +16 -0
  16. package/dist/module/navigation/router-chat-navigation.d.ts +4 -0
  17. package/dist/module/session/chat-session.d.ts +9 -0
  18. package/dist/module/widget/chat-widget.d.ts +2 -0
  19. package/dist/module/widget/chat-widget.types.d.ts +13 -0
  20. package/dist/module/widget/widget-chat-navigation.d.ts +8 -0
  21. package/dist/module/widget/widget-conversation-screen.d.ts +15 -0
  22. package/dist/pages/conversation/conversation-detail/conversation-detail.d.ts +1 -0
  23. package/dist/pages/conversation/conversation-footer/conversation-footer.d.ts +3 -1
  24. package/dist/pages/conversation/conversation-header/conversation-header.d.ts +6 -1
  25. package/dist/pages/conversation/hooks/use-current-membership.d.ts +1 -1
  26. package/dist/pages/conversation/index.d.ts +4 -0
  27. package/dist/pages/conversations/index.d.ts +3 -3
  28. package/dist/pages/conversations/use-conversation-workspace.d.ts +21 -0
  29. package/dist/pages/conversations/workspace-user-profile-modal.d.ts +12 -0
  30. package/dist/pages/sidebar/index.d.ts +9 -1
  31. package/dist/pages/sidebar/sidbar-conversation-list/sidbar-conversation-list.d.ts +4 -2
  32. package/dist/pages/sidebar/sidebar-header-infor/sidebar-header-infor.d.ts +9 -3
  33. package/dist/styles.css +1 -1
  34. package/package.json +2 -2
package/README.md CHANGED
@@ -24,9 +24,13 @@ import '@medipha/chat/styles.css';
24
24
  path="/chat-erp/*"
25
25
  element={
26
26
  <ChatModule
27
+ userId={currentUserId}
27
28
  accessToken={accessToken}
28
29
  apiUrl={CHAT_API_URL}
29
30
  socketUrl={CHAT_SOCKET_URL}
31
+ hasAddGroupVerified={permissions.addGroupVerified}
32
+ hasUpdateGroupVerified={permissions.updateGroupVerified}
33
+ hasDeleteGroupVerified={permissions.deleteGroupVerified}
30
34
  onUnauthorized={handleUnauthorized}
31
35
  onNavigateOutsideChat={handleNavigateOutsideChat}
32
36
  />
@@ -40,18 +44,89 @@ relative routes: `/chat-erp` for the conversation list and
40
44
 
41
45
  ## `ChatModuleProps`
42
46
 
43
- | Prop | Required | Meaning |
44
- | ----------------------- | -------- | --------------------------------------------------------- |
45
- | `accessToken` | Yes | Current ERP access token used by chat API/socket clients. |
46
- | `apiUrl` | Yes | Base URL for the Chat HTTP API. |
47
- | `socketUrl` | Yes | Socket server URL. |
48
- | `onUnauthorized` | No | ERP callback for an unauthorized chat response. |
49
- | `onNavigateOutsideChat` | No | ERP callback for navigation that leaves chat. |
47
+ | Prop | Required | Meaning |
48
+ | ------------------------ | -------- | ------------------------------------------------------------- |
49
+ | `userId` | Yes | ERP id of the signed-in user, as the chat backend knows them. |
50
+ | `accessToken` | Yes | Current ERP access token used by chat API/socket clients. |
51
+ | `apiUrl` | Yes | Base URL for the Chat HTTP API. |
52
+ | `socketUrl` | Yes | Socket server URL. |
53
+ | `hasAddGroupVerified` | Yes | May the user create a verified ("tích xanh") group. |
54
+ | `hasUpdateGroupVerified` | Yes | May the user rename/re-avatar a verified group. |
55
+ | `hasDeleteGroupVerified` | Yes | May the user disband a verified group. |
56
+ | `onUnauthorized` | No | ERP callback for an unauthorized chat response. |
57
+ | `onNavigateOutsideChat` | No | ERP callback for navigation that leaves chat. |
58
+
59
+ `accessToken`, `apiUrl` and `socketUrl` are asserted non-empty at mount and
60
+ throw otherwise, so render chat only once the ERP session is resolved.
50
61
 
51
62
  Pass a new `accessToken` prop whenever ERP refreshes its credential.
52
63
  `ChatModule` updates its internal runtime context from the new prop and never
53
64
  writes a token to `localStorage` or `sessionStorage`.
54
65
 
66
+ ## Anchored widget
67
+
68
+ `ChatWidget` is the second entry point: a rail the ERP anchors to the right
69
+ edge of the shell, plus a floating chat window. It takes every `ChatModuleProps`
70
+ field and does **not** use the router, so it can be mounted in the ERP layout
71
+ outside any `<Routes>`.
72
+
73
+ ```tsx
74
+ import { ChatWidget } from '@medipha/chat';
75
+
76
+ const [isChatOpen, setIsChatOpen] = useState(true);
77
+ const isChatFullPage = location.pathname.startsWith('/chat-erp');
78
+
79
+ <aside className="erp-chat-rail" hidden={!isChatOpen || isChatFullPage}>
80
+ <ChatWidget
81
+ {...chatRuntimeProps}
82
+ isOpen={isChatOpen && !isChatFullPage}
83
+ onRequestClose={() => setIsChatOpen(false)}
84
+ onUnreadTotalChange={setChatUnreadTotal}
85
+ onOpenFullPage={(conversationId) =>
86
+ navigate(conversationId ? `/chat-erp/${conversationId}` : '/chat-erp')
87
+ }
88
+ />
89
+ </aside>;
90
+ ```
91
+
92
+ The ERP owns the rail's box — size it `72px` wide and full height. Keep the
93
+ widget **mounted** while hidden and switch `isOpen` instead of unmounting: the
94
+ conversation list stays warm and `onUnreadTotalChange` keeps feeding the ERP's
95
+ own unread badge.
96
+
97
+ | Prop | Meaning |
98
+ | -------------------------- | --------------------------------------------------------------------------- |
99
+ | `isOpen` | Host is showing the widget. Defaults to `true`. Withholds the chat window. |
100
+ | `onRequestClose` | The rail's close button was pressed; hide the rail. Omit to hide the button. |
101
+ | `onOpenFullPage` | The window's expand button was pressed; route to the full-page chat. |
102
+ | `onUnreadTotalChange` | Total unread across conversations, for the ERP's launcher badge. |
103
+ | `onActiveConversationChange` | Which conversation the widget currently has open, or `undefined`. |
104
+ | `onExpandChange` | The rail widened to the full sidebar (320px) or collapsed back to 72px. |
105
+
106
+ The rail's expanded state anchors itself to the viewport (`position: fixed`),
107
+ so it works whether or not the ERP reacts to `onExpandChange` — but a host that
108
+ hides the rail by collapsing its width must hide it with `visibility`,
109
+ `display` or `hidden` rather than `overflow`, which does not clip fixed
110
+ children.
111
+
112
+ The floating window is portalled to `document.body` at `z-index: 1000`; ERP
113
+ chrome that must sit above chat needs a higher value.
114
+
115
+ ### Widget CSS variables
116
+
117
+ Set these on any ancestor to retune the widget without a rebuild:
118
+
119
+ | Variable | Default |
120
+ | ------------------------------------- | ------- |
121
+ | `--med-chat-widget-window-width` | `360px` |
122
+ | `--med-chat-widget-window-height` | `480px` |
123
+ | `--med-chat-widget-window-right` | `88px` |
124
+ | `--med-chat-widget-window-bottom` | `24px` |
125
+ | `--med-chat-widget-window-z` | `1000` |
126
+ | `--med-chat-widget-rail-expanded-width` | `320px` |
127
+ | `--med-chat-widget-image-width` | `180px` |
128
+ | `--med-chat-widget-image-height` | `240px` |
129
+
55
130
  ## Nginx SPA fallback
56
131
 
57
132
  Configure the ERP server so deep links under `/chat-erp/*` return the ERP
@@ -6,6 +6,8 @@ interface ConversationComposerProps {
6
6
  members: ChatUser[];
7
7
  canMentionAll: boolean;
8
8
  enableMentions?: boolean;
9
+ placeholder?: string;
10
+ isCompact?: boolean;
9
11
  disabled?: boolean;
10
12
  hasPendingAttachments?: boolean;
11
13
  onSubmit: (content: MessageContent) => boolean | void;
@@ -1,9 +1,10 @@
1
1
  import { Editor } from '@tiptap/core';
2
2
  interface EmojiPickerButtonProps {
3
3
  editor: Editor | null | undefined;
4
+ isCompact?: boolean;
4
5
  }
5
6
  /** Composer toolbar's smiley button: toggles a native-emoji picker popover and inserts
6
7
  * the picked emoji at the cursor. Stays open after a pick so several emoji can be
7
8
  * chosen in a row. */
8
- export declare function EmojiPickerButton({ editor }: EmojiPickerButtonProps): import("react/jsx-runtime").JSX.Element;
9
+ export declare function EmojiPickerButton({ editor, isCompact }: EmojiPickerButtonProps): import("react/jsx-runtime").JSX.Element;
9
10
  export {};
@@ -11,9 +11,12 @@ interface ComposerToolbarProps {
11
11
  /** Shared send button — rendered here (on the format bar) when it's open, or by the
12
12
  * parent composer's input row otherwise; never both at once. */
13
13
  sendButton: ReactNode;
14
+ isCollapsed?: boolean;
15
+ onExpand?: () => void;
16
+ showEmojiButton?: boolean;
14
17
  }
15
18
  /** Composer toolbar row: attach file/image, the "Định dạng" toggle, the emoji picker, and
16
19
  * the "..." more menu — plus the format bar it reveals underneath when toggled open. Each
17
20
  * button's own popover/panel lives in its own feature folder; this just arranges them. */
18
- export declare function ComposerToolbar({ editor, onAttach, onAttachImages, isFormatOpen, onToggleFormat, isEnlarged, onToggleEnlarged, sendButton, }: ComposerToolbarProps): import("react/jsx-runtime").JSX.Element;
21
+ export declare function ComposerToolbar({ editor, onAttach, onAttachImages, isFormatOpen, onToggleFormat, isEnlarged, onToggleEnlarged, sendButton, isCollapsed, onExpand, showEmojiButton, }: ComposerToolbarProps): import("react/jsx-runtime").JSX.Element;
19
22
  export {};
@@ -5,5 +5,5 @@ interface CreateConversationPanelProps {
5
5
  onCreated: (conversation: Conversation) => void;
6
6
  }
7
7
  /** Modal panel to start a direct chat or create a named group conversation. */
8
- export declare function CreateConversationPanel({ currentUserId, onClose, onCreated, }: CreateConversationPanelProps): import("react/jsx-runtime").JSX.Element;
8
+ export declare function CreateConversationPanel({ currentUserId, onClose, onCreated, }: CreateConversationPanelProps): import('react').ReactPortal;
9
9
  export {};
@@ -22,5 +22,5 @@ interface MediaPreviewModalProps {
22
22
  * rail stay ours, because the library's Thumbnails plugin only renders a flat strip with no
23
23
  * date grouping.
24
24
  */
25
- export declare function MediaPreviewModal({ state, onClose, onIndexChange }: MediaPreviewModalProps): import("react/jsx-runtime").JSX.Element | null;
25
+ export declare function MediaPreviewModal({ state, onClose, onIndexChange }: MediaPreviewModalProps): import('react').ReactPortal | null;
26
26
  export {};
@@ -1,3 +1,4 @@
1
+ import { MessageMenuPosition } from '../../overlays/message-menu/use-message-menu';
1
2
  interface MessageActionsMenuProps {
2
3
  canRemove: boolean;
3
4
  removeLabel: string;
@@ -13,11 +14,7 @@ interface MessageActionsMenuProps {
13
14
  canForward: boolean;
14
15
  isPinned: boolean;
15
16
  isMenuOpen: boolean;
16
- menuPosition: {
17
- top?: number;
18
- bottom?: number;
19
- left: number;
20
- } | null;
17
+ menuPosition: MessageMenuPosition | null;
21
18
  onReply: () => void;
22
19
  onForward: () => void;
23
20
  onOpenMenu: (triggerRect: DOMRect) => void;
@@ -1,3 +1,4 @@
1
+ import { MessageMenuPosition } from '../overlays/message-menu/use-message-menu';
1
2
  import { ChatMessage, MessageReplyPreview } from '../../../utils/chat';
2
3
  import { ReactionType } from '@medipha/chat-core';
3
4
  export interface MessageBubbleProps {
@@ -20,11 +21,7 @@ export interface MessageBubbleProps {
20
21
  isPinned: boolean;
21
22
  onTogglePin: () => void;
22
23
  isMenuOpen: boolean;
23
- menuPosition: {
24
- top?: number;
25
- bottom?: number;
26
- left: number;
27
- } | null;
24
+ menuPosition: MessageMenuPosition | null;
28
25
  onOpenMenu: (triggerRect: DOMRect) => void;
29
26
  onCloseMenu: () => void;
30
27
  onCopyMessage: () => void;
@@ -3,6 +3,8 @@ export interface MessageMenuPosition {
3
3
  top?: number;
4
4
  bottom?: number;
5
5
  left: number;
6
+ width: number;
7
+ maxHeight: number;
6
8
  }
7
9
  /**
8
10
  * Tracks which message's options menu ("...") is open and its fixed-position pixel