Browse Source

Add `parseContent` option to customRTE

pull/5649/head
Artur Arseniev 3 years ago
parent
commit
7f32069212
  1. 2
      src/dom_components/view/ComponentTextView.ts
  2. 4
      src/editor/index.ts
  3. 27
      src/rich_text_editor/index.ts

2
src/dom_components/view/ComponentTextView.ts

@ -151,7 +151,7 @@ export default class ComponentTextView extends ComponentView {
// If there is a custom RTE the content is just baked staticly
// inside 'content'
if (rte?.customRte) {
if (rte?.customRte && !rte.customRte.parseContent) {
comps.length && comps.reset(undefined, opts);
model.set('content', content, contentOpt);
} else {

4
src/editor/index.ts

@ -78,7 +78,7 @@ import PageManager from '../pages';
import PanelManager from '../panels';
import ParserModule from '../parser';
import { CustomParserCss } from '../parser/config/config';
import RichTextEditorModule, { RichTextEditorEvent } from '../rich_text_editor';
import RichTextEditorModule, { CustomRTE, RichTextEditorEvent } from '../rich_text_editor';
import SelectorManager, { SelectorEvent } from '../selector_manager';
import StorageManager, { StorageEvent } from '../storage_manager';
import { ProjectData } from '../storage_manager/model/IStorage';
@ -649,7 +649,7 @@ export default class Editor implements IBaseModule<EditorConfig> {
* }
* });
*/
setCustomRte(obj: any) {
setCustomRte<T>(obj: CustomRTE & ThisType<T & CustomRTE>) {
this.RichTextEditor.customRte = obj;
}

27
src/rich_text_editor/index.ts

@ -49,9 +49,32 @@ export type RichTextEditorEvent = 'rte:enable' | 'rte:disable';
const eventsUp = 'change:canvasOffset frame:scroll component:update';
export interface CustomRTE<T = any> {
enable: (el: HTMLElement, rte: T) => T;
disable: (el: HTMLElement, rte: T) => T;
/**
* If true, the returned HTML content will be parsed into Components, allowing
* the custom RTE to behave in the same way as the native one.
* If false, the HTML content will be used as it is in the canvas and the export code.
*/
parseContent?: boolean;
/**
* Create or enable the custom RTE.
*/
enable: (el: HTMLElement, rte: T) => T | Promise<T>;
/**
* Disable the custom RTE.
*/
disable: (el: HTMLElement, rte: T) => any | Promise<any>;
/**
* Get HTML content from the custom RTE.
* If not specified, it will use the innerHTML of the element.
*/
getContent?: () => string;
/**
* Destroy the custom RTE.
* Will be triggered on editor destroy.
*/
destroy?: () => void;
[key: string]: unknown;
}
export default class RichTextEditorModule extends Module<RichTextEditorConfig & { pStylePrefix?: string }> {

Loading…
Cancel
Save