6
6
CSSPropertyInfo ,
7
7
PropertyInfo ,
8
8
SlotInfo ,
9
- SlotValue ,
10
- EventInfo
9
+ SlotValue
11
10
} from './lib/types.js' ;
12
11
import {
13
12
getTemplates ,
@@ -132,19 +131,19 @@ export interface ApiDemoKnobsInterface {
132
131
props : PropertyInfo [ ] ;
133
132
propKnobs : Knob < PropertyInfo > [ ] ;
134
133
slots : SlotInfo [ ] ;
135
- events : EventInfo [ ] ;
136
134
cssProps : CSSPropertyInfo [ ] ;
137
135
exclude : string ;
138
136
vid ?: number ;
139
137
processedSlots : SlotValue [ ] ;
140
138
processedCss : CSSPropertyInfo [ ] ;
141
- eventLog : CustomEvent [ ] ;
142
139
customKnobs : Knob < PropertyInfo > [ ] ;
143
140
knobs : Record < string , Knob > ;
144
141
setKnobs ( target : HTMLInputElement ) : void ;
145
142
setSlots ( target : HTMLInputElement ) : void ;
146
143
setCss ( target : HTMLInputElement ) : void ;
147
- onRendered ( event : CustomEvent ) : void ;
144
+ initKnobs ( component : HTMLElement ) : void ;
145
+ getKnob ( name : string ) : { knob : Knob < PropertyInfo > ; custom ?: boolean } ;
146
+ syncKnob ( component : Element , changed : Knob < PropertyInfo > ) : void ;
148
147
}
149
148
150
149
export const ApiDemoKnobsMixin = < T extends Constructor < LitElement > > (
@@ -159,9 +158,6 @@ export const ApiDemoKnobsMixin = <T extends Constructor<LitElement>>(
159
158
@property ( { attribute : false } )
160
159
slots : SlotInfo [ ] = [ ] ;
161
160
162
- @property ( { attribute : false } )
163
- events : EventInfo [ ] = [ ] ;
164
-
165
161
@property ( { attribute : false } )
166
162
cssProps : CSSPropertyInfo [ ] = [ ] ;
167
163
@@ -175,9 +171,6 @@ export const ApiDemoKnobsMixin = <T extends Constructor<LitElement>>(
175
171
@property ( { attribute : false } )
176
172
processedCss ! : CSSPropertyInfo [ ] ;
177
173
178
- @property ( { attribute : false } )
179
- eventLog ! : CustomEvent [ ] ;
180
-
181
174
@property ( { attribute : false } )
182
175
customKnobs : Knob < PropertyInfo > [ ] = [ ] ;
183
176
@@ -191,7 +184,6 @@ export const ApiDemoKnobsMixin = <T extends Constructor<LitElement>>(
191
184
// Reset state if tag changed
192
185
if ( props . has ( 'tag' ) ) {
193
186
this . knobs = { } ;
194
- this . eventLog = [ ] ;
195
187
this . processedCss = [ ] ;
196
188
this . processedSlots = [ ] ;
197
189
this . propKnobs = getKnobs ( this . tag , this . props , this . exclude ) ;
@@ -218,18 +210,18 @@ export const ApiDemoKnobsMixin = <T extends Constructor<LitElement>>(
218
210
}
219
211
}
220
212
221
- private _getProp ( name : string ) : {
222
- prop : Knob < PropertyInfo > ;
213
+ getKnob ( name : string ) : {
214
+ knob : Knob < PropertyInfo > ;
223
215
custom ?: boolean ;
224
216
} {
225
217
const isMatch = isPropMatch ( name ) ;
226
- let prop = this . propKnobs . find ( isMatch ) ;
218
+ let knob = this . propKnobs . find ( isMatch ) ;
227
219
let custom = false ;
228
- if ( ! prop ) {
229
- prop = this . customKnobs . find ( isMatch ) as Knob < PropertyInfo > ;
220
+ if ( ! knob ) {
221
+ knob = this . customKnobs . find ( isMatch ) as Knob < PropertyInfo > ;
230
222
custom = true ;
231
223
}
232
- return { prop , custom } ;
224
+ return { knob , custom } ;
233
225
}
234
226
235
227
setCss ( target : HTMLInputElement ) : void {
@@ -259,9 +251,9 @@ export const ApiDemoKnobsMixin = <T extends Constructor<LitElement>>(
259
251
value = target . value ;
260
252
}
261
253
262
- const { prop , custom } = this . _getProp ( name as string ) ;
263
- if ( prop ) {
264
- const { attribute } = prop ;
254
+ const { knob , custom } = this . getKnob ( name as string ) ;
255
+ if ( knob ) {
256
+ const { attribute } = knob ;
265
257
this . knobs = {
266
258
...this . knobs ,
267
259
[ name as string ] : {
@@ -288,39 +280,23 @@ export const ApiDemoKnobsMixin = <T extends Constructor<LitElement>>(
288
280
} ) ;
289
281
}
290
282
291
- onRendered ( e : CustomEvent ) : void {
292
- const { component } = e . detail ;
293
-
283
+ initKnobs ( component : HTMLElement ) {
294
284
if ( hasTemplate ( this . vid as number , this . tag , HOST ) ) {
295
285
// Apply property values from template
296
286
this . propKnobs
297
287
. filter ( ( prop ) => {
298
288
const { name, knobType } = prop ;
299
289
const defaultValue = getDefault ( prop ) ;
300
290
return (
301
- component [ name ] !== defaultValue ||
291
+ ( component as any ) [ name ] !== defaultValue ||
302
292
( knobType === 'boolean' && defaultValue )
303
293
) ;
304
294
} )
305
295
. forEach ( ( prop ) => {
306
- this . _syncKnob ( component , prop ) ;
296
+ this . syncKnob ( component , prop ) ;
307
297
} ) ;
308
298
}
309
299
310
- this . events . forEach ( ( event ) => {
311
- component . addEventListener ( event . name , ( ( evt : CustomEvent ) => {
312
- const s = '-changed' ;
313
- if ( event . name . endsWith ( s ) ) {
314
- const { prop } = this . _getProp ( event . name . replace ( s , '' ) ) ;
315
- if ( prop ) {
316
- this . _syncKnob ( component , prop ) ;
317
- }
318
- }
319
-
320
- this . eventLog = [ ...this . eventLog , evt ] ;
321
- } ) as EventListener ) ;
322
- } ) ;
323
-
324
300
if ( this . cssProps . length ) {
325
301
const style = getComputedStyle ( component ) ;
326
302
@@ -339,7 +315,7 @@ export const ApiDemoKnobsMixin = <T extends Constructor<LitElement>>(
339
315
}
340
316
}
341
317
342
- private _syncKnob ( component : Element , changed : Knob < PropertyInfo > ) : void {
318
+ syncKnob ( component : Element , changed : Knob < PropertyInfo > ) : void {
343
319
const { name, knobType, attribute } = changed ;
344
320
const value = ( component as unknown as ComponentWithProps ) [ name ] ;
345
321
0 commit comments