diff --git a/editor/src/components/editor/action/command-functions.ts b/editor/src/components/editor/action/command-functions.ts index e367824..b750b5d 100644 --- a/editor/src/components/editor/action/command-functions.ts +++ b/editor/src/components/editor/action/command-functions.ts @@ -40,12 +40,11 @@ declare module "@tiptap/core" { } } +let articleType = ARTICLE_TYPE_OPTIONS[0]; + export const CommandFunctions = Extension.create({ name: "commandFunctions", - addStorage: () => ({ - backgroundContext: "", - articleType: ARTICLE_TYPE_OPTIONS[0], - }), + // @ts-ignore addCommands: () => { return { @@ -59,16 +58,13 @@ export const CommandFunctions = Extension.create({ }, getArticleType: () => - ({ editor }: { editor: Editor }) => { - return editor.state.tr.getMeta("articleType") as ArticleTypeOption + ({ tr }: { tr: Transaction }) => { + return articleType }, setArticleType: - (articleType: ArticleTypeOption) => - ({ editor, tr, dispatch }: { editor: Editor, tr: Transaction, dispatch: Dispatch }) => { - console.info("set article type to: ", articleType); - tr.setMeta("articleType", articleType); - // @ts-ignore - dispatch(tr); + (type: ArticleTypeOption) => + ({ editor, tr, dispatch }: { editor: Editor, tr: Transaction, dispatch: any }) => { + articleType = type; }, callLlm: diff --git a/editor/src/components/editor/data/ArticleTypeOption.tsx b/editor/src/components/editor/data/ArticleTypeOption.tsx index 6335439..0e57c4a 100644 --- a/editor/src/components/editor/data/ArticleTypeOption.tsx +++ b/editor/src/components/editor/data/ArticleTypeOption.tsx @@ -5,5 +5,5 @@ export interface ArticleTypeOption { export const ARTICLE_TYPE_OPTIONS: ArticleTypeOption[] = [ { value: 'article', label: '文章' }, - { value: 'user-story', label: '需求文档' }, + { value: 'requirements', label: '需求文档' }, ]; diff --git a/editor/src/components/editor/intelli/menu/menu-ai-dropdown.tsx b/editor/src/components/editor/intelli/menu/toolbar-ai-dropdown.tsx similarity index 74% rename from editor/src/components/editor/intelli/menu/menu-ai-dropdown.tsx rename to editor/src/components/editor/intelli/menu/toolbar-ai-dropdown.tsx index ca36b10..9970952 100644 --- a/editor/src/components/editor/intelli/menu/menu-ai-dropdown.tsx +++ b/editor/src/components/editor/intelli/menu/toolbar-ai-dropdown.tsx @@ -1,20 +1,24 @@ import { CookieIcon } from "@radix-ui/react-icons"; -import React from "react"; -import { FacetType } from "@/types/custom-action.type"; +import React, { useCallback, useEffect } from "react"; import { Editor } from "@tiptap/core"; import { Button, DropdownMenu } from "@radix-ui/themes"; -export const MenuAiDropdown = ({ editor }: { +import { FacetType } from "@/types/custom-action.type"; + +export const ToolbarAiDropdown = ({ editor }: { editor: Editor }) => { const [menus, setMenus] = React.useState([]); - React.useEffect(() => { + useEffect(() => { setMenus(editor?.commands?.getAiActions(FacetType.TOOLBAR_MENU)); - }, []); + }, [editor]); return ( - + { + let aiActions = editor?.commands?.getAiActions(FacetType.TOOLBAR_MENU); + setMenus(aiActions) + }}>