Skip to content

Commit 3787d30

Browse files
authored
feat: [AIChatInput] The newly added keepSkillAfterSend API allows users to set whether to delete the skill upon sending (#3046)
1 parent b41fc36 commit 3787d30

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
@@ -679,3 +679,37 @@ export const SetContent = () => {
679679
>点我查看富文本区域内容</Button>
680680
</>);
681681
}
682+
683+
export const KeepSkill = () => {
684+
const ref = useRef();
685+
const [generating, setGenerating] = useState(false);
686+
687+
const onContentChange = useCallback((content) => {
688+
console.log('onContentChange', content);
689+
}, []);
690+
691+
const toggleGenerate = useCallback((props) => {
692+
setGenerating(value => !value);
693+
}, []);
694+
695+
return (<>
696+
<AIChatInput
697+
ref={ref}
698+
generating={generating}
699+
keepSkillAfterSend
700+
defaultContent={`<skill-slot data-label="帮我写作" data-value="writing" data-template=true></skill-slot>帮我完成...`}
701+
placeholder={'输入内容或者上传内容'}
702+
uploadProps={uploadProps}
703+
onContentChange={onContentChange}
704+
onMessageSend={toggleGenerate}
705+
onStopGenerate={toggleGenerate}
706+
style={outerStyle}
707+
/>
708+
<Button onClick={() => {
709+
const html = ref.current.editor.getHTML();
710+
const json = ref.current.editor.getJSON();
711+
console.log('html', html);
712+
console.log('json', json);
713+
}}>点击获取</Button>
714+
</>);
715+
}

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)