Browse Source

Make use of HTMLGeneratorBuildOptions

pull/4849/head
Artur Arseniev 4 years ago
parent
commit
a0a13628fc
  1. 13
      src/code_manager/model/HtmlGenerator.ts
  2. 6
      src/editor/config/config.ts
  3. 2
      src/editor/index.ts
  4. 3
      src/editor/model/Editor.ts

13
src/code_manager/model/HtmlGenerator.ts

@ -2,14 +2,21 @@ import { Model } from '../../common';
import Component from '../../dom_components/model/Component';
import EditorModel from '../../editor/model/Editor';
type HTMLGeneratorBuildOptions = {
em?: EditorModel;
export type HTMLGeneratorBuildOptions = {
/**
* Remove unnecessary IDs (eg. those created automatically).
*/
cleanId?: boolean;
/**
* You can pass an object of custom attributes to replace with the current ones
* or you can even pass a function to generate attributes dynamically.
*/
attributes?: Record<string, any> | ((component: Component, attr: Record<string, any>) => Record<string, any>);
};
export default class HTMLGenerator extends Model {
build(model: Component, opts: HTMLGeneratorBuildOptions = {}) {
build(model: Component, opts: HTMLGeneratorBuildOptions & { em?: EditorModel } = {}) {
const { em, ...restOpts } = opts;
const htmlOpts = restOpts;

6
src/editor/config/config.ts

@ -19,6 +19,7 @@ import { TraitManagerConfig } from '../../trait_manager/config/config';
import { CommandsConfig } from '../../commands/config/config';
import { StyleManagerConfig } from '../../style_manager/config/config';
import { DomComponentsConfig } from '../../dom_components/config/config';
import { HTMLGeneratorBuildOptions } from '../../code_manager/model/HtmlGenerator';
type AnyObject = Record<string, any>;
@ -225,12 +226,13 @@ export interface EditorConfig {
*/
multipleSelection?: boolean;
// TODO
/**
* Pass default available options wherever `editor.getHtml()` is called.
* @default {}
*/
optsHtml?: Record<string, any>;
optsHtml?: HTMLGeneratorBuildOptions;
// TODO
/**
* Pass default available options wherever `editor.getCss()` is called
* @default {}

2
src/editor/index.ts

@ -218,7 +218,7 @@ export default class EditorModule implements IBaseModule<EditorConfig> {
* @param {Boolean} [opts.cleanId=false] Remove unnecessary IDs (eg. those created automatically)
* @returns {string} HTML string
*/
getHtml(opts?: { component?: Component; cleanId?: boolean }) {
getHtml(opts?: EditorModelParam<'getHtml', 0>) {
return this.em.getHtml(opts);
}

3
src/editor/model/Editor.ts

@ -34,6 +34,7 @@ import RichTextEditorModule from '../../rich_text_editor';
import CommandsModule from '../../commands';
import StyleManager from '../../style_manager';
import CssRule from '../../css_composer/model/CssRule';
import { HTMLGeneratorBuildOptions } from '../../code_manager/model/HtmlGenerator';
export interface ProjectData {
[key: string]: any;
@ -768,7 +769,7 @@ export default class EditorModel extends Model {
* @returns {string} HTML string
* @public
*/
getHtml(opts: { component?: Component; cleanId?: boolean } = {}): string {
getHtml(opts: { component?: Component } & HTMLGeneratorBuildOptions = {}): string {
const { config } = this;
const { optsHtml } = config;
const js = config.jsInHtml ? this.getJs(opts) : '';

Loading…
Cancel
Save