@@ -380,7 +380,14 @@ export type BlockNoteEditorOptions<
380380 *
381381 * @deprecated , should use `extensions` instead
382382 */
383- _extensions : Record < string , BlockNoteExtension | BlockNoteExtensionFactory > ;
383+ _extensions : Record <
384+ string ,
385+ | { plugin : Plugin ; priority ?: number }
386+ | ( ( editor : BlockNoteEditor < any , any , any > ) => {
387+ plugin : Plugin ;
388+ priority ?: number ;
389+ } )
390+ > ;
384391
385392 /**
386393 * Register
@@ -630,17 +637,44 @@ export class BlockNoteEditor<
630637 // factory
631638 ext = ext ( this ) ;
632639 }
633- const key = ( ext . constructor as any ) . name ( ) ;
640+ const key = ( ext . constructor as any ) . key ( ) ;
641+ if ( ! key ) {
642+ throw new Error (
643+ `Extension ${ ext . constructor . name } does not have a key method` ,
644+ ) ;
645+ }
646+ if ( this . extensions [ key ] ) {
647+ throw new Error (
648+ `Extension ${ ext . constructor . name } already exists with key ${ key } ` ,
649+ ) ;
650+ }
634651 this . extensions [ key ] = ext ;
635652 }
636653
637654 // (when passed in via the deprecated `_extensions` option)
638655 Object . entries ( newOptions . _extensions || { } ) . forEach ( ( [ key , ext ] ) => {
639- if ( typeof ext === "function" ) {
640- // factory
641- ext = ext ( this ) ;
656+ // eslint-disable-next-line @typescript-eslint/no-this-alias
657+ const editor = this ;
658+
659+ const instance = typeof ext === "function" ? ext ( editor ) : ext ;
660+ if ( ! ( "plugin" in instance ) ) {
661+ // Assume it is an Extension/Mark/Node
662+ this . extensions [ key ] = instance ;
663+ return ;
642664 }
643- this . extensions [ key ] = ext ;
665+
666+ this . extensions [ key ] = new ( class extends BlockNoteExtension {
667+ public static key ( ) {
668+ return key ;
669+ }
670+ constructor ( ) {
671+ super ( ) ;
672+ this . addProsemirrorPlugin ( instance . plugin ) ;
673+ }
674+ public get priority ( ) {
675+ return instance . priority ;
676+ }
677+ } ) ( ) ;
644678 } ) ;
645679
646680 this . formattingToolbar = this . extensions [ "formattingToolbar" ] as any ;
@@ -901,7 +935,7 @@ export class BlockNoteEditor<
901935 */
902936 public extension < T extends BlockNoteExtension > (
903937 ext : { new ( ...args : any [ ] ) : T } & typeof BlockNoteExtension ,
904- key = ext . name ( ) ,
938+ key = ext . key ( ) ,
905939 ) : T {
906940 const extension = this . extensions [ key ] as T ;
907941 if ( ! extension ) {
0 commit comments