@forcecalendar/interface 1.0.43 → 1.0.45
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.
- package/dist/force-calendar-interface.esm.js +567 -568
- package/dist/force-calendar-interface.esm.js.map +1 -1
- package/dist/force-calendar-interface.umd.js +12 -12
- package/dist/force-calendar-interface.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ForceCalendar.js +17 -2
- package/src/core/EventBus.js +4 -15
- package/src/core/StateManager.js +4 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(l,
|
|
1
|
+
(function(l,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@forcecalendar/core")):typeof define=="function"&&define.amd?define(["exports","@forcecalendar/core"],u):(l=typeof globalThis<"u"?globalThis:l||self,u(l.ForceCalendarInterface={},l.ForceCalendarCore))})(this,function(l,u){"use strict";var B=Object.defineProperty;var A=(l,u,v)=>u in l?B(l,u,{enumerable:!0,configurable:!0,writable:!0,value:v}):l[u]=v;var y=(l,u,v)=>A(l,typeof u!="symbol"?u+"":u,v);class v extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this._listeners=[],this._state=null,this._props=new Map,this._initialized=!1}connectedCallback(){this._initialized||(this.initialize(),this._initialized=!0),this.mount()}disconnectedCallback(){this.unmount(),this.cleanup()}initialize(){}mount(){this.render()}unmount(){}cleanup(){this._listeners.forEach(({element:e,event:t,handler:r})=>{e.removeEventListener(t,r)}),this._listeners=[]}setState(e){const t=this._state;this._state={...this._state,...e},this.stateChanged(t,this._state),this.render()}getState(){return this._state}stateChanged(e,t){}setProp(e,t){const r=this._props.get(e);this._props.set(e,t),this.propChanged(e,r,t)}getProp(e){return this._props.get(e)}propChanged(e,t,r){}addListener(e,t,r){if(!e||!t||!r){console.warn("addListener called with invalid parameters",{element:e,event:t,handler:r});return}const i=r.bind(this);e.addEventListener(t,i),this._listeners.push({element:e,event:t,handler:i})}emit(e,t={}){this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}getStyles(){return""}getBaseStyles(){return`
|
|
2
2
|
:host {
|
|
3
3
|
display: block;
|
|
4
4
|
box-sizing: border-box;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
${this.getBaseStyles()}
|
|
13
13
|
${this.getStyles()}
|
|
14
14
|
</style>
|
|
15
|
-
`,t=this.template();this.shadowRoot.innerHTML=e+t,this.afterRender()}template(){return""}afterRender(){}$(e){return this.shadowRoot.querySelector(e)}$$(e){return this.shadowRoot.querySelectorAll(e)}static get observedAttributes(){return[]}attributeChangedCallback(e,t,r){this.setProp(e,r),this._initialized&&this.render()}}class k{constructor(){this.events=new Map,this.wildcardHandlers=new Set}on(e,t,r={}){const{once:i=!1,priority:s=0}=r;if(e.includes("*")){const a={pattern:e,handler:t,once:i,priority:s};return this.wildcardHandlers.add(a),()=>this.wildcardHandlers.delete(a)}this.events.has(e)||this.events.set(e,[]);const n={handler:t,once:i,priority:s},o=this.events.get(e);return o.push(n),o.sort((a,c)=>c.priority-a.priority),()=>{const a=o.indexOf(n);a>-1&&o.splice(a,1)}}once(e,t,r={}){return this.on(e,t,{...r,once:!0})}off(e,t){if(e.includes("*")){for(const s of this.wildcardHandlers)if(s.pattern===e&&s.handler===t){this.wildcardHandlers.delete(s);return}return}if(!this.events.has(e))return;const r=this.events.get(e),i=r.findIndex(s=>s.handler===t);i>-1&&r.splice(i,1),r.length===0&&this.events.delete(e)}offWildcard(e){for(const t of[...this.wildcardHandlers])t.pattern===e&&this.wildcardHandlers.delete(t)}offAll(e){for(const[t,r]of this.events){const i=r.findIndex(s=>s.handler===e);i>-1&&r.splice(i,1),r.length===0&&this.events.delete(t)}for(const t of[...this.wildcardHandlers])t.handler===e&&this.wildcardHandlers.delete(t)}async emit(e,t){const r=[];if(this.events.has(e)){const s=[...this.events.get(e)];for(const n of s){const{handler:o,once:a}=n;a&&this.off(e,o);try{const c=o(t,e);c instanceof Promise&&r.push(c)}catch(c){console.error(`Error in event handler for ${e}:`,c)}}}const i=[];for(const s of[...this.wildcardHandlers])if(this.matchesPattern(e,s.pattern)){const{handler:n,once:o}=s;o&&i.push(s);try{const a=n(t,e);a instanceof Promise&&r.push(a)}catch(a){console.error(`Error in wildcard handler for ${e}:`,a)}}return i.forEach(s=>this.wildcardHandlers.delete(s)),Promise.all(r)}matchesPattern(e,t){return new RegExp("^"+t.replace(/\*/g,".*")+"$").test(e)}clear(){this.events.clear(),this.wildcardHandlers.clear()}getEventNames(){return Array.from(this.events.keys())}getHandlerCount(e){return this.events.has(e)?this.events.get(e).length:0}getWildcardHandlerCount(){return this.wildcardHandlers.size}getTotalHandlerCount(){let e=this.wildcardHandlers.size;for(const t of this.events.values())e+=t.length;return e}}const V=new k;class S{constructor(e={}){this.eventBus=new k,this.calendar=new f.Calendar({view:e.view||"month",date:e.date||new Date,weekStartsOn:e.weekStartsOn??0,locale:e.locale||"en-US",timeZone:e.timeZone||Intl.DateTimeFormat().resolvedOptions().timeZone,...e}),this.state={view:this.calendar.getView(),currentDate:this.calendar.getCurrentDate(),events:[],selectedEvent:null,selectedDate:null,loading:!1,error:null,config:{...e}},this.subscribers=new Set,this.subscribe=this.subscribe.bind(this),this.unsubscribe=this.unsubscribe.bind(this),this.setState=this.setState.bind(this),this._syncEventsFromCore({silent:!0})}_syncEventsFromCore(e={}){const{force:t=!1}=e,r=this.calendar.getEvents()||[];return(t||this.state.events.length!==r.length||!this._eventsMatch(this.state.events,r))&&this.setState({events:[...r]},e),r}_eventsMatch(e,t){if(e.length!==t.length)return!1;const r=new Set(e.map(i=>i.id));return t.every(i=>r.has(i.id))}getState(){return{...this.state,config:{...this.state.config},events:[...this.state.events]}}setState(e,t={}){const{silent:r=!1}=t,i={...this.state};return this.state={...this.state,...e},r||(this.notifySubscribers(i,this.state),this.emitStateChange(i,this.state)),this.state}subscribe(e,t=null){return this.subscribers.add(e),t&&(this._subscriberIds||(this._subscriberIds=new Map),this._subscriberIds.set(t,e)),()=>this.unsubscribe(e,t)}unsubscribe(e,t=null){this.subscribers.delete(e),t&&this._subscriberIds&&this._subscriberIds.delete(t)}unsubscribeById(e){if(!this._subscriberIds)return!1;const t=this._subscriberIds.get(e);return t?(this.subscribers.delete(t),this._subscriberIds.delete(e),!0):!1}getSubscriberCount(){return this.subscribers.size}notifySubscribers(e,t){this.subscribers.forEach(r=>{try{r(t,e)}catch(i){console.error("Error in state subscriber:",i)}})}emitStateChange(e,t){const r=Object.keys(t).filter(i=>e[i]!==t[i]);r.forEach(i=>{this.eventBus.emit(`state:${i}:changed`,{oldValue:e[i],newValue:t[i],state:t})}),r.length>0&&this.eventBus.emit("state:changed",{oldState:e,newState:t,changedKeys:r})}setView(e){this.calendar.setView(e),this.setState({view:e}),this.eventBus.emit("view:changed",{view:e})}getView(){return this.state.view}setDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),this.eventBus.emit("date:changed",{date:this.state.currentDate})}getCurrentDate(){return this.state.currentDate}next(){this.calendar.next(),this.setState({currentDate:this.calendar.getCurrentDate()}),this.eventBus.emit("navigation:next",{date:this.state.currentDate})}previous(){this.calendar.previous(),this.setState({currentDate:this.calendar.getCurrentDate()}),this.eventBus.emit("navigation:previous",{date:this.state.currentDate})}today(){this.calendar.today(),this.setState({currentDate:this.calendar.getCurrentDate()}),this.eventBus.emit("navigation:today",{date:this.state.currentDate})}goToDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),this.eventBus.emit("navigation:goto",{date:this.state.currentDate})}addEvent(e){const t=this.calendar.addEvent(e);return t?(this._syncEventsFromCore(),this.eventBus.emit("event:add",{event:t}),this.eventBus.emit("event:added",{event:t}),t):(console.error("Failed to add event to calendar"),this.eventBus.emit("event:error",{action:"add",event:e,error:"Failed to add event"}),null)}updateEvent(e,t){this._syncEventsFromCore({silent:!0});const r=this.calendar.updateEvent(e,t);return r?(this._syncEventsFromCore({force:!0}),this.eventBus.emit("event:update",{event:r}),this.eventBus.emit("event:updated",{event:r}),r):(console.error(`Failed to update event: ${e}`),this.eventBus.emit("event:error",{action:"update",eventId:e,updates:t,error:"Event not found in calendar"}),null)}deleteEvent(e){return this._syncEventsFromCore({silent:!0}),this.calendar.removeEvent(e)?(this._syncEventsFromCore(),this.eventBus.emit("event:remove",{eventId:e}),this.eventBus.emit("event:deleted",{eventId:e}),!0):(console.error(`Failed to delete event: ${e}`),this.eventBus.emit("event:error",{action:"delete",eventId:e,error:"Event not found"}),!1)}getEvents(){return this.calendar.getEvents()||[]}syncEvents(){return this._syncEventsFromCore()}getEventsForDate(e){return this.calendar.getEventsForDate(e)}getEventsInRange(e,t){return this.calendar.getEventsInRange(e,t)}getViewData(){const e=this.calendar.getViewData();return this.enrichViewData(e)}enrichViewData(e){var i;const t={...e},r=(i=this.state.selectedDate)==null?void 0:i.toDateString();if(t.weeks&&(t.weeks=t.weeks.map(s=>({...s,days:s.days.map(n=>{const o=new Date(n.date);return{...n,isSelected:o.toDateString()===r,events:n.events||this.getEventsForDate(o)}})}))),t.days&&(t.days=t.days.map(s=>{const n=new Date(s.date);return{...s,isSelected:n.toDateString()===r,events:s.events||this.getEventsForDate(n)}})),t.date&&!t.days&&!t.weeks){const s=new Date(t.date);t.isSelected=s.toDateString()===r,t.events=t.events||this.getEventsForDate(s)}return t}selectEvent(e){this.setState({selectedEvent:e}),this.eventBus.emit("event:selected",{event:e})}selectEventById(e){const t=this.state.events.find(r=>r.id===e);t&&this.selectEvent(t)}deselectEvent(){this.setState({selectedEvent:null}),this.eventBus.emit("event:deselected",{})}selectDate(e){this.setState({selectedDate:e}),this.eventBus.emit("date:selected",{date:e})}deselectDate(){this.setState({selectedDate:null}),this.eventBus.emit("date:deselected",{})}isToday(e){const t=new Date;return e.toDateString()===t.toDateString()}isSelectedDate(e){return this.state.selectedDate&&e.toDateString()===this.state.selectedDate.toDateString()}isWeekend(e){const t=e.getDay();return t===0||t===6}setLoading(e){this.setState({loading:e})}setError(e){this.setState({error:e}),e&&this.eventBus.emit("error",{error:e})}clearError(){this.setState({error:null})}updateConfig(e){this.setState({config:{...this.state.config,...e}}),e.weekStartsOn!==void 0&&this.calendar.setWeekStartsOn(e.weekStartsOn),e.locale!==void 0&&this.calendar.setLocale(e.locale),e.timeZone!==void 0&&this.calendar.setTimezone(e.timeZone)}destroy(){this.subscribers.clear(),this._subscriberIds&&(this._subscriberIds.clear(),this._subscriberIds=null),this.state=null,this.calendar=null}}class m extends f.DateUtils{static formatDate(e,t="default",r="en-US"){if(!e)return"";const i={default:{year:"numeric",month:"long",day:"numeric"},short:{year:"numeric",month:"short",day:"numeric"},long:{weekday:"long",year:"numeric",month:"long",day:"numeric"},month:{year:"numeric",month:"long"},monthShort:{year:"numeric",month:"short"},day:{weekday:"long",day:"numeric"},dayShort:{weekday:"short",day:"numeric"},time:{hour:"numeric",minute:"2-digit"},timeShort:{hour:"numeric"},datetime:{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}},s=i[t]||i.default;return new Intl.DateTimeFormat(r,s).format(e)}static formatTime(e,t=!0,r=!1,i="en-US"){if(!e)return"";const s={hour:"numeric",minute:t?"2-digit":void 0,hour12:!r};return new Intl.DateTimeFormat(i,s).format(e)}static formatDateRange(e,t,r="en-US"){if(!e)return"";if(!t||this.isSameDay(e,t))return this.formatDate(e,"default",r);const i=this.isSameYear(e,t)?"short":"default";return`${this.formatDate(e,i,r)} - ${this.formatDate(t,"default",r)}`}static formatTimeRange(e,t,r="en-US"){if(!e)return"";const i=this.formatTime(e,!0,!1,r);if(!t)return i;const s=this.formatTime(t,!0,!1,r);return`${i} - ${s}`}static getRelativeTime(e,t=new Date,r="en-US"){const i=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),s=e-t,n=Math.floor(s/1e3),o=Math.floor(n/60),a=Math.floor(o/60),c=Math.floor(a/24),d=Math.floor(c/7),h=Math.floor(c/30),p=Math.floor(c/365);return Math.abs(n)<60?i.format(n,"second"):Math.abs(o)<60?i.format(o,"minute"):Math.abs(a)<24?i.format(a,"hour"):Math.abs(c)<7?i.format(c,"day"):Math.abs(d)<4?i.format(d,"week"):Math.abs(h)<12?i.format(h,"month"):i.format(p,"year")}static isToday(e){const t=new Date;return this.isSameDay(e,t)}static isPast(e){return e<new Date}static isFuture(e){return e>new Date}static getWeekNumber(e){const t=new Date(e.getFullYear(),0,1),r=(e-t)/864e5;return Math.ceil((r+t.getDay()+1)/7)}static getDayAbbreviation(e,t="en-US"){const r=new Date(2024,0,7+e);return new Intl.DateTimeFormat(t,{weekday:"short"}).format(r)}static getMonthName(e,t="long",r="en-US"){const i=new Date(2024,e,1);return new Intl.DateTimeFormat(r,{month:t}).format(i)}static parseTimeString(e,t=new Date){const r=new Date(t),[i,s]=e.split(/\s+/),[n,o]=i.split(":").map(Number);let a=n;return s&&(s.toLowerCase()==="pm"&&n<12?a=n+12:s.toLowerCase()==="am"&&n===12&&(a=0)),r.setHours(a,o||0,0,0),r}}class w{static createElement(e,t={},r=[]){const i=document.createElement(e);return Object.entries(t).forEach(([s,n])=>{if(s==="className")i.className=n;else if(s==="style"&&typeof n=="object")Object.assign(i.style,n);else if(s.startsWith("data-"))i.setAttribute(s,n);else if(s.startsWith("on")&&typeof n=="function"){const o=s.slice(2).toLowerCase();i.addEventListener(o,n)}else i[s]=n}),r.forEach(s=>{typeof s=="string"?i.appendChild(document.createTextNode(s)):s instanceof Node&&i.appendChild(s)}),i}static addEventListeners(e,t){return Object.entries(t).forEach(([r,i])=>{e.addEventListener(r,i)}),()=>{Object.entries(t).forEach(([r,i])=>{e.removeEventListener(r,i)})}}static delegate(e,t,r,i){const s=n=>{const o=n.target.closest(t);o&&e.contains(o)&&i.call(o,n)};return e.addEventListener(r,s),()=>e.removeEventListener(r,s)}static getPosition(e){const t=e.getBoundingClientRect();return{top:t.top+window.scrollY,left:t.left+window.scrollX,bottom:t.bottom+window.scrollY,right:t.right+window.scrollX,width:t.width,height:t.height}}static isInViewport(e,t=0){const r=e.getBoundingClientRect();return r.top>=-t&&r.left>=-t&&r.bottom<=(window.innerHeight||document.documentElement.clientHeight)+t&&r.right<=(window.innerWidth||document.documentElement.clientWidth)+t}static scrollToElement(e,t={}){const{behavior:r="smooth",block:i="start",inline:s="nearest"}=t;e.scrollIntoView({behavior:r,block:i,inline:s})}static getStyle(e,t){return window.getComputedStyle(e).getPropertyValue(t)}static setStyles(e,t){Object.assign(e.style,t)}static async animateClass(e,t,r=300){e.classList.add(t),await this.wait(r),e.classList.remove(t)}static waitForAnimation(e,t="animationend"){return new Promise(r=>{const i=()=>{e.removeEventListener(t,i),r()};e.addEventListener(t,i)})}static wait(e){return new Promise(t=>setTimeout(t,e))}static parseHTML(e){const t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}static escapeHTML(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}static debounce(e,t=250){let r;return function(...s){const n=()=>{clearTimeout(r),e(...s)};clearTimeout(r),r=setTimeout(n,t)}}static throttle(e,t=250){let r;return function(...i){r||(e.apply(this,i),r=!0,setTimeout(()=>r=!1,t))}}static closest(e,t){return e.closest(t)}static parents(e,t){const r=[];let i=e.parentElement;for(;i;)i.matches(t)&&r.push(i),i=i.parentElement;return r}static getOuterDimensions(e){const t=window.getComputedStyle(e),r={top:parseInt(t.marginTop),right:parseInt(t.marginRight),bottom:parseInt(t.marginBottom),left:parseInt(t.marginLeft)};return{width:e.offsetWidth+r.left+r.right,height:e.offsetHeight+r.top+r.bottom,margin:r}}static cloneWithEvents(e,t=!0){return e.cloneNode(t)}static trapFocus(e){const t=e.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(t.length===0)return e.setAttribute("tabindex","-1"),e.focus(),()=>e.removeAttribute("tabindex");const r=t[0],i=t[t.length-1],s=n=>{n.key==="Tab"&&(n.shiftKey?document.activeElement===r&&(i==null||i.focus(),n.preventDefault()):document.activeElement===i&&(r==null||r.focus(),n.preventDefault()))};return e.addEventListener("keydown",s),r==null||r.focus(),()=>e.removeEventListener("keydown",s)}}class u{static getCSSVariable(e,t=document.documentElement){return getComputedStyle(t).getPropertyValue(e).trim()}static setCSSVariables(e,t=document.documentElement){Object.entries(e).forEach(([r,i])=>{t.style.setProperty(r,i)})}static getBaseStyles(){return`
|
|
15
|
+
`,t=this.template();this.shadowRoot.innerHTML=e+t,this.afterRender()}template(){return""}afterRender(){}$(e){return this.shadowRoot.querySelector(e)}$$(e){return this.shadowRoot.querySelectorAll(e)}static get observedAttributes(){return[]}attributeChangedCallback(e,t,r){this.setProp(e,r),this._initialized&&this.render()}}class k{constructor(){this.events=new Map,this.wildcardHandlers=new Set}on(e,t,r={}){const{once:i=!1,priority:s=0}=r;if(e.includes("*")){const a={pattern:e,handler:t,once:i,priority:s};return this.wildcardHandlers.add(a),()=>this.wildcardHandlers.delete(a)}this.events.has(e)||this.events.set(e,[]);const n={handler:t,once:i,priority:s},o=this.events.get(e);return o.push(n),o.sort((a,c)=>c.priority-a.priority),()=>{const a=o.indexOf(n);a>-1&&o.splice(a,1)}}once(e,t,r={}){return this.on(e,t,{...r,once:!0})}off(e,t){if(e.includes("*")){for(const s of this.wildcardHandlers)if(s.pattern===e&&s.handler===t){this.wildcardHandlers.delete(s);return}return}if(!this.events.has(e))return;const r=this.events.get(e),i=r.findIndex(s=>s.handler===t);i>-1&&r.splice(i,1),r.length===0&&this.events.delete(e)}offWildcard(e){for(const t of[...this.wildcardHandlers])t.pattern===e&&this.wildcardHandlers.delete(t)}offAll(e){for(const[t,r]of this.events){const i=r.findIndex(s=>s.handler===e);i>-1&&r.splice(i,1),r.length===0&&this.events.delete(t)}for(const t of[...this.wildcardHandlers])t.handler===e&&this.wildcardHandlers.delete(t)}emit(e,t){if(this.events.has(e)){const i=[...this.events.get(e)];for(const s of i){const{handler:n,once:o}=s;o&&this.off(e,n);try{n(t,e)}catch(a){console.error(`Error in event handler for ${e}:`,a)}}}const r=[];for(const i of[...this.wildcardHandlers])if(this.matchesPattern(e,i.pattern)){const{handler:s,once:n}=i;n&&r.push(i);try{s(t,e)}catch(o){console.error(`Error in wildcard handler for ${e}:`,o)}}r.forEach(i=>this.wildcardHandlers.delete(i))}matchesPattern(e,t){return new RegExp("^"+t.replace(/\*/g,".*")+"$").test(e)}clear(){this.events.clear(),this.wildcardHandlers.clear()}getEventNames(){return Array.from(this.events.keys())}getHandlerCount(e){return this.events.has(e)?this.events.get(e).length:0}getWildcardHandlerCount(){return this.wildcardHandlers.size}getTotalHandlerCount(){let e=this.wildcardHandlers.size;for(const t of this.events.values())e+=t.length;return e}}const V=new k;class S{constructor(e={}){this.eventBus=new k,this.calendar=new u.Calendar({view:e.view||"month",date:e.date||new Date,weekStartsOn:e.weekStartsOn??0,locale:e.locale||"en-US",timeZone:e.timeZone||Intl.DateTimeFormat().resolvedOptions().timeZone,...e}),this.state={view:this.calendar.getView(),currentDate:this.calendar.getCurrentDate(),events:[],selectedEvent:null,selectedDate:null,loading:!1,error:null,config:{...e}},this.subscribers=new Set,this.subscribe=this.subscribe.bind(this),this.unsubscribe=this.unsubscribe.bind(this),this.setState=this.setState.bind(this),this._syncEventsFromCore({silent:!0})}_syncEventsFromCore(e={}){const{force:t=!1}=e,r=this.calendar.getEvents()||[];return(t||this.state.events.length!==r.length||!this._eventsMatch(this.state.events,r))&&this.setState({events:[...r]},e),r}_eventsMatch(e,t){if(e.length!==t.length)return!1;const r=new Set(e.map(i=>i.id));return t.every(i=>r.has(i.id))}getState(){return{...this.state,config:{...this.state.config},events:[...this.state.events]}}setState(e,t={}){const{silent:r=!1}=t,i={...this.state};return this.state={...this.state,...e},r||(this.notifySubscribers(i,this.state),this.emitStateChange(i,this.state)),this.state}subscribe(e,t=null){return this.subscribers.add(e),t&&(this._subscriberIds||(this._subscriberIds=new Map),this._subscriberIds.set(t,e)),()=>this.unsubscribe(e,t)}unsubscribe(e,t=null){this.subscribers.delete(e),t&&this._subscriberIds&&this._subscriberIds.delete(t)}unsubscribeById(e){if(!this._subscriberIds)return!1;const t=this._subscriberIds.get(e);return t?(this.subscribers.delete(t),this._subscriberIds.delete(e),!0):!1}getSubscriberCount(){return this.subscribers.size}notifySubscribers(e,t){this.subscribers.forEach(r=>{try{r(t,e)}catch(i){console.error("Error in state subscriber:",i)}})}emitStateChange(e,t){const r=Object.keys(t).filter(i=>e[i]!==t[i]);r.forEach(i=>{this.eventBus.emit(`state:${i}:changed`,{oldValue:e[i],newValue:t[i],state:t})}),r.length>0&&this.eventBus.emit("state:changed",{oldState:e,newState:t,changedKeys:r})}setView(e){this.calendar.setView(e),this.setState({view:e}),this.eventBus.emit("view:changed",{view:e})}getView(){return this.state.view}setDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),this.eventBus.emit("date:changed",{date:this.state.currentDate})}getCurrentDate(){return this.state.currentDate}next(){this.calendar.next(),this.setState({currentDate:this.calendar.getCurrentDate()}),this.eventBus.emit("navigation:next",{date:this.state.currentDate})}previous(){this.calendar.previous(),this.setState({currentDate:this.calendar.getCurrentDate()}),this.eventBus.emit("navigation:previous",{date:this.state.currentDate})}today(){this.calendar.today(),this.setState({currentDate:this.calendar.getCurrentDate()}),this.eventBus.emit("navigation:today",{date:this.state.currentDate})}goToDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),this.eventBus.emit("navigation:goto",{date:this.state.currentDate})}addEvent(e){const t=this.calendar.addEvent(e);return t?(this._syncEventsFromCore(),this.eventBus.emit("event:add",{event:t}),this.eventBus.emit("event:added",{event:t}),t):(console.error("Failed to add event to calendar"),this.eventBus.emit("event:error",{action:"add",event:e,error:"Failed to add event"}),null)}updateEvent(e,t){this._syncEventsFromCore({silent:!0});const r=this.calendar.updateEvent(e,t);return r?(this._syncEventsFromCore({force:!0}),this.eventBus.emit("event:update",{event:r}),this.eventBus.emit("event:updated",{event:r}),r):(console.error(`Failed to update event: ${e}`),this.eventBus.emit("event:error",{action:"update",eventId:e,updates:t,error:"Event not found in calendar"}),null)}deleteEvent(e){return this._syncEventsFromCore({silent:!0}),this.calendar.removeEvent(e)?(this._syncEventsFromCore(),this.eventBus.emit("event:remove",{eventId:e}),this.eventBus.emit("event:deleted",{eventId:e}),!0):(console.error(`Failed to delete event: ${e}`),this.eventBus.emit("event:error",{action:"delete",eventId:e,error:"Event not found"}),!1)}getEvents(){return this.calendar.getEvents()||[]}syncEvents(){return this._syncEventsFromCore()}getEventsForDate(e){return this.calendar.getEventsForDate(e)}getEventsInRange(e,t){return this.calendar.getEventsInRange(e,t)}getViewData(){const e=this.calendar.getViewData();return this.enrichViewData(e)}enrichViewData(e){var i;const t={...e},r=(i=this.state.selectedDate)==null?void 0:i.toDateString();if(t.weeks&&(t.weeks=t.weeks.map(s=>({...s,days:s.days.map(n=>{const o=new Date(n.date);return{...n,isSelected:o.toDateString()===r,events:n.events||this.getEventsForDate(o)}})}))),t.days&&(t.days=t.days.map(s=>{const n=new Date(s.date);return{...s,isSelected:n.toDateString()===r,events:s.events||this.getEventsForDate(n)}})),t.date&&!t.days&&!t.weeks){const s=new Date(t.date);t.isSelected=s.toDateString()===r,t.events=t.events||this.getEventsForDate(s)}return t}selectEvent(e){this.setState({selectedEvent:e}),this.eventBus.emit("event:selected",{event:e})}selectEventById(e){const t=this.state.events.find(r=>r.id===e);t&&this.selectEvent(t)}deselectEvent(){this.setState({selectedEvent:null}),this.eventBus.emit("event:deselected",{})}selectDate(e){this.setState({selectedDate:e}),this.eventBus.emit("date:selected",{date:e})}deselectDate(){this.setState({selectedDate:null}),this.eventBus.emit("date:deselected",{})}isToday(e){const t=new Date;return e.toDateString()===t.toDateString()}isSelectedDate(e){return this.state.selectedDate&&e.toDateString()===this.state.selectedDate.toDateString()}isWeekend(e){const t=e.getDay();return t===0||t===6}setLoading(e){this.setState({loading:e})}setError(e){this.setState({error:e}),e&&this.eventBus.emit("error",{error:e})}clearError(){this.setState({error:null})}updateConfig(e){this.setState({config:{...this.state.config,...e}}),e.weekStartsOn!==void 0&&this.calendar.setWeekStartsOn(e.weekStartsOn),e.locale!==void 0&&this.calendar.setLocale(e.locale),e.timeZone!==void 0&&this.calendar.setTimezone(e.timeZone)}destroy(){this.subscribers.clear(),this._subscriberIds&&(this._subscriberIds.clear(),this._subscriberIds=null),this.eventBus&&(this.eventBus.clear(),this.eventBus=null),this.state=null,this.calendar=null}}class m extends u.DateUtils{static formatDate(e,t="default",r="en-US"){if(!e)return"";const i={default:{year:"numeric",month:"long",day:"numeric"},short:{year:"numeric",month:"short",day:"numeric"},long:{weekday:"long",year:"numeric",month:"long",day:"numeric"},month:{year:"numeric",month:"long"},monthShort:{year:"numeric",month:"short"},day:{weekday:"long",day:"numeric"},dayShort:{weekday:"short",day:"numeric"},time:{hour:"numeric",minute:"2-digit"},timeShort:{hour:"numeric"},datetime:{year:"numeric",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}},s=i[t]||i.default;return new Intl.DateTimeFormat(r,s).format(e)}static formatTime(e,t=!0,r=!1,i="en-US"){if(!e)return"";const s={hour:"numeric",minute:t?"2-digit":void 0,hour12:!r};return new Intl.DateTimeFormat(i,s).format(e)}static formatDateRange(e,t,r="en-US"){if(!e)return"";if(!t||this.isSameDay(e,t))return this.formatDate(e,"default",r);const i=this.isSameYear(e,t)?"short":"default";return`${this.formatDate(e,i,r)} - ${this.formatDate(t,"default",r)}`}static formatTimeRange(e,t,r="en-US"){if(!e)return"";const i=this.formatTime(e,!0,!1,r);if(!t)return i;const s=this.formatTime(t,!0,!1,r);return`${i} - ${s}`}static getRelativeTime(e,t=new Date,r="en-US"){const i=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),s=e-t,n=Math.floor(s/1e3),o=Math.floor(n/60),a=Math.floor(o/60),c=Math.floor(a/24),d=Math.floor(c/7),h=Math.floor(c/30),p=Math.floor(c/365);return Math.abs(n)<60?i.format(n,"second"):Math.abs(o)<60?i.format(o,"minute"):Math.abs(a)<24?i.format(a,"hour"):Math.abs(c)<7?i.format(c,"day"):Math.abs(d)<4?i.format(d,"week"):Math.abs(h)<12?i.format(h,"month"):i.format(p,"year")}static isToday(e){const t=new Date;return this.isSameDay(e,t)}static isPast(e){return e<new Date}static isFuture(e){return e>new Date}static getWeekNumber(e){const t=new Date(e.getFullYear(),0,1),r=(e-t)/864e5;return Math.ceil((r+t.getDay()+1)/7)}static getDayAbbreviation(e,t="en-US"){const r=new Date(2024,0,7+e);return new Intl.DateTimeFormat(t,{weekday:"short"}).format(r)}static getMonthName(e,t="long",r="en-US"){const i=new Date(2024,e,1);return new Intl.DateTimeFormat(r,{month:t}).format(i)}static parseTimeString(e,t=new Date){const r=new Date(t),[i,s]=e.split(/\s+/),[n,o]=i.split(":").map(Number);let a=n;return s&&(s.toLowerCase()==="pm"&&n<12?a=n+12:s.toLowerCase()==="am"&&n===12&&(a=0)),r.setHours(a,o||0,0,0),r}}class w{static createElement(e,t={},r=[]){const i=document.createElement(e);return Object.entries(t).forEach(([s,n])=>{if(s==="className")i.className=n;else if(s==="style"&&typeof n=="object")Object.assign(i.style,n);else if(s.startsWith("data-"))i.setAttribute(s,n);else if(s.startsWith("on")&&typeof n=="function"){const o=s.slice(2).toLowerCase();i.addEventListener(o,n)}else i[s]=n}),r.forEach(s=>{typeof s=="string"?i.appendChild(document.createTextNode(s)):s instanceof Node&&i.appendChild(s)}),i}static addEventListeners(e,t){return Object.entries(t).forEach(([r,i])=>{e.addEventListener(r,i)}),()=>{Object.entries(t).forEach(([r,i])=>{e.removeEventListener(r,i)})}}static delegate(e,t,r,i){const s=n=>{const o=n.target.closest(t);o&&e.contains(o)&&i.call(o,n)};return e.addEventListener(r,s),()=>e.removeEventListener(r,s)}static getPosition(e){const t=e.getBoundingClientRect();return{top:t.top+window.scrollY,left:t.left+window.scrollX,bottom:t.bottom+window.scrollY,right:t.right+window.scrollX,width:t.width,height:t.height}}static isInViewport(e,t=0){const r=e.getBoundingClientRect();return r.top>=-t&&r.left>=-t&&r.bottom<=(window.innerHeight||document.documentElement.clientHeight)+t&&r.right<=(window.innerWidth||document.documentElement.clientWidth)+t}static scrollToElement(e,t={}){const{behavior:r="smooth",block:i="start",inline:s="nearest"}=t;e.scrollIntoView({behavior:r,block:i,inline:s})}static getStyle(e,t){return window.getComputedStyle(e).getPropertyValue(t)}static setStyles(e,t){Object.assign(e.style,t)}static async animateClass(e,t,r=300){e.classList.add(t),await this.wait(r),e.classList.remove(t)}static waitForAnimation(e,t="animationend"){return new Promise(r=>{const i=()=>{e.removeEventListener(t,i),r()};e.addEventListener(t,i)})}static wait(e){return new Promise(t=>setTimeout(t,e))}static parseHTML(e){const t=document.createElement("template");return t.innerHTML=e.trim(),t.content.firstChild}static escapeHTML(e){const t=document.createElement("div");return t.textContent=e,t.innerHTML}static debounce(e,t=250){let r;return function(...s){const n=()=>{clearTimeout(r),e(...s)};clearTimeout(r),r=setTimeout(n,t)}}static throttle(e,t=250){let r;return function(...i){r||(e.apply(this,i),r=!0,setTimeout(()=>r=!1,t))}}static closest(e,t){return e.closest(t)}static parents(e,t){const r=[];let i=e.parentElement;for(;i;)i.matches(t)&&r.push(i),i=i.parentElement;return r}static getOuterDimensions(e){const t=window.getComputedStyle(e),r={top:parseInt(t.marginTop),right:parseInt(t.marginRight),bottom:parseInt(t.marginBottom),left:parseInt(t.marginLeft)};return{width:e.offsetWidth+r.left+r.right,height:e.offsetHeight+r.top+r.bottom,margin:r}}static cloneWithEvents(e,t=!0){return e.cloneNode(t)}static trapFocus(e){const t=e.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');if(t.length===0)return e.setAttribute("tabindex","-1"),e.focus(),()=>e.removeAttribute("tabindex");const r=t[0],i=t[t.length-1],s=n=>{n.key==="Tab"&&(n.shiftKey?document.activeElement===r&&(i==null||i.focus(),n.preventDefault()):document.activeElement===i&&(r==null||r.focus(),n.preventDefault()))};return e.addEventListener("keydown",s),r==null||r.focus(),()=>e.removeEventListener("keydown",s)}}class f{static getCSSVariable(e,t=document.documentElement){return getComputedStyle(t).getPropertyValue(e).trim()}static setCSSVariables(e,t=document.documentElement){Object.entries(e).forEach(([r,i])=>{t.style.setProperty(r,i)})}static getBaseStyles(){return`
|
|
16
16
|
:host {
|
|
17
17
|
/* Apply CSS variables */
|
|
18
18
|
${Object.entries(this.cssVariables).map(([e,t])=>`${e}: ${t};`).join(`
|
|
@@ -235,7 +235,7 @@
|
|
|
235
235
|
.fc-scale-in {
|
|
236
236
|
animation: fc-scale-in var(--fc-transition);
|
|
237
237
|
}
|
|
238
|
-
`}}y(
|
|
238
|
+
`}}y(f,"colors",{primary:"#3B82F6",secondary:"#64748B",accent:"#F59E0B",danger:"#EF4444",warning:"#F97316",info:"#06B6D4",success:"#22C55E",light:"#F8FAFC",dark:"#0F172A",white:"#FFFFFF",gray:{50:"#F8FAFC",100:"#F1F5F9",200:"#E2E8F0",300:"#CBD5E1",400:"#94A3B8",500:"#64748B",600:"#475569",700:"#334155",800:"#1E293B",900:"#0F172A"}}),y(f,"cssVariables",{"--fc-primary-color":"#2563EB","--fc-primary-hover":"#1D4ED8","--fc-primary-light":"#EFF6FF","--fc-text-color":"#111827","--fc-text-secondary":"#6B7280","--fc-text-light":"#9CA3AF","--fc-border-color":"#E5E7EB","--fc-border-color-hover":"#D1D5DB","--fc-background":"#FFFFFF","--fc-background-alt":"#FAFAFA","--fc-background-hover":"#F3F4F6","--fc-background-active":"#E5E7EB","--fc-accent-color":"#F59E0B","--fc-danger-color":"#EF4444","--fc-success-color":"#10B981","--fc-font-family":'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',"--fc-font-size-xs":"11px","--fc-font-size-sm":"12px","--fc-font-size-base":"13px","--fc-font-size-lg":"15px","--fc-font-size-xl":"18px","--fc-font-size-2xl":"24px","--fc-line-height":"1.4","--fc-font-weight-normal":"400","--fc-font-weight-medium":"500","--fc-font-weight-semibold":"600","--fc-font-weight-bold":"700","--fc-spacing-xs":"2px","--fc-spacing-sm":"6px","--fc-spacing-md":"10px","--fc-spacing-lg":"14px","--fc-spacing-xl":"20px","--fc-spacing-2xl":"28px","--fc-border-width":"1px","--fc-border-radius-sm":"3px","--fc-border-radius":"5px","--fc-border-radius-lg":"8px","--fc-border-radius-full":"9999px","--fc-shadow-sm":"0 1px 1px rgba(0,0,0,0.05)","--fc-shadow":"0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06)","--fc-shadow-md":"0 4px 6px -1px rgba(0, 0, 0, 0.1)","--fc-shadow-lg":"0 10px 15px -3px rgba(0, 0, 0, 0.1)","--fc-transition-fast":"100ms ease-out","--fc-transition":"150ms ease-out","--fc-transition-slow":"250ms ease-out","--fc-z-dropdown":"1000","--fc-z-modal":"2000","--fc-z-tooltip":"3000"}),y(f,"breakpoints",{xs:"320px",sm:"576px",md:"768px",lg:"992px",xl:"1200px","2xl":"1400px"});class x{constructor(e,t){this.container=e,this.stateManager=t,this._listeners=[],this._scrolled=!1}render(){throw new Error("render() must be implemented by subclass")}cleanup(){this._listeners.forEach(({element:e,event:t,handler:r})=>{e.removeEventListener(t,r)}),this._listeners=[]}addListener(e,t,r){const i=r.bind(this);e.addEventListener(t,i),this._listeners.push({element:e,event:t,handler:i})}escapeHTML(e){return e==null?"":w.escapeHTML(String(e))}isToday(e){const t=new Date;return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}isSameDay(e,t){return e.getDate()===t.getDate()&&e.getMonth()===t.getMonth()&&e.getFullYear()===t.getFullYear()}formatHour(e){const t=e>=12?"PM":"AM";return`${e%12||12} ${t}`}formatTime(e){const t=e.getHours(),r=e.getMinutes(),i=t>=12?"PM":"AM",s=t%12||12;return r===0?`${s} ${i}`:`${s}:${r.toString().padStart(2,"0")} ${i}`}getContrastingTextColor(e){if(!e||typeof e!="string")return"white";const t=e.charAt(0)==="#"?e.substring(1):e;if(!/^[0-9A-Fa-f]{3}$|^[0-9A-Fa-f]{6}$/.test(t))return"white";const r=t.length===3?t[0]+t[0]+t[1]+t[1]+t[2]+t[2]:t,i=parseInt(r.substring(0,2),16),s=parseInt(r.substring(2,4),16),n=parseInt(r.substring(4,6),16);if(isNaN(i)||isNaN(s)||isNaN(n))return"white";const a=[i/255,s/255,n/255].map(d=>d<=.03928?d/12.92:Math.pow((d+.055)/1.055,2.4));return .2126*a[0]+.7152*a[1]+.0722*a[2]>.179?"black":"white"}renderNowIndicator(){const e=new Date;return`<div class="fc-now-indicator" style="position: absolute; left: 0; right: 0; top: ${e.getHours()*60+e.getMinutes()}px; height: 2px; background: #dc2626; z-index: 15; pointer-events: none;"></div>`}computeOverlapLayout(e){if(!e||e.length===0)return new Map;const t=e.map(a=>{const c=new Date(a.start),d=new Date(a.end),h=c.getHours()*60+c.getMinutes(),p=Math.max(h+1,d.getHours()*60+d.getMinutes());return{id:a.id,startMin:h,endMin:p}});t.sort((a,c)=>a.startMin-c.startMin||c.endMin-c.startMin-(a.endMin-a.startMin));const r=[],i=new Map;for(const a of t){let c=!1;for(let d=0;d<r.length;d++)if(r[d]<=a.startMin){r[d]=a.endMin,i.set(a.id,{column:d,totalColumns:0}),c=!0;break}c||(i.set(a.id,{column:r.length,totalColumns:0}),r.push(a.endMin))}const s=[];let n=[],o=0;for(const a of t)n.length===0||a.startMin<o?(n.push(a),o=Math.max(o,a.endMin)):(s.push(n),n=[a],o=a.endMin);n.length>0&&s.push(n);for(const a of s){const c=Math.max(...a.map(d=>i.get(d.id).column))+1;for(const d of a)i.get(d.id).totalColumns=c}return i}renderTimedEvent(e,t={}){const{compact:r=!0,overlapLayout:i=null}=t,s=new Date(e.start),n=new Date(e.end),o=s.getHours()*60+s.getMinutes(),a=Math.max((n-s)/(1e3*60),r?20:30),c=this.getEventColor(e),d=r?"4px 8px":"8px 12px",h=r?"11px":"13px",p=r?2:12,_=r?2:24,$=r?"4px":"6px";let M,T;if(i&&i.has(e.id)){const{column:z,totalColumns:H}=i.get(e.id),L=`(100% - ${p+_}px)`;M=`calc(${p}px + ${z} * ${L} / ${H})`,T=`calc(${L} / ${H})`}else M=`${p}px`,T=`calc(100% - ${p+_}px)`;return`
|
|
239
239
|
<div class="fc-event fc-timed-event" data-event-id="${this.escapeHTML(e.id)}"
|
|
240
240
|
style="position: absolute; top: ${o}px; height: ${a}px;
|
|
241
241
|
left: ${M}; width: ${T};
|
|
@@ -251,7 +251,7 @@
|
|
|
251
251
|
${this.formatTime(s)}${r?"":" - "+this.formatTime(n)}
|
|
252
252
|
</div>
|
|
253
253
|
</div>
|
|
254
|
-
`}getEventColor(e){return
|
|
254
|
+
`}getEventColor(e){return f.sanitizeColor(e==null?void 0:e.backgroundColor,"#2563eb")}attachCommonEventHandlers(){this.addListener(this.container,"click",e=>{const t=e.target.closest(".fc-event");if(!t||!this.container.contains(t))return;e.stopPropagation();const r=t.dataset.eventId,i=this.stateManager.getEvents().find(s=>s.id===r);i&&this.stateManager.selectEvent(i)})}}class D extends x{constructor(e,t){super(e,t),this.maxEventsToShow=3}render(){if(!this.container||!this.stateManager)return;const e=this.stateManager.getViewData();if(!e||!e.weeks){this.container.innerHTML='<div style="padding: 20px; text-align: center; color: #666;">No data available for month view.</div>';return}this.cleanup();const t=this.stateManager.getState().config,r=this._renderMonthView(e,t);this.container.innerHTML=r,this._attachEventHandlers()}_renderMonthView(e,t){const r=t.weekStartsOn||0;let s=`
|
|
255
255
|
<div class="fc-month-view" style="display: flex; flex-direction: column; height: 100%; min-height: 400px; background: #fff; border: 1px solid #e5e7eb;">
|
|
256
256
|
<div class="fc-month-header" style="display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid #e5e7eb; background: #f9fafb;">
|
|
257
257
|
${this._getDayNames(r).map(n=>`<div class="fc-month-header-cell" style="padding: 12px 8px; text-align: center; font-size: 11px; font-weight: 600; color: #6b7280; text-transform: uppercase;">${n}</div>`).join("")}
|
|
@@ -394,8 +394,8 @@
|
|
|
394
394
|
${(()=>{const s=this.computeOverlapLayout(e);return e.map(n=>this.renderTimedEvent(n,{compact:!1,overlapLayout:s})).join("")})()}
|
|
395
395
|
</div>
|
|
396
396
|
`}_attachEventHandlers(){this.addListener(this.container,"click",e=>{const t=e.target.closest(".fc-day-column");if(!t||!this.container.contains(t)||e.target.closest(".fc-event"))return;const r=new Date(t.dataset.date),i=this.container.querySelector("#day-scroll-container"),s=t.offsetTop,n=e.clientY-t.getBoundingClientRect().top+(i?i.scrollTop:0)-s,o=Math.max(0,Math.min(n+s,this.totalHeight));r.setHours(Math.floor(o/this.hourHeight),Math.floor(o%this.hourHeight/(this.hourHeight/60)),0,0),this.stateManager.selectDate(r)}),this.attachCommonEventHandlers()}_scrollToCurrentTime(){if(this._scrolled)return;const e=this.container.querySelector("#day-scroll-container");e&&(e.scrollTop=8*this.hourHeight-50,this._scrolled=!0)}}class I extends v{constructor(){super(),this._isVisible=!1,this._cleanupFocusTrap=null,this.config={title:"New Event",defaultDuration:60,colors:[{color:"#2563EB",label:"Blue"},{color:"#10B981",label:"Green"},{color:"#F59E0B",label:"Amber"},{color:"#EF4444",label:"Red"},{color:"#8B5CF6",label:"Purple"},{color:"#6B7280",label:"Gray"}]},this._formData={title:"",start:new Date,end:new Date,allDay:!1,color:this.config.colors[0].color}}static get observedAttributes(){return["open"]}attributeChangedCallback(e,t,r){e==="open"&&(r!==null?this.open():this.close())}getStyles(){return`
|
|
397
|
-
${
|
|
398
|
-
${
|
|
397
|
+
${f.getBaseStyles()}
|
|
398
|
+
${f.getButtonStyles()}
|
|
399
399
|
|
|
400
400
|
:host {
|
|
401
401
|
display: none;
|
|
@@ -615,11 +615,11 @@
|
|
|
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(e=>{this.addListener(e,"click",t=>{this._formData.color=t.currentTarget.dataset.color,this.updateColorSelection()})}),this.addListener(this,"click",e=>{e.target===this&&this.close()}),this._keydownListenerAdded||(this._handleKeyDown=e=>{e.key==="Escape"&&this.hasAttribute("open")&&this.close()},window.addEventListener("keydown",this._handleKeyDown),this._keydownListenerAdded=!0)}updateColorSelection(){this.colorContainer.querySelectorAll(".color-btn").forEach(t=>{const r=t.dataset.color===this._formData.color;t.classList.toggle("selected",r),t.setAttribute("aria-checked",r?"true":"false")})}open(e=new Date){this.hasAttribute("open")||this.setAttribute("open",""),this.titleGroup.classList.remove("has-error"),this.endGroup.classList.remove("has-error"),this._formData.start=e,this._formData.end=new Date(e.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 e=!0;this.titleGroup.classList.remove("has-error"),this.endGroup.classList.remove("has-error"),this.titleInput.value.trim()||(this.titleGroup.classList.add("has-error"),e=!1);const t=new Date(this.startInput.value);return new Date(this.endInput.value)<=t&&(this.endGroup.classList.add("has-error"),e=!1),e}save(){if(!this.validate())return;const e={title:this.titleInput.value.trim(),start:new Date(this.startInput.value),end:new Date(this.endInput.value),backgroundColor:this._formData.color};this.emit("save",e),this.close()}formatDateForInput(e){const t=a=>String(a).padStart(2,"0"),r=e.getFullYear(),i=t(e.getMonth()+1),s=t(e.getDate()),n=t(e.getHours()),o=t(e.getMinutes());return`${r}-${i}-${s}T${n}:${o}`}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 v{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 e={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 S(e),this.stateManager.subscribe(this.handleStateChange.bind(this)),this.setupEventListeners()}setupEventListeners(){this._busUnsubscribers.forEach(r=>r()),this._busUnsubscribers=[];const e=this.stateManager.eventBus;this._busUnsubscribers.push(e.on("navigation:*",(r,i)=>{this.emit("calendar-navigate",{action:i.split(":")[1],...r})})),this._busUnsubscribers.push(e.on("view:changed",r=>{this.emit("calendar-view-change",r)}));const t=(r,i)=>{this.emit(`calendar-event-${r}`,i)};this._busUnsubscribers.push(e.on("event:add",r=>{t("add",r)})),this._busUnsubscribers.push(e.on("event:update",r=>{t("update",r)})),this._busUnsubscribers.push(e.on("event:remove",r=>{t("remove",r)})),this._busUnsubscribers.push(e.on("event:added",r=>{this.emit("calendar-event-added",r)})),this._busUnsubscribers.push(e.on("event:updated",r=>{this.emit("calendar-event-updated",r)})),this._busUnsubscribers.push(e.on("event:deleted",r=>{this.emit("calendar-event-deleted",r)})),this._busUnsubscribers.push(e.on("date:selected",r=>{this.emit("calendar-date-select",r)}))}handleStateChange(e,t){var a,c;if(!this._hasRendered)return;const r=e.view!==(t==null?void 0:t.view),i=((a=e.currentDate)==null?void 0:a.getTime())!==((c=t==null?void 0:t.currentDate)==null?void 0:c.getTime()),s=e.events!==(t==null?void 0:t.events),n=e.loading!==(t==null?void 0:t.loading);if(e.error!==(t==null?void 0:t.error)){this.render();return}if(n){this._updateLoadingState(e.loading);return}r&&(this.currentView=e.view),r?(this._updateTitle(),this._updateViewButtons(),this._switchView()):i?(this._updateTitle(),this._updateViewContent()):s&&this._updateViewContent()}_updateTitle(){const e=this.$(".fc-title");if(e){const t=this.stateManager.getState();e.textContent=this.getTitle(t.currentDate,t.view)}}_updateViewButtons(){const e=this.stateManager.getState();this.$$("[data-view]").forEach(t=>{const r=t.dataset.view===e.view;t.classList.toggle("active",r)})}_switchView(){const e=this.$("#calendar-view-container");if(e){this._currentViewInstance&&this._currentViewInstance.cleanup&&this._currentViewInstance.cleanup();try{const t=b.RENDERERS[this.currentView]||D,r=new t(e,this.stateManager);r._viewType=this.currentView,this._currentViewInstance=r,r.render()}catch(t){console.error("[ForceCalendar] Error switching view:",t)}}}_updateViewContent(){this._currentViewInstance&&this._currentViewInstance.render&&this._currentViewInstance.render()}_updateLoadingState(e){const t=this.$(".fc-loading"),r=this.$(".fc-view-container");t&&(t.style.display=e?"flex":"none"),r&&(r.style.display=e?"none":"flex")}mount(){this.currentView=this.stateManager.getView(),super.mount()}loadView(e){!e||this.currentView===e||(this.currentView=e,this._switchView(),this._updateViewButtons(),this._updateTitle())}getStyles(){const e=this.getAttribute("height")||"800px";return`
|
|
619
|
-
${
|
|
620
|
-
${
|
|
621
|
-
${
|
|
622
|
-
${
|
|
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(e=>{this.addListener(e,"click",t=>{this._formData.color=t.currentTarget.dataset.color,this.updateColorSelection()})}),this.addListener(this,"click",e=>{e.target===this&&this.close()}),this._keydownListenerAdded||(this._handleKeyDown=e=>{e.key==="Escape"&&this.hasAttribute("open")&&this.close()},window.addEventListener("keydown",this._handleKeyDown),this._keydownListenerAdded=!0)}updateColorSelection(){this.colorContainer.querySelectorAll(".color-btn").forEach(t=>{const r=t.dataset.color===this._formData.color;t.classList.toggle("selected",r),t.setAttribute("aria-checked",r?"true":"false")})}open(e=new Date){this.hasAttribute("open")||this.setAttribute("open",""),this.titleGroup.classList.remove("has-error"),this.endGroup.classList.remove("has-error"),this._formData.start=e,this._formData.end=new Date(e.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 e=!0;this.titleGroup.classList.remove("has-error"),this.endGroup.classList.remove("has-error"),this.titleInput.value.trim()||(this.titleGroup.classList.add("has-error"),e=!1);const t=new Date(this.startInput.value);return new Date(this.endInput.value)<=t&&(this.endGroup.classList.add("has-error"),e=!1),e}save(){if(!this.validate())return;const e={title:this.titleInput.value.trim(),start:new Date(this.startInput.value),end:new Date(this.endInput.value),backgroundColor:this._formData.color};this.emit("save",e),this.close()}formatDateForInput(e){const t=a=>String(a).padStart(2,"0"),r=e.getFullYear(),i=t(e.getMonth()+1),s=t(e.getDate()),n=t(e.getHours()),o=t(e.getMinutes());return`${r}-${i}-${s}T${n}:${o}`}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 v{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 e={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 S(e),this._stateUnsubscribe=this.stateManager.subscribe(this.handleStateChange.bind(this)),this.setupEventListeners()}setupEventListeners(){this._busUnsubscribers.forEach(r=>r()),this._busUnsubscribers=[];const e=this.stateManager.eventBus;this._busUnsubscribers.push(e.on("navigation:*",(r,i)=>{this.emit("calendar-navigate",{action:i.split(":")[1],...r})})),this._busUnsubscribers.push(e.on("view:changed",r=>{this.emit("calendar-view-change",r)}));const t=(r,i)=>{this.emit(`calendar-event-${r}`,i)};this._busUnsubscribers.push(e.on("event:add",r=>{t("add",r)})),this._busUnsubscribers.push(e.on("event:update",r=>{t("update",r)})),this._busUnsubscribers.push(e.on("event:remove",r=>{t("remove",r)})),this._busUnsubscribers.push(e.on("event:added",r=>{this.emit("calendar-event-added",r)})),this._busUnsubscribers.push(e.on("event:updated",r=>{this.emit("calendar-event-updated",r)})),this._busUnsubscribers.push(e.on("event:deleted",r=>{this.emit("calendar-event-deleted",r)})),this._busUnsubscribers.push(e.on("date:selected",r=>{this.emit("calendar-date-select",r)}))}handleStateChange(e,t){var a,c;if(!this._hasRendered)return;const r=e.view!==(t==null?void 0:t.view),i=((a=e.currentDate)==null?void 0:a.getTime())!==((c=t==null?void 0:t.currentDate)==null?void 0:c.getTime()),s=e.events!==(t==null?void 0:t.events),n=e.loading!==(t==null?void 0:t.loading);if(e.error!==(t==null?void 0:t.error)){this.render();return}if(n){this._updateLoadingState(e.loading);return}r&&(this.currentView=e.view),r?(this._updateTitle(),this._updateViewButtons(),this._switchView()):i?(this._updateTitle(),this._updateViewContent()):s&&this._updateViewContent()}_updateTitle(){const e=this.$(".fc-title");if(e){const t=this.stateManager.getState();e.textContent=this.getTitle(t.currentDate,t.view)}}_updateViewButtons(){const e=this.stateManager.getState();this.$$("[data-view]").forEach(t=>{const r=t.dataset.view===e.view;t.classList.toggle("active",r)})}_switchView(){const e=this.$("#calendar-view-container");if(e){this._currentViewInstance&&this._currentViewInstance.cleanup&&this._currentViewInstance.cleanup();try{const t=b.RENDERERS[this.currentView]||D,r=new t(e,this.stateManager);r._viewType=this.currentView,this._currentViewInstance=r,r.render()}catch(t){console.error("[ForceCalendar] Error switching view:",t)}}}_updateViewContent(){this._currentViewInstance&&this._currentViewInstance.render&&this._currentViewInstance.render()}_updateLoadingState(e){const t=this.$(".fc-loading"),r=this.$(".fc-view-container");t&&(t.style.display=e?"flex":"none"),r&&(r.style.display=e?"none":"flex")}mount(){this.currentView=this.stateManager.getView(),super.mount()}loadView(e){!e||this.currentView===e||(this.currentView=e,this._switchView(),this._updateViewButtons(),this._updateTitle())}getStyles(){const e=this.getAttribute("height")||"800px";return`
|
|
619
|
+
${f.getBaseStyles()}
|
|
620
|
+
${f.getButtonStyles()}
|
|
621
|
+
${f.getGridStyles()}
|
|
622
|
+
${f.getAnimations()}
|
|
623
623
|
|
|
624
624
|
:host {
|
|
625
625
|
--calendar-height: ${e};
|
|
@@ -1064,5 +1064,5 @@
|
|
|
1064
1064
|
<svg class="fc-icon" viewBox="0 0 24 24">
|
|
1065
1065
|
<path d="M19 3h-1V1h-2v2H8V1H6v2H5c-1.11 0-1.99.9-1.99 2L3 19c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5V8h14v11zM7 10h5v5H7z"/>
|
|
1066
1066
|
</svg>
|
|
1067
|
-
`}[e]||""}addEvent(e){return this.stateManager.addEvent(e)}updateEvent(e,t){return this.stateManager.updateEvent(e,t)}deleteEvent(e){return this.stateManager.deleteEvent(e)}getEvents(){return this.stateManager.getEvents()}setView(e){this.stateManager.setView(e)}setDate(e){this.stateManager.setDate(e)}next(){this.stateManager.next()}previous(){this.stateManager.previous()}today(){this.stateManager.today()}destroy(){this._busUnsubscribers.forEach(e=>e()),this._busUnsubscribers=[],this.stateManager&&this.stateManager.destroy(),super.cleanup()}};y(b,"RENDERERS",{month:D,week:C,day:F});let E=b;customElements.get("forcecal-main")||customElements.define("forcecal-main",E),l.BaseComponent=v,l.BaseViewRenderer=x,l.DOMUtils=w,l.DateUtils=m,l.DayViewRenderer=F,l.EventBus=k,l.ForceCalendar=E,l.MonthViewRenderer=D,l.StateManager=S,l.StyleUtils=
|
|
1067
|
+
`}[e]||""}addEvent(e){return this.stateManager.addEvent(e)}updateEvent(e,t){return this.stateManager.updateEvent(e,t)}deleteEvent(e){return this.stateManager.deleteEvent(e)}getEvents(){return this.stateManager.getEvents()}setView(e){this.stateManager.setView(e)}setDate(e){this.stateManager.setDate(e)}next(){this.stateManager.next()}previous(){this.stateManager.previous()}today(){this.stateManager.today()}unmount(){this.destroy()}destroy(){this._busUnsubscribers.forEach(e=>e()),this._busUnsubscribers=[],this._stateUnsubscribe&&(this._stateUnsubscribe(),this._stateUnsubscribe=null),this._currentViewInstance&&this._currentViewInstance.cleanup&&(this._currentViewInstance.cleanup(),this._currentViewInstance=null),this.stateManager&&this.stateManager.destroy(),super.cleanup()}};y(b,"RENDERERS",{month:D,week:C,day:F});let E=b;customElements.get("forcecal-main")||customElements.define("forcecal-main",E),l.BaseComponent=v,l.BaseViewRenderer=x,l.DOMUtils=w,l.DateUtils=m,l.DayViewRenderer=F,l.EventBus=k,l.ForceCalendar=E,l.MonthViewRenderer=D,l.StateManager=S,l.StyleUtils=f,l.WeekViewRenderer=C,l.eventBus=V,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|
|
1068
1068
|
//# sourceMappingURL=force-calendar-interface.umd.js.map
|