@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.
73 lines (72 loc) • 2.61 kB
JavaScript
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Quill = require("quill");
function FormatPainter() {
if (!this.formatPainter) {
this.formatPainter = {
rangeFormat: {},
isFormatterLock: false,
isFormating: false,
prepareLock: false
};
}
const [, formatterBtn] = this.controls.find(([name]) => name === FormatPainter.toolName);
const formatRange = (range) => {
var _a, _b, _c, _d;
if (!range) return;
const currentFormats = this.quill.getFormat(range);
for (const format in currentFormats) {
if ((_b = (_a = this.quill.options["format-painter"]) == null ? void 0 : _a.ignoreFormat) == null ? void 0 : _b.includes(format)) continue;
this.quill.format(format, null, Quill.sources.USER);
}
for (const format in this.formatPainter.rangeFormat) {
if ((_d = (_c = this.quill.options["format-painter"]) == null ? void 0 : _c.ignoreFormat) == null ? void 0 : _d.includes(format)) continue;
this.quill.format(format, this.formatPainter.rangeFormat[format], Quill.sources.USER);
}
if (!this.formatPainter.isFormatterLock) {
unbindFormatSelect();
} else {
btnActive();
}
};
const btnActive = () => {
setTimeout(() => {
formatterBtn.classList.add("ql-active");
}, 0);
};
const btnRemoveActive = () => {
setTimeout(() => {
formatterBtn.classList.remove("ql-active");
}, 0);
};
const bindFormatSelect = () => {
const range = this.quill.getSelection();
if (range.length === 0) return;
this.formatPainter.rangeFormat = this.quill.getFormat(range);
this.formatPainter.isFormating = true;
this.quill.on(Quill.events.SELECTION_CHANGE, formatRange);
btnActive();
};
const unbindFormatSelect = () => {
this.quill.off(Quill.events.SELECTION_CHANGE, formatRange);
this.formatPainter.rangeFormat = {};
btnRemoveActive();
this.formatPainter.isFormating = false;
this.formatPainter.isFormatterLock = false;
};
if (this.formatPainter.isFormatterLock || this.formatPainter.isFormating && !this.formatPainter.prepareLock) {
unbindFormatSelect();
} else if (this.formatPainter.isFormating && this.formatPainter.prepareLock) {
this.formatPainter.isFormatterLock = true;
btnActive();
} else {
this.formatPainter.prepareLock = true;
setTimeout(() => {
this.formatPainter.prepareLock = false;
}, 200);
bindFormatSelect();
}
}
FormatPainter.toolName = "format-painter";
exports.FormatPainter = FormatPainter;
//# sourceMappingURL=format-painter.cjs.js.map