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

16 lines (15 loc) 4.66 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 h=Object.defineProperty;var l=(o,t,e)=>t in o?h(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var s=(o,t,e)=>l(o,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../../../core/ui/PopupManager.cjs"),c=require("../services/CategoryManager.cjs"),p=require("./CalendarForm.cjs"),d=require("./EventForm.cjs");class u{constructor(t,e,a,i){s(this,"popup");s(this,"editor");s(this,"manager");s(this,"categoryManager");s(this,"onSelect",null);s(this,"onImport");this.editor=e,this.manager=t,this.categoryManager=i||new c.CategoryManager,this.onImport=a,this.popup=this.createMainPopup()}createMainPopup(){return new r.PopupManager(this.editor,{title:this.editor.t("Calendar"),className:"calendar-menu",closeOnClickOutside:!0,buttons:[{label:this.editor.t("Import"),variant:"secondary",onClick:()=>this.showImportDialog()},{label:this.editor.t("New Calendar"),variant:"primary",onClick:()=>this.showNewCalendarForm()}],items:[{type:"custom",id:"calendars-content",content:()=>this.createCalendarsList()}]})}createCalendarsList(){const t=document.createElement("div");t.className="calendars-list";const e=this.manager.getCalendars();if(e.length===0){const a=document.createElement("div");a.className="empty-state",a.innerHTML=` <p>${this.editor.t("No calendars found")}</p> <p>${this.editor.t("Create your first calendar to get started")}</p> `,t.appendChild(a)}else e.forEach(a=>{const i=this.createCalendarItem(a);t.appendChild(i)});return t}createCalendarItem(t){const e=this.manager.getEvents(t.id),a=document.createElement("div");return a.className="calendar-item",a.innerHTML=` <div class="calendar-info"> <h4 class="calendar-title">${t.title}</h4> <p class="calendar-description">${t.description||""}</p> <span class="calendar-events-count">${e.length} events</span> </div> <div class="calendar-actions"> <button class="btn-edit" title="${this.editor.t("Edit")}">✏️</button> <button class="btn-delete" title="${this.editor.t("Delete")}">🗑️</button> </div> `,a.addEventListener("click",i=>{i.target.classList.contains("btn-edit")?(i.stopPropagation(),this.showEditCalendarForm(t)):i.target.classList.contains("btn-delete")?(i.stopPropagation(),this.handleDeleteCalendar(t)):this.handleSelectCalendar(t)}),a}createFormPopup(t,e,a,i){this.popup=new r.PopupManager(this.editor,{title:this.editor.t(t),className:"calendar-menu",closeOnClickOutside:!0,buttons:[{label:this.editor.t("Cancel"),variant:"secondary",onClick:i||(()=>this.popup.hide())},{label:this.editor.t(a),variant:"primary",onClick:()=>{this.editor.ensureEditorFocus(),e.submit()}}],items:[{type:"custom",id:"form-content",content:()=>e.getElement()}]}),this.popup.show()}showNewCalendarForm(t){const e=new p.CalendarForm(this.editor,a=>{const i=this.manager.createCalendar(a);this.popup.hide(),this.popup=this.createMainPopup(),this.popup.show(),t&&i&&t(i)});this.createFormPopup("New Calendar",e,"Create",()=>{this.popup=this.createMainPopup(),this.popup.show()})}showEditCalendarForm(t){const e=new p.CalendarForm(this.editor,a=>{this.manager.updateCalendar(t.id,a),this.popup.hide(),this.popup=this.createMainPopup(),this.popup.show()},t);this.createFormPopup("Edit Calendar",e,"Update",()=>{this.popup=this.createMainPopup(),this.popup.show()})}handleSelectCalendar(t){var e;(e=this.onSelect)==null||e.call(this,t),this.popup.hide()}handleDeleteCalendar(t){confirm(this.editor.t("Are you sure you want to delete this calendar?"))&&(this.manager.deleteCalendar(t.id),this.popup.hide(),this.popup=this.createMainPopup(),this.popup.show())}show(t){this.onSelect=t,this.popup.show()}showEditEvent(t,e){const a=new d.EventForm(this.editor,i=>{const n=this.manager.updateEvent(t.id,i);this.popup.hide(),e(n)},t,this.categoryManager);this.createFormPopup("Edit Event",a,"Update",()=>{this.popup.hide()})}showCreateEvent(t,e){const a=new d.EventForm(this.editor,i=>{const n=this.manager.createEvent(i,t);this.popup.hide(),e(n)},void 0,this.categoryManager);this.createFormPopup("New Event",a,"Create",()=>{this.popup.hide()})}showImportDialog(){this.onImport&&this.onImport()}destroy(){this.popup&&(this.popup.hide(),typeof this.popup.destroy=="function"&&this.popup.destroy(),this.popup=null),this.editor=null,this.manager=null,this.onSelect=null}}exports.CalendarMenu=u;