|
|
|
@ -12,7 +12,7 @@ import { |
|
|
|
keys, |
|
|
|
} from 'underscore'; |
|
|
|
import { shallowDiff, capitalize, isEmptyObj, isObject, toLowerCase } from '../../utils/mixins'; |
|
|
|
import StyleableModel, { StyleProps } from '../../domain_abstract/model/StyleableModel'; |
|
|
|
import StyleableModel, { StyleProps, UpdateStyleOptions } from '../../domain_abstract/model/StyleableModel'; |
|
|
|
import { Model } from 'backbone'; |
|
|
|
import Components from './Components'; |
|
|
|
import Selector from '../../selector_manager/model/Selector'; |
|
|
|
@ -22,7 +22,6 @@ import EditorModel from '../../editor/model/Editor'; |
|
|
|
import { |
|
|
|
AddComponentsOption, |
|
|
|
ComponentAdd, |
|
|
|
ComponentAddType, |
|
|
|
ComponentDefinition, |
|
|
|
ComponentDefinitionDefined, |
|
|
|
ComponentOptions, |
|
|
|
@ -44,6 +43,8 @@ import ItemView from '../../navigator/view/ItemView'; |
|
|
|
|
|
|
|
export interface IComponent extends ExtractMethods<Component> {} |
|
|
|
|
|
|
|
export interface SetAttrOptions extends SetOptions, UpdateStyleOptions {} |
|
|
|
|
|
|
|
const escapeRegExp = (str: string) => { |
|
|
|
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); |
|
|
|
}; |
|
|
|
@ -541,7 +542,7 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
* Emit changes for each updated attribute |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
attrUpdated(m: any, v: any, opts: any = {}) { |
|
|
|
attrUpdated(m: any, v: any, opts: SetAttrOptions = {}) { |
|
|
|
const attrs = this.get('attributes')!; |
|
|
|
// Handle classes
|
|
|
|
const classes = attrs.class; |
|
|
|
@ -570,7 +571,7 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
* @example |
|
|
|
* component.setAttributes({ id: 'test', 'data-key': 'value' }); |
|
|
|
*/ |
|
|
|
setAttributes(attrs: ObjectAny, opts: SetOptions = {}) { |
|
|
|
setAttributes(attrs: ObjectAny, opts: SetAttrOptions = {}) { |
|
|
|
this.set('attributes', { ...attrs }, opts); |
|
|
|
return this; |
|
|
|
} |
|
|
|
@ -583,7 +584,7 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
* @example |
|
|
|
* component.addAttributes({ 'data-key': 'value' }); |
|
|
|
*/ |
|
|
|
addAttributes(attrs: ObjectAny, opts: SetOptions = {}) { |
|
|
|
addAttributes(attrs: ObjectAny, opts: SetAttrOptions = {}) { |
|
|
|
return this.setAttributes( |
|
|
|
{ |
|
|
|
...this.getAttributes({ noClass: true }), |
|
|
|
@ -643,7 +644,7 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
|
* @example |
|
|
|
* component.setStyle({ color: 'red' }); |
|
|
|
*/ |
|
|
|
setStyle(prop: StyleProps = {}, opts: any = {}) { |
|
|
|
setStyle(prop: StyleProps = {}, opts: UpdateStyleOptions = {}) { |
|
|
|
const { opt, em } = this; |
|
|
|
|
|
|
|
if (avoidInline(em) && !opt.temporary && !opts.inline) { |
|
|
|
|