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) • 6.21 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 */
"use strict";var ue=Object.defineProperty;var Ce=(o,n,i)=>n in o?ue(o,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[n]=i;var d=(o,n,i)=>Ce(o,typeof n!="symbol"?n+"":n,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../../utils/helpers.cjs");class ge{constructor(n,i,u,a){d(this,"editor");d(this,"onSubmit");d(this,"event");d(this,"formElement");d(this,"categoryManager");this.editor=n,this.onSubmit=i,this.event=u,this.categoryManager=a}getElement(){var R,z,B,G,J,K,Q,U,V,W,X,Y,Z,_,$,ee,te;const n=document.createElement("div");n.className="event-form-container",this.formElement=e.createForm("event-form",null,"POST");const i=e.createContainer("form-group mb-4"),u=e.createLabel(this.editor.t("Title"),"event-title"),a=e.createInputField("text",this.editor.t("Enter event title"),((R=this.event)==null?void 0:R.title)||"");a.id="event-title",a.name="title",a.required=!0,i.appendChild(u),i.appendChild(a),this.formElement.appendChild(i);const C=e.createContainer("form-group mb-4"),ne=e.createLabel(this.editor.t("Description"),"event-description"),c=e.createTextarea(this.editor.t("Enter event description"),((z=this.event)==null?void 0:z.description)||"");c.id="event-description",c.name="description",c.rows=3,C.appendChild(ne),C.appendChild(c),this.formElement.appendChild(C);const g=e.createContainer("form-row grid grid-cols-2 gap-4 mb-4"),v=e.createContainer("form-group"),ie=e.createLabel(this.editor.t("Date"),"event-date"),p=e.createInputField("date","",((B=this.event)==null?void 0:B.date)||"");p.id="event-date",p.name="date",p.required=!0,v.appendChild(ie),v.appendChild(p),g.appendChild(v);const b=e.createContainer("form-group"),re=e.createLabel(this.editor.t("Time"),"event-time"),m=e.createInputField("time","",((G=this.event)==null?void 0:G.time)||"");m.id="event-time",m.name="time",m.required=!0,b.appendChild(re),b.appendChild(m),g.appendChild(b),this.formElement.appendChild(g);const f=e.createContainer("form-row grid grid-cols-2 gap-4 mb-4"),y=e.createContainer("form-group"),oe=e.createLabel(this.editor.t("Duration (minutes)"),"event-duration"),l=e.createInputField("number","",((K=(J=this.event)==null?void 0:J.duration)==null?void 0:K.toString())||"60");l.id="event-duration",l.name="duration",l.min="15",l.step="15",y.appendChild(oe),y.appendChild(l),f.appendChild(y);const E=e.createContainer("form-group"),ae=e.createLabel(this.editor.t("Color"),"event-color"),L=e.createInputField("color","",((Q=this.event)==null?void 0:Q.color)||"#3b82f6");L.id="event-color",L.name="color",E.appendChild(ae),E.appendChild(L),f.appendChild(E),this.formElement.appendChild(f);const I=e.createContainer("form-row grid grid-cols-2 gap-4 mb-4"),F=e.createContainer("form-group"),de=e.createLabel(this.editor.t("Priority"),"event-priority"),le=[{value:"low",label:this.editor.t("Low")},{value:"medium",label:this.editor.t("Medium")},{value:"high",label:this.editor.t("High")}],S=e.createSelectField(le,((U=this.event)==null?void 0:U.priority)||"medium");S.id="event-priority",S.name="priority",F.appendChild(de),F.appendChild(S),I.appendChild(F);const D=e.createContainer("form-group"),se=e.createLabel(this.editor.t("Category"),"event-category");let x=[{value:"",label:this.editor.t("Select category")}];if(this.categoryManager){const t=this.categoryManager.getCategories();x=x.concat(t.map(h=>({value:h.id,label:h.name})))}const T=e.createSelectField(x,((V=this.event)==null?void 0:V.category)||"");T.id="event-category",T.name="category",D.appendChild(se),D.appendChild(T),I.appendChild(D),this.formElement.appendChild(I);const w=e.createContainer("form-group mb-4"),ce=e.createLabel(this.editor.t("Location"),"event-location"),A=e.createInputField("text",this.editor.t("Enter event location"),((W=this.event)==null?void 0:W.location)||"");A.id="event-location",A.name="location",w.appendChild(ce),w.appendChild(A),this.formElement.appendChild(w);const M=e.createContainer("form-group mb-4"),pe=e.createLabel(this.editor.t("Attendees"),"event-attendees"),q=e.createInputField("text",this.editor.t("Enter attendees (comma separated)"),((Y=(X=this.event)==null?void 0:X.attendees)==null?void 0:Y.join(", "))||"");q.id="event-attendees",q.name="attendees",M.appendChild(pe),M.appendChild(q),this.formElement.appendChild(M);const O=e.createContainer("form-group mb-4"),me=e.createLabel(this.editor.t("Tags"),"event-tags"),j=e.createInputField("text",this.editor.t("Enter tags (comma separated)"),((_=(Z=this.event)==null?void 0:Z.tags)==null?void 0:_.join(", "))||"");j.id="event-tags",j.name="tags",O.appendChild(me),O.appendChild(j),this.formElement.appendChild(O);const P=e.createContainer("form-group mb-4"),he=e.createLabel(this.editor.t("Reminder (minutes before)"),"event-reminder"),s=e.createInputField("number","",((ee=($=this.event)==null?void 0:$.reminder)==null?void 0:ee.toString())||"");s.id="event-reminder",s.name="reminder",s.min="0",s.placeholder=this.editor.t("No reminder"),P.appendChild(he),P.appendChild(s),this.formElement.appendChild(P);const k=e.createContainer("form-group mb-4"),H=e.createCheckbox(this.editor.t("All day event"),((te=this.event)==null?void 0:te.isAllDay)||!1),N=H.querySelector("input");return N.id="event-all-day",N.name="isAllDay",k.appendChild(H),this.formElement.appendChild(k),this.formElement.addEventListener("submit",e.createFormSubmitHandler(this.formElement,t=>{const h={title:t.title,description:t.description,date:t.date,time:t.time,duration:t.duration,location:t.location,color:t.color,isAllDay:t.isAllDay,priority:t.priority,category:t.category,tags:t.tags?t.tags.split(",").map(r=>r.trim()).filter(r=>r):[],attendees:t.attendees?t.attendees.split(",").map(r=>r.trim()).filter(r=>r):[],reminder:t.reminder?parseInt(t.reminder):void 0};this.onSubmit(h)})),n.appendChild(this.formElement),n}submit(){if(!this.formElement)return!1;const n=new Event("submit",{bubbles:!0,cancelable:!0});return this.formElement.dispatchEvent(n),!0}}exports.EventForm=ge;