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.

53 lines (52 loc) 2.25 kB
"use strict"; var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); const Quill = require("quill"); require("../config/index.cjs.js"); const enUs = require("../config/i18n/en-us.cjs.js"); const zhCn = require("../config/i18n/zh-cn.cjs.js"); const merge = require("../utils/merge.cjs.js"); const editor_config = require("../config/editor.config.cjs.js"); const LEGACY_I18N_KEY_REGEX = /^_i18n(?:"([^"]+)"|'([^']+)'|`([^`]+)`)$/; function resolveLegacyI18nKey(name) { const key = name.trim(); const matched = key.match(LEGACY_I18N_KEY_REGEX); if (!matched) return name; return matched[1] || matched[2] || matched[3] || name; } class FluentEditor extends Quill { constructor(container, options = {}) { if (!options.modules) options.modules = {}; if (!options.modules.i18n) options.modules.i18n = {}; const i18nOptions = options.modules.i18n; const defaultMessages = { "en-US": enUs.EN_US, "zh-CN": zhCn.ZH_CN }; const userMessages = i18nOptions.messages || {}; i18nOptions.messages = merge.merge({}, defaultMessages, userMessages); if (!i18nOptions.interpolate) { i18nOptions.interpolate = (template, params) => { return template.replaceAll(/\{\{([\w]+)\}\}/g, (match, key) => params[key] != null ? String(params[key]) : match); }; } super(container, options); __publicField(this, "isFullscreen", false); } static register(...args) { super.register(...args); } get lang() { const i18nModule = this.getModule("i18n"); return i18nModule ? i18nModule.getLocale() : editor_config.defaultLanguage; } getLangText(name, params, defaultValue) { const i18nModule = this.getModule("i18n"); if (!i18nModule) return name; return i18nModule.t(resolveLegacyI18nKey(name), params, defaultValue); } } exports.default = FluentEditor; //# sourceMappingURL=fluent-editor.cjs.js.map