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.

52 lines (51 loc) 1.63 kB
import Quill from "quill"; import { MENTION_CHAR, DEFAULT_MENTION_CHAR, ON_MENTION_LINK_REMOVE } from "./constants.es.js"; const Embed = Quill.import("blots/embed"); class MentionLink extends Embed { static create(data) { let node; if (data.link) { node = document.createElement("a"); node.setAttribute("href", data.link); node.setAttribute("target", data.target); } else { node = document.createElement(this.tagName); } node.classList.add(this.className); node.dataset.mentionId = data.name || data.mention && data.mention[data.searchKey || "name"] || ""; node.setAttribute("title", data.text); node.setAttribute(MENTION_CHAR, data.char); node.textContent = data.char + data.text; return node; } static value(domNode) { const value = { char: domNode.getAttribute(MENTION_CHAR) || DEFAULT_MENTION_CHAR, text: domNode.getAttribute("title"), name: domNode.dataset.mentionId }; if (domNode.tagName.toLowerCase() === "a" && domNode.hasAttribute("href")) { value.link = domNode.getAttribute("href"); value.target = domNode.getAttribute("target"); } return value; } constructor(scroll, domNode, data) { super(scroll, domNode); this.mentionData = data; } value() { return super.value(); } remove() { this.scroll.emitter.emit(ON_MENTION_LINK_REMOVE, this.mentionData); return super.remove(); } } MentionLink.blotName = "mention"; MentionLink.tagName = "span"; MentionLink.className = "ql-mention-link"; export { MentionLink as default }; //# sourceMappingURL=MentionLink.es.js.map