mirror of https://github.com/buster-so/buster.git
stabilize pass up props
This commit is contained in:
parent
14ad0f5729
commit
ec63a347c6
|
@ -4,6 +4,7 @@ import { Button } from '@/components/ui/buttons';
|
||||||
import { ArrowUp, Magnifier, Sparkle2 } from '@/components/ui/icons';
|
import { ArrowUp, Magnifier, Sparkle2 } from '@/components/ui/icons';
|
||||||
import Atom from '@/components/ui/icons/NucleoIconOutlined/atom';
|
import Atom from '@/components/ui/icons/NucleoIconOutlined/atom';
|
||||||
import Microphone from '@/components/ui/icons/NucleoIconOutlined/microphone';
|
import Microphone from '@/components/ui/icons/NucleoIconOutlined/microphone';
|
||||||
|
import type { MentionOnChangeFn } from '@/components/ui/inputs/MentionInput';
|
||||||
import {
|
import {
|
||||||
useMentionInputHasValue,
|
useMentionInputHasValue,
|
||||||
useMentionInputSuggestionsGetValue,
|
useMentionInputSuggestionsGetValue,
|
||||||
|
@ -18,7 +19,7 @@ import { cn } from '@/lib/utils';
|
||||||
export type BusterChatInputMode = 'auto' | 'research' | 'deep-research';
|
export type BusterChatInputMode = 'auto' | 'research' | 'deep-research';
|
||||||
|
|
||||||
type BusterChatInputButtons = {
|
type BusterChatInputButtons = {
|
||||||
onSubmit: (value: string) => void;
|
onSubmit: MentionOnChangeFn;
|
||||||
onStop: () => void;
|
onStop: () => void;
|
||||||
submitting: boolean;
|
submitting: boolean;
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
|
@ -99,7 +100,12 @@ export const BusterChatInputButtons = React.memo(
|
||||||
submitting
|
submitting
|
||||||
? onStop
|
? onStop
|
||||||
: () => {
|
: () => {
|
||||||
onSubmit(getValue?.());
|
const value = getValue?.();
|
||||||
|
if (!value) {
|
||||||
|
console.warn('Value is not defined');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onSubmit(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loading={submitting}
|
loading={submitting}
|
||||||
|
|
|
@ -131,6 +131,8 @@ export const useShortcutsSuggestions = (
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
setOpenCreateShortcutModal(true);
|
setOpenCreateShortcutModal(true);
|
||||||
},
|
},
|
||||||
|
closeOnSelect: false,
|
||||||
|
addValueToInput: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -81,7 +81,15 @@ export type MentionArrayItem =
|
||||||
attrs: MentionPillAttributes;
|
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;
|
transformedValue: string;
|
||||||
arrayValue: MentionArrayItem[];
|
arrayValue: MentionArrayItem[];
|
||||||
editorText: string;
|
editorText: string;
|
||||||
|
@ -89,8 +97,8 @@ export type MentionOnChangeParams = (d: {
|
||||||
|
|
||||||
export type MentionInputProps = {
|
export type MentionInputProps = {
|
||||||
mentions: MentionSuggestionExtension[];
|
mentions: MentionSuggestionExtension[];
|
||||||
onChange: MentionOnChangeParams;
|
onChange: MentionOnChangeFn;
|
||||||
onPressEnter?: MentionOnChangeParams;
|
onPressEnter?: MentionOnChangeFn;
|
||||||
onFocus?: (v: EditorEvents['focus']) => void;
|
onFocus?: (v: EditorEvents['focus']) => void;
|
||||||
onBlur?: (v: EditorEvents['blur']) => void;
|
onBlur?: (v: EditorEvents['blur']) => void;
|
||||||
defaultValue?: string;
|
defaultValue?: string;
|
||||||
|
@ -107,7 +115,7 @@ export type MentionInputProps = {
|
||||||
export type MentionInputRef = {
|
export type MentionInputRef = {
|
||||||
editor: Editor | null;
|
editor: Editor | null;
|
||||||
addMentionToInput: (mention: MentionPillAttributes) => void;
|
addMentionToInput: (mention: MentionPillAttributes) => void;
|
||||||
getValue: MentionOnChangeParams;
|
getValue: GetMentionOnChange;
|
||||||
};
|
};
|
||||||
|
|
||||||
declare module '@tiptap/core' {
|
declare module '@tiptap/core' {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import type { Editor, NodeType, TextType } from '@tiptap/react';
|
import type { Editor, NodeType, TextType } from '@tiptap/react';
|
||||||
import type {
|
import type {
|
||||||
|
GetMentionOnChange,
|
||||||
MentionArrayItem,
|
MentionArrayItem,
|
||||||
MentionOnChangeParams,
|
MentionOnChange,
|
||||||
MentionSuggestionExtension,
|
MentionSuggestionExtension,
|
||||||
} from './MentionInput.types';
|
} from './MentionInput.types';
|
||||||
import type { MentionPillAttributes } from './MentionPill';
|
import type { MentionPillAttributes } from './MentionPill';
|
||||||
|
@ -12,7 +13,7 @@ export const onUpdateTransformer = ({
|
||||||
}: {
|
}: {
|
||||||
editor: Editor;
|
editor: Editor;
|
||||||
mentionsByTrigger: Record<string, MentionSuggestionExtension>;
|
mentionsByTrigger: Record<string, MentionSuggestionExtension>;
|
||||||
}) => {
|
}): MentionOnChange => {
|
||||||
const editorText = editor.getText();
|
const editorText = editor.getText();
|
||||||
const editorJson = editor.getJSON();
|
const editorJson = editor.getJSON();
|
||||||
const arrayValue: MentionArrayItem[] = editorJson.content.reduce<MentionArrayItem[]>(
|
const arrayValue: MentionArrayItem[] = editorJson.content.reduce<MentionArrayItem[]>(
|
||||||
|
@ -48,5 +49,5 @@ export const onUpdateTransformer = ({
|
||||||
transformedValue,
|
transformedValue,
|
||||||
arrayValue,
|
arrayValue,
|
||||||
editorText,
|
editorText,
|
||||||
} satisfies Parameters<MentionOnChangeParams>[0];
|
} satisfies MentionOnChange;
|
||||||
};
|
};
|
||||||
|
|
|
@ -106,7 +106,7 @@ export const MentionInputSuggestions = forwardRef<
|
||||||
setValue(stringValue);
|
setValue(stringValue);
|
||||||
}
|
}
|
||||||
onClick?.();
|
onClick?.();
|
||||||
if (closeSuggestionOnSelect) setHasClickedSelect(true);
|
if (closeSuggestionOnSelect && params.closeOnSelect !== false) setHasClickedSelect(true);
|
||||||
onSuggestionItemClick?.(params);
|
onSuggestionItemClick?.(params);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue