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
3 lines (2 loc) • 2.3 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 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 s=(a,e,t)=>d(a,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../../../core/ui/PopupManager.cjs"),u=require("../services/TableExportService.cjs");class h{constructor(e){s(this,"editor");s(this,"exportService");this.editor=e,this.exportService=new u.TableExportService}execute(){this.showImportDialog()}showImportDialog(){if(!this.editor)return;const e=new m.PopupManager(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 l=document.createElement("option");l.value=r.value,l.textContent=r.label,i.appendChild(l)}),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 l=this.editor.getContainer();l&&l.appendChild(r)}}catch(r){console.error("Import failed:",r)}},i.readAsText(e)}undo(){}}exports.ImportTableCommand=h;