UNPKG

@opentiny/fluent-editor

Version:

A rich text editor based on Quill 2.0, which extends rich modules and formats on the basis of Quill. It's powerful and out-of-the-box.

43 lines (42 loc) 1.33 kB
import Quill from "quill"; import { ON_DOC_LINK_REMOVE } from "../constants.es.js"; const Embed = Quill.imports["blots/embed"]; class DocumentLink extends Embed { static create(value) { const node = super.create(value); node.setAttribute("href", value.link); node.setAttribute("title", value.text); node.setAttribute("target", "_blank"); node.setAttribute("icon-link", value.icon); const icon = document.createElement("span"); icon.classList.add("ql-doc-link-icon"); icon.style.background = `url(${value.icon}) no-repeat center`; icon.style.backgroundSize = "contain"; node.insertAdjacentElement("afterbegin", icon); const text = document.createTextNode(value.text); node.appendChild(text); return node; } static value(domNode) { return { link: domNode.getAttribute("href"), icon: domNode.getAttribute("icon-link"), text: domNode.textContent }; } constructor(scroll, domNode, data) { super(scroll, domNode, data); this.docData = data; } remove() { this.scroll.emitter.emit(ON_DOC_LINK_REMOVE, this.docData); return super.remove(); } } DocumentLink.blotName = "doc-link"; DocumentLink.tagName = "A"; DocumentLink.className = "ql-doc-link"; export { DocumentLink as default }; //# sourceMappingURL=doc-link.es.js.map