devexpress-richedit
Version:
DevExpress Rich Text Editor is an advanced word-processing tool designed for working with rich text documents.
32 lines (31 loc) • 1.62 kB
JavaScript
import { FixedInterval } from "@devexpress/utils/lib/intervals/fixed";
import { HtmlMimeType } from "@devexpress/utils/lib/utils/mime-type";
import { RichUtils } from "../../../model/rich-utils";
import { HtmlExporter } from "./html-export";
import { Base64Utils } from "@devexpress/utils/lib/utils/base64";
export class HtmlDocumentExporter {
get modelManipulator() { return this.exportModelOptions.modelManager.modelManipulator; }
constructor(exportModelOptions, options) {
this.exportModelOptions = exportModelOptions;
this.options = options;
}
exportToBlob(callback) {
this.modelManipulator.picture.loader.ensureAllPicturesLoaded(this.options.ensurePictureLoadedTimeout, (_loaded) => {
callback(new Blob([this.exportAsString()], { type: HtmlMimeType }));
});
}
exportToBase64(callback) {
this.exportToBlob(blob => Base64Utils.fromBlobAsDataUrl(blob, base64 => {
const splitted = base64.split(',');
callback(splitted.length === 2 ? splitted[1] : '');
}));
}
exportAsString() {
const model = this.modelManipulator.model;
const subDocument = model.mainSubDocument;
const interval = new FixedInterval(0, model.mainSubDocument.getDocumentEndPosition());
const guidLabel = RichUtils.getCopyPasteGuidLabel({ sguid: this.sessionGuid, cguid: this.clientGuid });
const exporter = new HtmlExporter(this.exportModelOptions);
return exporter.getHtmlElementsByInterval(model, subDocument, interval, guidLabel).getHtmlString(true);
}
}