@copilotz/chat-ui 0.9.17 → 0.9.19
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 +25 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -14
- package/dist/index.js.map +1 -1
- package/dist/styles.css +42 -69
- package/package.json +1 -1
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,
|
|
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 =
|
|
4697
|
+
const nextValue = draftValue.slice(0, activeMention.start) + replacement + draftValue.slice(activeMention.end);
|
|
4687
4698
|
const nextCaret = activeMention.start + replacement.length;
|
|
4688
|
-
|
|
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,
|
|
4707
|
+
}, [activeMention, draftValue, onTargetAgentChange, updateDraftValue]);
|
|
4697
4708
|
const handleSubmit = (e) => {
|
|
4698
4709
|
e.preventDefault();
|
|
4699
|
-
if (!
|
|
4700
|
-
const mentionedAgent = resolveTargetFromMentions(
|
|
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(
|
|
4705
|
-
|
|
4715
|
+
onSubmit(draftValue.trim(), attachments);
|
|
4716
|
+
updateDraftValue("");
|
|
4706
4717
|
onAttachmentsChange([]);
|
|
4707
4718
|
setActiveMention(null);
|
|
4708
4719
|
setActiveMentionIndex(0);
|
|
@@ -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
|
-
|
|
5250
|
+
updateDraftValue(e.target.value);
|
|
5240
5251
|
syncMentionState(e.target.value, e.target.selectionStart ?? e.target.value.length);
|
|
5241
5252
|
requestAnimationFrame(resizeTextarea);
|
|
5242
5253
|
},
|
|
@@ -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 && !
|
|
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 || !
|
|
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
|
-
|
|
6632
|
+
inputValueRef.current = value;
|
|
6622
6633
|
if (initialInputApplied.current && !initialInputConsumedRef.current) {
|
|
6623
6634
|
initialInputConsumedRef.current = true;
|
|
6624
6635
|
onInitialInputConsumed?.();
|