@@ -9,12 +9,6 @@ import {
9
9
import { Node , Schema } from "prosemirror-model" ;
10
10
// import "./blocknote.css";
11
11
import * as Y from "yjs" ;
12
- import {
13
- getBlock ,
14
- getNextBlock ,
15
- getParentBlock ,
16
- getPrevBlock ,
17
- } from "../api/blockManipulation/getBlock/getBlock.js" ;
18
12
import { insertBlocks } from "../api/blockManipulation/commands/insertBlocks/insertBlocks.js" ;
19
13
import {
20
14
moveBlocksDown ,
@@ -29,15 +23,21 @@ import {
29
23
import { removeBlocks } from "../api/blockManipulation/commands/removeBlocks/removeBlocks.js" ;
30
24
import { replaceBlocks } from "../api/blockManipulation/commands/replaceBlocks/replaceBlocks.js" ;
31
25
import { updateBlock } from "../api/blockManipulation/commands/updateBlock/updateBlock.js" ;
32
- import { insertContentAt } from "../api/blockManipulation/insertContentAt.js" ;
33
26
import {
34
- getTextCursorPosition ,
35
- setTextCursorPosition ,
36
- } from "../api/blockManipulation/selections/textCursorPosition/textCursorPosition.js" ;
27
+ getBlock ,
28
+ getNextBlock ,
29
+ getParentBlock ,
30
+ getPrevBlock ,
31
+ } from "../api/blockManipulation/getBlock/getBlock.js" ;
32
+ import { insertContentAt } from "../api/blockManipulation/insertContentAt.js" ;
37
33
import {
38
34
getSelection ,
39
35
setSelection ,
40
36
} from "../api/blockManipulation/selections/selection.js" ;
37
+ import {
38
+ getTextCursorPosition ,
39
+ setTextCursorPosition ,
40
+ } from "../api/blockManipulation/selections/textCursorPosition/textCursorPosition.js" ;
41
41
import { createExternalHTMLExporter } from "../api/exporters/html/externalHTMLExporter.js" ;
42
42
import { blocksToMarkdown } from "../api/exporters/markdown/markdownExporter.js" ;
43
43
import { HTMLToBlocks } from "../api/parsers/html/parseHTML.js" ;
@@ -89,11 +89,15 @@ import { en } from "../i18n/locales/index.js";
89
89
90
90
import { Plugin , Transaction } from "@tiptap/pm/state" ;
91
91
import { dropCursor } from "prosemirror-dropcursor" ;
92
+ import { EditorView } from "prosemirror-view" ;
92
93
import { createInternalHTMLSerializer } from "../api/exporters/html/internalHTMLSerializer.js" ;
93
94
import { inlineContentToNodes } from "../api/nodeConversions/blockToNode.js" ;
94
95
import { nodeToBlock } from "../api/nodeConversions/nodeToBlock.js" ;
95
96
import "../style.css" ;
96
- import { EditorView } from "prosemirror-view" ;
97
+
98
+ export type BlockNoteExtensionFactory = (
99
+ editor : BlockNoteEditor < any , any , any >
100
+ ) => BlockNoteExtension ;
97
101
98
102
export type BlockNoteExtension =
99
103
| AnyExtension
@@ -213,7 +217,7 @@ export type BlockNoteEditorOptions<
213
217
/**
214
218
* (experimental) add extra prosemirror plugins or tiptap extensions to the editor
215
219
*/
216
- _extensions : Record < string , BlockNoteExtension > ;
220
+ _extensions : Record < string , BlockNoteExtension | BlockNoteExtensionFactory > ;
217
221
218
222
trailingBlock ?: boolean ;
219
223
@@ -449,6 +453,10 @@ export class BlockNoteEditor<
449
453
450
454
// add extensions from options
451
455
Object . entries ( newOptions . _extensions || { } ) . forEach ( ( [ key , ext ] ) => {
456
+ if ( typeof ext === "function" ) {
457
+ // factory
458
+ ext = ext ( this ) ;
459
+ }
452
460
this . extensions [ key ] = ext ;
453
461
} ) ;
454
462
0 commit comments