UNPKG

@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.

166 lines (165 loc) 5.05 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const I18n = require("quill-i18n"); const is = require("../../utils/is.cjs.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.on(I18n.I18N_LOCALE_CHANGE, () => { this.destroyAllTips(); this.options = this.resolveOptions(options); this.createToolbarTip(); }); } resolveOptions(options) { const result = super.resolveOptions(options); if (!this.quill.lang) return result; const shortKeyMap = { "bold": "Ctrl + B", "italic": "Ctrl + I", "underline": "Ctrl + U", "strike": "Ctrl + D", "clean": "Ctrl + /", "align-left": "Alt + L", "align-center": "Alt + C", "align-right": "Alt + R", "align-justify": "Alt + J", "indent-+1": "Ctrl + ]", "indent--1": "Ctrl + [", "script-sub": "Ctrl + ;", "script-super": "Ctrl + '", "code": "Ctrl + E", "direction-rtl": "Ctrl + R", "direction-ltr": "Ctrl + L", "undo": "Ctrl + Z", "redo": "Ctrl + shift + Z", "color": "Ctrl + Alt + C", "background": "Ctrl + Alt + B", "link": "Ctrl + K" }; const shortcutModule = this.quill.getModule("shortcut-key"); const getShortKey = (name) => { if (!shortcutModule) return ""; const shortKey = shortKeyMap[name]; return shortKey ? ` ${shortKey}` : ""; }; const btnTips = [ "color", "background", "bold", "italic", "strike", "underline", "undo", "redo", "clean", "link", "divider", "blockquote", "code", "image", "file", "emoji", "video", "screenshot", "code-block", "formula", "format-painter", "header-list", "table-up" ].reduce((map, name) => { map[name] = this.quill.getLangText(name) + getShortKey(name); return map; }, {}); const selectTips = [ "font", "size", "line-height" ].reduce((map, name) => { map[name] = { onShow: () => { return this.quill.getLangText(name) + getShortKey(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}`) + getShortKey(`${name}-${value}`); } }; return map; }, {}); const textMap = { ...btnTips, ...valueControlTips, ...selectTips, fullscreen: { onShow: () => { return this.quill.getLangText(this.quill.isFullscreen ? "exit-fullscreen" : "fullscreen"); } } }; const inputTipTextMap = Object.entries(options.tipTextMap).reduce((pre, [key, value]) => { if (is.isString(value)) { pre[key] = { msg: this.quill.getLangText(value) }; } else if (value && is.isObject(value)) { const isNewConfig = "values" in value || "onShow" in value || "msg" in value || "content" in value; if (!isNewConfig) { pre[key] = { values: Object.fromEntries( Object.entries(value).map(([k, v]) => [k, is.isString(v) ? this.quill.getLangText(v) : v]) ) }; } else { const config = { ...value }; if (is.isString(config.msg)) config.msg = this.quill.getLangText(config.msg); if (is.isString(config.content)) config.content = this.quill.getLangText(config.content); if (config.values) { config.values = Object.fromEntries( Object.entries(config.values).map(([k, v]) => [k, is.isString(v) ? this.quill.getLangText(v) : v]) ); } pre[key] = config; } } else { pre[key] = value; } return pre; }, {}); return { ...result, tipTextMap: { ...textMap, ...inputTipTextMap } }; } }; } exports.generateToolbarTip = generateToolbarTip; //# sourceMappingURL=toolbar-tip.cjs.js.map