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
51 lines (50 loc) • 2.14 kB
JavaScript
/*! 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 r = Object.defineProperty;
var s = (i, t, e) => t in i ? r(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
var o = (i, t, e) => s(i, typeof t != "symbol" ? t + "" : t, e);
/* empty css */
/* empty css */
import { TemplatesMenu as l } from "./components/TemplatesMenu.mjs";
import { TemplateManager as a } from "./services/TemplateManager.mjs";
import { createToolbarButton as m } from "../ToolbarPlugin/utils.mjs";
import h from "../../icons/templates.svg.mjs";
class B {
constructor() {
o(this, "name", "templates");
o(this, "hotkeys", [
{ keys: "Ctrl+Alt+M", description: "Insert template", command: "templates", icon: "📄" }
]);
o(this, "editor", null);
o(this, "menu", null);
o(this, "manager");
o(this, "toolbarButton", null);
this.manager = new a();
}
initialize(t) {
this.menu = new l(this.manager, t), this.editor = t, this.addToolbarButton(), this.editor.on("templates", () => {
this.showTemplatesMenu();
});
}
addToolbarButton() {
var e, n;
const t = (e = this.editor) == null ? void 0 : e.getToolbar();
t && (this.toolbarButton = m({
icon: h,
title: (n = this.editor) == null ? void 0 : n.t("Templates"),
onClick: () => this.showTemplatesMenu()
}), t.appendChild(this.toolbarButton));
}
showTemplatesMenu() {
var t;
this.editor && ((t = this.menu) == null || t.show((e) => {
this.editor && (this.editor.getContainer().innerHTML = e.content);
}));
}
destroy() {
var t;
this.toolbarButton && this.toolbarButton.parentElement && this.toolbarButton.parentElement.removeChild(this.toolbarButton), this.menu && (this.menu.destroy(), this.menu = null), (t = this.editor) == null || t.off("templates"), this.editor = null, this.manager = null, this.toolbarButton = null;
}
}
export {
B as TemplatesPlugin
};