From e6e2050ce108be9044ce3f14a46a970b0ae9bbfb Mon Sep 17 00:00:00 2001 From: ditiqi Date: Thu, 27 Feb 2025 22:06:26 +0800 Subject: [PATCH 1/2] add --- apps/web/src/app/main/layout/MainHeader.tsx | 3 +- .../components/common/editor/MindEditor.tsx | 77 ++++++------------- .../src/components/common/editor/constant.ts | 34 ++++++++ 3 files changed, 60 insertions(+), 54 deletions(-) create mode 100644 apps/web/src/components/common/editor/constant.ts diff --git a/apps/web/src/app/main/layout/MainHeader.tsx b/apps/web/src/app/main/layout/MainHeader.tsx index 69b2344..d5b74aa 100755 --- a/apps/web/src/app/main/layout/MainHeader.tsx +++ b/apps/web/src/app/main/layout/MainHeader.tsx @@ -1,4 +1,4 @@ -import { Input, Layout, Avatar, Button, Dropdown } from "antd"; +import { Input, Button } from "antd"; import { EditFilled, PlusOutlined, @@ -10,7 +10,6 @@ import { useNavigate, useParams, useSearchParams } from "react-router-dom"; import { UserMenu } from "./UserMenu/UserMenu"; import { NavigationMenu } from "./NavigationMenu"; import { useMainContext } from "./MainProvider"; -import { Header } from "antd/es/layout/layout"; export function MainHeader() { const { isAuthenticated, user } = useAuth(); diff --git a/apps/web/src/components/common/editor/MindEditor.tsx b/apps/web/src/components/common/editor/MindEditor.tsx index 88d745b..59843de 100755 --- a/apps/web/src/components/common/editor/MindEditor.tsx +++ b/apps/web/src/components/common/editor/MindEditor.tsx @@ -3,12 +3,11 @@ import NodeMenu from "./NodeMenu"; import { api, usePost } from "@nice/client"; import { ObjectType, + PathDto, postDetailSelect, - PostDto, PostType, Prisma, RolePerms, - Taxonomy, } from "@nice/common"; import TermSelect from "../../models/term/term-select"; import DepartmentSelect from "../../models/department/department-select"; @@ -19,45 +18,12 @@ import MindElixir from "mind-elixir"; import { useTusUpload } from "@web/src/hooks/useTusUpload"; import { useNavigate } from "react-router-dom"; import { useAuth } from "@web/src/providers/auth-provider"; -const MIND_OPTIONS = { - direction: MindElixir.SIDE, - draggable: true, - contextMenu: true, - toolBar: true, - nodeMenu: true, - keypress: true, - locale: "zh_CN" as const, - theme: { - name: "Latte", - palette: [ - "#dd7878", - "#ea76cb", - "#8839ef", - "#e64553", - "#fe640b", - "#df8e1d", - "#40a02b", - "#209fb5", - "#1e66f5", - "#7287fd", - ], - cssVar: { - "--main-color": "#444446", - "--main-bgcolor": "#ffffff", - "--color": "#777777", - "--bgcolor": "#f6f6f6", - "--panel-color": "#444446", - "--panel-bgcolor": "#ffffff", - "--panel-border-color": "#eaeaea", - }, - }, -}; +import { MIND_OPTIONS } from "./constant"; export default function MindEditor({ id }: { id?: string }) { const containerRef = useRef(null); const [instance, setInstance] = useState(null); const { isAuthenticated, user, hasSomePermissions } = useAuth(); - - const { data: post, isLoading }: { data: PostDto; isLoading: boolean } = + const { data: post, isLoading }: { data: PathDto; isLoading: boolean } = api.post.findFirst.useQuery({ where: { id, @@ -66,9 +32,9 @@ export default function MindEditor({ id }: { id?: string }) { }); const canEdit: boolean = useMemo(() => { //登录了且是作者、超管、无id新建模式 - const isAuth = isAuthenticated && user?.id == post?.author.id - return !Boolean(id) || isAuth || hasSomePermissions(RolePerms.MANAGE_ANY_POST); - }, [user]) + const isAuth = isAuthenticated && user?.id === post?.author?.id; + return !!id || isAuth || hasSomePermissions(RolePerms.MANAGE_ANY_POST); + }, [user]); const navigate = useNavigate(); const { create, update } = usePost(); const { data: taxonomies } = api.taxonomy.getAll.useQuery({ @@ -91,16 +57,15 @@ export default function MindEditor({ id }: { id?: string }) { form.setFieldsValue(formData); } }, [post, form, instance, id]); - useEffect(() => { if (!containerRef.current) return; const mind = new MindElixir({ ...MIND_OPTIONS, el: containerRef.current, - before:{ - beginEdit(){ - return canEdit - } + before: { + beginEdit() { + return canEdit; + }, }, draggable: canEdit, // 禁用拖拽 contextMenu: canEdit, // 禁用右键菜单 @@ -116,7 +81,9 @@ export default function MindEditor({ id }: { id?: string }) { if ((!id || post) && instance) { containerRef.current.hidden = false; instance.toCenter(); - instance.refresh((post as any)?.meta); + if (post?.meta?.nodeData) { + instance.refresh(post?.meta); + } } }, [id, post, instance]); const handleSave = async () => { @@ -178,16 +145,14 @@ export default function MindEditor({ id }: { id?: string }) { } console.log(result); }, - (error) => { }, + (error) => {}, `mind-thumb-${new Date().toString()}` ); }; return (
{canEdit && taxonomies && ( -
+
{taxonomies.map((tax, index) => ( @@ -214,13 +179,21 @@ export default function MindEditor({ id }: { id?: string }) { />
-
)} -
e.preventDefault()} /> +
e.preventDefault()} + /> {canEdit && instance && } {isLoading && (
Date: Thu, 27 Feb 2025 22:26:36 +0800 Subject: [PATCH 2/2] update --- apps/web/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/web/package.json b/apps/web/package.json index 1456e66..f10e338 100755 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -36,7 +36,6 @@ "@nice/iconer": "workspace:^", "@nice/utils": "workspace:^", "mind-elixir": "workspace:^", - "@mind-elixir/node-menu": "workspace:*", "@nice/ui": "workspace:^", "@tanstack/query-async-storage-persister": "^5.51.9", "@tanstack/react-query": "^5.51.21",