@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.cjs
CHANGED
|
@@ -4547,7 +4547,7 @@ var resolveVoiceErrorMessage = (error, config) => {
|
|
|
4547
4547
|
var clearVoiceTranscript = () => ({});
|
|
4548
4548
|
var resolveVoiceSegmentDuration = (segment) => segment.attachment.durationMs ?? 0;
|
|
4549
4549
|
var ChatInput = (0, import_react8.memo)(function ChatInput2({
|
|
4550
|
-
value,
|
|
4550
|
+
value: externalValue,
|
|
4551
4551
|
onChange,
|
|
4552
4552
|
onSubmit,
|
|
4553
4553
|
attachments,
|
|
@@ -4578,6 +4578,7 @@ var ChatInput = (0, import_react8.memo)(function ChatInput2({
|
|
|
4578
4578
|
const voiceTranscriptMode = config?.voiceCompose?.transcriptMode ?? "final-only";
|
|
4579
4579
|
const voiceMaxRecordingMs = config?.voiceCompose?.maxRecordingMs;
|
|
4580
4580
|
const { setContext } = useChatUserContext();
|
|
4581
|
+
const [draftValue, setDraftValue] = (0, import_react8.useState)(externalValue);
|
|
4581
4582
|
const [uploadProgress, setUploadProgress] = (0, import_react8.useState)(/* @__PURE__ */ new Map());
|
|
4582
4583
|
const [isVoiceComposerOpen, setIsVoiceComposerOpen] = (0, import_react8.useState)(
|
|
4583
4584
|
() => enableAudioRecording && voiceDefaultMode === "voice"
|
|
@@ -4600,6 +4601,7 @@ var ChatInput = (0, import_react8.memo)(function ChatInput2({
|
|
|
4600
4601
|
const voiceDraftRef = (0, import_react8.useRef)(null);
|
|
4601
4602
|
const voiceAppendBaseRef = (0, import_react8.useRef)(null);
|
|
4602
4603
|
const voiceAppendBaseDurationRef = (0, import_react8.useRef)(0);
|
|
4604
|
+
const previousExternalValueRef = (0, import_react8.useRef)(externalValue);
|
|
4603
4605
|
const filteredMentionAgents = import_react8.default.useMemo(() => {
|
|
4604
4606
|
if (!activeMention || mentionAgents.length === 0) return [];
|
|
4605
4607
|
const query = activeMention.query.trim().toLowerCase();
|
|
@@ -4629,7 +4631,16 @@ var ChatInput = (0, import_react8.memo)(function ChatInput2({
|
|
|
4629
4631
|
}, []);
|
|
4630
4632
|
(0, import_react8.useEffect)(() => {
|
|
4631
4633
|
resizeTextarea();
|
|
4632
|
-
}, [resizeTextarea,
|
|
4634
|
+
}, [resizeTextarea, draftValue]);
|
|
4635
|
+
(0, import_react8.useEffect)(() => {
|
|
4636
|
+
if (externalValue === previousExternalValueRef.current) return;
|
|
4637
|
+
previousExternalValueRef.current = externalValue;
|
|
4638
|
+
setDraftValue(externalValue);
|
|
4639
|
+
}, [externalValue]);
|
|
4640
|
+
const updateDraftValue = (0, import_react8.useCallback)((nextValue) => {
|
|
4641
|
+
setDraftValue(nextValue);
|
|
4642
|
+
onChange(nextValue);
|
|
4643
|
+
}, [onChange]);
|
|
4633
4644
|
const syncMentionState = (0, import_react8.useCallback)((nextValue, nextCaret) => {
|
|
4634
4645
|
const caret = typeof nextCaret === "number" ? nextCaret : textareaRef.current?.selectionStart ?? nextValue.length;
|
|
4635
4646
|
const nextMatch = getActiveMentionMatch(nextValue, caret);
|
|
@@ -4664,9 +4675,9 @@ var ChatInput = (0, import_react8.memo)(function ChatInput2({
|
|
|
4664
4675
|
const selectMentionAgent = (0, import_react8.useCallback)((agent) => {
|
|
4665
4676
|
if (!activeMention) return;
|
|
4666
4677
|
const replacement = `@${agent.name} `;
|
|
4667
|
-
const nextValue =
|
|
4678
|
+
const nextValue = draftValue.slice(0, activeMention.start) + replacement + draftValue.slice(activeMention.end);
|
|
4668
4679
|
const nextCaret = activeMention.start + replacement.length;
|
|
4669
|
-
|
|
4680
|
+
updateDraftValue(nextValue);
|
|
4670
4681
|
onTargetAgentChange?.(agent.id);
|
|
4671
4682
|
setActiveMention(null);
|
|
4672
4683
|
setActiveMentionIndex(0);
|
|
@@ -4674,16 +4685,16 @@ var ChatInput = (0, import_react8.memo)(function ChatInput2({
|
|
|
4674
4685
|
textareaRef.current?.focus();
|
|
4675
4686
|
textareaRef.current?.setSelectionRange(nextCaret, nextCaret);
|
|
4676
4687
|
});
|
|
4677
|
-
}, [activeMention,
|
|
4688
|
+
}, [activeMention, draftValue, onTargetAgentChange, updateDraftValue]);
|
|
4678
4689
|
const handleSubmit = (e) => {
|
|
4679
4690
|
e.preventDefault();
|
|
4680
|
-
if (!
|
|
4681
|
-
const mentionedAgent = resolveTargetFromMentions(
|
|
4691
|
+
if (!draftValue.trim() && attachments.length === 0 || disabled || isGenerating) return;
|
|
4692
|
+
const mentionedAgent = resolveTargetFromMentions(draftValue, mentionAgents);
|
|
4682
4693
|
if (mentionedAgent) {
|
|
4683
4694
|
onTargetAgentChange?.(mentionedAgent.id);
|
|
4684
4695
|
}
|
|
4685
|
-
onSubmit(
|
|
4686
|
-
|
|
4696
|
+
onSubmit(draftValue.trim(), attachments);
|
|
4697
|
+
updateDraftValue("");
|
|
4687
4698
|
onAttachmentsChange([]);
|
|
4688
4699
|
setActiveMention(null);
|
|
4689
4700
|
setActiveMentionIndex(0);
|
|
@@ -5215,9 +5226,9 @@ var ChatInput = (0, import_react8.memo)(function ChatInput2({
|
|
|
5215
5226
|
Textarea,
|
|
5216
5227
|
{
|
|
5217
5228
|
ref: textareaRef,
|
|
5218
|
-
value,
|
|
5229
|
+
value: draftValue,
|
|
5219
5230
|
onChange: (e) => {
|
|
5220
|
-
|
|
5231
|
+
updateDraftValue(e.target.value);
|
|
5221
5232
|
syncMentionState(e.target.value, e.target.selectionStart ?? e.target.value.length);
|
|
5222
5233
|
requestAnimationFrame(resizeTextarea);
|
|
5223
5234
|
},
|
|
@@ -5300,7 +5311,7 @@ var ChatInput = (0, import_react8.memo)(function ChatInput2({
|
|
|
5300
5311
|
)
|
|
5301
5312
|
] }),
|
|
5302
5313
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsxs)("div", { className: "flex shrink-0 items-center gap-1", children: [
|
|
5303
|
-
enableAudioRecording && canAddMoreAttachments && !
|
|
5314
|
+
enableAudioRecording && canAddMoreAttachments && !draftValue.trim() && /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(Tooltip, { children: [
|
|
5304
5315
|
/* @__PURE__ */ (0, import_jsx_runtime25.jsx)(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(
|
|
5305
5316
|
Button,
|
|
5306
5317
|
{
|
|
@@ -5337,7 +5348,7 @@ var ChatInput = (0, import_react8.memo)(function ChatInput2({
|
|
|
5337
5348
|
type: "submit",
|
|
5338
5349
|
size: "icon",
|
|
5339
5350
|
className: "h-9 w-9 rounded-full",
|
|
5340
|
-
disabled: disabled || !
|
|
5351
|
+
disabled: disabled || !draftValue.trim() && attachments.length === 0,
|
|
5341
5352
|
children: disabled ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_lucide_react12.Loader2, { className: "h-4 w-4 animate-spin" }) : /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_lucide_react12.Send, { className: "h-4 w-4" })
|
|
5342
5353
|
}
|
|
5343
5354
|
) }),
|
|
@@ -6566,7 +6577,7 @@ var ChatUI = ({
|
|
|
6566
6577
|
{
|
|
6567
6578
|
value: inputValue,
|
|
6568
6579
|
onChange: (value) => {
|
|
6569
|
-
|
|
6580
|
+
inputValueRef.current = value;
|
|
6570
6581
|
if (initialInputApplied.current && !initialInputConsumedRef.current) {
|
|
6571
6582
|
initialInputConsumedRef.current = true;
|
|
6572
6583
|
onInitialInputConsumed?.();
|