@@ -24,15 +24,21 @@ export class GroupPlugin extends ConverterComponent {
2424 @BindOption ( "searchGroupBoosts" )
2525 boosts ! : Record < string , number > ;
2626
27+ @BindOption ( "groupOrder" )
28+ groupOrder ! : string [ ] ;
29+
2730 usedBoosts = new Set < string > ( ) ;
2831
32+ static WEIGHTS : string [ ] = [ ] ;
33+
2934 /**
3035 * Create a new GroupPlugin instance.
3136 */
3237 override initialize ( ) {
3338 this . listenTo ( this . owner , {
3439 [ Converter . EVENT_RESOLVE_BEGIN ] : ( ) => {
3540 this . sortFunction = getSortFunction ( this . application . options ) ;
41+ GroupPlugin . WEIGHTS = this . groupOrder ;
3642 } ,
3743 [ Converter . EVENT_RESOLVE ] : this . onResolve ,
3844 [ Converter . EVENT_RESOLVE_END ] : this . onEndResolve ,
@@ -162,6 +168,30 @@ export class GroupPlugin extends ConverterComponent {
162168 }
163169 } ) ;
164170
165- return Array . from ( groups . values ( ) ) ;
171+ return Array . from ( groups . values ( ) ) . sort ( GroupPlugin . sortGroupCallback ) ;
172+ }
173+
174+ /**
175+ * Callback used to sort groups by name.
176+ */
177+ static sortGroupCallback ( a : ReflectionGroup , b : ReflectionGroup ) : number {
178+ let aWeight = GroupPlugin . WEIGHTS . indexOf ( a . title ) ;
179+ let bWeight = GroupPlugin . WEIGHTS . indexOf ( b . title ) ;
180+ if ( aWeight === - 1 || bWeight === - 1 ) {
181+ let asteriskIndex = GroupPlugin . WEIGHTS . indexOf ( "*" ) ;
182+ if ( asteriskIndex === - 1 ) {
183+ asteriskIndex = GroupPlugin . WEIGHTS . length ;
184+ }
185+ if ( aWeight === - 1 ) {
186+ aWeight = asteriskIndex ;
187+ }
188+ if ( bWeight === - 1 ) {
189+ bWeight = asteriskIndex ;
190+ }
191+ }
192+ if ( aWeight === bWeight ) {
193+ return a . title > b . title ? 1 : - 1 ;
194+ }
195+ return aWeight - bWeight ;
166196 }
167197}
0 commit comments