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

89 lines (88 loc) 3.16 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 p = Object.defineProperty; var d = (a, e, t) => e in a ? p(a, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[e] = t; var l = (a, e, t) => d(a, typeof e != "symbol" ? e + "" : e, t); import { PopupManager as m } from "../../../core/ui/PopupManager.mjs"; import { TableExportService as u } from "../services/TableExportService.mjs"; class v { constructor(e) { l(this, "editor"); l(this, "exportService"); this.editor = e, this.exportService = new u(); } execute() { this.showImportDialog(); } showImportDialog() { if (!this.editor) return; const e = new m(this.editor, { title: this.editor.t("Import Table"), className: "import-dialog-popup", closeOnClickOutside: !0, buttons: [ { label: this.editor.t("Cancel"), variant: "secondary", onClick: () => e.hide() } ], items: [ { type: "custom", id: "import-options", content: () => { const t = document.createElement("div"); t.className = "p-4 space-y-4"; const i = document.createElement("select"); i.className = "w-full p-2 border border-gray-300 rounded-md", [ { value: "csv", label: "CSV" }, { value: "json", label: "JSON" } ].forEach((r) => { const s = document.createElement("option"); s.value = r.value, s.textContent = r.label, i.appendChild(s); }), t.appendChild(i); const o = document.createElement("input"); o.type = "file", o.className = "w-full p-2 border border-gray-300 rounded-md", o.accept = ".csv,.json,.html,.txt", t.appendChild(o); const n = document.createElement("button"); return n.className = "w-full bg-blue-500 text-white p-2 rounded-md hover:bg-blue-600", n.textContent = this.editor.t("Import"), n.onclick = () => { o.files && o.files[0] && (this.performImport(o.files[0], i.value), e.hide()); }, t.appendChild(n), t; } } ] }); e.show(); } performImport(e, t) { const i = new FileReader(); i.onload = (c) => { var n; const o = (n = c.target) == null ? void 0 : n.result; if (o) try { let r; switch (t) { case "csv": r = this.exportService.importFromCSV(o); break; case "json": r = this.exportService.importFromJSON(o); break; default: throw new Error(`Unsupported format: ${t}`); } if (this.editor) { const s = this.editor.getContainer(); s && s.appendChild(r); } } catch (r) { console.error("Import failed:", r); } }, i.readAsText(e); } undo() { } } export { v as ImportTableCommand };