forked from TypeCellOS/BlockNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseBlockNoteEditor.ts
More file actions
34 lines (30 loc) · 1 KB
/
useBlockNoteEditor.ts
File metadata and controls
34 lines (30 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import {
BlockNoteEditor,
BlockNoteSchema,
BlockSchema,
DefaultBlockSchema,
DefaultInlineContentSchema,
DefaultStyleSchema,
InlineContentSchema,
StyleSchema,
} from "@blocknote/core";
import { useBlockNoteContext } from "../editor/BlockNoteContext.js";
/**
* Get the BlockNoteEditor instance from the nearest BlockNoteContext provider
* @param _schema: optional, pass in the schema to return type-safe BlockNoteEditor if you're using a custom schema
*/
export function useBlockNoteEditor<
BSchema extends BlockSchema = DefaultBlockSchema,
ISchema extends InlineContentSchema = DefaultInlineContentSchema,
SSchema extends StyleSchema = DefaultStyleSchema
>(
_schema?: BlockNoteSchema<BSchema, ISchema, SSchema>
): BlockNoteEditor<BSchema, ISchema, SSchema> {
const context = useBlockNoteContext(_schema);
if (!context?.editor) {
throw new Error(
"useBlockNoteEditor was called outside of a BlockNoteContext provider or BlockNoteView component"
);
}
return context.editor;
}