@forcecalendar/interface 1.0.39 → 1.0.41
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 +208 -158
- package/dist/force-calendar-interface.esm.js.map +1 -1
- package/dist/force-calendar-interface.umd.js +33 -33
- package/dist/force-calendar-interface.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/renderers/BaseViewRenderer.js +88 -4
- package/src/renderers/DayViewRenderer.js +5 -1
- package/src/renderers/WeekViewRenderer.js +5 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(h,u){typeof exports=="object"&&typeof module<"u"?u(exports,require("@forcecalendar/core")):typeof define=="function"&&define.amd?define(["exports","@forcecalendar/core"],u):(h=typeof globalThis<"u"?globalThis:h||self,u(h.ForceCalendarInterface={},h.ForceCalendarCore))})(this,function(h,u){"use strict";var z=Object.defineProperty;var A=(h,u,v)=>u in h?z(h,u,{enumerable:!0,configurable:!0,writable:!0,value:v}):h[u]=v;var E=(h,u,v)=>A(h,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 _{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 o={pattern:e,handler:t,once:i,priority:s};return this.wildcardHandlers.add(o),()=>this.wildcardHandlers.delete(o)}this.events.has(e)||this.events.set(e,[]);const n={handler:t,once:i,priority:s},a=this.events.get(e);return a.push(n),a.sort((o,c)=>c.priority-o.priority),()=>{const o=a.indexOf(n);o>-1&&a.splice(o,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:a,once:o}=n;o&&this.off(e,a);try{const c=a(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:a}=s;a&&i.push(s);try{const o=n(t,e);o instanceof Promise&&r.push(o)}catch(o){console.error(`Error in wildcard handler for ${e}:`,o)}}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 d=new _;class ${constructor(e={}){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=>{d.emit(`state:${i}:changed`,{oldValue:e[i],newValue:t[i],state:t})}),r.length>0&&d.emit("state:changed",{oldState:e,newState:t,changedKeys:r})}setView(e){this.calendar.setView(e),this.setState({view:e}),d.emit("view:changed",{view:e})}getView(){return this.state.view}setDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),d.emit("date:changed",{date:this.state.currentDate})}getCurrentDate(){return this.state.currentDate}next(){this.calendar.next(),this.setState({currentDate:this.calendar.getCurrentDate()}),d.emit("navigation:next",{date:this.state.currentDate})}previous(){this.calendar.previous(),this.setState({currentDate:this.calendar.getCurrentDate()}),d.emit("navigation:previous",{date:this.state.currentDate})}today(){this.calendar.today(),this.setState({currentDate:this.calendar.getCurrentDate()}),d.emit("navigation:today",{date:this.state.currentDate})}goToDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),d.emit("navigation:goto",{date:this.state.currentDate})}addEvent(e){const t=this.calendar.addEvent(e);return t?(this._syncEventsFromCore(),d.emit("event:add",{event:t}),d.emit("event:added",{event:t}),t):(console.error("Failed to add event to calendar"),d.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}),d.emit("event:update",{event:r}),d.emit("event:updated",{event:r}),r):(console.error(`Failed to update event: ${e}`),d.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(),d.emit("event:remove",{eventId:e}),d.emit("event:deleted",{eventId:e}),!0):(console.error(`Failed to delete event: ${e}`),d.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 a=new Date(n.date);return{...n,isSelected:a.toDateString()===r,events:n.events||this.getEventsForDate(a)}})}))),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}),d.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}),d.emit("event:deselected",{})}selectDate(e){this.setState({selectedDate:e}),d.emit("date:selected",{date:e})}deselectDate(){this.setState({selectedDate:null}),d.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&&d.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 v 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),a=Math.floor(n/60),o=Math.floor(a/60),c=Math.floor(o/24),h=Math.floor(c/7),f=Math.floor(c/30),y=Math.floor(c/365);return Math.abs(n)<60?i.format(n,"second"):Math.abs(a)<60?i.format(a,"minute"):Math.abs(o)<24?i.format(o,"hour"):Math.abs(c)<7?i.format(c,"day"):Math.abs(h)<4?i.format(h,"week"):Math.abs(f)<12?i.format(f,"month"):i.format(y,"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,a]=i.split(":").map(Number);let o=n;return s&&(s.toLowerCase()==="pm"&&n<12?o=n+12:s.toLowerCase()==="am"&&n===12&&(o=0)),r.setHours(o,a||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 a=s.slice(2).toLowerCase();i.addEventListener(a,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 a=n.target.closest(t);a&&e.contains(a)&&i.call(a,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 p{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 C{constructor(){this.events=new Map,this.wildcardHandlers=new Set}on(e,t,r={}){const{once:i=!1,priority:n=0}=r;if(e.includes("*")){const a={pattern:e,handler:t,once:i,priority:n};return this.wildcardHandlers.add(a),()=>this.wildcardHandlers.delete(a)}this.events.has(e)||this.events.set(e,[]);const s={handler:t,once:i,priority:n},o=this.events.get(e);return o.push(s),o.sort((a,c)=>c.priority-a.priority),()=>{const a=o.indexOf(s);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 n of this.wildcardHandlers)if(n.pattern===e&&n.handler===t){this.wildcardHandlers.delete(n);return}return}if(!this.events.has(e))return;const r=this.events.get(e),i=r.findIndex(n=>n.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(n=>n.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 n=[...this.events.get(e)];for(const s of n){const{handler:o,once:a}=s;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 n of[...this.wildcardHandlers])if(this.matchesPattern(e,n.pattern)){const{handler:s,once:o}=n;o&&i.push(n);try{const a=s(t,e);a instanceof Promise&&r.push(a)}catch(a){console.error(`Error in wildcard handler for ${e}:`,a)}}return i.forEach(n=>this.wildcardHandlers.delete(n)),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 l=new C;class S{constructor(e={}){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=>{l.emit(`state:${i}:changed`,{oldValue:e[i],newValue:t[i],state:t})}),r.length>0&&l.emit("state:changed",{oldState:e,newState:t,changedKeys:r})}setView(e){this.calendar.setView(e),this.setState({view:e}),l.emit("view:changed",{view:e})}getView(){return this.state.view}setDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),l.emit("date:changed",{date:this.state.currentDate})}getCurrentDate(){return this.state.currentDate}next(){this.calendar.next(),this.setState({currentDate:this.calendar.getCurrentDate()}),l.emit("navigation:next",{date:this.state.currentDate})}previous(){this.calendar.previous(),this.setState({currentDate:this.calendar.getCurrentDate()}),l.emit("navigation:previous",{date:this.state.currentDate})}today(){this.calendar.today(),this.setState({currentDate:this.calendar.getCurrentDate()}),l.emit("navigation:today",{date:this.state.currentDate})}goToDate(e){this.calendar.goToDate(e),this.setState({currentDate:this.calendar.getCurrentDate()}),l.emit("navigation:goto",{date:this.state.currentDate})}addEvent(e){const t=this.calendar.addEvent(e);return t?(this._syncEventsFromCore(),l.emit("event:add",{event:t}),l.emit("event:added",{event:t}),t):(console.error("Failed to add event to calendar"),l.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}),l.emit("event:update",{event:r}),l.emit("event:updated",{event:r}),r):(console.error(`Failed to update event: ${e}`),l.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(),l.emit("event:remove",{eventId:e}),l.emit("event:deleted",{eventId:e}),!0):(console.error(`Failed to delete event: ${e}`),l.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(n=>({...n,days:n.days.map(s=>{const o=new Date(s.date);return{...s,isSelected:o.toDateString()===r,events:s.events||this.getEventsForDate(o)}})}))),t.days&&(t.days=t.days.map(n=>{const s=new Date(n.date);return{...n,isSelected:s.toDateString()===r,events:n.events||this.getEventsForDate(s)}})),t.date&&!t.days&&!t.weeks){const n=new Date(t.date);t.isSelected=n.toDateString()===r,t.events=t.events||this.getEventsForDate(n)}return t}selectEvent(e){this.setState({selectedEvent:e}),l.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}),l.emit("event:deselected",{})}selectDate(e){this.setState({selectedDate:e}),l.emit("date:selected",{date:e})}deselectDate(){this.setState({selectedDate:null}),l.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&&l.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 b 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"}},n=i[t]||i.default;return new Intl.DateTimeFormat(r,n).format(e)}static formatTime(e,t=!0,r=!1,i="en-US"){if(!e)return"";const n={hour:"numeric",minute:t?"2-digit":void 0,hour12:!r};return new Intl.DateTimeFormat(i,n).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 n=this.formatTime(t,!0,!1,r);return`${i} - ${n}`}static getRelativeTime(e,t=new Date,r="en-US"){const i=new Intl.RelativeTimeFormat(r,{numeric:"auto"}),n=e-t,s=Math.floor(n/1e3),o=Math.floor(s/60),a=Math.floor(o/60),c=Math.floor(a/24),d=Math.floor(c/7),f=Math.floor(c/30),m=Math.floor(c/365);return Math.abs(s)<60?i.format(s,"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(f)<12?i.format(f,"month"):i.format(m,"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,n]=e.split(/\s+/),[s,o]=i.split(":").map(Number);let a=s;return n&&(n.toLowerCase()==="pm"&&s<12?a=s+12:n.toLowerCase()==="am"&&s===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(([n,s])=>{if(n==="className")i.className=s;else if(n==="style"&&typeof s=="object")Object.assign(i.style,s);else if(n.startsWith("data-"))i.setAttribute(n,s);else if(n.startsWith("on")&&typeof s=="function"){const o=n.slice(2).toLowerCase();i.addEventListener(o,s)}else i[n]=s}),r.forEach(n=>{typeof n=="string"?i.appendChild(document.createTextNode(n)):n instanceof Node&&i.appendChild(n)}),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 n=s=>{const o=s.target.closest(t);o&&e.contains(o)&&i.call(o,s)};return e.addEventListener(r,n),()=>e.removeEventListener(r,n)}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:n="nearest"}=t;e.scrollIntoView({behavior:r,block:i,inline:n})}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(...n){const s=()=>{clearTimeout(r),e(...n)};clearTimeout(r),r=setTimeout(s,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],n=s=>{s.key==="Tab"&&(s.shiftKey?document.activeElement===r&&(i==null||i.focus(),s.preventDefault()):document.activeElement===i&&(r==null||r.focus(),s.preventDefault()))};return e.addEventListener("keydown",n),r==null||r.focus(),()=>e.removeEventListener("keydown",n)}}class p{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(`
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
padding: 0;
|
|
150
150
|
border-radius: var(--fc-border-radius-full);
|
|
151
151
|
}
|
|
152
|
-
`}static darken(e,t){const r=parseInt(e.replace("#",""),16),i=Math.round(2.55*t),
|
|
152
|
+
`}static darken(e,t){const r=parseInt(e.replace("#",""),16),i=Math.round(2.55*t),n=(r>>16)-i,s=(r>>8&255)-i,o=(r&255)-i;return"#"+(16777216+(n<255?n<1?0:n:255)*65536+(s<255?s<1?0:s:255)*256+(o<255?o<1?0:o:255)).toString(16).slice(1)}static lighten(e,t){const r=parseInt(e.replace("#",""),16),i=Math.round(2.55*t),n=(r>>16)+i,s=(r>>8&255)+i,o=(r&255)+i;return"#"+(16777216+(n<255?n<1?0:n:255)*65536+(s<255?s<1?0:s:255)*256+(o<255?o<1?0:o:255)).toString(16).slice(1)}static getContrastColor(e){const t=e.replace("#",""),r=parseInt(t.substr(0,2),16),i=parseInt(t.substr(2,2),16),n=parseInt(t.substr(4,2),16);return(r*299+i*587+n*114)/1e3>=128?"#000000":"#FFFFFF"}static sanitizeColor(e,t="var(--fc-primary-color)"){if(!e||typeof e!="string")return t;const r=e.trim();return/[;{}()<>\"\'\\]/.test(r)?t:/^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6}|[0-9A-Fa-f]{8})$/.test(r)||/^var\(--[a-zA-Z0-9-]+\)$/.test(r)||/^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*(0|1|0?\.\d+))?\s*\)$/.test(r)||["transparent","currentColor","inherit","black","white","red","green","blue","yellow","orange","purple","pink","brown","gray","grey","cyan","magenta","lime","navy","teal","aqua","maroon","olive","silver","fuchsia"].includes(r.toLowerCase())?r:t}static hexToRgba(e,t=1){const r=e.replace("#",""),i=parseInt(r.substr(0,2),16),n=parseInt(r.substr(2,2),16),s=parseInt(r.substr(4,2),16);return`rgba(${i}, ${n}, ${s}, ${t})`}static getGridStyles(){return`
|
|
153
153
|
.fc-grid {
|
|
154
154
|
display: grid;
|
|
155
155
|
gap: 1px;
|
|
@@ -235,12 +235,12 @@
|
|
|
235
235
|
.fc-scale-in {
|
|
236
236
|
animation: fc-scale-in var(--fc-transition);
|
|
237
237
|
}
|
|
238
|
-
`}}E(p,"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"}}),E(p,"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"}),E(p,"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",
|
|
238
|
+
`}}E(p,"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"}}),E(p,"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"}),E(p,"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",n=t%12||12;return r===0?`${n} ${i}`:`${n}:${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),n=parseInt(r.substring(2,4),16),s=parseInt(r.substring(4,6),16);if(isNaN(i)||isNaN(n)||isNaN(s))return"white";const a=[i/255,n/255,s/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),f=c.getHours()*60+c.getMinutes(),m=Math.max(f+1,d.getHours()*60+d.getMinutes());return{id:a.id,startMin:f,endMin:m}});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 n=[];let s=[],o=0;for(const a of t)s.length===0||a.startMin<o?(s.push(a),o=Math.max(o,a.endMin)):(n.push(s),s=[a],o=a.endMin);s.length>0&&n.push(s);for(const a of n){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,n=new Date(e.start),s=new Date(e.end),o=n.getHours()*60+n.getMinutes(),a=Math.max((s-n)/(1e3*60),r?20:30),c=this.getEventColor(e),d=r?"4px 8px":"8px 12px",f=r?"11px":"13px",m=r?2:12,_=r?2:24,$=r?"4px":"6px";let M,T;if(i&&i.has(e.id)){const{column:I,totalColumns:H}=i.get(e.id),L=`(100% - ${m+_}px)`;M=`calc(${m}px + ${I} * ${L} / ${H})`,T=`calc(${L} / ${H})`}else M=`${m}px`,T=`calc(100% - ${m+_}px)`;return`
|
|
239
239
|
<div class="fc-event fc-timed-event" data-event-id="${this.escapeHTML(e.id)}"
|
|
240
|
-
style="position: absolute; top: ${
|
|
241
|
-
left: ${
|
|
242
|
-
background-color: ${
|
|
243
|
-
padding: ${
|
|
240
|
+
style="position: absolute; top: ${o}px; height: ${a}px;
|
|
241
|
+
left: ${M}; width: ${T};
|
|
242
|
+
background-color: ${c}; border-radius: ${$};
|
|
243
|
+
padding: ${d}; font-size: ${f};
|
|
244
244
|
font-weight: 500; color: white; overflow: hidden;
|
|
245
245
|
box-shadow: 0 1px 2px rgba(0,0,0,0.1);
|
|
246
246
|
cursor: pointer; z-index: 5;">
|
|
@@ -248,23 +248,23 @@
|
|
|
248
248
|
${this.escapeHTML(e.title)}
|
|
249
249
|
</div>
|
|
250
250
|
<div style="font-size: ${r?"10px":"11px"}; opacity: 0.9;">
|
|
251
|
-
${this.formatTime(
|
|
251
|
+
${this.formatTime(n)}${r?"":" - "+this.formatTime(s)}
|
|
252
252
|
</div>
|
|
253
253
|
</div>
|
|
254
|
-
`}getEventColor(e){return p.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(
|
|
254
|
+
`}getEventColor(e){return p.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(n=>n.id===r);i&&this.stateManager.selectEvent(i)})}}class y 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 n=`
|
|
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
|
-
${this._getDayNames(r).map(
|
|
257
|
+
${this._getDayNames(r).map(s=>`<div class="fc-month-header-cell" style="padding: 12px 8px; text-align: center; font-size: 11px; font-weight: 600; color: #6b7280; text-transform: uppercase;">${s}</div>`).join("")}
|
|
258
258
|
</div>
|
|
259
259
|
<div class="fc-month-body" style="display: flex; flex-direction: column; flex: 1;">
|
|
260
|
-
`;return e.weeks.forEach(
|
|
260
|
+
`;return e.weeks.forEach(s=>{n+=this._renderWeek(s)}),n+="</div></div>",n}_getDayNames(e){const t=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],r=[];for(let i=0;i<7;i++){const n=(e+i)%7;r.push(t[n])}return r}_renderWeek(e){let t='<div class="fc-month-week" style="display: grid; grid-template-columns: repeat(7, 1fr); flex: 1; min-height: 80px;">';return e.days.forEach(r=>{t+=this._renderDay(r)}),t+="</div>",t}_renderDay(e){const t=!e.isCurrentMonth,r=e.isToday,i=t?"#f3f4f6":"#fff",n=t?"#9ca3af":"#111827",s=r?"background: #2563eb; color: white; border-radius: 50%; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;":"",o=e.events||[],a=o.slice(0,this.maxEventsToShow),c=o.length-this.maxEventsToShow;return`
|
|
261
261
|
<div class="fc-month-day" data-date="${e.date}"
|
|
262
262
|
style="background: ${i}; border-right: 1px solid #e5e7eb; border-bottom: 1px solid #e5e7eb; padding: 4px; min-height: 80px; cursor: pointer; display: flex; flex-direction: column;">
|
|
263
|
-
<div class="fc-day-number" style="font-size: 13px; font-weight: 500; color: ${
|
|
263
|
+
<div class="fc-day-number" style="font-size: 13px; font-weight: 500; color: ${n}; padding: 2px 4px; margin-bottom: 4px; ${s}">
|
|
264
264
|
${e.dayOfMonth}
|
|
265
265
|
</div>
|
|
266
266
|
<div class="fc-day-events" style="display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: hidden;">
|
|
267
|
-
${
|
|
267
|
+
${a.map(d=>this._renderEvent(d)).join("")}
|
|
268
268
|
${c>0?`<div class="fc-more-events" style="font-size: 10px; color: #6b7280; padding: 2px 4px; font-weight: 500;">+${c} more</div>`:""}
|
|
269
269
|
</div>
|
|
270
270
|
</div>
|
|
@@ -273,11 +273,11 @@
|
|
|
273
273
|
style="background-color: ${t}; font-size: 11px; padding: 2px 6px; border-radius: 3px; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;">
|
|
274
274
|
${this.escapeHTML(e.title)}
|
|
275
275
|
</div>
|
|
276
|
-
`}_attachEventHandlers(){this.addListener(this.container,"click",e=>{const t=e.target.closest(".fc-month-day");if(!t||!this.container.contains(t)||e.target.closest(".fc-event"))return;const r=new Date(t.dataset.date);this.stateManager.selectDate(r)}),this.attachCommonEventHandlers()}}class D extends x{constructor(e,t){super(e,t),this.hourHeight=60,this.totalHeight=24*this.hourHeight}render(){if(!this.container||!this.stateManager)return;const e=this.stateManager.getViewData();if(!e||!e.days||e.days.length===0){this.container.innerHTML='<div style="padding: 20px; text-align: center; color: #666;">No data available for week view.</div>';return}this.cleanup();const t=this.stateManager.getState().config,r=this._renderWeekView(e,t);this.container.innerHTML=r,this._attachEventHandlers(),this._scrollToCurrentTime()}_renderWeekView(e,t){const r=e.days,i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],
|
|
276
|
+
`}_attachEventHandlers(){this.addListener(this.container,"click",e=>{const t=e.target.closest(".fc-month-day");if(!t||!this.container.contains(t)||e.target.closest(".fc-event"))return;const r=new Date(t.dataset.date);this.stateManager.selectDate(r)}),this.attachCommonEventHandlers()}}class D extends x{constructor(e,t){super(e,t),this.hourHeight=60,this.totalHeight=24*this.hourHeight}render(){if(!this.container||!this.stateManager)return;const e=this.stateManager.getViewData();if(!e||!e.days||e.days.length===0){this.container.innerHTML='<div style="padding: 20px; text-align: center; color: #666;">No data available for week view.</div>';return}this.cleanup(),this._scrolled=!1;const t=this.stateManager.getState().config,r=this._renderWeekView(e,t);this.container.innerHTML=r,this._attachEventHandlers(),this._scrollToCurrentTime()}_renderWeekView(e,t){const r=e.days,i=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],n=Array.from({length:24},(o,a)=>a),s=r.map(o=>{const a=new Date(o.date),c=o.events||[];return{...o,date:a,dayName:i[a.getDay()],dayOfMonth:a.getDate(),isToday:this.isToday(a),timedEvents:c.filter(d=>!d.allDay),allDayEvents:c.filter(d=>d.allDay)}});return`
|
|
277
277
|
<div class="fc-week-view" style="display: flex; flex-direction: column; height: 100%; background: #fff; overflow: hidden;">
|
|
278
|
-
${this._renderHeader(
|
|
279
|
-
${this._renderAllDayRow(
|
|
280
|
-
${this._renderTimeGrid(n
|
|
278
|
+
${this._renderHeader(s)}
|
|
279
|
+
${this._renderAllDayRow(s)}
|
|
280
|
+
${this._renderTimeGrid(s,n)}
|
|
281
281
|
</div>
|
|
282
282
|
`}_renderHeader(e){return`
|
|
283
283
|
<div class="fc-week-header" style="display: grid; grid-template-columns: 60px repeat(7, 1fr); border-bottom: 1px solid #e5e7eb; background: #f9fafb; flex-shrink: 0;">
|
|
@@ -333,15 +333,15 @@
|
|
|
333
333
|
${e.isToday?this.renderNowIndicator():""}
|
|
334
334
|
|
|
335
335
|
<!-- Timed events -->
|
|
336
|
-
${e.timedEvents.map(
|
|
336
|
+
${(()=>{const r=this.computeOverlapLayout(e.timedEvents);return e.timedEvents.map(i=>this.renderTimedEvent(i,{compact:!0,overlapLayout:r})).join("")})()}
|
|
337
337
|
</div>
|
|
338
|
-
`}_attachEventHandlers(){this.addListener(this.container,"click",e=>{const t=e.target.closest(".fc-week-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("#week-scroll-container"),
|
|
338
|
+
`}_attachEventHandlers(){this.addListener(this.container,"click",e=>{const t=e.target.closest(".fc-week-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("#week-scroll-container"),n=t.offsetTop,s=e.clientY-t.getBoundingClientRect().top+(i?i.scrollTop:0)-n,o=Math.max(0,Math.min(s+n,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("#week-scroll-container");e&&(e.scrollTop=8*this.hourHeight-50,this._scrolled=!0)}}class k extends x{constructor(e,t){super(e,t),this.hourHeight=60,this.totalHeight=24*this.hourHeight}render(){if(!this.container||!this.stateManager)return;const e=this.stateManager.getViewData();if(!e){this.container.innerHTML='<div style="padding: 20px; text-align: center; color: #666;">No data available for day view.</div>';return}this.cleanup(),this._scrolled=!1;const t=this.stateManager.getState().config,r=this._renderDayView(e,t);this.container.innerHTML=r,this._attachEventHandlers(),this._scrollToCurrentTime()}_renderDayView(e,t){var f,m;const r=((m=(f=this.stateManager)==null?void 0:f.getState())==null?void 0:m.currentDate)||new Date,i=this._extractDayData(e,r);if(!i)return'<div style="padding: 20px; text-align: center; color: #666;">No data available for day view.</div>';const{dayDate:n,dayName:s,isToday:o,allDayEvents:a,timedEvents:c}=i,d=Array.from({length:24},(_,$)=>$);return`
|
|
339
339
|
<div class="fc-day-view" style="display: flex; flex-direction: column; height: 100%; background: #fff; overflow: hidden;">
|
|
340
|
-
${this._renderHeader(s,
|
|
341
|
-
${this._renderAllDayRow(
|
|
342
|
-
${this._renderTimeGrid(c,
|
|
340
|
+
${this._renderHeader(n,s,o)}
|
|
341
|
+
${this._renderAllDayRow(a,n)}
|
|
342
|
+
${this._renderTimeGrid(c,o,n,d)}
|
|
343
343
|
</div>
|
|
344
|
-
`}_extractDayData(e,t){let r,i,s,
|
|
344
|
+
`}_extractDayData(e,t){let r,i,n,s,o;const a=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];if(e.type==="day"&&e.date)if(r=new Date(e.date),i=e.dayName||a[r.getDay()],n=e.isToday!==void 0?e.isToday:this.isToday(r),s=e.allDayEvents||[],e.hours&&Array.isArray(e.hours)){const c=new Map;e.hours.forEach(d=>{(d.events||[]).forEach(f=>{c.has(f.id)||c.set(f.id,f)})}),o=Array.from(c.values())}else o=[];else if(e.days&&e.days.length>0){const c=e.days.find(f=>this.isSameDay(new Date(f.date),t))||e.days[0];r=new Date(c.date),i=a[r.getDay()],n=this.isToday(r);const d=c.events||[];s=d.filter(f=>f.allDay),o=d.filter(f=>!f.allDay)}else return null;return{dayDate:r,dayName:i,isToday:n,allDayEvents:s,timedEvents:o}}_renderHeader(e,t,r){return`
|
|
345
345
|
<div class="fc-day-header" style="display: grid; grid-template-columns: 60px 1fr; border-bottom: 1px solid #e5e7eb; background: #f9fafb; flex-shrink: 0;">
|
|
346
346
|
<div style="border-right: 1px solid #e5e7eb;"></div>
|
|
347
347
|
<div style="padding: 16px 24px;">
|
|
@@ -391,9 +391,9 @@
|
|
|
391
391
|
${t?this.renderNowIndicator():""}
|
|
392
392
|
|
|
393
393
|
<!-- Timed events -->
|
|
394
|
-
${e.map(s=>this.renderTimedEvent(s,{compact:!1})).join("")}
|
|
394
|
+
${(()=>{const n=this.computeOverlapLayout(e);return e.map(s=>this.renderTimedEvent(s,{compact:!1,overlapLayout:n})).join("")})()}
|
|
395
395
|
</div>
|
|
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"),
|
|
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"),n=t.offsetTop,s=e.clientY-t.getBoundingClientRect().top+(i?i.scrollTop:0)-n,o=Math.max(0,Math.min(s+n,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 V 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
397
|
${p.getBaseStyles()}
|
|
398
398
|
${p.getButtonStyles()}
|
|
399
399
|
|
|
@@ -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(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=
|
|
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),n=t(e.getDate()),s=t(e.getHours()),o=t(e.getMinutes());return`${r}-${i}-${n}T${s}:${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",V);class F 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(t=>t()),this._busUnsubscribers=[],this._busUnsubscribers.push(l.on("navigation:*",(t,r)=>{this.emit("calendar-navigate",{action:r.split(":")[1],...t})})),this._busUnsubscribers.push(l.on("view:changed",t=>{this.emit("calendar-view-change",t)}));const e=(t,r)=>{this.emit(`calendar-event-${t}`,r)};this._busUnsubscribers.push(l.on("event:add",t=>{e("add",t)})),this._busUnsubscribers.push(l.on("event:update",t=>{e("update",t)})),this._busUnsubscribers.push(l.on("event:remove",t=>{e("remove",t)})),this._busUnsubscribers.push(l.on("event:added",t=>{this.emit("calendar-event-added",t)})),this._busUnsubscribers.push(l.on("event:updated",t=>{this.emit("calendar-event-updated",t)})),this._busUnsubscribers.push(l.on("event:deleted",t=>{this.emit("calendar-event-deleted",t)})),this._busUnsubscribers.push(l.on("date:selected",t=>{this.emit("calendar-date-select",t)}))}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()),n=e.events!==(t==null?void 0:t.events),s=e.loading!==(t==null?void 0:t.loading);if(e.error!==(t==null?void 0:t.error)){this.render();return}if(s){this._updateLoadingState(e.loading);return}r&&(this.currentView=e.view),r?(this._updateTitle(),this._updateViewButtons(),this._switchView()):i?(this._updateTitle(),this._updateViewContent()):n&&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 r={month:y,week:D,day:k}[this.currentView]||y,i=new r(e,this.stateManager);i._viewType=this.currentView,this._currentViewInstance=i,i.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
619
|
${p.getBaseStyles()}
|
|
620
620
|
${p.getButtonStyles()}
|
|
621
621
|
${p.getGridStyles()}
|
|
@@ -1000,13 +1000,13 @@
|
|
|
1000
1000
|
height: 100%;
|
|
1001
1001
|
background: var(--fc-background);
|
|
1002
1002
|
}
|
|
1003
|
-
`}template(){const e=this.stateManager.getState(),{currentDate:t,view:r,loading:i,error:
|
|
1003
|
+
`}template(){const e=this.stateManager.getState(),{currentDate:t,view:r,loading:i,error:n}=e;if(n)return`
|
|
1004
1004
|
<div class="force-calendar">
|
|
1005
1005
|
<div class="fc-error">
|
|
1006
|
-
<p><strong>Error:</strong> ${w.escapeHTML(
|
|
1006
|
+
<p><strong>Error:</strong> ${w.escapeHTML(n.message||"An error occurred")}</p>
|
|
1007
1007
|
</div>
|
|
1008
1008
|
</div>
|
|
1009
|
-
`;const
|
|
1009
|
+
`;const s=this.getTitle(t,r);return`
|
|
1010
1010
|
<div class="force-calendar">
|
|
1011
1011
|
<header class="fc-header">
|
|
1012
1012
|
<div class="fc-header-left">
|
|
@@ -1019,7 +1019,7 @@
|
|
|
1019
1019
|
<button class="fc-nav-arrow" data-action="previous" title="Previous">
|
|
1020
1020
|
${this.getIcon("chevron-left")}
|
|
1021
1021
|
</button>
|
|
1022
|
-
<h2 class="fc-title">${
|
|
1022
|
+
<h2 class="fc-title">${s}</h2>
|
|
1023
1023
|
<button class="fc-nav-arrow" data-action="next" title="Next">
|
|
1024
1024
|
${this.getIcon("chevron-right")}
|
|
1025
1025
|
</button>
|
|
@@ -1052,7 +1052,7 @@
|
|
|
1052
1052
|
|
|
1053
1053
|
<forcecal-event-form id="event-modal"></forcecal-event-form>
|
|
1054
1054
|
</div>
|
|
1055
|
-
`}renderView(){return'<div id="calendar-view-container"></div>'}afterRender(){const e=this.$("#calendar-view-container");if(e&&this.stateManager&&this.currentView){if(this._currentViewInstance&&this._currentViewInstance._viewType===this.currentView&&e.children.length>0)return;this._currentViewInstance&&(this._currentViewInstance.cleanup&&this._currentViewInstance.cleanup(),this._viewUnsubscribe&&(this._viewUnsubscribe(),this._viewUnsubscribe=null));try{const
|
|
1055
|
+
`}renderView(){return'<div id="calendar-view-container"></div>'}afterRender(){const e=this.$("#calendar-view-container");if(e&&this.stateManager&&this.currentView){if(this._currentViewInstance&&this._currentViewInstance._viewType===this.currentView&&e.children.length>0)return;this._currentViewInstance&&(this._currentViewInstance.cleanup&&this._currentViewInstance.cleanup(),this._viewUnsubscribe&&(this._viewUnsubscribe(),this._viewUnsubscribe=null));try{const n={month:y,week:D,day:k}[this.currentView]||y,s=new n(e,this.stateManager);s._viewType=this.currentView,this._currentViewInstance=s,s.render()}catch(i){console.error("[ForceCalendar] Error creating/rendering view:",i)}}this.$$("[data-action]").forEach(i=>{this.addListener(i,"click",this.handleNavigation)}),this.$$("[data-view]").forEach(i=>{this.addListener(i,"click",this.handleViewChange)});const t=this.$("#event-modal"),r=this.$("#create-event-btn");r&&t&&this.addListener(r,"click",()=>{t.open(new Date)}),this.addListener(this.shadowRoot,"day-click",i=>{t&&t.open(i.detail.date)}),t&&this.addListener(t,"save",i=>{const n=i.detail,s=window.crypto&&typeof window.crypto.randomUUID=="function"?window.crypto.randomUUID():Math.random().toString(36).substring(2,15);this.stateManager.addEvent({id:s,...n})}),this._hasRendered=!0}_createViewRenderer(e){const r={month:y,week:D,day:k}[e]||y;return new r(null,null)}handleNavigation(e){switch(e.currentTarget.dataset.action){case"today":this.stateManager.today();break;case"previous":this.stateManager.previous();break;case"next":this.stateManager.next();break}}handleViewChange(e){const t=e.currentTarget.dataset.view;this.stateManager.setView(t)}getTitle(e,t){const r=this.stateManager.state.config.locale;switch(t){case"month":return b.formatDate(e,"month",r);case"week":{const i=b.startOfWeek(e),n=b.endOfWeek(e);return b.formatDateRange(i,n,r)}case"day":return b.formatDate(e,"long",r);default:return b.formatDate(e,"month",r)}}getIcon(e){return{"chevron-left":`
|
|
1056
1056
|
<svg class="fc-icon" viewBox="0 0 24 24">
|
|
1057
1057
|
<path d="M15.41 7.41L14 6l-6 6 6 6 1.41-1.41L10.83 12z"/>
|
|
1058
1058
|
</svg>
|
|
@@ -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()}}customElements.get("forcecal-main")||customElements.define("forcecal-main",
|
|
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()}}customElements.get("forcecal-main")||customElements.define("forcecal-main",F),h.BaseComponent=v,h.BaseViewRenderer=x,h.DOMUtils=w,h.DateUtils=b,h.DayViewRenderer=k,h.EventBus=C,h.ForceCalendar=F,h.MonthViewRenderer=y,h.StateManager=S,h.StyleUtils=p,h.WeekViewRenderer=D,h.eventBus=l,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
1068
1068
|
//# sourceMappingURL=force-calendar-interface.umd.js.map
|