Browse Source

Update Traits

pull/4160/head
Artur Arseniev 5 years ago
parent
commit
bcfe9f6e7a
  1. 4
      src/common/module.js
  2. 61
      src/trait_manager/index.js

4
src/common/module.js

@ -28,6 +28,7 @@ export default {
...conf, ...conf,
}; };
this.em = this.config.em; this.em = this.config.em;
this.cls = [];
}, },
__initListen(opts = {}) { __initListen(opts = {}) {
@ -116,5 +117,8 @@ export default {
coll.reset(); coll.reset();
}); });
this.em = 0; this.em = 0;
this.config = 0;
this.view?.remove();
this.view = 0;
}, },
}; };

61
src/trait_manager/index.js

@ -1,5 +1,4 @@
import { defaults, isElement } from 'underscore'; import defaults from './config/config';
import defaultOpts from './config/config';
import TraitsView from './view/TraitsView'; import TraitsView from './view/TraitsView';
import TraitView from './view/TraitView'; import TraitView from './view/TraitView';
import TraitSelectView from './view/TraitSelectView'; import TraitSelectView from './view/TraitSelectView';
@ -7,22 +6,32 @@ import TraitCheckboxView from './view/TraitCheckboxView';
import TraitNumberView from './view/TraitNumberView'; import TraitNumberView from './view/TraitNumberView';
import TraitColorView from './view/TraitColorView'; import TraitColorView from './view/TraitColorView';
import TraitButtonView from './view/TraitButtonView'; import TraitButtonView from './view/TraitButtonView';
import Module from 'common/module';
export const evAll = 'trait';
export const evPfx = `${evAll}:`;
export const evCustom = `${evPfx}custom`;
export default () => { export default () => {
let c = {};
let TraitsViewer;
const typesDef = { const typesDef = {
text: TraitView, text: TraitView,
number: TraitNumberView, number: TraitNumberView,
select: TraitSelectView, select: TraitSelectView,
checkbox: TraitCheckboxView, checkbox: TraitCheckboxView,
color: TraitColorView, color: TraitColorView,
button: TraitButtonView button: TraitButtonView,
}; };
return { return {
...Module,
TraitsView, TraitsView,
events: {
all: evAll,
custom: evCustom,
},
/** /**
* Name of the module * Name of the module
* @type {String} * @type {String}
@ -32,20 +41,19 @@ export default () => {
/** /**
* Get configuration object * Get configuration object
* @name getConfig
* @function
* @return {Object} * @return {Object}
* @private
*/ */
getConfig() {
return c;
},
/** /**
* Initialize module. Automatically called with a new instance of the editor * Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations * @param {Object} config Configurations
* @private
*/ */
init(config = {}) { init(config = {}) {
c = config; this.__initConfig(defaults, config);
defaults(c, defaultOpts); const c = this.config;
const ppfx = c.pStylePrefix; const ppfx = c.pStylePrefix;
this.types = { ...typesDef }; this.types = { ...typesDef };
ppfx && (c.stylePrefix = `${ppfx}${c.stylePrefix}`); ppfx && (c.stylePrefix = `${ppfx}${c.stylePrefix}`);
@ -53,12 +61,7 @@ export default () => {
}, },
postRender() { postRender() {
const elTo = this.getConfig().appendTo; this.__appendTo();
if (elTo) {
const el = isElement(elTo) ? elTo : document.querySelector(elTo);
el.appendChild(this.render());
}
}, },
/** /**
@ -67,7 +70,7 @@ export default () => {
* @private * @private
*/ */
getTraitsViewer() { getTraitsViewer() {
return TraitsViewer; return this.view;
}, },
/** /**
@ -98,21 +101,23 @@ export default () => {
}, },
render() { render() {
const el = TraitsViewer && TraitsViewer.el; let { view } = this;
TraitsViewer = new TraitsView({ const config = this.getConfig();
const el = view && view.el;
view = new TraitsView({
el, el,
collection: [], collection: [],
editor: c.em, editor: config.em,
config: c config,
}); });
TraitsViewer.itemsView = this.getTypes(); view.itemsView = this.getTypes();
TraitsViewer.updatedCollection(); view.updatedCollection();
return TraitsViewer.el; this.view = view;
return view.el;
}, },
destroy() { destroy() {
TraitsViewer && TraitsViewer.remove(); this.__destroy();
[c, TraitsViewer].forEach(i => (i = {})); },
}
}; };
}; };

Loading…
Cancel
Save