@@ -134,7 +134,7 @@ class RgthreePowerLoraLoader extends RgthreeBaseServerNode {
134134
135135 override getExtraMenuOptions ( canvas : LGraphCanvas , options : ContextMenuItem [ ] ) : void {
136136 super . getExtraMenuOptions ?. apply ( this , [ ...arguments ] as any ) ;
137- const fetchInfoMenuItem = {
137+ const fetchInfoMenuItem : ContextMenuItem = {
138138 content : "Fetch info for all LoRAs" ,
139139 callback : (
140140 _value : ContextMenuItem ,
@@ -154,7 +154,7 @@ class RgthreePowerLoraLoader extends RgthreeBaseServerNode {
154154 } ) ;
155155 } ,
156156 } ;
157- const fixPathsMenuItem = {
157+ const fixPathsMenuItem : ContextMenuItem = {
158158 content : "Update paths for all LoRAs" ,
159159 callback : (
160160 _value : ContextMenuItem ,
@@ -189,7 +189,22 @@ class RgthreePowerLoraLoader extends RgthreeBaseServerNode {
189189 } ) ;
190190 } ,
191191 } ;
192- options . splice ( options . length - 1 , 0 , fetchInfoMenuItem , fixPathsMenuItem ) ;
192+ const sortLoraWidgetsMenuItem : ContextMenuItem = {
193+ content : "Sort LoRA widgets by name" ,
194+ callback : (
195+ _value : ContextMenuItem ,
196+ _options : IContextMenuOptions ,
197+ _event : MouseEvent ,
198+ _parentMenu : ContextMenu | undefined ,
199+ _node : TLGraphNode ,
200+ ) => {
201+ const loraWidgets = this . getLoraWidgets ( ) ;
202+ const sortedWidgets = loraWidgets . toSorted ( ( a , b ) => a . getLoraLabel ( ) . localeCompare ( b . getLoraLabel ( ) ) ) ;
203+ const firstLoraWidget = this . widgets . findIndex ( w => isLoraWidget ( w ) ) ;
204+ this . widgets . splice ( firstLoraWidget , sortedWidgets . length , ...sortedWidgets ) ;
205+ } ,
206+ } ;
207+ options . splice ( options . length - 1 , 0 , fetchInfoMenuItem , fixPathsMenuItem , sortLoraWidgetsMenuItem ) ;
193208 }
194209
195210 private updateCommonPrefix ( ) {
@@ -834,6 +849,10 @@ class PowerLoraLoaderWidget extends RgthreeBaseWidget<PowerLoraLoaderWidgetValue
834849 ctx . restore ( ) ;
835850 }
836851
852+ getLoraLabel ( ) {
853+ return this . getLoraName ( ) ;
854+ }
855+
837856 private getLoraName ( commonPrefix = '' , nameDisplay : NameDisplay = PROP_VALUE_NAME_OPTIONS_CIVITAI ) {
838857 if ( this . loraInfo ?. name && nameDisplay === PROP_VALUE_NAME_OPTIONS_CIVITAI ) {
839858 return this . loraInfo . name ;
0 commit comments