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

3 lines (2 loc) 2.3 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 */ "use strict";var o=Object.defineProperty;var h=(i,t,e)=>t in i?o(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var c=(i,t,e)=>h(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../../icons/delete.svg.cjs"),l=require("../../../icons/edit.svg.cjs"),d=require("../../../icons/export.svg.cjs"),u=require("../../../core/ui/ContextMenu.cjs");class C{constructor(t,e){c(this,"contextMenu");c(this,"activeChart",null);c(this,"editor");this.chartMenu=e,this.editor=t,this.contextMenu=new u.ContextMenu(t,[{label:t.t("Edit"),icon:l.default,action:"edit",onClick:()=>this.handleEdit()},{label:t.t("Export PNG"),icon:d.default,action:"export",onClick:()=>this.handleExport()},{label:t.t("Delete"),icon:s.default,action:"delete",className:"text-red-600",onClick:()=>this.handleDelete()}],{orientation:"vertical"})}handleEdit(){if(!this.activeChart)return;const t=this.activeChart.getAttribute("data-chart-type"),e=this.activeChart.getAttribute("data-chart-data");if(t&&e)try{this.chartMenu.edit(this.activeChart)}catch(a){console.error("Failed to parse chart data:",a)}}handleDelete(){this.activeChart&&this.activeChart.remove()}handleExport(){var e,a;if(!this.activeChart)return;const t=this.activeChart.querySelector("img.svg-chart");if(t&&t.src){const n=document.createElement("a");n.href=t.src,n.download="chart.png",(this.editor.getInnerContainer()||document.body).appendChild(n),n.click(),(e=n.parentNode)==null||e.removeChild(n)}else{const n=this.activeChart.querySelector("canvas");if(n){const r=document.createElement("a");r.href=n.toDataURL("image/png"),r.download="chart.png",(this.editor.getInnerContainer()||document.body).appendChild(r),r.click(),(a=r.parentNode)==null||a.removeChild(r)}}}show(t,e,a){this.activeChart=t,this.contextMenu.show(t,e,a)}hide(){this.contextMenu.hide(),this.activeChart=null}destroy(){typeof this.contextMenu.destroy=="function"&&this.contextMenu.destroy(),this.contextMenu=null,this.activeChart=null,this.chartMenu=null}}exports.ChartContextMenu=C;