@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.
53 lines (52 loc) • 1.44 kB
JavaScript
import Quill from "quill";
import { sanitize } from "../config/editor.utils.es.js";
const BlockEmbed = Quill.imports["blots/block/embed"];
const VIDEO_ATTRIBUTES = ["id", "title", "src"];
class Video extends BlockEmbed {
static sanitize(url) {
return sanitize(url, this.PROTOCOL_WHITELIST) ? url : this.SANITIZED_URL;
}
static create(value) {
const node = super.create(value);
node.setAttribute("contenteditable", "false");
node.setAttribute("controls", "controls");
VIDEO_ATTRIBUTES.forEach((key) => {
if (value[key]) {
switch (key) {
case "src": {
const src = Video.sanitize(value[key]);
node.setAttribute(key, src);
break;
}
case "title": {
node.setAttribute(key, value[key]);
break;
}
default: {
node.dataset[key] = value[key];
}
}
}
});
return node;
}
static value(domNode) {
const formats = {};
VIDEO_ATTRIBUTES.forEach((key) => {
const value = domNode.getAttribute(key) || domNode.dataset[key];
if (value) {
formats[key] = value;
}
});
return formats;
}
}
Video.blotName = "video";
Video.tagName = "VIDEO";
Video.SANITIZED_URL = "about:blank";
Video.PROTOCOL_WHITELIST = ["http", "https"];
Video.className = "ql-video-item";
export {
Video as default
};
//# sourceMappingURL=video.es.js.map