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.44 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 s=Object.defineProperty;var p=(a,t,e)=>t in a?s(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e;var c=(a,t,e)=>p(a,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("../../../core/ui/PopupManager.cjs"),u=require("../services/TableExportService.cjs");class b{constructor(t,e){c(this,"editor");c(this,"table");c(this,"exportService");this.editor=t,this.table=e,this.exportService=new u.TableExportService}execute(){this.showExportDialog()}showExportDialog(){if(!this.editor)return;const t=new d.PopupManager(this.editor,{title:this.editor.t("Export Table"),className:"export-dialog-popup",closeOnClickOutside:!0,buttons:[{label:this.editor.t("Cancel"),variant:"secondary",onClick:()=>t.hide()}],items:[{type:"custom",id:"export-options",content:()=>{const e=document.createElement("div");e.className="p-4 space-y-4";const o=document.createElement("select");o.className="w-full p-2 border border-gray-300 rounded-md",[{value:"csv",label:"CSV"},{value:"json",label:"JSON"},{value:"html",label:"HTML"},{value:"excel",label:"Excel"}].forEach(r=>{const n=document.createElement("option");n.value=r.value,n.textContent=r.label,o.appendChild(n)}),e.appendChild(o);const l=document.createElement("button");return l.className="w-full bg-blue-500 text-white p-2 rounded-md hover:bg-blue-600",l.textContent=this.editor.t("Export"),l.onclick=()=>{this.performExport(o.value),t.hide()},e.appendChild(l),e}}]});t.show()}performExport(t){try{let e,o;switch(t){case"csv":e=this.exportService.exportToCSV(this.table),o="text/csv";break;case"json":e=this.exportService.exportToJSON(this.table),o="application/json";break;case"html":e=this.exportService.exportToHTML(this.table),o="text/html";break;case"excel":e=this.exportService.exportToExcel(this.table),o="application/vnd.ms-excel";break;default:throw new Error(`Unsupported format: ${t}`)}const i=new Blob([e],{type:o}),l=URL.createObjectURL(i),r=document.createElement("a");r.href=l,r.download=`table.${t}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(l)}catch(e){console.error("Export failed:",e)}}undo(){}}exports.ExportTableCommand=b;