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

2 lines (1 loc) 5.09 kB
"use strict";var d=Object.defineProperty;var u=(l,e,t)=>e in l?d(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t;var n=(l,e,t)=>u(l,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("../../../core/ui/ContextMenu.cjs"),c=require("../commands/AddRowCommand.cjs"),a=require("../commands/AddColumnCommand.cjs"),C=require("../commands/DeleteRowCommand.cjs"),h=require("../commands/DeleteColumnCommand.cjs"),p=require("../commands/DeleteTableCommand.cjs"),w=require("../commands/StyleTableCellCommand.cjs"),b=require("../commands/CopyTableCommand.cjs"),v=require("../commands/MergeCellsCommand.cjs"),k=require("../commands/SplitCellCommand.cjs"),g=require("../commands/AddHeaderRowCommand.cjs"),f=require("../commands/RemoveHeaderRowCommand.cjs"),M=require("../commands/SetCellBorderCommand.cjs"),x=require("../../../icons/copy.svg.cjs"),y=require("../../../icons/delete-table.svg.cjs"),A=require("../../../icons/delete-row.svg.cjs"),q=require("../../../icons/delete-column.svg.cjs"),R=require("../../../core/ui/PopupManager.cjs"),i={arrowUp:"↑",arrowDown:"↓",arrowLeft:"←",arrowRight:"→",remove:"×"},r="🟰",s="✂️";class P{constructor(e){n(this,"contextMenu");n(this,"activeCell",null);n(this,"popupManager");n(this,"colorPicker",null);this.contextMenu=new m.ContextMenu(e,[{title:e.t("Add Row Above"),icon:i.arrowUp,action:"add-row-above",onClick:()=>this.executeAction("add-row-above")},{title:e.t("Add Row Below"),icon:i.arrowDown,action:"add-row-below",onClick:()=>this.executeAction("add-row-below")},{title:e.t("Add Column Left"),icon:i.arrowLeft,action:"add-col-left",onClick:()=>this.executeAction("add-col-left")},{title:e.t("Add Column Right"),icon:i.arrowRight,action:"add-col-right",onClick:()=>this.executeAction("add-col-right")},{type:"divider"},{title:e.t("Delete Row"),icon:A.default,action:"delete-row",onClick:()=>this.executeAction("delete-row")},{title:e.t("Delete Column"),icon:q.default,action:"delete-col",onClick:()=>this.executeAction("delete-col")},{title:e.t("Delete Table"),icon:y.default,action:"delete-table",onClick:()=>this.executeAction("delete-table")},{type:"divider"},{title:e.t("Copy"),icon:x.default,action:"copy-table",onClick:()=>this.executeAction("copy-table")},{type:"divider"},{title:e.t("Merge Cells"),icon:r,action:"merge-cells",onClick:()=>this.executeAction("merge-cells")},{title:e.t("Split Cell"),icon:s,action:"split-cell",onClick:()=>this.executeAction("split-cell")},{type:"divider"},{type:"custom",customHTML:`<input type="color" class="table-color-picker" title="${e.t("Background Color")}">`}],{orientation:"vertical"}),this.popupManager=new R.PopupManager(e,{title:e.t("Set Cell Border"),closeOnClickOutside:!0,buttons:[{label:e.t("Confirm"),variant:"primary",onClick:()=>this.handleBorderConfirm()},{label:e.t("Cancel"),variant:"secondary",onClick:()=>this.popupManager.hide()}]}),this.setupColorPicker()}handleBorderConfirm(){const e=this.popupManager.getValue("border-style");e&&this.activeCell&&new M.SetCellBorderCommand(this.activeCell,e).execute(),this.popupManager.hide()}setupColorPicker(){this.colorPicker=this.contextMenu.getElement().querySelector(".table-color-picker"),this.colorPicker&&(this.colorPicker.addEventListener("input",e=>{this.activeCell&&new w.StyleTableCellCommand(this.activeCell,{backgroundColor:e.target.value}).execute()}),this.colorPicker.addEventListener("contextmenu",e=>e.stopPropagation()))}executeAction(e){if(!this.activeCell)return;const t=this.activeCell.closest("table");if(!t||!(t instanceof HTMLTableElement))return;let o=null;switch(e){case"add-row-above":o=new c.AddRowCommand(t,this.activeCell,!0);break;case"add-row-below":o=new c.AddRowCommand(t,this.activeCell,!1);break;case"add-col-left":o=new a.AddColumnCommand(t,this.activeCell,!0);break;case"add-col-right":o=new a.AddColumnCommand(t,this.activeCell,!1);break;case"delete-row":o=new C.DeleteRowCommand(t,this.activeCell);break;case"delete-col":o=new h.DeleteColumnCommand(t,this.activeCell);break;case"delete-table":o=new p.DeleteTableCommand(t);break;case"copy-table":o=new b.CopyTableCommand(t);break;case"merge-cells":o=new v.MergeCellsCommand(t,this.activeCell);break;case"split-cell":o=new k.SplitCellCommand(t,this.activeCell);break;case"add-header-row":o=new g.AddHeaderRowCommand(t);break;case"remove-header-row":o=new f.RemoveHeaderRowCommand(t);break}o&&o.execute(),e!=="set-background"&&this.contextMenu.hide()}show(e,t,o){this.activeCell=e,this.contextMenu.show(e,t,o)}hide(){this.contextMenu.hide(),this.activeCell=null}destroy(){this.colorPicker&&(this.colorPicker.removeEventListener("input",()=>{}),this.colorPicker.removeEventListener("contextmenu",()=>{}),this.colorPicker=null),this.contextMenu&&typeof this.contextMenu.destroy=="function"&&this.contextMenu.destroy(),this.popupManager&&typeof this.popupManager.destroy=="function"&&this.popupManager.destroy(),this.contextMenu=null,this.popupManager=null,this.activeCell=null}}exports.TableContextMenu=P;exports.mergeIcon=r;exports.navigationIcons=i;exports.splitIcon=s;