@@ -2,27 +2,36 @@ import { app } from "../../../scripts/app.js";
2
2
import { ComfyWidgets } from "../../../scripts/widgets.js" ;
3
3
4
4
// Displays input text on a node
5
+
6
+ // TODO: This should need to be so complicated. Refactor at some point.
7
+
5
8
app . registerExtension ( {
6
9
name : "pysssss.ShowText" ,
7
10
async beforeRegisterNodeDef ( nodeType , nodeData , app ) {
8
11
if ( nodeData . name === "ShowText|pysssss" ) {
9
12
function populate ( text ) {
10
13
if ( this . widgets ) {
11
- for ( let i = 1 ; i < this . widgets . length ; i ++ ) {
14
+ // On older frontend versions there is a hidden converted-widget
15
+ const isConvertedWidget = + ! ! this . inputs ?. [ 0 ] . widget ;
16
+ for ( let i = isConvertedWidget ; i < this . widgets . length ; i ++ ) {
12
17
this . widgets [ i ] . onRemove ?. ( ) ;
13
18
}
14
- this . widgets . length = 1 ;
19
+ this . widgets . length = isConvertedWidget ;
15
20
}
16
21
17
22
const v = [ ...text ] ;
18
23
if ( ! v [ 0 ] ) {
19
24
v . shift ( ) ;
20
25
}
21
- for ( const list of v ) {
22
- const w = ComfyWidgets [ "STRING" ] ( this , "text2" , [ "STRING" , { multiline : true } ] , app ) . widget ;
23
- w . inputEl . readOnly = true ;
24
- w . inputEl . style . opacity = 0.6 ;
25
- w . value = list ;
26
+ for ( let list of v ) {
27
+ // Force list to be an array, not sure why sometimes it is/isn't
28
+ if ( ! ( list instanceof Array ) ) list = [ list ] ;
29
+ for ( const l of list ) {
30
+ const w = ComfyWidgets [ "STRING" ] ( this , "text_" + this . widgets ?. length ?? 0 , [ "STRING" , { multiline : true } ] , app ) . widget ;
31
+ w . inputEl . readOnly = true ;
32
+ w . inputEl . style . opacity = 0.6 ;
33
+ w . value = l ;
34
+ }
26
35
}
27
36
28
37
requestAnimationFrame ( ( ) => {
@@ -45,11 +54,23 @@ app.registerExtension({
45
54
populate . call ( this , message . text ) ;
46
55
} ;
47
56
57
+ const VALUES = Symbol ( ) ;
58
+ const configure = nodeType . prototype . configure ;
59
+ nodeType . prototype . configure = function ( ) {
60
+ // Store unmodified widget values as they get removed on configure by new frontend
61
+ this [ VALUES ] = arguments [ 0 ] ?. widgets_values ;
62
+ return configure ?. apply ( this , arguments ) ;
63
+ } ;
64
+
48
65
const onConfigure = nodeType . prototype . onConfigure ;
49
66
nodeType . prototype . onConfigure = function ( ) {
50
67
onConfigure ?. apply ( this , arguments ) ;
51
- if ( this . widgets_values ?. length ) {
52
- populate . call ( this , this . widgets_values . slice ( + this . widgets_values . length > 1 ) ) ;
68
+ const widgets_values = this [ VALUES ] ;
69
+ if ( widgets_values ?. length ) {
70
+ // In newer frontend there seems to be a delay in creating the initial widget
71
+ requestAnimationFrame ( ( ) => {
72
+ populate . call ( this , widgets_values . slice ( + ( widgets_values . length > 1 && this . inputs ?. [ 0 ] . widget ) ) ) ;
73
+ } ) ;
53
74
}
54
75
} ;
55
76
}
0 commit comments