@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.
60 lines (59 loc) • 2.21 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Quill = require("quill");
const constants = require("./constants.cjs.js");
const Embed = Quill.import("blots/embed");
class MentionLink extends Embed {
constructor(scroll, domNode, data) {
super(scroll, domNode);
__publicField(this, "mentionData");
this.scroll = scroll;
this.mentionData = data;
}
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(constants.MENTION_CHAR, data.char);
node.textContent = data.char + data.text;
return node;
}
static value(domNode) {
const value = {
char: domNode.getAttribute(constants.MENTION_CHAR) || constants.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;
}
value() {
return super.value();
}
remove() {
this.scroll.emitter.emit(constants.ON_MENTION_LINK_REMOVE, this.mentionData);
return super.remove();
}
}
__publicField(MentionLink, "blotName");
__publicField(MentionLink, "tagName");
__publicField(MentionLink, "className");
MentionLink.blotName = "mention";
MentionLink.tagName = "span";
MentionLink.className = "ql-mention-link";
exports.MentionLink = MentionLink;
//# sourceMappingURL=mention-link.cjs.js.map