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.44 kB
JavaScript
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 r = (e, t, o) => l(e, typeof t != "symbol" ? t + "" : t, o);
/* empty css */
/* empty css */
import { ShortcutManager as m } from "./services/ShortcutManager.mjs";
import { ShortcutsMenu as d } from "./components/ShortcutsMenu.mjs";
import { createToolbarButton as c } from "../ToolbarPlugin/utils.mjs";
import g from "../../icons/shortcuts.svg.mjs";
class w {
constructor() {
r(this, "name", "shortcuts");
r(this, "editor", null);
r(this, "shortcutManager");
r(this, "menu", null);
r(this, "toolbarButton", null);
this.shortcutManager = new m();
}
initialize(t) {
this.menu = new d(t), this.editor = t, this.addToolbarButton(), setTimeout(() => {
this.setupShortcuts();
}, 1e3);
}
addToolbarButton() {
var o;
const t = document.querySelector(".editor-toolbar");
t && (this.toolbarButton = c({
icon: g,
title: (o = this.editor) == null ? void 0 : o.t("Keyboard Shortcuts"),
onClick: () => {
var n;
return (n = this.menu) == null ? void 0 : n.show();
}
}), t.appendChild(this.toolbarButton));
}
setupShortcuts() {
var o, n;
const t = (o = this.editor) == null ? void 0 : o.getHotkeys();
t && (Object.entries(t).map(([a, h]) => {
h.map((i) => {
this.shortcutManager.register(
i.keys,
() => {
var s;
return (s = this.editor) == null ? void 0 : s.triggerEvent(i.command);
}
), i.keysMac && this.shortcutManager.register(
i.keysMac,
() => {
var s;
return (s = this.editor) == null ? void 0 : s.triggerEvent(i.command);
}
);
});
}), (n = this.editor) == null || n.getContainer().addEventListener("keydown", (a) => {
this.shortcutManager.handleKeyDown(a);
}));
}
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.editor = null, this.menu = null, this.toolbarButton = null;
}
}
export {
w as ShortcutsPlugin
};