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

98 lines (97 loc) 3.93 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 s = Object.defineProperty; var d = (r, t, e) => t in r ? s(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e; var l = (r, t, e) => d(r, typeof t != "symbol" ? t + "" : t, e); /* empty css */ /* empty css */ import { PopupManager as n } from "../../core/ui/PopupManager.mjs"; import { createToolbarButton as a } from "../ToolbarPlugin/utils.mjs"; import h from "../../icons/pdf.svg.mjs"; import { Resizer as u } from "../../utils/Resizer.mjs"; class w { constructor() { l(this, "name", "pdf-embed"); l(this, "hotkeys", [{ keys: "Ctrl+Alt+P", description: "Insert PDF", command: "pdf-embed", icon: "📄" }]); l(this, "editor", null); l(this, "popup", null); l(this, "toolbarButton", null); } initialize(t) { this.editor = t, this.addToolbarButton(), this.popup = new n(t, { title: t.t("Insert PDF"), className: "pdf-embed-popup", closeOnClickOutside: !0, items: this.buildPopupItems(), buttons: [ { label: t.t("Cancel"), variant: "secondary", onClick: () => { var e; return (e = this.popup) == null ? void 0 : e.hide(); } }, { label: t.t("Insert"), variant: "primary", onClick: () => this.handleInsert() } ] }), this.editor.on("pdf-embed", () => this.openModal()); } addToolbarButton() { var e, i; const t = (e = this.editor) == null ? void 0 : e.getToolbar(); t && (this.toolbarButton = a({ icon: h, title: (i = this.editor) == null ? void 0 : i.t("Insert PDF"), onClick: () => this.openModal() }), t.appendChild(this.toolbarButton)); } buildPopupItems() { var t, e, i; return [ { type: "input", id: "pdf-url", label: ((t = this.editor) == null ? void 0 : t.t("PDF URL")) || "PDF URL", placeholder: "https://example.com/file.pdf", value: "" }, { type: "number", id: "pdf-width", label: ((e = this.editor) == null ? void 0 : e.t("Width")) || "Width", value: 800 }, { type: "number", id: "pdf-height", label: ((i = this.editor) == null ? void 0 : i.t("Height")) || "Height", value: 600 } ]; } openModal() { var t, e; (t = this.popup) == null || t.show(), (e = this.popup) == null || e.setFocus("pdf-url"); } handleInsert() { if (!this.editor || !this.popup) return; const t = String(this.popup.getValue("pdf-url") || "").trim(), e = Number(this.popup.getValue("pdf-width") || 800), i = Number(this.popup.getValue("pdf-height") || 600); if (!t) { this.editor.showWarningNotification(this.editor.t("Please provide PDF URL")); return; } const p = document.createElement("div"); p.className = "pdf-embed-container my-4", p.style.width = `${e}px`, p.style.height = `${i}px`; const o = document.createElement("iframe"); o.className = "pdf-embed-frame", o.src = t, o.width = "100%", o.height = "100%", o.setAttribute("frameborder", "0"), o.setAttribute("allowfullscreen", "true"), o.setAttribute("loading", "lazy"), p.appendChild(o), new u(p, { handleSize: 10, handleColor: "#2563eb" }), this.editor.insertContent(p), this.popup.hide(); } destroy() { var t, e, i; this.popup && (this.popup.destroy(), this.popup = null), this.toolbarButton && (this.toolbarButton.remove(), this.toolbarButton = null), (t = this.editor) == null || t.off("pdf-embed"), (e = this.editor) == null || e.off("pdf-insert"), (i = this.editor) == null || i.off("pdf-error"), this.editor = null; } } export { w as PDFEmbedPlugin };