@cairn214/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.
95 lines (94 loc) • 2.86 kB
JavaScript
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Quill = require("quill");
const editor_utils = require("../../config/editor.utils.cjs.js");
const tableConfig = require("../table-config.cjs.js");
const Block = Quill.imports["blots/block"];
class Header extends Block {
static create(value) {
if (typeof value === "string") {
value = { value };
}
const node = super.create(value.value);
tableConfig.CELL_IDENTITY_KEYS.forEach((key) => {
if (value[key]) {
node.setAttribute(`data-${key}`, value[key]);
}
});
tableConfig.CELL_ATTRIBUTES.forEach((key) => {
if (value[key]) {
node.setAttribute(`data-${key}`, value[key]);
}
});
return node;
}
static formats(domNode) {
const formats = {};
formats.value = this.tagName.indexOf(domNode.tagName) + 1;
return tableConfig.CELL_ATTRIBUTES.concat(tableConfig.CELL_IDENTITY_KEYS).reduce((tableFormats, attribute) => {
if (domNode.hasAttribute(`data-${attribute}`)) {
tableFormats[attribute] = domNode.getAttribute(`data-${attribute}`) || void 0;
}
return tableFormats;
}, formats);
}
format(name, value) {
if (Object.prototype.toString.call(value) === "[object Object]") {
value = value.value;
}
const headerDom = Header.formats(this.domNode);
const { row, cell, rowspan, colspan } = headerDom;
if (name === Header.blotName) {
if (value) {
super.format(name, {
value,
row,
cell,
rowspan,
colspan
});
} else {
if (row) {
this.replaceWith("table-cell-line", {
row,
cell,
rowspan,
colspan
});
} else {
super.format(name, value);
}
}
} else {
super.format(name, value);
}
}
optimize(_context) {
const { row, cell, rowspan, colspan } = Header.formats(this.domNode);
if (row && this.parent.statics.blotName !== "table") {
this.wrap("table", {
row,
cell,
colspan,
rowspan
});
}
this.enforceAllowedChildren();
if (!editor_utils.isNullOrUndefined(this.uiNode) && this.uiNode !== this.domNode.firstChild) {
this.domNode.insertBefore(this.uiNode, this.domNode.firstChild);
}
if (this.children.length === 0) {
if (!editor_utils.isNullOrUndefined(this.statics.defaultChild)) {
const child = this.scroll.create(this.statics.defaultChild.blotName);
this.appendChild(child);
} else {
this.remove();
}
}
this.cache = {};
}
}
Header.blotName = "header";
Header.tagName = ["H1", "H2", "H3", "H4", "H5", "H6"];
exports.default = Header;
//# sourceMappingURL=header.cjs.js.map
;