11import MarkdownIt from 'markdown-it' ;
22import type { Plugin } from 'prosemirror-state' ;
33import { ActionsManager } from './ActionsManager' ;
4+ import { ExtensionBuilder } from './ExtensionBuilder' ;
45import { ParserTokensRegistry } from './ParserTokensRegistry' ;
56import { SchemaSpecRegistry } from './SchemaSpecRegistry' ;
67import { SerializerTokensRegistry } from './SerializerTokensRegistry' ;
78import type { ActionSpec } from './types/actions' ;
8- import type { ExtensionDeps , ExtensionSpec , YEMarkSpec , YENodeSpec } from './types/extension' ;
9+ import type {
10+ Extension ,
11+ ExtensionDeps ,
12+ ExtensionSpec ,
13+ YEMarkSpec ,
14+ YENodeSpec ,
15+ } from './types/extension' ;
916import type { MarkViewConstructor , NodeViewConstructor } from './types/node-views' ;
1017
1118const attrs = require ( 'markdown-it-attrs' ) ;
1219
1320type ExtensionsManagerParams = {
14- extensions : ExtensionSpec [ ] ;
21+ extensions : Extension ;
1522 options ?: ExtensionsManagerOptions ;
1623} ;
1724
@@ -25,7 +32,7 @@ type ExtensionsManagerOptions = {
2532} ;
2633
2734export class ExtensionsManager {
28- static process ( extensions : ExtensionSpec [ ] , options : ExtensionsManagerOptions ) {
35+ static process ( extensions : Extension , options : ExtensionsManagerOptions ) {
2936 return new this ( { extensions, options} ) . build ( ) ;
3037 }
3138
@@ -38,8 +45,10 @@ export class ExtensionsManager {
3845
3946 #md: MarkdownIt ;
4047 #mdWithoutAttrs: MarkdownIt ;
41- #extensions: ExtensionSpec [ ] ;
48+ #extensions: Extension ;
49+ #builder: ExtensionBuilder ;
4250
51+ #spec! : ExtensionSpec ;
4352 #deps! : ExtensionDeps ;
4453 #plugins: Plugin [ ] = [ ] ;
4554 #actions: Record < string , ActionSpec > = { } ;
@@ -51,6 +60,9 @@ export class ExtensionsManager {
5160
5261 this . #md = new MarkdownIt ( options . mdOpts ?? { } ) . use ( attrs , options . attrsOpts ?? { } ) ;
5362 this . #mdWithoutAttrs = new MarkdownIt ( options . mdOpts ?? { } ) ;
63+
64+ // TODO: add prefilled context
65+ this . #builder = new ExtensionBuilder ( ) ;
5466 }
5567
5668 build ( ) {
@@ -75,12 +87,11 @@ export class ExtensionsManager {
7587 }
7688
7789 private processExtensions ( ) {
78- for ( const ext of this . #extensions) {
79- this . #md = ext . configureMd ( this . #md) ;
80- this . #mdWithoutAttrs = ext . configureMd ( this . #mdWithoutAttrs) ;
81- ext . nodes ( ) . forEach ( this . processNode ) ;
82- ext . marks ( ) . forEach ( this . processMark ) ;
83- }
90+ this . #spec = this . #builder. use ( this . #extensions) . build ( ) ;
91+ this . #md = this . #spec. configureMd ( this . #md) ;
92+ this . #mdWithoutAttrs = this . #spec. configureMd ( this . #mdWithoutAttrs) ;
93+ this . #spec. nodes ( ) . forEach ( this . processNode ) ;
94+ this . #spec. marks ( ) . forEach ( this . processMark ) ;
8495 }
8596
8697 private processNode = ( name : string , { spec, fromYfm, toYfm, view} : YENodeSpec ) => {
@@ -113,14 +124,8 @@ export class ExtensionsManager {
113124 }
114125
115126 private createDerived ( ) {
116- const plugins : { plugin : Plugin ; priority : number } [ ] = [ ] ;
117- for ( const ext of this . #extensions) {
118- plugins . push ( ...ext . plugins ( this . #deps) ) ;
119- Object . assign ( this . #actions, ext . actions ( this . #deps) ) ;
120- }
121-
122- // TODO: move sorting to ExtensionBuilder after WIKI-16660
123- this . #plugins = plugins . sort ( ( a , b ) => b . priority - a . priority ) . map ( ( item ) => item . plugin ) ;
127+ this . #plugins = this . #spec. plugins ( this . #deps) ;
128+ Object . assign ( this . #actions, this . #spec. actions ( this . #deps) ) ;
124129
125130 for ( const [ name , view ] of this . #nodeViewCreators) {
126131 this . #nodeViews[ name ] = view ( this . #deps) ;
0 commit comments