返回 presentation-ai
usePresentationEditorInstance.ts
根目录 / src / components / notebook / presentation / editor / hooks / usePresentationEditorInstance.ts
1 "use client";
2
3 import { type Value } from "platejs";
4 import { type PlateEditor } from "platejs/react";
5
6 import { usePlateEditor } from "@/components/plate/hooks/usePlateEditor";
7 import { normalizePresentationValue } from "../../utils/normalizePresentationSlate";
8 import { presentationPlugins } from "../plugins";
9
10 interface UsePresentationEditorInstanceArgs {
11 initialValue: Value | undefined;
12 onReady?: (args: { editor: PlateEditor }) => void;
13 id?: string;
14 }
15
16 export function usePresentationEditorInstance({
17 initialValue,
18 onReady,
19 id,
20 }: UsePresentationEditorInstanceArgs) {
21 const normalizedInitialValue = normalizePresentationValue(initialValue);
22
23 const editor = usePlateEditor({
24 plugins: presentationPlugins,
25 value: normalizedInitialValue,
26 onReady,
27 override: {
28 enabled: {
29 history: false,
30 },
31 },
32 id,
33 });
34
35 return editor as PlateEditor;
36 }
37
37 lines TYPESCRIPT