| 48 | const eventsUp = `${CanvasEvents.refresh} frame:scroll ${ComponentsEvents.update}`; |
| 49 | |
| 50 | export default class RichTextEditorModule extends Module<RichTextEditorConfig & { pStylePrefix?: string }> { |
| 51 | pfx: string; |
| 52 | toolbar!: HTMLElement; |
| 53 | globalRte?: RichTextEditor; |
| 54 | actionbar?: HTMLElement; |
| 55 | lastEl?: HTMLElement; |
| 56 | actions?: (RichTextEditorAction | string)[]; |
| 57 | customRte?: CustomRTE; |
| 58 | model: Model<ModelRTE>; |
| 59 | __dbdTrgCustom: Debounced; |
| 60 | events = RichTextEditorEvents; |
| 61 | |
| 62 | /** |
| 63 | * Get configuration object |
| 64 | * @name getConfig |
| 65 | * @function |
| 66 | * @return {Object} |
| 67 | */ |
| 68 | |
| 69 | constructor(em: EditorModel) { |
| 70 | super(em, 'RichTextEditor', defConfig()); |
| 71 | const { config } = this; |
| 72 | const ppfx = config.pStylePrefix; |
| 73 | |
| 74 | if (ppfx) { |
| 75 | config.stylePrefix = ppfx + config.stylePrefix; |
| 76 | } |
| 77 | |
| 78 | this.pfx = config.stylePrefix!; |
| 79 | this.actions = config.actions || []; |
| 80 | const model = new Model(); |
| 81 | this.model = model; |
| 82 | model.on('change:currentView', this.__trgCustom, this); |
| 83 | this.__dbdTrgCustom = debounce(() => this.__trgCustom(), 0); |
| 84 | } |
| 85 | |
| 86 | onLoad() { |
| 87 | if (!hasWin()) return; |
| 88 | const { config } = this; |
| 89 | const ppfx = config.pStylePrefix; |
| 90 | const isCustom = config.custom; |
| 91 | const toolbar = createEl('div', { |
| 92 | class: cx(`${ppfx}rte-toolbar`, !isCustom && `${ppfx}one-bg ${ppfx}rte-toolbar-ui`), |
| 93 | }); |
| 94 | this.toolbar = toolbar; |
| 95 | this.initRte(createEl('div')); |
| 96 | |
| 97 | //Avoid closing on toolbar clicking |
| 98 | on(toolbar, 'mousedown', (e) => e.stopPropagation()); |
| 99 | } |
| 100 | |
| 101 | __trgCustom() { |
| 102 | const { model, em, events } = this; |
| 103 | em.trigger(events.custom, { |
| 104 | enabled: !!model.get('currentView'), |
| 105 | container: this.getToolbarEl(), |
| 106 | actions: this.getAll(), |
| 107 | }); |
nothing calls this directly
no outgoing calls
no test coverage detected