@contentgrowth/llm-service 1.0.8 → 1.0.9

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.
@@ -177,10 +177,17 @@ interface ChatInputAreaProps {
177
177
  value?: string;
178
178
  onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
179
179
  defaultInputMode?: 'text' | 'voice';
180
+ hideVoiceButton?: boolean;
181
+ inputMode?: 'none' | 'text' | 'search' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal';
180
182
  }
181
183
  interface ChatInputAreaHandle {
182
184
  focus: () => void;
183
185
  setValue: (value: string) => void;
186
+ getSelection: () => {
187
+ start: number;
188
+ end: number;
189
+ } | null;
190
+ replaceSelection: (text: string) => void;
184
191
  }
185
192
  declare const ChatInputArea: React.ForwardRefExoticComponent<ChatInputAreaProps & React.RefAttributes<ChatInputAreaHandle>>;
186
193
 
@@ -177,10 +177,17 @@ interface ChatInputAreaProps {
177
177
  value?: string;
178
178
  onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
179
179
  defaultInputMode?: 'text' | 'voice';
180
+ hideVoiceButton?: boolean;
181
+ inputMode?: 'none' | 'text' | 'search' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal';
180
182
  }
181
183
  interface ChatInputAreaHandle {
182
184
  focus: () => void;
183
185
  setValue: (value: string) => void;
186
+ getSelection: () => {
187
+ start: number;
188
+ end: number;
189
+ } | null;
190
+ replaceSelection: (text: string) => void;
184
191
  }
185
192
  declare const ChatInputArea: React.ForwardRefExoticComponent<ChatInputAreaProps & React.RefAttributes<ChatInputAreaHandle>>;
186
193
 
@@ -437,7 +437,9 @@ var ChatInputArea = forwardRef(({
437
437
  placeholder,
438
438
  value,
439
439
  onChange,
440
- defaultInputMode = "text"
440
+ defaultInputMode = "text",
441
+ hideVoiceButton = false,
442
+ inputMode: inputModeProp
441
443
  }, ref) => {
442
444
  var _a, _b, _c, _d;
443
445
  const [internalMessage, setInternalMessage] = useState3("");
@@ -487,6 +489,7 @@ var ChatInputArea = forwardRef(({
487
489
  const textareaRef = useRef3(null);
488
490
  const measurementRef = useRef3(null);
489
491
  const pendingSelectionRef = useRef3(null);
492
+ const lastSelectionRef = useRef3(null);
490
493
  const isControlled = value !== void 0;
491
494
  const message = isControlled ? value : internalMessage;
492
495
  const messageRef = useRef3(message);
@@ -581,11 +584,39 @@ var ChatInputArea = forwardRef(({
581
584
  });
582
585
  useImperativeHandle(ref, () => ({
583
586
  focus: () => {
584
- var _a2;
585
- (_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
587
+ const textarea = textareaRef.current;
588
+ if (textarea) {
589
+ textarea.focus();
590
+ if (lastSelectionRef.current) {
591
+ textarea.setSelectionRange(
592
+ lastSelectionRef.current.start,
593
+ lastSelectionRef.current.end
594
+ );
595
+ }
596
+ }
586
597
  },
587
598
  setValue: (newValue) => {
588
599
  triggerChange(newValue);
600
+ },
601
+ getSelection: () => {
602
+ const textarea = textareaRef.current;
603
+ if (textarea && document.activeElement === textarea) {
604
+ return { start: textarea.selectionStart, end: textarea.selectionEnd };
605
+ }
606
+ return lastSelectionRef.current;
607
+ },
608
+ replaceSelection: (text) => {
609
+ const selection = lastSelectionRef.current;
610
+ const currentVal = messageRef.current || "";
611
+ if (selection && selection.start !== selection.end) {
612
+ const before = currentVal.substring(0, selection.start);
613
+ const after = currentVal.substring(selection.end);
614
+ const newText = before + text + after;
615
+ triggerChange(newText);
616
+ lastSelectionRef.current = null;
617
+ } else {
618
+ insertTextAtCursor(text);
619
+ }
589
620
  }
590
621
  }));
591
622
  const handleSubmit = (e) => {
@@ -674,7 +705,7 @@ var ChatInputArea = forwardRef(({
674
705
  logs.length === 0 && /* @__PURE__ */ jsx6("div", { children: "No logs yet..." })
675
706
  ] }),
676
707
  /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2", children: [
677
- voiceConfig && /* @__PURE__ */ jsx6(
708
+ voiceConfig && !hideVoiceButton && /* @__PURE__ */ jsx6(
678
709
  VoiceInputButton,
679
710
  {
680
711
  voiceConfig,
@@ -719,12 +750,22 @@ var ChatInputArea = forwardRef(({
719
750
  setIsFocused(true);
720
751
  setVoiceError(null);
721
752
  },
722
- onBlur: () => setIsFocused(false),
753
+ onBlur: () => {
754
+ setIsFocused(false);
755
+ const textarea = textareaRef.current;
756
+ if (textarea) {
757
+ lastSelectionRef.current = {
758
+ start: textarea.selectionStart,
759
+ end: textarea.selectionEnd
760
+ };
761
+ }
762
+ },
723
763
  placeholder: getPlaceholder(),
724
764
  disabled: isInputDisabled,
725
765
  readOnly: !!voiceTrigger || isTranscribing,
726
766
  rows: 1,
727
- className: `flex-grow px-4 py-2 outline-none text-gray-700 placeholder-gray-500 resize-none leading-6 w-full ${isInputDisabled ? "bg-gray-100 cursor-not-allowed" : "bg-transparent"} ${voiceTrigger || isTranscribing ? "cursor-default" : ""}`
767
+ className: `flex-grow px-4 py-2 outline-none text-gray-700 placeholder-gray-500 resize-none leading-6 w-full ${isInputDisabled ? "bg-gray-100 cursor-not-allowed" : "bg-transparent"} ${voiceTrigger || isTranscribing ? "cursor-default" : ""}`,
768
+ ...inputModeProp ? { inputMode: inputModeProp } : {}
728
769
  }
729
770
  ),
730
771
  /* @__PURE__ */ jsxs4("div", { className: "relative mx-2 flex-shrink-0", children: [