MCPcopy
hub / github.com/GrapesJS/grapesjs / RichTextEditorModule

Class RichTextEditorModule

packages/core/src/rich_text_editor/index.ts:50–409  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48const eventsUp = `${CanvasEvents.refresh} frame:scroll ${ComponentsEvents.update}`;
49
50export 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 });

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected