返回 presentation-ai
useAntvInfographicActions.ts
根目录 / src / hooks / presentation / infographic / useAntvInfographicActions.ts
1 "use client";
2
3 import { type PlateEditor } from "platejs/react";
4 import { useCallback, type MutableRefObject } from "react";
5
6 import { type TAntvInfographicElement } from "@/components/notebook/presentation/editor/plugins/antv-infographic-plugin";
7 import { findInfographicEntryById } from "@/hooks/presentation/infographic/findInfographicNode";
8
9 type ActionParams = {
10 editor: PlateEditor;
11 elementRef: MutableRefObject<TAntvInfographicElement>;
12 };
13
14 export function useAntvInfographicActions({
15 editor,
16 elementRef,
17 }: ActionParams) {
18 const handleDelete = useCallback(() => {
19 const elementId =
20 typeof elementRef.current.id === "string" ? elementRef.current.id : "";
21 const path = findInfographicEntryById(editor, elementId)?.[1];
22 if (path) {
23 editor.tf.removeNodes({ at: path });
24 }
25 }, [editor, elementRef]);
26
27 return { handleDelete };
28 }
29
29 lines TYPESCRIPT