forked from TypeCellOS/BlockNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlockNoteContext.ts
More file actions
41 lines (37 loc) · 1.36 KB
/
BlockNoteContext.ts
File metadata and controls
41 lines (37 loc) · 1.36 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
35
36
37
38
39
40
41
import {
BlockNoteEditor,
BlockNoteSchema,
BlockSchema,
DefaultBlockSchema,
DefaultInlineContentSchema,
DefaultStyleSchema,
InlineContentSchema,
StyleSchema,
} from "@blocknote/core";
import { createContext, useContext, useState } from "react";
type BlockNoteContextValue<
BSchema extends BlockSchema = DefaultBlockSchema,
ISchema extends InlineContentSchema = DefaultInlineContentSchema,
SSchema extends StyleSchema = DefaultStyleSchema
> = {
setContentEditableProps?: ReturnType<typeof useState<Record<string, any>>>[1]; // copy type of setXXX from useState
editor?: BlockNoteEditor<BSchema, ISchema, SSchema>;
colorSchemePreference?: "light" | "dark";
};
export const BlockNoteContext = createContext<
BlockNoteContextValue | undefined
>(undefined);
/**
* Get the BlockNoteContext instance from the nearest BlockNoteContext provider
* @param _schema: optional, pass in the schema to return type-safe Context if you're using a custom schema
*/
export function useBlockNoteContext<
BSchema extends BlockSchema = DefaultBlockSchema,
ISchema extends InlineContentSchema = DefaultInlineContentSchema,
SSchema extends StyleSchema = DefaultStyleSchema
>(
_schema?: BlockNoteSchema<BSchema, ISchema, SSchema>
): BlockNoteContextValue<BSchema, ISchema, SSchema> | undefined {
const context = useContext(BlockNoteContext) as any;
return context;
}