@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.
109 lines (108 loc) • 2.73 kB
JavaScript
import "../../config/index.es.js";
import { CHANGE_LANGUAGE_EVENT } from "../../config/editor.config.es.js";
function generateToolbarTip(QuillToolbarTip) {
return class extends QuillToolbarTip {
constructor(quill, options) {
if (!(options == null ? void 0 : options.tipTextMap)) {
options.tipTextMap = {};
}
super(quill, options);
this.quill = quill;
this.quill.emitter.on(CHANGE_LANGUAGE_EVENT, () => {
this.destroyAllTips();
this.options = this.resolveOptions(options);
this.createToolbarTip();
});
}
resolveOptions(options) {
const result = super.resolveOptions(options);
if (!this.quill.lang) return result;
const btnTips = [
"bold",
"italic",
"strike",
"underline",
"undo",
"redo",
"clean",
"link",
"divider",
"blockquote",
"code",
"image",
"file",
"emoji",
"video",
"screenshot",
"better-table",
"code-block",
"formula",
"format-painter",
"header-list"
].reduce((map, name) => {
map[name] = this.quill.getLangText(name);
return map;
}, {});
const selectTips = [
"color",
"background",
"font",
"size",
"lineheight"
].reduce((map, name) => {
map[name] = {
onShow: () => {
return this.quill.getLangText(name);
}
};
return map;
}, {});
const valueControlTips = [
"list",
"align",
"script",
"indent",
"header",
"direction"
].reduce((map, name) => {
map[name] = {
onShow: (target, value) => {
if (name === "direction") {
value = target.classList.contains("ql-active") ? "rtl" : "ltr";
}
if (!value) {
if (name === "align") {
value = "left";
} else if (name === "header") {
value = "normal";
}
}
return this.quill.getLangText(`${name}-${value}`);
}
};
return map;
}, {});
const textMap = {
...btnTips,
...valueControlTips,
...selectTips,
fullscreen: {
onShow: () => {
return this.quill.getLangText(this.quill.isFullscreen ? "exit-fullscreen" : "fullscreen");
}
}
};
return {
...result,
tipTextMap: {
...textMap,
...options.tipTextMap
}
};
}
};
}
export {
generateToolbarTip
};
//# sourceMappingURL=toolbar-tip.es.js.map