Skip to content

Commit 5357b2e

Browse files
committed
refactor(editor): update for context
1 parent 9201999 commit 5357b2e

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

editor/src/components/editor/action/command-functions.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Commands, Dispatch, Extension } from "@tiptap/react";
22
import { Editor } from "@tiptap/core";
33
import { Transaction } from "prosemirror-state";
44
import {
5+
DefinedVariable,
56
FacetType, OutputForm,
67
PromptAction,
78
} from "@/types/custom-action.type";
@@ -56,6 +57,7 @@ export const CommandFunctions = Extension.create({
5657
(action: PromptAction) =>
5758
async ({ tr, commands, editor }: { tr: Transaction; commands: Commands, editor: Editor }) => {
5859
// do execute action
60+
editor.setEditable(false)
5961
const actionExecutor = new ActionExecutor(action, editor);
6062
actionExecutor.compile();
6163
let prompt = action.compiledTemplate;
@@ -78,13 +80,16 @@ export const CommandFunctions = Extension.create({
7880
}
7981
}));
8082

83+
editor.setEditable(true);
8184
return undefined;
8285

8386
case OutputForm.TEXT:
8487
const text = await fetch("/api/completion/yiyan", {
8588
method: "POST",
8689
body: JSON.stringify({ prompt: prompt }),
8790
}).then(it => it.text());
91+
92+
editor.setEditable(true);
8893
return text;
8994

9095
default:
@@ -95,6 +100,8 @@ export const CommandFunctions = Extension.create({
95100

96101
const posInfo = actionExecutor.position(editor.state.selection);
97102
editor.chain().focus().insertContentAt(posInfo, msg).run();
103+
104+
editor.setEditable(true);
98105
return undefined;
99106
}
100107
},
@@ -111,12 +118,14 @@ export const CommandFunctions = Extension.create({
111118
callQuickAction:
112119
(text: string) =>
113120
({ editor }: { editor: Editor }) => {
121+
editor.setEditable(false);
114122
editor.commands.callLlm(<PromptAction>{
115123
name: text,
116-
template: text,
124+
template: `You are an assistant to help user write article. Here is user command:` + text + `\n Here is some content ###Article title: {{${DefinedVariable.TITLE}}}, Before Content: {{${DefinedVariable.BEFORE_CURSOR}}}###`,
117125
facetType: FacetType.QUICK_INSERT,
118126
outputForm: OutputForm.STREAMING,
119127
});
128+
editor.setEditable(true);
120129
},
121130
replaceRange:
122131
(text: string) =>

editor/src/components/editor/intelli/ai-block-view.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const AiBlockView = (props?: { editor: Editor }) => {
1515
props?.editor?.commands.enableEnter();
1616
}}
1717
go={(content: string) => {
18+
props?.editor?.commands.toggleAiBlock({});
1819
props?.editor?.commands.callQuickAction(content);
1920
}}/>
2021
</NodeViewWrapper>

editor/src/components/editor/intelli/menu/menu-bubble.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const MenuBubble = ({ editor }: {
7575
}
7676
});
7777

78-
return <BubbleMenu className={'bubble-menu-group w-64 bg-white'} editor={editor}>
78+
return <BubbleMenu className={'bubble-menu-group w-64 bg-white'} editor={editor} tippyOptions={{ duration: 100 }}>
7979
<div>
8080
<DropdownMenu.Root>
8181
<DropdownMenu.Trigger>

0 commit comments

Comments
 (0)