1- import {
2- ClassField ,
3- CssCustomProperty ,
4- SlotValue ,
5- unquote
6- } from '@api-viewer/common/lib/index.js' ;
1+ import { ClassField , unquote } from '@api-viewer/common/lib/index.js' ;
72import {
83 getTemplateNode ,
94 getTemplates ,
105 TemplateTypes
116} from '@api-viewer/common/lib/templates.js' ;
7+ import { ComponentWithProps , KnobValue , PropertyKnob } from '../types.js' ;
128
13- export type KnobValue = string | number | boolean | null | undefined ;
14-
15- export type ComponentWithProps = {
16- [ key : string ] : KnobValue ;
17- } ;
18-
19- export type Knobable = unknown | ( CssCustomProperty | ClassField | SlotValue ) ;
20-
21- export type Knob < T extends Knobable = unknown > = T & {
22- attribute : string | undefined ;
23- value : KnobValue ;
24- custom ?: boolean ;
25- options ?: string [ ] ;
26- knobType : string ;
27- content ?: string ;
28- } ;
29-
30- export interface HasKnobs {
31- getKnob ( name : string ) : { knob : Knob < ClassField > ; custom ?: boolean } ;
32- syncKnob ( component : Element , changed : Knob < ClassField > ) : void ;
33- }
34-
35- const getDefault = ( prop : Knob < ClassField > ) : KnobValue => {
9+ const getDefault = ( prop : PropertyKnob ) : KnobValue => {
3610 const { knobType, default : value } = prop ;
3711 switch ( knobType ) {
3812 case 'boolean' :
@@ -75,12 +49,12 @@ export const getKnobs = (
7549 tag : string ,
7650 props : ClassField [ ] ,
7751 exclude = ''
78- ) : Knob < ClassField > [ ] => {
52+ ) : PropertyKnob [ ] => {
7953 // Exclude getters and specific properties
8054 let propKnobs = props . filter (
8155 ( { name } ) =>
8256 ! exclude . includes ( name ) && ! isGetter ( customElements . get ( tag ) , name )
83- ) as Knob < ClassField > [ ] ;
57+ ) as PropertyKnob [ ] ;
8458
8559 // Set knob types and default knobs values
8660 propKnobs = propKnobs . map ( ( prop ) => {
@@ -99,10 +73,7 @@ export const getKnobs = (
9973 return propKnobs ;
10074} ;
10175
102- export const getCustomKnobs = (
103- tag : string ,
104- vid ?: number
105- ) : Knob < ClassField > [ ] => {
76+ export const getCustomKnobs = ( tag : string , vid ?: number ) : PropertyKnob [ ] => {
10677 return getTemplates ( vid as number , tag , TemplateTypes . KNOB )
10778 . map ( ( template ) => {
10879 const { attr, type } = template . dataset ;
@@ -134,15 +105,15 @@ export const getCustomKnobs = (
134105 } ;
135106 }
136107 }
137- return result as Knob < ClassField > ;
108+ return result as PropertyKnob ;
138109 } )
139110 . filter ( Boolean ) ;
140111} ;
141112
142113export const getInitialKnobs = (
143- propKnobs : Knob < ClassField > [ ] ,
114+ propKnobs : PropertyKnob [ ] ,
144115 component : HTMLElement
145- ) : Knob < ClassField > [ ] => {
116+ ) : PropertyKnob [ ] => {
146117 return propKnobs . filter ( ( prop ) => {
147118 const { name, knobType } = prop ;
148119 const defaultValue = getDefault ( prop ) ;
0 commit comments