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
45 lines (44 loc) • 1.67 kB
JavaScript
var e = Object.defineProperty;
var i = (r, t, o) => t in r ? e(r, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : r[t] = o;
var n = (r, t, o) => i(r, typeof t != "symbol" ? t + "" : t, o);
/* empty css */
/* empty css */
import { ExportMenu as l } from "./components/ExportMenu.mjs";
import { createToolbarButton as s } from "../ToolbarPlugin/utils.mjs";
import u from "../../icons/export.svg.mjs";
class b {
constructor() {
n(this, "name", "export");
n(this, "hotkeys", [{ keys: "Ctrl+Alt+E", description: "Export document", command: "export", icon: "📤" }]);
n(this, "editor", null);
n(this, "menu", null);
n(this, "toolbarButton", null);
}
initialize(t) {
this.menu = new l(t), this.editor = t, this.addToolbarButton(), this.editor.on("export", () => {
this.showExportMenu();
});
}
addToolbarButton() {
var o;
const t = document.querySelector(".editor-toolbar");
t && (this.toolbarButton = s({
icon: u,
title: ((o = this.editor) == null ? void 0 : o.t("Export")) ?? "",
onClick: () => this.showExportMenu()
}), t.appendChild(this.toolbarButton));
}
showExportMenu() {
var o;
if (!this.editor) return;
const t = this.editor.getContainer().innerHTML;
(o = this.menu) == null || o.show(t);
}
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("export"), this.editor = null, this.toolbarButton = null;
}
}
export {
b as ExportPlugin
};