@ -512,33 +512,29 @@ export default () => {
/ * *
/ * *
* Add new property type
* Add new property type
* @ param { string } id Type ID
* @ param { string } id Type ID
* @ param { Object } definition Definition of the type . Each definition contains
* @ param { Object } definition Definition of the type .
* ` model ` ( business logic ) , ` view ` ( presentation logic )
* @ example
* and ` isType ` function which recognize the type of the
* passed entity
* @ example
* styleManager . addType ( 'my-custom-prop' , {
* styleManager . addType ( 'my-custom-prop' , {
* // Create UI
* create ( { props , change } ) {
* create ( { props , change } ) {
* const el = document . createElement ( 'div' ) ;
* const el = document . createElement ( 'div' ) ;
* el . innerHTML = '<input type="range" class="my-input" min="10" max="50"/>' ;
* el . innerHTML = '<input type="range" class="my-input" min="10" max="50"/>' ;
* const inputEl = el . querySelector ( '.my-input' ) ;
* const inputEl = el . querySelector ( '.my-input' ) ;
* inputEl . addEventListener ( 'change' , event => change ( { event } ) ) ; // change will trigger the emit
* inputEl . addEventListener ( 'change' , event => change ( { event } ) ) ;
* inputEl . addEventListener ( 'input' , event => change ( { event , complete : fals e } ) ) ;
* inputEl . addEventListener ( 'input' , event => change ( { event , partial : tru e } ) ) ;
* return el ;
* return el ;
* } ,
* } ,
* emit ( { props , updateStyle } , { event , complete } ) {
* // Propagate UI changes up to the targets
* emit ( { props , updateStyle } , { event , partial } ) {
* const { value } = event . target ;
* const { value } = event . target ;
* const valueRes = value + 'px' ;
* updateStyle ( ` ${ value } px ` , { partial } ) ;
* // Pass a string value for the exact CSS property or an object containing multiple properties
* // eg. updateStyle({ [props.property]: valueRes, color: 'red' });
* updateStyle ( valueRes , { complete } ) ;
* } ,
* } ,
* // Update UI (eg. when the target is changed)
* update ( { value , el } ) {
* update ( { value , el } ) {
* el . querySelector ( '.my-input' ) . value = parseInt ( value , 10 ) ;
* el . querySelector ( '.my-input' ) . value = parseInt ( value , 10 ) ;
* } ,
* } ,
* destroy ( ) {
* // Clean the memory from side effects if necessary (eg. global event listeners, etc.)
* // In order to prevent memory leaks, use this method to clean, eventually, created instances, global event listeners, etc.
* destroy ( ) { }
* }
* } )
* } )
* /
* /
addType ( id , definition ) {
addType ( id , definition ) {