@contentgrowth/llm-service 1.0.8 → 1.1.0

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,40 @@ 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
+ pendingSelectionRef.current = { start: selection.start, end: selection.start + text.length };
657
+ triggerChange(newText);
658
+ lastSelectionRef.current = null;
659
+ } else {
660
+ insertTextAtCursor(text);
661
+ }
630
662
  }
631
663
  }));
632
664
  const handleSubmit = (e) => {
@@ -715,7 +747,7 @@ var ChatInputArea = (0, import_react5.forwardRef)(({
715
747
  logs.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { children: "No logs yet..." })
716
748
  ] }),
717
749
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "flex items-center gap-2", children: [
718
- voiceConfig && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
750
+ voiceConfig && !hideVoiceButton && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
719
751
  VoiceInputButton,
720
752
  {
721
753
  voiceConfig,
@@ -760,12 +792,22 @@ var ChatInputArea = (0, import_react5.forwardRef)(({
760
792
  setIsFocused(true);
761
793
  setVoiceError(null);
762
794
  },
763
- onBlur: () => setIsFocused(false),
795
+ onBlur: () => {
796
+ setIsFocused(false);
797
+ const textarea = textareaRef.current;
798
+ if (textarea) {
799
+ lastSelectionRef.current = {
800
+ start: textarea.selectionStart,
801
+ end: textarea.selectionEnd
802
+ };
803
+ }
804
+ },
764
805
  placeholder: getPlaceholder(),
765
806
  disabled: isInputDisabled,
766
807
  readOnly: !!voiceTrigger || isTranscribing,
767
808
  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" : ""}`
809
+ 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" : ""}`,
810
+ ...inputModeProp ? { inputMode: inputModeProp } : {}
769
811
  }
770
812
  ),
771
813
  /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "relative mx-2 flex-shrink-0", children: [