@copilotz/chat-ui 0.9.16 → 0.9.18

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.js CHANGED
@@ -4566,7 +4566,7 @@ var resolveVoiceErrorMessage = (error, config) => {
4566
4566
  var clearVoiceTranscript = () => ({});
4567
4567
  var resolveVoiceSegmentDuration = (segment) => segment.attachment.durationMs ?? 0;
4568
4568
  var ChatInput = memo4(function ChatInput2({
4569
- value,
4569
+ value: externalValue,
4570
4570
  onChange,
4571
4571
  onSubmit,
4572
4572
  attachments,
@@ -4597,6 +4597,7 @@ var ChatInput = memo4(function ChatInput2({
4597
4597
  const voiceTranscriptMode = config?.voiceCompose?.transcriptMode ?? "final-only";
4598
4598
  const voiceMaxRecordingMs = config?.voiceCompose?.maxRecordingMs;
4599
4599
  const { setContext } = useChatUserContext();
4600
+ const [draftValue, setDraftValue] = useState7(externalValue);
4600
4601
  const [uploadProgress, setUploadProgress] = useState7(/* @__PURE__ */ new Map());
4601
4602
  const [isVoiceComposerOpen, setIsVoiceComposerOpen] = useState7(
4602
4603
  () => enableAudioRecording && voiceDefaultMode === "voice"
@@ -4619,6 +4620,7 @@ var ChatInput = memo4(function ChatInput2({
4619
4620
  const voiceDraftRef = useRef5(null);
4620
4621
  const voiceAppendBaseRef = useRef5(null);
4621
4622
  const voiceAppendBaseDurationRef = useRef5(0);
4623
+ const previousExternalValueRef = useRef5(externalValue);
4622
4624
  const filteredMentionAgents = React13.useMemo(() => {
4623
4625
  if (!activeMention || mentionAgents.length === 0) return [];
4624
4626
  const query = activeMention.query.trim().toLowerCase();
@@ -4648,7 +4650,16 @@ var ChatInput = memo4(function ChatInput2({
4648
4650
  }, []);
4649
4651
  useEffect9(() => {
4650
4652
  resizeTextarea();
4651
- }, [resizeTextarea, value]);
4653
+ }, [resizeTextarea, draftValue]);
4654
+ useEffect9(() => {
4655
+ if (externalValue === previousExternalValueRef.current) return;
4656
+ previousExternalValueRef.current = externalValue;
4657
+ setDraftValue(externalValue);
4658
+ }, [externalValue]);
4659
+ const updateDraftValue = useCallback3((nextValue) => {
4660
+ setDraftValue(nextValue);
4661
+ onChange(nextValue);
4662
+ }, [onChange]);
4652
4663
  const syncMentionState = useCallback3((nextValue, nextCaret) => {
4653
4664
  const caret = typeof nextCaret === "number" ? nextCaret : textareaRef.current?.selectionStart ?? nextValue.length;
4654
4665
  const nextMatch = getActiveMentionMatch(nextValue, caret);
@@ -4683,9 +4694,9 @@ var ChatInput = memo4(function ChatInput2({
4683
4694
  const selectMentionAgent = useCallback3((agent) => {
4684
4695
  if (!activeMention) return;
4685
4696
  const replacement = `@${agent.name} `;
4686
- const nextValue = value.slice(0, activeMention.start) + replacement + value.slice(activeMention.end);
4697
+ const nextValue = draftValue.slice(0, activeMention.start) + replacement + draftValue.slice(activeMention.end);
4687
4698
  const nextCaret = activeMention.start + replacement.length;
4688
- onChange(nextValue);
4699
+ updateDraftValue(nextValue);
4689
4700
  onTargetAgentChange?.(agent.id);
4690
4701
  setActiveMention(null);
4691
4702
  setActiveMentionIndex(0);
@@ -4693,16 +4704,16 @@ var ChatInput = memo4(function ChatInput2({
4693
4704
  textareaRef.current?.focus();
4694
4705
  textareaRef.current?.setSelectionRange(nextCaret, nextCaret);
4695
4706
  });
4696
- }, [activeMention, onChange, onTargetAgentChange, value]);
4707
+ }, [activeMention, draftValue, onTargetAgentChange, updateDraftValue]);
4697
4708
  const handleSubmit = (e) => {
4698
4709
  e.preventDefault();
4699
- if (!value.trim() && attachments.length === 0 || disabled || isGenerating) return;
4700
- const mentionedAgent = resolveTargetFromMentions(value, mentionAgents);
4710
+ if (!draftValue.trim() && attachments.length === 0 || disabled || isGenerating) return;
4711
+ const mentionedAgent = resolveTargetFromMentions(draftValue, mentionAgents);
4701
4712
  if (mentionedAgent) {
4702
4713
  onTargetAgentChange?.(mentionedAgent.id);
4703
4714
  }
4704
- onSubmit(value.trim(), attachments);
4705
- onChange("");
4715
+ onSubmit(draftValue.trim(), attachments);
4716
+ updateDraftValue("");
4706
4717
  onAttachmentsChange([]);
4707
4718
  setActiveMention(null);
4708
4719
  setActiveMentionIndex(0);
@@ -5214,7 +5225,7 @@ var ChatInput = memo4(function ChatInput2({
5214
5225
  ) }) : /* @__PURE__ */ jsx25("form", { onSubmit: handleSubmit, className: "mb-1", children: /* @__PURE__ */ jsxs15(
5215
5226
  "div",
5216
5227
  {
5217
- className: `group/composer relative flex w-full flex-col gap-2 overflow-hidden rounded-3xl border border-border/80 bg-card/95 p-2.5 shadow-sm transition-[border-color,box-shadow,background-color] focus-within:border-ring/60 focus-within:bg-card focus-within:shadow-md focus-within:ring-2 focus-within:ring-ring/15 ${isDraggingFiles ? "border-primary/60 bg-primary/5 shadow-md ring-2 ring-primary/15" : ""}`,
5228
+ className: `group/composer relative flex w-full flex-col gap-2 overflow-visible rounded-3xl border border-border/80 bg-card/95 p-2.5 shadow-sm transition-[border-color,box-shadow,background-color] focus-within:border-ring/60 focus-within:bg-card focus-within:shadow-md focus-within:ring-2 focus-within:ring-ring/15 ${isDraggingFiles ? "border-primary/60 bg-primary/5 shadow-md ring-2 ring-primary/15" : ""}`,
5218
5229
  onDrop: handleDrop,
5219
5230
  onDragEnter: handleDragEnter,
5220
5231
  onDragOver: handleDragOver,
@@ -5234,9 +5245,9 @@ var ChatInput = memo4(function ChatInput2({
5234
5245
  Textarea,
5235
5246
  {
5236
5247
  ref: textareaRef,
5237
- value,
5248
+ value: draftValue,
5238
5249
  onChange: (e) => {
5239
- onChange(e.target.value);
5250
+ updateDraftValue(e.target.value);
5240
5251
  syncMentionState(e.target.value, e.target.selectionStart ?? e.target.value.length);
5241
5252
  requestAnimationFrame(resizeTextarea);
5242
5253
  },
@@ -5255,7 +5266,7 @@ var ChatInput = memo4(function ChatInput2({
5255
5266
  rows: 1
5256
5267
  }
5257
5268
  ),
5258
- isMentionMenuOpen && /* @__PURE__ */ jsx25("div", { className: "absolute bottom-full left-0 right-0 mb-2 overflow-hidden rounded-md border bg-popover shadow-md", children: /* @__PURE__ */ jsx25("div", { className: "p-1", children: filteredMentionAgents.map((agent, index) => /* @__PURE__ */ jsxs15(
5269
+ isMentionMenuOpen && /* @__PURE__ */ jsx25("div", { className: "absolute bottom-full left-0 right-0 z-30 mb-2 overflow-hidden rounded-md border bg-popover shadow-md", children: /* @__PURE__ */ jsx25("div", { className: "p-1", children: filteredMentionAgents.map((agent, index) => /* @__PURE__ */ jsxs15(
5259
5270
  "button",
5260
5271
  {
5261
5272
  type: "button",
@@ -5319,7 +5330,7 @@ var ChatInput = memo4(function ChatInput2({
5319
5330
  )
5320
5331
  ] }),
5321
5332
  /* @__PURE__ */ jsxs15("div", { className: "flex shrink-0 items-center gap-1", children: [
5322
- enableAudioRecording && canAddMoreAttachments && !value.trim() && /* @__PURE__ */ jsxs15(Tooltip, { children: [
5333
+ enableAudioRecording && canAddMoreAttachments && !draftValue.trim() && /* @__PURE__ */ jsxs15(Tooltip, { children: [
5323
5334
  /* @__PURE__ */ jsx25(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx25(
5324
5335
  Button,
5325
5336
  {
@@ -5356,7 +5367,7 @@ var ChatInput = memo4(function ChatInput2({
5356
5367
  type: "submit",
5357
5368
  size: "icon",
5358
5369
  className: "h-9 w-9 rounded-full",
5359
- disabled: disabled || !value.trim() && attachments.length === 0,
5370
+ disabled: disabled || !draftValue.trim() && attachments.length === 0,
5360
5371
  children: disabled ? /* @__PURE__ */ jsx25(Loader22, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ jsx25(Send2, { className: "h-4 w-4" })
5361
5372
  }
5362
5373
  ) }),
@@ -6618,7 +6629,7 @@ var ChatUI = ({
6618
6629
  {
6619
6630
  value: inputValue,
6620
6631
  onChange: (value) => {
6621
- setInputValue(value);
6632
+ inputValueRef.current = value;
6622
6633
  if (initialInputApplied.current && !initialInputConsumedRef.current) {
6623
6634
  initialInputConsumedRef.current = true;
6624
6635
  onInitialInputConsumed?.();