@adatechnology/conversations-ui 0.1.0-rc.10 → 0.1.0-rc.12

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.
@@ -864,6 +864,12 @@ var EmojiPicker = ({ onSelect, labels, className = "" }) => {
864
864
  // src/MessageComposer.tsx
865
865
  import { useState as useState6, useRef as useRef2, useCallback as useCallback2 } from "react";
866
866
  import { Fragment as Fragment2, jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
867
+ function applyQuickReplyVariables(template, variables = {}) {
868
+ return template.replace(/\{\{\s*([\w.]+)\s*\}\}/g, (_, chave) => variables[chave] ?? "");
869
+ }
870
+ function resolveQuickReply(quickReply, variables = {}) {
871
+ return typeof quickReply.text === "function" ? quickReply.text(variables) : applyQuickReplyVariables(quickReply.text, variables);
872
+ }
867
873
  var DEFAULT_MESSAGE_COMPOSER_LABELS = {
868
874
  emoji: "Emoji",
869
875
  attach: "Anexar",
@@ -884,6 +890,8 @@ var MessageComposer = ({
884
890
  onAttach,
885
891
  value: externalValue,
886
892
  onChange: externalOnChange,
893
+ quickReplies,
894
+ quickReplyVariables,
887
895
  features,
888
896
  placeholder = "Digite uma mensagem...",
889
897
  maxLength,
@@ -994,6 +1002,31 @@ var MessageComposer = ({
994
1002
  ordem do WhatsApp. Invertido, o pill arredondado ia até a borda da tela e os cantos
995
1003
  descobriam o fundo branco da página, que lia como defeito. */
996
1004
  /* @__PURE__ */ jsxs8("div", { className: cn("bg-[#f0f2f5] px-2 py-2", className), children: [
1005
+ quickReplies && quickReplies.length > 0 && /* @__PURE__ */ jsx12(
1006
+ "div",
1007
+ {
1008
+ className: cn(
1009
+ "mb-2 flex flex-nowrap gap-1 overflow-x-auto px-1 sm:flex-wrap sm:overflow-x-visible [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
1010
+ classNames?.quickReplies
1011
+ ),
1012
+ children: quickReplies.map((quickReply) => /* @__PURE__ */ jsx12(
1013
+ "button",
1014
+ {
1015
+ type: "button",
1016
+ onClick: () => {
1017
+ setText(resolveQuickReply(quickReply, quickReplyVariables));
1018
+ textareaRef.current?.focus();
1019
+ },
1020
+ className: cn(
1021
+ "whitespace-nowrap rounded-full border border-gray-200 bg-white px-2 py-1 text-xs text-gray-600 transition-colors hover:border-teal-200 hover:bg-teal-50 hover:text-teal-700 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-400",
1022
+ classNames?.quickReply
1023
+ ),
1024
+ children: quickReply.label
1025
+ },
1026
+ quickReply.key
1027
+ ))
1028
+ }
1029
+ ),
997
1030
  attachments.length > 0 && /* @__PURE__ */ jsx12("div", { className: "flex gap-2 px-1 pb-2 overflow-x-auto", children: attachments.map((a, i) => /* @__PURE__ */ jsxs8("div", { className: "relative flex-shrink-0", children: [
998
1031
  a.previewUrl ? /* @__PURE__ */ jsx12("img", { src: a.previewUrl, alt: "", className: "w-16 h-16 object-cover rounded-lg border border-gray-200" }) : /* @__PURE__ */ jsx12("div", { className: "w-16 h-16 bg-gray-100 rounded-lg border border-gray-200 flex items-center justify-center", children: /* @__PURE__ */ jsxs8("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "#9ca3af", strokeWidth: "1.5", children: [
999
1032
  /* @__PURE__ */ jsx12("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }),
@@ -1724,6 +1757,8 @@ export {
1724
1757
  searchEmojis,
1725
1758
  DEFAULT_EMOJI_PICKER_LABELS,
1726
1759
  EmojiPicker,
1760
+ applyQuickReplyVariables,
1761
+ resolveQuickReply,
1727
1762
  DEFAULT_MESSAGE_COMPOSER_LABELS,
1728
1763
  DEFAULT_ACCEPTED_FILE_TYPES,
1729
1764
  MessageComposer,
package/dist/index.d.ts CHANGED
@@ -128,6 +128,25 @@ declare const EMOJI_CATEGORIES: readonly EmojiCategory[];
128
128
  */
129
129
  declare function searchEmojis(query: string): readonly EmojiEntry[];
130
130
 
131
+ /**
132
+ * Mensagem pronta que o atendente cola no campo com um clique.
133
+ *
134
+ * `text` aceita string com `{{variavel}}` ou função: a string cobre o caso comum (copy fixa com o
135
+ * nome do cliente no meio) sem o host escrever código, e a função cobre o que precisa de lógica —
136
+ * escolher texto por produto, pluralizar, formatar moeda.
137
+ */
138
+ interface QuickReply {
139
+ key: string;
140
+ /** O que aparece no chip, emoji incluso: `👋 Saudação`. */
141
+ label: string;
142
+ text: string | ((variables: Readonly<Record<string, string>>) => string);
143
+ }
144
+ /**
145
+ * Troca `{{nome}}` pelos valores passados. Variável ausente vira string vazia, e não o literal
146
+ * `{{nome}}`: mandar "Olá {{nome}}!" para o cliente é pior que mandar "Olá !".
147
+ */
148
+ declare function applyQuickReplyVariables(template: string, variables?: Readonly<Record<string, string>>): string;
149
+ declare function resolveQuickReply(quickReply: QuickReply, variables?: Readonly<Record<string, string>>): string;
131
150
  interface MessageComposerLabels {
132
151
  emoji: string;
133
152
  attach: string;
@@ -150,11 +169,17 @@ interface MessageComposerProps {
150
169
  * microfone. Fora do campo, o botão vira um bloco solto ao lado do pill e quebra a barra.
151
170
  */
152
171
  idleAction?: ReactNode;
172
+ /** Mensagens prontas exibidas acima do campo. Vazio ou ausente, a faixa não é renderizada. */
173
+ quickReplies?: readonly QuickReply[];
174
+ /** Valores para `{{variavel}}` — tipicamente nome do cliente, produto, protocolo. */
175
+ quickReplyVariables?: Readonly<Record<string, string>>;
153
176
  className?: string;
154
177
  classNames?: Partial<MessageComposerClassNames>;
155
178
  }
156
179
  interface MessageComposerClassNames {
157
180
  root: string;
181
+ quickReplies: string;
182
+ quickReply: string;
158
183
  field: string;
159
184
  }
160
185
  /**
@@ -164,7 +189,83 @@ interface MessageComposerClassNames {
164
189
  * Produto com regra própria passa `acceptedFileTypes`.
165
190
  */
166
191
  declare const DEFAULT_ACCEPTED_FILE_TYPES: string;
167
- declare const MessageComposer: ({ onSend, onAttach, value: externalValue, onChange: externalOnChange, features, placeholder, maxLength, disabled, acceptedFileTypes, idleAction, className, classNames, labels, }: MessageComposerProps) => react.JSX.Element;
192
+ declare const MessageComposer: ({ onSend, onAttach, value: externalValue, onChange: externalOnChange, quickReplies, quickReplyVariables, features, placeholder, maxLength, disabled, acceptedFileTypes, idleAction, className, classNames, labels, }: MessageComposerProps) => react.JSX.Element;
193
+
194
+ /** Cada ação que a barra sabe oferecer. `toolbar` decide quais delas aparecem. */
195
+ declare const RICH_COMPOSER_ACTION: {
196
+ readonly BOLD: "bold";
197
+ readonly ITALIC: "italic";
198
+ readonly STRIKETHROUGH: "strikethrough";
199
+ readonly MONOSPACE: "monospace";
200
+ readonly EMOJI: "emoji";
201
+ readonly ATTACH: "attach";
202
+ readonly VARIABLES: "variables";
203
+ };
204
+ type RichComposerAction = (typeof RICH_COMPOSER_ACTION)[keyof typeof RICH_COMPOSER_ACTION];
205
+ /** Texto das dicas. O host troca só o que quiser; o resto fica no padrão. */
206
+ interface RichComposerTooltips {
207
+ bold: string;
208
+ italic: string;
209
+ strikethrough: string;
210
+ monospace: string;
211
+ emoji: string;
212
+ attach: string;
213
+ send: string;
214
+ variables: string;
215
+ }
216
+ declare const DEFAULT_RICH_COMPOSER_TOOLTIPS: RichComposerTooltips;
217
+ /**
218
+ * Um valor que o operador pode inserir no texto sem digitar. `value` é o que entra no campo — pode
219
+ * ser o dado já resolvido ("Anderson") ou um marcador a resolver depois ("{{nome}}"): quem decide é
220
+ * o host, porque só ele sabe se a substituição acontece aqui ou no envio.
221
+ */
222
+ interface RichComposerVariable {
223
+ id: string;
224
+ label: string;
225
+ value: string;
226
+ /** Prévia do que será inserido, para o operador conferir antes de tocar. */
227
+ tooltip?: string;
228
+ }
229
+ /** Uma resposta rápida: o que o operador lê no chip e o que cai no campo ao tocar nele. */
230
+ interface RichComposerQuickReply {
231
+ id: string;
232
+ label: string;
233
+ text: string;
234
+ /** Dica ao passar o mouse. Sem isto, o chip não tem `title` — rótulo curto já se explica. */
235
+ tooltip?: string;
236
+ }
237
+ /** Handle imperativo: `contentEditable` controlado pelo React perde o cursor a cada tecla. */
238
+ interface RichMessageComposerHandle {
239
+ setContent: (text: string) => void;
240
+ clear: () => void;
241
+ focus: () => void;
242
+ }
243
+ interface RichMessageComposerProps {
244
+ /** Texto na notação do WhatsApp (`*negrito*`), não HTML. */
245
+ value: string;
246
+ onChange: (value: string) => void;
247
+ onSend: () => void;
248
+ onAttachFiles?: (files: FileList) => void;
249
+ quickReplies?: RichComposerQuickReply[];
250
+ /** Variáveis que o operador pode inserir no texto. Vazio ou ausente, o botão não aparece. */
251
+ variables?: RichComposerVariable[];
252
+ /**
253
+ * Quais ações aparecem. Ausente, todas aparecem — menos as que não têm como funcionar (anexo sem
254
+ * `onAttachFiles` some sozinho, porque botão que não faz nada é pior que botão nenhum).
255
+ */
256
+ toolbar?: Partial<Record<RichComposerAction, boolean>>;
257
+ tooltips?: Partial<RichComposerTooltips>;
258
+ placeholder?: string;
259
+ disabled?: boolean;
260
+ isSending?: boolean;
261
+ /** Ocupa o lugar do enviar enquanto não há nada para enviar — onde o WhatsApp põe o microfone. */
262
+ idleAction?: ReactNode;
263
+ /** Prévia dos anexos já escolhidos, desenhada pelo host acima da barra. */
264
+ attachmentsPreview?: ReactNode;
265
+ acceptedFileTypes?: string;
266
+ className?: string;
267
+ }
268
+ declare const RichMessageComposer: react.ForwardRefExoticComponent<RichMessageComposerProps & react.RefAttributes<RichMessageComposerHandle>>;
168
269
 
169
270
  interface WhatsAppMessageEditorLabels {
170
271
  bold: string;
@@ -1022,4 +1123,4 @@ interface AsyncResourceState<T> {
1022
1123
 
1023
1124
  declare function createMediaUrlResolver(api: Pick<ConversationsApi, 'getDocumentUrl' | 'getMediaProxyUrl'>): ResolveMediaUrl;
1024
1125
 
1025
- export { type AsyncResourceState, AudioPlayer, type AudioPlayerProps, Avatar, type AvatarLabels, type AvatarProps, type BuildTranscriptTextParams, CHANNEL_BRAND_COLOR, CONVERSATION_WINDOW, ChannelIcon, type ChannelIconProps, ConversationChannel, type ConversationContextEntry, ConversationContextPanel, type ConversationContextPanelClassNames, type ConversationContextPanelLabels, type ConversationContextPanelProps, ConversationDocument, ConversationDocumentsPanel, type ConversationDocumentsPanelClassNames, type ConversationDocumentsPanelLabels, type ConversationDocumentsPanelProps, ConversationHeader, type ConversationHeaderClassNames, type ConversationHeaderLabels, type ConversationHeaderProps, type ConversationHeaderUtility, ConversationListItem, type ConversationListItemLabels, type ConversationListItemProps, type ConversationLocales, ConversationLocalesProvider, type ConversationLocalesProviderProps, type ConversationRealtimeHandler, ConversationRow, type ConversationRowClassNames, type ConversationRowProps, ConversationSummary, ConversationTemplate, ConversationWallpaper, type ConversationWallpaperProps, type ConversationWindow, ConversationsApi, ConversationsFeatures, ConversationsProvider, DEFAULT_ACCEPTED_FILE_TYPES, DEFAULT_AVATAR_LABELS, DEFAULT_CONVERSATION_CONTEXT_LABELS, DEFAULT_CONVERSATION_DOCUMENTS_LABELS, DEFAULT_CONVERSATION_HEADER_LABELS, DEFAULT_CONVERSATION_LIST_ITEM_LABELS, DEFAULT_DOCUMENTS_LIBRARY_LABELS, DEFAULT_EMOJI_PICKER_LABELS, DEFAULT_INTERACTIVE_MESSAGE_LABELS, DEFAULT_LIGHTBOX_LABELS, DEFAULT_MESSAGE_COMPOSER_LABELS, DEFAULT_TEMPLATES_SETTINGS_LABELS, DEFAULT_WHATSAPP_MESSAGE_EDITOR_LABELS, DEFAULT_WINDOW_EXPIRED_LABELS, DOCUMENT_SOURCE_FILTER, DateDivider, type DateDividerClassNames, type DateDividerProps, type DocumentSourceFilter, DocumentsLibrary, type DocumentsLibraryClassNames, type DocumentsLibraryLabels, type DocumentsLibraryProps, EMOJI_CATEGORIES, type EmojiCategory, type EmojiEntry, EmojiPicker, type EmojiPickerLabels, type EmojiPickerProps, FileIcon, type FileIconProps, InteractiveMessage, type InteractiveMessageLabels, type InteractiveMessageProps, InteractivePayload, InteractiveSelection, Lightbox, type LightboxLabels, type LightboxProps, ListConversationsParams, ListDocumentsParams, MessageBubble, type MessageBubbleProps, MessageComposer, type MessageComposerClassNames, type MessageComposerLabels, type MessageComposerProps, MessagePayload, MessageTail, MessageText, type MessageTextProps, MessageTimestamp, NARROW_MAX_WIDTH_PX, ResolveMediaUrl, SSEProvider, SimpleEmojiPicker, type SimpleEmojiPickerProps, StatusTicks, type StatusTicksProps, TEMPLATE_SETTINGS_TAB, type TemplateSettingsTab, ToastProvider, type TopicItem, TopicsForm, type TopicsFormLabels, type TopicsFormProps, type UseConversationActionsResult, type UseConversationContextResult, type UseConversationDocumentsParams, type UseConversationDocumentsResult, type UseConversationListParams, type UseConversationListResult, type UseConversationMessagesResult, type UseInboxActionsResult, type UseWaitingNotificationsLabels, type UseWaitingNotificationsParams, type UseWaitingNotificationsResult, WINDOW_FILTERS, WelcomeFarewellForm, type WelcomeFarewellFormLabels, type WelcomeFarewellFormProps, WhatsAppCreateTemplateForm, type WhatsAppCreateTemplateFormLabels, type WhatsAppCreateTemplateFormProps, type WhatsAppCreateTemplateResult, type WhatsAppCreateTemplateState, WhatsAppMessageEditor, type WhatsAppMessageEditorLabels, type WhatsAppMessageEditorProps, type WhatsAppTemplateHeaderType, WhatsAppTemplateSettingsForm, type WhatsAppTemplateSettingsFormLabels, type WhatsAppTemplateSettingsFormProps, type WhatsAppTemplateSummary, type WhatsAppTemplateVariableSuggestion, WhatsAppTemplatesSettings, type WhatsAppTemplatesSettingsLabels, type WhatsAppTemplatesSettingsProps, WindowExpiredNotice, type WindowExpiredNoticeLabels, type WindowExpiredNoticeProps, type WindowOfParams, buildTranscriptFilename, buildTranscriptText, createMediaUrlResolver, downloadTextFile, formatDateTime, formatFileSize, formatPhone, formatStalledFor, formatTimestamp, htmlToWA, isSameDay, isWindowBlocking, parseWhatsAppFormatting, phoneInitials, searchEmojis, toast, useConversationActions, useConversationContext, useConversationDocuments, useConversationList, useConversationLocales, useConversationMessages, useConversationRealtime, useConversations, useDarkMode, useGlobalRealtime, useInboxActions, useIsDarkTheme, useIsNarrow, useToast, useWaitingNotifications, waToHTML, waToHTMLInline, windowOf };
1126
+ export { type AsyncResourceState, AudioPlayer, type AudioPlayerProps, Avatar, type AvatarLabels, type AvatarProps, type BuildTranscriptTextParams, CHANNEL_BRAND_COLOR, CONVERSATION_WINDOW, ChannelIcon, type ChannelIconProps, ConversationChannel, type ConversationContextEntry, ConversationContextPanel, type ConversationContextPanelClassNames, type ConversationContextPanelLabels, type ConversationContextPanelProps, ConversationDocument, ConversationDocumentsPanel, type ConversationDocumentsPanelClassNames, type ConversationDocumentsPanelLabels, type ConversationDocumentsPanelProps, ConversationHeader, type ConversationHeaderClassNames, type ConversationHeaderLabels, type ConversationHeaderProps, type ConversationHeaderUtility, ConversationListItem, type ConversationListItemLabels, type ConversationListItemProps, type ConversationLocales, ConversationLocalesProvider, type ConversationLocalesProviderProps, type ConversationRealtimeHandler, ConversationRow, type ConversationRowClassNames, type ConversationRowProps, ConversationSummary, ConversationTemplate, ConversationWallpaper, type ConversationWallpaperProps, type ConversationWindow, ConversationsApi, ConversationsFeatures, ConversationsProvider, DEFAULT_ACCEPTED_FILE_TYPES, DEFAULT_AVATAR_LABELS, DEFAULT_CONVERSATION_CONTEXT_LABELS, DEFAULT_CONVERSATION_DOCUMENTS_LABELS, DEFAULT_CONVERSATION_HEADER_LABELS, DEFAULT_CONVERSATION_LIST_ITEM_LABELS, DEFAULT_DOCUMENTS_LIBRARY_LABELS, DEFAULT_EMOJI_PICKER_LABELS, DEFAULT_INTERACTIVE_MESSAGE_LABELS, DEFAULT_LIGHTBOX_LABELS, DEFAULT_MESSAGE_COMPOSER_LABELS, DEFAULT_RICH_COMPOSER_TOOLTIPS, DEFAULT_TEMPLATES_SETTINGS_LABELS, DEFAULT_WHATSAPP_MESSAGE_EDITOR_LABELS, DEFAULT_WINDOW_EXPIRED_LABELS, DOCUMENT_SOURCE_FILTER, DateDivider, type DateDividerClassNames, type DateDividerProps, type DocumentSourceFilter, DocumentsLibrary, type DocumentsLibraryClassNames, type DocumentsLibraryLabels, type DocumentsLibraryProps, EMOJI_CATEGORIES, type EmojiCategory, type EmojiEntry, EmojiPicker, type EmojiPickerLabels, type EmojiPickerProps, FileIcon, type FileIconProps, InteractiveMessage, type InteractiveMessageLabels, type InteractiveMessageProps, InteractivePayload, InteractiveSelection, Lightbox, type LightboxLabels, type LightboxProps, ListConversationsParams, ListDocumentsParams, MessageBubble, type MessageBubbleProps, MessageComposer, type MessageComposerClassNames, type MessageComposerLabels, type MessageComposerProps, MessagePayload, MessageTail, MessageText, type MessageTextProps, MessageTimestamp, NARROW_MAX_WIDTH_PX, type QuickReply, RICH_COMPOSER_ACTION, ResolveMediaUrl, type RichComposerAction, type RichComposerQuickReply, type RichComposerTooltips, type RichComposerVariable, RichMessageComposer, type RichMessageComposerHandle, type RichMessageComposerProps, SSEProvider, SimpleEmojiPicker, type SimpleEmojiPickerProps, StatusTicks, type StatusTicksProps, TEMPLATE_SETTINGS_TAB, type TemplateSettingsTab, ToastProvider, type TopicItem, TopicsForm, type TopicsFormLabels, type TopicsFormProps, type UseConversationActionsResult, type UseConversationContextResult, type UseConversationDocumentsParams, type UseConversationDocumentsResult, type UseConversationListParams, type UseConversationListResult, type UseConversationMessagesResult, type UseInboxActionsResult, type UseWaitingNotificationsLabels, type UseWaitingNotificationsParams, type UseWaitingNotificationsResult, WINDOW_FILTERS, WelcomeFarewellForm, type WelcomeFarewellFormLabels, type WelcomeFarewellFormProps, WhatsAppCreateTemplateForm, type WhatsAppCreateTemplateFormLabels, type WhatsAppCreateTemplateFormProps, type WhatsAppCreateTemplateResult, type WhatsAppCreateTemplateState, WhatsAppMessageEditor, type WhatsAppMessageEditorLabels, type WhatsAppMessageEditorProps, type WhatsAppTemplateHeaderType, WhatsAppTemplateSettingsForm, type WhatsAppTemplateSettingsFormLabels, type WhatsAppTemplateSettingsFormProps, type WhatsAppTemplateSummary, type WhatsAppTemplateVariableSuggestion, WhatsAppTemplatesSettings, type WhatsAppTemplatesSettingsLabels, type WhatsAppTemplatesSettingsProps, WindowExpiredNotice, type WindowExpiredNoticeLabels, type WindowExpiredNoticeProps, type WindowOfParams, applyQuickReplyVariables, buildTranscriptFilename, buildTranscriptText, createMediaUrlResolver, downloadTextFile, formatDateTime, formatFileSize, formatPhone, formatStalledFor, formatTimestamp, htmlToWA, isSameDay, isWindowBlocking, parseWhatsAppFormatting, phoneInitials, resolveQuickReply, searchEmojis, toast, useConversationActions, useConversationContext, useConversationDocuments, useConversationList, useConversationLocales, useConversationMessages, useConversationRealtime, useConversations, useDarkMode, useGlobalRealtime, useInboxActions, useIsDarkTheme, useIsNarrow, useToast, useWaitingNotifications, waToHTML, waToHTMLInline, windowOf };