@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.
@@ -478,7 +478,9 @@ var ChatInputArea = (0, import_react5.forwardRef)(({
478
478
  placeholder,
479
479
  value,
480
480
  onChange,
481
- defaultInputMode = "text"
481
+ defaultInputMode = "text",
482
+ hideVoiceButton = false,
483
+ inputMode: inputModeProp
482
484
  }, ref) => {
483
485
  var _a, _b, _c, _d;
484
486
  const [internalMessage, setInternalMessage] = (0, import_react5.useState)("");
@@ -528,6 +530,7 @@ var ChatInputArea = (0, import_react5.forwardRef)(({
528
530
  const textareaRef = (0, import_react5.useRef)(null);
529
531
  const measurementRef = (0, import_react5.useRef)(null);
530
532
  const pendingSelectionRef = (0, import_react5.useRef)(null);
533
+ const lastSelectionRef = (0, import_react5.useRef)(null);
531
534
  const isControlled = value !== void 0;
532
535
  const message = isControlled ? value : internalMessage;
533
536
  const messageRef = (0, import_react5.useRef)(message);
@@ -622,11 +625,39 @@ var ChatInputArea = (0, import_react5.forwardRef)(({
622
625
  });
623
626
  (0, import_react5.useImperativeHandle)(ref, () => ({
624
627
  focus: () => {
625
- var _a2;
626
- (_a2 = textareaRef.current) == null ? void 0 : _a2.focus();
628
+ const textarea = textareaRef.current;
629
+ if (textarea) {
630
+ textarea.focus();
631
+ if (lastSelectionRef.current) {
632
+ textarea.setSelectionRange(
633
+ lastSelectionRef.current.start,
634
+ lastSelectionRef.current.end
635
+ );
636
+ }
637
+ }
627
638
  },
628
639
  setValue: (newValue) => {
629
640
  triggerChange(newValue);
641
+ },
642
+ getSelection: () => {
643
+ const textarea = textareaRef.current;
644
+ if (textarea && document.activeElement === textarea) {
645
+ return { start: textarea.selectionStart, end: textarea.selectionEnd };
646
+ }
647
+ return lastSelectionRef.current;
648
+ },
649
+ replaceSelection: (text) => {
650
+ const selection = lastSelectionRef.current;
651
+ const currentVal = messageRef.current || "";
652
+ if (selection && selection.start !== selection.end) {
653
+ const before = currentVal.substring(0, selection.start);
654
+ const after = currentVal.substring(selection.end);
655
+ const newText = before + text + after;
656
+ triggerChange(newText);
657
+ lastSelectionRef.current = null;
658
+ } else {
659
+ insertTextAtCursor(text);
660
+ }
630
661
  }
631
662
  }));
632
663
  const handleSubmit = (e) => {
@@ -715,7 +746,7 @@ var ChatInputArea = (0, import_react5.forwardRef)(({
715
746
  logs.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { children: "No logs yet..." })
716
747
  ] }),
717
748
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-2", children: [
718
- voiceConfig && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
749
+ voiceConfig && !hideVoiceButton && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
719
750
  VoiceInputButton,
720
751
  {
721
752
  voiceConfig,
@@ -760,12 +791,22 @@ var ChatInputArea = (0, import_react5.forwardRef)(({
760
791
  setIsFocused(true);
761
792
  setVoiceError(null);
762
793
  },
763
- onBlur: () => setIsFocused(false),
794
+ onBlur: () => {
795
+ setIsFocused(false);
796
+ const textarea = textareaRef.current;
797
+ if (textarea) {
798
+ lastSelectionRef.current = {
799
+ start: textarea.selectionStart,
800
+ end: textarea.selectionEnd
801
+ };
802
+ }
803
+ },
764
804
  placeholder: getPlaceholder(),
765
805
  disabled: isInputDisabled,
766
806
  readOnly: !!voiceTrigger || isTranscribing,
767
807
  rows: 1,
768
- 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" : ""}`
808
+ 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" : ""}`,
809
+ ...inputModeProp ? { inputMode: inputModeProp } : {}
769
810
  }
770
811
  ),
771
812
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "relative mx-2 flex-shrink-0", children: [