@menuia/react 1.2.0 → 1.4.1

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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { MenuIAConfig, ChatMessage, ConnectionStatus } from '@menuia/core';
2
+ import { MenuIAConfig, ChatMessage, ConnectionStatus, MessageAttachment } from '@menuia/core';
3
3
  export { ChatMessage, ConnectionStatus, MenuIAClient, MenuIAConfig, MessageAttachment, SendMessageOptions } from '@menuia/core';
4
4
 
5
5
  interface MenuIAChatProps extends Omit<MenuIAConfig, 'widgetId' | 'agentId'> {
@@ -43,7 +43,7 @@ interface UseMenuIAReturn {
43
43
  isStreaming: boolean;
44
44
  streamingText: string;
45
45
  error: string | null;
46
- sendMessage: (content: string) => Promise<void>;
46
+ sendMessage: (content: string, attachments?: MessageAttachment[]) => Promise<void>;
47
47
  clearChat: () => void;
48
48
  ticketId: string | null;
49
49
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { MenuIAConfig, ChatMessage, ConnectionStatus } from '@menuia/core';
2
+ import { MenuIAConfig, ChatMessage, ConnectionStatus, MessageAttachment } from '@menuia/core';
3
3
  export { ChatMessage, ConnectionStatus, MenuIAClient, MenuIAConfig, MessageAttachment, SendMessageOptions } from '@menuia/core';
4
4
 
5
5
  interface MenuIAChatProps extends Omit<MenuIAConfig, 'widgetId' | 'agentId'> {
@@ -43,7 +43,7 @@ interface UseMenuIAReturn {
43
43
  isStreaming: boolean;
44
44
  streamingText: string;
45
45
  error: string | null;
46
- sendMessage: (content: string) => Promise<void>;
46
+ sendMessage: (content: string, attachments?: MessageAttachment[]) => Promise<void>;
47
47
  clearChat: () => void;
48
48
  ticketId: string | null;
49
49
  }
package/dist/index.js CHANGED
@@ -75,22 +75,27 @@ function useMenuIA(config) {
75
75
  clientRef.current = null;
76
76
  };
77
77
  }, [config.widgetId, config.agentId, config.apiUrl]);
78
- const sendMessage = (0, import_react.useCallback)(async (content) => {
79
- if (!clientRef.current || !content.trim()) return;
78
+ const sendMessage = (0, import_react.useCallback)(async (content, attachments) => {
79
+ const text = content.trim();
80
+ const hasAttachments = !!(attachments && attachments.length);
81
+ if (!clientRef.current || !text && !hasAttachments) return;
80
82
  setError(null);
81
83
  setIsLoading(true);
84
+ const firstAtt = hasAttachments ? attachments[0] : void 0;
82
85
  const userMsg = {
83
86
  id: `user_${Date.now()}`,
84
87
  role: "user",
85
- content: content.trim(),
86
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
88
+ content: text,
89
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
90
+ mediaUrl: firstAtt ? `data:${firstAtt.mimeType};base64,${firstAtt.data}` : void 0,
91
+ mediaType: firstAtt ? firstAtt.mimeType : void 0
87
92
  };
88
93
  setMessages((prev) => [...prev, userMsg]);
89
94
  try {
90
95
  setIsStreaming(true);
91
96
  setStreamingText("");
92
97
  const response = await clientRef.current.sendMessageStream(
93
- { content: content.trim() },
98
+ { content: text, attachments },
94
99
  (_token, fullText) => {
95
100
  setStreamingText(fullText);
96
101
  }
@@ -113,7 +118,7 @@ function useMenuIA(config) {
113
118
  try {
114
119
  setIsStreaming(false);
115
120
  setStreamingText("");
116
- const response = await clientRef.current.sendMessage({ content: content.trim() });
121
+ const response = await clientRef.current.sendMessage({ content: text, attachments });
117
122
  const assistantMsg = {
118
123
  id: `assistant_${Date.now()}_fb`,
119
124
  role: "assistant",
@@ -388,6 +393,69 @@ function getStyles(primaryColor, theme) {
388
393
  display: "flex",
389
394
  alignItems: "center",
390
395
  justifyContent: "center"
396
+ },
397
+ // Attach (anexo) button in the input area
398
+ attachButton: {
399
+ width: 40,
400
+ height: 40,
401
+ borderRadius: 12,
402
+ background: bgSecondary,
403
+ border: `1px solid ${border}`,
404
+ cursor: "pointer",
405
+ display: "flex",
406
+ alignItems: "center",
407
+ justifyContent: "center",
408
+ color: textMuted,
409
+ flexShrink: 0,
410
+ transition: "opacity 0.2s, color 0.2s"
411
+ },
412
+ // Selected-attachment preview chip (above the input)
413
+ attachPreview: {
414
+ margin: "0 16px 8px",
415
+ padding: "8px 10px",
416
+ borderRadius: 10,
417
+ background: bgSecondary,
418
+ border: `1px solid ${border}`,
419
+ display: "flex",
420
+ alignItems: "center",
421
+ gap: 8,
422
+ fontSize: 12,
423
+ color: text
424
+ },
425
+ attachThumb: {
426
+ width: 36,
427
+ height: 36,
428
+ borderRadius: 8,
429
+ objectFit: "cover",
430
+ flexShrink: 0
431
+ },
432
+ attachRemove: {
433
+ marginLeft: "auto",
434
+ background: "transparent",
435
+ border: "none",
436
+ cursor: "pointer",
437
+ color: textMuted,
438
+ display: "flex",
439
+ alignItems: "center",
440
+ justifyContent: "center",
441
+ padding: 4
442
+ },
443
+ // Media inside a message bubble
444
+ messageImage: {
445
+ maxWidth: "100%",
446
+ borderRadius: 10,
447
+ marginBottom: 6,
448
+ display: "block",
449
+ cursor: "pointer"
450
+ },
451
+ messageFile: {
452
+ display: "flex",
453
+ alignItems: "center",
454
+ gap: 6,
455
+ fontSize: 13,
456
+ marginBottom: 6,
457
+ color: "inherit",
458
+ textDecoration: "underline"
391
459
  }
392
460
  };
393
461
  }
@@ -432,6 +500,9 @@ function MenuIAChat({
432
500
  const [input, setInput] = (0, import_react2.useState)("");
433
501
  const messagesEndRef = (0, import_react2.useRef)(null);
434
502
  const inputRef = (0, import_react2.useRef)(null);
503
+ const fileInputRef = (0, import_react2.useRef)(null);
504
+ const [attachment, setAttachment] = (0, import_react2.useState)(null);
505
+ const [attachError, setAttachError] = (0, import_react2.useState)(null);
435
506
  const {
436
507
  messages,
437
508
  isLoading,
@@ -462,11 +533,39 @@ function MenuIAChat({
462
533
  setTimeout(() => inputRef.current?.focus(), 300);
463
534
  }
464
535
  }, [isOpen]);
536
+ const MAX_ATTACH_BYTES = 10 * 1024 * 1024;
537
+ const handleFileChange = (e) => {
538
+ const file = e.target.files?.[0];
539
+ e.target.value = "";
540
+ if (!file) return;
541
+ setAttachError(null);
542
+ if (file.size > MAX_ATTACH_BYTES) {
543
+ setAttachError("Arquivo muito grande (m\xE1x. 10MB).");
544
+ return;
545
+ }
546
+ const mime = file.type || "application/octet-stream";
547
+ const type = mime.startsWith("image/") ? "image" : mime.startsWith("audio/") ? "audio" : "document";
548
+ const reader = new FileReader();
549
+ reader.onload = () => {
550
+ const result = String(reader.result || "");
551
+ const base64 = result.includes(",") ? result.slice(result.indexOf(",") + 1) : result;
552
+ if (!base64) {
553
+ setAttachError("Nao foi possivel ler o arquivo.");
554
+ return;
555
+ }
556
+ setAttachment({ type, data: base64, mimeType: mime, name: file.name, preview: type === "image" ? result : void 0 });
557
+ };
558
+ reader.onerror = () => setAttachError("Nao foi possivel ler o arquivo.");
559
+ reader.readAsDataURL(file);
560
+ };
465
561
  const handleSend = async () => {
466
562
  const text = input.trim();
467
- if (!text || isLoading) return;
563
+ if (!text && !attachment || isLoading) return;
564
+ const atts = attachment ? [{ type: attachment.type, data: attachment.data, mimeType: attachment.mimeType, name: attachment.name }] : void 0;
468
565
  setInput("");
469
- await sendMessage(text);
566
+ setAttachment(null);
567
+ setAttachError(null);
568
+ await sendMessage(text, atts);
470
569
  };
471
570
  const handleKeyDown = (e) => {
472
571
  if (e.key === "Enter" && !e.shiftKey) {
@@ -507,7 +606,10 @@ function MenuIAChat({
507
606
  welcomeMessage
508
607
  ] }),
509
608
  messages.map((msg) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
510
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: msg.role === "user" ? styles.userBubble : styles.aiBubble, children: renderContent(msg.content) }),
609
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: msg.role === "user" ? styles.userBubble : styles.aiBubble, children: [
610
+ renderMedia(msg, styles),
611
+ renderContent(msg.content)
612
+ ] }),
511
613
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: { ...styles.timestamp, textAlign: msg.role === "user" ? "right" : "left" }, children: formatTime(msg.createdAt) })
512
614
  ] }, msg.id)),
513
615
  isStreaming && streamingText && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: styles.streaming, children: [
@@ -521,7 +623,49 @@ function MenuIAChat({
521
623
  ] }),
522
624
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: messagesEndRef })
523
625
  ] }),
626
+ (attachment || attachError) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { ...styles.attachPreview, ...attachError && !attachment ? { color: "#ef4444" } : {} }, children: [
627
+ attachment?.preview ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: attachment.preview, alt: "", style: styles.attachThumb }) : attachment ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
628
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z" }),
629
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 2v6h6" })
630
+ ] }) : null,
631
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: attachError ? attachError : attachment?.name || "anexo" }),
632
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
633
+ "button",
634
+ {
635
+ type: "button",
636
+ onClick: () => {
637
+ setAttachment(null);
638
+ setAttachError(null);
639
+ },
640
+ style: styles.attachRemove,
641
+ "aria-label": "Remover anexo",
642
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M18 6L6 18M6 6l12 12" }) })
643
+ }
644
+ )
645
+ ] }),
524
646
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: styles.inputArea, children: [
647
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
648
+ "input",
649
+ {
650
+ ref: fileInputRef,
651
+ type: "file",
652
+ accept: "image/*,audio/*,.pdf,.doc,.docx,.txt,.csv,.xls,.xlsx",
653
+ style: { display: "none" },
654
+ onChange: handleFileChange
655
+ }
656
+ ),
657
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
658
+ "button",
659
+ {
660
+ type: "button",
661
+ onClick: () => fileInputRef.current?.click(),
662
+ disabled: isLoading,
663
+ style: { ...styles.attachButton, opacity: isLoading ? 0.5 : 1 },
664
+ title: "Anexar arquivo",
665
+ "aria-label": "Anexar arquivo",
666
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48" }) })
667
+ }
668
+ ),
525
669
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
526
670
  "textarea",
527
671
  {
@@ -539,8 +683,8 @@ function MenuIAChat({
539
683
  "button",
540
684
  {
541
685
  onClick: handleSend,
542
- disabled: !input.trim() || isLoading,
543
- style: { ...styles.sendButton, opacity: !input.trim() || isLoading ? 0.5 : 1 },
686
+ disabled: !input.trim() && !attachment || isLoading,
687
+ style: { ...styles.sendButton, opacity: !input.trim() && !attachment || isLoading ? 0.5 : 1 },
544
688
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
545
689
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M22 2L11 13" }),
546
690
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M22 2L15 22L11 13L2 9L22 2Z" })
@@ -586,6 +730,33 @@ function MenuIAChat({
586
730
  )
587
731
  ] });
588
732
  }
733
+ function renderMedia(msg, styles) {
734
+ if (!msg.mediaUrl) return null;
735
+ const isImage = (msg.mediaType || "").startsWith("image");
736
+ if (isImage) {
737
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
738
+ "img",
739
+ {
740
+ src: msg.mediaUrl,
741
+ alt: msg.content || "imagem",
742
+ style: styles.messageImage,
743
+ onClick: () => {
744
+ try {
745
+ window.open(msg.mediaUrl, "_blank");
746
+ } catch {
747
+ }
748
+ }
749
+ }
750
+ );
751
+ }
752
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("a", { href: msg.mediaUrl, target: "_blank", rel: "noreferrer", style: styles.messageFile, children: [
753
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
754
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z" }),
755
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 2v6h6" })
756
+ ] }),
757
+ "Ver anexo"
758
+ ] });
759
+ }
589
760
  function renderContent(content) {
590
761
  if (!content) return null;
591
762
  const paragraphs = content.split("\n\n");
package/dist/index.mjs CHANGED
@@ -37,22 +37,27 @@ function useMenuIA(config) {
37
37
  clientRef.current = null;
38
38
  };
39
39
  }, [config.widgetId, config.agentId, config.apiUrl]);
40
- const sendMessage = useCallback(async (content) => {
41
- if (!clientRef.current || !content.trim()) return;
40
+ const sendMessage = useCallback(async (content, attachments) => {
41
+ const text = content.trim();
42
+ const hasAttachments = !!(attachments && attachments.length);
43
+ if (!clientRef.current || !text && !hasAttachments) return;
42
44
  setError(null);
43
45
  setIsLoading(true);
46
+ const firstAtt = hasAttachments ? attachments[0] : void 0;
44
47
  const userMsg = {
45
48
  id: `user_${Date.now()}`,
46
49
  role: "user",
47
- content: content.trim(),
48
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
50
+ content: text,
51
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
52
+ mediaUrl: firstAtt ? `data:${firstAtt.mimeType};base64,${firstAtt.data}` : void 0,
53
+ mediaType: firstAtt ? firstAtt.mimeType : void 0
49
54
  };
50
55
  setMessages((prev) => [...prev, userMsg]);
51
56
  try {
52
57
  setIsStreaming(true);
53
58
  setStreamingText("");
54
59
  const response = await clientRef.current.sendMessageStream(
55
- { content: content.trim() },
60
+ { content: text, attachments },
56
61
  (_token, fullText) => {
57
62
  setStreamingText(fullText);
58
63
  }
@@ -75,7 +80,7 @@ function useMenuIA(config) {
75
80
  try {
76
81
  setIsStreaming(false);
77
82
  setStreamingText("");
78
- const response = await clientRef.current.sendMessage({ content: content.trim() });
83
+ const response = await clientRef.current.sendMessage({ content: text, attachments });
79
84
  const assistantMsg = {
80
85
  id: `assistant_${Date.now()}_fb`,
81
86
  role: "assistant",
@@ -350,6 +355,69 @@ function getStyles(primaryColor, theme) {
350
355
  display: "flex",
351
356
  alignItems: "center",
352
357
  justifyContent: "center"
358
+ },
359
+ // Attach (anexo) button in the input area
360
+ attachButton: {
361
+ width: 40,
362
+ height: 40,
363
+ borderRadius: 12,
364
+ background: bgSecondary,
365
+ border: `1px solid ${border}`,
366
+ cursor: "pointer",
367
+ display: "flex",
368
+ alignItems: "center",
369
+ justifyContent: "center",
370
+ color: textMuted,
371
+ flexShrink: 0,
372
+ transition: "opacity 0.2s, color 0.2s"
373
+ },
374
+ // Selected-attachment preview chip (above the input)
375
+ attachPreview: {
376
+ margin: "0 16px 8px",
377
+ padding: "8px 10px",
378
+ borderRadius: 10,
379
+ background: bgSecondary,
380
+ border: `1px solid ${border}`,
381
+ display: "flex",
382
+ alignItems: "center",
383
+ gap: 8,
384
+ fontSize: 12,
385
+ color: text
386
+ },
387
+ attachThumb: {
388
+ width: 36,
389
+ height: 36,
390
+ borderRadius: 8,
391
+ objectFit: "cover",
392
+ flexShrink: 0
393
+ },
394
+ attachRemove: {
395
+ marginLeft: "auto",
396
+ background: "transparent",
397
+ border: "none",
398
+ cursor: "pointer",
399
+ color: textMuted,
400
+ display: "flex",
401
+ alignItems: "center",
402
+ justifyContent: "center",
403
+ padding: 4
404
+ },
405
+ // Media inside a message bubble
406
+ messageImage: {
407
+ maxWidth: "100%",
408
+ borderRadius: 10,
409
+ marginBottom: 6,
410
+ display: "block",
411
+ cursor: "pointer"
412
+ },
413
+ messageFile: {
414
+ display: "flex",
415
+ alignItems: "center",
416
+ gap: 6,
417
+ fontSize: 13,
418
+ marginBottom: 6,
419
+ color: "inherit",
420
+ textDecoration: "underline"
353
421
  }
354
422
  };
355
423
  }
@@ -394,6 +462,9 @@ function MenuIAChat({
394
462
  const [input, setInput] = useState2("");
395
463
  const messagesEndRef = useRef2(null);
396
464
  const inputRef = useRef2(null);
465
+ const fileInputRef = useRef2(null);
466
+ const [attachment, setAttachment] = useState2(null);
467
+ const [attachError, setAttachError] = useState2(null);
397
468
  const {
398
469
  messages,
399
470
  isLoading,
@@ -424,11 +495,39 @@ function MenuIAChat({
424
495
  setTimeout(() => inputRef.current?.focus(), 300);
425
496
  }
426
497
  }, [isOpen]);
498
+ const MAX_ATTACH_BYTES = 10 * 1024 * 1024;
499
+ const handleFileChange = (e) => {
500
+ const file = e.target.files?.[0];
501
+ e.target.value = "";
502
+ if (!file) return;
503
+ setAttachError(null);
504
+ if (file.size > MAX_ATTACH_BYTES) {
505
+ setAttachError("Arquivo muito grande (m\xE1x. 10MB).");
506
+ return;
507
+ }
508
+ const mime = file.type || "application/octet-stream";
509
+ const type = mime.startsWith("image/") ? "image" : mime.startsWith("audio/") ? "audio" : "document";
510
+ const reader = new FileReader();
511
+ reader.onload = () => {
512
+ const result = String(reader.result || "");
513
+ const base64 = result.includes(",") ? result.slice(result.indexOf(",") + 1) : result;
514
+ if (!base64) {
515
+ setAttachError("Nao foi possivel ler o arquivo.");
516
+ return;
517
+ }
518
+ setAttachment({ type, data: base64, mimeType: mime, name: file.name, preview: type === "image" ? result : void 0 });
519
+ };
520
+ reader.onerror = () => setAttachError("Nao foi possivel ler o arquivo.");
521
+ reader.readAsDataURL(file);
522
+ };
427
523
  const handleSend = async () => {
428
524
  const text = input.trim();
429
- if (!text || isLoading) return;
525
+ if (!text && !attachment || isLoading) return;
526
+ const atts = attachment ? [{ type: attachment.type, data: attachment.data, mimeType: attachment.mimeType, name: attachment.name }] : void 0;
430
527
  setInput("");
431
- await sendMessage(text);
528
+ setAttachment(null);
529
+ setAttachError(null);
530
+ await sendMessage(text, atts);
432
531
  };
433
532
  const handleKeyDown = (e) => {
434
533
  if (e.key === "Enter" && !e.shiftKey) {
@@ -469,7 +568,10 @@ function MenuIAChat({
469
568
  welcomeMessage
470
569
  ] }),
471
570
  messages.map((msg) => /* @__PURE__ */ jsxs("div", { children: [
472
- /* @__PURE__ */ jsx("div", { style: msg.role === "user" ? styles.userBubble : styles.aiBubble, children: renderContent(msg.content) }),
571
+ /* @__PURE__ */ jsxs("div", { style: msg.role === "user" ? styles.userBubble : styles.aiBubble, children: [
572
+ renderMedia(msg, styles),
573
+ renderContent(msg.content)
574
+ ] }),
473
575
  /* @__PURE__ */ jsx("div", { style: { ...styles.timestamp, textAlign: msg.role === "user" ? "right" : "left" }, children: formatTime(msg.createdAt) })
474
576
  ] }, msg.id)),
475
577
  isStreaming && streamingText && /* @__PURE__ */ jsxs("div", { style: styles.streaming, children: [
@@ -483,7 +585,49 @@ function MenuIAChat({
483
585
  ] }),
484
586
  /* @__PURE__ */ jsx("div", { ref: messagesEndRef })
485
587
  ] }),
588
+ (attachment || attachError) && /* @__PURE__ */ jsxs("div", { style: { ...styles.attachPreview, ...attachError && !attachment ? { color: "#ef4444" } : {} }, children: [
589
+ attachment?.preview ? /* @__PURE__ */ jsx("img", { src: attachment.preview, alt: "", style: styles.attachThumb }) : attachment ? /* @__PURE__ */ jsxs("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
590
+ /* @__PURE__ */ jsx("path", { d: "M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z" }),
591
+ /* @__PURE__ */ jsx("path", { d: "M14 2v6h6" })
592
+ ] }) : null,
593
+ /* @__PURE__ */ jsx("span", { style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: attachError ? attachError : attachment?.name || "anexo" }),
594
+ /* @__PURE__ */ jsx(
595
+ "button",
596
+ {
597
+ type: "button",
598
+ onClick: () => {
599
+ setAttachment(null);
600
+ setAttachError(null);
601
+ },
602
+ style: styles.attachRemove,
603
+ "aria-label": "Remover anexo",
604
+ children: /* @__PURE__ */ jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" }) })
605
+ }
606
+ )
607
+ ] }),
486
608
  /* @__PURE__ */ jsxs("div", { style: styles.inputArea, children: [
609
+ /* @__PURE__ */ jsx(
610
+ "input",
611
+ {
612
+ ref: fileInputRef,
613
+ type: "file",
614
+ accept: "image/*,audio/*,.pdf,.doc,.docx,.txt,.csv,.xls,.xlsx",
615
+ style: { display: "none" },
616
+ onChange: handleFileChange
617
+ }
618
+ ),
619
+ /* @__PURE__ */ jsx(
620
+ "button",
621
+ {
622
+ type: "button",
623
+ onClick: () => fileInputRef.current?.click(),
624
+ disabled: isLoading,
625
+ style: { ...styles.attachButton, opacity: isLoading ? 0.5 : 1 },
626
+ title: "Anexar arquivo",
627
+ "aria-label": "Anexar arquivo",
628
+ children: /* @__PURE__ */ jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ jsx("path", { d: "M21.44 11.05l-9.19 9.19a6 6 0 01-8.49-8.49l9.19-9.19a4 4 0 015.66 5.66l-9.2 9.19a2 2 0 01-2.83-2.83l8.49-8.48" }) })
629
+ }
630
+ ),
487
631
  /* @__PURE__ */ jsx(
488
632
  "textarea",
489
633
  {
@@ -501,8 +645,8 @@ function MenuIAChat({
501
645
  "button",
502
646
  {
503
647
  onClick: handleSend,
504
- disabled: !input.trim() || isLoading,
505
- style: { ...styles.sendButton, opacity: !input.trim() || isLoading ? 0.5 : 1 },
648
+ disabled: !input.trim() && !attachment || isLoading,
649
+ style: { ...styles.sendButton, opacity: !input.trim() && !attachment || isLoading ? 0.5 : 1 },
506
650
  children: /* @__PURE__ */ jsxs("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
507
651
  /* @__PURE__ */ jsx("path", { d: "M22 2L11 13" }),
508
652
  /* @__PURE__ */ jsx("path", { d: "M22 2L15 22L11 13L2 9L22 2Z" })
@@ -548,6 +692,33 @@ function MenuIAChat({
548
692
  )
549
693
  ] });
550
694
  }
695
+ function renderMedia(msg, styles) {
696
+ if (!msg.mediaUrl) return null;
697
+ const isImage = (msg.mediaType || "").startsWith("image");
698
+ if (isImage) {
699
+ return /* @__PURE__ */ jsx(
700
+ "img",
701
+ {
702
+ src: msg.mediaUrl,
703
+ alt: msg.content || "imagem",
704
+ style: styles.messageImage,
705
+ onClick: () => {
706
+ try {
707
+ window.open(msg.mediaUrl, "_blank");
708
+ } catch {
709
+ }
710
+ }
711
+ }
712
+ );
713
+ }
714
+ return /* @__PURE__ */ jsxs("a", { href: msg.mediaUrl, target: "_blank", rel: "noreferrer", style: styles.messageFile, children: [
715
+ /* @__PURE__ */ jsxs("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
716
+ /* @__PURE__ */ jsx("path", { d: "M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z" }),
717
+ /* @__PURE__ */ jsx("path", { d: "M14 2v6h6" })
718
+ ] }),
719
+ "Ver anexo"
720
+ ] });
721
+ }
551
722
  function renderContent(content) {
552
723
  if (!content) return null;
553
724
  const paragraphs = content.split("\n\n");
package/package.json CHANGED
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "name": "@menuia/react",
3
- "version": "1.2.0",
3
+ "version": "1.4.1",
4
4
  "description": "MenuIA Chat SDK - React Component",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
- "files": ["dist"],
8
+ "files": [
9
+ "dist"
10
+ ],
9
11
  "scripts": {
10
12
  "build": "tsup src/index.tsx --format cjs,esm --dts --clean --external react --external react-dom --external @menuia/core",
11
13
  "dev": "tsup src/index.tsx --format cjs,esm --dts --watch --external react --external react-dom --external @menuia/core"
@@ -15,7 +17,7 @@
15
17
  "react-dom": ">=17.0.0"
16
18
  },
17
19
  "dependencies": {
18
- "@menuia/core": "^1.0.0"
20
+ "@menuia/core": "^1.4.0"
19
21
  },
20
22
  "devDependencies": {
21
23
  "@types/react": "^18.2.0",