|
|
|
@ -4,8 +4,7 @@ import ParserHtml from '../../parser/model/ParserHtml'; |
|
|
|
import Selectors from '../../selector_manager/model/Selectors'; |
|
|
|
import { shallowDiff } from '../../utils/mixins'; |
|
|
|
import EditorModel from '../../editor/model/Editor'; |
|
|
|
import StyleDataVariable from '../../data_sources/model/StyleDataVariable'; |
|
|
|
import { DataVariableProps, DataVariableType } from '../../data_sources/model/DataVariable'; |
|
|
|
import DataVariable, { DataVariableProps, DataVariableType } from '../../data_sources/model/DataVariable'; |
|
|
|
import DynamicVariableListenerManager from '../../data_sources/model/DataVariableListenerManager'; |
|
|
|
import CssRuleView from '../../css_composer/view/CssRuleView'; |
|
|
|
import ComponentView from '../../dom_components/view/ComponentView'; |
|
|
|
@ -112,8 +111,10 @@ export default class StyleableModel<T extends ObjectHash = any> extends Model<T> |
|
|
|
const styleValue = newStyle[key]; |
|
|
|
if (isDynamicValueDefinition(styleValue)) { |
|
|
|
const styleDynamicVariable = this.resolveDynamicValue(styleValue); |
|
|
|
newStyle[key] = styleDynamicVariable; |
|
|
|
this.manageDataVariableListener(styleDynamicVariable, key); |
|
|
|
if (styleDynamicVariable) { |
|
|
|
newStyle[key] = styleDynamicVariable; |
|
|
|
this.manageDataVariableListener(styleDynamicVariable, key); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
@ -140,21 +141,19 @@ export default class StyleableModel<T extends ObjectHash = any> extends Model<T> |
|
|
|
} |
|
|
|
|
|
|
|
private resolveDynamicValue(styleValue: DynamicValueProps) { |
|
|
|
const em = this.em!; |
|
|
|
const dynamicType = styleValue.type; |
|
|
|
let styleDynamicVariable; |
|
|
|
|
|
|
|
switch (dynamicType) { |
|
|
|
case DataVariableType: |
|
|
|
styleDynamicVariable = new StyleDataVariable(styleValue, { em: this.em }); |
|
|
|
styleDynamicVariable = new DataVariable(styleValue, { em }); |
|
|
|
break; |
|
|
|
case DataConditionType: { |
|
|
|
const { condition, ifTrue, ifFalse } = styleValue; |
|
|
|
styleDynamicVariable = new DataCondition(condition, ifTrue, ifFalse, { em: this.em! }); |
|
|
|
styleDynamicVariable = new DataCondition(condition, ifTrue, ifFalse, { em }); |
|
|
|
break; |
|
|
|
} |
|
|
|
default: |
|
|
|
throw new Error( |
|
|
|
`Unsupported dynamic value type for styles. Only '${DataVariableType}' and '${DataConditionType}' are supported. Received '${dynamicType}'.`, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return styleDynamicVariable; |
|
|
|
@ -163,7 +162,7 @@ export default class StyleableModel<T extends ObjectHash = any> extends Model<T> |
|
|
|
/** |
|
|
|
* Manage DataVariableListenerManager for a style property |
|
|
|
*/ |
|
|
|
manageDataVariableListener(dataVar: StyleDataVariable | DataCondition, styleProp: string) { |
|
|
|
manageDataVariableListener(dataVar: DataVariable | DataCondition, styleProp: string) { |
|
|
|
if (this.dynamicVariableListeners[styleProp]) { |
|
|
|
this.dynamicVariableListeners[styleProp].listenToDynamicVariable(); |
|
|
|
} else { |
|
|
|
@ -209,7 +208,9 @@ export default class StyleableModel<T extends ObjectHash = any> extends Model<T> |
|
|
|
|
|
|
|
if (isDynamicValueDefinition(styleValue)) { |
|
|
|
const dataVar = this.resolveDynamicValue(styleValue); |
|
|
|
resolvedStyle[key] = dataVar.getDataValue(); |
|
|
|
if (dataVar) { |
|
|
|
resolvedStyle[key] = dataVar.getDataValue(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (isDynamicValue(styleValue)) { |
|
|
|
|