var t = `

` import Icon from './icon.js' import { formatDate } from './dateutils.js'; export default { props: { dottedDates: { type: Object, default: {} }, }, emits: ['date-selected', 'date-dblclick'], components: { Icon }, data() { return { today: null, selectedDate: null, displayedMonth: null, } }, methods: { getDotForType(dateStr, type) { const noteTypes = this.dottedDates[dateStr]; if (noteTypes && noteTypes.includes(type)) return '•'; return ''; }, getCalendarDays(year, month) { const startDate = new Date(year, month, 1); const endDate = new Date(year, month + 1, 0); // Last day of the month const days = []; // Previous month days let startDayOfWeek = startDate.getDay() - this.$notesiumState.startOfWeek; if (startDayOfWeek < 0) startDayOfWeek += 7; for (let i = startDayOfWeek; i > 0; i--) { const date = new Date(year, month, 1 - i); days.push({ date: formatDate(date, '%Y-%m-%d'), day: date.getDate(), }); } // Current month days for (let day = 1; day <= endDate.getDate(); day++) { const date = new Date(year, month, day); const dateStr = formatDate(date, '%Y-%m-%d'); days.push({ date: dateStr, day: day, isCurrentMonth: true, isToday: dateStr === this.today, }); } // Next month days to complete the week let endDayOfWeek = endDate.getDay(); let daysToAdd = 6 - ((endDayOfWeek - this.$notesiumState.startOfWeek + 7) % 7); if ((days.length + daysToAdd) == 35) daysToAdd += 7; for (let i = 1; i <= daysToAdd; i++) { const date = new Date(year, month + 1, i); days.push({ date: formatDate(date, '%Y-%m-%d'), day: date.getDate(), }); } return days; }, setSelectedDate(dateStr) { this.selectedDate = dateStr; this.$emit('date-selected', this.selectedDate); const dateParts = this.selectedDate.split('-'); const selectedYear = parseInt(dateParts[0], 10); const selectedMonth = parseInt(dateParts[1], 10); const displayedMonthDate = new Date(this.displayedMonth); if (selectedYear !== displayedMonthDate.getFullYear() || selectedMonth !== displayedMonthDate.getMonth() + 1) { this.displayedMonth = new Date(selectedYear, selectedMonth - 1, 1); } }, changeMonth(increment) { this.displayedMonth = new Date(this.displayedMonth.getFullYear(), this.displayedMonth.getMonth() + increment, 1); }, }, computed: { formattedMonthYear() { return this.displayedMonth.toLocaleString('default', { month: 'short', year: 'numeric' }); }, displayedMonthDates() { const year = this.displayedMonth.getFullYear(); const month = this.displayedMonth.getMonth(); // getMonth is 0-indexed return this.getCalendarDays(year, month) }, sortedDaysOfWeek() { const daysOfWeek = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']; return [...daysOfWeek.slice(this.$notesiumState.startOfWeek), ...daysOfWeek.slice(0, this.$notesiumState.startOfWeek)]; }, }, created() { this.displayedMonth = new Date(); this.today = formatDate(this.displayedMonth, '%Y-%m-%d'); }, mounted() { this.setSelectedDate(this.today); }, template: t }