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.43 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 l=(n,t,e)=>t in n?o(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var i=(n,t,e)=>l(n,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../../core/ui/PopupManager.cjs"),s=require("../../../utils/helpers.cjs");class r{constructor(t){i(this,"editor");i(this,"popup");i(this,"callback",null);i(this,"textarea",null);i(this,"deleteButton",null);this.editor=t,this.popup=new c.PopupManager(t,{title:t.t("Insert Comment"),className:"comment-menu",closeOnClickOutside:!0,buttons:[{label:t.t("Cancel"),variant:"secondary",onClick:()=>this.popup.hide()},{label:t.t("Save"),variant:"primary",onClick:()=>this.handleSubmit()}],items:[{type:"custom",id:"comment-content",content:()=>this.createContent()}]})}createContent(){const t=s.createContainer("p-4");this.textarea=s.createTextarea("Add your comment..."),this.textarea.className="comment-content w-full h-32 p-2 border rounded-lg resize-none focus:outline-none focus:ring-2 focus:ring-blue-500";const e=s.createContainer("flex justify-between items-center mt-4"),a=s.createP("text-sm text-gray-500",this.editor.t("Use comments to provide feedback or suggestions."));return this.deleteButton=s.createButton(this.editor.t("Delete Comment"),()=>{this.callback&&(this.callback("","delete"),this.popup.hide())}),this.deleteButton.className="delete-comment hidden px-3 py-1.5 text-sm text-red-600 hover:text-red-700 transition-colors",e.appendChild(a),e.appendChild(this.deleteButton),t.appendChild(this.textarea),t.appendChild(e),t}handleSubmit(){if(this.textarea&&this.callback){const t=this.textarea.value.trim();t&&(this.callback(t,"save"),this.popup.hide())}}show(t,e="",a=!1){this.callback=t,this.textarea&&this.deleteButton&&(this.textarea.value=e,this.deleteButton.classList.toggle("hidden",!a),this.popup.show(),this.textarea.focus())}destroy(){this.deleteButton&&this.deleteButton.removeEventListener("click",()=>{this.callback&&(this.callback("","delete"),this.popup.hide())}),this.popup.destroy(),this.editor=null,this.popup=null,this.callback=null,this.textarea=null,this.deleteButton=null}}exports.CommentMenu=r;