Skip to content

Commit e27b701

Browse files
committed
feat: [AIChatInput] The newly added keepSkillAfterSend API allows users to set whether to delete the skill upon sending
1 parent a4f3201 commit e27b701

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

packages/semi-ui/aiChatInput/_story/aiChatInput.stories.jsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,3 +575,37 @@ export const CustomRichTextExtension = () => {
575575
</>
576576
);
577577
}
578+
579+
export const KeepSkill = () => {
580+
const ref = useRef();
581+
const [generating, setGenerating] = useState(false);
582+
583+
const onContentChange = useCallback((content) => {
584+
console.log('onContentChange', content);
585+
}, []);
586+
587+
const toggleGenerate = useCallback((props) => {
588+
setGenerating(value => !value);
589+
}, []);
590+
591+
return (<>
592+
<AIChatInput
593+
ref={ref}
594+
generating={generating}
595+
keepSkillAfterSend
596+
defaultContent={`<skill-slot data-label="帮我写作" data-value="writing" data-template=true></skill-slot>帮我完成...`}
597+
placeholder={'输入内容或者上传内容'}
598+
uploadProps={uploadProps}
599+
onContentChange={onContentChange}
600+
onMessageSend={toggleGenerate}
601+
onStopGenerate={toggleGenerate}
602+
style={outerStyle}
603+
/>
604+
<Button onClick={() => {
605+
const html = ref.current.editor.getHTML();
606+
const json = ref.current.editor.getJSON();
607+
console.log('html', html);
608+
console.log('json', json);
609+
}}>点击获取</Button>
610+
</>);
611+
}

packages/semi-ui/aiChatInput/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class AIChatInput extends BaseComponent<AIChatInputProps, AIChatInputState> {
5454
dropdownMatchTriggerWidth: true,
5555
round: true,
5656
topSlotPosition: 'top',
57+
keepSkillAfterSend: false,
5758
}
5859

5960
constructor(props: AIChatInputProps) {
@@ -203,14 +204,14 @@ class AIChatInput extends BaseComponent<AIChatInputProps, AIChatInputState> {
203204
}
204205

205206
componentDidUpdate(prevProps: Readonly<AIChatInputProps>): void {
206-
const { suggestions } = this.props;
207+
const { suggestions, keepSkillAfterSend } = this.props;
207208
if (!isEqual(suggestions, prevProps.suggestions)) {
208209
const newVisible = (suggestions && suggestions.length > 0) ? true : false;
209210
newVisible ? this.foundation.showSuggestionPanel() :
210211
this.foundation.hideSuggestionPanel();
211212
}
212213
if (this.props.generating && (this.props.generating !== prevProps.generating)) {
213-
this.adapter.clearContent();
214+
keepSkillAfterSend ? this.setContentWhileSaveTool('') : this.adapter.clearContent();
214215
this.adapter.clearAttachments();
215216
}
216217
}

packages/semi-ui/aiChatInput/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface AIChatInputState {
2323

2424
export interface AIChatInputProps {
2525
dropdownMatchTriggerWidth?: boolean;
26+
keepSkillAfterSend: boolean;
2627
className?: string;
2728
style?: React.CSSProperties;
2829
// Rich text editor related

0 commit comments

Comments
 (0)