/
OpenTraitManager.ts
70 lines (57 loc) · 1.83 KB
/
OpenTraitManager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { CommandObject } from './CommandAbstract';
import { $ } from '../../common';
export default {
run(editor, sender) {
this.sender = sender;
const em = editor.getModel();
const config = editor.Config;
const pfx = config.stylePrefix;
const tm = editor.TraitManager;
const confTm = tm.getConfig();
let panelC;
if (confTm.appendTo) return;
if (!this.$cn) {
this.$cn = $('<div></div>');
this.$cn2 = $('<div></div>');
this.$cn.append(this.$cn2);
this.$header = $('<div>').append(`<div class="${confTm.stylePrefix}header">${em.t('traitManager.empty')}</div>`);
this.$cn.append(this.$header);
if (confTm.custom) {
tm.__trgCustom({ container: this.$cn2.get(0) });
} else {
this.$cn2.append(`<div class="${pfx}traits-label">${em.t('traitManager.label')}</div>`);
this.$cn2.append(tm.render());
}
var panels = editor.Panels;
if (!panels.getPanel('views-container')) {
// @ts-ignore
panelC = panels.addPanel({ id: 'views-container' });
} else {
panelC = panels.getPanel('views-container');
}
panelC?.set('appendContent', this.$cn.get(0)).trigger('change:appendContent');
this.target = editor.getModel();
this.listenTo(this.target, 'component:toggled', this.toggleTm);
}
this.toggleTm();
},
/**
* Toggle Trait Manager visibility
* @private
*/
toggleTm() {
const sender = this.sender;
if (sender && sender.get && !sender.get('active')) return;
if (this.target.getSelectedAll().length === 1) {
this.$cn2.show();
this.$header.hide();
} else {
this.$cn2.hide();
this.$header.show();
}
},
stop() {
this.$cn2 && this.$cn2.hide();
this.$header && this.$header.hide();
},
} as CommandObject<{}, { [k: string]: any }>;