Browse Source

Update Selector docs

pull/3905/head
Artur Arseniev 5 years ago
parent
commit
99f168a0eb
  1. 1
      docs/.vuepress/config.js
  2. 35
      src/selector_manager/model/Selector.js

1
docs/.vuepress/config.js

@ -76,6 +76,7 @@ module.exports = {
['/api/device_manager', 'Device Manager'],
['/api/device', `${subDivider}Device`],
['/api/selector_manager', 'Selector Manager'],
['/api/selector', `${subDivider}Selector`],
['/api/css_composer', 'CSS Composer'],
['/api/css_rule', `${subDivider}CssRule`],
['/api/modal_dialog', 'Modal'],

35
src/selector_manager/model/Selector.js

@ -4,24 +4,23 @@ import { result, forEach, keys } from 'underscore';
const TYPE_CLASS = 1;
const TYPE_ID = 2;
/**
* @typedef Selector
* @property {String} name Selector name, eg. `my-class`
* @property {String} label Selector label, eg. `My Class`
* @property {Number} [type=1] Type of the selector. 1 (class) | 2 (id)
* @property {Boolean} [active=true] If not active, it's not selectable by the Style Manager.
* @property {Boolean} [private=false] If true, it can't be seen by the Style Manager, but it will be rendered in the canvas and in export code.
* @property {Boolean} [protected=false] If true, it can't be removed from the attacched component.
*/
export default class Selector extends Model {
defaults() {
return {
name: '',
label: '',
// Type of the selector
type: TYPE_CLASS,
// If not active it's not selectable by the style manager (uncheckboxed)
active: true,
// Can't be seen by the style manager, therefore even by the user
// Will be rendered only in export code
private: false,
// If true, can't be removed from the attacched element
protected: false
};
}
@ -55,24 +54,28 @@ export default class Selector extends Model {
}
/**
* Get full selector name
* @return {string}
* Get full selector name.
* @returns {String}
* @example
* // Given such selector: { name: 'my-selector', type: 2 }
* console.log(selector.getFullName());
* // -> `#my-selector`
*/
getFullName(opts = {}) {
const { escape } = opts;
const name = this.get('name');
let init = '';
let pfx = '';
switch (this.get('type')) {
case TYPE_CLASS:
init = '.';
pfx = '.';
break;
case TYPE_ID:
init = '#';
pfx = '#';
break;
}
return init + (escape ? escape(name) : name);
return pfx + (escape ? escape(name) : name);
}
toJSON(opts = {}) {

Loading…
Cancel
Save