@better-zap/react 0.0.1 → 0.0.2

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.cjs CHANGED
@@ -29,6 +29,7 @@ let react_jsx_runtime = require("react/jsx-runtime");
29
29
  let _hugeicons_react = require("@hugeicons/react");
30
30
  let _hugeicons_core_free_icons = require("@hugeicons/core-free-icons");
31
31
  let class_variance_authority = require("class-variance-authority");
32
+ let better_zap = require("better-zap");
32
33
  //#region src/react/utils.ts
33
34
  function cn(...inputs) {
34
35
  return (0, tailwind_merge.twMerge)((0, clsx.clsx)(inputs));
@@ -490,11 +491,16 @@ function formatTime(dateStr) {
490
491
  }
491
492
  //#endregion
492
493
  //#region src/react/message-input.tsx
493
- function MessageInput({ onSend, disabled, placeholder = "Digite uma mensagem", className, contextWindowOpen = true }) {
494
+ function MessageInput({ onSend, conversation, messages, disabled, placeholder = "Digite uma mensagem", className, contextWindowOpen = true }) {
494
495
  const [text, setText] = (0, react.useState)("");
495
496
  const [isSending, setIsSending] = (0, react.useState)(false);
496
497
  const textareaRef = (0, react.useRef)(null);
497
- const isDisabled = disabled || isSending || !contextWindowOpen;
498
+ const isContextWindowOpen = (conversation ? (0, better_zap.resolveConversationFreeformMessageWindow)(conversation, messages) : {
499
+ isOpen: contextWindowOpen,
500
+ lastIncomingMessageAt: null,
501
+ expiresAt: null
502
+ }).isOpen;
503
+ const isDisabled = disabled || isSending || !isContextWindowOpen;
498
504
  const handleSend = async () => {
499
505
  const trimmedText = text.trim();
500
506
  if (!trimmedText || isDisabled) return;
@@ -520,7 +526,7 @@ function MessageInput({ onSend, disabled, placeholder = "Digite uma mensagem", c
520
526
  }
521
527
  }, [text]);
522
528
  const hasText = text.trim().length > 0;
523
- if (!contextWindowOpen) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
529
+ if (!isContextWindowOpen) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
524
530
  className: cn("w-full flex flex-col p-4 z-10 shrink-0", className),
525
531
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
526
532
  className: "flex items-center gap-2 px-4 py-3 min-h-[62px] bg-[#fef3c7] rounded-2xl border border-[#f59e0b]/20",
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime0 from "react/jsx-runtime";
2
2
  import React from "react";
3
- import { Conversation, Conversation as Conversation$1, UIMessage, UIMessage as UIMessage$1, UIMessageStatus, UIMessageStatus as UIMessageStatus$1 } from "better-zap";
3
+ import { Conversation, Conversation as Conversation$1, ConversationRecord, FreeformMessageWindow, UIMessage, UIMessage as UIMessage$1, UIMessageStatus, UIMessageStatus as UIMessageStatus$1 } from "better-zap";
4
4
  import { ClassValue } from "clsx";
5
5
 
6
6
  //#region src/react/whatsapp-dashboard.d.ts
@@ -130,17 +130,22 @@ declare function cn(...inputs: ClassValue[]): string;
130
130
  //#region src/react/message-input.d.ts
131
131
  interface MessageInputProps {
132
132
  onSend: (text: string) => void | Promise<void>;
133
+ conversation?: Conversation$1 | null;
134
+ messages?: UIMessage$1[];
133
135
  disabled?: boolean;
134
136
  placeholder?: string;
135
137
  className?: string;
138
+ /** @deprecated Prefer `conversation` (and optional `messages`) so the library owns window state. */
136
139
  contextWindowOpen?: boolean;
137
140
  }
138
141
  declare function MessageInput({
139
142
  onSend,
143
+ conversation,
144
+ messages,
140
145
  disabled,
141
146
  placeholder,
142
147
  className,
143
148
  contextWindowOpen
144
149
  }: MessageInputProps): react_jsx_runtime0.JSX.Element;
145
150
  //#endregion
146
- export { type Conversation, ConversationItem, ConversationList, FormattedMessage, MessageBubble, MessageBubbleProps, MessageInput, MessageList, MessageView, MessageViewContent, MessageViewEmpty, MessageViewHeader, type UIMessage, type UIMessageStatus, WhatsappDashboard, cn, useWhatsappDashboard };
151
+ export { type Conversation, ConversationItem, ConversationList, type ConversationRecord, FormattedMessage, type FreeformMessageWindow, MessageBubble, MessageBubbleProps, MessageInput, MessageList, MessageView, MessageViewContent, MessageViewEmpty, MessageViewHeader, type UIMessage, type UIMessageStatus, WhatsappDashboard, cn, useWhatsappDashboard };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import { ClassValue } from "clsx";
3
3
  import * as react_jsx_runtime0 from "react/jsx-runtime";
4
- import { Conversation, Conversation as Conversation$1, UIMessage, UIMessage as UIMessage$1, UIMessageStatus, UIMessageStatus as UIMessageStatus$1 } from "better-zap";
4
+ import { Conversation, Conversation as Conversation$1, ConversationRecord, FreeformMessageWindow, UIMessage, UIMessage as UIMessage$1, UIMessageStatus, UIMessageStatus as UIMessageStatus$1 } from "better-zap";
5
5
 
6
6
  //#region src/react/whatsapp-dashboard.d.ts
7
7
  type MobileView = "list" | "chat";
@@ -130,17 +130,22 @@ declare function cn(...inputs: ClassValue[]): string;
130
130
  //#region src/react/message-input.d.ts
131
131
  interface MessageInputProps {
132
132
  onSend: (text: string) => void | Promise<void>;
133
+ conversation?: Conversation$1 | null;
134
+ messages?: UIMessage$1[];
133
135
  disabled?: boolean;
134
136
  placeholder?: string;
135
137
  className?: string;
138
+ /** @deprecated Prefer `conversation` (and optional `messages`) so the library owns window state. */
136
139
  contextWindowOpen?: boolean;
137
140
  }
138
141
  declare function MessageInput({
139
142
  onSend,
143
+ conversation,
144
+ messages,
140
145
  disabled,
141
146
  placeholder,
142
147
  className,
143
148
  contextWindowOpen
144
149
  }: MessageInputProps): react_jsx_runtime0.JSX.Element;
145
150
  //#endregion
146
- export { type Conversation, ConversationItem, ConversationList, FormattedMessage, MessageBubble, MessageBubbleProps, MessageInput, MessageList, MessageView, MessageViewContent, MessageViewEmpty, MessageViewHeader, type UIMessage, type UIMessageStatus, WhatsappDashboard, cn, useWhatsappDashboard };
151
+ export { type Conversation, ConversationItem, ConversationList, type ConversationRecord, FormattedMessage, type FreeformMessageWindow, MessageBubble, MessageBubbleProps, MessageInput, MessageList, MessageView, MessageViewContent, MessageViewEmpty, MessageViewHeader, type UIMessage, type UIMessageStatus, WhatsappDashboard, cn, useWhatsappDashboard };
package/dist/index.mjs CHANGED
@@ -5,6 +5,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  import { HugeiconsIcon } from "@hugeicons/react";
6
6
  import { Add01Icon, ArrowLeft02Icon, Clock01Icon, InformationCircleIcon, Message01Icon, Mic01Icon, Search01Icon, Sent02Icon, SmileIcon, UserIcon } from "@hugeicons/core-free-icons";
7
7
  import { cva } from "class-variance-authority";
8
+ import { resolveConversationFreeformMessageWindow } from "better-zap";
8
9
  //#region src/react/utils.ts
9
10
  function cn(...inputs) {
10
11
  return twMerge(clsx(inputs));
@@ -466,11 +467,16 @@ function formatTime(dateStr) {
466
467
  }
467
468
  //#endregion
468
469
  //#region src/react/message-input.tsx
469
- function MessageInput({ onSend, disabled, placeholder = "Digite uma mensagem", className, contextWindowOpen = true }) {
470
+ function MessageInput({ onSend, conversation, messages, disabled, placeholder = "Digite uma mensagem", className, contextWindowOpen = true }) {
470
471
  const [text, setText] = useState("");
471
472
  const [isSending, setIsSending] = useState(false);
472
473
  const textareaRef = useRef(null);
473
- const isDisabled = disabled || isSending || !contextWindowOpen;
474
+ const isContextWindowOpen = (conversation ? resolveConversationFreeformMessageWindow(conversation, messages) : {
475
+ isOpen: contextWindowOpen,
476
+ lastIncomingMessageAt: null,
477
+ expiresAt: null
478
+ }).isOpen;
479
+ const isDisabled = disabled || isSending || !isContextWindowOpen;
474
480
  const handleSend = async () => {
475
481
  const trimmedText = text.trim();
476
482
  if (!trimmedText || isDisabled) return;
@@ -496,7 +502,7 @@ function MessageInput({ onSend, disabled, placeholder = "Digite uma mensagem", c
496
502
  }
497
503
  }, [text]);
498
504
  const hasText = text.trim().length > 0;
499
- if (!contextWindowOpen) return /* @__PURE__ */ jsx("div", {
505
+ if (!isContextWindowOpen) return /* @__PURE__ */ jsx("div", {
500
506
  className: cn("w-full flex flex-col p-4 z-10 shrink-0", className),
501
507
  children: /* @__PURE__ */ jsxs("div", {
502
508
  className: "flex items-center gap-2 px-4 py-3 min-h-[62px] bg-[#fef3c7] rounded-2xl border border-[#f59e0b]/20",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-zap/react",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "React components for Better Zap.",
5
5
  "license": "ISC",
6
6
  "type": "module",
@@ -36,7 +36,7 @@
36
36
  "class-variance-authority": "^0.7.1",
37
37
  "clsx": "^2.1.1",
38
38
  "tailwind-merge": "^3.0.0",
39
- "better-zap": "0.0.1"
39
+ "better-zap": "0.0.2"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "react": "^19.0.0",