From cef42658cab9a530b1f8ce006b0c2ef1983cac93 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 18 Nov 2021 06:34:30 +0100 Subject: [PATCH] Support partial in properties --- src/domain_abstract/model/Styleable.js | 4 +- src/style_manager/index.js | 83 ++++++++++++++------------ src/style_manager/model/Property.js | 9 +-- 3 files changed, 51 insertions(+), 45 deletions(-) diff --git a/src/domain_abstract/model/Styleable.js b/src/domain_abstract/model/Styleable.js index fc12aabc2..80a5e636d 100644 --- a/src/domain_abstract/model/Styleable.js +++ b/src/domain_abstract/model/Styleable.js @@ -46,8 +46,8 @@ export default { const em = this.em; this.trigger(`change:style:${pr}`); if (em) { - em.trigger(`styleable:change`, this, pr); - em.trigger(`styleable:change:${pr}`, this, pr); + em.trigger(`styleable:change`, this, pr, opts); + em.trigger(`styleable:change:${pr}`, this, pr, opts); } }); diff --git a/src/style_manager/index.js b/src/style_manager/index.js index 439d9db0c..6e914d686 100644 --- a/src/style_manager/index.js +++ b/src/style_manager/index.js @@ -102,12 +102,12 @@ export default () => { properties = new Properties(); sectors = new Sectors([], c); this.model = new Model({ targets: [] }); - const toListen = + const ev = 'component:toggled component:update:classes change:state change:device frame:resized selector:type styleable:change'; this.model.listenTo( em, - toListen, - debounce((...args) => { + ev, + debounce(() => { this.select(em.getSelectedAll()); this.__trgCustom(); }) @@ -493,46 +493,13 @@ export default () => { const lastTarget = targets.slice().reverse()[0]; const lastTargetParents = this.getParentRules(lastTarget); this.model.set({ targets, lastTarget, lastTargetParents }); - - // Update all property values - if (lastTarget && em.getConfig('customUI')) { - const style = lastTarget.getStyle(); - const parentStyles = lastTargetParents.map(p => ({ - target: p, - style: p.getStyle() - })); - - sectors.map(sector => { - sector.getProperties().map(prop => { - const name = prop.getName(); - const value = style[name]; - const hasVal = propDef(value); - let newValue = hasVal ? value : null; - let parentTarget = null; - - if (!hasVal) { - newValue = null; - const parentItem = parentStyles.filter(p => - propDef(p.style[name]) - )[0]; - - if (parentItem) { - newValue = parentItem.style[name]; - parentTarget = parentItem.target; - } - } - - prop.__setParentTarget(parentTarget); - prop.upValue(newValue, { __up: true }); - }); - }); - } + this.__upProps(opts); return targets; }, - addStyleTargets(style) { - this.getSelected().map(t => t.addStyle(style)); + addStyleTargets(style, opts) { + this.getSelected().map(t => t.addStyle(style, opts)); }, getSelected() { @@ -572,6 +539,44 @@ export default () => { em && em.logWarning(`'${sectorId}' sector not found`); }, + __upProps(opts) { + const lastTarget = this.getLastSelected(); + if (!lastTarget || !this.em.getConfig('customUI')) return; + + const lastTargetParents = this.getSelectedParents(); + const style = lastTarget.getStyle(); + const parentStyles = lastTargetParents.map(p => ({ + target: p, + style: p.getStyle() + })); + + sectors.map(sector => { + sector.getProperties().map(prop => { + const name = prop.getName(); + const value = style[name]; + const hasVal = propDef(value); + let newValue = hasVal ? value : null; + let parentTarget = null; + + if (!hasVal) { + newValue = null; + const parentItem = parentStyles.filter(p => + propDef(p.style[name]) + )[0]; + + if (parentItem) { + newValue = parentItem.style[name]; + parentTarget = parentItem.target; + } + } + + prop.__setParentTarget(parentTarget); + prop.getFullValue() !== newValue && + prop.upValue(newValue, { ...opts, __up: true }); + }); + }); + }, + destroy() { [properties, sectors].forEach(coll => { coll.reset(); diff --git a/src/style_manager/model/Property.js b/src/style_manager/model/Property.js index 0883e777b..2a943bc4c 100644 --- a/src/style_manager/model/Property.js +++ b/src/style_manager/model/Property.js @@ -30,13 +30,14 @@ export default class Property extends Model { }, {}); sm.__trgEv(sm.events.propertyUpdate, { property: this, from, to }); - !opts.__up && sm.addStyleTargets({ [name]: value }); + !opts.__up && + sm.addStyleTargets({ [name]: value, __p: !!opts.avoidStore }, opts); } _up(props, opts = {}) { - const { preview, ...rest } = opts; - props.__p = preview; - return this.set(props, { ...rest, avoidStore: !!preview }); + const { partial, ...rest } = opts; + props.__p = !!partial; + return this.set(props, { ...rest, avoidStore: !!partial }); } init() {}