|
|
@ -51,15 +51,16 @@ import { |
|
|
updateSymbolComps, |
|
|
updateSymbolComps, |
|
|
updateSymbolProps, |
|
|
updateSymbolProps, |
|
|
} from './SymbolUtils'; |
|
|
} from './SymbolUtils'; |
|
|
import { ComponentDynamicValueWatcher } from './ComponentDynamicValueListener'; |
|
|
import { ComponentDynamicValueWatcher } from './ComponentDynamicValueWatcher'; |
|
|
import { DynamicValueWatcher } from './DynamicValueWatcher'; |
|
|
import { DynamicValueWatcher } from './DynamicValueWatcher'; |
|
|
|
|
|
|
|
|
export interface IComponent extends ExtractMethods<Component> { } |
|
|
export interface IComponent extends ExtractMethods<Component> {} |
|
|
export interface DynamicWatchersOptions { |
|
|
export interface DynamicWatchersOptions { |
|
|
skipWatcherUpdates?: boolean; |
|
|
skipWatcherUpdates?: boolean; |
|
|
|
|
|
fromDataSource?: boolean; |
|
|
} |
|
|
} |
|
|
export interface SetAttrOptions extends SetOptions, UpdateStyleOptions, DynamicWatchersOptions { } |
|
|
export interface SetAttrOptions extends SetOptions, UpdateStyleOptions, DynamicWatchersOptions {} |
|
|
export interface ComponentSetOptions extends SetOptions, DynamicWatchersOptions { } |
|
|
export interface ComponentSetOptions extends SetOptions, DynamicWatchersOptions {} |
|
|
|
|
|
|
|
|
const escapeRegExp = (str: string) => { |
|
|
const escapeRegExp = (str: string) => { |
|
|
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); |
|
|
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); |
|
|
@ -226,12 +227,12 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
return this.frame?.getPage(); |
|
|
return this.frame?.getPage(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
preInit() { } |
|
|
preInit() {} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Hook method, called once the model is created |
|
|
* Hook method, called once the model is created |
|
|
*/ |
|
|
*/ |
|
|
init() { } |
|
|
init() {} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Hook method, called when the model has been updated (eg. updated some model's property) |
|
|
* Hook method, called when the model has been updated (eg. updated some model's property) |
|
|
@ -239,12 +240,12 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
* @param {*} value Property value, if triggered after some property update |
|
|
* @param {*} value Property value, if triggered after some property update |
|
|
* @param {*} previous Property previous value, if triggered after some property update |
|
|
* @param {*} previous Property previous value, if triggered after some property update |
|
|
*/ |
|
|
*/ |
|
|
updated(property: string, value: any, previous: any) { } |
|
|
updated(property: string, value: any, previous: any) {} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Hook method, called once the model has been removed |
|
|
* Hook method, called once the model has been removed |
|
|
*/ |
|
|
*/ |
|
|
removed() { } |
|
|
removed() {} |
|
|
|
|
|
|
|
|
em!: EditorModel; |
|
|
em!: EditorModel; |
|
|
opt!: ComponentOptions; |
|
|
opt!: ComponentOptions; |
|
|
@ -264,8 +265,7 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
componentDVListener: ComponentDynamicValueWatcher; |
|
|
componentDVListener: ComponentDynamicValueWatcher; |
|
|
|
|
|
|
|
|
constructor(props: ComponentProperties = {}, opt: ComponentOptions) { |
|
|
constructor(props: ComponentProperties = {}, opt: ComponentOptions) { |
|
|
const evaluatedProps = ComponentDynamicValueWatcher.evaluateComponentDef(props, opt.em); |
|
|
super(props, opt); |
|
|
super(evaluatedProps, opt); |
|
|
|
|
|
this.componentDVListener = new ComponentDynamicValueWatcher(this, opt.em); |
|
|
this.componentDVListener = new ComponentDynamicValueWatcher(this, opt.em); |
|
|
this.componentDVListener.watchComponentDef(props); |
|
|
this.componentDVListener.watchComponentDef(props); |
|
|
|
|
|
|
|
|
@ -295,7 +295,7 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
this.opt = opt; |
|
|
this.opt = opt; |
|
|
this.em = em!; |
|
|
this.em = em!; |
|
|
this.config = opt.config || {}; |
|
|
this.config = opt.config || {}; |
|
|
this.set('attributes', { |
|
|
this.setAttributes({ |
|
|
...(result(this, 'defaults').attributes || {}), |
|
|
...(result(this, 'defaults').attributes || {}), |
|
|
...(this.get('attributes') || {}), |
|
|
...(this.get('attributes') || {}), |
|
|
}); |
|
|
}); |
|
|
@ -343,7 +343,7 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
optionsOrUndefined?: ComponentSetOptions, |
|
|
optionsOrUndefined?: ComponentSetOptions, |
|
|
): this { |
|
|
): this { |
|
|
let attributes: Partial<ComponentProperties>; |
|
|
let attributes: Partial<ComponentProperties>; |
|
|
let options: ComponentSetOptions = { skipWatcherUpdates: false }; |
|
|
let options: ComponentSetOptions = { skipWatcherUpdates: false, fromDataSource: false }; |
|
|
if (typeof keyOrAttributes === 'object') { |
|
|
if (typeof keyOrAttributes === 'object') { |
|
|
attributes = keyOrAttributes; |
|
|
attributes = keyOrAttributes; |
|
|
options = valueOrOptions || (options as ComponentSetOptions); |
|
|
options = valueOrOptions || (options as ComponentSetOptions); |
|
|
@ -360,11 +360,14 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
if (areStaticAttributes) { |
|
|
if (areStaticAttributes) { |
|
|
evaluatedAttributes = attributes; |
|
|
evaluatedAttributes = attributes; |
|
|
} else { |
|
|
} else { |
|
|
evaluatedAttributes = ComponentDynamicValueWatcher.evaluateComponentDef(attributes, this.em); |
|
|
// @ts-ignore
|
|
|
|
|
|
const em = this.em || options.em; |
|
|
|
|
|
evaluatedAttributes = ComponentDynamicValueWatcher.evaluateComponentDef(attributes, em); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!options.skipWatcherUpdates) { |
|
|
const shouldSkipWatcherUpdates = options.skipWatcherUpdates || options.fromDataSource; |
|
|
this.componentDVListener?.watchProps(attributes); |
|
|
if (!shouldSkipWatcherUpdates) { |
|
|
|
|
|
this.componentDVListener?.addProps(attributes); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return super.set(evaluatedAttributes, options); |
|
|
return super.set(evaluatedAttributes, options); |
|
|
@ -687,9 +690,12 @@ export default class Component extends StyleableModel<ComponentProperties> { |
|
|
* @example |
|
|
* @example |
|
|
* component.setAttributes({ id: 'test', 'data-key': 'value' }); |
|
|
* component.setAttributes({ id: 'test', 'data-key': 'value' }); |
|
|
*/ |
|
|
*/ |
|
|
setAttributes(attrs: ObjectAny, opts: SetAttrOptions = { skipWatcherUpdates: false }) { |
|
|
setAttributes(attrs: ObjectAny, opts: SetAttrOptions = { skipWatcherUpdates: false, fromDataSource: false }) { |
|
|
const evaluatedAttributes = DynamicValueWatcher.getStaticValues(attrs, this.em); |
|
|
// @ts-ignore
|
|
|
if (!opts.skipWatcherUpdates) { |
|
|
const em = this.em || opts.em; |
|
|
|
|
|
const evaluatedAttributes = DynamicValueWatcher.getStaticValues(attrs, em); |
|
|
|
|
|
const shouldSkipWatcherUpdates = opts.skipWatcherUpdates || opts.fromDataSource; |
|
|
|
|
|
if (!shouldSkipWatcherUpdates) { |
|
|
this.componentDVListener.setAttributes(attrs); |
|
|
this.componentDVListener.setAttributes(attrs); |
|
|
} |
|
|
} |
|
|
this.set('attributes', { ...evaluatedAttributes }, opts); |
|
|
this.set('attributes', { ...evaluatedAttributes }, opts); |
|
|
|