@@ -13,6 +13,7 @@ import Transition from './Transition';
13
13
import Animation from './Animation' ;
14
14
import Action from './Action' ;
15
15
import { string_literal } from '../utils/stringify' ;
16
+ import Text from './Text' ;
16
17
17
18
export default class DynamicElement extends Node {
18
19
type : 'DynamicElement' ;
@@ -29,6 +30,7 @@ export default class DynamicElement extends Node {
29
30
animation ?: Animation = null ;
30
31
children : INode [ ] ;
31
32
scope : TemplateScope ;
33
+ needs_manual_style_scoping : boolean ;
32
34
33
35
constructor ( component : Component , parent , scope , info ) {
34
36
super ( component , parent , scope , info ) ;
@@ -95,4 +97,37 @@ export default class DynamicElement extends Node {
95
97
96
98
this . children = map_children ( component , this , this . scope , info . children ) ;
97
99
}
100
+
101
+ add_css_class ( ) {
102
+ if ( this . attributes . some ( attr => attr . is_spread ) ) {
103
+ this . needs_manual_style_scoping = true ;
104
+ return ;
105
+ }
106
+
107
+ const { id } = this . component . stylesheet ;
108
+
109
+ const class_attribute = this . attributes . find ( a => a . name === 'class' ) ;
110
+
111
+ if ( class_attribute && ! class_attribute . is_true ) {
112
+ if ( class_attribute . chunks . length === 1 && class_attribute . chunks [ 0 ] . type === 'Text' ) {
113
+ ( class_attribute . chunks [ 0 ] as Text ) . data += ` ${ id } ` ;
114
+ } else {
115
+ ( class_attribute . chunks as Node [ ] ) . push (
116
+ new Text ( this . component , this , this . scope , {
117
+ type : 'Text' ,
118
+ data : ` ${ id } ` ,
119
+ synthetic : true
120
+ } )
121
+ ) ;
122
+ }
123
+ } else {
124
+ this . attributes . push (
125
+ new Attribute ( this . component , this , this . scope , {
126
+ type : 'Attribute' ,
127
+ name : 'class' ,
128
+ value : [ { type : 'Text' , data : id , synthetic : true } ]
129
+ } )
130
+ ) ;
131
+ }
132
+ }
98
133
}
0 commit comments