stabilize pass up props

This commit is contained in:
Nate Kelley 2025-09-29 21:13:09 -06:00
parent 14ad0f5729
commit ec63a347c6
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
5 changed files with 27 additions and 10 deletions

View File

@ -4,6 +4,7 @@ import { Button } from '@/components/ui/buttons';
import { ArrowUp, Magnifier, Sparkle2 } from '@/components/ui/icons';
import Atom from '@/components/ui/icons/NucleoIconOutlined/atom';
import Microphone from '@/components/ui/icons/NucleoIconOutlined/microphone';
import type { MentionOnChangeFn } from '@/components/ui/inputs/MentionInput';
import {
useMentionInputHasValue,
useMentionInputSuggestionsGetValue,
@ -18,7 +19,7 @@ import { cn } from '@/lib/utils';
export type BusterChatInputMode = 'auto' | 'research' | 'deep-research';
type BusterChatInputButtons = {
onSubmit: (value: string) => void;
onSubmit: MentionOnChangeFn;
onStop: () => void;
submitting: boolean;
disabled: boolean;
@ -99,7 +100,12 @@ export const BusterChatInputButtons = React.memo(
submitting
? onStop
: () => {
onSubmit(getValue?.());
const value = getValue?.();
if (!value) {
console.warn('Value is not defined');
return;
}
onSubmit(value);
}
}
loading={submitting}

View File

@ -131,6 +131,8 @@ export const useShortcutsSuggestions = (
onClick: () => {
setOpenCreateShortcutModal(true);
},
closeOnSelect: false,
addValueToInput: false,
});
return [

View File

@ -81,7 +81,15 @@ export type MentionArrayItem =
attrs: MentionPillAttributes;
};
export type MentionOnChangeParams = (d: {
export type MentionOnChange = {
transformedValue: string;
arrayValue: MentionArrayItem[];
editorText: string;
};
export type GetMentionOnChange = () => MentionOnChange;
export type MentionOnChangeFn = (d: {
transformedValue: string;
arrayValue: MentionArrayItem[];
editorText: string;
@ -89,8 +97,8 @@ export type MentionOnChangeParams = (d: {
export type MentionInputProps = {
mentions: MentionSuggestionExtension[];
onChange: MentionOnChangeParams;
onPressEnter?: MentionOnChangeParams;
onChange: MentionOnChangeFn;
onPressEnter?: MentionOnChangeFn;
onFocus?: (v: EditorEvents['focus']) => void;
onBlur?: (v: EditorEvents['blur']) => void;
defaultValue?: string;
@ -107,7 +115,7 @@ export type MentionInputProps = {
export type MentionInputRef = {
editor: Editor | null;
addMentionToInput: (mention: MentionPillAttributes) => void;
getValue: MentionOnChangeParams;
getValue: GetMentionOnChange;
};
declare module '@tiptap/core' {

View File

@ -1,7 +1,8 @@
import type { Editor, NodeType, TextType } from '@tiptap/react';
import type {
GetMentionOnChange,
MentionArrayItem,
MentionOnChangeParams,
MentionOnChange,
MentionSuggestionExtension,
} from './MentionInput.types';
import type { MentionPillAttributes } from './MentionPill';
@ -12,7 +13,7 @@ export const onUpdateTransformer = ({
}: {
editor: Editor;
mentionsByTrigger: Record<string, MentionSuggestionExtension>;
}) => {
}): MentionOnChange => {
const editorText = editor.getText();
const editorJson = editor.getJSON();
const arrayValue: MentionArrayItem[] = editorJson.content.reduce<MentionArrayItem[]>(
@ -48,5 +49,5 @@ export const onUpdateTransformer = ({
transformedValue,
arrayValue,
editorText,
} satisfies Parameters<MentionOnChangeParams>[0];
} satisfies MentionOnChange;
};

View File

@ -106,7 +106,7 @@ export const MentionInputSuggestions = forwardRef<
setValue(stringValue);
}
onClick?.();
if (closeSuggestionOnSelect) setHasClickedSelect(true);
if (closeSuggestionOnSelect && params.closeOnSelect !== false) setHasClickedSelect(true);
onSuggestionItemClick?.(params);
}
);