UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

41 lines (40 loc) 1.33 kB
/** * DevExtreme (esm/__internal/ui/html_editor/converters/m_delta.js) * Version: 25.2.5 * Build date: Fri Feb 20 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import ConverterController from "../m_converterController"; class DeltaConverter { constructor() { this.quillInstance = null } setQuillInstance(quillInstance) { this.quillInstance = quillInstance } toHtml() { if (!this.quillInstance) { return } return this._isQuillEmpty() ? "" : this.quillInstance.getSemanticHTML(0, this.quillInstance.getLength() + 1) } _isQuillEmpty() { if (!this.quillInstance) { return true } const delta = this.quillInstance.getContents(); return 1 === delta.length() && DeltaConverter._isDeltaEmpty(delta) } static _isDeltaEmpty(delta) { return delta.reduce(((_, operation) => { if ("string" === typeof operation.insert) { return operation.insert.includes("\n") } return false }), false) } } ConverterController.addConverter("delta", DeltaConverter); export default DeltaConverter;