@forcecalendar/interface 1.0.49 → 1.0.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -615,7 +615,7 @@
615
615
  <button class="fc-btn fc-btn-primary" id="save-btn">Save Event</button>
616
616
  </footer>
617
617
  </div>
618
- `}afterRender(){this.modalContent=this.$(".modal-content"),this.titleInput=this.$("#event-title"),this.startInput=this.$("#event-start"),this.endInput=this.$("#event-end"),this.colorContainer=this.$("#color-picker"),this.titleGroup=this.$("#title-group"),this.endGroup=this.$("#end-group"),this.addListener(this.$("#close-x"),"click",()=>this.close()),this.addListener(this.$("#cancel-btn"),"click",()=>this.close()),this.addListener(this.$("#save-btn"),"click",()=>this.save()),this.colorContainer.querySelectorAll(".color-btn").forEach(t=>{this.addListener(t,"click",e=>{this._formData.color=e.currentTarget.dataset.color,this.updateColorSelection()})}),this.addListener(this,"click",t=>{t.target===this&&this.close()}),this._keydownListenerAdded||(this._handleKeyDown=t=>{t.key==="Escape"&&this.hasAttribute("open")&&this.close()},window.addEventListener("keydown",this._handleKeyDown),this._keydownListenerAdded=!0)}updateColorSelection(){this.colorContainer.querySelectorAll(".color-btn").forEach(e=>{const r=e.dataset.color===this._formData.color;e.classList.toggle("selected",r),e.setAttribute("aria-checked",r?"true":"false")})}open(t=new Date){this.hasAttribute("open")||this.setAttribute("open",""),this.titleGroup.classList.remove("has-error"),this.endGroup.classList.remove("has-error"),this._formData.start=t,this._formData.end=new Date(t.getTime()+this.config.defaultDuration*60*1e3),this._formData.title="",this._formData.color=this.config.colors[0].color,this.startInput&&(this.titleInput.value="",this.startInput.value=this.formatDateForInput(this._formData.start),this.endInput.value=this.formatDateForInput(this._formData.end),this.updateColorSelection(),this._cleanupFocusTrap&&this._cleanupFocusTrap(),this._cleanupFocusTrap=w.trapFocus(this.modalContent))}close(){this.removeAttribute("open"),this._cleanupFocusTrap&&(this._cleanupFocusTrap(),this._cleanupFocusTrap=null)}validate(){let t=!0;this.titleGroup.classList.remove("has-error"),this.endGroup.classList.remove("has-error"),this.titleInput.value.trim()||(this.titleGroup.classList.add("has-error"),t=!1);const e=new Date(this.startInput.value);return new Date(this.endInput.value)<=e&&(this.endGroup.classList.add("has-error"),t=!1),t}save(){if(!this.validate())return;const t={title:this.titleInput.value.trim(),start:new Date(this.startInput.value),end:new Date(this.endInput.value),backgroundColor:this._formData.color};this.emit("save",t),this.close()}formatDateForInput(t){const e=o=>String(o).padStart(2,"0"),r=t.getFullYear(),i=e(t.getMonth()+1),s=e(t.getDate()),n=e(t.getHours()),a=e(t.getMinutes());return`${r}-${i}-${s}T${n}:${a}`}unmount(){this._cleanupFocusTrap&&this._cleanupFocusTrap(),this._handleKeyDown&&(window.removeEventListener("keydown",this._handleKeyDown),this._handleKeyDown=null,this._keydownListenerAdded=!1)}}customElements.get("forcecal-event-form")||customElements.define("forcecal-event-form",I);const b=class b extends g{static get observedAttributes(){return["view","date","locale","timezone","week-starts-on","height"]}constructor(){super(),this.stateManager=null,this.currentView=null,this._hasRendered=!1,this._cachedStyles=null,this._busUnsubscribers=[]}initialize(){const t={view:this.getAttribute("view")||"month",date:this.getAttribute("date")?new Date(this.getAttribute("date")):new Date,locale:this.getAttribute("locale")||"en-US",timeZone:this.getAttribute("timezone")||Intl.DateTimeFormat().resolvedOptions().timeZone,weekStartsOn:parseInt(this.getAttribute("week-starts-on")||"0")};this.stateManager=new C(t),this._stateUnsubscribe=this.stateManager.subscribe(this.handleStateChange.bind(this)),this.setupEventListeners()}setupEventListeners(){this._busUnsubscribers.forEach(r=>r()),this._busUnsubscribers=[];const t=this.stateManager.eventBus;this._busUnsubscribers.push(t.on("navigation:*",(r,i)=>{this.emit("calendar-navigate",{action:i.split(":")[1],...r})})),this._busUnsubscribers.push(t.on("view:changed",r=>{this.emit("calendar-view-change",r)}));const e=(r,i)=>{this.emit(`calendar-event-${r}`,i)};this._busUnsubscribers.push(t.on("event:add",r=>{e("add",r)})),this._busUnsubscribers.push(t.on("event:update",r=>{e("update",r)})),this._busUnsubscribers.push(t.on("event:remove",r=>{e("remove",r)})),this._busUnsubscribers.push(t.on("event:added",r=>{this.emit("calendar-event-added",r)})),this._busUnsubscribers.push(t.on("event:updated",r=>{this.emit("calendar-event-updated",r)})),this._busUnsubscribers.push(t.on("event:deleted",r=>{this.emit("calendar-event-deleted",r)})),this._busUnsubscribers.push(t.on("date:selected",r=>{this.emit("calendar-date-select",r)}))}handleStateChange(t,e){var o,c;if(!this._hasRendered)return;const r=t.view!==(e==null?void 0:e.view),i=((o=t.currentDate)==null?void 0:o.getTime())!==((c=e==null?void 0:e.currentDate)==null?void 0:c.getTime()),s=t.events!==(e==null?void 0:e.events),n=t.loading!==(e==null?void 0:e.loading);if(t.error!==(e==null?void 0:e.error)){this.render();return}if(n){this._updateLoadingState(t.loading);return}r&&(this.currentView=t.view),r?(this._updateTitle(),this._updateViewButtons(),this._switchView()):i?(this._updateTitle(),this._updateViewContent()):s&&this._updateViewContent()}_updateTitle(){const t=this.$(".fc-title");if(t){const e=this.stateManager.getState();t.textContent=this.getTitle(e.currentDate,e.view)}}_updateViewButtons(){const t=this.stateManager.getState();this.$$("[data-view]").forEach(e=>{const r=e.dataset.view===t.view;e.classList.toggle("active",r)})}_switchView(){const t=this.$("#calendar-view-container");if(t){this._currentViewInstance&&this._currentViewInstance.cleanup&&this._currentViewInstance.cleanup();try{const e=b.RENDERERS[this.currentView]||D,r=new e(t,this.stateManager);r._viewType=this.currentView,this._currentViewInstance=r,r.render()}catch(e){console.error("[ForceCalendar] Error switching view:",e)}}}_updateViewContent(){this._currentViewInstance&&this._currentViewInstance.render&&this._currentViewInstance.render()}_updateLoadingState(t){const e=this.$(".fc-loading"),r=this.$(".fc-view-container");e&&(e.style.display=t?"flex":"none"),r&&(r.style.display=t?"none":"flex")}mount(){this.currentView=this.stateManager.getView(),super.mount()}loadView(t){!t||this.currentView===t||(this.currentView=t,this._switchView(),this._updateViewButtons(),this._updateTitle())}getStyles(){const t=this.getAttribute("height")||"800px";return`
618
+ `}afterRender(){this.modalContent=this.$(".modal-content"),this.titleInput=this.$("#event-title"),this.startInput=this.$("#event-start"),this.endInput=this.$("#event-end"),this.colorContainer=this.$("#color-picker"),this.titleGroup=this.$("#title-group"),this.endGroup=this.$("#end-group"),this.addListener(this.$("#close-x"),"click",()=>this.close()),this.addListener(this.$("#cancel-btn"),"click",()=>this.close()),this.addListener(this.$("#save-btn"),"click",()=>this.save()),this.colorContainer.querySelectorAll(".color-btn").forEach(t=>{this.addListener(t,"click",e=>{this._formData.color=e.currentTarget.dataset.color,this.updateColorSelection()})}),this.addListener(this,"click",t=>{t.target===this&&this.close()}),this._keydownListenerAdded||(this._handleKeyDown=t=>{t.key==="Escape"&&this.hasAttribute("open")&&this.close()},window.addEventListener("keydown",this._handleKeyDown),this._keydownListenerAdded=!0)}updateColorSelection(){this.colorContainer.querySelectorAll(".color-btn").forEach(e=>{const r=e.dataset.color===this._formData.color;e.classList.toggle("selected",r),e.setAttribute("aria-checked",r?"true":"false")})}open(t=new Date){this.hasAttribute("open")||this.setAttribute("open",""),this.titleGroup.classList.remove("has-error"),this.endGroup.classList.remove("has-error"),this._formData.start=t,this._formData.end=new Date(t.getTime()+this.config.defaultDuration*60*1e3),this._formData.title="",this._formData.color=this.config.colors[0].color,this.startInput&&(this.titleInput.value="",this.startInput.value=this.formatDateForInput(this._formData.start),this.endInput.value=this.formatDateForInput(this._formData.end),this.updateColorSelection(),this._cleanupFocusTrap&&this._cleanupFocusTrap(),this._cleanupFocusTrap=w.trapFocus(this.modalContent))}close(){this.removeAttribute("open"),this._cleanupFocusTrap&&(this._cleanupFocusTrap(),this._cleanupFocusTrap=null)}validate(){let t=!0;this.titleGroup.classList.remove("has-error"),this.endGroup.classList.remove("has-error"),this.titleInput.value.trim()||(this.titleGroup.classList.add("has-error"),t=!1);const e=new Date(this.startInput.value);return new Date(this.endInput.value)<=e&&(this.endGroup.classList.add("has-error"),t=!1),t}save(){if(!this.validate())return;const t={title:this.titleInput.value.trim(),start:new Date(this.startInput.value),end:new Date(this.endInput.value),backgroundColor:this._formData.color};this.emit("save",t),this.close()}formatDateForInput(t){const e=o=>String(o).padStart(2,"0"),r=t.getFullYear(),i=e(t.getMonth()+1),s=e(t.getDate()),n=e(t.getHours()),a=e(t.getMinutes());return`${r}-${i}-${s}T${n}:${a}`}unmount(){this._cleanupFocusTrap&&this._cleanupFocusTrap(),this._handleKeyDown&&(window.removeEventListener("keydown",this._handleKeyDown),this._handleKeyDown=null,this._keydownListenerAdded=!1)}}customElements.get("forcecal-event-form")||customElements.define("forcecal-event-form",I);const b=class b extends g{static get observedAttributes(){return["view","date","locale","timezone","week-starts-on","height"]}constructor(){super(),this.stateManager=null,this.currentView=null,this._hasRendered=!1,this._busUnsubscribers=[]}initialize(){const t={view:this.getAttribute("view")||"month",date:this.getAttribute("date")?new Date(this.getAttribute("date")):new Date,locale:this.getAttribute("locale")||"en-US",timeZone:this.getAttribute("timezone")||Intl.DateTimeFormat().resolvedOptions().timeZone,weekStartsOn:parseInt(this.getAttribute("week-starts-on")||"0")};this.stateManager=new C(t),this._stateUnsubscribe=this.stateManager.subscribe(this.handleStateChange.bind(this)),this.setupEventListeners()}setupEventListeners(){this._busUnsubscribers.forEach(r=>r()),this._busUnsubscribers=[];const t=this.stateManager.eventBus;this._busUnsubscribers.push(t.on("navigation:*",(r,i)=>{this.emit("calendar-navigate",{action:i.split(":")[1],...r})})),this._busUnsubscribers.push(t.on("view:changed",r=>{this.emit("calendar-view-change",r)}));const e=(r,i)=>{this.emit(`calendar-event-${r}`,i)};this._busUnsubscribers.push(t.on("event:add",r=>{e("add",r)})),this._busUnsubscribers.push(t.on("event:update",r=>{e("update",r)})),this._busUnsubscribers.push(t.on("event:remove",r=>{e("remove",r)})),this._busUnsubscribers.push(t.on("event:added",r=>{this.emit("calendar-event-added",r)})),this._busUnsubscribers.push(t.on("event:updated",r=>{this.emit("calendar-event-updated",r)})),this._busUnsubscribers.push(t.on("event:deleted",r=>{this.emit("calendar-event-deleted",r)})),this._busUnsubscribers.push(t.on("date:selected",r=>{this.emit("calendar-date-select",r)}))}handleStateChange(t,e){var o,c;if(!this._hasRendered)return;const r=t.view!==(e==null?void 0:e.view),i=((o=t.currentDate)==null?void 0:o.getTime())!==((c=e==null?void 0:e.currentDate)==null?void 0:c.getTime()),s=t.events!==(e==null?void 0:e.events),n=t.loading!==(e==null?void 0:e.loading);if(t.error!==(e==null?void 0:e.error)){this.render();return}if(n){this._updateLoadingState(t.loading);return}r&&(this.currentView=t.view),r?(this._updateTitle(),this._updateViewButtons(),this._switchView()):i?(this._updateTitle(),this._updateViewContent()):s&&this._updateViewContent()}_updateTitle(){const t=this.$(".fc-title");if(t){const e=this.stateManager.getState();t.textContent=this.getTitle(e.currentDate,e.view)}}_updateViewButtons(){const t=this.stateManager.getState();this.$$("[data-view]").forEach(e=>{const r=e.dataset.view===t.view;e.classList.toggle("active",r)})}_switchView(){const t=this.$("#calendar-view-container");if(t){this._currentViewInstance&&this._currentViewInstance.cleanup&&this._currentViewInstance.cleanup();try{const e=b.RENDERERS[this.currentView]||D,r=new e(t,this.stateManager);r._viewType=this.currentView,this._currentViewInstance=r,r.render()}catch(e){console.error("[ForceCalendar] Error switching view:",e)}}}_updateViewContent(){this._currentViewInstance&&this._currentViewInstance.render&&this._currentViewInstance.render()}_updateLoadingState(t){const e=this.$(".fc-loading"),r=this.$(".fc-view-container");e&&(e.style.display=t?"flex":"none"),r&&(r.style.display=t?"none":"flex")}mount(){this.currentView=this.stateManager.getView(),super.mount()}loadView(t){!t||this.currentView===t||(this.currentView=t,this._switchView(),this._updateViewButtons(),this._updateTitle())}getStyles(){const t=this.getAttribute("height")||"800px";return`
619
619
  ${f.getBaseStyles()}
620
620
  ${f.getButtonStyles()}
621
621
  ${f.getGridStyles()}