UNPKG

on-codemerge

Version:

A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product

69 lines (68 loc) 2.14 kB
var h = Object.defineProperty; var u = (t, e, s) => e in t ? h(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s; var a = (t, e, s) => u(t, typeof e != "symbol" ? e + "" : e, s); class d { constructor() { a(this, "plugins", /* @__PURE__ */ new Map()); } /** * Регистрирует новый плагин * @param plugin Плагин для регистрации * @throws Ошибка, если плагин с таким именем уже зарегистрирован */ register(e) { if (this.plugins.has(e.name)) throw new Error(`Plugin ${e.name} is already registered`); this.plugins.set(e.name, e); } /** * Удаляет плагин по его имени * @param pluginName Имя плагина для удаления */ unregister(e) { const s = this.plugins.get(e); s != null && s.destroy && s.destroy(), this.plugins.delete(e); } /** * Возвращает плагины */ getPlugins() { return this.plugins; } getHotkeys() { const e = {}, s = {}; return this.plugins.forEach((g, r) => { const o = r.charAt(0).toUpperCase() + r.slice(1) + " Plugin", c = g.hotkeys ?? []; for (const l in c) { const i = c[l], n = i.keys; s[n] ? console.warn( `Hotkey conflict: The key combination "${n}" is already used for the command "${s[n]}".` ) : s[n] = i.command, e[o] || (e[o] = []), e[o].push({ command: i.command, description: i.description, icon: i.icon, keys: i.keys }); } }), e; } /** * Возвращает плагин по его имени * @param pluginName Имя плагина * @returns Плагин или undefined, если плагин не найден */ getPlugin(e) { return this.plugins.get(e); } /** * Уничтожает все зарегистрированные плагины */ destroy() { for (const [e, s] of this.plugins) s.destroy && s.destroy(); this.plugins.clear(); } } export { d as DefaultPluginManager };