diff --git a/src/selector_manager/index.js b/src/selector_manager/index.js index 97b574367..4341629ca 100644 --- a/src/selector_manager/index.js +++ b/src/selector_manager/index.js @@ -47,6 +47,7 @@ */ import { isString, isElement, isObject, isArray } from 'underscore'; +import { isComponent, isRule } from 'utils/mixins'; import defaults from './config/config'; import Selector from './model/Selector'; import Selectors from './model/Selectors'; @@ -132,7 +133,14 @@ export default config => { select(value, opts = {}) { const targets = Array.isArray(value) ? value : [value]; const toSelect = this.em.get('StyleManager').setTarget(targets, opts); - const res = toSelect.map(sel => sel.getSelectorsString()); + const res = toSelect.map(sel => + isComponent(sel) + ? sel + : isRule(sel) && !sel.get('selectorsAdd') + ? sel + : sel.getSelectorsString() + ); + console.log({ res }); this.selectorTags.componentChanged({ targets: res }); return this; }, diff --git a/src/selector_manager/view/ClassTagsView.js b/src/selector_manager/view/ClassTagsView.js index f07f8adae..16f583aa5 100644 --- a/src/selector_manager/view/ClassTagsView.js +++ b/src/selector_manager/view/ClassTagsView.js @@ -209,17 +209,17 @@ export default Backbone.View.extend({ * @private */ componentChanged: debounce(function({ targets } = {}) { - const target = targets || this.getTarget(); + const trgs = targets || this.getTargets(); let validSelectors = []; - if (target) { - this.checkStates(); - validSelectors = this.getCommonSelectors({ targets }); + if (trgs && trgs.length) { + validSelectors = this.getCommonSelectors({ targets: trgs }); this.checkSync({ validSelectors }); } + this.checkStates(); this.collection.reset(validSelectors); - this.updateStateVis(target); + this.updateStateVis(trgs); }), getCommonSelectors({ targets, opts = {} } = {}) { diff --git a/src/utils/mixins.js b/src/utils/mixins.js index df1a08db3..0b516ac74 100644 --- a/src/utils/mixins.js +++ b/src/utils/mixins.js @@ -209,6 +209,8 @@ const getKeyChar = ev => String.fromCharCode(getKeyCode(ev)); const isEscKey = ev => getKeyCode(ev) === 27; const capitalize = str => str.charAt(0).toUpperCase() + str.substring(1); +const isComponent = obj => obj && obj.toHTML; +const isRule = obj => obj && obj.toCSS; export { on, @@ -229,5 +231,7 @@ export { getPointerEvent, getUnitFromValue, capitalize, - appendStyles + appendStyles, + isComponent, + isRule };