From 6089f632a712236debb1af81146f2e359866e77d Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 24 Nov 2023 16:15:58 +0800 Subject: [PATCH] gst --- .../editor/action/command-functions.jsx | 21 ------------- .../editor/action/command-functions.tsx | 31 +++++++++++++++++++ 2 files changed, 31 insertions(+), 21 deletions(-) delete mode 100644 src/components/editor/action/command-functions.jsx create mode 100644 src/components/editor/action/command-functions.tsx diff --git a/src/components/editor/action/command-functions.jsx b/src/components/editor/action/command-functions.jsx deleted file mode 100644 index 5b19a7e..0000000 --- a/src/components/editor/action/command-functions.jsx +++ /dev/null @@ -1,21 +0,0 @@ -import { Extension } from '@tiptap/react' - -export const CommandFunctions = Extension.create({ - addCommands: () => { - return { - // for examples: $selection, $beforeCursor - variable: (variableName, variableValue) => ({ tr, commands }) => { - console.log('variable', variableName, variableValue) - }, - getSelectedText: () => ({ editor }) => { - if (!editor.state) return null - - const { from, to, empty } = editor.state.selection - - if (empty) return null - - return editor.state.doc.textBetween(from, to, ' ') - }, - } - }, -}) \ No newline at end of file diff --git a/src/components/editor/action/command-functions.tsx b/src/components/editor/action/command-functions.tsx new file mode 100644 index 0000000..c1ce217 --- /dev/null +++ b/src/components/editor/action/command-functions.tsx @@ -0,0 +1,31 @@ +import { Commands, Extension } from '@tiptap/react' +import { Editor } from "@tiptap/core"; +import { Transaction } from "prosemirror-state"; +import { PromptAction } from "@/types/custom-action.type"; + +export const CommandFunctions = Extension.create({ + name: 'commandFunctions', + // @ts-ignore + addCommands: () => { + return { + // for examples: $selection, $beforeCursor + variable: (variableName: string, variableValue: string) => () => { + console.log('variable', variableName, variableValue) + }, + getSelectedText: () => ({ editor }: { editor: Editor }) => { + if (!editor.state) return null + + const { from, to, empty } = editor.state.selection + + if (empty) return null + + return editor.state.doc.textBetween(from, to, ' ') + }, + callLlm: (action: PromptAction) => ({ tr, commands }: { tr: Transaction, commands: Commands }) => { + // TODO: @phodal convert action to request + // TODO: @genffy add LLM request type + // do execute action + } + } + }, +}) \ No newline at end of file