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

71 lines (70 loc) 2.66 kB
/*! on-codemerge v1.3.1 @author Pavel Kuzmin @license MIT @homepage https://s00d.github.io/on-codemerge/ @repository git+https://github.com/s00d/on-codemerge.git Copyright (c) 2026 Pavel Kuzmin - Built on 2026-07-02T13:39:17.947Z */ var u = Object.defineProperty; var l = (e, t, o) => t in e ? u(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o; var n = (e, t, o) => l(e, typeof t != "symbol" ? t + "" : t, o); /* empty css */ /* empty css */ import { ShortcutManager as c } from "./services/ShortcutManager.mjs"; import { ShortcutsMenu as d } from "./components/ShortcutsMenu.mjs"; import { createToolbarButton as m } from "../ToolbarPlugin/utils.mjs"; import g from "../../icons/shortcuts.svg.mjs"; class w { constructor() { n(this, "name", "shortcuts"); n(this, "editor", null); n(this, "shortcutManager"); n(this, "menu", null); n(this, "toolbarButton", null); this.shortcutManager = new c(); } initialize(t) { this.editor = t, this.menu = new d(t), this.addToolbarButton(), setTimeout(() => { this.setupShortcuts(); }, 1e3); } addToolbarButton() { var o, i; const t = (o = this.editor) == null ? void 0 : o.getToolbar(); t && (this.toolbarButton = m({ icon: g, title: (i = this.editor) == null ? void 0 : i.t("Keyboard Shortcuts"), onClick: () => { var r; return (r = this.menu) == null ? void 0 : r.show(); } }), t.appendChild(this.toolbarButton)); } setupShortcuts() { var o, i; const t = (o = this.editor) == null ? void 0 : o.getHotkeys(); t && (Object.entries(t).forEach(([r, h]) => { h.forEach((s) => { this.shortcutManager.register( s.command, s.keys, () => { var a; return (a = this.editor) == null ? void 0 : a.triggerEvent(s.command); }, s.description, r, s.keysMac ); }); }), (i = this.editor) == null || i.getContainer().addEventListener("keydown", (r) => { this.shortcutManager.handleKeyDown(r); })); } getShortcutManager() { return this.shortcutManager; } destroy() { var t; this.toolbarButton && this.toolbarButton.parentElement && this.toolbarButton.parentElement.removeChild(this.toolbarButton), (t = this.editor) == null || t.getContainer().removeEventListener("keydown", (o) => { this.shortcutManager.handleKeyDown(o); }), this.menu && this.menu.destroy(), this.shortcutManager.clear(), this.editor = null, this.menu = null, this.toolbarButton = null; } } export { w as ShortcutsPlugin };